Skip to content

Commit

Permalink
net: hns3: debugfs add dump tm info of nodes, priority and qset
Browse files Browse the repository at this point in the history
To increase methods to dump more tm info, adds three debugfs commands
to dump tm info of nodes, priority and qset. And a new tm file of debugfs
is created for only dumping tm info.

Unlike previous debugfs commands, to dump each tm information, user needs
to enter two commands now. The first command writes parameters to tm and
the second command reads info from tm. For examples, to dump tm info of
priority 0, user needs to enter follow two commands:
1. echo dump priority 0 > tm
2. cat tm

The reason for adding new tm file is because we accepted Jakub Kicinski's
opinion as link https://lkml.org/lkml/2020/9/29/2101. And in order to
avoid generating too many files, we implement write ops to allow user to
input parameters.

However, If there are two or more users concurrently write parameters to
tm, parameters of the latest command will overwrite previous commands,
this concurrency problem will confuse users, but now there is no good
method to fix it.

Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
  • Loading branch information
Guangbin Huang authored and intel-lab-lkp committed Dec 31, 2020
1 parent 2c85ebc commit 6803a8c
Show file tree
Hide file tree
Showing 8 changed files with 412 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/net/ethernet/hisilicon/hns3/hnae3.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ struct hnae3_vector_info {
int vector;
};

enum hnae3_dbg_module_type {
HNAE3_DBG_MODULE_TYPE_TM,
};

