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