1 // SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
3 * Copyright (c) 2024, Broadcom. All rights reserved. The term
4 * Broadcom refers to Broadcom Limited and/or its subsidiaries.
6 * Description: Debugfs component of the bnxt_re driver
9 #include <linux/debugfs.h>
10 #include <linux/pci.h>
11 #include <rdma/ib_addr.h>
15 #include "qplib_res.h"
18 #include "qplib_rcfw.h"
23 static struct dentry *bnxt_re_debugfs_root;
25 static inline const char *bnxt_re_qp_state_str(u8 state)
28 case CMDQ_MODIFY_QP_NEW_STATE_RESET:
30 case CMDQ_MODIFY_QP_NEW_STATE_INIT:
32 case CMDQ_MODIFY_QP_NEW_STATE_RTR:
34 case CMDQ_MODIFY_QP_NEW_STATE_RTS:
36 case CMDQ_MODIFY_QP_NEW_STATE_SQE:
38 case CMDQ_MODIFY_QP_NEW_STATE_SQD:
40 case CMDQ_MODIFY_QP_NEW_STATE_ERR:
43 return "Invalid QP state";
47 static inline const char *bnxt_re_qp_type_str(u8 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";
59 static ssize_t qp_info_read(struct file *filep,
61 size_t count, loff_t *ppos)
63 struct bnxt_re_qp *qp = filep->private_data;
70 buf = kasprintf(GFP_KERNEL,
78 bnxt_re_qp_type_str(qp->qplib_qp.type),
79 bnxt_re_qp_state_str(qp->qplib_qp.state),
82 qp->qplib_qp.dest_qpn);
85 if (count < strlen(buf)) {
89 len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
94 static const struct file_operations debugfs_qp_fops = {
100 void bnxt_re_debug_add_qpinfo(struct bnxt_re_dev *rdev, struct bnxt_re_qp *qp)
104 sprintf(resn, "0x%x", qp->qplib_qp.id);
105 qp->dentry = debugfs_create_file(resn, 0400, rdev->qp_debugfs, qp, &debugfs_qp_fops);
108 void bnxt_re_debug_rem_qpinfo(struct bnxt_re_dev *rdev, struct bnxt_re_qp *qp)
110 debugfs_remove(qp->dentry);
113 void bnxt_re_debugfs_add_pdev(struct bnxt_re_dev *rdev)
115 struct pci_dev *pdev = rdev->en_dev->pdev;
117 rdev->dbg_root = debugfs_create_dir(dev_name(&pdev->dev), bnxt_re_debugfs_root);
119 rdev->qp_debugfs = debugfs_create_dir("QPs", rdev->dbg_root);
122 void bnxt_re_debugfs_rem_pdev(struct bnxt_re_dev *rdev)
124 debugfs_remove_recursive(rdev->qp_debugfs);
126 debugfs_remove_recursive(rdev->dbg_root);
127 rdev->dbg_root = NULL;
130 void bnxt_re_register_debugfs(void)
132 bnxt_re_debugfs_root = debugfs_create_dir("bnxt_re", NULL);
135 void bnxt_re_unregister_debugfs(void)
137 debugfs_remove(bnxt_re_debugfs_root);