2 * Copyright (c) 2002-2005 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.
15 * 3. Neither the names of the above-listed copyright holders nor the names
16 * of any contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * Alternatively, this software may be distributed under the terms of the
20 * GNU General Public License ("GPL") version 2 as published by the Free
21 * Software Foundation.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
29 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34 * THE POSSIBILITY OF SUCH DAMAGES.
36 * $FreeBSD: src/sys/dev/ath/if_ath_pci.c,v 1.12 2005/03/05 19:06:12 imp Exp $
37 * $DragonFly: src/sys/dev/netif/ath/ath/if_ath_pci.c,v 1.1 2006/07/13 09:15:22 sephe Exp $
41 * PCI/Cardbus front-end for the Atheros Wireless LAN controller driver.
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/module.h>
47 #include <sys/kernel.h>
48 #include <sys/errno.h>
49 #include <sys/sysctl.h>
51 #include <machine/bus.h>
52 #include <machine/resource.h>
56 #include <sys/socket.h>
59 #include <net/if_media.h>
60 #include <net/if_arp.h>
62 #include <netproto/802_11/ieee80211_var.h>
64 #include <bus/pci/pcivar.h>
65 #include <bus/pci/pcireg.h>
67 #include <dev/netif/ath/ath/if_athvar.h>
68 #include <contrib/dev/ath/ah.h>
70 static int ath_pci_probe(device_t);
71 static int ath_pci_attach(device_t);
72 static int ath_pci_detach(device_t);
73 static int ath_pci_shutdown(device_t);
74 static int ath_pci_suspend(device_t);
75 static int ath_pci_resume(device_t);
77 static void ath_pci_setup(device_t);
83 struct ath_pci_softc {
84 struct ath_softc sc_sc;
85 struct resource *sc_sr; /* memory resource */
90 #define PCIR_RETRY_TIMEOUT 0x41
93 ath_pci_probe(device_t dev)
97 devname = ath_hal_probe(pci_get_vendor(dev), pci_get_device(dev));
98 if (devname != NULL) {
99 device_set_desc(dev, devname);
106 ath_pci_setup(device_t dev)
109 * Enable memory mapping and bus mastering.
111 pci_enable_busmaster(dev);
114 * Disable retry timeout to keep PCI Tx retries from
115 * interfering with C3 CPU state.
117 pci_write_config(dev, PCIR_RETRY_TIMEOUT, 0, 1);
121 ath_pci_attach(device_t dev)
123 struct ath_pci_softc *psc = device_get_softc(dev);
124 struct ath_softc *sc = &psc->sc_sc;
132 * Setup memory-mapping of PCI registers.
134 psc->sc_srid = BS_BAR;
135 psc->sc_sr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &psc->sc_srid,
137 if (psc->sc_sr == NULL) {
138 device_printf(dev, "cannot map register space\n");
141 sc->sc_st = rman_get_bustag(psc->sc_sr);
142 sc->sc_sh = rman_get_bushandle(psc->sc_sr);
145 * Setup DMA descriptor area.
147 error = bus_dma_tag_create(NULL, 1, 0,
148 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
149 NULL, NULL, 0x3ffff/* maxsize XXX */,
150 ATH_MAX_SCATTER, BUS_SPACE_MAXADDR,
151 BUS_DMA_ALLOCNOW, &sc->sc_dmat);
153 device_printf(dev, "cannot allocate DMA tag\n");
157 error = ath_attach(pci_get_device(dev), sc);
166 ath_pci_detach(device_t dev)
168 struct ath_pci_softc *psc = device_get_softc(dev);
169 struct ath_softc *sc = &psc->sc_sc;
171 /* XXX check if device was removed */
172 sc->sc_invalid = !bus_child_present(dev);
174 if (device_is_attached(dev))
177 bus_generic_detach(dev);
179 if (sc->sc_dmat != NULL)
180 bus_dma_tag_destroy(sc->sc_dmat);
182 if (psc->sc_sr != NULL) {
183 bus_release_resource(dev, SYS_RES_MEMORY, psc->sc_srid,
190 ath_pci_shutdown(device_t dev)
192 struct ath_pci_softc *psc = device_get_softc(dev);
194 ath_shutdown(&psc->sc_sc);
199 ath_pci_suspend(device_t dev)
201 struct ath_pci_softc *psc = device_get_softc(dev);
203 ath_suspend(&psc->sc_sc);
208 ath_pci_resume(device_t dev)
210 struct ath_pci_softc *psc = device_get_softc(dev);
213 ath_resume(&psc->sc_sc);
217 static device_method_t ath_pci_methods[] = {
218 /* Device interface */
219 DEVMETHOD(device_probe, ath_pci_probe),
220 DEVMETHOD(device_attach, ath_pci_attach),
221 DEVMETHOD(device_detach, ath_pci_detach),
222 DEVMETHOD(device_shutdown, ath_pci_shutdown),
223 DEVMETHOD(device_suspend, ath_pci_suspend),
224 DEVMETHOD(device_resume, ath_pci_resume),
229 static driver_t ath_pci_driver = {
232 sizeof (struct ath_pci_softc)
235 static devclass_t ath_devclass;
237 DRIVER_MODULE(if_ath, pci, ath_pci_driver, ath_devclass, 0, 0);
238 DRIVER_MODULE(if_ath, cardbus, ath_pci_driver, ath_devclass, 0, 0);
240 MODULE_VERSION(if_ath, 1);
242 MODULE_DEPEND(if_ath, ath_hal, 1, 1, 1); /* Atheros HAL */
243 MODULE_DEPEND(if_ath, ath_rate, 1, 1, 1); /* rate control algorithm */
244 MODULE_DEPEND(if_ath, wlan, 1, 1, 1); /* 802.11 media layer */