git: 11c53278a8a3 - main - rtw88: update Realtek's rtw88 driver.

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 28 Oct 2024 14:49:45 UTC
The branch main has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=11c53278a8a3e86e14377f09bbaa7bad193d3713

commit 11c53278a8a3e86e14377f09bbaa7bad193d3713
Merge: a4128aad8503 8e9553a4cdee
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-09-24 23:50:22 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-10-28 14:42:32 +0000

    rtw88: update Realtek's rtw88 driver.
    
    This version is based on
    git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    98f7e32f20d28ec452afb208f9cffc08448a2652 ( tag: v6.11 ).
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      14 days

 sys/contrib/dev/rtw88/Makefile          |    9 +
 sys/contrib/dev/rtw88/coex.c            |    4 +-
 sys/contrib/dev/rtw88/debug.c           |   54 +-
 sys/contrib/dev/rtw88/debug.h           |   23 +-
 sys/contrib/dev/rtw88/fw.c              |   92 +-
 sys/contrib/dev/rtw88/fw.h              |    5 +
 sys/contrib/dev/rtw88/mac.c             |   27 +-
 sys/contrib/dev/rtw88/mac80211.c        |   12 +-
 sys/contrib/dev/rtw88/main.c            |   25 +-
 sys/contrib/dev/rtw88/main.h            |   27 +-
 sys/contrib/dev/rtw88/pci.c             |   28 +-
 sys/contrib/dev/rtw88/pci.h             |    2 +-
 sys/contrib/dev/rtw88/phy.c             |    3 +
 sys/contrib/dev/rtw88/ps.c              |    2 +
 sys/contrib/dev/rtw88/reg.h             |   27 +
 sys/contrib/dev/rtw88/regd.c            |   24 +-
 sys/contrib/dev/rtw88/regd.h            |    2 +
 sys/contrib/dev/rtw88/rtw8703b.c        | 2122 +++++++++++++++++++++++++++++++
 sys/contrib/dev/rtw88/rtw8703b.h        |  102 ++
 sys/contrib/dev/rtw88/rtw8703b_tables.c |  902 +++++++++++++
 sys/contrib/dev/rtw88/rtw8703b_tables.h |   14 +
 sys/contrib/dev/rtw88/rtw8723cs.c       |   34 +
 sys/contrib/dev/rtw88/rtw8723d.c        |  674 +---------
 sys/contrib/dev/rtw88/rtw8723d.h        |  268 +---
 sys/contrib/dev/rtw88/rtw8723x.c        |  724 +++++++++++
 sys/contrib/dev/rtw88/rtw8723x.h        |  518 ++++++++
 sys/contrib/dev/rtw88/rtw8821c.c        |   70 +-
 sys/contrib/dev/rtw88/rtw8821c.h        |    1 +
 sys/contrib/dev/rtw88/rtw8821c_table.c  | 1154 ++++++++++++-----
 sys/contrib/dev/rtw88/rtw8821cu.c       |   40 +-
 sys/contrib/dev/rtw88/rtw8822b.c        |    1 +
 sys/contrib/dev/rtw88/rtw8822c.c        |    1 +
 sys/contrib/dev/rtw88/rtw8822c_table.c  | 1239 ++++++++----------
 sys/contrib/dev/rtw88/rtw8822cu.c       |    4 +-
 sys/contrib/dev/rtw88/rx.h              |    2 +
 sys/contrib/dev/rtw88/sar.c             |    4 +
 sys/contrib/dev/rtw88/sdio.c            |   35 +-
 sys/contrib/dev/rtw88/tx.c              |    3 +-
 sys/contrib/dev/rtw88/usb.c             |   87 +-
 sys/modules/rtw88/Makefile              |    2 +
 40 files changed, 6278 insertions(+), 2089 deletions(-)

