]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
net: hns3: Add debugfs framework registration
authorliuzhongzhu <liuzhongzhu@huawei.com>
Thu, 22 Nov 2018 14:09:41 +0000 (14:09 +0000)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Mon, 14 Jan 2019 09:28:55 +0000 (09:28 +0000)
BugLink: https://bugs.launchpad.net/bugs/1810457
Add the debugfs framework to the driver and create a debugfs
command interface for each device.

example command:
"echo queue info > cmd" Query the packet forwarding queue information.

Signed-off-by: liuzhongzhu <liuzhongzhu@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit b2292360bb2ae50be043c3806e84210f9027f6eb)
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/net/ethernet/hisilicon/hns3/Makefile
drivers/net/ethernet/hisilicon/hns3/hnae3.h
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c [new file with mode: 0644]
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
drivers/net/ethernet/hisilicon/hns3/hns3_enet.h

index 002534f12b661dc01da7aab04da179b3a4c05cb1..d01bf536eb86941218770cb9c28835228e9cd953 100644 (file)
@@ -9,6 +9,6 @@ obj-$(CONFIG_HNS3) += hns3vf/
 obj-$(CONFIG_HNS3) += hnae3.o
 
 obj-$(CONFIG_HNS3_ENET) += hns3.o
-hns3-objs = hns3_enet.o hns3_ethtool.o
+hns3-objs = hns3_enet.o hns3_ethtool.o hns3_debugfs.o
 
 hns3-$(CONFIG_HNS3_DCB) += hns3_dcbnl.o
index fa152ef6b11e3f837a2ad241c0782788d52324e5..e16e6102a396a8a899a5bb80a569e02307b08b09 100644 (file)
@@ -563,6 +563,7 @@ struct hnae3_handle {
        u32 numa_node_mask;     /* for multi-chip support */
 
        u8 netdev_flags;
+       struct dentry *hnae3_dbgfs;
 };
 
 #define hnae3_set_field(origin, mask, shift, val) \
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
new file mode 100644 (file)
index 0000000..9d9ad11
--- /dev/null
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (c) 2018-2019 Hisilicon Limited. */
+
+#include <linux/debugfs.h>
+#include <linux/device.h>
+
+#include "hnae3.h"
+#include "hns3_enet.h"
+
+#define HNS3_DBG_READ_LEN 256
+
+static struct dentry *hns3_dbgfs_root;
+
+static void hns3_dbg_help(struct hnae3_handle *h)
+{
+       dev_info(&h->pdev->dev, "available commands\n");
+       dev_info(&h->pdev->dev, "queue info [number]\n");
+       dev_info(&h->pdev->dev, "dump fd tcam\n");
+}
+
+static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
+                                size_t count, loff_t *ppos)
+{
+       int uncopy_bytes;
+       char *buf;
+       int len;
+
+       if (*ppos != 0)
+               return 0;
+
+       if (count < HNS3_DBG_READ_LEN)
+               return -ENOSPC;
+
+       buf = kzalloc(HNS3_DBG_READ_LEN, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       len = snprintf(buf, HNS3_DBG_READ_LEN, "%s\n",
+                      "Please echo help to cmd to get help information");
+       uncopy_bytes = copy_to_user(buffer, buf, len);
+
+       kfree(buf);
+
+       if (uncopy_bytes)
+               return -EFAULT;
+
+       return (*ppos = len);
+}
+
+static ssize_t hns3_dbg_cmd_write(struct file *filp, const char __user *buffer,
+                                 size_t count, loff_t *ppos)
+{
+       struct hnae3_handle *handle = filp->private_data;
+       char *cmd_buf, *cmd_buf_tmp;
+       int uncopied_bytes;
+       int ret = 0;
+
+       if (*ppos != 0)
+               return 0;
+
+       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;
+       }
+
+       if (strncmp(cmd_buf, "help", 4) == 0)
+               hns3_dbg_help(handle);
+
+       if (ret)
+               hns3_dbg_help(handle);
+
+       kfree(cmd_buf);
+       cmd_buf = NULL;
+
+       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,
+};
+
+void hns3_dbg_init(struct hnae3_handle *handle)
+{
+       const char *name = pci_name(handle->pdev);
+       struct dentry *pfile;
+
+       handle->hnae3_dbgfs = debugfs_create_dir(name, hns3_dbgfs_root);
+       if (!handle->hnae3_dbgfs)
+               return;
+
+       pfile = debugfs_create_file("cmd", 0600, handle->hnae3_dbgfs, handle,
+                                   &hns3_dbg_cmd_fops);
+       if (!pfile) {
+               debugfs_remove_recursive(handle->hnae3_dbgfs);
+               handle->hnae3_dbgfs = NULL;
+               dev_warn(&handle->pdev->dev, "create file for %s fail\n",
+                        name);
+       }
+}
+
+void hns3_dbg_uninit(struct hnae3_handle *handle)
+{
+       debugfs_remove_recursive(handle->hnae3_dbgfs);
+       handle->hnae3_dbgfs = NULL;
+}
+
+void hns3_dbg_register_debugfs(const char *debugfs_dir_name)
+{
+       hns3_dbgfs_root = debugfs_create_dir(debugfs_dir_name, NULL);
+       if (!hns3_dbgfs_root) {
+               pr_warn("Register debugfs for %s fail\n", debugfs_dir_name);
+               return;
+       }
+}
+
+void hns3_dbg_unregister_debugfs(void)
+{
+       debugfs_remove_recursive(hns3_dbgfs_root);
+       hns3_dbgfs_root = NULL;
+}
index 57de21622e884538ec17c75c781522052150f154..f031e418272019a3c00e58f27de4744bcf2028d5 100644 (file)
@@ -3607,6 +3607,8 @@ static int hns3_client_init(struct hnae3_handle *handle)
 
        hns3_dcbnl_setup(handle);
 
