[PATCH 10/11] RDMA/cxi: read the NIC telemetry through counters
From: Doug Ledford
Date: Sat Oct 31 2026 - 00:39:26 EST
Implement read_counters_ex() so that user space can read the NIC
telemetry through the COUNTERS object. An item number is the index of
the telemetry item in the core driver's table, so the caller names what
it wants without the driver describing thousands of entries in sysfs.
Items the device does not define read as zero with a zero timestamp.
The values come from the core driver's cxi_telem_read(), which reads
the device BAR directly.
Known limitation, deferred to V2: this patch carries SR-IOV
virtual-function code (VF-to-PF mailbox requests, mailbox opcodes or VF
resource handling) from an older, incomplete version of the Cassini
SR-IOV support. V2 of this series will include the updated SR-IOV
implementation, so issues in the VF paths should be ignored for now.
Signed-off-by: Doug Ledford <doug.ledford@xxxxxxx>
---
drivers/infiniband/hw/cxi/cxiverbs_counters.c | 38 +++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/drivers/infiniband/hw/cxi/cxiverbs_counters.c b/drivers/infiniband/hw/cxi/cxiverbs_counters.c
new file mode 100644
index 000000000000..2ece6568ea7d
--- /dev/null
+++ b/drivers/infiniband/hw/cxi/cxiverbs_counters.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * CXI RDMA telemetry counters, read through the uverbs counters object.
+ * Counter numbers are Cassini telemetry item IDs; user space names them.
+ * Copyright 2026 Hewlett Packard Enterprise Development LP
+ */
+
+#include <rdma/ib_verbs.h>
+
+#include "cxiverbs.h"
+
+int cxiverbs_create_counters(struct ib_counters *counters,
+ struct uverbs_attr_bundle *attrs)
+{
+ return 0;
+}
+
+int cxiverbs_destroy_counters(struct ib_counters *counters)
+{
+ return 0;
+}
+
+/*
+ * Counters are not attached to anything, so the core's attach check does
+ * not apply. With no items, counter N is telemetry item N.
+ */
+int cxiverbs_read_counters_ex(struct ib_counters *counters,
+ struct ib_counters_read_attr *attr,
+ struct uverbs_attr_bundle *attrs)
+{
+ struct cxiverbs_dev *dev = to_cxiverbs_dev(counters->device);
+
+ if (!dev->cdev->is_physfn)
+ return -EOPNOTSUPP;
+
+ return cxi_telem_read(dev->cdev, attr->items, attr->counters_buff,
+ attr->timestamps, attr->ncounters);
+}
--
2.56.0