IB/mlx5: Allocate the per-port Q counter shared when DEVX is supported
authorYishai Hadas <yishaih@mellanox.com>
Sun, 9 Dec 2018 10:52:36 +0000 (12:52 +0200)
committerJason Gunthorpe <jgg@mellanox.com>
Fri, 21 Dec 2018 19:15:07 +0000 (12:15 -0700)
The per-port Q counter is some kernel resource and as such may be used by
few UID(s) upon DEVX usage.

To enable using it for QP/RQ when DEVX context is used need to allocate it
with a sharing mode indication to let firmware allows its usage.

The UID = 0xffff was chosen to mark it.

Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/mlx5/cmd.c
drivers/infiniband/hw/mlx5/cmd.h
drivers/infiniband/hw/mlx5/main.c

index 59d569c6a13a840f5d6f1c4ebfedd00ae2c0891f..356bccc715ee6ec7fda48e3b102ecdd8c8f5167a 100644 (file)
@@ -328,3 +328,20 @@ int mlx5_cmd_xrcd_dealloc(struct mlx5_core_dev *dev, u32 xrcdn, u16 uid)
        MLX5_SET(dealloc_xrcd_in, in, uid, uid);
        return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
 }
+
+int mlx5_cmd_alloc_q_counter(struct mlx5_core_dev *dev, u16 *counter_id,
+                            u16 uid)
+{
+       u32 in[MLX5_ST_SZ_DW(alloc_q_counter_in)]   = {0};
+       u32 out[MLX5_ST_SZ_DW(alloc_q_counter_out)] = {0};
+       int err;
+
+       MLX5_SET(alloc_q_counter_in, in, opcode, MLX5_CMD_OP_ALLOC_Q_COUNTER);
+       MLX5_SET(alloc_q_counter_in, in, uid, uid);
+
+       err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
+       if (!err)
+               *counter_id = MLX5_GET(alloc_q_counter_out, out,
+                                      counter_set_id);
+       return err;
+}
index c03c56455534cc48b46ec0748a87155689320774..1e76dc67a369e973c182f5efaf61ab0944a4bbb7 100644 (file)
@@ -61,4 +61,6 @@ int mlx5_cmd_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid,
                        u32 qpn, u16 uid);
 int mlx5_cmd_xrcd_alloc(struct mlx5_core_dev *dev, u32 *xrcdn, u16 uid);
 int mlx5_cmd_xrcd_dealloc(struct mlx5_core_dev *dev, u32 xrcdn, u16 uid);
+int mlx5_cmd_alloc_q_counter(struct mlx5_core_dev *dev, u16 *counter_id,
+                            u16 uid);
 #endif /* MLX5_IB_CMD_H */
index 75edb080435851eeee93d1181d7c10d5227d4ac9..a57183413e8b39b05b4171ae1a51b9c3ba2cf2bc 100644 (file)
@@ -5115,6 +5115,9 @@ static int mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev)
 {
        int err = 0;
        int i;
+       bool is_shared;
+
+       is_shared = MLX5_CAP_GEN(dev->mdev, log_max_uctx) != 0;
 
        for (i = 0; i < dev->num_ports; i++) {
                err = __mlx5_ib_alloc_counters(dev, &dev->port[i].cnts);
@@ -5124,8 +5127,10 @@ static int mlx5_ib_alloc_counters(struct mlx5_ib_dev *dev)
                mlx5_ib_fill_counters(dev, dev->port[i].cnts.names,
                                      dev->port[i].cnts.offsets);
 
-               err = mlx5_core_alloc_q_counter(dev->mdev,
-                                               &dev->port[i].cnts.set_id);
+               err = mlx5_cmd_alloc_q_counter(dev->mdev,
+                                              &dev->port[i].cnts.set_id,
+                                              is_shared ?
+                                              MLX5_SHARED_RESOURCE_UID : 0);
                if (err) {
                        mlx5_ib_warn(dev,
                                     "couldn't allocate queue counter for port %d, err %d\n",