RDMA/hns: Add debugfs to hns RoCE
authorJunxian Huang <huangjunxian6@hisilicon.com>
Tue, 14 Nov 2023 12:34:48 +0000 (20:34 +0800)
committerLeon Romanovsky <leon@kernel.org>
Sun, 19 Nov 2023 12:55:43 +0000 (14:55 +0200)
Add debugfs to hns RoCE. This patch only adds an empty directory
"hns_roce" to debugs root directory.

Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
Link: https://lore.kernel.org/r/20231114123449.1106162-3-huangjunxian6@hisilicon.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/hns/Makefile
drivers/infiniband/hw/hns/hns_roce_debugfs.c [new file with mode: 0644]
drivers/infiniband/hw/hns/hns_roce_debugfs.h [new file with mode: 0644]
drivers/infiniband/hw/hns/hns_roce_device.h
drivers/infiniband/hw/hns/hns_roce_hw_v2.c
drivers/infiniband/hw/hns/hns_roce_main.c

index a7d259238305b4505bc9634679cf20fefe31839b..be1e1cdbcfa8a82ea206ec4ca6d96e1c3924a89d 100644 (file)
@@ -7,7 +7,8 @@ ccflags-y :=  -I $(srctree)/drivers/net/ethernet/hisilicon/hns3
 
 hns-roce-objs := hns_roce_main.o hns_roce_cmd.o hns_roce_pd.o \
        hns_roce_ah.o hns_roce_hem.o hns_roce_mr.o hns_roce_qp.o \
-       hns_roce_cq.o hns_roce_alloc.o hns_roce_db.o hns_roce_srq.o hns_roce_restrack.o
+       hns_roce_cq.o hns_roce_alloc.o hns_roce_db.o hns_roce_srq.o hns_roce_restrack.o \
+       hns_roce_debugfs.o
 
 ifdef CONFIG_INFINIBAND_HNS_HIP08
 hns-roce-hw-v2-objs := hns_roce_hw_v2.o $(hns-roce-objs)
diff --git a/drivers/infiniband/hw/hns/hns_roce_debugfs.c b/drivers/infiniband/hw/hns/hns_roce_debugfs.c
new file mode 100644 (file)
index 0000000..7982557
--- /dev/null
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2023 Hisilicon Limited.
+ */
+
+#include <linux/debugfs.h>
+#include <linux/device.h>
+
+#include "hns_roce_device.h"
+
+static struct dentry *hns_roce_dbgfs_root;
+
+static int hns_debugfs_seqfile_open(struct inode *inode, struct file *f)
+{
+       struct hns_debugfs_seqfile *seqfile = inode->i_private;
+
+       return single_open(f, seqfile->read, seqfile->data);
+}
+
+static const struct file_operations hns_debugfs_seqfile_fops = {
+       .owner = THIS_MODULE,
+       .open = hns_debugfs_seqfile_open,
+       .release = single_release,
+       .read = seq_read,
+       .llseek = seq_lseek
+};
+
+static void init_debugfs_seqfile(struct hns_debugfs_seqfile *seq,
+                                const char *name, struct dentry *parent,
+                                int (*read_fn)(struct seq_file *, void *),
+                                void *data)
+{
+       debugfs_create_file(name, 0400, parent, seq, &hns_debugfs_seqfile_fops);
+
+       seq->read = read_fn;
+       seq->data = data;
+}
+
+/* debugfs for device */
+void hns_roce_register_debugfs(struct hns_roce_dev *hr_dev)
+{
+       struct hns_roce_dev_debugfs *dbgfs = &hr_dev->dbgfs;
+
+       dbgfs->root = debugfs_create_dir(dev_name(&hr_dev->ib_dev.dev),
+                                        hns_roce_dbgfs_root);
+}
+
+void hns_roce_unregister_debugfs(struct hns_roce_dev *hr_dev)
+{
+       debugfs_remove_recursive(hr_dev->dbgfs.root);
+}
+
+/* debugfs for hns module */
+void hns_roce_init_debugfs(void)
+{
+       hns_roce_dbgfs_root = debugfs_create_dir("hns_roce", NULL);
+}
+
+void hns_roce_cleanup_debugfs(void)
+{
+       debugfs_remove_recursive(hns_roce_dbgfs_root);
+       hns_roce_dbgfs_root = NULL;
+}
diff --git a/drivers/infiniband/hw/hns/hns_roce_debugfs.h b/drivers/infiniband/hw/hns/hns_roce_debugfs.h
new file mode 100644 (file)
index 0000000..ece71fe
--- /dev/null
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2023 Hisilicon Limited.
+ */
+
+#ifndef __HNS_ROCE_DEBUGFS_H
+#define __HNS_ROCE_DEBUGFS_H
+
+/* debugfs seqfile */
+struct hns_debugfs_seqfile {
+       int (*read)(struct seq_file *seq, void *data);
+       void *data;
+};
+
+/* Debugfs for device */
+struct hns_roce_dev_debugfs {
+       struct dentry *root;
+};
+
+struct hns_roce_dev;
+
+void hns_roce_init_debugfs(void);
+void hns_roce_cleanup_debugfs(void);
+void hns_roce_register_debugfs(struct hns_roce_dev *hr_dev);
+void hns_roce_unregister_debugfs(struct hns_roce_dev *hr_dev);
+
+#endif
index 1627f3b0ef28ba44e1840491ef87eadb2dec3020..a847cdfb4ad681a5a77771f8d661b5c8d01f92c6 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <rdma/ib_verbs.h>
 #include <rdma/hns-abi.h>
+#include "hns_roce_debugfs.h"
 
 #define PCI_REVISION_ID_HIP08                  0x21
 #define PCI_REVISION_ID_HIP09                  0x30
@@ -979,6 +980,7 @@ struct hns_roce_dev {
        u32 is_vf;
        u32 cong_algo_tmpl_id;
        u64 dwqe_page;
+       struct hns_roce_dev_debugfs dbgfs;
 };
 
 static inline struct hns_roce_dev *to_hr_dev(struct ib_device *ib_dev)
index c01307be06ab1f1f10d02c7d715ef7a75818960b..8a5432bb0e85b468a5a1265cf032d7b317635b06 100644 (file)
@@ -6958,12 +6958,14 @@ static struct hnae3_client hns_roce_hw_v2_client = {
 
 static int __init hns_roce_hw_v2_init(void)
 {
+       hns_roce_init_debugfs();
        return hnae3_register_client(&hns_roce_hw_v2_client);
 }
 
 static void __exit hns_roce_hw_v2_exit(void)
 {
        hnae3_unregister_client(&hns_roce_hw_v2_client);
+       hns_roce_cleanup_debugfs();
 }
 
 module_init(hns_roce_hw_v2_init);
index a4a10a4e1aab119a870ff132a43b0862addc2120..c9f93ba522c9024c0e336de7a23d510a861ab4e2 100644 (file)
@@ -1079,6 +1079,8 @@ int hns_roce_init(struct hns_roce_dev *hr_dev)
        if (ret)
                goto error_failed_register_device;
 
+       hns_roce_register_debugfs(hr_dev);
+
        return 0;
 
 error_failed_register_device:
@@ -1108,6 +1110,7 @@ error_failed_cmd_init:
 
 void hns_roce_exit(struct hns_roce_dev *hr_dev)
 {
+       hns_roce_unregister_debugfs(hr_dev);
        hns_roce_unregister_device(hr_dev);
 
        if (hr_dev->hw->hw_exit)