ethdev: add device flag to bypass auto-filled queue xstats
[dpdk.git] / drivers / net / mlx5 / linux / mlx5_os.c
index 505e7d9..10f6370 100644 (file)
@@ -250,6 +250,14 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
                err = ENOMEM;
                goto error;
        }
+       snprintf(s, sizeof(s), "%s_encaps_decaps", sh->ibdev_name);
+       sh->encaps_decaps = mlx5_hlist_create(s,
+                                             MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ);
+       if (!sh->encaps_decaps) {
+               DRV_LOG(ERR, "encap decap hash creation failed");
+               err = ENOMEM;
+               goto error;
+       }
 #ifdef HAVE_MLX5DV_DR
        void *domain;
 
@@ -323,6 +331,10 @@ error:
                mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
                sh->pop_vlan_action = NULL;
        }
+       if (sh->encaps_decaps) {
+               mlx5_hlist_destroy(sh->encaps_decaps, NULL, NULL);
+               sh->encaps_decaps = NULL;
+       }
        if (sh->modify_cmds) {
                mlx5_hlist_destroy(sh->modify_cmds, NULL, NULL);
                sh->modify_cmds = NULL;
@@ -380,6 +392,10 @@ mlx5_os_free_shared_dr(struct mlx5_priv *priv)
        }
        pthread_mutex_destroy(&sh->dv_mutex);
 #endif /* HAVE_MLX5DV_DR */
+       if (sh->encaps_decaps) {
+               mlx5_hlist_destroy(sh->encaps_decaps, NULL, NULL);
+               sh->encaps_decaps = NULL;
+       }
        if (sh->modify_cmds) {
                mlx5_hlist_destroy(sh->modify_cmds, NULL, NULL);
                sh->modify_cmds = NULL;
@@ -495,6 +511,70 @@ 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_dev_config *config = &priv->config;
+       struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
+       struct mlx5_txq_ctrl *txq_ctrl =
+                       container_of(txq_data, struct mlx5_txq_ctrl, txq);
+
+       /*
+        * When DevX is supported and DV flow is enable, and dest tir is enable,
+        * hairpin functions use DevX API.
+        * When, in addition, DV E-Switch is enable and DevX uar offset is
+        * supported, all Tx functions also use DevX API.
+        * Otherwise, all Tx functions use Verbs API.
+        */
+       if (config->devx && config->dv_flow_en && config->dest_tir) {
+               if (txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN)
+                       return mlx5_txq_devx_obj_new(dev, idx);
+#ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
+               if (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)
+{
+       struct mlx5_dev_config *config = &txq_obj->txq_ctrl->priv->config;
+
+       if (config->devx && config->dv_flow_en && config->dest_tir) {
+#ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
+               if (config->dv_esw_en) {
+                       mlx5_txq_devx_obj_release(txq_obj);
+                       return;
+               }
+#endif
+               if (txq_obj->txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN) {
+                       mlx5_txq_devx_obj_release(txq_obj);
+                       return;
+               }
+       }
+       mlx5_txq_ibv_obj_release(txq_obj);
+}
+
 /**
  * Spawn an Ethernet device from Verbs information.
  *
@@ -602,6 +682,8 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
                }
                eth_dev->device = dpdk_dev;
                eth_dev->dev_ops = &mlx5_os_dev_sec_ops;
+               eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status;
+               eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status;
                err = mlx5_proc_priv_init(eth_dev);
                if (err)
                        return NULL;
@@ -1016,6 +1098,20 @@ err_secondary:
                                        priv->mtr_color_reg);
                        }
                }
+#endif
+#if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
+               if (config->hca_attr.log_max_ft_sampler_num > 0  &&
+                   config->dv_flow_en) {
+                       priv->sampler_en = 1;
+                       DRV_LOG(DEBUG, "The Sampler enabled!\n");
+               } else {
+                       priv->sampler_en = 0;
+                       if (!config->hca_attr.log_max_ft_sampler_num)
+                               DRV_LOG(WARNING, "No available register for"
+                                               " Sampler.");
+                       else
+                               DRV_LOG(DEBUG, "DV flow is not supported!\n");
+               }
 #endif
        }
        if (config->tx_pp) {
@@ -1153,8 +1249,6 @@ err_secondary:
                err = ENOMEM;
                goto error;
        }
-       /* Flag to call rte_eth_dev_release_port() in rte_eth_dev_close(). */
-       eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
        if (priv->representor) {
                eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
                eth_dev->data->representor_id = priv->representor_id;
@@ -1166,10 +1260,24 @@ err_secondary:
         */
        MLX5_ASSERT(spawn->ifindex);
        priv->if_index = spawn->ifindex;
+       if (priv->pf_bond >= 0 && priv->master) {
+               /* Get bond interface info */
+               err = mlx5_sysfs_bond_info(priv->if_index,
+                                    &priv->bond_ifindex,
+                                    priv->bond_name);
+               if (err)
+                       DRV_LOG(ERR, "unable to get bond info: %s",
+                               strerror(rte_errno));
+               else
+                       DRV_LOG(INFO, "PF device %u, bond device %u(%s)",
+                               priv->if_index, priv->bond_ifindex,
+                               priv->bond_name);
+       }
        eth_dev->data->dev_private = priv;
        priv->dev_data = eth_dev->data;
        eth_dev->data->mac_addrs = priv->mac;
        eth_dev->device = dpdk_dev;
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
        /* Configure the first MAC address by default. */
        if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) {
                DRV_LOG(ERR,
@@ -1209,6 +1317,9 @@ err_secondary:
        eth_dev->rx_pkt_burst = removed_rx_burst;
        eth_dev->tx_pkt_burst = removed_tx_burst;
        eth_dev->dev_ops = &mlx5_os_dev_ops;
+       eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status;
+       eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status;
+       eth_dev->rx_queue_count = mlx5_rx_queue_count;
        /* Register MAC address. */
        claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0));
        if (config->vf && config->vf_nl_en)
@@ -1267,13 +1378,31 @@ err_secondary:
                        goto error;
                }
        }
