Commit | Line | Data |
---|---|---|
f65c0825 SM |
1 | /* |
2 | * Copyright (c) 2013 Qualcomm Atheros, Inc. | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #include <linux/relay.h> | |
18 | #include "ath9k.h" | |
19 | ||
20 | static s8 fix_rssi_inv_only(u8 rssi_val) | |
21 | { | |
22 | if (rssi_val == 128) | |
23 | rssi_val = 0; | |
24 | return (s8) rssi_val; | |
25 | } | |
26 | ||
1111d426 | 27 | static void ath_debug_send_fft_sample(struct ath_spec_scan_priv *spec_priv, |
f65c0825 SM |
28 | struct fft_sample_tlv *fft_sample_tlv) |
29 | { | |
30 | int length; | |
1111d426 | 31 | if (!spec_priv->rfs_chan_spec_scan) |
f65c0825 SM |
32 | return; |
33 | ||
34 | length = __be16_to_cpu(fft_sample_tlv->length) + | |
35 | sizeof(*fft_sample_tlv); | |
1111d426 | 36 | relay_write(spec_priv->rfs_chan_spec_scan, fft_sample_tlv, length); |
f65c0825 SM |
37 | } |
38 | ||
39 | /* returns 1 if this was a spectral frame, even if not handled. */ | |
1111d426 | 40 | int ath_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr, |
f65c0825 SM |
41 | struct ath_rx_status *rs, u64 tsf) |
42 | { | |
1111d426 OR |
43 | struct ath_hw *ah = spec_priv->ah; |
44 | struct ath_common *common = ath9k_hw_common(spec_priv->ah); | |
f65c0825 SM |
45 | 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 | ||
1111d426 | 71 | chan_type = cfg80211_get_chandef_type(&common->hw->conf.chandef); |
f65c0825 SM |
72 | 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 | ||
1111d426 | 203 | ath_debug_send_fft_sample(spec_priv, tlv); |
f65c0825 SM |
204 | |
205 | return 1; | |
206 | } | |
207 | ||
208 | /*********************/ | |
209 | /* spectral_scan_ctl */ | |
210 | /*********************/ | |
211 | ||
212 | static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf, | |
213 | size_t count, loff_t *ppos) | |
214 | { | |
1111d426 | 215 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
f65c0825 SM |
216 | char *mode = ""; |
217 | unsigned int len; | |
218 | ||
1111d426 | 219 | switch (spec_priv->spectral_mode) { |
f65c0825 SM |
220 | case SPECTRAL_DISABLED: |
221 | mode = "disable"; | |
222 | break; | |
223 | case SPECTRAL_BACKGROUND: | |
224 | mode = "background"; | |
225 | break; | |
226 | case SPECTRAL_CHANSCAN: | |
227 | mode = "chanscan"; | |
228 | break; | |
229 | case SPECTRAL_MANUAL: | |
230 | mode = "manual"; | |
231 | break; | |
232 | } | |
233 | len = strlen(mode); | |
234 | return simple_read_from_buffer(user_buf, count, ppos, mode, len); | |
235 | } | |
236 | ||
f00a422c OR |
237 | void ath9k_spectral_scan_trigger(struct ath_common *common, |
238 | struct ath_spec_scan_priv *spec_priv) | |
239 | { | |
240 | struct ath_hw *ah = spec_priv->ah; | |
241 | u32 rxfilter; | |
242 | ||
243 | if (config_enabled(CONFIG_ATH9K_TX99)) | |
244 | return; | |
245 | ||
246 | if (!ath9k_hw_ops(ah)->spectral_scan_trigger) { | |
247 | ath_err(common, "spectrum analyzer not implemented on this hardware\n"); | |
248 | return; | |
249 | } | |
250 | ||
251 | ath_ps_ops(common)->wakeup(common); | |
252 | rxfilter = ath9k_hw_getrxfilter(ah); | |
253 | ath9k_hw_setrxfilter(ah, rxfilter | | |
254 | ATH9K_RX_FILTER_PHYRADAR | | |
255 | ATH9K_RX_FILTER_PHYERR); | |
256 | ||
257 | /* TODO: usually this should not be neccesary, but for some reason | |
258 | * (or in some mode?) the trigger must be called after the | |
259 | * configuration, otherwise the register will have its values reset | |
260 | * (on my ar9220 to value 0x01002310) | |
261 | */ | |
262 | ath9k_spectral_scan_config(common, spec_priv, spec_priv->spectral_mode); | |
263 | ath9k_hw_ops(ah)->spectral_scan_trigger(ah); | |
264 | ath_ps_ops(common)->restore(common); | |
265 | } | |
266 | ||
267 | int ath9k_spectral_scan_config(struct ath_common *common, | |
268 | struct ath_spec_scan_priv *spec_priv, | |
269 | enum spectral_mode spectral_mode) | |
270 | { | |
271 | struct ath_hw *ah = spec_priv->ah; | |
272 | ||
273 | if (!ath9k_hw_ops(ah)->spectral_scan_trigger) { | |
274 | ath_err(common, "spectrum analyzer not implemented on this hardware\n"); | |
275 | return -1; | |
276 | } | |
277 | ||
278 | switch (spectral_mode) { | |
279 | case SPECTRAL_DISABLED: | |
280 | spec_priv->spec_config.enabled = 0; | |
281 | break; | |
282 | case SPECTRAL_BACKGROUND: | |
283 | /* send endless samples. | |
284 | * TODO: is this really useful for "background"? | |
285 | */ | |
286 | spec_priv->spec_config.endless = 1; | |
287 | spec_priv->spec_config.enabled = 1; | |
288 | break; | |
289 | case SPECTRAL_CHANSCAN: | |
290 | case SPECTRAL_MANUAL: | |
291 | spec_priv->spec_config.endless = 0; | |
292 | spec_priv->spec_config.enabled = 1; | |
293 | break; | |
294 | default: | |
295 | return -1; | |
296 | } | |
297 | ||
298 | ath_ps_ops(common)->wakeup(common); | |
299 | ath9k_hw_ops(ah)->spectral_scan_config(ah, &spec_priv->spec_config); | |
300 | ath_ps_ops(common)->restore(common); | |
301 | ||
302 | spec_priv->spectral_mode = spectral_mode; | |
303 | ||
304 | return 0; | |
305 | } | |
306 | ||
f65c0825 SM |
307 | static ssize_t write_file_spec_scan_ctl(struct file *file, |
308 | const char __user *user_buf, | |
309 | size_t count, loff_t *ppos) | |
310 | { | |
1111d426 OR |
311 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
312 | struct ath_common *common = ath9k_hw_common(spec_priv->ah); | |
f65c0825 SM |
313 | char buf[32]; |
314 | ssize_t len; | |
315 | ||
316 | if (config_enabled(CONFIG_ATH9K_TX99)) | |
317 | return -EOPNOTSUPP; | |
318 | ||
319 | len = min(count, sizeof(buf) - 1); | |
320 | if (copy_from_user(buf, user_buf, len)) | |
321 | return -EFAULT; | |
322 | ||
323 | buf[len] = '\0'; | |
324 | ||
325 | if (strncmp("trigger", buf, 7) == 0) { | |
963916df | 326 | ath9k_spectral_scan_trigger(common, spec_priv); |
ded3fb4c | 327 | } else if (strncmp("background", buf, 10) == 0) { |
963916df | 328 | ath9k_spectral_scan_config(common, spec_priv, SPECTRAL_BACKGROUND); |
f65c0825 SM |
329 | ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n"); |
330 | } else if (strncmp("chanscan", buf, 8) == 0) { | |
963916df | 331 | ath9k_spectral_scan_config(common, spec_priv, SPECTRAL_CHANSCAN); |
f65c0825 SM |
332 | ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n"); |
333 | } else if (strncmp("manual", buf, 6) == 0) { | |
963916df | 334 | ath9k_spectral_scan_config(common, spec_priv, SPECTRAL_MANUAL); |
f65c0825 SM |
335 | ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n"); |
336 | } else if (strncmp("disable", buf, 7) == 0) { | |
963916df | 337 | ath9k_spectral_scan_config(common, spec_priv, SPECTRAL_DISABLED); |
f65c0825 SM |
338 | ath_dbg(common, CONFIG, "spectral scan: disabled\n"); |
339 | } else { | |
340 | return -EINVAL; | |
341 | } | |
342 | ||
343 | return count; | |
344 | } | |
345 | ||
346 | static const struct file_operations fops_spec_scan_ctl = { | |
347 | .read = read_file_spec_scan_ctl, | |
348 | .write = write_file_spec_scan_ctl, | |
349 | .open = simple_open, | |
350 | .owner = THIS_MODULE, | |
351 | .llseek = default_llseek, | |
352 | }; | |
353 | ||
354 | /*************************/ | |
355 | /* spectral_short_repeat */ | |
356 | /*************************/ | |
357 | ||
358 | static ssize_t read_file_spectral_short_repeat(struct file *file, | |
359 | char __user *user_buf, | |
360 | size_t count, loff_t *ppos) | |
361 | { | |
1111d426 | 362 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
f65c0825 SM |
363 | char buf[32]; |
364 | unsigned int len; | |
365 | ||
1111d426 | 366 | len = sprintf(buf, "%d\n", spec_priv->spec_config.short_repeat); |
f65c0825 SM |
367 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
368 | } | |
369 | ||
370 | static ssize_t write_file_spectral_short_repeat(struct file *file, | |
371 | const char __user *user_buf, | |
372 | size_t count, loff_t *ppos) | |
373 | { | |
1111d426 | 374 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
f65c0825 SM |
375 | unsigned long val; |
376 | char buf[32]; | |
377 | ssize_t len; | |
378 | ||
379 | len = min(count, sizeof(buf) - 1); | |
380 | if (copy_from_user(buf, user_buf, len)) | |
381 | return -EFAULT; | |
382 | ||
383 | buf[len] = '\0'; | |
384 | if (kstrtoul(buf, 0, &val)) | |
385 | return -EINVAL; | |
386 | ||
3f557202 | 387 | if (val > 1) |
f65c0825 SM |
388 | return -EINVAL; |
389 | ||
1111d426 | 390 | spec_priv->spec_config.short_repeat = val; |
f65c0825 SM |
391 | return count; |
392 | } | |
393 | ||
394 | static const struct file_operations fops_spectral_short_repeat = { | |
395 | .read = read_file_spectral_short_repeat, | |
396 | .write = write_file_spectral_short_repeat, | |
397 | .open = simple_open, | |
398 | .owner = THIS_MODULE, | |
399 | .llseek = default_llseek, | |
400 | }; | |
401 | ||
402 | /******************/ | |
403 | /* spectral_count */ | |
404 | /******************/ | |
405 | ||
406 | static ssize_t read_file_spectral_count(struct file *file, | |
407 | char __user *user_buf, | |
408 | size_t count, loff_t *ppos) | |
409 | { | |
1111d426 | 410 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
f65c0825 SM |
411 | char buf[32]; |
412 | unsigned int len; | |
413 | ||
1111d426 | 414 | len = sprintf(buf, "%d\n", spec_priv->spec_config.count); |
f65c0825 SM |
415 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
416 | } | |
417 | ||
418 | static ssize_t write_file_spectral_count(struct file *file, | |
419 | const char __user *user_buf, | |
420 | size_t count, loff_t *ppos) | |
421 | { | |
1111d426 | 422 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
f65c0825 SM |
423 | unsigned long val; |
424 | char buf[32]; | |
425 | ssize_t len; | |
426 | ||
427 | len = min(count, sizeof(buf) - 1); | |
428 | if (copy_from_user(buf, user_buf, len)) | |
429 | return -EFAULT; | |
430 | ||
431 | buf[len] = '\0'; | |
432 | if (kstrtoul(buf, 0, &val)) | |
433 | return -EINVAL; | |
434 | ||
3f557202 | 435 | if (val > 255) |
f65c0825 SM |
436 | return -EINVAL; |
437 | ||
1111d426 | 438 | spec_priv->spec_config.count = val; |
f65c0825 SM |
439 | return count; |
440 | } | |
441 | ||
442 | static const struct file_operations fops_spectral_count = { | |
443 | .read = read_file_spectral_count, | |
444 | .write = write_file_spectral_count, | |
445 | .open = simple_open, | |
446 | .owner = THIS_MODULE, | |
447 | .llseek = default_llseek, | |
448 | }; | |
449 | ||
450 | /*******************/ | |
451 | /* spectral_period */ | |
452 | /*******************/ | |
453 | ||
454 | static ssize_t read_file_spectral_period(struct file *file, | |
455 | char __user *user_buf, | |
456 | size_t count, loff_t *ppos) | |
457 | { | |
1111d426 | 458 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
f65c0825 SM |
459 | char buf[32]; |
460 | unsigned int len; | |
461 | ||
1111d426 | 462 | len = sprintf(buf, "%d\n", spec_priv->spec_config.period); |
f65c0825 SM |
463 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
464 | } | |
465 | ||
466 | static ssize_t write_file_spectral_period(struct file *file, | |
467 | const char __user *user_buf, | |
468 | size_t count, loff_t *ppos) | |
469 | { | |
1111d426 | 470 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
f65c0825 SM |
471 | unsigned long val; |
472 | char buf[32]; | |
473 | ssize_t len; | |
474 | ||
475 | len = min(count, sizeof(buf) - 1); | |
476 | if (copy_from_user(buf, user_buf, len)) | |
477 | return -EFAULT; | |
478 | ||
479 | buf[len] = '\0'; | |
480 | if (kstrtoul(buf, 0, &val)) | |
481 | return -EINVAL; | |
482 | ||
3f557202 | 483 | if (val > 255) |
f65c0825 SM |
484 | return -EINVAL; |
485 | ||
1111d426 | 486 | spec_priv->spec_config.period = val; |
f65c0825 SM |
487 | return count; |
488 | } | |
489 | ||
490 | static const struct file_operations fops_spectral_period = { | |
491 | .read = read_file_spectral_period, | |
492 | .write = write_file_spectral_period, | |
493 | .open = simple_open, | |
494 | .owner = THIS_MODULE, | |
495 | .llseek = default_llseek, | |
496 | }; | |
497 | ||
498 | /***********************/ | |
499 | /* spectral_fft_period */ | |
500 | /***********************/ | |
501 | ||
502 | static ssize_t read_file_spectral_fft_period(struct file *file, | |
503 | char __user *user_buf, | |
504 | size_t count, loff_t *ppos) | |
505 | { | |
1111d426 | 506 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
f65c0825 SM |
507 | char buf[32]; |
508 | unsigned int len; | |
509 | ||
1111d426 | 510 | len = sprintf(buf, "%d\n", spec_priv->spec_config.fft_period); |
f65c0825 SM |
511 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
512 | } | |
513 | ||
514 | static ssize_t write_file_spectral_fft_period(struct file *file, | |
515 | const char __user *user_buf, | |
516 | size_t count, loff_t *ppos) | |
517 | { | |
1111d426 | 518 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
f65c0825 SM |
519 | unsigned long val; |
520 | char buf[32]; | |
521 | ssize_t len; | |
522 | ||
523 | len = min(count, sizeof(buf) - 1); | |
524 | if (copy_from_user(buf, user_buf, len)) | |
525 | return -EFAULT; | |
526 | ||
527 | buf[len] = '\0'; | |
528 | if (kstrtoul(buf, 0, &val)) | |
529 | return -EINVAL; | |
530 | ||
3f557202 | 531 | if (val > 15) |
f65c0825 SM |
532 | return -EINVAL; |
533 | ||
1111d426 | 534 | spec_priv->spec_config.fft_period = val; |
f65c0825 SM |
535 | return count; |
536 | } | |
537 | ||
538 | static const struct file_operations fops_spectral_fft_period = { | |
539 | .read = read_file_spectral_fft_period, | |
540 | .write = write_file_spectral_fft_period, | |
541 | .open = simple_open, | |
542 | .owner = THIS_MODULE, | |
543 | .llseek = default_llseek, | |
544 | }; | |
545 | ||
546 | /*******************/ | |
547 | /* Relay interface */ | |
548 | /*******************/ | |
549 | ||
550 | static struct dentry *create_buf_file_handler(const char *filename, | |
551 | struct dentry *parent, | |
552 | umode_t mode, | |
553 | struct rchan_buf *buf, | |
554 | int *is_global) | |
555 | { | |
556 | struct dentry *buf_file; | |
557 | ||
558 | buf_file = debugfs_create_file(filename, mode, parent, buf, | |
559 | &relay_file_operations); | |
560 | *is_global = 1; | |
561 | return buf_file; | |
562 | } | |
563 | ||
564 | static int remove_buf_file_handler(struct dentry *dentry) | |
565 | { | |
566 | debugfs_remove(dentry); | |
567 | ||
568 | return 0; | |
569 | } | |
570 | ||
f84d1b49 | 571 | static struct rchan_callbacks rfs_spec_scan_cb = { |
f65c0825 SM |
572 | .create_buf_file = create_buf_file_handler, |
573 | .remove_buf_file = remove_buf_file_handler, | |
574 | }; | |
575 | ||
576 | /*********************/ | |
577 | /* Debug Init/Deinit */ | |
578 | /*********************/ | |
579 | ||
1111d426 | 580 | void ath9k_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv) |
f65c0825 | 581 | { |
1111d426 OR |
582 | if (config_enabled(CONFIG_ATH9K_DEBUGFS) && spec_priv->rfs_chan_spec_scan) { |
583 | relay_close(spec_priv->rfs_chan_spec_scan); | |
584 | spec_priv->rfs_chan_spec_scan = NULL; | |
f65c0825 SM |
585 | } |
586 | } | |
587 | ||
1111d426 | 588 | void ath9k_spectral_init_debug(struct ath_spec_scan_priv *spec_priv, struct dentry *debugfs_phy) |
f65c0825 | 589 | { |
1111d426 | 590 | spec_priv->rfs_chan_spec_scan = relay_open("spectral_scan", |
c10b75af | 591 | debugfs_phy, |
f65c0825 SM |
592 | 1024, 256, &rfs_spec_scan_cb, |
593 | NULL); | |
594 | debugfs_create_file("spectral_scan_ctl", | |
595 | S_IRUSR | S_IWUSR, | |
1111d426 | 596 | debugfs_phy, spec_priv, |
f65c0825 SM |
597 | &fops_spec_scan_ctl); |
598 | debugfs_create_file("spectral_short_repeat", | |
599 | S_IRUSR | S_IWUSR, | |
1111d426 | 600 | debugfs_phy, spec_priv, |
f65c0825 SM |
601 | &fops_spectral_short_repeat); |
602 | debugfs_create_file("spectral_count", | |
603 | S_IRUSR | S_IWUSR, | |
1111d426 | 604 | debugfs_phy, spec_priv, |
f65c0825 SM |
605 | &fops_spectral_count); |
606 | debugfs_create_file("spectral_period", | |
607 | S_IRUSR | S_IWUSR, | |
1111d426 | 608 | debugfs_phy, spec_priv, |
f65c0825 SM |
609 | &fops_spectral_period); |
610 | debugfs_create_file("spectral_fft_period", | |
611 | S_IRUSR | S_IWUSR, | |
1111d426 | 612 | debugfs_phy, spec_priv, |
f65c0825 SM |
613 | &fops_spectral_fft_period); |
614 | } |