]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/ispfw/ispfw.c
MFC r291188: Rip off target mode support for parallel SCSI QLogic adapters.
[FreeBSD/stable/10.git] / sys / dev / ispfw / ispfw.c
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 #if     !defined(KLD_MODULE)
130 #define ISPFW_KLD       0
131 #else
132 #define ISPFW_KLD       1
133 #endif
134
135 #define RMACRO(token)   do {                                            \
136         if (token##_loaded)                                             \
137                 break;                                                  \
138         if (firmware_register(#token, token##_risc_code,                \
139             token##_risc_code[3] * sizeof(token##_risc_code[3]),        \
140             ISPFW_VERSION, NULL) == NULL) {                             \
141                 printf("%s: unable to register firmware <%s>\n",        \
142                     MODULE_NAME, #token);                               \
143                 break;                                                  \
144         }                                                               \
145         token##_loaded++;                                               \
146         if (bootverbose || ISPFW_KLD)                                   \
147                 printf("%s: registered firmware <%s>\n", MODULE_NAME,   \
148                     #token);                                            \
149 } while (0)
150
151 #define UMACRO(token)   do {                                            \
152         if (!token##_loaded)                                            \
153                 break;                                                  \
154         if (firmware_unregister(#token) != 0) {                         \
155                 printf("%s: unable to unregister firmware <%s>\n",      \
156                     MODULE_NAME, #token);                               \
157                 break;                                                  \
158         }                                                               \
159         token##_loaded--;                                               \
160         if (bootverbose || ISPFW_KLD)                                   \
161                 printf("%s: unregistered firmware <%s>\n", MODULE_NAME, \
162                     #token);                                            \
163 } while (0)
164
165 static void
166 do_load_fw(void)
167 {
168
169 #if     defined(ISP_1000)
170         RMACRO(isp_1000);
171 #endif
172 #if     defined(ISP_1040)
173         RMACRO(isp_1040);
174 #endif
175 #if     defined(ISP_1080)
176         RMACRO(isp_1080);
177 #endif
178 #if     defined(ISP_12160)
179         RMACRO(isp_12160);
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 #if     defined(ISP_2500)
197         RMACRO(isp_2500);
198 #endif
199 }
200
201 static void
202 do_unload_fw(void)
203 {
204
205 #if     defined(ISP_1000)
206         UMACRO(isp_1000);
207 #endif
208 #if     defined(ISP_1040)
209         UMACRO(isp_1040);
210 #endif
211 #if     defined(ISP_1080)
212         UMACRO(isp_1080);
213 #endif
214 #if     defined(ISP_12160)
215         UMACRO(isp_12160);
216 #endif
217 #if     defined(ISP_2100)
218         UMACRO(isp_2100);
219 #endif
220 #if     defined(ISP_2200)
221         UMACRO(isp_2200);
222 #endif
223 #if     defined(ISP_2300)
224         UMACRO(isp_2300);
225 #endif
226 #if     defined(ISP_2322)
227         UMACRO(isp_2322);
228 #endif
229 #if     defined(ISP_2400)
230         UMACRO(isp_2400);
231 #endif
232 #if     defined(ISP_2500)
233         UMACRO(isp_2500);
234 #endif
235 }
236
237 static int
238 module_handler(module_t mod, int what, void *arg)
239 {
240
241         switch (what) {
242         case MOD_LOAD:
243                 do_load_fw();
244                 break;
245         case MOD_UNLOAD:
246                 do_unload_fw();
247                 break;
248         case MOD_SHUTDOWN:
249                 break;
250         default:
251                 return (EOPNOTSUPP);
252         }
253         return (0);
254 }
255 static moduledata_t ispfw_mod = {
256         MODULE_NAME, module_handler, NULL
257 };
258 #if     defined(ISP_ALL) || !defined(KLD_MODULE) 
259 DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
260 #elif   defined(ISP_1000)
261 DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
262 #elif   defined(ISP_1040)
263 DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
264 #elif   defined(ISP_1080)
265 DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
266 #elif   defined(ISP_12160)
267 DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
268 #elif   defined(ISP_2100)
269 DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
270 #elif   defined(ISP_2200)
271 DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
272 #elif   defined(ISP_2300)
273 DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
274 #elif   defined(ISP_2322)
275 DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
276 #elif   defined(ISP_2400)
277 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
278 #elif   defined(ISP_2500)
279 DECLARE_MODULE(isp_2500, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
280 #else
281 #error  "firmware not specified"
282 #endif