+       hns3_dbg_init(handle);
+
        /* MTU range: (ETH_MIN_MTU(kernel default) - 9702) */
        netdev->max_mtu = HNS3_MAX_MTU;
 
@@ -3663,6 +3665,8 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset)
 
        hns3_put_ring_config(priv);
 
+       hns3_dbg_uninit(handle);
+
        priv->ring_data = NULL;
 
 out_netdev_free:
@@ -4232,15 +4236,23 @@ static int __init hns3_init_module(void)
 
        INIT_LIST_HEAD(&client.node);
 
+       hns3_dbg_register_debugfs(hns3_driver_name);
+
        ret = hnae3_register_client(&client);
        if (ret)
-               return ret;
+               goto err_reg_client;
 
        ret = pci_register_driver(&hns3_driver);
        if (ret)
-               hnae3_unregister_client(&client);
+               goto err_reg_driver;
 
        return ret;
+
+err_reg_driver:
+       hnae3_unregister_client(&client);
+err_reg_client:
+       hns3_dbg_unregister_debugfs();
+       return ret;
 }
 module_init(hns3_init_module);
 
@@ -4252,6 +4264,7 @@ static void __exit hns3_exit_module(void)
 {
        pci_unregister_driver(&hns3_driver);
        hnae3_unregister_client(&client);
+       hns3_dbg_unregister_debugfs();
 }
 module_exit(hns3_exit_module);
 
index ba235a4c173f9d77953a89259bc8b63b3ec5765e..6eff12a172c73808b1a351f8c517b918626df1c5 100644 (file)
@@ -683,4 +683,8 @@ void hns3_dcbnl_setup(struct hnae3_handle *handle);
 static inline void hns3_dcbnl_setup(struct hnae3_handle *handle) {}
 #endif
 
+void hns3_dbg_init(struct hnae3_handle *handle);
+void hns3_dbg_uninit(struct hnae3_handle *handle);
+void hns3_dbg_register_debugfs(const char *debugfs_dir_name);
+void hns3_dbg_unregister_debugfs(void);
 #endif