net/mlx5: add flow translation of eCPRI header
[dpdk.git] / drivers / net / mlx5 / mlx5.c
index 07c6add..1ba5e0c 100644 (file)
  */
 #define MLX5_TXQ_MAX_INLINE_LEN "txq_max_inline_len"
 
+/*
+ * Device parameter to enable Tx scheduling on timestamps
+ * and specify the packet pacing granularity in nanoseconds.
+ */
+#define MLX5_TX_PP "tx_pp"
+
+/*
+ * Device parameter to specify skew in nanoseconds on Tx datapath,
+ * it represents the time between SQ start WQE processing and
+ * appearing actual packet data on the wire.
+ */
+#define MLX5_TX_SKEW "tx_skew"
+
 /*
  * Device parameter to enable hardware Tx vector.
  * Deprecated, ignored (no vectorized Tx routines anymore).
@@ -177,8 +190,6 @@ static rte_spinlock_t mlx5_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
 
 /* Process local data for secondary processes. */
 static struct mlx5_local_data mlx5_local_data;
-/** Driver-specific log messages type. */
-int mlx5_logtype;
 
 static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
                                                LIST_HEAD_INITIALIZER();
@@ -597,6 +608,46 @@ mlx5_flow_ipool_destroy(struct mlx5_dev_ctx_shared *sh)
                mlx5_ipool_destroy(sh->ipool[i]);
 }
 
+/*
+ * Check if dynamic flex parser for eCPRI already exists.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ *
+ * @return
+ *   true on exists, false on not.
+ */
+bool
+mlx5_flex_parser_ecpri_exist(struct rte_eth_dev *dev)
+{
+       struct mlx5_priv *priv = dev->data->dev_private;
+       struct mlx5_flex_parser_profiles *prf =
+                               &priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0];
+
+       return !!prf->obj;
+}
+
+/*
+ * Allocation of a flex parser for eCPRI. Once created, this parser related
+ * resources will be held until the device is closed.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_flex_parser_ecpri_alloc(struct rte_eth_dev *dev)
+{
+       struct mlx5_priv *priv = dev->data->dev_private;
+       struct mlx5_flex_parser_profiles *prf =
+                               &priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0];
+
+       (void)prf;
+       return 0;
+}
+
 /**
  * Allocate shared device context. If there is multiport device the
  * master and representors will share this context, if there is single
@@ -698,6 +749,12 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
                        err = ENOMEM;
                        goto error;
                }
+               sh->tx_uar = mlx5_glue->devx_alloc_uar(sh->ctx, 0);
+               if (!sh->tx_uar) {
+                       DRV_LOG(ERR, "Failed to allocate DevX UAR.");
+                       err = ENOMEM;
+                       goto error;
+               }
        }
        sh->flow_id_pool = mlx5_flow_id_pool_alloc
                                        ((1 << HAIRPIN_FLOW_ID_BITS) - 1);
@@ -706,6 +763,12 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
                err = ENOMEM;
                goto error;
        }
+#ifndef RTE_ARCH_64
+       /* Initialize UAR access locks for 32bit implementations. */
+       rte_spinlock_init(&sh->uar_lock_cq);
+       for (i = 0; i < MLX5_UAR_PAGE_NUM_MAX; i++)
+               rte_spinlock_init(&sh->uar_lock[i]);
+#endif
        /*
         * Once the device is added to the list of memory event
         * callback, its global MR cache table cannot be expanded
@@ -744,12 +807,17 @@ exit:
        pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
        return sh;
 error:
+       pthread_mutex_destroy(&sh->txpp.mutex);
        pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
        MLX5_ASSERT(sh);
        if (sh->cnt_id_tbl) {
                mlx5_l3t_destroy(sh->cnt_id_tbl);
                sh->cnt_id_tbl = NULL;
        }
+       if (sh->tx_uar) {
+               mlx5_glue->devx_free_uar(sh->tx_uar);
+               sh->tx_uar = NULL;
+       }
        if (sh->tis)
                claim_zero(mlx5_devx_cmd_destroy(sh->tis));
        if (sh->td)
@@ -815,6 +883,10 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
                mlx5_l3t_destroy(sh->cnt_id_tbl);
                sh->cnt_id_tbl = NULL;
        }
+       if (sh->tx_uar) {
+               mlx5_glue->devx_free_uar(sh->tx_uar);
+               sh->tx_uar = NULL;
+       }
        if (sh->pd)
                claim_zero(mlx5_glue->dealloc_pd(sh->pd));
        if (sh->tis)
@@ -825,6 +897,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
                claim_zero(mlx5_glue->close_device(sh->ctx));
        if (sh->flow_id_pool)
                mlx5_flow_id_pool_release(sh->flow_id_pool);
+       pthread_mutex_destroy(&sh->txpp.mutex);
        rte_free(sh);
 exit:
        pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
@@ -1273,18 +1346,26 @@ static int
 mlx5_args_check(const char *key, const char *val, void *opaque)
 {
        struct mlx5_dev_config *config = opaque;
-       unsigned long tmp;
+       unsigned long mod;
+       signed long tmp;
 
        /* No-op, port representors are processed in mlx5_dev_spawn(). */
        if (!strcmp(MLX5_REPRESENTOR, key))
                return 0;
        errno = 0;
