Skip to content

Commit 7a2210a

Browse files
MarkZhang81rleon
authored andcommitted
RDMA/mlx5: Support per-plane port IB counters by querying PPCNT register
Supports per-plane port counters by querying PPCNT register with the "extended port counters" group, as the query_vport_counter command doesn't support plane ports. Signed-off-by: Mark Zhang <[email protected]> Link: https://lore.kernel.org/r/06ffb582d67159b7def4654c8272d3d6e8bd2f2f.1718553901.git.leon@kernel.org Signed-off-by: Leon Romanovsky <[email protected]>
1 parent c6b6677 commit 7a2210a

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

drivers/infiniband/hw/mlx5/mad.c

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,39 @@ static void pma_cnt_assign(struct ib_pma_portcounters *pma_cnt,
147147
vl_15_dropped);
148148
}
149149

150-
static int query_ib_ppcnt(struct mlx5_core_dev *dev, u8 port_num, void *out,
151-
size_t sz)
150+
static void pma_cnt_ext_assign_ppcnt(struct ib_pma_portcounters_ext *cnt_ext,
151+
void *out)
152+
{
153+
void *out_pma = MLX5_ADDR_OF(ppcnt_reg, out,
154+
counter_set);
155+
156+
#define MLX5_GET_EXT_CNTR(counter_name) \
157+
MLX5_GET64(ib_ext_port_cntrs_grp_data_layout, \
158+
out_pma, counter_name##_high)
159+
160+
cnt_ext->port_xmit_data =
161+
cpu_to_be64(MLX5_GET_EXT_CNTR(port_xmit_data) >> 2);
162+
cnt_ext->port_rcv_data =
163+
cpu_to_be64(MLX5_GET_EXT_CNTR(port_rcv_data) >> 2);
164+
165+
cnt_ext->port_xmit_packets =
166+
cpu_to_be64(MLX5_GET_EXT_CNTR(port_xmit_pkts));
167+
cnt_ext->port_rcv_packets =
168+
cpu_to_be64(MLX5_GET_EXT_CNTR(port_rcv_pkts));
169+
170+
cnt_ext->port_unicast_xmit_packets =
171+
cpu_to_be64(MLX5_GET_EXT_CNTR(port_unicast_xmit_pkts));
172+
cnt_ext->port_unicast_rcv_packets =
173+
cpu_to_be64(MLX5_GET_EXT_CNTR(port_unicast_rcv_pkts));
174+
175+
cnt_ext->port_multicast_xmit_packets =
176+
cpu_to_be64(MLX5_GET_EXT_CNTR(port_multicast_xmit_pkts));
177+
cnt_ext->port_multicast_rcv_packets =
178+
cpu_to_be64(MLX5_GET_EXT_CNTR(port_multicast_rcv_pkts));
179+
}
180+
181+
static int query_ib_ppcnt(struct mlx5_core_dev *dev, u8 port_num, u8 plane_num,
182+
void *out, size_t sz, bool ext)
152183
{
153184
u32 *in;
154185
int err;
@@ -160,8 +191,14 @@ static int query_ib_ppcnt(struct mlx5_core_dev *dev, u8 port_num, void *out,
160191
}
161192

162193
MLX5_SET(ppcnt_reg, in, local_port, port_num);
163-
164-
MLX5_SET(ppcnt_reg, in, grp, MLX5_INFINIBAND_PORT_COUNTERS_GROUP);
194+
MLX5_SET(ppcnt_reg, in, plane_ind, plane_num);
195+
196+
if (ext)
197+
MLX5_SET(ppcnt_reg, in, grp,
198+
MLX5_INFINIBAND_EXTENDED_PORT_COUNTERS_GROUP);
199+
else
200+
MLX5_SET(ppcnt_reg, in, grp,
201+
MLX5_INFINIBAND_PORT_COUNTERS_GROUP);
165202
err = mlx5_core_access_reg(dev, in, sz, out,
166203
sz, MLX5_REG_PPCNT, 0, 0);
167204

@@ -189,7 +226,8 @@ static int process_pma_cmd(struct mlx5_ib_dev *dev, u32 port_num,
189226
mdev_port_num = 1;
190227
}
191228
if (MLX5_CAP_GEN(dev->mdev, num_ports) == 1 &&
192-
!mlx5_core_mp_enabled(mdev)) {
229+
!mlx5_core_mp_enabled(mdev) &&
230+
dev->ib_dev.type != RDMA_DEVICE_TYPE_SMI) {
193231
/* set local port to one for Function-Per-Port HCA. */
194232
mdev = dev->mdev;
195233
mdev_port_num = 1;
@@ -208,18 +246,27 @@ static int process_pma_cmd(struct mlx5_ib_dev *dev, u32 port_num,
208246
if (in_mad->mad_hdr.attr_id == IB_PMA_PORT_COUNTERS_EXT) {
209247
struct ib_pma_portcounters_ext *pma_cnt_ext =
210248
(struct ib_pma_portcounters_ext *)(out_mad->data + 40);
211-
int sz = MLX5_ST_SZ_BYTES(query_vport_counter_out);
249+
int sz = max(MLX5_ST_SZ_BYTES(query_vport_counter_out),
250+
MLX5_ST_SZ_BYTES(ppcnt_reg));
212251

213252
out_cnt = kvzalloc(sz, GFP_KERNEL);
214253
if (!out_cnt) {
215254
err = IB_MAD_RESULT_FAILURE;
216255
goto done;
217256
}
218257

219-
err = mlx5_core_query_vport_counter(mdev, 0, 0, mdev_port_num,
220-
out_cnt);
221-
if (!err)
222-
pma_cnt_ext_assign(pma_cnt_ext, out_cnt);
258+
if (dev->ib_dev.type == RDMA_DEVICE_TYPE_SMI) {
259+
err = query_ib_ppcnt(mdev, mdev_port_num,
260+
port_num, out_cnt, sz, 1);
261+
if (!err)
262+
pma_cnt_ext_assign_ppcnt(pma_cnt_ext, out_cnt);
263+
} else {
264+
err = mlx5_core_query_vport_counter(mdev, 0, 0,
265+
mdev_port_num,
266+
out_cnt);
267+
if (!err)
268+
pma_cnt_ext_assign(pma_cnt_ext, out_cnt);
269+
}
223270
} else {
224271
struct ib_pma_portcounters *pma_cnt =
225272
(struct ib_pma_portcounters *)(out_mad->data + 40);
@@ -231,7 +278,7 @@ static int process_pma_cmd(struct mlx5_ib_dev *dev, u32 port_num,
231278
goto done;
232279
}
233280

234-
err = query_ib_ppcnt(mdev, mdev_port_num, out_cnt, sz);
281+
err = query_ib_ppcnt(mdev, mdev_port_num, 0, out_cnt, sz, 0);
235282
if (!err)
236283
pma_cnt_assign(pma_cnt, out_cnt);
237284
}

include/linux/mlx5/device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,7 @@ enum {
14661466
MLX5_PER_TRAFFIC_CLASS_CONGESTION_GROUP = 0x13,
14671467
MLX5_PHYSICAL_LAYER_STATISTICAL_GROUP = 0x16,
14681468
MLX5_INFINIBAND_PORT_COUNTERS_GROUP = 0x20,
1469+
MLX5_INFINIBAND_EXTENDED_PORT_COUNTERS_GROUP = 0x21,
14691470
};
14701471

14711472
enum {

0 commit comments

Comments
 (0)