Skip to contentSkip to conversation

wifi: mt76: mt7996: add debugging for MCU command timeouts.

PATCH New [email protected] 1 participant 6 messages Mar 7, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 wifi: mt76: mt7996: add debugging for MCU command timeouts.

From: Ben Greear <[email protected]>

Print information about whether the message is the first timeout, and also print info if we manage to recover after a timeout.

---
 drivers/net/wireless/mediatek/mt76/mt76.h     |  2 ++
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   | 31 +++++++++++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76.h +2 -0
index b20c34d5a0f7..c341915e4d62 100644
@@ -829,6 +829,8 @@ struct mt76_dev {
 	struct device *dma_dev;
 
 	struct mt76_mcu mcu;
+	u32 first_failed_mcu_cmd; /* for debugging */
+	u32 last_successful_mcu_cmd; /* for debugging */
 
 	struct net_device napi_dev;
 	struct net_device tx_napi_dev;
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +28 -3
index 699be57309c2..a858a0914bf0 100644
@@ -200,14 +200,39 @@ mt7996_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 	int ret = 0;
 
 	if (!skb) {
-		dev_err(mdev->dev, "Message %08x (seq %d) timeout\n",
-			cmd, seq);
+		const char *first = "Secondary";
+
+		if (!mdev->first_failed_mcu_cmd)
+			first = "Initial";
+
+		dev_err(mdev->dev,
+			"MCU: %s Failure: Message %08x (cid %lx ext_cid: %lx seq %d) timeout.  Last successful cmd: 0x%x\n",
+			first,
+			cmd, FIELD_GET(__MCU_CMD_FIELD_ID, cmd),
+			FIELD_GET(__MCU_CMD_FIELD_EXT_ID, cmd), seq,
+			mdev->last_successful_mcu_cmd);
+
+		if (!mdev->first_failed_mcu_cmd)
+			mdev->first_failed_mcu_cmd = cmd;
 		return -ETIMEDOUT;
 	}
 
+	mdev->last_successful_mcu_cmd = cmd;
+
+	if (mdev->first_failed_mcu_cmd) {
+		dev_err(mdev->dev, "MCU: First success after failure: Message %08x (cid %lx ext_cid: %lx seq %d)\n",
+			cmd, FIELD_GET(__MCU_CMD_FIELD_ID, cmd),
+			FIELD_GET(__MCU_CMD_FIELD_EXT_ID, cmd), seq);
+		mdev->first_failed_mcu_cmd = 0;
+	}
+
 	rxd = (struct mt7996_mcu_rxd *)skb->data;
-	if (seq != rxd->seq)
+	if (seq != rxd->seq) {
+		/* This can happen if the previous request didn't wait (which is normal).
+		 * Quietly return EAGAIN in that case, it is not something to warn about.
+		 */
 		return -EAGAIN;
+	}
 
 	if (cmd == MCU_CMD(PATCH_SEM_CONTROL)) {
 		skb_pull(skb, sizeof(*rxd) - 4);
Signature · 1 line
2.42.0
#1 lore raw

PATCH 2/6 wifi: mt76: mt7996: add configured logging

From: Ben Greear <[email protected]>

Allow module param and debugfs to configure a debug level to allow adding more debug logic that is only enabled when needed.

Similar to how ath10k and iwlwifi work in this regard.

---
 drivers/net/wireless/mediatek/mt76/debugfs.c  | 24 ++++++++++++++++
 drivers/net/wireless/mediatek/mt76/mt76.h     | 17 +++++++++++
 .../net/wireless/mediatek/mt76/mt7996/init.c  |  3 ++
 .../net/wireless/mediatek/mt76/mt7996/mac.c   | 28 +++++++++++++++++--
 .../net/wireless/mediatek/mt76/mt7996/main.c  | 18 ++++++++++++
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   |  4 +++
 6 files changed, 92 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/debugfs.c +24 -0
index ae83be572b94..bc16c3257540 100644
@@ -100,6 +100,29 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
 }
 EXPORT_SYMBOL_GPL(mt76_seq_puts_array);
 
+static int
+mt76_debug_lvl_set(void *data, u64 val)
+{
+	struct mt76_dev *dev = data;
+
+	dev->debug_lvl = val;
+
+	return 0;
+}
+
+static int
+mt76_debug_lvl_get(void *data, u64 *val)
+{
+	struct mt76_dev *dev = data;
+
+	*val = dev->debug_lvl;
+
+	return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_debug_lvl, mt76_debug_lvl_get,
+			 mt76_debug_lvl_set, "%lld\n");
+
 struct dentry *
 mt76_register_debugfs_fops(struct mt76_phy *phy,
 			   const struct file_operations *ops)
@@ -115,6 +138,7 @@ mt76_register_debugfs_fops(struct mt76_phy *phy,
 	debugfs_create_file_unsafe("regval", 0600, dir, dev, fops);
 	debugfs_create_file_unsafe("napi_threaded", 0600, dir, dev,
 				   &fops_napi_threaded);
+	debugfs_create_file("debug_lvl", 0600, dir, dev, &fops_debug_lvl);
 	debugfs_create_blob("eeprom", 0400, dir, &dev->eeprom);
 	if (dev->otp.data)
 		debugfs_create_blob("otp", 0400, dir, &dev->otp);
drivers/net/wireless/mediatek/mt76/mt76.h +17 -0
index c341915e4d62..dd8a24cda48a 100644
@@ -815,6 +815,7 @@ struct mt76_dev {
 	spinlock_t cc_lock;
 
 	u32 cur_cc_bss_rx;
+	u32 debug_lvl;
 
 	struct mt76_rx_status rx_ampdu_status;
 	u32 rx_ampdu_len;
@@ -1004,6 +1005,22 @@ struct mt76_mib_stats {
 	u32 ul_hetrig_4mu_cnt;
 };
 
+enum MTK_DEUBG {
+	MTK_DEBUG_TX		= 0x00000001, /* tx path */
+	MTK_DEBUG_TXV		= 0x00000002, /* verbose tx path */
+	MTK_DEBUG_FATAL		= 0x00000004,
+	MTK_DEBUG_WRN		= 0x00000008,
+	MTK_DEBUG_MSG		= 0x00000010, /* messages to/from firmware */
+	MTK_DEBUG_CFG		= 0x00000020, /* Configuration related */
+	MTK_DEBUG_ANY		= 0xffffffff
+};
+
+#define mtk_dbg(mt76, dbg_mask, fmt, ...)				\
+	do {								\
+		if ((mt76)->debug_lvl & MTK_DEBUG_##dbg_mask)		\
+			dev_info((mt76)->dev, fmt, ##__VA_ARGS__); \
+	} while (0)
+
 struct mt76_power_limits {
 	s8 cck[4];
 	s8 ofdm[8];
drivers/net/wireless/mediatek/mt76/mt7996/init.c +3 -0
index 0cf0d1fe420a..d3b72fb73c30 100644
@@ -14,6 +14,8 @@
 #include "coredump.h"
 #include "eeprom.h"
 
+extern u32 debug_lvl; /* module param */
+
 static const struct ieee80211_iface_limit if_limits[] = {
 	{
 		.max = 1,
@@ -1309,6 +1311,7 @@ int mt7996_register_device(struct mt7996_dev *dev)
 	dev->phy.dev = dev;
 	dev->phy.mt76 = &dev->mt76.phy;
 	dev->mt76.phy.priv = &dev->phy;
+	dev->mt76.debug_lvl = debug_lvl;
 	INIT_WORK(&dev->rc_work, mt7996_mac_sta_rc_work);
 	INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7996_mac_work);
 	INIT_LIST_HEAD(&dev->sta_rc_list);
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +26 -2
index 53258488d49f..9b4637867354 100644
@@ -923,6 +923,9 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
 	bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
 	u8 *txwi = (u8 *)txwi_ptr;
 
+	mtk_dbg(&dev->mt76, TXV, "mt7996-tx-prepare-skb, skb-len: %d\n",
+		tx_info->skb->len);
+
 	if (unlikely(tx_info->skb->len <= ETH_HLEN))
 		return -EINVAL;
 
@@ -933,8 +936,11 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
 	t->skb = tx_info->skb;
 
 	id = mt76_token_consume(mdev, &t);
-	if (id < 0)
+	if (id < 0) {
+		mtk_dbg(&dev->mt76, TXV, "mt7996-tx-prepare-skb, token_consume error: %d\n",
+			id);
 		return id;
+	}
 
 	pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb);
 	mt7996_mac_write_txwi(dev, txwi_ptr, tx_info->skb, wcid, key,
@@ -1124,6 +1130,9 @@ mt7996_mac_tx_free(struct mt7996_dev *dev, void *data, int len)
 			idx = FIELD_GET(MT_TXFREE_INFO_WLAN_ID, info);
 			wcid = rcu_dereference(dev->mt76.wcid[idx]);
 			sta = wcid_to_sta(wcid);
+
+			mtk_dbg(mdev, TXV, "mt7996-mac-tx-free, new wcid pair, idx: %d sta: %p wcid: %p\n",
+				idx, sta, wcid);
 			if (!sta)
 				continue;
 
@@ -1157,8 +1166,14 @@ mt7996_mac_tx_free(struct mt7996_dev *dev, void *data, int len)
 
 			count++;
 			txwi = mt76_token_release(mdev, msdu, &wake);
-			if (!txwi)
+
+			mtk_dbg(mdev, TXV, "mt7996-mac-tx-free, msdu: %d, count: %d/%d\n",
+				msdu, count, total);
+
+			if (!txwi) {
+				WARN_ON_ONCE(1);
 				continue;
+			}
 
 			mt7996_txwi_free(dev, txwi, sta, &free_list);
 		}
@@ -1333,6 +1348,9 @@ static void mt7996_mac_add_txs(struct mt7996_dev *dev, void *data)
 	u16 wcidx;
 	u8 pid;
 
+	mtk_dbg(&dev->mt76, TX, "mt7996-mac-add-txs, format: %d\n",
+		le32_get_bits(txs_data[0], MT_TXS0_TXS_FORMAT));
+
 	wcidx = le32_get_bits(txs_data[2], MT_TXS2_WCID);
 	pid = le32_get_bits(txs_data[3], MT_TXS3_PID);
 
@@ -1391,7 +1409,12 @@ bool mt7996_rx_check(struct mt76_dev *mdev, void *data, int len)
 	case PKT_TYPE_RX_FW_MONITOR:
 		mt7996_debugfs_rx_fw_monitor(dev, data, len);
 		return false;
+	case PKT_TYPE_RX_EVENT:
+	case PKT_TYPE_NORMAL:
+		/* These are handled elsewhere, do not warn about them. */
+		return true;
 	default:
+		mtk_dbg(mdev, MSG, "mt7996-rx-check, pkt-type: %d not handled.\n", type);
 		return true;
 	}
 }
@@ -1443,6 +1466,7 @@ void mt7996_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
 		}
 		fallthrough;
 	default:
+		mtk_dbg(mdev, MSG, "mt7996-mac-queue-rx-skb, unhandled type: %d\n", type);
 		dev_kfree_skb(skb);
 		break;
 	}
drivers/net/wireless/mediatek/mt76/mt7996/main.c +18 -0
index 51deea84b642..f9a8a60a947e 100644
@@ -7,6 +7,19 @@
 #include "mcu.h"
 #include "mac.h"
 
+u32 debug_lvl = MTK_DEBUG_FATAL | MTK_DEBUG_WRN;
+module_param(debug_lvl, uint, 0644);
+MODULE_PARM_DESC(debug_lvl,
+		 "Enable debugging messages\n"
+		 "0x00001	tx path\n"
+		 "0x00002	tx path verbose\n"
+		 "0x00004	fatal/very-important messages\n"
+		 "0x00008	warning messages\n"
+		 "0x00010	Info about messages to/from firmware\n"
+		 "0x00020	Configuration logs.\n"
+		 "0xffffffff	any/all\n"
+	);
+
 static bool mt7996_dev_running(struct mt7996_dev *dev)
 {
 	struct mt7996_phy *phy;
@@ -76,6 +89,8 @@ static int mt7996_start(struct ieee80211_hw *hw)
 	struct mt7996_dev *dev = mt7996_hw_dev(hw);
 	int ret;
 
+	dev->mt76.debug_lvl = debug_lvl;
+
 	flush_work(&dev->init_work);
 
 	mutex_lock(&dev->mt76.mutex);
@@ -739,6 +754,9 @@ static void mt7996_tx(struct ieee80211_hw *hw,
 		wcid = &mvif->sta.wcid;
 	}
 
+	mtk_dbg(&dev->mt76, TXV, "mt7996-tx, wcid: %d\n",
+		wcid->idx);
+
 	mt76_tx(mphy, control->sta, wcid, skb);
 }
 
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +4 -0
index a858a0914bf0..5550671cdaf6 100644
@@ -616,11 +616,15 @@ mt7996_mcu_rx_ext_event(struct mt7996_dev *dev, struct sk_buff *skb)
 {
 	struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data;
 
+	mtk_dbg(&dev->mt76, MSG, "mt7996-mcu-rx-ext-event, ext-eid: %d\n", rxd->ext_eid);
+
 	switch (rxd->ext_eid) {
 	case MCU_EXT_EVENT_FW_LOG_2_HOST:
 		mt7996_mcu_rx_log_message(dev, skb);
 		break;
 	default:
+		/* in SDK, grep for EventExtEventHandler */
+		mtk_dbg(&dev->mt76, WRN, "mt7996, unhandled rx_ext_event: 0x%x", rxd->ext_eid);
 		break;
 	}
 }
Signature · 1 line
2.42.0
#2 lore raw

PATCH 3/6 wifi: mt76: mt7996: Enable spectrum management hw flag.

In reply to [email protected]

From: Ben Greear <[email protected]>

This hardware does appear to support changing txpower dynamically.

---
 drivers/net/wireless/mediatek/mt76/mt7996/init.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +1 -0
index d3b72fb73c30..494679a412cf 100644
@@ -402,6 +402,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
 	ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD);
 	ieee80211_hw_set(hw, WANT_MONITOR_VIF);
 	ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
+	ieee80211_hw_set(hw, SPECTRUM_MGMT);
 
 	hw->max_tx_fragments = 4;
 
Signature · 1 line
2.42.0
#3 lore raw

PATCH 4/6 wifi: mt76: mt7915: Mitigate mcu communication loss.

In reply to [email protected]

From: Ben Greear <[email protected]>

Many calls that end up sending mcu messages to the firmware hold RTNL or other important locks. So when radio stops answering, the entire system becomes very sluggish.

Add timeout counter, and if radio times out 3 times in a row, consider it dead and no longer attempt to talk to it.

---
 drivers/net/wireless/mediatek/mt76/dma.c        | 14 ++++++++++++++
 drivers/net/wireless/mediatek/mt76/mt76.h       |  3 +++
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c |  2 ++
 3 files changed, 19 insertions(+)
drivers/net/wireless/mediatek/mt76/dma.c +14 -0
index 00230f106294..4d1426093e1e 100644
@@ -510,6 +510,20 @@ mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q,
 	if (test_bit(MT76_MCU_RESET, &dev->phy.state))
 		goto error;
 
+	/* Check for non responsive radios.  Better to just stop sending it messages
+	 * than continuously block the OS (since rtnl and similar are often held while
+	 * the timeout is happening).
+	 */
+	if (dev->mcu_timeouts > MAX_MCU_TIMEOUTS) {
+		static unsigned long last_log;
+
+		if (time_after(jiffies, last_log + 5 * HZ)) {
+			last_log = jiffies;
+			mtk_dbg(dev, WRN, "mt76-dma-tx-queue-skb-raw, too many timeouts, msg is dropped.\n");
+		}
+		goto error;
+	}
+
 	if (q->queued + 1 >= q->ndesc - 1)
 		goto error;
 
drivers/net/wireless/mediatek/mt76/mt76.h +3 -0
index dd8a24cda48a..b052a9c24c73 100644
@@ -832,6 +832,9 @@ struct mt76_dev {
 	struct mt76_mcu mcu;
 	u32 first_failed_mcu_cmd; /* for debugging */
 	u32 last_successful_mcu_cmd; /* for debugging */
+	u32 mcu_timeouts; /* sequential timeout counter */
+	#define MAX_MCU_TIMEOUTS 3
+
 
 	struct net_device napi_dev;
 	struct net_device tx_napi_dev;
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +2 -0
index c67c4f6ca2aa..f3e60fba48b2 100644
@@ -161,11 +161,13 @@ mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 	int ret = 0;
 
 	if (!skb) {
+		mdev->mcu_timeouts++;
 		dev_err(mdev->dev, "Message %08x (seq %d) timeout\n",
 			cmd, seq);
 		return -ETIMEDOUT;
 	}
 
+	mdev->mcu_timeouts = 0;
 	rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
 	if (seq != rxd->seq &&
 	    !(rxd->eid == MCU_CMD_EXT_CID &&
Signature · 1 line
2.42.0
#4 lore raw

PATCH 5/6 wifi: mt76: mt7996: Mitigate mcu communication loss.

In reply to [email protected]

From: Ben Greear <[email protected]>

Many calls that end up sending mcu messages to the firmware hold RTNL or other important locks. So when radio stops answering, the entire system becomes very sluggish.

Add timeout counter, and if radio times out 3 times in a row, consider it dead and no longer attempt to talk to it.

---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +4 -1
index 5550671cdaf6..77c89d2d2423 100644
@@ -202,14 +202,16 @@ mt7996_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 	if (!skb) {
 		const char *first = "Secondary";
 
+		mdev->mcu_timeouts++;
 		if (!mdev->first_failed_mcu_cmd)
 			first = "Initial";
 
 		dev_err(mdev->dev,
-			"MCU: %s Failure: Message %08x (cid %lx ext_cid: %lx seq %d) timeout.  Last successful cmd: 0x%x\n",
+			"MCU: %s Failure: Message %08x (cid %lx ext_cid: %lx seq %d) timeout (%d/%d).  Last successful cmd: 0x%x\n",
 			first,
 			cmd, FIELD_GET(__MCU_CMD_FIELD_ID, cmd),
 			FIELD_GET(__MCU_CMD_FIELD_EXT_ID, cmd), seq,
+			mdev->mcu_timeouts, MAX_MCU_TIMEOUTS,
 			mdev->last_successful_mcu_cmd);
 
 		if (!mdev->first_failed_mcu_cmd)
@@ -217,6 +219,7 @@ mt7996_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 		return -ETIMEDOUT;
 	}
 
+	mdev->mcu_timeouts = 0;
 	mdev->last_successful_mcu_cmd = cmd;
 
 	if (mdev->first_failed_mcu_cmd) {
Signature · 1 line
2.42.0
#5 lore raw

PATCH 6/6 wifi: mt76: mt7996: Allow ignoring radar events.

In reply to [email protected]

From: Ben Greear <[email protected]>

Useful for testing.

---
 .../net/wireless/mediatek/mt76/mt7996/debugfs.c    |  2 ++
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c    | 14 ++++++++------
 drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h |  1 +
 3 files changed, 11 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c +2 -0
index 9bd953586b04..39008274b493 100644
@@ -806,6 +806,8 @@ int mt7996_init_debugfs(struct mt7996_phy *phy)
 	debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
 				    mt7996_twt_stats);
 	debugfs_create_file("rf_regval", 0600, dir, dev, &fops_rf_regval);
+	debugfs_create_u32("ignore_radar", 0600, dir,
+			   &dev->ignore_radar);
 
 	if (phy->mt76->cap.has_5ghz) {
 		debugfs_create_u32("dfs_hw_pattern", 0400, dir,
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +8 -6
index 77c89d2d2423..c31fd2ea18ea 100644
@@ -391,12 +391,14 @@ mt7996_mcu_rx_radar_detected(struct mt7996_dev *dev, struct sk_buff *skb)
 	if (!mphy)
 		return;
 
-	if (r->band_idx == MT_RX_SEL2)
-		cfg80211_background_radar_event(mphy->hw->wiphy,
-						&dev->rdd2_chandef,
-						GFP_ATOMIC);
-	else
-		ieee80211_radar_detected(mphy->hw);
+	if (!dev->ignore_radar) {
+		if (r->band_idx == MT_RX_SEL2)
+			cfg80211_background_radar_event(mphy->hw->wiphy,
+							&dev->rdd2_chandef,
+							GFP_ATOMIC);
+		else
+			ieee80211_radar_detected(mphy->hw);
+	}
 	dev->hw_pattern++;
 }
 
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +1 -0
index bc73bcb47bf0..8b5eb6e3807f 100644
@@ -286,6 +286,7 @@ struct mt7996_dev {
 	struct list_head twt_list;
 
 	u32 hw_pattern;
+	u32 ignore_radar; /* skip propagating up the stack, for debugging */
 
 	bool flash_mode:1;
 	bool has_eht:1;
Signature · 1 line
2.42.0