xref: /freebsd/sys/dev/ath/ath_dfs/null/dfs_null.c (revision b7d683e608ac894e75b2de7eac5eaa083650de54)
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/mutex.h>
47 #include <sys/errno.h>
48 
49 #include <machine/bus.h>
50 #include <machine/resource.h>
51 #include <sys/bus.h>
52 
53 #include <sys/socket.h>
54 
55 #include <net/if.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
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 	return (1);
136 #else
137 	return (0);
138 #endif
139 }
140 
141 /*
142  * Process DFS related PHY errors
143  *
144  * The mbuf is not "ours" and if we want a copy, we have
145  * to take a copy.  It'll be freed after this function returns.
146  */
147 void
148 ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,
149     uint64_t tsf, struct ath_rx_status *rxstat)
150 {
151 
152 }
153 
154 /*
155  * Process the radar events and determine whether a DFS event has occured.
156  *
157  * This is designed to run outside of the RX processing path.
158  * The RX path will call ath_dfs_tasklet_needed() to see whether
159  * the task/callback running this routine needs to be called.
160  */
161 int
162 ath_dfs_process_radar_event(struct ath_softc *sc,
163     struct ieee80211_channel *chan)
164 {
165 	return (0);
166 }
167 
168 /*
169  * Determine whether the DFS check task needs to be queued.
170  *
171  * This is called in the RX task when the current batch of packets
172  * have been received. It will return whether there are any radar
173  * events for ath_dfs_process_radar_event() to handle.
174  */
175 int
176 ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
177 {
178 	return (0);
179 }
180 
181 /*
182  * Handle ioctl requests from the diagnostic interface.
183  *
184  * The initial part of this code resembles ath_ioctl_diag();
185  * it's likely a good idea to reduce duplication between
186  * these two routines.
187  */
188 int
189 ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
190 {
191 	unsigned int id = ad->ad_id & ATH_DIAG_ID;
192 	void *indata = NULL;
193 	void *outdata = NULL;
194 	u_int32_t insize = ad->ad_in_size;
195 	u_int32_t outsize = ad->ad_out_size;
196 	int error = 0;
197 	HAL_PHYERR_PARAM peout;
198 	HAL_PHYERR_PARAM *pe;
199 
200 	if (ad->ad_id & ATH_DIAG_IN) {
201 		/*
202 		 * Copy in data.
203 		 */
204 		indata = malloc(insize, M_TEMP, M_NOWAIT);
205 		if (indata == NULL) {
206 			error = ENOMEM;
207 			goto bad;
208 		}
209 		error = copyin(ad->ad_in_data, indata, insize);
210 		if (error)
211 			goto bad;
212 	}
213 	if (ad->ad_id & ATH_DIAG_DYN) {
214 		/*
215 		 * Allocate a buffer for the results (otherwise the HAL
216 		 * returns a pointer to a buffer where we can read the
217 		 * results).  Note that we depend on the HAL leaving this
218 		 * pointer for us to use below in reclaiming the buffer;
219 		 * may want to be more defensive.
220 		 */
221 		outdata = malloc(outsize, M_TEMP, M_NOWAIT);
222 		if (outdata == NULL) {
223 			error = ENOMEM;
224 			goto bad;
225 		}
226 	}
227 	switch (id) {
228 		case DFS_SET_THRESH:
229 			if (insize < sizeof(HAL_PHYERR_PARAM)) {
230 				error = EINVAL;
231 				break;
232 			}
233 			pe = (HAL_PHYERR_PARAM *) indata;
234 			ath_hal_enabledfs(sc->sc_ah, pe);
235 			break;
236 		case DFS_GET_THRESH:
237 			memset(&peout, 0, sizeof(peout));
238 			outsize = sizeof(HAL_PHYERR_PARAM);
239 			ath_hal_getdfsthresh(sc->sc_ah, &peout);
240 			pe = (HAL_PHYERR_PARAM *) outdata;
241 			memcpy(pe, &peout, sizeof(*pe));
242 			break;
243 		default:
244 			error = EINVAL;
245 	}
246 	if (outsize < ad->ad_out_size)
247 		ad->ad_out_size = outsize;
248 	if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
249 		error = EFAULT;
250 bad:
251 	if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
252 		free(indata, M_TEMP);
253 	if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
254 		free(outdata, M_TEMP);
255 	return (error);
256 }
257 
258 /*
259  * Get the current DFS thresholds from the HAL
260  */
261 int
262 ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
263 {
264 	ath_hal_getdfsthresh(sc->sc_ah, param);
265 	return (1);
266 }
267