@@ -736,6 +736,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
struct ether_addr mac;
char name[RTE_ETH_NAME_MAX_LEN];
int own_domain_id = 0;
+ struct rte_flow_error flow_error;
unsigned int i;
/* Determine if this port representor is supposed to be spawned. */
@@ -959,6 +960,8 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
priv->representor_id =
switch_info->representor ? switch_info->port_name : -1;
+ /* Interface index will be known once eth_dev is allocated. */
+ priv->ifindex = 0;
/*
* Look for sibling devices in order to reuse their switch domain
* if any, otherwise allocate one.
@@ -1087,6 +1090,16 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
err = rte_errno;
goto error;
}
+ /*
+ * Cache associated interface index since lookups are expensive.
+ * It is not expected to change while a PMD instance is bound and
+ * running.
+ */
+ priv->ifindex = mlx5_ifindex(eth_dev);
+ if (!priv->ifindex)
+ DRV_LOG(WARNING,
+ "cannot retrieve network interface index: %s",
+ strerror(rte_errno));
/* Configure the first MAC address by default. */
if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) {
DRV_LOG(ERR,
@@ -1131,32 +1144,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
if (vf && config.vf_nl_en)
mlx5_nl_mac_addr_sync(eth_dev);
priv->mnl_socket = mlx5_nl_flow_socket_create();
- if (!priv->mnl_socket) {
- err = -rte_errno;
+ if (!priv->mnl_socket ||
+ !priv->ifindex ||
+ mlx5_nl_flow_init(priv->mnl_socket, priv->ifindex, &flow_error)) {
+ if (!priv->mnl_socket) {
+ flow_error.message = "cannot open libmnl socket";
+ } else if (!priv->ifindex) {
+ rte_errno = ENXIO;
+ flow_error.message = "unknown network interface index";
+ }
DRV_LOG(WARNING,
"flow rules relying on switch offloads will not be"
- " supported: cannot open libmnl socket: %s",
- strerror(rte_errno));
- } else {
- struct rte_flow_error error;
- unsigned int ifindex = mlx5_ifindex(eth_dev);
-
- if (!ifindex) {
- err = -rte_errno;
- error.message =
- "cannot retrieve network interface index";
- } else {
- err = mlx5_nl_flow_init(priv->mnl_socket, ifindex,
- &error);
- }
- if (err) {
- DRV_LOG(WARNING,
- "flow rules relying on switch offloads will"
- " not be supported: %s: %s",
- error.message, strerror(rte_errno));
- mlx5_nl_flow_socket_destroy(priv->mnl_socket);
- priv->mnl_socket = NULL;
- }
+ " supported: %s: %s",
+ flow_error.message, strerror(rte_errno));
}
TAILQ_INIT(&priv->flows);
TAILQ_INIT(&priv->ctrl_flows);
@@ -183,6 +183,7 @@ struct priv {
unsigned int representor:1; /* Device is a port representor. */
uint16_t domain_id; /* Switch domain identifier. */
int32_t representor_id; /* Port representor identifier. */
+ unsigned int ifindex; /* Interface index associated with device. */
/* RX/TX queues. */
unsigned int rxqs_n; /* RX queues array size. */
unsigned int txqs_n; /* TX queues array size. */
@@ -511,7 +511,6 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
struct 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;
@@ -532,8 +531,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 = priv->ifindex;
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;
@@ -2466,13 +2466,13 @@ mlx5_flow_merge_switch(struct rte_eth_dev *dev,
n = RTE_MIN(mlx5_dev_to_port_id(dev->device, port_id, n), n);
}
for (i = 0; i != n; ++i) {
- struct rte_eth_dev_info dev_info;
+ struct rte_eth_dev *i_dev = &rte_eth_devices[port_id[i]];
+ struct priv *i_priv = i_dev->data->dev_private;
- rte_eth_dev_info_get(port_id[i], &dev_info);
if (port_id[i] == dev->data->port_id)
own = i;
ptoi[i].port_id = port_id[i];
- ptoi[i].ifindex = dev_info.if_index;
+ ptoi[i].ifindex = i_priv->ifindex;
}
/* Ensure first entry of ptoi[] is the current device. */
if (own) {
@@ -362,7 +362,6 @@ mlx5_nl_mac_addr_list(struct rte_eth_dev *dev, struct ether_addr (*mac)[],
int *mac_n)
{
struct priv *priv = dev->data->dev_private;
- unsigned int iface_idx = mlx5_ifindex(dev);
struct {
struct nlmsghdr hdr;
struct ifinfomsg ifm;
@@ -374,7 +373,7 @@ mlx5_nl_mac_addr_list(struct rte_eth_dev *dev, struct ether_addr (*mac)[],
},
.ifm = {
.ifi_family = PF_BRIDGE,
- .ifi_index = iface_idx,
+ .ifi_index = priv->ifindex,
},
};
struct mlx5_nl_mac_addr data = {
@@ -421,7 +420,6 @@ mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct ether_addr *mac,
int add)
{
struct priv *priv = dev->data->dev_private;
- unsigned int iface_idx = mlx5_ifindex(dev);
struct {
struct nlmsghdr hdr;
struct ndmsg ndm;
@@ -437,7 +435,7 @@ mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct ether_addr *mac,
.ndm = {
.ndm_family = PF_BRIDGE,
.ndm_state = NUD_NOARP | NUD_PERMANENT,
- .ndm_ifindex = iface_idx,
+ .ndm_ifindex = priv->ifindex,
.ndm_flags = NTF_SELF,
},
.rta = {
@@ -600,7 +598,6 @@ static int
mlx5_nl_device_flags(struct rte_eth_dev *dev, uint32_t flags, int enable)
{
struct priv *priv = dev->data->dev_private;
- unsigned int iface_idx = mlx5_ifindex(dev);
struct {
struct nlmsghdr hdr;
struct ifinfomsg ifi;
@@ -613,7 +610,7 @@ mlx5_nl_device_flags(struct rte_eth_dev *dev, uint32_t flags, int enable)
.ifi = {
.ifi_flags = enable ? flags : 0,
.ifi_change = flags,
- .ifi_index = iface_idx,
+ .ifi_index = priv->ifindex,
},
};
int fd;