xref: /freebsd/sys/dev/ispfw/ispfw.c (revision a4dc509f723944821bcfcc52005ff87c9a5dee5b)
1 /*-
2  * ISP Firmware Modules for FreeBSD
3  *
4  * Copyright (c) 2000, 2001, 2006 by Matthew Jacob
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice immediately at the beginning of the file, without modification,
12  *    this list of conditions, and the following disclaimer.
13  * 2. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 
32 #include <sys/param.h>
33 #include <sys/firmware.h>
34 #include <sys/kernel.h>
35 #include <sys/linker.h>
36 #include <sys/module.h>
37 #include <sys/systm.h>
38 
39 #if	defined(ISP_ALL) || !defined(KLD_MODULE)
40 #ifdef __sparc64__
41 #define	ISP_1000	1
42 #endif
43 #define	ISP_1040	1
44 #define	ISP_1040_IT	1
45 #define	ISP_1080	1
46 #define	ISP_1080_IT	1
47 #define	ISP_12160	1
48 #define	ISP_12160_IT	1
49 #define	ISP_2100	1
50 #define	ISP_2200	1
51 #define	ISP_2300	1
52 #define	ISP_2322	1
53 #define	ISP_2400	1
54 #define	ISP_2500	1
55 #endif
56 
57 #ifndef MODULE_NAME
58 #define	MODULE_NAME	"ispfw"
59 #endif
60 
61 #if	defined(ISP_1000)
62 #ifdef __sparc64__
63 #include <dev/ispfw/asm_1000.h>
64 #else
65 #error "firmware not compatible with this platform"
66 #endif
67 #endif
68 #if	defined(ISP_1040) || defined(ISP_1040_IT)
69 #include <dev/ispfw/asm_1040.h>
70 #endif
71 #if	defined(ISP_1080) || defined(ISP_1080_IT)
72 #include <dev/ispfw/asm_1080.h>
73 #endif
74 #if	defined(ISP_12160) || defined(ISP_12160_IT)
75 #include <dev/ispfw/asm_12160.h>
76 #endif
77 #if	defined(ISP_2100)
78 #include <dev/ispfw/asm_2100.h>
79 #endif
80 #if	defined(ISP_2200)
81 #include <dev/ispfw/asm_2200.h>
82 #endif
83 #if	defined(ISP_2300)
84 #include <dev/ispfw/asm_2300.h>
85 #endif
86 #if	defined(ISP_2322)
87 #include <dev/ispfw/asm_2322.h>
88 #endif
89 #if	defined(ISP_2400)
90 #include <dev/ispfw/asm_2400.h>
91 #endif
92 #if	defined(ISP_2500)
93 #include <dev/ispfw/asm_2500.h>
94 #endif
95 
96 #if	defined(ISP_1000)
97 static int	isp_1000_loaded;
98 #endif
99 #if	defined(ISP_1040)
100 static int	isp_1040_loaded;
101 #endif
102 #if	defined(ISP_1040_IT)
103 static int	isp_1040_it_loaded;
104 #endif
105 #if	defined(ISP_1080)
106 static int	isp_1080_loaded;
107 #endif
108 #if	defined(ISP_1080_IT)
109 static int	isp_1080_it_loaded;
110 #endif
111 #if	defined(ISP_12160)
112 static int	isp_12160_loaded;
113 #endif
114 #if	defined(ISP_12160_IT)
115 static int	isp_12160_it_loaded;
116 #endif
117 #if	defined(ISP_2100)
118 static int	isp_2100_loaded;
119 #endif
120 #if	defined(ISP_2200)
121 static int	isp_2200_loaded;
122 #endif
123 #if	defined(ISP_2300)
124 static int	isp_2300_loaded;
125 #endif
126 #if	defined(ISP_2322)
127 static int	isp_2322_loaded;
128 #endif
129 #if	defined(ISP_2400)
130 static int	isp_2400_loaded;
131 #endif
132 #if	defined(ISP_2500)
133 static int	isp_2500_loaded;
134 #endif
135 
136 #define	ISPFW_VERSION	1
137 
138 #define	RMACRO(token)	do {						\
139 	if (token##_loaded)						\
140 		break;							\
141 	if (firmware_register(#token, token##_risc_code,		\
142 	    token##_risc_code[3] * sizeof(token##_risc_code[3]),	\
143 	    ISPFW_VERSION, NULL) == NULL)				\
144 		break;							\
145 	token##_loaded++;						\
146 } while (0)
147 
148 #define	UMACRO(token)	do {						\
149 	if (!token##_loaded)						\
150 		break;							\
151 	if (firmware_unregister(#token) != 0) {				\
152 		error = EBUSY;						\
153 		break;							\
154 	}								\
155 	token##_loaded--;						\
156 } while (0)
157 
158 static int
159 do_load_fw(void)
160 {
161 
162 #if	defined(ISP_1000)
163 	RMACRO(isp_1000);
164 #endif
165 #if	defined(ISP_1040)
166 	RMACRO(isp_1040);
167 #endif
168 #if	defined(ISP_1040_IT)
169 	RMACRO(isp_1040_it);
170 #endif
171 #if	defined(ISP_1080)
172 	RMACRO(isp_1080);
173 #endif
174 #if	defined(ISP_1080_IT)
175 	RMACRO(isp_1080_it);
176 #endif
177 #if	defined(ISP_12160)
178 	RMACRO(isp_12160);
179 #endif
180 #if	defined(ISP_12160_IT)
181 	RMACRO(isp_12160_it);
182 #endif
183 #if	defined(ISP_2100)
184 	RMACRO(isp_2100);
185 #endif
186 #if	defined(ISP_2200)
187 	RMACRO(isp_2200);
188 #endif
189 #if	defined(ISP_2300)
190 	RMACRO(isp_2300);
191 #endif
192 #if	defined(ISP_2322)
193 	RMACRO(isp_2322);
194 #endif
195 #if	defined(ISP_2400)
196 	RMACRO(isp_2400);
197 #endif
198 #if	defined(ISP_2500)
199 	RMACRO(isp_2500);
200 #endif
201 	return (0);
202 }
203 
204 static int
205 do_unload_fw(void)
206 {
207 	int error = 0;
208 
209 #if	defined(ISP_1000)
210 	UMACRO(isp_1000);
211 #endif
212 #if	defined(ISP_1040)
213 	UMACRO(isp_1040);
214 #endif
215 #if	defined(ISP_1040_IT)
216 	UMACRO(isp_1040_it);
217 #endif
218 #if	defined(ISP_1080)
219 	UMACRO(isp_1080);
220 #endif
221 #if	defined(ISP_1080_IT)
222 	UMACRO(isp_1080_it);
223 #endif
224 #if	defined(ISP_12160)
225 	UMACRO(isp_12160);
226 #endif
227 #if	defined(ISP_12160_IT)
228 	UMACRO(isp_12160_it);
229 #endif
230 #if	defined(ISP_2100)
231 	UMACRO(isp_2100);
232 #endif
233 #if	defined(ISP_2200)
234 	UMACRO(isp_2200);
235 #endif
236 #if	defined(ISP_2300)
237 	UMACRO(isp_2300);
238 #endif
239 #if	defined(ISP_2322)
240 	UMACRO(isp_2322);
241 #endif
242 #if	defined(ISP_2400)
243 	UMACRO(isp_2400);
244 #endif
245 #if	defined(ISP_2500)
246 	UMACRO(isp_2500);
247 #endif
248 	return (error);
249 }
250 
251 static int
252 module_handler(module_t mod, int what, void *arg)
253 {
254 
255 	switch (what) {
256 	case MOD_LOAD:
257 		return (do_load_fw());
258 	case MOD_UNLOAD:
259 		return (do_unload_fw());
260 	}
261 	return (EOPNOTSUPP);
262 }
263 static moduledata_t ispfw_mod = {
264 	MODULE_NAME, module_handler, NULL
265 };
266 #if	defined(ISP_ALL) || !defined(KLD_MODULE)
267 DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
268 #elif	defined(ISP_1000)
269 DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
270 #elif	defined(ISP_1040)
271 DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
272 #elif	defined(ISP_1040_IT)
273 DECLARE_MODULE(isp_1040_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
274 #elif	defined(ISP_1080)
275 DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
276 #elif	defined(ISP_1080_IT)
277 DECLARE_MODULE(isp_1080_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
278 #elif	defined(ISP_12160)
279 DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
280 #elif	defined(ISP_12160_IT)
281 DECLARE_MODULE(isp_12160_IT, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
282 #elif	defined(ISP_2100)
283 DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
284 #elif	defined(ISP_2200)
285 DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
286 #elif	defined(ISP_2300)
287 DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
288 #elif	defined(ISP_2322)
289 DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
290 #elif	defined(ISP_2400)
291 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
292 #elif	defined(ISP_2500)
293 DECLARE_MODULE(isp_2500, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
294 #else
295 #error	"firmware not specified"
296 #endif
297