Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Qualcomm Atheros, Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/relay.h> |
| 18 | #include "ath9k.h" |
| 19 | |
| 20 | static s8 fix_rssi_inv_only(u8 rssi_val) |
| 21 | { |
| 22 | if (rssi_val == 128) |
| 23 | rssi_val = 0; |
| 24 | return (s8) rssi_val; |
| 25 | } |
| 26 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 27 | static void ath_debug_send_fft_sample(struct ath_spec_scan_priv *spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 28 | struct fft_sample_tlv *fft_sample_tlv) |
| 29 | { |
| 30 | int length; |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 31 | if (!spec_priv->rfs_chan_spec_scan) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 32 | return; |
| 33 | |
| 34 | length = __be16_to_cpu(fft_sample_tlv->length) + |
| 35 | sizeof(*fft_sample_tlv); |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 36 | relay_write(spec_priv->rfs_chan_spec_scan, fft_sample_tlv, length); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /* returns 1 if this was a spectral frame, even if not handled. */ |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 40 | int ath_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 41 | struct ath_rx_status *rs, u64 tsf) |
| 42 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 43 | struct ath_hw *ah = spec_priv->ah; |
| 44 | struct ath_common *common = ath9k_hw_common(spec_priv->ah); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 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 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 71 | chan_type = cfg80211_get_chandef_type(&common->hw->conf.chandef); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 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 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 203 | ath_debug_send_fft_sample(spec_priv, tlv); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 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 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 215 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 216 | char *mode = ""; |
| 217 | unsigned int len; |
| 218 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 219 | switch (spec_priv->spectral_mode) { |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 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 | |
| 237 | static ssize_t write_file_spec_scan_ctl(struct file *file, |
| 238 | const char __user *user_buf, |
| 239 | size_t count, loff_t *ppos) |
| 240 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 241 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
| 242 | struct ath_common *common = ath9k_hw_common(spec_priv->ah); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 243 | char buf[32]; |
| 244 | ssize_t len; |
| 245 | |
| 246 | if (config_enabled(CONFIG_ATH9K_TX99)) |
| 247 | return -EOPNOTSUPP; |
| 248 | |
| 249 | len = min(count, sizeof(buf) - 1); |
| 250 | if (copy_from_user(buf, user_buf, len)) |
| 251 | return -EFAULT; |
| 252 | |
| 253 | buf[len] = '\0'; |
| 254 | |
| 255 | if (strncmp("trigger", buf, 7) == 0) { |
Oleksij Rempel | ef948da | 2014-11-06 08:53:27 +0100 | [diff] [blame^] | 256 | ath9k_spectral_scan_trigger(common); |
Maks Naumov | ded3fb4 | 2014-08-16 00:41:07 -0700 | [diff] [blame] | 257 | } else if (strncmp("background", buf, 10) == 0) { |
Oleksij Rempel | ef948da | 2014-11-06 08:53:27 +0100 | [diff] [blame^] | 258 | ath9k_spectral_scan_config(common, SPECTRAL_BACKGROUND); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 259 | ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n"); |
| 260 | } else if (strncmp("chanscan", buf, 8) == 0) { |
Oleksij Rempel | ef948da | 2014-11-06 08:53:27 +0100 | [diff] [blame^] | 261 | ath9k_spectral_scan_config(common, SPECTRAL_CHANSCAN); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 262 | ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n"); |
| 263 | } else if (strncmp("manual", buf, 6) == 0) { |
Oleksij Rempel | ef948da | 2014-11-06 08:53:27 +0100 | [diff] [blame^] | 264 | ath9k_spectral_scan_config(common, SPECTRAL_MANUAL); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 265 | ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n"); |
| 266 | } else if (strncmp("disable", buf, 7) == 0) { |
Oleksij Rempel | ef948da | 2014-11-06 08:53:27 +0100 | [diff] [blame^] | 267 | ath9k_spectral_scan_config(common, SPECTRAL_DISABLED); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 268 | ath_dbg(common, CONFIG, "spectral scan: disabled\n"); |
| 269 | } else { |
| 270 | return -EINVAL; |
| 271 | } |
| 272 | |
| 273 | return count; |
| 274 | } |
| 275 | |
| 276 | static const struct file_operations fops_spec_scan_ctl = { |
| 277 | .read = read_file_spec_scan_ctl, |
| 278 | .write = write_file_spec_scan_ctl, |
| 279 | .open = simple_open, |
| 280 | .owner = THIS_MODULE, |
| 281 | .llseek = default_llseek, |
| 282 | }; |
| 283 | |
| 284 | /*************************/ |
| 285 | /* spectral_short_repeat */ |
| 286 | /*************************/ |
| 287 | |
| 288 | static ssize_t read_file_spectral_short_repeat(struct file *file, |
| 289 | char __user *user_buf, |
| 290 | size_t count, loff_t *ppos) |
| 291 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 292 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 293 | char buf[32]; |
| 294 | unsigned int len; |
| 295 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 296 | len = sprintf(buf, "%d\n", spec_priv->spec_config.short_repeat); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 297 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 298 | } |
| 299 | |
| 300 | static ssize_t write_file_spectral_short_repeat(struct file *file, |
| 301 | const char __user *user_buf, |
| 302 | size_t count, loff_t *ppos) |
| 303 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 304 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 305 | unsigned long val; |
| 306 | char buf[32]; |
| 307 | ssize_t len; |
| 308 | |
| 309 | len = min(count, sizeof(buf) - 1); |
| 310 | if (copy_from_user(buf, user_buf, len)) |
| 311 | return -EFAULT; |
| 312 | |
| 313 | buf[len] = '\0'; |
| 314 | if (kstrtoul(buf, 0, &val)) |
| 315 | return -EINVAL; |
| 316 | |
Andrey Utkin | 3f55720 | 2014-07-17 16:56:37 +0300 | [diff] [blame] | 317 | if (val > 1) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 318 | return -EINVAL; |
| 319 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 320 | spec_priv->spec_config.short_repeat = val; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 321 | return count; |
| 322 | } |
| 323 | |
| 324 | static const struct file_operations fops_spectral_short_repeat = { |
| 325 | .read = read_file_spectral_short_repeat, |
| 326 | .write = write_file_spectral_short_repeat, |
| 327 | .open = simple_open, |
| 328 | .owner = THIS_MODULE, |
| 329 | .llseek = default_llseek, |
| 330 | }; |
| 331 | |
| 332 | /******************/ |
| 333 | /* spectral_count */ |
| 334 | /******************/ |
| 335 | |
| 336 | static ssize_t read_file_spectral_count(struct file *file, |
| 337 | char __user *user_buf, |
| 338 | size_t count, loff_t *ppos) |
| 339 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 340 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 341 | char buf[32]; |
| 342 | unsigned int len; |
| 343 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 344 | len = sprintf(buf, "%d\n", spec_priv->spec_config.count); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 345 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 346 | } |
| 347 | |
| 348 | static ssize_t write_file_spectral_count(struct file *file, |
| 349 | const char __user *user_buf, |
| 350 | size_t count, loff_t *ppos) |
| 351 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 352 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 353 | unsigned long val; |
| 354 | char buf[32]; |
| 355 | ssize_t len; |
| 356 | |
| 357 | len = min(count, sizeof(buf) - 1); |
| 358 | if (copy_from_user(buf, user_buf, len)) |
| 359 | return -EFAULT; |
| 360 | |
| 361 | buf[len] = '\0'; |
| 362 | if (kstrtoul(buf, 0, &val)) |
| 363 | return -EINVAL; |
| 364 | |
Andrey Utkin | 3f55720 | 2014-07-17 16:56:37 +0300 | [diff] [blame] | 365 | if (val > 255) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 366 | return -EINVAL; |
| 367 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 368 | spec_priv->spec_config.count = val; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 369 | return count; |
| 370 | } |
| 371 | |
| 372 | static const struct file_operations fops_spectral_count = { |
| 373 | .read = read_file_spectral_count, |
| 374 | .write = write_file_spectral_count, |
| 375 | .open = simple_open, |
| 376 | .owner = THIS_MODULE, |
| 377 | .llseek = default_llseek, |
| 378 | }; |
| 379 | |
| 380 | /*******************/ |
| 381 | /* spectral_period */ |
| 382 | /*******************/ |
| 383 | |
| 384 | static ssize_t read_file_spectral_period(struct file *file, |
| 385 | char __user *user_buf, |
| 386 | size_t count, loff_t *ppos) |
| 387 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 388 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 389 | char buf[32]; |
| 390 | unsigned int len; |
| 391 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 392 | len = sprintf(buf, "%d\n", spec_priv->spec_config.period); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 393 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 394 | } |
| 395 | |
| 396 | static ssize_t write_file_spectral_period(struct file *file, |
| 397 | const char __user *user_buf, |
| 398 | size_t count, loff_t *ppos) |
| 399 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 400 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 401 | unsigned long val; |
| 402 | char buf[32]; |
| 403 | ssize_t len; |
| 404 | |
| 405 | len = min(count, sizeof(buf) - 1); |
| 406 | if (copy_from_user(buf, user_buf, len)) |
| 407 | return -EFAULT; |
| 408 | |
| 409 | buf[len] = '\0'; |
| 410 | if (kstrtoul(buf, 0, &val)) |
| 411 | return -EINVAL; |
| 412 | |
Andrey Utkin | 3f55720 | 2014-07-17 16:56:37 +0300 | [diff] [blame] | 413 | if (val > 255) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 414 | return -EINVAL; |
| 415 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 416 | spec_priv->spec_config.period = val; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 417 | return count; |
| 418 | } |
| 419 | |
| 420 | static const struct file_operations fops_spectral_period = { |
| 421 | .read = read_file_spectral_period, |
| 422 | .write = write_file_spectral_period, |
| 423 | .open = simple_open, |
| 424 | .owner = THIS_MODULE, |
| 425 | .llseek = default_llseek, |
| 426 | }; |
| 427 | |
| 428 | /***********************/ |
| 429 | /* spectral_fft_period */ |
| 430 | /***********************/ |
| 431 | |
| 432 | static ssize_t read_file_spectral_fft_period(struct file *file, |
| 433 | char __user *user_buf, |
| 434 | size_t count, loff_t *ppos) |
| 435 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 436 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 437 | char buf[32]; |
| 438 | unsigned int len; |
| 439 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 440 | len = sprintf(buf, "%d\n", spec_priv->spec_config.fft_period); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 441 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 442 | } |
| 443 | |
| 444 | static ssize_t write_file_spectral_fft_period(struct file *file, |
| 445 | const char __user *user_buf, |
| 446 | size_t count, loff_t *ppos) |
| 447 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 448 | struct ath_spec_scan_priv *spec_priv = file->private_data; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 449 | unsigned long val; |
| 450 | char buf[32]; |
| 451 | ssize_t len; |
| 452 | |
| 453 | len = min(count, sizeof(buf) - 1); |
| 454 | if (copy_from_user(buf, user_buf, len)) |
| 455 | return -EFAULT; |
| 456 | |
| 457 | buf[len] = '\0'; |
| 458 | if (kstrtoul(buf, 0, &val)) |
| 459 | return -EINVAL; |
| 460 | |
Andrey Utkin | 3f55720 | 2014-07-17 16:56:37 +0300 | [diff] [blame] | 461 | if (val > 15) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 462 | return -EINVAL; |
| 463 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 464 | spec_priv->spec_config.fft_period = val; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 465 | return count; |
| 466 | } |
| 467 | |
| 468 | static const struct file_operations fops_spectral_fft_period = { |
| 469 | .read = read_file_spectral_fft_period, |
| 470 | .write = write_file_spectral_fft_period, |
| 471 | .open = simple_open, |
| 472 | .owner = THIS_MODULE, |
| 473 | .llseek = default_llseek, |
| 474 | }; |
| 475 | |
| 476 | /*******************/ |
| 477 | /* Relay interface */ |
| 478 | /*******************/ |
| 479 | |
| 480 | static struct dentry *create_buf_file_handler(const char *filename, |
| 481 | struct dentry *parent, |
| 482 | umode_t mode, |
| 483 | struct rchan_buf *buf, |
| 484 | int *is_global) |
| 485 | { |
| 486 | struct dentry *buf_file; |
| 487 | |
| 488 | buf_file = debugfs_create_file(filename, mode, parent, buf, |
| 489 | &relay_file_operations); |
| 490 | *is_global = 1; |
| 491 | return buf_file; |
| 492 | } |
| 493 | |
| 494 | static int remove_buf_file_handler(struct dentry *dentry) |
| 495 | { |
| 496 | debugfs_remove(dentry); |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
Wei Yongjun | f84d1b4 | 2013-12-20 10:22:51 +0800 | [diff] [blame] | 501 | static struct rchan_callbacks rfs_spec_scan_cb = { |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 502 | .create_buf_file = create_buf_file_handler, |
| 503 | .remove_buf_file = remove_buf_file_handler, |
| 504 | }; |
| 505 | |
| 506 | /*********************/ |
| 507 | /* Debug Init/Deinit */ |
| 508 | /*********************/ |
| 509 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 510 | void ath9k_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 511 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 512 | if (config_enabled(CONFIG_ATH9K_DEBUGFS) && spec_priv->rfs_chan_spec_scan) { |
| 513 | relay_close(spec_priv->rfs_chan_spec_scan); |
| 514 | spec_priv->rfs_chan_spec_scan = NULL; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 518 | void ath9k_spectral_init_debug(struct ath_spec_scan_priv *spec_priv, struct dentry *debugfs_phy) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 519 | { |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 520 | spec_priv->rfs_chan_spec_scan = relay_open("spectral_scan", |
Oleksij Rempel | c10b75a | 2014-11-06 08:53:21 +0100 | [diff] [blame] | 521 | debugfs_phy, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 522 | 1024, 256, &rfs_spec_scan_cb, |
| 523 | NULL); |
| 524 | debugfs_create_file("spectral_scan_ctl", |
| 525 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 526 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 527 | &fops_spec_scan_ctl); |
| 528 | debugfs_create_file("spectral_short_repeat", |
| 529 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 530 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 531 | &fops_spectral_short_repeat); |
| 532 | debugfs_create_file("spectral_count", |
| 533 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 534 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 535 | &fops_spectral_count); |
| 536 | debugfs_create_file("spectral_period", |
| 537 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 538 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 539 | &fops_spectral_period); |
| 540 | debugfs_create_file("spectral_fft_period", |
| 541 | S_IRUSR | S_IWUSR, |
Oleksij Rempel | 1111d42 | 2014-11-06 08:53:23 +0100 | [diff] [blame] | 542 | debugfs_phy, spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 543 | &fops_spectral_fft_period); |
| 544 | } |