linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] wifi: mt76: mt7996: get tx_retries and tx_failed from txfree
@ 2023-08-25 17:47 Yi-Chia Hsieh
  2023-08-25 17:47 ` [PATCH 2/6] wifi: mt76: mt7996: Add mcu commands for getting sta tx statistic Yi-Chia Hsieh
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Yi-Chia Hsieh @ 2023-08-25 17:47 UTC (permalink / raw)
  To: Felix Fietkau, Johannes Berg
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai, Money Wang,
	Peter Chiu, Benjamin Lin, linux-wireless, linux-mediatek,
	Yi-Chia Hsieh

Retrieve tx retries/failed counts from 'txfree done' events and report
them via mt7996_sta_statistics().

Signed-off-by: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
---
 .../wireless/mediatek/mt76/mt76_connac3_mac.h |  4 ++--
 .../net/wireless/mediatek/mt76/mt7996/mac.c   | 21 ++++++++++++++-----
 .../net/wireless/mediatek/mt76/mt7996/main.c  |  6 ++++++
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac3_mac.h b/drivers/net/wireless/mediatek/mt76/mt76_connac3_mac.h
index 68ca0844cbbf..e0354f1ffcc3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac3_mac.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac3_mac.h
@@ -269,11 +269,11 @@ enum tx_mgnt_type {
 #define MT_TXFREE0_MSDU_CNT		GENMASK(25, 16)
 #define MT_TXFREE0_RX_BYTE		GENMASK(15, 0)
 
-#define MT_TXFREE1_VER			GENMASK(18, 16)
+#define MT_TXFREE1_VER			GENMASK(19, 16)
 
 #define MT_TXFREE_INFO_PAIR		BIT(31)
 #define MT_TXFREE_INFO_HEADER		BIT(30)
-#define MT_TXFREE_INFO_WLAN_ID		GENMASK(23, 12)
+#define MT_TXFREE_INFO_MLD_ID		GENMASK(23, 12)
 #define MT_TXFREE_INFO_MSDU_ID		GENMASK(14, 0)
 #define MT_TXFREE_INFO_COUNT		GENMASK(27, 24)
 #define MT_TXFREE_INFO_STAT		GENMASK(29, 28)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index ac8759febe48..0bdb5533847b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -1070,6 +1070,7 @@ mt7996_mac_tx_free(struct mt7996_dev *dev, void *data, int len)
 	struct mt76_phy *phy3 = mdev->phys[MT_BAND2];
 	struct mt76_txwi_cache *txwi;
 	struct ieee80211_sta *sta = NULL;
+	struct mt76_wcid *wcid;
 	LIST_HEAD(free_list);
 	struct sk_buff *skb, *tmp;
 	void *end = data + len;
@@ -1088,7 +1089,7 @@ mt7996_mac_tx_free(struct mt7996_dev *dev, void *data, int len)
 		mt76_queue_tx_cleanup(dev, phy3->q_tx[MT_TXQ_BE], false);
 	}
 
-	if (WARN_ON_ONCE(le32_get_bits(tx_free[1], MT_TXFREE1_VER) < 4))
+	if (WARN_ON_ONCE(le32_get_bits(tx_free[1], MT_TXFREE1_VER) < 5))
 		return;
 
 	total = le32_get_bits(tx_free[0], MT_TXFREE0_MSDU_CNT);
@@ -1104,10 +1105,9 @@ mt7996_mac_tx_free(struct mt7996_dev *dev, void *data, int len)
 		info = le32_to_cpu(*cur_info);
 		if (info & MT_TXFREE_INFO_PAIR) {
 			struct mt7996_sta *msta;
-			struct mt76_wcid *wcid;
 			u16 idx;
 
-			idx = FIELD_GET(MT_TXFREE_INFO_WLAN_ID, info);
+			idx = FIELD_GET(MT_TXFREE_INFO_MLD_ID, info);
 			wcid = rcu_dereference(dev->mt76.wcid[idx]);
 			sta = wcid_to_sta(wcid);
 			if (!sta)
@@ -1120,10 +1120,21 @@ mt7996_mac_tx_free(struct mt7996_dev *dev, void *data, int len)
 					      &mdev->sta_poll_list);
 			spin_unlock_bh(&mdev->sta_poll_lock);
 			continue;
-		}
+		} else if (info & MT_TXFREE_INFO_HEADER) {
+			u32 tx_retries = 0, tx_failed = 0;
+
+			if (!wcid)
+				continue;
+
+			tx_retries =
+				FIELD_GET(MT_TXFREE_INFO_COUNT, info) - 1;
+			tx_failed = tx_retries +
+				!!FIELD_GET(MT_TXFREE_INFO_STAT, info);
 
-		if (info & MT_TXFREE_INFO_HEADER)
+			wcid->stats.tx_retries += tx_retries;
+			wcid->stats.tx_failed += tx_failed;
 			continue;
+		}
 
 		for (i = 0; i < 2; i++) {
 			msdu = (info >> (15 * i)) & MT_TXFREE_INFO_MSDU_ID;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
index c3a479dc3f53..07c13fcc187a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -992,6 +992,12 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw,
 	sinfo->txrate.flags = txrate->flags;
 	sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
 
+	sinfo->tx_failed = msta->wcid.stats.tx_failed;
+	sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
+
+	sinfo->tx_retries = msta->wcid.stats.tx_retries;
+	sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
+
 	sinfo->ack_signal = (s8)msta->ack_signal;
 	sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
 
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/6] wifi: mt76: mt7996: Add mcu commands for getting sta tx statistic
  2023-08-25 17:47 [PATCH 1/6] wifi: mt76: mt7996: get tx_retries and tx_failed from txfree Yi-Chia Hsieh
@ 2023-08-25 17:47 ` Yi-Chia Hsieh
  2023-08-25 17:47 ` [PATCH 3/6] wifi: mt76: mt7996: enable PPDU-TxS to host Yi-Chia Hsieh
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Yi-Chia Hsieh @ 2023-08-25 17:47 UTC (permalink / raw)
  To: Felix Fietkau, Johannes Berg
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai, Money Wang,
	Peter Chiu, Benjamin Lin, linux-wireless, linux-mediatek,
	Yi-Chia Hsieh

Per peer Tx/Rx statistic can only be obtained by querying WM when WED is
on. This patch switches to periodic event reporting in the case of WED
being enabled.

Signed-off-by: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
---
 .../wireless/mediatek/mt76/mt76_connac_mcu.h  | 15 ++++
 .../net/wireless/mediatek/mt76/mt7996/mac.c   |  5 ++
 .../net/wireless/mediatek/mt76/mt7996/main.c  | 15 ++++
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   | 68 +++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7996/mcu.h   | 26 +++++++
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |  1 +
 6 files changed, 130 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
index 4543e5bf0482..ef49ad0ffc35 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
@@ -1011,6 +1011,8 @@ enum {
 	MCU_UNI_EVENT_FW_LOG_2_HOST = 0x04,
 	MCU_UNI_EVENT_IE_COUNTDOWN = 0x09,
 	MCU_UNI_EVENT_RDD_REPORT = 0x11,
+	MCU_UNI_EVENT_PER_STA_INFO = 0x6d,
+	MCU_UNI_EVENT_ALL_STA_INFO = 0x6e,
 };
 
 #define MCU_UNI_CMD_EVENT			BIT(1)
@@ -1224,6 +1226,8 @@ enum {
 	MCU_UNI_CMD_VOW = 0x37,
 	MCU_UNI_CMD_RRO = 0x57,
 	MCU_UNI_CMD_OFFCH_SCAN_CTRL = 0x58,
+	MCU_UNI_CMD_PER_STA_INFO = 0x6d,
+	MCU_UNI_CMD_ALL_STA_INFO = 0x6e,
 	MCU_UNI_CMD_ASSERT_DUMP = 0x6f,
 };
 
@@ -1302,6 +1306,17 @@ enum {
 	UNI_OFFLOAD_OFFLOAD_BMC_RPY_DETECT,
 };
 
+enum UNI_ALL_STA_INFO_TAG {
+	UNI_ALL_STA_TX_RATE,
+	UNI_ALL_STA_TX_STAT,
+	UNI_ALL_STA_TXRX_ADM_STAT,
+	UNI_ALL_STA_TXRX_AIR_TIME,
+	UNI_ALL_STA_DATA_TX_RETRY_COUNT,
+	UNI_ALL_STA_GI_MODE,
+	UNI_ALL_STA_TXRX_MSDU_COUNT,
+	UNI_ALL_STA_MAX_NUM
+};
+
 enum {
 	MT_NIC_CAP_TX_RESOURCE,
 	MT_NIC_CAP_TX_EFUSE_ADDR,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index 0bdb5533847b..4e19d4f8c70b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -2202,6 +2202,11 @@ void mt7996_mac_work(struct work_struct *work)
 		mphy->mac_work_count = 0;
 
 		mt7996_mac_update_stats(phy);
+
+		if (mtk_wed_device_active(&phy->dev->mt76.mmio.wed)) {
+			mt7996_mcu_get_all_sta_info(phy, UNI_ALL_STA_TXRX_ADM_STAT);
+			mt7996_mcu_get_all_sta_info(phy, UNI_ALL_STA_TXRX_MSDU_COUNT);
+		}
 	}
 
 	mutex_unlock(&mphy->dev->mutex);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
index 07c13fcc187a..37128f7f6671 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -972,6 +972,7 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw,
 				  struct ieee80211_sta *sta,
 				  struct station_info *sinfo)
 {
+	struct mt7996_phy *phy = mt7996_hw_phy(hw);
 	struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
 	struct rate_info *txrate = &msta->wcid.rate;
 
@@ -1003,6 +1004,20 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw,
 
 	sinfo->avg_ack_signal = -(s8)ewma_avg_signal_read(&msta->avg_ack_signal);
 	sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG);
+
+	if (mtk_wed_device_active(&phy->dev->mt76.mmio.wed)) {
+		sinfo->tx_bytes = msta->wcid.stats.tx_bytes;
+		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
+
+		sinfo->rx_bytes = msta->wcid.stats.rx_bytes;
+		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES64);
+
+		sinfo->tx_packets = msta->wcid.stats.tx_packets;
+		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
+
+		sinfo->rx_packets = msta->wcid.stats.rx_packets;
+		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
+	}
 }
 
 static void mt7996_sta_rc_work(void *data, struct ieee80211_sta *sta)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index 4a30db49ef33..923e6f006cee 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -447,6 +447,54 @@ mt7996_mcu_ie_countdown(struct mt7996_dev *dev, struct sk_buff *skb)
 	}
 }
 
+static void
+mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb)
+{
+	struct mt7996_mcu_all_sta_info_event *res;
+	u16 i;
+
+	skb_pull(skb, sizeof(struct mt7996_mcu_rxd));
+
+	res = (struct mt7996_mcu_all_sta_info_event *)skb->data;
+
+	for (i = 0; i < le16_to_cpu(res->sta_num); i++) {
+		u8 ac;
+		u16 wlan_idx;
+		struct mt76_wcid *wcid;
+
+		switch (le16_to_cpu(res->tag)) {
+		case UNI_ALL_STA_TXRX_ADM_STAT:
+			wlan_idx = le16_to_cpu(res->adm_stat[i].wlan_idx);
+			wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
+
+			if (!wcid)
+				break;
+
+			for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
+				wcid->stats.tx_bytes +=
+					le32_to_cpu(res->adm_stat[i].tx_bytes[ac]);
+				wcid->stats.rx_bytes +=
+					le32_to_cpu(res->adm_stat[i].rx_bytes[ac]);
+			}
+			break;
+		case UNI_ALL_STA_TXRX_MSDU_COUNT:
+			wlan_idx = le16_to_cpu(res->msdu_cnt[i].wlan_idx);
+			wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
+
+			if (!wcid)
+				break;
+
+			wcid->stats.tx_packets +=
+				le32_to_cpu(res->msdu_cnt[i].tx_msdu_cnt);
+			wcid->stats.rx_packets +=
+				le32_to_cpu(res->msdu_cnt[i].rx_msdu_cnt);
+			break;
+		default:
+			break;
+		}
+	}
+}
+
 static void
 mt7996_mcu_rx_ext_event(struct mt7996_dev *dev, struct sk_buff *skb)
 {
@@ -491,6 +539,9 @@ mt7996_mcu_uni_rx_unsolicited_event(struct mt7996_dev *dev, struct sk_buff *skb)
 	case MCU_UNI_EVENT_RDD_REPORT:
 		mt7996_mcu_rx_radar_detected(dev, skb);
 		break;
+	case MCU_UNI_EVENT_ALL_STA_INFO:
+		mt7996_mcu_rx_all_sta_info_event(dev, skb);
+		break;
 	default:
 		break;
 	}
@@ -3786,3 +3837,20 @@ int mt7996_mcu_set_rro(struct mt7996_dev *dev, u16 tag, u8 val)
 	return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(RRO), &req,
 				 sizeof(req), true);
 }
+
+int mt7996_mcu_get_all_sta_info(struct mt7996_phy *phy, u16 tag)
+{
+	struct mt7996_dev *dev = phy->dev;
+	struct {
+		u8 _rsv[4];
+
+		__le16 tag;
+		__le16 len;
+	} __packed req = {
+		.tag = cpu_to_le16(tag),
+		.len = cpu_to_le16(sizeof(req) - 4),
+	};
+
+	return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(ALL_STA_INFO),
+				 &req, sizeof(req), false);
+}
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
index 078f82858621..5aece2046a9d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
@@ -153,6 +153,32 @@ struct mt7996_mcu_mib {
 	__le64 data;
 } __packed;
 
+struct mt7996_mcu_all_sta_info_event {
+	u8 rsv[4];
+	__le16 tag;
+	__le16 len;
+	u8 more;
+	u8 rsv2;
+	__le16 sta_num;
+	u8 rsv3[2];
+
+	union {
+		struct {
+			__le16 wlan_idx;
+			u8 rsv[2];
+			__le32 tx_bytes[IEEE80211_NUM_ACS];
+			__le32 rx_bytes[IEEE80211_NUM_ACS];
+		} adm_stat[];
+
+		struct {
+			__le16 wlan_idx;
+			u8 rsv[2];
+			__le32 tx_msdu_cnt;
+			__le32 rx_msdu_cnt;
+		} msdu_cnt[];
+	};
+} __packed;
+
 enum mt7996_chan_mib_offs {
 	UNI_MIB_OBSS_AIRTIME = 26,
 	UNI_MIB_NON_WIFI_TIME = 27,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index 7354e5cf8e67..cb67a2d4c6d4 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -402,6 +402,7 @@ int mt7996_mcu_fw_dbg_ctrl(struct mt7996_dev *dev, u32 module, u8 level);
 int mt7996_mcu_trigger_assert(struct mt7996_dev *dev);
 void mt7996_mcu_rx_event(struct mt7996_dev *dev, struct sk_buff *skb);
 void mt7996_mcu_exit(struct mt7996_dev *dev);
+int mt7996_mcu_get_all_sta_info(struct mt7996_phy *phy, u16 tag);
 
 static inline u8 mt7996_max_interface_num(struct mt7996_dev *dev)
 {
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/6] wifi: mt76: mt7996: enable PPDU-TxS to host
  2023-08-25 17:47 [PATCH 1/6] wifi: mt76: mt7996: get tx_retries and tx_failed from txfree Yi-Chia Hsieh
  2023-08-25 17:47 ` [PATCH 2/6] wifi: mt76: mt7996: Add mcu commands for getting sta tx statistic Yi-Chia Hsieh
