Deleted Added
full compact
if_ath_ahb.c (221163) if_ath_ahb.c (223032)
1/*-
2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2010-2011 Adrian Chadd, Xenion Pty Ltd
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
14 * redistribution must be conditioned upon including a substantially
15 * similar Disclaimer requirement for further binary redistribution.
16 *
17 * NO WARRANTY
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
21 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
23 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGES.
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2010-2011 Adrian Chadd, Xenion Pty Ltd
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
14 * redistribution must be conditioned upon including a substantially
15 * similar Disclaimer requirement for further binary redistribution.
16 *
17 * NO WARRANTY
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
21 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
23 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGES.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/ath/if_ath_ahb.c 221163 2011-04-28 12:47:40Z adrian $");
32__FBSDID("$FreeBSD: head/sys/dev/ath/if_ath_ahb.c 223032 2011-06-13 04:31:57Z adrian $");
33
34/*
35 * AHB bus front-end for the Atheros Wireless LAN controller driver.
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/module.h>
41#include <sys/kernel.h>
42#include <sys/lock.h>
43#include <sys/mutex.h>
44#include <sys/errno.h>
45
46#include <machine/bus.h>
47#include <machine/resource.h>
48#include <sys/bus.h>
49#include <sys/rman.h>
50
51#include <sys/socket.h>
52
53#include <net/if.h>
54#include <net/if_media.h>
55#include <net/if_arp.h>
56
57#include <net80211/ieee80211_var.h>
58
59#include <dev/ath/if_athvar.h>
60
61#include <mips/atheros/ar71xxreg.h>
62#include <mips/atheros/ar91xxreg.h>
63#include <mips/atheros/ar71xx_cpudef.h>
64
65/*
66 * bus glue.
67 */
68
69/* number of 16 bit words */
70#define ATH_EEPROM_DATA_SIZE 2048
71
72struct ath_ahb_softc {
73 struct ath_softc sc_sc;
74 struct resource *sc_sr; /* memory resource */
75 struct resource *sc_irq; /* irq resource */
76 struct resource *sc_eeprom; /* eeprom location */
77 void *sc_ih; /* interrupt handler */
78};
79
80#define VENDOR_ATHEROS 0x168c
81#define AR9130_DEVID 0x000b
82
83static int
84ath_ahb_probe(device_t dev)
85{
86 const char* devname;
87
88 /* Atheros / ar9130 */
89 devname = ath_hal_probe(VENDOR_ATHEROS, AR9130_DEVID);
90
91 if (devname != NULL) {
92 device_set_desc(dev, devname);
93 return BUS_PROBE_DEFAULT;
94 }
95 return ENXIO;
96}
97
98static int
99ath_ahb_attach(device_t dev)
100{
101 struct ath_ahb_softc *psc = device_get_softc(dev);
102 struct ath_softc *sc = &psc->sc_sc;
103 int error = ENXIO;
104 int rid;
105 long eepromaddr;
106 uint8_t *p;
107
108 sc->sc_dev = dev;
109
110 rid = 0;
111 psc->sc_sr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
112 if (psc->sc_sr == NULL) {
113 device_printf(dev, "cannot map register space\n");
114 goto bad;
115 }
116
117 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
118 "eepromaddr", &eepromaddr) != 0) {
119 device_printf(dev, "cannot fetch 'eepromaddr' from hints\n");
120 goto bad0;
121 }
122 rid = 0;
123 device_printf(sc->sc_dev, "eeprom @ %p\n", (void *) eepromaddr);
124 psc->sc_eeprom = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, (uintptr_t) eepromaddr,
125 (uintptr_t) eepromaddr + (uintptr_t) ((ATH_EEPROM_DATA_SIZE * 2) - 1), 0, RF_ACTIVE);
33
34/*
35 * AHB bus front-end for the Atheros Wireless LAN controller driver.
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/module.h>
41#include <sys/kernel.h>
42#include <sys/lock.h>
43#include <sys/mutex.h>
44#include <sys/errno.h>
45
46#include <machine/bus.h>
47#include <machine/resource.h>
48#include <sys/bus.h>
49#include <sys/rman.h>
50
51#include <sys/socket.h>
52
53#include <net/if.h>
54#include <net/if_media.h>
55#include <net/if_arp.h>
56
57#include <net80211/ieee80211_var.h>
58
59#include <dev/ath/if_athvar.h>
60
61#include <mips/atheros/ar71xxreg.h>
62#include <mips/atheros/ar91xxreg.h>
63#include <mips/atheros/ar71xx_cpudef.h>
64
65/*
66 * bus glue.
67 */
68
69/* number of 16 bit words */
70#define ATH_EEPROM_DATA_SIZE 2048
71
72struct ath_ahb_softc {
73 struct ath_softc sc_sc;
74 struct resource *sc_sr; /* memory resource */
75 struct resource *sc_irq; /* irq resource */
76 struct resource *sc_eeprom; /* eeprom location */
77 void *sc_ih; /* interrupt handler */
78};
79
80#define VENDOR_ATHEROS 0x168c
81#define AR9130_DEVID 0x000b
82
83static int
84ath_ahb_probe(device_t dev)
85{
86 const char* devname;
87
88 /* Atheros / ar9130 */
89 devname = ath_hal_probe(VENDOR_ATHEROS, AR9130_DEVID);
90
91 if (devname != NULL) {
92 device_set_desc(dev, devname);
93 return BUS_PROBE_DEFAULT;
94 }
95 return ENXIO;
96}
97
98static int
99ath_ahb_attach(device_t dev)
100{
101 struct ath_ahb_softc *psc = device_get_softc(dev);
102 struct ath_softc *sc = &psc->sc_sc;
103 int error = ENXIO;
104 int rid;
105 long eepromaddr;
106 uint8_t *p;
107
108 sc->sc_dev = dev;
109
110 rid = 0;
111 psc->sc_sr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
112 if (psc->sc_sr == NULL) {
113 device_printf(dev, "cannot map register space\n");
114 goto bad;
115 }
116
117 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
118 "eepromaddr", &eepromaddr) != 0) {
119 device_printf(dev, "cannot fetch 'eepromaddr' from hints\n");
120 goto bad0;
121 }
122 rid = 0;
123 device_printf(sc->sc_dev, "eeprom @ %p\n", (void *) eepromaddr);
124 psc->sc_eeprom = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, (uintptr_t) eepromaddr,
125 (uintptr_t) eepromaddr + (uintptr_t) ((ATH_EEPROM_DATA_SIZE * 2) - 1), 0, RF_ACTIVE);
126 if (psc->sc_sr == NULL) {
126 if (psc->sc_eeprom == NULL) {
127 device_printf(dev, "cannot map eeprom space\n");
128 goto bad0;
129 }
130
131 /* XXX uintptr_t is a bandaid for ia64; to be fixed */
132 sc->sc_st = (HAL_BUS_TAG)(uintptr_t) rman_get_bustag(psc->sc_sr);
133 sc->sc_sh = (HAL_BUS_HANDLE) rman_get_bushandle(psc->sc_sr);
134 /*
135 * Mark device invalid so any interrupts (shared or otherwise)
136 * that arrive before the HAL is setup are discarded.
137 */
138 sc->sc_invalid = 1;
139
140 /* Copy the EEPROM data out */
141 sc->sc_eepromdata = malloc(ATH_EEPROM_DATA_SIZE * 2, M_TEMP, M_NOWAIT | M_ZERO);
127 device_printf(dev, "cannot map eeprom space\n");
128 goto bad0;
129 }
130
131 /* XXX uintptr_t is a bandaid for ia64; to be fixed */
132 sc->sc_st = (HAL_BUS_TAG)(uintptr_t) rman_get_bustag(psc->sc_sr);
133 sc->sc_sh = (HAL_BUS_HANDLE) rman_get_bushandle(psc->sc_sr);
134 /*
135 * Mark device invalid so any interrupts (shared or otherwise)
136 * that arrive before the HAL is setup are discarded.
137 */
138 sc->sc_invalid = 1;
139
140 /* Copy the EEPROM data out */
141 sc->sc_eepromdata = malloc(ATH_EEPROM_DATA_SIZE * 2, M_TEMP, M_NOWAIT | M_ZERO);
142 if (sc->sc_eepromdata == NULL) {
143 device_printf(dev, "cannot allocate memory for eeprom data\n");
144 goto bad1;
145 }
142 device_printf(sc->sc_dev, "eeprom data @ %p\n", (void *) rman_get_bushandle(psc->sc_eeprom));
143 /* XXX why doesn't this work? -adrian */
144#if 0
145 bus_space_read_multi_1(
146 rman_get_bustag(psc->sc_eeprom),
147 rman_get_bushandle(psc->sc_eeprom),
148 0, (u_int8_t *) sc->sc_eepromdata, ATH_EEPROM_DATA_SIZE * 2);
149#endif
150 p = (void *) rman_get_bushandle(psc->sc_eeprom);
151 memcpy(sc->sc_eepromdata, p, ATH_EEPROM_DATA_SIZE * 2);
152
153 /*
154 * Arrange interrupt line.
155 */
156 rid = 0;
157 psc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE|RF_ACTIVE);
158 if (psc->sc_irq == NULL) {
159 device_printf(dev, "could not map interrupt\n");
160 goto bad1;
161 }
162 if (bus_setup_intr(dev, psc->sc_irq,
163 INTR_TYPE_NET | INTR_MPSAFE,
164 NULL, ath_intr, sc, &psc->sc_ih)) {
165 device_printf(dev, "could not establish interrupt\n");
166 goto bad2;
167 }
168
169 /*
170 * Setup DMA descriptor area.
171 */
172 if (bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
173 1, 0, /* alignment, bounds */
174 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
175 BUS_SPACE_MAXADDR, /* highaddr */
176 NULL, NULL, /* filter, filterarg */
177 0x3ffff, /* maxsize XXX */
178 ATH_MAX_SCATTER, /* nsegments */
179 0x3ffff, /* maxsegsize XXX */
180 BUS_DMA_ALLOCNOW, /* flags */
181 NULL, /* lockfunc */
182 NULL, /* lockarg */
183 &sc->sc_dmat)) {
184 device_printf(dev, "cannot allocate DMA tag\n");
185 goto bad3;
186 }
187
188 ATH_LOCK_INIT(sc);
189
190 error = ath_attach(AR9130_DEVID, sc);
191 if (error == 0) /* success */
192 return 0;
193
194 ATH_LOCK_DESTROY(sc);
195 bus_dma_tag_destroy(sc->sc_dmat);
196bad3:
197 bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
198bad2:
199 bus_release_resource(dev, SYS_RES_IRQ, 0, psc->sc_irq);
200bad1:
201 bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_eeprom);
202bad0:
203 bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_sr);
204bad:
205 /* XXX?! */
206 if (sc->sc_eepromdata)
207 free(sc->sc_eepromdata, M_TEMP);
208 return (error);
209}
210
211static int
212ath_ahb_detach(device_t dev)
213{
214 struct ath_ahb_softc *psc = device_get_softc(dev);
215 struct ath_softc *sc = &psc->sc_sc;
216
217 /* check if device was removed */
218 sc->sc_invalid = !bus_child_present(dev);
219
220 ath_detach(sc);
221
222 bus_generic_detach(dev);
223 bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
224 bus_release_resource(dev, SYS_RES_IRQ, 0, psc->sc_irq);
225
226 bus_dma_tag_destroy(sc->sc_dmat);
227 bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_sr);
228 bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_eeprom);
229 /* XXX?! */
230 if (sc->sc_eepromdata)
231 free(sc->sc_eepromdata, M_TEMP);
232
233 ATH_LOCK_DESTROY(sc);
234
235 return (0);
236}
237
238static int
239ath_ahb_shutdown(device_t dev)
240{
241 struct ath_ahb_softc *psc = device_get_softc(dev);
242
243 ath_shutdown(&psc->sc_sc);
244 return (0);
245}
246
247static int
248ath_ahb_suspend(device_t dev)
249{
250 struct ath_ahb_softc *psc = device_get_softc(dev);
251
252 ath_suspend(&psc->sc_sc);
253
254 return (0);
255}
256
257static int
258ath_ahb_resume(device_t dev)
259{
260 struct ath_ahb_softc *psc = device_get_softc(dev);
261
262 ath_resume(&psc->sc_sc);
263
264 return (0);
265}
266
267static device_method_t ath_ahb_methods[] = {
268 /* Device interface */
269 DEVMETHOD(device_probe, ath_ahb_probe),
270 DEVMETHOD(device_attach, ath_ahb_attach),
271 DEVMETHOD(device_detach, ath_ahb_detach),
272 DEVMETHOD(device_shutdown, ath_ahb_shutdown),
273 DEVMETHOD(device_suspend, ath_ahb_suspend),
274 DEVMETHOD(device_resume, ath_ahb_resume),
275
276 { 0,0 }
277};
278static driver_t ath_ahb_driver = {
279 "ath",
280 ath_ahb_methods,
281 sizeof (struct ath_ahb_softc)
282};
283static devclass_t ath_devclass;
284DRIVER_MODULE(ath, nexus, ath_ahb_driver, ath_devclass, 0, 0);
285MODULE_VERSION(ath, 1);
286MODULE_DEPEND(ath, wlan, 1, 1, 1); /* 802.11 media layer */
287MODULE_DEPEND(ath, if_ath, 1, 1, 1); /* if_ath driver */
146 device_printf(sc->sc_dev, "eeprom data @ %p\n", (void *) rman_get_bushandle(psc->sc_eeprom));
147 /* XXX why doesn't this work? -adrian */
148#if 0
149 bus_space_read_multi_1(
150 rman_get_bustag(psc->sc_eeprom),
151 rman_get_bushandle(psc->sc_eeprom),
152 0, (u_int8_t *) sc->sc_eepromdata, ATH_EEPROM_DATA_SIZE * 2);
153#endif
154 p = (void *) rman_get_bushandle(psc->sc_eeprom);
155 memcpy(sc->sc_eepromdata, p, ATH_EEPROM_DATA_SIZE * 2);
156
157 /*
158 * Arrange interrupt line.
159 */
160 rid = 0;
161 psc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE|RF_ACTIVE);
162 if (psc->sc_irq == NULL) {
163 device_printf(dev, "could not map interrupt\n");
164 goto bad1;
165 }
166 if (bus_setup_intr(dev, psc->sc_irq,
167 INTR_TYPE_NET | INTR_MPSAFE,
168 NULL, ath_intr, sc, &psc->sc_ih)) {
169 device_printf(dev, "could not establish interrupt\n");
170 goto bad2;
171 }
172
173 /*
174 * Setup DMA descriptor area.
175 */
176 if (bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
177 1, 0, /* alignment, bounds */
178 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
179 BUS_SPACE_MAXADDR, /* highaddr */
180 NULL, NULL, /* filter, filterarg */
181 0x3ffff, /* maxsize XXX */
182 ATH_MAX_SCATTER, /* nsegments */
183 0x3ffff, /* maxsegsize XXX */
184 BUS_DMA_ALLOCNOW, /* flags */
185 NULL, /* lockfunc */
186 NULL, /* lockarg */
187 &sc->sc_dmat)) {
188 device_printf(dev, "cannot allocate DMA tag\n");
189 goto bad3;
190 }
191
192 ATH_LOCK_INIT(sc);
193
194 error = ath_attach(AR9130_DEVID, sc);
195 if (error == 0) /* success */
196 return 0;
197
198 ATH_LOCK_DESTROY(sc);
199 bus_dma_tag_destroy(sc->sc_dmat);
200bad3:
201 bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
202bad2:
203 bus_release_resource(dev, SYS_RES_IRQ, 0, psc->sc_irq);
204bad1:
205 bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_eeprom);
206bad0:
207 bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_sr);
208bad:
209 /* XXX?! */
210 if (sc->sc_eepromdata)
211 free(sc->sc_eepromdata, M_TEMP);
212 return (error);
213}
214
215static int
216ath_ahb_detach(device_t dev)
217{
218 struct ath_ahb_softc *psc = device_get_softc(dev);
219 struct ath_softc *sc = &psc->sc_sc;
220
221 /* check if device was removed */
222 sc->sc_invalid = !bus_child_present(dev);
223
224 ath_detach(sc);
225
226 bus_generic_detach(dev);
227 bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
228 bus_release_resource(dev, SYS_RES_IRQ, 0, psc->sc_irq);
229
230 bus_dma_tag_destroy(sc->sc_dmat);
231 bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_sr);
232 bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_eeprom);
233 /* XXX?! */
234 if (sc->sc_eepromdata)
235 free(sc->sc_eepromdata, M_TEMP);
236
237 ATH_LOCK_DESTROY(sc);
238
239 return (0);
240}
241
242static int
243ath_ahb_shutdown(device_t dev)
244{
245 struct ath_ahb_softc *psc = device_get_softc(dev);
246
247 ath_shutdown(&psc->sc_sc);
248 return (0);
249}
250
251static int
252ath_ahb_suspend(device_t dev)
253{
254 struct ath_ahb_softc *psc = device_get_softc(dev);
255
256 ath_suspend(&psc->sc_sc);
257
258 return (0);
259}
260
261static int
262ath_ahb_resume(device_t dev)
263{
264 struct ath_ahb_softc *psc = device_get_softc(dev);
265
266 ath_resume(&psc->sc_sc);
267
268 return (0);
269}
270
271static device_method_t ath_ahb_methods[] = {
272 /* Device interface */
273 DEVMETHOD(device_probe, ath_ahb_probe),
274 DEVMETHOD(device_attach, ath_ahb_attach),
275 DEVMETHOD(device_detach, ath_ahb_detach),
276 DEVMETHOD(device_shutdown, ath_ahb_shutdown),
277 DEVMETHOD(device_suspend, ath_ahb_suspend),
278 DEVMETHOD(device_resume, ath_ahb_resume),
279
280 { 0,0 }
281};
282static driver_t ath_ahb_driver = {
283 "ath",
284 ath_ahb_methods,
285 sizeof (struct ath_ahb_softc)
286};
287static devclass_t ath_devclass;
288DRIVER_MODULE(ath, nexus, ath_ahb_driver, ath_devclass, 0, 0);
289MODULE_VERSION(ath, 1);
290MODULE_DEPEND(ath, wlan, 1, 1, 1); /* 802.11 media layer */
291MODULE_DEPEND(ath, if_ath, 1, 1, 1); /* if_ath driver */