xref: /freebsd/sys/contrib/dev/rtw88/debug.c (revision b1879975794772ee51f0b4865753364c7d7626c3)
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 	u32 input;
320 	int ret;
321 
322 	ret = kstrtou32_from_user(buffer, count, 0, &input);
323 	if (ret)
324 		return ret;
325 
326 	debugfs_priv->cb_data = input;
327 
328 	return count;
329 }
330 
331 static ssize_t rtw_debugfs_set_write_reg(struct file *filp,
332 					 const char __user *buffer,
333 					 size_t count, loff_t *loff)
334 {
335 	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
336 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
337 	char tmp[32 + 1];
338 	u32 addr, val, len;
339 	int num;
340 	int ret;
341 
342 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
343 	if (ret)
344 		return ret;
345 
346 	/* write BB/MAC register */
347 	num = sscanf(tmp, "%x %x %x", &addr, &val, &len);
348 
349 	if (num !=  3)
350 		return -EINVAL;
351 
352 	switch (len) {
353 	case 1:
354 		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
355 			"reg write8 0x%03x: 0x%08x\n", addr, val);
356 		rtw_write8(rtwdev, addr, (u8)val);
357 		break;
358 	case 2:
359 		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
360 			"reg write16 0x%03x: 0x%08x\n", addr, val);
361 		rtw_write16(rtwdev, addr, (u16)val);
362 		break;
363 	case 4:
364 		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
365 			"reg write32 0x%03x: 0x%08x\n", addr, val);
366 		rtw_write32(rtwdev, addr, (u32)val);
367 		break;
368 	default:
369 		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
370 			"error write length = %d\n", len);
371 		break;
372 	}
373 
374 	return count;
375 }
376 
377 static ssize_t rtw_debugfs_set_h2c(struct file *filp,
378 				   const char __user *buffer,
379 				   size_t count, loff_t *loff)
380 {
381 	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
382 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
383 	char tmp[32 + 1];
384 	u8 param[8];
385 	int num;
386 	int ret;
387 
388 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
389 	if (ret)
390 		return ret;
391 
392 	num = sscanf(tmp, "%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx",
393 		     &param[0], &param[1], &param[2], &param[3],
394 		     &param[4], &param[5], &param[6], &param[7]);
395 	if (num != 8) {
396 		rtw_warn(rtwdev, "invalid H2C command format for debug\n");
397 		return -EINVAL;
398 	}
399 
400 	mutex_lock(&rtwdev->mutex);
401 	rtw_fw_h2c_cmd_dbg(rtwdev, param);
402 	mutex_unlock(&rtwdev->mutex);
403 
404 	return count;
405 }
406 
407 static ssize_t rtw_debugfs_set_rf_write(struct file *filp,
408 					const char __user *buffer,
409 					size_t count, loff_t *loff)
410 {
411 	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
412 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
413 	char tmp[32 + 1];
414 	u32 path, addr, mask, val;
415 	int num;
416 	int ret;
417 
418 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 4);
419 	if (ret)
420 		return ret;
421 
422 	num = sscanf(tmp, "%x %x %x %x", &path, &addr, &mask, &val);
423 
424 	if (num !=  4) {
425 		rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n");
426 		return -EINVAL;
427 	}
428 
429 	mutex_lock(&rtwdev->mutex);
430 	rtw_write_rf(rtwdev, path, addr, mask, val);
431 	mutex_unlock(&rtwdev->mutex);
432 	rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
433 		"write_rf path:%d addr:0x%08x mask:0x%08x, val:0x%08x\n",
434 		path, addr, mask, val);
435 
436 	return count;
437 }
438 
439 static ssize_t rtw_debugfs_set_rf_read(struct file *filp,
440 				       const char __user *buffer,
441 				       size_t count, loff_t *loff)
442 {
443 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
444 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
445 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
446 	char tmp[32 + 1];
447 	u32 path, addr, mask;
448 	int num;
449 	int ret;
450 
451 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
452 	if (ret)
453 		return ret;
454 
455 	num = sscanf(tmp, "%x %x %x", &path, &addr, &mask);
456 
457 	if (num !=  3) {
458 		rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n");
459 		return -EINVAL;
460 	}
461 
462 	debugfs_priv->rf_path = path;
463 	debugfs_priv->rf_addr = addr;
464 	debugfs_priv->rf_mask = mask;
465 
466 	return count;
467 }
468 
469 static ssize_t rtw_debugfs_set_fix_rate(struct file *filp,
470 					const char __user *buffer,
471 					size_t count, loff_t *loff)
472 {
473 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
474 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
475 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
476 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
477 	u8 fix_rate;
478 	int ret;
479 
480 	ret = kstrtou8_from_user(buffer, count, 0, &fix_rate);
481 	if (ret)
482 		return ret;
483 
484 	dm_info->fix_rate = fix_rate;
485 
486 	return count;
487 }
488 
489 static int rtw_debug_get_mac_page(struct seq_file *m, void *v)
490 {
491 	struct rtw_debugfs_priv *debugfs_priv = m->private;
492 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
493 	u32 page = debugfs_priv->cb_data;
494 	int i, n;
495 	int max = 0xff;
496 
497 	rtw_read32(rtwdev, debugfs_priv->cb_data);
498 	for (n = 0; n <= max; ) {
499 		seq_printf(m, "\n%8.8x  ", n + page);
500 		for (i = 0; i < 4 && n <= max; i++, n += 4)
501 			seq_printf(m, "%8.8x    ",
502 				   rtw_read32(rtwdev, (page | n)));
503 	}
504 	seq_puts(m, "\n");
505 	return 0;
506 }
507 
508 static int rtw_debug_get_bb_page(struct seq_file *m, void *v)
509 {
510 	struct rtw_debugfs_priv *debugfs_priv = m->private;
511 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
512 	u32 page = debugfs_priv->cb_data;
513 	int i, n;
514 	int max = 0xff;
515 
516 	rtw_read32(rtwdev, debugfs_priv->cb_data);
517 	for (n = 0; n <= max; ) {
518 		seq_printf(m, "\n%8.8x  ", n + page);
519 		for (i = 0; i < 4 && n <= max; i++, n += 4)
520 			seq_printf(m, "%8.8x    ",
521 				   rtw_read32(rtwdev, (page | n)));
522 	}
523 	seq_puts(m, "\n");
524 	return 0;
525 }
526 
527 static int rtw_debug_get_rf_dump(struct seq_file *m, void *v)
528 {
529 	struct rtw_debugfs_priv *debugfs_priv = m->private;
530 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
531 	u32 addr, offset, data;
532 	u8 path;
533 
534 	mutex_lock(&rtwdev->mutex);
535 
536 	for (path = 0; path < rtwdev->hal.rf_path_num; path++) {
537 		seq_printf(m, "RF path:%d\n", path);
538 		for (addr = 0; addr < 0x100; addr += 4) {
539 			seq_printf(m, "%8.8x  ", addr);
540 			for (offset = 0; offset < 4; offset++) {
541 				data = rtw_read_rf(rtwdev, path, addr + offset,
542 						   0xffffffff);
543 				seq_printf(m, "%8.8x    ", data);
544 			}
545 			seq_puts(m, "\n");
546 		}
547 		seq_puts(m, "\n");
548 	}
549 
550 	mutex_unlock(&rtwdev->mutex);
551 
552 	return 0;
553 }
554 
555 static void rtw_print_cck_rate_txt(struct seq_file *m, u8 rate)
556 {
557 	static const char * const
558 	cck_rate[] = {"1M", "2M", "5.5M", "11M"};
559 	u8 idx = rate - DESC_RATE1M;
560 
561 	seq_printf(m, " CCK_%-5s", cck_rate[idx]);
562 }
563 
564 static void rtw_print_ofdm_rate_txt(struct seq_file *m, u8 rate)
565 {
566 	static const char * const
567 	ofdm_rate[] = {"6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M"};
568 	u8 idx = rate - DESC_RATE6M;
569 
570 	seq_printf(m, " OFDM_%-4s", ofdm_rate[idx]);
571 }
572 
573 static void rtw_print_ht_rate_txt(struct seq_file *m, u8 rate)
574 {
575 	u8 mcs_n = rate - DESC_RATEMCS0;
576 
577 	seq_printf(m, " MCS%-6u", mcs_n);
578 }
579 
580 static void rtw_print_vht_rate_txt(struct seq_file *m, u8 rate)
581 {
582 	u8 idx = rate - DESC_RATEVHT1SS_MCS0;
583 	u8 n_ss, mcs_n;
584 
585 	/* n spatial stream */
586 	n_ss = 1 + idx / 10;
587 	/* MCS n */
588 	mcs_n = idx % 10;
589 	seq_printf(m, " VHT%uSMCS%u", n_ss, mcs_n);
590 }
591 
592 static void rtw_print_rate(struct seq_file *m, u8 rate)
593 {
594 	switch (rate) {
595 	case DESC_RATE1M...DESC_RATE11M:
596 		rtw_print_cck_rate_txt(m, rate);
597 		break;
598 	case DESC_RATE6M...DESC_RATE54M:
599 		rtw_print_ofdm_rate_txt(m, rate);
600 		break;
601 	case DESC_RATEMCS0...DESC_RATEMCS15:
602 		rtw_print_ht_rate_txt(m, rate);
603 		break;
604 	case DESC_RATEVHT1SS_MCS0...DESC_RATEVHT2SS_MCS9:
605 		rtw_print_vht_rate_txt(m, rate);
606 		break;
607 	default:
608 		seq_printf(m, " Unknown rate=0x%x\n", rate);
609 		break;
610 	}
611 }
612 
613 #define case_REGD(src) \
614 	case RTW_REGD_##src: return #src
615 
616 static const char *rtw_get_regd_string(u8 regd)
617 {
618 	switch (regd) {
619 	case_REGD(FCC);
620 	case_REGD(MKK);
621 	case_REGD(ETSI);
622 	case_REGD(IC);
623 	case_REGD(KCC);
624 	case_REGD(ACMA);
625 	case_REGD(CHILE);
626 	case_REGD(UKRAINE);
627 	case_REGD(MEXICO);
628 	case_REGD(CN);
629 	case_REGD(WW);
630 	default:
631 		return "Unknown";
632 	}
633 }
634 
635 static int rtw_debugfs_get_tx_pwr_tbl(struct seq_file *m, void *v)
636 {
637 	struct rtw_debugfs_priv *debugfs_priv = m->private;
638 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
639 	struct rtw_hal *hal = &rtwdev->hal;
640 	u8 path, rate, bw, ch, regd;
641 	struct rtw_power_params pwr_param = {0};
642 
643 	mutex_lock(&rtwdev->mutex);
644 	bw = hal->current_band_width;
645 	ch = hal->current_channel;
646 	regd = rtw_regd_get(rtwdev);
647 
648 	seq_printf(m, "channel: %u\n", ch);
649 	seq_printf(m, "bandwidth: %u\n", bw);
650 	seq_printf(m, "regulatory: %s\n", rtw_get_regd_string(regd));
651 	seq_printf(m, "%-4s %-10s %-9s %-9s (%-4s %-4s %-4s) %-4s\n",
652 		   "path", "rate", "pwr", "base", "byr", "lmt", "sar", "rem");
653 
654 	mutex_lock(&hal->tx_power_mutex);
655 	for (path = RF_PATH_A; path <= RF_PATH_B; path++) {
656 		/* there is no CCK rates used in 5G */
657 		if (hal->current_band_type == RTW_BAND_5G)
658 			rate = DESC_RATE6M;
659 		else
660 			rate = DESC_RATE1M;
661 
662 		/* now, not support vht 3ss and vht 4ss*/
663 		for (; rate <= DESC_RATEVHT2SS_MCS9; rate++) {
664 			/* now, not support ht 3ss and ht 4ss*/
665 			if (rate > DESC_RATEMCS15 &&
666 			    rate < DESC_RATEVHT1SS_MCS0)
667 				continue;
668 
669 			rtw_get_tx_power_params(rtwdev, path, rate, bw,
670 						ch, regd, &pwr_param);
671 
672 			seq_printf(m, "%4c ", path + 'A');
673 			rtw_print_rate(m, rate);
674 			seq_printf(m, " %3u(0x%02x) %4u %4d (%4d %4d %4d) %4d\n",
675 				   hal->tx_pwr_tbl[path][rate],
676 				   hal->tx_pwr_tbl[path][rate],
677 				   pwr_param.pwr_base,
678 				   min3(pwr_param.pwr_offset,
679 					pwr_param.pwr_limit,
680 					pwr_param.pwr_sar),
681 				   pwr_param.pwr_offset, pwr_param.pwr_limit,
682 				   pwr_param.pwr_sar,
683 				   pwr_param.pwr_remnant);
684 		}
685 	}
686 
687 	mutex_unlock(&hal->tx_power_mutex);
688 	mutex_unlock(&rtwdev->mutex);
689 
690 	return 0;
691 }
692 
693 void rtw_debugfs_get_simple_phy_info(struct seq_file *m)
694 {
695 	struct rtw_debugfs_priv *debugfs_priv = m->private;
696 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
697 	struct rtw_hal *hal = &rtwdev->hal;
698 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
699 	struct rtw_traffic_stats *stats = &rtwdev->stats;
700 
701 	seq_printf(m, "%-40s = %ddBm/ %d\n", "RSSI/ STA Channel",
702 		   dm_info->rssi[RF_PATH_A] - 100, hal->current_channel);
703 
704 	seq_printf(m, "TP {Tx, Rx} = {%u, %u}Mbps\n",
705 		   stats->tx_throughput, stats->rx_throughput);
706 
707 	seq_puts(m, "[Tx Rate] = ");
708 	rtw_print_rate(m, dm_info->tx_rate);
709 	seq_printf(m, "(0x%x)\n", dm_info->tx_rate);
710 
711 	seq_puts(m, "[Rx Rate] = ");
712 	rtw_print_rate(m, dm_info->curr_rx_rate);
713 	seq_printf(m, "(0x%x)\n", dm_info->curr_rx_rate);
714 }
715 
716 static int rtw_debugfs_get_phy_info(struct seq_file *m, void *v)
717 {
718 	struct rtw_debugfs_priv *debugfs_priv = m->private;
719 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
720 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
721 	struct rtw_traffic_stats *stats = &rtwdev->stats;
722 	struct rtw_pkt_count *last_cnt = &dm_info->last_pkt_count;
723 	struct rtw_efuse *efuse = &rtwdev->efuse;
724 	struct ewma_evm *ewma_evm = dm_info->ewma_evm;
725 	struct ewma_snr *ewma_snr = dm_info->ewma_snr;
726 	u8 ss, rate_id;
727 
728 	seq_puts(m, "==========[Common Info]========\n");
729 	seq_printf(m, "Is link = %c\n", rtw_is_assoc(rtwdev) ? 'Y' : 'N');
730 	seq_printf(m, "Current CH(fc) = %u\n", rtwdev->hal.current_channel);
731 	seq_printf(m, "Current BW = %u\n", rtwdev->hal.current_band_width);
732 	seq_printf(m, "Current IGI = 0x%x\n", dm_info->igi_history[0]);
733 	seq_printf(m, "TP {Tx, Rx} = {%u, %u}Mbps\n",
734 		   stats->tx_throughput, stats->rx_throughput);
735 	seq_printf(m, "1SS for TX and RX = %c\n\n", rtwdev->hal.txrx_1ss ?
736 		   'Y' : 'N');
737 
738 	seq_puts(m, "==========[Tx Phy Info]========\n");
739 	seq_puts(m, "[Tx Rate] = ");
740 	rtw_print_rate(m, dm_info->tx_rate);
741 	seq_printf(m, "(0x%x)\n\n", dm_info->tx_rate);
742 
743 	seq_puts(m, "==========[Rx Phy Info]========\n");
744 	seq_printf(m, "[Rx Beacon Count] = %u\n", last_cnt->num_bcn_pkt);
745 	seq_puts(m, "[Rx Rate] = ");
746 	rtw_print_rate(m, dm_info->curr_rx_rate);
747 	seq_printf(m, "(0x%x)\n", dm_info->curr_rx_rate);
748 
749 	seq_puts(m, "[Rx Rate Count]:\n");
750 	seq_printf(m, " * CCK = {%u, %u, %u, %u}\n",
751 		   last_cnt->num_qry_pkt[DESC_RATE1M],
752 		   last_cnt->num_qry_pkt[DESC_RATE2M],
753 		   last_cnt->num_qry_pkt[DESC_RATE5_5M],
754 		   last_cnt->num_qry_pkt[DESC_RATE11M]);
755 
756 	seq_printf(m, " * OFDM = {%u, %u, %u, %u, %u, %u, %u, %u}\n",
757 		   last_cnt->num_qry_pkt[DESC_RATE6M],
758 		   last_cnt->num_qry_pkt[DESC_RATE9M],
759 		   last_cnt->num_qry_pkt[DESC_RATE12M],
760 		   last_cnt->num_qry_pkt[DESC_RATE18M],
761 		   last_cnt->num_qry_pkt[DESC_RATE24M],
762 		   last_cnt->num_qry_pkt[DESC_RATE36M],
763 		   last_cnt->num_qry_pkt[DESC_RATE48M],
764 		   last_cnt->num_qry_pkt[DESC_RATE54M]);
765 
766 	for (ss = 0; ss < efuse->hw_cap.nss; ss++) {
767 		rate_id = DESC_RATEMCS0 + ss * 8;
768 		seq_printf(m, " * HT_MCS[%u:%u] = {%u, %u, %u, %u, %u, %u, %u, %u}\n",
769 			   ss * 8, ss * 8 + 7,
770 			   last_cnt->num_qry_pkt[rate_id],
771 			   last_cnt->num_qry_pkt[rate_id + 1],
772 			   last_cnt->num_qry_pkt[rate_id + 2],
773 			   last_cnt->num_qry_pkt[rate_id + 3],
774 			   last_cnt->num_qry_pkt[rate_id + 4],
775 			   last_cnt->num_qry_pkt[rate_id + 5],
776 			   last_cnt->num_qry_pkt[rate_id + 6],
777 			   last_cnt->num_qry_pkt[rate_id + 7]);
778 	}
779 
780 	for (ss = 0; ss < efuse->hw_cap.nss; ss++) {
781 		rate_id = DESC_RATEVHT1SS_MCS0 + ss * 10;
782 		seq_printf(m, " * VHT_MCS-%uss MCS[0:9] = {%u, %u, %u, %u, %u, %u, %u, %u, %u, %u}\n",
783 			   ss + 1,
784 			   last_cnt->num_qry_pkt[rate_id],
785 			   last_cnt->num_qry_pkt[rate_id + 1],
786 			   last_cnt->num_qry_pkt[rate_id + 2],
787 			   last_cnt->num_qry_pkt[rate_id + 3],
788 			   last_cnt->num_qry_pkt[rate_id + 4],
789 			   last_cnt->num_qry_pkt[rate_id + 5],
790 			   last_cnt->num_qry_pkt[rate_id + 6],
791 			   last_cnt->num_qry_pkt[rate_id + 7],
792 			   last_cnt->num_qry_pkt[rate_id + 8],
793 			   last_cnt->num_qry_pkt[rate_id + 9]);
794 	}
795 
796 	seq_printf(m, "[RSSI(dBm)] = {%d, %d}\n",
797 		   dm_info->rssi[RF_PATH_A] - 100,
798 		   dm_info->rssi[RF_PATH_B] - 100);
799 	seq_printf(m, "[Rx EVM(dB)] = {-%d, -%d}\n",
800 		   dm_info->rx_evm_dbm[RF_PATH_A],
801 		   dm_info->rx_evm_dbm[RF_PATH_B]);
802 	seq_printf(m, "[Rx SNR] = {%d, %d}\n",
803 		   dm_info->rx_snr[RF_PATH_A],
804 		   dm_info->rx_snr[RF_PATH_B]);
805 	seq_printf(m, "[CFO_tail(KHz)] = {%d, %d}\n",
806 		   dm_info->cfo_tail[RF_PATH_A],
807 		   dm_info->cfo_tail[RF_PATH_B]);
808 
809 	if (dm_info->curr_rx_rate >= DESC_RATE11M) {
810 		seq_puts(m, "[Rx Average Status]:\n");
811 		seq_printf(m, " * OFDM, EVM: {-%d}, SNR: {%d}\n",
812 			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_OFDM]),
813 			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_OFDM_A]));
814 		seq_printf(m, " * 1SS, EVM: {-%d}, SNR: {%d}\n",
815 			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_1SS]),
816 			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_1SS_A]));
817 		seq_printf(m, " * 2SS, EVM: {-%d, -%d}, SNR: {%d, %d}\n",
818 			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_2SS_A]),
819 			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_2SS_B]),
820 			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_2SS_A]),
821 			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_2SS_B]));
822 	}
823 
824 	seq_puts(m, "[Rx Counter]:\n");
825 	seq_printf(m, " * CCA (CCK, OFDM, Total) = (%u, %u, %u)\n",
826 		   dm_info->cck_cca_cnt,
827 		   dm_info->ofdm_cca_cnt,
828 		   dm_info->total_cca_cnt);
829 	seq_printf(m, " * False Alarm (CCK, OFDM, Total) = (%u, %u, %u)\n",
830 		   dm_info->cck_fa_cnt,
831 		   dm_info->ofdm_fa_cnt,
832 		   dm_info->total_fa_cnt);
833 	seq_printf(m, " * CCK cnt (ok, err) = (%u, %u)\n",
834 		   dm_info->cck_ok_cnt, dm_info->cck_err_cnt);
835 	seq_printf(m, " * OFDM cnt (ok, err) = (%u, %u)\n",
836 		   dm_info->ofdm_ok_cnt, dm_info->ofdm_err_cnt);
837 	seq_printf(m, " * HT cnt (ok, err) = (%u, %u)\n",
838 		   dm_info->ht_ok_cnt, dm_info->ht_err_cnt);
839 	seq_printf(m, " * VHT cnt (ok, err) = (%u, %u)\n",
840 		   dm_info->vht_ok_cnt, dm_info->vht_err_cnt);
841 
842 	return 0;
843 }
844 
845 static int rtw_debugfs_get_coex_info(struct seq_file *m, void *v)
846 {
847 	struct rtw_debugfs_priv *debugfs_priv = m->private;
848 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
849 
850 	mutex_lock(&rtwdev->mutex);
851 	rtw_coex_display_coex_info(rtwdev, m);
852 	mutex_unlock(&rtwdev->mutex);
853 
854 	return 0;
855 }
856 
857 static ssize_t rtw_debugfs_set_coex_enable(struct file *filp,
858 					   const char __user *buffer,
859 					   size_t count, loff_t *loff)
860 {
861 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
862 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
863 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
864 	struct rtw_coex *coex = &rtwdev->coex;
865 	bool enable;
866 	int ret;
867 
868 	ret = kstrtobool_from_user(buffer, count, &enable);
869 	if (ret)
870 		return ret;
871 
872 	mutex_lock(&rtwdev->mutex);
873 	coex->manual_control = !enable;
874 	mutex_unlock(&rtwdev->mutex);
875 
876 	return count;
877 }
878 
879 static int rtw_debugfs_get_coex_enable(struct seq_file *m, void *v)
880 {
881 	struct rtw_debugfs_priv *debugfs_priv = m->private;
882 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
883 	struct rtw_coex *coex = &rtwdev->coex;
884 
885 	seq_printf(m, "coex mechanism %s\n",
886 		   coex->manual_control ? "disabled" : "enabled");
887 
888 	return 0;
889 }
890 
891 static ssize_t rtw_debugfs_set_edcca_enable(struct file *filp,
892 					    const char __user *buffer,
893 					    size_t count, loff_t *loff)
894 {
895 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
896 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
897 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
898 	bool input;
899 	int err;
900 
901 	err = kstrtobool_from_user(buffer, count, &input);
902 	if (err)
903 		return err;
904 
905 	rtw_edcca_enabled = input;
906 	rtw_phy_adaptivity_set_mode(rtwdev);
907 
908 	return count;
909 }
910 
911 static int rtw_debugfs_get_edcca_enable(struct seq_file *m, void *v)
912 {
913 	struct rtw_debugfs_priv *debugfs_priv = m->private;
914 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
915 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
916 
917 	seq_printf(m, "EDCCA %s: EDCCA mode %d\n",
918 		   rtw_edcca_enabled ? "enabled" : "disabled",
919 		   dm_info->edcca_mode);
920 	return 0;
921 }
922 
923 static ssize_t rtw_debugfs_set_fw_crash(struct file *filp,
924 					const char __user *buffer,
925 					size_t count, loff_t *loff)
926 {
927 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
928 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
929 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
930 	bool input;
931 	int ret;
932 
933 	ret = kstrtobool_from_user(buffer, count, &input);
934 	if (ret)
935 		return ret;
936 
937 	if (!input)
938 		return -EINVAL;
939 
940 	if (test_bit(RTW_FLAG_RESTARTING, rtwdev->flags))
941 		return -EINPROGRESS;
942 
943 	mutex_lock(&rtwdev->mutex);
944 	rtw_leave_lps_deep(rtwdev);
945 	set_bit(RTW_FLAG_RESTART_TRIGGERING, rtwdev->flags);
946 	rtw_write8(rtwdev, REG_HRCV_MSG, 1);
947 	mutex_unlock(&rtwdev->mutex);
948 
949 	return count;
950 }
951 
952 static int rtw_debugfs_get_fw_crash(struct seq_file *m, void *v)
953 {
954 	struct rtw_debugfs_priv *debugfs_priv = m->private;
955 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
956 
957 	seq_printf(m, "%d\n",
958 		   test_bit(RTW_FLAG_RESTART_TRIGGERING, rtwdev->flags) ||
959 		   test_bit(RTW_FLAG_RESTARTING, rtwdev->flags));
960 	return 0;
961 }
962 
963 static ssize_t rtw_debugfs_set_force_lowest_basic_rate(struct file *filp,
964 						       const char __user *buffer,
965 						       size_t count, loff_t *loff)
966 {
967 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
968 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
969 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
970 	bool input;
971 	int err;
972 
973 	err = kstrtobool_from_user(buffer, count, &input);
974 	if (err)
975 		return err;
976 
977 	if (input)
978 		set_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags);
979 	else
980 		clear_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags);
981 
982 	return count;
983 }
984 
985 static int rtw_debugfs_get_force_lowest_basic_rate(struct seq_file *m, void *v)
986 {
987 	struct rtw_debugfs_priv *debugfs_priv = m->private;
988 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
989 
990 	seq_printf(m, "force lowest basic rate: %d\n",
991 		   test_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags));
992 
993 	return 0;
994 }
995 
996 static ssize_t rtw_debugfs_set_dm_cap(struct file *filp,
997 				      const char __user *buffer,
998 				      size_t count, loff_t *loff)
999 {
1000 	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
1001 	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
1002 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
1003 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1004 	int ret, bit;
1005 	bool en;
1006 
1007 	ret = kstrtoint_from_user(buffer, count, 10, &bit);
1008 	if (ret)
1009 		return ret;
1010 
1011 	en = bit > 0;
1012 	bit = abs(bit);
1013 
1014 	if (bit >= RTW_DM_CAP_NUM) {
1015 		rtw_warn(rtwdev, "unknown DM CAP %d\n", bit);
1016 		return -EINVAL;
1017 	}
1018 
1019 	if (en)
1020 		dm_info->dm_flags &= ~BIT(bit);
1021 	else
1022 		dm_info->dm_flags |= BIT(bit);
1023 
1024 	debugfs_priv->dm_cap.bit = bit;
1025 
1026 	return count;
1027 }
1028 
1029 static void dump_gapk_status(struct rtw_dev *rtwdev, struct seq_file *m)
1030 {
1031 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1032 	struct rtw_gapk_info *txgapk = &rtwdev->dm_info.gapk;
1033 	int i, path;
1034 	u32 val;
1035 
1036 	seq_printf(m, "\n(%2d) %c%s\n\n", RTW_DM_CAP_TXGAPK,
1037 		   dm_info->dm_flags & BIT(RTW_DM_CAP_TXGAPK) ? '-' : '+',
1038 		   rtw_dm_cap_strs[RTW_DM_CAP_TXGAPK]);
1039 
1040 	mutex_lock(&rtwdev->mutex);
1041 
1042 	for (path = 0; path < rtwdev->hal.rf_path_num; path++) {
1043 		val = rtw_read_rf(rtwdev, path, RF_GAINTX, RFREG_MASK);
1044 		seq_printf(m, "path %d:\n0x%x = 0x%x\n", path, RF_GAINTX, val);
1045 
1046 		for (i = 0; i < RF_HW_OFFSET_NUM; i++)
1047 			seq_printf(m, "[TXGAPK] offset %d %d\n",
1048 				   txgapk->rf3f_fs[path][i], i);
1049 		seq_puts(m, "\n");
1050 	}
1051 	mutex_unlock(&rtwdev->mutex);
1052 }
1053 
1054 static int rtw_debugfs_get_dm_cap(struct seq_file *m, void *v)
1055 {
1056 	struct rtw_debugfs_priv *debugfs_priv = m->private;
1057 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
1058 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1059 	int i;
1060 
1061 	switch (debugfs_priv->dm_cap.bit) {
1062 	case RTW_DM_CAP_TXGAPK:
1063 		dump_gapk_status(rtwdev, m);
1064 		break;
1065 	default:
1066 		for (i = 1; i < RTW_DM_CAP_NUM; i++) {
1067 			seq_printf(m, "(%2d) %c%s\n", i,
1068 				   dm_info->dm_flags & BIT(i) ? '-' : '+',
1069 				   rtw_dm_cap_strs[i]);
1070 		}
1071 		break;
1072 	}
1073 	debugfs_priv->dm_cap.bit = RTW_DM_CAP_NA;
1074 	return 0;
1075 }
1076 
1077 #define rtw_debug_impl_mac(page, addr)				\
1078 static struct rtw_debugfs_priv rtw_debug_priv_mac_ ##page = {	\
1079 	.cb_read = rtw_debug_get_mac_page,			\
1080 	.cb_data = addr,					\
1081 }
1082 
1083 rtw_debug_impl_mac(0, 0x0000);
1084 rtw_debug_impl_mac(1, 0x0100);
1085 rtw_debug_impl_mac(2, 0x0200);
1086 rtw_debug_impl_mac(3, 0x0300);
1087 rtw_debug_impl_mac(4, 0x0400);
1088 rtw_debug_impl_mac(5, 0x0500);
1089 rtw_debug_impl_mac(6, 0x0600);
1090 rtw_debug_impl_mac(7, 0x0700);
1091 rtw_debug_impl_mac(10, 0x1000);
1092 rtw_debug_impl_mac(11, 0x1100);
1093 rtw_debug_impl_mac(12, 0x1200);
1094 rtw_debug_impl_mac(13, 0x1300);
1095 rtw_debug_impl_mac(14, 0x1400);
1096 rtw_debug_impl_mac(15, 0x1500);
1097 rtw_debug_impl_mac(16, 0x1600);
1098 rtw_debug_impl_mac(17, 0x1700);
1099 
1100 #define rtw_debug_impl_bb(page, addr)			\
1101 static struct rtw_debugfs_priv rtw_debug_priv_bb_ ##page = {	\
1102 	.cb_read = rtw_debug_get_bb_page,			\
1103 	.cb_data = addr,					\
1104 }
1105 
1106 rtw_debug_impl_bb(8, 0x0800);
1107 rtw_debug_impl_bb(9, 0x0900);
1108 rtw_debug_impl_bb(a, 0x0a00);
1109 rtw_debug_impl_bb(b, 0x0b00);
1110 rtw_debug_impl_bb(c, 0x0c00);
1111 rtw_debug_impl_bb(d, 0x0d00);
1112 rtw_debug_impl_bb(e, 0x0e00);
1113 rtw_debug_impl_bb(f, 0x0f00);
1114 rtw_debug_impl_bb(18, 0x1800);
1115 rtw_debug_impl_bb(19, 0x1900);
1116 rtw_debug_impl_bb(1a, 0x1a00);
1117 rtw_debug_impl_bb(1b, 0x1b00);
1118 rtw_debug_impl_bb(1c, 0x1c00);
1119 rtw_debug_impl_bb(1d, 0x1d00);
1120 rtw_debug_impl_bb(1e, 0x1e00);
1121 rtw_debug_impl_bb(1f, 0x1f00);
1122 rtw_debug_impl_bb(2c, 0x2c00);
1123 rtw_debug_impl_bb(2d, 0x2d00);
1124 rtw_debug_impl_bb(40, 0x4000);
1125 rtw_debug_impl_bb(41, 0x4100);
1126 
1127 static struct rtw_debugfs_priv rtw_debug_priv_rf_dump = {
1128 	.cb_read = rtw_debug_get_rf_dump,
1129 };
1130 
1131 static struct rtw_debugfs_priv rtw_debug_priv_tx_pwr_tbl = {
1132 	.cb_read = rtw_debugfs_get_tx_pwr_tbl,
1133 };
1134 
1135 static struct rtw_debugfs_priv rtw_debug_priv_write_reg = {
1136 	.cb_write = rtw_debugfs_set_write_reg,
1137 };
1138 
1139 static struct rtw_debugfs_priv rtw_debug_priv_h2c = {
1140 	.cb_write = rtw_debugfs_set_h2c,
1141 };
1142 
1143 static struct rtw_debugfs_priv rtw_debug_priv_rf_write = {
1144 	.cb_write = rtw_debugfs_set_rf_write,
1145 };
1146 
1147 static struct rtw_debugfs_priv rtw_debug_priv_rf_read = {
1148 	.cb_write = rtw_debugfs_set_rf_read,
1149 	.cb_read = rtw_debugfs_get_rf_read,
1150 };
1151 
1152 static struct rtw_debugfs_priv rtw_debug_priv_read_reg = {
1153 	.cb_write = rtw_debugfs_set_read_reg,
1154 	.cb_read = rtw_debugfs_get_read_reg,
1155 };
1156 
1157 static struct rtw_debugfs_priv rtw_debug_priv_fix_rate = {
1158 	.cb_write = rtw_debugfs_set_fix_rate,
1159 	.cb_read = rtw_debugfs_get_fix_rate,
1160 };
1161 
1162 static struct rtw_debugfs_priv rtw_debug_priv_dump_cam = {
1163 	.cb_write = rtw_debugfs_set_single_input,
1164 	.cb_read = rtw_debugfs_get_dump_cam,
1165 };
1166 
1167 static struct rtw_debugfs_priv rtw_debug_priv_rsvd_page = {
1168 	.cb_write = rtw_debugfs_set_rsvd_page,
1169 	.cb_read = rtw_debugfs_get_rsvd_page,
1170 };
1171 
1172 static struct rtw_debugfs_priv rtw_debug_priv_phy_info = {
1173 	.cb_read = rtw_debugfs_get_phy_info,
1174 };
1175 
1176 static struct rtw_debugfs_priv rtw_debug_priv_coex_enable = {
1177 	.cb_write = rtw_debugfs_set_coex_enable,
1178 	.cb_read = rtw_debugfs_get_coex_enable,
1179 };
1180 
1181 static struct rtw_debugfs_priv rtw_debug_priv_coex_info = {
1182 	.cb_read = rtw_debugfs_get_coex_info,
1183 };
1184 
1185 static struct rtw_debugfs_priv rtw_debug_priv_edcca_enable = {
1186 	.cb_write = rtw_debugfs_set_edcca_enable,
1187 	.cb_read = rtw_debugfs_get_edcca_enable,
1188 };
1189 
1190 static struct rtw_debugfs_priv rtw_debug_priv_fw_crash = {
1191 	.cb_write = rtw_debugfs_set_fw_crash,
1192 	.cb_read = rtw_debugfs_get_fw_crash,
1193 };
1194 
1195 static struct rtw_debugfs_priv rtw_debug_priv_force_lowest_basic_rate = {
1196 	.cb_write = rtw_debugfs_set_force_lowest_basic_rate,
1197 	.cb_read = rtw_debugfs_get_force_lowest_basic_rate,
1198 };
1199 
1200 static struct rtw_debugfs_priv rtw_debug_priv_dm_cap = {
1201 	.cb_write = rtw_debugfs_set_dm_cap,
1202 	.cb_read = rtw_debugfs_get_dm_cap,
1203 };
1204 
1205 #define rtw_debugfs_add_core(name, mode, fopname, parent)		\
1206 	do {								\
1207 		rtw_debug_priv_ ##name.rtwdev = rtwdev;			\
1208 		if (IS_ERR(debugfs_create_file(#name, mode,		\
1209 					 parent, &rtw_debug_priv_ ##name,\
1210 					 &file_ops_ ##fopname)))	\
1211 			pr_debug("Unable to initialize debugfs:%s\n",	\
1212 			       #name);					\
1213 	} while (0)
1214 
1215 #define rtw_debugfs_add_w(name)						\
1216 	rtw_debugfs_add_core(name, S_IFREG | 0222, common_write, debugfs_topdir)
1217 #define rtw_debugfs_add_rw(name)					\
1218 	rtw_debugfs_add_core(name, S_IFREG | 0666, single_rw, debugfs_topdir)
1219 #define rtw_debugfs_add_r(name)						\
1220 	rtw_debugfs_add_core(name, S_IFREG | 0444, single_r, debugfs_topdir)
1221 
1222 void rtw_debugfs_init(struct rtw_dev *rtwdev)
1223 {
1224 	struct dentry *debugfs_topdir;
1225 
1226 	debugfs_topdir = debugfs_create_dir("rtw88",
1227 					    rtwdev->hw->wiphy->debugfsdir);
1228 	rtw_debugfs_add_w(write_reg);
1229 	rtw_debugfs_add_rw(read_reg);
1230 	rtw_debugfs_add_w(rf_write);
1231 	rtw_debugfs_add_rw(rf_read);
1232 	rtw_debugfs_add_rw(fix_rate);
1233 	rtw_debugfs_add_rw(dump_cam);
1234 	rtw_debugfs_add_rw(rsvd_page);
1235 	rtw_debugfs_add_r(phy_info);
1236 	rtw_debugfs_add_r(coex_info);
1237 	rtw_debugfs_add_rw(coex_enable);
1238 	rtw_debugfs_add_w(h2c);
1239 	rtw_debugfs_add_r(mac_0);
1240 	rtw_debugfs_add_r(mac_1);
1241 	rtw_debugfs_add_r(mac_2);
1242 	rtw_debugfs_add_r(mac_3);
1243 	rtw_debugfs_add_r(mac_4);
1244 	rtw_debugfs_add_r(mac_5);
1245 	rtw_debugfs_add_r(mac_6);
1246 	rtw_debugfs_add_r(mac_7);
1247 	rtw_debugfs_add_r(bb_8);
1248 	rtw_debugfs_add_r(bb_9);
1249 	rtw_debugfs_add_r(bb_a);
1250 	rtw_debugfs_add_r(bb_b);
1251 	rtw_debugfs_add_r(bb_c);
1252 	rtw_debugfs_add_r(bb_d);
1253 	rtw_debugfs_add_r(bb_e);
1254 	rtw_debugfs_add_r(bb_f);
1255 	rtw_debugfs_add_r(mac_10);
1256 	rtw_debugfs_add_r(mac_11);
1257 	rtw_debugfs_add_r(mac_12);
1258 	rtw_debugfs_add_r(mac_13);
1259 	rtw_debugfs_add_r(mac_14);
1260 	rtw_debugfs_add_r(mac_15);
1261 	rtw_debugfs_add_r(mac_16);
1262 	rtw_debugfs_add_r(mac_17);
1263 	rtw_debugfs_add_r(bb_18);
1264 	rtw_debugfs_add_r(bb_19);
1265 	rtw_debugfs_add_r(bb_1a);
1266 	rtw_debugfs_add_r(bb_1b);
1267 	rtw_debugfs_add_r(bb_1c);
1268 	rtw_debugfs_add_r(bb_1d);
1269 	rtw_debugfs_add_r(bb_1e);
1270 	rtw_debugfs_add_r(bb_1f);
1271 	if (rtwdev->chip->id == RTW_CHIP_TYPE_8822C) {
1272 		rtw_debugfs_add_r(bb_2c);
1273 		rtw_debugfs_add_r(bb_2d);
1274 		rtw_debugfs_add_r(bb_40);
1275 		rtw_debugfs_add_r(bb_41);
1276 	}
1277 	rtw_debugfs_add_r(rf_dump);
1278 	rtw_debugfs_add_r(tx_pwr_tbl);
1279 	rtw_debugfs_add_rw(edcca_enable);
1280 	rtw_debugfs_add_rw(fw_crash);
1281 	rtw_debugfs_add_rw(force_lowest_basic_rate);
1282 	rtw_debugfs_add_rw(dm_cap);
1283 }
1284 
1285 #endif /* CONFIG_RTW88_DEBUGFS */
1286 
1287 #ifdef CONFIG_RTW88_DEBUG
1288 
1289 void rtw_dbg(struct rtw_dev *rtwdev, enum rtw_debug_mask mask,
1290 	     const char *fmt, ...)
1291 {
1292 	struct va_format vaf = {
1293 		.fmt = fmt,
1294 	};
1295 	va_list args;
1296 
1297 	va_start(args, fmt);
1298 	vaf.va = &args;
1299 
1300 	if (rtw_debug_mask & mask)
1301 #if defined(__linux__)
1302 		dev_printk(KERN_DEBUG, rtwdev->dev, "%pV", &vaf);
1303 #elif defined(__FreeBSD__)
1304 		vlog(LOG_DEBUG, vaf.fmt, args);
1305 #endif
1306 
1307 	va_end(args);
1308 }
1309 EXPORT_SYMBOL(rtw_dbg);
1310 
1311 #endif /* CONFIG_RTW88_DEBUG */
1312