Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Qualcomm Atheros, Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/relay.h> |
| 18 | #include "ath9k.h" |
| 19 | |
| 20 | static s8 fix_rssi_inv_only(u8 rssi_val) |
| 21 | { |
| 22 | if (rssi_val == 128) |
| 23 | rssi_val = 0; |
| 24 | return (s8) rssi_val; |
| 25 | } |
| 26 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 27 | static void ath_debug_send_fft_sample(struct ath_spec_scan_priv *spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 28 | struct fft_sample_tlv *fft_sample_tlv) |
| 29 | { |
| 30 | int length; |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 31 | if (!spec_priv->rfs_chan_spec_scan) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 32 | return; |
| 33 | |
| 34 | length = __be16_to_cpu(fft_sample_tlv->length) + |
| 35 | sizeof(*fft_sample_tlv); |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 36 | relay_write(spec_priv->rfs_chan_spec_scan, fft_sample_tlv, length); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 37 | } |
| 38 | |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 39 | typedef int (ath_cmn_fft_idx_validator) (u8 *sample_end, int bytes_read); |
| 40 | |
| 41 | static int |
| 42 | ath_cmn_max_idx_verify_ht20_fft(u8 *sample_end, int bytes_read) |
| 43 | { |
| 44 | struct ath_ht20_mag_info *mag_info; |
| 45 | u8 *sample; |
| 46 | u16 max_magnitude; |
| 47 | u8 max_index; |
| 48 | u8 max_exp; |
| 49 | |
| 50 | /* Sanity check so that we don't read outside the read |
| 51 | * buffer |
| 52 | */ |
| 53 | if (bytes_read < SPECTRAL_HT20_SAMPLE_LEN - 1) |
| 54 | return -1; |
| 55 | |
| 56 | mag_info = (struct ath_ht20_mag_info *) (sample_end - |
| 57 | sizeof(struct ath_ht20_mag_info) + 1); |
| 58 | |
| 59 | sample = sample_end - SPECTRAL_HT20_SAMPLE_LEN + 1; |
| 60 | |
| 61 | max_index = spectral_max_index(mag_info->all_bins, |
| 62 | SPECTRAL_HT20_NUM_BINS); |
| 63 | max_magnitude = spectral_max_magnitude(mag_info->all_bins); |
| 64 | |
| 65 | max_exp = mag_info->max_exp & 0xf; |
| 66 | |
| 67 | /* Don't try to read something outside the read buffer |
| 68 | * in case of a missing byte (so bins[0] will be outside |
| 69 | * the read buffer) |
| 70 | */ |
| 71 | if (bytes_read < SPECTRAL_HT20_SAMPLE_LEN && max_index < 1) |
| 72 | return -1; |
| 73 | |
| 74 | if (sample[max_index] != (max_magnitude >> max_exp)) |
| 75 | return -1; |
| 76 | else |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static int |
| 81 | ath_cmn_max_idx_verify_ht20_40_fft(u8 *sample_end, int bytes_read) |
| 82 | { |
| 83 | struct ath_ht20_40_mag_info *mag_info; |
| 84 | u8 *sample; |
| 85 | u16 lower_mag, upper_mag; |
| 86 | u8 lower_max_index, upper_max_index; |
| 87 | u8 max_exp; |
| 88 | int dc_pos = SPECTRAL_HT20_40_NUM_BINS / 2; |
| 89 | |
| 90 | /* Sanity check so that we don't read outside the read |
| 91 | * buffer |
| 92 | */ |
| 93 | if (bytes_read < SPECTRAL_HT20_40_SAMPLE_LEN - 1) |
| 94 | return -1; |
| 95 | |
| 96 | mag_info = (struct ath_ht20_40_mag_info *) (sample_end - |
| 97 | sizeof(struct ath_ht20_40_mag_info) + 1); |
| 98 | |
| 99 | sample = sample_end - SPECTRAL_HT20_40_SAMPLE_LEN + 1; |
| 100 | |
| 101 | lower_mag = spectral_max_magnitude(mag_info->lower_bins); |
| 102 | lower_max_index = spectral_max_index(mag_info->lower_bins, |
| 103 | SPECTRAL_HT20_40_NUM_BINS); |
| 104 | |
| 105 | upper_mag = spectral_max_magnitude(mag_info->upper_bins); |
| 106 | upper_max_index = spectral_max_index(mag_info->upper_bins, |
| 107 | SPECTRAL_HT20_40_NUM_BINS); |
| 108 | |
| 109 | max_exp = mag_info->max_exp & 0xf; |
| 110 | |
| 111 | /* Don't try to read something outside the read buffer |
| 112 | * in case of a missing byte (so bins[0] will be outside |
| 113 | * the read buffer) |
| 114 | */ |
| 115 | if (bytes_read < SPECTRAL_HT20_40_SAMPLE_LEN && |
| 116 | ((upper_max_index < 1) || (lower_max_index < 1))) |
| 117 | return -1; |
| 118 | |
| 119 | /* Some time hardware messes up the index and adds |
| 120 | * the index of the middle point (dc_pos). Try to fix it. |
| 121 | */ |
| 122 | if ((upper_max_index - dc_pos > 0) && |
| 123 | (sample[upper_max_index] == (upper_mag >> max_exp))) |
| 124 | upper_max_index -= dc_pos; |
| 125 | |
| 126 | if ((lower_max_index - dc_pos > 0) && |
| 127 | (sample[lower_max_index - dc_pos] == (lower_mag >> max_exp))) |
| 128 | lower_max_index -= dc_pos; |
| 129 | |
| 130 | if ((sample[upper_max_index + dc_pos] != (upper_mag >> max_exp)) || |
| 131 | (sample[lower_max_index] != (lower_mag >> max_exp))) |
| 132 | return -1; |
| 133 | else |
| 134 | return 0; |
| 135 | } |
| 136 | |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 137 | typedef int (ath_cmn_fft_sample_handler) (struct ath_rx_status *rs, |
| 138 | struct ath_spec_scan_priv *spec_priv, |
| 139 | u8 *sample_buf, u64 tsf, u16 freq, int chan_type); |
| 140 | |
| 141 | static int |
| 142 | ath_cmn_process_ht20_fft(struct ath_rx_status *rs, |
| 143 | struct ath_spec_scan_priv *spec_priv, |
| 144 | u8 *sample_buf, |
| 145 | u64 tsf, u16 freq, int chan_type) |
| 146 | { |
| 147 | struct fft_sample_ht20 fft_sample_20; |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 148 | struct ath_common *common = ath9k_hw_common(spec_priv->ah); |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 149 | struct ath_hw *ah = spec_priv->ah; |
| 150 | struct ath_ht20_mag_info *mag_info; |
| 151 | struct fft_sample_tlv *tlv; |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 152 | int i = 0; |
| 153 | int ret = 0; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 154 | int dc_pos = SPECTRAL_HT20_NUM_BINS / 2; |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 155 | u16 magnitude, tmp_mag, length; |
| 156 | u8 max_index, bitmap_w, max_exp; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 157 | |
| 158 | length = sizeof(fft_sample_20) - sizeof(struct fft_sample_tlv); |
| 159 | fft_sample_20.tlv.type = ATH_FFT_SAMPLE_HT20; |
| 160 | fft_sample_20.tlv.length = __cpu_to_be16(length); |
| 161 | fft_sample_20.freq = __cpu_to_be16(freq); |
| 162 | fft_sample_20.rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]); |
| 163 | fft_sample_20.noise = ah->noise; |
| 164 | |
| 165 | mag_info = (struct ath_ht20_mag_info *) (sample_buf + |
| 166 | SPECTRAL_HT20_NUM_BINS); |
| 167 | |
| 168 | magnitude = spectral_max_magnitude(mag_info->all_bins); |
| 169 | fft_sample_20.max_magnitude = __cpu_to_be16(magnitude); |
| 170 | |
| 171 | max_index = spectral_max_index(mag_info->all_bins, |
| 172 | SPECTRAL_HT20_NUM_BINS); |
| 173 | fft_sample_20.max_index = max_index; |
| 174 | |
| 175 | bitmap_w = spectral_bitmap_weight(mag_info->all_bins); |
| 176 | fft_sample_20.bitmap_weight = bitmap_w; |
| 177 | |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 178 | max_exp = mag_info->max_exp & 0xf; |
| 179 | fft_sample_20.max_exp = max_exp; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 180 | |
| 181 | fft_sample_20.tsf = __cpu_to_be64(tsf); |
| 182 | |
| 183 | memcpy(fft_sample_20.data, sample_buf, SPECTRAL_HT20_NUM_BINS); |
| 184 | |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 185 | ath_dbg(common, SPECTRAL_SCAN, "FFT HT20 frame: max mag 0x%X," |
| 186 | "max_mag_idx %i\n", |
| 187 | magnitude >> max_exp, |
| 188 | max_index); |
| 189 | |
| 190 | if (fft_sample_20.data[max_index] != (magnitude >> max_exp)) { |
| 191 | ath_dbg(common, SPECTRAL_SCAN, "Magnitude mismatch !\n"); |
| 192 | ret = -1; |
| 193 | } |
| 194 | |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 195 | /* DC value (value in the middle) is the blind spot of the spectral |
| 196 | * sample and invalid, interpolate it. |
| 197 | */ |
| 198 | fft_sample_20.data[dc_pos] = (fft_sample_20.data[dc_pos + 1] + |
| 199 | fft_sample_20.data[dc_pos - 1]) / 2; |
| 200 | |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 201 | /* Check if the maximum magnitude is indeed maximum, |
| 202 | * also if the maximum value was at dc_pos, calculate |
| 203 | * a new one (since value at dc_pos is invalid). |
| 204 | */ |
| 205 | if (max_index == dc_pos) { |
| 206 | tmp_mag = 0; |
| 207 | for (i = 0; i < dc_pos; i++) { |
| 208 | if (fft_sample_20.data[i] > tmp_mag) { |
| 209 | tmp_mag = fft_sample_20.data[i]; |
| 210 | fft_sample_20.max_index = i; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | magnitude = tmp_mag << max_exp; |
| 215 | fft_sample_20.max_magnitude = __cpu_to_be16(magnitude); |
| 216 | |
| 217 | ath_dbg(common, SPECTRAL_SCAN, |
| 218 | "Calculated new lower max 0x%X at %i\n", |
| 219 | tmp_mag, fft_sample_20.max_index); |
| 220 | } else |
| 221 | for (i = 0; i < SPECTRAL_HT20_NUM_BINS; i++) { |
| 222 | if (fft_sample_20.data[i] == (magnitude >> max_exp)) |
| 223 | ath_dbg(common, SPECTRAL_SCAN, |
| 224 | "Got max: 0x%X at index %i\n", |
| 225 | fft_sample_20.data[i], i); |
| 226 | |
| 227 | if (fft_sample_20.data[i] > (magnitude >> max_exp)) { |
| 228 | ath_dbg(common, SPECTRAL_SCAN, |
| 229 | "Got bin %i greater than max: 0x%X\n", |
| 230 | i, fft_sample_20.data[i]); |
| 231 | ret = -1; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | if (ret < 0) |
| 236 | return ret; |
| 237 | |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 238 | tlv = (struct fft_sample_tlv *)&fft_sample_20; |
| 239 | |
| 240 | ath_debug_send_fft_sample(spec_priv, tlv); |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static int |
| 246 | ath_cmn_process_ht20_40_fft(struct ath_rx_status *rs, |
| 247 | struct ath_spec_scan_priv *spec_priv, |
| 248 | u8 *sample_buf, |
| 249 | u64 tsf, u16 freq, int chan_type) |
| 250 | { |
| 251 | struct fft_sample_ht20_40 fft_sample_40; |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 252 | struct ath_common *common = ath9k_hw_common(spec_priv->ah); |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 253 | struct ath_hw *ah = spec_priv->ah; |
| 254 | struct ath9k_hw_cal_data *caldata = ah->caldata; |
| 255 | struct ath_ht20_40_mag_info *mag_info; |
| 256 | struct fft_sample_tlv *tlv; |
| 257 | int dc_pos = SPECTRAL_HT20_40_NUM_BINS / 2; |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 258 | int i = 0; |
| 259 | int ret = 0; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 260 | s16 ext_nf; |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 261 | u16 lower_mag, upper_mag, tmp_mag, length; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 262 | s8 lower_rssi, upper_rssi; |
| 263 | u8 lower_max_index, upper_max_index; |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 264 | u8 lower_bitmap_w, upper_bitmap_w, max_exp; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 265 | |
| 266 | if (caldata) |
| 267 | ext_nf = ath9k_hw_getchan_noise(ah, ah->curchan, |
| 268 | caldata->nfCalHist[3].privNF); |
| 269 | else |
| 270 | ext_nf = ATH_DEFAULT_NOISE_FLOOR; |
| 271 | |
| 272 | length = sizeof(fft_sample_40) - sizeof(struct fft_sample_tlv); |
| 273 | fft_sample_40.tlv.type = ATH_FFT_SAMPLE_HT20_40; |
| 274 | fft_sample_40.tlv.length = __cpu_to_be16(length); |
| 275 | fft_sample_40.freq = __cpu_to_be16(freq); |
| 276 | fft_sample_40.channel_type = chan_type; |
| 277 | |
| 278 | if (chan_type == NL80211_CHAN_HT40PLUS) { |
| 279 | lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]); |
| 280 | upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]); |
| 281 | |
| 282 | fft_sample_40.lower_noise = ah->noise; |
| 283 | fft_sample_40.upper_noise = ext_nf; |
| 284 | } else { |
| 285 | lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]); |
| 286 | upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]); |
| 287 | |
| 288 | fft_sample_40.lower_noise = ext_nf; |
| 289 | fft_sample_40.upper_noise = ah->noise; |
| 290 | } |
| 291 | |
| 292 | fft_sample_40.lower_rssi = lower_rssi; |
| 293 | fft_sample_40.upper_rssi = upper_rssi; |
| 294 | |
| 295 | mag_info = (struct ath_ht20_40_mag_info *) (sample_buf + |
| 296 | SPECTRAL_HT20_40_NUM_BINS); |
| 297 | |
| 298 | lower_mag = spectral_max_magnitude(mag_info->lower_bins); |
| 299 | fft_sample_40.lower_max_magnitude = __cpu_to_be16(lower_mag); |
| 300 | |
| 301 | upper_mag = spectral_max_magnitude(mag_info->upper_bins); |
| 302 | fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag); |
| 303 | |
| 304 | lower_max_index = spectral_max_index(mag_info->lower_bins, |
| 305 | SPECTRAL_HT20_40_NUM_BINS); |
| 306 | fft_sample_40.lower_max_index = lower_max_index; |
| 307 | |
| 308 | upper_max_index = spectral_max_index(mag_info->upper_bins, |
| 309 | SPECTRAL_HT20_40_NUM_BINS); |
| 310 | fft_sample_40.upper_max_index = upper_max_index; |
| 311 | |
| 312 | lower_bitmap_w = spectral_bitmap_weight(mag_info->lower_bins); |
| 313 | fft_sample_40.lower_bitmap_weight = lower_bitmap_w; |
| 314 | |
| 315 | upper_bitmap_w = spectral_bitmap_weight(mag_info->upper_bins); |
| 316 | fft_sample_40.upper_bitmap_weight = upper_bitmap_w; |
| 317 | |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 318 | max_exp = mag_info->max_exp & 0xf; |
| 319 | fft_sample_40.max_exp = max_exp; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 320 | |
| 321 | fft_sample_40.tsf = __cpu_to_be64(tsf); |
| 322 | |
| 323 | memcpy(fft_sample_40.data, sample_buf, SPECTRAL_HT20_40_NUM_BINS); |
| 324 | |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 325 | ath_dbg(common, SPECTRAL_SCAN, "FFT HT20/40 frame: lower mag 0x%X," |
| 326 | "lower_mag_idx %i, upper mag 0x%X," |
| 327 | "upper_mag_idx %i\n", |
| 328 | lower_mag >> max_exp, |
| 329 | lower_max_index, |
| 330 | upper_mag >> max_exp, |
| 331 | upper_max_index); |
| 332 | |
| 333 | /* Some time hardware messes up the index and adds |
| 334 | * the index of the middle point (dc_pos). Try to fix it. |
| 335 | */ |
| 336 | if ((upper_max_index - dc_pos > 0) && |
| 337 | (fft_sample_40.data[upper_max_index] == (upper_mag >> max_exp))) { |
| 338 | upper_max_index -= dc_pos; |
| 339 | fft_sample_40.upper_max_index = upper_max_index; |
| 340 | } |
| 341 | |
| 342 | if ((lower_max_index - dc_pos > 0) && |
| 343 | (fft_sample_40.data[lower_max_index - dc_pos] == |
| 344 | (lower_mag >> max_exp))) { |
| 345 | lower_max_index -= dc_pos; |
| 346 | fft_sample_40.lower_max_index = lower_max_index; |
| 347 | } |
| 348 | |
| 349 | /* Check if we got the expected magnitude values at |
| 350 | * the expected bins |
| 351 | */ |
| 352 | if ((fft_sample_40.data[upper_max_index + dc_pos] |
| 353 | != (upper_mag >> max_exp)) || |
| 354 | (fft_sample_40.data[lower_max_index] |
| 355 | != (lower_mag >> max_exp))) { |
| 356 | ath_dbg(common, SPECTRAL_SCAN, "Magnitude mismatch !\n"); |
| 357 | ret = -1; |
| 358 | } |
| 359 | |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 360 | /* DC value (value in the middle) is the blind spot of the spectral |
| 361 | * sample and invalid, interpolate it. |
| 362 | */ |
| 363 | fft_sample_40.data[dc_pos] = (fft_sample_40.data[dc_pos + 1] + |
| 364 | fft_sample_40.data[dc_pos - 1]) / 2; |
| 365 | |
Nick Kossifidis | 7fa580c | 2015-04-29 23:51:15 +0000 | [diff] [blame] | 366 | /* Check if the maximum magnitudes are indeed maximum, |
| 367 | * also if the maximum value was at dc_pos, calculate |
| 368 | * a new one (since value at dc_pos is invalid). |
| 369 | */ |
| 370 | if (lower_max_index == dc_pos) { |
| 371 | tmp_mag = 0; |
| 372 | for (i = 0; i < dc_pos; i++) { |
| 373 | if (fft_sample_40.data[i] > tmp_mag) { |
| 374 | tmp_mag = fft_sample_40.data[i]; |
| 375 | fft_sample_40.lower_max_index = i; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | lower_mag = tmp_mag << max_exp; |
| 380 | fft_sample_40.lower_max_magnitude = __cpu_to_be16(lower_mag); |
| 381 | |
| 382 | ath_dbg(common, SPECTRAL_SCAN, |
| 383 | "Calculated new lower max 0x%X at %i\n", |
| 384 | tmp_mag, fft_sample_40.lower_max_index); |
| 385 | } else |
| 386 | for (i = 0; i < dc_pos; i++) { |
| 387 | if (fft_sample_40.data[i] == (lower_mag >> max_exp)) |
| 388 | ath_dbg(common, SPECTRAL_SCAN, |
| 389 | "Got lower mag: 0x%X at index %i\n", |
| 390 | fft_sample_40.data[i], i); |
| 391 | |
| 392 | if (fft_sample_40.data[i] > (lower_mag >> max_exp)) { |
| 393 | ath_dbg(common, SPECTRAL_SCAN, |
| 394 | "Got lower bin %i higher than max: 0x%X\n", |
| 395 | i, fft_sample_40.data[i]); |
| 396 | ret = -1; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if (upper_max_index == dc_pos) { |
| 401 | tmp_mag = 0; |
| 402 | for (i = dc_pos; i < SPECTRAL_HT20_40_NUM_BINS; i++) { |
| 403 | if (fft_sample_40.data[i] > tmp_mag) { |
| 404 | tmp_mag = fft_sample_40.data[i]; |
| 405 | fft_sample_40.upper_max_index = i; |
| 406 | } |
| 407 | } |
| 408 | upper_mag = tmp_mag << max_exp; |
| 409 | fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag); |
| 410 | |
| 411 | ath_dbg(common, SPECTRAL_SCAN, |
| 412 | "Calculated new upper max 0x%X at %i\n", |
| 413 | tmp_mag, i); |
| 414 | } else |
| 415 | for (i = dc_pos; i < SPECTRAL_HT20_40_NUM_BINS; i++) { |
| 416 | if (fft_sample_40.data[i] == (upper_mag >> max_exp)) |
| 417 | ath_dbg(common, SPECTRAL_SCAN, |
| 418 | "Got upper mag: 0x%X at index %i\n", |
| 419 | fft_sample_40.data[i], i); |
| 420 | |
| 421 | if (fft_sample_40.data[i] > (upper_mag >> max_exp)) { |
| 422 | ath_dbg(common, SPECTRAL_SCAN, |
| 423 | "Got upper bin %i higher than max: 0x%X\n", |
| 424 | i, fft_sample_40.data[i]); |
| 425 | |
| 426 | ret = -1; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | if (ret < 0) |
| 431 | return ret; |
| 432 | |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 433 | tlv = (struct fft_sample_tlv *)&fft_sample_40; |
| 434 | |
| 435 | ath_debug_send_fft_sample(spec_priv, tlv); |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
Nick Kossifidis | 0f2c75d | 2015-04-29 23:51:17 +0000 | [diff] [blame] | 440 | static inline void |
| 441 | ath_cmn_copy_fft_frame(u8 *in, u8 *out, int sample_len, int sample_bytes) |
| 442 | { |
| 443 | switch (sample_bytes - sample_len) { |
| 444 | case -1: |
| 445 | /* First byte missing */ |
| 446 | memcpy(&out[1], in, |
| 447 | sample_len - 1); |
| 448 | break; |
| 449 | case 0: |
| 450 | /* Length correct, nothing to do. */ |
| 451 | memcpy(out, in, sample_len); |
| 452 | break; |
| 453 | case 1: |
| 454 | /* MAC added 2 extra bytes AND first byte |
| 455 | * is missing. |
| 456 | */ |
| 457 | memcpy(&out[1], in, 30); |
| 458 | out[31] = in[31]; |
| 459 | memcpy(&out[32], &in[33], |
| 460 | sample_len - 32); |
| 461 | break; |
| 462 | case 2: |
| 463 | /* MAC added 2 extra bytes at bin 30 and 32, |
| 464 | * remove them. |
| 465 | */ |
| 466 | memcpy(out, in, 30); |
| 467 | out[30] = in[31]; |
| 468 | memcpy(&out[31], &in[33], |
| 469 | sample_len - 31); |
| 470 | break; |
| 471 | default: |
| 472 | break; |
| 473 | } |
| 474 | } |
| 475 | |
Nick Kossifidis | 6b8f85a | 2015-04-29 23:51:19 +0000 | [diff] [blame^] | 476 | static int |
| 477 | ath_cmn_is_fft_buf_full(struct ath_spec_scan_priv *spec_priv) |
| 478 | { |
| 479 | int i = 0; |
| 480 | int ret = 0; |
| 481 | struct rchan *rc = spec_priv->rfs_chan_spec_scan; |
| 482 | |
| 483 | for_each_online_cpu(i) |
| 484 | ret += relay_buf_full(rc->buf[i]); |
| 485 | |
| 486 | i = num_online_cpus(); |
| 487 | |
| 488 | if (ret == i) |
| 489 | return 1; |
| 490 | else |
| 491 | return 0; |
| 492 | } |
| 493 | |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 494 | /* returns 1 if this was a spectral frame, even if not handled. */ |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 495 | int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 496 | struct ath_rx_status *rs, u64 tsf) |
| 497 | { |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 498 | u8 sample_buf[SPECTRAL_SAMPLE_MAX_LEN] = {0}; |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 499 | struct ath_hw *ah = spec_priv->ah; |
| 500 | struct ath_common *common = ath9k_hw_common(spec_priv->ah); |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 501 | u8 num_bins, *vdata = (u8 *)hdr; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 502 | struct ath_radar_info *radar_info; |
| 503 | int len = rs->rs_datalen; |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 504 | int i; |
| 505 | int got_slen = 0; |
| 506 | u8 *sample_start; |
| 507 | int sample_bytes = 0; |
| 508 | int ret = 0; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 509 | u16 fft_len, sample_len, freq = ah->curchan->chan->center_freq; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 510 | enum nl80211_channel_type chan_type; |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 511 | ath_cmn_fft_idx_validator *fft_idx_validator; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 512 | ath_cmn_fft_sample_handler *fft_handler; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 513 | |
| 514 | /* AR9280 and before report via ATH9K_PHYERR_RADAR, AR93xx and newer |
| 515 | * via ATH9K_PHYERR_SPECTRAL. Haven't seen ATH9K_PHYERR_FALSE_RADAR_EXT |
| 516 | * yet, but this is supposed to be possible as well. |
| 517 | */ |
| 518 | if (rs->rs_phyerr != ATH9K_PHYERR_RADAR && |
| 519 | rs->rs_phyerr != ATH9K_PHYERR_FALSE_RADAR_EXT && |
| 520 | rs->rs_phyerr != ATH9K_PHYERR_SPECTRAL) |
| 521 | return 0; |
| 522 | |
| 523 | /* check if spectral scan bit is set. This does not have to be checked |
| 524 | * if received through a SPECTRAL phy error, but shouldn't hurt. |
| 525 | */ |
| 526 | radar_info = ((struct ath_radar_info *)&vdata[len]) - 1; |
| 527 | if (!(radar_info->pulse_bw_info & SPECTRAL_SCAN_BITMASK)) |
| 528 | return 0; |
| 529 | |
Nick Kossifidis | 6b8f85a | 2015-04-29 23:51:19 +0000 | [diff] [blame^] | 530 | /* Output buffers are full, no need to process anything |
| 531 | * since there is no space to put the result anyway |
| 532 | */ |
| 533 | ret = ath_cmn_is_fft_buf_full(spec_priv); |
| 534 | if (ret == 1) { |
| 535 | ath_dbg(common, SPECTRAL_SCAN, "FFT report ignored, no space " |
| 536 | "left on output buffers\n"); |
| 537 | return 1; |
| 538 | } |
| 539 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 540 | chan_type = cfg80211_get_chandef_type(&common->hw->conf.chandef); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 541 | if ((chan_type == NL80211_CHAN_HT40MINUS) || |
| 542 | (chan_type == NL80211_CHAN_HT40PLUS)) { |
| 543 | fft_len = SPECTRAL_HT20_40_TOTAL_DATA_LEN; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 544 | sample_len = SPECTRAL_HT20_40_SAMPLE_LEN; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 545 | num_bins = SPECTRAL_HT20_40_NUM_BINS; |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 546 | fft_idx_validator = &ath_cmn_max_idx_verify_ht20_40_fft; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 547 | fft_handler = &ath_cmn_process_ht20_40_fft; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 548 | } else { |
| 549 | fft_len = SPECTRAL_HT20_TOTAL_DATA_LEN; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 550 | sample_len = SPECTRAL_HT20_SAMPLE_LEN; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 551 | num_bins = SPECTRAL_HT20_NUM_BINS; |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 552 | fft_idx_validator = ath_cmn_max_idx_verify_ht20_fft; |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 553 | fft_handler = &ath_cmn_process_ht20_fft; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 554 | } |
| 555 | |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 556 | ath_dbg(common, SPECTRAL_SCAN, "Got radar dump bw_info: 0x%X," |
| 557 | "len: %i fft_len: %i\n", |
| 558 | radar_info->pulse_bw_info, |
| 559 | len, |
| 560 | fft_len); |
| 561 | sample_start = vdata; |
| 562 | for (i = 0; i < len - 2; i++) { |
| 563 | sample_bytes++; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 564 | |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 565 | /* Only a single sample received, no need to look |
| 566 | * for the sample's end, do the correction based |
| 567 | * on the packet's length instead. Note that hw |
| 568 | * will always put the radar_info structure on |
| 569 | * the end. |
| 570 | */ |
| 571 | if (len <= fft_len + 2) { |
| 572 | sample_bytes = len - sizeof(struct ath_radar_info); |
| 573 | got_slen = 1; |
| 574 | } |
| 575 | |
| 576 | /* Search for the end of the FFT frame between |
| 577 | * sample_len - 1 and sample_len + 2. exp_max is 3 |
| 578 | * bits long and it's the only value on the last |
| 579 | * byte of the frame so since it'll be smaller than |
| 580 | * the next byte (the first bin of the next sample) |
| 581 | * 90% of the time, we can use it as a separator. |
| 582 | */ |
| 583 | if (vdata[i] <= 0x7 && sample_bytes >= sample_len - 1) { |
| 584 | |
| 585 | /* Got a frame length within boundaries, there are |
| 586 | * four scenarios here: |
| 587 | * |
| 588 | * a) sample_len -> We got the correct length |
| 589 | * b) sample_len + 2 -> 2 bytes added around bin[31] |
| 590 | * c) sample_len - 1 -> The first byte is missing |
| 591 | * d) sample_len + 1 -> b + c at the same time |
| 592 | * |
| 593 | * When MAC adds 2 extra bytes, bin[31] and bin[32] |
| 594 | * have the same value, so we can use that for further |
| 595 | * verification in cases b and d. |
| 596 | */ |
| 597 | |
| 598 | /* Did we go too far ? If so we couldn't determine |
| 599 | * this sample's boundaries, discard any further |
| 600 | * data |
| 601 | */ |
| 602 | if ((sample_bytes > sample_len + 2) || |
| 603 | ((sample_bytes > sample_len) && |
| 604 | (sample_start[31] != sample_start[32]))) |
| 605 | break; |
| 606 | |
| 607 | /* See if we got a valid frame by checking the |
| 608 | * consistency of mag_info fields. This is to |
| 609 | * prevent from "fixing" a correct frame. |
| 610 | * Failure is non-fatal, later frames may |
| 611 | * be valid. |
| 612 | */ |
| 613 | if (!fft_idx_validator(&vdata[i], i)) { |
| 614 | ath_dbg(common, SPECTRAL_SCAN, |
| 615 | "Found valid fft frame at %i\n", i); |
| 616 | got_slen = 1; |
| 617 | } |
| 618 | |
| 619 | /* We expect 1 - 2 more bytes */ |
| 620 | else if ((sample_start[31] == sample_start[32]) && |
| 621 | (sample_bytes >= sample_len) && |
| 622 | (sample_bytes < sample_len + 2) && |
| 623 | (vdata[i + 1] <= 0x7)) |
| 624 | continue; |
| 625 | |
| 626 | /* Try to distinguish cases a and c */ |
| 627 | else if ((sample_bytes == sample_len - 1) && |
| 628 | (vdata[i + 1] <= 0x7)) |
| 629 | continue; |
| 630 | |
| 631 | got_slen = 1; |
| 632 | } |
| 633 | |
| 634 | if (got_slen) { |
| 635 | ath_dbg(common, SPECTRAL_SCAN, "FFT frame len: %i\n", |
| 636 | sample_bytes); |
Nick Kossifidis | 0f2c75d | 2015-04-29 23:51:17 +0000 | [diff] [blame] | 637 | |
| 638 | /* Only try to fix a frame if it's the only one |
| 639 | * on the report, else just skip it. |
| 640 | */ |
| 641 | if (sample_bytes != sample_len && len <= fft_len + 2) { |
| 642 | ath_cmn_copy_fft_frame(sample_start, |
| 643 | sample_buf, sample_len, |
| 644 | sample_bytes); |
| 645 | |
| 646 | fft_handler(rs, spec_priv, sample_buf, |
| 647 | tsf, freq, chan_type); |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Nick Kossifidis | 0f2c75d | 2015-04-29 23:51:17 +0000 | [diff] [blame] | 650 | /* Process a normal frame */ |
Nick Kossifidis | 9acc98b | 2015-04-29 23:51:18 +0000 | [diff] [blame] | 651 | if (sample_bytes == sample_len) |
| 652 | ret = fft_handler(rs, spec_priv, sample_start, |
Nick Kossifidis | 0f2c75d | 2015-04-29 23:51:17 +0000 | [diff] [blame] | 653 | tsf, freq, chan_type); |
Nick Kossifidis | 0f2c75d | 2015-04-29 23:51:17 +0000 | [diff] [blame] | 654 | |
| 655 | /* Short report processed, break out of the |
| 656 | * loop. |
| 657 | */ |
| 658 | if (len <= fft_len + 2) |
| 659 | break; |
| 660 | |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 661 | memset(sample_buf, 0, SPECTRAL_SAMPLE_MAX_LEN); |
| 662 | sample_start = &vdata[i + 1]; |
Nick Kossifidis | 0f2c75d | 2015-04-29 23:51:17 +0000 | [diff] [blame] | 663 | |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 664 | /* -1 to grab sample_len -1, -2 since |
| 665 | * they 'll get increased by one. In case |
| 666 | * of failure try to recover by going byte |
Nick Kossifidis | 0f2c75d | 2015-04-29 23:51:17 +0000 | [diff] [blame] | 667 | * by byte instead. |
| 668 | */ |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 669 | if (ret == 0) { |
| 670 | i += num_bins - 2; |
| 671 | sample_bytes = num_bins - 2; |
| 672 | } |
| 673 | got_slen = 0; |
| 674 | } |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 675 | } |
| 676 | |
Nick Kossifidis | 72dd2cd | 2015-04-29 23:51:16 +0000 | [diff] [blame] | 677 | i -= num_bins - 2; |
| 678 | if (len - i != sizeof(struct ath_radar_info)) |
| 679 | ath_dbg(common, SPECTRAL_SCAN, "FFT report truncated" |
| 680 | "(bytes left: %i)\n", |
| 681 | len - i); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 682 | return 1; |
| 683 | } |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 684 | EXPORT_SYMBOL(ath_cmn_process_fft); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 685 | |
| 686 | /*********************/ |
| 687 | /* spectral_scan_ctl */ |
| 688 | /*********************/ |
| 689 | |
| 690 | static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf, |
| 691 | size_t count, loff_t *ppos) |
| 692 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 693 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 694 | char *mode = ""; |
| 695 | unsigned int len; |
| 696 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 697 | switch (spec_priv->spectral_mode) { |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 698 | case SPECTRAL_DISABLED: |
| 699 | mode = "disable"; |
| 700 | break; |
| 701 | case SPECTRAL_BACKGROUND: |
| 702 | mode = "background"; |
| 703 | break; |
| 704 | case SPECTRAL_CHANSCAN: |
| 705 | mode = "chanscan"; |
| 706 | break; |
| 707 | case SPECTRAL_MANUAL: |
| 708 | mode = "manual"; |
| 709 | break; |
| 710 | } |
| 711 | len = strlen(mode); |
| 712 | return simple_read_from_buffer(user_buf, count, ppos, mode, len); |
| 713 | } |
| 714 | |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 715 | void ath9k_cmn_spectral_scan_trigger(struct ath_common *common, |
Oleksij Rempel | f00a422 | 2014-11-06 08:53:29 +0100 | [diff] [blame] | 716 | struct ath_spec_scan_priv *spec_priv) |
| 717 | { |
| 718 | struct ath_hw *ah = spec_priv->ah; |
| 719 | u32 rxfilter; |
| 720 | |
| 721 | if (config_enabled(CONFIG_ATH9K_TX99)) |
| 722 | return; |
| 723 | |
| 724 | if (!ath9k_hw_ops(ah)->spectral_scan_trigger) { |
| 725 | ath_err(common, "spectrum analyzer not implemented on this hardware\n"); |
| 726 | return; |
| 727 | } |
| 728 | |
| 729 | ath_ps_ops(common)->wakeup(common); |
| 730 | rxfilter = ath9k_hw_getrxfilter(ah); |
| 731 | ath9k_hw_setrxfilter(ah, rxfilter | |
| 732 | ATH9K_RX_FILTER_PHYRADAR | |
| 733 | ATH9K_RX_FILTER_PHYERR); |
| 734 | |
| 735 | /* TODO: usually this should not be neccesary, but for some reason |
| 736 | * (or in some mode?) the trigger must be called after the |
| 737 | * configuration, otherwise the register will have its values reset |
| 738 | * (on my ar9220 to value 0x01002310) |
| 739 | */ |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 740 | ath9k_cmn_spectral_scan_config(common, spec_priv, spec_priv->spectral_mode); |
Oleksij Rempel | f00a422 | 2014-11-06 08:53:29 +0100 | [diff] [blame] | 741 | ath9k_hw_ops(ah)->spectral_scan_trigger(ah); |
| 742 | ath_ps_ops(common)->restore(common); |
| 743 | } |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 744 | EXPORT_SYMBOL(ath9k_cmn_spectral_scan_trigger); |
Oleksij Rempel | f00a422 | 2014-11-06 08:53:29 +0100 | [diff] [blame] | 745 | |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 746 | int ath9k_cmn_spectral_scan_config(struct ath_common *common, |
Oleksij Rempel | f00a422 | 2014-11-06 08:53:29 +0100 | [diff] [blame] | 747 | struct ath_spec_scan_priv *spec_priv, |
| 748 | enum spectral_mode spectral_mode) |
| 749 | { |
| 750 | struct ath_hw *ah = spec_priv->ah; |
| 751 | |
| 752 | if (!ath9k_hw_ops(ah)->spectral_scan_trigger) { |
| 753 | ath_err(common, "spectrum analyzer not implemented on this hardware\n"); |
| 754 | return -1; |
| 755 | } |
| 756 | |
| 757 | switch (spectral_mode) { |
| 758 | case SPECTRAL_DISABLED: |
| 759 | spec_priv->spec_config.enabled = 0; |
| 760 | break; |
| 761 | case SPECTRAL_BACKGROUND: |
| 762 | /* send endless samples. |
| 763 | * TODO: is this really useful for "background"? |
| 764 | */ |
| 765 | spec_priv->spec_config.endless = 1; |
| 766 | spec_priv->spec_config.enabled = 1; |
| 767 | break; |
| 768 | case SPECTRAL_CHANSCAN: |
| 769 | case SPECTRAL_MANUAL: |
| 770 | spec_priv->spec_config.endless = 0; |
| 771 | spec_priv->spec_config.enabled = 1; |
| 772 | break; |
| 773 | default: |
| 774 | return -1; |
| 775 | } |
| 776 | |
| 777 | ath_ps_ops(common)->wakeup(common); |
| 778 | ath9k_hw_ops(ah)->spectral_scan_config(ah, &spec_priv->spec_config); |
| 779 | ath_ps_ops(common)->restore(common); |
| 780 | |
| 781 | spec_priv->spectral_mode = spectral_mode; |
| 782 | |
| 783 | return 0; |
| 784 | } |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 785 | EXPORT_SYMBOL(ath9k_cmn_spectral_scan_config); |
Oleksij Rempel | f00a422 | 2014-11-06 08:53:29 +0100 | [diff] [blame] | 786 | |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 787 | static ssize_t write_file_spec_scan_ctl(struct file *file, |
| 788 | const char __user *user_buf, |
| 789 | size_t count, loff_t *ppos) |
| 790 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 791 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
| 792 | struct ath_common *common = ath9k_hw_common(spec_priv->ah); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 793 | char buf[32]; |
| 794 | ssize_t len; |
| 795 | |
| 796 | if (config_enabled(CONFIG_ATH9K_TX99)) |
| 797 | return -EOPNOTSUPP; |
| 798 | |
| 799 | len = min(count, sizeof(buf) - 1); |
| 800 | if (copy_from_user(buf, user_buf, len)) |
| 801 | return -EFAULT; |
| 802 | |
| 803 | buf[len] = '\0'; |
| 804 | |
| 805 | if (strncmp("trigger", buf, 7) == 0) { |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 806 | ath9k_cmn_spectral_scan_trigger(common, spec_priv); |
Maks Naumov | ded3fb4 | 2014-08-16 00:41:07 -0700 | [diff] [blame] | 807 | } else if (strncmp("background", buf, 10) == 0) { |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 808 | ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_BACKGROUND); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 809 | ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n"); |
| 810 | } else if (strncmp("chanscan", buf, 8) == 0) { |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 811 | ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_CHANSCAN); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 812 | ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n"); |
| 813 | } else if (strncmp("manual", buf, 6) == 0) { |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 814 | ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_MANUAL); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 815 | ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n"); |
| 816 | } else if (strncmp("disable", buf, 7) == 0) { |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 817 | ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_DISABLED); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 818 | ath_dbg(common, CONFIG, "spectral scan: disabled\n"); |
| 819 | } else { |
| 820 | return -EINVAL; |
| 821 | } |
| 822 | |
| 823 | return count; |
| 824 | } |
| 825 | |
| 826 | static const struct file_operations fops_spec_scan_ctl = { |
| 827 | .read = read_file_spec_scan_ctl, |
| 828 | .write = write_file_spec_scan_ctl, |
| 829 | .open = simple_open, |
| 830 | .owner = THIS_MODULE, |
| 831 | .llseek = default_llseek, |
| 832 | }; |
| 833 | |
| 834 | /*************************/ |
| 835 | /* spectral_short_repeat */ |
| 836 | /*************************/ |
| 837 | |
| 838 | static ssize_t read_file_spectral_short_repeat(struct file *file, |
| 839 | char __user *user_buf, |
| 840 | size_t count, loff_t *ppos) |
| 841 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 842 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 843 | char buf[32]; |
| 844 | unsigned int len; |
| 845 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 846 | len = sprintf(buf, "%d\n", spec_priv->spec_config.short_repeat); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 847 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 848 | } |
| 849 | |
| 850 | static ssize_t write_file_spectral_short_repeat(struct file *file, |
| 851 | const char __user *user_buf, |
| 852 | size_t count, loff_t *ppos) |
| 853 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 854 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 855 | unsigned long val; |
| 856 | char buf[32]; |
| 857 | ssize_t len; |
| 858 | |
| 859 | len = min(count, sizeof(buf) - 1); |
| 860 | if (copy_from_user(buf, user_buf, len)) |
| 861 | return -EFAULT; |
| 862 | |
| 863 | buf[len] = '\0'; |
| 864 | if (kstrtoul(buf, 0, &val)) |
| 865 | return -EINVAL; |
| 866 | |
Andrey Utkin | 3f55720 | 2014-07-17 16:56:37 +0300 | [diff] [blame] | 867 | if (val > 1) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 868 | return -EINVAL; |
| 869 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 870 | spec_priv->spec_config.short_repeat = val; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 871 | return count; |
| 872 | } |
| 873 | |
| 874 | static const struct file_operations fops_spectral_short_repeat = { |
| 875 | .read = read_file_spectral_short_repeat, |
| 876 | .write = write_file_spectral_short_repeat, |
| 877 | .open = simple_open, |
| 878 | .owner = THIS_MODULE, |
| 879 | .llseek = default_llseek, |
| 880 | }; |
| 881 | |
| 882 | /******************/ |
| 883 | /* spectral_count */ |
| 884 | /******************/ |
| 885 | |
| 886 | static ssize_t read_file_spectral_count(struct file *file, |
| 887 | char __user *user_buf, |
| 888 | size_t count, loff_t *ppos) |
| 889 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 890 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 891 | char buf[32]; |
| 892 | unsigned int len; |
| 893 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 894 | len = sprintf(buf, "%d\n", spec_priv->spec_config.count); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 895 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 896 | } |
| 897 | |
| 898 | static ssize_t write_file_spectral_count(struct file *file, |
| 899 | const char __user *user_buf, |
| 900 | size_t count, loff_t *ppos) |
| 901 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 902 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 903 | unsigned long val; |
| 904 | char buf[32]; |
| 905 | ssize_t len; |
| 906 | |
| 907 | len = min(count, sizeof(buf) - 1); |
| 908 | if (copy_from_user(buf, user_buf, len)) |
| 909 | return -EFAULT; |
| 910 | |
| 911 | buf[len] = '\0'; |
| 912 | if (kstrtoul(buf, 0, &val)) |
| 913 | return -EINVAL; |
| 914 | |
Andrey Utkin | 3f55720 | 2014-07-17 16:56:37 +0300 | [diff] [blame] | 915 | if (val > 255) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 916 | return -EINVAL; |
| 917 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 918 | spec_priv->spec_config.count = val; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 919 | return count; |
| 920 | } |
| 921 | |
| 922 | static const struct file_operations fops_spectral_count = { |
| 923 | .read = read_file_spectral_count, |
| 924 | .write = write_file_spectral_count, |
| 925 | .open = simple_open, |
| 926 | .owner = THIS_MODULE, |
| 927 | .llseek = default_llseek, |
| 928 | }; |
| 929 | |
| 930 | /*******************/ |
| 931 | /* spectral_period */ |
| 932 | /*******************/ |
| 933 | |
| 934 | static ssize_t read_file_spectral_period(struct file *file, |
| 935 | char __user *user_buf, |
| 936 | size_t count, loff_t *ppos) |
| 937 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 938 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 939 | char buf[32]; |
| 940 | unsigned int len; |
| 941 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 942 | len = sprintf(buf, "%d\n", spec_priv->spec_config.period); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 943 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 944 | } |
| 945 | |
| 946 | static ssize_t write_file_spectral_period(struct file *file, |
| 947 | const char __user *user_buf, |
| 948 | size_t count, loff_t *ppos) |
| 949 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 950 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 951 | unsigned long val; |
| 952 | char buf[32]; |
| 953 | ssize_t len; |
| 954 | |
| 955 | len = min(count, sizeof(buf) - 1); |
| 956 | if (copy_from_user(buf, user_buf, len)) |
| 957 | return -EFAULT; |
| 958 | |
| 959 | buf[len] = '\0'; |
| 960 | if (kstrtoul(buf, 0, &val)) |
| 961 | return -EINVAL; |
| 962 | |
Andrey Utkin | 3f55720 | 2014-07-17 16:56:37 +0300 | [diff] [blame] | 963 | if (val > 255) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 964 | return -EINVAL; |
| 965 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 966 | spec_priv->spec_config.period = val; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 967 | return count; |
| 968 | } |
| 969 | |
| 970 | static const struct file_operations fops_spectral_period = { |
| 971 | .read = read_file_spectral_period, |
| 972 | .write = write_file_spectral_period, |
| 973 | .open = simple_open, |
| 974 | .owner = THIS_MODULE, |
| 975 | .llseek = default_llseek, |
| 976 | }; |
| 977 | |
| 978 | /***********************/ |
| 979 | /* spectral_fft_period */ |
| 980 | /***********************/ |
| 981 | |
| 982 | static ssize_t read_file_spectral_fft_period(struct file *file, |
| 983 | char __user *user_buf, |
| 984 | size_t count, loff_t *ppos) |
| 985 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 986 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 987 | char buf[32]; |
| 988 | unsigned int len; |
| 989 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 990 | len = sprintf(buf, "%d\n", spec_priv->spec_config.fft_period); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 991 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 992 | } |
| 993 | |
| 994 | static ssize_t write_file_spectral_fft_period(struct file *file, |
| 995 | const char __user *user_buf, |
| 996 | size_t count, loff_t *ppos) |
| 997 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 998 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 999 | unsigned long val; |
| 1000 | char buf[32]; |
| 1001 | ssize_t len; |
| 1002 | |
| 1003 | len = min(count, sizeof(buf) - 1); |
| 1004 | if (copy_from_user(buf, user_buf, len)) |
| 1005 | return -EFAULT; |
| 1006 | |
| 1007 | buf[len] = '\0'; |
| 1008 | if (kstrtoul(buf, 0, &val)) |
| 1009 | return -EINVAL; |
| 1010 | |
Andrey Utkin | 3f55720 | 2014-07-17 16:56:37 +0300 | [diff] [blame] | 1011 | if (val > 15) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1012 | return -EINVAL; |
| 1013 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 1014 | spec_priv->spec_config.fft_period = val; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1015 | return count; |
| 1016 | } |
| 1017 | |
| 1018 | static const struct file_operations fops_spectral_fft_period = { |
| 1019 | .read = read_file_spectral_fft_period, |
| 1020 | .write = write_file_spectral_fft_period, |
| 1021 | .open = simple_open, |
| 1022 | .owner = THIS_MODULE, |
| 1023 | .llseek = default_llseek, |
| 1024 | }; |
| 1025 | |
| 1026 | /*******************/ |
| 1027 | /* Relay interface */ |
| 1028 | /*******************/ |
| 1029 | |
| 1030 | static struct dentry *create_buf_file_handler(const char *filename, |
| 1031 | struct dentry *parent, |
| 1032 | umode_t mode, |
| 1033 | struct rchan_buf *buf, |
| 1034 | int *is_global) |
| 1035 | { |
| 1036 | struct dentry *buf_file; |
| 1037 | |
| 1038 | buf_file = debugfs_create_file(filename, mode, parent, buf, |
| 1039 | &relay_file_operations); |
| 1040 | *is_global = 1; |
| 1041 | return buf_file; |
| 1042 | } |
| 1043 | |
| 1044 | static int remove_buf_file_handler(struct dentry *dentry) |
| 1045 | { |
| 1046 | debugfs_remove(dentry); |
| 1047 | |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
Wei Yongjun | f84d1b4 | 2013-12-20 10:22:51 +0800 | [diff] [blame] | 1051 | static struct rchan_callbacks rfs_spec_scan_cb = { |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1052 | .create_buf_file = create_buf_file_handler, |
| 1053 | .remove_buf_file = remove_buf_file_handler, |
| 1054 | }; |
| 1055 | |
| 1056 | /*********************/ |
| 1057 | /* Debug Init/Deinit */ |
| 1058 | /*********************/ |
| 1059 | |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 1060 | void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1061 | { |
Markus Elfring | c0420ea | 2015-02-04 18:48:28 +0100 | [diff] [blame] | 1062 | if (config_enabled(CONFIG_ATH9K_DEBUGFS)) { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 1063 | relay_close(spec_priv->rfs_chan_spec_scan); |
| 1064 | spec_priv->rfs_chan_spec_scan = NULL; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1065 | } |
| 1066 | } |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 1067 | EXPORT_SYMBOL(ath9k_cmn_spectral_deinit_debug); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1068 | |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 1069 | void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv, |
| 1070 | struct dentry *debugfs_phy) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1071 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 1072 | spec_priv->rfs_chan_spec_scan = relay_open("spectral_scan", |
Oleksij Rempel | c10b75a | 2014-11-06 08:53:21 +0100 | [diff] [blame] | 1073 | debugfs_phy, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1074 | 1024, 256, &rfs_spec_scan_cb, |
| 1075 | NULL); |
| 1076 | debugfs_create_file("spectral_scan_ctl", |
| 1077 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 1078 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1079 | &fops_spec_scan_ctl); |
| 1080 | debugfs_create_file("spectral_short_repeat", |
| 1081 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 1082 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1083 | &fops_spectral_short_repeat); |
| 1084 | debugfs_create_file("spectral_count", |
| 1085 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 1086 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1087 | &fops_spectral_count); |
| 1088 | debugfs_create_file("spectral_period", |
| 1089 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 1090 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1091 | &fops_spectral_period); |
| 1092 | debugfs_create_file("spectral_fft_period", |
| 1093 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 1094 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1095 | &fops_spectral_fft_period); |
| 1096 | } |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 1097 | EXPORT_SYMBOL(ath9k_cmn_spectral_init_debug); |