net/mlx5: fix SF representor probing in isolate mode
[dpdk.git] / drivers / net / mlx5 / mlx5.c
index 3b5c784..f68c769 100644 (file)
@@ -12,7 +12,6 @@
 
 #include <rte_malloc.h>
 #include <ethdev_driver.h>
-#include <ethdev_pci.h>
 #include <rte_pci.h>
 #include <rte_bus_pci.h>
 #include <rte_common.h>
@@ -28,7 +27,6 @@
 #include <mlx5_common.h>
 #include <mlx5_common_os.h>
 #include <mlx5_common_mp.h>
-#include <mlx5_common_pci.h>
 #include <mlx5_malloc.h>
 
 #include "mlx5_defs.h"
@@ -43,6 +41,8 @@
 #include "mlx5_flow_os.h"
 #include "rte_pmd_mlx5.h"
 
+#define MLX5_ETH_DRIVER_NAME mlx5_eth
+
 /* Device parameter to enable RX completion queue compression. */
 #define MLX5_RXQ_CQE_COMP_EN "rxq_cqe_comp_en"
 
@@ -217,7 +217,8 @@ static const struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {
                .grow_trunk = 3,
                .grow_shift = 2,
                .need_lock = 1,
-               .release_mem_en = 1,
+               .release_mem_en = 0,
+               .per_core_cache = (1 << 16),
                .malloc = mlx5_malloc,
                .free = mlx5_free,
                .type = "mlx5_tag_ipool",
@@ -398,6 +399,24 @@ mlx5_is_hpf(struct rte_eth_dev *dev)
               MLX5_REPRESENTOR_REPR(-1) == repr;
 }
 
