ispfw(4): Add MODULE_VERSION()s.
[dragonfly.git] / sys / dev / disk / ispfw / ispfw.c
CommitLineData
191d7ec1
SW
1/*-
2 * ISP Firmware Modules for FreeBSD
984263bc 3 *
191d7ec1 4 * Copyright (c) 2000, 2001, 2006 by Matthew Jacob
984263bc
MD
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.
191d7ec1
SW
27 *
28 * $FreeBSD: src/sys/dev/ispfw/ispfw.c,v 1.22 2010/03/05 03:37:42 sobomax Exp $
984263bc
MD
29 */
30
31#include <sys/param.h>
191d7ec1 32#include <sys/firmware.h>
984263bc 33#include <sys/kernel.h>
984263bc 34#include <sys/linker.h>
191d7ec1
SW
35#include <sys/module.h>
36#include <sys/systm.h>
984263bc 37
191d7ec1
SW
38#if defined(ISP_ALL) || !defined(KLD_MODULE)
39#define ISP_1040 1
40#define ISP_1040_IT 1
41#define ISP_1080 1
42#define ISP_1080_IT 1
43#define ISP_12160 1
44#define ISP_12160_IT 1
45#define ISP_2100 1
46#define ISP_2200 1
47#define ISP_2300 1
48#define ISP_2322 1
49#define ISP_2400 1
50#define ISP_2400_MULTI 1
51#define ISP_2500 1
52#define ISP_2500_MULTI 1
53#endif
984263bc 54
191d7ec1
SW
55#ifndef MODULE_NAME
56#define MODULE_NAME "ispfw"
57#endif
984263bc 58
191d7ec1
SW
59#if defined(ISP_1040) || defined(ISP_1040_IT)
60#include <dev/disk/ispfw/asm_1040.h>
61#endif
62#if defined(ISP_1080) || defined(ISP_1080_IT)
63#include <dev/disk/ispfw/asm_1080.h>
64#endif
65#if defined(ISP_12160) || defined(ISP_12160_IT)
66#include <dev/disk/ispfw/asm_12160.h>
67#endif
68#if defined(ISP_2100)
69#include <dev/disk/ispfw/asm_2100.h>
70#endif
71#if defined(ISP_2200)
72#include <dev/disk/ispfw/asm_2200.h>
73#endif
74#if defined(ISP_2300)
75#include <dev/disk/ispfw/asm_2300.h>
76#endif
77#if defined(ISP_2322)
78#include <dev/disk/ispfw/asm_2322.h>
79#endif
80#if defined(ISP_2400) || defined(ISP_2400_MULTI)
81#include <dev/disk/ispfw/asm_2400.h>
82#endif
83#if defined(ISP_2500) || defined(ISP_2500_MULTI)
84#include <dev/disk/ispfw/asm_2500.h>
85#endif
984263bc 86
191d7ec1
SW
87#if defined(ISP_1000)
88static int isp_1000_loaded;
89#endif
90#if defined(ISP_1040)
91static int isp_1040_loaded;
92#endif
93#if defined(ISP_1040_IT)
94static int isp_1040_it_loaded;
95#endif
96#if defined(ISP_1080)
97static int isp_1080_loaded;
98#endif
99#if defined(ISP_1080_IT)
100static int isp_1080_it_loaded;
101#endif
102#if defined(ISP_12160)
103static int isp_12160_loaded;
104#endif
105#if defined(ISP_12160_IT)
106static int isp_12160_it_loaded;
107#endif
108#if defined(ISP_2100)
109static int isp_2100_loaded;
110#endif
111#if defined(ISP_2200)
112static int isp_2200_loaded;
113#endif
114#if defined(ISP_2300)
115static int isp_2300_loaded;
116#endif
117#if defined(ISP_2322)
118static int isp_2322_loaded;
119#endif
120#if defined(ISP_2400)
121static int isp_2400_loaded;
122#endif
123#if defined(ISP_2400_MULTI)
124static int isp_2400_multi_loaded;
125#endif
126#if defined(ISP_2500)
127static int isp_2500_loaded;
128#endif
129#if defined(ISP_2500_MULTI)
130static int isp_2500_multi_loaded;
131#endif
984263bc 132
191d7ec1 133#define ISPFW_VERSION 1
984263bc 134
191d7ec1
SW
135#if !defined(KLD_MODULE)
136#define ISPFW_KLD 0
137#else
138#define ISPFW_KLD 1
139#endif
140
141#define RMACRO(token) do { \
142 if (token##_loaded) \
143 break; \
144 if (firmware_register(#token, token##_risc_code, \
145 token##_risc_code[3] * sizeof(token##_risc_code[3]), \
146 ISPFW_VERSION, NULL) == NULL) { \
147 kprintf("%s: unable to register firmware <%s>\n", \
148 MODULE_NAME, #token); \
149 break; \
150 } \
151 token##_loaded++; \
152 if (bootverbose || ISPFW_KLD) \
153 kprintf("%s: registered firmware <%s>\n", MODULE_NAME, \
154 #token); \
155} while (0)
156
157#define UMACRO(token) do { \
158 if (!token##_loaded) \
159 break; \
160 if (firmware_unregister(#token) != 0) { \
161 kprintf("%s: unable to unregister firmware <%s>\n", \
162 MODULE_NAME, #token); \
163 break; \
164 } \
165 token##_loaded--; \
166 if (bootverbose || ISPFW_KLD) \
167 kprintf("%s: unregistered firmware <%s>\n", MODULE_NAME,\
168 #token); \
169} while (0)
170
171static void
172do_load_fw(void)
984263bc 173{
191d7ec1
SW
174
175#if defined(ISP_1000)
176 RMACRO(isp_1000);
177#endif
178#if defined(ISP_1040)
179 RMACRO(isp_1040);
180#endif
181#if defined(ISP_1040_IT)
182 RMACRO(isp_1040_it);
183#endif
184#if defined(ISP_1080)
185 RMACRO(isp_1080);
186#endif
187#if defined(ISP_1080_IT)
188 RMACRO(isp_1080_it);
189#endif
190#if defined(ISP_12160)
191 RMACRO(isp_12160);
192#endif
193#if defined(ISP_12160_IT)
194 RMACRO(isp_12160_it);
195#endif
196#if defined(ISP_2100)
197 RMACRO(isp_2100);
198#endif
199#if defined(ISP_2200)
200 RMACRO(isp_2200);
201#endif
202#if defined(ISP_2300)
203 RMACRO(isp_2300);
204#endif
205#if defined(ISP_2322)
206 RMACRO(isp_2322);
207#endif
208#if defined(ISP_2400)
209 RMACRO(isp_2400);
210#endif
211#if defined(ISP_2400_MULTI)
212 RMACRO(isp_2400_multi);
213#endif
214#if defined(ISP_2500)
215 RMACRO(isp_2500);
216#endif
217#if defined(ISP_2500_MULTI)
218 RMACRO(isp_2500_multi);
219#endif
984263bc
MD
220}
221
222static void
191d7ec1 223do_unload_fw(void)
984263bc 224{
984263bc 225
191d7ec1
SW
226#if defined(ISP_1000)
227 UMACRO(isp_1000);
228#endif
229#if defined(ISP_1040)
230 UMACRO(isp_1040);
231#endif
232#if defined(ISP_1040_IT)
233 UMACRO(isp_1040_it);
234#endif
235#if defined(ISP_1080)
236 UMACRO(isp_1080);
237#endif
238#if defined(ISP_1080_IT)
239 UMACRO(isp_1080_it);
240#endif
241#if defined(ISP_12160)
242 UMACRO(isp_12160);
243#endif
244#if defined(ISP_12160_IT)
245 UMACRO(isp_12160_it);
246#endif
247#if defined(ISP_2100)
248 UMACRO(isp_2100);
249#endif
250#if defined(ISP_2200)
251 UMACRO(isp_2200);
252#endif
253#if defined(ISP_2300)
254 UMACRO(isp_2300);
255#endif
256#if defined(ISP_2322)
257 UMACRO(isp_2322);
258#endif
259#if defined(ISP_2400)
260 UMACRO(isp_2400);
261#endif
262#if defined(ISP_2400_MULTI)
263 UMACRO(isp_2400_multi);
264#endif
265#if defined(ISP_2500)
266 UMACRO(isp_2500);
267#endif
268#if defined(ISP_2500_MULTI)
269 UMACRO(isp_2500_multi);
270#endif
984263bc
MD
271}
272
273static int
191d7ec1 274module_handler(module_t mod, int what, void *arg)
984263bc 275{
191d7ec1 276
984263bc
MD
277 switch (what) {
278 case MOD_LOAD:
191d7ec1 279 do_load_fw();
984263bc
MD
280 break;
281 case MOD_UNLOAD:
191d7ec1 282 do_unload_fw();
984263bc 283 break;
191d7ec1 284 case MOD_SHUTDOWN:
984263bc 285 break;
191d7ec1
SW
286 default:
287 return (EOPNOTSUPP);
984263bc
MD
288 }
289 return (0);
290}
291static moduledata_t ispfw_mod = {
191d7ec1 292 MODULE_NAME, module_handler, NULL
984263bc 293};
191d7ec1 294#if defined(ISP_ALL) || !defined(KLD_MODULE)
984263bc 295DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 296MODULE_VERSION(ispfw, 1);
191d7ec1
SW
297#elif defined(ISP_1000)
298DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 299MODULE_VERSION(isp_1000, 1);
191d7ec1
SW
300#elif defined(ISP_1040)
301DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 302MODULE_VERSION(isp_1040, 1);
191d7ec1
SW
303#elif defined(ISP_1040_IT)
304DECLARE_MODULE(isp_1040_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 305MODULE_VERSION(isp_1040_it, 1);
191d7ec1
SW
306#elif defined(ISP_1080)
307DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 308MODULE_VERSION(isp_1080, 1);
191d7ec1
SW
309#elif defined(ISP_1080_IT)
310DECLARE_MODULE(isp_1080_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 311MODULE_VERSION(isp_1080_it, 1);
191d7ec1
SW
312#elif defined(ISP_12160)
313DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 314MODULE_VERSION(isp_12160, 1);
191d7ec1 315#elif defined(ISP_12160_IT)
41a6f0ad 316DECLARE_MODULE(isp_12160_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 317MODULE_VERSION(isp_12160_it, 1);
191d7ec1
SW
318#elif defined(ISP_2100)
319DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 320MODULE_VERSION(isp_2100, 1);
191d7ec1
SW
321#elif defined(ISP_2200)
322DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 323MODULE_VERSION(isp_2200, 1);
191d7ec1
SW
324#elif defined(ISP_2300)
325DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 326MODULE_VERSION(isp_2300, 1);
191d7ec1
SW
327#elif defined(ISP_2322)
328DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 329MODULE_VERSION(isp_2322, 1);
191d7ec1
SW
330#elif defined(ISP_2400)
331DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 332MODULE_VERSION(isp_2400, 1);
191d7ec1
SW
333#elif defined(ISP_2400_MULTI)
334DECLARE_MODULE(isp_2400_multi, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 335MODULE_VERSION(isp_2400_multi, 1);
191d7ec1
SW
336#elif defined(ISP_2500)
337DECLARE_MODULE(isp_2500, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 338MODULE_VERSION(isp_2500, 1);
191d7ec1
SW
339#elif defined(ISP_2500_MULTI)
340DECLARE_MODULE(isp_2500_multi, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
e43987e0 341MODULE_VERSION(isp_2500_multi, 1);
191d7ec1
SW
342#else
343#error "firmware not specified"
344#endif