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/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_media.h>
57 #include <net/if_arp.h>
58 #include <net/ethernet.h> /* XXX for ether_sprintf */
60 #include <net80211/ieee80211_var.h>
65 #include <netinet/in.h>
66 #include <netinet/if_ether.h>
69 #include <dev/ath/if_athvar.h>
70 #include <dev/ath/if_athdfs.h>
72 #include <dev/ath/ath_hal/ah_desc.h>
75 * Methods which are required
79 * Attach DFS to the given interface
82 ath_dfs_attach(struct ath_softc *sc)
88 * Detach DFS from the given interface
91 ath_dfs_detach(struct ath_softc *sc)
97 * Enable radar check. Return 1 if the driver should
98 * enable radar PHY errors, or 0 if not.
101 ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
106 /* Check if the hardware supports radar reporting */
107 /* XXX TODO: migrate HAL_CAP_RADAR/HAL_CAP_AR to somewhere public! */
108 if (ath_hal_getcapability(sc->sc_ah,
109 HAL_CAP_PHYDIAG, 0, NULL) != HAL_OK)
112 /* Check if the current channel is radar-enabled */
113 if (! IEEE80211_IS_CHAN_DFS(chan))
116 /* Fetch the default parameters */
117 memset(&pe, '\0', sizeof(pe));
118 if (! ath_hal_getdfsdefaultthresh(sc->sc_ah, &pe))
121 /* Enable radar PHY error reporting */
124 /* Tell the hardware to enable radar reporting */
127 /* Flip on extension channel events only if doing HT40 */
128 if (IEEE80211_IS_CHAN_HT40(chan))
129 pe.pe_extchannel = 1;
131 pe.pe_extchannel = 0;
133 ath_hal_enabledfs(sc->sc_ah, &pe);
136 * Disable strong signal fast diversity - needed for
137 * AR5212 and similar PHYs for reliable short pulse
140 (void) ath_hal_setcapability(sc->sc_ah, HAL_CAP_DIVERSITY, 2, 0, NULL);
149 * Explicity disable radar reporting.
151 * Return 0 if it was disabled, < 0 on error.
154 ath_dfs_radar_disable(struct ath_softc *sc)
159 (void) ath_hal_getdfsthresh(sc->sc_ah, &pe);
161 (void) ath_hal_enabledfs(sc->sc_ah, &pe);
169 * Process DFS related PHY errors
171 * The mbuf is not "ours" and if we want a copy, we have
172 * to take a copy. It'll be freed after this function returns.
175 ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,
176 uint64_t tsf, struct ath_rx_status *rxstat)
182 * Process the radar events and determine whether a DFS event has occured.
184 * This is designed to run outside of the RX processing path.
185 * The RX path will call ath_dfs_tasklet_needed() to see whether
186 * the task/callback running this routine needs to be called.
189 ath_dfs_process_radar_event(struct ath_softc *sc,
190 struct ieee80211_channel *chan)
196 * Determine whether the DFS check task needs to be queued.
198 * This is called in the RX task when the current batch of packets
199 * have been received. It will return whether there are any radar
200 * events for ath_dfs_process_radar_event() to handle.
203 ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
209 * Handle ioctl requests from the diagnostic interface.
211 * The initial part of this code resembles ath_ioctl_diag();
212 * it's likely a good idea to reduce duplication between
213 * these two routines.
216 ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
218 unsigned int id = ad->ad_id & ATH_DIAG_ID;
220 void *outdata = NULL;
221 u_int32_t insize = ad->ad_in_size;
222 u_int32_t outsize = ad->ad_out_size;
224 HAL_PHYERR_PARAM peout;
225 HAL_PHYERR_PARAM *pe;
227 if (ad->ad_id & ATH_DIAG_IN) {
231 indata = malloc(insize, M_TEMP, M_NOWAIT);
232 if (indata == NULL) {
236 error = copyin(ad->ad_in_data, indata, insize);
240 if (ad->ad_id & ATH_DIAG_DYN) {
242 * Allocate a buffer for the results (otherwise the HAL
243 * returns a pointer to a buffer where we can read the
244 * results). Note that we depend on the HAL leaving this
245 * pointer for us to use below in reclaiming the buffer;
246 * may want to be more defensive.
248 outdata = malloc(outsize, M_TEMP, M_NOWAIT);
249 if (outdata == NULL) {
256 if (insize < sizeof(HAL_PHYERR_PARAM)) {
260 pe = (HAL_PHYERR_PARAM *) indata;
261 ath_hal_enabledfs(sc->sc_ah, pe);
264 memset(&peout, 0, sizeof(peout));
265 outsize = sizeof(HAL_PHYERR_PARAM);
266 ath_hal_getdfsthresh(sc->sc_ah, &peout);
267 pe = (HAL_PHYERR_PARAM *) outdata;
268 memcpy(pe, &peout, sizeof(*pe));
273 if (outsize < ad->ad_out_size)
274 ad->ad_out_size = outsize;
275 if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
278 if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
279 free(indata, M_TEMP);
280 if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
281 free(outdata, M_TEMP);
286 * Get the current DFS thresholds from the HAL
289 ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
291 ath_hal_getdfsthresh(sc->sc_ah, param);