@ 2023-08-25 17:47 ` Yi-Chia Hsieh
  2023-08-25 17:47 ` [PATCH 4/6] wifi: mt76: mt7996: remove periodic MPDU TXS request Yi-Chia Hsieh
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Yi-Chia Hsieh @ 2023-08-25 17:47 UTC (permalink / raw)
  To: Felix Fietkau, Johannes Berg
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai, Money Wang,
	Peter Chiu, Benjamin Lin, linux-wireless, linux-mediatek,
	Yi-Chia Hsieh

Enable PPDU TxS by default. This makes the driver able to get Tx rate
information from TxS. The driver will also refresh BA session timer
on receive of PPDU TxS when WED is on.

Signed-off-by: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
---
 .../wireless/mediatek/mt76/mt76_connac3_mac.h | 16 +++++++-
 .../net/wireless/mediatek/mt76/mt7996/init.c  |  5 +++
 .../net/wireless/mediatek/mt76/mt7996/mac.c   | 41 +++++++++++--------
 .../net/wireless/mediatek/mt76/mt7996/regs.h  |  7 ++++
 4 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac3_mac.h b/drivers/net/wireless/mediatek/mt76/mt76_connac3_mac.h
index e0354f1ffcc3..fc98d8de04ff 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac3_mac.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac3_mac.h
@@ -303,7 +303,7 @@ enum tx_mgnt_type {
 
 #define MT_TXS2_BF_STATUS		GENMASK(31, 30)
 #define MT_TXS2_BAND			GENMASK(29, 28)
-#define MT_TXS2_WCID			GENMASK(27, 16)
+#define MT_TXS2_MLD_ID			GENMASK(27, 16)
 #define MT_TXS2_TX_DELAY		GENMASK(15, 0)
 
 #define MT_TXS3_PID			GENMASK(31, 24)
@@ -315,6 +315,7 @@ enum tx_mgnt_type {
 
 #define MT_TXS4_TIMESTAMP		GENMASK(31, 0)
 
+/* MPDU based TXS */
 #define MT_TXS5_F0_FINAL_MPDU		BIT(31)
 #define MT_TXS5_F0_QOS			BIT(30)
 #define MT_TXS5_F0_TX_COUNT		GENMASK(29, 25)
@@ -336,4 +337,17 @@ enum tx_mgnt_type {
 #define MT_TXS7_F1_MPDU_RETRY_COUNT	GENMASK(31, 24)
 #define MT_TXS7_F1_MPDU_RETRY_BYTES	GENMASK(23, 0)
 
+/* PPDU based TXS */
+#define MT_TXS5_MPDU_TX_CNT		GENMASK(30, 20)
+#define MT_TXS5_MPDU_TX_BYTE_SCALE	BIT(15)
+#define MT_TXS5_MPDU_TX_BYTE		GENMASK(14, 0)
+
+#define MT_TXS6_MPDU_FAIL_CNT		GENMASK(30, 20)
+#define MT_TXS6_MPDU_FAIL_BYTE_SCALE	BIT(15)
+#define MT_TXS6_MPDU_FAIL_BYTE		GENMASK(14, 0)
+
+#define MT_TXS7_MPDU_RETRY_CNT		GENMASK(30, 20)
+#define MT_TXS7_MPDU_RETRY_BYTE_SCALE	BIT(15)
+#define MT_TXS7_MPDU_RETRY_BYTE		GENMASK(14, 0)
+
 #endif /* __MT76_CONNAC3_MAC_H */
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
index e297e7cb3a7a..36d6868960c2 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
@@ -257,6 +257,11 @@ mt7996_mac_init_band(struct mt7996_dev *dev, u8 band)
 	set = FIELD_PREP(MT_WTBLOFF_RSCR_RCPI_MODE, 0) |
 	      FIELD_PREP(MT_WTBLOFF_RSCR_RCPI_PARAM, 0x3);
 	mt76_rmw(dev, MT_WTBLOFF_RSCR(band), mask, set);
+
+	/* MT_TXD5_TX_STATUS_HOST (MPDU format) has higher priority than
+	 * MT_AGG_ACR_PPDU_TXS2H (PPDU format) even though ACR bit is set.
+	 */
+	mt76_set(dev, MT_AGG_ACR4(band), MT_AGG_ACR_PPDU_TXS2H);
 }
 
 static void mt7996_mac_init_basic_rates(struct mt7996_dev *dev)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index 4e19d4f8c70b..ef5d1192ef0e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -1178,22 +1178,31 @@ mt7996_mac_add_txs_skb(struct mt7996_dev *dev, struct mt76_wcid *wcid,
 	bool cck = false;
 	u32 txrate, txs, mode, stbc;
 
+	txs = le32_to_cpu(txs_data[0]);
+
 	mt76_tx_status_lock(mdev, &list);
 	skb = mt76_tx_status_skb_get(mdev, wcid, pid, &list);
-	if (!skb)
-		goto out_no_skb;
 
-	txs = le32_to_cpu(txs_data[0]);
+	if (skb) {
+		info = IEEE80211_SKB_CB(skb);
+		if (!(txs & MT_TXS0_ACK_ERROR_MASK))
+			info->flags |= IEEE80211_TX_STAT_ACK;
 
-	info = IEEE80211_SKB_CB(skb);
-	if (!(txs & MT_TXS0_ACK_ERROR_MASK))
-		info->flags |= IEEE80211_TX_STAT_ACK;
+		info->status.ampdu_len = 1;
+		info->status.ampdu_ack_len =
+			!!(info->flags & IEEE80211_TX_STAT_ACK);
 
-	info->status.ampdu_len = 1;
-	info->status.ampdu_ack_len = !!(info->flags &
-					IEEE80211_TX_STAT_ACK);
+		info->status.rates[0].idx = -1;
+	}
 
-	info->status.rates[0].idx = -1;
+	if (mtk_wed_device_active(&dev->mt76.mmio.wed) && wcid->sta) {
+		struct ieee80211_sta *sta;
+		u8 tid;
+
+		sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv);
+		tid = FIELD_GET(MT_TXS0_TID, txs);
+		ieee80211_refresh_tx_agg_session_timer(sta, tid);
+	}
 
 	txrate = FIELD_GET(MT_TXS0_TX_RATE, txs);
 
@@ -1293,9 +1302,8 @@ mt7996_mac_add_txs_skb(struct mt7996_dev *dev, struct mt76_wcid *wcid,
 	wcid->rate = rate;
 
 out:
-	mt76_tx_status_skb_done(mdev, skb, &list);
-
-out_no_skb:
+	if (skb)
+		mt76_tx_status_skb_done(mdev, skb, &list);
 	mt76_tx_status_unlock(mdev, &list);
 
 	return !!skb;
@@ -1309,13 +1317,10 @@ static void mt7996_mac_add_txs(struct mt7996_dev *dev, void *data)
 	u16 wcidx;
 	u8 pid;
 
-	if (le32_get_bits(txs_data[0], MT_TXS0_TXS_FORMAT) > 1)
-		return;
-
-	wcidx = le32_get_bits(txs_data[2], MT_TXS2_WCID);
+	wcidx = le32_get_bits(txs_data[2], MT_TXS2_MLD_ID);
 	pid = le32_get_bits(txs_data[3], MT_TXS3_PID);
 
-	if (pid < MT_PACKET_ID_FIRST)
+	if (pid < MT_PACKET_ID_WED)
 		return;
 
 	if (wcidx >= mt7996_wtbl_size(dev))
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/regs.h b/drivers/net/wireless/mediatek/mt76/mt7996/regs.h
index 97beab924517..293496daddd3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/regs.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/regs.h
@@ -243,6 +243,13 @@ enum base_rev {
 						 FIELD_PREP(MT_WTBL_LMAC_ID, _id) | \
 						 FIELD_PREP(MT_WTBL_LMAC_DW, _dw))
 
+/* AGG: band 0(0x820e2000), band 1(0x820f2000), band 2(0x830e2000) */
+#define MT_WF_AGG_BASE(_band)			__BASE(WF_AGG_BASE, (_band))
+#define MT_WF_AGG(_band, ofs)			(MT_WF_AGG_BASE(_band) + (ofs))
+
+#define MT_AGG_ACR4(_band)			MT_WF_AGG(_band, 0x3c)
+#define MT_AGG_ACR_PPDU_TXS2H			BIT(1)
+
 /* ARB: band 0(0x820e3000), band 1(0x820f3000), band 2(0x830e3000) */
 #define MT_WF_ARB_BASE(_band)			__BASE(WF_ARB_BASE, (_band))
 #define MT_WF_ARB(_band, ofs)			(MT_WF_ARB_BASE(_band) + (ofs))
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/6] wifi: mt76: mt7996: remove periodic MPDU TXS request
  2023-08-25 17:47 [PATCH 1/6] wifi: mt76: mt7996: get tx_retries and tx_failed from txfree Yi-Chia Hsieh
  2023-08-25 17:47 ` [PATCH 2/6] wifi: mt76: mt7996: Add mcu commands for getting sta tx statistic Yi-Chia Hsieh
  2023-08-25 17:47 ` [PATCH 3/6] wifi: mt76: mt7996: enable PPDU-TxS to host Yi-Chia Hsieh
@ 2023-08-25 17:47 ` Yi-Chia Hsieh
  2023-08-25 17:47 ` [PATCH 5/6] wifi: mac80211: export ieee80211_tpt_led_trig_tx/rx for driver Yi-Chia Hsieh
  2023-08-25 17:47 ` [PATCH 6/6] wifi: mt76: report per-phy tx and rx byte to tpt_led Yi-Chia Hsieh
  4 siblings, 0 replies; 9+ messages in thread
From: Yi-Chia Hsieh @ 2023-08-25 17:47 UTC (permalink / raw)
  To: Felix Fietkau, Johannes Berg
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai, Money Wang,
	Peter Chiu, Benjamin Lin, linux-wireless, linux-mediatek,
	Yi-Chia Hsieh

Remove periodic MPDU TXS request. Get TID and FrameType from SKB
instead of TXWI, which is empty for Data Frame after MPDU TXS request
is removed, hence prohibiting the establishment of TX BA session.

Signed-off-by: Benjamin Lin <benjamin-jw.lin@mediatek.com>
Signed-off-by: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
---
 .../net/wireless/mediatek/mt76/mt7996/mac.c   | 38 ++++++++++---------
 .../net/wireless/mediatek/mt76/mt7996/main.c  |  1 -
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |  1 -
 3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index ef5d1192ef0e..383b55c8cca8 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -948,15 +948,6 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
 	if (!wcid)
 		wcid = &dev->mt76.global_wcid;
 
-	if (sta) {
-		struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
-
-		if (time_after(jiffies, msta->jiffies + HZ / 4)) {
-			info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
-			msta->jiffies = jiffies;
-		}
-	}
-
 	t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
 	t->skb = tx_info->skb;
 
@@ -1006,22 +997,35 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
 }
 
 static void
-mt7996_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi)
+mt7996_tx_check_aggr(struct ieee80211_sta *sta, struct sk_buff *skb)
 {
 	struct mt7996_sta *msta;
+	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+	bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
 	u16 fc, tid;
-	u32 val;
 
 	if (!sta || !(sta->deflink.ht_cap.ht_supported || sta->deflink.he_cap.has_he))
 		return;
 
-	tid = le32_get_bits(txwi[1], MT_TXD1_TID);
+	tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
 	if (tid >= 6) /* skip VO queue */
 		return;
 
-	val = le32_to_cpu(txwi[2]);
-	fc = FIELD_GET(MT_TXD2_FRAME_TYPE, val) << 2 |
-	     FIELD_GET(MT_TXD2_SUB_TYPE, val) << 4;
+	if (is_8023) {
+		fc = IEEE80211_FTYPE_DATA |
+		     (sta->wme ? IEEE80211_STYPE_QOS_DATA : IEEE80211_STYPE_DATA);
+	} else {
+		/* No need to get precise TID for Action/Management Frame,
+		 * since it will not meet the following Frame Control
+		 * condition anyway.
+		 */
+
+		struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
+
+		fc = le16_to_cpu(hdr->frame_control) &
+		     (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
+	}
+
 	if (unlikely(fc != (IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA)))
 		return;
 
@@ -1049,7 +1053,7 @@ mt7996_txwi_free(struct mt7996_dev *dev, struct mt76_txwi_cache *t,
 		wcid_idx = wcid->idx;
 
 		if (likely(t->skb->protocol != cpu_to_be16(ETH_P_PAE)))
-			mt7996_tx_check_aggr(sta, txwi);
+			mt7996_tx_check_aggr(sta, t->skb);
 	} else {
 		wcid_idx = le32_get_bits(txwi[1], MT_TXD1_WLAN_IDX);
 	}
@@ -1320,7 +1324,7 @@ static void mt7996_mac_add_txs(struct mt7996_dev *dev, void *data)
 	wcidx = le32_get_bits(txs_data[2], MT_TXS2_MLD_ID);
 	pid = le32_get_bits(txs_data[3], MT_TXS3_PID);
 
-	if (pid < MT_PACKET_ID_WED)
+	if (pid < MT_PACKET_ID_NO_SKB)
 		return;
 
 	if (wcidx >= mt7996_wtbl_size(dev))
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
index 37128f7f6671..202c6083e8f0 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -660,7 +660,6 @@ int mt7996_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 	msta->wcid.idx = idx;
 	msta->wcid.phy_idx = band_idx;
 	msta->wcid.tx_info |= MT_WCID_TX_INFO_SET;
-	msta->jiffies = jiffies;
 
 	ewma_avg_signal_init(&msta->avg_ack_signal);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index cb67a2d4c6d4..e53cf6a3704c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -110,7 +110,6 @@ struct mt7996_sta {
 	struct ewma_avg_signal avg_ack_signal;
 
 	unsigned long changed;
-	unsigned long jiffies;
 
 	struct mt76_connac_sta_key_conf bip;
 
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/6] wifi: mac80211: export ieee80211_tpt_led_trig_tx/rx for driver
  2023-08-25 17:47 [PATCH 1/6] wifi: mt76: mt7996: get tx_retries and tx_failed from txfree Yi-Chia Hsieh
                   ` (2 preceding siblings ...)
  2023-08-25 17:47 ` [PATCH 4/6] wifi: mt76: mt7996: remove periodic MPDU TXS request Yi-Chia Hsieh
@ 2023-08-25 17:47 ` Yi-Chia Hsieh
  2023-08-25 18:08   ` Jeff Johnson
  2023-08-29  6:36   ` Kalle Valo
  2023-08-25 17:47 ` [PATCH 6/6] wifi: mt76: report per-phy tx and rx byte to tpt_led Yi-Chia Hsieh
  4 siblings, 2 replies; 9+ messages in thread
From: Yi-Chia Hsieh @ 2023-08-25 17:47 UTC (permalink / raw)
  To: Felix Fietkau, Johannes Berg
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai, Money Wang,
	Peter Chiu, Benjamin Lin, linux-wireless, linux-mediatek,
	Yi-Chia Hsieh

Whenever the H/W path is enabled and traffic is in the binding state,
mac80211 is not aware of the traffic. Consequently, the LED does not
blink for that reason.

The ieee80211_tpt_led_trig_tx/rx functions are exported for the driver
so that we can report the tx and rx bytes from the driver when
the H/W path is being used.

Signed-off-by: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
---
 include/net/mac80211.h | 17 +++++++++++++++++
 net/mac80211/led.c     | 18 ++++++++++++++++++
 net/mac80211/led.h     | 18 ------------------
 net/mac80211/rx.c      |  2 +-
 net/mac80211/tx.c      |  4 ++--
 5 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 3a8a2d2c58c3..53804822dc8d 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -4729,6 +4729,8 @@ __ieee80211_create_tpt_led_trigger(struct ieee80211_hw *hw,
 				   unsigned int flags,
 				   const struct ieee80211_tpt_blink *blink_table,
 				   unsigned int blink_table_len);
+void __ieee80211_tpt_led_trig_tx(struct ieee80211_hw *hw, int bytes);
+void __ieee80211_tpt_led_trig_rx(struct ieee80211_hw *hw, int bytes);
 #endif
 /**
  * ieee80211_get_tx_led_name - get name of TX LED
@@ -4839,6 +4841,21 @@ ieee80211_create_tpt_led_trigger(struct ieee80211_hw *hw, unsigned int flags,
 #endif
 }
 
+static inline void
+ieee80211_tpt_led_trig_tx(struct ieee80211_hw *hw, int bytes)
+{
+#ifdef CPTCFG_MAC80211_LEDS
+	__ieee80211_tpt_led_trig_tx(hw, bytes);
+#endif
+}
+
+static inline void
+ieee80211_tpt_led_trig_rx(struct ieee80211_hw *hw, int bytes)
+{
+#ifdef CPTCFG_MAC80211_LEDS
+	__ieee80211_tpt_led_trig_rx(hw, bytes);
+#endif
+}
 /**
  * ieee80211_unregister_hw - Unregister a hardware device
  *
diff --git a/net/mac80211/led.c b/net/mac80211/led.c
index 2dc732147e85..af03a2ef5c6a 100644
--- a/net/mac80211/led.c
+++ b/net/mac80211/led.c
@@ -319,6 +319,24 @@ __ieee80211_create_tpt_led_trigger(struct ieee80211_hw *hw,
 }
 EXPORT_SYMBOL(__ieee80211_create_tpt_led_trigger);
 
+void __ieee80211_tpt_led_trig_tx(struct ieee80211_hw *hw, int bytes)
+{
+	struct ieee80211_local *local = hw_to_local(hw);
+
+	if (atomic_read(&local->tpt_led_active))
+		local->tpt_led_trigger->tx_bytes += bytes;
+}
+EXPORT_SYMBOL(__ieee80211_tpt_led_trig_tx);
+
+void __ieee80211_tpt_led_trig_rx(struct ieee80211_hw *hw, int bytes)
+{
+	struct ieee80211_local *local = hw_to_local(hw);
+
+	if (atomic_read(&local->tpt_led_active))
+		local->tpt_led_trigger->rx_bytes += bytes;
+}
+EXPORT_SYMBOL(__ieee80211_tpt_led_trig_rx);
+
 static void ieee80211_start_tpt_led_trig(struct ieee80211_local *local)
 {
 	struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
diff --git a/net/mac80211/led.h b/net/mac80211/led.h
index d25f13346b82..98db4356d0de 100644
--- a/net/mac80211/led.h
+++ b/net/mac80211/led.h
@@ -66,21 +66,3 @@ static inline void ieee80211_mod_tpt_led_trig(struct ieee80211_local *local,
 {
 }
 #endif
-
-static inline void
-ieee80211_tpt_led_trig_tx(struct ieee80211_local *local, int bytes)
-{
-#ifdef CONFIG_MAC80211_LEDS
-	if (atomic_read(&local->tpt_led_active))
-		local->tpt_led_trigger->tx_bytes += bytes;
-#endif
-}
-
-static inline void
-ieee80211_tpt_led_trig_rx(struct ieee80211_local *local, int bytes)
-{
-#ifdef CONFIG_MAC80211_LEDS
-	if (atomic_read(&local->tpt_led_active))
-		local->tpt_led_trigger->rx_bytes += bytes;
-#endif
-}
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 4f707d2a160f..5747d7dac4d7 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -5375,7 +5375,7 @@ void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
 	if (skb) {
 		if ((status->flag & RX_FLAG_8023) ||
 			ieee80211_is_data_present(hdr->frame_control))
-			ieee80211_tpt_led_trig_rx(local, skb->len);
+			ieee80211_tpt_led_trig_rx(&local->hw, skb->len);
 
 		if (status->flag & RX_FLAG_8023)
 			__ieee80211_rx_handle_8023(hw, pubsta, skb, list);
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 7fe7280e8437..234de8d3b8bb 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -4320,7 +4320,7 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb,
 	len = 0;
  out:
 	if (len)
-		ieee80211_tpt_led_trig_tx(local, len);
+		ieee80211_tpt_led_trig_tx(&local->hw, len);
 	rcu_read_unlock();
 }
 
@@ -4646,7 +4646,7 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
 	sta->deflink.tx_stats.packets[queue] += skbs;
 	sta->deflink.tx_stats.bytes[queue] += len;
 
-	ieee80211_tpt_led_trig_tx(local, len);
+	ieee80211_tpt_led_trig_tx(&local->hw, len);
 
 	ieee80211_tx_8023(sdata, skb, sta, false);
 
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/6] wifi: mt76: report per-phy tx and rx byte to tpt_led
  2023-08-25 17:47 [PATCH 1/6] wifi: mt76: mt7996: get tx_retries and tx_failed from txfree Yi-Chia Hsieh
                   ` (3 preceding siblings ...)
  2023-08-25 17:47 ` [PATCH 5/6] wifi: mac80211: export ieee80211_tpt_led_trig_tx/rx for driver Yi-Chia Hsieh
@ 2023-08-25 17:47 ` Yi-Chia Hsieh
  4 siblings, 0 replies; 9+ messages in thread
From: Yi-Chia Hsieh @ 2023-08-25 17:47 UTC (permalink / raw)
  To: Felix Fietkau, Johannes Berg
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai, Money Wang,
	Peter Chiu, Benjamin Lin, linux-wireless, linux-mediatek,
	Yi-Chia Hsieh

Fix the issue where the tx and rx byte count is not reported to mac80211
when H/W path is binded.

Signed-off-by: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
---
 .../net/wireless/mediatek/mt76/mt76_connac_mac.c  | 10 ++++++----
 drivers/net/wireless/mediatek/mt76/mt7915/mmio.c  |  5 +++++
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c   | 15 +++++++++++----
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c
index ee5177fd6dde..ff3cefadaa7c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c
@@ -608,9 +608,15 @@ bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid,
 
 	txs = le32_to_cpu(txs_data[0]);
 
+	mphy = mt76_dev_phy(dev, wcid->phy_idx);
+
 	/* PPDU based reporting */
 	if (mtk_wed_device_active(&dev->mmio.wed) &&
 	    FIELD_GET(MT_TXS0_TXS_FORMAT, txs) > 1) {
+		ieee80211_tpt_led_trig_tx(mphy->hw,
+			le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE) -
+			le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_BYTE));
+
 		stats->tx_bytes +=
 			le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE) -
 			le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_BYTE);
