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