common/mlx5: share device context object
[dpdk.git] / drivers / common / mlx5 / linux / mlx5_glue.c
index 4a76902..037ca96 100644 (file)
@@ -8,7 +8,6 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <rte_memory.h>
 /*
  * Not needed by this file; included to work around the lack of off_t
  * definition for mlx5dv.h with unpatched rdma-core versions.
@@ -16,7 +15,6 @@
 #include <sys/types.h>
 
 #include "mlx5_glue.h"
-#include "../mlx5_malloc.h"
 
 static int
 mlx5_glue_fork_init(void)
@@ -186,7 +184,7 @@ mlx5_glue_destroy_flow_action(void *action)
                res = ibv_destroy_flow_action(attr->action);
                break;
        }
-       mlx5_free(action);
+       free(action);
        return res;
 #endif
 #else
@@ -393,7 +391,7 @@ mlx5_glue_dr_create_flow_action_dest_flow_tbl(void *tbl)
 static void *
 mlx5_glue_dr_create_flow_action_dest_port(void *domain, uint32_t port)
 {
-#ifdef HAVE_MLX5DV_DR_DEVX_PORT
+#ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
        return mlx5dv_dr_action_create_dest_ib_port(domain, port);
 #else
 #ifdef HAVE_MLX5DV_DR_ESWITCH
@@ -632,7 +630,7 @@ mlx5_glue_dv_create_flow_action_counter(void *counter_obj, uint32_t offset)
        struct mlx5dv_flow_action_attr *action;
 
        (void)offset;
-       action = mlx5_malloc(0, sizeof(*action), 0, SOCKET_ID_ANY);
+       action = malloc(sizeof(*action));
        if (!action)
                return NULL;
        action->type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX;
@@ -656,7 +654,7 @@ mlx5_glue_dv_create_flow_action_dest_ibv_qp(void *qp)
 #else
        struct mlx5dv_flow_action_attr *action;
 
-       action = mlx5_malloc(0, sizeof(*action), 0, SOCKET_ID_ANY);
+       action = malloc(sizeof(*action));
        if (!action)
                return NULL;
        action->type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
@@ -701,7 +699,7 @@ mlx5_glue_dv_create_flow_action_modify_header
 
        (void)domain;
        (void)flags;
-       action = mlx5_malloc(0, sizeof(*action), 0, SOCKET_ID_ANY);
+       action = malloc(sizeof(*action));
        if (!action)
                return NULL;
        action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
@@ -741,7 +739,7 @@ mlx5_glue_dv_create_flow_action_packet_reformat
        (void)flags;
        struct mlx5dv_flow_action_attr *action;
 
-       action = mlx5_malloc(0, sizeof(*action), 0, SOCKET_ID_ANY);
+       action = malloc(sizeof(*action));
        if (!action)
                return NULL;
        action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
@@ -771,7 +769,7 @@ mlx5_glue_dv_create_flow_action_tag(uint32_t tag)
 #else /* HAVE_MLX5DV_DR */
        struct mlx5dv_flow_action_attr *action;
 
-       action = mlx5_malloc(0, sizeof(*action), 0, SOCKET_ID_ANY);
+       action = malloc(sizeof(*action));
        if (!action)
                return NULL;
        action->type = MLX5DV_FLOW_ACTION_TAG;
@@ -813,6 +811,27 @@ mlx5_glue_dv_modify_flow_action_meter(void *action,
 #endif
 }
 
