This source file includes following definitions.
- atw_cardbus_match
- atw_cardbus_attach
- atw_cardbus_detach
- atw_cardbus_enable
- atw_cardbus_disable
- atw_cardbus_power
- atw_cardbus_setup
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
41
42
43
44
45
46 #include "bpfilter.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/mbuf.h>
51 #include <sys/malloc.h>
52 #include <sys/kernel.h>
53 #include <sys/socket.h>
54 #include <sys/ioctl.h>
55 #include <sys/errno.h>
56 #include <sys/device.h>
57
58 #include <machine/endian.h>
59
60 #include <net/if.h>
61 #include <net/if_dl.h>
62 #include <net/if_media.h>
63
64 #ifdef INET
65 #include <netinet/in.h>
66 #include <netinet/if_ether.h>
67 #endif
68
69 #include <net80211/ieee80211_radiotap.h>
70 #include <net80211/ieee80211_var.h>
71
72 #if NBPFILTER > 0
73 #include <net/bpf.h>
74 #endif
75
76 #include <machine/bus.h>
77 #include <machine/intr.h>
78
79 #include <dev/ic/atwreg.h>
80 #include <dev/ic/rf3000reg.h>
81 #include <dev/ic/si4136reg.h>
82 #include <dev/ic/atwvar.h>
83
84 #include <dev/pci/pcivar.h>
85 #include <dev/pci/pcireg.h>
86 #include <dev/pci/pcidevs.h>
87
88 #include <dev/cardbus/cardbusvar.h>
89
90
91
92
93 #define ATW_PCI_IOBA 0x10
94 #define ATW_PCI_MMBA 0x14
95
96 struct atw_cardbus_softc {
97 struct atw_softc sc_atw;
98
99
100 void *sc_ih;
101 cardbus_devfunc_t sc_ct;
102 cardbustag_t sc_tag;
103 int sc_csr;
104 bus_size_t sc_mapsize;
105
106
107 int sc_cben;
108 int sc_bar_reg;
109 pcireg_t sc_bar_val;
110
111 int sc_intrline;
112 };
113
114 int atw_cardbus_match(struct device *, void *, void *);
115 void atw_cardbus_attach(struct device *, struct device *, void *);
116 int atw_cardbus_detach(struct device *, int);
117
118 struct cfattach atw_cardbus_ca = {
119 sizeof(struct atw_cardbus_softc), atw_cardbus_match, atw_cardbus_attach,
120 atw_cardbus_detach
121 };
122
123 void atw_cardbus_setup(struct atw_cardbus_softc *);
124
125 int atw_cardbus_enable(struct atw_softc *);
126 void atw_cardbus_disable(struct atw_softc *);
127 void atw_cardbus_power(struct atw_softc *, int);
128
129 const struct cardbus_matchid atw_cardbus_devices[] = {
130 { PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_ADM8211 },
131 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CRSHPW796 },
132 };
133
134 int
135 atw_cardbus_match(struct device *parent, void *match, void *aux)
136 {
137 return (cardbus_matchbyid((struct cardbus_attach_args *)aux,
138 atw_cardbus_devices,
139 sizeof(atw_cardbus_devices)/sizeof(atw_cardbus_devices[0])));
140 }
141
142 void
143 atw_cardbus_attach(struct device *parent, struct device *self, void *aux)
144 {
145 struct atw_cardbus_softc *csc = (void *)self;
146 struct atw_softc *sc = &csc->sc_atw;
147 struct cardbus_attach_args *ca = aux;
148 cardbus_devfunc_t ct = ca->ca_ct;
149 bus_addr_t adr;
150
151 sc->sc_dmat = ca->ca_dmat;
152 csc->sc_ct = ct;
153 csc->sc_tag = ca->ca_tag;
154
155
156
157
158 sc->sc_enable = atw_cardbus_enable;
159 sc->sc_disable = atw_cardbus_disable;
160 sc->sc_power = atw_cardbus_power;
161
162
163 sc->sc_rev = PCI_REVISION(ca->ca_class);
164
165 #if 0
166 printf(": signature %08x\n%s",
167 cardbus_conf_read(ct->ct_cc, ct->ct_cf, csc->sc_tag, 0x80),
168 sc->sc_dev.dv_xname);
169 #endif
170
171
172
173
174 csc->sc_csr = CARDBUS_COMMAND_MASTER_ENABLE;
175 if (Cardbus_mapreg_map(ct, ATW_PCI_MMBA,
176 CARDBUS_MAPREG_TYPE_MEM, 0, &sc->sc_st, &sc->sc_sh, &adr,
177 &csc->sc_mapsize) == 0) {
178 #if 0
179 printf(": atw_cardbus_attach mapped %d bytes mem space\n%s",
180 csc->sc_mapsize, sc->sc_dev.dv_xname);
181 #endif
182 csc->sc_cben = CARDBUS_MEM_ENABLE;
183 csc->sc_csr |= CARDBUS_COMMAND_MEM_ENABLE;
184 csc->sc_bar_reg = ATW_PCI_MMBA;
185 csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_MEM;
186 } else if (Cardbus_mapreg_map(ct, ATW_PCI_IOBA,
187 CARDBUS_MAPREG_TYPE_IO, 0, &sc->sc_st, &sc->sc_sh, &adr,
188 &csc->sc_mapsize) == 0) {
189 #if 0
190 printf(": atw_cardbus_attach mapped %d bytes I/O space\n%s",
191 csc->sc_mapsize, sc->sc_dev.dv_xname);
192 #endif
193 csc->sc_cben = CARDBUS_IO_ENABLE;
194 csc->sc_csr |= CARDBUS_COMMAND_IO_ENABLE;
195 csc->sc_bar_reg = ATW_PCI_IOBA;
196 csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_IO;
197 } else {
198 printf(": unable to map device registers\n");
199 return;
200 }
201
202
203
204
205
206 atw_cardbus_setup(csc);
207
208
209 csc->sc_intrline = ca->ca_intrline;
210
211 printf(": revision %d.%d: irq %d\n",
212 (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf, csc->sc_intrline);
213 #if 0
214
215
216
217
218
219 sc->sc_txthresh = 3;
220 #endif
221
222
223
224
225 atw_attach(sc);
226
227 ATW_WRITE(sc, ATW_FER, ATW_FER_INTR);
228
229
230
231
232 Cardbus_function_disable(csc->sc_ct);
233 }
234
235 int
236 atw_cardbus_detach(struct device *self, int flags)
237 {
238 struct atw_cardbus_softc *csc = (void *)self;
239 struct atw_softc *sc = &csc->sc_atw;
240 struct cardbus_devfunc *ct = csc->sc_ct;
241 int rv;
242
243 #if defined(DIAGNOSTIC)
244 if (ct == NULL)
245 panic("%s: data structure lacks", sc->sc_dev.dv_xname);
246 #endif
247
248 rv = atw_detach(sc);
249 if (rv)
250 return (rv);
251
252
253
254
255 if (csc->sc_ih != NULL)
256 cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, csc->sc_ih);
257
258
259
260
261 if (csc->sc_bar_reg != 0)
262 Cardbus_mapreg_unmap(ct, csc->sc_bar_reg,
263 sc->sc_st, sc->sc_sh, csc->sc_mapsize);
264
265 return (0);
266 }
267
268 int
269 atw_cardbus_enable(struct atw_softc *sc)
270 {
271 struct atw_cardbus_softc *csc = (void *) sc;
272 cardbus_devfunc_t ct = csc->sc_ct;
273 cardbus_chipset_tag_t cc = ct->ct_cc;
274 cardbus_function_tag_t cf = ct->ct_cf;
275
276
277
278
279 Cardbus_function_enable(ct);
280
281
282
283
284 atw_cardbus_setup(csc);
285
286
287
288
289 csc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline, IPL_NET,
290 atw_intr, sc, sc->sc_dev.dv_xname);
291 if (csc->sc_ih == NULL) {
292 printf("%s: unable to establish interrupt at %d\n",
293 sc->sc_dev.dv_xname, csc->sc_intrline);
294 Cardbus_function_disable(csc->sc_ct);
295 return (1);
296 }
297
298 return (0);
299 }
300
301 void
302 atw_cardbus_disable(struct atw_softc *sc)
303 {
304 struct atw_cardbus_softc *csc = (void *) sc;
305 cardbus_devfunc_t ct = csc->sc_ct;
306 cardbus_chipset_tag_t cc = ct->ct_cc;
307 cardbus_function_tag_t cf = ct->ct_cf;
308
309
310 cardbus_intr_disestablish(cc, cf, csc->sc_ih);
311 csc->sc_ih = NULL;
312
313
314 Cardbus_function_disable(ct);
315 }
316
317 void
318 atw_cardbus_power(struct atw_softc *sc, int why)
319 {
320 if (why == PWR_RESUME)
321 atw_enable(sc);
322 }
323
324 void
325 atw_cardbus_setup(struct atw_cardbus_softc *csc)
326 {
327 #ifdef notyet
328 struct atw_softc *sc = &csc->sc_atw;
329 #endif
330 cardbus_devfunc_t ct = csc->sc_ct;
331 cardbus_chipset_tag_t cc = ct->ct_cc;
332 cardbus_function_tag_t cf = ct->ct_cf;
333 pcireg_t reg;
334
335 #ifdef notyet
336 (void)cardbus_setpowerstate(sc->sc_dev.dv_xname, ct, csc->sc_tag,
337 PCI_PWR_D0);
338 #endif
339
340
341 cardbus_conf_write(cc, cf, csc->sc_tag, csc->sc_bar_reg,
342 csc->sc_bar_val);
343
344
345 (*ct->ct_cf->cardbus_ctrl)(cc, csc->sc_cben);
346 (*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
347
348
349 reg = cardbus_conf_read(cc, cf, csc->sc_tag,
350 CARDBUS_COMMAND_STATUS_REG);
351 reg &= ~(CARDBUS_COMMAND_IO_ENABLE|CARDBUS_COMMAND_MEM_ENABLE);
352 reg |= csc->sc_csr;
353 cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_COMMAND_STATUS_REG,
354 reg);
355
356
357
358
359
360 reg = cardbus_conf_read(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG);
361 if (CARDBUS_LATTIMER(reg) < 0x20) {
362 reg &= ~(CARDBUS_LATTIMER_MASK << CARDBUS_LATTIMER_SHIFT);
363 reg |= (0x20 << CARDBUS_LATTIMER_SHIFT);
364 cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG, reg);
365 }
366 }