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