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