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.4 2007/02/22 05:17:09 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>
53 #include <sys/socket.h>
56 #include <net/if_media.h>
57 #include <net/if_arp.h>
59 #include <netproto/802_11/ieee80211_var.h>
61 #include <bus/pci/pcivar.h>
62 #include <bus/pci/pcireg.h>
64 #include <dev/netif/ath/ath/if_athvar.h>
65 #include <contrib/dev/ath/ah.h>
67 static int ath_pci_probe(device_t);
68 static int ath_pci_attach(device_t);
69 static int ath_pci_detach(device_t);
70 static int ath_pci_shutdown(device_t);
71 static int ath_pci_suspend(device_t);
72 static int ath_pci_resume(device_t);
74 static void ath_pci_setup(device_t);
80 struct ath_pci_softc {
81 struct ath_softc sc_sc;
82 struct resource *sc_sr; /* memory resource */
87 #define PCIR_RETRY_TIMEOUT 0x41
90 ath_pci_probe(device_t dev)
94 devname = ath_hal_probe(pci_get_vendor(dev), pci_get_device(dev));
95 if (devname != NULL) {
96 device_set_desc(dev, devname);
103 ath_pci_setup(device_t dev)
106 * Enable memory mapping and bus mastering.
108 pci_enable_busmaster(dev);
111 * Disable retry timeout to keep PCI Tx retries from
112 * interfering with C3 CPU state.
114 pci_write_config(dev, PCIR_RETRY_TIMEOUT, 0, 1);
118 ath_pci_attach(device_t dev)
120 struct ath_pci_softc *psc = device_get_softc(dev);
121 struct ath_softc *sc = &psc->sc_sc;
129 * Setup memory-mapping of PCI registers.
131 psc->sc_srid = BS_BAR;
132 psc->sc_sr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &psc->sc_srid,
134 if (psc->sc_sr == NULL) {
135 device_printf(dev, "cannot map register space\n");
138 /* NB: these casts are known to be safe */
139 sc->sc_st = (HAL_BUS_TAG)rman_get_bustag(psc->sc_sr);
140 sc->sc_sh = (HAL_BUS_HANDLE)rman_get_bushandle(psc->sc_sr);
143 * Setup DMA descriptor area.
145 error = bus_dma_tag_create(NULL, 1, 0,
146 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
147 NULL, NULL, 0x3ffff/* maxsize XXX */,
148 ATH_MAX_SCATTER, 0x3ffff/* maxsegsize XXX */,
149 BUS_DMA_ALLOCNOW, &sc->sc_dmat);
151 device_printf(dev, "cannot allocate DMA tag\n");
155 error = ath_attach(pci_get_device(dev), sc);
164 ath_pci_detach(device_t dev)
166 struct ath_pci_softc *psc = device_get_softc(dev);
167 struct ath_softc *sc = &psc->sc_sc;
169 /* XXX check if device was removed */
170 sc->sc_invalid = !bus_child_present(dev);
172 if (device_is_attached(dev))
175 bus_generic_detach(dev);
177 if (sc->sc_dmat != NULL)
178 bus_dma_tag_destroy(sc->sc_dmat);
180 if (psc->sc_sr != NULL) {
181 bus_release_resource(dev, SYS_RES_MEMORY, psc->sc_srid,
188 ath_pci_shutdown(device_t dev)
190 struct ath_pci_softc *psc = device_get_softc(dev);
192 ath_shutdown(&psc->sc_sc);
197 ath_pci_suspend(device_t dev)
199 struct ath_pci_softc *psc = device_get_softc(dev);
201 ath_suspend(&psc->sc_sc);
206 ath_pci_resume(device_t dev)
208 struct ath_pci_softc *psc = device_get_softc(dev);
211 ath_resume(&psc->sc_sc);
215 static device_method_t ath_pci_methods[] = {
216 /* Device interface */
217 DEVMETHOD(device_probe, ath_pci_probe),
218 DEVMETHOD(device_attach, ath_pci_attach),
219 DEVMETHOD(device_detach, ath_pci_detach),
220 DEVMETHOD(device_shutdown, ath_pci_shutdown),
221 DEVMETHOD(device_suspend, ath_pci_suspend),
222 DEVMETHOD(device_resume, ath_pci_resume),
227 static driver_t ath_pci_driver = {
230 sizeof (struct ath_pci_softc)
233 static devclass_t ath_devclass;
235 DRIVER_MODULE(if_ath, pci, ath_pci_driver, ath_devclass, 0, 0);
236 DRIVER_MODULE(if_ath, cardbus, ath_pci_driver, ath_devclass, 0, 0);
238 MODULE_VERSION(if_ath, 1);
240 MODULE_DEPEND(if_ath, ath_hal, 1, 1, 1); /* Atheros HAL */
241 MODULE_DEPEND(if_ath, ath_rate, 1, 1, 1); /* rate control algorithm */
242 MODULE_DEPEND(if_ath, wlan, 1, 1, 1); /* 802.11 media layer */