net/mlx5: support sub-function representor
[dpdk.git] / drivers / net / mlx5 / linux / mlx5_ethdev_os.c
index 7256c1b..2127fcf 100644 (file)
@@ -24,8 +24,7 @@
 #include <sys/un.h>
 #include <time.h>
 
-#include <rte_atomic.h>
-#include <rte_ethdev_driver.h>
+#include <ethdev_driver.h>
 #include <rte_bus_pci.h>
 #include <rte_mbuf.h>
 #include <rte_common.h>
@@ -144,13 +143,17 @@ struct ethtool_link_settings {
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 int
-mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE])
+mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[MLX5_NAMESIZE])
 {
        struct mlx5_priv *priv = dev->data->dev_private;
        unsigned int ifindex;
 
        MLX5_ASSERT(priv);
        MLX5_ASSERT(priv->sh);
+       if (priv->bond_ifindex > 0) {
+               memcpy(ifname, priv->bond_name, MLX5_NAMESIZE);
+               return 0;
+       }
        ifindex = mlx5_ifindex(dev);
        if (!ifindex) {
                if (!priv->representor)
@@ -402,7 +405,7 @@ mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev,
        }
        link_speed = ethtool_cmd_speed(&edata);
        if (link_speed == -1)
-               dev_link.link_speed = ETH_SPEED_NUM_NONE;
+               dev_link.link_speed = ETH_SPEED_NUM_UNKNOWN;
        else
                dev_link.link_speed = link_speed;
        priv->link_speed_capa = 0;
@@ -422,11 +425,6 @@ mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev,
                                ETH_LINK_HALF_DUPLEX : ETH_LINK_FULL_DUPLEX);
        dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
                        ETH_LINK_SPEED_FIXED);
-       if (((dev_link.link_speed && !dev_link.link_status) ||
-            (!dev_link.link_speed && dev_link.link_status))) {
-               rte_errno = EAGAIN;
-               return -rte_errno;
-       }
        *link = dev_link;
        return 0;
 }
@@ -514,8 +512,8 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev,
                        dev->data->port_id, strerror(rte_errno));
                return ret;
        }
-       dev_link.link_speed = (ecmd->speed == UINT32_MAX) ? ETH_SPEED_NUM_NONE :
-                                                           ecmd->speed;
+       dev_link.link_speed = (ecmd->speed == UINT32_MAX) ?
+                               ETH_SPEED_NUM_UNKNOWN : ecmd->speed;
        sc = ecmd->link_mode_masks[0] |
                ((uint64_t)ecmd->link_mode_masks[1] << 32);
        priv->link_speed_capa = 0;
@@ -568,11 +566,6 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev,
                                ETH_LINK_HALF_DUPLEX : ETH_LINK_FULL_DUPLEX);
        dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
                                  ETH_LINK_SPEED_FIXED);
-       if (((dev_link.link_speed && !dev_link.link_status) ||
-            (!dev_link.link_speed && dev_link.link_status))) {
-               rte_errno = EAGAIN;
-               return -rte_errno;
-       }
        *link = dev_link;
        return 0;
 }
@@ -1017,9 +1010,14 @@ mlx5_sysfs_check_switch_info(bool device_dir,
        case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
                /* Fallthrough */
        case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
+               /* Fallthrough */
+       case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
                /* New representors naming schema. */
                switch_info->representor = 1;
                break;
+       default:
+               switch_info->master = device_dir;
+               break;
        }
 }
 
@@ -1101,6 +1099,58 @@ mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info)
        return 0;
 }
 