+/**
+ * Decide whether representor ID is a SF port representor.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ *
+ * @return
+ *   Non-zero if HPF, otherwise 0.
+ */
+bool
+mlx5_is_sf_repr(struct rte_eth_dev *dev)
+{
+       struct mlx5_priv *priv = dev->data->dev_private;
+       int type = MLX5_REPRESENTOR_TYPE(priv->representor_id);
+
+       return priv->representor != 0 && type == RTE_ETH_REPRESENTOR_SF;
+}
+
 /**
  * Initialize the ASO aging management structure.
  *
@@ -797,6 +816,8 @@ mlx5_flow_ipool_create(struct mlx5_dev_ctx_shared *sh,
                if (config->reclaim_mode) {
                        cfg.release_mem_en = 1;
                        cfg.per_core_cache = 0;
+               } else {
+                       cfg.release_mem_en = 0;
                }
                sh->ipool[i] = mlx5_ipool_create(&cfg);
        }
@@ -1117,6 +1138,7 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
                rte_errno  = ENOMEM;
                goto exit;
        }
+       sh->numa_node = spawn->numa_node;
        if (spawn->bond_info)
                sh->bond = *spawn->bond_info;
        err = mlx5_os_open_device(spawn, config, sh);
@@ -1129,6 +1151,7 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
        }
        sh->refcnt = 1;
        sh->max_port = spawn->max_port;
+       sh->reclaim_mode = config->reclaim_mode;
        strncpy(sh->ibdev_name, mlx5_os_get_ctx_device_name(sh->ctx),
                sizeof(sh->ibdev_name) - 1);
        strncpy(sh->ibdev_path, mlx5_os_get_ctx_device_path(sh->ctx),
@@ -1193,7 +1216,7 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
         */
        err = mlx5_mr_btree_init(&sh->share_cache.cache,
                                 MLX5_MR_BTREE_CACHE_N * 2,
-                                spawn->pci_dev->device.numa_node);
+                                sh->numa_node);
        if (err) {
                err = rte_errno;
                goto error;
@@ -1631,7 +1654,7 @@ mlx5_dev_close(struct rte_eth_dev *dev)
                unsigned int c = 0;
                uint16_t port_id;
 
-               MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) {
+               MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
                        struct mlx5_priv *opriv =
                                rte_eth_devices[port_id].data->dev_private;
 
@@ -1733,6 +1756,7 @@ const struct eth_dev_ops mlx5_dev_sec_ops = {
        .xstats_get_names = mlx5_xstats_get_names,
        .fw_version_get = mlx5_fw_version_get,
        .dev_infos_get = mlx5_dev_infos_get,
+       .representor_info_get = mlx5_representor_info_get,
        .read_clock = mlx5_txpp_read_clock,
        .rx_queue_start = mlx5_rx_queue_start,
        .rx_queue_stop = mlx5_rx_queue_stop,
@@ -1766,6 +1790,7 @@ const struct eth_dev_ops mlx5_dev_ops_isolate = {
        .xstats_get_names = mlx5_xstats_get_names,
        .fw_version_get = mlx5_fw_version_get,
        .dev_infos_get = mlx5_dev_infos_get,
+       .representor_info_get = mlx5_representor_info_get,
        .read_clock = mlx5_txpp_read_clock,
        .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
        .vlan_filter_set = mlx5_vlan_filter_set,
@@ -2073,18 +2098,20 @@ mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
 {
        if (config->txq_inline_min != MLX5_ARG_UNSET) {
                /* Application defines size of inlined data explicitly. */
-               switch (spawn->pci_dev->id.device_id) {
-               case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
-               case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
-                       if (config->txq_inline_min <
-                                      (int)MLX5_INLINE_HSIZE_L2) {
-                               DRV_LOG(DEBUG,
-                                       "txq_inline_mix aligned to minimal"
-                                       " ConnectX-4 required value %d",
-                                       (int)MLX5_INLINE_HSIZE_L2);
-                               config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
+               if (spawn->pci_dev != NULL) {
+                       switch (spawn->pci_dev->id.device_id) {
+                       case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
+                       case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
+                               if (config->txq_inline_min <
+                                              (int)MLX5_INLINE_HSIZE_L2) {
+                                       DRV_LOG(DEBUG,
+                                               "txq_inline_mix aligned to minimal ConnectX-4 required value %d",
+                                               (int)MLX5_INLINE_HSIZE_L2);
+                                       config->txq_inline_min =
+                                                       MLX5_INLINE_HSIZE_L2;
+                               }
+                               break;
                        }
-                       break;
                }
                goto exit;
        }
@@ -2138,6 +2165,10 @@ mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
                        }
                }
        }
+       if (spawn->pci_dev == NULL) {
+               config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
+               goto exit;
+       }
        /*
         * We get here if we are unable to deduce
         * inline data size with DevX. Try PCI ID
@@ -2272,7 +2303,7 @@ mlx5_dev_check_sibling_config(struct mlx5_priv *priv,
        if (sh->refcnt == 1)
                return 0;
        /* Find the device with shared context. */
-       MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) {
+       MLX5_ETH_FOREACH_DEV(port_id, NULL) {
                struct mlx5_priv *opriv =
                        rte_eth_devices[port_id].data->dev_private;
 
@@ -2303,28 +2334,31 @@ mlx5_dev_check_sibling_config(struct mlx5_priv *priv,
  *
  * @param[in] port_id
  *   port_id to start looking for device.
- * @param[in] pci_dev
- *   Pointer to the hint PCI device. When device is being probed
+ * @param[in] odev
+ *   Pointer to the hint device. When device is being probed
  *   the its siblings (master and preceding representors might
  *   not have assigned driver yet (because the mlx5_os_pci_probe()
- *   is not completed yet, for this case match on hint PCI
+ *   is not completed yet, for this case match on hint
  *   device may be used to detect sibling device.
  *
  * @return
  *   port_id of found device, RTE_MAX_ETHPORT if not found.
  */
 uint16_t
-mlx5_eth_find_next(uint16_t port_id, struct rte_pci_device *pci_dev)
+mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev)
 {
        while (port_id < RTE_MAX_ETHPORTS) {
                struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 
                if (dev->state != RTE_ETH_DEV_UNUSED &&
                    dev->device &&
-                   (dev->device == &pci_dev->device ||
+                   (dev->device == odev ||
                     (dev->device->driver &&
                     dev->device->driver->name &&
-                    !strcmp(dev->device->driver->name, MLX5_PCI_DRIVER_NAME))))
+                    ((strcmp(dev->device->driver->name,
+                             MLX5_PCI_DRIVER_NAME) == 0) ||
+                     (strcmp(dev->device->driver->name,
+                             MLX5_AUXILIARY_DRIVER_NAME) == 0)))))
                        break;
                port_id++;
        }
@@ -2334,23 +2368,23 @@ mlx5_eth_find_next(uint16_t port_id, struct rte_pci_device *pci_dev)
 }
 
 /**
- * DPDK callback to remove a PCI device.
+ * Callback to remove a device.
  *
- * This function removes all Ethernet devices belong to a given PCI device.
+ * This function removes all Ethernet devices belong to a given device.
  *
- * @param[in] pci_dev
- *   Pointer to the PCI device.
+ * @param[in] dev
+ *   Pointer to the generic device.
  *
  * @return
  *   0 on success, the function cannot fail.
  */
 static int
-mlx5_pci_remove(struct rte_pci_device *pci_dev)
+mlx5_net_remove(struct rte_device *dev)
 {
        uint16_t port_id;
        int ret = 0;
 
-       RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device) {
+       RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
                /*
                 * mlx5_dev_close() is not registered to secondary process,
                 * call the close function explicitly for secondary process.
@@ -2441,19 +2475,17 @@ static const struct rte_pci_id mlx5_pci_id_map[] = {
        }
 };
 
-static struct mlx5_pci_driver mlx5_driver = {
-       .driver_class = MLX5_CLASS_NET,
-       .pci_driver = {
-               .driver = {
-                       .name = MLX5_PCI_DRIVER_NAME,
-               },
-               .id_table = mlx5_pci_id_map,
-               .probe = mlx5_os_pci_probe,
-               .remove = mlx5_pci_remove,
-               .dma_map = mlx5_dma_map,
-               .dma_unmap = mlx5_dma_unmap,
-               .drv_flags = PCI_DRV_FLAGS,
-       },
+static struct mlx5_class_driver mlx5_net_driver = {
+       .drv_class = MLX5_CLASS_ETH,
+       .name = RTE_STR(MLX5_ETH_DRIVER_NAME),
+       .id_table = mlx5_pci_id_map,
+       .probe = mlx5_os_net_probe,
+       .remove = mlx5_net_remove,
+       .dma_map = mlx5_net_dma_map,
+       .dma_unmap = mlx5_net_dma_unmap,
+       .probe_again = 1,
+       .intr_lsc = 1,
+       .intr_rmv = 1,
 };
 
 /* Initialize driver log type. */
@@ -2471,9 +2503,9 @@ RTE_INIT(rte_mlx5_pmd_init)
        mlx5_set_cksum_table();
        mlx5_set_swp_types_table();
        if (mlx5_glue)
-               mlx5_pci_driver_register(&mlx5_driver);
+               mlx5_class_driver_register(&mlx5_net_driver);
 }
 
-RTE_PMD_EXPORT_NAME(net_mlx5, __COUNTER__);
-RTE_PMD_REGISTER_PCI_TABLE(net_mlx5, mlx5_pci_id_map);
-RTE_PMD_REGISTER_KMOD_DEP(net_mlx5, "* ib_uverbs & mlx5_core & mlx5_ib");
+RTE_PMD_EXPORT_NAME(MLX5_ETH_DRIVER_NAME, __COUNTER__);
+RTE_PMD_REGISTER_PCI_TABLE(MLX5_ETH_DRIVER_NAME, mlx5_pci_id_map);
+RTE_PMD_REGISTER_KMOD_DEP(MLX5_ETH_DRIVER_NAME, "* ib_uverbs & mlx5_core & mlx5_ib");