xref: /freebsd/sys/dev/ispfw/ispfw.c (revision 3c6e15bceeab4470243c60c9a4b5b9cafca9abaa)
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 #endif
55 
56 #ifndef MODULE_NAME
57 #define	MODULE_NAME	"ispfw"
58 #endif
59 
60 #if	defined(ISP_1000)
61 #ifdef __sparc64__
62 #include <dev/ispfw/asm_1000.h>
63 #else
64 #error "firmware not compatible with this platform"
65 #endif
66 #endif
67 #if	defined(ISP_1040) || defined(ISP_1040_IT)
68 #include <dev/ispfw/asm_1040.h>
69 #endif
70 #if	defined(ISP_1080) || defined(ISP_1080_IT)
71 #include <dev/ispfw/asm_1080.h>
72 #endif
73 #if	defined(ISP_12160) || defined(ISP_12160_IT)
74 #include <dev/ispfw/asm_12160.h>
75 #endif
76 #if	defined(ISP_2100)
77 #include <dev/ispfw/asm_2100.h>
78 #endif
79 #if	defined(ISP_2200)
80 #include <dev/ispfw/asm_2200.h>
81 #endif
82 #if	defined(ISP_2300)
83 #include <dev/ispfw/asm_2300.h>
84 #endif
85 #if	defined(ISP_2322)
86 #include <dev/ispfw/asm_2322.h>
87 #endif
88 #if	defined(ISP_2400)
89 #include <dev/ispfw/asm_2400.h>
90 #endif
91 
92 #if	defined(ISP_1000)
93 static int	isp_1000_loaded;
94 #endif
95 #if	defined(ISP_1040)
96 static int	isp_1040_loaded;
97 #endif
98 #if	defined(ISP_1040_IT)
99 static int	isp_1040_it_loaded;
100 #endif
101 #if	defined(ISP_1080)
102 static int	isp_1080_loaded;
103 #endif
104 #if	defined(ISP_1080_IT)
105 static int	isp_1080_it_loaded;
106 #endif
107 #if	defined(ISP_12160)
108 static int	isp_12160_loaded;
109 #endif
110 #if	defined(ISP_12160_IT)
111 static int	isp_12160_it_loaded;
112 #endif
113 #if	defined(ISP_2100)
114 static int	isp_2100_loaded;
115 #endif
116 #if	defined(ISP_2200)
117 static int	isp_2200_loaded;
118 #endif
119 #if	defined(ISP_2300)
120 static int	isp_2300_loaded;
121 #endif
122 #if	defined(ISP_2322)
123 static int	isp_2322_loaded;
124 #endif
125 #if	defined(ISP_2400)
126 static int	isp_2400_loaded;
127 #endif
128 
129 #define	ISPFW_VERSION	1
130 #define	RMACRO(token)	do {						\
131 	if (token##_loaded)						\
132 		break;							\
133 	if (firmware_register(#token, token##_risc_code,		\
134 	    token##_risc_code[3] * sizeof(token##_risc_code[3]),	\
135 	    ISPFW_VERSION, NULL) == NULL) {				\
136 		printf("%s: unable to register firmware <%s>\n",	\
137 		    MODULE_NAME, #token);				\
138 		break;							\
139 	}								\
140 	token##_loaded++;						\
141 	printf("%s: registered firmware <%s>\n", MODULE_NAME, #token);	\
142 } while (0)
143 
144 #define	UMACRO(token)	do {						\
145 	if (!token##_loaded)						\
146 		break;							\
147 	if (firmware_unregister(#token) != 0) {				\
148 		printf("%s: unable to unregister firmware <%s>\n",	\
149 		    MODULE_NAME, #token);				\
150 		break;							\
151 	}								\
152 	token##_loaded--;						\
153 	printf("%s: unregistered firmware <%s>\n", MODULE_NAME, #token);\
154 } while (0)
155 
156 static void
157 do_load_fw(void)
158 {
159 
160 #if	defined(ISP_1000)
161 	RMACRO(isp_1000);
162 #endif
163 #if	defined(ISP_1040)
164 	RMACRO(isp_1040);
165 #endif
166 #if	defined(ISP_1040_IT)
167 	RMACRO(isp_1040_it);
168 #endif
169 #if	defined(ISP_1080)
170 	RMACRO(isp_1080);
171 #endif
172 #if	defined(ISP_1080_IT)
173 	RMACRO(isp_1080_it);
174 #endif
175 #if	defined(ISP_12160)
176 	RMACRO(isp_12160);
177 #endif
178 #if	defined(ISP_12160_IT)
179 	RMACRO(isp_12160_it);
180 #endif
181 #if	defined(ISP_2100)
182 	RMACRO(isp_2100);
183 #endif
184 #if	defined(ISP_2200)
185 	RMACRO(isp_2200);
186 #endif
187 #if	defined(ISP_2300)
188 	RMACRO(isp_2300);
189 #endif
190 #if	defined(ISP_2322)
191 	RMACRO(isp_2322);
192 #endif
193 #if	defined(ISP_2400)
194 	RMACRO(isp_2400);
195 #endif
196 }
197 
198 static void
199 do_unload_fw(void)
200 {
201 
202 #if	defined(ISP_1000)
203 	UMACRO(isp_1000);
204 #endif
205 #if	defined(ISP_1040)
206 	UMACRO(isp_1040);
207 #endif
208 #if	defined(ISP_1040_IT)
209 	UMACRO(isp_1040_it);
210 #endif
211 #if	defined(ISP_1080)
212 	UMACRO(isp_1080);
213 #endif
214 #if	defined(ISP_1080_IT)
215 	UMACRO(isp_1080_it);
216 #endif
217 #if	defined(ISP_12160)
218 	UMACRO(isp_12160);
219 #endif
220 #if	defined(ISP_12160_IT)
221 	UMACRO(isp_12160_it);
222 #endif
223 #if	defined(ISP_2100)
224 	UMACRO(isp_2100);
225 #endif
226 #if	defined(ISP_2200)
227 	UMACRO(isp_2200);
228 #endif
229 #if	defined(ISP_2300)
230 	UMACRO(isp_2300);
231 #endif
232 #if	defined(ISP_2322)
233 	UMACRO(isp_2322);
234 #endif
235 #if	defined(ISP_2400)
236 	UMACRO(isp_2400);
237 #endif
238 }
239 
240 static int
241 module_handler(module_t mod, int what, void *arg)
242 {
243 
244 	switch (what) {
245 	case MOD_LOAD:
246 		do_load_fw();
247 		break;
248 	case MOD_UNLOAD:
249 		do_unload_fw();
250 		break;
251 	case MOD_SHUTDOWN:
252 		break;
253 	default:
254 		return (EOPNOTSUPP);
255 	}
256 	return (0);
257 }
258 static moduledata_t ispfw_mod = {
259 	MODULE_NAME, module_handler, NULL
260 };
261 #if	defined(ISP_ALL) || !defined(KLD_MODULE)
262 DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
263 #elif	defined(ISP_1000)
264 DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
265 #elif	defined(ISP_1040)
266 DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
267 #elif	defined(ISP_1040_IT)
268 DECLARE_MODULE(isp_1040_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
269 #elif	defined(ISP_1080)
270 DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
271 #elif	defined(ISP_1080_IT)
272 DECLARE_MODULE(isp_1080_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
273 #elif	defined(ISP_12160)
274 DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
275 #elif	defined(ISP_12160_IT)
276 DECLARE_MODULE(isp_12160_IT, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
277 #elif	defined(ISP_2100)
278 DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
279 #elif	defined(ISP_2200)
280 DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
281 #elif	defined(ISP_2300)
282 DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
283 #elif	defined(ISP_2322)
284 DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
285 #elif	defined(ISP_2400)
286 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
287 #else
288 #error	"firmware not specified"
289 #endif
290