cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

debug.c (34941B)


      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
     19struct 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
     46static const char * const rtw_dm_cap_strs[] = {
     47	[RTW_DM_CAP_NA] = "NA",
     48	[RTW_DM_CAP_TXGAPK] = "TXGAPK",
     49};
     50
     51static 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
     58static 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
     67static 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
     77static 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
     82static int rtw_debugfs_close(struct inode *inode, struct file *filp)
     83{
     84	return 0;
     85}
     86
     87static 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
     95static 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
    104static 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
    111static 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
    136static 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
    155static 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
    171static 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
    192static 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
    220static 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
    246static 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
    283static 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
    309static 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
    334static 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
    377static 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_warn(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
    402static 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
    429static 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
    456static 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
    481static 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
    500static 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
    519static 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
    543static 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
    552static 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
    561static 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
    568static 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
    580static 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
    604static 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
    623static 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
    678void 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
    701static 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",
    719		   stats->tx_throughput, stats->rx_throughput);
    720	seq_printf(m, "1SS for TX and RX = %c\n\n", rtwdev->hal.txrx_1ss ?
    721		   'Y' : 'N');
    722
    723	seq_puts(m, "==========[Tx Phy Info]========\n");
    724	seq_puts(m, "[Tx Rate] = ");
    725	rtw_print_rate(m, dm_info->tx_rate);
    726	seq_printf(m, "(0x%x)\n\n", dm_info->tx_rate);
    727
    728	seq_puts(m, "==========[Rx Phy Info]========\n");
    729	seq_printf(m, "[Rx Beacon Count] = %u\n", last_cnt->num_bcn_pkt);
    730	seq_puts(m, "[Rx Rate] = ");
    731	rtw_print_rate(m, dm_info->curr_rx_rate);
    732	seq_printf(m, "(0x%x)\n", dm_info->curr_rx_rate);
    733
    734	seq_puts(m, "[Rx Rate Count]:\n");
    735	seq_printf(m, " * CCK = {%u, %u, %u, %u}\n",
    736		   last_cnt->num_qry_pkt[DESC_RATE1M],
    737		   last_cnt->num_qry_pkt[DESC_RATE2M],
    738		   last_cnt->num_qry_pkt[DESC_RATE5_5M],
    739		   last_cnt->num_qry_pkt[DESC_RATE11M]);
    740
    741	seq_printf(m, " * OFDM = {%u, %u, %u, %u, %u, %u, %u, %u}\n",
    742		   last_cnt->num_qry_pkt[DESC_RATE6M],
    743		   last_cnt->num_qry_pkt[DESC_RATE9M],
    744		   last_cnt->num_qry_pkt[DESC_RATE12M],
    745		   last_cnt->num_qry_pkt[DESC_RATE18M],
    746		   last_cnt->num_qry_pkt[DESC_RATE24M],
    747		   last_cnt->num_qry_pkt[DESC_RATE36M],
    748		   last_cnt->num_qry_pkt[DESC_RATE48M],
    749		   last_cnt->num_qry_pkt[DESC_RATE54M]);
    750
    751	for (ss = 0; ss < efuse->hw_cap.nss; ss++) {
    752		rate_id = DESC_RATEMCS0 + ss * 8;
    753		seq_printf(m, " * HT_MCS[%u:%u] = {%u, %u, %u, %u, %u, %u, %u, %u}\n",
    754			   ss * 8, ss * 8 + 7,
    755			   last_cnt->num_qry_pkt[rate_id],
    756			   last_cnt->num_qry_pkt[rate_id + 1],
    757			   last_cnt->num_qry_pkt[rate_id + 2],
    758			   last_cnt->num_qry_pkt[rate_id + 3],
    759			   last_cnt->num_qry_pkt[rate_id + 4],
    760			   last_cnt->num_qry_pkt[rate_id + 5],
    761			   last_cnt->num_qry_pkt[rate_id + 6],
    762			   last_cnt->num_qry_pkt[rate_id + 7]);
    763	}
    764
    765	for (ss = 0; ss < efuse->hw_cap.nss; ss++) {
    766		rate_id = DESC_RATEVHT1SS_MCS0 + ss * 10;
    767		seq_printf(m, " * VHT_MCS-%uss MCS[0:9] = {%u, %u, %u, %u, %u, %u, %u, %u, %u, %u}\n",
    768			   ss + 1,
    769			   last_cnt->num_qry_pkt[rate_id],
    770			   last_cnt->num_qry_pkt[rate_id + 1],
    771			   last_cnt->num_qry_pkt[rate_id + 2],
    772			   last_cnt->num_qry_pkt[rate_id + 3],
    773			   last_cnt->num_qry_pkt[rate_id + 4],
    774			   last_cnt->num_qry_pkt[rate_id + 5],
    775			   last_cnt->num_qry_pkt[rate_id + 6],
    776			   last_cnt->num_qry_pkt[rate_id + 7],
    777			   last_cnt->num_qry_pkt[rate_id + 8],
    778			   last_cnt->num_qry_pkt[rate_id + 9]);
    779	}
    780
    781	seq_printf(m, "[RSSI(dBm)] = {%d, %d}\n",
    782		   dm_info->rssi[RF_PATH_A] - 100,
    783		   dm_info->rssi[RF_PATH_B] - 100);
    784	seq_printf(m, "[Rx EVM(dB)] = {-%d, -%d}\n",
    785		   dm_info->rx_evm_dbm[RF_PATH_A],
    786		   dm_info->rx_evm_dbm[RF_PATH_B]);
    787	seq_printf(m, "[Rx SNR] = {%d, %d}\n",
    788		   dm_info->rx_snr[RF_PATH_A],
    789		   dm_info->rx_snr[RF_PATH_B]);
    790	seq_printf(m, "[CFO_tail(KHz)] = {%d, %d}\n",
    791		   dm_info->cfo_tail[RF_PATH_A],
    792		   dm_info->cfo_tail[RF_PATH_B]);
    793
    794	if (dm_info->curr_rx_rate >= DESC_RATE11M) {
    795		seq_puts(m, "[Rx Average Status]:\n");
    796		seq_printf(m, " * OFDM, EVM: {-%d}, SNR: {%d}\n",
    797			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_OFDM]),
    798			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_OFDM_A]));
    799		seq_printf(m, " * 1SS, EVM: {-%d}, SNR: {%d}\n",
    800			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_1SS]),
    801			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_1SS_A]));
    802		seq_printf(m, " * 2SS, EVM: {-%d, -%d}, SNR: {%d, %d}\n",
    803			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_2SS_A]),
    804			   (u8)ewma_evm_read(&ewma_evm[RTW_EVM_2SS_B]),
    805			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_2SS_A]),
    806			   (u8)ewma_snr_read(&ewma_snr[RTW_SNR_2SS_B]));
    807	}
    808
    809	seq_puts(m, "[Rx Counter]:\n");
    810	seq_printf(m, " * CCA (CCK, OFDM, Total) = (%u, %u, %u)\n",
    811		   dm_info->cck_cca_cnt,
    812		   dm_info->ofdm_cca_cnt,
    813		   dm_info->total_cca_cnt);
    814	seq_printf(m, " * False Alarm (CCK, OFDM, Total) = (%u, %u, %u)\n",
    815		   dm_info->cck_fa_cnt,
    816		   dm_info->ofdm_fa_cnt,
    817		   dm_info->total_fa_cnt);
    818	seq_printf(m, " * CCK cnt (ok, err) = (%u, %u)\n",
    819		   dm_info->cck_ok_cnt, dm_info->cck_err_cnt);
    820	seq_printf(m, " * OFDM cnt (ok, err) = (%u, %u)\n",
    821		   dm_info->ofdm_ok_cnt, dm_info->ofdm_err_cnt);
    822	seq_printf(m, " * HT cnt (ok, err) = (%u, %u)\n",
    823		   dm_info->ht_ok_cnt, dm_info->ht_err_cnt);
    824	seq_printf(m, " * VHT cnt (ok, err) = (%u, %u)\n",
    825		   dm_info->vht_ok_cnt, dm_info->vht_err_cnt);
    826
    827	return 0;
    828}
    829
    830static int rtw_debugfs_get_coex_info(struct seq_file *m, void *v)
    831{
    832	struct rtw_debugfs_priv *debugfs_priv = m->private;
    833	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    834
    835	rtw_coex_display_coex_info(rtwdev, m);
    836
    837	return 0;
    838}
    839
    840static ssize_t rtw_debugfs_set_coex_enable(struct file *filp,
    841					   const char __user *buffer,
    842					   size_t count, loff_t *loff)
    843{
    844	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
    845	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
    846	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    847	struct rtw_coex *coex = &rtwdev->coex;
    848	char tmp[32 + 1];
    849	bool enable;
    850	int ret;
    851
    852	rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
    853
    854	ret = kstrtobool(tmp, &enable);
    855	if (ret) {
    856		rtw_warn(rtwdev, "invalid arguments\n");
    857		return ret;
    858	}
    859
    860	mutex_lock(&rtwdev->mutex);
    861	coex->manual_control = !enable;
    862	mutex_unlock(&rtwdev->mutex);
    863
    864	return count;
    865}
    866
    867static int rtw_debugfs_get_coex_enable(struct seq_file *m, void *v)
    868{
    869	struct rtw_debugfs_priv *debugfs_priv = m->private;
    870	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    871	struct rtw_coex *coex = &rtwdev->coex;
    872
    873	seq_printf(m, "coex mechanism %s\n",
    874		   coex->manual_control ? "disabled" : "enabled");
    875
    876	return 0;
    877}
    878
    879static ssize_t rtw_debugfs_set_edcca_enable(struct file *filp,
    880					    const char __user *buffer,
    881					    size_t count, loff_t *loff)
    882{
    883	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
    884	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
    885	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    886	bool input;
    887	int err;
    888
    889	err = kstrtobool_from_user(buffer, count, &input);
    890	if (err)
    891		return err;
    892
    893	rtw_edcca_enabled = input;
    894	rtw_phy_adaptivity_set_mode(rtwdev);
    895
    896	return count;
    897}
    898
    899static int rtw_debugfs_get_edcca_enable(struct seq_file *m, void *v)
    900{
    901	struct rtw_debugfs_priv *debugfs_priv = m->private;
    902	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    903	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
    904
    905	seq_printf(m, "EDCCA %s: EDCCA mode %d\n",
    906		   rtw_edcca_enabled ? "enabled" : "disabled",
    907		   dm_info->edcca_mode);
    908	return 0;
    909}
    910
    911static ssize_t rtw_debugfs_set_fw_crash(struct file *filp,
    912					const char __user *buffer,
    913					size_t count, loff_t *loff)
    914{
    915	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
    916	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
    917	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    918	char tmp[32 + 1];
    919	bool input;
    920	int ret;
    921
    922	rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
    923
    924	ret = kstrtobool(tmp, &input);
    925	if (ret)
    926		return -EINVAL;
    927
    928	if (!input)
    929		return -EINVAL;
    930
    931	if (test_bit(RTW_FLAG_RESTARTING, rtwdev->flags))
    932		return -EINPROGRESS;
    933
    934	mutex_lock(&rtwdev->mutex);
    935	rtw_leave_lps_deep(rtwdev);
    936	set_bit(RTW_FLAG_RESTART_TRIGGERING, rtwdev->flags);
    937	rtw_write8(rtwdev, REG_HRCV_MSG, 1);
    938	mutex_unlock(&rtwdev->mutex);
    939
    940	return count;
    941}
    942
    943static int rtw_debugfs_get_fw_crash(struct seq_file *m, void *v)
    944{
    945	struct rtw_debugfs_priv *debugfs_priv = m->private;
    946	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    947
    948	seq_printf(m, "%d\n",
    949		   test_bit(RTW_FLAG_RESTART_TRIGGERING, rtwdev->flags) ||
    950		   test_bit(RTW_FLAG_RESTARTING, rtwdev->flags));
    951	return 0;
    952}
    953
    954static ssize_t rtw_debugfs_set_force_lowest_basic_rate(struct file *filp,
    955						       const char __user *buffer,
    956						       size_t count, loff_t *loff)
    957{
    958	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
    959	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
    960	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    961	bool input;
    962	int err;
    963
    964	err = kstrtobool_from_user(buffer, count, &input);
    965	if (err)
    966		return err;
    967
    968	if (input)
    969		set_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags);
    970	else
    971		clear_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags);
    972
    973	return count;
    974}
    975
    976static int rtw_debugfs_get_force_lowest_basic_rate(struct seq_file *m, void *v)
    977{
    978	struct rtw_debugfs_priv *debugfs_priv = m->private;
    979	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    980
    981	seq_printf(m, "force lowest basic rate: %d\n",
    982		   test_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags));
    983
    984	return 0;
    985}
    986
    987static ssize_t rtw_debugfs_set_dm_cap(struct file *filp,
    988				      const char __user *buffer,
    989				      size_t count, loff_t *loff)
    990{
    991	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
    992	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
    993	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
    994	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
    995	int bit;
    996	bool en;
    997
    998	if (kstrtoint_from_user(buffer, count, 10, &bit))
    999		return -EINVAL;
   1000
   1001	en = bit > 0;
   1002	bit = abs(bit);
   1003
   1004	if (bit >= RTW_DM_CAP_NUM) {
   1005		rtw_warn(rtwdev, "unknown DM CAP %d\n", bit);
   1006		return -EINVAL;
   1007	}
   1008
   1009	if (en)
   1010		dm_info->dm_flags &= ~BIT(bit);
   1011	else
   1012		dm_info->dm_flags |= BIT(bit);
   1013
   1014	debugfs_priv->dm_cap.bit = bit;
   1015
   1016	return count;
   1017}
   1018
   1019static void dump_gapk_status(struct rtw_dev *rtwdev, struct seq_file *m)
   1020{
   1021	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
   1022	struct rtw_gapk_info *txgapk = &rtwdev->dm_info.gapk;
   1023	int i, path;
   1024	u32 val;
   1025
   1026	seq_printf(m, "\n(%2d) %c%s\n\n", RTW_DM_CAP_TXGAPK,
   1027		   dm_info->dm_flags & BIT(RTW_DM_CAP_TXGAPK) ? '-' : '+',
   1028		   rtw_dm_cap_strs[RTW_DM_CAP_TXGAPK]);
   1029
   1030	for (path = 0; path < rtwdev->hal.rf_path_num; path++) {
   1031		val = rtw_read_rf(rtwdev, path, RF_GAINTX, RFREG_MASK);
   1032		seq_printf(m, "path %d:\n0x%x = 0x%x\n", path, RF_GAINTX, val);
   1033
   1034		for (i = 0; i < RF_HW_OFFSET_NUM; i++)
   1035			seq_printf(m, "[TXGAPK] offset %d %d\n",
   1036				   txgapk->rf3f_fs[path][i], i);
   1037		seq_puts(m, "\n");
   1038	}
   1039}
   1040
   1041static int rtw_debugfs_get_dm_cap(struct seq_file *m, void *v)
   1042{
   1043	struct rtw_debugfs_priv *debugfs_priv = m->private;
   1044	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
   1045	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
   1046	int i;
   1047
   1048	switch (debugfs_priv->dm_cap.bit) {
   1049	case RTW_DM_CAP_TXGAPK:
   1050		dump_gapk_status(rtwdev, m);
   1051		break;
   1052	default:
   1053		for (i = 1; i < RTW_DM_CAP_NUM; i++) {
   1054			seq_printf(m, "(%2d) %c%s\n", i,
   1055				   dm_info->dm_flags & BIT(i) ? '-' : '+',
   1056				   rtw_dm_cap_strs[i]);
   1057		}
   1058		break;
   1059	}
   1060	debugfs_priv->dm_cap.bit = RTW_DM_CAP_NA;
   1061	return 0;
   1062}
   1063
   1064#define rtw_debug_impl_mac(page, addr)				\
   1065static struct rtw_debugfs_priv rtw_debug_priv_mac_ ##page = {	\
   1066	.cb_read = rtw_debug_get_mac_page,			\
   1067	.cb_data = addr,					\
   1068}
   1069
   1070rtw_debug_impl_mac(0, 0x0000);
   1071rtw_debug_impl_mac(1, 0x0100);
   1072rtw_debug_impl_mac(2, 0x0200);
   1073rtw_debug_impl_mac(3, 0x0300);
   1074rtw_debug_impl_mac(4, 0x0400);
   1075rtw_debug_impl_mac(5, 0x0500);
   1076rtw_debug_impl_mac(6, 0x0600);
   1077rtw_debug_impl_mac(7, 0x0700);
   1078rtw_debug_impl_mac(10, 0x1000);
   1079rtw_debug_impl_mac(11, 0x1100);
   1080rtw_debug_impl_mac(12, 0x1200);
   1081rtw_debug_impl_mac(13, 0x1300);
   1082rtw_debug_impl_mac(14, 0x1400);
   1083rtw_debug_impl_mac(15, 0x1500);
   1084rtw_debug_impl_mac(16, 0x1600);
   1085rtw_debug_impl_mac(17, 0x1700);
   1086
   1087#define rtw_debug_impl_bb(page, addr)			\
   1088static struct rtw_debugfs_priv rtw_debug_priv_bb_ ##page = {	\
   1089	.cb_read = rtw_debug_get_bb_page,			\
   1090	.cb_data = addr,					\
   1091}
   1092
   1093rtw_debug_impl_bb(8, 0x0800);
   1094rtw_debug_impl_bb(9, 0x0900);
   1095rtw_debug_impl_bb(a, 0x0a00);
   1096rtw_debug_impl_bb(b, 0x0b00);
   1097rtw_debug_impl_bb(c, 0x0c00);
   1098rtw_debug_impl_bb(d, 0x0d00);
   1099rtw_debug_impl_bb(e, 0x0e00);
   1100rtw_debug_impl_bb(f, 0x0f00);
   1101rtw_debug_impl_bb(18, 0x1800);
   1102rtw_debug_impl_bb(19, 0x1900);
   1103rtw_debug_impl_bb(1a, 0x1a00);
   1104rtw_debug_impl_bb(1b, 0x1b00);
   1105rtw_debug_impl_bb(1c, 0x1c00);
   1106rtw_debug_impl_bb(1d, 0x1d00);
   1107rtw_debug_impl_bb(1e, 0x1e00);
   1108rtw_debug_impl_bb(1f, 0x1f00);
   1109rtw_debug_impl_bb(2c, 0x2c00);
   1110rtw_debug_impl_bb(2d, 0x2d00);
   1111rtw_debug_impl_bb(40, 0x4000);
   1112rtw_debug_impl_bb(41, 0x4100);
   1113
   1114static struct rtw_debugfs_priv rtw_debug_priv_rf_dump = {
   1115	.cb_read = rtw_debug_get_rf_dump,
   1116};
   1117
   1118static struct rtw_debugfs_priv rtw_debug_priv_tx_pwr_tbl = {
   1119	.cb_read = rtw_debugfs_get_tx_pwr_tbl,
   1120};
   1121
   1122static struct rtw_debugfs_priv rtw_debug_priv_write_reg = {
   1123	.cb_write = rtw_debugfs_set_write_reg,
   1124};
   1125
   1126static struct rtw_debugfs_priv rtw_debug_priv_h2c = {
   1127	.cb_write = rtw_debugfs_set_h2c,
   1128};
   1129
   1130static struct rtw_debugfs_priv rtw_debug_priv_rf_write = {
   1131	.cb_write = rtw_debugfs_set_rf_write,
   1132};
   1133
   1134static struct rtw_debugfs_priv rtw_debug_priv_rf_read = {
   1135	.cb_write = rtw_debugfs_set_rf_read,
   1136	.cb_read = rtw_debugfs_get_rf_read,
   1137};
   1138
   1139static struct rtw_debugfs_priv rtw_debug_priv_read_reg = {
   1140	.cb_write = rtw_debugfs_set_read_reg,
   1141	.cb_read = rtw_debugfs_get_read_reg,
   1142};
   1143
   1144static struct rtw_debugfs_priv rtw_debug_priv_fix_rate = {
   1145	.cb_write = rtw_debugfs_set_fix_rate,
   1146	.cb_read = rtw_debugfs_get_fix_rate,
   1147};
   1148
   1149static struct rtw_debugfs_priv rtw_debug_priv_dump_cam = {
   1150	.cb_write = rtw_debugfs_set_single_input,
   1151	.cb_read = rtw_debugfs_get_dump_cam,
   1152};
   1153
   1154static struct rtw_debugfs_priv rtw_debug_priv_rsvd_page = {
   1155	.cb_write = rtw_debugfs_set_rsvd_page,
   1156	.cb_read = rtw_debugfs_get_rsvd_page,
   1157};
   1158
   1159static struct rtw_debugfs_priv rtw_debug_priv_phy_info = {
   1160	.cb_read = rtw_debugfs_get_phy_info,
   1161};
   1162
   1163static struct rtw_debugfs_priv rtw_debug_priv_coex_enable = {
   1164	.cb_write = rtw_debugfs_set_coex_enable,
   1165	.cb_read = rtw_debugfs_get_coex_enable,
   1166};
   1167
   1168static struct rtw_debugfs_priv rtw_debug_priv_coex_info = {
   1169	.cb_read = rtw_debugfs_get_coex_info,
   1170};
   1171
   1172static struct rtw_debugfs_priv rtw_debug_priv_edcca_enable = {
   1173	.cb_write = rtw_debugfs_set_edcca_enable,
   1174	.cb_read = rtw_debugfs_get_edcca_enable,
   1175};
   1176
   1177static struct rtw_debugfs_priv rtw_debug_priv_fw_crash = {
   1178	.cb_write = rtw_debugfs_set_fw_crash,
   1179	.cb_read = rtw_debugfs_get_fw_crash,
   1180};
   1181
   1182static struct rtw_debugfs_priv rtw_debug_priv_force_lowest_basic_rate = {
   1183	.cb_write = rtw_debugfs_set_force_lowest_basic_rate,
   1184	.cb_read = rtw_debugfs_get_force_lowest_basic_rate,
   1185};
   1186
   1187static struct rtw_debugfs_priv rtw_debug_priv_dm_cap = {
   1188	.cb_write = rtw_debugfs_set_dm_cap,
   1189	.cb_read = rtw_debugfs_get_dm_cap,
   1190};
   1191
   1192#define rtw_debugfs_add_core(name, mode, fopname, parent)		\
   1193	do {								\
   1194		rtw_debug_priv_ ##name.rtwdev = rtwdev;			\
   1195		if (!debugfs_create_file(#name, mode,			\
   1196					 parent, &rtw_debug_priv_ ##name,\
   1197					 &file_ops_ ##fopname))		\
   1198			pr_debug("Unable to initialize debugfs:%s\n",	\
   1199			       #name);					\
   1200	} while (0)
   1201
   1202#define rtw_debugfs_add_w(name)						\
   1203	rtw_debugfs_add_core(name, S_IFREG | 0222, common_write, debugfs_topdir)
   1204#define rtw_debugfs_add_rw(name)					\
   1205	rtw_debugfs_add_core(name, S_IFREG | 0666, single_rw, debugfs_topdir)
   1206#define rtw_debugfs_add_r(name)						\
   1207	rtw_debugfs_add_core(name, S_IFREG | 0444, single_r, debugfs_topdir)
   1208
   1209void rtw_debugfs_init(struct rtw_dev *rtwdev)
   1210{
   1211	struct dentry *debugfs_topdir;
   1212
   1213	debugfs_topdir = debugfs_create_dir("rtw88",
   1214					    rtwdev->hw->wiphy->debugfsdir);
   1215	rtw_debugfs_add_w(write_reg);
   1216	rtw_debugfs_add_rw(read_reg);
   1217	rtw_debugfs_add_w(rf_write);
   1218	rtw_debugfs_add_rw(rf_read);
   1219	rtw_debugfs_add_rw(fix_rate);
   1220	rtw_debugfs_add_rw(dump_cam);
   1221	rtw_debugfs_add_rw(rsvd_page);
   1222	rtw_debugfs_add_r(phy_info);
   1223	rtw_debugfs_add_r(coex_info);
   1224	rtw_debugfs_add_rw(coex_enable);
   1225	rtw_debugfs_add_w(h2c);
   1226	rtw_debugfs_add_r(mac_0);
   1227	rtw_debugfs_add_r(mac_1);
   1228	rtw_debugfs_add_r(mac_2);
   1229	rtw_debugfs_add_r(mac_3);
   1230	rtw_debugfs_add_r(mac_4);
   1231	rtw_debugfs_add_r(mac_5);
   1232	rtw_debugfs_add_r(mac_6);
   1233	rtw_debugfs_add_r(mac_7);
   1234	rtw_debugfs_add_r(bb_8);
   1235	rtw_debugfs_add_r(bb_9);
   1236	rtw_debugfs_add_r(bb_a);
   1237	rtw_debugfs_add_r(bb_b);
   1238	rtw_debugfs_add_r(bb_c);
   1239	rtw_debugfs_add_r(bb_d);
   1240	rtw_debugfs_add_r(bb_e);
   1241	rtw_debugfs_add_r(bb_f);
   1242	rtw_debugfs_add_r(mac_10);
   1243	rtw_debugfs_add_r(mac_11);
   1244	rtw_debugfs_add_r(mac_12);
   1245	rtw_debugfs_add_r(mac_13);
   1246	rtw_debugfs_add_r(mac_14);
   1247	rtw_debugfs_add_r(mac_15);
   1248	rtw_debugfs_add_r(mac_16);
   1249	rtw_debugfs_add_r(mac_17);
   1250	rtw_debugfs_add_r(bb_18);
   1251	rtw_debugfs_add_r(bb_19);
   1252	rtw_debugfs_add_r(bb_1a);
   1253	rtw_debugfs_add_r(bb_1b);
   1254	rtw_debugfs_add_r(bb_1c);
   1255	rtw_debugfs_add_r(bb_1d);
   1256	rtw_debugfs_add_r(bb_1e);
   1257	rtw_debugfs_add_r(bb_1f);
   1258	if (rtwdev->chip->id == RTW_CHIP_TYPE_8822C) {
   1259		rtw_debugfs_add_r(bb_2c);
   1260		rtw_debugfs_add_r(bb_2d);
   1261		rtw_debugfs_add_r(bb_40);
   1262		rtw_debugfs_add_r(bb_41);
   1263	}
   1264	rtw_debugfs_add_r(rf_dump);
   1265	rtw_debugfs_add_r(tx_pwr_tbl);
   1266	rtw_debugfs_add_rw(edcca_enable);
   1267	rtw_debugfs_add_rw(fw_crash);
   1268	rtw_debugfs_add_rw(force_lowest_basic_rate);
   1269	rtw_debugfs_add_rw(dm_cap);
   1270}
   1271
   1272#endif /* CONFIG_RTW88_DEBUGFS */
   1273
   1274#ifdef CONFIG_RTW88_DEBUG
   1275
   1276void __rtw_dbg(struct rtw_dev *rtwdev, enum rtw_debug_mask mask,
   1277	       const char *fmt, ...)
   1278{
   1279	struct va_format vaf = {
   1280		.fmt = fmt,
   1281	};
   1282	va_list args;
   1283
   1284	va_start(args, fmt);
   1285	vaf.va = &args;
   1286
   1287	if (rtw_debug_mask & mask)
   1288		dev_printk(KERN_DEBUG, rtwdev->dev, "%pV", &vaf);
   1289
   1290	va_end(args);
   1291}
   1292EXPORT_SYMBOL(__rtw_dbg);
   1293
   1294#endif /* CONFIG_RTW88_DEBUG */