From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 941ADA05D3 for ; Sat, 27 Apr 2019 06:20:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6C1111B725; Sat, 27 Apr 2019 06:20:07 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 510921B71D for ; Sat, 27 Apr 2019 06:20:05 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from viacheslavo@mellanox.com) with ESMTPS (AES256-SHA encrypted); 27 Apr 2019 07:20:00 +0300 Received: from pegasus12.mtr.labs.mlnx. (pegasus12.mtr.labs.mlnx [10.210.17.40]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x3R4K0Uf025173; Sat, 27 Apr 2019 07:20:00 +0300 From: Viacheslav Ovsiienko To: dev@dpdk.org Cc: shahafs@mellanox.com Date: Sat, 27 Apr 2019 04:19:58 +0000 Message-Id: <1556338798-17768-1-git-send-email-viacheslavo@mellanox.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dpdk-dev] [PATCH] net/mlx5: inherit master link settings for representors X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190427041958.fP94lUK2QrNlaMjZP873mnWWyQ5Y5DvK4rDffwkKvdQ@z> There are some physical link settings can be queried from Ethernet devices: link status, link speed, speed capabilities, duplex mode, etc. These setting do not make a lot of sense for representors due to missing physical link. The new kernel drivers dropped query for link settings for representors causing the ioctl call to fail. This patch adds some kind of emulation of link settings to PMD - representors inherit the link parameters from the master device. The actual link status (up/down) is retrieved from the representor device. Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5_ethdev.c | 101 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 89 insertions(+), 12 deletions(-) diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index 57a6449..d1a70fc 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -628,6 +628,36 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) } /** + * Retrieve the master device for representor in the same switch domain. + * + * @param dev + * Pointer to representor Ethernet device structure. + * + * @return + * Master device structure on success, NULL otherwise. + */ + +static struct rte_eth_dev * +mlx5_find_master_dev(struct rte_eth_dev *dev) +{ + struct mlx5_priv *priv; + uint16_t port_id; + uint16_t domain_id; + + priv = dev->data->dev_private; + domain_id = priv->domain_id; + assert(priv->representor); + RTE_ETH_FOREACH_DEV_OF(port_id, dev->device) { + priv = rte_eth_devices[port_id].data->dev_private; + if (priv && + priv->master && + priv->domain_id == domain_id) + return &rte_eth_devices[port_id]; + } + return NULL; +} + +/** * DPDK callback to retrieve physical link information. * * @param dev @@ -666,10 +696,34 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) }; ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); if (ret) { - DRV_LOG(WARNING, - "port %u ioctl(SIOCETHTOOL, ETHTOOL_GSET) failed: %s", - dev->data->port_id, strerror(rte_errno)); - return ret; + if (ret == -ENOTSUP && priv->representor) { + struct rte_eth_dev *master; + + /* + * For representors we can try to inherit link + * settings from the master device. Actually + * link settings do not make a lot of sense + * for representors due to missing physical + * link. The old kernel drivers supported + * emulated settings query for representors, + * the new ones do not, so we have to add + * this code for compatibility issues. + */ + master = mlx5_find_master_dev(dev); + if (master) { + ifr = (struct ifreq) { + .ifr_data = (void *)&edata, + }; + ret = mlx5_ifreq(master, SIOCETHTOOL, &ifr); + } + } + if (ret) { + DRV_LOG(WARNING, + "port %u ioctl(SIOCETHTOOL," + " ETHTOOL_GSET) failed: %s", + dev->data->port_id, strerror(rte_errno)); + return ret; + } } link_speed = ethtool_cmd_speed(&edata); if (link_speed == -1) @@ -722,6 +776,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) struct ethtool_link_settings gcmd = { .cmd = ETHTOOL_GLINKSETTINGS }; struct ifreq ifr; struct rte_eth_link dev_link; + struct rte_eth_dev *master = NULL; uint64_t sc; int ret; @@ -740,11 +795,33 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) }; ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); if (ret) { - DRV_LOG(DEBUG, - "port %u ioctl(SIOCETHTOOL, ETHTOOL_GLINKSETTINGS)" - " failed: %s", - dev->data->port_id, strerror(rte_errno)); - return ret; + if (ret == -ENOTSUP && priv->representor) { + /* + * For representors we can try to inherit link + * settings from the master device. Actually + * link settings do not make a lot of sense + * for representors due to missing physical + * link. The old kernel drivers supported + * emulated settings query for representors, + * the new ones do not, so we have to add + * this code for compatibility issues. + */ + master = mlx5_find_master_dev(dev); + if (master) { + ifr = (struct ifreq) { + .ifr_data = (void *)&gcmd, + }; + ret = mlx5_ifreq(master, SIOCETHTOOL, &ifr); + } + } + if (ret) { + DRV_LOG(DEBUG, + "port %u ioctl(SIOCETHTOOL," + " ETHTOOL_GLINKSETTINGS) failed: %s", + dev->data->port_id, strerror(rte_errno)); + return ret; + } + } gcmd.link_mode_masks_nwords = -gcmd.link_mode_masks_nwords; @@ -755,11 +832,11 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) *ecmd = gcmd; ifr.ifr_data = (void *)ecmd; - ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); + ret = mlx5_ifreq(master ? master : dev, SIOCETHTOOL, &ifr); if (ret) { DRV_LOG(DEBUG, - "port %u ioctl(SIOCETHTOOL, ETHTOOL_GLINKSETTINGS)" - " failed: %s", + "port %u ioctl(SIOCETHTOOL," + "ETHTOOL_GLINKSETTINGS) failed: %s", dev->data->port_id, strerror(rte_errno)); return ret; } -- 1.8.3.1