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>
32 __FBSDID("$FreeBSD$");
35 * This implements an empty DFS module.
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/sysctl.h>
44 #include <sys/kernel.h>
46 #include <sys/malloc.h>
47 #include <sys/mutex.h>
48 #include <sys/errno.h>
50 #include <machine/bus.h>
51 #include <machine/resource.h>
54 #include <sys/socket.h>
57 #include <net/if_var.h>
58 #include <net/if_media.h>
59 #include <net/if_arp.h>
60 #include <net/ethernet.h> /* XXX for ether_sprintf */
62 #include <net80211/ieee80211_var.h>
67 #include <netinet/in.h>
68 #include <netinet/if_ether.h>
71 #include <dev/ath/if_athvar.h>
72 #include <dev/ath/if_athdfs.h>
74 #include <dev/ath/ath_hal/ah_desc.h>
77 * Methods which are required
81 * Attach DFS to the given interface
84 ath_dfs_attach(struct ath_softc *sc)
90 * Detach DFS from the given interface
93 ath_dfs_detach(struct ath_softc *sc)
99 * Enable radar check. Return 1 if the driver should
100 * enable radar PHY errors, or 0 if not.
103 ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
108 /* Check if the hardware supports radar reporting */
109 /* XXX TODO: migrate HAL_CAP_RADAR/HAL_CAP_AR to somewhere public! */
110 if (ath_hal_getcapability(sc->sc_ah,
111 HAL_CAP_PHYDIAG, 0, NULL) != HAL_OK)
114 /* Check if the current channel is radar-enabled */
115 if (! IEEE80211_IS_CHAN_DFS(chan))
118 /* Fetch the default parameters */
119 memset(&pe, '\0', sizeof(pe));
120 if (! ath_hal_getdfsdefaultthresh(sc->sc_ah, &pe))
123 /* Enable radar PHY error reporting */
126 /* Tell the hardware to enable radar reporting */
129 /* Flip on extension channel events only if doing HT40 */
130 if (IEEE80211_IS_CHAN_HT40(chan))
131 pe.pe_extchannel = 1;
133 pe.pe_extchannel = 0;
135 ath_hal_enabledfs(sc->sc_ah, &pe);
138 * Disable strong signal fast diversity - needed for
139 * AR5212 and similar PHYs for reliable short pulse
142 (void) ath_hal_setcapability(sc->sc_ah, HAL_CAP_DIVERSITY, 2, 0, NULL);
151 * Explicity disable radar reporting.
153 * Return 0 if it was disabled, < 0 on error.
156 ath_dfs_radar_disable(struct ath_softc *sc)
161 (void) ath_hal_getdfsthresh(sc->sc_ah, &pe);
163 (void) ath_hal_enabledfs(sc->sc_ah, &pe);
171 * Process DFS related PHY errors
173 * The mbuf is not "ours" and if we want a copy, we have
174 * to take a copy. It'll be freed after this function returns.
177 ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,
178 uint64_t tsf, struct ath_rx_status *rxstat)
184 * Process the radar events and determine whether a DFS event has occurred.
186 * This is designed to run outside of the RX processing path.
187 * The RX path will call ath_dfs_tasklet_needed() to see whether
188 * the task/callback running this routine needs to be called.
191 ath_dfs_process_radar_event(struct ath_softc *sc,
192 struct ieee80211_channel *chan)
198 * Determine whether the DFS check task needs to be queued.
200 * This is called in the RX task when the current batch of packets
201 * have been received. It will return whether there are any radar
202 * events for ath_dfs_process_radar_event() to handle.
205 ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
211 * Handle ioctl requests from the diagnostic interface.
213 * The initial part of this code resembles ath_ioctl_diag();
214 * it's likely a good idea to reduce duplication between
215 * these two routines.
218 ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
220 unsigned int id = ad->ad_id & ATH_DIAG_ID;
222 void *outdata = NULL;
223 u_int32_t insize = ad->ad_in_size;
224 u_int32_t outsize = ad->ad_out_size;
226 HAL_PHYERR_PARAM peout;
227 HAL_PHYERR_PARAM *pe;
229 if (ad->ad_id & ATH_DIAG_IN) {
233 indata = malloc(insize, M_TEMP, M_NOWAIT);
234 if (indata == NULL) {
238 error = copyin(ad->ad_in_data, indata, insize);
242 if (ad->ad_id & ATH_DIAG_DYN) {
244 * Allocate a buffer for the results (otherwise the HAL
245 * returns a pointer to a buffer where we can read the
246 * results). Note that we depend on the HAL leaving this
247 * pointer for us to use below in reclaiming the buffer;
248 * may want to be more defensive.
250 outdata = malloc(outsize, M_TEMP, M_NOWAIT);
251 if (outdata == NULL) {
258 if (insize < sizeof(HAL_PHYERR_PARAM)) {
262 pe = (HAL_PHYERR_PARAM *) indata;
263 ath_hal_enabledfs(sc->sc_ah, pe);
266 memset(&peout, 0, sizeof(peout));
267 outsize = sizeof(HAL_PHYERR_PARAM);
268 ath_hal_getdfsthresh(sc->sc_ah, &peout);
269 pe = (HAL_PHYERR_PARAM *) outdata;
270 memcpy(pe, &peout, sizeof(*pe));
275 if (outsize < ad->ad_out_size)
276 ad->ad_out_size = outsize;
277 if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
280 if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
281 free(indata, M_TEMP);
282 if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
283 free(outdata, M_TEMP);
288 * Get the current DFS thresholds from the HAL
291 ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
293 ath_hal_getdfsthresh(sc->sc_ah, param);