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