forked from ulli-kroll/rtw88-usb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
248 lines (197 loc) · 5.39 KB
/
debug.c
File metadata and controls
248 lines (197 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright(c) 2018-2019 Realtek Corporation
*/
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/sched.h>
#include <linux/workqueue.h>
#include "main.h"
#include "coex.h"
#include "sec.h"
#include "fw.h"
#include "debug.h"
#include "phy.h"
#include "mac.h"
#ifdef CONFIG_RTW88_DEBUGFS
struct rtw_debugfs_priv {
struct rtw_dev *rtwdev;
union {
u32 result;
};
};
/* do_tx_perf */
static int rtw_debugfs_do_tx_perf(struct seq_file *s, void *data)
{
int i;
struct rtw_debugfs_priv *priv = s->private;
struct rtw_dev *rtwdev = priv->rtwdev;
u64 start_time, delta;
start_time = ktime_get_ns();
for (i = 0; i < 1000; i++)
rtw_fw_send_h2c2h_loopback(rtwdev);
delta = ktime_get_ns() - start_time;
seq_printf(s, "H2C loopback 1000, total time: %llu, average: %llu ns\n",
delta, delta / 1000);
return 0;
}
static int rtw_debugfs_do_tx_perf_open(struct inode *inode, struct file *filp)
{
return single_open(filp, rtw_debugfs_do_tx_perf, inode->i_private);
}
static const struct file_operations file_ops_do_tx_perf = {
.owner = THIS_MODULE,
.open = rtw_debugfs_do_tx_perf_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
/* usb_loopback_func */
static int rtw_debugfs_usb_loopback_func(struct seq_file *s, void *data)
{
struct rtw_debugfs_priv *priv = s->private;
struct rtw_dev *rtwdev = priv->rtwdev;
struct sk_buff *skb;
struct rtw_chip_info *chip = rtwdev->chip;
struct rtw_tx_pkt_info pkt_info = {0};
struct rtw_loopback *loopback = &rtwdev->loopback;
int size;
int cnt = 100;
u32 pktsize = 2000;
ktime_t t1, spend;
int ret = 0;
int i;
sema_init(&loopback->sema, 0);
loopback->total = cnt;
loopback->pktsize = pktsize;
rtwdev->trx_mode = RTW_TRX_MODE_LOOPBACK;
ret = rtw_mac_init(rtwdev);
if (ret) {
rtw_err(rtwdev, "failed to configure mac\n");
goto exit;
}
size = pktsize + chip->tx_pkt_desc_sz + 24;
skb = dev_alloc_skb(size);
if (!skb) {
ret = -ENOMEM;
goto trxmode_deinit;
}
loopback->rx_buf = kmalloc(pktsize, GFP_KERNEL);
if (!loopback->rx_buf) {
ret = -ENOMEM;
goto skb_deinit;
}
loopback->tx_buf = kmalloc(pktsize, GFP_KERNEL);
if (!loopback->tx_buf) {
ret = -ENOMEM;
goto rxbuf_deinit;
}
skb_put(skb, pktsize + 24);
memset(skb->data, 0x00, 24);
skb->data[0] = 0x40;
memset(skb->data + 4, 0xFF, ETH_ALEN);
memcpy(skb->data + 4 + ETH_ALEN, rtwdev->efuse.addr, ETH_ALEN);
memset(skb->data + 4 + 2 * ETH_ALEN, 0Xff, ETH_ALEN);
get_random_bytes(skb->data + 24, pktsize);
memcpy(loopback->tx_buf, skb->data + 24, pktsize);
/* set pkt_info */
pkt_info.sec_type = 0;
pkt_info.tx_pkt_size = skb->len;
pkt_info.offset = chip->tx_pkt_desc_sz;
pkt_info.qsel = 0;
pkt_info.ls = true;
loopback->cur = 0;
loopback->read_cnt = 0;
loopback->start = true;
t1 = ktime_get();
for (i = 0; i < loopback->total; i++) {
struct sk_buff *skb1;
skb1 = skb_copy(skb, GFP_ATOMIC);
if (!skb1) {
rtw_err(rtwdev, "skb_copy failed\n");
ret = -ENOMEM;
goto txbuf_deinit;
}
ret = rtw_hci_tx_write(rtwdev, &pkt_info, skb1);
if (ret) {
rtw_err(rtwdev, "rtw_hci_tx() failed\n");
goto txbuf_deinit;
}
rtw_hci_tx_kick_off(rtwdev);
}
down(&loopback->sema);
cnt += loopback->read_cnt;
spend = ktime_to_ns(ktime_sub(ktime_get(), t1)) / (cnt * 1000);
seq_printf(s, "pktsize:%d, spend: %lldus, throughput=%lldMbps\n",
pktsize, spend, pktsize * 8 / spend);
msleep(100);
if (memcmp(loopback->tx_buf, loopback->rx_buf, pktsize) == 0)
seq_printf(s, "loopback success, pktsize=%d\n", pktsize);
else
seq_printf(s, "loopback failed, pktsize=%d\n", pktsize);
loopback->start = false;
txbuf_deinit:
kfree(loopback->tx_buf);
rxbuf_deinit:
kfree(loopback->rx_buf);
skb_deinit:
dev_kfree_skb(skb);
trxmode_deinit:
rtwdev->trx_mode = RTW_TRX_MODE_NORMAL;
ret = rtw_mac_init(rtwdev);
if (ret) {
rtw_err(rtwdev, "failed to configure mac\n");
return ret;
}
exit:
return ret;
}
static int rtw_debugfs_usb_loopback_func_open(struct inode *inode,
struct file *filp)
{
return single_open(filp, rtw_debugfs_usb_loopback_func,
inode->i_private);
}
static const struct file_operations file_ops_usb_loopback_func = {
.owner = THIS_MODULE,
.open = rtw_debugfs_usb_loopback_func_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static struct rtw_debugfs_priv priv_data;
void rtw_debugfs_init(struct rtw_dev *rtwdev)
{
struct dentry *debugfs_topdir;
debugfs_topdir = debugfs_create_dir("rtw88", NULL);
rtwdev->debugfs = debugfs_topdir;
priv_data.rtwdev = rtwdev;
if (!debugfs_create_file("do_tx_perf", S_IFREG | S_IRUGO,
debugfs_topdir, &priv_data,
&file_ops_do_tx_perf))
pr_err("Unable to initialize debugfs-do_tx_perf\n");
if (!debugfs_create_file("usb_loopback_func", S_IFREG | S_IRUGO,
debugfs_topdir, &priv_data,
&file_ops_usb_loopback_func))
pr_err("Unable to initialize debugfs-usb_loopback_func\n");
}
void rtw_debugfs_deinit(struct rtw_dev *rtwdev)
{
debugfs_remove_recursive(rtwdev->debugfs);
}
#endif /* CONFIG_RTW88_DEBUGFS */
#ifdef CONFIG_RTW88_DEBUG
void __rtw_dbg(struct rtw_dev *rtwdev, enum rtw_debug_mask mask,
const char *fmt, ...)
{
struct va_format vaf = {
.fmt = fmt,
};
va_list args;
va_start(args, fmt);
vaf.va = &args;
if (rtw_debug_mask & mask)
dev_dbg(rtwdev->dev, "%pV", &vaf);
va_end(args);
}
EXPORT_SYMBOL(__rtw_dbg);
#endif /* CONFIG_RTW88_DEBUG */