2022-01-15 08:14:04

by Bryan O'Donoghue

[permalink] [raw]
Subject: [PATCH v3 0/4] wcn36xx: Add spectrum survey reporting

V3:
- Fixes an indexing bug in get_survey()

We use an array to track snr and rssi. This array is organised so that
the index value passed in get_survey() references the array directly.

We also want to know the index into the frequency band tables which are
divided into two parts for 2 GHz and 5 GHz.

The previous patch modified the index to dereference the band instead of
taking a copy of the index and modifying the copy to reference the band
table.

In other words the same index couldn't be used for both the array and the
band index.

Fixes by way of separating the two indices into idx and band_idx.

V2:
- Fixes typo "ret -= ENOMEM" => "ret = -ENOMEM" - kernel test bot
- Makes get_survey() static - kernel test bot
- Ignores riscv warnings since none apply to code in this patch - bod

V1:
This series enables get_survey() on wcn36xx. Tested with wcn3620 and
wcn3680b.

wcn36xx reports RSSI and SNR in the buffer descriptor of each delivered
frame wcn36xx -> host. Thus far we have only extracted RSSI but, extracting
the SNR lets us also report the noise-floor.

Adding in some background tracking of the current tuned channel lets us
flag which channel is currently in use when running "iw wlan0 survey dump"

For both wcn3620 and wcn3680b I have verified both the STA and AP's view of
RSSI and noise.

Example wcn3620:
AP Asus RT-AX88U
SSID: "linaro-test"
noise: -78 dBm Channel: 8
BSSID: 04:D4:C4:AA:BB:CC

MAC RSSI
02:00:16:qq:xx:yy -35dBm

STA
root@linaro-developer:~# iw wlan0 link
Connected to 04:d4:c4:aa:bb:cc (on wlan0)
SSID: linaro-test
freq: 2447
RX: 768377 bytes (4250 packets)
TX: 8136 bytes (97 packets)
signal: -37 dBm

root@linaro-developer:~# iw wlan0 survey dump
Survey data from wlan0
frequency: 2412 MHz
Survey data from wlan0
frequency: 2417 MHz
noise: -12 dBm
Survey data from wlan0
frequency: 2422 MHz
noise: -82 dBm
Survey data from wlan0
frequency: 2427 MHz
noise: -76 dBm
Survey data from wlan0
frequency: 2432 MHz
noise: -78 dBm
Survey data from wlan0
frequency: 2437 MHz
noise: -100 dBm
Survey data from wlan0
frequency: 2442 MHz
noise: -41 dBm
Survey data from wlan0
frequency: 2447 MHz [in use]
noise: -75 dBm

Example wcn3680b:
AP Asus RT-AX88U:
SSID: "linaro-test"
noise: -80 dBm Channel: 60/160
BSSID: 04:D4:C4:DD:EE:FF

MAC RSSI
E2:C0:10:YY:XX:QQ -31dBm

STA:
root@linaro-developer:~# iw wlan0 link
Connected to 04:d4:c4:dd:ee:ff (on wlan0)
SSID: linaro-test
freq: 5300
RX: 5999294 bytes (32764 packets)
TX: 35443 bytes (493 packets)
signal: -27 dBm
rx bitrate: 433.3 MBit/s VHT-MCS 9 80MHz short GI VHT-NSS 1
tx bitrate: 6.0 MBit/s

bss flags: short-slot-time
dtim period: 3
beacon int: 100

root@linaro-developer:~# iw wlan0 survey dump
Survey data from wlan0
frequency: 2412 MHz
noise: -63 dBm
Survey data from wlan0
frequency: 2417 MHz
noise: -57 dBm
Survey data from wlan0
frequency: 2422 MHz
noise: -74 dBm
Survey data from wlan0
frequency: 2427 MHz
noise: -90 dBm
Survey data from wlan0
frequency: 2432 MHz
noise: -72 dBm
Survey data from wlan0
frequency: 2437 MHz
noise: -33 dBm
Survey data from wlan0
frequency: 2442 MHz
noise: -72 dBm
Survey data from wlan0
frequency: 2447 MHz
noise: -68 dBm
Survey data from wlan0
frequency: 2452 MHz
noise: -33 dBm
Survey data from wlan0
frequency: 2457 MHz
noise: -33 dBm
Survey data from wlan0
frequency: 2462 MHz
noise: -36 dBm
Survey data from wlan0
frequency: 2467 MHz
noise: -68 dBm
Survey data from wlan0
frequency: 2472 MHz
noise: -34 dBm
Survey data from wlan0
frequency: 5180 MHz
noise: -63 dBm
Survey data from wlan0
frequency: 5200 MHz
noise: -57 dBm
Survey data from wlan0
frequency: 5220 MHz
noise: -74 dBm
Survey data from wlan0
frequency: 5240 MHz
noise: -90 dBm
Survey data from wlan0
frequency: 5260 MHz
noise: -72 dBm
Survey data from wlan0
frequency: 5280 MHz
noise: -33 dBm
Survey data from wlan0
frequency: 5300 MHz [in use]
noise: -72 dBm

