Skip to contentSkip to conversation

ath9k: FFT fixes and improvements

PATCH In review Simon Wunderlich 3 participants 12 messages Sep 19, 2018 – Oct 2, 2018 1 message not in the archive Qualcomm Atheros ATH9K wireless driver

lore
Share & tools
lore
#0 lore raw

cover ath9k: FFT fixes and improvements

During FFT evaluation on an AR9462 adapter, we noticed that there were way less FFT samples received than we would expect. This patchset adds some counters to be able to check for received (and discarded) FFT samples, and fixes a variety of issues I found while debugging.

Cheers,
Simon

Simon Wunderlich (5):
ath9k: add counters for good and errorneous FFT/spectral frames
ath9k: return when short FFT frame was handled
ath9k: fix and simplify FFT max index retrieval
ath9k: FFT magnitude check: don't consider lower 3 data bits
ath9k: fix reporting calculated new FFT upper max

 drivers/net/wireless/ath/ath9k/common-debug.c    |  2 +
 drivers/net/wireless/ath/ath9k/common-debug.h    |  4 ++
 drivers/net/wireless/ath/ath9k/common-spectral.c | 83 +++++++++---------------
 drivers/net/wireless/ath/ath9k/common-spectral.h | 17 +++++
 4 files changed, 55 insertions(+), 51 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/5 ath9k: add counters for good and errorneous FFT/spectral frames

This is helpful to see whether spectral samples get discarded.

---
 drivers/net/wireless/ath/ath9k/common-debug.c    |  2 ++
 drivers/net/wireless/ath/ath9k/common-debug.h    |  4 ++++
 drivers/net/wireless/ath/ath9k/common-spectral.c | 15 +++++++++++++--
 3 files changed, 19 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath9k/common-debug.c +2 -0
index 239429f10378..53ca4b063eb9 100644
@@ -144,6 +144,8 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,
 	RXS_ERR("BEACONS", rx_beacons);
 	RXS_ERR("FRAGS", rx_frags);
 	RXS_ERR("SPECTRAL", rx_spectral);
+	RXS_ERR("SPECTRAL SMPL GOOD", rx_spectral_sample_good);
+	RXS_ERR("SPECTRAL SMPL ERR", rx_spectral_sample_err);
 
 	RXS_ERR("CRC ERR", crc_err);
 	RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
drivers/net/wireless/ath/ath9k/common-debug.h +4 -0
index 3376990d3a24..2938b5b96b07 100644
@@ -39,6 +39,8 @@
  * @rx_beacons:  No. of beacons received.
  * @rx_frags:  No. of rx-fragements received.
  * @rx_spectral: No of spectral packets received.
+ * @rx_spectral_sample_good: No. of good spectral samples
+ * @rx_spectral_sample_err: No. of good spectral samples
  */
 struct ath_rx_stats {
 	u32 rx_pkts_all;
@@ -58,6 +60,8 @@ struct ath_rx_stats {
 	u32 rx_beacons;
 	u32 rx_frags;
 	u32 rx_spectral;
+	u32 rx_spectral_sample_good;
+	u32 rx_spectral_sample_err;
 };
 
 #ifdef CONFIG_ATH9K_COMMON_DEBUG
drivers/net/wireless/ath/ath9k/common-spectral.c +13 -2
index 440e16e641e4..0c5559009a28 100644
@@ -501,6 +501,7 @@ int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_h
 	u8 sample_buf[SPECTRAL_SAMPLE_MAX_LEN] = {0};
 	struct ath_hw *ah = spec_priv->ah;
 	struct ath_common *common = ath9k_hw_common(spec_priv->ah);
+	struct ath_softc *sc = (struct ath_softc *)common->priv;
 	u8 num_bins, *vdata = (u8 *)hdr;
 	struct ath_radar_info *radar_info;
 	int len = rs->rs_datalen;
@@ -649,8 +650,13 @@ int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_h
 						       sample_buf, sample_len,
 						       sample_bytes);
 
