diff mbox series

[rdma-next,09/10] RDMA/mlx5: Add get_op_stats() support

Message ID 20210818112428.209111-10-markzhang@nvidia.com (mailing list archive)
State Not Applicable
Headers show
Series Optional counter statistics support | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Mark Zhang Aug. 18, 2021, 11:24 a.m. UTC
From: Aharon Landau <aharonl@nvidia.com>

Add support for ib callback alloc_op_port_stats(), to get optional
counter statistics.

Signed-off-by: Aharon Landau <aharonl@nvidia.com>
Signed-off-by: Mark Zhang <markzhang@nvidia.com>
---
 drivers/infiniband/hw/mlx5/counters.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mlx5/counters.c b/drivers/infiniband/hw/mlx5/counters.c
index 5bd1e5a5dffa..5e0cc5af9761 100644
--- a/drivers/infiniband/hw/mlx5/counters.c
+++ b/drivers/infiniband/hw/mlx5/counters.c
@@ -797,12 +797,35 @@  static int mlx5_ib_remove_op_stat(struct ib_device *device, u32 port, int type)
 	return 0;
 }
 
+static int mlx5_ib_get_op_stats(struct ib_device *device, u32 port,
+				struct rdma_op_stats *stats)
+{
+	struct mlx5_ib_dev *dev = to_mdev(device);
+	struct mlx5_ib_op_fc *opfcs = dev->port[port - 1].cnts.opfcs;
+	u64 packets, bytes;
+	int i, ret, type;
+
+	for (i = 0; i < stats->num_opcounters; i++) {
+		type = stats->opcounters[i].type;
+		if (opfcs[type].fc) {
+			ret = mlx5_fc_query(dev->mdev, opfcs[type].fc,
+					    &packets, &bytes);
+			if (ret)
+				return ret;
+			stats->opcounters[i].value = packets;
+		}
+	}
+
+	return 0;
+}
+
 static const struct ib_device_ops stats_ops = {
 	.alloc_hw_port_stats = mlx5_ib_alloc_hw_port_stats,
 	.alloc_op_port_stats = mlx5_ib_alloc_op_port_stats,
 	.add_op_stat = mlx5_ib_add_op_stat,
 	.remove_op_stat = mlx5_ib_remove_op_stat,
 	.get_hw_stats = mlx5_ib_get_hw_stats,
+	.get_op_stats = mlx5_ib_get_op_stats,
 	.counter_bind_qp = mlx5_ib_counter_bind_qp,
 	.counter_unbind_qp = mlx5_ib_counter_unbind_qp,
 	.counter_dealloc = mlx5_ib_counter_dealloc,