Line data Source code
1 : /* $OpenBSD: if_wi_pci.c,v 1.52 2015/11/24 17:11:39 mpi Exp $ */
2 :
3 : /*
4 : * Copyright (c) 2001-2003 Todd C. Miller <Todd.Miller@courtesan.com>
5 : *
6 : * Permission to use, copy, modify, and distribute this software for any
7 : * purpose with or without fee is hereby granted, provided that the above
8 : * copyright notice and this permission notice appear in all copies.
9 : *
10 : * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 : * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 : * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 : * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 : * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 : * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 : * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 : *
18 : * Sponsored in part by the Defense Advanced Research Projects
19 : * Agency (DARPA) and Air Force Research Laboratory, Air Force
20 : * Materiel Command, USAF, under agreement number F39502-99-1-0512.
21 : */
22 :
23 : /*
24 : * PCI attachment for the Wavelan driver. There are two basic types
25 : * of PCI card supported:
26 : *
27 : * 1) Cards based on the Prism2.5 Mini-PCI chipset
28 : * 2) Cards that use a dumb PCMCIA->PCI bridge
29 : *
30 : * Only the first type are "true" PCI cards.
31 : *
32 : * The latter are simply PCMCIA cards (or the guts of same) with some
33 : * type of dumb PCMCIA->PCI bridge. They are "dumb" in that they
34 : * are not true PCMCIA bridges and really just serve to deal with
35 : * the different interrupt types and timings of the ISA vs. PCI bus.
36 : *
37 : * The following bridge types are supported:
38 : * o PLX 9052 (the most common)
39 : * o TMD 7160 (found in some NDC/Sohoware NCP130 cards)
40 : * o ACEX EP1K30 (really a PLD, found in Symbol cards and their OEMs)
41 : */
42 :
43 : #include <sys/param.h>
44 : #include <sys/systm.h>
45 : #include <sys/device.h>
46 : #include <sys/timeout.h>
47 : #include <sys/socket.h>
48 : #include <sys/tree.h>
49 :
50 : #include <net/if.h>
51 : #include <net/if_media.h>
52 :
53 : #include <netinet/in.h>
54 : #include <netinet/if_ether.h>
55 :
56 : #include <net80211/ieee80211_var.h>
57 : #include <net80211/ieee80211_ioctl.h>
58 :
59 : #include <machine/bus.h>
60 :
61 : #include <dev/pci/pcireg.h>
62 : #include <dev/pci/pcivar.h>
63 : #include <dev/pci/pcidevs.h>
64 :
65 : #include <dev/ic/if_wireg.h>
66 : #include <dev/ic/if_wi_ieee.h>
67 : #include <dev/ic/if_wivar.h>
68 :
69 : /* For printing CIS of the actual PCMCIA card */
70 : #define CIS_MFG_NAME_OFFSET 0x16
71 : #define CIS_INFO_SIZE 256
72 :
73 : const struct wi_pci_product *wi_pci_lookup(struct pci_attach_args *pa);
74 : int wi_pci_match(struct device *, void *, void *);
75 : void wi_pci_attach(struct device *, struct device *, void *);
76 : int wi_pci_activate(struct device *, int);
77 : void wi_pci_wakeup(struct wi_softc *);
78 : int wi_pci_acex_attach(struct pci_attach_args *pa, struct wi_softc *sc);
79 : int wi_pci_plx_attach(struct pci_attach_args *pa, struct wi_softc *sc);
80 : int wi_pci_tmd_attach(struct pci_attach_args *pa, struct wi_softc *sc);
81 : int wi_pci_native_attach(struct pci_attach_args *pa, struct wi_softc *sc);
82 : int wi_pci_common_attach(struct pci_attach_args *pa, struct wi_softc *sc);
83 : void wi_pci_plx_print_cis(struct wi_softc *);
84 :
85 : struct wi_pci_softc {
86 : struct wi_softc sc_wi; /* real softc */
87 : };
88 :
89 : struct cfattach wi_pci_ca = {
90 : sizeof (struct wi_pci_softc), wi_pci_match, wi_pci_attach, NULL,
91 : wi_pci_activate
92 : };
93 :
94 : static const struct wi_pci_product {
95 : pci_vendor_id_t pp_vendor;
96 : pci_product_id_t pp_product;
97 : int (*pp_attach)(struct pci_attach_args *pa, struct wi_softc *sc);
98 : } wi_pci_products[] = {
99 : { PCI_VENDOR_GLOBALSUN, PCI_PRODUCT_GLOBALSUN_GL24110P, wi_pci_plx_attach },
100 : { PCI_VENDOR_GLOBALSUN, PCI_PRODUCT_GLOBALSUN_GL24110P02, wi_pci_plx_attach },
101 : { PCI_VENDOR_GLOBALSUN, PCI_PRODUCT_GLOBALSUN_GL24110P03, wi_pci_plx_attach },
102 : { PCI_VENDOR_GLOBALSUN, PCI_PRODUCT_GLOBALSUN_8031, wi_pci_plx_attach },
103 : { PCI_VENDOR_EUMITCOM, PCI_PRODUCT_EUMITCOM_WL11000P, wi_pci_plx_attach },
104 : { PCI_VENDOR_USR2, PCI_PRODUCT_USR2_WL11000P, wi_pci_plx_attach },
105 : { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CRWE777A, wi_pci_plx_attach },
106 : { PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_MA301, wi_pci_plx_attach },
107 : { PCI_VENDOR_EFFICIENTNETS, PCI_PRODUCT_EFFICIENTNETS_SS1023, wi_pci_plx_attach },
108 : { PCI_VENDOR_ADDTRON, PCI_PRODUCT_ADDTRON_AWA100, wi_pci_plx_attach },
109 : { PCI_VENDOR_BELKIN, PCI_PRODUCT_BELKIN_F5D6000, wi_pci_plx_attach },
110 : { PCI_VENDOR_NDC, PCI_PRODUCT_NDC_NCP130, wi_pci_plx_attach },
111 : { PCI_VENDOR_NDC, PCI_PRODUCT_NDC_NCP130A2, wi_pci_tmd_attach },
112 : { PCI_VENDOR_INTERSIL, PCI_PRODUCT_INTERSIL_MINI_PCI_WLAN, wi_pci_native_attach },
113 : { PCI_VENDOR_INTERSIL, PCI_PRODUCT_INTERSIL_ISL3872, wi_pci_native_attach },
114 : { PCI_VENDOR_SAMSUNG, PCI_PRODUCT_SAMSUNG_SWL2210P, wi_pci_native_attach },
115 : { PCI_VENDOR_NORTEL, PCI_PRODUCT_NORTEL_211818A, wi_pci_acex_attach },
116 : { PCI_VENDOR_SYMBOL, PCI_PRODUCT_SYMBOL_LA41X3, wi_pci_acex_attach },
117 : { 0, 0, 0 }
118 : };
119 :
120 : const struct wi_pci_product *
121 0 : wi_pci_lookup(struct pci_attach_args *pa)
122 : {
123 : const struct wi_pci_product *pp;
124 :
125 0 : for (pp = wi_pci_products; pp->pp_product != 0; pp++) {
126 0 : if (PCI_VENDOR(pa->pa_id) == pp->pp_vendor &&
127 0 : PCI_PRODUCT(pa->pa_id) == pp->pp_product)
128 0 : return (pp);
129 : }
130 :
131 0 : return (NULL);
132 0 : }
133 :
134 : int
135 0 : wi_pci_match(struct device *parent, void *match, void *aux)
136 : {
137 0 : return (wi_pci_lookup(aux) != NULL);
138 : }
139 :
140 : void
141 0 : wi_pci_attach(struct device *parent, struct device *self, void *aux)
142 : {
143 0 : struct wi_softc *sc = (struct wi_softc *)self;
144 0 : struct pci_attach_args *pa = aux;
145 : const struct wi_pci_product *pp;
146 :
147 0 : pp = wi_pci_lookup(pa);
148 0 : if (pp->pp_attach(pa, sc) != 0)
149 0 : return;
150 0 : printf("\n");
151 0 : wi_attach(sc, &wi_func_io);
152 0 : }
153 :
154 : int
155 0 : wi_pci_activate(struct device *self, int act)
156 : {
157 0 : struct wi_softc *sc = (struct wi_softc *)self;
158 0 : struct ifnet *ifp = &sc->sc_ic.ic_if;
159 :
160 0 : switch (act) {
161 : case DVACT_SUSPEND:
162 0 : if (ifp->if_flags & IFF_RUNNING)
163 0 : wi_stop(sc);
164 : break;
165 : case DVACT_WAKEUP:
166 0 : if (ifp->if_flags & IFF_UP)
167 0 : wi_pci_wakeup(sc);
168 : break;
169 : }
170 0 : return (0);
171 : }
172 :
173 : void
174 0 : wi_pci_wakeup(struct wi_softc *sc)
175 : {
176 : int s;
177 :
178 0 : s = splnet();
179 0 : while (sc->wi_flags & WI_FLAGS_BUSY)
180 0 : tsleep(&sc->wi_flags, 0, "wipwr", 0);
181 0 : sc->wi_flags |= WI_FLAGS_BUSY;
182 :
183 0 : wi_init(sc);
184 :
185 0 : sc->wi_flags &= ~WI_FLAGS_BUSY;
186 0 : wakeup(&sc->wi_flags);
187 0 : splx(s);
188 0 : }
189 :
190 : /*
191 : * ACEX EP1K30-based PCMCIA->PCI bridge attachment.
192 : *
193 : * The ACEX EP1K30 is a programmable logic device (PLD) used as a
194 : * PCMCIA->PCI bridge on the Symbol LA4123 and its OEM equivalents
195 : * (such as the Nortel E-mobility 211818-A). There are 3 I/O ports:
196 : * BAR0 at 0x10 appears to be a command port.
197 : * BAR1 at 0x14 contains COR at offset 0xe0.
198 : * BAR2 at 0x18 maps the actual PCMCIA card.
199 : *
200 : * The datasheet for the ACEX EP1K30 is available from Altera but that
201 : * doesn't really help much since we don't know how it is programmed.
202 : * Details for this attachment were gleaned from a version of the
203 : * Linux orinoco driver modified by Tobias Hoffmann based on
204 : * what he discoverd from the Windows driver.
205 : */
206 : int
207 0 : wi_pci_acex_attach(struct pci_attach_args *pa, struct wi_softc *sc)
208 : {
209 0 : bus_space_handle_t commandh, localh, ioh;
210 0 : bus_space_tag_t commandt, localt;
211 0 : bus_space_tag_t iot = pa->pa_iot;
212 0 : bus_size_t commandsize, localsize, iosize;
213 : int i;
214 :
215 0 : if (pci_mapreg_map(pa, WI_ACEX_CMDRES, PCI_MAPREG_TYPE_IO,
216 0 : 0, &commandt, &commandh, NULL, &commandsize, 0) != 0) {
217 0 : printf(": can't map command i/o space\n");
218 0 : return (ENXIO);
219 : }
220 :
221 0 : if (pci_mapreg_map(pa, WI_ACEX_LOCALRES, PCI_MAPREG_TYPE_IO,
222 0 : 0, &localt, &localh, NULL, &localsize, 0) != 0) {
223 0 : printf(": can't map local i/o space\n");
224 0 : bus_space_unmap(commandt, commandh, commandsize);
225 0 : return (ENXIO);
226 : }
227 0 : sc->wi_ltag = localt;
228 0 : sc->wi_lhandle = localh;
229 :
230 0 : if (pci_mapreg_map(pa, WI_TMD_IORES, PCI_MAPREG_TYPE_IO,
231 0 : 0, &iot, &ioh, NULL, &iosize, 0) != 0) {
232 0 : printf(": can't map i/o space\n");
233 0 : bus_space_unmap(localt, localh, localsize);
234 0 : bus_space_unmap(commandt, commandh, commandsize);
235 0 : return (ENXIO);
236 : }
237 0 : sc->wi_btag = iot;
238 0 : sc->wi_bhandle = ioh;
239 :
240 : /*
241 : * Setup bridge chip.
242 : */
243 0 : if (bus_space_read_4(commandt, commandh, 0) & 1) {
244 0 : printf(": bridge not ready\n");
245 0 : bus_space_unmap(iot, ioh, iosize);
246 0 : bus_space_unmap(localt, localh, localsize);
247 0 : bus_space_unmap(commandt, commandh, commandsize);
248 0 : return (ENXIO);
249 : }
250 0 : bus_space_write_4(commandt, commandh, 2, 0x118);
251 0 : bus_space_write_4(commandt, commandh, 2, 0x108);
252 0 : DELAY(30 * 1000);
253 0 : bus_space_write_4(commandt, commandh, 2, 0x8);
254 0 : for (i = 0; i < 30; i++) {
255 0 : DELAY(30 * 1000);
256 0 : if (bus_space_read_4(commandt, commandh, 0) & 0x10)
257 : break;
258 : }
259 0 : if (i == 30) {
260 0 : printf(": bridge timeout\n");
261 0 : bus_space_unmap(iot, ioh, iosize);
262 0 : bus_space_unmap(localt, localh, localsize);
263 0 : bus_space_unmap(commandt, commandh, commandsize);
264 0 : return (ENXIO);
265 : }
266 0 : if ((bus_space_read_4(localt, localh, 0xe0) & 1) ||
267 0 : (bus_space_read_4(localt, localh, 0xe2) & 1) ||
268 0 : (bus_space_read_4(localt, localh, 0xe4) & 1)) {
269 0 : printf(": failed bridge setup\n");
270 0 : bus_space_unmap(iot, ioh, iosize);
271 0 : bus_space_unmap(localt, localh, localsize);
272 0 : bus_space_unmap(commandt, commandh, commandsize);
273 0 : return (ENXIO);
274 : }
275 :
276 0 : if (wi_pci_common_attach(pa, sc) != 0) {
277 0 : bus_space_unmap(iot, ioh, iosize);
278 0 : bus_space_unmap(localt, localh, localsize);
279 0 : bus_space_unmap(commandt, commandh, commandsize);
280 0 : return (ENXIO);
281 : }
282 :
283 : /*
284 : * Enable I/O mode and level interrupts on the embedded PCMCIA
285 : * card.
286 : */
287 0 : bus_space_write_1(localt, localh, WI_ACEX_COR_OFFSET, WI_COR_IOMODE);
288 0 : sc->wi_cor_offset = WI_ACEX_COR_OFFSET;
289 :
290 : /* Unmap registers we no longer need access to. */
291 0 : bus_space_unmap(commandt, commandh, commandsize);
292 :
293 0 : return (0);
294 0 : }
295 :
296 : /*
297 : * PLX 9052-based PCMCIA->PCI bridge attachment.
298 : *
299 : * These are often sold as "PCI wireless card adapters" and are
300 : * sold by several vendors. Most are simply rebadged versions of the
301 : * Eumitcom WL11000P or Global Sun Technology GL24110P02.
302 : * These cards use the PLX 9052 dumb bridge chip to connect a PCMCIA
303 : * wireless card to the PCI bus. Because it is a dumb bridge and
304 : * not a true PCMCIA bridge, the PCMCIA subsystem is not involved
305 : * (or even required). The PLX 9052 provides multiple PCI address
306 : * space mappings. The primary mappings at PCI registers 0x10 (mem)
307 : * and 0x14 (I/O) are for the PLX chip itself, *NOT* the PCMCIA card.
308 : * The mem and I/O spaces for the PCMCIA card are mapped to 0x18 and
309 : * 0x1C respectively.
310 : * The PLX 9050/9052 datasheet may be downloaded from PLX at
311 : * http://www.plxtech.com/products/toolbox/9050.htm
312 : */
313 : int
314 0 : wi_pci_plx_attach(struct pci_attach_args *pa, struct wi_softc *sc)
315 : {
316 0 : bus_space_handle_t localh, ioh, memh;
317 0 : bus_space_tag_t localt;
318 0 : bus_space_tag_t iot = pa->pa_iot;
319 0 : bus_space_tag_t memt = pa->pa_memt;
320 0 : bus_size_t localsize, memsize, iosize;
321 : u_int32_t intcsr;
322 :
323 0 : if (pci_mapreg_map(pa, WI_PLX_MEMRES, PCI_MAPREG_TYPE_MEM, 0,
324 0 : &memt, &memh, NULL, &memsize, 0) != 0) {
325 0 : printf(": can't map mem space\n");
326 0 : return (ENXIO);
327 : }
328 0 : sc->wi_ltag = memt;
329 0 : sc->wi_lhandle = memh;
330 :
331 0 : if (pci_mapreg_map(pa, WI_PLX_IORES,
332 0 : PCI_MAPREG_TYPE_IO, 0, &iot, &ioh, NULL, &iosize, 0) != 0) {
333 0 : printf(": can't map i/o space\n");
334 0 : bus_space_unmap(memt, memh, memsize);
335 0 : return (ENXIO);
336 : }
337 0 : sc->wi_btag = iot;
338 0 : sc->wi_bhandle = ioh;
339 :
340 : /*
341 : * Some cards, such as the PLX version of the NDC NCP130,
342 : * don't have the PLX local registers mapped. In general
343 : * this is OK since on those cards the serial EEPROM has
344 : * already set things up for us.
345 : * As such, we don't consider an error here to be fatal.
346 : */
347 0 : localsize = 0;
348 0 : if (pci_mapreg_type(pa->pa_pc, pa->pa_tag, WI_PLX_LOCALRES)
349 0 : == PCI_MAPREG_TYPE_IO) {
350 0 : if (pci_mapreg_map(pa, WI_PLX_LOCALRES, PCI_MAPREG_TYPE_IO,
351 0 : 0, &localt, &localh, NULL, &localsize, 0) != 0)
352 0 : printf(": can't map PLX I/O space\n");
353 : }
354 :
355 0 : if (wi_pci_common_attach(pa, sc) != 0) {
356 0 : if (localsize)
357 0 : bus_space_unmap(localt, localh, localsize);
358 0 : bus_space_unmap(iot, ioh, iosize);
359 0 : bus_space_unmap(memt, memh, memsize);
360 0 : return (ENXIO);
361 : }
362 :
363 0 : if (localsize != 0) {
364 0 : intcsr = bus_space_read_4(localt, localh,
365 : WI_PLX_INTCSR);
366 :
367 : /*
368 : * The Netgear MA301 has local interrupt 1 active
369 : * when there is no card in the adapter. We bail
370 : * early in this case since our attempt to check
371 : * for the presence of a card later will hang the
372 : * MA301.
373 : */
374 0 : if (intcsr & WI_PLX_LINT1STAT) {
375 0 : printf("\n%s: no PCMCIA card detected in bridge card\n",
376 0 : WI_PRT_ARG(sc));
377 0 : pci_intr_disestablish(pa->pa_pc, sc->sc_ih);
378 0 : if (localsize)
379 0 : bus_space_unmap(localt, localh, localsize);
380 0 : bus_space_unmap(iot, ioh, iosize);
381 0 : bus_space_unmap(memt, memh, memsize);
382 0 : return (ENXIO);
383 : }
384 :
385 : /*
386 : * Enable PCI interrupts on the PLX chip if they are
387 : * not already enabled. On most adapters the serial
388 : * EEPROM has done this for us but some (such as
389 : * the Netgear MA301) do not.
390 : */
391 0 : if (!(intcsr & WI_PLX_INTEN)) {
392 0 : intcsr |= WI_PLX_INTEN;
393 0 : bus_space_write_4(localt, localh, WI_PLX_INTCSR,
394 : intcsr);
395 0 : }
396 : }
397 :
398 : /*
399 : * Enable I/O mode and level interrupts on the PCMCIA card.
400 : * The PCMCIA card's COR is the first byte after the CIS.
401 : */
402 0 : bus_space_write_1(memt, memh, WI_PLX_COR_OFFSET, WI_COR_IOMODE);
403 0 : sc->wi_cor_offset = WI_PLX_COR_OFFSET;
404 :
405 0 : if (localsize != 0) {
406 : /*
407 : * Test the presence of a wi(4) card by writing
408 : * a magic number to the first software support
409 : * register and then reading it back.
410 : */
411 0 : CSR_WRITE_2(sc, WI_SW0, WI_DRVR_MAGIC);
412 0 : DELAY(1000);
413 0 : if (CSR_READ_2(sc, WI_SW0) != WI_DRVR_MAGIC) {
414 0 : printf("\n%s: no PCMCIA card detected in bridge card\n",
415 0 : WI_PRT_ARG(sc));
416 0 : pci_intr_disestablish(pa->pa_pc, sc->sc_ih);
417 0 : if (localsize)
418 0 : bus_space_unmap(localt, localh, localsize);
419 0 : bus_space_unmap(iot, ioh, iosize);
420 0 : bus_space_unmap(memt, memh, memsize);
421 0 : return (ENXIO);
422 : }
423 :
424 : /* Unmap registers we no longer need access to. */
425 0 : bus_space_unmap(localt, localh, localsize);
426 :
427 : /* Print PCMCIA card's CIS strings. */
428 0 : wi_pci_plx_print_cis(sc);
429 0 : }
430 :
431 0 : return (0);
432 0 : }
433 :
434 : /*
435 : * TMD 7160-based PCMCIA->PCI bridge attachment.
436 : *
437 : * The TMD7160 dumb bridge chip is used on some versions of the
438 : * NDC/Sohoware NCP130. The TMD7160 provides two PCI I/O registers.
439 : * The first, at 0x14, maps to the Prism2 COR.
440 : * The second, at 0x18, is for the Prism2 chip itself.
441 : *
442 : * The datasheet for the TMD7160 does not seem to be publicly available.
443 : * Details for this attachment were gleaned from a version of the
444 : * Linux WLAN driver modified by NDC.
445 : */
446 : int
447 0 : wi_pci_tmd_attach(struct pci_attach_args *pa, struct wi_softc *sc)
448 : {
449 0 : bus_space_handle_t localh, ioh;
450 0 : bus_space_tag_t localt;
451 0 : bus_space_tag_t iot = pa->pa_iot;
452 0 : bus_size_t localsize, iosize;
453 :
454 0 : if (pci_mapreg_map(pa, WI_TMD_LOCALRES, PCI_MAPREG_TYPE_IO,
455 0 : 0, &localt, &localh, NULL, &localsize, 0) != 0) {
456 0 : printf(": can't map TMD I/O space\n");
457 0 : return (ENXIO);
458 : }
459 0 : sc->wi_ltag = localt;
460 0 : sc->wi_lhandle = localh;
461 :
462 0 : if (pci_mapreg_map(pa, WI_TMD_IORES, PCI_MAPREG_TYPE_IO,
463 0 : 0, &iot, &ioh, NULL, &iosize, 0) != 0) {
464 0 : printf(": can't map i/o space\n");
465 0 : bus_space_unmap(localt, localh, localsize);
466 0 : return (ENXIO);
467 : }
468 0 : sc->wi_btag = iot;
469 0 : sc->wi_bhandle = ioh;
470 :
471 0 : if (wi_pci_common_attach(pa, sc) != 0) {
472 0 : bus_space_unmap(iot, ioh, iosize);
473 0 : bus_space_unmap(localt, localh, localsize);
474 0 : return (ENXIO);
475 : }
476 :
477 : /*
478 : * Enable I/O mode and level interrupts on the embedded PCMCIA
479 : * card. The PCMCIA card's COR is the first byte of BAR 0.
480 : */
481 0 : bus_space_write_1(localt, localh, 0, WI_COR_IOMODE);
482 0 : sc->wi_cor_offset = 0;
483 :
484 0 : return (0);
485 0 : }
486 :
487 : int
488 0 : wi_pci_native_attach(struct pci_attach_args *pa, struct wi_softc *sc)
489 : {
490 0 : bus_space_handle_t ioh;
491 0 : bus_space_tag_t iot = pa->pa_iot;
492 0 : bus_size_t iosize;
493 :
494 0 : if (pci_mapreg_map(pa, WI_PCI_CBMA, PCI_MAPREG_TYPE_MEM,
495 0 : 0, &iot, &ioh, NULL, &iosize, 0) != 0) {
496 0 : printf(": can't map mem space\n");
497 0 : return (ENXIO);
498 : }
499 0 : sc->wi_ltag = iot;
500 0 : sc->wi_lhandle = ioh;
501 0 : sc->wi_btag = iot;
502 0 : sc->wi_bhandle = ioh;
503 0 : sc->sc_pci = 1;
504 :
505 0 : if (wi_pci_common_attach(pa, sc) != 0) {
506 0 : bus_space_unmap(iot, ioh, iosize);
507 0 : return (ENXIO);
508 : }
509 :
510 : /* Do a soft reset of the HFA3842 MAC core */
511 0 : bus_space_write_2(iot, ioh, WI_PCI_COR_OFFSET, WI_COR_SOFT_RESET);
512 0 : DELAY(100*1000); /* 100 m sec */
513 0 : bus_space_write_2(iot, ioh, WI_PCI_COR_OFFSET, WI_COR_CLEAR);
514 0 : DELAY(100*1000); /* 100 m sec */
515 0 : sc->wi_cor_offset = WI_PCI_COR_OFFSET;
516 :
517 0 : return (0);
518 0 : }
519 :
520 : int
521 0 : wi_pci_common_attach(struct pci_attach_args *pa, struct wi_softc *sc)
522 : {
523 0 : pci_intr_handle_t ih;
524 0 : pci_chipset_tag_t pc = pa->pa_pc;
525 : const char *intrstr;
526 :
527 : /* Make sure interrupts are disabled. */
528 0 : CSR_WRITE_2(sc, WI_INT_EN, 0);
529 0 : CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
530 :
531 : /* Map and establish the interrupt. */
532 0 : if (pci_intr_map(pa, &ih)) {
533 0 : printf(": couldn't map interrupt\n");
534 0 : return (ENXIO);
535 : }
536 0 : intrstr = pci_intr_string(pc, ih);
537 0 : sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, wi_intr, sc,
538 0 : sc->sc_dev.dv_xname);
539 0 : if (sc->sc_ih == NULL) {
540 0 : printf(": couldn't establish interrupt");
541 0 : if (intrstr != NULL)
542 0 : printf(" at %s", intrstr);
543 0 : printf("\n");
544 0 : return (ENXIO);
545 : }
546 0 : printf(": %s", intrstr);
547 :
548 0 : return (0);
549 0 : }
550 :
551 : void
552 0 : wi_pci_plx_print_cis(struct wi_softc *sc)
553 : {
554 : int i, stringno;
555 0 : char cisbuf[CIS_INFO_SIZE];
556 0 : char *cis_strings[3];
557 : u_int8_t value;
558 : const u_int8_t cis_magic[] = {
559 : 0x01, 0x03, 0x00, 0x00, 0xff, 0x17, 0x04, 0x67
560 : };
561 :
562 : /* Make sure the CIS data is valid. */
563 0 : for (i = 0; i < 8; i++) {
564 0 : value = bus_space_read_1(sc->wi_ltag, sc->wi_lhandle, i * 2);
565 0 : if (value != cis_magic[i])
566 0 : return;
567 : }
568 :
569 0 : cis_strings[0] = cisbuf;
570 : stringno = 0;
571 0 : for (i = 0; i < CIS_INFO_SIZE && stringno < 3; i++) {
572 0 : cisbuf[i] = bus_space_read_1(sc->wi_ltag,
573 : sc->wi_lhandle, (CIS_MFG_NAME_OFFSET + i) * 2);
574 0 : if (cisbuf[i] == '\0' && ++stringno < 3)
575 0 : cis_strings[stringno] = &cisbuf[i + 1];
576 : }
577 0 : cisbuf[CIS_INFO_SIZE - 1] = '\0';
578 0 : printf("\n%s: \"%s, %s, %s\"", WI_PRT_ARG(sc),
579 0 : cis_strings[0], cis_strings[1], cis_strings[2]);
580 0 : }
|