xref: /freebsd/sys/dev/ath/ath_dfs/null/dfs_null.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer,
12  *    without modification.
13  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15  *    redistribution must be conditioned upon including a substantially
16  *    similar Disclaimer requirement for further binary redistribution.
17  *
18  * NO WARRANTY
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
22  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
24  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29  * THE POSSIBILITY OF SUCH DAMAGES.
30  */
31 #include <sys/cdefs.h>
32 /*
33  * This implements an empty DFS module.
34  */
35 #include "opt_ath.h"
36 #include "opt_inet.h"
37 #include "opt_wlan.h"
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/sysctl.h>
42 #include <sys/kernel.h>
43 #include <sys/lock.h>
44 #include <sys/malloc.h>
45 #include <sys/mutex.h>
46 #include <sys/errno.h>
47 
48 #include <machine/bus.h>
49 #include <machine/resource.h>
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 <net80211/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/ath/if_athvar.h>
70 #include <dev/ath/if_athdfs.h>
71 
72 #include <dev/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
ath_dfs_attach(struct ath_softc * sc)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
ath_dfs_detach(struct ath_softc * sc)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
ath_dfs_radar_enable(struct ath_softc * sc,struct ieee80211_channel * chan)101 ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
102 {
103 #if 1
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
ath_dfs_radar_disable(struct ath_softc * sc)154 ath_dfs_radar_disable(struct ath_softc *sc)
155 {
156 #if 1
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
ath_dfs_process_phy_err(struct ath_softc * sc,struct mbuf * m,uint64_t tsf,struct ath_rx_status * rxstat)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 occurred.
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
ath_dfs_process_radar_event(struct ath_softc * sc,struct ieee80211_channel * chan)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
ath_dfs_tasklet_needed(struct ath_softc * sc,struct ieee80211_channel * chan)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
ath_ioctl_phyerr(struct ath_softc * sc,struct ath_diag * ad)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 = malloc(insize, M_TEMP, M_NOWAIT);
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 = malloc(outsize, M_TEMP, M_NOWAIT);
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 		free(indata, M_TEMP);
280 	if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
281 		free(outdata, M_TEMP);
282 	return (error);
283 }
284 
285 /*
286  * Get the current DFS thresholds from the HAL
287  */
288 int
ath_dfs_get_thresholds(struct ath_softc * sc,HAL_PHYERR_PARAM * param)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