]> git.droids-corp.org - dpdk.git/commitdiff
net/mlx5: cache associated network device index
authorViacheslav Ovsiienko <viacheslavo@mellanox.com>
Sun, 21 Jul 2019 14:56:40 +0000 (14:56 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 23 Jul 2019 12:31:36 +0000 (14:31 +0200)
The associated device index is retrieved via Netlink request to
underlying Infiniband device driver. This network device index
is permanent throughout the lifetime of device. We do not
spawn the rte_eth_dev ports without associated network device, and
if network device is being unbound we get the remove notification
message and rte_eth_dev port is also detached. So, we may store
the ifindex in mlx5_device_spawn() routine at rte_eth_dev port
creation and initialization time and use the cached value further
instead of doing actual Netlink request.

Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_ethdev.c

index 33ca36d29a0b58548e07195ec2a63b11da269327..5538f925893fae2180577f8b919338860e5fca95 100644 (file)
@@ -1706,6 +1706,13 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
                eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
                eth_dev->data->representor_id = priv->representor_id;
        }
+       /*
+        * Store associated network device interface index. This index
+        * is permanent throughout the lifetime of device. So, we may store
+        * the ifindex here and use the cached value further.
+        */
+       assert(spawn->ifindex);
+       priv->if_index = spawn->ifindex;
        eth_dev->data->dev_private = priv;
        priv->dev_data = eth_dev->data;
        eth_dev->data->mac_addrs = priv->mac;
index 7aad94d93ff4c864e4109700f956a1eb41d99379..5fe3cf926af8ab1b3f82b0f8530942da3ad398f3 100644 (file)
@@ -466,6 +466,7 @@ struct mlx5_priv {
        uint16_t domain_id; /* Switch domain identifier. */
        uint16_t vport_id; /* Associated VF vport index (if any). */
        int32_t representor_id; /* Port representor identifier. */
+       unsigned int if_index; /* Associated kernel network device index. */
        /* RX/TX queues. */
        unsigned int rxqs_n; /* RX queues array size. */
        unsigned int txqs_n; /* TX queues array size. */
index 6c9bcf13f32320b74979c1997193e5307454ea82..dfd9e974b98a3060be50dc798e1a7bc1ffb5ba3e 100644 (file)
@@ -225,10 +225,7 @@ mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE])
 
        assert(priv);
        assert(priv->sh);
-       ifindex = priv->nl_socket_rdma >= 0 ?
-                 mlx5_nl_ifindex(priv->nl_socket_rdma,
-                                 priv->sh->ibdev_name,
-                                 priv->ibv_port) : 0;
+       ifindex = mlx5_ifindex(dev);
        if (!ifindex) {
                if (!priv->representor)
                        return mlx5_get_master_ifname(priv->sh->ibdev_path,
@@ -299,14 +296,14 @@ mlx5_get_ifname_base(const struct rte_eth_dev *base,
 unsigned int
 mlx5_ifindex(const struct rte_eth_dev *dev)
 {
-       char ifname[IF_NAMESIZE];
+       struct mlx5_priv *priv = dev->data->dev_private;
        unsigned int ifindex;
 
-       if (mlx5_get_ifname(dev, &ifname))
-               return 0;
-       ifindex = if_nametoindex(ifname);
+       assert(priv);
+       assert(priv->if_index);
+       ifindex = priv->if_index;
        if (!ifindex)
-               rte_errno = errno;
+               rte_errno = ENXIO;
        return ifindex;
 }
 
@@ -641,7 +638,6 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
        struct mlx5_priv *priv = dev->data->dev_private;
        struct mlx5_dev_config *config = &priv->config;
        unsigned int max;
-       char ifname[IF_NAMESIZE];
 
        /* FIXME: we should ask the device for these values. */
        info->min_rx_bufsize = 32;
@@ -662,8 +658,7 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
        info->rx_offload_capa = (mlx5_get_rx_port_offloads() |
                                 info->rx_queue_offload_capa);
        info->tx_offload_capa = mlx5_get_tx_port_offloads(dev);
-       if (mlx5_get_ifname(dev, &ifname) == 0)
-               info->if_index = if_nametoindex(ifname);
+       info->if_index = mlx5_ifindex(dev);
        info->reta_size = priv->reta_idx_n ?
                priv->reta_idx_n : config->ind_table_max_size;
        info->hash_key_size = MLX5_RSS_HASH_KEY_LEN;