3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
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>
43 #include <sys/sysctl.h>
46 #include <net/if_arp.h>
47 #include <net/if_media.h>
49 #include <machine/bus.h>
50 #include <machine/resource.h>
54 #include <net80211/ieee80211_var.h>
56 #include <compat/ndis/pe_var.h>
57 #include <compat/ndis/cfg_var.h>
58 #include <compat/ndis/resource_var.h>
59 #include <compat/ndis/ntoskrnl_var.h>
60 #include <compat/ndis/ndis_var.h>
61 #include <dev/if_ndis/if_ndisvar.h>
63 #include <dev/pccard/pccardvar.h>
66 MODULE_DEPEND(ndis, pccard, 1, 1, 1);
68 static int ndis_probe_pccard (device_t);
69 static int ndis_attach_pccard (device_t);
70 static struct resource_list *ndis_get_resource_list
72 static int ndis_devcompare (struct ndis_pccard_type *, device_t);
73 extern int ndisdrv_modevent (module_t, int, void *);
74 extern int ndis_attach (device_t);
75 extern int ndis_shutdown (device_t);
76 extern int ndis_detach (device_t);
77 extern int ndis_suspend (device_t);
78 extern int ndis_resume (device_t);
80 extern unsigned char drv_data[];
82 static device_method_t ndis_methods[] = {
83 /* Device interface */
84 DEVMETHOD(device_probe, ndis_probe_pccard),
85 DEVMETHOD(device_attach, ndis_attach_pccard),
86 DEVMETHOD(device_detach, ndis_detach),
87 DEVMETHOD(device_shutdown, ndis_shutdown),
88 DEVMETHOD(device_suspend, ndis_suspend),
89 DEVMETHOD(device_resume, ndis_resume),
94 * This is an awful kludge, but we need it becase pccard
95 * does not implement a bus_get_resource_list() method.
98 DEVMETHOD(bus_get_resource_list, ndis_get_resource_list),
103 static driver_t ndis_driver = {
106 sizeof(struct ndis_softc)
109 static devclass_t ndis_devclass;
111 DRIVER_MODULE(ndis, pccard, ndis_driver, ndis_devclass, ndisdrv_modevent, 0);
114 ndis_devcompare(t, dev)
115 struct ndis_pccard_type *t;
118 const char *prodstr, *vendstr;
121 error = pccard_get_product_str(dev, &prodstr);
124 error = pccard_get_vendor_str(dev, &vendstr);
128 while(t->ndis_name != NULL) {
129 if (ndis_strcasecmp(vendstr, t->ndis_vid) == 0 &&
130 ndis_strcasecmp(prodstr, t->ndis_did) == 0) {
131 device_set_desc(dev, t->ndis_name);
141 * Probe for an NDIS device. Check the PCI vendor and device
142 * IDs against our list and return a device name if we find a match.
145 ndis_probe_pccard(dev)
149 struct drvdb_ent *db;
151 drv = windrv_lookup(0, "PCCARD Bus");
155 db = windrv_match((matchfuncptr)ndis_devcompare, dev);
158 /* Create PDO for this device instance */
159 windrv_create_pdo(drv, dev);
167 * Attach the interface. Allocate softc structures, do ifmedia
168 * setup and ethernet/BPF attach.
171 ndis_attach_pccard(dev)
174 struct ndis_softc *sc;
175 int unit, error = 0, rid;
176 struct ndis_pccard_type *t;
178 const char *prodstr, *vendstr;
179 struct drvdb_ent *db;
181 sc = device_get_softc(dev);
182 unit = device_get_unit(dev);
185 db = windrv_match((matchfuncptr)ndis_devcompare, dev);
189 resource_list_init(&sc->ndis_rl);
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) {
197 "couldn't map iospace\n");
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));
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) {
212 "couldn't map interrupt\n");
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 sc->ndis_iftype = PCMCIABus;
222 /* Figure out exactly which device we matched. */
224 t = db->windrv_devlist;
226 error = pccard_get_product_str(dev, &prodstr);
229 error = pccard_get_vendor_str(dev, &vendstr);
233 while(t->ndis_name != NULL) {
234 if (ndis_strcasecmp(vendstr, t->ndis_vid) == 0 &&
235 ndis_strcasecmp(prodstr, t->ndis_did) == 0)
241 sc->ndis_devidx = devidx;
243 error = ndis_attach(dev);
249 static struct resource_list *
250 ndis_get_resource_list(dev, child)
254 struct ndis_softc *sc;
256 sc = device_get_softc(dev);
257 return (&sc->ndis_rl);
260 #define NDIS_AM_RID 3
266 struct ndis_softc *sc;
274 sc->ndis_res_am = bus_alloc_resource(sc->ndis_dev, SYS_RES_MEMORY,
275 &rid, 0UL, ~0UL, 0x1000, RF_ACTIVE);
277 if (sc->ndis_res_am == NULL) {
278 device_printf(sc->ndis_dev,
279 "failed to allocate attribute memory\n");
283 resource_list_add(&sc->ndis_rl, SYS_RES_MEMORY, rid,
284 rman_get_start(sc->ndis_res_am), rman_get_end(sc->ndis_res_am),
285 rman_get_size(sc->ndis_res_am));
287 error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->ndis_dev),
288 sc->ndis_dev, rid, 0, NULL);
291 device_printf(sc->ndis_dev,
292 "CARD_SET_MEMORY_OFFSET() returned 0x%x\n", error);
296 error = CARD_SET_RES_FLAGS(device_get_parent(sc->ndis_dev),
297 sc->ndis_dev, SYS_RES_MEMORY, rid, PCCARD_A_MEM_ATTR);
300 device_printf(sc->ndis_dev,
301 "CARD_SET_RES_FLAGS() returned 0x%x\n", error);
305 sc->ndis_am_rid = rid;
314 struct ndis_softc *sc;
321 if (sc->ndis_res_am != NULL)
322 bus_release_resource(sc->ndis_dev, SYS_RES_MEMORY,
323 sc->ndis_am_rid, sc->ndis_res_am);
324 resource_list_free(&sc->ndis_rl);