if_ath_arbus.c revision 1.7 1 /* $NetBSD: if_ath_arbus.c,v 1.7 2006/09/04 05:17:26 gdamore Exp $ */
2
3 /*-
4 * Copyright (c) 2006 Jared D. McNeill <jmcneill (at) invisible.ca>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the NetBSD
18 * Foundation, Inc. and its contributors.
19 * 4. Neither the name of The NetBSD Foundation nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * 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 IN
31 * 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 THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: if_ath_arbus.c,v 1.7 2006/09/04 05:17:26 gdamore Exp $");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/mbuf.h>
42 #include <sys/malloc.h>
43 #include <sys/kernel.h>
44 #include <sys/errno.h>
45 #include <sys/device.h>
46
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49
50 #include <net/if.h>
51 #include <net/if_media.h>
52 #include <net/if_ether.h>
53 #include <net/if_llc.h>
54 #include <net/if_arp.h>
55
56 #include <netinet/in.h>
57
58 #include <net80211/ieee80211_netbsd.h>
59 #include <net80211/ieee80211_var.h>
60
61 #include <mips/atheros/include/ar5312reg.h>
62 #include <mips/atheros/include/ar531xvar.h>
63 #include <mips/atheros/include/arbusvar.h>
64
65 #include <dev/pci/pcidevs.h>
66 #include <dev/ic/ath_netbsd.h>
67 #include <dev/ic/athvar.h>
68 #include <contrib/dev/ath/ah.h>
69
70 struct ath_arbus_softc {
71 struct ath_softc sc_ath;
72 bus_space_tag_t sc_iot;
73 bus_space_handle_t sc_ioh;
74 void *sc_ih;
75 struct ar531x_config sc_config;
76 void *sc_sdhook;
77 };
78
79 static int ath_arbus_match(struct device *, struct cfdata *, void *);
80 static void ath_arbus_attach(struct device *, struct device *, void *);
81 static int ath_arbus_detach(struct device *, int);
82 static void ath_arbus_shutdown(void *);
83
84 CFATTACH_DECL(ath_arbus, sizeof(struct ath_arbus_softc),
85 ath_arbus_match, ath_arbus_attach, ath_arbus_detach, NULL);
86
87 static int
88 ath_arbus_match(struct device *parent, struct cfdata *cf, void *opaque)
89 {
90 struct arbus_attach_args *aa;
91
92 aa = (struct arbus_attach_args *)opaque;
93 if (strcmp(aa->aa_name, "ath") == 0)
94 return 1;
95
96 return 0;
97 }
98
99 static void
100 ath_arbus_attach(struct device *parent, struct device *self, void *opaque)
101 {
102 struct ath_arbus_softc *asc;
103 struct ath_softc *sc;
104 struct arbus_attach_args *aa;
105 const char *name;
106 int rv;
107 uint16_t devid;
108 uint32_t rev;
109
110 asc = (struct ath_arbus_softc *)self;
111 sc = &asc->sc_ath;
112 aa = (struct arbus_attach_args *)opaque;
113
114 rev = GETSYSREG(AR5312_SYSREG_REVISION);
115 devid = AR5312_REVISION_WMAC(rev);
116 name = ath_hal_probe(PCI_VENDOR_ATHEROS, devid);
117
118 printf(": %s\n", name ? name : "Unknown AR531X WLAN");
119
120 asc->sc_iot = aa->aa_bst;
121 rv = bus_space_map(asc->sc_iot, aa->aa_addr, aa->aa_size, 0,
122 &asc->sc_ioh);
123 if (rv) {
124 aprint_error("%s: unable to map registers\n",
125 sc->sc_dev.dv_xname);
126 return;
127 }
128 /*
129 * Setup HAL configuration state for use by the driver.
130 */
131 rv = ar531x_board_config(&asc->sc_config);
132 if (rv) {
133 aprint_error("%s: unable to locate board configuration\n",
134 sc->sc_dev.dv_xname);
135 return;
136 }
137 asc->sc_config.unit = sc->sc_dev.dv_unit; /* XXX? */
138 asc->sc_config.tag = asc->sc_iot;
139
140 /* NB: the HAL expects the config state passed as the tag */
141 sc->sc_st = (HAL_BUS_TAG) &asc->sc_config;
142 sc->sc_sh = (HAL_BUS_HANDLE) asc->sc_ioh;
143 sc->sc_dmat = aa->aa_dmat;
144
145 sc->sc_invalid = 1;
146
147 asc->sc_ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ath_intr,
148 sc);
149 if (asc->sc_ih == NULL) {
150 aprint_error("%s: couldn't establish interrupt\n",
151 sc->sc_dev.dv_xname);
152 return;
153 }
154
155 if (ath_attach(devid, sc) != 0) {
156 aprint_error("%s: ath_attach failed\n", sc->sc_dev.dv_xname);
157 goto err;
158 }
159
160 asc->sc_sdhook = shutdownhook_establish(ath_arbus_shutdown, asc);
161 if (asc->sc_sdhook == NULL) {
162 aprint_error("%s: couldn't establish shutdown hook\n",
163 sc->sc_dev.dv_xname);
164 goto err;
165 }
166
167 return;
168
169 err:
170 arbus_intr_disestablish(asc->sc_ih);
171 }
172
173 static int
174 ath_arbus_detach(struct device *self, int flags)
175 {
176 struct ath_arbus_softc *asc = (struct ath_arbus_softc *)self;
177
178 shutdownhook_disestablish(asc->sc_sdhook);
179 ath_detach(&asc->sc_ath);
180 arbus_intr_disestablish(asc->sc_ih);
181
182 return (0);
183 }
184
185 static void
186 ath_arbus_shutdown(void *opaque)
187 {
188 struct ath_arbus_softc *asc = opaque;
189
190 ath_shutdown(&asc->sc_ath);
191
192 return;
193 }
194