@@ -651,10 +657,6 @@ bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid,
 		cck = true;
 		fallthrough;
 	case MT_PHY_TYPE_OFDM:
-		mphy = &dev->phy;
-		if (wcid->phy_idx == MT_BAND1 && dev->phys[MT_BAND1])
-			mphy = dev->phys[MT_BAND1];
-
 		if (mphy->chandef.chan->band == NL80211_BAND_5GHZ)
 			sband = &mphy->sband_5g.sband;
 		else if (mphy->chandef.chan->band == NL80211_BAND_6GHZ)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
index fc7ace638ce8..c1ed6aa5cc3b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
@@ -657,6 +657,11 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed,
 
 	wcid = rcu_dereference(dev->mt76.wcid[idx]);
 	if (wcid) {
+		struct mt76_phy *mphy = mt76_dev_phy(&dev->mt76, wcid->phy_idx);
+
+		ieee80211_tpt_led_trig_rx(mphy->hw,
+					  le32_to_cpu(stats->rx_byte_cnt));
+
 		wcid->stats.rx_bytes += le32_to_cpu(stats->rx_byte_cnt);
 		wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt);
 		wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index 923e6f006cee..4222343de2f8 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -461,6 +461,8 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb)
 		u8 ac;
 		u16 wlan_idx;
 		struct mt76_wcid *wcid;