-				fft_handler(rs, spec_priv, sample_buf,
-					    tsf, freq, chan_type);
+				ret = fft_handler(rs, spec_priv, sample_buf,
+						  tsf, freq, chan_type);
+
+				if (ret == 0)
+					RX_STAT_INC(rx_spectral_sample_good);
+				else
+					RX_STAT_INC(rx_spectral_sample_err);
 
 				memset(sample_buf, 0, SPECTRAL_SAMPLE_MAX_LEN);
 
@@ -665,6 +671,11 @@ int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_h
 				ret = fft_handler(rs, spec_priv, sample_start,
 						  tsf, freq, chan_type);
 
+				if (ret == 0)
+					RX_STAT_INC(rx_spectral_sample_good);
+				else
+					RX_STAT_INC(rx_spectral_sample_err);
+
 				/* Mix the received bins to the /dev/random
 				 * pool
 				 */
Signature · 1 line
2.11.0
#2 lore raw

Re: [PATCH 1/5] ath9k: add counters for good and errorneous FFT/spectral frames

Quoted 4 lines · Simon Wunderlich

This is helpful to see whether spectral samples get discarded.

5 patches applied to ath-next branch of ath.git, thanks.

03224678c013 ath9k: add counters for good and errorneous FFT/spectral frames b796a6c04e65 ath9k: return when short FFT frame was handled 2f85786b8a57 ath9k: fix and simplify FFT max index retrieval 4e7a3fa5394e ath9k: FFT magnitude check: don't consider lower 3 data bits 4fb5837ac2bd ath9k: fix reporting calculated new FFT upper max

Signature · 3 lines
https://patchwork.kernel.org/patch/10605607/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw

PATCH 2/5 ath9k: return when short FFT frame was handled

In reply to Simon Wunderlich

With the loop break like this, there are false "FFT report truncated" messages because the iterator is not advanced as the check expects.

Instead, just return, for a single frame there is nothing left to be done anyways.

---
 drivers/net/wireless/ath/ath9k/common-spectral.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/common-spectral.c +1 -1
index 0c5559009a28..f6dd0ecfbbf3 100644
@@ -686,7 +686,7 @@ int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_h
 			 * loop.
 			 */
 			if (len <= fft_len + 2)
-				break;
+				return 1;
 
 			sample_start = &vdata[i + 1];
 
Signature · 1 line
2.11.0
#4 lore raw

PATCH 3/5 ath9k: fix and simplify FFT max index retrieval

In reply to Simon Wunderlich

FFT max index retrieval was not retrieved correctly for HT20/HT40 FFT frames. Fixing the retrieval allows us to remove the fixup function as well. While at it, split the spectral_max_index function into versions for ht20 and ht40 to simplify the code.

---
 drivers/net/wireless/ath/ath9k/common-spectral.c | 45 ++++--------------------
 drivers/net/wireless/ath/ath9k/common-spectral.h | 17 +++++++++
 2 files changed, 23 insertions(+), 39 deletions(-)
drivers/net/wireless/ath/ath9k/common-spectral.c +6 -39
index f6dd0ecfbbf3..d10e3f29c356 100644
@@ -59,8 +59,7 @@ ath_cmn_max_idx_verify_ht20_fft(u8 *sample_end, int bytes_read)
 
 	sample = sample_end - SPECTRAL_HT20_SAMPLE_LEN + 1;
 
-	max_index = spectral_max_index(mag_info->all_bins,
-				       SPECTRAL_HT20_NUM_BINS);
+	max_index = spectral_max_index_ht20(mag_info->all_bins);
 	max_magnitude = spectral_max_magnitude(mag_info->all_bins);
 
 	max_exp = mag_info->max_exp & 0xf;
@@ -100,12 +99,10 @@ ath_cmn_max_idx_verify_ht20_40_fft(u8 *sample_end, int bytes_read)
 	sample = sample_end - SPECTRAL_HT20_40_SAMPLE_LEN + 1;
 
 	lower_mag = spectral_max_magnitude(mag_info->lower_bins);
