net/mlx5: Replace hand written QP context struct with automatic getters
authorLeon Romanovsky <leonro@mellanox.com>
Mon, 6 Apr 2020 12:53:06 +0000 (15:53 +0300)
committerLeon Romanovsky <leonro@mellanox.com>
Sun, 19 Apr 2020 12:53:19 +0000 (15:53 +0300)
By changing debugfs to not use any QP related API, convert the debugfs
code to use MLX5_GET() directly to access QP context instead of hand
written struct.

Reviewed-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/debugfs.c

index 04854e5..d40c3d5 100644 (file)
@@ -202,42 +202,37 @@ void mlx5_cq_debugfs_cleanup(struct mlx5_core_dev *dev)
 static u64 qp_read_field(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp,
                         int index, int *is_str)
 {
-       int outlen = MLX5_ST_SZ_BYTES(query_qp_out);
-       struct mlx5_qp_context *ctx;
+       u32 out[MLX5_ST_SZ_BYTES(query_qp_out)] = {};
+       u32 in[MLX5_ST_SZ_DW(query_qp_in)] = {};
        u64 param = 0;
-       u32 *out;
+       int state;
+       u32 *qpc;
        int err;
-       int no_sq;
 
-       out = kzalloc(outlen, GFP_KERNEL);
-       if (!out)
-               return param;
-
-       err = mlx5_core_qp_query(dev, qp, out, outlen);
-       if (err) {
-               mlx5_core_warn(dev, "failed to query qp err=%d\n", err);
-               goto out;
-       }
+       MLX5_SET(query_qp_in, in, opcode, MLX5_CMD_OP_QUERY_QP);
+       MLX5_SET(query_qp_in, in, qpn, qp->qpn);
+       err = mlx5_cmd_exec_inout(dev, query_qp, in, out);
+       if (err)
+               return 0;
 
        *is_str = 0;
 
-       /* FIXME: use MLX5_GET rather than mlx5_qp_context manual struct */
-       ctx = (struct mlx5_qp_context *)MLX5_ADDR_OF(query_qp_out, out, qpc);
-
+       qpc = MLX5_ADDR_OF(query_qp_out, out, qpc);
        switch (index) {
        case QP_PID:
                param = qp->pid;
                break;
        case QP_STATE:
-               param = (unsigned long)mlx5_qp_state_str(be32_to_cpu(ctx->flags) >> 28);
+               state = MLX5_GET(qpc, qpc, state);
+               param = (unsigned long)mlx5_qp_state_str(state);
                *is_str = 1;
                break;
        case QP_XPORT:
-               param = (unsigned long)mlx5_qp_type_str((be32_to_cpu(ctx->flags) >> 16) & 0xff);
+               param = (unsigned long)mlx5_qp_type_str(MLX5_GET(qpc, qpc, st));
                *is_str = 1;
                break;
        case QP_MTU:
-               switch (ctx->mtu_msgmax >> 5) {
+               switch (MLX5_GET(qpc, qpc, mtu)) {
                case IB_MTU_256:
                        param = 256;
                        break;
@@ -258,29 +253,23 @@ static u64 qp_read_field(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp,
                }
                break;
        case QP_N_RECV:
-               param = 1 << ((ctx->rq_size_stride >> 3) & 0xf);
+               param = 1 << MLX5_GET(qpc, qpc, log_rq_size);
                break;
        case QP_RECV_SZ:
-               param = 1 << ((ctx->rq_size_stride & 7) + 4);
+               param = 1 << (MLX5_GET(qpc, qpc, log_rq_stride) + 4);
                break;
        case QP_N_SEND:
-               no_sq = be16_to_cpu(ctx->sq_crq_size) >> 15;
-               if (!no_sq)
-                       param = 1 << (be16_to_cpu(ctx->sq_crq_size) >> 11);
-               else
-                       param = 0;
+               if (!MLX5_GET(qpc, qpc, no_sq))
+                       param = 1 << MLX5_GET(qpc, qpc, log_sq_size);
                break;
        case QP_LOG_PG_SZ:
-               param = (be32_to_cpu(ctx->log_pg_sz_remote_qpn) >> 24) & 0x1f;
-               param += 12;
+               param = MLX5_GET(qpc, qpc, log_page_size) + 12;
                break;
        case QP_RQPN:
-               param = be32_to_cpu(ctx->log_pg_sz_remote_qpn) & 0xffffff;
+               param = MLX5_GET(qpc, qpc, remote_qpn);
                break;
        }
 
-out:
-       kfree(out);
        return param;
 }