Skip to content

Commit d7d5476

Browse files
Kalesh APrleon
authored andcommitted
RDMA/bnxt_re: Add debugfs hook in the driver
Adding support for a per device debugfs folder for exporting some of the device specific debug information. Added support to get QP info for now. The same folder can be used to export other debug features in future. Signed-off-by: Saravanan Vajravel <[email protected]> Signed-off-by: Kalesh AP <[email protected]> Signed-off-by: Selvin Xavier <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent e4bcf8e commit d7d5476

File tree

7 files changed

+180
-2
lines changed

7 files changed

+180
-2
lines changed

drivers/infiniband/hw/bnxt_re/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ ccflags-y := -I $(srctree)/drivers/net/ethernet/broadcom/bnxt
44
obj-$(CONFIG_INFINIBAND_BNXT_RE) += bnxt_re.o
55
bnxt_re-y := main.o ib_verbs.o \
66
qplib_res.o qplib_rcfw.o \
7-
qplib_sp.o qplib_fp.o hw_counters.o
7+
qplib_sp.o qplib_fp.o hw_counters.o \
8+
debugfs.o

drivers/infiniband/hw/bnxt_re/bnxt_re.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ struct bnxt_re_dev {
221221
struct delayed_work dbq_pacing_work;
222222
DECLARE_HASHTABLE(cq_hash, MAX_CQ_HASH_BITS);
223223
DECLARE_HASHTABLE(srq_hash, MAX_SRQ_HASH_BITS);
224+
struct dentry *dbg_root;
225+
struct dentry *qp_debugfs;
224226
};
225227

