xref: /freebsd/sys/contrib/dev/mediatek/mt76/mt792x_debugfs.c (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2023 MediaTek Inc. */
3 
4 #include "mt792x.h"
5 
6 static void
7 mt792x_ampdu_stat_read_phy(struct mt792x_phy *phy,
8 			   struct seq_file *file)
9 {
10 	struct mt792x_dev *dev = file->private;
11 	int bound[15], range[4], i;
12 
13 	if (!phy)
14 		return;
15 
16 	mt792x_mac_update_mib_stats(phy);
17 
18 	/* Tx ampdu stat */
19 	for (i = 0; i < ARRAY_SIZE(range); i++)
20 		range[i] = mt76_rr(dev, MT_MIB_ARNG(0, i));
21 
22 	for (i = 0; i < ARRAY_SIZE(bound); i++)
23 		bound[i] = MT_MIB_ARNCR_RANGE(range[i / 4], i % 4) + 1;
24 
25 	seq_puts(file, "\nPhy0\n");
26 
27 	seq_printf(file, "Length: %8d | ", bound[0]);
28 	for (i = 0; i < ARRAY_SIZE(bound) - 1; i++)
29 		seq_printf(file, "%3d  %3d | ", bound[i] + 1, bound[i + 1]);
30 
31 	seq_puts(file, "\nCount:  ");
32 	for (i = 0; i < ARRAY_SIZE(bound); i++)
33 		seq_printf(file, "%8d | ", phy->mt76->aggr_stats[i]);
34 	seq_puts(file, "\n");
35 
36 	seq_printf(file, "BA miss count: %d\n", phy->mib.ba_miss_cnt);
37 }
38 
39 int mt792x_tx_stats_show(struct seq_file *file, void *data)
40 {
41 	struct mt792x_dev *dev = file->private;
42 	struct mt792x_phy *phy = &dev->phy;
43 	struct mt76_mib_stats *mib = &phy->mib;
44 	int i;
45 
46 	mt792x_mutex_acquire(dev);
47 
48 	mt792x_ampdu_stat_read_phy(phy, file);
49 
50 	seq_puts(file, "Tx MSDU stat:\n");
51 	for (i = 0; i < ARRAY_SIZE(mib->tx_amsdu); i++) {
52 		seq_printf(file, "AMSDU pack count of %d MSDU in TXD: %8d ",
53 			   i + 1, mib->tx_amsdu[i]);
54 		if (mib->tx_amsdu_cnt)
55 			seq_printf(file, "(%3d%%)\n",
56 				   mib->tx_amsdu[i] * 100 / mib->tx_amsdu_cnt);
57 		else
58 			seq_puts(file, "\n");
59 	}
60 
61 	mt792x_mutex_release(dev);
62 
63 	return 0;
64 }
65 EXPORT_SYMBOL_GPL(mt792x_tx_stats_show);
66 
67 int mt792x_queues_acq(struct seq_file *s, void *data)
68 {
69 	struct mt792x_dev *dev = dev_get_drvdata(s->private);
70 	int i;
71 
72 	mt792x_mutex_acquire(dev);
73 
74 	for (i = 0; i < 4; i++) {
75 		u32 ctrl, val, qlen = 0;
76 		int j;
77 
78 		val = mt76_rr(dev, MT_PLE_AC_QEMPTY(i));
79 		ctrl = BIT(31) | BIT(11) | (i << 24);
80 
81 		for (j = 0; j < 32; j++) {
82 			if (val & BIT(j))
83 				continue;
84 
85 			mt76_wr(dev, MT_PLE_FL_Q0_CTRL, ctrl | j);
86 			qlen += mt76_get_field(dev, MT_PLE_FL_Q3_CTRL,
87 					       GENMASK(11, 0));
88 		}
89 		seq_printf(s, "AC%d: queued=%d\n", i, qlen);
90 	}
91 
92 	mt792x_mutex_release(dev);
93 
94 	return 0;
95 }
96 EXPORT_SYMBOL_GPL(mt792x_queues_acq);
97 
98 int mt792x_queues_read(struct seq_file *s, void *data)
99 {
100 	struct mt792x_dev *dev = dev_get_drvdata(s->private);
101 	struct {
102 		struct mt76_queue *q;
103 		char *queue;
104 	} queue_map[] = {
105 		{ dev->mphy.q_tx[MT_TXQ_BE],	 "WFDMA0" },
106 		{ dev->mt76.q_mcu[MT_MCUQ_WM],	 "MCUWM"  },
107 		{ dev->mt76.q_mcu[MT_MCUQ_FWDL], "MCUFWQ" },
108 	};
109 	int i;
110 
111 	for (i = 0; i < ARRAY_SIZE(queue_map); i++) {
112 		struct mt76_queue *q = queue_map[i].q;
113 
114 		if (!q)
115 			continue;
116 
117 		seq_printf(s,
118 			   "%s:	queued=%d head=%d tail=%d\n",
119 			   queue_map[i].queue, q->queued, q->head,
120 			   q->tail);
121 	}
122 
123 	return 0;
124 }
125 EXPORT_SYMBOL_GPL(mt792x_queues_read);
126 
127 int mt792x_pm_stats(struct seq_file *s, void *data)
128 {
129 	struct mt792x_dev *dev = dev_get_drvdata(s->private);
130 	struct mt76_connac_pm *pm = &dev->pm;
131 
132 	unsigned long awake_time = pm->stats.awake_time;
133 	unsigned long doze_time = pm->stats.doze_time;
134 
135 	if (!test_bit(MT76_STATE_PM, &dev->mphy.state))
136 		awake_time += jiffies - pm->stats.last_wake_event;
137 	else
138 		doze_time += jiffies - pm->stats.last_doze_event;
139 
140 	seq_printf(s, "awake time: %14u\ndoze time: %15u\n",
141 		   jiffies_to_msecs(awake_time),
142 		   jiffies_to_msecs(doze_time));
143 
144 	seq_printf(s, "low power wakes: %9d\n", pm->stats.lp_wake);
145 
146 	return 0;
147 }
148 EXPORT_SYMBOL_GPL(mt792x_pm_stats);
149 
150 int mt792x_pm_idle_timeout_set(void *data, u64 val)
151 {
152 	struct mt792x_dev *dev = data;
153 
154 	dev->pm.idle_timeout = msecs_to_jiffies(val);
155 
156 	return 0;
157 }
158 EXPORT_SYMBOL_GPL(mt792x_pm_idle_timeout_set);
159 
160 int mt792x_pm_idle_timeout_get(void *data, u64 *val)
161 {
162 	struct mt792x_dev *dev = data;
163 
164 	*val = jiffies_to_msecs(dev->pm.idle_timeout);
165 
166 	return 0;
167 }
168 EXPORT_SYMBOL_GPL(mt792x_pm_idle_timeout_get);
169