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 } 139