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