blob: b8682bc4f7ac2e204c75fd74bd75a5d293a97a47 [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
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530476/* returns 1 if this was a spectral frame, even if not handled. */
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100477int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr,
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530478 struct ath_rx_status *rs, u64 tsf)
479{
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000480 u8 sample_buf[SPECTRAL_SAMPLE_MAX_LEN] = {0};
Oleksij Rempel1111d422014-11-06 08:53:23 +0100481 struct ath_hw *ah = spec_priv->ah;
482 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000483 u8 num_bins, *vdata = (u8 *)hdr;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530484 struct ath_radar_info *radar_info;
485 int len = rs->rs_datalen;
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000486 int i;
487 int got_slen = 0;
488 u8 *sample_start;
489 int sample_bytes = 0;
490 int ret = 0;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000491 u16 fft_len, sample_len, freq = ah->curchan->chan->center_freq;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530492 enum nl80211_channel_type chan_type;
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000493 ath_cmn_fft_idx_validator *fft_idx_validator;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000494 ath_cmn_fft_sample_handler *fft_handler;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530495
496 /* AR9280 and before report via ATH9K_PHYERR_RADAR, AR93xx and newer
497 * via ATH9K_PHYERR_SPECTRAL. Haven't seen ATH9K_PHYERR_FALSE_RADAR_EXT
498 * yet, but this is supposed to be possible as well.
499 */
500 if (rs->rs_phyerr != ATH9K_PHYERR_RADAR &&
501 rs->rs_phyerr != ATH9K_PHYERR_FALSE_RADAR_EXT &&
502 rs->rs_phyerr != ATH9K_PHYERR_SPECTRAL)
503 return 0;
504
505 /* check if spectral scan bit is set. This does not have to be checked
506 * if received through a SPECTRAL phy error, but shouldn't hurt.
507 */
508 radar_info = ((struct ath_radar_info *)&vdata[len]) - 1;
509 if (!(radar_info->pulse_bw_info & SPECTRAL_SCAN_BITMASK))
510 return 0;
511
Oleksij Rempel1111d422014-11-06 08:53:23 +0100512 chan_type = cfg80211_get_chandef_type(&common->hw->conf.chandef);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530513 if ((chan_type == NL80211_CHAN_HT40MINUS) ||
514 (chan_type == NL80211_CHAN_HT40PLUS)) {
515 fft_len = SPECTRAL_HT20_40_TOTAL_DATA_LEN;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000516 sample_len = SPECTRAL_HT20_40_SAMPLE_LEN;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530517 num_bins = SPECTRAL_HT20_40_NUM_BINS;
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000518 fft_idx_validator = &ath_cmn_max_idx_verify_ht20_40_fft;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000519 fft_handler = &ath_cmn_process_ht20_40_fft;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530520 } else {
521 fft_len = SPECTRAL_HT20_TOTAL_DATA_LEN;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000522 sample_len = SPECTRAL_HT20_SAMPLE_LEN;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530523 num_bins = SPECTRAL_HT20_NUM_BINS;
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000524 fft_idx_validator = ath_cmn_max_idx_verify_ht20_fft;
Nick Kossifidis58b5e4c2015-04-29 23:51:14 +0000525 fft_handler = &ath_cmn_process_ht20_fft;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530526 }
527
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000528 ath_dbg(common, SPECTRAL_SCAN, "Got radar dump bw_info: 0x%X,"
529 "len: %i fft_len: %i\n",
530 radar_info->pulse_bw_info,
531 len,
532 fft_len);
533 sample_start = vdata;
534 for (i = 0; i < len - 2; i++) {
535 sample_bytes++;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530536
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000537 /* Only a single sample received, no need to look
538 * for the sample's end, do the correction based
539 * on the packet's length instead. Note that hw
540 * will always put the radar_info structure on
541 * the end.
542 */
543 if (len <= fft_len + 2) {
544 sample_bytes = len - sizeof(struct ath_radar_info);
545 got_slen = 1;
546 }
547
548 /* Search for the end of the FFT frame between
549 * sample_len - 1 and sample_len + 2. exp_max is 3
550 * bits long and it's the only value on the last
551 * byte of the frame so since it'll be smaller than
552 * the next byte (the first bin of the next sample)
553 * 90% of the time, we can use it as a separator.
554 */
555 if (vdata[i] <= 0x7 && sample_bytes >= sample_len - 1) {
556
557 /* Got a frame length within boundaries, there are
558 * four scenarios here:
559 *
560 * a) sample_len -> We got the correct length
561 * b) sample_len + 2 -> 2 bytes added around bin[31]
562 * c) sample_len - 1 -> The first byte is missing
563 * d) sample_len + 1 -> b + c at the same time
564 *
565 * When MAC adds 2 extra bytes, bin[31] and bin[32]
566 * have the same value, so we can use that for further
567 * verification in cases b and d.
568 */
569
570 /* Did we go too far ? If so we couldn't determine
571 * this sample's boundaries, discard any further
572 * data
573 */
574 if ((sample_bytes > sample_len + 2) ||
575 ((sample_bytes > sample_len) &&
576 (sample_start[31] != sample_start[32])))
577 break;
578
579 /* See if we got a valid frame by checking the
580 * consistency of mag_info fields. This is to
581 * prevent from "fixing" a correct frame.
582 * Failure is non-fatal, later frames may
583 * be valid.
584 */
585 if (!fft_idx_validator(&vdata[i], i)) {
586 ath_dbg(common, SPECTRAL_SCAN,
587 "Found valid fft frame at %i\n", i);
588 got_slen = 1;
589 }
590
591 /* We expect 1 - 2 more bytes */
592 else if ((sample_start[31] == sample_start[32]) &&
593 (sample_bytes >= sample_len) &&
594 (sample_bytes < sample_len + 2) &&
595 (vdata[i + 1] <= 0x7))
596 continue;
597
598 /* Try to distinguish cases a and c */
599 else if ((sample_bytes == sample_len - 1) &&
600 (vdata[i + 1] <= 0x7))
601 continue;
602
603 got_slen = 1;
604 }
605
606 if (got_slen) {
607 ath_dbg(common, SPECTRAL_SCAN, "FFT frame len: %i\n",
608 sample_bytes);
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000609
610 /* Only try to fix a frame if it's the only one
611 * on the report, else just skip it.
612 */
613 if (sample_bytes != sample_len && len <= fft_len + 2) {
614 ath_cmn_copy_fft_frame(sample_start,
615 sample_buf, sample_len,
616 sample_bytes);
617
618 fft_handler(rs, spec_priv, sample_buf,
619 tsf, freq, chan_type);
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000620 }
621
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000622 /* Process a normal frame */
Nick Kossifidis9acc98b2015-04-29 23:51:18 +0000623 if (sample_bytes == sample_len)
624 ret = fft_handler(rs, spec_priv, sample_start,
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000625 tsf, freq, chan_type);
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000626
627 /* Short report processed, break out of the
628 * loop.
629 */
630 if (len <= fft_len + 2)
631 break;
632
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000633 memset(sample_buf, 0, SPECTRAL_SAMPLE_MAX_LEN);
634 sample_start = &vdata[i + 1];
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000635
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000636 /* -1 to grab sample_len -1, -2 since
637 * they 'll get increased by one. In case
638 * of failure try to recover by going byte
Nick Kossifidis0f2c75d2015-04-29 23:51:17 +0000639 * by byte instead.
640 */
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000641 if (ret == 0) {
642 i += num_bins - 2;
643 sample_bytes = num_bins - 2;
644 }
645 got_slen = 0;
646 }
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530647 }
648
Nick Kossifidis72dd2cd2015-04-29 23:51:16 +0000649 i -= num_bins - 2;
650 if (len - i != sizeof(struct ath_radar_info))
651 ath_dbg(common, SPECTRAL_SCAN, "FFT report truncated"
652 "(bytes left: %i)\n",
653 len - i);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530654 return 1;
655}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100656EXPORT_SYMBOL(ath_cmn_process_fft);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530657
658/*********************/
659/* spectral_scan_ctl */
660/*********************/
661
662static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
663 size_t count, loff_t *ppos)
664{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100665 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530666 char *mode = "";
667 unsigned int len;
668
Oleksij Rempel1111d422014-11-06 08:53:23 +0100669 switch (spec_priv->spectral_mode) {
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530670 case SPECTRAL_DISABLED:
671 mode = "disable";
672 break;
673 case SPECTRAL_BACKGROUND:
674 mode = "background";
675 break;
676 case SPECTRAL_CHANSCAN:
677 mode = "chanscan";
678 break;
679 case SPECTRAL_MANUAL:
680 mode = "manual";
681 break;
682 }
683 len = strlen(mode);
684 return simple_read_from_buffer(user_buf, count, ppos, mode, len);
685}
686
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100687void ath9k_cmn_spectral_scan_trigger(struct ath_common *common,
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100688 struct ath_spec_scan_priv *spec_priv)
689{
690 struct ath_hw *ah = spec_priv->ah;
691 u32 rxfilter;
692
693 if (config_enabled(CONFIG_ATH9K_TX99))
694 return;
695
696 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
697 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
698 return;
699 }
700
701 ath_ps_ops(common)->wakeup(common);
702 rxfilter = ath9k_hw_getrxfilter(ah);
703 ath9k_hw_setrxfilter(ah, rxfilter |
704 ATH9K_RX_FILTER_PHYRADAR |
705 ATH9K_RX_FILTER_PHYERR);
706
707 /* TODO: usually this should not be neccesary, but for some reason
708 * (or in some mode?) the trigger must be called after the
709 * configuration, otherwise the register will have its values reset
710 * (on my ar9220 to value 0x01002310)
711 */
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100712 ath9k_cmn_spectral_scan_config(common, spec_priv, spec_priv->spectral_mode);
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100713 ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
714 ath_ps_ops(common)->restore(common);
715}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100716EXPORT_SYMBOL(ath9k_cmn_spectral_scan_trigger);
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100717
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100718int ath9k_cmn_spectral_scan_config(struct ath_common *common,
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100719 struct ath_spec_scan_priv *spec_priv,
720 enum spectral_mode spectral_mode)
721{
722 struct ath_hw *ah = spec_priv->ah;
723
724 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
725 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
726 return -1;
727 }
728
729 switch (spectral_mode) {
730 case SPECTRAL_DISABLED:
731 spec_priv->spec_config.enabled = 0;
732 break;
733 case SPECTRAL_BACKGROUND:
734 /* send endless samples.
735 * TODO: is this really useful for "background"?
736 */
737 spec_priv->spec_config.endless = 1;
738 spec_priv->spec_config.enabled = 1;
739 break;
740 case SPECTRAL_CHANSCAN:
741 case SPECTRAL_MANUAL:
742 spec_priv->spec_config.endless = 0;
743 spec_priv->spec_config.enabled = 1;
744 break;
745 default:
746 return -1;
747 }
748
749 ath_ps_ops(common)->wakeup(common);
750 ath9k_hw_ops(ah)->spectral_scan_config(ah, &spec_priv->spec_config);
751 ath_ps_ops(common)->restore(common);
752
753 spec_priv->spectral_mode = spectral_mode;
754
755 return 0;
756}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100757EXPORT_SYMBOL(ath9k_cmn_spectral_scan_config);
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100758
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530759static ssize_t write_file_spec_scan_ctl(struct file *file,
760 const char __user *user_buf,
761 size_t count, loff_t *ppos)
762{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100763 struct ath_spec_scan_priv *spec_priv = file->private_data;
764 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530765 char buf[32];
766 ssize_t len;
767
768 if (config_enabled(CONFIG_ATH9K_TX99))
769 return -EOPNOTSUPP;
770
771 len = min(count, sizeof(buf) - 1);
772 if (copy_from_user(buf, user_buf, len))
773 return -EFAULT;
774
775 buf[len] = '\0';
776
777 if (strncmp("trigger", buf, 7) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100778 ath9k_cmn_spectral_scan_trigger(common, spec_priv);
Maks Naumovded3fb42014-08-16 00:41:07 -0700779 } else if (strncmp("background", buf, 10) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100780 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_BACKGROUND);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530781 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
782 } else if (strncmp("chanscan", buf, 8) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100783 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_CHANSCAN);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530784 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
785 } else if (strncmp("manual", buf, 6) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100786 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_MANUAL);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530787 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
788 } else if (strncmp("disable", buf, 7) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100789 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_DISABLED);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530790 ath_dbg(common, CONFIG, "spectral scan: disabled\n");
791 } else {
792 return -EINVAL;
793 }
794
795 return count;
796}
797
798static const struct file_operations fops_spec_scan_ctl = {
799 .read = read_file_spec_scan_ctl,
800 .write = write_file_spec_scan_ctl,
801 .open = simple_open,
802 .owner = THIS_MODULE,
803 .llseek = default_llseek,
804};
805
806/*************************/
807/* spectral_short_repeat */
808/*************************/
809
810static ssize_t read_file_spectral_short_repeat(struct file *file,
811 char __user *user_buf,
812 size_t count, loff_t *ppos)
813{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100814 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530815 char buf[32];
816 unsigned int len;
817
Oleksij Rempel1111d422014-11-06 08:53:23 +0100818 len = sprintf(buf, "%d\n", spec_priv->spec_config.short_repeat);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530819 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
820}
821
822static ssize_t write_file_spectral_short_repeat(struct file *file,
823 const char __user *user_buf,
824 size_t count, loff_t *ppos)
825{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100826 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530827 unsigned long val;
828 char buf[32];
829 ssize_t len;
830
831 len = min(count, sizeof(buf) - 1);
832 if (copy_from_user(buf, user_buf, len))
833 return -EFAULT;
834
835 buf[len] = '\0';
836 if (kstrtoul(buf, 0, &val))
837 return -EINVAL;
838
Andrey Utkin3f557202014-07-17 16:56:37 +0300839 if (val > 1)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530840 return -EINVAL;
841
Oleksij Rempel1111d422014-11-06 08:53:23 +0100842 spec_priv->spec_config.short_repeat = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530843 return count;
844}
845
846static const struct file_operations fops_spectral_short_repeat = {
847 .read = read_file_spectral_short_repeat,
848 .write = write_file_spectral_short_repeat,
849 .open = simple_open,
850 .owner = THIS_MODULE,
851 .llseek = default_llseek,
852};
853
854/******************/
855/* spectral_count */
856/******************/
857
858static ssize_t read_file_spectral_count(struct file *file,
859 char __user *user_buf,
860 size_t count, loff_t *ppos)
861{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100862 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530863 char buf[32];
864 unsigned int len;
865
Oleksij Rempel1111d422014-11-06 08:53:23 +0100866 len = sprintf(buf, "%d\n", spec_priv->spec_config.count);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530867 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
868}
869
870static ssize_t write_file_spectral_count(struct file *file,
871 const char __user *user_buf,
872 size_t count, loff_t *ppos)
873{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100874 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530875 unsigned long val;
876 char buf[32];
877 ssize_t len;
878
879 len = min(count, sizeof(buf) - 1);
880 if (copy_from_user(buf, user_buf, len))
881 return -EFAULT;
882
883 buf[len] = '\0';
884 if (kstrtoul(buf, 0, &val))
885 return -EINVAL;
886
Andrey Utkin3f557202014-07-17 16:56:37 +0300887 if (val > 255)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530888 return -EINVAL;
889
Oleksij Rempel1111d422014-11-06 08:53:23 +0100890 spec_priv->spec_config.count = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530891 return count;
892}
893
894static const struct file_operations fops_spectral_count = {
895 .read = read_file_spectral_count,
896 .write = write_file_spectral_count,
897 .open = simple_open,
898 .owner = THIS_MODULE,
899 .llseek = default_llseek,
900};
901
902/*******************/
903/* spectral_period */
904/*******************/
905
906static ssize_t read_file_spectral_period(struct file *file,
907 char __user *user_buf,
908 size_t count, loff_t *ppos)
909{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100910 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530911 char buf[32];
912 unsigned int len;
913
Oleksij Rempel1111d422014-11-06 08:53:23 +0100914 len = sprintf(buf, "%d\n", spec_priv->spec_config.period);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530915 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
916}
917
918static ssize_t write_file_spectral_period(struct file *file,
919 const char __user *user_buf,
920 size_t count, loff_t *ppos)
921{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100922 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530923 unsigned long val;
924 char buf[32];
925 ssize_t len;
926
927 len = min(count, sizeof(buf) - 1);
928 if (copy_from_user(buf, user_buf, len))
929 return -EFAULT;
930
931 buf[len] = '\0';
932 if (kstrtoul(buf, 0, &val))
933 return -EINVAL;
934
Andrey Utkin3f557202014-07-17 16:56:37 +0300935 if (val > 255)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530936 return -EINVAL;
937
Oleksij Rempel1111d422014-11-06 08:53:23 +0100938 spec_priv->spec_config.period = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530939 return count;
940}
941
942static const struct file_operations fops_spectral_period = {
943 .read = read_file_spectral_period,
944 .write = write_file_spectral_period,
945 .open = simple_open,
946 .owner = THIS_MODULE,
947 .llseek = default_llseek,
948};
949
950/***********************/
951/* spectral_fft_period */
952/***********************/
953
954static ssize_t read_file_spectral_fft_period(struct file *file,
955 char __user *user_buf,
956 size_t count, loff_t *ppos)
957{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100958 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530959 char buf[32];
960 unsigned int len;
961
Oleksij Rempel1111d422014-11-06 08:53:23 +0100962 len = sprintf(buf, "%d\n", spec_priv->spec_config.fft_period);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530963 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
964}
965
966static ssize_t write_file_spectral_fft_period(struct file *file,
967 const char __user *user_buf,
968 size_t count, loff_t *ppos)
969{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100970 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530971 unsigned long val;
972 char buf[32];
973 ssize_t len;
974
975 len = min(count, sizeof(buf) - 1);
976 if (copy_from_user(buf, user_buf, len))
977 return -EFAULT;
978
979 buf[len] = '\0';
980 if (kstrtoul(buf, 0, &val))
981 return -EINVAL;
982
Andrey Utkin3f557202014-07-17 16:56:37 +0300983 if (val > 15)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530984 return -EINVAL;
985
Oleksij Rempel1111d422014-11-06 08:53:23 +0100986 spec_priv->spec_config.fft_period = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530987 return count;
988}
989
990static const struct file_operations fops_spectral_fft_period = {
991 .read = read_file_spectral_fft_period,
992 .write = write_file_spectral_fft_period,
993 .open = simple_open,
994 .owner = THIS_MODULE,
995 .llseek = default_llseek,
996};
997
998/*******************/
999/* Relay interface */
1000/*******************/
1001
1002static struct dentry *create_buf_file_handler(const char *filename,
1003 struct dentry *parent,
1004 umode_t mode,
1005 struct rchan_buf *buf,
1006 int *is_global)
1007{
1008 struct dentry *buf_file;
1009
1010 buf_file = debugfs_create_file(filename, mode, parent, buf,
1011 &relay_file_operations);
1012 *is_global = 1;
1013 return buf_file;
1014}
1015
1016static int remove_buf_file_handler(struct dentry *dentry)
1017{
1018 debugfs_remove(dentry);
1019
1020 return 0;
1021}
1022
Wei Yongjunf84d1b42013-12-20 10:22:51 +08001023static struct rchan_callbacks rfs_spec_scan_cb = {
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301024 .create_buf_file = create_buf_file_handler,
1025 .remove_buf_file = remove_buf_file_handler,
1026};
1027
1028/*********************/
1029/* Debug Init/Deinit */
1030/*********************/
1031
Oleksij Rempel67dc74f2014-11-06 08:53:30 +01001032void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv)
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301033{
Markus Elfringc0420ea2015-02-04 18:48:28 +01001034 if (config_enabled(CONFIG_ATH9K_DEBUGFS)) {
Oleksij Rempel1111d422014-11-06 08:53:23 +01001035 relay_close(spec_priv->rfs_chan_spec_scan);
1036 spec_priv->rfs_chan_spec_scan = NULL;
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301037 }
1038}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +01001039EXPORT_SYMBOL(ath9k_cmn_spectral_deinit_debug);
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301040
Oleksij Rempel67dc74f2014-11-06 08:53:30 +01001041void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv,
1042 struct dentry *debugfs_phy)
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301043{
Oleksij Rempel1111d422014-11-06 08:53:23 +01001044 spec_priv->rfs_chan_spec_scan = relay_open("spectral_scan",
Oleksij Rempelc10b75a2014-11-06 08:53:21 +01001045 debugfs_phy,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301046 1024, 256, &rfs_spec_scan_cb,
1047 NULL);
1048 debugfs_create_file("spectral_scan_ctl",
1049 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001050 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301051 &fops_spec_scan_ctl);
1052 debugfs_create_file("spectral_short_repeat",
1053 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001054 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301055 &fops_spectral_short_repeat);
1056 debugfs_create_file("spectral_count",
1057 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001058 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301059 &fops_spectral_count);
1060 debugfs_create_file("spectral_period",
1061 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001062 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301063 &fops_spectral_period);
1064 debugfs_create_file("spectral_fft_period",
1065 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +01001066 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301067 &fops_spectral_fft_period);
1068}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +01001069EXPORT_SYMBOL(ath9k_cmn_spectral_init_debug);