xref: /dflybsd-src/sys/dev/netif/ath/ath_dfs/null/dfs_null.c (revision 5cd80a8ca6f18f728c9f1e9bd79270cf365cb3a4)
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 <machine/resource.h>
67 
68 #include <dev/netif/ath/ath/if_athvar.h>
69 #include <dev/netif/ath/ath/if_athdfs.h>
70 
71 #include <dev/netif/ath/ath_hal/ah_desc.h>
72 
73 /*
74  * Methods which are required
75  */
76 
77 /*
78  * Attach DFS to the given interface
79  */
80 int
81 ath_dfs_attach(struct ath_softc *sc)
82 {
83 	return (1);
84 }
85 
86 /*
87  * Detach DFS from the given interface
88  */
89 int
90 ath_dfs_detach(struct ath_softc *sc)
91 {
92 	return (1);
93 }
94 
95 /*
96  * Enable radar check.  Return 1 if the driver should
97  * enable radar PHY errors, or 0 if not.
98  */
99 int
100 ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
101 {
102 #if 0
103 	HAL_PHYERR_PARAM pe;
104 
105 	/* Check if the hardware supports radar reporting */
106 	/* XXX TODO: migrate HAL_CAP_RADAR/HAL_CAP_AR to somewhere public! */
107 	if (ath_hal_getcapability(sc->sc_ah,
108 	    HAL_CAP_PHYDIAG, 0, NULL) != HAL_OK)
109 		return (0);
110 
111 	/* Check if the current channel is radar-enabled */
112 	if (! IEEE80211_IS_CHAN_DFS(chan))
113 		return (0);
114 
115 	/* Fetch the default parameters */
116 	memset(&pe, '\0', sizeof(pe));
117 	if (! ath_hal_getdfsdefaultthresh(sc->sc_ah, &pe))
118 		return (0);
119 
120 	/* Enable radar PHY error reporting */
121 	sc->sc_dodfs = 1;
122 
123 	/* Tell the hardware to enable radar reporting */
124 	pe.pe_enabled = 1;
125 
126 	/* Flip on extension channel events only if doing HT40 */
127 	if (IEEE80211_IS_CHAN_HT40(chan))
128 		pe.pe_extchannel = 1;
129 	else
130 		pe.pe_extchannel = 0;
131 
132 	ath_hal_enabledfs(sc->sc_ah, &pe);
133 
134 	/*
135 	 * Disable strong signal fast diversity - needed for
136 	 * AR5212 and similar PHYs for reliable short pulse
137 	 * duration.
138 	 */
139 	(void) ath_hal_setcapability(sc->sc_ah, HAL_CAP_DIVERSITY, 2, 0, NULL);
140 
141 	return (1);
142 #else
143 	return (0);
144 #endif
145 }
146 
147 /*
148  * Explicity disable radar reporting.
149  *
150  * Return 0 if it was disabled, < 0 on error.
151  */
152 int
153 ath_dfs_radar_disable(struct ath_softc *sc)
154 {
155 #if 0
156 	HAL_PHYERR_PARAM pe;
157 
158 	(void) ath_hal_getdfsthresh(sc->sc_ah, &pe);
159 	pe.pe_enabled = 0;
160 	(void) ath_hal_enabledfs(sc->sc_ah, &pe);
161 	return (0);
162 #else
163 	return (0);
164 #endif
165 }
166 
167 /*
168  * Process DFS related PHY errors
169  *
170  * The mbuf is not "ours" and if we want a copy, we have
171  * to take a copy.  It'll be freed after this function returns.
172  */
173 void
174 ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,
175     uint64_t tsf, struct ath_rx_status *rxstat)
176 {
177 
178 }
179 
180 /*
181  * Process the radar events and determine whether a DFS event has occured.
182  *
183  * This is designed to run outside of the RX processing path.
184  * The RX path will call ath_dfs_tasklet_needed() to see whether
185  * the task/callback running this routine needs to be called.
186  */
187 int
188 ath_dfs_process_radar_event(struct ath_softc *sc,
189     struct ieee80211_channel *chan)
190 {
191 	return (0);
192 }
193 
194 /*
195  * Determine whether the DFS check task needs to be queued.
196  *
197  * This is called in the RX task when the current batch of packets
198  * have been received. It will return whether there are any radar
199  * events for ath_dfs_process_radar_event() to handle.
200  */
201 int
202 ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
203 {
204 	return (0);
205 }
206 
207 /*
208  * Handle ioctl requests from the diagnostic interface.
209  *
210  * The initial part of this code resembles ath_ioctl_diag();
211  * it's likely a good idea to reduce duplication between
212  * these two routines.
213  */
214 int
215 ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
216 {
217 	unsigned int id = ad->ad_id & ATH_DIAG_ID;
218 	void *indata = NULL;
219 	void *outdata = NULL;
220 	u_int32_t insize = ad->ad_in_size;
221 	u_int32_t outsize = ad->ad_out_size;
222 	int error = 0;
223 	HAL_PHYERR_PARAM peout;
224 	HAL_PHYERR_PARAM *pe;
225 
226 	if (ad->ad_id & ATH_DIAG_IN) {
227 		/*
228 		 * Copy in data.
229 		 */
230 		indata = malloc(insize, M_TEMP, M_NOWAIT);
231 		if (indata == NULL) {
232 			error = ENOMEM;
233 			goto bad;
234 		}
235 		error = copyin(ad->ad_in_data, indata, insize);
236 		if (error)
237 			goto bad;
238 	}
239 	if (ad->ad_id & ATH_DIAG_DYN) {
240 		/*
241 		 * Allocate a buffer for the results (otherwise the HAL
242 		 * returns a pointer to a buffer where we can read the
243 		 * results).  Note that we depend on the HAL leaving this
244 		 * pointer for us to use below in reclaiming the buffer;
245 		 * may want to be more defensive.
246 		 */
247 		outdata = malloc(outsize, M_TEMP, M_NOWAIT);
248 		if (outdata == NULL) {
249 			error = ENOMEM;
250 			goto bad;
251 		}
252 	}
253 	switch (id) {
254 		case DFS_SET_THRESH:
255 			if (insize < sizeof(HAL_PHYERR_PARAM)) {
256 				error = EINVAL;
257 				break;
258 			}
259 			pe = (HAL_PHYERR_PARAM *) indata;
260 			ath_hal_enabledfs(sc->sc_ah, pe);
261 			break;
262 		case DFS_GET_THRESH:
263 			memset(&peout, 0, sizeof(peout));
264 			outsize = sizeof(HAL_PHYERR_PARAM);
265 			ath_hal_getdfsthresh(sc->sc_ah, &peout);
266 			pe = (HAL_PHYERR_PARAM *) outdata;
267 			memcpy(pe, &peout, sizeof(*pe));
268 			break;
269 		default:
270 			error = EINVAL;
271 	}
272 	if (outsize < ad->ad_out_size)
273 		ad->ad_out_size = outsize;
274 	if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
275 		error = EFAULT;
276 bad:
277 	if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
278 		free(indata, M_TEMP);
279 	if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
280 		free(outdata, M_TEMP);
281 	return (error);
282 }
283 
284 /*
285  * Get the current DFS thresholds from the HAL
286  */
287 int
288 ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
289 {
290 	ath_hal_getdfsthresh(sc->sc_ah, param);
291 	return (1);
292 }
293