+		struct mt76_phy *mphy;
+		u32 tx_bytes, rx_bytes;
 
 		switch (le16_to_cpu(res->tag)) {
 		case UNI_ALL_STA_TXRX_ADM_STAT:
@@ -470,11 +472,16 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb)
 			if (!wcid)
 				break;
 
+			mphy = mt76_dev_phy(&dev->mt76, wcid->phy_idx);
 			for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
-				wcid->stats.tx_bytes +=
-					le32_to_cpu(res->adm_stat[i].tx_bytes[ac]);
-				wcid->stats.rx_bytes +=
-					le32_to_cpu(res->adm_stat[i].rx_bytes[ac]);
+				tx_bytes = le32_to_cpu(res->adm_stat[i].tx_bytes[ac]);
+				rx_bytes = le32_to_cpu(res->adm_stat[i].rx_bytes[ac]);
+
+				wcid->stats.tx_bytes += tx_bytes;
+				wcid->stats.rx_bytes += rx_bytes;
+
+				ieee80211_tpt_led_trig_tx(mphy->hw, tx_bytes);
+				ieee80211_tpt_led_trig_rx(mphy->hw, rx_bytes);
 			}
 			break;
 		case UNI_ALL_STA_TXRX_MSDU_COUNT:
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 5/6] wifi: mac80211: export ieee80211_tpt_led_trig_tx/rx for driver
  2023-08-25 17:47 ` [PATCH 5/6] wifi: mac80211: export ieee80211_tpt_led_trig_tx/rx for driver Yi-Chia Hsieh
@ 2023-08-25 18:08   ` Jeff Johnson
  2023-08-28 18:03     ` Ryder Lee
  2023-08-29  6:36   ` Kalle Valo
  1 sibling, 1 reply; 9+ messages in thread
