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