-	lower_max_index = spectral_max_index(mag_info->lower_bins,
-					     SPECTRAL_HT20_40_NUM_BINS);
+	lower_max_index = spectral_max_index_ht40(mag_info->lower_bins);
 
 	upper_mag = spectral_max_magnitude(mag_info->upper_bins);
-	upper_max_index = spectral_max_index(mag_info->upper_bins,
-					     SPECTRAL_HT20_40_NUM_BINS);
+	upper_max_index = spectral_max_index_ht40(mag_info->upper_bins);
 
 	max_exp = mag_info->max_exp & 0xf;
 
@@ -117,17 +114,6 @@ ath_cmn_max_idx_verify_ht20_40_fft(u8 *sample_end, int bytes_read)
 	   ((upper_max_index < 1) || (lower_max_index < 1)))
 		return -1;
 
-	/* Some time hardware messes up the index and adds
-	 * the index of the middle point (dc_pos). Try to fix it.
-	 */
-	if ((upper_max_index - dc_pos > 0) &&
-	   (sample[upper_max_index] == (upper_mag >> max_exp)))
-		upper_max_index -= dc_pos;
-
-	if ((lower_max_index - dc_pos > 0) &&
-	   (sample[lower_max_index - dc_pos] == (lower_mag >> max_exp)))
-		lower_max_index -= dc_pos;
-
 	if ((sample[upper_max_index + dc_pos] != (upper_mag >> max_exp)) ||
 	   (sample[lower_max_index] != (lower_mag >> max_exp)))
 		return -1;
@@ -169,8 +155,7 @@ ath_cmn_process_ht20_fft(struct ath_rx_status *rs,
 	magnitude = spectral_max_magnitude(mag_info->all_bins);
 	fft_sample_20.max_magnitude = __cpu_to_be16(magnitude);
 
-	max_index = spectral_max_index(mag_info->all_bins,
-					SPECTRAL_HT20_NUM_BINS);
+	max_index = spectral_max_index_ht20(mag_info->all_bins);
 	fft_sample_20.max_index = max_index;
 
 	bitmap_w = spectral_bitmap_weight(mag_info->all_bins);
@@ -302,12 +287,10 @@ ath_cmn_process_ht20_40_fft(struct ath_rx_status *rs,
 	upper_mag = spectral_max_magnitude(mag_info->upper_bins);
 	fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag);
 
-	lower_max_index = spectral_max_index(mag_info->lower_bins,
-					SPECTRAL_HT20_40_NUM_BINS);
+	lower_max_index = spectral_max_index_ht40(mag_info->lower_bins);
 	fft_sample_40.lower_max_index = lower_max_index;
 
-	upper_max_index = spectral_max_index(mag_info->upper_bins,
-					SPECTRAL_HT20_40_NUM_BINS);
+	upper_max_index = spectral_max_index_ht40(mag_info->upper_bins);
 	fft_sample_40.upper_max_index = upper_max_index;
 
 	lower_bitmap_w = spectral_bitmap_weight(mag_info->lower_bins);
@@ -331,22 +314,6 @@ ath_cmn_process_ht20_40_fft(struct ath_rx_status *rs,
 					upper_mag >> max_exp,
 					upper_max_index);
 
-	/* Some time hardware messes up the index and adds
-	 * the index of the middle point (dc_pos). Try to fix it.
-	 */
-	if ((upper_max_index - dc_pos > 0) &&
-	   (fft_sample_40.data[upper_max_index] == (upper_mag >> max_exp))) {
-		upper_max_index -= dc_pos;
-		fft_sample_40.upper_max_index = upper_max_index;
-	}
-
-	if ((lower_max_index - dc_pos > 0) &&
-	   (fft_sample_40.data[lower_max_index - dc_pos] ==
-	   (lower_mag >> max_exp))) {
-		lower_max_index -= dc_pos;
-		fft_sample_40.lower_max_index = lower_max_index;
-	}
-
 	/* Check if we got the expected magnitude values at
 	 * the expected bins
 	 */
drivers/net/wireless/ath/ath9k/common-spectral.h +17 -0
index 303ab470ce34..011d8ab8b974 100644
@@ -145,6 +145,23 @@ static inline u8 spectral_max_index(u8 *bins, int num_bins)
 	return m;
 }
 