Bryan O'Donoghue (4):
wcn36xx: Implement get_snr()
wcn36xx: Track the band and channel we are tuned to
wcn36xx: Track SNR and RSSI for each RX frame
wcn36xx: Add SNR reporting via get_survey()

drivers/net/wireless/ath/wcn36xx/main.c | 83 ++++++++++++++++++++++
drivers/net/wireless/ath/wcn36xx/txrx.c | 36 ++++++++++
drivers/net/wireless/ath/wcn36xx/wcn36xx.h | 13 ++++
3 files changed, 132 insertions(+)

--
2.33.0


2022-01-15 08:14:07

by Bryan O'Donoghue

[permalink] [raw]
Subject: [PATCH v3 1/4] wcn36xx: Implement get_snr()

The wcn36xx BD phy descriptor returns both Received Signal Strength
Information (RSSI) and Signal To Noise Ratio (SNR) with each delivered BD.

The macro to extract this data is a simple-one liner, easily imported from
downstream. This data will be useful to us when implementing
mac80211-ops->get_survey().

Signed-off-by: Bryan O'Donoghue <[email protected]>
---
drivers/net/wireless/ath/wcn36xx/txrx.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/net/wireless/ath/wcn36xx/txrx.c b/drivers/net/wireless/ath/wcn36xx/txrx.c
index ed4e8f201f510..a3eb476c2cbc4 100644
--- a/drivers/net/wireless/ath/wcn36xx/txrx.c
+++ b/drivers/net/wireless/ath/wcn36xx/txrx.c
@@ -23,6 +23,11 @@ static inline int get_rssi0(struct wcn36xx_rx_bd *bd)
return 100 - ((bd->phy_stat0 >> 24) & 0xff);
}

