blob: 5cee231cca1f99510e21410e362a1086cae19672 [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
39/* returns 1 if this was a spectral frame, even if not handled. */
Oleksij Rempel67dc74f2014-11-06 08:53:30 +010040int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr,
Sujith Manoharanf65c0822013-12-18 09:53:18 +053041 struct ath_rx_status *rs, u64 tsf)
42{
Oleksij Rempel1111d422014-11-06 08:53:23 +010043 struct ath_hw *ah = spec_priv->ah;
44 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
Sujith Manoharanf65c0822013-12-18 09:53:18 +053045 u8 num_bins, *bins, *vdata = (u8 *)hdr;
46 struct fft_sample_ht20 fft_sample_20;
47 struct fft_sample_ht20_40 fft_sample_40;
48 struct fft_sample_tlv *tlv;
49 struct ath_radar_info *radar_info;
50 int len = rs->rs_datalen;
51 int dc_pos;
52 u16 fft_len, length, freq = ah->curchan->chan->center_freq;
53 enum nl80211_channel_type chan_type;
54
55 /* AR9280 and before report via ATH9K_PHYERR_RADAR, AR93xx and newer
56 * via ATH9K_PHYERR_SPECTRAL. Haven't seen ATH9K_PHYERR_FALSE_RADAR_EXT
57 * yet, but this is supposed to be possible as well.
58 */
59 if (rs->rs_phyerr != ATH9K_PHYERR_RADAR &&
60 rs->rs_phyerr != ATH9K_PHYERR_FALSE_RADAR_EXT &&
61 rs->rs_phyerr != ATH9K_PHYERR_SPECTRAL)
62 return 0;
63
64 /* check if spectral scan bit is set. This does not have to be checked
65 * if received through a SPECTRAL phy error, but shouldn't hurt.
66 */
67 radar_info = ((struct ath_radar_info *)&vdata[len]) - 1;
68 if (!(radar_info->pulse_bw_info & SPECTRAL_SCAN_BITMASK))
69 return 0;
70
Oleksij Rempel1111d422014-11-06 08:53:23 +010071 chan_type = cfg80211_get_chandef_type(&common->hw->conf.chandef);
Sujith Manoharanf65c0822013-12-18 09:53:18 +053072 if ((chan_type == NL80211_CHAN_HT40MINUS) ||
73 (chan_type == NL80211_CHAN_HT40PLUS)) {
74 fft_len = SPECTRAL_HT20_40_TOTAL_DATA_LEN;
75 num_bins = SPECTRAL_HT20_40_NUM_BINS;
76 bins = (u8 *)fft_sample_40.data;
77 } else {
78 fft_len = SPECTRAL_HT20_TOTAL_DATA_LEN;
79 num_bins = SPECTRAL_HT20_NUM_BINS;
80 bins = (u8 *)fft_sample_20.data;
81 }
82
83 /* Variation in the data length is possible and will be fixed later */
84 if ((len > fft_len + 2) || (len < fft_len - 1))
85 return 1;
86
87 switch (len - fft_len) {
88 case 0:
89 /* length correct, nothing to do. */
90 memcpy(bins, vdata, num_bins);
91 break;
92 case -1:
93 /* first byte missing, duplicate it. */
94 memcpy(&bins[1], vdata, num_bins - 1);
95 bins[0] = vdata[0];
96 break;
97 case 2:
98 /* MAC added 2 extra bytes at bin 30 and 32, remove them. */
99 memcpy(bins, vdata, 30);
100 bins[30] = vdata[31];
101 memcpy(&bins[31], &vdata[33], num_bins - 31);
102 break;
103 case 1:
104 /* MAC added 2 extra bytes AND first byte is missing. */
105 bins[0] = vdata[0];
106 memcpy(&bins[1], vdata, 30);
107 bins[31] = vdata[31];
108 memcpy(&bins[32], &vdata[33], num_bins - 32);
109 break;
110 default:
111 return 1;
112 }
113
114 /* DC value (value in the middle) is the blind spot of the spectral
115 * sample and invalid, interpolate it.
116 */
117 dc_pos = num_bins / 2;
118 bins[dc_pos] = (bins[dc_pos + 1] + bins[dc_pos - 1]) / 2;
119
120 if ((chan_type == NL80211_CHAN_HT40MINUS) ||
121 (chan_type == NL80211_CHAN_HT40PLUS)) {
122 s8 lower_rssi, upper_rssi;
123 s16 ext_nf;
124 u8 lower_max_index, upper_max_index;
125 u8 lower_bitmap_w, upper_bitmap_w;
126 u16 lower_mag, upper_mag;
127 struct ath9k_hw_cal_data *caldata = ah->caldata;
128 struct ath_ht20_40_mag_info *mag_info;
129
130 if (caldata)
131 ext_nf = ath9k_hw_getchan_noise(ah, ah->curchan,
132 caldata->nfCalHist[3].privNF);
133 else
134 ext_nf = ATH_DEFAULT_NOISE_FLOOR;
135
136 length = sizeof(fft_sample_40) - sizeof(struct fft_sample_tlv);
137 fft_sample_40.tlv.type = ATH_FFT_SAMPLE_HT20_40;
138 fft_sample_40.tlv.length = __cpu_to_be16(length);
139 fft_sample_40.freq = __cpu_to_be16(freq);
140 fft_sample_40.channel_type = chan_type;
141
142 if (chan_type == NL80211_CHAN_HT40PLUS) {
143 lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]);
144 upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]);
145
146 fft_sample_40.lower_noise = ah->noise;
147 fft_sample_40.upper_noise = ext_nf;
148 } else {
149 lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]);
150 upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]);
151
152 fft_sample_40.lower_noise = ext_nf;
153 fft_sample_40.upper_noise = ah->noise;
154 }
155 fft_sample_40.lower_rssi = lower_rssi;
156 fft_sample_40.upper_rssi = upper_rssi;
157
158 mag_info = ((struct ath_ht20_40_mag_info *)radar_info) - 1;
159 lower_mag = spectral_max_magnitude(mag_info->lower_bins);
160 upper_mag = spectral_max_magnitude(mag_info->upper_bins);
161 fft_sample_40.lower_max_magnitude = __cpu_to_be16(lower_mag);
162 fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag);
163 lower_max_index = spectral_max_index(mag_info->lower_bins);
164 upper_max_index = spectral_max_index(mag_info->upper_bins);
165 fft_sample_40.lower_max_index = lower_max_index;
166 fft_sample_40.upper_max_index = upper_max_index;
167 lower_bitmap_w = spectral_bitmap_weight(mag_info->lower_bins);
168 upper_bitmap_w = spectral_bitmap_weight(mag_info->upper_bins);
169 fft_sample_40.lower_bitmap_weight = lower_bitmap_w;
170 fft_sample_40.upper_bitmap_weight = upper_bitmap_w;
171 fft_sample_40.max_exp = mag_info->max_exp & 0xf;
172
173 fft_sample_40.tsf = __cpu_to_be64(tsf);
174
175 tlv = (struct fft_sample_tlv *)&fft_sample_40;
176 } else {
177 u8 max_index, bitmap_w;
178 u16 magnitude;
179 struct ath_ht20_mag_info *mag_info;
180
181 length = sizeof(fft_sample_20) - sizeof(struct fft_sample_tlv);
182 fft_sample_20.tlv.type = ATH_FFT_SAMPLE_HT20;
183 fft_sample_20.tlv.length = __cpu_to_be16(length);
184 fft_sample_20.freq = __cpu_to_be16(freq);
185
186 fft_sample_20.rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]);
187 fft_sample_20.noise = ah->noise;
188
189 mag_info = ((struct ath_ht20_mag_info *)radar_info) - 1;
190 magnitude = spectral_max_magnitude(mag_info->all_bins);
191 fft_sample_20.max_magnitude = __cpu_to_be16(magnitude);
192 max_index = spectral_max_index(mag_info->all_bins);
193 fft_sample_20.max_index = max_index;
194 bitmap_w = spectral_bitmap_weight(mag_info->all_bins);
195 fft_sample_20.bitmap_weight = bitmap_w;
196 fft_sample_20.max_exp = mag_info->max_exp & 0xf;
197
198 fft_sample_20.tsf = __cpu_to_be64(tsf);
199
200 tlv = (struct fft_sample_tlv *)&fft_sample_20;
201 }
202
Oleksij Rempel1111d422014-11-06 08:53:23 +0100203 ath_debug_send_fft_sample(spec_priv, tlv);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530204
205 return 1;
206}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100207EXPORT_SYMBOL(ath_cmn_process_fft);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530208
209/*********************/
210/* spectral_scan_ctl */
211/*********************/
212
213static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
214 size_t count, loff_t *ppos)
215{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100216 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530217 char *mode = "";
218 unsigned int len;
219
Oleksij Rempel1111d422014-11-06 08:53:23 +0100220 switch (spec_priv->spectral_mode) {
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530221 case SPECTRAL_DISABLED:
222 mode = "disable";
223 break;
224 case SPECTRAL_BACKGROUND:
225 mode = "background";
226 break;
227 case SPECTRAL_CHANSCAN:
228 mode = "chanscan";
229 break;
230 case SPECTRAL_MANUAL:
231 mode = "manual";
232 break;
233 }
234 len = strlen(mode);
235 return simple_read_from_buffer(user_buf, count, ppos, mode, len);
236}
237
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100238void ath9k_cmn_spectral_scan_trigger(struct ath_common *common,
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100239 struct ath_spec_scan_priv *spec_priv)
240{
241 struct ath_hw *ah = spec_priv->ah;
242 u32 rxfilter;
243
244 if (config_enabled(CONFIG_ATH9K_TX99))
245 return;
246
247 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
248 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
249 return;
250 }
251
252 ath_ps_ops(common)->wakeup(common);
253 rxfilter = ath9k_hw_getrxfilter(ah);
254 ath9k_hw_setrxfilter(ah, rxfilter |
255 ATH9K_RX_FILTER_PHYRADAR |
256 ATH9K_RX_FILTER_PHYERR);
257
258 /* TODO: usually this should not be neccesary, but for some reason
259 * (or in some mode?) the trigger must be called after the
260 * configuration, otherwise the register will have its values reset
261 * (on my ar9220 to value 0x01002310)
262 */
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100263 ath9k_cmn_spectral_scan_config(common, spec_priv, spec_priv->spectral_mode);
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100264 ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
265 ath_ps_ops(common)->restore(common);
266}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100267EXPORT_SYMBOL(ath9k_cmn_spectral_scan_trigger);
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100268
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100269int ath9k_cmn_spectral_scan_config(struct ath_common *common,
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100270 struct ath_spec_scan_priv *spec_priv,
271 enum spectral_mode spectral_mode)
272{
273 struct ath_hw *ah = spec_priv->ah;
274
275 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
276 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
277 return -1;
278 }
279
280 switch (spectral_mode) {
281 case SPECTRAL_DISABLED:
282 spec_priv->spec_config.enabled = 0;
283 break;
284 case SPECTRAL_BACKGROUND:
285 /* send endless samples.
286 * TODO: is this really useful for "background"?
287 */
288 spec_priv->spec_config.endless = 1;
289 spec_priv->spec_config.enabled = 1;
290 break;
291 case SPECTRAL_CHANSCAN:
292 case SPECTRAL_MANUAL:
293 spec_priv->spec_config.endless = 0;
294 spec_priv->spec_config.enabled = 1;
295 break;
296 default:
297 return -1;
298 }
299
300 ath_ps_ops(common)->wakeup(common);
301 ath9k_hw_ops(ah)->spectral_scan_config(ah, &spec_priv->spec_config);
302 ath_ps_ops(common)->restore(common);
303
304 spec_priv->spectral_mode = spectral_mode;
305
306 return 0;
307}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100308EXPORT_SYMBOL(ath9k_cmn_spectral_scan_config);
Oleksij Rempelf00a4222014-11-06 08:53:29 +0100309
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530310static ssize_t write_file_spec_scan_ctl(struct file *file,
311 const char __user *user_buf,
312 size_t count, loff_t *ppos)
313{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100314 struct ath_spec_scan_priv *spec_priv = file->private_data;
315 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530316 char buf[32];
317 ssize_t len;
318
319 if (config_enabled(CONFIG_ATH9K_TX99))
320 return -EOPNOTSUPP;
321
322 len = min(count, sizeof(buf) - 1);
323 if (copy_from_user(buf, user_buf, len))
324 return -EFAULT;
325
326 buf[len] = '\0';
327
328 if (strncmp("trigger", buf, 7) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100329 ath9k_cmn_spectral_scan_trigger(common, spec_priv);
Maks Naumovded3fb42014-08-16 00:41:07 -0700330 } else if (strncmp("background", buf, 10) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100331 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_BACKGROUND);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530332 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
333 } else if (strncmp("chanscan", buf, 8) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100334 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_CHANSCAN);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530335 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
336 } else if (strncmp("manual", buf, 6) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100337 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_MANUAL);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530338 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
339 } else if (strncmp("disable", buf, 7) == 0) {
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100340 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_DISABLED);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530341 ath_dbg(common, CONFIG, "spectral scan: disabled\n");
342 } else {
343 return -EINVAL;
344 }
345
346 return count;
347}
348
349static const struct file_operations fops_spec_scan_ctl = {
350 .read = read_file_spec_scan_ctl,
351 .write = write_file_spec_scan_ctl,
352 .open = simple_open,
353 .owner = THIS_MODULE,
354 .llseek = default_llseek,
355};
356
357/*************************/
358/* spectral_short_repeat */
359/*************************/
360
361static ssize_t read_file_spectral_short_repeat(struct file *file,
362 char __user *user_buf,
363 size_t count, loff_t *ppos)
364{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100365 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530366 char buf[32];
367 unsigned int len;
368
Oleksij Rempel1111d422014-11-06 08:53:23 +0100369 len = sprintf(buf, "%d\n", spec_priv->spec_config.short_repeat);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530370 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
371}
372
373static ssize_t write_file_spectral_short_repeat(struct file *file,
374 const char __user *user_buf,
375 size_t count, loff_t *ppos)
376{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100377 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530378 unsigned long val;
379 char buf[32];
380 ssize_t len;
381
382 len = min(count, sizeof(buf) - 1);
383 if (copy_from_user(buf, user_buf, len))
384 return -EFAULT;
385
386 buf[len] = '\0';
387 if (kstrtoul(buf, 0, &val))
388 return -EINVAL;
389
Andrey Utkin3f557202014-07-17 16:56:37 +0300390 if (val > 1)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530391 return -EINVAL;
392
Oleksij Rempel1111d422014-11-06 08:53:23 +0100393 spec_priv->spec_config.short_repeat = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530394 return count;
395}
396
397static const struct file_operations fops_spectral_short_repeat = {
398 .read = read_file_spectral_short_repeat,
399 .write = write_file_spectral_short_repeat,
400 .open = simple_open,
401 .owner = THIS_MODULE,
402 .llseek = default_llseek,
403};
404
405/******************/
406/* spectral_count */
407/******************/
408
409static ssize_t read_file_spectral_count(struct file *file,
410 char __user *user_buf,
411 size_t count, loff_t *ppos)
412{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100413 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530414 char buf[32];
415 unsigned int len;
416
Oleksij Rempel1111d422014-11-06 08:53:23 +0100417 len = sprintf(buf, "%d\n", spec_priv->spec_config.count);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530418 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
419}
420
421static ssize_t write_file_spectral_count(struct file *file,
422 const char __user *user_buf,
423 size_t count, loff_t *ppos)
424{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100425 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530426 unsigned long val;
427 char buf[32];
428 ssize_t len;
429
430 len = min(count, sizeof(buf) - 1);
431 if (copy_from_user(buf, user_buf, len))
432 return -EFAULT;
433
434 buf[len] = '\0';
435 if (kstrtoul(buf, 0, &val))
436 return -EINVAL;
437
Andrey Utkin3f557202014-07-17 16:56:37 +0300438 if (val > 255)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530439 return -EINVAL;
440
Oleksij Rempel1111d422014-11-06 08:53:23 +0100441 spec_priv->spec_config.count = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530442 return count;
443}
444
445static const struct file_operations fops_spectral_count = {
446 .read = read_file_spectral_count,
447 .write = write_file_spectral_count,
448 .open = simple_open,
449 .owner = THIS_MODULE,
450 .llseek = default_llseek,
451};
452
453/*******************/
454/* spectral_period */
455/*******************/
456
457static ssize_t read_file_spectral_period(struct file *file,
458 char __user *user_buf,
459 size_t count, loff_t *ppos)
460{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100461 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530462 char buf[32];
463 unsigned int len;
464
Oleksij Rempel1111d422014-11-06 08:53:23 +0100465 len = sprintf(buf, "%d\n", spec_priv->spec_config.period);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530466 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
467}
468
469static ssize_t write_file_spectral_period(struct file *file,
470 const char __user *user_buf,
471 size_t count, loff_t *ppos)
472{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100473 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530474 unsigned long val;
475 char buf[32];
476 ssize_t len;
477
478 len = min(count, sizeof(buf) - 1);
479 if (copy_from_user(buf, user_buf, len))
480 return -EFAULT;
481
482 buf[len] = '\0';
483 if (kstrtoul(buf, 0, &val))
484 return -EINVAL;
485
Andrey Utkin3f557202014-07-17 16:56:37 +0300486 if (val > 255)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530487 return -EINVAL;
488
Oleksij Rempel1111d422014-11-06 08:53:23 +0100489 spec_priv->spec_config.period = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530490 return count;
491}
492
493static const struct file_operations fops_spectral_period = {
494 .read = read_file_spectral_period,
495 .write = write_file_spectral_period,
496 .open = simple_open,
497 .owner = THIS_MODULE,
498 .llseek = default_llseek,
499};
500
501/***********************/
502/* spectral_fft_period */
503/***********************/
504
505static ssize_t read_file_spectral_fft_period(struct file *file,
506 char __user *user_buf,
507 size_t count, loff_t *ppos)
508{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100509 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530510 char buf[32];
511 unsigned int len;
512
Oleksij Rempel1111d422014-11-06 08:53:23 +0100513 len = sprintf(buf, "%d\n", spec_priv->spec_config.fft_period);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530514 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
515}
516
517static ssize_t write_file_spectral_fft_period(struct file *file,
518 const char __user *user_buf,
519 size_t count, loff_t *ppos)
520{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100521 struct ath_spec_scan_priv *spec_priv = file->private_data;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530522 unsigned long val;
523 char buf[32];
524 ssize_t len;
525
526 len = min(count, sizeof(buf) - 1);
527 if (copy_from_user(buf, user_buf, len))
528 return -EFAULT;
529
530 buf[len] = '\0';
531 if (kstrtoul(buf, 0, &val))
532 return -EINVAL;
533
Andrey Utkin3f557202014-07-17 16:56:37 +0300534 if (val > 15)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530535 return -EINVAL;
536
Oleksij Rempel1111d422014-11-06 08:53:23 +0100537 spec_priv->spec_config.fft_period = val;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530538 return count;
539}
540
541static const struct file_operations fops_spectral_fft_period = {
542 .read = read_file_spectral_fft_period,
543 .write = write_file_spectral_fft_period,
544 .open = simple_open,
545 .owner = THIS_MODULE,
546 .llseek = default_llseek,
547};
548
549/*******************/
550/* Relay interface */
551/*******************/
552
553static struct dentry *create_buf_file_handler(const char *filename,
554 struct dentry *parent,
555 umode_t mode,
556 struct rchan_buf *buf,
557 int *is_global)
558{
559 struct dentry *buf_file;
560
561 buf_file = debugfs_create_file(filename, mode, parent, buf,
562 &relay_file_operations);
563 *is_global = 1;
564 return buf_file;
565}
566
567static int remove_buf_file_handler(struct dentry *dentry)
568{
569 debugfs_remove(dentry);
570
571 return 0;
572}
573
Wei Yongjunf84d1b42013-12-20 10:22:51 +0800574static struct rchan_callbacks rfs_spec_scan_cb = {
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530575 .create_buf_file = create_buf_file_handler,
576 .remove_buf_file = remove_buf_file_handler,
577};
578
579/*********************/
580/* Debug Init/Deinit */
581/*********************/
582
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100583void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530584{
Markus Elfringc0420ea2015-02-04 18:48:28 +0100585 if (config_enabled(CONFIG_ATH9K_DEBUGFS)) {
Oleksij Rempel1111d422014-11-06 08:53:23 +0100586 relay_close(spec_priv->rfs_chan_spec_scan);
587 spec_priv->rfs_chan_spec_scan = NULL;
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530588 }
589}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100590EXPORT_SYMBOL(ath9k_cmn_spectral_deinit_debug);
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530591
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100592void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv,
593 struct dentry *debugfs_phy)
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530594{
Oleksij Rempel1111d422014-11-06 08:53:23 +0100595 spec_priv->rfs_chan_spec_scan = relay_open("spectral_scan",
Oleksij Rempelc10b75a2014-11-06 08:53:21 +0100596 debugfs_phy,
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530597 1024, 256, &rfs_spec_scan_cb,
598 NULL);
599 debugfs_create_file("spectral_scan_ctl",
600 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +0100601 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530602 &fops_spec_scan_ctl);
603 debugfs_create_file("spectral_short_repeat",
604 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +0100605 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530606 &fops_spectral_short_repeat);
607 debugfs_create_file("spectral_count",
608 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +0100609 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530610 &fops_spectral_count);
611 debugfs_create_file("spectral_period",
612 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +0100613 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530614 &fops_spectral_period);
615 debugfs_create_file("spectral_fft_period",
616 S_IRUSR | S_IWUSR,
Oleksij Rempel1111d422014-11-06 08:53:23 +0100617 debugfs_phy, spec_priv,
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530618 &fops_spectral_fft_period);
619}
Oleksij Rempel67dc74f2014-11-06 08:53:30 +0100620EXPORT_SYMBOL(ath9k_cmn_spectral_init_debug);