xref: /dragonfly/sys/dev/netif/ath/ath_dfs/null/dfs_null.c (revision f2c43266)
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 <sys/bus.h>
51 
52 #include <sys/socket.h>
53 
54 #include <net/if.h>
55 #include <net/if_var.h>
56 #include <net/if_media.h>
57 #include <net/if_arp.h>
58 #include <net/ethernet.h>		/* XXX for ether_sprintf */
59 
60 #include <netproto/802_11/ieee80211_var.h>
61 
62 #include <net/bpf.h>
63 
64 #ifdef INET
65 #include <netinet/in.h>
66 #include <netinet/if_ether.h>
67 #endif
68 
69 #include <dev/netif/ath/ath/if_athvar.h>
70 #include <dev/netif/ath/ath/if_athdfs.h>
71 
72 #include <dev/netif/ath/ath_hal/ah_desc.h>
73 
74 /*
75  * Methods which are required
76  */
77 
78 /*
79  * Attach DFS to the given interface
80  */
81 int
82 ath_dfs_attach(struct ath_softc *sc)
83 {
84 	return (1);
85 }
86 
87 /*
88  * Detach DFS from the given interface
89  */
90 int
91 ath_dfs_detach(struct ath_softc *sc)
92 {
93 	return (1);
94 }
95 
96 /*
97  * Enable radar check.  Return 1 if the driver should
98  * enable radar PHY errors, or 0 if not.
99  */
100 int
101 ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
102 {
103 #if 0
104 	HAL_PHYERR_PARAM pe;
105 
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)
110 		return (0);
111 
112 	/* Check if the current channel is radar-enabled */
113 	if (! IEEE80211_IS_CHAN_DFS(chan))
114 		return (0);
115 
116 	/* Fetch the default parameters */
117 	memset(&pe, '\0', sizeof(pe));
118 	if (! ath_hal_getdfsdefaultthresh(sc->sc_ah, &pe))
119 		return (0);
120 
121 	/* Enable radar PHY error reporting */
122 	sc->sc_dodfs = 1;
123 
124 	/* Tell the hardware to enable radar reporting */
125 	pe.pe_enabled = 1;
126 
127 	/* Flip on extension channel events only if doing HT40 */
128 	if (IEEE80211_IS_CHAN_HT40(chan))
129 		pe.pe_extchannel = 1;
130 	else
131 		pe.pe_extchannel = 0;
132 
133 	ath_hal_enabledfs(sc->sc_ah, &pe);
134 
135 	/*
136 	 * Disable strong signal fast diversity - needed for
137 	 * AR5212 and similar PHYs for reliable short pulse
138 	 * duration.
139 	 */
140 	(void) ath_hal_setcapability(sc->sc_ah, HAL_CAP_DIVERSITY, 2, 0, NULL);
141 
142 	return (1);
143 #else
144 	return (0);
145 #endif
146 }
147 
148 /*
149  * Explicity disable radar reporting.
150  *
151  * Return 0 if it was disabled, < 0 on error.
152  */
153 int
154 ath_dfs_radar_disable(struct ath_softc *sc)
155 {
156 #if 0
157 	HAL_PHYERR_PARAM pe;
158 
159 	(void) ath_hal_getdfsthresh(sc->sc_ah, &pe);
160 	pe.pe_enabled = 0;
161 	(void) ath_hal_enabledfs(sc->sc_ah, &pe);
162 	return (0);
163 #else
164 	return (0);
165 #endif
166 }
167 
168 /*
169  * Process DFS related PHY errors
170  *
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.
173  */
174 void
175 ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,
176     uint64_t tsf, struct ath_rx_status *rxstat)
177 {
178 
179 }
180 
181 /*
182  * Process the radar events and determine whether a DFS event has occured.
183  *
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.
187  */
188 int
189 ath_dfs_process_radar_event(struct ath_softc *sc,
190     struct ieee80211_channel *chan)
191 {
192 	return (0);
193 }
194 
195 /*
196  * Determine whether the DFS check task needs to be queued.
197  *
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.
201  */
202 int
203 ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
204 {
205 	return (0);
206 }
207 
208 /*
209  * Handle ioctl requests from the diagnostic interface.
210  *
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.
214  */
215 int
216 ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
217 {
218 	unsigned int id = ad->ad_id & ATH_DIAG_ID;
219 	void *indata = NULL;
220 	void *outdata = NULL;
221 	u_int32_t insize = ad->ad_in_size;
222 	u_int32_t outsize = ad->ad_out_size;
223 	int error = 0;
224 	HAL_PHYERR_PARAM peout;
225 	HAL_PHYERR_PARAM *pe;
226 
227 	if (ad->ad_id & ATH_DIAG_IN) {
228 		/*
229 		 * Copy in data.
230 		 */
231 		indata = kmalloc(insize, M_TEMP, M_INTWAIT);
232 		if (indata == NULL) {
233 			error = ENOMEM;
234 			goto bad;
235 		}
236 		error = copyin(ad->ad_in_data, indata, insize);
237 		if (error)
238 			goto bad;
239 	}
240 	if (ad->ad_id & ATH_DIAG_DYN) {
241 		/*
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.
247 		 */
248 		outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
249 		if (outdata == NULL) {
250 			error = ENOMEM;
251 			goto bad;
252 		}
253 	}
254 	switch (id) {
255 		case DFS_SET_THRESH:
256 			if (insize < sizeof(HAL_PHYERR_PARAM)) {
257 				error = EINVAL;
258 				break;
259 			}
260 			pe = (HAL_PHYERR_PARAM *) indata;
261 			ath_hal_enabledfs(sc->sc_ah, pe);
262 			break;
263 		case DFS_GET_THRESH:
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));
269 			break;
270 		default:
271 			error = EINVAL;
272 	}
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))
276 		error = EFAULT;
277 bad:
278 	if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
279 		kfree(indata, M_TEMP);
280 	if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
281 		kfree(outdata, M_TEMP);
282 	return (error);
283 }
284 
285 /*
286  * Get the current DFS thresholds from the HAL
287  */
288 int
289 ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
290 {
291 	ath_hal_getdfsthresh(sc->sc_ah, param);
292 	return (1);
293 }
294 
295 /*
296  * Module glue.
297  */
298 static int
299 null_dfs_modevent(module_t mod, int type, void *unused)
300 {
301 	int error;
302 
303 	wlan_serialize_enter();
304 
305 	switch (type) {
306 	case MOD_LOAD:
307 		if (bootverbose) {
308 			kprintf("ath_dfs: WTF module\n");
309 		}
310 		error = 0;
311 		break;
312 	case MOD_UNLOAD:
313 		error = 0;
314 		break;
315 	default:
316 		error = EINVAL;
317 		break;
318 	}
319 	wlan_serialize_exit();
320 
321 	return error;
322 }
323 
324 static moduledata_t null_dfs_mod = {
325 	"ath_dfs",
326 	null_dfs_modevent,
327 	0
328 };
329 
330 DECLARE_MODULE(ath_dfs, null_dfs_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
331 MODULE_VERSION(ath_dfs, 1);
332