From: Jeff Johnson @ 2023-08-25 18:08 UTC (permalink / raw)
  To: Yi-Chia Hsieh, Felix Fietkau, Johannes Berg
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai, Money Wang,
	Peter Chiu, Benjamin Lin, linux-wireless, linux-mediatek

On 8/25/2023 10:47 AM, Yi-Chia Hsieh wrote:
> Whenever the H/W path is enabled and traffic is in the binding state,
> mac80211 is not aware of the traffic. Consequently, the LED does not
> blink for that reason.
> 
> The ieee80211_tpt_led_trig_tx/rx functions are exported for the driver
> so that we can report the tx and rx bytes from the driver when
> the H/W path is being used.
> 
> Signed-off-by: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
> ---
>   include/net/mac80211.h | 17 +++++++++++++++++
>   net/mac80211/led.c     | 18 ++++++++++++++++++
>   net/mac80211/led.h     | 18 ------------------
>   net/mac80211/rx.c      |  2 +-
>   net/mac80211/tx.c      |  4 ++--
>   5 files changed, 38 insertions(+), 21 deletions(-)
> 
> diff --git a/include/net/mac80211.h b/include/net/mac80211.h
> index 3a8a2d2c58c3..53804822dc8d 100644
> --- a/include/net/mac80211.h
> +++ b/include/net/mac80211.h
> @@ -4729,6 +4729,8 @@ __ieee80211_create_tpt_led_trigger(struct ieee80211_hw *hw,
>   				   unsigned int flags,
>   				   const struct ieee80211_tpt_blink *blink_table,
>   				   unsigned int blink_table_len);
> +void __ieee80211_tpt_led_trig_tx(struct ieee80211_hw *hw, int bytes);
> +void __ieee80211_tpt_led_trig_rx(struct ieee80211_hw *hw, int bytes);

