forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/net/wireless/ath/ath9k/common-spectral.c
....@@ -59,8 +59,7 @@
5959
6060 sample = sample_end - SPECTRAL_HT20_SAMPLE_LEN + 1;
6161
62
- max_index = spectral_max_index(mag_info->all_bins,
63
- SPECTRAL_HT20_NUM_BINS);
62
+ max_index = spectral_max_index_ht20(mag_info->all_bins);
6463 max_magnitude = spectral_max_magnitude(mag_info->all_bins);
6564
6665 max_exp = mag_info->max_exp & 0xf;
....@@ -72,7 +71,7 @@
7271 if (bytes_read < SPECTRAL_HT20_SAMPLE_LEN && max_index < 1)
7372 return -1;
7473
75
- if (sample[max_index] != (max_magnitude >> max_exp))
74
+ if ((sample[max_index] & 0xf8) != ((max_magnitude >> max_exp) & 0xf8))
7675 return -1;
7776 else
7877 return 0;
....@@ -100,12 +99,10 @@
10099 sample = sample_end - SPECTRAL_HT20_40_SAMPLE_LEN + 1;
101100
102101 lower_mag = spectral_max_magnitude(mag_info->lower_bins);
103
- lower_max_index = spectral_max_index(mag_info->lower_bins,
104
- SPECTRAL_HT20_40_NUM_BINS);
102
+ lower_max_index = spectral_max_index_ht40(mag_info->lower_bins);
105103
106104 upper_mag = spectral_max_magnitude(mag_info->upper_bins);
107
- upper_max_index = spectral_max_index(mag_info->upper_bins,
108
- SPECTRAL_HT20_40_NUM_BINS);
105
+ upper_max_index = spectral_max_index_ht40(mag_info->upper_bins);
109106
110107 max_exp = mag_info->max_exp & 0xf;
111108
....@@ -117,19 +114,10 @@
117114 ((upper_max_index < 1) || (lower_max_index < 1)))
118115 return -1;
119116
120
- /* Some time hardware messes up the index and adds
121
- * the index of the middle point (dc_pos). Try to fix it.
122
- */
123
- if ((upper_max_index - dc_pos > 0) &&
124
- (sample[upper_max_index] == (upper_mag >> max_exp)))
125
- upper_max_index -= dc_pos;
126
-
127
- if ((lower_max_index - dc_pos > 0) &&
128
- (sample[lower_max_index - dc_pos] == (lower_mag >> max_exp)))
129
- lower_max_index -= dc_pos;
130
-
131
- if ((sample[upper_max_index + dc_pos] != (upper_mag >> max_exp)) ||
132
- (sample[lower_max_index] != (lower_mag >> max_exp)))
117
+ if (((sample[upper_max_index + dc_pos] & 0xf8) !=
118
+ ((upper_mag >> max_exp) & 0xf8)) ||
119
+ ((sample[lower_max_index] & 0xf8) !=
120
+ ((lower_mag >> max_exp) & 0xf8)))
133121 return -1;
134122 else
135123 return 0;
....@@ -169,8 +157,7 @@
169157 magnitude = spectral_max_magnitude(mag_info->all_bins);
170158 fft_sample_20.max_magnitude = __cpu_to_be16(magnitude);
171159
172
- max_index = spectral_max_index(mag_info->all_bins,
173
- SPECTRAL_HT20_NUM_BINS);
160
+ max_index = spectral_max_index_ht20(mag_info->all_bins);
174161 fft_sample_20.max_index = max_index;
175162
176163 bitmap_w = spectral_bitmap_weight(mag_info->all_bins);
....@@ -188,7 +175,8 @@
188175 magnitude >> max_exp,
189176 max_index);
190177
191
- if (fft_sample_20.data[max_index] != (magnitude >> max_exp)) {
178
+ if ((fft_sample_20.data[max_index] & 0xf8) !=
179
+ ((magnitude >> max_exp) & 0xf8)) {
192180 ath_dbg(common, SPECTRAL_SCAN, "Magnitude mismatch !\n");
193181 ret = -1;
194182 }
....@@ -302,12 +290,10 @@
302290 upper_mag = spectral_max_magnitude(mag_info->upper_bins);
303291 fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag);
304292
305
- lower_max_index = spectral_max_index(mag_info->lower_bins,
306
- SPECTRAL_HT20_40_NUM_BINS);
293
+ lower_max_index = spectral_max_index_ht40(mag_info->lower_bins);
307294 fft_sample_40.lower_max_index = lower_max_index;
308295
309
- upper_max_index = spectral_max_index(mag_info->upper_bins,
310
- SPECTRAL_HT20_40_NUM_BINS);
296
+ upper_max_index = spectral_max_index_ht40(mag_info->upper_bins);
311297 fft_sample_40.upper_max_index = upper_max_index;
312298
313299 lower_bitmap_w = spectral_bitmap_weight(mag_info->lower_bins);
....@@ -331,29 +317,13 @@
331317 upper_mag >> max_exp,
332318 upper_max_index);
333319
334
- /* Some time hardware messes up the index and adds
335
- * the index of the middle point (dc_pos). Try to fix it.
336
- */
337
- if ((upper_max_index - dc_pos > 0) &&
338
- (fft_sample_40.data[upper_max_index] == (upper_mag >> max_exp))) {
339
- upper_max_index -= dc_pos;
340
- fft_sample_40.upper_max_index = upper_max_index;
341
- }
342
-
343
- if ((lower_max_index - dc_pos > 0) &&
344
- (fft_sample_40.data[lower_max_index - dc_pos] ==
345
- (lower_mag >> max_exp))) {
346
- lower_max_index -= dc_pos;
347
- fft_sample_40.lower_max_index = lower_max_index;
348
- }
349
-
350320 /* Check if we got the expected magnitude values at
351321 * the expected bins
352322 */
353
- if ((fft_sample_40.data[upper_max_index + dc_pos]
354
- != (upper_mag >> max_exp)) ||
355
- (fft_sample_40.data[lower_max_index]
356
- != (lower_mag >> max_exp))) {
323
+ if (((fft_sample_40.data[upper_max_index + dc_pos] & 0xf8)
324
+ != ((upper_mag >> max_exp) & 0xf8)) ||
325
+ ((fft_sample_40.data[lower_max_index] & 0xf8)
326
+ != ((lower_mag >> max_exp) & 0xf8))) {
357327 ath_dbg(common, SPECTRAL_SCAN, "Magnitude mismatch !\n");
358328 ret = -1;
359329 }
....@@ -501,6 +471,7 @@
501471 u8 sample_buf[SPECTRAL_SAMPLE_MAX_LEN] = {0};
502472 struct ath_hw *ah = spec_priv->ah;
503473 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
474
+ struct ath_softc *sc = (struct ath_softc *)common->priv;
504475 u8 num_bins, *vdata = (u8 *)hdr;
505476 struct ath_radar_info *radar_info;
506477 int len = rs->rs_datalen;
....@@ -649,8 +620,13 @@
649620 sample_buf, sample_len,
650621 sample_bytes);
651622
652
- fft_handler(rs, spec_priv, sample_buf,
653
- tsf, freq, chan_type);
623
+ ret = fft_handler(rs, spec_priv, sample_buf,
624
+ tsf, freq, chan_type);
625
+
626
+ if (ret == 0)
627
+ RX_STAT_INC(sc, rx_spectral_sample_good);
628
+ else
629
+ RX_STAT_INC(sc, rx_spectral_sample_err);
654630
655631 memset(sample_buf, 0, SPECTRAL_SAMPLE_MAX_LEN);
656632
....@@ -665,6 +641,11 @@
665641 ret = fft_handler(rs, spec_priv, sample_start,
666642 tsf, freq, chan_type);
667643
644
+ if (ret == 0)
645
+ RX_STAT_INC(sc, rx_spectral_sample_good);
646
+ else
647
+ RX_STAT_INC(sc, rx_spectral_sample_err);
648
+
668649 /* Mix the received bins to the /dev/random
669650 * pool
670651 */
....@@ -675,7 +656,7 @@
675656 * loop.
676657 */
677658 if (len <= fft_len + 2)
678
- break;
659
+ return 1;
679660
680661 sample_start = &vdata[i + 1];
681662
....@@ -1058,6 +1039,9 @@
10581039
10591040 buf_file = debugfs_create_file(filename, mode, parent, buf,
10601041 &relay_file_operations);
1042
+ if (IS_ERR(buf_file))
1043
+ return NULL;
1044
+
10611045 *is_global = 1;
10621046 return buf_file;
10631047 }