226228
#define to_bnxt_re_dev(ptr, member) \
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
2+
/*
3+
* Copyright (c) 2024, Broadcom. All rights reserved. The term
4+
* Broadcom refers to Broadcom Limited and/or its subsidiaries.
5+
*
6+
* Description: Debugfs component of the bnxt_re driver
7+
*/
8+
9+
#include <linux/debugfs.h>
10+
#include <linux/pci.h>
11+
#include <rdma/ib_addr.h>
12+
13+
#include "bnxt_ulp.h"
14+
#include "roce_hsi.h"
15+
#include "qplib_res.h"
16+
#include "qplib_sp.h"
17+
#include "qplib_fp.h"
18+
#include "qplib_rcfw.h"
19+
#include "bnxt_re.h"
20+
#include "ib_verbs.h"
21+
#include "debugfs.h"
22+
23+
static struct dentry *bnxt_re_debugfs_root;
24+
25+
static inline const char *bnxt_re_qp_state_str(u8 state)
26+
{
27+
switch (state) {
28+
case CMDQ_MODIFY_QP_NEW_STATE_RESET:
29+
return "RST";
30+
case CMDQ_MODIFY_QP_NEW_STATE_INIT:
31+
return "INIT";
32+
case CMDQ_MODIFY_QP_NEW_STATE_RTR:
33+
return "RTR";
34+
case CMDQ_MODIFY_QP_NEW_STATE_RTS:
35+
return "RTS";
36+
case CMDQ_MODIFY_QP_NEW_STATE_SQE:
37+
return "SQER";
38+
case CMDQ_MODIFY_QP_NEW_STATE_SQD:
39+
return "SQD";
40+
case CMDQ_MODIFY_QP_NEW_STATE_ERR:
41+
return "ERR";
42+
default:
43+
return "Invalid QP state";
44+
}
45+
}
46+
47+
static inline const char *bnxt_re_qp_type_str(u8 type)
48+
{
49+
switch (type) {
50+
case CMDQ_CREATE_QP1_TYPE_GSI: return "QP1";
51+
case CMDQ_CREATE_QP_TYPE_GSI: return "QP1";
52+
case CMDQ_CREATE_QP_TYPE_RC: return "RC";
53+
case CMDQ_CREATE_QP_TYPE_UD: return "UD";
54+
case CMDQ_CREATE_QP_TYPE_RAW_ETHERTYPE: return "RAW_ETHERTYPE";
55+
default: return "Invalid transport type";
56+
}
57+
}
58+
59+
static ssize_t qp_info_read(struct file *filep,
60+
char __user *buffer,
61+
size_t count, loff_t *ppos)
62+
{
63+
struct bnxt_re_qp *qp = filep->private_data;
64+
char *buf;
65+
int len;
66+
67+
if (*ppos)
68+
return 0;
69+
70+
buf = kasprintf(GFP_KERNEL,
71+
"QPN\t\t: %d\n"
72+
"transport\t: %s\n"
73+
"state\t\t: %s\n"
74+
"mtu\t\t: %d\n"
75+
"timeout\t\t: %d\n"
76+
"remote QPN\t: %d\n",
77+
qp->qplib_qp.id,
78+
bnxt_re_qp_type_str(qp->qplib_qp.type),
79+
bnxt_re_qp_state_str(qp->qplib_qp.state),
80+
qp->qplib_qp.mtu,
81+
qp->qplib_qp.timeout,
82+
qp->qplib_qp.dest_qpn);
83+
if (!buf)
84+
return -ENOMEM;
85+
if (count < strlen(buf)) {
86+
kfree(buf);
87+
return -ENOSPC;
88+
}
89+
len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90+
kfree(buf);
91+
return len;
92+
}
93+
94+
static const struct file_operations debugfs_qp_fops = {
95+
.owner = THIS_MODULE,
96+
.open = simple_open,
97+
.read = qp_info_read,
98+
};
99+
100+
void bnxt_re_debug_add_qpinfo(struct bnxt_re_dev *rdev, struct bnxt_re_qp *qp)
101+
{
102+
char resn[32];
103+
104+
sprintf(resn, "0x%x", qp->qplib_qp.id);
105+
qp->dentry = debugfs_create_file(resn, 0400, rdev->qp_debugfs, qp, &debugfs_qp_fops);
106+
}
107+
108+
void bnxt_re_debug_rem_qpinfo(struct bnxt_re_dev *rdev, struct bnxt_re_qp *qp)
109+
{
110+
debugfs_remove(qp->dentry);
111+
}
112+
113+
void bnxt_re_debugfs_add_pdev(struct bnxt_re_dev *rdev)
114+
{
115+
struct pci_dev *pdev = rdev->en_dev->pdev;
116+
117+
rdev->dbg_root = debugfs_create_dir(dev_name(&pdev->dev), bnxt_re_debugfs_root);
118+
119+
rdev->qp_debugfs = debugfs_create_dir("QPs", rdev->dbg_root);
120+
}
121+
122+
void bnxt_re_debugfs_rem_pdev(struct bnxt_re_dev *rdev)
123+
{
124+
debugfs_remove_recursive(rdev->qp_debugfs);
125+
126+
debugfs_remove_recursive(rdev->dbg_root);
127+
rdev->dbg_root = NULL;
128+
}
129+
130+
void bnxt_re_register_debugfs(void)
131+
{
132+
bnxt_re_debugfs_root = debugfs_create_dir("bnxt_re", NULL);
133+
}
134+
135+
void bnxt_re_unregister_debugfs(void)
136+
{
137+
debugfs_remove(bnxt_re_debugfs_root);
138+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
2+
/*
3+
* Copyright (c) 2024, Broadcom. All rights reserved. The term
4+
* Broadcom refers to Broadcom Limited and/or its subsidiaries.
5+
*
6+
* Description: Debugfs header
7+
*/
8+
9+
#ifndef __BNXT_RE_DEBUGFS__
10+
#define __BNXT_RE_DEBUGFS__
11+
12+
void bnxt_re_debug_add_qpinfo(struct bnxt_re_dev *rdev, struct bnxt_re_qp *qp);
13+
void bnxt_re_debug_rem_qpinfo(struct bnxt_re_dev *rdev, struct bnxt_re_qp *qp);
14+
15+
void bnxt_re_debugfs_add_pdev(struct bnxt_re_dev *rdev);
16+
void bnxt_re_debugfs_rem_pdev(struct bnxt_re_dev *rdev);
17+
18+
void bnxt_re_register_debugfs(void);
19+
void bnxt_re_unregister_debugfs(void);
20+
21+
#endif

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
#include "bnxt_re.h"
6464
#include "ib_verbs.h"
65+
#include "debugfs.h"
6566

6667
#include <rdma/uverbs_types.h>
6768
#include <rdma/uverbs_std_types.h>
@@ -997,6 +998,8 @@ int bnxt_re_destroy_qp(struct ib_qp *ib_qp, struct ib_udata *udata)
997998
else if (qp->qplib_qp.type == CMDQ_CREATE_QP_TYPE_UD)
998999
atomic_dec(&rdev->stats.res.ud_qp_count);
9991000

1001+
bnxt_re_debug_rem_qpinfo(rdev, qp);
1002+
10001003
ib_umem_release(qp->rumem);
10011004
ib_umem_release(qp->sumem);
10021005

@@ -1676,6 +1679,7 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr,
16761679
if (active_qps > rdev->stats.res.ud_qp_watermark)
16771680
rdev->stats.res.ud_qp_watermark = active_qps;
16781681
}
1682+
bnxt_re_debug_add_qpinfo(rdev, qp);
16791683