+static inline int get_snr(struct wcn36xx_rx_bd *bd)
+{
+ return ((bd->phy_stat1 >> 24) & 0xff);
+}
+
struct wcn36xx_rate {
u16 bitrate;
u16 mcs_or_legacy_index;
--
2.33.0

2022-01-15 08:14:56

by Bryan O'Donoghue

[permalink] [raw]
Subject: [PATCH v3 2/4] wcn36xx: Track the band and channel we are tuned to

Track the band and channel we are currently tuned to by way of pointers to
the standard structures that describe them both embedded within the driver.

Tracking of the pair makes it much easier when implementing
ieee80211_ops->get_survey to return quickly captured metrics for the
currently tuned channel.

Signed-off-by: Bryan O'Donoghue <[email protected]>
---
drivers/net/wireless/ath/wcn36xx/main.c | 27 ++++++++++++++++++++++
drivers/net/wireless/ath/wcn36xx/wcn36xx.h | 3 +++
2 files changed, 30 insertions(+)

diff --git a/drivers/net/wireless/ath/wcn36xx/main.c b/drivers/net/wireless/ath/wcn36xx/main.c
index ec355807f5817..d2b99f6112f6b 100644
--- a/drivers/net/wireless/ath/wcn36xx/main.c
+++ b/drivers/net/wireless/ath/wcn36xx/main.c
@@ -392,11 +392,38 @@ static void wcn36xx_change_opchannel(struct wcn36xx *wcn, int ch)
{
struct ieee80211_vif *vif = NULL;
struct wcn36xx_vif *tmp;
+ struct ieee80211_supported_band *band;
+ struct ieee80211_channel *channel;
+ int i, j;
+
+ for (i = 0; i < ARRAY_SIZE(wcn->hw->wiphy->bands); i++) {
+ band = wcn->hw->wiphy->bands[i];
+ if (!band)
+ break;
+ for (j = 0; j < band->n_channels; j++) {
+ if (HW_VALUE_CHANNEL(band->channels[j].hw_value) == ch) {
+ channel = &band->channels[j];
+ break;
+ }
+ }
+ if (channel)
+ break;
+ }
+
+ if (!channel) {
+ wcn36xx_err("Cannot tune to channel %d\n", ch);
+ return;
+ }
+
+ wcn->band = band;
+ wcn->channel = channel;

list_for_each_entry(tmp, &wcn->vif_list, list) {
vif = wcn36xx_priv_to_vif(tmp);
wcn36xx_smd_switch_channel(wcn, vif, ch);
}
+
+ return;
}

static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
diff --git a/drivers/net/wireless/ath/wcn36xx/wcn36xx.h b/drivers/net/wireless/ath/wcn36xx/wcn36xx.h
index fbd0558c2c196..dd2570e468084 100644
--- a/drivers/net/wireless/ath/wcn36xx/wcn36xx.h
+++ b/drivers/net/wireless/ath/wcn36xx/wcn36xx.h
@@ -281,6 +281,9 @@ struct wcn36xx {
/* Debug file system entry */
struct wcn36xx_dfs_entry dfs;
#endif /* CONFIG_WCN36XX_DEBUGFS */
+
+ struct ieee80211_supported_band *band;
+ struct ieee80211_channel *channel;
};

static inline bool wcn36xx_is_fw_version(struct wcn36xx *wcn,
--
2.33.0

2022-01-15 08:15:04

by Bryan O'Donoghue

[permalink] [raw]
Subject: [PATCH v3 3/4] wcn36xx: Track SNR and RSSI for each RX frame

The BDs for each RX frame contain both the RSSI and SNR for the received
frame. If we track and store this information it can be useful to us in
get_survey() and potentially elsewhere.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Bryan O'Donoghue <[email protected]>
---
drivers/net/wireless/ath/wcn36xx/main.c | 12 +++++++++
drivers/net/wireless/ath/wcn36xx/txrx.c | 31 ++++++++++++++++++++++
drivers/net/wireless/ath/wcn36xx/wcn36xx.h | 10 +++++++
3 files changed, 53 insertions(+)

diff --git a/drivers/net/wireless/ath/wcn36xx/main.c b/drivers/net/wireless/ath/wcn36xx/main.c
index d2b99f6112f6b..0e1f3dc4f69d4 100644
--- a/drivers/net/wireless/ath/wcn36xx/main.c
+++ b/drivers/net/wireless/ath/wcn36xx/main.c
@@ -331,6 +331,7 @@ static int wcn36xx_start(struct ieee80211_hw *hw)

INIT_LIST_HEAD(&wcn->vif_list);
spin_lock_init(&wcn->dxe_lock);
+ spin_lock_init(&wcn->survey_lock);

return 0;

@@ -394,6 +395,7 @@ static void wcn36xx_change_opchannel(struct wcn36xx *wcn, int ch)
struct wcn36xx_vif *tmp;
struct ieee80211_supported_band *band;
struct ieee80211_channel *channel;
+ unsigned long flags;
int i, j;

for (i = 0; i < ARRAY_SIZE(wcn->hw->wiphy->bands); i++) {
@@ -415,8 +417,10 @@ static void wcn36xx_change_opchannel(struct wcn36xx *wcn, int ch)
return;
}

+ spin_lock_irqsave(&wcn->survey_lock, flags);
wcn->band = band;
wcn->channel = channel;
+ spin_unlock_irqrestore(&wcn->survey_lock, flags);

list_for_each_entry(tmp, &wcn->vif_list, list) {
vif = wcn36xx_priv_to_vif(tmp);
@@ -1562,6 +1566,7 @@ static int wcn36xx_probe(struct platform_device *pdev)
void *wcnss;
int ret;
const u8 *addr;
+ int n_channels;

wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");

@@ -1589,6 +1594,13 @@ static int wcn36xx_probe(struct platform_device *pdev)
goto out_wq;
}

+ n_channels = wcn_band_2ghz.n_channels + wcn_band_5ghz.n_channels;
+ wcn->chan_survey = devm_kmalloc(wcn->dev, n_channels, GFP_KERNEL);
+ if (!wcn->chan_survey) {
+ ret = -ENOMEM;
+ goto out_wq;
+ }
+
ret = dma_set_mask_and_coherent(wcn->dev, DMA_BIT_MASK(32));
if (ret < 0) {
wcn36xx_err("failed to set DMA mask: %d\n", ret);
diff --git a/drivers/net/wireless/ath/wcn36xx/txrx.c b/drivers/net/wireless/ath/wcn36xx/txrx.c
index a3eb476c2cbc4..8e8f014225dba 100644
--- a/drivers/net/wireless/ath/wcn36xx/txrx.c
+++ b/drivers/net/wireless/ath/wcn36xx/txrx.c
@@ -271,6 +271,34 @@ static void __skb_queue_purge_irq(struct sk_buff_head *list)
dev_kfree_skb_irq(skb);
}

+static void wcn36xx_update_survey(struct wcn36xx *wcn, int rssi, int snr,
+ int band, int freq)
+{
+ static struct ieee80211_channel *channel;
+ struct ieee80211_supported_band *sband;
+ int idx;
+ int i;
+
+ idx = 0;
+ if (band == NL80211_BAND_5GHZ)
+ idx = wcn->hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels;
+
+ sband = wcn->hw->wiphy->bands[band];
+ channel = sband->channels;
+
+ for (i = 0; i < sband->n_channels; i++, channel++) {
+ if (channel->center_freq == freq) {
+ idx += i;
+ break;
+ }
+ }
+
+ spin_lock(&wcn->survey_lock);
+ wcn->chan_survey[idx].rssi = rssi;
+ wcn->chan_survey[idx].snr = snr;
+ spin_unlock(&wcn->survey_lock);
+}
+
int wcn36xx_rx_skb(struct wcn36xx *wcn, struct sk_buff *skb)
{
struct ieee80211_rx_status status;
@@ -348,6 +376,9 @@ int wcn36xx_rx_skb(struct wcn36xx *wcn, struct sk_buff *skb)
status.freq = WCN36XX_CENTER_FREQ(wcn);
}

+ wcn36xx_update_survey(wcn, status.signal, get_snr(bd),
+ status.band, status.freq);
+
if (bd->rate_id < ARRAY_SIZE(wcn36xx_rate_table)) {
rate = &wcn36xx_rate_table[bd->rate_id];
status.encoding = rate->encoding;
diff --git a/drivers/net/wireless/ath/wcn36xx/wcn36xx.h b/drivers/net/wireless/ath/wcn36xx/wcn36xx.h
index dd2570e468084..81eaa74601d0f 100644
--- a/drivers/net/wireless/ath/wcn36xx/wcn36xx.h
+++ b/drivers/net/wireless/ath/wcn36xx/wcn36xx.h
@@ -194,7 +194,14 @@ struct wcn36xx_sta {
enum wcn36xx_ampdu_state ampdu_state[16];
int non_agg_frame_ct;
};
+
struct wcn36xx_dxe_ch;
+
+struct wcn36xx_chan_survey {
+ s8 rssi;
+ u8 snr;
+};
+
struct wcn36xx {
struct ieee80211_hw *hw;
struct device *dev;
@@ -284,6 +291,9 @@ struct wcn36xx {

struct ieee80211_supported_band *band;
struct ieee80211_channel *channel;
+
+ spinlock_t survey_lock; /* protects chan_survey */
+ struct wcn36xx_chan_survey *chan_survey;
};

static inline bool wcn36xx_is_fw_version(struct wcn36xx *wcn,
--
2.33.0

2022-01-15 08:15:04

by Bryan O'Donoghue

[permalink] [raw]
Subject: [PATCH v3 4/4] wcn36xx: Add SNR reporting via get_survey()

Add support for get_survey() reporting. Current channel and noise-floor are
reported, other parameters such as scan, busy, TX and RX time are not
immediately available.

Noise is a useful metric to report, so bring it out now.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Bryan O'Donoghue <[email protected]>
---
drivers/net/wireless/ath/wcn36xx/main.c | 44 +++++++++++++++++++++++++
1 file changed, 44 insertions(+)

diff --git a/drivers/net/wireless/ath/wcn36xx/main.c b/drivers/net/wireless/ath/wcn36xx/main.c
index 0e1f3dc4f69d4..af2b6f7c34137 100644
--- a/drivers/net/wireless/ath/wcn36xx/main.c
+++ b/drivers/net/wireless/ath/wcn36xx/main.c
@@ -1357,6 +1357,49 @@ static void wcn36xx_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
}
}

+static int wcn36xx_get_survey(struct ieee80211_hw *hw, int idx,
+ struct survey_info *survey)
+{
+ struct wcn36xx *wcn = hw->priv;
+ struct ieee80211_supported_band *sband;
+ struct wcn36xx_chan_survey *chan_survey;
+ int band_idx;
+ unsigned long flags;
+
+ sband = wcn->hw->wiphy->bands[NL80211_BAND_2GHZ];
+ band_idx = idx;
+ if (band_idx >= sband->n_channels) {
+ band_idx -= sband->n_channels;
+ sband = wcn->hw->wiphy->bands[NL80211_BAND_5GHZ];
+ }
+
+ if (!sband || band_idx >= sband->n_channels)
+ return -ENOENT;
+
+ spin_lock_irqsave(&wcn->survey_lock, flags);
+
+ chan_survey = &wcn->chan_survey[idx];
+ survey->channel = &sband->channels[band_idx];
+ survey->noise = chan_survey->rssi - chan_survey->snr;
+ survey->filled = 0;
+
+ if (chan_survey->rssi > -100 && chan_survey->rssi < 0)
+ survey->filled |= SURVEY_INFO_NOISE_DBM;
+
+ if (survey->channel == wcn->channel)
+ survey->filled |= SURVEY_INFO_IN_USE;
+
+ spin_unlock_irqrestore(&wcn->survey_lock, flags);
+
+ wcn36xx_dbg(WCN36XX_DBG_MAC,
+ "ch %d rssi %d snr %d noise %d filled %x freq %d\n",
+ HW_VALUE_CHANNEL(survey->channel->hw_value),
+ chan_survey->rssi, chan_survey->snr, survey->noise,
+ survey->filled, survey->channel->center_freq);
+
+ return 0;
+}
+
static const struct ieee80211_ops wcn36xx_ops = {
.start = wcn36xx_start,
.stop = wcn36xx_stop,
@@ -1385,6 +1428,7 @@ static const struct ieee80211_ops wcn36xx_ops = {
.ipv6_addr_change = wcn36xx_ipv6_addr_change,
#endif
.flush = wcn36xx_flush,
+ .get_survey = wcn36xx_get_survey,

CFG80211_TESTMODE_CMD(wcn36xx_tm_cmd)
};
--
2.33.0

2022-01-16 06:48:17

by Loic Poulain

[permalink] [raw]
Subject: Re: [PATCH v3 1/4] wcn36xx: Implement get_snr()

On Sat, 15 Jan 2022 at 01:14, Bryan O'Donoghue
<[email protected]> wrote:
>
> The wcn36xx BD phy descriptor returns both Received Signal Strength
> Information (RSSI) and Signal To Noise Ratio (SNR) with each delivered BD.
>
> The macro to extract this data is a simple-one liner, easily imported from
> downstream. This data will be useful to us when implementing
> mac80211-ops->get_survey().
>
> Signed-off-by: Bryan O'Donoghue <[email protected]>
> ---

Reviewed-by: Loic Poulain <[email protected]>

2022-01-18 02:23:27

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v3 1/4] wcn36xx: Implement get_snr()

Bryan O'Donoghue <[email protected]> writes:

> The wcn36xx BD phy descriptor returns both Received Signal Strength
> Information (RSSI) and Signal To Noise Ratio (SNR) with each delivered BD.
>
> The macro to extract this data is a simple-one liner, easily imported from
> downstream. This data will be useful to us when implementing
> mac80211-ops->get_survey().

I assume with downstream you mean the prima driver, I'll change that.

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

2022-01-21 19:00:53

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v3 1/4] wcn36xx: Implement get_snr()

Bryan O'Donoghue <[email protected]> wrote:

> The wcn36xx BD phy descriptor returns both Received Signal Strength
> Information (RSSI) and Signal To Noise Ratio (SNR) with each delivered BD.
>
> The macro to extract this data is a simple-one liner, easily imported from
> prima driver. This data will be useful to us when implementing
> mac80211-ops->get_survey().
>
> Signed-off-by: Bryan O'Donoghue <[email protected]>
> Reviewed-by: Loic Poulain <[email protected]>
> Signed-off-by: Kalle Valo <[email protected]>

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

039d5d4db4bc wcn36xx: Implement get_snr()
d6f2746691cb wcn36xx: Track the band and channel we are tuned to
29696e0aa413 wcn36xx: Track SNR and RSSI for each RX frame
51395cf204f2 wcn36xx: Add SNR reporting via get_survey()

--
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches