net/mlx5: enable DevX Tx queue creation
[dpdk.git] / drivers / net / mlx5 / linux / mlx5_os.c
index 7bed7da..0ab6d55 100644 (file)
@@ -44,7 +44,6 @@
 #include "mlx5_rx.h"
 #include "mlx5_tx.h"
 #include "mlx5_autoconf.h"
-#include "mlx5_mr.h"
 #include "mlx5_flow.h"
 #include "rte_pmd_mlx5.h"
 #include "mlx5_verbs.h"
@@ -623,10 +622,6 @@ mlx5_init_once(void)
        case RTE_PROC_PRIMARY:
                if (sd->init_done)
                        break;
-               LIST_INIT(&sd->mem_event_cb_list);
-               rte_rwlock_init(&sd->mem_event_rwlock);
-               rte_mem_event_callback_register("MLX5_MEM_EVENT_CB",
-                                               mlx5_mr_mem_event_cb, NULL);
                ret = mlx5_mp_init_primary(MLX5_MP_NAME,
                                           mlx5_mp_os_primary_handle);
                if (ret)
@@ -651,56 +646,6 @@ out:
        return ret;
 }
 
-/**
- * Create the Tx queue DevX/Verbs object.
- *
- * @param dev
- *   Pointer to Ethernet device.
- * @param idx
- *   Queue index in DPDK Tx queue array.
- *
- * @return
- *   0 on success, a negative errno value otherwise and rte_errno is set.
- */
-static int
-mlx5_os_txq_obj_new(struct rte_eth_dev *dev, uint16_t idx)
-{
-       struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
-       struct mlx5_txq_ctrl *txq_ctrl =
-                       container_of(txq_data, struct mlx5_txq_ctrl, txq);
-
-       if (txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN)
-               return mlx5_txq_devx_obj_new(dev, idx);
-#ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
-       if (!priv->config.dv_esw_en)
-               return mlx5_txq_devx_obj_new(dev, idx);
-#endif
-       return mlx5_txq_ibv_obj_new(dev, idx);
-}
-
-/**
- * Release an Tx DevX/verbs queue object.
- *
- * @param txq_obj
- *   DevX/Verbs Tx queue object.
- */
-static void
-mlx5_os_txq_obj_release(struct mlx5_txq_obj *txq_obj)
-{
-       if (txq_obj->txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN) {
-               mlx5_txq_devx_obj_release(txq_obj);
-               return;
-       }
-#ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
-       if (!txq_obj->txq_ctrl->priv->config.dv_esw_en) {
-               mlx5_txq_devx_obj_release(txq_obj);
-               return;
-       }
-#endif
-       mlx5_txq_ibv_obj_release(txq_obj);
-}
-
 /**
  * DV flow counter mode detect and config.
  *
@@ -910,7 +855,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 {
        const struct mlx5_switch_info *switch_info = &spawn->info;
        struct mlx5_dev_ctx_shared *sh = NULL;
-       struct ibv_port_attr port_attr;
+       struct ibv_port_attr port_attr = { .state = IBV_PORT_NOP };
        struct mlx5dv_context dv_attr = { .comp_mask = 0 };
        struct rte_eth_dev *eth_dev = NULL;
        struct mlx5_priv *priv = NULL;
@@ -929,6 +874,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
        int own_domain_id = 0;
        uint16_t port_id;
        struct mlx5_port_info vport_info = { .query_flags = 0 };
+       int nl_rdma = -1;
        int i;
 
        /* Determine if this port representor is supposed to be spawned. */
@@ -1126,20 +1072,36 @@ err_secondary:
                " old OFED/rdma-core version or firmware configuration");
 #endif
        config->mpls_en = mpls_en;
+       nl_rdma = mlx5_nl_init(NETLINK_RDMA);
        /* Check port status. */
