1 /* $NetBSD: if_wi_pci.c,v 1.49 2009/09/05 14:13:50 tsutsui Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Hideaki Imaizumi <hiddy@sfc.wide.ad.jp>
9 * and Ichiro FUKUHARA (ichiro@ichiro.org).
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * PCI bus front-end for the Intersil PCI WaveLan.
35 * Works with Prism2.5 Mini-PCI wavelan.
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: if_wi_pci.c,v 1.49 2009/09/05 14:13:50 tsutsui Exp $");
41 #include <sys/param.h>
42 #include <sys/systm.h>
44 #include <sys/syslog.h>
45 #include <sys/socket.h>
46 #include <sys/device.h>
47 #include <sys/callout.h>
50 #include <net/if_ether.h>
51 #include <net/if_media.h>
53 #include <net80211/ieee80211_netbsd.h>
54 #include <net80211/ieee80211_var.h>
55 #include <net80211/ieee80211_radiotap.h>
56 #include <net80211/ieee80211_rssadapt.h>
61 #include <dev/pci/pcireg.h>
62 #include <dev/pci/pcivar.h>
63 #include <dev/pci/pcidevs.h>
65 #include <dev/ic/wi_ieee.h>
66 #include <dev/ic/wireg.h>
67 #include <dev/ic/wivar.h>
69 #define WI_PCI_CBMA 0x10 /* Configuration Base Memory Address */
70 #define WI_PCI_PLX_LOMEM 0x10 /* PLX chip membase */
71 #define WI_PCI_PLX_LOIO 0x14 /* PLX chip iobase */
72 #define WI_PCI_LOMEM 0x18 /* ISA membase */
73 #define WI_PCI_LOIO 0x1C /* ISA iobase */
75 #define CHIP_PLX_OTHER 0x01
76 #define CHIP_PLX_9052 0x02
77 #define CHIP_TMD_7160 0x03
79 #define WI_PLX_COR_OFFSET 0x3E0
80 #define WI_PLX_COR_VALUE 0x41
83 struct wi_softc psc_wi
; /* real "wi" softc */
85 /* PCI-specific goo */
86 pci_intr_handle_t psc_ih
;
87 pci_chipset_tag_t psc_pc
;
91 static int wi_pci_match(device_t
, cfdata_t
, void *);
92 static void wi_pci_attach(device_t
, device_t
, void *);
93 static int wi_pci_enable(struct wi_softc
*);
94 static void wi_pci_disable(struct wi_softc
*);
95 static void wi_pci_reset(struct wi_softc
*);
97 static const struct wi_pci_product
98 *wi_pci_lookup(struct pci_attach_args
*);
100 CFATTACH_DECL(wi_pci
, sizeof(struct wi_pci_softc
),
101 wi_pci_match
, wi_pci_attach
, NULL
, NULL
);
103 static const struct wi_pci_product
{
104 pci_vendor_id_t wpp_vendor
; /* vendor ID */
105 pci_product_id_t wpp_product
; /* product ID */
106 int wpp_chip
; /* uses other chip */
107 } wi_pci_products
[] = {
108 { PCI_VENDOR_GLOBALSUN
, PCI_PRODUCT_GLOBALSUN_GL24110P
,
110 { PCI_VENDOR_GLOBALSUN
, PCI_PRODUCT_GLOBALSUN_GL24110P02
,
112 { PCI_VENDOR_EUMITCOM
, PCI_PRODUCT_EUMITCOM_WL11000P
,
114 { PCI_VENDOR_3COM
, PCI_PRODUCT_3COM_3CRWE777A
,
116 { PCI_VENDOR_NETGEAR
, PCI_PRODUCT_NETGEAR_MA301
,
118 { PCI_VENDOR_INTERSIL
, PCI_PRODUCT_INTERSIL_MINI_PCI_WLAN
,
120 { PCI_VENDOR_NDC
, PCI_PRODUCT_NDC_NCP130
,
122 { PCI_VENDOR_USR2
, PCI_PRODUCT_USR2_2415
,
124 { PCI_VENDOR_NDC
, PCI_PRODUCT_NDC_NCP130A2
,
131 wi_pci_enable(struct wi_softc
*sc
)
133 struct wi_pci_softc
*psc
= (struct wi_pci_softc
*)sc
;
135 /* establish the interrupt. */
136 sc
->sc_ih
= pci_intr_establish(psc
->psc_pc
,
137 psc
->psc_ih
, IPL_NET
, wi_intr
, sc
);
138 if (sc
->sc_ih
== NULL
) {
139 aprint_error_dev(&sc
->sc_dev
, "couldn't establish interrupt\n");
143 /* reset HFA3842 MAC core */
144 if (sc
->sc_reset
!= NULL
)
151 wi_pci_disable(struct wi_softc
*sc
)
153 struct wi_pci_softc
*psc
= (struct wi_pci_softc
*)sc
;
155 pci_intr_disestablish(psc
->psc_pc
, sc
->sc_ih
);
159 wi_pci_reset(struct wi_softc
*sc
)
163 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
,
164 WI_PCI_COR
, WI_COR_SOFT_RESET
);
165 DELAY(250*1000); /* 1/4 second */
167 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
,
168 WI_PCI_COR
, WI_COR_CLEAR
);
169 DELAY(500*1000); /* 1/2 second */
171 /* wait 2 seconds for firmware to complete initialization. */
173 for (i
= 200000; i
--; DELAY(10))
174 if (!(CSR_READ_2(sc
, WI_COMMAND
) & WI_CMD_BUSY
))
178 printf("%s: PCI reset timed out\n", device_xname(&sc
->sc_dev
));
179 } else if (sc
->sc_if
.if_flags
& IFF_DEBUG
) {
180 usecs
= (200000 - i
) * 10;
181 secs
= usecs
/ 1000000;
184 printf("%s: PCI reset in %d.%06d seconds\n",
185 device_xname(&sc
->sc_dev
), secs
, usecs
);
191 static const struct wi_pci_product
*
192 wi_pci_lookup(struct pci_attach_args
*pa
)
194 const struct wi_pci_product
*wpp
;
196 for (wpp
= wi_pci_products
; wpp
->wpp_vendor
!= 0; wpp
++) {
197 if (PCI_VENDOR(pa
->pa_id
) == wpp
->wpp_vendor
&&
198 PCI_PRODUCT(pa
->pa_id
) == wpp
->wpp_product
)
205 wi_pci_match(device_t parent
, cfdata_t match
, void *aux
)
207 struct pci_attach_args
*pa
= aux
;
209 if (wi_pci_lookup(pa
) != NULL
)
215 wi_pci_attach(device_t parent
, device_t self
, void *aux
)
217 struct wi_pci_softc
*psc
= device_private(self
);
218 struct wi_softc
*sc
= &psc
->psc_wi
;
219 struct pci_attach_args
*pa
= aux
;
220 pci_chipset_tag_t pc
= pa
->pa_pc
;
222 const struct wi_pci_product
*wpp
;
223 pci_intr_handle_t ih
;
224 bus_space_tag_t memt
, iot
, plxt
, tmdt
;
225 bus_space_handle_t memh
, ioh
, plxh
, tmdh
;
228 psc
->psc_pcitag
= pa
->pa_tag
;
230 wpp
= wi_pci_lookup(pa
);
234 panic("wi_pci_attach: impossible");
238 switch (wpp
->wpp_chip
) {
241 /* Map memory and I/O registers. */
242 if (pci_mapreg_map(pa
, WI_PCI_LOMEM
, PCI_MAPREG_TYPE_MEM
, 0,
243 &memt
, &memh
, NULL
, NULL
) != 0) {
244 printf(": can't map mem space\n");
247 if (pci_mapreg_map(pa
, WI_PCI_LOIO
, PCI_MAPREG_TYPE_IO
, 0,
248 &iot
, &ioh
, NULL
, NULL
) != 0) {
249 printf(": can't map I/O space\n");
253 if (wpp
->wpp_chip
== CHIP_PLX_OTHER
) {
254 /* The PLX 9052 doesn't have IO at 0x14. Perhaps
255 other chips have, so we'll make this conditional. */
256 if (pci_mapreg_map(pa
, WI_PCI_PLX_LOIO
,
257 PCI_MAPREG_TYPE_IO
, 0, &plxt
,
258 &plxh
, NULL
, NULL
) != 0) {
259 printf(": can't map PLX\n");
265 /* Used instead of PLX on at least one revision of
266 * the National Datacomm Corporation NCP130. Values
267 * for registers acquired from OpenBSD, which in
268 * turn got them from a Linux driver.
270 /* Map COR and I/O registers. */
271 if (pci_mapreg_map(pa
, WI_TMD_COR
, PCI_MAPREG_TYPE_IO
, 0,
272 &tmdt
, &tmdh
, NULL
, NULL
) != 0) {
273 printf(": can't map TMD\n");
276 if (pci_mapreg_map(pa
, WI_TMD_IO
, PCI_MAPREG_TYPE_IO
, 0,
277 &iot
, &ioh
, NULL
, NULL
) != 0) {
278 printf(": can't map I/O space\n");
283 if (pci_mapreg_map(pa
, WI_PCI_CBMA
,
284 PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_32BIT
,
285 0, &iot
, &ioh
, NULL
, NULL
) != 0) {
286 printf(": can't map mem space\n");
299 pci_devinfo(pa
->pa_id
, pa
->pa_class
, 0, devinfo
, sizeof(devinfo
));
300 printf(": %s (rev. 0x%02x)\n", devinfo
,
301 PCI_REVISION(pa
->pa_class
));
305 sc
->sc_enable
= wi_pci_enable
;
306 sc
->sc_disable
= wi_pci_disable
;
310 /* Make sure interrupts are disabled. */
311 CSR_WRITE_2(sc
, WI_INT_EN
, 0);
312 CSR_WRITE_2(sc
, WI_EVENT_ACK
, 0xFFFF);
314 if (wpp
->wpp_chip
== CHIP_PLX_OTHER
) {
316 #define WI_LOCAL_INTCSR 0x4c
317 #define WI_LOCAL_INTEN 0x40 /* poke this into INTCSR */
319 command
= bus_space_read_4(plxt
, plxh
, WI_LOCAL_INTCSR
);
320 command
|= WI_LOCAL_INTEN
;
321 bus_space_write_4(plxt
, plxh
, WI_LOCAL_INTCSR
, command
);
324 /* Map and establish the interrupt. */
325 if (pci_intr_map(pa
, &ih
)) {
326 aprint_error_dev(self
, "couldn't map interrupt\n");
329 intrstr
= pci_intr_string(pc
, ih
);
332 sc
->sc_ih
= pci_intr_establish(pc
, ih
, IPL_NET
, wi_intr
, sc
);
333 if (sc
->sc_ih
== NULL
) {
334 aprint_error_dev(self
, "couldn't establish interrupt");
336 aprint_error(" at %s", intrstr
);
341 aprint_normal_dev(self
, "interrupting at %s\n", intrstr
);
343 switch (wpp
->wpp_chip
) {
347 * Setup the PLX chip for level interrupts and config index 1
348 * XXX - should really reset the PLX chip too.
350 bus_space_write_1(memt
, memh
,
351 WI_PLX_COR_OFFSET
, WI_PLX_COR_VALUE
);
354 /* Enable I/O mode and level interrupts on the embedded
355 * card. The card's COR is the first byte of BAR 0.
357 bus_space_write_1(tmdt
, tmdh
, 0, WI_COR_IOMODE
);
360 /* reset HFA3842 MAC core */
365 printf("%s:", device_xname(self
));
367 if (wi_attach(sc
, 0) != 0) {
368 aprint_error_dev(self
, "failed to attach controller\n");
369 pci_intr_disestablish(pa
->pa_pc
, sc
->sc_ih
);
374 sc
->sc_reset
= wi_pci_reset
;
376 if (pmf_device_register(self
, NULL
, NULL
))
377 pmf_class_network_register(self
, &sc
->sc_if
);
379 aprint_error_dev(self
, "couldn't establish power handler\n");