1/*-
|
2 * ISP Firmware Helper Pseudo Device for FreeBSD
|
2 * ISP Firmware Modules for FreeBSD |
3 *
|
4 * Copyright (c) 2000, 2001, by Matthew Jacob
|
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: head/sys/dev/ispfw/ispfw.c 160079 2006-07-03 08:22:09Z mjacob $");
|
30__FBSDID("$FreeBSD: head/sys/dev/ispfw/ispfw.c 160212 2006-07-09 17:50:20Z mjacob $"); |
31 32#include <sys/param.h> 33#include <sys/kernel.h>
|
34#include <sys/malloc.h>
|
34#include <sys/module.h>
|
35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/linker.h> 38#include <sys/firmware.h> |
39
|
40#if defined(ISP_ALL) || !defined(KLD_MODULE) 41#define ISP_1040 1 42#define ISP_1040_IT 1 43#define ISP_1080 1 44#define ISP_1080_IT 1 45#define ISP_12160 1 46#define ISP_12160_IT 1 47#define ISP_2100 1 48#define ISP_2200 1 49#define ISP_2300 1 50#define ISP_2322 1 51#ifdef __sparc64__ 52#define ISP_1000 1 53#endif 54#define MODULE_NAME "isp" 55#endif 56 57#if defined(ISP_1040) || defined(ISP_1040_IT) |
58#include <dev/ispfw/asm_1040.h>
|
59#endif 60#if defined(ISP_1080) || defined(ISP_1080_IT) |
61#include <dev/ispfw/asm_1080.h>
|
62#endif 63#if defined(ISP_12160) || defined(ISP_12160_IT) |
64#include <dev/ispfw/asm_12160.h>
|
65#endif 66#if defined(ISP_2100) |
67#include <dev/ispfw/asm_2100.h>
|
68#endif 69#if defined(ISP_2200) |
70#include <dev/ispfw/asm_2200.h>
|
71#endif 72#if defined(ISP_2300) |
73#include <dev/ispfw/asm_2300.h>
|
74#endif 75#if defined(ISP_2322) |
76#include <dev/ispfw/asm_2322.h>
|
44#ifdef __sparc64__
|
77#endif 78#if defined(ISP_1000) |
79#include <dev/ispfw/asm_1000.h> 80#endif 81
|
48#define ISPFW_VERSION 0
|
82#define ISPFW_VERSION 1 83#define RMACRO(token) \ 84 if (firmware_register(#token, token##_risc_code, \ 85 token##_risc_code [3] << 1, ISPFW_VERSION, NULL) == NULL) { \ 86 printf("unable to register firmware '%s'\n", #token); \ 87 } else { \ 88 printf("registered firmware set <%s>\n", #token); \ 89 } |
90
|
50#define PCI_PRODUCT_QLOGIC_ISP1020 0x1020
51#define PCI_PRODUCT_QLOGIC_ISP1080 0x1080
52#define PCI_PRODUCT_QLOGIC_ISP10160 0x1016
53#define PCI_PRODUCT_QLOGIC_ISP12160 0x1216
54#define PCI_PRODUCT_QLOGIC_ISP1240 0x1240
55#define PCI_PRODUCT_QLOGIC_ISP1280 0x1280
56#define PCI_PRODUCT_QLOGIC_ISP2100 0x2100
57#define PCI_PRODUCT_QLOGIC_ISP2200 0x2200
58#define PCI_PRODUCT_QLOGIC_ISP2300 0x2300
59#define PCI_PRODUCT_QLOGIC_ISP2312 0x2312
60#define PCI_PRODUCT_QLOGIC_ISP2322 0x2322
61#define PCI_PRODUCT_QLOGIC_ISP6312 0x6312
62#ifdef __sparc64__
63#define SBUS_PRODUCT_QLOGIC_ISP1000 0x1000
64#endif
|
91#define UMACRO(token) \ 92 firmware_unregister(#token); \ 93 printf("unregistered firmware set <%s>\n", #token); |
94
|
66typedef void ispfwfunc(int, int, int, const u_int16_t **);
67extern ispfwfunc *isp_get_firmware_p;
68static void isp_get_firmware(int, int, int, const u_int16_t **);
69
70static int ncallers = 0;
71static const u_int16_t ***callp = NULL;
72static int addcaller(const u_int16_t **);
73
|
95static int
|
75addcaller(const u_int16_t **caller)
|
96do_load_fw(void) |
97{
|
77 const u_int16_t ***newcallp;
78 int i;
79 for (i = 0; i < ncallers; i++) {
80 if (callp[i] == caller)
81 return (1);
82 }
83 newcallp = malloc((ncallers + 1) * sizeof (const u_int16_t ***),
84 M_DEVBUF, M_NOWAIT);
85 if (newcallp == NULL) {
86 return (0);
87 }
88 for (i = 0; i < ncallers; i++) {
89 newcallp[i] = callp[i];
90 }
91 newcallp[ncallers] = caller;
92 if (ncallers++)
93 free(callp, M_DEVBUF);
94 callp = newcallp;
95 return (1);
|
98#if defined(ISP_1000) 99 RMACRO(isp_1000); 100#endif 101#if defined(ISP_1040) 102 RMACRO(isp_1040); 103#endif 104#if defined(ISP_1040_IT) 105 RMACRO(isp_1040_it); 106#endif 107#if defined(ISP_1080) 108 RMACRO(isp_1080); 109#endif 110#if defined(ISP_1080_IT) 111 RMACRO(isp_1080_it); 112#endif 113#if defined(ISP_12160) 114 RMACRO(isp_12160); 115#endif 116#if defined(ISP_12160_IT) 117 RMACRO(isp_12160_it); 118#endif 119#if defined(ISP_2100) 120 RMACRO(isp_2100); 121#endif 122#if defined(ISP_2200) 123 RMACRO(isp_2200); 124#endif 125#if defined(ISP_2300) 126 RMACRO(isp_2300); 127#endif 128#if defined(ISP_2322) 129 RMACRO(isp_2322); 130#endif 131 return (0); |
132} 133
|
98static void
99isp_get_firmware(int version, int tgtmode, int devid, const u_int16_t **ptrp)
|
134static int 135do_unload_fw(void) |
136{
|
101 const u_int16_t *rp = NULL;
102
103 if (version == ISPFW_VERSION) {
104 switch (devid) {
105 case PCI_PRODUCT_QLOGIC_ISP1020:
106 if (tgtmode)
107 rp = isp_1040_risc_code_it;
108 else
109 rp = isp_1040_risc_code;
110 break;
111 case PCI_PRODUCT_QLOGIC_ISP1080:
112 case PCI_PRODUCT_QLOGIC_ISP1240:
113 case PCI_PRODUCT_QLOGIC_ISP1280:
114 if (tgtmode)
115 rp = isp_1080_risc_code_it;
116 else
117 rp = isp_1080_risc_code;
118 break;
119 case PCI_PRODUCT_QLOGIC_ISP10160:
120 case PCI_PRODUCT_QLOGIC_ISP12160:
121 if (tgtmode)
122 rp = isp_12160_risc_code_it;
123 else
124 rp = isp_12160_risc_code;
125 break;
126 case PCI_PRODUCT_QLOGIC_ISP2100:
127 rp = isp_2100_risc_code;
128 break;
129 case PCI_PRODUCT_QLOGIC_ISP2200:
130 rp = isp_2200_risc_code;
131 break;
132 case PCI_PRODUCT_QLOGIC_ISP2300:
133 case PCI_PRODUCT_QLOGIC_ISP2312:
134 case PCI_PRODUCT_QLOGIC_ISP6312:
135 rp = isp_2300_risc_code;
136 break;
137 case PCI_PRODUCT_QLOGIC_ISP2322:
138 rp = isp_2322_risc_code;
139 break;
140#ifdef __sparc64__
141 case SBUS_PRODUCT_QLOGIC_ISP1000:
142 if (tgtmode)
143 break;
144 rp = isp_1000_risc_code;
145 break;
|
137#if defined(ISP_1000) 138 UMACRO(isp_1000); 139#elif defined(ISP_1040) 140 UMACRO(isp_1040); 141#elif defined(ISP_1040_IT) 142 UMACRO(isp_1040_it); 143#elif defined(ISP_1080) 144 UMACRO(isp_1080); 145#elif defined(ISP_1080_IT) 146 UMACRO(isp_1080_it); 147#elif defined(ISP_12160) 148 UMACRO(isp_12160); 149#elif defined(ISP_12160_IT) 150 UMACRO(isp_12160_it); 151#elif defined(ISP_2100) 152 UMACRO(isp_2100); 153#elif defined(ISP_2200) 154 UMACRO(isp_2200); 155#elif defined(ISP_2300) 156 UMACRO(isp_2300); 157#elif defined(ISP_2322) 158 UMACRO(isp_2322); |
159#endif
|
147 default:
148 break;
149 }
150 }
151 if (rp && addcaller(ptrp)) {
152 *ptrp = rp;
153 }
|
160 return (0); |
161} 162 163static int
|
157isp_module_handler(module_t mod, int what, void *arg)
|
164module_handler(module_t mod, int what, void *arg) |
165{
|
166 int r; |
167 switch (what) { 168 case MOD_LOAD:
|
161 isp_get_firmware_p = isp_get_firmware;
|
169 r = do_load_fw(); |
170 break; 171 case MOD_UNLOAD:
|
164 isp_get_firmware_p = NULL;
165 if (ncallers) {
166 int i;
167 for (i = 0; i < ncallers; i++) {
168 *callp[i] = NULL;
169 }
170 free(callp, M_DEVBUF);
171 }
|
172 r = do_unload_fw(); |
173 break; 174 default:
|
174 return (EOPNOTSUPP);
|
175 r = EOPNOTSUPP; |
176 break; 177 }
|
177 return (0);
|
178 return (r); |
179} 180static moduledata_t ispfw_mod = {
|
180 "ispfw", isp_module_handler, NULL
|
181 MODULE_NAME, module_handler, NULL |
182};
|
182DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
183MODULE_VERSION(ispfw, ISPFW_VERSION);
184MODULE_DEPEND(ispfw, isp, 1, 1, 1);
|
183#ifndef KLD_MODULE 184DECLARE_MODULE(isp, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 185#else 186#if defined(ISP_1000) 187DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 188#elif defined(ISP_1040) 189DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 190#elif defined(ISP_1040_IT) 191DECLARE_MODULE(isp_1040_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 192#elif defined(ISP_1080) 193DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 194#elif defined(ISP_1080_IT) 195DECLARE_MODULE(isp_1080_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 196#elif defined(ISP_12160) 197DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 198#elif defined(ISP_12160_IT) 199DECLARE_MODULE(isp_12160_IT, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 200#elif defined(ISP_2100) 201DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 202#elif defined(ISP_2200) 203DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 204#elif defined(ISP_2300) 205DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 206#elif defined(ISP_2322) 207DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 208#endif 209#endif |
|