-       if (config->devx && config->dv_flow_en) {
+       /*
+        * Initialize the dev_ops structure with DevX/Verbs function pointers.
+        * When DevX is supported and both DV flow and dest tir are enabled, all
+        * Rx functions use DevX API (except for drop that has not yet been
+        * implemented in DevX).
+        */
+       if (config->devx && config->dv_flow_en && config->dest_tir) {
                priv->obj_ops = devx_obj_ops;
-               priv->obj_ops.hrxq_drop_new = ibv_obj_ops.hrxq_drop_new;
-               priv->obj_ops.hrxq_drop_release = ibv_obj_ops.hrxq_drop_release;
+               priv->obj_ops.drop_action_create =
+                                               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
        } else {
                priv->obj_ops = ibv_obj_ops;
        }
+       /* The Tx objects are managed by a specific linux wrapper functions. */
+       priv->obj_ops.txq_obj_new = mlx5_os_txq_obj_new;
+       priv->obj_ops.txq_obj_release = mlx5_os_txq_obj_release;
        /* Supported Verbs flow priority number detection. */
        err = mlx5_flow_discover_priorities(eth_dev);
        if (err < 0) {
@@ -2404,13 +2533,10 @@ const struct eth_dev_ops mlx5_os_dev_ops = {
        .rss_hash_update = mlx5_rss_hash_update,
        .rss_hash_conf_get = mlx5_rss_hash_conf_get,
        .filter_ctrl = mlx5_dev_filter_ctrl,
-       .rx_descriptor_status = mlx5_rx_descriptor_status,
-       .tx_descriptor_status = mlx5_tx_descriptor_status,
        .rxq_info_get = mlx5_rxq_info_get,
        .txq_info_get = mlx5_txq_info_get,
        .rx_burst_mode_get = mlx5_rx_burst_mode_get,
        .tx_burst_mode_get = mlx5_tx_burst_mode_get,
-       .rx_queue_count = mlx5_rx_queue_count,
        .rx_queue_intr_enable = mlx5_rx_intr_enable,
        .rx_queue_intr_disable = mlx5_rx_intr_disable,
        .is_removed = mlx5_is_removed,
@@ -2435,8 +2561,6 @@ const struct eth_dev_ops mlx5_os_dev_sec_ops = {
        .rx_queue_stop = mlx5_rx_queue_stop,
        .tx_queue_start = mlx5_tx_queue_start,
        .tx_queue_stop = mlx5_tx_queue_stop,
-       .rx_descriptor_status = mlx5_rx_descriptor_status,
-       .tx_descriptor_status = mlx5_tx_descriptor_status,
        .rxq_info_get = mlx5_rxq_info_get,
        .txq_info_get = mlx5_txq_info_get,
        .rx_burst_mode_get = mlx5_rx_burst_mode_get,
@@ -2488,8 +2612,6 @@ const struct eth_dev_ops mlx5_os_dev_ops_isolate = {
        .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
        .vlan_offload_set = mlx5_vlan_offload_set,
        .filter_ctrl = mlx5_dev_filter_ctrl,
-       .rx_descriptor_status = mlx5_rx_descriptor_status,
-       .tx_descriptor_status = mlx5_tx_descriptor_status,
        .rxq_info_get = mlx5_rxq_info_get,
        .txq_info_get = mlx5_txq_info_get,
        .rx_burst_mode_get = mlx5_rx_burst_mode_get,