xref: /linux/drivers/net/wireless/realtek/rtw88/debug.c (revision 4db102dcb0396a4ccf89b1eac0f4eb3fd167a080)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /* Copyright(c) 2018-2019  Realtek Corporation
3  */
4 
5 #include <linux/debugfs.h>
6 #include <linux/seq_file.h>
7 #include "main.h"
8 #include "coex.h"
9 #include "sec.h"
10 #include "fw.h"
11 #include "debug.h"
12 #include "phy.h"
13 #include "reg.h"
14 #include "ps.h"
15 #include "regd.h"
16 
17 #ifdef CONFIG_RTW88_DEBUGFS
18 
19 struct rtw_debugfs_priv {
20 	struct rtw_dev *rtwdev;
21 	int (*cb_read)(struct seq_file *m, void *v);
22 	ssize_t (*cb_write)(struct file *filp, const char __user *buffer,
23 			    size_t count, loff_t *loff);
24 	union {
25 		u32 cb_data;
26 		u8 *buf;
27 		struct {
28 			u32 page_offset;
29 			u32 page_num;
30 		} rsvd_page;
31 		struct {
32 			u8 rf_path;
33 			u32 rf_addr;
34 			u32 rf_mask;
35 		};
36 		struct {
37 			u32 addr;
38 			u32 len;
39 		} read_reg;
40 		struct {
41 			u8 bit;
42 		} dm_cap;
43 	};
44 };
45 
46 static const char * const rtw_dm_cap_strs[] = {
47 	[RTW_DM_CAP_NA] = "NA",
48 	[RTW_DM_CAP_TXGAPK] = "TXGAPK",
49 };
50 
51 static int rtw_debugfs_single_show(struct seq_file *m, void *v)
52 {
53 	struct rtw_debugfs_priv *debugfs_priv = m->private;
54 
55 	return debugfs_priv->cb_read(m, v);
56 }
57 
58 static ssize_t rtw_debugfs_common_write(struct file *filp,
59 					const char __user *buffer,
60 					size_t count, loff_t *loff)
61 {
62 	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
63 
64 	return debugfs_priv->cb_write(filp, buffer, count, loff);
65 }
66 
67 static ssize_t rtw_debugfs_single_write(struct file *filp,
68 					const char __user *buffer,
69 					size_t count, loff_t *loff)
70 {
71 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
72 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
73 
74 	return debugfs_priv->cb_write(filp, buffer, count, loff);
75 }
76 
77 static int rtw_debugfs_single_open_rw(struct inode *inode, struct file *filp)
78 {
79 	return single_open(filp, rtw_debugfs_single_show, inode->i_private);
80 }
81 
82 static int rtw_debugfs_close(struct inode *inode, struct file *filp)
83 {
84 	return 0;
85 }
86 
87 static const struct file_operations file_ops_single_r = {
88 	.owner = THIS_MODULE,
89 	.open = rtw_debugfs_single_open_rw,
90 	.read = seq_read,
91 	.llseek = seq_lseek,
92 	.release = single_release,
93 };
94 
95 static const struct file_operations file_ops_single_rw = {
96 	.owner = THIS_MODULE,
97 	.open = rtw_debugfs_single_open_rw,
98 	.release = single_release,
99 	.read = seq_read,
100 	.llseek = seq_lseek,
101 	.write = rtw_debugfs_single_write,
102 };
103 
104 static const struct file_operations file_ops_common_write = {
105 	.owner = THIS_MODULE,
106 	.write = rtw_debugfs_common_write,
107 	.open = simple_open,
108 	.release = rtw_debugfs_close,
109 };
110 
111 static int rtw_debugfs_get_read_reg(struct seq_file *m, void *v)
112 {
113 	struct rtw_debugfs_priv *debugfs_priv = m->private;
114 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
115 	u32 val, len, addr;
116 
117 	len = debugfs_priv->read_reg.len;
118 	addr = debugfs_priv->read_reg.addr;
119 	switch (len) {
120 	case 1:
121 		val = rtw_read8(rtwdev, addr);
122 		seq_printf(m, "reg 0x%03x: 0x%02x\n", addr, val);
123 		break;
124 	case 2:
125 		val = rtw_read16(rtwdev, addr);
126 		seq_printf(m, "reg 0x%03x: 0x%04x\n", addr, val);
127 		break;
128 	case 4:
129 		val = rtw_read32(rtwdev, addr);
130 		seq_printf(m, "reg 0x%03x: 0x%08x\n", addr, val);
131 		break;
132 	}
133 	return 0;
134 }
135 
136 static int rtw_debugfs_get_rf_read(struct seq_file *m, void *v)
137 {
138 	struct rtw_debugfs_priv *debugfs_priv = m->private;
139 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
140 	u32 val, addr, mask;
141 	u8 path;
142 
143 	path = debugfs_priv->rf_path;
144 	addr = debugfs_priv->rf_addr;
145 	mask = debugfs_priv->rf_mask;
146 
147 	mutex_lock(&rtwdev->mutex);
148 	val = rtw_read_rf(rtwdev, path, addr, mask);
149 	mutex_unlock(&rtwdev->mutex);
150 
151 	seq_printf(m, "rf_read path:%d addr:0x%08x mask:0x%08x val=0x%08x\n",
152 		   path, addr, mask, val);
153 
154 	return 0;
155 }
156 
157 static int rtw_debugfs_get_fix_rate(struct seq_file *m, void *v)
158 {
159 	struct rtw_debugfs_priv *debugfs_priv = m->private;
160 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
161 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
162 	u8 fix_rate = dm_info->fix_rate;
163 
164 	if (fix_rate >= DESC_RATE_MAX) {
165 		seq_printf(m, "Fix rate disabled, fix_rate = %u\n", fix_rate);
166 		return 0;
167 	}
168 
169 	seq_printf(m, "Data frames fixed at desc rate %u\n", fix_rate);
170 	return 0;
171 }
172 
173 static int rtw_debugfs_copy_from_user(char tmp[], int size,
174 				      const char __user *buffer, size_t count,
175 				      int num)
176 {
177 	int tmp_len;
178 
179 	memset(tmp, 0, size);
180 
181 	if (count < num)
182 		return -EFAULT;
183 
184 	tmp_len = (count > size - 1 ? size - 1 : count);
185 
186 	if (copy_from_user(tmp, buffer, tmp_len))
187 		return -EFAULT;
188 
189 	tmp[tmp_len] = '\0';
190 
191 	return 0;
192 }
193 
194 static ssize_t rtw_debugfs_set_read_reg(struct file *filp,
195 					const char __user *buffer,
196 					size_t count, loff_t *loff)
197 {
198 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
199 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
200 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
201 	char tmp[32 + 1];
202 	u32 addr, len;
203 	int num;
204 	int ret;
205 
206 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2);
207 	if (ret)
208 		return ret;
209 
210 	num = sscanf(tmp, "%x %x", &addr, &len);
211 
212 	if (num !=  2)
213 		return -EINVAL;
214 
215 	if (len != 1 && len != 2 && len != 4) {
216 		rtw_warn(rtwdev, "read reg setting wrong len\n");
217 		return -EINVAL;
218 	}
219 	debugfs_priv->read_reg.addr = addr;
220 	debugfs_priv->read_reg.len = len;
221 
222 	return count;
223 }
224 
225 static int rtw_debugfs_get_dump_cam(struct seq_file *m, void *v)
226 {
227 	struct rtw_debugfs_priv *debugfs_priv = m->private;
228 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
229 	u32 val, command;
230 	u32 hw_key_idx = debugfs_priv->cb_data << RTW_SEC_CAM_ENTRY_SHIFT;
231 	u32 read_cmd = RTW_SEC_CMD_POLLING;
232 	int i;
233 
234 	seq_printf(m, "cam entry%d\n", debugfs_priv->cb_data);
235 	seq_puts(m, "0x0      0x1      0x2     0x3     ");
236 	seq_puts(m, "0x4     0x5\n");
237 	mutex_lock(&rtwdev->mutex);
238 	for (i = 0; i <= 5; i++) {
239 		command = read_cmd | (hw_key_idx + i);
240 		rtw_write32(rtwdev, RTW_SEC_CMD_REG, command);
241 		val = rtw_read32(rtwdev, RTW_SEC_READ_REG);
242 		seq_printf(m, "%8.8x", val);
243 		if (i < 2)
244 			seq_puts(m, " ");
245 	}
246 	seq_puts(m, "\n");
247 	mutex_unlock(&rtwdev->mutex);
248 	return 0;
249 }
250 
251 static int rtw_debugfs_get_rsvd_page(struct seq_file *m, void *v)
252 {
253 	struct rtw_debugfs_priv *debugfs_priv = m->private;
254 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
255 	u8 page_size = rtwdev->chip->page_size;
256 	u32 buf_size = debugfs_priv->rsvd_page.page_num * page_size;
257 	u32 offset = debugfs_priv->rsvd_page.page_offset * page_size;
258 	u8 *buf;
259 	int i;
260 	int ret;
261 
262 	buf = vzalloc(buf_size);
263 	if (!buf)
264 		return -ENOMEM;
265 
266 	ret = rtw_fw_dump_fifo(rtwdev, RTW_FW_FIFO_SEL_RSVD_PAGE, offset,
267 			       buf_size, (u32 *)buf);
268 	if (ret) {
269 		rtw_err(rtwdev, "failed to dump rsvd page\n");
270 		vfree(buf);
271 		return ret;
272 	}
273 
274 	for (i = 0 ; i < buf_size ; i += 8) {
275 		if (i % page_size == 0)
276 			seq_printf(m, "PAGE %d\n", (i + offset) / page_size);
277 		seq_printf(m, "%8ph\n", buf + i);
278 	}
279 	vfree(buf);
280 
281 	return 0;
282 }
283 
284 static ssize_t rtw_debugfs_set_rsvd_page(struct file *filp,
285 					 const char __user *buffer,
286 					 size_t count, loff_t *loff)
287 {
288 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
289 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
290 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
291 	char tmp[32 + 1];
292 	u32 offset, page_num;
293 	int num;
294 	int ret;
295 
296 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2);
297 	if (ret)
298 		return ret;
299 
300 	num = sscanf(tmp, "%d %d", &offset, &page_num);
301 
302 	if (num != 2) {
303 		rtw_warn(rtwdev, "invalid arguments\n");
304 		return -EINVAL;
305 	}
306 
307 	debugfs_priv->rsvd_page.page_offset = offset;
308 	debugfs_priv->rsvd_page.page_num = page_num;
309 
310 	return count;
311 }
312 
313 static ssize_t rtw_debugfs_set_single_input(struct file *filp,
314 					    const char __user *buffer,
315 					    size_t count, loff_t *loff)
316 {
317 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
318 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
319 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
320 	char tmp[32 + 1];
321 	u32 input;
322 	int num;
323 	int ret;
324 
325 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
326 	if (ret)
327 		return ret;
328 
329 	num = kstrtoint(tmp, 0, &input);
330 
331 	if (num) {
332 		rtw_warn(rtwdev, "kstrtoint failed\n");
333 		return num;
334 	}
335 
336 	debugfs_priv->cb_data = input;
337 
338 	return count;
339 }
340 
341 static ssize_t rtw_debugfs_set_write_reg(struct file *filp,
342 					 const char __user *buffer,
343 					 size_t count, loff_t *loff)
344 {
345 	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
346 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
347 	char tmp[32 + 1];
348 	u32 addr, val, len;
349 	int num;
350 	int ret;
351 
352 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
353 	if (ret)
354 		return ret;
355 
356 	/* write BB/MAC register */
357 	num = sscanf(tmp, "%x %x %x", &addr, &val, &len);
358 
359 	if (num !=  3)
360 		return -EINVAL;
361 
362 	switch (len) {
363 	case 1:
364 		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
365 			"reg write8 0x%03x: 0x%08x\n", addr, val);
366 		rtw_write8(rtwdev, addr, (u8)val);
367 		break;
368 	case 2:
369 		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
370 			"reg write16 0x%03x: 0x%08x\n", addr, val);
371 		rtw_write16(rtwdev, addr, (u16)val);
372 		break;
373 	case 4:
374 		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
375 			"reg write32 0x%03x: 0x%08x\n", addr, val);
376 		rtw_write32(rtwdev, addr, (u32)val);
377 		break;
378 	default:
379 		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
380 			"error write length = %d\n", len);
381 		break;
382 	}
383 
384 	return count;
385 }
386 
387 static ssize_t rtw_debugfs_set_h2c(struct file *filp,
388 				   const char __user *buffer,
389 				   size_t count, loff_t *loff)
390 {
391 	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
392 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
393 	char tmp[32 + 1];
394 	u8 param[8];
395 	int num;
396 	int ret;
397 
398 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
399 	if (ret)
400 		return ret;
401 
402 	num = sscanf(tmp, "%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx",
403 		     &param[0], &param[1], &param[2], &param[3],
404 		     &param[4], &param[5], &param[6], &param[7]);
405 	if (num != 8) {
406 		rtw_warn(rtwdev, "invalid H2C command format for debug\n");
407 		return -EINVAL;
408 	}
409 
410 	mutex_lock(&rtwdev->mutex);
411 	rtw_fw_h2c_cmd_dbg(rtwdev, param);
412 	mutex_unlock(&rtwdev->mutex);
413 
414 	return count;
415 }
416 
417 static ssize_t rtw_debugfs_set_rf_write(struct file *filp,
418 					const char __user *buffer,
419 					size_t count, loff_t *loff)
420 {
421 	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
422 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
423 	char tmp[32 + 1];
424 	u32 path, addr, mask, val;
425 	int num;
426 	int ret;
427 
428 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 4);
429 	if (ret)
430 		return ret;
431 
432 	num = sscanf(tmp, "%x %x %x %x", &path, &addr, &mask, &val);
433 
434 	if (num !=  4) {
435 		rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n");
436 		return -EINVAL;
437 	}
438 
439 	mutex_lock(&rtwdev->mutex);
440 	rtw_write_rf(rtwdev, path, addr, mask, val);
441 	mutex_unlock(&rtwdev->mutex);
442 	rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
443 		"write_rf path:%d addr:0x%08x mask:0x%08x, val:0x%08x\n",
444 		path, addr, mask, val);
445 
446 	return count;
447 }
448 
449 static ssize_t rtw_debugfs_set_rf_read(struct file *filp,
450 				       const char __user *buffer,
451 				       size_t count, loff_t *loff)
452 {
453 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
454 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
455 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
456 	char tmp[32 + 1];
457 	u32 path, addr, mask;
458 	int num;
459 	int ret;
460 
461 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
462 	if (ret)
463 		return ret;
464 
465 	num = sscanf(tmp, "%x %x %x", &path, &addr, &mask);
466 
467 	if (num !=  3) {
468 		rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n");
469 		return -EINVAL;
470 	}
471 
472 	debugfs_priv->rf_path = path;
473 	debugfs_priv->rf_addr = addr;
474 	debugfs_priv->rf_mask = mask;
475 
476 	return count;
477 }
478 
479 static ssize_t rtw_debugfs_set_fix_rate(struct file *filp,
480 					const char __user *buffer,
481 					size_t count, loff_t *loff)
482 {
483 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
484 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
485 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
486 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
487 	u8 fix_rate;
488 	char tmp[32 + 1];
489 	int ret;
490 
491 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
492 	if (ret)
493 		return ret;
494 
495 	ret = kstrtou8(tmp, 0, &fix_rate);
496 	if (ret) {
497 		rtw_warn(rtwdev, "invalid args, [rate]\n");
498 		return ret;
499 	}
500 
501 	dm_info->fix_rate = fix_rate;
502 
503 	return count;
504 }
505 
506 static int rtw_debug_get_mac_page(struct seq_file *m, void *v)
507 {
508 	struct rtw_debugfs_priv *debugfs_priv = m->private;
509 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
510 	u32 page = debugfs_priv->cb_data;
511 	int i, n;
512 	int max = 0xff;
513 
514 	rtw_read32(rtwdev, debugfs_priv->cb_data);
515 	for (n = 0; n <= max; ) {
516 		seq_printf(m, "\n%8.8x  ", n + page);
517 		for (i = 0; i < 4 && n <= max; i++, n += 4)
518 			seq_printf(m, "%8.8x    ",
519 				   rtw_read32(rtwdev, (page | n)));
520 	}
521 	seq_puts(m, "\n");
522 	return 0;
523 }
524 
525 static int rtw_debug_get_bb_page(struct seq_file *m, void *v)
526 {
527 	struct rtw_debugfs_priv *debugfs_priv = m->private;
528 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
529 	u32 page = debugfs_priv->cb_data;
530 	int i, n;
531 	int max = 0xff;
532 
533 	rtw_read32(rtwdev, debugfs_priv->cb_data);
534 	for (n = 0; n <= max; ) {
535 		seq_printf(m, "\n%8.8x  ", n + page);
536 		for (i = 0; i < 4 && n <= max; i++, n += 4)
537 			seq_printf(m, "%8.8x    ",
538 				   rtw_read32(rtwdev, (page | n)));
539 	}
540 	seq_puts(m, "\n");
541 	return 0;
542 }
543 
544 static int rtw_debug_get_rf_dump(struct seq_file *m, void *v)
545 {
546 	struct rtw_debugfs_priv *debugfs_priv = m->private;
547 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
548 	u32 addr, offset, data;
549 	u8 path;
550 
551 	mutex_lock(&rtwdev->mutex);
552 
553 	for (path = 0; path < rtwdev->hal.rf_path_num; path++) {
554 		seq_printf(m, "RF path:%d\n", path);
555 		for (addr = 0; addr < 0x100; addr += 4) {
556 			seq_printf(m, "%8.8x  ", addr);
557 			for (offset = 0; offset < 4; offset++) {
558 				data = rtw_read_rf(rtwdev, path, addr + offset,
559 						   0xffffffff);
560 				seq_printf(m, "%8.8x    ", data);
561 			}
562 			seq_puts(m, "\n");
563 		}
564 		seq_puts(m, "\n");
565 	}
566 
567 	mutex_unlock(&rtwdev->mutex);
568 
569 	return 0;
570 }
571 
572 static void rtw_print_cck_rate_txt(struct seq_file *m, u8 rate)
573 {
574 	static const char * const
575 	cck_rate[] = {"1M", "2M", "5.5M", "11M"};
576 	u8 idx = rate - DESC_RATE1M;
577 
578 	seq_printf(m, " CCK_%-5s", cck_rate[idx]);
579 }
580 
581 static void rtw_print_ofdm_rate_txt(struct seq_file *m, u8 rate)
582 {
583 	static const char * const
584 	ofdm_rate[] = {"6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M"};
585 	u8 idx = rate - DESC_RATE6M;
586 
587 	seq_printf(m, " OFDM_%-4s", ofdm_rate[idx]);
588 }
589 
590 static void rtw_print_ht_rate_txt(struct seq_file *m, u8 rate)
591 {
592 	u8 mcs_n = rate - DESC_RATEMCS0;
593 
594 	seq_printf(m, " MCS%-6u", mcs_n);
595 }
596 
597 static void rtw_print_vht_rate_txt(struct seq_file *m, u8 rate)
598 {
599 	u8 idx = rate - DESC_RATEVHT1SS_MCS0;
600 	u8 n_ss, mcs_n;
601 
602 	/* n spatial stream */
603 	n_ss = 1 + idx / 10;
604 	/* MCS n */
605 	mcs_n = idx % 10;
606 	seq_printf(m, " VHT%uSMCS%u", n_ss, mcs_n);
607 }
608 
609 static void rtw_print_rate(struct seq_file *m, u8 rate)
610 {
611 	switch (rate) {
612 	case DESC_RATE1M...DESC_RATE11M:
613 		rtw_print_cck_rate_txt(m, rate);
614 		break;
615 	case DESC_RATE6M...DESC_RATE54M:
616 		rtw_print_ofdm_rate_txt(m, rate);
617 		break;
618 	case DESC_RATEMCS0...DESC_RATEMCS15:
619 		rtw_print_ht_rate_txt(m, rate);
620 		break;
621 	case DESC_RATEVHT1SS_MCS0...DESC_RATEVHT2SS_MCS9:
622 		rtw_print_vht_rate_txt(m, rate);
623 		break;
624 	default:
625 		seq_printf(m, " Unknown rate=0x%x\n", rate);
626 		break;
627 	}
628 }
629 
630 #define case_REGD(src) \
631 	case RTW_REGD_##src: return #src
632 
633 static const char *rtw_get_regd_string(u8 regd)
634 {
635 	switch (regd) {
636 	case_REGD(FCC);
637 	case_REGD(MKK);
638 	case_REGD(ETSI);
639 	case_REGD(IC);
640 	case_REGD(KCC);
641 	case_REGD(ACMA);
642 	case_REGD(CHILE);
643 	case_REGD(UKRAINE);
644 	case_REGD(MEXICO);
645 	case_REGD(CN);
646 	case_REGD(WW);
647 	default:
648 		return "Unknown";
649 	}
650 }
651 
652 static int rtw_debugfs_get_tx_pwr_tbl(struct seq_file *m, void *v)
653 {
654 	struct rtw_debugfs_priv *debugfs_priv = m->private;
655 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
656 	struct rtw_hal *hal = &rtwdev->hal;
657 	u8 path, rate, bw, ch, regd;
658 	struct rtw_power_params pwr_param = {0};
659 
660 	mutex_lock(&rtwdev->mutex);
661 	bw = hal->current_band_width;
662 	ch = hal->current_channel;
663 	regd = rtw_regd_get(rtwdev);
664 
665 	seq_printf(m, "channel: %u\n", ch);
666 	seq_printf(m, "bandwidth: %u\n", bw);
667 	seq_printf(m, "regulatory: %s\n", rtw_get_regd_string(regd));
668 	seq_printf(m, "%-4s %-10s %-9s %-9s (%-4s %-4s %-4s) %-4s\n",
669 		   "path", "rate", "pwr", "base", "byr", "lmt", "sar", "rem");
670 
671 	mutex_lock(&hal->tx_power_mutex);
672 	for (path = RF_PATH_A; path <= RF_PATH_B; path++) {
673 		/* there is no CCK rates used in 5G */
674 		if (hal->current_band_type == RTW_BAND_5G)
675 			rate = DESC_RATE6M;
676 		else
677 			rate = DESC_RATE1M;
678 
679 		/* now, not support vht 3ss and vht 4ss*/
680 		for (; rate <= DESC_RATEVHT2SS_MCS9; rate++) {
681 			/* now, not support ht 3ss and ht 4ss*/
682 			if (rate > DESC_RATEMCS15 &&
683 			    rate < DESC_RATEVHT1SS_MCS0)
684 				continue;
685 
686 			rtw_get_tx_power_params(rtwdev, path, rate, bw,
687 						ch, regd, &pwr_param);
688 
689 			seq_printf(m, "%4c ", path + 'A');
690 			rtw_print_rate(m, rate);
691 			seq_printf(m, " %3u(0x%02x) %4u %4d (%4d %4d %4d) %4d\n",
692 				   hal->tx_pwr_tbl[path][rate],
693 				   hal->tx_pwr_tbl[path][rate],
694 				   pwr_param.pwr_base,
695 				   min3(pwr_param.pwr_offset,
696 					pwr_param.pwr_limit,
697 					pwr_param.pwr_sar),
698 				   pwr_param.pwr_offset, pwr_param.pwr_limit,
699 				   pwr_param.pwr_sar,
700 				   pwr_param.pwr_remnant);
701 		}
702 	}
703 
704 	mutex_unlock(&hal->tx_power_mutex);
705 	mutex_unlock(&rtwdev->mutex);
706 
707 	return 0;
708 }
709 
710 void rtw_debugfs_get_simple_phy_info(struct seq_file *m)
711 {
712 	struct rtw_debugfs_priv *debugfs_priv = m->private;
713 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
714 	struct rtw_hal *hal = &rtwdev->hal;
715 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
716 	struct rtw_traffic_stats *stats = &rtwdev->stats;
717 
718 	seq_printf(m, "%-40s = %ddBm/ %d\n", "RSSI/ STA Channel",
719 		   dm_info->rssi[RF_PATH_A] - 100, hal->current_channel);
720 
721 	seq_printf(m, "TP {Tx, Rx} = {%u, %u}Mbps\n",
722 		   stats->tx_throughput, stats->rx_throughput);
723 
724 	seq_puts(m, "[Tx Rate] = ");
725 	rtw_print_rate(m, dm_info->tx_rate);
726 	seq_printf(m, "(0x%x)\n", dm_info->tx_rate);
727 
728 	seq_puts(m, "[Rx Rate] = ");
729 	rtw_print_rate(m, dm_info->curr_rx_rate);
730 	seq_printf(m, "(0x%x)\n", dm_info->curr_rx_rate);
731 }
732 
733 static int rtw_debugfs_get_phy_info(struct seq_file *m, void *v)
734 {
735 	struct rtw_debugfs_priv *debugfs_priv = m->private;
736 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
737 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
738 	struct rtw_traffic_stats *stats = &rtwdev->stats;
739 	struct rtw_pkt_count *last_cnt = &dm_info->last_pkt_count;
740 	struct rtw_efuse *efuse = &rtwdev->efuse;
741 	struct ewma_evm *ewma_evm = dm_info->ewma_evm;
742 	struct ewma_snr *ewma_snr = dm_info->ewma_snr;
743 	u8 ss, rate_id;
744 
745 	seq_puts(m, "==========[Common Info]========\n");
746 	seq_printf(m, "Is link = %c\n", rtw_is_assoc(rtwdev) ? 'Y' : 'N');
747 	seq_printf(m, "Current CH(fc) = %u\n", rtwdev->hal.current_channel);
748 	seq_printf(m, "Current BW = %u\n", rtwdev->hal.current_band_width);
749 	seq_printf(m, "Current IGI = 0x%x\n", dm_info->igi_history[0]);
750 	seq_printf(m, "TP {Tx, Rx} = {%u, %u}Mbps\n",
751 		   stats->tx_throughput, stats->rx_throughput);
752 	seq_printf(m, "1SS for TX and RX = %c\n\n", rtwdev->hal.txrx_1ss ?
753 		   'Y' : 'N');
754 
755 	seq_puts(m, "==========[Tx Phy Info]========\n");
756 	seq_puts(m, "[Tx Rate] = ");
757 	rtw_print_rate(m, dm_info->tx_rate);
758 	seq_printf(m, "(0x%x)\n\n", dm_info->tx_rate);
759 
760 	seq_puts(m, "==========[Rx Phy Info]========\n");
761 	seq_printf(m, "[Rx Beacon Count] = %u\n", last_cnt->num_bcn_pkt);
762 	seq_puts(m, "[Rx Rate] = ");
763 	rtw_print_rate(m, dm_info->curr_rx_rate);
764 	seq_printf(m, "(0x%x)\n", dm_info->curr_rx_rate);
765 
766 	seq_puts(m, "[Rx Rate Count]:\n");
767 	seq_printf(m, " * CCK = {%u, %u, %u, %u}\n",
768 		   last_cnt->num_qry_pkt[DESC_RATE1M],
769 		   last_cnt->num_qry_pkt[DESC_RATE2M],
770 		   last_cnt->num_qry_pkt[DESC_RATE5_5M],
771 		   last_cnt->num_qry_pkt[DESC_RATE11M]);
772 
773 	seq_printf(m, " * OFDM = {%u, %u, %u, %u, %u, %u, %u, %u}\n",
774 		   last_cnt->num_qry_pkt[DESC_RATE6M],
775 		   last_cnt->num_qry_pkt[DESC_RATE9M],
776 		   last_cnt->num_qry_pkt[DESC_RATE12M],
777 		   last_cnt->num_qry_pkt[DESC_RATE18M],
778 		   last_cnt->num_qry_pkt[DESC_RATE24M],
779 		   last_cnt->num_qry_pkt[DESC_RATE36M],
780 		   last_cnt->num_qry_pkt[DESC_RATE48M],
781 		   last_cnt->num_qry_pkt[DESC_RATE54M]);
782 
783 	for (ss = 0; ss < efuse->hw_cap.nss; ss++) {
784 		rate_id = DESC_RATEMCS0 + ss * 8;
785 		seq_printf(m, " * HT_MCS[%u:%u] = {%u, %u, %u, %u, %u, %u, %u, %u}\n",
786 			   ss * 8, ss * 8 + 7,
787 			   last_cnt->num_qry_pkt[rate_id],
788 			   last_cnt->num_qry_pkt[rate_id + 1],
789 			   last_cnt->num_qry_pkt[rate_id + 2],
790 			   last_cnt->num_qry_pkt[rate_id + 3],
791 			   last_cnt->num_qry_pkt[rate_id + 4],
792 			   last_cnt->num_qry_pkt[rate_id + 5],
793 			   last_cnt->num_qry_pkt[rate_id + 6],
794 			   last_cnt->num_qry_pkt[rate_id + 7]);
795 	}
796 
797 	for (ss = 0; ss < efuse->hw_cap.nss; ss++) {
798 		rate_id = DESC_RATEVHT1SS_MCS0 + ss * 10;
799 		seq_printf(m, " * VHT_MCS-%uss MCS[0:9] = {%u, %u, %u, %u, %u, %u, %u, %u, %u, %u}\n",
800 			   ss + 1,
801 			   last_cnt->num_qry_pkt[rate_id],
802 			   last_cnt->num_qry_pkt[rate_id + 1],
803 			   last_cnt->num_qry_pkt[rate_id + 2],
804 			   last_cnt->num_qry_pkt[rate_id + 3],
805 			   last_cnt->num_qry_pkt[rate_id + 4],
806 			   last_cnt->num_qry_pkt[rate_id + 5],
807 			   last_cnt->num_qry_pkt[rate_id + 6],
808 			   last_cnt->num_qry_pkt[rate_id + 7],
809 			   last_cnt->num_qry_pkt[rate_id + 8],
810 			   last_cnt->num_qry_pkt[rate_id + 9]);
811 	}
812 
813 	seq_printf(m, "[RSSI(dBm)] = {%d, %d}\n",
814 		   dm_info->rssi[RF_PATH_A] - 100,
815 		   dm_info->rssi[RF_PATH_B] - 100);
816 	seq_printf(m, "[Rx EVM(dB)] = {-%d, -%d}\n",
817 		   dm_info->rx_evm_dbm[RF_PATH_A],
818 		   dm_info->rx_evm_dbm[RF_PATH_B]);
819 	seq_printf(m, "[Rx SNR] = {%d, %d}\n",
820 		   dm_info->rx_snr[RF_PATH_A],
821 		   dm_info->rx_snr[RF_PATH_B]);
822 	seq_printf(m, "[CFO_tail(KHz)] = {%d, %d}\n",
823 		   dm_info->cfo_tail[RF_PATH_A],
824 		   dm_info->cfo_tail[RF_PATH_B]);
825 
826 	if (dm_info->curr_rx_rate >= DESC_RATE11M) {
827 		seq_puts(m, "[Rx Average Status]:\n");
828 		seq_printf(m, " * OFDM, EVM: {-%d}, SNR: {%d}\n",
829 			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_OFDM]),
830 			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_OFDM_A]));
831 		seq_printf(m, " * 1SS, EVM: {-%d}, SNR: {%d}\n",
832 			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_1SS]),
833 			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_1SS_A]));
834 		seq_printf(m, " * 2SS, EVM: {-%d, -%d}, SNR: {%d, %d}\n",
835 			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_2SS_A]),
836 			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_2SS_B]),
837 			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_2SS_A]),
838 			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_2SS_B]));
839 	}
840 
841 	seq_puts(m, "[Rx Counter]:\n");
842 	seq_printf(m, " * CCA (CCK, OFDM, Total) = (%u, %u, %u)\n",
843 		   dm_info->cck_cca_cnt,
844 		   dm_info->ofdm_cca_cnt,
845 		   dm_info->total_cca_cnt);
846 	seq_printf(m, " * False Alarm (CCK, OFDM, Total) = (%u, %u, %u)\n",
847 		   dm_info->cck_fa_cnt,
848 		   dm_info->ofdm_fa_cnt,
849 		   dm_info->total_fa_cnt);
850 	seq_printf(m, " * CCK cnt (ok, err) = (%u, %u)\n",
851 		   dm_info->cck_ok_cnt, dm_info->cck_err_cnt);
852 	seq_printf(m, " * OFDM cnt (ok, err) = (%u, %u)\n",
853 		   dm_info->ofdm_ok_cnt, dm_info->ofdm_err_cnt);
854 	seq_printf(m, " * HT cnt (ok, err) = (%u, %u)\n",
855 		   dm_info->ht_ok_cnt, dm_info->ht_err_cnt);
856 	seq_printf(m, " * VHT cnt (ok, err) = (%u, %u)\n",
857 		   dm_info->vht_ok_cnt, dm_info->vht_err_cnt);
858 
859 	return 0;
860 }
861 
862 static int rtw_debugfs_get_coex_info(struct seq_file *m, void *v)
863 {
864 	struct rtw_debugfs_priv *debugfs_priv = m->private;
865 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
866 
867 	mutex_lock(&rtwdev->mutex);
868 	rtw_coex_display_coex_info(rtwdev, m);
869 	mutex_unlock(&rtwdev->mutex);
870 
871 	return 0;
872 }
873 
874 static ssize_t rtw_debugfs_set_coex_enable(struct file *filp,
875 					   const char __user *buffer,
876 					   size_t count, loff_t *loff)
877 {
878 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
879 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
880 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
881 	struct rtw_coex *coex = &rtwdev->coex;
882 	char tmp[32 + 1];
883 	bool enable;
884 	int ret;
885 
886 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
887 	if (ret)
888 		return ret;
889 
890 	ret = kstrtobool(tmp, &enable);
891 	if (ret) {
892 		rtw_warn(rtwdev, "invalid arguments\n");
893 		return ret;
894 	}
895 
896 	mutex_lock(&rtwdev->mutex);
897 	coex->manual_control = !enable;
898 	mutex_unlock(&rtwdev->mutex);
899 
900 	return count;
901 }
902 
903 static int rtw_debugfs_get_coex_enable(struct seq_file *m, void *v)
904 {
905 	struct rtw_debugfs_priv *debugfs_priv = m->private;
906 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
907 	struct rtw_coex *coex = &rtwdev->coex;
908 
909 	seq_printf(m, "coex mechanism %s\n",
910 		   coex->manual_control ? "disabled" : "enabled");
911 
912 	return 0;
913 }
914 
915 static ssize_t rtw_debugfs_set_edcca_enable(struct file *filp,
916 					    const char __user *buffer,
917 					    size_t count, loff_t *loff)
918 {
919 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
920 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
921 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
922 	bool input;
923 	int err;
924 
925 	err = kstrtobool_from_user(buffer, count, &input);
926 	if (err)
927 		return err;
928 
929 	rtw_edcca_enabled = input;
930 	rtw_phy_adaptivity_set_mode(rtwdev);
931 
932 	return count;
933 }
934 
935 static int rtw_debugfs_get_edcca_enable(struct seq_file *m, void *v)
936 {
937 	struct rtw_debugfs_priv *debugfs_priv = m->private;
938 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
939 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
940 
941 	seq_printf(m, "EDCCA %s: EDCCA mode %d\n",
942 		   rtw_edcca_enabled ? "enabled" : "disabled",
943 		   dm_info->edcca_mode);
944 	return 0;
945 }
946 
947 static ssize_t rtw_debugfs_set_fw_crash(struct file *filp,
948 					const char __user *buffer,
949 					size_t count, loff_t *loff)
950 {
951 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
952 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
953 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
954 	char tmp[32 + 1];
955 	bool input;
956 	int ret;
957 
958 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
959 	if (ret)
960 		return ret;
961 
962 	ret = kstrtobool(tmp, &input);
963 	if (ret)
964 		return -EINVAL;
965 
966 	if (!input)
967 		return -EINVAL;
968 
969 	if (test_bit(RTW_FLAG_RESTARTING, rtwdev->flags))
970 		return -EINPROGRESS;
971 
972 	mutex_lock(&rtwdev->mutex);
973 	rtw_leave_lps_deep(rtwdev);
974 	set_bit(RTW_FLAG_RESTART_TRIGGERING, rtwdev->flags);
975 	rtw_write8(rtwdev, REG_HRCV_MSG, 1);
976 	mutex_unlock(&rtwdev->mutex);
977 
978 	return count;
979 }
980 
981 static int rtw_debugfs_get_fw_crash(struct seq_file *m, void *v)
982 {
983 	struct rtw_debugfs_priv *debugfs_priv = m->private;
984 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
985 
986 	seq_printf(m, "%d\n",
987 		   test_bit(RTW_FLAG_RESTART_TRIGGERING, rtwdev->flags) ||
988 		   test_bit(RTW_FLAG_RESTARTING, rtwdev->flags));
989 	return 0;
990 }
991 
992 static ssize_t rtw_debugfs_set_force_lowest_basic_rate(struct file *filp,
993 						       const char __user *buffer,
994 						       size_t count, loff_t *loff)
995 {
996 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
997 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
998 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
999 	bool input;
1000 	int err;
1001 
1002 	err = kstrtobool_from_user(buffer, count, &input);
1003 	if (err)
1004 		return err;
1005 
1006 	if (input)
1007 		set_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags);
1008 	else
1009 		clear_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags);
1010 
1011 	return count;
1012 }
1013 
1014 static int rtw_debugfs_get_force_lowest_basic_rate(struct seq_file *m, void *v)
1015 {
1016 	struct rtw_debugfs_priv *debugfs_priv = m->private;
1017 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
1018 
1019 	seq_printf(m, "force lowest basic rate: %d\n",
1020 		   test_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags));
1021 
1022 	return 0;
1023 }
1024 
1025 static ssize_t rtw_debugfs_set_dm_cap(struct file *filp,
1026 				      const char __user *buffer,
1027 				      size_t count, loff_t *loff)
1028 {
1029 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
1030 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
1031 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
1032 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1033 	int bit;
1034 	bool en;
1035 
1036 	if (kstrtoint_from_user(buffer, count, 10, &bit))
1037 		return -EINVAL;
1038 
1039 	en = bit > 0;
1040 	bit = abs(bit);
1041 
1042 	if (bit >= RTW_DM_CAP_NUM) {
1043 		rtw_warn(rtwdev, "unknown DM CAP %d\n", bit);
1044 		return -EINVAL;
1045 	}
1046 
1047 	if (en)
1048 		dm_info->dm_flags &= ~BIT(bit);
1049 	else
1050 		dm_info->dm_flags |= BIT(bit);
1051 
1052 	debugfs_priv->dm_cap.bit = bit;
1053 
1054 	return count;
1055 }
1056 
1057 static void dump_gapk_status(struct rtw_dev *rtwdev, struct seq_file *m)
1058 {
1059 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1060 	struct rtw_gapk_info *txgapk = &rtwdev->dm_info.gapk;
1061 	int i, path;
1062 	u32 val;
1063 
1064 	seq_printf(m, "\n(%2d) %c%s\n\n", RTW_DM_CAP_TXGAPK,
1065 		   dm_info->dm_flags & BIT(RTW_DM_CAP_TXGAPK) ? '-' : '+',
1066 		   rtw_dm_cap_strs[RTW_DM_CAP_TXGAPK]);
1067 
1068 	mutex_lock(&rtwdev->mutex);
1069 
1070 	for (path = 0; path < rtwdev->hal.rf_path_num; path++) {
1071 		val = rtw_read_rf(rtwdev, path, RF_GAINTX, RFREG_MASK);
1072 		seq_printf(m, "path %d:\n0x%x = 0x%x\n", path, RF_GAINTX, val);
1073 
1074 		for (i = 0; i < RF_HW_OFFSET_NUM; i++)
1075 			seq_printf(m, "[TXGAPK] offset %d %d\n",
1076 				   txgapk->rf3f_fs[path][i], i);
1077 		seq_puts(m, "\n");
1078 	}
1079 	mutex_unlock(&rtwdev->mutex);
1080 }
1081 
1082 static int rtw_debugfs_get_dm_cap(struct seq_file *m, void *v)
1083 {
1084 	struct rtw_debugfs_priv *debugfs_priv = m->private;
1085 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
1086 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1087 	int i;
1088 
1089 	switch (debugfs_priv->dm_cap.bit) {
1090 	case RTW_DM_CAP_TXGAPK:
1091 		dump_gapk_status(rtwdev, m);
1092 		break;
1093 	default:
1094 		for (i = 1; i < RTW_DM_CAP_NUM; i++) {
1095 			seq_printf(m, "(%2d) %c%s\n", i,
1096 				   dm_info->dm_flags & BIT(i) ? '-' : '+',
1097 				   rtw_dm_cap_strs[i]);
1098 		}
1099 		break;
1100 	}
1101 	debugfs_priv->dm_cap.bit = RTW_DM_CAP_NA;
1102 	return 0;
1103 }
1104 
1105 #define rtw_debug_impl_mac(page, addr)				\
1106 static struct rtw_debugfs_priv rtw_debug_priv_mac_ ##page = {	\
1107 	.cb_read = rtw_debug_get_mac_page,			\
1108 	.cb_data = addr,					\
1109 }
1110 
1111 rtw_debug_impl_mac(0, 0x0000);
1112 rtw_debug_impl_mac(1, 0x0100);
1113 rtw_debug_impl_mac(2, 0x0200);
1114 rtw_debug_impl_mac(3, 0x0300);
1115 rtw_debug_impl_mac(4, 0x0400);
1116 rtw_debug_impl_mac(5, 0x0500);
1117 rtw_debug_impl_mac(6, 0x0600);
1118 rtw_debug_impl_mac(7, 0x0700);
1119 rtw_debug_impl_mac(10, 0x1000);
1120 rtw_debug_impl_mac(11, 0x1100);
1121 rtw_debug_impl_mac(12, 0x1200);
1122 rtw_debug_impl_mac(13, 0x1300);
1123 rtw_debug_impl_mac(14, 0x1400);
1124 rtw_debug_impl_mac(15, 0x1500);
1125 rtw_debug_impl_mac(16, 0x1600);
1126 rtw_debug_impl_mac(17, 0x1700);
1127 
1128 #define rtw_debug_impl_bb(page, addr)			\
1129 static struct rtw_debugfs_priv rtw_debug_priv_bb_ ##page = {	\
1130 	.cb_read = rtw_debug_get_bb_page,			\
1131 	.cb_data = addr,					\
1132 }
1133 
1134 rtw_debug_impl_bb(8, 0x0800);
1135 rtw_debug_impl_bb(9, 0x0900);
1136 rtw_debug_impl_bb(a, 0x0a00);
1137 rtw_debug_impl_bb(b, 0x0b00);
1138 rtw_debug_impl_bb(c, 0x0c00);
1139 rtw_debug_impl_bb(d, 0x0d00);
1140 rtw_debug_impl_bb(e, 0x0e00);
1141 rtw_debug_impl_bb(f, 0x0f00);
1142 rtw_debug_impl_bb(18, 0x1800);
1143 rtw_debug_impl_bb(19, 0x1900);
1144 rtw_debug_impl_bb(1a, 0x1a00);
1145 rtw_debug_impl_bb(1b, 0x1b00);
1146 rtw_debug_impl_bb(1c, 0x1c00);
1147 rtw_debug_impl_bb(1d, 0x1d00);
1148 rtw_debug_impl_bb(1e, 0x1e00);
1149 rtw_debug_impl_bb(1f, 0x1f00);
1150 rtw_debug_impl_bb(2c, 0x2c00);
1151 rtw_debug_impl_bb(2d, 0x2d00);
1152 rtw_debug_impl_bb(40, 0x4000);
1153 rtw_debug_impl_bb(41, 0x4100);
1154 
1155 static struct rtw_debugfs_priv rtw_debug_priv_rf_dump = {
1156 	.cb_read = rtw_debug_get_rf_dump,
1157 };
1158 
1159 static struct rtw_debugfs_priv rtw_debug_priv_tx_pwr_tbl = {
1160 	.cb_read = rtw_debugfs_get_tx_pwr_tbl,
1161 };
1162 
1163 static struct rtw_debugfs_priv rtw_debug_priv_write_reg = {
1164 	.cb_write = rtw_debugfs_set_write_reg,
1165 };
1166 
1167 static struct rtw_debugfs_priv rtw_debug_priv_h2c = {
1168 	.cb_write = rtw_debugfs_set_h2c,
1169 };
1170 
1171 static struct rtw_debugfs_priv rtw_debug_priv_rf_write = {
1172 	.cb_write = rtw_debugfs_set_rf_write,
1173 };
1174 
1175 static struct rtw_debugfs_priv rtw_debug_priv_rf_read = {
1176 	.cb_write = rtw_debugfs_set_rf_read,
1177 	.cb_read = rtw_debugfs_get_rf_read,
1178 };
1179 
1180 static struct rtw_debugfs_priv rtw_debug_priv_read_reg = {
1181 	.cb_write = rtw_debugfs_set_read_reg,
1182 	.cb_read = rtw_debugfs_get_read_reg,
1183 };
1184 
1185 static struct rtw_debugfs_priv rtw_debug_priv_fix_rate = {
1186 	.cb_write = rtw_debugfs_set_fix_rate,
1187 	.cb_read = rtw_debugfs_get_fix_rate,
1188 };
1189 
1190 static struct rtw_debugfs_priv rtw_debug_priv_dump_cam = {
1191 	.cb_write = rtw_debugfs_set_single_input,
1192 	.cb_read = rtw_debugfs_get_dump_cam,
1193 };
1194 
1195 static struct rtw_debugfs_priv rtw_debug_priv_rsvd_page = {
1196 	.cb_write = rtw_debugfs_set_rsvd_page,
1197 	.cb_read = rtw_debugfs_get_rsvd_page,
1198 };
1199 
1200 static struct rtw_debugfs_priv rtw_debug_priv_phy_info = {
1201 	.cb_read = rtw_debugfs_get_phy_info,
1202 };
1203 
1204 static struct rtw_debugfs_priv rtw_debug_priv_coex_enable = {
1205 	.cb_write = rtw_debugfs_set_coex_enable,
1206 	.cb_read = rtw_debugfs_get_coex_enable,
1207 };
1208 
1209 static struct rtw_debugfs_priv rtw_debug_priv_coex_info = {
1210 	.cb_read = rtw_debugfs_get_coex_info,
1211 };
1212 
1213 static struct rtw_debugfs_priv rtw_debug_priv_edcca_enable = {
1214 	.cb_write = rtw_debugfs_set_edcca_enable,
1215 	.cb_read = rtw_debugfs_get_edcca_enable,
1216 };
1217 
1218 static struct rtw_debugfs_priv rtw_debug_priv_fw_crash = {
1219 	.cb_write = rtw_debugfs_set_fw_crash,
1220 	.cb_read = rtw_debugfs_get_fw_crash,
1221 };
1222 
1223 static struct rtw_debugfs_priv rtw_debug_priv_force_lowest_basic_rate = {
1224 	.cb_write = rtw_debugfs_set_force_lowest_basic_rate,
1225 	.cb_read = rtw_debugfs_get_force_lowest_basic_rate,
1226 };
1227 
1228 static struct rtw_debugfs_priv rtw_debug_priv_dm_cap = {
1229 	.cb_write = rtw_debugfs_set_dm_cap,
1230 	.cb_read = rtw_debugfs_get_dm_cap,
1231 };
1232 
1233 #define rtw_debugfs_add_core(name, mode, fopname, parent)		\
1234 	do {								\
1235 		rtw_debug_priv_ ##name.rtwdev = rtwdev;			\
1236 		if (IS_ERR(debugfs_create_file(#name, mode,		\
1237 					 parent, &rtw_debug_priv_ ##name,\
1238 					 &file_ops_ ##fopname)))	\
1239 			pr_debug("Unable to initialize debugfs:%s\n",	\
1240 			       #name);					\
1241 	} while (0)
1242 
1243 #define rtw_debugfs_add_w(name)						\
1244 	rtw_debugfs_add_core(name, S_IFREG | 0222, common_write, debugfs_topdir)
1245 #define rtw_debugfs_add_rw(name)					\
1246 	rtw_debugfs_add_core(name, S_IFREG | 0666, single_rw, debugfs_topdir)
1247 #define rtw_debugfs_add_r(name)						\
1248 	rtw_debugfs_add_core(name, S_IFREG | 0444, single_r, debugfs_topdir)
1249 
1250 void rtw_debugfs_init(struct rtw_dev *rtwdev)
1251 {
1252 	struct dentry *debugfs_topdir;
1253 
1254 	debugfs_topdir = debugfs_create_dir("rtw88",
1255 					    rtwdev->hw->wiphy->debugfsdir);
1256 	rtw_debugfs_add_w(write_reg);
1257 	rtw_debugfs_add_rw(read_reg);
1258 	rtw_debugfs_add_w(rf_write);
1259 	rtw_debugfs_add_rw(rf_read);
1260 	rtw_debugfs_add_rw(fix_rate);
1261 	rtw_debugfs_add_rw(dump_cam);
1262 	rtw_debugfs_add_rw(rsvd_page);
1263 	rtw_debugfs_add_r(phy_info);
1264 	rtw_debugfs_add_r(coex_info);
1265 	rtw_debugfs_add_rw(coex_enable);
1266 	rtw_debugfs_add_w(h2c);
1267 	rtw_debugfs_add_r(mac_0);
1268 	rtw_debugfs_add_r(mac_1);
1269 	rtw_debugfs_add_r(mac_2);
1270 	rtw_debugfs_add_r(mac_3);
1271 	rtw_debugfs_add_r(mac_4);
1272 	rtw_debugfs_add_r(mac_5);
1273 	rtw_debugfs_add_r(mac_6);
1274 	rtw_debugfs_add_r(mac_7);
1275 	rtw_debugfs_add_r(bb_8);
1276 	rtw_debugfs_add_r(bb_9);
1277 	rtw_debugfs_add_r(bb_a);
1278 	rtw_debugfs_add_r(bb_b);
1279 	rtw_debugfs_add_r(bb_c);
1280 	rtw_debugfs_add_r(bb_d);
1281 	rtw_debugfs_add_r(bb_e);
1282 	rtw_debugfs_add_r(bb_f);
1283 	rtw_debugfs_add_r(mac_10);
1284 	rtw_debugfs_add_r(mac_11);
1285 	rtw_debugfs_add_r(mac_12);
1286 	rtw_debugfs_add_r(mac_13);
1287 	rtw_debugfs_add_r(mac_14);
1288 	rtw_debugfs_add_r(mac_15);
1289 	rtw_debugfs_add_r(mac_16);
1290 	rtw_debugfs_add_r(mac_17);
1291 	rtw_debugfs_add_r(bb_18);
1292 	rtw_debugfs_add_r(bb_19);
1293 	rtw_debugfs_add_r(bb_1a);
1294 	rtw_debugfs_add_r(bb_1b);
1295 	rtw_debugfs_add_r(bb_1c);
1296 	rtw_debugfs_add_r(bb_1d);
1297 	rtw_debugfs_add_r(bb_1e);
1298 	rtw_debugfs_add_r(bb_1f);
1299 	if (rtwdev->chip->id == RTW_CHIP_TYPE_8822C) {
1300 		rtw_debugfs_add_r(bb_2c);
1301 		rtw_debugfs_add_r(bb_2d);
1302 		rtw_debugfs_add_r(bb_40);
1303 		rtw_debugfs_add_r(bb_41);
1304 	}
1305 	rtw_debugfs_add_r(rf_dump);
1306 	rtw_debugfs_add_r(tx_pwr_tbl);
1307 	rtw_debugfs_add_rw(edcca_enable);
1308 	rtw_debugfs_add_rw(fw_crash);
1309 	rtw_debugfs_add_rw(force_lowest_basic_rate);
1310 	rtw_debugfs_add_rw(dm_cap);
1311 }
1312 
1313 #endif /* CONFIG_RTW88_DEBUGFS */
1314 
1315 #ifdef CONFIG_RTW88_DEBUG
1316 
1317 void rtw_dbg(struct rtw_dev *rtwdev, enum rtw_debug_mask mask,
1318 	     const char *fmt, ...)
1319 {
1320 	struct va_format vaf = {
1321 		.fmt = fmt,
1322 	};
1323 	va_list args;
1324 
1325 	va_start(args, fmt);
1326 	vaf.va = &args;
1327 
1328 	if (rtw_debug_mask & mask)
1329 		dev_printk(KERN_DEBUG, rtwdev->dev, "%pV", &vaf);
1330 
1331 	va_end(args);
1332 }
1333 EXPORT_SYMBOL(rtw_dbg);
1334 
1335 #endif /* CONFIG_RTW88_DEBUG */
1336