blob: b753114f6ef67783a21b8b572a386c82f07f4222 [file] [log] [blame]
developerd0c89452024-10-11 16:53:27 +08001From e126a0d9cd5d6a25caf5db58a5cc5edb6b22cc16 Mon Sep 17 00:00:00 2001
developer05f3b2b2024-08-19 19:17:34 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Thu, 13 Jun 2024 17:47:13 +0800
developerd0c89452024-10-11 16:53:27 +08004Subject: [PATCH 152/223] mtk: mt76: add debugfs for tx drop counters
developer05f3b2b2024-08-19 19:17:34 +08005
developerd0c89452024-10-11 16:53:27 +08006Change-Id: I1d375169cca29fb58544edfbd235ef3e058a130a
developer05f3b2b2024-08-19 19:17:34 +08007Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
8---
9 dma.c | 22 +++++++++---
10 mac80211.c | 2 ++
11 mt76.h | 27 +++++++++++++++
12 mt7996/mac.c | 20 ++++++++---
13 mt7996/main.c | 10 ++++--
14 mt7996/mtk_debugfs.c | 80 ++++++++++++++++++++++++++++++++++++++++++++
15 tx.c | 12 +++++++
16 7 files changed, 161 insertions(+), 12 deletions(-)
17
18diff --git a/dma.c b/dma.c
19index 3f1fb6c2..0dae40e2 100644
20--- a/dma.c
21+++ b/dma.c
22@@ -612,12 +612,16 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,
23 dma_addr_t addr;
24 u8 *txwi;
25
26- if (test_bit(MT76_RESET, &phy->state))
27+ if (test_bit(MT76_RESET, &phy->state)) {
28+ phy->tx_dbg_stats.tx_drop[MT_TX_DROP_RESET_STATE]++;
29 goto free_skb;
30+ }
31
32 t = mt76_get_txwi(dev);
33- if (!t)
34+ if (!t) {
35+ dev->tx_dbg_stats.tx_drop[MT_TX_DROP_GET_TXWI_FAIL]++;
36 goto free_skb;
37+ }
38
39 txwi = mt76_get_txwi_ptr(dev, t);
40
41@@ -627,8 +631,10 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,
42
43 len = skb_headlen(skb);
44 addr = dma_map_single(dev->dma_dev, skb->data, len, DMA_TO_DEVICE);
45- if (unlikely(dma_mapping_error(dev->dma_dev, addr)))
46+ if (unlikely(dma_mapping_error(dev->dma_dev, addr))) {
47+ dev->tx_dbg_stats.tx_drop[MT_TX_DROP_DMA_FAIL]++;
48 goto free;
49+ }
50
51 tx_info.buf[n].addr = t->dma_addr;
52 tx_info.buf[n++].len = dev->drv->txwi_size;
53@@ -636,13 +642,17 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,
54 tx_info.buf[n++].len = len;
55
56 skb_walk_frags(skb, iter) {
57- if (n == ARRAY_SIZE(tx_info.buf))
58+ if (n == ARRAY_SIZE(tx_info.buf)) {
59+ dev->tx_dbg_stats.tx_drop[MT_TX_DROP_AGG_EXCEEDED]++;
60 goto unmap;
61+ }
62
63 addr = dma_map_single(dev->dma_dev, iter->data, iter->len,
64 DMA_TO_DEVICE);
65- if (unlikely(dma_mapping_error(dev->dma_dev, addr)))
66+ if (unlikely(dma_mapping_error(dev->dma_dev, addr))) {
67+ dev->tx_dbg_stats.tx_drop[MT_TX_DROP_DMA_FAIL]++;
68 goto unmap;
69+ }
70
71 tx_info.buf[n].addr = addr;
72 tx_info.buf[n++].len = iter->len;
73@@ -651,6 +661,7 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,
74
75 if (q->queued + (tx_info.nbuf + 1) / 2 >= q->ndesc - 1) {
76 ret = -ENOMEM;
77+ phy->tx_dbg_stats.tx_drop[MT_TX_DROP_RING_FULL]++;
78 goto unmap;
79 }
80
81@@ -662,6 +673,7 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,
82 if (ret < 0)
83 goto unmap;
84
85+ phy->tx_dbg_stats.tx_to_hw++;
86 return mt76_dma_add_buf(dev, q, tx_info.buf, tx_info.nbuf,
87 tx_info.info, tx_info.skb, t);
88
89diff --git a/mac80211.c b/mac80211.c
developerd0c89452024-10-11 16:53:27 +080090index a555bec2..93ff77be 100644
developer05f3b2b2024-08-19 19:17:34 +080091--- a/mac80211.c
92+++ b/mac80211.c
93@@ -417,6 +417,7 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
94
95 INIT_LIST_HEAD(&phy->tx_list);
96 spin_lock_init(&phy->tx_lock);
97+ spin_lock_init(&phy->tx_dbg_stats.lock);
98
99 SET_IEEE80211_DEV(hw, dev->dev);
100 SET_IEEE80211_PERM_ADDR(hw, phy->macaddr);
101@@ -597,6 +598,7 @@ mt76_alloc_device(struct device *pdev, unsigned int size,
102 spin_lock_init(&dev->lock);
103 spin_lock_init(&dev->cc_lock);
104 spin_lock_init(&dev->status_lock);
105+ spin_lock_init(&dev->tx_dbg_stats.lock);
106 mutex_init(&dev->mutex);
107 init_waitqueue_head(&dev->tx_wait);
108
109diff --git a/mt76.h b/mt76.h
developerd0c89452024-10-11 16:53:27 +0800110index 8e71c2ce..8e78ba86 100644
developer05f3b2b2024-08-19 19:17:34 +0800111--- a/mt76.h
112+++ b/mt76.h
developerd0c89452024-10-11 16:53:27 +0800113@@ -849,6 +849,31 @@ struct mt76_vif {
developer05f3b2b2024-08-19 19:17:34 +0800114 struct ieee80211_chanctx_conf *ctx;
115 };
116
117+enum {
118+ MT_TX_DROP_IN_TESTMODE,
119+ MT_TX_DROP_WCID_NOT_INIT,
120+ MT_TX_DROP_STOPPED_QUEUE,
121+ MT_TX_DROP_RESET_STATE,
122+ MT_TX_DROP_GET_TXWI_FAIL,
123+ MT_TX_DROP_DMA_FAIL,
124+ MT_TX_DROP_AGG_EXCEEDED,
125+ MT_TX_DROP_RING_FULL,
126+ MT_TX_DROP_INVALID_SKB,
127+ MT_TX_DROP_GET_TOKEN_FAIL,
128+ MT_TX_DROP_ADDR_TRANS_FAIL,
129+ MT_TX_DROP_INVALID_WCID,
130+ MT_TX_DROP_INVALID_LINK,
131+ MT_TX_DROP_MAX,
132+};
133+
134+struct mt76_tx_debug {
135+ u32 tx_from_mac80211;
136+ u32 tx_to_hw;
137+
138+ u32 tx_drop[MT_TX_DROP_MAX];
139+ spinlock_t lock;
140+};
141+
142 struct mt76_phy {
143 struct ieee80211_hw *hw;
144 struct ieee80211_hw *ori_hw;
developerd0c89452024-10-11 16:53:27 +0800145@@ -906,6 +931,7 @@ struct mt76_phy {
developer05f3b2b2024-08-19 19:17:34 +0800146 bool al;
147 u8 pin;
148 } leds;
149+ struct mt76_tx_debug tx_dbg_stats;
150 };
151
152 struct mt76_dev {
developerd0c89452024-10-11 16:53:27 +0800153@@ -1010,6 +1036,7 @@ struct mt76_dev {
developer05f3b2b2024-08-19 19:17:34 +0800154 };
155
156 const char *bin_file_name;
157+ struct mt76_tx_debug tx_dbg_stats;
158 };
159
160 #define MT76_MAX_AMSDU_NUM 8
161diff --git a/mt7996/mac.c b/mt7996/mac.c
developerd0c89452024-10-11 16:53:27 +0800162index c341a553..a78ebefc 100644
developer05f3b2b2024-08-19 19:17:34 +0800163--- a/mt7996/mac.c
164+++ b/mt7996/mac.c
developerd0c89452024-10-11 16:53:27 +0800165@@ -909,11 +909,15 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer05f3b2b2024-08-19 19:17:34 +0800166 u8 *txwi = (u8 *)txwi_ptr;
167 u8 link_id;
168
169- if (unlikely(tx_info->skb->len <= ETH_HLEN))
170+ if (unlikely(tx_info->skb->len <= ETH_HLEN)) {
171+ mdev->tx_dbg_stats.tx_drop[MT_TX_DROP_INVALID_SKB]++;
172 return -EINVAL;
173+ }
174
175- if (WARN_ON(!wcid))
176+ if (WARN_ON(!wcid)) {
177+ mdev->tx_dbg_stats.tx_drop[MT_TX_DROP_INVALID_WCID]++;
178 return -EINVAL;
179+ }
180
181 msta = sta ? (struct mt7996_sta *)sta->drv_priv : &mvif->sta;
182 if (ieee80211_is_data_qos(hdr->frame_control) && sta->mlo) {
developerd0c89452024-10-11 16:53:27 +0800183@@ -939,15 +943,19 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer05f3b2b2024-08-19 19:17:34 +0800184 }
185
186 mconf = rcu_dereference(mvif->link[wcid->link_id]);
187- if (!mconf)
188+ if (!mconf) {
189+ mdev->tx_dbg_stats.tx_drop[MT_TX_DROP_INVALID_LINK]++;
190 return -ENOLINK;
191+ }
192
193 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
194 t->skb = tx_info->skb;
195
196 id = mt76_token_consume(mdev, &t);
197- if (id < 0)
198+ if (id < 0) {
199+ mdev->tx_dbg_stats.tx_drop[MT_TX_DROP_GET_TOKEN_FAIL]++;
200 return id;
201+ }
202 #ifdef CONFIG_MTK_DEBUG
203 t->jiffies = jiffies;
204 #endif
developerd0c89452024-10-11 16:53:27 +0800205@@ -969,8 +977,10 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer05f3b2b2024-08-19 19:17:34 +0800206
207 conf = rcu_dereference(vif->link_conf[wcid->link_id]);
208 link_sta = rcu_dereference(sta->link[wcid->link_id]);
209- if (!conf || !link_sta)
210+ if (!conf || !link_sta) {
211+ mdev->tx_dbg_stats.tx_drop[MT_TX_DROP_INVALID_LINK]++;
212 return -ENOLINK;
213+ }
214
215 dma_sync_single_for_cpu(mdev->dma_dev, tx_info->buf[1].addr,
216 tx_info->buf[1].len, DMA_TO_DEVICE);
217diff --git a/mt7996/main.c b/mt7996/main.c
developerd0c89452024-10-11 16:53:27 +0800218index 455beb74..8fb68880 100644
developer05f3b2b2024-08-19 19:17:34 +0800219--- a/mt7996/main.c
220+++ b/mt7996/main.c
developerd0c89452024-10-11 16:53:27 +0800221@@ -1427,11 +1427,13 @@ static void mt7996_tx(struct ieee80211_hw *hw,
developer05f3b2b2024-08-19 19:17:34 +0800222 struct sk_buff *skb)
223 {
224 struct mt76_phy *mphy;
225+ struct mt7996_dev *dev = mt7996_hw_dev(hw);
226 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
227 struct ieee80211_vif *vif = info->control.vif;
228 struct mt76_wcid *wcid;
229 struct mt7996_vif *mvif;
230 struct mt7996_sta *msta;
231+ bool addr_trans_success = false;
232
233 if (control->sta) {
234 msta = (struct mt7996_sta *)control->sta->drv_priv;
developerd0c89452024-10-11 16:53:27 +0800235@@ -1503,14 +1505,18 @@ static void mt7996_tx(struct ieee80211_hw *hw,
developer05f3b2b2024-08-19 19:17:34 +0800236 mphy = mconf->phy->mt76;
237 wcid = &mlink->wcid;
238 } else {
239- struct mt7996_dev *dev = mt7996_hw_dev(hw);
240-
241 mphy = hw->priv;
242 wcid = &dev->mt76.global_wcid;
243 }
244
245+ addr_trans_success = true;
246 mt76_tx(mphy, control->sta, wcid, skb);
247 unlock:
248+ if (!addr_trans_success) {
249+ spin_lock_bh(&dev->mt76.tx_dbg_stats.lock);
250+ dev->mt76.tx_dbg_stats.tx_drop[MT_TX_DROP_ADDR_TRANS_FAIL]++;
251+ spin_unlock_bh(&dev->mt76.tx_dbg_stats.lock);
252+ }
253 rcu_read_unlock();
254 }
255
256diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c
developerd0c89452024-10-11 16:53:27 +0800257index f13f09e1..d15d403b 100644
developer05f3b2b2024-08-19 19:17:34 +0800258--- a/mt7996/mtk_debugfs.c
259+++ b/mt7996/mtk_debugfs.c
developerd0c89452024-10-11 16:53:27 +0800260@@ -4162,6 +4162,83 @@ out:
developer05f3b2b2024-08-19 19:17:34 +0800261 return ret;
262 }
263
264+static int
265+mt7996_tx_drop_show(struct seq_file *s, void *data)
266+{
267+ struct mt7996_dev *dev = s->private;
268+ struct mt76_dev *mdev = &dev->mt76;
269+ struct mt76_tx_debug *dev_stats = &mdev->tx_dbg_stats;
270+ struct mt76_tx_debug *phy_stats[__MT_MAX_BAND];
271+ int i = 0;
272+
273+ seq_printf(s, "\t\t\t\t dev");
274+ for (i = 0; i < __MT_MAX_BAND; i++) {
275+ seq_printf(s, " Band%d", i);
276+ if (mdev->phys[i]) {
277+ phy_stats[i] = &mdev->phys[i]->tx_dbg_stats;
278+ } else {
279+ phy_stats[i] = kzalloc(sizeof(struct mt76_tx_debug),
280+ GFP_KERNEL);
281+ if (!phy_stats[i])
282+ goto out;
283+ }
284+
285+ }
286+ seq_printf(s, " total\n");
287+
288+ seq_printf(s, "%-30s%12d%12d%12d%12d%12d\n", "Receive from mac80211",
289+ dev_stats->tx_from_mac80211,
290+ phy_stats[0]->tx_from_mac80211,
291+ phy_stats[1]->tx_from_mac80211,
292+ phy_stats[2]->tx_from_mac80211,
293+ dev_stats->tx_from_mac80211 +
294+ phy_stats[0]->tx_from_mac80211 +
295+ phy_stats[1]->tx_from_mac80211 +
296+ phy_stats[2]->tx_from_mac80211);
297+ seq_printf(s, "%-30s%12d%12d%12d%12d%12d\n\n", "Send to hw",
298+ dev_stats->tx_to_hw,
299+ phy_stats[0]->tx_to_hw,
300+ phy_stats[1]->tx_to_hw,
301+ phy_stats[2]->tx_to_hw,
302+ dev_stats->tx_to_hw +
303+ phy_stats[0]->tx_to_hw +
304+ phy_stats[1]->tx_to_hw +
305+ phy_stats[2]->tx_to_hw);
306+#define __pr(t) seq_printf(s, "Drop due to %-18s%12d%12d%12d%12d%12d\n",\
307+ #t, dev_stats->tx_drop[MT_TX_DROP_##t], \
308+ phy_stats[0]->tx_drop[MT_TX_DROP_##t], \
309+ phy_stats[1]->tx_drop[MT_TX_DROP_##t], \
310+ phy_stats[2]->tx_drop[MT_TX_DROP_##t], \
311+ dev_stats->tx_drop[MT_TX_DROP_##t] + \
312+ phy_stats[0]->tx_drop[MT_TX_DROP_##t] + \
313+ phy_stats[1]->tx_drop[MT_TX_DROP_##t] + \
314+ phy_stats[2]->tx_drop[MT_TX_DROP_##t])
315+
316+ __pr(IN_TESTMODE);
317+ __pr(WCID_NOT_INIT);
318+ __pr(STOPPED_QUEUE);
319+ __pr(RESET_STATE);
320+ __pr(GET_TXWI_FAIL);
321+ __pr(DMA_FAIL);
322+ __pr(AGG_EXCEEDED);
323+ __pr(RING_FULL);
324+ __pr(INVALID_SKB);
325+ __pr(GET_TOKEN_FAIL);
326+ __pr(ADDR_TRANS_FAIL);
327+ __pr(INVALID_WCID);
328+ __pr(INVALID_LINK);
329+
330+#undef __pr
331+out:
332+ for (i = 0; i < __MT_MAX_BAND; i++) {
333+ if (!mdev->phys[i] && phy_stats[i])
334+ kfree(phy_stats[i]);
335+ }
336+
337+ return 0;
338+}
339+DEFINE_SHOW_ATTRIBUTE(mt7996_tx_drop);
340+
341 /* DRR */
342 static int
343 mt7996_drr_info(struct seq_file *s, void *data)
developerd0c89452024-10-11 16:53:27 +0800344@@ -4287,6 +4364,9 @@ void mt7996_mtk_init_dev_debugfs(struct mt7996_dev *dev, struct dentry *dir)
developer05f3b2b2024-08-19 19:17:34 +0800345 /* amsdu */
346 debugfs_create_file("amsdu_algo", 0600, dir, dev, &fops_amsdu_algo);
347 debugfs_create_file("amsdu_para", 0600, dir, dev, &fops_amsdu_para);
348+
349+ /* Drop counters */
350+ debugfs_create_file("tx_drop_stats", 0400, dir, dev, &mt7996_tx_drop_fops);
351 }
352
353 #endif
354diff --git a/tx.c b/tx.c
developerd0c89452024-10-11 16:53:27 +0800355index 95c84dab..c9fda966 100644
developer05f3b2b2024-08-19 19:17:34 +0800356--- a/tx.c
357+++ b/tx.c
developerd0c89452024-10-11 16:53:27 +0800358@@ -335,8 +335,14 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta,
developer05f3b2b2024-08-19 19:17:34 +0800359 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
developerd0c89452024-10-11 16:53:27 +0800360 struct sk_buff_head *head;
developer05f3b2b2024-08-19 19:17:34 +0800361
362+ spin_lock_bh(&phy->tx_dbg_stats.lock);
363+ phy->tx_dbg_stats.tx_from_mac80211++;
364+ spin_unlock_bh(&phy->tx_dbg_stats.lock);
365 if (mt76_testmode_enabled(phy)) {
366 ieee80211_free_txskb(phy->hw, skb);
367+ spin_lock_bh(&phy->tx_dbg_stats.lock);
368+ phy->tx_dbg_stats.tx_drop[MT_TX_DROP_IN_TESTMODE]++;
369+ spin_unlock_bh(&phy->tx_dbg_stats.lock);
370 return;
371 }
372
developerd0c89452024-10-11 16:53:27 +0800373@@ -357,6 +363,9 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta,
374 dev_warn(phy->dev->dev, "Un-initialized STA %pM wcid %d in mt76_tx\n",
375 sta->addr, wcid->idx);
developer05f3b2b2024-08-19 19:17:34 +0800376
developerd0c89452024-10-11 16:53:27 +0800377+ spin_lock_bh(&phy->tx_dbg_stats.lock);
378+ phy->tx_dbg_stats.tx_drop[MT_TX_DROP_WCID_NOT_INIT]++;
379+ spin_unlock_bh(&phy->tx_dbg_stats.lock);
380 ieee80211_free_txskb(phy->hw, skb);
381 return;
382 }
383@@ -390,6 +399,8 @@ mt76_txq_dequeue(struct mt76_phy *phy, struct mt76_txq *mtxq)
developer05f3b2b2024-08-19 19:17:34 +0800384 info = IEEE80211_SKB_CB(skb);
385 info->hw_queue |= FIELD_PREP(MT_TX_HW_QUEUE_PHY, phy->band_idx);
386
387+ phy->dev->tx_dbg_stats.tx_from_mac80211++;
388+
389 return skb;
390 }
391
developerd0c89452024-10-11 16:53:27 +0800392@@ -628,6 +639,7 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid,
developer05f3b2b2024-08-19 19:17:34 +0800393 q = phy->q_tx[qid];
developerd0c89452024-10-11 16:53:27 +0800394 if (mt76_txq_stopped(q) || test_bit(MT76_RESET, &phy->state)) {
developer05f3b2b2024-08-19 19:17:34 +0800395 ret = -1;
396+ phy->tx_dbg_stats.tx_drop[MT_TX_DROP_STOPPED_QUEUE]++;
397 break;
398 }
399
400--
developerd0c89452024-10-11 16:53:27 +08004012.45.2
developer05f3b2b2024-08-19 19:17:34 +0800402