diff mbox series

[05/11] mt76: mt7915: ethtool group-5 rx stats information

Message ID 20211118164056.2965-5-greearb@candelatech.com (mailing list archive)
State Rejected
Delegated to: Felix Fietkau
Headers show
Series [01/11] mt76: mt7915: add comments about rx descriptor parsing | expand

Commit Message

Ben Greear Nov. 18, 2021, 4:40 p.m. UTC
From: Ben Greear <greearb@candelatech.com>

Add ethtool support for rx-nss, rx-bw, rx-mode stats.
These are only valid when the group-5 rx stats are
enabled.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 23 ++++++++++++++++++-
 drivers/net/wireless/mediatek/mt76/mt76.h     | 10 ++++++++
 .../net/wireless/mediatek/mt76/mt7915/mac.c   | 23 +++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7915/main.c  | 21 +++++++++++++++++
 4 files changed, 76 insertions(+), 1 deletion(-)

Comments

Lorenzo Bianconi Jan. 4, 2022, 10:58 a.m. UTC | #1
> From: Ben Greear <greearb@candelatech.com>
> 

[...]
>  
>  		msta = container_of(status->wcid, struct mt7915_sta, wcid);
> +		stats = &msta->stats;
>  		spin_lock_bh(&dev->sta_poll_lock);
>  		if (list_empty(&msta->poll_list))
>  			list_add_tail(&msta->poll_list, &dev->sta_poll_list);
> @@ -654,8 +656,19 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb)
>  				WARN_ON_ONCE(nss > 4);
>  			}
>  
> +			if (stats) {
> +				if (nss > 3)
> +					stats->rx_nss[3]++;
> +				else
> +					stats->rx_nss[nss - 1]++;
> +
> +				stats->rx_mode[mode]++;
> +			}
> +
>  			switch (FIELD_GET(MT_CRXV_FRAME_MODE, v2)) {
>  			case IEEE80211_STA_RX_BW_20:
> +				if (stats)
> +					stats->rx_bw_20++;
>  				break;
>  			case IEEE80211_STA_RX_BW_40:
>  				if (mode & MT_PHY_TYPE_HE_EXT_SU &&
> @@ -663,14 +676,24 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb)

after mt7916 support, I guess this patch must be rebased

Regards,
Lorenzo

>  					status->bw = RATE_INFO_BW_HE_RU;
>  					status->he_ru =
>  						NL80211_RATE_INFO_HE_RU_ALLOC_106;
> +					if (stats) {
> +						stats->rx_bw_he_ru++;
> +						stats->rx_ru_106++;
> +					}
>  				} else {
>  					status->bw = RATE_INFO_BW_40;
> +					if (stats)
> +						stats->rx_bw_40++;
>  				}
>  				break;
>  			case IEEE80211_STA_RX_BW_80:
>  				status->bw = RATE_INFO_BW_80;
> +				if (stats)
> +					stats->rx_bw_80++;
>  				break;
>  			case IEEE80211_STA_RX_BW_160:
> +				if (stats)
> +					stats->rx_bw_160++;
>  				status->bw = RATE_INFO_BW_160;
>  				break;
>  			default:
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
> index e973b2527b34..bfc81e008f86 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
> @@ -1170,6 +1170,27 @@ static const char mt7915_gstrings_stats[][ETH_GSTRING_LEN] = {
>  	"v_tx_mcs_9",
>  	"v_tx_mcs_10",
>  	"v_tx_mcs_11",
> +
> +	/* per-vif rx counters */
> +	"v_rx_nss1",
> +	"v_rx_nss2",
> +	"v_rx_nss3",
> +	"v_rx_nss4",
> +	"v_rx_mode_cck",
> +	"v_rx_mode_ofdm",
> +	"v_rx_mode_ht",
> +	"v_rx_mode_ht_gf",
> +	"v_rx_mode_vht",
> +	"v_rx_mode_he_su",
> +	"v_rx_mode_he_ext_su",
> +	"v_rx_mode_he_tb",
> +	"v_rx_mode_he_mu",
> +	"v_rx_bw_20",
> +	"v_rx_bw_40",
> +	"v_rx_bw_80",
> +	"v_rx_bw_160",
> +	"v_rx_bw_he_ru",
> +	"v_rx_ru_106",
>  };
>  
>  #define MT7915_SSTATS_LEN ARRAY_SIZE(mt7915_gstrings_stats)
> -- 
> 2.20.1
>
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
index a385c1850c61..577d83f8ae71 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -1512,7 +1512,7 @@  EXPORT_SYMBOL_GPL(mt76_calculate_default_rate);
 void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi,
 			 struct mt76_sta_stats *stats)
 {
-	int i, ei = wi->initial_stat_idx;
+	int i, q, ei = wi->initial_stat_idx;
 	u64 *data = wi->data;
 
 	wi->sta_count++;
@@ -1537,6 +1537,27 @@  void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi,
 	for (i = 0; i < 12; i++)
 		data[ei++] += stats->tx_mcs[i];
 
+	/* rx stats */
+	for (q = 0; q < ARRAY_SIZE(stats->rx_nss); q++)
+		data[ei++] += stats->rx_nss[q];
+
+	data[ei++] += stats->rx_mode[MT_PHY_TYPE_CCK];
+	data[ei++] += stats->rx_mode[MT_PHY_TYPE_OFDM];
+	data[ei++] += stats->rx_mode[MT_PHY_TYPE_HT];
+	data[ei++] += stats->rx_mode[MT_PHY_TYPE_HT_GF];
+	data[ei++] += stats->rx_mode[MT_PHY_TYPE_VHT];
+	data[ei++] += stats->rx_mode[MT_PHY_TYPE_HE_SU];
+	data[ei++] += stats->rx_mode[MT_PHY_TYPE_HE_EXT_SU];
+	data[ei++] += stats->rx_mode[MT_PHY_TYPE_HE_TB];
+	data[ei++] += stats->rx_mode[MT_PHY_TYPE_HE_MU];
+
+	data[ei++] += stats->rx_bw_20;
+	data[ei++] += stats->rx_bw_40;
+	data[ei++] += stats->rx_bw_80;
+	data[ei++] += stats->rx_bw_160;
+	data[ei++] += stats->rx_bw_he_ru;
+	data[ei++] += stats->rx_ru_106;
+
 	wi->worker_stat_count = ei - wi->initial_stat_idx;
 }
 EXPORT_SYMBOL_GPL(mt76_ethtool_worker);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 7bcdfef3c983..9e43ea0077d3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -798,6 +798,16 @@  struct mt76_sta_stats {
 	u64 tx_bw[4];		/* 20, 40, 80, 160 */
 	u64 tx_nss[4];		/* 1, 2, 3, 4 */
 	u64 tx_mcs[16];		/* mcs idx */
+
+	/* This section requires group-5 in rxd to be enabled for 7915. */
+	u32 rx_nss[4]; /* rx-nss histogram */
+	u32 rx_mode[__MT_PHY_TYPE_HE_MAX]; /* rx mode histogram */
+	u32 rx_bw_20;
+	u32 rx_bw_40;
+	u32 rx_bw_80;
+	u32 rx_bw_160;
+	u32 rx_bw_he_ru;
+	u32 rx_ru_106;
 };
 
 struct mt76_ethtool_worker_info {
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
index ddc85464b1e9..2915e7237d96 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
@@ -424,6 +424,7 @@  mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb)
 	u8 qos_ctl = 0;
 	__le16 fc = 0;
 	int i, idx;
