xref: /freebsd/sys/dev/ath/ath_dfs/null/dfs_null.c (revision 41059135ce931c0f1014a999ffabc6bc470ce856)
1 /*-
2  * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
15  *
16  * NO WARRANTY
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.
28  *
29  * $FreeBSD$
30  */
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33 
34 /*
35  * This implements an empty DFS module.
36  */
37 #include "opt_ath.h"
38 #include "opt_inet.h"
39 #include "opt_wlan.h"
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/sysctl.h>
44 #include <sys/kernel.h>
45 #include <sys/lock.h>
46 #include <sys/malloc.h>
47 #include <sys/mutex.h>
48 #include <sys/errno.h>
49 
50 #include <machine/bus.h>
51 #include <machine/resource.h>
52 #include <sys/bus.h>
53 
54 #include <sys/socket.h>
55 
56 #include <net/if.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 */
61 
62 #include <net80211/ieee80211_var.h>
63 
64 #include <net/bpf.h>
65 
66 #ifdef INET
67 #include <netinet/in.h>
68 #include <netinet/if_ether.h>
69 #endif
70 
71 #include <dev/ath/if_athvar.h>
72 #include <dev/ath/if_athdfs.h>
73 
74 #include <dev/ath/ath_hal/ah_desc.h>
75 
76 /*
77  * Methods which are required
78  */
79 
80 /*
81  * Attach DFS to the given interface
82  */
83 int
84 ath_dfs_attach(struct ath_softc *sc)
85 {
86 	return (1);
87 }
88 
89 /*
90  * Detach DFS from the given interface
91  */
92 int
93 ath_dfs_detach(struct ath_softc *sc)
94 {
95 	return (1);
96 }
97 
98 /*
99  * Enable radar check.  Return 1 if the driver should
100  * enable radar PHY errors, or 0 if not.
101  */
102 int
103 ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
104 {
105 #if 1
106 	HAL_PHYERR_PARAM pe;
107 
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)
112 		return (0);
113 
114 	/* Check if the current channel is radar-enabled */
115 	if (! IEEE80211_IS_CHAN_DFS(chan))
116 		return (0);
117 
118 	/* Fetch the default parameters */
119 	memset(&pe, '\0', sizeof(pe));
120 	if (! ath_hal_getdfsdefaultthresh(sc->sc_ah, &pe))
121 		return (0);
122 
123 	/* Enable radar PHY error reporting */
124 	sc->sc_dodfs = 1;
125 
126 	/* Tell the hardware to enable radar reporting */
127 	pe.pe_enabled = 1;
128 
129 	/* Flip on extension channel events only if doing HT40 */
130 	if (IEEE80211_IS_CHAN_HT40(chan))
131 		pe.pe_extchannel = 1;
132 	else
133 		pe.pe_extchannel = 0;
134 
135 	ath_hal_enabledfs(sc->sc_ah, &pe);
136 
137 	/*
138 	 * Disable strong signal fast diversity - needed for
139 	 * AR5212 and similar PHYs for reliable short pulse
140 	 * duration.
141 	 */
142 	(void) ath_hal_setcapability(sc->sc_ah, HAL_CAP_DIVERSITY, 2, 0, NULL);
143 
144 	return (1);
145 #else
146 	return (0);
147 #endif
148 }
149 
150 /*
151  * Explicity disable radar reporting.
152  *
153  * Return 0 if it was disabled, < 0 on error.
154  */
155 int
156 ath_dfs_radar_disable(struct ath_softc *sc)
157 {
158 #if 1
159 	HAL_PHYERR_PARAM pe;
160 
161 	(void) ath_hal_getdfsthresh(sc->sc_ah, &pe);
162 	pe.pe_enabled = 0;
163 	(void) ath_hal_enabledfs(sc->sc_ah, &pe);
164 	return (0);
165 #else
166 	return (0);
167 #endif
168 }
169 
170 /*
171  * Process DFS related PHY errors
172  *
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.
175  */
176 void
177 ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,
178     uint64_t tsf, struct ath_rx_status *rxstat)
179 {
180 
181 }
182 
183 /*
184  * Process the radar events and determine whether a DFS event has occurred.
185  *
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.
189  */
190 int
191 ath_dfs_process_radar_event(struct ath_softc *sc,
192     struct ieee80211_channel *chan)
193 {
194 	return (0);
195 }
196 
197 /*
198  * Determine whether the DFS check task needs to be queued.
199  *
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.
203  */
204 int
205 ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
206 {
207 	return (0);
208 }
209 
210 /*
211  * Handle ioctl requests from the diagnostic interface.
212  *
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.
216  */
217 int
218 ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
219 {
220 	unsigned int id = ad->ad_id & ATH_DIAG_ID;
221 	void *indata = NULL;
222 	void *outdata = NULL;
223 	u_int32_t insize = ad->ad_in_size;
224 	u_int32_t outsize = ad->ad_out_size;
225 	int error = 0;
226 	HAL_PHYERR_PARAM peout;
227 	HAL_PHYERR_PARAM *pe;
228 
229 	if (ad->ad_id & ATH_DIAG_IN) {
230 		/*
231 		 * Copy in data.
232 		 */
233 		indata = malloc(insize, M_TEMP, M_NOWAIT);
234 		if (indata == NULL) {
235 			error = ENOMEM;
236 			goto bad;
237 		}
238 		error = copyin(ad->ad_in_data, indata, insize);
239 		if (error)
240 			goto bad;
241 	}
242 	if (ad->ad_id & ATH_DIAG_DYN) {
243 		/*
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.
249 		 */
250 		outdata = malloc(outsize, M_TEMP, M_NOWAIT);
251 		if (outdata == NULL) {
252 			error = ENOMEM;
253 			goto bad;
254 		}
255 	}
256 	switch (id) {
257 		case DFS_SET_THRESH:
258 			if (insize < sizeof(HAL_PHYERR_PARAM)) {
259 				error = EINVAL;
260 				break;
261 			}
262 			pe = (HAL_PHYERR_PARAM *) indata;
263 			ath_hal_enabledfs(sc->sc_ah, pe);
264 			break;
265 		case DFS_GET_THRESH:
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));
271 			break;
272 		default:
273 			error = EINVAL;
274 	}
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))
278 		error = EFAULT;
279 bad:
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);
284 	return (error);
285 }
286 
287 /*
288  * Get the current DFS thresholds from the HAL
289  */
290 int
291 ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
292 {
293 	ath_hal_getdfsthresh(sc->sc_ah, param);
294 	return (1);
295 }
296