linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: greearb@candelatech.com
Cc: linux-wireless@vger.kernel.org
Subject: Re: [PATCH v3 2/8] mt76 - mt7915: Add tx stats gathered from tx-status callbacks.
Date: Thu, 22 Jul 2021 23:45:23 +0200	[thread overview]
Message-ID: <YPnm8yRZt9anINhK@lore-desk> (raw)
In-Reply-To: <20210722202504.6180-2-greearb@candelatech.com>

[-- Attachment #1: Type: text/plain, Size: 6134 bytes --]

> From: Ben Greear <greearb@candelatech.com>
> 
> Add tx-mode (ofdma, ht, vht, HE) histogram,
> tx-ru-idx histogram, and tx-bandwidth histogram.
> Also add tx attempts and tx success counters.
> 
> All of this is per-station.
> 
> Signed-off-by: Ben Greear <greearb@candelatech.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt76.h     |  1 +
>  .../net/wireless/mediatek/mt76/mt7915/mac.c   | 32 +++++++++++++------
>  .../wireless/mediatek/mt76/mt7915/mt7915.h    | 14 ++++++++
>  3 files changed, 37 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index b41faedee001..436bf2b8e2cd 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -755,6 +755,7 @@ enum mt76_phy_type {
>  	MT_PHY_TYPE_HE_EXT_SU,
>  	MT_PHY_TYPE_HE_TB,
>  	MT_PHY_TYPE_HE_MU,
> +	MT_PHY_TYPE_HE_LAST, /* keep last */
>  };
>  
>  #define CCK_RATE(_idx, _rate) {					\
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
> index f1574538315d..3a10e14fbd50 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
> @@ -1304,7 +1304,7 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, struct sk_buff *skb)
>  
>  static bool
>  mt7915_mac_add_txs_skb(struct mt7915_dev *dev, struct mt76_wcid *wcid, int pid,
> -		       __le32 *txs_data)
> +		       __le32 *txs_data, struct mt7915_sta_stats *stats)
>  {
>  	struct ieee80211_supported_band *sband;
>  	struct mt76_dev *mdev = &dev->mt76;
> @@ -1314,7 +1314,7 @@ mt7915_mac_add_txs_skb(struct mt7915_dev *dev, struct mt76_wcid *wcid, int pid,
>  	struct rate_info rate = {};
>  	struct sk_buff *skb;
>  	bool cck = false;
> -	u32 txrate, txs;
> +	u32 txrate, txs, txs5, txs6, txs7, mode;
>  
>  	mt76_tx_status_lock(mdev, &list);
>  	skb = mt76_tx_status_skb_get(mdev, wcid, pid, &list);
> @@ -1322,6 +1322,9 @@ mt7915_mac_add_txs_skb(struct mt7915_dev *dev, struct mt76_wcid *wcid, int pid,
>  		goto out;
>  
>  	txs = le32_to_cpu(txs_data[0]);
> +	txs5 = le32_to_cpu(txs_data[5]);
> +	txs6 = le32_to_cpu(txs_data[6]);
> +	txs7 = le32_to_cpu(txs_data[7]);
>  
>  	info = IEEE80211_SKB_CB(skb);
>  	if (!(txs & MT_TXS0_ACK_ERROR_MASK))
> @@ -1333,15 +1336,20 @@ mt7915_mac_add_txs_skb(struct mt7915_dev *dev, struct mt76_wcid *wcid, int pid,
>  
>  	info->status.rates[0].idx = -1;
>  
> -	if (!wcid->sta)
> -		goto out;
> +	stats->tx_mpdu_attempts += FIELD_GET(MT_TXS5_F1_MPDU_TX_COUNT, txs5);
> +	stats->tx_mpdu_fail += FIELD_GET(MT_TXS6_F1_MPDU_FAIL_COUNT, txs6);
> +	stats->tx_mpdu_retry += FIELD_GET(MT_TXS7_F1_MPDU_RETRY_COUNT, txs7);
>  
>  	txrate = FIELD_GET(MT_TXS0_TX_RATE, txs);
>  
>  	rate.mcs = FIELD_GET(MT_TX_RATE_IDX, txrate);
>  	rate.nss = FIELD_GET(MT_TX_RATE_NSS, txrate) + 1;
>  
> -	switch (FIELD_GET(MT_TX_RATE_MODE, txrate)) {
> +	stats->tx_nss[rate.nss - 1]++;
> +	stats->tx_mcs[rate.mcs]++;

here, with the patch below, we can have a oob access in tx_mcs array

https://patchwork.kernel.org/project/linux-wireless/patch/20210720130014.23572-2-shayne.chen@mediatek.com/

> +
> +	mode = FIELD_GET(MT_TX_RATE_MODE, txrate);
> +	switch (mode) {
>  	case MT_PHY_TYPE_CCK:
>  		cck = true;
>  		fallthrough;
> @@ -1389,18 +1397,24 @@ mt7915_mac_add_txs_skb(struct mt7915_dev *dev, struct mt76_wcid *wcid, int pid,
>  		goto out;
>  	}
>  
> +	stats->tx_mode[mode]++;
> +
>  	switch (FIELD_GET(MT_TXS0_BW, txs)) {
>  	case IEEE80211_STA_RX_BW_160:
>  		rate.bw = RATE_INFO_BW_160;
> +		stats->tx_bw[3]++;
>  		break;
>  	case IEEE80211_STA_RX_BW_80:
>  		rate.bw = RATE_INFO_BW_80;
> +		stats->tx_bw[2]++;
>  		break;
>  	case IEEE80211_STA_RX_BW_40:
>  		rate.bw = RATE_INFO_BW_40;
> +		stats->tx_bw[1]++;
>  		break;
>  	default:
>  		rate.bw = RATE_INFO_BW_20;
> +		stats->tx_bw[0]++;
>  		break;
>  	}
>  	wcid->rate = rate;
> @@ -1440,15 +1454,13 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
>  	rcu_read_lock();
>  
>  	wcid = rcu_dereference(dev->mt76.wcid[wcidx]);
> -	if (!wcid)
> +	if (!wcid || !wcid->sta)
>  		goto out;
>  
> -	mt7915_mac_add_txs_skb(dev, wcid, pid, txs_data);
> +	msta = container_of(wcid, struct mt7915_sta, wcid);
>  
> -	if (!wcid->sta)
> -		goto out;
> +	mt7915_mac_add_txs_skb(dev, wcid, pid, txs_data, &msta->stats);

it seems to me here we are changing the behaviour since
mt7915_mac_add_txs_skb() is run even with wcid->sta = false

Regards,
Lorenzo

>  
> -	msta = container_of(wcid, struct mt7915_sta, wcid);
>  	spin_lock_bh(&dev->sta_poll_lock);
>  	if (list_empty(&msta->poll_list))
>  		list_add_tail(&msta->poll_list, &dev->sta_poll_list);
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
> index a3c78365db23..ff944d1cf527 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
> @@ -64,6 +64,16 @@ enum mt7915_rxq_id {
>  	MT7915_RXQ_MCU_WA_EXT,
>  };
>  
> +struct mt7915_sta_stats {
> +	unsigned long tx_mpdu_attempts;
> +	unsigned long tx_mpdu_fail;
> +	unsigned long tx_mpdu_retry;
> +	unsigned long tx_mode[MT_PHY_TYPE_HE_LAST]; /* See mt76_phy_type */
> +	unsigned long tx_bw[4]; /* 20, 40, 80, 160 */
> +	unsigned long tx_nss[4]; /* 1, 2, 3, 4 */
> +	unsigned long tx_mcs[16]; /* mcs idx */
> +};
> +
>  struct mt7915_sta_key_conf {
>  	s8 keyidx;
>  	u8 key[16];
> @@ -82,8 +92,11 @@ struct mt7915_sta {
>  	unsigned long jiffies;
>  	unsigned long ampdu_state;
>  
> +	struct mt7915_sta_stats stats;
> +
>  	struct mt7915_sta_key_conf bip;
>  };
> +
>  struct mt7915_vif {
>  	u16 idx;
>  	u8 omac_idx;
> @@ -103,6 +116,7 @@ struct mib_stats {
>  	u32 rts_cnt;
>  	u32 rts_retries_cnt;
>  	u32 ba_miss_cnt;
> +	/* Add more stats here, updated from mac_update_stats */
>  };
>  
>  struct mt7915_hif {
> -- 
> 2.20.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2021-07-22 21:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22 20:24 [PATCH v3 1/8] mt76 - mt7915: Add ethtool stats support greearb
2021-07-22 20:24 ` [PATCH v3 2/8] mt76 - mt7915: Add tx stats gathered from tx-status callbacks greearb
2021-07-22 21:45   ` Lorenzo Bianconi [this message]
2021-07-22 20:24 ` [PATCH v3 3/8] mt76 - mt7915: Add some per-station tx stats to ethtool greearb
2021-07-22 21:46   ` Lorenzo Bianconi
2021-07-22 20:25 ` [PATCH v3 4/8] mt76 - mt7915: Add tx mu/su counters to mib greearb
2021-07-22 21:48   ` Lorenzo Bianconi
2021-07-22 20:25 ` [PATCH v3 5/8] mt76 - mt7915: Move more tx-bf stats " greearb
2021-07-22 20:25 ` [PATCH v3 6/8] mt76 - mt7915: Fix he_mcs capabilities for 160mhz greearb
2021-07-22 20:25 ` [PATCH v3 7/8] mt76 - mt7915: Add more MIB registers greearb
2021-07-22 20:25 ` [PATCH v3 8/8] mt76 - mt7915: Add mib counters to ethtool stats greearb
2021-07-22 20:52 ` [PATCH v3 1/8] mt76 - mt7915: Add ethtool stats support Lorenzo Bianconi

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=YPnm8yRZt9anINhK@lore-desk \
    --to=lorenzo@kernel.org \
    --cc=greearb@candelatech.com \
    --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).