blob: 4ab08edeb065e4a104f579da9c27f60d737ff084 [file] [log] [blame]
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301/*
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
20static 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 Rempel1111d422014-11-06 08:53:23 +010027static void ath_debug_send_fft_sample(struct ath_spec_scan_priv *spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +053028 struct fft_sample_tlv *fft_sample_tlv)
29{
30 int length;
Oleksij Rempel1111d422014-11-06 08:53:23 +010031 if (!spec_priv->rfs_chan_spec_scan)
Sujith Manoharanf65c0822013-12-18 09:53:18 +053032 return;
33
34 length = __be16_to_cpu(fft_sample_tlv->length) +
35 sizeof(*fft_sample_tlv);
Oleksij Rempel1111d422014-11-06 08:53:23 +010036 relay_write(spec_priv->rfs_chan_spec_scan, fft_sample_tlv, length);
Sujith Manoharanf65c0822013-12-18 09:53:18 +053037}
38
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +000039typedef int (ath_cmn_fft_idx_validator) (u8 *sample_end, int bytes_read);
40
41static int
42ath_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
80static int
81ath_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 Kossifidis58b5e4c2015-04-29 23:51:14 +0000137typedef 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
141static int
142ath_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 Kossifidis7fa580c2015-04-29 23:51:15 +0000148 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000149 struct ath_hw *ah = spec_priv->ah;
150 struct ath_ht20_mag_info *mag_info;
151 struct fft_sample_tlv *tlv;
Nick Kossifidis7fa580c2015-04-29 23:51:15 +0000152 int i = 0;
153 int ret = 0;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000154 int dc_pos = SPECTRAL_HT20_NUM_BINS / 2;
Nick Kossifidis7fa580c2015-04-29 23:51:15 +0000155 u16 magnitude, tmp_mag, length;
156 u8 max_index, bitmap_w, max_exp;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000157
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 Kossifidis7fa580c2015-04-29 23:51:15 +0000178 max_exp = mag_info->max_exp & 0xf;
179 fft_sample_20.max_exp = max_exp;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000180
181 fft_sample_20.tsf = __cpu_to_be64(tsf);
182
183 memcpy(fft_sample_20.data, sample_buf, SPECTRAL_HT20_NUM_BINS);
184
Nick Kossifidis7fa580c2015-04-29 23:51:15 +0000185 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 Kossifidis58b5e4c2015-04-29 23:51:14 +0000195 /* 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 Kossifidis7fa580c2015-04-29 23:51:15 +0000201 /* 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 Kossifidis58b5e4c2015-04-29 23:51:14 +0000238 tlv = (struct fft_sample_tlv *)&fft_sample_20;
239
240 ath_debug_send_fft_sample(spec_priv, tlv);
241
242 return 0;
243}
244
245static int
246ath_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 Kossifidis7fa580c2015-04-29 23:51:15 +0000252 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000253 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 Kossifidis7fa580c2015-04-29 23:51:15 +0000258 int i = 0;
259 int ret = 0;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000260 s16 ext_nf;
Nick Kossifidis7fa580c2015-04-29 23:51:15 +0000261 u16 lower_mag, upper_mag, tmp_mag, length;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000262 s8 lower_rssi, upper_rssi;
263 u8 lower_max_index, upper_max_index;
Nick Kossifidis7fa580c2015-04-29 23:51:15 +0000264 u8 lower_bitmap_w, upper_bitmap_w, max_exp;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000265
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 Kossifidis7fa580c2015-04-29 23:51:15 +0000318 max_exp = mag_info->max_exp & 0xf;
319 fft_sample_40.max_exp = max_exp;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000320
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 Kossifidis7fa580c2015-04-29 23:51:15 +0000325 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 Kossifidis58b5e4c2015-04-29 23:51:14 +0000360 /* 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 Kossifidis7fa580c2015-04-29 23:51:15 +0000366 /* 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 Kossifidis58b5e4c2015-04-29 23:51:14 +0000433 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 Kossifidis0f2c75d2015-04-29 23:51:17 +0000440static inline void
441ath_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 Kossifidis6b8f85a2015-04-29 23:51:19 +0000476static int
477ath_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 Manoharanf65c0822013-12-18 09:53:18 +0530494/* returns 1 if this was a spectral frame, even if not handled. */
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100495int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr,
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530496 struct ath_rx_status *rs, u64 tsf)
497{
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000498 u8 sample_buf[SPECTRAL_SAMPLE_MAX_LEN] = {0};
Oleksij Rempel1111d422014-11-06 08:53:23 +0100499 struct ath_hw *ah = spec_priv->ah;
500 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000501 u8 num_bins, *vdata = (u8 *)hdr;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530502 struct ath_radar_info *radar_info;
503 int len = rs->rs_datalen;
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000504 int i;
505 int got_slen = 0;
506 u8 *sample_start;
507 int sample_bytes = 0;
508 int ret = 0;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000509 u16 fft_len, sample_len, freq = ah->curchan->chan->center_freq;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530510 enum nl80211_channel_type chan_type;
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000511 ath_cmn_fft_idx_validator *fft_idx_validator;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000512 ath_cmn_fft_sample_handler *fft_handler;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530513
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 Kossifidis6b8f85a2015-04-29 23:51:19 +0000530 /* 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 Rempel1111d422014-11-06 08:53:23 +0100540 chan_type = cfg80211_get_chandef_type(&common->hw->conf.chandef);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530541 if ((chan_type == NL80211_CHAN_HT40MINUS) ||
542 (chan_type == NL80211_CHAN_HT40PLUS)) {
543 fft_len = SPECTRAL_HT20_40_TOTAL_DATA_LEN;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000544 sample_len = SPECTRAL_HT20_40_SAMPLE_LEN;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530545 num_bins = SPECTRAL_HT20_40_NUM_BINS;
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000546 fft_idx_validator = &ath_cmn_max_idx_verify_ht20_40_fft;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000547 fft_handler = &ath_cmn_process_ht20_40_fft;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530548 } else {
549 fft_len = SPECTRAL_HT20_TOTAL_DATA_LEN;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000550 sample_len = SPECTRAL_HT20_SAMPLE_LEN;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530551 num_bins = SPECTRAL_HT20_NUM_BINS;
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000552 fft_idx_validator = ath_cmn_max_idx_verify_ht20_fft;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000553 fft_handler = &ath_cmn_process_ht20_fft;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530554 }
555
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000556 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 Manoharanf65c0822013-12-18 09:53:18 +0530564
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000565 /* 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 Kossifidis0f2c75d2015-04-29 23:51:17 +0000637
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 Kossifidis72dd2cd2015-04-29 23:51:16 +0000648 }
649
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000650 /* Process a normal frame */
Nick Kossifidis9acc98b2015-04-29 23:51:18 +0000651 if (sample_bytes == sample_len)
652 ret = fft_handler(rs, spec_priv, sample_start,
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000653 tsf, freq, chan_type);
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000654
655 /* Short report processed, break out of the
656 * loop.
657 */
658 if (len <= fft_len + 2)
659 break;
660
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000661 memset(sample_buf, 0, SPECTRAL_SAMPLE_MAX_LEN);
662 sample_start = &vdata[i + 1];
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000663
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000664 /* -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 Kossifidis0f2c75d2015-04-29 23:51:17 +0000667 * by byte instead.
668 */
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000669 if (ret == 0) {
670 i += num_bins - 2;
671 sample_bytes = num_bins - 2;
672 }
673 got_slen = 0;
674 }
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530675 }
676
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000677 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 Manoharanf65c0822013-12-18 09:53:18 +0530682 return 1;
683}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100684EXPORT_SYMBOL(ath_cmn_process_fft);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530685
686/*********************/
687/* spectral_scan_ctl */
688/*********************/
689
690static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
691 size_t count, loff_t *ppos)
692{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100693 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530694 char *mode = "";
695 unsigned int len;
696
Oleksij Rempel1111d422014-11-06 08:53:23 +0100697 switch (spec_priv->spectral_mode) {
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530698 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 Rempel67dc74f2014-11-06 08:53:30 +0100715void ath9k_cmn_spectral_scan_trigger(struct ath_common *common,
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100716 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 Rempel67dc74f2014-11-06 08:53:30 +0100740 ath9k_cmn_spectral_scan_config(common, spec_priv, spec_priv->spectral_mode);
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100741 ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
742 ath_ps_ops(common)->restore(common);
743}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100744EXPORT_SYMBOL(ath9k_cmn_spectral_scan_trigger);
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100745
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100746int ath9k_cmn_spectral_scan_config(struct ath_common *common,
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100747 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 Rempel67dc74f2014-11-06 08:53:30 +0100785EXPORT_SYMBOL(ath9k_cmn_spectral_scan_config);
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100786
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530787static 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 Rempel1111d422014-11-06 08:53:23 +0100791 struct ath_spec_scan_priv *spec_priv = file->private_data;
792 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530793 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 Rempel67dc74f2014-11-06 08:53:30 +0100806 ath9k_cmn_spectral_scan_trigger(common, spec_priv);
Maks Naumovded3fb42014-08-16 00:41:07 -0700807 } else if (strncmp("background", buf, 10) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100808 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_BACKGROUND);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530809 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
810 } else if (strncmp("chanscan", buf, 8) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100811 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_CHANSCAN);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530812 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
813 } else if (strncmp("manual", buf, 6) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100814 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_MANUAL);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530815 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
816 } else if (strncmp("disable", buf, 7) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100817 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_DISABLED);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530818 ath_dbg(common, CONFIG, "spectral scan: disabled\n");
819 } else {
820 return -EINVAL;
821 }
822
823 return count;
824}
825
826static 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
838static ssize_t read_file_spectral_short_repeat(struct file *file,
839 char __user *user_buf,
840 size_t count, loff_t *ppos)
841{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100842 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530843 char buf[32];
844 unsigned int len;
845
Oleksij Rempel1111d422014-11-06 08:53:23 +0100846 len = sprintf(buf, "%d\n", spec_priv->spec_config.short_repeat);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530847 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
848}
849
850static 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 Rempel1111d422014-11-06 08:53:23 +0100854 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530855 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 Utkin3f557202014-07-17 16:56:37 +0300867 if (val > 1)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530868 return -EINVAL;
869
Oleksij Rempel1111d422014-11-06 08:53:23 +0100870 spec_priv->spec_config.short_repeat = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530871 return count;
872}
873
874static 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
886static ssize_t read_file_spectral_count(struct file *file,
887 char __user *user_buf,
888 size_t count, loff_t *ppos)
889{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100890 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530891 char buf[32];
892 unsigned int len;
893
Oleksij Rempel1111d422014-11-06 08:53:23 +0100894 len = sprintf(buf, "%d\n", spec_priv->spec_config.count);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530895 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
896}
897
898static ssize_t write_file_spectral_count(struct file *file,
899 const char __user *user_buf,
900 size_t count, loff_t *ppos)
901{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100902 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530903 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 Utkin3f557202014-07-17 16:56:37 +0300915 if (val > 255)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530916 return -EINVAL;
917
Oleksij Rempel1111d422014-11-06 08:53:23 +0100918 spec_priv->spec_config.count = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530919 return count;
920}
921
922static 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
934static ssize_t read_file_spectral_period(struct file *file,
935 char __user *user_buf,
936 size_t count, loff_t *ppos)
937{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100938 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530939 char buf[32];
940 unsigned int len;
941
Oleksij Rempel1111d422014-11-06 08:53:23 +0100942 len = sprintf(buf, "%d\n", spec_priv->spec_config.period);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530943 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
944}
945
946static ssize_t write_file_spectral_period(struct file *file,
947 const char __user *user_buf,
948 size_t count, loff_t *ppos)
949{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100950 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530951 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 Utkin3f557202014-07-17 16:56:37 +0300963 if (val > 255)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530964 return -EINVAL;
965
Oleksij Rempel1111d422014-11-06 08:53:23 +0100966 spec_priv->spec_config.period = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530967 return count;
968}
969
970static 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
982static ssize_t read_file_spectral_fft_period(struct file *file,
983 char __user *user_buf,
984 size_t count, loff_t *ppos)
985{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100986 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530987 char buf[32];
988 unsigned int len;
989
Oleksij Rempel1111d422014-11-06 08:53:23 +0100990 len = sprintf(buf, "%d\n", spec_priv->spec_config.fft_period);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530991 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
992}
993
994static 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 Rempel1111d422014-11-06 08:53:23 +0100998 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530999 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 Utkin3f557202014-07-17 16:56:37 +03001011 if (val > 15)
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301012 return -EINVAL;
1013
Oleksij Rempel1111d422014-11-06 08:53:23 +01001014 spec_priv->spec_config.fft_period = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301015 return count;
1016}
1017
1018static 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
1030static 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
1044static int remove_buf_file_handler(struct dentry *dentry)
1045{
1046 debugfs_remove(dentry);
1047
1048 return 0;
1049}
1050
Wei Yongjunf84d1b42013-12-20 10:22:51 +08001051static struct rchan_callbacks rfs_spec_scan_cb = {
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301052 .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 Rempel67dc74f2014-11-06 08:53:30 +01001060void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv)
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301061{
Markus Elfringc0420ea2015-02-04 18:48:28 +01001062 if (config_enabled(CONFIG_ATH9K_DEBUGFS)) {
Oleksij Rempel1111d422014-11-06 08:53:23 +01001063 relay_close(spec_priv->rfs_chan_spec_scan);
1064 spec_priv->rfs_chan_spec_scan = NULL;
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301065 }
1066}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +01001067EXPORT_SYMBOL(ath9k_cmn_spectral_deinit_debug);
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301068
Oleksij Rempel67dc74f2014-11-06 08:53:30 +01001069void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv,
1070 struct dentry *debugfs_phy)
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301071{
Oleksij Rempel1111d422014-11-06 08:53:23 +01001072 spec_priv->rfs_chan_spec_scan = relay_open("spectral_scan",
Oleksij Rempelc10b75a2014-11-06 08:53:21 +01001073 debugfs_phy,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301074 1024, 256, &rfs_spec_scan_cb,
1075 NULL);
1076 debugfs_create_file("spectral_scan_ctl",
1077 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001078 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301079 &fops_spec_scan_ctl);
1080 debugfs_create_file("spectral_short_repeat",
1081 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001082 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301083 &fops_spectral_short_repeat);
1084 debugfs_create_file("spectral_count",
1085 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001086 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301087 &fops_spectral_count);
1088 debugfs_create_file("spectral_period",
1089 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001090 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301091 &fops_spectral_period);
1092 debugfs_create_file("spectral_fft_period",
1093 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001094 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301095 &fops_spectral_fft_period);
1096}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +01001097EXPORT_SYMBOL(ath9k_cmn_spectral_init_debug);