From: "Nick Kossifidis" <mickflemm@gmail.com>
To: kvalo@codeaurora.org, ath9k-devel@qca.qualcomm.com
Cc: linux-wireless@vger.kernel.org, ath9k-devel@lists.ath9k.org,
adrian.chadd@gmail.com, Nick Kossifidis <mickflemm@gmail.com>
Subject: [PATCH 02/11] ath9k: Fix hanlding of maximum magnitude index
Date: Wed, 29 Apr 2015 23:51:13 +0000 [thread overview]
Message-ID: <1430351482-59418-3-git-send-email-mickflemm@gmail.com> (raw)
In-Reply-To: <1430351482-59418-1-git-send-email-mickflemm@gmail.com>
Maximum magnitude index is a 5bit signed integer,
convert to an 8bit signed integer and then "shift" it so that it can be used
as an array index. Note that the current implementation adds +1 to the index
value (so it can't be used as an array index) and it's only valid for HT20
channels.
Note that the maximum magnitude index is not being used by
the userspace tools that parse FFT samples (they just use
maximum magnitude) so this doesn't break userspace compatibility.
Signed-off-by: Nick Kossifidis <mickflemm@gmail.com>
---
drivers/net/wireless/ath/ath9k/common-spectral.c | 9 +++++---
drivers/net/wireless/ath/ath9k/common-spectral.h | 29 ++++++++++++++++++------
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/drivers/net/wireless/ath/ath9k/common-spectral.c b/drivers/net/wireless/ath/ath9k/common-spectral.c
index 5cee231..8752634 100644
--- a/drivers/net/wireless/ath/ath9k/common-spectral.c
+++ b/drivers/net/wireless/ath/ath9k/common-spectral.c
@@ -160,8 +160,10 @@ int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_h
upper_mag = spectral_max_magnitude(mag_info->upper_bins);
fft_sample_40.lower_max_magnitude = __cpu_to_be16(lower_mag);
fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag);
- lower_max_index = spectral_max_index(mag_info->lower_bins);
- upper_max_index = spectral_max_index(mag_info->upper_bins);
+ lower_max_index = spectral_max_index(mag_info->lower_bins,
+ num_bins);
+ upper_max_index = spectral_max_index(mag_info->upper_bins,
+ num_bins);
fft_sample_40.lower_max_index = lower_max_index;
fft_sample_40.upper_max_index = upper_max_index;
lower_bitmap_w = spectral_bitmap_weight(mag_info->lower_bins);
@@ -189,7 +191,8 @@ int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_h
mag_info = ((struct ath_ht20_mag_info *)radar_info) - 1;
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);
+ max_index = spectral_max_index(mag_info->all_bins,
+ num_bins);
fft_sample_20.max_index = max_index;
bitmap_w = spectral_bitmap_weight(mag_info->all_bins);
fft_sample_20.bitmap_weight = bitmap_w;
diff --git a/drivers/net/wireless/ath/ath9k/common-spectral.h b/drivers/net/wireless/ath/ath9k/common-spectral.h
index d45dc83..75e24da 100644
--- a/drivers/net/wireless/ath/ath9k/common-spectral.h
+++ b/drivers/net/wireless/ath/ath9k/common-spectral.h
@@ -117,17 +117,32 @@ static inline u16 spectral_max_magnitude(u8 *bins)
}
/* return the max magnitude from the all/upper/lower bins */
-static inline u8 spectral_max_index(u8 *bins)
+static inline u8 spectral_max_index(u8 *bins, int num_bins)
{
s8 m = (bins[2] & 0xfc) >> 2;
-
- /* TODO: this still doesn't always report the right values ... */
- if (m > 32)
+ u8 zero_idx = num_bins / 2;
+
+ /* It's a 5 bit signed int, remove its sign and use one's
+ * complement interpretation to add the sign back to the 8
+ * bit int
+ */
+ if (m & 0x20) {
+ m &= ~0x20;
m |= 0xe0;
- else
- m &= ~0xe0;
+ }
+
+ /* Bring the zero point to the beginning
+ * instead of the middle so that we can use
+ * it for array lookup and that we don't deal
+ * with negative values later
+ */
+ m += zero_idx;
+
+ /* Sanity check to make sure index is within bounds */
+ if (m < 0 || m > num_bins - 1)
+ m = 0;
- return m + 29;
+ return m;
}
/* return the bitmap weight from the all/upper/lower bins */
--
2.3.5
next prev parent reply other threads:[~2015-04-29 23:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-29 23:51 [PATCH 00/11] ath9k: Spectral scan updates Nick Kossifidis
2015-04-29 23:51 ` [PATCH 01/11] ath9k: Add a new debug flag for FFT spectral scan Nick Kossifidis
2015-05-09 13:47 ` [01/11] " Kalle Valo
2015-04-29 23:51 ` Nick Kossifidis [this message]
2015-04-29 23:51 ` [PATCH 03/11] ath9k: Move processing of FFT frames to different functions Nick Kossifidis
2015-04-29 23:51 ` [PATCH 04/11] ath9k: Perform integrity checks when processing FFT frames Nick Kossifidis
2015-04-29 23:51 ` [PATCH 05/11] ath9k: Support processing of multiple FFT frames per report Nick Kossifidis
2015-04-29 23:51 ` [PATCH 06/11] ath9k: Skip malformed frames on normal FFT report Nick Kossifidis
2015-04-29 23:51 ` [PATCH 07/11] ath9k: No need for that extra memcpy Nick Kossifidis
2015-04-29 23:51 ` [PATCH 8/11] ath9k: Skip FFT reports if we are out of output buffers Nick Kossifidis
2015-04-29 23:51 ` [PATCH 9/11] ath9k: No need for that extra memset Nick Kossifidis
2015-04-29 23:51 ` [PATCH 10/11] ath9k: Mix the received FFT bins to the random pool Nick Kossifidis
2015-04-29 23:51 ` [PATCH 11/11] ath9k: Enable short repeat by default on ath9k_htc Nick Kossifidis
2015-05-01 12:46 ` [PATCH 00/11] ath9k: Spectral scan updates Bob Copeland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1430351482-59418-3-git-send-email-mickflemm@gmail.com \
--to=mickflemm@gmail.com \
--cc=adrian.chadd@gmail.com \
--cc=ath9k-devel@lists.ath9k.org \
--cc=ath9k-devel@qca.qualcomm.com \
--cc=kvalo@codeaurora.org \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).