From owner-svn-src-user@FreeBSD.ORG Sun Aug 22 16:03:33 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5B75C1065693; Sun, 22 Aug 2010 16:03:33 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4ABDA8FC13; Sun, 22 Aug 2010 16:03:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7MG3X5K008192; Sun, 22 Aug 2010 16:03:33 GMT (envelope-from adrian@svn.freebsd.org) Received: (from adrian@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7MG3X8p008190; Sun, 22 Aug 2010 16:03:33 GMT (envelope-from adrian@svn.freebsd.org) Message-Id: <201008221603.o7MG3X8p008190@svn.freebsd.org> From: Adrian Chadd Date: Sun, 22 Aug 2010 16:03:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211625 - user/adrian/if_ath_devel/sys/dev/ath X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Aug 2010 16:03:33 -0000 Author: adrian Date: Sun Aug 22 16:03:33 2010 New Revision: 211625 URL: http://svn.freebsd.org/changeset/base/211625 Log: Add some glue to shim ath direct into a SoC setup. This doesn't include the stuff needed for eeprom support. Added: user/adrian/if_ath_devel/sys/dev/ath/if_ath_ahb.c Added: user/adrian/if_ath_devel/sys/dev/ath/if_ath_ahb.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/adrian/if_ath_devel/sys/dev/ath/if_ath_ahb.c Sun Aug 22 16:03:33 2010 (r211625) @@ -0,0 +1,244 @@ +/*- + * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting + * Copyright (c) 2010 Adrian Chadd + * 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 +__FBSDID("$FreeBSD$"); + +/* + * SoC (ar91xx) front-end for the Atheros Wireless LAN controller driver. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + +#include + +#include +#include +#include + +/* + * bus glue. + */ + +struct ath_ahb_softc { + struct ath_softc sc_sc; + struct resource *sc_sr; /* memory resource */ + struct resource *sc_irq; /* irq resource */ + void *sc_ih; /* interrupt handler */ +}; + +#define VENDOR_ATHEROS 0x168c +#define AR9100_DEVID 0x000b + +static int +ath_ahb_probe(device_t dev) +{ + const char* devname; + + /* Atheros / ar9100 */ + devname = ath_hal_probe(VENDOR_ATHEROS, AR9100_DEVID); + + if (devname != NULL) { + device_set_desc(dev, devname); + return BUS_PROBE_DEFAULT; + } + return ENXIO; +} + +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; + + 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; + } + + /* XXX uintptr_t is a bandaid for ia64; to be fixed */ + sc->sc_st = (HAL_BUS_TAG)(uintptr_t) rman_get_bustag(psc->sc_sr); + 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; + + /* + * 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, + NULL, ath_intr, sc, &psc->sc_ih)) { + 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; + } + + ATH_LOCK_INIT(sc); + + error = ath_attach(AR9100_DEVID, sc); + if (error == 0) /* success */ + return 0; + + 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, BS_BAR, psc->sc_sr); +bad: + 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, BS_BAR, psc->sc_sr); + + 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); +MODULE_VERSION(ath, 1); +MODULE_DEPEND(ath, wlan, 1, 1, 1); /* 802.11 media layer */