xref: /freebsd/sys/dev/ispfw/ispfw.c (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
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_1080)
103 static int	isp_1080_loaded;
104 #endif
105 #if	defined(ISP_12160)
106 static int	isp_12160_loaded;
107 #endif
108 #if	defined(ISP_2100)
109 static int	isp_2100_loaded;
110 #endif
111 #if	defined(ISP_2200)
112 static int	isp_2200_loaded;
113 #endif
114 #if	defined(ISP_2300)
115 static int	isp_2300_loaded;
116 #endif
117 #if	defined(ISP_2322)
118 static int	isp_2322_loaded;
119 #endif
120 #if	defined(ISP_2400)
121 static int	isp_2400_loaded;
122 #endif
123 #if	defined(ISP_2500)
124 static int	isp_2500_loaded;
125 #endif
126 
127 #define	ISPFW_VERSION	1
128 
129 #define	RMACRO(token)	do {						\
130 	if (token##_loaded)						\
131 		break;							\
132 	if (firmware_register(#token, token##_risc_code,		\
133 	    token##_risc_code[3] * sizeof(token##_risc_code[3]),	\
134 	    ISPFW_VERSION, NULL) == NULL)				\
135 		break;							\
136 	token##_loaded++;						\
137 } while (0)
138 
139 #define	UMACRO(token)	do {						\
140 	if (!token##_loaded)						\
141 		break;							\
142 	if (firmware_unregister(#token) != 0) {				\
143 		error = EBUSY;						\
144 		break;							\
145 	}								\
146 	token##_loaded--;						\
147 } while (0)
148 
149 static int
150 do_load_fw(void)
151 {
152 
153 #if	defined(ISP_1000)
154 	RMACRO(isp_1000);
155 #endif
156 #if	defined(ISP_1040)
157 	RMACRO(isp_1040);
158 #endif
159 #if	defined(ISP_1080)
160 	RMACRO(isp_1080);
161 #endif
162 #if	defined(ISP_12160)
163 	RMACRO(isp_12160);
164 #endif
165 #if	defined(ISP_2100)
166 	RMACRO(isp_2100);
167 #endif
168 #if	defined(ISP_2200)
169 	RMACRO(isp_2200);
170 #endif
171 #if	defined(ISP_2300)
172 	RMACRO(isp_2300);
173 #endif
174 #if	defined(ISP_2322)
175 	RMACRO(isp_2322);
176 #endif
177 #if	defined(ISP_2400)
178 	RMACRO(isp_2400);
179 #endif
180 #if	defined(ISP_2500)
181 	RMACRO(isp_2500);
182 #endif
183 	return (0);
184 }
185 
186 static int
187 do_unload_fw(void)
188 {
189 	int error = 0;
190 
191 #if	defined(ISP_1000)
192 	UMACRO(isp_1000);
193 #endif
194 #if	defined(ISP_1040)
195 	UMACRO(isp_1040);
196 #endif
197 #if	defined(ISP_1080)
198 	UMACRO(isp_1080);
199 #endif
200 #if	defined(ISP_12160)
201 	UMACRO(isp_12160);
202 #endif
203 #if	defined(ISP_2100)
204 	UMACRO(isp_2100);
205 #endif
206 #if	defined(ISP_2200)
207 	UMACRO(isp_2200);
208 #endif
209 #if	defined(ISP_2300)
210 	UMACRO(isp_2300);
211 #endif
212 #if	defined(ISP_2322)
213 	UMACRO(isp_2322);
214 #endif
215 #if	defined(ISP_2400)
216 	UMACRO(isp_2400);
217 #endif
218 #if	defined(ISP_2500)
219 	UMACRO(isp_2500);
220 #endif
221 	return (error);
222 }
223 
224 static int
225 module_handler(module_t mod, int what, void *arg)
226 {
227 
228 	switch (what) {
229 	case MOD_LOAD:
230 		return (do_load_fw());
231 	case MOD_UNLOAD:
232 		return (do_unload_fw());
233 	}
234 	return (EOPNOTSUPP);
235 }
236 static moduledata_t ispfw_mod = {
237 	MODULE_NAME, module_handler, NULL
238 };
239 #if	defined(ISP_ALL) || !defined(KLD_MODULE)
240 DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
241 #elif	defined(ISP_1000)
242 DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
243 #elif	defined(ISP_1040)
244 DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
245 #elif	defined(ISP_1080)
246 DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
247 #elif	defined(ISP_12160)
248 DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
249 #elif	defined(ISP_2100)
250 DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
251 #elif	defined(ISP_2200)
252 DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
253 #elif	defined(ISP_2300)
254 DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
255 #elif	defined(ISP_2322)
256 DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
257 #elif	defined(ISP_2400)
258 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
259 #elif	defined(ISP_2500)
260 DECLARE_MODULE(isp_2500, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
261 #else
262 #error	"firmware not specified"
263 #endif
264