diff --cc sys/contrib/dev/rtw88/Makefile
index fd212c09d88a,000000000000..8f47359b4380
mode 100644,000000..100644
--- a/sys/contrib/dev/rtw88/Makefile
+++ b/sys/contrib/dev/rtw88/Makefile
@@@ -1,78 -1,0 +1,87 @@@
 +# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
 +
 +obj-$(CONFIG_RTW88_CORE)	+= rtw88_core.o
 +rtw88_core-y += main.o \
 +	   mac80211.o \
 +	   util.o \
 +	   debug.o \
 +	   tx.o \
 +	   rx.o \
 +	   mac.o \
 +	   phy.o \
 +	   coex.o \
 +	   efuse.o \
 +	   fw.o \
 +	   ps.o \
 +	   sec.o \
 +	   bf.o \
 +	   sar.o \
 +	   regd.o
 +
 +rtw88_core-$(CONFIG_PM) += wow.o
 +
 +obj-$(CONFIG_RTW88_8822B)	+= rtw88_8822b.o
 +rtw88_8822b-objs		:= rtw8822b.o rtw8822b_table.o
 +
 +obj-$(CONFIG_RTW88_8822BE)	+= rtw88_8822be.o
 +rtw88_8822be-objs		:= rtw8822be.o
 +
 +obj-$(CONFIG_RTW88_8822BS)	+= rtw88_8822bs.o
 +rtw88_8822bs-objs		:= rtw8822bs.o
 +
 +obj-$(CONFIG_RTW88_8822BU)	+= rtw88_8822bu.o
 +rtw88_8822bu-objs		:= rtw8822bu.o
 +
 +obj-$(CONFIG_RTW88_8822C)	+= rtw88_8822c.o
 +rtw88_8822c-objs		:= rtw8822c.o rtw8822c_table.o
 +
 +obj-$(CONFIG_RTW88_8822CE)	+= rtw88_8822ce.o
 +rtw88_8822ce-objs		:= rtw8822ce.o
 +
 +obj-$(CONFIG_RTW88_8822CS)	+= rtw88_8822cs.o
 +rtw88_8822cs-objs		:= rtw8822cs.o
 +
 +obj-$(CONFIG_RTW88_8822CU)	+= rtw88_8822cu.o
 +rtw88_8822cu-objs		:= rtw8822cu.o
 +
++obj-$(CONFIG_RTW88_8723X)	+= rtw88_8723x.o
++rtw88_8723x-objs		:= rtw8723x.o
++
++obj-$(CONFIG_RTW88_8703B)	+= rtw88_8703b.o
++rtw88_8703b-objs		:= rtw8703b.o rtw8703b_tables.o
++
++obj-$(CONFIG_RTW88_8723CS)	+= rtw88_8723cs.o
++rtw88_8723cs-objs		:= rtw8723cs.o
++
 +obj-$(CONFIG_RTW88_8723D)	+= rtw88_8723d.o
 +rtw88_8723d-objs		:= rtw8723d.o rtw8723d_table.o
 +
 +obj-$(CONFIG_RTW88_8723DE)	+= rtw88_8723de.o
 +rtw88_8723de-objs		:= rtw8723de.o
 +
 +obj-$(CONFIG_RTW88_8723DS)	+= rtw88_8723ds.o
 +rtw88_8723ds-objs		:= rtw8723ds.o
 +
 +obj-$(CONFIG_RTW88_8723DU)	+= rtw88_8723du.o
 +rtw88_8723du-objs		:= rtw8723du.o
 +
 +obj-$(CONFIG_RTW88_8821C)	+= rtw88_8821c.o
 +rtw88_8821c-objs		:= rtw8821c.o rtw8821c_table.o
 +
 +obj-$(CONFIG_RTW88_8821CE)	+= rtw88_8821ce.o
 +rtw88_8821ce-objs		:= rtw8821ce.o
 +
 +obj-$(CONFIG_RTW88_8821CS)	+= rtw88_8821cs.o
 +rtw88_8821cs-objs		:= rtw8821cs.o
 +
 +obj-$(CONFIG_RTW88_8821CU)	+= rtw88_8821cu.o
 +rtw88_8821cu-objs		:= rtw8821cu.o
 +
 +obj-$(CONFIG_RTW88_PCI)		+= rtw88_pci.o
 +rtw88_pci-objs			:= pci.o
 +
 +obj-$(CONFIG_RTW88_SDIO)	+= rtw88_sdio.o
 +rtw88_sdio-objs			:= sdio.o
 +
 +obj-$(CONFIG_RTW88_USB)		+= rtw88_usb.o
 +rtw88_usb-objs			:= usb.o
