Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/dev/ath/if_ath_led.c
39535 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause
3
*
4
* Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
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
* 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.
17
*
18
* NO WARRANTY
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.
30
*/
31
32
#include <sys/cdefs.h>
33
/*
34
* Driver for the Atheros Wireless LAN controller.
35
*
36
* This software is derived from work of Atsushi Onoe; his contribution
37
* is greatly appreciated.
38
*/
39
40
#include "opt_inet.h"
41
#include "opt_ath.h"
42
/*
43
* This is needed for register operations which are performed
44
* by the driver - eg, calls to ath_hal_gettsf32().
45
*/
46
#include "opt_ah.h"
47
#include "opt_wlan.h"
48
49
#include <sys/param.h>
50
#include <sys/systm.h>
51
#include <sys/sysctl.h>
52
#include <sys/mbuf.h>
53
#include <sys/malloc.h>
54
#include <sys/lock.h>
55
#include <sys/mutex.h>
56
#include <sys/kernel.h>
57
#include <sys/socket.h>
58
#include <sys/sockio.h>
59
#include <sys/errno.h>
60
#include <sys/callout.h>
61
#include <sys/bus.h>
62
#include <sys/endian.h>
63
#include <sys/kthread.h>
64
#include <sys/taskqueue.h>
65
#include <sys/priv.h>
66
#include <sys/module.h>
67
#include <sys/ktr.h>
68
#include <sys/smp.h> /* for mp_ncpus */
69
70
#include <machine/bus.h>
71
72
#include <net/if.h>
73
#include <net/if_dl.h>
74
#include <net/if_media.h>
75
#include <net/if_types.h>
76
#include <net/if_arp.h>
77
#include <net/ethernet.h>
78
#include <net/if_llc.h>
79
#include <net/if_var.h>
80
81
#include <net80211/ieee80211_var.h>
82
#include <net80211/ieee80211_regdomain.h>
83
#ifdef IEEE80211_SUPPORT_SUPERG
84
#include <net80211/ieee80211_superg.h>
85
#endif
86
#ifdef IEEE80211_SUPPORT_TDMA
87
#include <net80211/ieee80211_tdma.h>
88
#endif
89
90
#include <net/bpf.h>
91
92
#ifdef INET
93
#include <netinet/in.h>
94
#include <netinet/if_ether.h>
95
#endif
96
97
#include <dev/ath/if_athvar.h>
98
#include <dev/ath/ath_hal/ah_devid.h> /* XXX for softled */
99
#include <dev/ath/ath_hal/ah_diagcodes.h>
100
101
#include <dev/ath/if_ath_debug.h>
102
#include <dev/ath/if_ath_misc.h>
103
104
#include <dev/ath/if_ath_led.h>
105
106
/*
107
* Software LED driver routines.
108
*/
109
110
/*
111
* XXX TODO: move the LED sysctls here.
112
*/
113
114
/*
115
* Configure the hardware for software and LED blinking.
116
* The user may choose to configure part of each, depending upon the
117
* NIC being used.
118
*
119
* This requires the configuration to be set before this function
120
* is called.
121
*/
122
void
123
ath_led_config(struct ath_softc *sc)
124
{
125
126
ATH_LOCK(sc);
127
ath_power_set_power_state(sc, HAL_PM_AWAKE);
128
ATH_UNLOCK(sc);
129
130
/* Software LED blinking - GPIO controlled LED */
131
if (sc->sc_softled) {
132
ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_ledpin,
133
HAL_GPIO_OUTPUT_MUX_AS_OUTPUT);
134
ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, !sc->sc_ledon);
135
}
136
137
/* Hardware LED blinking - MAC controlled LED */
138
if (sc->sc_hardled) {
139
/*
140
* Only enable each LED if required.
141
*
142
* Some NICs only have one LED connected; others may
143
* have GPIO1/GPIO2 connected to other hardware.
144
*/
145
if (sc->sc_led_pwr_pin > 0)
146
ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_led_pwr_pin,
147
HAL_GPIO_OUTPUT_MUX_MAC_POWER_LED);
148
if (sc->sc_led_net_pin > 0)
149
ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_led_net_pin,
150
HAL_GPIO_OUTPUT_MUX_MAC_NETWORK_LED);
151
}
152
153
ATH_LOCK(sc);
154
ath_power_restore_power_state(sc);
155
ATH_UNLOCK(sc);
156
}
157
158
static void
159
ath_led_done(void *arg)
160
{
161
struct ath_softc *sc = arg;
162
163
sc->sc_blinking = 0;
164
}
165
166
/*
167
* Turn the LED off: flip the pin and then set a timer so no
168
* update will happen for the specified duration.
169
*/
170
static void
171
ath_led_off(void *arg)
172
{
173
struct ath_softc *sc = arg;
174
175
ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, !sc->sc_ledon);
176
callout_reset(&sc->sc_ledtimer, sc->sc_ledoff, ath_led_done, sc);
177
}
178
179
/*
180
* Blink the LED according to the specified on/off times.
181
*/
182
static void
183
ath_led_blink(struct ath_softc *sc, int on, int off)
184
{
185
DPRINTF(sc, ATH_DEBUG_LED, "%s: on %u off %u\n", __func__, on, off);
186
ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, sc->sc_ledon);
187
sc->sc_blinking = 1;
188
sc->sc_ledoff = off;
189
callout_reset(&sc->sc_ledtimer, on, ath_led_off, sc);
190
}
191
192
void
193
ath_led_event(struct ath_softc *sc, int rix)
194
{
195
sc->sc_ledevent = ticks; /* time of last event */
196
if (sc->sc_blinking) /* don't interrupt active blink */
197
return;
198
ath_led_blink(sc, sc->sc_hwmap[rix].ledon, sc->sc_hwmap[rix].ledoff);
199
}
200
201