diff mbox series

[v3,1/8] mt76 - mt7915: Add ethtool stats support.

Message ID 20210722202504.6180-1-greearb@candelatech.com
State New
Headers show
Series [v3,1/8] mt76 - mt7915: Add ethtool stats support. | expand

Commit Message

Ben Greear July 22, 2021, 8:24 p.m. UTC
From: Ben Greear <greearb@candelatech.com>

This exposes some tx-path stats to the ethtool API, so that
ethtool -S wlanX provides some more useful info.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
v3:  Clean up checkpatch warnings.

 .../wireless/mediatek/mt76/mt7915/debugfs.c   | 135 ++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7915/main.c  |   3 +
 .../wireless/mediatek/mt76/mt7915/mt7915.h    |  12 ++
 3 files changed, 150 insertions(+)

Comments

Lorenzo Bianconi July 22, 2021, 9:48 p.m. UTC | #1
On Jul 22, greearb@candelatech.com wrote:
> From: Ben Greear <greearb@candelatech.com>
> 
> These counters are clear-on-read, so we need to accumulate
> them in the update_stats poll logic, and read the accumulated
> values instead of directly doing register reads when reporting
> to debugfs and ethtool stats.
> 
> Signed-off-by: Ben Greear <greearb@candelatech.com>
> ---
>  .../wireless/mediatek/mt76/mt7915/debugfs.c   | 33 ++++++++-----------
>  .../net/wireless/mediatek/mt76/mt7915/mac.c   | 13 +++++++-
>  .../wireless/mediatek/mt76/mt7915/mt7915.h    |  4 +++
>  3 files changed, 29 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
> index ad400ddf36c3..759899c44583 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
> @@ -152,6 +152,7 @@ mt7915_txbf_stat_read_phy(struct mt7915_phy *phy, struct seq_file *s)
>  		"BW20", "BW40", "BW80", "BW160"
>  	};
>  	int cnt;
> +	struct mib_stats *mib = &phy->mib;
>  
>  	if (!phy)
>  		return;
> @@ -187,15 +188,13 @@ mt7915_txbf_stat_read_phy(struct mt7915_phy *phy, struct seq_file *s)
>  		   FIELD_GET(MT_ETBF_TX_FB_TRI, cnt));
>  
>  	/* Tx SU & MU counters */
> -	cnt = mt76_rr(dev, MT_MIB_SDR34(ext_phy));
> -	seq_printf(s, "Tx multi-user Beamforming counts: %ld\n",
> -		   FIELD_GET(MT_MIB_MU_BF_TX_CNT, cnt));
> -	cnt = mt76_rr(dev, MT_MIB_DR8(ext_phy));
> -	seq_printf(s, "Tx multi-user MPDU counts: %d\n", cnt);
> -	cnt = mt76_rr(dev, MT_MIB_DR9(ext_phy));
> -	seq_printf(s, "Tx multi-user successful MPDU counts: %d\n", cnt);
> -	cnt = mt76_rr(dev, MT_MIB_DR11(ext_phy));
> -	seq_printf(s, "Tx single-user successful MPDU counts: %d\n", cnt);
> +	seq_printf(s, "Tx multi-user Beamforming counts: %d\n",
> +		   mib->tx_bf_cnt);
> +	seq_printf(s, "Tx multi-user MPDU counts: %d\n", mib->tx_mu_mpdu_cnt);
> +	seq_printf(s, "Tx multi-user successful MPDU counts: %d\n",
> +		   mib->tx_mu_successful_mpdu_cnt);
> +	seq_printf(s, "Tx single-user successful MPDU counts: %d\n",
> +		   mib->tx_su_successful_mpdu_cnt);
>  
>  	seq_puts(s, "\n");
>  }
> @@ -488,6 +487,7 @@ void mt7915_debug_get_et_stats(struct ieee80211_hw *hw,
>  	struct mt7915_sta *msta;
>  	struct mt7915_sta_stats *mstats;
>  	bool found_sta = false;
> +	struct mib_stats *mib = &phy->mib;
>  
>  	/* See mt7915_ampdu_stat_read_phy, etc */
>  	bool ext_phy = phy != &dev->phy;
> @@ -527,17 +527,10 @@ void mt7915_debug_get_et_stats(struct ieee80211_hw *hw,
>  	data[ei++] = FIELD_GET(MT_ETBF_TX_FB_TRI, cnt);
>  
>  	/* Tx SU & MU counters */
> -	cnt = mt76_rr(dev, MT_MIB_SDR34(ext_phy));
> -	data[ei++] = FIELD_GET(MT_MIB_MU_BF_TX_CNT, cnt);
> -
> -	cnt = mt76_rr(dev, MT_MIB_DR8(ext_phy));
> -	data[ei++] = cnt;
> -
> -	cnt = mt76_rr(dev, MT_MIB_DR9(ext_phy));
> -	data[ei++] = cnt; /* MU MPDU SUccessful */
> -
> -	cnt = mt76_rr(dev, MT_MIB_DR11(ext_phy));
> -	data[ei++] = cnt; /* SU MPDU successful */
> +	data[ei++] = mib->tx_bf_cnt;
> +	data[ei++] = mib->tx_mu_mpdu_cnt;
> +	data[ei++] = mib->tx_mu_successful_mpdu_cnt;
> +	data[ei++] = mib->tx_su_successful_mpdu_cnt;
>  
>  	/* TODO:  External phy too?? */
>  
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
> index 3a10e14fbd50..23540ba5da97 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
> @@ -1880,10 +1880,21 @@ mt7915_mac_update_stats(struct mt7915_phy *phy)
>  	struct mt7915_dev *dev = phy->dev;
>  	struct mib_stats *mib = &phy->mib;
>  	bool ext_phy = phy != &dev->phy;
> -	int i, aggr0, aggr1;
> +	int i, aggr0, aggr1, cnt;
>  
>  	mib->fcs_err_cnt += mt76_get_field(dev, MT_MIB_SDR3(ext_phy),
>  					   MT_MIB_SDR3_FCS_ERR_MASK);
> +	cnt = mt76_rr(dev, MT_MIB_SDR34(ext_phy));
> +	mib->tx_bf_cnt += FIELD_GET(MT_MIB_MU_BF_TX_CNT, cnt);
> +
> +	cnt = mt76_rr(dev, MT_MIB_DR8(ext_phy));
> +	mib->tx_mu_mpdu_cnt += cnt;
> +
> +	cnt = mt76_rr(dev, MT_MIB_DR9(ext_phy));
> +	mib->tx_mu_successful_mpdu_cnt += cnt;
> +
> +	cnt = mt76_rr(dev, MT_MIB_DR11(ext_phy));
> +	mib->tx_su_successful_mpdu_cnt += cnt;
>  
>  	aggr0 = ext_phy ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0;
>  	for (i = 0, aggr1 = aggr0 + 4; i < 4; i++) {
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
> index ff944d1cf527..c5d0f2331b6f 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
> @@ -116,6 +116,10 @@ struct mib_stats {
>  	u32 rts_cnt;
>  	u32 rts_retries_cnt;
>  	u32 ba_miss_cnt;
> +	u32 tx_bf_cnt;
> +	u32 tx_mu_mpdu_cnt;
> +	u32 tx_mu_successful_mpdu_cnt;
> +	u32 tx_su_successful_mpdu_cnt;

nit:
s/tx_mu_successful*/tx_mu_acked*/

>  	/* Add more stats here, updated from mac_update_stats */
>  };
>  
> -- 
> 2.20.1
>
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
index 1a48b09d0cb7..469028d641c7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
@@ -382,4 +382,139 @@  void mt7915_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 {
 	debugfs_create_file("fixed_rate", 0600, dir, sta, &fops_fixed_rate);
 }
+
 #endif
+
+static const char mt7915_gstrings_stats[][ETH_GSTRING_LEN] = {
+	"tx_ampdu_len:0-1",
+	"tx_ampdu_len:2-10",
+	"tx_ampdu_len:11-19",
+	"tx_ampdu_len:20-28",
+	"tx_ampdu_len:29-37",
+	"tx_ampdu_len:38-46",
+	"tx_ampdu_len:47-55",
+	"tx_ampdu_len:56-79",
+	"tx_ampdu_len:80-103",
+	"tx_ampdu_len:104-127",
+	"tx_ampdu_len:128-151",
+	"tx_ampdu_len:152-175",
+	"tx_ampdu_len:176-199",
+	"tx_ampdu_len:200-223",
+	"tx_ampdu_len:224-247",
+	"ba_miss_count",
+	"tx_beamformer_ppdu_iBF",
+	"tx_beamformer_ppdu_eBF",
+	"tx_beamformer_rx_feedback_all",
+	"tx_beamformer_rx_feedback_he",
+	"tx_beamformer_rx_feedback_vht",
+	"tx_beamformer_rx_feedback_ht",
+	"tx_beamformer_rx_feedback_bw", /* zero based idx: 20, 40, 80, 160 */
+	"tx_beamformer_rx_feedback_nc",
+	"tx_beamformer_rx_feedback_nr",
+	"tx_beamformee_ok_feedback_pkts",
+	"tx_beamformee_feedback_trig",
+	"tx_mu_beamforming",
+	"tx_mu_mpdu",
+	"tx_mu_successful_mpdu",
+	"tx_su_successful_mpdu",
+	"tx_msdu_pack_1",
+	"tx_msdu_pack_2",
+	"tx_msdu_pack_3",
+	"tx_msdu_pack_4",
+	"tx_msdu_pack_5",
+	"tx_msdu_pack_6",
+	"tx_msdu_pack_7",
+	"tx_msdu_pack_8",
+};
+
+#define MT7915_SSTATS_LEN ARRAY_SIZE(mt7915_gstrings_stats)
+
+/* Ethtool related API */
+void mt7915_debug_get_et_strings(struct ieee80211_hw *hw,
+				 struct ieee80211_vif *vif,
+				 u32 sset, u8 *data)
+{
+	if (sset == ETH_SS_STATS)
+		memcpy(data, *mt7915_gstrings_stats,
+		       sizeof(mt7915_gstrings_stats));
+}
+
+int mt7915_debug_get_et_sset_count(struct ieee80211_hw *hw,
+				   struct ieee80211_vif *vif, int sset)
+{
+	if (sset == ETH_SS_STATS)
+		return MT7915_SSTATS_LEN;
+
+	return 0;
+}
+
+void mt7915_debug_get_et_stats(struct ieee80211_hw *hw,
+			       struct ieee80211_vif *vif,
+			       struct ethtool_stats *stats, u64 *data)
+{
+	struct mt7915_dev *dev = mt7915_hw_dev(hw);
+	struct mt7915_phy *phy = mt7915_hw_phy(hw);
+
+	/* TODO:  These are mostly dev-wide stats at this point.
+	 *  Get some per-vif stats?
+	 */
+
+	/* See mt7915_ampdu_stat_read_phy, etc */
+	bool ext_phy = phy != &dev->phy;
+	int i, n, cnt;
+	int ei = 0;
+
+	if (!phy)
+		return;
+
+	/* Tx ampdu stat */
+	n = ext_phy ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0;
+	for (i = 0; i < 15 /*ARRAY_SIZE(bound)*/; i++)
+		data[ei++] = dev->mt76.aggr_stats[i + n];
+
+	data[ei++] = phy->mib.ba_miss_cnt;
+
+	/* Tx Beamformer monitor */
+	cnt = mt76_rr(dev, MT_ETBF_TX_APP_CNT(ext_phy));
+	data[ei++] = FIELD_GET(MT_ETBF_TX_IBF_CNT, cnt);
+	data[ei++] = FIELD_GET(MT_ETBF_TX_EBF_CNT, cnt);
+
+	/* Tx Beamformer Rx feedback monitor */
+	cnt = mt76_rr(dev, MT_ETBF_RX_FB_CNT(ext_phy));
+	data[ei++] = FIELD_GET(MT_ETBF_RX_FB_ALL, cnt);
+	data[ei++] = FIELD_GET(MT_ETBF_RX_FB_HE, cnt);
+	data[ei++] = FIELD_GET(MT_ETBF_RX_FB_VHT, cnt);
+	data[ei++] = FIELD_GET(MT_ETBF_RX_FB_HT, cnt);
+
+	cnt = mt76_rr(dev, MT_ETBF_RX_FB_CONT(ext_phy));
+	data[ei++] = FIELD_GET(MT_ETBF_RX_FB_BW, cnt);
+	data[ei++] = FIELD_GET(MT_ETBF_RX_FB_NC, cnt);
+	data[ei++] = FIELD_GET(MT_ETBF_RX_FB_NR, cnt);
+
+	/* Tx Beamformee Rx NDPA & Tx feedback report */
+	cnt = mt76_rr(dev, MT_ETBF_TX_NDP_BFRP(ext_phy));
+	data[ei++] = FIELD_GET(MT_ETBF_TX_FB_CPL, cnt);
+	data[ei++] = FIELD_GET(MT_ETBF_TX_FB_TRI, cnt);
+
+	/* Tx SU & MU counters */
+	cnt = mt76_rr(dev, MT_MIB_SDR34(ext_phy));
+	data[ei++] = FIELD_GET(MT_MIB_MU_BF_TX_CNT, cnt);
+
+	cnt = mt76_rr(dev, MT_MIB_DR8(ext_phy));
+	data[ei++] = cnt;
+
+	cnt = mt76_rr(dev, MT_MIB_DR9(ext_phy));
+	data[ei++] = cnt; /* MU MPDU SUccessful */
+
+	cnt = mt76_rr(dev, MT_MIB_DR11(ext_phy));
+	data[ei++] = cnt; /* SU MPDU successful */
+
+	/* TODO:  External phy too?? */
+
+	/* Tx amsdu info (pack-count histogram) */
+	for (i = 0; i < 8; i++)
+		data[ei++] = mt76_rr(dev,  MT_PLE_AMSDU_PACK_MSDU_CNT(i));
+
+	WARN_ON(ei != MT7915_SSTATS_LEN);
+}
+
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index 48b5e2051bad..ed94e3c3c51d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -1052,6 +1052,9 @@  const struct ieee80211_ops mt7915_ops = {
 	.get_txpower = mt76_get_txpower,
 	.channel_switch_beacon = mt7915_channel_switch_beacon,
 	.get_stats = mt7915_get_stats,
+	.get_et_sset_count = mt7915_debug_get_et_sset_count,
+	.get_et_stats = mt7915_debug_get_et_stats,
+	.get_et_strings = mt7915_debug_get_et_strings,
 	.get_tsf = mt7915_get_tsf,
 	.set_tsf = mt7915_set_tsf,
 	.offset_tsf = mt7915_offset_tsf,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
index 33be449309e0..a3c78365db23 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
@@ -419,4 +419,16 @@  void mt7915_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 			    struct ieee80211_sta *sta, struct dentry *dir);
 #endif
 
+/* Ethtool API, implementation found in debugfs.c */
+void mt7915_debug_get_et_strings(struct ieee80211_hw *hw,
+				 struct ieee80211_vif *vif,
+				 u32 sset, u8 *data);
+
+int mt7915_debug_get_et_sset_count(struct ieee80211_hw *hw,
+				   struct ieee80211_vif *vif, int sset);
+
+void mt7915_debug_get_et_stats(struct ieee80211_hw *hw,
+			       struct ieee80211_vif *vif,
+			       struct ethtool_stats *stats, u64 *data);
+
 #endif