xref: /dragonfly/sys/dev/netif/ath/ath_dfs/null/dfs_null.c (revision d4ef6694)
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 
33 /*
34  * This implements an empty DFS module.
35  */
36 #include "opt_ath.h"
37 #include "opt_inet.h"
38 #include "opt_wlan.h"
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/sysctl.h>
43 #include <sys/kernel.h>
44 #include <sys/lock.h>
45 #include <sys/malloc.h>
46 #include <sys/mutex.h>
47 #include <sys/errno.h>
48 #include <sys/bus.h>
49 #include <sys/socket.h>
50 
51 #include <net/if.h>
52 #include <net/if_var.h>
53 #include <net/if_media.h>
54 #include <net/if_arp.h>
55 #include <net/ethernet.h>		/* XXX for ether_sprintf */
56 
57 #include <netproto/802_11/ieee80211_var.h>
58 
59 #include <net/bpf.h>
60 
61 #ifdef INET
62 #include <netinet/in.h>
63 #include <netinet/if_ether.h>
64 #endif
65 
66 #include <dev/netif/ath/ath/if_athvar.h>
67 #include <dev/netif/ath/ath/if_athdfs.h>
68 
69 #include <dev/netif/ath/ath_hal/ah_desc.h>
70 
71 /*
72  * Methods which are required
73  */
74 
75 /*
76  * Attach DFS to the given interface
77  */
78 int
79 ath_dfs_attach(struct ath_softc *sc)
80 {
81 	return (1);
82 }
83 
84 /*
85  * Detach DFS from the given interface
86  */
87 int
88 ath_dfs_detach(struct ath_softc *sc)
89 {
90 	return (1);
91 }
92 
93 /*
94  * Enable radar check.  Return 1 if the driver should
95  * enable radar PHY errors, or 0 if not.
96  */
97 int
98 ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
99 {
100 #if 0
101 	HAL_PHYERR_PARAM pe;
102 
103 	/* Check if the hardware supports radar reporting */
104 	/* XXX TODO: migrate HAL_CAP_RADAR/HAL_CAP_AR to somewhere public! */
105 	if (ath_hal_getcapability(sc->sc_ah,
106 	    HAL_CAP_PHYDIAG, 0, NULL) != HAL_OK)
107 		return (0);
108 
109 	/* Check if the current channel is radar-enabled */
110 	if (! IEEE80211_IS_CHAN_DFS(chan))
111 		return (0);
112 
113 	/* Fetch the default parameters */
114 	memset(&pe, '\0', sizeof(pe));
115 	if (! ath_hal_getdfsdefaultthresh(sc->sc_ah, &pe))
116 		return (0);
117 
118 	/* Enable radar PHY error reporting */
119 	sc->sc_dodfs = 1;
120 
121 	/* Tell the hardware to enable radar reporting */
122 	pe.pe_enabled = 1;
123 
124 	/* Flip on extension channel events only if doing HT40 */
125 	if (IEEE80211_IS_CHAN_HT40(chan))
126 		pe.pe_extchannel = 1;
127 	else
128 		pe.pe_extchannel = 0;
129 
130 	ath_hal_enabledfs(sc->sc_ah, &pe);
131 
132 	/*
133 	 * Disable strong signal fast diversity - needed for
134 	 * AR5212 and similar PHYs for reliable short pulse
135 	 * duration.
136 	 */
137 	(void) ath_hal_setcapability(sc->sc_ah, HAL_CAP_DIVERSITY, 2, 0, NULL);
138 
139 	return (1);
140 #else
141 	return (0);
142 #endif
143 }
144 
145 /*
146  * Explicity disable radar reporting.
147  *
148  * Return 0 if it was disabled, < 0 on error.
149  */
150 int
151 ath_dfs_radar_disable(struct ath_softc *sc)
152 {
153 #if 0
154 	HAL_PHYERR_PARAM pe;
155 
156 	(void) ath_hal_getdfsthresh(sc->sc_ah, &pe);
157 	pe.pe_enabled = 0;
158 	(void) ath_hal_enabledfs(sc->sc_ah, &pe);
159 	return (0);
160 #else
161 	return (0);
162 #endif
163 }
164 
165 /*
166  * Process DFS related PHY errors
167  *
168  * The mbuf is not "ours" and if we want a copy, we have
169  * to take a copy.  It'll be freed after this function returns.
170  */
171 void
172 ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,
173     uint64_t tsf, struct ath_rx_status *rxstat)
174 {
175 
176 }
177 
178 /*
179  * Process the radar events and determine whether a DFS event has occured.
180  *
181  * This is designed to run outside of the RX processing path.
182  * The RX path will call ath_dfs_tasklet_needed() to see whether
183  * the task/callback running this routine needs to be called.
184  */
185 int
186 ath_dfs_process_radar_event(struct ath_softc *sc,
187     struct ieee80211_channel *chan)
188 {
189 	return (0);
190 }
191 
192 /*
193  * Determine whether the DFS check task needs to be queued.
194  *
195  * This is called in the RX task when the current batch of packets
196  * have been received. It will return whether there are any radar
197  * events for ath_dfs_process_radar_event() to handle.
198  */
199 int
200 ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
201 {
202 	return (0);
203 }
204 
205 /*
206  * Handle ioctl requests from the diagnostic interface.
207  *
208  * The initial part of this code resembles ath_ioctl_diag();
209  * it's likely a good idea to reduce duplication between
210  * these two routines.
211  */
212 int
213 ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
214 {
215 	unsigned int id = ad->ad_id & ATH_DIAG_ID;
216 	void *indata = NULL;
217 	void *outdata = NULL;
218 	u_int32_t insize = ad->ad_in_size;
219 	u_int32_t outsize = ad->ad_out_size;
220 	int error = 0;
221 	HAL_PHYERR_PARAM peout;
222 	HAL_PHYERR_PARAM *pe;
223 
224 	if (ad->ad_id & ATH_DIAG_IN) {
225 		/*
226 		 * Copy in data.
227 		 */
228 		indata = kmalloc(insize, M_TEMP, M_INTWAIT);
229 		if (indata == NULL) {
230 			error = ENOMEM;
231 			goto bad;
232 		}
233 		error = copyin(ad->ad_in_data, indata, insize);
234 		if (error)
235 			goto bad;
236 	}
237 	if (ad->ad_id & ATH_DIAG_DYN) {
238 		/*
239 		 * Allocate a buffer for the results (otherwise the HAL
240 		 * returns a pointer to a buffer where we can read the
241 		 * results).  Note that we depend on the HAL leaving this
242 		 * pointer for us to use below in reclaiming the buffer;
243 		 * may want to be more defensive.
244 		 */
245 		outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
246 		if (outdata == NULL) {
247 			error = ENOMEM;
248 			goto bad;
249 		}
250 	}
251 	switch (id) {
252 		case DFS_SET_THRESH:
253 			if (insize < sizeof(HAL_PHYERR_PARAM)) {
254 				error = EINVAL;
255 				break;
256 			}
257 			pe = (HAL_PHYERR_PARAM *) indata;
258 			ath_hal_enabledfs(sc->sc_ah, pe);
259 			break;
260 		case DFS_GET_THRESH:
261 			memset(&peout, 0, sizeof(peout));
262 			outsize = sizeof(HAL_PHYERR_PARAM);
263 			ath_hal_getdfsthresh(sc->sc_ah, &peout);
264 			pe = (HAL_PHYERR_PARAM *) outdata;
265 			memcpy(pe, &peout, sizeof(*pe));
266 			break;
267 		default:
268 			error = EINVAL;
269 	}
270 	if (outsize < ad->ad_out_size)
271 		ad->ad_out_size = outsize;
272 	if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
273 		error = EFAULT;
274 bad:
275 	if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
276 		kfree(indata, M_TEMP);
277 	if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
278 		kfree(outdata, M_TEMP);
279 	return (error);
280 }
281 
282 /*
283  * Get the current DFS thresholds from the HAL
284  */
285 int
286 ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
287 {
288 	ath_hal_getdfsthresh(sc->sc_ah, param);
289 	return (1);
290 }
291 
292 /*
293  * Module glue.
294  */
295 static int
296 null_dfs_modevent(module_t mod, int type, void *unused)
297 {
298         int error;
299 
300         wlan_serialize_enter();
301 
302         switch (type) {
303         case MOD_LOAD:
304                 if (bootverbose) {
305                         kprintf("ath_dfs: WTF module\n");
306                 }
307                 error = 0;
308                 break;
309         case MOD_UNLOAD:
310                 error = 0;
311                 break;
312         default:
313                 error = EINVAL;
314                 break;
315         }
316         wlan_serialize_exit();
317 
318         return error;
319 }
320 
321 static moduledata_t null_dfs_mod = {
322         "ath_dfs",
323         null_dfs_modevent,
324         0
325 };
326 
327 DECLARE_MODULE(ath_dfs, null_dfs_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
328 MODULE_VERSION(ath_dfs, 1);
329