2 * Copyright (c) 2002-2007 Sam Leffler, Errno Consulting
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 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
34 * PCI/Cardbus front-end for the Broadcom Wireless LAN controller driver.
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/module.h>
42 #include <sys/kernel.h>
44 #include <sys/mutex.h>
45 #include <sys/errno.h>
47 #include <machine/bus.h>
48 #include <machine/resource.h>
52 #include <sys/socket.h>
55 #include <net/if_media.h>
56 #include <net/if_arp.h>
58 #include <net80211/ieee80211_var.h>
59 #include <net80211/ieee80211_radiotap.h>
60 #include <net80211/ieee80211_amrr.h>
62 #include <dev/pci/pcivar.h>
63 #include <dev/pci/pcireg.h>
65 #include <dev/bwi/if_bwivar.h>
66 #include <dev/bwi/if_bwireg.h>
67 #include <dev/bwi/bitops.h>
73 struct bwi_pci_softc {
74 struct bwi_softc sc_sc;
78 #define PCIR_RETRY_TIMEOUT 0x41
80 static const struct bwi_dev {
85 { PCI_VENDOR_BROADCOM, 0x4301,"Broadcom BCM4301 802.11b Wireless Lan" },
86 { PCI_VENDOR_BROADCOM, 0x4307,"Broadcom BCM4307 802.11b Wireless Lan" },
87 { PCI_VENDOR_BROADCOM, 0x4311,"Broadcom BCM4311 802.11b/g Wireless Lan" },
88 { PCI_VENDOR_BROADCOM, 0x4312,"Broadcom BCM4312 802.11a/b/g Wireless Lan" },
89 { PCI_VENDOR_BROADCOM, 0x4313,"Broadcom BCM4312 802.11a Wireless Lan" },
90 { PCI_VENDOR_BROADCOM, 0x4320,"Broadcom BCM4306 802.11b/g Wireless Lan"},
91 { PCI_VENDOR_BROADCOM, 0x4321,"Broadcom BCM4306 802.11a Wireless Lan"},
92 { PCI_VENDOR_BROADCOM, 0x4325,"Broadcom BCM4306 802.11b/g Wireless Lan"},
93 { PCI_VENDOR_BROADCOM, 0x4324,"Broadcom BCM4309 802.11a/b/g Wireless Lan" },
94 { PCI_VENDOR_BROADCOM, 0x4318,"Broadcom BCM4318 802.11b/g Wireless Lan" },
95 { PCI_VENDOR_BROADCOM, 0x4319,"Broadcom BCM4318 802.11a/b/g Wireless Lan" },
96 { PCI_VENDOR_BROADCOM, 0x431a,"Broadcom BCM4318 802.11a Wireless Lan" },
101 bwi_pci_probe(device_t dev)
103 const struct bwi_dev *b;
106 did = pci_get_device(dev);
107 vid = pci_get_vendor(dev);
109 for (b = bwi_devices; b->desc != NULL; ++b) {
110 if (b->did == did && b->vid == vid) {
111 device_set_desc(dev, b->desc);
112 return BUS_PROBE_DEFAULT;
119 bwi_pci_attach(device_t dev)
121 struct bwi_pci_softc *psc = device_get_softc(dev);
122 struct bwi_softc *sc = &psc->sc_sc;
128 * Enable bus mastering.
130 pci_enable_busmaster(dev);
133 * Setup memory-mapping of PCI registers.
135 sc->sc_mem_rid = BWI_PCIR_BAR;
136 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
137 &sc->sc_mem_rid, RF_ACTIVE);
138 if (sc->sc_mem_res == NULL) {
139 device_printf(dev, "cannot map register space\n");
142 sc->sc_mem_bt = rman_get_bustag(sc->sc_mem_res);
143 sc->sc_mem_bh = rman_get_bushandle(sc->sc_mem_res);
145 * Mark device invalid so any interrupts (shared or otherwise)
146 * that arrive before the card is setup are discarded.
151 * Arrange interrupt line.
154 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
156 RF_SHAREABLE|RF_ACTIVE);
157 if (sc->sc_irq_res == NULL) {
158 device_printf(dev, "could not map interrupt\n");
161 if (bus_setup_intr(dev, sc->sc_irq_res,
162 INTR_TYPE_NET | INTR_MPSAFE,
163 NULL, bwi_intr, sc, &sc->sc_irq_handle)) {
164 device_printf(dev, "could not establish interrupt\n");
168 /* Get more PCI information */
169 sc->sc_pci_did = pci_get_device(dev);
170 sc->sc_pci_revid = pci_get_revid(dev);
171 sc->sc_pci_subvid = pci_get_subvendor(dev);
172 sc->sc_pci_subdid = pci_get_subdevice(dev);
174 error = bwi_attach(sc);
175 if (error == 0) /* success */
178 bus_teardown_intr(dev, sc->sc_irq_res, sc->sc_irq_handle);
180 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res);
182 bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, sc->sc_mem_res);
188 bwi_pci_detach(device_t dev)
190 struct bwi_pci_softc *psc = device_get_softc(dev);
191 struct bwi_softc *sc = &psc->sc_sc;
193 /* check if device was removed */
194 sc->sc_invalid = !bus_child_present(dev);
198 bus_generic_detach(dev);
199 bus_teardown_intr(dev, sc->sc_irq_res, sc->sc_irq_handle);
200 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res);
202 bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, sc->sc_mem_res);
208 bwi_pci_shutdown(device_t dev)
210 struct bwi_pci_softc *psc = device_get_softc(dev);
212 bwi_shutdown(&psc->sc_sc);
217 bwi_pci_suspend(device_t dev)
219 struct bwi_pci_softc *psc = device_get_softc(dev);
221 bwi_suspend(&psc->sc_sc);
227 bwi_pci_resume(device_t dev)
229 struct bwi_pci_softc *psc = device_get_softc(dev);
231 bwi_resume(&psc->sc_sc);
236 static device_method_t bwi_pci_methods[] = {
237 /* Device interface */
238 DEVMETHOD(device_probe, bwi_pci_probe),
239 DEVMETHOD(device_attach, bwi_pci_attach),
240 DEVMETHOD(device_detach, bwi_pci_detach),
241 DEVMETHOD(device_shutdown, bwi_pci_shutdown),
242 DEVMETHOD(device_suspend, bwi_pci_suspend),
243 DEVMETHOD(device_resume, bwi_pci_resume),
247 static driver_t bwi_driver = {
250 sizeof (struct bwi_pci_softc)
252 static devclass_t bwi_devclass;
253 DRIVER_MODULE(bwi, pci, bwi_driver, bwi_devclass, 0, 0);
254 MODULE_DEPEND(bwi, wlan, 1, 1, 1); /* 802.11 media layer */
255 MODULE_DEPEND(bwi, firmware, 1, 1, 1); /* firmware support */
256 MODULE_DEPEND(bwi, wlan_amrr, 1, 1, 1);