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