+/**
+ * Get bond information associated with network interface.
+ *
+ * @param pf_ifindex
+ *   Network interface index of bond slave interface
+ * @param[out] ifindex
+ *   Pointer to bond ifindex.
+ * @param[out] ifname
+ *   Pointer to bond ifname.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_sysfs_bond_info(unsigned int pf_ifindex, unsigned int *ifindex,
+                    char *ifname)
+{
+       char name[IF_NAMESIZE];
+       FILE *file;
+       unsigned int index;
+       int ret;
+
+       if (!if_indextoname(pf_ifindex, name) || !strlen(name)) {
+               rte_errno = errno;
+               return -rte_errno;
+       }
+       MKSTR(bond_if, "/sys/class/net/%s/master/ifindex", name);
+       /* read bond ifindex */
+       file = fopen(bond_if, "rb");
+       if (file == NULL) {
+               rte_errno = errno;
+               return -rte_errno;
+       }
+       ret = fscanf(file, "%u", &index);
+       fclose(file);
+       if (ret <= 0) {
+               rte_errno = errno;
+               return -rte_errno;
+       }
+       if (ifindex)
+               *ifindex = index;
+
+       /* read bond device name from symbol link */
+       if (ifname) {
+               if (!if_indextoname(index, ifname)) {
+                       rte_errno = errno;
+                       return -rte_errno;
+               }
+       }
+       return 0;
+}
+
 /**
  * DPDK callback to retrieve plug-in module EEPROM information (type and size).
  *
@@ -1270,71 +1320,71 @@ mlx5_os_get_stats_n(struct rte_eth_dev *dev)
 
 static const struct mlx5_counter_ctrl mlx5_counters_init[] = {
        {
-               .dpdk_name = "rx_port_unicast_bytes",
+               .dpdk_name = "rx_unicast_bytes",
                .ctr_name = "rx_vport_unicast_bytes",
        },
        {
-               .dpdk_name = "rx_port_multicast_bytes",
+               .dpdk_name = "rx_multicast_bytes",
                .ctr_name = "rx_vport_multicast_bytes",
        },
        {
-               .dpdk_name = "rx_port_broadcast_bytes",
+               .dpdk_name = "rx_broadcast_bytes",
                .ctr_name = "rx_vport_broadcast_bytes",
        },
        {
-               .dpdk_name = "rx_port_unicast_packets",
+               .dpdk_name = "rx_unicast_packets",
                .ctr_name = "rx_vport_unicast_packets",
        },
        {
-               .dpdk_name = "rx_port_multicast_packets",
+               .dpdk_name = "rx_multicast_packets",
                .ctr_name = "rx_vport_multicast_packets",
        },
        {
-               .dpdk_name = "rx_port_broadcast_packets",
+               .dpdk_name = "rx_broadcast_packets",
                .ctr_name = "rx_vport_broadcast_packets",
        },
        {
-               .dpdk_name = "tx_port_unicast_bytes",
+               .dpdk_name = "tx_unicast_bytes",
                .ctr_name = "tx_vport_unicast_bytes",
        },
        {
-               .dpdk_name = "tx_port_multicast_bytes",
+               .dpdk_name = "tx_multicast_bytes",
                .ctr_name = "tx_vport_multicast_bytes",
        },
        {
-               .dpdk_name = "tx_port_broadcast_bytes",
+               .dpdk_name = "tx_broadcast_bytes",
                .ctr_name = "tx_vport_broadcast_bytes",
        },
        {
-               .dpdk_name = "tx_port_unicast_packets",
+               .dpdk_name = "tx_unicast_packets",
                .ctr_name = "tx_vport_unicast_packets",
        },
        {
-               .dpdk_name = "tx_port_multicast_packets",
+               .dpdk_name = "tx_multicast_packets",
                .ctr_name = "tx_vport_multicast_packets",
        },
        {
-               .dpdk_name = "tx_port_broadcast_packets",
+               .dpdk_name = "tx_broadcast_packets",
                .ctr_name = "tx_vport_broadcast_packets",
        },
        {
-               .dpdk_name = "rx_wqe_err",
+               .dpdk_name = "rx_wqe_errors",
                .ctr_name = "rx_wqe_err",
        },
        {
-               .dpdk_name = "rx_crc_errors_phy",
+               .dpdk_name = "rx_phy_crc_errors",
                .ctr_name = "rx_crc_errors_phy",
        },
        {
-               .dpdk_name = "rx_in_range_len_errors_phy",
+               .dpdk_name = "rx_phy_in_range_len_errors",
                .ctr_name = "rx_in_range_len_errors_phy",
        },
        {
-               .dpdk_name = "rx_symbol_err_phy",
+               .dpdk_name = "rx_phy_symbol_errors",
                .ctr_name = "rx_symbol_err_phy",
        },
        {
-               .dpdk_name = "tx_errors_phy",
+               .dpdk_name = "tx_phy_errors",
                .ctr_name = "tx_errors_phy",
        },
        {
@@ -1343,44 +1393,44 @@ static const struct mlx5_counter_ctrl mlx5_counters_init[] = {
                .dev = 1,
        },
        {
-               .dpdk_name = "tx_packets_phy",
+               .dpdk_name = "tx_phy_packets",
                .ctr_name = "tx_packets_phy",
        },
        {
-               .dpdk_name = "rx_packets_phy",
+               .dpdk_name = "rx_phy_packets",
                .ctr_name = "rx_packets_phy",
        },
        {
-               .dpdk_name = "tx_discards_phy",
+               .dpdk_name = "tx_phy_discard_packets",
                .ctr_name = "tx_discards_phy",
        },
        {
-               .dpdk_name = "rx_discards_phy",
+               .dpdk_name = "rx_phy_discard_packets",
                .ctr_name = "rx_discards_phy",
        },
        {
-               .dpdk_name = "tx_bytes_phy",
+               .dpdk_name = "tx_phy_bytes",
                .ctr_name = "tx_bytes_phy",
        },
        {
-               .dpdk_name = "rx_bytes_phy",
+               .dpdk_name = "rx_phy_bytes",
                .ctr_name = "rx_bytes_phy",
        },
        /* Representor only */
        {
-               .dpdk_name = "rx_packets",
+               .dpdk_name = "rx_vport_packets",
                .ctr_name = "vport_rx_packets",
        },
        {
-               .dpdk_name = "rx_bytes",
+               .dpdk_name = "rx_vport_bytes",
                .ctr_name = "vport_rx_bytes",
        },
        {
-               .dpdk_name = "tx_packets",
+               .dpdk_name = "tx_vport_packets",
                .ctr_name = "vport_tx_packets",
        },
        {
-               .dpdk_name = "tx_bytes",
+               .dpdk_name = "tx_vport_bytes",
                .ctr_name = "vport_tx_bytes",
        },
 };