developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 1 | From 86545609cc73f064e34e6783175b502623e08217 Mon Sep 17 00:00:00 2001 |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 2 | From: Peter Chiu <chui-hao.chiu@mediatek.com> |
| 3 | Date: Mon, 18 Mar 2024 14:16:34 +0800 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 2013/2015] wifi: mt76: add debugfs for tx drop counters |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com> |
| 7 | --- |
| 8 | dma.c | 26 +++++++++++++++++++++----- |
| 9 | mt76.h | 22 ++++++++++++++++++++++ |
| 10 | mt7915/mac.c | 16 +++++++++++++--- |
| 11 | mt7915/mtk_debugfs.c | 37 +++++++++++++++++++++++++++++++++++++ |
| 12 | tx.c | 6 ++++++ |
| 13 | 5 files changed, 99 insertions(+), 8 deletions(-) |
| 14 | |
| 15 | diff --git a/dma.c b/dma.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 16 | index d17fc88c..da3e8bc3 100644 |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 17 | --- a/dma.c |
| 18 | +++ b/dma.c |
| 19 | @@ -612,13 +612,18 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, |
| 20 | struct sk_buff *iter; |
| 21 | dma_addr_t addr; |
| 22 | u8 *txwi; |
| 23 | + int reason = -1; |
| 24 | |
| 25 | - if (test_bit(MT76_RESET, &phy->state)) |
| 26 | + if (test_bit(MT76_RESET, &phy->state)) { |
| 27 | + reason = MT_TX_DROP_RESET_STATE; |
| 28 | goto free_skb; |
| 29 | + } |
| 30 | |
| 31 | t = mt76_get_txwi(dev); |
| 32 | - if (!t) |
| 33 | + if (!t) { |
| 34 | + reason = MT_TX_DROP_GET_TXWI_FAIL; |
| 35 | goto free_skb; |
| 36 | + } |
| 37 | |
| 38 | txwi = mt76_get_txwi_ptr(dev, t); |
| 39 | |
| 40 | @@ -628,8 +633,10 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, |
| 41 | |
| 42 | len = skb_headlen(skb); |
| 43 | addr = dma_map_single(dev->dma_dev, skb->data, len, DMA_TO_DEVICE); |
| 44 | - if (unlikely(dma_mapping_error(dev->dma_dev, addr))) |
| 45 | + if (unlikely(dma_mapping_error(dev->dma_dev, addr))) { |
| 46 | + reason = MT_TX_DROP_DMA_FAIL; |
| 47 | goto free; |
| 48 | + } |
| 49 | |
| 50 | tx_info.buf[n].addr = t->dma_addr; |
| 51 | tx_info.buf[n++].len = dev->drv->txwi_size; |
| 52 | @@ -637,13 +644,17 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, |
| 53 | tx_info.buf[n++].len = len; |
| 54 | |
| 55 | skb_walk_frags(skb, iter) { |
| 56 | - if (n == ARRAY_SIZE(tx_info.buf)) |
| 57 | + if (n == ARRAY_SIZE(tx_info.buf)) { |
| 58 | + reason = MT_TX_DROP_AGG_EXCEEDED; |
| 59 | goto unmap; |
| 60 | + } |
| 61 | |
| 62 | addr = dma_map_single(dev->dma_dev, iter->data, iter->len, |
| 63 | DMA_TO_DEVICE); |
| 64 | - if (unlikely(dma_mapping_error(dev->dma_dev, addr))) |
| 65 | + if (unlikely(dma_mapping_error(dev->dma_dev, addr))) { |
| 66 | + reason = MT_TX_DROP_DMA_FAIL; |
| 67 | goto unmap; |
| 68 | + } |
| 69 | |
| 70 | tx_info.buf[n].addr = addr; |
| 71 | tx_info.buf[n++].len = iter->len; |
| 72 | @@ -652,6 +663,7 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, |
| 73 | |
| 74 | if (q->queued + (tx_info.nbuf + 1) / 2 >= q->ndesc - 1) { |
| 75 | ret = -ENOMEM; |
| 76 | + reason = MT_TX_DROP_RING_FULL; |
| 77 | goto unmap; |
| 78 | } |
| 79 | |
| 80 | @@ -663,6 +675,7 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, |
| 81 | if (ret < 0) |
| 82 | goto unmap; |
| 83 | |
| 84 | + phy->tx_dbg_stats.tx_to_hw++; |
| 85 | return mt76_dma_add_buf(dev, q, tx_info.buf, tx_info.nbuf, |
| 86 | tx_info.info, tx_info.skb, t, NULL); |
| 87 | |
| 88 | @@ -690,6 +703,9 @@ free_skb: |
| 89 | ieee80211_tx_status_ext(hw, &status); |
| 90 | spin_unlock_bh(&dev->rx_lock); |
| 91 | |
| 92 | + if (reason >= 0) |
| 93 | + phy->tx_dbg_stats.tx_drop[reason]++; |
| 94 | + |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | diff --git a/mt76.h b/mt76.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 99 | index 07dc6b34..08f1a7ce 100644 |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 100 | --- a/mt76.h |
| 101 | +++ b/mt76.h |
| 102 | @@ -849,6 +849,27 @@ struct mt76_vif { |
| 103 | struct ieee80211_chanctx_conf *ctx; |
| 104 | }; |
| 105 | |
| 106 | +enum { |
| 107 | + MT_TX_DROP_IN_TESTMODE, |
| 108 | + MT_TX_DROP_WCID_NOT_INIT, |
| 109 | + MT_TX_DROP_STOPPED_QUEUE, |
| 110 | + MT_TX_DROP_RESET_STATE, |
| 111 | + MT_TX_DROP_GET_TXWI_FAIL, |
| 112 | + MT_TX_DROP_DMA_FAIL, |
| 113 | + MT_TX_DROP_AGG_EXCEEDED, |
| 114 | + MT_TX_DROP_RING_FULL, |
| 115 | + MT_TX_DROP_INVALID_SKB, |
| 116 | + MT_TX_DROP_GET_TOKEN_FAIL, |
| 117 | + MT_TX_DROP_MAX, |
| 118 | +}; |
| 119 | + |
| 120 | +struct mt76_tx_debug { |
| 121 | + u32 tx_from_mac80211; |
| 122 | + u32 tx_to_hw; |
| 123 | + |
| 124 | + u32 tx_drop[MT_TX_DROP_MAX]; |
| 125 | +}; |
| 126 | + |
| 127 | struct mt76_phy { |
| 128 | struct ieee80211_hw *hw; |
| 129 | struct mt76_dev *dev; |
| 130 | @@ -906,6 +927,7 @@ struct mt76_phy { |
| 131 | u8 pin; |
| 132 | } leds; |
| 133 | int tokens; |
| 134 | + struct mt76_tx_debug tx_dbg_stats; |
| 135 | }; |
| 136 | |
| 137 | struct mt76_dev { |
| 138 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 139 | index 0c121700..1e2ef8c0 100644 |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 140 | --- a/mt7915/mac.c |
| 141 | +++ b/mt7915/mac.c |
| 142 | @@ -782,9 +782,15 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 143 | u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2; |
| 144 | u8 *txwi = (u8 *)txwi_ptr; |
| 145 | int pid; |
| 146 | + struct mt76_phy *mphy = &mdev->phy; |
| 147 | |
| 148 | - if (unlikely(tx_info->skb->len <= ETH_HLEN)) |
| 149 | + if (phy_idx && mdev->phys[MT_BAND1]) |
| 150 | + mphy = mdev->phys[MT_BAND1]; |
| 151 | + |
| 152 | + if (unlikely(tx_info->skb->len <= ETH_HLEN)) { |
| 153 | + mphy->tx_dbg_stats.tx_drop[MT_TX_DROP_INVALID_SKB]++; |
| 154 | return -EINVAL; |
| 155 | + } |
| 156 | |
| 157 | if (!wcid) |
| 158 | wcid = &dev->mt76.global_wcid; |
| 159 | @@ -804,12 +810,16 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 160 | t->skb = tx_info->skb; |
| 161 | |
| 162 | if (ieee80211_is_action(fc) && |
| 163 | - mgmt->u.action.category == 0xff) |
| 164 | + mgmt->u.action.category == 0xff) { |
| 165 | + mphy->tx_dbg_stats.tx_drop[MT_TX_DROP_INVALID_SKB]++; |
| 166 | return -1; |
| 167 | + } |
| 168 | |
| 169 | id = mt76_token_consume(mdev, &t, phy_idx); |
| 170 | - if (id < 0) |
| 171 | + if (id < 0) { |
| 172 | + mphy->tx_dbg_stats.tx_drop[MT_TX_DROP_GET_TOKEN_FAIL]++; |
| 173 | return id; |
| 174 | + } |
| 175 | |
| 176 | t->jiffies = jiffies; |
| 177 | |
| 178 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 179 | index c4eb7368..abb09b76 100644 |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 180 | --- a/mt7915/mtk_debugfs.c |
| 181 | +++ b/mt7915/mtk_debugfs.c |
| 182 | @@ -4033,6 +4033,12 @@ static int mt7915_reset_counter(void *data, u64 val) |
| 183 | struct mt7915_dev *dev = phy->dev; |
| 184 | struct mt76_wcid *wcid; |
| 185 | |
| 186 | + if (!dev->wlan_idx) { |
| 187 | + memset(&phy->mt76->tx_dbg_stats, 0, sizeof(struct mt76_tx_debug)); |
| 188 | + |
| 189 | + return 0; |
| 190 | + } |
| 191 | + |
| 192 | /* Clear the firmware counters */ |
| 193 | mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx, NULL); |
| 194 | mt7915_get_tx_stat(phy, dev->wlan_idx); |
| 195 | @@ -4087,6 +4093,35 @@ mt7915_per_read(struct seq_file *s, void *data) |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | +static int |
| 200 | +mt7915_tx_drop_show(struct seq_file *s, void *data) |
| 201 | +{ |
| 202 | + struct mt7915_phy *phy = s->private; |
| 203 | + struct mt76_tx_debug *stats = &phy->mt76->tx_dbg_stats; |
| 204 | + |
| 205 | + seq_printf(s, "Receive from mac80211: %d\n", stats->tx_from_mac80211); |
| 206 | + seq_printf(s, "Send to hw: %d\n", stats->tx_to_hw); |
| 207 | + |
| 208 | +#define __pr(t) seq_printf(s, "Drop due to %s: %d\n", \ |
| 209 | + #t, stats->tx_drop[MT_TX_DROP_##t]) |
| 210 | + __pr(IN_TESTMODE); |
| 211 | + __pr(WCID_NOT_INIT); |
| 212 | + __pr(STOPPED_QUEUE); |
| 213 | + __pr(RESET_STATE); |
| 214 | + __pr(GET_TXWI_FAIL); |
| 215 | + __pr(DMA_FAIL); |
| 216 | + __pr(AGG_EXCEEDED); |
| 217 | + __pr(RING_FULL); |
| 218 | + __pr(INVALID_SKB); |
| 219 | + __pr(GET_TOKEN_FAIL); |
| 220 | + |
| 221 | +#undef __pr |
| 222 | + |
| 223 | + return 0; |
| 224 | +} |
| 225 | + |
| 226 | +DEFINE_SHOW_ATTRIBUTE(mt7915_tx_drop); |
| 227 | + |
| 228 | int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 229 | { |
| 230 | struct mt7915_dev *dev = phy->dev; |
| 231 | @@ -4186,7 +4221,9 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 232 | debugfs_create_file("sr_scene_cond", 0400, dir, phy, &mt7915_sr_scene_cond_fops); |
| 233 | debugfs_create_file("reset_counter", 0200, dir, phy, &fops_reset_counter); |
| 234 | debugfs_create_devm_seqfile(dev->mt76.dev, "per", dir, mt7915_per_read); |
| 235 | + debugfs_create_file("tx_drop_stats", 0400, dir, phy, &mt7915_tx_drop_fops); |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | + |
| 240 | #endif |
| 241 | diff --git a/tx.c b/tx.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 242 | index df2bb07d..e4eb74b7 100644 |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 243 | --- a/tx.c |
| 244 | +++ b/tx.c |
| 245 | @@ -330,8 +330,10 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta, |
| 246 | { |
| 247 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 248 | |
| 249 | + phy->tx_dbg_stats.tx_from_mac80211++; |
| 250 | if (mt76_testmode_enabled(phy)) { |
| 251 | ieee80211_free_txskb(phy->hw, skb); |
| 252 | + phy->tx_dbg_stats.tx_drop[MT_TX_DROP_IN_TESTMODE]++; |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | @@ -348,6 +350,7 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta, |
| 257 | dev_warn(phy->dev->dev, "Un-initialized STA %pM wcid %d in mt76_tx\n", |
| 258 | sta->addr, wcid->idx); |
| 259 | |
| 260 | + phy->tx_dbg_stats.tx_drop[MT_TX_DROP_WCID_NOT_INIT]++; |
| 261 | ieee80211_free_txskb(phy->hw, skb); |
| 262 | return; |
| 263 | } |
| 264 | @@ -379,6 +382,8 @@ mt76_txq_dequeue(struct mt76_phy *phy, struct mt76_txq *mtxq) |
| 265 | info = IEEE80211_SKB_CB(skb); |
| 266 | info->hw_queue |= FIELD_PREP(MT_TX_HW_QUEUE_PHY, phy->band_idx); |
| 267 | |
| 268 | + phy->tx_dbg_stats.tx_from_mac80211++; |
| 269 | + |
| 270 | return skb; |
| 271 | } |
| 272 | |
| 273 | @@ -616,6 +621,7 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid) |
| 274 | q = phy->q_tx[qid]; |
| 275 | if (mt76_txq_stopped(q)) { |
| 276 | ret = -1; |
| 277 | + phy->tx_dbg_stats.tx_drop[MT_TX_DROP_STOPPED_QUEUE]++; |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | -- |
| 282 | 2.18.0 |
| 283 | |