+static void *
+mlx5_glue_dv_create_flow_action_aso(struct mlx5dv_dr_domain *domain,
+                                   void *aso_obj,
+                                   uint32_t offset,
+                                   uint32_t flags,
+                                   uint8_t return_reg_c)
+{
+#if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_ASO)
+       return mlx5dv_dr_action_create_aso(domain, aso_obj, offset,
+                                          flags, return_reg_c);
+#else
+       (void)domain;
+       (void)aso_obj;
+       (void)offset;
+       (void)flags;
+       (void)return_reg_c;
+       errno = ENOTSUP;
+       return NULL;
+#endif
+}
+
 static void *
 mlx5_glue_dr_create_flow_action_default_miss(void)
 {
@@ -1049,21 +1068,87 @@ mlx5_glue_devx_qp_query(struct ibv_qp *qp,
 }
 
 static int
-mlx5_glue_devx_port_query(struct ibv_context *ctx,
-                         uint32_t port_num,
-                         struct mlx5dv_devx_port *mlx5_devx_port)
+mlx5_glue_devx_wq_query(struct ibv_wq *wq, const void *in, size_t inlen,
+                       void *out, size_t outlen)
 {
-#ifdef HAVE_MLX5DV_DR_DEVX_PORT
-       return mlx5dv_query_devx_port(ctx, port_num, mlx5_devx_port);
+#ifdef HAVE_IBV_DEVX_QP
+       return mlx5dv_devx_wq_query(wq, in, inlen, out, outlen);
 #else
-       (void)ctx;
-       (void)port_num;
-       (void)mlx5_devx_port;
+       (void)wq;
+       (void)in;
+       (void)inlen;
+       (void)out;
+       (void)outlen;
        errno = ENOTSUP;
        return errno;
 #endif
 }
 
+static int
+mlx5_glue_devx_port_query(struct ibv_context *ctx,
+                         uint32_t port_num,
+                         struct mlx5_port_info *info)
+{
+       int err = 0;
+
+       info->query_flags = 0;
+#ifdef HAVE_MLX5DV_DR_DEVX_PORT_V35
+       /* The DevX port query API is implemented (rdma-core v35 and above). */
+       struct mlx5_ib_uapi_query_port devx_port;
+
+       memset(&devx_port, 0, sizeof(devx_port));
+       err = mlx5dv_query_port(ctx, port_num, &devx_port);
+       if (err)
+               return err;
+       if (devx_port.flags & MLX5DV_QUERY_PORT_VPORT_REG_C0) {
+               info->vport_meta_tag = devx_port.reg_c0.value;
+               info->vport_meta_mask = devx_port.reg_c0.mask;
+               info->query_flags |= MLX5_PORT_QUERY_REG_C0;
+       }
+       if (devx_port.flags & MLX5DV_QUERY_PORT_VPORT) {
+               info->vport_id = devx_port.vport;
+               info->query_flags |= MLX5_PORT_QUERY_VPORT;
+       }
+#else
+#ifdef HAVE_MLX5DV_DR_DEVX_PORT
+       /* The legacy DevX port query API is implemented (prior v35). */
+       struct mlx5dv_devx_port devx_port = {
+               .comp_mask = MLX5DV_DEVX_PORT_VPORT |
+                            MLX5DV_DEVX_PORT_MATCH_REG_C_0
+       };
+
+       err = mlx5dv_query_devx_port(ctx, port_num, &devx_port);
+       if (err)
+               return err;
+       if (devx_port.comp_mask & MLX5DV_DEVX_PORT_MATCH_REG_C_0) {
+               info->vport_meta_tag = devx_port.reg_c_0.value;
+               info->vport_meta_mask = devx_port.reg_c_0.mask;
+               info->query_flags |= MLX5_PORT_QUERY_REG_C0;
+       }
+       if (devx_port.comp_mask & MLX5DV_DEVX_PORT_VPORT) {
+               info->vport_id = devx_port.vport_num;
+               info->query_flags |= MLX5_PORT_QUERY_VPORT;
+       }
+#else
+       RTE_SET_USED(ctx);
+       RTE_SET_USED(port_num);
+#endif /* HAVE_MLX5DV_DR_DEVX_PORT */
+#endif /* HAVE_MLX5DV_DR_DEVX_PORT_V35 */
+       return err;
+}
+
+static int
+mlx5_glue_dr_dump_single_rule(FILE *file, void *rule)
+{
+#ifdef HAVE_MLX5_DR_FLOW_DUMP_RULE
+       return mlx5dv_dump_dr_rule(file, rule);
+#else
+       RTE_SET_USED(file);
+       RTE_SET_USED(rule);
+       return -ENOTSUP;
+#endif
+}
+
 static int
 mlx5_glue_dr_dump_domain(FILE *file, void *domain)
 {
@@ -1273,6 +1358,17 @@ mlx5_glue_dv_alloc_pp(struct ibv_context *context,
 #endif
 }
 
+static void
+mlx5_glue_dr_allow_duplicate_rules(void *domain, uint32_t allow)
+{
+#ifdef HAVE_MLX5_DR_ALLOW_DUPLICATE
+       mlx5dv_dr_domain_allow_duplicate_rules(domain, allow);
+#else
+       (void)(allow);
+       (void)(domain);
+#endif
+}
+
 static void
 mlx5_glue_dv_free_pp(struct mlx5dv_pp *pp)
 {
@@ -1366,6 +1462,7 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
        .dv_create_flow_action_tag =  mlx5_glue_dv_create_flow_action_tag,
        .dv_create_flow_action_meter = mlx5_glue_dv_create_flow_action_meter,
        .dv_modify_flow_action_meter = mlx5_glue_dv_modify_flow_action_meter,
+       .dv_create_flow_action_aso = mlx5_glue_dv_create_flow_action_aso,
        .dr_create_flow_action_default_miss =
                mlx5_glue_dr_create_flow_action_default_miss,
        .dv_destroy_flow = mlx5_glue_dv_destroy_flow,
@@ -1383,13 +1480,16 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
        .devx_umem_reg = mlx5_glue_devx_umem_reg,
        .devx_umem_dereg = mlx5_glue_devx_umem_dereg,
        .devx_qp_query = mlx5_glue_devx_qp_query,
+       .devx_wq_query = mlx5_glue_devx_wq_query,
        .devx_port_query = mlx5_glue_devx_port_query,
        .dr_dump_domain = mlx5_glue_dr_dump_domain,
+       .dr_dump_rule = mlx5_glue_dr_dump_single_rule,
        .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory,
        .dr_create_flow_action_sampler =
                mlx5_glue_dr_create_flow_action_sampler,
        .dr_create_flow_action_dest_array =
                mlx5_glue_dr_action_create_dest_array,
+       .dr_allow_duplicate_rules = mlx5_glue_dr_allow_duplicate_rules,
        .devx_query_eqn = mlx5_glue_devx_query_eqn,
        .devx_create_event_channel = mlx5_glue_devx_create_event_channel,
        .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,