if_ndis_pccard.c (129972) | if_ndis_pccard.c (131953) |
---|---|
1/* 2 * Copyright (c) 2003 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 2003 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/dev/if_ndis/if_ndis_pccard.c 129972 2004-06-01 23:27:36Z wpaul $"); | 34__FBSDID("$FreeBSD: head/sys/dev/if_ndis/if_ndis_pccard.c 131953 2004-07-11 00:19:30Z wpaul $"); |
35 36#include <sys/ctype.h> 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/kernel.h> 40#include <sys/module.h> 41#include <sys/socket.h> 42#include <sys/queue.h> --- 37 unchanged lines hidden (view full) --- 80#ifdef NDIS_PCMCIA_DEV_TABLE 81 NDIS_PCMCIA_DEV_TABLE 82#endif 83 { NULL, NULL, NULL } 84}; 85 86static int ndis_probe_pccard (device_t); 87static int ndis_attach_pccard (device_t); | 35 36#include <sys/ctype.h> 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/kernel.h> 40#include <sys/module.h> 41#include <sys/socket.h> 42#include <sys/queue.h> --- 37 unchanged lines hidden (view full) --- 80#ifdef NDIS_PCMCIA_DEV_TABLE 81 NDIS_PCMCIA_DEV_TABLE 82#endif 83 { NULL, NULL, NULL } 84}; 85 86static int ndis_probe_pccard (device_t); 87static int ndis_attach_pccard (device_t); |
88static struct resource_list *ndis_get_resource_list 89 (device_t, device_t); |
|
88extern int ndis_attach (device_t); 89extern int ndis_shutdown (device_t); 90extern int ndis_detach (device_t); 91extern int ndis_suspend (device_t); 92extern int ndis_resume (device_t); 93 | 90extern int ndis_attach (device_t); 91extern int ndis_shutdown (device_t); 92extern int ndis_detach (device_t); 93extern int ndis_suspend (device_t); 94extern int ndis_resume (device_t); 95 |
94static int my_strcasecmp (const char *, const char *, int); 95 | |
96extern struct mtx_pool *ndis_mtxpool; 97 98static device_method_t ndis_methods[] = { 99 /* Device interface */ 100 DEVMETHOD(device_probe, ndis_probe_pccard), 101 DEVMETHOD(device_attach, ndis_attach_pccard), 102 DEVMETHOD(device_detach, ndis_detach), 103 DEVMETHOD(device_shutdown, ndis_shutdown), 104 DEVMETHOD(device_suspend, ndis_suspend), 105 DEVMETHOD(device_resume, ndis_resume), 106 | 96extern struct mtx_pool *ndis_mtxpool; 97 98static device_method_t ndis_methods[] = { 99 /* Device interface */ 100 DEVMETHOD(device_probe, ndis_probe_pccard), 101 DEVMETHOD(device_attach, ndis_attach_pccard), 102 DEVMETHOD(device_detach, ndis_detach), 103 DEVMETHOD(device_shutdown, ndis_shutdown), 104 DEVMETHOD(device_suspend, ndis_suspend), 105 DEVMETHOD(device_resume, ndis_resume), 106 |
107 /* Bus interface. */ 108 109 /* 110 * This is an awful kludge, but we need it becase pccard 111 * does not implement a bus_get_resource_list() method. 112 */ 113 114 DEVMETHOD(bus_get_resource_list, ndis_get_resource_list), 115 |
|
107 { 0, 0 } 108}; 109 110static driver_t ndis_driver = { 111#ifdef NDIS_DEVNAME 112 NDIS_DEVNAME, 113#else 114 "ndis", --- 7 unchanged lines hidden (view full) --- 122#ifdef NDIS_MODNAME 123#define NDIS_MODNAME_OVERRIDE_PCMCIA(x) \ 124 DRIVER_MODULE(x, pccard, ndis_driver, ndis_devclass, 0, 0) 125NDIS_MODNAME_OVERRIDE_PCMCIA(NDIS_MODNAME); 126#else 127DRIVER_MODULE(ndis, pccard, ndis_driver, ndis_devclass, 0, 0); 128#endif 129 | 116 { 0, 0 } 117}; 118 119static driver_t ndis_driver = { 120#ifdef NDIS_DEVNAME 121 NDIS_DEVNAME, 122#else 123 "ndis", --- 7 unchanged lines hidden (view full) --- 131#ifdef NDIS_MODNAME 132#define NDIS_MODNAME_OVERRIDE_PCMCIA(x) \ 133 DRIVER_MODULE(x, pccard, ndis_driver, ndis_devclass, 0, 0) 134NDIS_MODNAME_OVERRIDE_PCMCIA(NDIS_MODNAME); 135#else 136DRIVER_MODULE(ndis, pccard, ndis_driver, ndis_devclass, 0, 0); 137#endif 138 |
130static int my_strcasecmp(s1, s2, len) 131 const char *s1; 132 const char *s2; 133 int len; 134{ 135 int i; 136 137 for (i = 0; i < len; i++) { 138 if (toupper(s1[i]) != toupper(s2[i])) 139 return(0); 140 } 141 142 return(1); 143} 144 145 | |
146/* 147 * Probe for an NDIS device. Check the PCI vendor and device 148 * IDs against our list and return a device name if we find a match. 149 */ 150static int 151ndis_probe_pccard(dev) 152 device_t dev; 153{ --- 6 unchanged lines hidden (view full) --- 160 error = pccard_get_product_str(dev, &prodstr); 161 if (error) 162 return(error); 163 error = pccard_get_vendor_str(dev, &vendstr); 164 if (error) 165 return(error); 166 167 while(t->ndis_name != NULL) { | 139/* 140 * Probe for an NDIS device. Check the PCI vendor and device 141 * IDs against our list and return a device name if we find a match. 142 */ 143static int 144ndis_probe_pccard(dev) 145 device_t dev; 146{ --- 6 unchanged lines hidden (view full) --- 153 error = pccard_get_product_str(dev, &prodstr); 154 if (error) 155 return(error); 156 error = pccard_get_vendor_str(dev, &vendstr); 157 if (error) 158 return(error); 159 160 while(t->ndis_name != NULL) { |
168 if (my_strcasecmp(vendstr, t->ndis_vid, strlen(vendstr)) && 169 my_strcasecmp(prodstr, t->ndis_did, strlen(prodstr))) { | 161 if (ndis_strcasecmp(vendstr, t->ndis_vid) == 0 && 162 ndis_strcasecmp(prodstr, t->ndis_did) == 0) { |
170 device_set_desc(dev, t->ndis_name); 171 return(0); 172 } 173 t++; 174 } 175 176 return(ENXIO); 177} --- 10 unchanged lines hidden (view full) --- 188 int unit, error = 0, rid; 189 struct ndis_pccard_type *t; 190 int devidx = 0; 191 const char *prodstr, *vendstr; 192 193 sc = device_get_softc(dev); 194 unit = device_get_unit(dev); 195 sc->ndis_dev = dev; | 163 device_set_desc(dev, t->ndis_name); 164 return(0); 165 } 166 t++; 167 } 168 169 return(ENXIO); 170} --- 10 unchanged lines hidden (view full) --- 181 int unit, error = 0, rid; 182 struct ndis_pccard_type *t; 183 int devidx = 0; 184 const char *prodstr, *vendstr; 185 186 sc = device_get_softc(dev); 187 unit = device_get_unit(dev); 188 sc->ndis_dev = dev; |
189 resource_list_init(&sc->ndis_rl); |
|
196 197 sc->ndis_io_rid = 0; 198 sc->ndis_res_io = bus_alloc_resource(dev, 199 SYS_RES_IOPORT, &sc->ndis_io_rid, 200 0, ~0, 1, RF_ACTIVE); 201 if (sc->ndis_res_io == NULL) { 202 device_printf(dev, 203 "couldn't map iospace\n"); 204 error = ENXIO; 205 goto fail; 206 } 207 sc->ndis_rescnt++; | 190 191 sc->ndis_io_rid = 0; 192 sc->ndis_res_io = bus_alloc_resource(dev, 193 SYS_RES_IOPORT, &sc->ndis_io_rid, 194 0, ~0, 1, RF_ACTIVE); 195 if (sc->ndis_res_io == NULL) { 196 device_printf(dev, 197 "couldn't map iospace\n"); 198 error = ENXIO; 199 goto fail; 200 } 201 sc->ndis_rescnt++; |
202 resource_list_add(&sc->ndis_rl, SYS_RES_IOPORT, rid, 203 rman_get_start(sc->ndis_res_io), rman_get_end(sc->ndis_res_io), 204 rman_get_size(sc->ndis_res_io)); |
|
208 209 rid = 0; 210 sc->ndis_irq = bus_alloc_resource(dev, 211 SYS_RES_IRQ, &rid, 0, ~0, 1, 212 RF_SHAREABLE | RF_ACTIVE); 213 if (sc->ndis_irq == NULL) { 214 device_printf(dev, 215 "couldn't map interrupt\n"); 216 error = ENXIO; 217 goto fail; 218 } 219 sc->ndis_rescnt++; | 205 206 rid = 0; 207 sc->ndis_irq = bus_alloc_resource(dev, 208 SYS_RES_IRQ, &rid, 0, ~0, 1, 209 RF_SHAREABLE | RF_ACTIVE); 210 if (sc->ndis_irq == NULL) { 211 device_printf(dev, 212 "couldn't map interrupt\n"); 213 error = ENXIO; 214 goto fail; 215 } 216 sc->ndis_rescnt++; |
217 resource_list_add(&sc->ndis_rl, SYS_RES_IRQ, rid, 218 rman_get_start(sc->ndis_irq), rman_get_start(sc->ndis_irq), 1); |
|
220 221 sc->ndis_iftype = PCMCIABus; 222 223 /* Figure out exactly which device we matched. */ 224 225 t = ndis_devs; 226 227 error = pccard_get_product_str(dev, &prodstr); 228 if (error) 229 return(error); 230 error = pccard_get_vendor_str(dev, &vendstr); 231 if (error) 232 return(error); 233 234 while(t->ndis_name != NULL) { | 219 220 sc->ndis_iftype = PCMCIABus; 221 222 /* Figure out exactly which device we matched. */ 223 224 t = ndis_devs; 225 226 error = pccard_get_product_str(dev, &prodstr); 227 if (error) 228 return(error); 229 error = pccard_get_vendor_str(dev, &vendstr); 230 if (error) 231 return(error); 232 233 while(t->ndis_name != NULL) { |
235 if (my_strcasecmp(vendstr, t->ndis_vid, strlen(vendstr)) && 236 my_strcasecmp(prodstr, t->ndis_did, strlen(prodstr))) | 234 if (ndis_strcasecmp(vendstr, t->ndis_vid) == 0 && 235 ndis_strcasecmp(prodstr, t->ndis_did) == 0) |
237 break; 238 t++; 239 devidx++; 240 } 241 242 sc->ndis_devidx = devidx; 243 244 error = ndis_attach(dev); 245 246fail: 247 return(error); 248} 249 | 236 break; 237 t++; 238 devidx++; 239 } 240 241 sc->ndis_devidx = devidx; 242 243 error = ndis_attach(dev); 244 245fail: 246 return(error); 247} 248 |
249static struct resource_list * 250ndis_get_resource_list(dev, child) 251 device_t dev; 252 device_t child; 253{ 254 struct ndis_softc *sc; 255 256 sc = device_get_softc(dev); 257 return (&sc->ndis_rl); 258} 259 |
|
250#endif /* NDIS_PCI_DEV_TABLE */ 251 252#define NDIS_AM_RID 3 253 254int 255ndis_alloc_amem(arg) 256 void *arg; 257{ --- 8 unchanged lines hidden (view full) --- 266 sc->ndis_res_am = bus_alloc_resource(sc->ndis_dev, SYS_RES_MEMORY, 267 &rid, 0UL, ~0UL, 0x1000, RF_ACTIVE); 268 269 if (sc->ndis_res_am == NULL) { 270 device_printf(sc->ndis_dev, 271 "failed to allocate attribute memory\n"); 272 return(ENXIO); 273 } | 260#endif /* NDIS_PCI_DEV_TABLE */ 261 262#define NDIS_AM_RID 3 263 264int 265ndis_alloc_amem(arg) 266 void *arg; 267{ --- 8 unchanged lines hidden (view full) --- 276 sc->ndis_res_am = bus_alloc_resource(sc->ndis_dev, SYS_RES_MEMORY, 277 &rid, 0UL, ~0UL, 0x1000, RF_ACTIVE); 278 279 if (sc->ndis_res_am == NULL) { 280 device_printf(sc->ndis_dev, 281 "failed to allocate attribute memory\n"); 282 return(ENXIO); 283 } |
284 sc->ndis_rescnt++; 285 resource_list_add(&sc->ndis_rl, SYS_RES_MEMORY, rid, 286 rman_get_start(sc->ndis_res_am), rman_get_end(sc->ndis_res_am), 287 rman_get_size(sc->ndis_res_am)); |
|
274 275 error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->ndis_dev), 276 sc->ndis_dev, rid, 0, NULL); 277 278 if (error) { 279 device_printf(sc->ndis_dev, 280 "CARD_SET_MEMORY_OFFSET() returned 0x%x\n", error); 281 return(error); 282 } 283 284 error = CARD_SET_RES_FLAGS(device_get_parent(sc->ndis_dev), 285 sc->ndis_dev, SYS_RES_MEMORY, rid, PCCARD_A_MEM_ATTR); 286 287 if (error) { 288 device_printf(sc->ndis_dev, 289 "CARD_SET_RES_FLAGS() returned 0x%x\n", error); 290 return(error); 291 } 292 | 288 289 error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->ndis_dev), 290 sc->ndis_dev, rid, 0, NULL); 291 292 if (error) { 293 device_printf(sc->ndis_dev, 294 "CARD_SET_MEMORY_OFFSET() returned 0x%x\n", error); 295 return(error); 296 } 297 298 error = CARD_SET_RES_FLAGS(device_get_parent(sc->ndis_dev), 299 sc->ndis_dev, SYS_RES_MEMORY, rid, PCCARD_A_MEM_ATTR); 300 301 if (error) { 302 device_printf(sc->ndis_dev, 303 "CARD_SET_RES_FLAGS() returned 0x%x\n", error); 304 return(error); 305 } 306 |
307 sc->ndis_am_rid = rid; 308 |
|
293 return(0); 294} | 309 return(0); 310} |
311 312void 313ndis_free_amem(arg) 314 void *arg; 315{ 316 struct ndis_softc *sc; 317 318 if (arg == NULL) 319 return; 320 321 sc = arg; 322 323 if (sc->ndis_res_am != NULL) 324 bus_release_resource(sc->ndis_dev, SYS_RES_MEMORY, 325 sc->ndis_am_rid, sc->ndis_res_am); 326 resource_list_free(&sc->ndis_rl); 327 328 return; 329} |
|