This source file includes following definitions.
- ath_pci_match
- ath_pci_attach
- ath_pci_detach
- ath_pci_shutdown
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
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;
86 };
87
88
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
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
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:
192 bad1:
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 }