2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15 * redistribution must be conditioned upon including a substantially
16 * similar Disclaimer requirement for further binary redistribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
24 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 * THE POSSIBILITY OF SUCH DAMAGES.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
36 * Driver for the Atheros Wireless LAN controller.
38 * This software is derived from work of Atsushi Onoe; his contribution
39 * is greatly appreciated.
45 * This is needed for register operations which are performed
46 * by the driver - eg, calls to ath_hal_gettsf32().
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/sysctl.h>
55 #include <sys/malloc.h>
57 #include <sys/mutex.h>
58 #include <sys/kernel.h>
59 #include <sys/socket.h>
60 #include <sys/sockio.h>
61 #include <sys/errno.h>
62 #include <sys/callout.h>
64 #include <sys/endian.h>
65 #include <sys/kthread.h>
66 #include <sys/taskqueue.h>
68 #include <sys/module.h>
70 #include <sys/smp.h> /* for mp_ncpus */
72 #include <machine/bus.h>
75 #include <net/if_dl.h>
76 #include <net/if_media.h>
77 #include <net/if_types.h>
78 #include <net/if_arp.h>
79 #include <net/ethernet.h>
80 #include <net/if_llc.h>
82 #include <net80211/ieee80211_var.h>
83 #include <net80211/ieee80211_regdomain.h>
84 #ifdef IEEE80211_SUPPORT_SUPERG
85 #include <net80211/ieee80211_superg.h>
87 #ifdef IEEE80211_SUPPORT_TDMA
88 #include <net80211/ieee80211_tdma.h>
94 #include <netinet/in.h>
95 #include <netinet/if_ether.h>
98 #include <dev/ath/if_athvar.h>
99 #include <dev/ath/ath_hal/ah_devid.h> /* XXX for softled */
100 #include <dev/ath/ath_hal/ah_diagcodes.h>
102 #include <dev/ath/if_ath_debug.h>
103 #include <dev/ath/if_ath_misc.h>
105 #include <dev/ath/if_ath_led.h>
108 * Software LED driver routines.
112 * XXX TODO: move the LED sysctls here.
117 * Configure the hardware for software and LED blinking.
118 * The user may choose to configure part of each, depending upon the
121 * This requires the configuration to be set before this function
125 ath_led_config(struct ath_softc *sc)
129 ath_power_set_power_state(sc, HAL_PM_AWAKE);
132 /* Software LED blinking - GPIO controlled LED */
133 if (sc->sc_softled) {
134 ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_ledpin,
135 HAL_GPIO_OUTPUT_MUX_AS_OUTPUT);
136 ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, !sc->sc_ledon);
139 /* Hardware LED blinking - MAC controlled LED */
140 if (sc->sc_hardled) {
142 * Only enable each LED if required.
144 * Some NICs only have one LED connected; others may
145 * have GPIO1/GPIO2 connected to other hardware.
147 if (sc->sc_led_pwr_pin > 0)
148 ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_led_pwr_pin,
149 HAL_GPIO_OUTPUT_MUX_MAC_POWER_LED);
150 if (sc->sc_led_net_pin > 0)
151 ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_led_net_pin,
152 HAL_GPIO_OUTPUT_MUX_MAC_NETWORK_LED);
156 ath_power_restore_power_state(sc);
161 ath_led_done(void *arg)
163 struct ath_softc *sc = arg;
169 * Turn the LED off: flip the pin and then set a timer so no
170 * update will happen for the specified duration.
173 ath_led_off(void *arg)
175 struct ath_softc *sc = arg;
177 ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, !sc->sc_ledon);
178 callout_reset(&sc->sc_ledtimer, sc->sc_ledoff, ath_led_done, sc);
182 * Blink the LED according to the specified on/off times.
185 ath_led_blink(struct ath_softc *sc, int on, int off)
187 DPRINTF(sc, ATH_DEBUG_LED, "%s: on %u off %u\n", __func__, on, off);
188 ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, sc->sc_ledon);
191 callout_reset(&sc->sc_ledtimer, on, ath_led_off, sc);
195 ath_led_event(struct ath_softc *sc, int rix)
197 sc->sc_ledevent = ticks; /* time of last event */
198 if (sc->sc_blinking) /* don't interrupt active blink */
200 ath_led_blink(sc, sc->sc_hwmap[rix].ledon, sc->sc_hwmap[rix].ledoff);