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