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