examples/ip_frag: fix use of ethdev internal device array
[dpdk.git] / drivers / net / mlx5 / mlx5_devx_cmds.c
index a9dff58..e5776c4 100644 (file)
@@ -105,3 +105,47 @@ mlx5_devx_cmd_flow_counter_query(struct mlx5_devx_counter_set *dcs,
        *bytes = MLX5_GET64(traffic_counter, stats, octets);
        return 0;
 }
+
+/**
+ * Query HCA attributes.
+ * Using those attributes we can check on run time if the device
+ * is having the required capabilities.
+ *
+ * @param[in] ctx
+ *   ibv contexts returned from mlx5dv_open_device.
+ * @param[out] attr
+ *   Attributes device values.
+ *
+ * @return
+ *   0 on success, a negative value otherwise.
+ */
+int
+mlx5_devx_cmd_query_hca_attr(struct ibv_context *ctx,
+                            struct mlx5_hca_attr *attr)
+{
+       uint32_t in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {0};
+       uint32_t out[MLX5_ST_SZ_DW(query_hca_cap_out)] = {0};
+       void *hcattr;
+       int status, syndrome, rc;
+
+       MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
+       MLX5_SET(query_hca_cap_in, in, op_mod,
+                MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE |
+                MLX5_HCA_CAP_OPMOD_GET_CUR);
+
+       rc = mlx5_glue->devx_general_cmd(ctx,
+                                        in, sizeof(in), out, sizeof(out));
+       if (rc)
+               return rc;
+       status = MLX5_GET(query_hca_cap_out, out, status);
+       syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
+       if (status) {
+               DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
+                       "status %x, syndrome = %x",
+                       status, syndrome);
+               return -1;
+       }
+       hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
+       attr->eswitch_manager = MLX5_GET(cmd_hca_cap, hcattr, eswitch_manager);
+       return 0;
+}