16801684
return 0;
16811685
qp_destroy:

drivers/infiniband/hw/bnxt_re/ib_verbs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct bnxt_re_qp {
9595
struct ib_ud_header qp1_hdr;
9696
struct bnxt_re_cq *scq;
9797
struct bnxt_re_cq *rcq;
98+
struct dentry *dentry;
9899
};
99100

100101
struct bnxt_re_cq {

drivers/infiniband/hw/bnxt_re/main.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include <rdma/bnxt_re-abi.h>
6868
#include "bnxt.h"
6969
#include "hw_counters.h"
70+
#include "debugfs.h"
7071

7172
static char version[] =
7273
BNXT_RE_DESC "\n";
@@ -1863,6 +1864,8 @@ static void bnxt_re_dev_uninit(struct bnxt_re_dev *rdev, u8 op_type)
18631864
u8 type;
18641865
int rc;
18651866

1867+
bnxt_re_debugfs_rem_pdev(rdev);
1868+
18661869
if (test_and_clear_bit(BNXT_RE_FLAG_QOS_WORK_REG, &rdev->flags))
18671870
cancel_delayed_work_sync(&rdev->worker);
18681871

@@ -2063,6 +2066,8 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev, u8 op_type)
20632066
if (rdev->chip_ctx->modes.toggle_bits & BNXT_QPLIB_SRQ_TOGGLE_BIT)
20642067
hash_init(rdev->srq_hash);
20652068

2069+
bnxt_re_debugfs_add_pdev(rdev);
2070+
20662071
return 0;
20672072
free_sctx:
20682073
bnxt_re_net_stats_ctx_free(rdev, rdev->qplib_ctx.stats.fw_id);
@@ -2389,18 +2394,24 @@ static int __init bnxt_re_mod_init(void)
23892394
int rc;
23902395

23912396
pr_info("%s: %s", ROCE_DRV_MODULE_NAME, version);
2397+
bnxt_re_register_debugfs();
2398+
23922399
rc = auxiliary_driver_register(&bnxt_re_driver);
23932400
if (rc) {
23942401
pr_err("%s: Failed to register auxiliary driver\n",
23952402
ROCE_DRV_MODULE_NAME);
2396-
return rc;
2403+
goto err_debug;
23972404
}
23982405
return 0;
2406+
err_debug:
2407+
bnxt_re_unregister_debugfs();
2408+
return rc;
23992409
}
24002410

24012411
static void __exit bnxt_re_mod_exit(void)
24022412
{
24032413
auxiliary_driver_unregister(&bnxt_re_driver);
2414+
bnxt_re_unregister_debugfs();
24042415
}
24052416

24062417
module_init(bnxt_re_mod_init);

0 commit comments

Comments
 (0)