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