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