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