Skip to contentSkip to conversation

RDMA/bnxt_re: Support Perf management counters

PATCH Superseded Selvin Xavier 2 participants 2 messages Mar 11, 2025 – Mar 12, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Selvin Xavier

author maintainer
#0 lore raw

PATCH 1/1 RDMA/bnxt_re: Support Perf management counters

From: Preethi G <[email protected]>

Add support for process_mad hook to retrieve the perf management counters. Supports IB_PMA_PORT_COUNTERS and IB_PMA_PORT_COUNTERS_EXT counters. Query the data from HW contexts and FW commands.

---
 drivers/infiniband/hw/bnxt_re/bnxt_re.h     |  4 ++
 drivers/infiniband/hw/bnxt_re/hw_counters.c | 88 +++++++++++++++++++++++++++++
 drivers/infiniband/hw/bnxt_re/ib_verbs.c    | 36 ++++++++++++
 drivers/infiniband/hw/bnxt_re/ib_verbs.h    |  6 ++
 drivers/infiniband/hw/bnxt_re/main.c        |  1 +
 5 files changed, 135 insertions(+)
drivers/infiniband/hw/bnxt_re/bnxt_re.h +4 -0
index b33b04e..8bc0237 100644
@@ -246,6 +246,10 @@ struct bnxt_re_dev {
 #define BNXT_RE_CHECK_RC(x) ((x) && ((x) != -ETIMEDOUT))
 void bnxt_re_pacing_alert(struct bnxt_re_dev *rdev);
 
+int bnxt_re_assign_pma_port_counters(struct bnxt_re_dev *rdev, struct ib_mad *out_mad);
+int bnxt_re_assign_pma_port_ext_counters(struct bnxt_re_dev *rdev,
+					 struct ib_mad *out_mad);
+
 static inline struct device *rdev_to_dev(struct bnxt_re_dev *rdev)
 {
 	if (rdev)
drivers/infiniband/hw/bnxt_re/hw_counters.c +88 -0

100 lines not on this page · raw message

drivers/infiniband/hw/bnxt_re/ib_verbs.c +36 -0
index 2de101d..dc31973 100644
@@ -49,6 +49,7 @@
 #include <rdma/ib_addr.h>
 #include <rdma/ib_mad.h>
 #include <rdma/ib_cache.h>
+#include <rdma/ib_pma.h>
 #include <rdma/uverbs_ioctl.h>
 #include <linux/hashtable.h>
 
@@ -4489,6 +4490,41 @@ void bnxt_re_mmap_free(struct rdma_user_mmap_entry *rdma_entry)
 	kfree(bnxt_entry);
 }
 
+int bnxt_re_process_mad(struct ib_device *ibdev, int mad_flags,
+			u32 port_num, const struct ib_wc *in_wc,
+			const struct ib_grh *in_grh,
+			const struct ib_mad *in_mad, struct ib_mad *out_mad,
+			size_t *out_mad_size, u16 *out_mad_pkey_index)
+{
+	struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
+	struct ib_class_port_info cpi = {};
+	int ret = IB_MAD_RESULT_SUCCESS;
+	int rc = 0;
+
+	if (in_mad->mad_hdr.mgmt_class  != IB_MGMT_CLASS_PERF_MGMT)
+		return ret;
+
+	switch (in_mad->mad_hdr.attr_id) {
+	case IB_PMA_CLASS_PORT_INFO:
+		cpi.capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH;
+		memcpy((out_mad->data + 40), &cpi, sizeof(cpi));
+		break;
+	case IB_PMA_PORT_COUNTERS_EXT:
+		rc = bnxt_re_assign_pma_port_ext_counters(rdev, out_mad);
+		break;
+	case IB_PMA_PORT_COUNTERS:
+		rc = bnxt_re_assign_pma_port_counters(rdev, out_mad);
+		break;
+	default:
+		rc = -EINVAL;
+		break;
+	}
+	if (rc)
+		return IB_MAD_RESULT_FAILURE;
+	ret |= IB_MAD_RESULT_REPLY;
+	return ret;
+}
+
 static int UVERBS_HANDLER(BNXT_RE_METHOD_NOTIFY_DRV)(struct uverbs_attr_bundle *attrs)
 {
 	struct bnxt_re_ucontext *uctx;
drivers/infiniband/hw/bnxt_re/ib_verbs.h +6 -0
index fbb16a4..22c9eb8 100644
@@ -268,6 +268,12 @@ void bnxt_re_dealloc_ucontext(struct ib_ucontext *context);
 int bnxt_re_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
 void bnxt_re_mmap_free(struct rdma_user_mmap_entry *rdma_entry);
 
+int bnxt_re_process_mad(struct ib_device *device, int process_mad_flags,
+			u32 port_num, const struct ib_wc *in_wc,
+			const struct ib_grh *in_grh,
+			const struct ib_mad *in_mad, struct ib_mad *out_mad,
+			size_t *out_mad_size, u16 *out_mad_pkey_index);
+
 static inline u32 __to_ib_port_num(u16 port_id)
 {
 	return (u32)port_id + 1;
drivers/infiniband/hw/bnxt_re/main.c +1 -0
index e9e4da4..59ddb36 100644
@@ -1276,6 +1276,7 @@ static const struct ib_device_ops bnxt_re_dev_ops = {
 	.post_recv = bnxt_re_post_recv,
 	.post_send = bnxt_re_post_send,
 	.post_srq_recv = bnxt_re_post_srq_recv,
+	.process_mad = bnxt_re_process_mad,
 	.query_ah = bnxt_re_query_ah,
 	.query_device = bnxt_re_query_device,
 	.modify_device = bnxt_re_modify_device,
Signature · 1 line
2.5.5
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Selvin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on rdma/for-next]
[also build test WARNING on linus/master v6.14-rc6 next-20250311] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Selvin-Xavier/RDMA-bnxt_re-Support-Perf-management-counters/20250311-144413
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-next
patch link:    https://lore.kernel.org/r/1741674104-5477-1-git-send-email-selvin.xavier%40broadcom.com
patch subject: [PATCH rdma-next] RDMA/bnxt_re: Support Perf management counters
config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20250312/[email protected]/config)
compiler: s390-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250312/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/infiniband/hw/bnxt_re/hw_counters.c: In function 'bnxt_re_assign_pma_port_ext_counters':

>> drivers/infiniband/hw/bnxt_re/hw_counters.c:295:13: warning: variable 'rc' set but not used [-Wunused-but-set-variable]
     295 |         int rc;
         |             ^~
   drivers/infiniband/hw/bnxt_re/hw_counters.c: In function 'bnxt_re_assign_pma_port_counters':
   drivers/infiniband/hw/bnxt_re/hw_counters.c:338:13: warning: variable 'rc' set but not used [-Wunused-but-set-variable]
     338 |         int rc;
         |             ^~

vim +/rc +295 drivers/infiniband/hw/bnxt_re/hw_counters.c

289
290 int bnxt_re_assign_pma_port_ext_counters(struct bnxt_re_dev *rdev, struct ib_mad *out_mad)
291 {
292 struct ib_pma_portcounters_ext *pma_cnt_ext;
293 struct bnxt_qplib_ext_stat *estat = &rdev->stats.rstat.ext_stat;
294 struct ctx_hw_stats *hw_stats = NULL;

 > 295		int rc;

296
297 hw_stats = rdev->qplib_ctx.stats.dma;
298
299 pma_cnt_ext = (void *)(out_mad->data + 40);
300 if (_is_ext_stats_supported(rdev->dev_attr->dev_cap_flags)) {
301 u32 fid = PCI_FUNC(rdev->en_dev->pdev->devfn);
302
303 rc = bnxt_qplib_qext_stat(&rdev->rcfw, fid, estat);
304 }
305
306 pma_cnt_ext = (void *)(out_mad->data + 40);
307 if ((bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx) && rdev->is_virtfn) ||
308 !bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx)) {
309 pma_cnt_ext->port_xmit_data =
310 cpu_to_be64(le64_to_cpu(hw_stats->tx_ucast_bytes) / 4);
311 pma_cnt_ext->port_rcv_data =
312 cpu_to_be64(le64_to_cpu(hw_stats->rx_ucast_bytes) / 4);
313 pma_cnt_ext->port_xmit_packets =
314 cpu_to_be64(le64_to_cpu(hw_stats->tx_ucast_pkts));
315 pma_cnt_ext->port_rcv_packets =
316 cpu_to_be64(le64_to_cpu(hw_stats->rx_ucast_pkts));
317 pma_cnt_ext->port_unicast_rcv_packets =
318 cpu_to_be64(le64_to_cpu(hw_stats->rx_ucast_pkts));
319 pma_cnt_ext->port_unicast_xmit_packets =
320 cpu_to_be64(le64_to_cpu(hw_stats->tx_ucast_pkts));
321
322 } else {
323 pma_cnt_ext->port_rcv_packets = cpu_to_be64(estat->rx_roce_good_pkts);
324 pma_cnt_ext->port_rcv_data = cpu_to_be64(estat->rx_roce_good_bytes / 4);
325 pma_cnt_ext->port_xmit_packets = cpu_to_be64(estat->tx_roce_pkts);
326 pma_cnt_ext->port_xmit_data = cpu_to_be64(estat->tx_roce_bytes / 4);
327 pma_cnt_ext->port_unicast_rcv_packets = cpu_to_be64(estat->rx_roce_good_pkts);
328 pma_cnt_ext->port_unicast_xmit_packets = cpu_to_be64(estat->tx_roce_pkts);
329 }
330 return 0;
331 }
332

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki