2 * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
31 #include <sys/cdefs.h>
34 * This implements an empty DFS module.
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/sysctl.h>
43 #include <sys/kernel.h>
45 #include <sys/malloc.h>
46 #include <sys/mutex.h>
47 #include <sys/errno.h>
49 #include <machine/bus.h>
50 #include <machine/resource.h>
53 #include <sys/socket.h>
56 #include <net/if_var.h>
57 #include <net/if_media.h>
58 #include <net/if_arp.h>
59 #include <net/ethernet.h> /* XXX for ether_sprintf */
61 #include <net80211/ieee80211_var.h>
66 #include <netinet/in.h>
67 #include <netinet/if_ether.h>
70 #include <dev/ath/if_athvar.h>
71 #include <dev/ath/if_athdfs.h>
73 #include <dev/ath/ath_hal/ah_desc.h>
76 * Methods which are required
80 * Attach DFS to the given interface
83 ath_dfs_attach(struct ath_softc *sc)
89 * Detach DFS from the given interface
92 ath_dfs_detach(struct ath_softc *sc)
98 * Enable radar check. Return 1 if the driver should
99 * enable radar PHY errors, or 0 if not.
102 ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
107 /* Check if the hardware supports radar reporting */
108 /* XXX TODO: migrate HAL_CAP_RADAR/HAL_CAP_AR to somewhere public! */
109 if (ath_hal_getcapability(sc->sc_ah,
110 HAL_CAP_PHYDIAG, 0, NULL) != HAL_OK)
113 /* Check if the current channel is radar-enabled */
114 if (! IEEE80211_IS_CHAN_DFS(chan))
117 /* Fetch the default parameters */
118 memset(&pe, '\0', sizeof(pe));
119 if (! ath_hal_getdfsdefaultthresh(sc->sc_ah, &pe))
122 /* Enable radar PHY error reporting */
125 /* Tell the hardware to enable radar reporting */
128 /* Flip on extension channel events only if doing HT40 */
129 if (IEEE80211_IS_CHAN_HT40(chan))
130 pe.pe_extchannel = 1;
132 pe.pe_extchannel = 0;
134 ath_hal_enabledfs(sc->sc_ah, &pe);
137 * Disable strong signal fast diversity - needed for
138 * AR5212 and similar PHYs for reliable short pulse
141 (void) ath_hal_setcapability(sc->sc_ah, HAL_CAP_DIVERSITY, 2, 0, NULL);
150 * Explicity disable radar reporting.
152 * Return 0 if it was disabled, < 0 on error.
155 ath_dfs_radar_disable(struct ath_softc *sc)
160 (void) ath_hal_getdfsthresh(sc->sc_ah, &pe);
162 (void) ath_hal_enabledfs(sc->sc_ah, &pe);
170 * Process DFS related PHY errors
172 * The mbuf is not "ours" and if we want a copy, we have
173 * to take a copy. It'll be freed after this function returns.
176 ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,
177 uint64_t tsf, struct ath_rx_status *rxstat)
183 * Process the radar events and determine whether a DFS event has occured.
185 * This is designed to run outside of the RX processing path.
186 * The RX path will call ath_dfs_tasklet_needed() to see whether
187 * the task/callback running this routine needs to be called.
190 ath_dfs_process_radar_event(struct ath_softc *sc,
191 struct ieee80211_channel *chan)
197 * Determine whether the DFS check task needs to be queued.
199 * This is called in the RX task when the current batch of packets
200 * have been received. It will return whether there are any radar
201 * events for ath_dfs_process_radar_event() to handle.
204 ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
210 * Handle ioctl requests from the diagnostic interface.
212 * The initial part of this code resembles ath_ioctl_diag();
213 * it's likely a good idea to reduce duplication between
214 * these two routines.
217 ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
219 unsigned int id = ad->ad_id & ATH_DIAG_ID;
221 void *outdata = NULL;
222 u_int32_t insize = ad->ad_in_size;
223 u_int32_t outsize = ad->ad_out_size;
225 HAL_PHYERR_PARAM peout;
226 HAL_PHYERR_PARAM *pe;
228 if (ad->ad_id & ATH_DIAG_IN) {
232 indata = malloc(insize, M_TEMP, M_NOWAIT);
233 if (indata == NULL) {
237 error = copyin(ad->ad_in_data, indata, insize);
241 if (ad->ad_id & ATH_DIAG_DYN) {
243 * Allocate a buffer for the results (otherwise the HAL
244 * returns a pointer to a buffer where we can read the
245 * results). Note that we depend on the HAL leaving this
246 * pointer for us to use below in reclaiming the buffer;
247 * may want to be more defensive.
249 outdata = malloc(outsize, M_TEMP, M_NOWAIT);
250 if (outdata == NULL) {
257 if (insize < sizeof(HAL_PHYERR_PARAM)) {
261 pe = (HAL_PHYERR_PARAM *) indata;
262 ath_hal_enabledfs(sc->sc_ah, pe);
265 memset(&peout, 0, sizeof(peout));
266 outsize = sizeof(HAL_PHYERR_PARAM);
267 ath_hal_getdfsthresh(sc->sc_ah, &peout);
268 pe = (HAL_PHYERR_PARAM *) outdata;
269 memcpy(pe, &peout, sizeof(*pe));
274 if (outsize < ad->ad_out_size)
275 ad->ad_out_size = outsize;
276 if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
279 if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
280 free(indata, M_TEMP);
281 if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
282 free(outdata, M_TEMP);
287 * Get the current DFS thresholds from the HAL
290 ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
292 ath_hal_getdfsthresh(sc->sc_ah, param);