blob: 665f489f16d5b0d271b611053727c01c3d15b72f [file] [log] [blame]
developer43a264f2024-03-26 14:09:54 +08001From 649e775c56c37b314cf69767bbf845237a2674cc Mon Sep 17 00:00:00 2001
developerd243af02023-12-21 14:49:33 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Fri, 28 Apr 2023 10:39:58 +0800
developer8935fc12024-01-11 14:08:37 +08004Subject: [PATCH 1029/1044] mtk: wifi: mt76: mt7996: add debugfs knob for
developerd243af02023-12-21 14:49:33 +08005 rx_counters
6
7Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
8---
9 agg-rx.c | 8 ++++++++
10 mac80211.c | 16 ++++++++++++++--
11 mt76.h | 15 +++++++++++++++
12 mt7996/mac.c | 18 +++++++++++++++---
13 mt7996/mtk_debugfs.c | 42 ++++++++++++++++++++++++++++++++++++++++++
14 5 files changed, 94 insertions(+), 5 deletions(-)
15
16diff --git a/agg-rx.c b/agg-rx.c
developer43a264f2024-03-26 14:09:54 +080017index 07c386c7..37588ac2 100644
developerd243af02023-12-21 14:49:33 +080018--- a/agg-rx.c
19+++ b/agg-rx.c
20@@ -33,10 +33,13 @@ mt76_rx_aggr_release_frames(struct mt76_rx_tid *tid,
21 struct sk_buff_head *frames,
22 u16 head)
23 {
24+ struct mt76_phy *phy = mt76_dev_phy(tid->dev, tid->band_idx);
25 int idx;
26
27 while (ieee80211_sn_less(tid->head, head)) {
28 idx = tid->head % tid->size;
29+ if (!tid->reorder_buf[idx])
30+ phy->rx_stats.rx_agg_miss++;
31 mt76_aggr_release(tid, frames, idx);
32 }
33 }
34@@ -151,6 +154,7 @@ void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames)
35 struct mt76_wcid *wcid = status->wcid;
36 struct ieee80211_sta *sta;
37 struct mt76_rx_tid *tid;
38+ struct mt76_phy *phy;
39 bool sn_less;
40 u16 seqno, head, size, idx;
41 u8 tidno = status->qos_ctl & IEEE80211_QOS_CTL_TID_MASK;
42@@ -186,6 +190,7 @@ void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames)
43 head = tid->head;
44 seqno = status->seqno;
45 size = tid->size;
46+ phy = mt76_dev_phy(tid->dev, tid->band_idx);
47 sn_less = ieee80211_sn_less(seqno, head);
48
49 if (!tid->started) {
50@@ -197,6 +202,7 @@ void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames)
51
52 if (sn_less) {
53 __skb_unlink(skb, frames);
54+ phy->rx_stats.rx_dup_drop++;
55 dev_kfree_skb(skb);
56 goto out;
57 }
58@@ -223,6 +229,7 @@ void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames)
59
60 /* Discard if the current slot is already in use */
61 if (tid->reorder_buf[idx]) {
62+ phy->rx_stats.rx_dup_drop++;
63 dev_kfree_skb(skb);
64 goto out;
65 }
66@@ -254,6 +261,7 @@ int mt76_rx_aggr_start(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tidno,
67 tid->head = ssn;
68 tid->size = size;
69 tid->num = tidno;
70+ tid->band_idx = wcid->phy_idx;
71 INIT_DELAYED_WORK(&tid->reorder_work, mt76_rx_aggr_reorder_work);
72 spin_lock_init(&tid->lock);
73
74diff --git a/mac80211.c b/mac80211.c
developerebda9012024-02-22 13:42:45 +080075index e7d02d15..ae040ec4 100644
developerd243af02023-12-21 14:49:33 +080076--- a/mac80211.c
77+++ b/mac80211.c
78@@ -784,6 +784,7 @@ static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q)
79 }
80
81 if (ether_addr_equal(skb->data + offset, rfc1042_header)) {
82+ phy->rx_stats.rx_drop++;
83 dev_kfree_skb(skb);
84 return;
85 }
86@@ -1100,10 +1101,16 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
87
88 *sta = wcid_to_sta(mstat.wcid);
89 *hw = mt76_phy_hw(dev, mstat.phy_idx);
90+
91+ if ((mstat.flag & RX_FLAG_8023) || ieee80211_is_data_qos(hdr->frame_control)) {
92+ struct mt76_phy *phy = mt76_dev_phy(dev, mstat.phy_idx);
93+
94+ phy->rx_stats.rx_mac80211++;
95+ }
96 }
97
98 static void
99-mt76_check_ccmp_pn(struct sk_buff *skb)
100+mt76_check_ccmp_pn(struct mt76_dev *dev, struct sk_buff *skb)
101 {
102 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
103 struct mt76_wcid *wcid = status->wcid;
104@@ -1150,7 +1157,11 @@ skip_hdr_check:
105 ret = memcmp(status->iv, wcid->rx_key_pn[security_idx],
106 sizeof(status->iv));
107 if (ret <= 0) {
108+ struct mt76_phy *phy = mt76_dev_phy(dev, status->phy_idx);
109+
110+ phy->rx_stats.rx_pn_iv_error++;
111 status->flag |= RX_FLAG_ONLY_MONITOR;
112+
113 return;
114 }
115
116@@ -1331,7 +1342,7 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
117 while ((skb = __skb_dequeue(frames)) != NULL) {
118 struct sk_buff *nskb = skb_shinfo(skb)->frag_list;
119
120- mt76_check_ccmp_pn(skb);
121+ mt76_check_ccmp_pn(dev, skb);
122 skb_shinfo(skb)->frag_list = NULL;
123 mt76_rx_convert(dev, skb, &hw, &sta);
124 ieee80211_rx_list(hw, sta, skb, &list);
125@@ -1354,6 +1365,7 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
126 }
127
128 list_for_each_entry_safe(skb, tmp, &list, list) {
129+ dev->rx_kernel++;
130 skb_list_del_init(skb);
131 napi_gro_receive(napi, skb);
132 }
133diff --git a/mt76.h b/mt76.h
developer43a264f2024-03-26 14:09:54 +0800134index a75277fe..58fd55b1 100644
developerd243af02023-12-21 14:49:33 +0800135--- a/mt76.h
136+++ b/mt76.h
developerebda9012024-02-22 13:42:45 +0800137@@ -423,6 +423,7 @@ struct mt76_rx_tid {
developerd243af02023-12-21 14:49:33 +0800138 struct rcu_head rcu_head;
139
140 struct mt76_dev *dev;
141+ u8 band_idx;
142
143 spinlock_t lock;
144 struct delayed_work reorder_work;
developerebda9012024-02-22 13:42:45 +0800145@@ -854,6 +855,19 @@ struct mt76_phy {
developerd243af02023-12-21 14:49:33 +0800146 bool al;
147 u8 pin;
148 } leds;
149+
150+ struct {
151+ u32 rx_mac80211;
152+
153+ u32 rx_drop;
154+ u32 rx_rxd_drop;
155+ u32 rx_dup_drop;
156+ u32 rx_agg_miss;
157+ u32 rx_icv_error;
158+ u32 rx_fcs_error;
159+ u32 rx_tkip_mic_error;
160+ u32 rx_pn_iv_error;
161+ } rx_stats;
162 };
163
164 struct mt76_dev {
developerebda9012024-02-22 13:42:45 +0800165@@ -959,6 +973,7 @@ struct mt76_dev {
developerd243af02023-12-21 14:49:33 +0800166 };
167
168 const char *bin_file_name;
169+ u32 rx_kernel;
170 };
171
172 /* per-phy stats. */
173diff --git a/mt7996/mac.c b/mt7996/mac.c
developer43a264f2024-03-26 14:09:54 +0800174index 2e0fb5d9..7885bc4c 100644
developerd243af02023-12-21 14:49:33 +0800175--- a/mt7996/mac.c
176+++ b/mt7996/mac.c
177@@ -469,8 +469,10 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q,
178 return -EINVAL;
179
180 /* ICV error or CCMP/BIP/WPI MIC error */
181- if (rxd1 & MT_RXD1_NORMAL_ICV_ERR)
182+ if (rxd1 & MT_RXD1_NORMAL_ICV_ERR) {
183+ mphy->rx_stats.rx_icv_error++;
184 status->flag |= RX_FLAG_ONLY_MONITOR;
185+ }
186
187 unicast = FIELD_GET(MT_RXD3_NORMAL_ADDR_TYPE, rxd3) == MT_RXD3_NORMAL_U2M;
188 idx = FIELD_GET(MT_RXD1_NORMAL_WLAN_IDX, rxd1);
189@@ -501,11 +503,15 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q,
190 !(csum_status & (BIT(0) | BIT(2) | BIT(3))))
191 skb->ip_summed = CHECKSUM_UNNECESSARY;
192
193- if (rxd1 & MT_RXD3_NORMAL_FCS_ERR)
194+ if (rxd1 & MT_RXD3_NORMAL_FCS_ERR) {
195+ mphy->rx_stats.rx_fcs_error++;
196 status->flag |= RX_FLAG_FAILED_FCS_CRC;
197+ }
198
199- if (rxd1 & MT_RXD1_NORMAL_TKIP_MIC_ERR)
200+ if (rxd1 & MT_RXD1_NORMAL_TKIP_MIC_ERR) {
201+ mphy->rx_stats.rx_tkip_mic_error++;
202 status->flag |= RX_FLAG_MMIC_ERROR;
203+ }
204
205 if (FIELD_GET(MT_RXD2_NORMAL_SEC_MODE, rxd2) != 0 &&
206 !(rxd1 & (MT_RXD1_NORMAL_CLM | MT_RXD1_NORMAL_CM))) {
developerebda9012024-02-22 13:42:45 +0800207@@ -1415,8 +1421,10 @@ void mt7996_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
developerd243af02023-12-21 14:49:33 +0800208 struct sk_buff *skb, u32 *info)
209 {
210 struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);
211+ struct mt76_phy *phy;
212 __le32 *rxd = (__le32 *)skb->data;
213 __le32 *end = (__le32 *)&skb->data[skb->len];
214+ u8 band_idx;
215 enum rx_pkt_type type;
216
217 type = le32_get_bits(rxd[0], MT_RXD0_PKT_TYPE);
developerebda9012024-02-22 13:42:45 +0800218@@ -1458,6 +1466,10 @@ void mt7996_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
developerd243af02023-12-21 14:49:33 +0800219 }
220 fallthrough;
221 default:
222+ band_idx = le32_get_bits(rxd[1], MT_RXD1_NORMAL_BAND_IDX);
223+ phy = mt76_dev_phy(mdev, band_idx);
224+ if (likely(phy))
225+ phy->rx_stats.rx_rxd_drop++;
226 dev_kfree_skb(skb);
227 break;
228 }
229diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c
developer43a264f2024-03-26 14:09:54 +0800230index ed01c089..d290ad4d 100644
developerd243af02023-12-21 14:49:33 +0800231--- a/mt7996/mtk_debugfs.c
232+++ b/mt7996/mtk_debugfs.c
developer8935fc12024-01-11 14:08:37 +0800233@@ -2854,6 +2854,46 @@ mt7996_sr_scene_cond_show(struct seq_file *file, void *data)
developerd243af02023-12-21 14:49:33 +0800234 }
235 DEFINE_SHOW_ATTRIBUTE(mt7996_sr_scene_cond);
236
237+static int mt7996_rx_counters(struct seq_file *s, void *data)
238+{
239+ struct mt7996_dev *dev = dev_get_drvdata(s->private);
240+ u32 rx_mac80211 = 0;
241+ int i = 0;
242+
243+ for (i = 0; i < __MT_MAX_BAND; i++) {
244+ struct mt76_phy *phy = mt76_dev_phy(&dev->mt76, i);
245+
246+ if (!phy)
247+ continue;
248+
249+ seq_printf(s, "\n==========PHY%d==========\n", i);
250+
251+#define SEQ_PRINT(_str, _rx_param) do { \
252+ seq_printf(s, _str"\n", phy->rx_stats._rx_param); \
253+ } while (0)
254+
255+ SEQ_PRINT("Rx to mac80211: %u", rx_mac80211);
256+ SEQ_PRINT("Rx drop: %u", rx_drop);
257+ SEQ_PRINT("Rx drop due to RXD type error: %u", rx_rxd_drop);
258+ SEQ_PRINT("Rx duplicated drop: %u", rx_dup_drop);
259+ SEQ_PRINT("Rx agg miss: %u", rx_agg_miss);
260+ SEQ_PRINT("Rx ICV error: %u", rx_icv_error);
261+ SEQ_PRINT("Rx FCS error: %u", rx_fcs_error);
262+ SEQ_PRINT("Rx TKIP MIC error: %u", rx_tkip_mic_error);
263+ SEQ_PRINT("Rx PN/IV error: %u", rx_pn_iv_error);
264+#undef SEQ_PRINT
265+
266+ rx_mac80211 += phy->rx_stats.rx_mac80211;
267+ }
268+
269+ seq_printf(s, "\n==========SUM==========\n");
270+ seq_printf(s, "Rx to kernel: %u\n", dev->mt76.rx_kernel);
271+ seq_printf(s, "Rx to mac80211: %u\n", rx_mac80211);
272+
273+
274+ return 0;
275+}
276+
277 int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
278 {
279 struct mt7996_dev *dev = phy->dev;
developer8935fc12024-01-11 14:08:37 +0800280@@ -2917,6 +2957,8 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
developerd243af02023-12-21 14:49:33 +0800281
282 debugfs_create_devm_seqfile(dev->mt76.dev, "tr_info", dir,
283 mt7996_trinfo_read);
284+ debugfs_create_devm_seqfile(dev->mt76.dev, "rx_counters", dir,
285+ mt7996_rx_counters);
286 debugfs_create_file("txpower_level", 0600, dir, phy, &fops_txpower_level);
287 debugfs_create_file("txpower_info", 0600, dir, phy, &mt7996_txpower_info_fops);
288 debugfs_create_file("txpower_sku", 0600, dir, phy, &mt7996_txpower_sku_fops);
289--
2902.18.0
291