#define HNAE3_RING_TYPE_B 0
#define HNAE3_RING_TYPE_TX 0
#define HNAE3_RING_TYPE_RX 1
Expand Down Expand Up @@ -454,6 +458,8 @@ struct hnae3_ae_dev {
* Configure the default MAC for specified VF
* get_module_eeprom
* Get the optical module eeprom info.
* dbg_read_cmd
* Execute debugfs read command.
*/
struct hnae3_ae_ops {
int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
Expand Down Expand Up @@ -609,6 +615,8 @@ struct hnae3_ae_ops {
int (*add_arfs_entry)(struct hnae3_handle *handle, u16 queue_id,
u16 flow_id, struct flow_keys *fkeys);
int (*dbg_run_cmd)(struct hnae3_handle *handle, const char *cmd_buf);
int (*dbg_read_cmd)(struct hnae3_handle *handle, const char *cmd_buf,
char *buf, int len);
pci_ers_result_t (*handle_hw_ras_error)(struct hnae3_ae_dev *ae_dev);
bool (*get_hw_reset_stat)(struct hnae3_handle *handle);
bool (*ae_dev_resetting)(struct hnae3_handle *handle);
Expand Down Expand Up @@ -734,6 +742,7 @@ struct hnae3_handle {

u8 netdev_flags;
struct dentry *hnae3_dbgfs;
int dbgfs_type;

/* Network interface message level enabled bits */
u32 msg_enable;
Expand Down
117 changes: 117 additions & 0 deletions drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

static struct dentry *hns3_dbgfs_root;

#define HNS3_HELP_INFO "help"

#define HNS3_DBG_MODULE_NAME_TM "tm"

static int hns3_dbg_queue_info(struct hnae3_handle *h,
const char *cmd_buf)
{
Expand Down Expand Up @@ -305,6 +309,22 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "%s", printf_buf);
}

static void hns3_dbg_tm_help(struct hnae3_handle *h, char *buf, int len)
{
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
int pos;

pos = scnprintf(buf, len, "available commands:\n");

if (!hns3_is_phys_func(h->pdev))
return;

if (ae_dev->dev_version > HNAE3_DEVICE_VERSION_V2)
pos += scnprintf(buf + pos, len - pos, "dump nodes\n");
pos += scnprintf(buf + pos, len - pos, "dump priority <pri id>\n");
pos += scnprintf(buf + pos, len - pos, "dump qset <qset id>\n");
}

static void hns3_dbg_dev_caps(struct hnae3_handle *h)
{
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
Expand Down Expand Up @@ -444,13 +464,107 @@ static ssize_t hns3_dbg_cmd_write(struct file *filp, const char __user *buffer,
return count;
}

static ssize_t hns3_dbg_tm_read(struct file *filp, char __user *buffer,
size_t count, loff_t *ppos)
{
struct hnae3_handle *handle = filp->private_data;
const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
struct hns3_nic_priv *priv = handle->priv;
char *cmd_buf, *read_buf;
ssize_t size = 0;
int ret = 0;

if (strncmp(filp->f_path.dentry->d_iname, HNS3_DBG_MODULE_NAME_TM,
strlen(HNS3_DBG_MODULE_NAME_TM)) != 0)
return -EINVAL;

if (!priv->dbg_in_msg.tm)
return -EINVAL;

read_buf = kzalloc(HNS3_DBG_READ_LEN, GFP_KERNEL);
if (!read_buf)
return -ENOMEM;

cmd_buf = priv->dbg_in_msg.tm;
handle->dbgfs_type = HNAE3_DBG_MODULE_TYPE_TM;

if (strncmp(cmd_buf, HNS3_HELP_INFO, strlen(HNS3_HELP_INFO)) == 0)
hns3_dbg_tm_help(handle, read_buf, HNS3_DBG_READ_LEN);
else if (ops->dbg_read_cmd)
ret = ops->dbg_read_cmd(handle, cmd_buf, read_buf,
HNS3_DBG_READ_LEN);

if (ret) {
dev_info(priv->dev, "unknown command\n");
goto out;
}

size = simple_read_from_buffer(buffer, count, ppos, read_buf,
strlen(read_buf));
out:
kfree(read_buf);
return size;
}

static ssize_t hns3_dbg_tm_write(struct file *filp, const char __user *buffer,
size_t count, loff_t *ppos)
{
struct hnae3_handle *handle = filp->private_data;
struct hns3_nic_priv *priv = handle->priv;
char *cmd_buf, *cmd_buf_tmp;
int uncopied_bytes;

if (*ppos != 0)
return 0;

/* Judge if the instance is being reset. */
if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
test_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
return 0;

if (count > HNS3_DBG_WRITE_LEN)
return -ENOSPC;

kfree(priv->dbg_in_msg.tm);
priv->dbg_in_msg.tm = NULL;

cmd_buf = kzalloc(count + 1, GFP_KERNEL);
if (!cmd_buf)
return count;

uncopied_bytes = copy_from_user(cmd_buf, buffer, count);
if (uncopied_bytes) {
kfree(cmd_buf);
return -EFAULT;
}

cmd_buf[count] = '\0';

cmd_buf_tmp = strchr(cmd_buf, '\n');
if (cmd_buf_tmp) {
*cmd_buf_tmp = '\0';
count = cmd_buf_tmp - cmd_buf + 1;
}

priv->dbg_in_msg.tm = cmd_buf;

return count;
}

static const struct file_operations hns3_dbg_cmd_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = hns3_dbg_cmd_read,
.write = hns3_dbg_cmd_write,
};

static const struct file_operations hns3_dbg_tm_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = hns3_dbg_tm_read,
.write = hns3_dbg_tm_write,
};

void hns3_dbg_init(struct hnae3_handle *handle)
{
const char *name = pci_name(handle->pdev);
Expand All @@ -459,6 +573,9 @@ void hns3_dbg_init(struct hnae3_handle *handle)

debugfs_create_file("cmd", 0600, handle->hnae3_dbgfs, handle,
&hns3_dbg_cmd_fops);

debugfs_create_file(HNS3_DBG_MODULE_NAME_TM, 0600, handle->hnae3_dbgfs,
handle, &hns3_dbg_tm_fops);
}

void hns3_dbg_uninit(struct hnae3_handle *handle)
Expand Down
6 changes: 6 additions & 0 deletions drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ struct hns3_enet_tqp_vector {
unsigned long last_jiffies;
} ____cacheline_internodealigned_in_smp;

struct hns3_dbg_input_msg {
char *tm;
};

struct hns3_nic_priv {
struct hnae3_handle *ae_handle;
struct net_device *netdev;
Expand All @@ -484,6 +488,8 @@ struct hns3_nic_priv {

struct hns3_enet_coalesce tx_coal;
struct hns3_enet_coalesce rx_coal;

struct hns3_dbg_input_msg dbg_in_msg;
};

union l3_hdr_info {
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ enum hclge_opcode_type {
HCLGE_OPC_TM_PRI_SCH_MODE_CFG = 0x0813,
HCLGE_OPC_TM_QS_SCH_MODE_CFG = 0x0814,
HCLGE_OPC_TM_BP_TO_QSET_MAPPING = 0x0815,
HCLGE_OPC_TM_NODES = 0x0816,
HCLGE_OPC_ETS_TC_WEIGHT = 0x0843,
HCLGE_OPC_QSET_DFX_STS = 0x0844,
HCLGE_OPC_PRI_DFX_STS = 0x0845,
Expand Down
Loading

0 comments on commit 6803a8c

Please sign in to comment.