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