-       err = mlx5_glue->query_port(sh->cdev->ctx, spawn->phys_port,
-                                   &port_attr);
-       if (err) {
-               DRV_LOG(ERR, "port query failed: %s", strerror(err));
-               goto error;
-       }
-       if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
-               DRV_LOG(ERR, "port is not configured in Ethernet mode");
-               err = EINVAL;
-               goto error;
+       if (spawn->phys_port <= UINT8_MAX) {
+               /* Legacy Verbs api only support u8 port number. */
+               err = mlx5_glue->query_port(sh->cdev->ctx, spawn->phys_port,
+                                           &port_attr);
+               if (err) {
+                       DRV_LOG(ERR, "port query failed: %s", strerror(err));
+                       goto error;
+               }
+               if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
+                       DRV_LOG(ERR, "port is not configured in Ethernet mode");
+                       err = EINVAL;
+                       goto error;
+               }
+       } else if (nl_rdma >= 0) {
+               /* IB doesn't allow more than 255 ports, must be Ethernet. */
+               err = mlx5_nl_port_state(nl_rdma,
+                       spawn->phys_dev_name,
+                       spawn->phys_port);
+               if (err < 0) {
+                       DRV_LOG(INFO, "Failed to get netlink port state: %s",
+                               strerror(rte_errno));
+                       err = -rte_errno;
+                       goto error;
+               }
+               port_attr.state = (enum ibv_port_state)err;
        }
        if (port_attr.state != IBV_PORT_ACTIVE)
-               DRV_LOG(DEBUG, "port is not active: \"%s\" (%d)",
+               DRV_LOG(INFO, "port is not active: \"%s\" (%d)",
                        mlx5_glue->port_state_str(port_attr.state),
                        port_attr.state);
        /* Allocate private eth device data. */
@@ -1156,7 +1118,7 @@ err_secondary:
        priv->pci_dev = spawn->pci_dev;
        priv->mtu = RTE_ETHER_MTU;
        /* Some internal functions rely on Netlink sockets, open them now. */
-       priv->nl_socket_rdma = mlx5_nl_init(NETLINK_RDMA);
+       priv->nl_socket_rdma = nl_rdma;
        priv->nl_socket_route = mlx5_nl_init(NETLINK_ROUTE);
        priv->representor = !!switch_info->representor;
        priv->master = !!switch_info->master;
@@ -1733,16 +1695,6 @@ err_secondary:
                                                ibv_obj_ops.drop_action_create;
                priv->obj_ops.drop_action_destroy =
                                                ibv_obj_ops.drop_action_destroy;
-#ifndef HAVE_MLX5DV_DEVX_UAR_OFFSET
-               priv->obj_ops.txq_obj_modify = ibv_obj_ops.txq_obj_modify;
-#else
-               if (config->dv_esw_en)
-                       priv->obj_ops.txq_obj_modify =
-                                               ibv_obj_ops.txq_obj_modify;
-#endif
-               /* Use specific wrappers for Tx object. */
-               priv->obj_ops.txq_obj_new = mlx5_os_txq_obj_new;
-               priv->obj_ops.txq_obj_release = mlx5_os_txq_obj_release;
                mlx5_queue_counter_id_prepare(eth_dev);
                priv->obj_ops.lb_dummy_queue_create =
                                        mlx5_rxq_ibv_obj_dummy_lb_create;
@@ -1753,7 +1705,7 @@ err_secondary:
        }
        if (config->tx_pp &&
            (priv->config.dv_esw_en ||
-            priv->obj_ops.txq_obj_new != mlx5_os_txq_obj_new)) {
+            priv->obj_ops.txq_obj_new != mlx5_txq_devx_obj_new)) {
                /*
                 * HAVE_MLX5DV_DEVX_UAR_OFFSET is required to support
                 * packet pacing and already checked above.
@@ -1849,8 +1801,6 @@ error:
                        mlx5_os_free_shared_dr(priv);
                if (priv->nl_socket_route >= 0)
                        close(priv->nl_socket_route);
-               if (priv->nl_socket_rdma >= 0)
-                       close(priv->nl_socket_rdma);
                if (priv->vmwa_context)
                        mlx5_vlan_vmwa_exit(priv->vmwa_context);
                if (eth_dev && priv->drop_queue.hrxq)
@@ -1874,6 +1824,8 @@ error:
        }
        if (sh)
                mlx5_free_shared_dev_ctx(sh);
+       if (nl_rdma >= 0)
+               close(nl_rdma);
        MLX5_ASSERT(err > 0);
        rte_errno = err;
        return NULL;