2011-03-31 08:07:13 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
|
|
|
|
* Copyright (c) 2010-2011 Adrian Chadd, Xenion Pty Ltd
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* without modification.
|
|
|
|
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
|
|
|
|
* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
|
|
|
|
* redistribution must be conditioned upon including a substantially
|
|
|
|
* similar Disclaimer requirement for further binary redistribution.
|
|
|
|
*
|
|
|
|
* NO WARRANTY
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
|
|
|
|
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
|
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGES.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AHB bus front-end for the Atheros Wireless LAN controller driver.
|
|
|
|
*/
|
|
|
|
|
2012-06-24 08:47:19 +00:00
|
|
|
#include "opt_ath.h"
|
|
|
|
|
2011-03-31 08:07:13 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2013-10-28 22:26:03 +00:00
|
|
|
#include <sys/malloc.h>
|
2011-03-31 08:07:13 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_arp.h>
|
2013-10-28 22:26:03 +00:00
|
|
|
#include <net/ethernet.h>
|
2011-03-31 08:07:13 +00:00
|
|
|
|
|
|
|
#include <net80211/ieee80211_var.h>
|
|
|
|
|
|
|
|
#include <dev/ath/if_athvar.h>
|
|
|
|
|
|
|
|
#include <mips/atheros/ar71xxreg.h>
|
|
|
|
#include <mips/atheros/ar91xxreg.h>
|
|
|
|
#include <mips/atheros/ar71xx_cpudef.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bus glue.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* number of 16 bit words */
|
|
|
|
#define ATH_EEPROM_DATA_SIZE 2048
|
|
|
|
|
|
|
|
struct ath_ahb_softc {
|
|
|
|
struct ath_softc sc_sc;
|
|
|
|
struct resource *sc_sr; /* memory resource */
|
|
|
|
struct resource *sc_irq; /* irq resource */
|
|
|
|
struct resource *sc_eeprom; /* eeprom location */
|
|
|
|
void *sc_ih; /* interrupt handler */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VENDOR_ATHEROS 0x168c
|
2011-04-28 12:47:40 +00:00
|
|
|
#define AR9130_DEVID 0x000b
|
2011-03-31 08:07:13 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ath_ahb_probe(device_t dev)
|
|
|
|
{
|
2013-06-26 04:58:25 +00:00
|
|
|
int vendor_id, device_id;
|
2011-03-31 08:07:13 +00:00
|
|
|
const char* devname;
|
|
|
|
|
2013-06-26 04:58:25 +00:00
|
|
|
/*
|
|
|
|
* Check if a device/vendor ID is provided in hints.
|
|
|
|
*/
|
|
|
|
if (resource_int_value(device_get_name(dev), device_get_unit(dev),
|
|
|
|
"vendor_id", &vendor_id) != 0) {
|
|
|
|
vendor_id = VENDOR_ATHEROS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource_int_value(device_get_name(dev), device_get_unit(dev),
|
|
|
|
"device_id", &device_id) != 0) {
|
|
|
|
device_id = AR9130_DEVID;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_printf(dev, "Vendor=0x%04x, Device=0x%04x\n",
|
|
|
|
vendor_id & 0xffff,
|
|
|
|
device_id & 0xffff);
|
|
|
|
|
|
|
|
/* Attempt to probe */
|
|
|
|
devname = ath_hal_probe(vendor_id, device_id);
|
2011-03-31 08:07:13 +00:00
|
|
|
|
|
|
|
if (devname != NULL) {
|
|
|
|
device_set_desc(dev, devname);
|
|
|
|
return BUS_PROBE_DEFAULT;
|
|
|
|
}
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
2015-07-04 03:07:28 +00:00
|
|
|
static void
|
|
|
|
ath_ahb_intr(void *arg)
|
|
|
|
{
|
|
|
|
/* XXX TODO: check if its ours! */
|
|
|
|
ar71xx_device_flush_ddr(AR71XX_CPU_DDR_FLUSH_WMAC);
|
|
|
|
ath_intr(arg);
|
|
|
|
}
|
|
|
|
|
2011-03-31 08:07:13 +00:00
|
|
|
static int
|
|
|
|
ath_ahb_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct ath_ahb_softc *psc = device_get_softc(dev);
|
|
|
|
struct ath_softc *sc = &psc->sc_sc;
|
|
|
|
int error = ENXIO;
|
|
|
|
int rid;
|
|
|
|
long eepromaddr;
|
2013-06-26 04:58:25 +00:00
|
|
|
int eepromsize;
|
2011-03-31 08:07:13 +00:00
|
|
|
uint8_t *p;
|
2013-06-26 04:58:25 +00:00
|
|
|
int device_id, vendor_id;
|
2011-03-31 08:07:13 +00:00
|
|
|
|
|
|
|
sc->sc_dev = dev;
|
|
|
|
|
|
|
|
rid = 0;
|
|
|
|
psc->sc_sr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
|
|
|
|
if (psc->sc_sr == NULL) {
|
|
|
|
device_printf(dev, "cannot map register space\n");
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2013-06-26 04:58:25 +00:00
|
|
|
if (resource_long_value(device_get_name(dev), device_get_unit(dev),
|
|
|
|
"eepromaddr", &eepromaddr) != 0) {
|
2011-03-31 08:07:13 +00:00
|
|
|
device_printf(dev, "cannot fetch 'eepromaddr' from hints\n");
|
|
|
|
goto bad0;
|
2013-06-26 04:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The default EEPROM size is 2048 * 16 bit words.
|
|
|
|
* Later EEPROM/OTP/flash regions may be quite a bit bigger.
|
|
|
|
*/
|
|
|
|
if (resource_int_value(device_get_name(dev), device_get_unit(dev),
|
|
|
|
"eepromsize", &eepromsize) != 0) {
|
|
|
|
eepromsize = ATH_EEPROM_DATA_SIZE * 2;
|
|
|
|
}
|
|
|
|
|
2011-03-31 08:07:13 +00:00
|
|
|
rid = 0;
|
2013-06-26 04:58:25 +00:00
|
|
|
device_printf(sc->sc_dev, "eeprom @ %p (%d bytes)\n",
|
|
|
|
(void *) eepromaddr, eepromsize);
|
2015-03-02 02:14:44 +00:00
|
|
|
/*
|
|
|
|
* XXX this assumes that the parent device is the nexus
|
|
|
|
* and will just pass through requests for all of memory.
|
|
|
|
*
|
|
|
|
* Later on, when this has to attach off of the actual
|
|
|
|
* AHB, this won't work.
|
|
|
|
*
|
|
|
|
* Ideally this would be done in machdep code in mips/atheros/
|
|
|
|
* and it'd expose the EEPROM via the firmware interface,
|
|
|
|
* so the ath/ath_ahb drivers can be loaded as modules
|
|
|
|
* after boot-time.
|
|
|
|
*/
|
|
|
|
psc->sc_eeprom = bus_alloc_resource(dev, SYS_RES_MEMORY,
|
|
|
|
&rid, (uintptr_t) eepromaddr,
|
|
|
|
(uintptr_t) eepromaddr + (uintptr_t) (eepromsize - 1), 0, RF_ACTIVE);
|
2011-06-13 04:31:57 +00:00
|
|
|
if (psc->sc_eeprom == NULL) {
|
2011-03-31 08:07:13 +00:00
|
|
|
device_printf(dev, "cannot map eeprom space\n");
|
|
|
|
goto bad0;
|
|
|
|
}
|
|
|
|
|
2014-07-07 00:27:09 +00:00
|
|
|
sc->sc_st = (HAL_BUS_TAG) rman_get_bustag(psc->sc_sr);
|
2011-03-31 08:07:13 +00:00
|
|
|
sc->sc_sh = (HAL_BUS_HANDLE) rman_get_bushandle(psc->sc_sr);
|
|
|
|
/*
|
|
|
|
* Mark device invalid so any interrupts (shared or otherwise)
|
|
|
|
* that arrive before the HAL is setup are discarded.
|
|
|
|
*/
|
|
|
|
sc->sc_invalid = 1;
|
|
|
|
|
|
|
|
/* Copy the EEPROM data out */
|
2013-06-26 04:58:25 +00:00
|
|
|
sc->sc_eepromdata = malloc(eepromsize, M_TEMP, M_NOWAIT | M_ZERO);
|
2011-06-13 04:31:57 +00:00
|
|
|
if (sc->sc_eepromdata == NULL) {
|
|
|
|
device_printf(dev, "cannot allocate memory for eeprom data\n");
|
|
|
|
goto bad1;
|
|
|
|
}
|
2011-03-31 08:07:13 +00:00
|
|
|
device_printf(sc->sc_dev, "eeprom data @ %p\n", (void *) rman_get_bushandle(psc->sc_eeprom));
|
|
|
|
/* XXX why doesn't this work? -adrian */
|
|
|
|
#if 0
|
|
|
|
bus_space_read_multi_1(
|
|
|
|
rman_get_bustag(psc->sc_eeprom),
|
|
|
|
rman_get_bushandle(psc->sc_eeprom),
|
2013-06-26 04:58:25 +00:00
|
|
|
0, (u_int8_t *) sc->sc_eepromdata, eepromsize);
|
2011-03-31 08:07:13 +00:00
|
|
|
#endif
|
|
|
|
p = (void *) rman_get_bushandle(psc->sc_eeprom);
|
2013-06-26 04:58:25 +00:00
|
|
|
memcpy(sc->sc_eepromdata, p, eepromsize);
|
2011-03-31 08:07:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Arrange interrupt line.
|
|
|
|
*/
|
|
|
|
rid = 0;
|
|
|
|
psc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE|RF_ACTIVE);
|
|
|
|
if (psc->sc_irq == NULL) {
|
|
|
|
device_printf(dev, "could not map interrupt\n");
|
|
|
|
goto bad1;
|
|
|
|
}
|
|
|
|
if (bus_setup_intr(dev, psc->sc_irq,
|
|
|
|
INTR_TYPE_NET | INTR_MPSAFE,
|
2015-07-04 03:07:28 +00:00
|
|
|
NULL, ath_ahb_intr, sc, &psc->sc_ih)) {
|
2011-03-31 08:07:13 +00:00
|
|
|
device_printf(dev, "could not establish interrupt\n");
|
|
|
|
goto bad2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup DMA descriptor area.
|
|
|
|
*/
|
|
|
|
if (bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
|
|
|
|
1, 0, /* alignment, bounds */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
0x3ffff, /* maxsize XXX */
|
|
|
|
ATH_MAX_SCATTER, /* nsegments */
|
|
|
|
0x3ffff, /* maxsegsize XXX */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
|
|
|
NULL, /* lockfunc */
|
|
|
|
NULL, /* lockarg */
|
|
|
|
&sc->sc_dmat)) {
|
|
|
|
device_printf(dev, "cannot allocate DMA tag\n");
|
|
|
|
goto bad3;
|
|
|
|
}
|
|
|
|
|
2013-06-26 04:58:25 +00:00
|
|
|
/*
|
|
|
|
* Check if a device/vendor ID is provided in hints.
|
|
|
|
*/
|
|
|
|
if (resource_int_value(device_get_name(dev), device_get_unit(dev),
|
|
|
|
"vendor_id", &vendor_id) != 0) {
|
|
|
|
vendor_id = VENDOR_ATHEROS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource_int_value(device_get_name(dev), device_get_unit(dev),
|
|
|
|
"device_id", &device_id) != 0) {
|
|
|
|
device_id = AR9130_DEVID;
|
|
|
|
}
|
|
|
|
|
2011-03-31 08:07:13 +00:00
|
|
|
ATH_LOCK_INIT(sc);
|
2011-11-08 02:12:11 +00:00
|
|
|
ATH_PCU_LOCK_INIT(sc);
|
2012-07-14 02:22:17 +00:00
|
|
|
ATH_RX_LOCK_INIT(sc);
|
2012-10-31 06:27:58 +00:00
|
|
|
ATH_TX_LOCK_INIT(sc);
|
2013-02-07 07:50:16 +00:00
|
|
|
ATH_TX_IC_LOCK_INIT(sc);
|
2012-07-23 02:49:25 +00:00
|
|
|
ATH_TXSTATUS_LOCK_INIT(sc);
|
2011-03-31 08:07:13 +00:00
|
|
|
|
2013-06-26 04:58:25 +00:00
|
|
|
error = ath_attach(device_id, sc);
|
2011-03-31 08:07:13 +00:00
|
|
|
if (error == 0) /* success */
|
|
|
|
return 0;
|
|
|
|
|
2012-07-23 02:49:25 +00:00
|
|
|
ATH_TXSTATUS_LOCK_DESTROY(sc);
|
2012-07-14 02:22:17 +00:00
|
|
|
ATH_RX_LOCK_DESTROY(sc);
|
2012-10-31 06:27:58 +00:00
|
|
|
ATH_TX_LOCK_DESTROY(sc);
|
2013-02-07 07:50:16 +00:00
|
|
|
ATH_TX_IC_LOCK_DESTROY(sc);
|
2011-11-08 02:12:11 +00:00
|
|
|
ATH_PCU_LOCK_DESTROY(sc);
|
2011-03-31 08:07:13 +00:00
|
|
|
ATH_LOCK_DESTROY(sc);
|
|
|
|
bus_dma_tag_destroy(sc->sc_dmat);
|
|
|
|
bad3:
|
|
|
|
bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
|
|
|
|
bad2:
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, psc->sc_irq);
|
|
|
|
bad1:
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_eeprom);
|
|
|
|
bad0:
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_sr);
|
|
|
|
bad:
|
|
|
|
/* XXX?! */
|
|
|
|
if (sc->sc_eepromdata)
|
|
|
|
free(sc->sc_eepromdata, M_TEMP);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ath_ahb_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct ath_ahb_softc *psc = device_get_softc(dev);
|
|
|
|
struct ath_softc *sc = &psc->sc_sc;
|
|
|
|
|
|
|
|
/* check if device was removed */
|
|
|
|
sc->sc_invalid = !bus_child_present(dev);
|
|
|
|
|
|
|
|
ath_detach(sc);
|
|
|
|
|
|
|
|
bus_generic_detach(dev);
|
|
|
|
bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, psc->sc_irq);
|
|
|
|
|
|
|
|
bus_dma_tag_destroy(sc->sc_dmat);
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_sr);
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_eeprom);
|
|
|
|
/* XXX?! */
|
|
|
|
if (sc->sc_eepromdata)
|
|
|
|
free(sc->sc_eepromdata, M_TEMP);
|
|
|
|
|
2012-07-23 02:49:25 +00:00
|
|
|
ATH_TXSTATUS_LOCK_DESTROY(sc);
|
2012-07-14 02:22:17 +00:00
|
|
|
ATH_RX_LOCK_DESTROY(sc);
|
2012-10-31 06:27:58 +00:00
|
|
|
ATH_TX_LOCK_DESTROY(sc);
|
2013-02-07 07:50:16 +00:00
|
|
|
ATH_TX_IC_LOCK_DESTROY(sc);
|
2011-11-08 02:12:11 +00:00
|
|
|
ATH_PCU_LOCK_DESTROY(sc);
|
2011-03-31 08:07:13 +00:00
|
|
|
ATH_LOCK_DESTROY(sc);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ath_ahb_shutdown(device_t dev)
|
|
|
|
{
|
|
|
|
struct ath_ahb_softc *psc = device_get_softc(dev);
|
|
|
|
|
|
|
|
ath_shutdown(&psc->sc_sc);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ath_ahb_suspend(device_t dev)
|
|
|
|
{
|
|
|
|
struct ath_ahb_softc *psc = device_get_softc(dev);
|
|
|
|
|
|
|
|
ath_suspend(&psc->sc_sc);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ath_ahb_resume(device_t dev)
|
|
|
|
{
|
|
|
|
struct ath_ahb_softc *psc = device_get_softc(dev);
|
|
|
|
|
|
|
|
ath_resume(&psc->sc_sc);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t ath_ahb_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, ath_ahb_probe),
|
|
|
|
DEVMETHOD(device_attach, ath_ahb_attach),
|
|
|
|
DEVMETHOD(device_detach, ath_ahb_detach),
|
|
|
|
DEVMETHOD(device_shutdown, ath_ahb_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, ath_ahb_suspend),
|
|
|
|
DEVMETHOD(device_resume, ath_ahb_resume),
|
|
|
|
|
|
|
|
{ 0,0 }
|
|
|
|
};
|
|
|
|
static driver_t ath_ahb_driver = {
|
|
|
|
"ath",
|
|
|
|
ath_ahb_methods,
|
|
|
|
sizeof (struct ath_ahb_softc)
|
|
|
|
};
|
|
|
|
static devclass_t ath_devclass;
|
|
|
|
DRIVER_MODULE(ath, nexus, ath_ahb_driver, ath_devclass, 0, 0);
|
2015-03-02 02:14:44 +00:00
|
|
|
DRIVER_MODULE(ath, apb, ath_ahb_driver, ath_devclass, 0, 0);
|
2011-03-31 08:07:13 +00:00
|
|
|
MODULE_VERSION(ath, 1);
|
|
|
|
MODULE_DEPEND(ath, wlan, 1, 1, 1); /* 802.11 media layer */
|
|
|
|
MODULE_DEPEND(ath, if_ath, 1, 1, 1); /* if_ath driver */
|