Annotation of sys/dev/pci/if_ath_pci.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: if_ath_pci.c,v 1.15 2007/06/06 21:41:31 reyk Exp $ */
2: /* $NetBSD: if_ath_pci.c,v 1.7 2004/06/30 05:58:17 mycroft Exp $ */
3:
4: /*-
5: * Copyright (c) 2002-2004 Sam Leffler, Errno Consulting
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer,
13: * without modification.
14: * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15: * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
16: * redistribution must be conditioned upon including a substantially
17: * similar Disclaimer requirement for further binary redistribution.
18: * 3. Neither the names of the above-listed copyright holders nor the names
19: * of any contributors may be used to endorse or promote products derived
20: * from this software without specific prior written permission.
21: *
22: * NO WARRANTY
23: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25: * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
26: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27: * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
28: * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33: * THE POSSIBILITY OF SUCH DAMAGES.
34: */
35:
36: /*
37: * PCI front-end for the Atheros Wireless LAN controller driver.
38: */
39:
40: #include <sys/param.h>
41: #include <sys/systm.h>
42: #include <sys/mbuf.h>
43: #include <sys/malloc.h>
44: #include <sys/kernel.h>
45: #include <sys/lock.h>
46: #include <sys/socket.h>
47: #include <sys/sockio.h>
48: #include <sys/errno.h>
49: #include <sys/device.h>
50: #include <sys/gpio.h>
51:
52: #include <machine/bus.h>
53:
54: #include <net/if.h>
55: #include <net/if_dl.h>
56: #include <net/if_media.h>
57: #include <net/if_llc.h>
58: #include <net/if_arp.h>
59: #ifdef INET
60: #include <netinet/in.h>
61: #include <netinet/if_ether.h>
62: #endif
63:
64: #include <net80211/ieee80211_var.h>
65: #include <net80211/ieee80211_rssadapt.h>
66:
67: #include <dev/gpio/gpiovar.h>
68:
69: #include <dev/pci/pcivar.h>
70: #include <dev/pci/pcireg.h>
71: #include <dev/pci/pcidevs.h>
72:
73: #include <dev/ic/athvar.h>
74:
75: /*
76: * PCI glue.
77: */
78:
79: struct ath_pci_softc {
80: struct ath_softc sc_sc;
81:
82: pci_chipset_tag_t sc_pc;
83: pcitag_t sc_pcitag;
84:
85: void *sc_ih; /* interrupt handler */
86: };
87:
88: /* Base Address Register */
89: #define ATH_BAR0 0x10
90:
91: int ath_pci_match(struct device *, void *, void *);
92: void ath_pci_attach(struct device *, struct device *, void *);
93: void ath_pci_shutdown(void *);
94: int ath_pci_detach(struct device *, int);
95:
96: struct cfattach ath_pci_ca = {
97: sizeof(struct ath_pci_softc),
98: ath_pci_match,
99: ath_pci_attach,
100: ath_pci_detach
101: };
102:
103: int
104: ath_pci_match(struct device *parent, void *match, void *aux)
105: {
106: const char* devname;
107: struct pci_attach_args *pa = aux;
108: pci_vendor_id_t vendor;
109:
110: vendor = PCI_VENDOR(pa->pa_id);
111: if (vendor == 0x128c)
112: vendor = PCI_VENDOR_ATHEROS;
113: devname = ath_hal_probe(vendor, PCI_PRODUCT(pa->pa_id));
114: if (devname)
115: return 1;
116:
117: return 0;
118: }
119:
120: void
121: ath_pci_attach(struct device *parent, struct device *self, void *aux)
122: {
123: struct ath_pci_softc *psc = (struct ath_pci_softc *)self;
124: struct ath_softc *sc = &psc->sc_sc;
125: struct pci_attach_args *pa = aux;
126: pci_chipset_tag_t pc = pa->pa_pc;
127: pcitag_t pt = pa->pa_tag;
128: bus_space_tag_t iot;
129: bus_space_handle_t ioh;
130: pci_intr_handle_t ih;
131: pcireg_t mem_type;
132: void *hook;
133: const char *intrstr = NULL;
134:
135: psc->sc_pc = pc;
136: psc->sc_pcitag = pt;
137:
138: /*
139: * Setup memory-mapping of PCI registers.
140: */
141: mem_type = pci_mapreg_type(pc, pa->pa_tag, ATH_BAR0);
142: if (mem_type != PCI_MAPREG_TYPE_MEM &&
143: mem_type != PCI_MAPREG_MEM_TYPE_64BIT) {
144: printf(": bad PCI register type %d\n", (int)mem_type);
145: goto bad;
146: }
147: if (mem_type == PCI_MAPREG_MEM_TYPE_64BIT)
148: sc->sc_64bit = 1;
149: if (pci_mapreg_map(pa, ATH_BAR0, mem_type, 0, &iot, &ioh,
150: NULL, NULL, 0)) {
151: printf(": cannot map register space\n");
152: goto bad;
153: }
154: sc->sc_st = iot;
155: sc->sc_sh = ioh;
156:
157: sc->sc_invalid = 1;
158:
159: /*
160: * Arrange interrupt line.
161: */
162: if (pci_intr_map(pa, &ih)) {
163: printf(": couldn't map interrupt\n");
164: goto bad1;
165: }
166:
167: intrstr = pci_intr_string(pc, ih);
168: psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, ath_intr, sc,
169: sc->sc_dev.dv_xname);
170: if (psc->sc_ih == NULL) {
171: printf(": couldn't map interrupt\n");
172: goto bad2;
173: }
174:
175: printf(": %s\n", intrstr);
176:
177: sc->sc_dmat = pa->pa_dmat;
178:
179: hook = shutdownhook_establish(ath_pci_shutdown, psc);
180: if (hook == NULL) {
181: printf(": couldn't make shutdown hook\n");
182: goto bad3;
183: }
184:
185: if (ath_attach(PCI_PRODUCT(pa->pa_id), sc) == 0)
186: return;
187:
188: shutdownhook_disestablish(hook);
189:
190: bad3: pci_intr_disestablish(pc, psc->sc_ih);
191: bad2: /* XXX */
192: bad1: /* XXX */
193: bad:
194: return;
195: }
196:
197: int
198: ath_pci_detach(struct device *self, int flags)
199: {
200: struct ath_pci_softc *psc = (struct ath_pci_softc *)self;
201:
202: ath_detach(&psc->sc_sc, flags);
203: pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
204:
205: return (0);
206: }
207:
208: void
209: ath_pci_shutdown(void *self)
210: {
211: struct ath_pci_softc *psc = (struct ath_pci_softc *)self;
212:
213: ath_shutdown(&psc->sc_sc);
214: }
CVSweb