+	struct mt76_sta_stats *stats = NULL;
 
 	memset(status, 0, sizeof(*status));
 
@@ -451,6 +452,7 @@  mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb)
 		struct mt7915_sta *msta;
 
 		msta = container_of(status->wcid, struct mt7915_sta, wcid);
+		stats = &msta->stats;
 		spin_lock_bh(&dev->sta_poll_lock);
 		if (list_empty(&msta->poll_list))
 			list_add_tail(&msta->poll_list, &dev->sta_poll_list);
@@ -654,8 +656,19 @@  mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb)
 				WARN_ON_ONCE(nss > 4);
 			}
 
+			if (stats) {
+				if (nss > 3)
+					stats->rx_nss[3]++;
+				else
+					stats->rx_nss[nss - 1]++;
+
+				stats->rx_mode[mode]++;
+			}
+
 			switch (FIELD_GET(MT_CRXV_FRAME_MODE, v2)) {
 			case IEEE80211_STA_RX_BW_20:
+				if (stats)
+					stats->rx_bw_20++;
 				break;
 			case IEEE80211_STA_RX_BW_40:
 				if (mode & MT_PHY_TYPE_HE_EXT_SU &&
@@ -663,14 +676,24 @@  mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb)
 					status->bw = RATE_INFO_BW_HE_RU;
 					status->he_ru =
 						NL80211_RATE_INFO_HE_RU_ALLOC_106;
+					if (stats) {
+						stats->rx_bw_he_ru++;
+						stats->rx_ru_106++;
+					}
 				} else {
 					status->bw = RATE_INFO_BW_40;
+					if (stats)
+						stats->rx_bw_40++;
 				}
 				break;
 			case IEEE80211_STA_RX_BW_80:
 				status->bw = RATE_INFO_BW_80;
+				if (stats)
+					stats->rx_bw_80++;
 				break;
 			case IEEE80211_STA_RX_BW_160:
+				if (stats)
+					stats->rx_bw_160++;
 				status->bw = RATE_INFO_BW_160;
 				break;
 			default:
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index e973b2527b34..bfc81e008f86 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -1170,6 +1170,27 @@  static const char mt7915_gstrings_stats[][ETH_GSTRING_LEN] = {
 	"v_tx_mcs_9",
 	"v_tx_mcs_10",
 	"v_tx_mcs_11",
+
+	/* per-vif rx counters */
+	"v_rx_nss1",
+	"v_rx_nss2",
+	"v_rx_nss3",
+	"v_rx_nss4",
+	"v_rx_mode_cck",
+	"v_rx_mode_ofdm",
+	"v_rx_mode_ht",
+	"v_rx_mode_ht_gf",
+	"v_rx_mode_vht",
+	"v_rx_mode_he_su",
+	"v_rx_mode_he_ext_su",
+	"v_rx_mode_he_tb",
+	"v_rx_mode_he_mu",
+	"v_rx_bw_20",
+	"v_rx_bw_40",
+	"v_rx_bw_80",
+	"v_rx_bw_160",
+	"v_rx_bw_he_ru",
+	"v_rx_ru_106",
 };
 
 #define MT7915_SSTATS_LEN ARRAY_SIZE(mt7915_gstrings_stats)