suggest these should be in led.h since they are local to mac80211 and 
should not be directly invoked by clients of mac80211

>   #endif
>   /**
>    * ieee80211_get_tx_led_name - get name of TX LED
> @@ -4839,6 +4841,21 @@ ieee80211_create_tpt_led_trigger(struct ieee80211_hw *hw, unsigned int flags,
>   #endif
>   }
>   
> +static inline void
> +ieee80211_tpt_led_trig_tx(struct ieee80211_hw *hw, int bytes)
> +{
> +#ifdef CPTCFG_MAC80211_LEDS

why isn't this using CONFIG_MAC80211_LEDS??

> +	__ieee80211_tpt_led_trig_tx(hw, bytes);
> +#endif
> +}
> +
> +static inline void
> +ieee80211_tpt_led_trig_rx(struct ieee80211_hw *hw, int bytes)
> +{
> +#ifdef CPTCFG_MAC80211_LEDS
> +	__ieee80211_tpt_led_trig_rx(hw, bytes);
> +#endif
> +}
>   /**
>    * ieee80211_unregister_hw - Unregister a hardware device
>    *
> diff --git a/net/mac80211/led.c b/net/mac80211/led.c
> index 2dc732147e85..af03a2ef5c6a 100644
> --- a/net/mac80211/led.c
> +++ b/net/mac80211/led.c
> @@ -319,6 +319,24 @@ __ieee80211_create_tpt_led_trigger(struct ieee80211_hw *hw,
>   }
>   EXPORT_SYMBOL(__ieee80211_create_tpt_led_trigger);
>   
> +void __ieee80211_tpt_led_trig_tx(struct ieee80211_hw *hw, int bytes)
> +{
> +	struct ieee80211_local *local = hw_to_local(hw);
> +
> +	if (atomic_read(&local->tpt_led_active))
> +		local->tpt_led_trigger->tx_bytes += bytes;
> +}
> +EXPORT_SYMBOL(__ieee80211_tpt_led_trig_tx);
> +
> +void __ieee80211_tpt_led_trig_rx(struct ieee80211_hw *hw, int bytes)
> +{
> +	struct ieee80211_local *local = hw_to_local(hw);
> +
> +	if (atomic_read(&local->tpt_led_active))
> +		local->tpt_led_trigger->rx_bytes += bytes;
> +}
> +EXPORT_SYMBOL(__ieee80211_tpt_led_trig_rx);
> +

why are you making these exported implementations instead of keeping 
them as inline in led.h?

>   static void ieee80211_start_tpt_led_trig(struct ieee80211_local *local)
>   {
>   	struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
> diff --git a/net/mac80211/led.h b/net/mac80211/led.h
> index d25f13346b82..98db4356d0de 100644
> --- a/net/mac80211/led.h
> +++ b/net/mac80211/led.h
> @@ -66,21 +66,3 @@ static inline void ieee80211_mod_tpt_led_trig(struct ieee80211_local *local,
>   {
>   }
>   #endif
> -
> -static inline void
> -ieee80211_tpt_led_trig_tx(struct ieee80211_local *local, int bytes)
> -{
> -#ifdef CONFIG_MAC80211_LEDS
> -	if (atomic_read(&local->tpt_led_active))
> -		local->tpt_led_trigger->tx_bytes += bytes;
> -#endif
> -}
> -
> -static inline void
> -ieee80211_tpt_led_trig_rx(struct ieee80211_local *local, int bytes)
> -{
> -#ifdef CONFIG_MAC80211_LEDS
> -	if (atomic_read(&local->tpt_led_active))
> -		local->tpt_led_trigger->rx_bytes += bytes;
> -#endif
> -}
> diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
> index 4f707d2a160f..5747d7dac4d7 100644
> --- a/net/mac80211/rx.c
> +++ b/net/mac80211/rx.c
> @@ -5375,7 +5375,7 @@ void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
>   	if (skb) {
>   		if ((status->flag & RX_FLAG_8023) ||
>   			ieee80211_is_data_present(hdr->frame_control))
> -			ieee80211_tpt_led_trig_rx(local, skb->len);
> +			ieee80211_tpt_led_trig_rx(&local->hw, skb->len);

what is the rationale for changing the signature, especially given that 
the first thing the implementations do is local = hw_to_local(hw)

>   
>   		if (status->flag & RX_FLAG_8023)
>   			__ieee80211_rx_handle_8023(hw, pubsta, skb, list);
> diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
> index 7fe7280e8437..234de8d3b8bb 100644
> --- a/net/mac80211/tx.c
> +++ b/net/mac80211/tx.c
> @@ -4320,7 +4320,7 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb,
>   	len = 0;
>    out:
>   	if (len)
> -		ieee80211_tpt_led_trig_tx(local, len);
> +		ieee80211_tpt_led_trig_tx(&local->hw, len);
>   	rcu_read_unlock();
>   }
>   
> @@ -4646,7 +4646,7 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
>   	sta->deflink.tx_stats.packets[queue] += skbs;
>   	sta->deflink.tx_stats.bytes[queue] += len;
>   
> -	ieee80211_tpt_led_trig_tx(local, len);
> +	ieee80211_tpt_led_trig_tx(&local->hw, len);
>   
>   	ieee80211_tx_8023(sdata, skb, sta, false);
>   



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 5/6] wifi: mac80211: export ieee80211_tpt_led_trig_tx/rx for driver
  2023-08-25 18:08   ` Jeff Johnson
@ 2023-08-28 18:03     ` Ryder Lee
  0 siblings, 0 replies; 9+ messages in thread
From: Ryder Lee @ 2023-08-28 18:03 UTC (permalink / raw)
  To: Yi-Chia Hsieh, nbd@nbd.name, quic_jjohnson@quicinc.com,
	johannes.berg@intel.com
  Cc: Evelyn Tsai (蔡珊鈺),
	linux-mediatek@lists.infradead.org,
	Shayne Chen (陳軒丞),
	Money Wang (王信安),
	Chui-hao Chiu (邱垂浩),
	Benjamin-jw Lin (林津緯),
	lorenzo.bianconi@redhat.com, linux-wireless@vger.kernel.org

On Fri, 2023-08-25 at 11:08 -0700, Jeff Johnson wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  On 8/25/2023 10:47 AM, Yi-Chia Hsieh wrote:
> > Whenever the H/W path is enabled and traffic is in the binding
> state,
> > mac80211 is not aware of the traffic. Consequently, the LED does
> not
> > blink for that reason.
> > 
> > The ieee80211_tpt_led_trig_tx/rx functions are exported for the
> driver
> > so that we can report the tx and rx bytes from the driver when
> > the H/W path is being used.
> > 
> > Signed-off-by: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
> > ---
> >   include/net/mac80211.h | 17 +++++++++++++++++
> >   net/mac80211/led.c     | 18 ++++++++++++++++++
> >   net/mac80211/led.h     | 18 ------------------
> >   net/mac80211/rx.c      |  2 +-
> >   net/mac80211/tx.c      |  4 ++--
> >   5 files changed, 38 insertions(+), 21 deletions(-)
> > 
> > diff --git a/include/net/mac80211.h b/include/net/mac80211.h
> > index 3a8a2d2c58c3..53804822dc8d 100644
> > --- a/include/net/mac80211.h
> > +++ b/include/net/mac80211.h
> > @@ -4729,6 +4729,8 @@ __ieee80211_create_tpt_led_trigger(struct
> ieee80211_hw *hw,
> >      unsigned int flags,
> >      const struct ieee80211_tpt_blink *blink_table,
> >      unsigned int blink_table_len);
> > +void __ieee80211_tpt_led_trig_tx(struct ieee80211_hw *hw, int
> bytes);
> > +void __ieee80211_tpt_led_trig_rx(struct ieee80211_hw *hw, int
> bytes);
> 
> suggest these should be in led.h since they are local to mac80211
> and 
> should not be directly invoked by clients of mac80211
> 
> >   #endif
> >   /**
> >    * ieee80211_get_tx_led_name - get name of TX LED
> > @@ -4839,6 +4841,21 @@ ieee80211_create_tpt_led_trigger(struct
> ieee80211_hw *hw, unsigned int flags,
> >   #endif
> >   }
> >   
> > +static inline void
> > +ieee80211_tpt_led_trig_tx(struct ieee80211_hw *hw, int bytes)
> > +{
> > +#ifdef CPTCFG_MAC80211_LEDS
> 
> why isn't this using CONFIG_MAC80211_LEDS??
> 

Will fix.
> > +__ieee80211_tpt_led_trig_tx(hw, bytes);
> > +#endif
> > +}
> > +
> > +static inline void
> > +ieee80211_tpt_led_trig_rx(struct ieee80211_hw *hw, int bytes)
> > +{
> > +#ifdef CPTCFG_MAC80211_LEDS
> > +__ieee80211_tpt_led_trig_rx(hw, bytes);
> > +#endif
> > +}
> >   /**
> >    * ieee80211_unregister_hw - Unregister a hardware device
> >    *
> > diff --git a/net/mac80211/led.c b/net/mac80211/led.c
> > index 2dc732147e85..af03a2ef5c6a 100644
> > --- a/net/mac80211/led.c
> > +++ b/net/mac80211/led.c
> > @@ -319,6 +319,24 @@ __ieee80211_create_tpt_led_trigger(struct
> ieee80211_hw *hw,
> >   }
> >   EXPORT_SYMBOL(__ieee80211_create_tpt_led_trigger);
> >   
> > +void __ieee80211_tpt_led_trig_tx(struct ieee80211_hw *hw, int
> bytes)
> > +{
> > +struct ieee80211_local *local = hw_to_local(hw);
> > +
> > +if (atomic_read(&local->tpt_led_active))
> > +local->tpt_led_trigger->tx_bytes += bytes;
> > +}
> > +EXPORT_SYMBOL(__ieee80211_tpt_led_trig_tx);
> > +
> > +void __ieee80211_tpt_led_trig_rx(struct ieee80211_hw *hw, int
> bytes)
> > +{
> > +struct ieee80211_local *local = hw_to_local(hw);
> > +
> > +if (atomic_read(&local->tpt_led_active))
> > +local->tpt_led_trigger->rx_bytes += bytes;
> > +}
> > +EXPORT_SYMBOL(__ieee80211_tpt_led_trig_rx);
> > +
> 
> why are you making these exported implementations instead of keeping 
> them as inline in led.h?
> 

We thought so. However, led.c has many same exported implementations,
including the local functions you suggested above. i.e.
__ieee80211_get_assoc_led_name() For the sake of consistency, we just
copy-pasted one of those functions. Do you want us to change this?

> >   static void ieee80211_start_tpt_led_trig(struct ieee80211_local
> *local)
> >   {
> >   struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
> > diff --git a/net/mac80211/led.h b/net/mac80211/led.h
> > index d25f13346b82..98db4356d0de 100644
> > --- a/net/mac80211/led.h
> > +++ b/net/mac80211/led.h
> > @@ -66,21 +66,3 @@ static inline void
> ieee80211_mod_tpt_led_trig(struct ieee80211_local *local,
> >   {
> >   }
> >   #endif
> > -
> > -static inline void
> > -ieee80211_tpt_led_trig_tx(struct ieee80211_local *local, int
> bytes)
> > -{
> > -#ifdef CONFIG_MAC80211_LEDS
> > -if (atomic_read(&local->tpt_led_active))
> > -local->tpt_led_trigger->tx_bytes += bytes;
> > -#endif
> > -}
> > -
> > -static inline void
> > -ieee80211_tpt_led_trig_rx(struct ieee80211_local *local, int
> bytes)
> > -{
> > -#ifdef CONFIG_MAC80211_LEDS
> > -if (atomic_read(&local->tpt_led_active))
> > -local->tpt_led_trigger->rx_bytes += bytes;
> > -#endif
> > -}
> > diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
> > index 4f707d2a160f..5747d7dac4d7 100644
> > --- a/net/mac80211/rx.c
> > +++ b/net/mac80211/rx.c
> > @@ -5375,7 +5375,7 @@ void ieee80211_rx_list(struct ieee80211_hw
> *hw, struct ieee80211_sta *pubsta,
> >   if (skb) {
> >   if ((status->flag & RX_FLAG_8023) ||
> >   ieee80211_is_data_present(hdr->frame_control))
> > -ieee80211_tpt_led_trig_rx(local, skb->len);
> > +ieee80211_tpt_led_trig_rx(&local->hw, skb->len);
> 
> what is the rationale for changing the signature, especially given
> that 
> the first thing the implementations do is local = hw_to_local(hw)
> 

We want to make ieee80211_tpt_led_trig_rx() more generic so that it can
be called by driver as what he did in patch 6/6. But the
ieee80211_local can't be accessed other than mac80211 so he made this
change to use ieee80211_hw instead. Does that make sense?

Ryder

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 5/6] wifi: mac80211: export ieee80211_tpt_led_trig_tx/rx for driver
  2023-08-25 17:47 ` [PATCH 5/6] wifi: mac80211: export ieee80211_tpt_led_trig_tx/rx for driver Yi-Chia Hsieh
  2023-08-25 18:08   ` Jeff Johnson
@ 2023-08-29  6:36   ` Kalle Valo
  1 sibling, 0 replies; 9+ messages in thread
From: Kalle Valo @ 2023-08-29  6:36 UTC (permalink / raw)
  To: Yi-Chia Hsieh
  Cc: Felix Fietkau, Johannes Berg, Lorenzo Bianconi, Ryder Lee,
	Shayne Chen, Evelyn Tsai, Money Wang, Peter Chiu, Benjamin Lin,
	linux-wireless, linux-mediatek

Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com> writes:

> Whenever the H/W path is enabled and traffic is in the binding state,
> mac80211 is not aware of the traffic. Consequently, the LED does not
> blink for that reason.
>
> The ieee80211_tpt_led_trig_tx/rx functions are exported for the driver
> so that we can report the tx and rx bytes from the driver when
> the H/W path is being used.
>
> Signed-off-by: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
> ---
>  include/net/mac80211.h | 17 +++++++++++++++++
>  net/mac80211/led.c     | 18 ++++++++++++++++++
>  net/mac80211/led.h     | 18 ------------------
>  net/mac80211/rx.c      |  2 +-
>  net/mac80211/tx.c      |  4 ++--
>  5 files changed, 38 insertions(+), 21 deletions(-)

The mac80211 patch should be first in the patchset to get more
visibility.

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

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-08-29  6:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-25 17:47 [PATCH 1/6] wifi: mt76: mt7996: get tx_retries and tx_failed from txfree Yi-Chia Hsieh
2023-08-25 17:47 ` [PATCH 2/6] wifi: mt76: mt7996: Add mcu commands for getting sta tx statistic Yi-Chia Hsieh
2023-08-25 17:47 ` [PATCH 3/6] wifi: mt76: mt7996: enable PPDU-TxS to host Yi-Chia Hsieh
2023-08-25 17:47 ` [PATCH 4/6] wifi: mt76: mt7996: remove periodic MPDU TXS request Yi-Chia Hsieh
2023-08-25 17:47 ` [PATCH 5/6] wifi: mac80211: export ieee80211_tpt_led_trig_tx/rx for driver Yi-Chia Hsieh
2023-08-25 18:08   ` Jeff Johnson
2023-08-28 18:03     ` Ryder Lee
2023-08-29  6:36   ` Kalle Valo
2023-08-25 17:47 ` [PATCH 6/6] wifi: mt76: report per-phy tx and rx byte to tpt_led Yi-Chia Hsieh

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).