if_ath_arbus.c revision 1.13 1 /* $NetBSD: if_ath_arbus.c,v 1.13 2008/04/28 20:23:28 martin 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 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: if_ath_arbus.c,v 1.13 2008/04/28 20:23:28 martin Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 #include <sys/mbuf.h>
36 #include <sys/malloc.h>
37 #include <sys/kernel.h>
38 #include <sys/errno.h>
39
40 #include <machine/bus.h>
41 #include <machine/intr.h>
42
43 #include <net/if.h>
44 #include <net/if_media.h>
45 #include <net/if_ether.h>
46 #include <net/if_llc.h>
47 #include <net/if_arp.h>
48
49 #include <netinet/in.h>
50
51 #include <net80211/ieee80211_netbsd.h>
52 #include <net80211/ieee80211_var.h>
53
54 #include <mips/atheros/include/ar531xvar.h>
55 #include <mips/atheros/include/arbusvar.h>
56
57 #include <dev/pci/pcidevs.h>
58 #include <dev/ic/ath_netbsd.h>
59 #include <dev/ic/athvar.h>
60 #include <contrib/dev/ath/ah.h>
61 #include <contrib/dev/ath/ah_soc.h> /* XXX really doesn't belong in hal */
62
63 struct ath_arbus_softc {
64 struct ath_softc sc_ath;
65 bus_space_tag_t sc_iot;
66 bus_space_handle_t sc_ioh;
67 void *sc_ih;
68 struct ar531x_config sc_config;
69 };
70
71 static int ath_arbus_match(device_t, struct cfdata *, void *);
72 static void ath_arbus_attach(device_t, device_t, void *);
73 static int ath_arbus_detach(device_t, int);
74
75 CFATTACH_DECL(ath_arbus, sizeof(struct ath_arbus_softc),
76 ath_arbus_match, ath_arbus_attach, ath_arbus_detach, NULL);
77
78 static int
79 ath_arbus_match(device_t parent, struct cfdata *cf, void *opaque)
80 {
81 struct arbus_attach_args *aa;
82
83 aa = (struct arbus_attach_args *)opaque;
84 if (strcmp(aa->aa_name, "ath") == 0)
85 return 1;
86
87 return 0;
88 }
89
90 static bool
91 ath_arbus_resume(device_t dv PMF_FN_ARGS)
92 {
93 struct ath_arbus_softc *asc = device_private(dv);
94 ath_resume(&asc->sc_ath);
95
96 return true;
97 }
98
99
100 static void
101 ath_arbus_attach(device_t parent, device_t self, void *opaque)
102 {
103 struct ath_arbus_softc *asc;
104 struct ath_softc *sc;
105 struct arbus_attach_args *aa;
106 const char *name;
107 prop_number_t prop;
108 int rv;
109 uint16_t devid;
110
111 asc = device_private(self);
112 sc = &asc->sc_ath;
113 aa = (struct arbus_attach_args *)opaque;
114
115 prop = prop_dictionary_get(device_properties(&sc->sc_dev),
116 "wmac-rev");
117 if (prop == NULL) {
118 printf(": unable to get wmac-rev property\n");
119 return;
120 }
121 KDASSERT(prop_object_type(prop) == PROP_TYPE_NUMBER);
122
123 devid = (uint16_t)prop_number_integer_value(prop);
124 name = ath_hal_probe(PCI_VENDOR_ATHEROS, devid);
125
126 printf(": %s\n", name ? name : "Unknown AR531X WLAN");
127
128 asc->sc_iot = aa->aa_bst;
129 rv = bus_space_map(asc->sc_iot, aa->aa_addr, aa->aa_size, 0,
130 &asc->sc_ioh);
131 if (rv) {
132 aprint_error("%s: unable to map registers\n",
133 sc->sc_dev.dv_xname);
134 return;
135 }
136 /*
137 * Setup HAL configuration state for use by the driver.
138 */
139 rv = ar531x_board_config(&asc->sc_config);
140 if (rv) {
141 aprint_error("%s: unable to locate board configuration\n",
142 sc->sc_dev.dv_xname);
143 return;
144 }
145 asc->sc_config.unit = sc->sc_dev.dv_unit; /* XXX? */
146 asc->sc_config.tag = asc->sc_iot;
147
148 /* NB: the HAL expects the config state passed as the tag */
149 sc->sc_st = (HAL_BUS_TAG) &asc->sc_config;
150 sc->sc_sh = (HAL_BUS_HANDLE) asc->sc_ioh;
151 sc->sc_dmat = aa->aa_dmat;
152
153 asc->sc_ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ath_intr,
154 sc);
155 if (asc->sc_ih == NULL) {
156 aprint_error("%s: couldn't establish interrupt\n",
157 sc->sc_dev.dv_xname);
158 return;
159 }
160
161 ATH_LOCK_INIT(sc);
162
163 if (!pmf_device_register(self, NULL, ath_arbus_resume))
164 aprint_error_dev(self, "couldn't establish power handler\n");
165 else
166 pmf_class_network_register(self, &sc->sc_if);
167
168 if (ath_attach(devid, sc) != 0) {
169 aprint_error("%s: ath_attach failed\n", sc->sc_dev.dv_xname);
170 goto err;
171 }
172
173 return;
174
175 err:
176 arbus_intr_disestablish(asc->sc_ih);
177 }
178
179 static int
180 ath_arbus_detach(device_t self, int flags)
181 {
182 struct ath_arbus_softc *asc = device_private(self);
183
184 ath_detach(&asc->sc_ath);
185 arbus_intr_disestablish(asc->sc_ih);
186
187 return (0);
188 }
189