blob: 70831fd29d86ed9e4ceb7658fb38d10cb59fa6ca [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From 5ef5041a7200a4e3877df4c3533bd3c5e2038615 Mon Sep 17 00:00:00 2001
2From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Wed, 7 Sep 2022 12:13:20 +0800
4Subject: [PATCH 121/199] mtk: mt76: mt7996: add linux tracing support
5
6Add static tracepoint support for besra.
7
8Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
9---
10 agg-rx.c | 2 +
11 mac80211.c | 3 +
12 mt7996/Makefile | 2 +-
13 mt7996/mac.c | 6 ++
14 mt7996/mcu.c | 8 +++
15 mt7996/mt7996_trace.h | 141 ++++++++++++++++++++++++++++++++++++++++++
16 mt7996/trace.c | 12 ++++
17 trace.h | 58 +++++++++++++++++
18 8 files changed, 231 insertions(+), 1 deletion(-)
19 create mode 100644 mt7996/mt7996_trace.h
20 create mode 100644 mt7996/trace.c
21
22diff --git a/agg-rx.c b/agg-rx.c
23index 07c386c7..b48943c4 100644
24--- a/agg-rx.c
25+++ b/agg-rx.c
26@@ -3,6 +3,7 @@
27 * Copyright (C) 2018 Felix Fietkau <nbd@nbd.name>
28 */
29 #include "mt76.h"
30+#include "trace.h"
31
32 static unsigned long mt76_aggr_tid_to_timeo(u8 tidno)
33 {
34@@ -187,6 +188,7 @@ void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames)
35 seqno = status->seqno;
36 size = tid->size;
37 sn_less = ieee80211_sn_less(seqno, head);
38+ trace_mt76_rx_aggr_reorder(tid->dev, wcid, head, seqno, sn_less);
39
40 if (!tid->started) {
41 if (sn_less)
42diff --git a/mac80211.c b/mac80211.c
43index 5e4935f2..dc91e827 100644
44--- a/mac80211.c
45+++ b/mac80211.c
46@@ -5,6 +5,7 @@
47 #include <linux/sched.h>
48 #include <linux/of.h>
49 #include "mt76.h"
50+#include "trace.h"
51
52 static const struct ieee80211_channel mt76_channels_2ghz[] = {
53 CHAN2G(1, 2412),
54@@ -1307,6 +1308,7 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
55
56 mt76_check_ccmp_pn(skb);
57 skb_shinfo(skb)->frag_list = NULL;
58+ trace_mt76_rx_complete(dev, (struct mt76_rx_status *)skb->cb, 0);
59 mt76_rx_convert(dev, skb, &hw, &sta);
60 ieee80211_rx_list(hw, sta, skb, &list);
61
62@@ -1316,6 +1318,7 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
63 nskb = nskb->next;
64 skb->next = NULL;
65
66+ trace_mt76_rx_complete(dev, (struct mt76_rx_status *)skb->cb, 1);
67 mt76_rx_convert(dev, skb, &hw, &sta);
68 ieee80211_rx_list(hw, sta, skb, &list);
69 }
70diff --git a/mt7996/Makefile b/mt7996/Makefile
71index 49ec9154..936edc61 100644
72--- a/mt7996/Makefile
73+++ b/mt7996/Makefile
74@@ -12,4 +12,4 @@ mt7996e-y := pci.o init.o dma.o eeprom.o main.o mcu.o mac.o \
75 mt7996e-$(CONFIG_DEV_COREDUMP) += coredump.o
76 mt7996e-$(CONFIG_NL80211_TESTMODE) += testmode.o
77
78-mt7996e-y += mtk_debugfs.o mtk_mcu.o mtk_debugfs_i.o
79+mt7996e-y += mtk_debugfs.o mtk_mcu.o mtk_debugfs_i.o trace.o
80diff --git a/mt7996/mac.c b/mt7996/mac.c
81index c6816ab5..6ba07156 100644
82--- a/mt7996/mac.c
83+++ b/mt7996/mac.c
84@@ -11,6 +11,7 @@
85 #include "mac.h"
86 #include "mcu.h"
87 #include "vendor.h"
88+#include "mt7996_trace.h"
89
90 static const struct mt7996_dfs_radar_spec etsi_radar_specs = {
91 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
92@@ -344,6 +345,8 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q,
93 phy = mphy->priv;
94 status->phy_idx = mphy->band_idx;
95
96+ trace_mt7996_fill_rx(phy, skb->data, skb->len);
97+
98 if (!test_bit(MT76_STATE_RUNNING, &mphy->state))
99 return -EINVAL;
100
101@@ -609,6 +612,8 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q,
102 !(status->flag & RX_FLAG_8023))
103 mt76_connac3_mac_decode_he_radiotap(skb, rxv, mode);
104
105+ trace_mt7996_fill_rx_done(phy, status->seqno, hdr_gap);
106+
107 if (!status->wcid || !ieee80211_is_data_qos(fc) || hw_aggr)
108 return 0;
109
110@@ -998,6 +1003,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
111 mt7996_packet_log_to_host(dev, t->skb->data, t->skb->len, PKT_BIN_DEBUG_TX, 0);
112 mt7996_dump_bmac_txd_info(NULL, dev, (__le32 *)txwi, true, false);
113 #endif
114+ trace_mt7996_tx_prepare(dev, wcid, qid, txwi, t->skb->data, t->skb->len);
115
116 return 0;
117 }
118diff --git a/mt7996/mcu.c b/mt7996/mcu.c
119index 0b02b76b..1cc08a30 100644
120--- a/mt7996/mcu.c
121+++ b/mt7996/mcu.c
122@@ -10,6 +10,7 @@
123 #include "mcu.h"
124 #include "mac.h"
125 #include "eeprom.h"
126+#include "mt7996_trace.h"
127
128 #define fw_name(_dev, name, ...) ({ \
129 char *_fw; \
130@@ -305,6 +306,9 @@ mt7996_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb,
131 else if (cmd & __MCU_CMD_FIELD_WM)
132 uni_txd->s2d_index = MCU_S2D_H2N;
133
134+ trace_mt7996_mcu_cmd(dev, 1, uni_txd->cid, 0,
135+ skb->data, skb->len);
136+
137 goto exit;
138 }
139
140@@ -332,6 +336,8 @@ mt7996_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb,
141 else
142 mcu_txd->s2d_index = MCU_S2D_H2N;
143
144+ trace_mt7996_mcu_cmd(dev, 0, mcu_txd->cid, mcu_txd->ext_cid,
145+ skb->data, skb->len);
146 exit:
147 #ifdef CONFIG_MTK_DEBUG
148 if (dev->dbg.dump_mcu_pkt)
149@@ -1177,6 +1183,8 @@ void mt7996_mcu_rx_event(struct mt7996_dev *dev, struct sk_buff *skb)
150 {
151 struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data;
152
153+ trace_mt7996_mcu_event(dev, rxd->option & MCU_UNI_CMD_UNSOLICITED_EVENT,
154+ rxd->eid, rxd->ext_eid, skb->data, skb->len);
155 if (rxd->option & MCU_UNI_CMD_UNSOLICITED_EVENT) {
156 mt7996_mcu_uni_rx_unsolicited_event(dev, skb);
157 return;
158diff --git a/mt7996/mt7996_trace.h b/mt7996/mt7996_trace.h
159new file mode 100644
160index 00000000..5fa73482
161--- /dev/null
162+++ b/mt7996/mt7996_trace.h
163@@ -0,0 +1,141 @@
164+/* SPDX-License-Identifier: ISC */
165+/*
166+ * Copyright (C) 2022 MediaTek Inc.
167+ */
168+
169+#if !defined(__MT7996_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
170+#define __MT7996_TRACE_H
171+
172+#include <linux/types.h>
173+#include <linux/tracepoint.h>
174+#include "mt7996.h"
175+
176+#undef TRACE_SYSTEM
177+#define TRACE_SYSTEM mt7996
178+
179+#define MAXNAME 32
180+#define DEV_ENTRY __array(char, wiphy_name, 32)
181+#define DEV_ASSIGN(_w) strlcpy(__entry->wiphy_name, wiphy_name(_w), MAXNAME)
182+#define DEV_PR_FMT "%s"
183+#define DEV_PR_ARG __entry->wiphy_name
184+
185+DECLARE_EVENT_CLASS(mt7996_mcu_debug,
186+ TP_PROTO(struct mt7996_dev *dev, bool uni, u8 id, u8 ext_id,
187+ const void *data, size_t len),
188+ TP_ARGS(dev, uni, id, ext_id, data, len),
189+ TP_STRUCT__entry(
190+ __field(bool, uni)
191+ __field(u8, id)
192+ __field(u8, ext_id)
193+ __field(size_t, len)
194+ __dynamic_array(u8, data, len)
195+ ),
196+ TP_fast_assign(
197+ __entry->uni = uni;
198+ __entry->id = id;
199+ __entry->ext_id = ext_id;
200+ __entry->len = len;
201+ memcpy(__get_dynamic_array(data), data, len);
202+ ),
203+ TP_printk(
204+ "uni: %d, id: %u, ext_id: %u, len: %zu",
205+ __entry->uni,
206+ __entry->id,
207+ __entry->ext_id,
208+ __entry->len
209+ )
210+);
211+
212+DEFINE_EVENT(mt7996_mcu_debug, mt7996_mcu_cmd,
213+ TP_PROTO(struct mt7996_dev *dev, bool uni, u8 id, u8 ext_id,
214+ const void *data, size_t len),
215+ TP_ARGS(dev, uni, id, ext_id, data, len)
216+);
217+
218+DEFINE_EVENT(mt7996_mcu_debug, mt7996_mcu_event,
219+ TP_PROTO(struct mt7996_dev *dev, bool uni, u8 id, u8 ext_id,
220+ const void *data, size_t len),
221+ TP_ARGS(dev, uni, id, ext_id, data, len)
222+);
223+
224+TRACE_EVENT(mt7996_tx_prepare,
225+ TP_PROTO(struct mt7996_dev *dev, struct mt76_wcid *wcid, enum mt76_txq_id qid,
226+ const void *txwi, const void *data, size_t len),
227+ TP_ARGS(dev, wcid, qid, txwi, data, len),
228+
229+ TP_STRUCT__entry(
230+ DEV_ENTRY
231+ __field(u16, wcid)
232+ __field(u8, qid)
233+ __array(u8, txwi, MT_TXD_SIZE)
234+ __field(size_t, len)
235+ __dynamic_array(u8, data, len)
236+ ),
237+
238+ TP_fast_assign(
239+ DEV_ASSIGN(dev->mt76.phys[wcid->phy_idx]->hw->wiphy);
240+ __entry->wcid = wcid->idx;
241+ __entry->qid = qid;
242+ memcpy(__entry->txwi, txwi, MT_TXD_SIZE);
243+ __entry->len = len;
244+ memcpy(__get_dynamic_array(data), data, len);
245+ ),
246+
247+ TP_printk(
248+ DEV_PR_FMT " wcid: %u, qid: %u, len: %zu",
249+ DEV_PR_ARG, __entry->wcid, __entry->qid, __entry->len
250+ )
251+);
252+
253+TRACE_EVENT(mt7996_fill_rx,
254+ TP_PROTO(struct mt7996_phy *phy, const void *data, size_t len),
255+ TP_ARGS(phy, data, len),
256+
257+ TP_STRUCT__entry(
258+ DEV_ENTRY
259+ __field(size_t, len)
260+ __dynamic_array(u8, data, len)
261+ ),
262+
263+ TP_fast_assign(
264+ DEV_ASSIGN(phy->mt76->hw->wiphy);
265+ __entry->len = len;
266+ memcpy(__get_dynamic_array(data), data, len);
267+ ),
268+
269+ TP_printk(
270+ DEV_PR_FMT " len: %zu",
271+ DEV_PR_ARG, __entry->len
272+ )
273+);
274+
275+TRACE_EVENT(mt7996_fill_rx_done,
276+ TP_PROTO(struct mt7996_phy *phy, u16 seqno, u16 hdr_gap),
277+ TP_ARGS(phy, seqno, hdr_gap),
278+
279+ TP_STRUCT__entry(
280+ DEV_ENTRY
281+ __field(u16, seqno)
282+ __field(u16, hdr_gap)
283+ ),
284+
285+ TP_fast_assign(
286+ DEV_ASSIGN(phy->mt76->hw->wiphy);
287+ __entry->seqno = seqno;
288+ __entry->hdr_gap = hdr_gap;
289+ ),
290+
291+ TP_printk(
292+ DEV_PR_FMT " seqno: %u, hdr_gap: %u",
293+ DEV_PR_ARG, __entry->seqno, __entry->hdr_gap
294+ )
295+);
296+
297+#endif
298+
299+#undef TRACE_INCLUDE_PATH
300+#define TRACE_INCLUDE_PATH ./mt7996
301+#undef TRACE_INCLUDE_FILE
302+#define TRACE_INCLUDE_FILE mt7996_trace
303+
304+#include <trace/define_trace.h>
305diff --git a/mt7996/trace.c b/mt7996/trace.c
306new file mode 100644
307index 00000000..ba36f79a
308--- /dev/null
309+++ b/mt7996/trace.c
310@@ -0,0 +1,12 @@
311+/* SPDX-License-Identifier: ISC */
312+/*
313+ * Copyright (C) 2022 MediaTek Inc.
314+ */
315+
316+#include <linux/module.h>
317+
318+#ifndef __CHECKER__
319+#define CREATE_TRACE_POINTS
320+#include "mt7996_trace.h"
321+
322+#endif
323diff --git a/trace.h b/trace.h
324index c3d0ef8e..57c94c6b 100644
325--- a/trace.h
326+++ b/trace.h
327@@ -101,6 +101,64 @@ DEFINE_EVENT(dev_txid_evt, mac_txdone,
328 TP_ARGS(dev, wcid, pktid)
329 );
330
331+TRACE_EVENT(mt76_rx_complete,
332+ TP_PROTO(struct mt76_dev *dev, struct mt76_rx_status *status, bool sub),
333+ TP_ARGS(dev, status, sub),
334+
335+ TP_STRUCT__entry(
336+ DEV_ENTRY
337+ __field(u16, seqno)
338+ __field(u16, wcid)
339+ __field(u8, first_amsdu)
340+ __field(bool, sub)
341+ ),
342+
343+ TP_fast_assign(
344+ strlcpy(__entry->wiphy_name,
345+ wiphy_name(mt76_dev_phy(dev, status->phy_idx)->hw->wiphy),
346+ MAXNAME);
347+ __entry->seqno = status->seqno;
348+ __entry->wcid = status->wcid ? status->wcid->idx : 0;
349+ __entry->first_amsdu = status->first_amsdu;
350+ __entry->sub = sub;
351+ ),
352+
353+ TP_printk(
354+ DEV_PR_FMT " seqno: %u, wcid: %u, first_amsdu: %x, sub: %d",
355+ DEV_PR_ARG, __entry->seqno, __entry->wcid, __entry->first_amsdu,
356+ __entry->sub
357+ )
358+);
359+
360+TRACE_EVENT(mt76_rx_aggr_reorder,
361+ TP_PROTO(struct mt76_dev *dev, struct mt76_wcid *wcid, u16 _head, u16 seqno, bool sn_less),
362+ TP_ARGS(dev, wcid, _head, seqno, sn_less),
363+
364+ TP_STRUCT__entry(
365+ DEV_ENTRY
366+ __field(u16, wcid)
367+ __field(u16, _head)
368+ __field(u16, seqno)
369+ __field(bool, sn_less)
370+ ),
371+
372+ TP_fast_assign(
373+ strlcpy(__entry->wiphy_name,
374+ wiphy_name(dev->phys[wcid->phy_idx]->hw->wiphy),
375+ MAXNAME);
376+ __entry->wcid = wcid->idx;
377+ __entry->_head = _head;
378+ __entry->seqno = seqno;
379+ __entry->sn_less = sn_less;
380+ ),
381+
382+ TP_printk(
383+ DEV_PR_FMT " wcid: %u, head: %u, seqno: %u, sn_less: %d",
384+ DEV_PR_ARG, __entry->wcid, __entry->_head, __entry->seqno,
385+ __entry->sn_less
386+ )
387+);
388+
389 #endif
390
391 #undef TRACE_INCLUDE_PATH
392--
3932.18.0
394