-       tmp = strtoul(val, NULL, 0);
+       tmp = strtol(val, NULL, 0);
        if (errno) {
                rte_errno = errno;
                DRV_LOG(WARNING, "%s: \"%s\" is not a valid integer", key, val);
                return -rte_errno;
        }
+       if (tmp < 0 && strcmp(MLX5_TX_PP, key) && strcmp(MLX5_TX_SKEW, key)) {
+               /* Negative values are acceptable for some keys only. */
+               rte_errno = EINVAL;
+               DRV_LOG(WARNING, "%s: invalid negative value \"%s\"", key, val);
+               return -rte_errno;
+       }
+       mod = tmp >= 0 ? tmp : -tmp;
        if (strcmp(MLX5_RXQ_CQE_COMP_EN, key) == 0) {
                config->cqe_comp = !!tmp;
        } else if (strcmp(MLX5_RXQ_CQE_PAD_EN, key) == 0) {
@@ -1335,6 +1416,15 @@ mlx5_args_check(const char *key, const char *val, void *opaque)
                config->txq_inline_mpw = tmp;
        } else if (strcmp(MLX5_TX_VEC_EN, key) == 0) {
                DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
+       } else if (strcmp(MLX5_TX_PP, key) == 0) {
+               if (!mod) {
+                       DRV_LOG(ERR, "Zero Tx packet pacing parameter");
+                       rte_errno = EINVAL;
+                       return -rte_errno;
+               }
+               config->tx_pp = tmp;
+       } else if (strcmp(MLX5_TX_SKEW, key) == 0) {
+               config->tx_skew = tmp;
        } else if (strcmp(MLX5_RX_VEC_EN, key) == 0) {
                config->rx_vec_en = !!tmp;
        } else if (strcmp(MLX5_L3_VXLAN_EN, key) == 0) {
@@ -1417,6 +1507,8 @@ mlx5_args(struct mlx5_dev_config *config, struct rte_devargs *devargs)
                MLX5_TXQ_MPW_HDR_DSEG_EN,
                MLX5_TXQ_MAX_INLINE_LEN,
                MLX5_TX_DB_NC,
+               MLX5_TX_PP,
+               MLX5_TX_SKEW,
                MLX5_TX_VEC_EN,
                MLX5_RX_VEC_EN,
                MLX5_L3_VXLAN_EN,
@@ -1695,7 +1787,8 @@ rte_pmd_mlx5_get_dyn_flag_names(char *names[], unsigned int n)
 {
        static const char *const dynf_names[] = {
                RTE_PMD_MLX5_FINE_GRANULARITY_INLINE,
-               RTE_MBUF_DYNFLAG_METADATA_NAME
+               RTE_MBUF_DYNFLAG_METADATA_NAME,
+               RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME
        };
        unsigned int i;
 
@@ -1887,6 +1980,10 @@ static const struct rte_pci_id mlx5_pci_id_map[] = {
                RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
                                PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF)
        },
+       {
+               RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
+                               PCI_DEVICE_ID_MELLANOX_CONNECTX6LX)
+       },
        {
                .vendor_id = 0
        }
@@ -1904,16 +2001,14 @@ struct rte_pci_driver mlx5_driver = {
        .drv_flags = PCI_DRV_FLAGS,
 };
 
+/* Initialize driver log type. */
+RTE_LOG_REGISTER(mlx5_logtype, pmd.net.mlx5, NOTICE)
+
 /**
  * Driver initialization routine.
  */
 RTE_INIT(rte_mlx5_pmd_init)
 {
-       /* Initialize driver log type. */
-       mlx5_logtype = rte_log_register("pmd.net.mlx5");
-       if (mlx5_logtype >= 0)
-               rte_log_set_level(mlx5_logtype, RTE_LOG_NOTICE);
-
        /* Build the static tables for Verbs conversion. */
        mlx5_set_ptype_table();
        mlx5_set_cksum_table();