+static inline u8 spectral_max_index_ht40(u8 *bins)
+{
+	u8 idx;
+
+	idx = spectral_max_index(bins, SPECTRAL_HT20_40_NUM_BINS);
+
+	/* positive values and zero are starting at the beginning
+	 * of the data field.
+	 */
+	return idx % (SPECTRAL_HT20_40_NUM_BINS / 2);
+}
+
+static inline u8 spectral_max_index_ht20(u8 *bins)
+{
+	return spectral_max_index(bins, SPECTRAL_HT20_NUM_BINS);
+}
+
 /* return the bitmap weight from the all/upper/lower bins */
 static inline u8 spectral_bitmap_weight(u8 *bins)
 {
Signature · 1 line
2.11.0
#5 lore raw

PATCH 4/5 ath9k: FFT magnitude check: don't consider lower 3 data bits

In reply to Simon Wunderlich

There were a lot of Magnitude Mismatch while getting FFT samples on my hardware (Atheros AR9462. I've compared the reported magnitude with the data in the FFT bin, and the FFT bin was less accurate:

[ 5395.193030] ath: phy0: FFT HT20 frame: max mag 0x89,max_mag_idx 28,
,magnitude 0x89 max_exp 0, data[28] = 0x88
[ 5395.194525] ath: phy0: FFT HT20 frame: max mag 0x89,max_mag_idx 28,
,magnitude 0x89 max_exp 0, data[28] = 0x88
[ 5395.196012] ath: phy0: FFT HT20 frame: max mag 0x88,max_mag_idx 28,
,magnitude 0x88 max_exp 0, data[28] = 0x88
[ 5395.197509] ath: phy0: FFT HT20 frame: max mag 0x6C,max_mag_idx 28,
,magnitude 0x6C max_exp 0, data[28] = 0x68
[ 5395.199015] ath: phy0: FFT HT20 frame: max mag 0x78,max_mag_idx 28,
,magnitude 0x78 max_exp 0, data[28] = 0x78
[ 5395.200497] ath: phy0: FFT HT20 frame: max mag 0xA1,max_mag_idx 28,
,magnitude 0xA1 max_exp 0, data[28] = 0xA0
[ 5395.202011] ath: phy0: FFT HT20 frame: max mag 0x91,max_mag_idx 28,
,magnitude 0x91 max_exp 0, data[28] = 0x90
[ 5395.203482] ath: phy0: FFT HT20 frame: max mag 0x89,max_mag_idx 28,
,magnitude 0x89 max_exp 0, data[28] = 0x88
[ 5395.204999] ath: phy0: FFT HT20 frame: max mag 0x27,max_mag_idx 4,
,magnitude 0x27 max_exp 0, data[4] = 0x20
[ 5395.206461] ath: phy0: FFT HT20 frame: max mag 0x41,max_mag_idx 28,
,magnitude 0x41 max_exp 0, data[28] = 0x40
[ 5395.207977] ath: phy0: FFT HT20 frame: max mag 0x51,max_mag_idx 28,
,magnitude 0x51 max_exp 0, data[28] = 0x50
[ 5395.209454] ath: phy0: FFT HT20 frame: max mag 0x53,max_mag_idx 28,
,magnitude 0x53 max_exp 0, data[28] = 0x50
[ 5395.210940] ath: phy0: FFT HT20 frame: max mag 0x40,max_mag_idx 28,
,magnitude 0x40 max_exp 0, data[28] = 0x40
[ 5395.212441] ath: phy0: FFT HT20 frame: max mag 0x59,max_mag_idx 28,
,magnitude 0x59 max_exp 0, data[28] = 0x58
[ 5395.213932] ath: phy0: FFT HT20 frame: max mag 0x53,max_mag_idx 28,
,magnitude 0x53 max_exp 0, data[28] = 0x50
[ 5395.215428] ath: phy0: FFT HT20 frame: max mag 0x7D,max_mag_idx 28,
,magnitude 0x7D max_exp 0, data[28] = 0x78
[ 5395.216910] ath: phy0: FFT HT20 frame: max mag 0x8C,max_mag_idx 28,
,magnitude 0x8C max_exp 0, data[28] = 0x88
[ 5395.218413] ath: phy0: FFT HT20 frame: max mag 0x7B,max_mag_idx 28,
,magnitude 0x7B max_exp 0, data[28] = 0x78
[ 5395.219900] ath: phy0: FFT HT20 frame: max mag 0x43,max_mag_idx 28,

,magnitude 0x43 max_exp 0, data[28] = 0x40

It seems like the lower 3 bits on my hardware are always zeroed, but the magnitude matches otherwise. Therefore, let's not make the magnitude check so strict so we can get those samples released to userspace.

---
 drivers/net/wireless/ath/ath9k/common-spectral.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/net/wireless/ath/ath9k/common-spectral.c +11 -8
index d10e3f29c356..70ddaf6199a0 100644
@@ -71,7 +71,7 @@ ath_cmn_max_idx_verify_ht20_fft(u8 *sample_end, int bytes_read)
 	if (bytes_read < SPECTRAL_HT20_SAMPLE_LEN && max_index < 1)
 		return -1;
 
-	if (sample[max_index] != (max_magnitude >> max_exp))
+	if ((sample[max_index] & 0xf8) != ((max_magnitude >> max_exp) & 0xf8))
 		return -1;
 	else
 		return 0;
@@ -114,8 +114,10 @@ ath_cmn_max_idx_verify_ht20_40_fft(u8 *sample_end, int bytes_read)
 	   ((upper_max_index < 1) || (lower_max_index < 1)))
 		return -1;
 
-	if ((sample[upper_max_index + dc_pos] != (upper_mag >> max_exp)) ||
-	   (sample[lower_max_index] != (lower_mag >> max_exp)))
+	if (((sample[upper_max_index + dc_pos] & 0xf8) !=
+	     ((upper_mag >> max_exp) & 0xf8)) ||
+	    ((sample[lower_max_index] & 0xf8) !=
+	     ((lower_mag >> max_exp) & 0xf8)))
 		return -1;
 	else
 		return 0;
@@ -173,7 +175,8 @@ ath_cmn_process_ht20_fft(struct ath_rx_status *rs,
 					magnitude >> max_exp,
 					max_index);
 
-	if (fft_sample_20.data[max_index] != (magnitude >> max_exp)) {
+	if ((fft_sample_20.data[max_index] & 0xf8) !=
+	    ((magnitude >> max_exp) & 0xf8)) {
 		ath_dbg(common, SPECTRAL_SCAN, "Magnitude mismatch !\n");
 		ret = -1;
 	}
@@ -317,10 +320,10 @@ ath_cmn_process_ht20_40_fft(struct ath_rx_status *rs,
 	/* Check if we got the expected magnitude values at
 	 * the expected bins
 	 */
-	if ((fft_sample_40.data[upper_max_index + dc_pos]
-	    != (upper_mag >> max_exp)) ||
-	   (fft_sample_40.data[lower_max_index]
-	    != (lower_mag >> max_exp))) {
+	if (((fft_sample_40.data[upper_max_index + dc_pos] & 0xf8)
+	    != ((upper_mag >> max_exp) & 0xf8)) ||
+	   ((fft_sample_40.data[lower_max_index] & 0xf8)
+	    != ((lower_mag >> max_exp) & 0xf8))) {
 		ath_dbg(common, SPECTRAL_SCAN, "Magnitude mismatch !\n");
 		ret = -1;
 	}
Signature · 1 line
2.11.0
#6 lore raw

PATCH 5/5 ath9k: fix reporting calculated new FFT upper max

In reply to Simon Wunderlich
---
 drivers/net/wireless/ath/ath9k/common-spectral.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/common-spectral.c +1 -1
index 70ddaf6199a0..6a43d26276e5 100644
@@ -381,7 +381,7 @@ ath_cmn_process_ht20_40_fft(struct ath_rx_status *rs,
 
 		ath_dbg(common, SPECTRAL_SCAN,
 			"Calculated new upper max 0x%X at %i\n",
-			tmp_mag, i);
+			tmp_mag, fft_sample_40.upper_max_index);
 	} else
 	for (i = dc_pos; i < SPECTRAL_HT20_40_NUM_BINS; i++) {
 		if (fft_sample_40.data[i] == (upper_mag >> max_exp))
Signature · 1 line
2.11.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Re: [PATCH 5/5] ath9k: fix reporting calculated new FFT upper max

Quoted 6 lines · CEST Kalle Valo
Quoted 3 lines · Simon Wunderlich

No empty commit logs, please. But I can add that, just tell me what to add.

How about:

Since the debug print code is outside of the loop, it shouldn't use the loop iterator anymore but instead print the found maximum index.

Let me know if you need me to resend or anything else.

Thank you,
Simon

#10 lore raw

Re: [PATCH 5/5] ath9k: fix reporting calculated new FFT upper max

Quoted 6 lines · Simon Wunderlich
Quoted 5 lines · CEST Kalle Valo
Quoted 3 lines · Simon Wunderlich
Quoted 6 lines
Quoted 1 line

No empty commit logs, please. But I can add that, just tell me what to add.

How about:

Since the debug print code is outside of the loop, it shouldn't use the loop iterator anymore but instead print the found maximum index.

Perfect, thanks.

Quoted 1 line

Let me know if you need me to resend or anything else.

No need, I added this to the patch in the (not yet pushed) pending branch.

Signature · 1 line
Kalle Valo
#11 lore raw

Re: [PATCH 5/5] ath9k: fix reporting calculated new FFT upper max

Quoted 15 lines · CEST Kalle Valo
Quoted 6 lines · Simon Wunderlich
Quoted 5 lines · CEST Kalle Valo
Quoted 3 lines · Simon Wunderlich
Quoted 7 lines
Quoted 2 lines

No empty commit logs, please. But I can add that, just tell me what to add.

How about:

Since the debug print code is outside of the loop, it shouldn't use the loop iterator anymore but instead print the found maximum index.

Quoted 6 lines

Perfect, thanks.

Quoted 1 line

Let me know if you need me to resend or anything else.

No need, I added this to the patch in the (not yet pushed) pending branch.

Awesome, thank you!

Cheers,
Simon

#12 lore raw
In reply to Simon Wunderlich

compiles OK, no interfere with normal card operations (IBSS) so it should be merged.

Quoted 26 lines · Simon Wunderlich

During FFT evaluation on an AR9462 adapter, we noticed that there were way less FFT samples received than we would expect. This patchset adds some counters to be able to check for received (and discarded) FFT samples, and fixes a variety of issues I found while debugging.

Cheers,
Simon

Simon Wunderlich (5):
ath9k: add counters for good and errorneous FFT/spectral frames
ath9k: return when short FFT frame was handled
ath9k: fix and simplify FFT max index retrieval
ath9k: FFT magnitude check: don't consider lower 3 data bits
ath9k: fix reporting calculated new FFT upper max

 drivers/net/wireless/ath/ath9k/common-debug.c    |  2 +
 drivers/net/wireless/ath/ath9k/common-debug.h    |  4 ++
 drivers/net/wireless/ath/ath9k/common-spectral.c | 83
+++++++++---------------
 drivers/net/wireless/ath/ath9k/common-spectral.h | 17 +++++
 4 files changed, 55 insertions(+), 51 deletions(-)

--
2.11.0