net/bnxt: add Tx TruFlow table config for P4 device
[dpdk.git] / drivers / net / mlx4 / mlx4_mp.c
index eaeb257..8fcfb54 100644 (file)
@@ -3,12 +3,11 @@
  * Copyright 2019 Mellanox Technologies, Ltd
  */
 
-#include <assert.h>
 #include <stdio.h>
 #include <time.h>
 
 #include <rte_eal.h>
-#include <rte_ethdev_driver.h>
+#include <ethdev_driver.h>
 #include <rte_string_fns.h>
 
 #include "mlx4.h"
@@ -58,9 +57,11 @@ mp_primary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
                (const struct mlx4_mp_param *)mp_msg->param;
        struct rte_eth_dev *dev;
        struct mlx4_priv *priv;
+       struct mlx4_mr_cache entry;
+       uint32_t lkey;
        int ret;
 
-       assert(rte_eal_process_type() == RTE_PROC_PRIMARY);
+       MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
        if (!rte_eth_dev_is_valid_port(param->port_id)) {
                rte_errno = ENODEV;
                ERROR("port %u invalid port ID", param->port_id);
@@ -69,6 +70,13 @@ mp_primary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
        dev = &rte_eth_devices[param->port_id];
        priv = dev->data->dev_private;
        switch (param->type) {
+       case MLX4_MP_REQ_CREATE_MR:
+               mp_init_msg(dev, &mp_res, param->type);
+               lkey = mlx4_mr_create_primary(dev, &entry, param->args.addr);
+               if (lkey == UINT32_MAX)
+                       res->result = -rte_errno;
+               ret = rte_mp_reply(&mp_res, peer);
+               break;
        case MLX4_MP_REQ_VERBS_CMD_FD:
                mp_init_msg(dev, &mp_res, param->type);
                mp_res.num_fds = 1;
@@ -103,9 +111,12 @@ mp_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
        const struct mlx4_mp_param *param =
                (const struct mlx4_mp_param *)mp_msg->param;
        struct rte_eth_dev *dev;
+#ifdef HAVE_IBV_MLX4_UAR_MMAP_OFFSET
+       struct mlx4_proc_priv *ppriv;
+#endif
        int ret;
 
-       assert(rte_eal_process_type() == RTE_PROC_SECONDARY);
+       MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
        if (!rte_eth_dev_is_valid_port(param->port_id)) {
                rte_errno = ENODEV;
                ERROR("port %u invalid port ID", param->port_id);
@@ -115,9 +126,24 @@ mp_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
        switch (param->type) {
        case MLX4_MP_REQ_START_RXTX:
                INFO("port %u starting datapath", dev->data->port_id);
-               rte_mb();
                dev->tx_pkt_burst = mlx4_tx_burst;
                dev->rx_pkt_burst = mlx4_rx_burst;
+#ifdef HAVE_IBV_MLX4_UAR_MMAP_OFFSET
+               ppriv = (struct mlx4_proc_priv *)dev->process_private;
+               if (ppriv->uar_table_sz != dev->data->nb_tx_queues) {
+                       mlx4_tx_uar_uninit_secondary(dev);
+                       mlx4_proc_priv_uninit(dev);
+                       ret = mlx4_proc_priv_init(dev);
+                       if (ret)
+                               return -rte_errno;
+                       ret = mlx4_tx_uar_init_secondary(dev, mp_msg->fds[0]);
+                       if (ret) {
+                               mlx4_proc_priv_uninit(dev);
+                               return -rte_errno;
+                       }
+               }
+#endif
+               rte_mb();
                mp_init_msg(dev, &mp_res, param->type);
                res->result = 0;
                ret = rte_mp_reply(&mp_res, peer);
@@ -155,10 +181,11 @@ mp_req_on_rxtx(struct rte_eth_dev *dev, enum mlx4_mp_req_type type)
        struct rte_mp_reply mp_rep;
        struct mlx4_mp_param *res __rte_unused;
        struct timespec ts = {.tv_sec = MLX4_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
+       struct mlx4_priv *priv;
        int ret;
        int i;
 
-       assert(rte_eal_process_type() == RTE_PROC_PRIMARY);
+       MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
        if (!mlx4_shared_data->secondary_cnt)
                return;
        if (type != MLX4_MP_REQ_START_RXTX && type != MLX4_MP_REQ_STOP_RXTX) {
@@ -167,10 +194,16 @@ mp_req_on_rxtx(struct rte_eth_dev *dev, enum mlx4_mp_req_type type)
                return;
        }
        mp_init_msg(dev, &mp_req, type);
+       if (type == MLX4_MP_REQ_START_RXTX) {
+               priv = dev->data->dev_private;
+               mp_req.num_fds = 1;
+               mp_req.fds[0] = priv->ctx->cmd_fd;
+       }
        ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
        if (ret) {
-               ERROR("port %u failed to request stop/start Rx/Tx (%d)",
-                     dev->data->port_id, type);
+               if (rte_errno != ENOTSUP)
+                       ERROR("port %u failed to request stop/start Rx/Tx (%d)",
+                                       dev->data->port_id, type);
                goto exit;
        }
        if (mp_rep.nb_sent != mp_rep.nb_received) {
@@ -217,6 +250,47 @@ mlx4_mp_req_stop_rxtx(struct rte_eth_dev *dev)
        mp_req_on_rxtx(dev, MLX4_MP_REQ_STOP_RXTX);
 }
 
+/**
+ * Request Memory Region creation to the primary process.
+ *
+ * @param[in] dev
+ *   Pointer to Ethernet structure.
+ * @param addr
+ *   Target virtual address to register.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx4_mp_req_mr_create(struct rte_eth_dev *dev, uintptr_t addr)
+{
+       struct rte_mp_msg mp_req;
+       struct rte_mp_msg *mp_res;
+       struct rte_mp_reply mp_rep;
+       struct mlx4_mp_param *req = (struct mlx4_mp_param *)mp_req.param;
+       struct mlx4_mp_param *res;
+       struct timespec ts = {.tv_sec = MLX4_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
+       int ret;
+
+       MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
+       mp_init_msg(dev, &mp_req, MLX4_MP_REQ_CREATE_MR);
+       req->args.addr = addr;
+       ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
+       if (ret) {
+               ERROR("port %u request to primary process failed",
+                     dev->data->port_id);
+               return -rte_errno;
+       }
+       MLX4_ASSERT(mp_rep.nb_received == 1);
+       mp_res = &mp_rep.msgs[0];
+       res = (struct mlx4_mp_param *)mp_res->param;
+       ret = res->result;
+       if (ret)
+               rte_errno = -ret;
+       free(mp_rep.msgs);
+       return ret;
+}
+
 /**
  * IPC message handler of primary process.
  *
@@ -236,7 +310,7 @@ mlx4_mp_req_verbs_cmd_fd(struct rte_eth_dev *dev)
        struct timespec ts = {.tv_sec = MLX4_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
        int ret;
 
-       assert(rte_eal_process_type() == RTE_PROC_SECONDARY);
+       MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
        mp_init_msg(dev, &mp_req, MLX4_MP_REQ_VERBS_CMD_FD);
        ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
        if (ret) {
@@ -244,7 +318,7 @@ mlx4_mp_req_verbs_cmd_fd(struct rte_eth_dev *dev)
                      dev->data->port_id);
                return -rte_errno;
        }
-       assert(mp_rep.nb_received == 1);
+       MLX4_ASSERT(mp_rep.nb_received == 1);
        mp_res = &mp_rep.msgs[0];
        res = (struct mlx4_mp_param *)mp_res->param;
        if (res->result) {
@@ -254,7 +328,7 @@ mlx4_mp_req_verbs_cmd_fd(struct rte_eth_dev *dev)
                ret = -rte_errno;
                goto exit;
        }
-       assert(mp_res->num_fds == 1);
+       MLX4_ASSERT(mp_res->num_fds == 1);
        ret = mp_res->fds[0];
        DEBUG("port %u command FD from primary is %d",
              dev->data->port_id, ret);
@@ -266,11 +340,18 @@ exit:
 /**
  * Initialize by primary process.
  */
-void
+int
 mlx4_mp_init_primary(void)
 {
-       assert(rte_eal_process_type() == RTE_PROC_PRIMARY);
-       rte_mp_action_register(MLX4_MP_NAME, mp_primary_handle);
+       int ret;
+
+       MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
+
+       /* primary is allowed to not support IPC */
+       ret = rte_mp_action_register(MLX4_MP_NAME, mp_primary_handle);
+       if (ret && rte_errno != ENOTSUP)
+               return -1;
+       return 0;
 }
 
 /**
@@ -279,18 +360,18 @@ mlx4_mp_init_primary(void)
 void
 mlx4_mp_uninit_primary(void)
 {
-       assert(rte_eal_process_type() == RTE_PROC_PRIMARY);
+       MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
        rte_mp_action_unregister(MLX4_MP_NAME);
 }
 
 /**
  * Initialize by secondary process.
  */
-void
+int
 mlx4_mp_init_secondary(void)
 {
-       assert(rte_eal_process_type() == RTE_PROC_SECONDARY);
-       rte_mp_action_register(MLX4_MP_NAME, mp_secondary_handle);
+       MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
+       return rte_mp_action_register(MLX4_MP_NAME, mp_secondary_handle);
 }
 
 /**
@@ -299,6 +380,6 @@ mlx4_mp_init_secondary(void)
 void
 mlx4_mp_uninit_secondary(void)
 {
-       assert(rte_eal_process_type() == RTE_PROC_SECONDARY);
+       MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
        rte_mp_action_unregister(MLX4_MP_NAME);
 }