xref: /dflybsd-src/sys/dev/netif/ath/ath_dfs/null/dfs_null.c (revision df052c2a9588fe12c7a2df4e61e2bfa3f3e16ce0)
1572ff6f6SMatthew Dillon /*-
2572ff6f6SMatthew Dillon  * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd
3572ff6f6SMatthew Dillon  * All rights reserved.
4572ff6f6SMatthew Dillon  *
5572ff6f6SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
6572ff6f6SMatthew Dillon  * modification, are permitted provided that the following conditions
7572ff6f6SMatthew Dillon  * are met:
8572ff6f6SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
9572ff6f6SMatthew Dillon  *    notice, this list of conditions and the following disclaimer,
10572ff6f6SMatthew Dillon  *    without modification.
11572ff6f6SMatthew Dillon  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12572ff6f6SMatthew Dillon  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13572ff6f6SMatthew Dillon  *    redistribution must be conditioned upon including a substantially
14572ff6f6SMatthew Dillon  *    similar Disclaimer requirement for further binary redistribution.
15572ff6f6SMatthew Dillon  *
16572ff6f6SMatthew Dillon  * NO WARRANTY
17572ff6f6SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18572ff6f6SMatthew Dillon  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*df052c2aSSascha Wildner  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY
20572ff6f6SMatthew Dillon  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21572ff6f6SMatthew Dillon  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22572ff6f6SMatthew Dillon  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23572ff6f6SMatthew Dillon  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24572ff6f6SMatthew Dillon  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25572ff6f6SMatthew Dillon  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26572ff6f6SMatthew Dillon  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27572ff6f6SMatthew Dillon  * THE POSSIBILITY OF SUCH DAMAGES.
28572ff6f6SMatthew Dillon  *
29572ff6f6SMatthew Dillon  * $FreeBSD$
30572ff6f6SMatthew Dillon  */
31572ff6f6SMatthew Dillon #include <sys/cdefs.h>
32848b370cSMatthew Dillon __FBSDID("$FreeBSD$");
33572ff6f6SMatthew Dillon 
34572ff6f6SMatthew Dillon /*
35572ff6f6SMatthew Dillon  * This implements an empty DFS module.
36572ff6f6SMatthew Dillon  */
37572ff6f6SMatthew Dillon #include "opt_ath.h"
38572ff6f6SMatthew Dillon #include "opt_inet.h"
39572ff6f6SMatthew Dillon #include "opt_wlan.h"
40572ff6f6SMatthew Dillon 
41572ff6f6SMatthew Dillon #include <sys/param.h>
42572ff6f6SMatthew Dillon #include <sys/systm.h>
43572ff6f6SMatthew Dillon #include <sys/sysctl.h>
44572ff6f6SMatthew Dillon #include <sys/kernel.h>
45572ff6f6SMatthew Dillon #include <sys/lock.h>
46572ff6f6SMatthew Dillon #include <sys/malloc.h>
47572ff6f6SMatthew Dillon #include <sys/errno.h>
48848b370cSMatthew Dillon 
49dc249793SMatthew Dillon #if defined(__DragonFly__)
50dc249793SMatthew Dillon /* empty */
51dc249793SMatthew Dillon #else
52b14ca477SMatthew Dillon #include <machine/bus.h>
53b14ca477SMatthew Dillon #include <machine/resource.h>
54dc249793SMatthew Dillon #endif
55572ff6f6SMatthew Dillon #include <sys/bus.h>
56848b370cSMatthew Dillon 
57572ff6f6SMatthew Dillon #include <sys/socket.h>
58572ff6f6SMatthew Dillon 
59572ff6f6SMatthew Dillon #include <net/if.h>
60572ff6f6SMatthew Dillon #include <net/if_var.h>
61572ff6f6SMatthew Dillon #include <net/if_media.h>
62572ff6f6SMatthew Dillon #include <net/if_arp.h>
63572ff6f6SMatthew Dillon #include <net/ethernet.h>		/* XXX for ether_sprintf */
64572ff6f6SMatthew Dillon 
65dc249793SMatthew Dillon #include <netproto/802_11/ieee80211_var.h>
66572ff6f6SMatthew Dillon 
67572ff6f6SMatthew Dillon #include <net/bpf.h>
68572ff6f6SMatthew Dillon 
69572ff6f6SMatthew Dillon #ifdef INET
70572ff6f6SMatthew Dillon #include <netinet/in.h>
71572ff6f6SMatthew Dillon #include <netinet/if_ether.h>
72572ff6f6SMatthew Dillon #endif
73572ff6f6SMatthew Dillon 
74dc249793SMatthew Dillon #include <dev/netif/ath/ath/if_athvar.h>
75dc249793SMatthew Dillon #include <dev/netif/ath/ath/if_athdfs.h>
765cd80a8cSMatthew Dillon 
77dc249793SMatthew Dillon #include <dev/netif/ath/ath_hal/ah_desc.h>
78572ff6f6SMatthew Dillon 
79572ff6f6SMatthew Dillon /*
80572ff6f6SMatthew Dillon  * Methods which are required
81572ff6f6SMatthew Dillon  */
82572ff6f6SMatthew Dillon 
83572ff6f6SMatthew Dillon /*
84572ff6f6SMatthew Dillon  * Attach DFS to the given interface
85572ff6f6SMatthew Dillon  */
86572ff6f6SMatthew Dillon int
ath_dfs_attach(struct ath_softc * sc)87572ff6f6SMatthew Dillon ath_dfs_attach(struct ath_softc *sc)
88572ff6f6SMatthew Dillon {
89572ff6f6SMatthew Dillon 	return (1);
90572ff6f6SMatthew Dillon }
91572ff6f6SMatthew Dillon 
92572ff6f6SMatthew Dillon /*
93572ff6f6SMatthew Dillon  * Detach DFS from the given interface
94572ff6f6SMatthew Dillon  */
95572ff6f6SMatthew Dillon int
ath_dfs_detach(struct ath_softc * sc)96572ff6f6SMatthew Dillon ath_dfs_detach(struct ath_softc *sc)
97572ff6f6SMatthew Dillon {
98572ff6f6SMatthew Dillon 	return (1);
99572ff6f6SMatthew Dillon }
100572ff6f6SMatthew Dillon 
101572ff6f6SMatthew Dillon /*
102572ff6f6SMatthew Dillon  * Enable radar check.  Return 1 if the driver should
103572ff6f6SMatthew Dillon  * enable radar PHY errors, or 0 if not.
104572ff6f6SMatthew Dillon  */
105572ff6f6SMatthew Dillon int
ath_dfs_radar_enable(struct ath_softc * sc,struct ieee80211_channel * chan)106572ff6f6SMatthew Dillon ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
107572ff6f6SMatthew Dillon {
108572ff6f6SMatthew Dillon #if 0
109572ff6f6SMatthew Dillon 	HAL_PHYERR_PARAM pe;
110572ff6f6SMatthew Dillon 
111572ff6f6SMatthew Dillon 	/* Check if the hardware supports radar reporting */
112572ff6f6SMatthew Dillon 	/* XXX TODO: migrate HAL_CAP_RADAR/HAL_CAP_AR to somewhere public! */
113572ff6f6SMatthew Dillon 	if (ath_hal_getcapability(sc->sc_ah,
114572ff6f6SMatthew Dillon 	    HAL_CAP_PHYDIAG, 0, NULL) != HAL_OK)
115572ff6f6SMatthew Dillon 		return (0);
116572ff6f6SMatthew Dillon 
117572ff6f6SMatthew Dillon 	/* Check if the current channel is radar-enabled */
118572ff6f6SMatthew Dillon 	if (! IEEE80211_IS_CHAN_DFS(chan))
119572ff6f6SMatthew Dillon 		return (0);
120572ff6f6SMatthew Dillon 
121572ff6f6SMatthew Dillon 	/* Fetch the default parameters */
122572ff6f6SMatthew Dillon 	memset(&pe, '\0', sizeof(pe));
123572ff6f6SMatthew Dillon 	if (! ath_hal_getdfsdefaultthresh(sc->sc_ah, &pe))
124572ff6f6SMatthew Dillon 		return (0);
125572ff6f6SMatthew Dillon 
126572ff6f6SMatthew Dillon 	/* Enable radar PHY error reporting */
127572ff6f6SMatthew Dillon 	sc->sc_dodfs = 1;
128572ff6f6SMatthew Dillon 
129572ff6f6SMatthew Dillon 	/* Tell the hardware to enable radar reporting */
130572ff6f6SMatthew Dillon 	pe.pe_enabled = 1;
131572ff6f6SMatthew Dillon 
132572ff6f6SMatthew Dillon 	/* Flip on extension channel events only if doing HT40 */
133572ff6f6SMatthew Dillon 	if (IEEE80211_IS_CHAN_HT40(chan))
134572ff6f6SMatthew Dillon 		pe.pe_extchannel = 1;
135572ff6f6SMatthew Dillon 	else
136572ff6f6SMatthew Dillon 		pe.pe_extchannel = 0;
137572ff6f6SMatthew Dillon 
138572ff6f6SMatthew Dillon 	ath_hal_enabledfs(sc->sc_ah, &pe);
139572ff6f6SMatthew Dillon 
140572ff6f6SMatthew Dillon 	/*
141572ff6f6SMatthew Dillon 	 * Disable strong signal fast diversity - needed for
142572ff6f6SMatthew Dillon 	 * AR5212 and similar PHYs for reliable short pulse
143572ff6f6SMatthew Dillon 	 * duration.
144572ff6f6SMatthew Dillon 	 */
145572ff6f6SMatthew Dillon 	(void) ath_hal_setcapability(sc->sc_ah, HAL_CAP_DIVERSITY, 2, 0, NULL);
146572ff6f6SMatthew Dillon 
147572ff6f6SMatthew Dillon 	return (1);
148572ff6f6SMatthew Dillon #else
149572ff6f6SMatthew Dillon 	return (0);
150572ff6f6SMatthew Dillon #endif
151572ff6f6SMatthew Dillon }
152572ff6f6SMatthew Dillon 
153572ff6f6SMatthew Dillon /*
154572ff6f6SMatthew Dillon  * Explicity disable radar reporting.
155572ff6f6SMatthew Dillon  *
156572ff6f6SMatthew Dillon  * Return 0 if it was disabled, < 0 on error.
157572ff6f6SMatthew Dillon  */
158572ff6f6SMatthew Dillon int
ath_dfs_radar_disable(struct ath_softc * sc)159572ff6f6SMatthew Dillon ath_dfs_radar_disable(struct ath_softc *sc)
160572ff6f6SMatthew Dillon {
161572ff6f6SMatthew Dillon #if 0
162572ff6f6SMatthew Dillon 	HAL_PHYERR_PARAM pe;
163572ff6f6SMatthew Dillon 
164572ff6f6SMatthew Dillon 	(void) ath_hal_getdfsthresh(sc->sc_ah, &pe);
165572ff6f6SMatthew Dillon 	pe.pe_enabled = 0;
166572ff6f6SMatthew Dillon 	(void) ath_hal_enabledfs(sc->sc_ah, &pe);
167572ff6f6SMatthew Dillon 	return (0);
168572ff6f6SMatthew Dillon #else
169572ff6f6SMatthew Dillon 	return (0);
170572ff6f6SMatthew Dillon #endif
171572ff6f6SMatthew Dillon }
172572ff6f6SMatthew Dillon 
173572ff6f6SMatthew Dillon /*
174572ff6f6SMatthew Dillon  * Process DFS related PHY errors
175572ff6f6SMatthew Dillon  *
176572ff6f6SMatthew Dillon  * The mbuf is not "ours" and if we want a copy, we have
177572ff6f6SMatthew Dillon  * to take a copy.  It'll be freed after this function returns.
178572ff6f6SMatthew Dillon  */
179572ff6f6SMatthew Dillon void
ath_dfs_process_phy_err(struct ath_softc * sc,struct mbuf * m,uint64_t tsf,struct ath_rx_status * rxstat)180572ff6f6SMatthew Dillon ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,
181572ff6f6SMatthew Dillon     uint64_t tsf, struct ath_rx_status *rxstat)
182572ff6f6SMatthew Dillon {
183572ff6f6SMatthew Dillon 
184572ff6f6SMatthew Dillon }
185572ff6f6SMatthew Dillon 
186572ff6f6SMatthew Dillon /*
187b14ca477SMatthew Dillon  * Process the radar events and determine whether a DFS event has occurred.
188572ff6f6SMatthew Dillon  *
189572ff6f6SMatthew Dillon  * This is designed to run outside of the RX processing path.
190572ff6f6SMatthew Dillon  * The RX path will call ath_dfs_tasklet_needed() to see whether
191572ff6f6SMatthew Dillon  * the task/callback running this routine needs to be called.
192572ff6f6SMatthew Dillon  */
193572ff6f6SMatthew Dillon int
ath_dfs_process_radar_event(struct ath_softc * sc,struct ieee80211_channel * chan)194572ff6f6SMatthew Dillon ath_dfs_process_radar_event(struct ath_softc *sc,
195572ff6f6SMatthew Dillon     struct ieee80211_channel *chan)
196572ff6f6SMatthew Dillon {
197572ff6f6SMatthew Dillon 	return (0);
198572ff6f6SMatthew Dillon }
199572ff6f6SMatthew Dillon 
200572ff6f6SMatthew Dillon /*
201572ff6f6SMatthew Dillon  * Determine whether the DFS check task needs to be queued.
202572ff6f6SMatthew Dillon  *
203572ff6f6SMatthew Dillon  * This is called in the RX task when the current batch of packets
204572ff6f6SMatthew Dillon  * have been received. It will return whether there are any radar
205572ff6f6SMatthew Dillon  * events for ath_dfs_process_radar_event() to handle.
206572ff6f6SMatthew Dillon  */
207572ff6f6SMatthew Dillon int
ath_dfs_tasklet_needed(struct ath_softc * sc,struct ieee80211_channel * chan)208572ff6f6SMatthew Dillon ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
209572ff6f6SMatthew Dillon {
210572ff6f6SMatthew Dillon 	return (0);
211572ff6f6SMatthew Dillon }
212572ff6f6SMatthew Dillon 
213572ff6f6SMatthew Dillon /*
214572ff6f6SMatthew Dillon  * Handle ioctl requests from the diagnostic interface.
215572ff6f6SMatthew Dillon  *
216572ff6f6SMatthew Dillon  * The initial part of this code resembles ath_ioctl_diag();
217572ff6f6SMatthew Dillon  * it's likely a good idea to reduce duplication between
218572ff6f6SMatthew Dillon  * these two routines.
219572ff6f6SMatthew Dillon  */
220572ff6f6SMatthew Dillon int
ath_ioctl_phyerr(struct ath_softc * sc,struct ath_diag * ad)221572ff6f6SMatthew Dillon ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
222572ff6f6SMatthew Dillon {
223572ff6f6SMatthew Dillon 	unsigned int id = ad->ad_id & ATH_DIAG_ID;
224572ff6f6SMatthew Dillon 	void *indata = NULL;
225572ff6f6SMatthew Dillon 	void *outdata = NULL;
226572ff6f6SMatthew Dillon 	u_int32_t insize = ad->ad_in_size;
227572ff6f6SMatthew Dillon 	u_int32_t outsize = ad->ad_out_size;
228572ff6f6SMatthew Dillon 	int error = 0;
229572ff6f6SMatthew Dillon 	HAL_PHYERR_PARAM peout;
230572ff6f6SMatthew Dillon 	HAL_PHYERR_PARAM *pe;
231572ff6f6SMatthew Dillon 
232572ff6f6SMatthew Dillon 	if (ad->ad_id & ATH_DIAG_IN) {
233572ff6f6SMatthew Dillon 		/*
234572ff6f6SMatthew Dillon 		 * Copy in data.
235572ff6f6SMatthew Dillon 		 */
236dc249793SMatthew Dillon 		indata = kmalloc(insize, M_TEMP, M_INTWAIT);
237572ff6f6SMatthew Dillon 		if (indata == NULL) {
238572ff6f6SMatthew Dillon 			error = ENOMEM;
239572ff6f6SMatthew Dillon 			goto bad;
240572ff6f6SMatthew Dillon 		}
241572ff6f6SMatthew Dillon 		error = copyin(ad->ad_in_data, indata, insize);
242572ff6f6SMatthew Dillon 		if (error)
243572ff6f6SMatthew Dillon 			goto bad;
244572ff6f6SMatthew Dillon 	}
245572ff6f6SMatthew Dillon 	if (ad->ad_id & ATH_DIAG_DYN) {
246572ff6f6SMatthew Dillon 		/*
247572ff6f6SMatthew Dillon 		 * Allocate a buffer for the results (otherwise the HAL
248572ff6f6SMatthew Dillon 		 * returns a pointer to a buffer where we can read the
249572ff6f6SMatthew Dillon 		 * results).  Note that we depend on the HAL leaving this
250572ff6f6SMatthew Dillon 		 * pointer for us to use below in reclaiming the buffer;
251572ff6f6SMatthew Dillon 		 * may want to be more defensive.
252572ff6f6SMatthew Dillon 		 */
253dc249793SMatthew Dillon 		outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
254572ff6f6SMatthew Dillon 		if (outdata == NULL) {
255572ff6f6SMatthew Dillon 			error = ENOMEM;
256572ff6f6SMatthew Dillon 			goto bad;
257572ff6f6SMatthew Dillon 		}
258572ff6f6SMatthew Dillon 	}
259572ff6f6SMatthew Dillon 	switch (id) {
260572ff6f6SMatthew Dillon 		case DFS_SET_THRESH:
261572ff6f6SMatthew Dillon 			if (insize < sizeof(HAL_PHYERR_PARAM)) {
262572ff6f6SMatthew Dillon 				error = EINVAL;
263572ff6f6SMatthew Dillon 				break;
264572ff6f6SMatthew Dillon 			}
265572ff6f6SMatthew Dillon 			pe = (HAL_PHYERR_PARAM *) indata;
266572ff6f6SMatthew Dillon 			ath_hal_enabledfs(sc->sc_ah, pe);
267572ff6f6SMatthew Dillon 			break;
268572ff6f6SMatthew Dillon 		case DFS_GET_THRESH:
269572ff6f6SMatthew Dillon 			memset(&peout, 0, sizeof(peout));
270572ff6f6SMatthew Dillon 			outsize = sizeof(HAL_PHYERR_PARAM);
271572ff6f6SMatthew Dillon 			ath_hal_getdfsthresh(sc->sc_ah, &peout);
272572ff6f6SMatthew Dillon 			pe = (HAL_PHYERR_PARAM *) outdata;
273572ff6f6SMatthew Dillon 			memcpy(pe, &peout, sizeof(*pe));
274572ff6f6SMatthew Dillon 			break;
275572ff6f6SMatthew Dillon 		default:
276572ff6f6SMatthew Dillon 			error = EINVAL;
277572ff6f6SMatthew Dillon 	}
278572ff6f6SMatthew Dillon 	if (outsize < ad->ad_out_size)
279572ff6f6SMatthew Dillon 		ad->ad_out_size = outsize;
280572ff6f6SMatthew Dillon 	if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
281572ff6f6SMatthew Dillon 		error = EFAULT;
282572ff6f6SMatthew Dillon bad:
283572ff6f6SMatthew Dillon 	if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
284dc249793SMatthew Dillon 		kfree(indata, M_TEMP);
285572ff6f6SMatthew Dillon 	if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
286dc249793SMatthew Dillon 		kfree(outdata, M_TEMP);
287572ff6f6SMatthew Dillon 	return (error);
288572ff6f6SMatthew Dillon }
289572ff6f6SMatthew Dillon 
290572ff6f6SMatthew Dillon /*
291572ff6f6SMatthew Dillon  * Get the current DFS thresholds from the HAL
292572ff6f6SMatthew Dillon  */
293572ff6f6SMatthew Dillon int
ath_dfs_get_thresholds(struct ath_softc * sc,HAL_PHYERR_PARAM * param)294572ff6f6SMatthew Dillon ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
295572ff6f6SMatthew Dillon {
296572ff6f6SMatthew Dillon 	ath_hal_getdfsthresh(sc->sc_ah, param);
297572ff6f6SMatthew Dillon 	return (1);
298572ff6f6SMatthew Dillon }
299dc249793SMatthew Dillon 
300dc249793SMatthew Dillon #if defined(__DragonFly__)
301dc249793SMatthew Dillon /*
302dc249793SMatthew Dillon  * Module glue.
303dc249793SMatthew Dillon  */
304dc249793SMatthew Dillon static int
null_dfs_modevent(module_t mod,int type,void * unused)305dc249793SMatthew Dillon null_dfs_modevent(module_t mod, int type, void *unused)
306dc249793SMatthew Dillon {
307dc249793SMatthew Dillon 	int error;
308dc249793SMatthew Dillon 
309dc249793SMatthew Dillon 	wlan_serialize_enter();
310dc249793SMatthew Dillon 
311dc249793SMatthew Dillon 	switch (type) {
312dc249793SMatthew Dillon 	case MOD_LOAD:
313dc249793SMatthew Dillon 		if (bootverbose) {
314dc249793SMatthew Dillon 			kprintf("ath_dfs: WTF module\n");
315dc249793SMatthew Dillon 		}
316dc249793SMatthew Dillon 		error = 0;
317dc249793SMatthew Dillon 		break;
318dc249793SMatthew Dillon 	case MOD_UNLOAD:
319dc249793SMatthew Dillon 		error = 0;
320dc249793SMatthew Dillon 		break;
321dc249793SMatthew Dillon 	default:
322dc249793SMatthew Dillon 		error = EINVAL;
323dc249793SMatthew Dillon 		break;
324dc249793SMatthew Dillon 	}
325dc249793SMatthew Dillon 	wlan_serialize_exit();
326dc249793SMatthew Dillon 
327dc249793SMatthew Dillon 	return error;
328dc249793SMatthew Dillon }
329dc249793SMatthew Dillon 
330dc249793SMatthew Dillon static moduledata_t null_dfs_mod = {
331dc249793SMatthew Dillon 	"ath_dfs",
332dc249793SMatthew Dillon 	null_dfs_modevent,
333dc249793SMatthew Dillon 	0
334dc249793SMatthew Dillon };
335dc249793SMatthew Dillon 
336dc249793SMatthew Dillon DECLARE_MODULE(ath_dfs, null_dfs_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
337dc249793SMatthew Dillon MODULE_VERSION(ath_dfs, 1);
338dc249793SMatthew Dillon 
339dc249793SMatthew Dillon #endif
340