diff --cc sys/contrib/dev/rtw88/debug.c
index d745c774aa6f,000000000000..e84f25b34c46
mode 100644,000000..100644
--- a/sys/contrib/dev/rtw88/debug.c
+++ b/sys/contrib/dev/rtw88/debug.c
@@@ -1,1339 -1,0 +1,1311 @@@
 +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
 +/* Copyright(c) 2018-2019  Realtek Corporation
 + */
 +
 +#include <linux/debugfs.h>
 +#include <linux/seq_file.h>
 +#include "main.h"
 +#include "coex.h"
 +#include "sec.h"
 +#include "fw.h"
 +#include "debug.h"
 +#include "phy.h"
 +#include "reg.h"
 +#include "ps.h"
 +#include "regd.h"
 +
 +#ifdef CONFIG_RTW88_DEBUGFS
 +
 +struct rtw_debugfs_priv {
 +	struct rtw_dev *rtwdev;
 +	int (*cb_read)(struct seq_file *m, void *v);
 +	ssize_t (*cb_write)(struct file *filp, const char __user *buffer,
 +			    size_t count, loff_t *loff);
 +	union {
 +		u32 cb_data;
 +		u8 *buf;
 +		struct {
 +			u32 page_offset;
 +			u32 page_num;
 +		} rsvd_page;
 +		struct {
 +			u8 rf_path;
 +			u32 rf_addr;
 +			u32 rf_mask;
 +		};
 +		struct {
 +			u32 addr;
 +			u32 len;
 +		} read_reg;
 +		struct {
 +			u8 bit;
 +		} dm_cap;
 +	};
 +};
 +
 +static const char * const rtw_dm_cap_strs[] = {
 +	[RTW_DM_CAP_NA] = "NA",
 +	[RTW_DM_CAP_TXGAPK] = "TXGAPK",
 +};
 +
 +static int rtw_debugfs_single_show(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +
 +	return debugfs_priv->cb_read(m, v);
 +}
 +
 +static ssize_t rtw_debugfs_common_write(struct file *filp,
 +					const char __user *buffer,
 +					size_t count, loff_t *loff)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
 +
 +	return debugfs_priv->cb_write(filp, buffer, count, loff);
 +}
 +
 +static ssize_t rtw_debugfs_single_write(struct file *filp,
 +					const char __user *buffer,
 +					size_t count, loff_t *loff)
 +{
 +	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
 +	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
 +
 +	return debugfs_priv->cb_write(filp, buffer, count, loff);
 +}
 +
 +static int rtw_debugfs_single_open_rw(struct inode *inode, struct file *filp)
 +{
 +	return single_open(filp, rtw_debugfs_single_show, inode->i_private);
 +}
 +
 +static int rtw_debugfs_close(struct inode *inode, struct file *filp)
 +{
 +	return 0;
 +}
 +
 +static const struct file_operations file_ops_single_r = {
 +	.owner = THIS_MODULE,
 +	.open = rtw_debugfs_single_open_rw,
 +	.read = seq_read,
 +	.llseek = seq_lseek,
 +	.release = single_release,
 +};
 +
 +static const struct file_operations file_ops_single_rw = {
 +	.owner = THIS_MODULE,
 +	.open = rtw_debugfs_single_open_rw,
 +	.release = single_release,
 +	.read = seq_read,
 +	.llseek = seq_lseek,
 +	.write = rtw_debugfs_single_write,
 +};
 +
 +static const struct file_operations file_ops_common_write = {
 +	.owner = THIS_MODULE,
 +	.write = rtw_debugfs_common_write,
 +	.open = simple_open,
 +	.release = rtw_debugfs_close,
 +};
 +
 +static int rtw_debugfs_get_read_reg(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	u32 val, len, addr;
 +
 +	len = debugfs_priv->read_reg.len;
 +	addr = debugfs_priv->read_reg.addr;
 +	switch (len) {
 +	case 1:
 +		val = rtw_read8(rtwdev, addr);
 +		seq_printf(m, "reg 0x%03x: 0x%02x\n", addr, val);
 +		break;
 +	case 2:
 +		val = rtw_read16(rtwdev, addr);
 +		seq_printf(m, "reg 0x%03x: 0x%04x\n", addr, val);
 +		break;
 +	case 4:
 +		val = rtw_read32(rtwdev, addr);
 +		seq_printf(m, "reg 0x%03x: 0x%08x\n", addr, val);
 +		break;
 +	}
 +	return 0;
 +}
 +
 +static int rtw_debugfs_get_rf_read(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	u32 val, addr, mask;
 +	u8 path;
 +
 +	path = debugfs_priv->rf_path;
 +	addr = debugfs_priv->rf_addr;
 +	mask = debugfs_priv->rf_mask;
 +
 +	mutex_lock(&rtwdev->mutex);
 +	val = rtw_read_rf(rtwdev, path, addr, mask);
 +	mutex_unlock(&rtwdev->mutex);
 +
 +	seq_printf(m, "rf_read path:%d addr:0x%08x mask:0x%08x val=0x%08x\n",
 +		   path, addr, mask, val);
 +
 +	return 0;
 +}
 +
 +static int rtw_debugfs_get_fix_rate(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
 +	u8 fix_rate = dm_info->fix_rate;
 +
 +	if (fix_rate >= DESC_RATE_MAX) {
 +		seq_printf(m, "Fix rate disabled, fix_rate = %u\n", fix_rate);
 +		return 0;
 +	}
 +
 +	seq_printf(m, "Data frames fixed at desc rate %u\n", fix_rate);
 +	return 0;
 +}
 +
 +static int rtw_debugfs_copy_from_user(char tmp[], int size,
 +				      const char __user *buffer, size_t count,
 +				      int num)
 +{
 +	int tmp_len;
 +
 +	memset(tmp, 0, size);
 +
 +	if (count < num)
 +		return -EFAULT;
 +
 +	tmp_len = (count > size - 1 ? size - 1 : count);
 +
 +	if (copy_from_user(tmp, buffer, tmp_len))
 +		return -EFAULT;
 +
 +	tmp[tmp_len] = '\0';
 +
 +	return 0;
 +}
 +
 +static ssize_t rtw_debugfs_set_read_reg(struct file *filp,
 +					const char __user *buffer,
 +					size_t count, loff_t *loff)
 +{
 +	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
 +	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	char tmp[32 + 1];
 +	u32 addr, len;
 +	int num;
 +	int ret;
 +
 +	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2);
 +	if (ret)
 +		return ret;
 +
 +	num = sscanf(tmp, "%x %x", &addr, &len);
 +
 +	if (num !=  2)
 +		return -EINVAL;
 +
 +	if (len != 1 && len != 2 && len != 4) {
 +		rtw_warn(rtwdev, "read reg setting wrong len\n");
 +		return -EINVAL;
 +	}
 +	debugfs_priv->read_reg.addr = addr;
 +	debugfs_priv->read_reg.len = len;
 +
 +	return count;
 +}
 +
 +static int rtw_debugfs_get_dump_cam(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	u32 val, command;
 +	u32 hw_key_idx = debugfs_priv->cb_data << RTW_SEC_CAM_ENTRY_SHIFT;
 +	u32 read_cmd = RTW_SEC_CMD_POLLING;
 +	int i;
 +
 +	seq_printf(m, "cam entry%d\n", debugfs_priv->cb_data);
 +	seq_puts(m, "0x0      0x1      0x2     0x3     ");
 +	seq_puts(m, "0x4     0x5\n");
 +	mutex_lock(&rtwdev->mutex);
 +	for (i = 0; i <= 5; i++) {
 +		command = read_cmd | (hw_key_idx + i);
 +		rtw_write32(rtwdev, RTW_SEC_CMD_REG, command);
 +		val = rtw_read32(rtwdev, RTW_SEC_READ_REG);
 +		seq_printf(m, "%8.8x", val);
 +		if (i < 2)
 +			seq_puts(m, " ");
 +	}
 +	seq_puts(m, "\n");
 +	mutex_unlock(&rtwdev->mutex);
 +	return 0;
 +}
 +
 +static int rtw_debugfs_get_rsvd_page(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	u8 page_size = rtwdev->chip->page_size;
 +	u32 buf_size = debugfs_priv->rsvd_page.page_num * page_size;
 +	u32 offset = debugfs_priv->rsvd_page.page_offset * page_size;
 +	u8 *buf;
 +	int i;
 +	int ret;
 +
 +	buf = vzalloc(buf_size);
 +	if (!buf)
 +		return -ENOMEM;
 +
 +	ret = rtw_fw_dump_fifo(rtwdev, RTW_FW_FIFO_SEL_RSVD_PAGE, offset,
 +			       buf_size, (u32 *)buf);
 +	if (ret) {
 +		rtw_err(rtwdev, "failed to dump rsvd page\n");
 +		vfree(buf);
 +		return ret;
 +	}
 +
 +	for (i = 0 ; i < buf_size ; i += 8) {
 +		if (i % page_size == 0)
 +			seq_printf(m, "PAGE %d\n", (i + offset) / page_size);
 +		seq_printf(m, "%8ph\n", buf + i);
 +	}
 +	vfree(buf);
 +
 +	return 0;
 +}
 +
 +static ssize_t rtw_debugfs_set_rsvd_page(struct file *filp,
 +					 const char __user *buffer,
 +					 size_t count, loff_t *loff)
 +{
 +	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
 +	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	char tmp[32 + 1];
 +	u32 offset, page_num;
 +	int num;
 +	int ret;
 +
 +	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2);
 +	if (ret)
 +		return ret;
 +
 +	num = sscanf(tmp, "%d %d", &offset, &page_num);
 +
 +	if (num != 2) {
 +		rtw_warn(rtwdev, "invalid arguments\n");
 +		return -EINVAL;
 +	}
 +
 +	debugfs_priv->rsvd_page.page_offset = offset;
 +	debugfs_priv->rsvd_page.page_num = page_num;
 +
 +	return count;
 +}
 +
 +static ssize_t rtw_debugfs_set_single_input(struct file *filp,
 +					    const char __user *buffer,
 +					    size_t count, loff_t *loff)
 +{
 +	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
 +	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
- 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
- 	char tmp[32 + 1];
 +	u32 input;
- 	int num;
 +	int ret;
 +
- 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
++	ret = kstrtou32_from_user(buffer, count, 0, &input);
 +	if (ret)
 +		return ret;
 +
- 	num = kstrtoint(tmp, 0, &input);
- 
- 	if (num) {
- 		rtw_warn(rtwdev, "kstrtoint failed\n");
- 		return num;
- 	}
- 
 +	debugfs_priv->cb_data = input;
 +
 +	return count;
 +}
 +
 +static ssize_t rtw_debugfs_set_write_reg(struct file *filp,
 +					 const char __user *buffer,
 +					 size_t count, loff_t *loff)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	char tmp[32 + 1];
 +	u32 addr, val, len;
 +	int num;
 +	int ret;
 +
 +	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
 +	if (ret)
 +		return ret;
 +
 +	/* write BB/MAC register */
 +	num = sscanf(tmp, "%x %x %x", &addr, &val, &len);
 +
 +	if (num !=  3)
 +		return -EINVAL;
 +
 +	switch (len) {
 +	case 1:
 +		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
 +			"reg write8 0x%03x: 0x%08x\n", addr, val);
 +		rtw_write8(rtwdev, addr, (u8)val);
 +		break;
 +	case 2:
 +		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
 +			"reg write16 0x%03x: 0x%08x\n", addr, val);
 +		rtw_write16(rtwdev, addr, (u16)val);
 +		break;
 +	case 4:
 +		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
 +			"reg write32 0x%03x: 0x%08x\n", addr, val);
 +		rtw_write32(rtwdev, addr, (u32)val);
 +		break;
 +	default:
 +		rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
 +			"error write length = %d\n", len);
 +		break;
 +	}
 +
 +	return count;
 +}
 +
 +static ssize_t rtw_debugfs_set_h2c(struct file *filp,
 +				   const char __user *buffer,
 +				   size_t count, loff_t *loff)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	char tmp[32 + 1];
 +	u8 param[8];
 +	int num;
 +	int ret;
 +
 +	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
 +	if (ret)
 +		return ret;
 +
 +	num = sscanf(tmp, "%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx",
 +		     &param[0], &param[1], &param[2], &param[3],
 +		     &param[4], &param[5], &param[6], &param[7]);
 +	if (num != 8) {
 +		rtw_warn(rtwdev, "invalid H2C command format for debug\n");
 +		return -EINVAL;
 +	}
 +
 +	mutex_lock(&rtwdev->mutex);
 +	rtw_fw_h2c_cmd_dbg(rtwdev, param);
 +	mutex_unlock(&rtwdev->mutex);
 +
 +	return count;
 +}
 +
 +static ssize_t rtw_debugfs_set_rf_write(struct file *filp,
 +					const char __user *buffer,
 +					size_t count, loff_t *loff)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	char tmp[32 + 1];
 +	u32 path, addr, mask, val;
 +	int num;
 +	int ret;
 +
 +	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 4);
 +	if (ret)
 +		return ret;
 +
 +	num = sscanf(tmp, "%x %x %x %x", &path, &addr, &mask, &val);
 +
 +	if (num !=  4) {
 +		rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n");
 +		return -EINVAL;
 +	}
 +
 +	mutex_lock(&rtwdev->mutex);
 +	rtw_write_rf(rtwdev, path, addr, mask, val);
 +	mutex_unlock(&rtwdev->mutex);
 +	rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
 +		"write_rf path:%d addr:0x%08x mask:0x%08x, val:0x%08x\n",
 +		path, addr, mask, val);
 +
 +	return count;
 +}
 +
 +static ssize_t rtw_debugfs_set_rf_read(struct file *filp,
 +				       const char __user *buffer,
 +				       size_t count, loff_t *loff)
 +{
 +	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
 +	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	char tmp[32 + 1];
 +	u32 path, addr, mask;
 +	int num;
 +	int ret;
 +
 +	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
 +	if (ret)
 +		return ret;
 +
 +	num = sscanf(tmp, "%x %x %x", &path, &addr, &mask);
 +
 +	if (num !=  3) {
 +		rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n");
 +		return -EINVAL;
 +	}
 +
 +	debugfs_priv->rf_path = path;
 +	debugfs_priv->rf_addr = addr;
 +	debugfs_priv->rf_mask = mask;
 +
 +	return count;
 +}
 +
 +static ssize_t rtw_debugfs_set_fix_rate(struct file *filp,
 +					const char __user *buffer,
 +					size_t count, loff_t *loff)
 +{
 +	struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
 +	struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
 +	u8 fix_rate;
- 	char tmp[32 + 1];
 +	int ret;
 +
- 	ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
++	ret = kstrtou8_from_user(buffer, count, 0, &fix_rate);
 +	if (ret)
 +		return ret;
 +
- 	ret = kstrtou8(tmp, 0, &fix_rate);
- 	if (ret) {
- 		rtw_warn(rtwdev, "invalid args, [rate]\n");
- 		return ret;
- 	}
- 
 +	dm_info->fix_rate = fix_rate;
 +
 +	return count;
 +}
 +
 +static int rtw_debug_get_mac_page(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	u32 page = debugfs_priv->cb_data;
 +	int i, n;
 +	int max = 0xff;
 +
 +	rtw_read32(rtwdev, debugfs_priv->cb_data);
 +	for (n = 0; n <= max; ) {
 +		seq_printf(m, "\n%8.8x  ", n + page);
 +		for (i = 0; i < 4 && n <= max; i++, n += 4)
 +			seq_printf(m, "%8.8x    ",
 +				   rtw_read32(rtwdev, (page | n)));
 +	}
 +	seq_puts(m, "\n");
 +	return 0;
 +}
 +
 +static int rtw_debug_get_bb_page(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	u32 page = debugfs_priv->cb_data;
 +	int i, n;
 +	int max = 0xff;
 +
 +	rtw_read32(rtwdev, debugfs_priv->cb_data);
 +	for (n = 0; n <= max; ) {
 +		seq_printf(m, "\n%8.8x  ", n + page);
 +		for (i = 0; i < 4 && n <= max; i++, n += 4)
 +			seq_printf(m, "%8.8x    ",
 +				   rtw_read32(rtwdev, (page | n)));
 +	}
 +	seq_puts(m, "\n");
 +	return 0;
 +}
 +
 +static int rtw_debug_get_rf_dump(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	u32 addr, offset, data;
 +	u8 path;
 +
 +	mutex_lock(&rtwdev->mutex);
 +
 +	for (path = 0; path < rtwdev->hal.rf_path_num; path++) {
 +		seq_printf(m, "RF path:%d\n", path);
 +		for (addr = 0; addr < 0x100; addr += 4) {
 +			seq_printf(m, "%8.8x  ", addr);
 +			for (offset = 0; offset < 4; offset++) {
 +				data = rtw_read_rf(rtwdev, path, addr + offset,
 +						   0xffffffff);
 +				seq_printf(m, "%8.8x    ", data);
 +			}
 +			seq_puts(m, "\n");
 +		}
 +		seq_puts(m, "\n");
 +	}
 +
 +	mutex_unlock(&rtwdev->mutex);
 +
 +	return 0;
 +}
 +
 +static void rtw_print_cck_rate_txt(struct seq_file *m, u8 rate)
 +{
 +	static const char * const
 +	cck_rate[] = {"1M", "2M", "5.5M", "11M"};
 +	u8 idx = rate - DESC_RATE1M;
 +
 +	seq_printf(m, " CCK_%-5s", cck_rate[idx]);
 +}
 +
 +static void rtw_print_ofdm_rate_txt(struct seq_file *m, u8 rate)
 +{
 +	static const char * const
 +	ofdm_rate[] = {"6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M"};
 +	u8 idx = rate - DESC_RATE6M;
 +
 +	seq_printf(m, " OFDM_%-4s", ofdm_rate[idx]);
 +}
 +
 +static void rtw_print_ht_rate_txt(struct seq_file *m, u8 rate)
 +{
 +	u8 mcs_n = rate - DESC_RATEMCS0;
 +
 +	seq_printf(m, " MCS%-6u", mcs_n);
 +}
 +
 +static void rtw_print_vht_rate_txt(struct seq_file *m, u8 rate)
 +{
 +	u8 idx = rate - DESC_RATEVHT1SS_MCS0;
 +	u8 n_ss, mcs_n;
 +
 +	/* n spatial stream */
 +	n_ss = 1 + idx / 10;
 +	/* MCS n */
 +	mcs_n = idx % 10;
 +	seq_printf(m, " VHT%uSMCS%u", n_ss, mcs_n);
 +}
 +
 +static void rtw_print_rate(struct seq_file *m, u8 rate)
 +{
 +	switch (rate) {
 +	case DESC_RATE1M...DESC_RATE11M:
 +		rtw_print_cck_rate_txt(m, rate);
 +		break;
 +	case DESC_RATE6M...DESC_RATE54M:
 +		rtw_print_ofdm_rate_txt(m, rate);
 +		break;
 +	case DESC_RATEMCS0...DESC_RATEMCS15:
 +		rtw_print_ht_rate_txt(m, rate);
 +		break;
 +	case DESC_RATEVHT1SS_MCS0...DESC_RATEVHT2SS_MCS9:
 +		rtw_print_vht_rate_txt(m, rate);
 +		break;
 +	default:
 +		seq_printf(m, " Unknown rate=0x%x\n", rate);
 +		break;
 +	}
 +}
 +
 +#define case_REGD(src) \
 +	case RTW_REGD_##src: return #src
 +
 +static const char *rtw_get_regd_string(u8 regd)
 +{
 +	switch (regd) {
 +	case_REGD(FCC);
 +	case_REGD(MKK);
 +	case_REGD(ETSI);
 +	case_REGD(IC);
 +	case_REGD(KCC);
 +	case_REGD(ACMA);
 +	case_REGD(CHILE);
 +	case_REGD(UKRAINE);
 +	case_REGD(MEXICO);
 +	case_REGD(CN);
 +	case_REGD(WW);
 +	default:
 +		return "Unknown";
 +	}
 +}
 +
 +static int rtw_debugfs_get_tx_pwr_tbl(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	struct rtw_hal *hal = &rtwdev->hal;
 +	u8 path, rate, bw, ch, regd;
 +	struct rtw_power_params pwr_param = {0};
 +
 +	mutex_lock(&rtwdev->mutex);
 +	bw = hal->current_band_width;
 +	ch = hal->current_channel;
 +	regd = rtw_regd_get(rtwdev);
 +
 +	seq_printf(m, "channel: %u\n", ch);
 +	seq_printf(m, "bandwidth: %u\n", bw);
 +	seq_printf(m, "regulatory: %s\n", rtw_get_regd_string(regd));
 +	seq_printf(m, "%-4s %-10s %-9s %-9s (%-4s %-4s %-4s) %-4s\n",
 +		   "path", "rate", "pwr", "base", "byr", "lmt", "sar", "rem");
 +
 +	mutex_lock(&hal->tx_power_mutex);
 +	for (path = RF_PATH_A; path <= RF_PATH_B; path++) {
 +		/* there is no CCK rates used in 5G */
 +		if (hal->current_band_type == RTW_BAND_5G)
 +			rate = DESC_RATE6M;
 +		else
 +			rate = DESC_RATE1M;
 +
 +		/* now, not support vht 3ss and vht 4ss*/
 +		for (; rate <= DESC_RATEVHT2SS_MCS9; rate++) {
 +			/* now, not support ht 3ss and ht 4ss*/
 +			if (rate > DESC_RATEMCS15 &&
 +			    rate < DESC_RATEVHT1SS_MCS0)
 +				continue;
 +
 +			rtw_get_tx_power_params(rtwdev, path, rate, bw,
 +						ch, regd, &pwr_param);
 +
 +			seq_printf(m, "%4c ", path + 'A');
 +			rtw_print_rate(m, rate);
 +			seq_printf(m, " %3u(0x%02x) %4u %4d (%4d %4d %4d) %4d\n",
 +				   hal->tx_pwr_tbl[path][rate],
 +				   hal->tx_pwr_tbl[path][rate],
 +				   pwr_param.pwr_base,
 +				   min3(pwr_param.pwr_offset,
 +					pwr_param.pwr_limit,
 +					pwr_param.pwr_sar),
 +				   pwr_param.pwr_offset, pwr_param.pwr_limit,
 +				   pwr_param.pwr_sar,
 +				   pwr_param.pwr_remnant);
 +		}
 +	}
 +
 +	mutex_unlock(&hal->tx_power_mutex);
 +	mutex_unlock(&rtwdev->mutex);
 +
 +	return 0;
 +}
 +
 +void rtw_debugfs_get_simple_phy_info(struct seq_file *m)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	struct rtw_hal *hal = &rtwdev->hal;
 +	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
 +	struct rtw_traffic_stats *stats = &rtwdev->stats;
 +
 +	seq_printf(m, "%-40s = %ddBm/ %d\n", "RSSI/ STA Channel",
 +		   dm_info->rssi[RF_PATH_A] - 100, hal->current_channel);
 +
 +	seq_printf(m, "TP {Tx, Rx} = {%u, %u}Mbps\n",
 +		   stats->tx_throughput, stats->rx_throughput);
 +
 +	seq_puts(m, "[Tx Rate] = ");
 +	rtw_print_rate(m, dm_info->tx_rate);
 +	seq_printf(m, "(0x%x)\n", dm_info->tx_rate);
 +
 +	seq_puts(m, "[Rx Rate] = ");
 +	rtw_print_rate(m, dm_info->curr_rx_rate);
 +	seq_printf(m, "(0x%x)\n", dm_info->curr_rx_rate);
 +}
 +
 +static int rtw_debugfs_get_phy_info(struct seq_file *m, void *v)
 +{
 +	struct rtw_debugfs_priv *debugfs_priv = m->private;
 +	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 +	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
 +	struct rtw_traffic_stats *stats = &rtwdev->stats;
 +	struct rtw_pkt_count *last_cnt = &dm_info->last_pkt_count;
 +	struct rtw_efuse *efuse = &rtwdev->efuse;
 +	struct ewma_evm *ewma_evm = dm_info->ewma_evm;
 +	struct ewma_snr *ewma_snr = dm_info->ewma_snr;
 +	u8 ss, rate_id;
 +
 +	seq_puts(m, "==========[Common Info]========\n");
 +	seq_printf(m, "Is link = %c\n", rtw_is_assoc(rtwdev) ? 'Y' : 'N');
 +	seq_printf(m, "Current CH(fc) = %u\n", rtwdev->hal.current_channel);
 +	seq_printf(m, "Current BW = %u\n", rtwdev->hal.current_band_width);
 +	seq_printf(m, "Current IGI = 0x%x\n", dm_info->igi_history[0]);
 +	seq_printf(m, "TP {Tx, Rx} = {%u, %u}Mbps\n",
 +		   stats->tx_throughput, stats->rx_throughput);
 +	seq_printf(m, "1SS for TX and RX = %c\n\n", rtwdev->hal.txrx_1ss ?
 +		   'Y' : 'N');
 +
 +	seq_puts(m, "==========[Tx Phy Info]========\n");
 +	seq_puts(m, "[Tx Rate] = ");
 +	rtw_print_rate(m, dm_info->tx_rate);
 +	seq_printf(m, "(0x%x)\n\n", dm_info->tx_rate);
 +
 +	seq_puts(m, "==========[Rx Phy Info]========\n");
 +	seq_printf(m, "[Rx Beacon Count] = %u\n", last_cnt->num_bcn_pkt);
 +	seq_puts(m, "[Rx Rate] = ");
 +	rtw_print_rate(m, dm_info->curr_rx_rate);
 +	seq_printf(m, "(0x%x)\n", dm_info->curr_rx_rate);
 +
 +	seq_puts(m, "[Rx Rate Count]:\n");
 +	seq_printf(m, " * CCK = {%u, %u, %u, %u}\n",
 +		   last_cnt->num_qry_pkt[DESC_RATE1M],
 +		   last_cnt->num_qry_pkt[DESC_RATE2M],
 +		   last_cnt->num_qry_pkt[DESC_RATE5_5M],
 +		   last_cnt->num_qry_pkt[DESC_RATE11M]);
 +
 +	seq_printf(m, " * OFDM = {%u, %u, %u, %u, %u, %u, %u, %u}\n",
 +		   last_cnt->num_qry_pkt[DESC_RATE6M],
 +		   last_cnt->num_qry_pkt[DESC_RATE9M],
 +		   last_cnt->num_qry_pkt[DESC_RATE12M],
 +		   last_cnt->num_qry_pkt[DESC_RATE18M],
 +		   last_cnt->num_qry_pkt[DESC_RATE24M],
 +		   last_cnt->num_qry_pkt[DESC_RATE36M],
 +		   last_cnt->num_qry_pkt[DESC_RATE48M],
 +		   last_cnt->num_qry_pkt[DESC_RATE54M]);
 +
 +	for (ss = 0; ss < efuse->hw_cap.nss; ss++) {
 +		rate_id = DESC_RATEMCS0 + ss * 8;
 +		seq_printf(m, " * HT_MCS[%u:%u] = {%u, %u, %u, %u, %u, %u, %u, %u}\n",
 +			   ss * 8, ss * 8 + 7,
 +			   last_cnt->num_qry_pkt[rate_id],
 +			   last_cnt->num_qry_pkt[rate_id + 1],
 +			   last_cnt->num_qry_pkt[rate_id + 2],
 +			   last_cnt->num_qry_pkt[rate_id + 3],
 +			   last_cnt->num_qry_pkt[rate_id + 4],
 +			   last_cnt->num_qry_pkt[rate_id + 5],
 +			   last_cnt->num_qry_pkt[rate_id + 6],
 +			   last_cnt->num_qry_pkt[rate_id + 7]);
 +	}
 +
 +	for (ss = 0; ss < efuse->hw_cap.nss; ss++) {
 +		rate_id = DESC_RATEVHT1SS_MCS0 + ss * 10;
 +		seq_printf(m, " * VHT_MCS-%uss MCS[0:9] = {%u, %u, %u, %u, %u, %u, %u, %u, %u, %u}\n",
 +			   ss + 1,
 +			   last_cnt->num_qry_pkt[rate_id],
 +			   last_cnt->num_qry_pkt[rate_id + 1],
 +			   last_cnt->num_qry_pkt[rate_id + 2],
 +			   last_cnt->num_qry_pkt[rate_id + 3],
 +			   last_cnt->num_qry_pkt[rate_id + 4],
 +			   last_cnt->num_qry_pkt[rate_id + 5],
 +			   last_cnt->num_qry_pkt[rate_id + 6],
 +			   last_cnt->num_qry_pkt[rate_id + 7],
 +			   last_cnt->num_qry_pkt[rate_id + 8],
 +			   last_cnt->num_qry_pkt[rate_id + 9]);
 +	}
 +
 +	seq_printf(m, "[RSSI(dBm)] = {%d, %d}\n",
 +		   dm_info->rssi[RF_PATH_A] - 100,
 +		   dm_info->rssi[RF_PATH_B] - 100);
 +	seq_printf(m, "[Rx EVM(dB)] = {-%d, -%d}\n",
 +		   dm_info->rx_evm_dbm[RF_PATH_A],
 +		   dm_info->rx_evm_dbm[RF_PATH_B]);
 +	seq_printf(m, "[Rx SNR] = {%d, %d}\n",
 +		   dm_info->rx_snr[RF_PATH_A],
 +		   dm_info->rx_snr[RF_PATH_B]);
 +	seq_printf(m, "[CFO_tail(KHz)] = {%d, %d}\n",
 +		   dm_info->cfo_tail[RF_PATH_A],
*** 15572 LINES SKIPPED ***