Skip to content

Commit c377913

Browse files
ogerlitzrolandd
authored andcommitted
IB/mlx4: Support PMA counters for IBoE
Use the per port counter attached to all QPs created on that port to implement port level packets/bytes performance counters a la IB. Derived from a patch by Eli Cohen <[email protected]> Signed-off-by: Or Gerlitz <[email protected]> Signed-off-by: Roland Dreier <[email protected]>
1 parent cfcde11 commit c377913

File tree

1 file changed

+67
-1
lines changed
  • drivers/infiniband/hw/mlx4

1 file changed

+67
-1
lines changed

drivers/infiniband/hw/mlx4/mad.c

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include <linux/mlx4/cmd.h>
3737
#include <linux/gfp.h>
38+
#include <rdma/ib_pma.h>
3839

3940
#include "mlx4_ib.h"
4041

@@ -232,7 +233,7 @@ static void forward_trap(struct mlx4_ib_dev *dev, u8 port_num, struct ib_mad *ma
232233
}
233234
}
234235

235-
int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
236+
static int ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
236237
struct ib_wc *in_wc, struct ib_grh *in_grh,
237238
struct ib_mad *in_mad, struct ib_mad *out_mad)
238239
{
@@ -302,6 +303,71 @@ int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
302303
return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
303304
}
304305

306+
static void edit_counter(struct mlx4_counter *cnt,
307+
struct ib_pma_portcounters *pma_cnt)
308+
{
309+
pma_cnt->port_xmit_data = cpu_to_be32((be64_to_cpu(cnt->tx_bytes)>>2));
310+
pma_cnt->port_rcv_data = cpu_to_be32((be64_to_cpu(cnt->rx_bytes)>>2));
311+
pma_cnt->port_xmit_packets = cpu_to_be32(be64_to_cpu(cnt->tx_frames));
312+
pma_cnt->port_rcv_packets = cpu_to_be32(be64_to_cpu(cnt->rx_frames));
313+
}
314+
315+
static int iboe_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
316+
struct ib_wc *in_wc, struct ib_grh *in_grh,
317+
struct ib_mad *in_mad, struct ib_mad *out_mad)
318+
{
319+
struct mlx4_cmd_mailbox *mailbox;
320+
struct mlx4_ib_dev *dev = to_mdev(ibdev);
321+
int err;
322+
u32 inmod = dev->counters[port_num - 1] & 0xffff;
323+
u8 mode;
324+
325+
if (in_mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_PERF_MGMT)
326+
return -EINVAL;
327+
328+
mailbox = mlx4_alloc_cmd_mailbox(dev->dev);
329+
if (IS_ERR(mailbox))
330+
return IB_MAD_RESULT_FAILURE;
331+
332+
err = mlx4_cmd_box(dev->dev, 0, mailbox->dma, inmod, 0,
333+
MLX4_CMD_QUERY_IF_STAT, MLX4_CMD_TIME_CLASS_C);
334+
if (err)
335+
err = IB_MAD_RESULT_FAILURE;
336+
else {
337+
memset(out_mad->data, 0, sizeof out_mad->data);
338+
mode = ((struct mlx4_counter *)mailbox->buf)->counter_mode;
339+
switch (mode & 0xf) {
340+
case 0:
341+
edit_counter(mailbox->buf,
342+
(void *)(out_mad->data + 40));
343+
err = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
344+
break;
345+
default:
346+
err = IB_MAD_RESULT_FAILURE;
347+
}
348+
}
349+
350+
mlx4_free_cmd_mailbox(dev->dev, mailbox);
351+
352+
return err;
353+
}
354+
355+
int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
356+
struct ib_wc *in_wc, struct ib_grh *in_grh,
357+
struct ib_mad *in_mad, struct ib_mad *out_mad)
358+
{
359+
switch (rdma_port_get_link_layer(ibdev, port_num)) {
360+
case IB_LINK_LAYER_INFINIBAND:
361+
return ib_process_mad(ibdev, mad_flags, port_num, in_wc,
362+
in_grh, in_mad, out_mad);
363+
case IB_LINK_LAYER_ETHERNET:
364+
return iboe_process_mad(ibdev, mad_flags, port_num, in_wc,
365+
in_grh, in_mad, out_mad);
366+
default:
367+
return -EINVAL;
368+
}
369+
}
370+
305371
static void send_handler(struct ib_mad_agent *agent,
306372
struct ib_mad_send_wc *mad_send_wc)
307373
{

0 commit comments

Comments
 (0)