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