patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
To: stable@dpdk.org, Yuanhan Liu <yuanhan.liu@linux.intel.com>
Cc: "Nélio Laranjeiro" <nelio.laranjeiro@6wind.com>,
	"Adrien Mazarguil" <adrien.mazarguil@6wind.com>
Subject: [dpdk-stable] [PATCH v2 12/12] net/mlx5: fix support for newer link speeds
Date: Wed,  9 Nov 2016 10:57:51 +0100	[thread overview]
Message-ID: <df459d3d9e7bcc3c7774a619002dfaa465d4a3e8.1478683594.git.nelio.laranjeiro@6wind.com> (raw)
In-Reply-To: <cover.1478683594.git.nelio.laranjeiro@6wind.com>
In-Reply-To: <cover.1478683594.git.nelio.laranjeiro@6wind.com>

From: Nélio Laranjeiro <nelio.laranjeiro@6wind.com>

[ upstream commit 188408719888c997e813fb9fbb11e9029f1f1191 ]

Not all speed capabilities can be reported properly before Linux 4.8 (25G,
50G and 100G speeds are missing), moreover the API to retrieve them only
exists since Linux 4.5, this commit thus implements compatibility code for
all versions.

Fixes: e274f5732225 ("ethdev: add speed capabilities")

Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
---
 drivers/net/mlx5/Makefile      |  15 +++++
 drivers/net/mlx5/mlx5_ethdev.c | 123 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 135 insertions(+), 3 deletions(-)

diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile
index 2c13c30..cf87f0b 100644
--- a/drivers/net/mlx5/Makefile
+++ b/drivers/net/mlx5/Makefile
@@ -121,6 +121,21 @@ mlx5_autoconf.h.new: $(RTE_SDK)/scripts/auto-config-h.sh
 		infiniband/mlx5_hw.h \
 		enum MLX5_OPCODE_TSO \
 		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
+		HAVE_ETHTOOL_LINK_MODE_25G \
+		/usr/include/linux/ethtool.h \
+		enum ETHTOOL_LINK_MODE_25000baseCR_Full_BIT \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
+		HAVE_ETHTOOL_LINK_MODE_50G \
+		/usr/include/linux/ethtool.h \
+		enum ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
+		HAVE_ETHTOOL_LINK_MODE_100G \
+		/usr/include/linux/ethtool.h \
+		enum ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT \
+		$(AUTOCONF_OUTPUT)
 
 # Create mlx5_autoconf.h or update it in case it differs from the new one.
 
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 20c1c8a..ba1ec2a 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -626,15 +626,15 @@ mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev)
 }
 
 /**
- * DPDK callback to retrieve physical link information (unlocked version).
+ * Retrieve physical link information (unlocked version using legacy ioctl).
  *
  * @param dev
  *   Pointer to Ethernet device structure.
  * @param wait_to_complete
  *   Wait for request completion (ignored).
  */
-int
-mlx5_link_update_unlocked(struct rte_eth_dev *dev, int wait_to_complete)
+static int
+mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev, int wait_to_complete)
 {
 	struct priv *priv = mlx5_get_priv(dev);
 	struct ethtool_cmd edata = {
@@ -690,6 +690,123 @@ mlx5_link_update_unlocked(struct rte_eth_dev *dev, int wait_to_complete)
 }
 
 /**
+ * Retrieve physical link information (unlocked version using new ioctl from
+ * Linux 4.5).
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param wait_to_complete
+ *   Wait for request completion (ignored).
+ */
+static int
+mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev, int wait_to_complete)
+{
+#ifdef ETHTOOL_GLINKSETTINGS
+	struct priv *priv = mlx5_get_priv(dev);
+	struct ethtool_link_settings edata = {
+		.cmd = ETHTOOL_GLINKSETTINGS,
+	};
+	struct ifreq ifr;
+	struct rte_eth_link dev_link;
+	uint64_t sc;
+
+	(void)wait_to_complete;
+	if (priv_ifreq(priv, SIOCGIFFLAGS, &ifr)) {
+		WARN("ioctl(SIOCGIFFLAGS) failed: %s", strerror(errno));
+		return -1;
+	}
+	memset(&dev_link, 0, sizeof(dev_link));
+	dev_link.link_status = ((ifr.ifr_flags & IFF_UP) &&
+				(ifr.ifr_flags & IFF_RUNNING));
+	ifr.ifr_data = (void *)&edata;
+	if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
+		DEBUG("ioctl(SIOCETHTOOL, ETHTOOL_GLINKSETTINGS) failed: %s",
+		      strerror(errno));
+		return -1;
+	}
+	dev_link.link_speed = edata.speed;
+	sc = edata.link_mode_masks[0] |
+		((uint64_t)edata.link_mode_masks[1] << 32);
+	priv->link_speed_capa = 0;
+	/* Link speeds available in kernel v4.5. */
+	if (sc & ETHTOOL_LINK_MODE_Autoneg_BIT)
+		priv->link_speed_capa |= ETH_LINK_SPEED_AUTONEG;
+	if (sc & (ETHTOOL_LINK_MODE_1000baseT_Full_BIT |
+		  ETHTOOL_LINK_MODE_1000baseKX_Full_BIT))
+		priv->link_speed_capa |= ETH_LINK_SPEED_1G;
+	if (sc & (ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT |
+		  ETHTOOL_LINK_MODE_10000baseKR_Full_BIT |
+		  ETHTOOL_LINK_MODE_10000baseR_FEC_BIT))
+		priv->link_speed_capa |= ETH_LINK_SPEED_10G;
+	if (sc & (ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT |
+		  ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT))
+		priv->link_speed_capa |= ETH_LINK_SPEED_20G;
+	if (sc & (ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT |
+		  ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT |
+		  ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT |
+		  ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT))
+		priv->link_speed_capa |= ETH_LINK_SPEED_40G;
+	if (sc & (ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT |
+		  ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT |
+		  ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT |
+		  ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT))
+		priv->link_speed_capa |= ETH_LINK_SPEED_56G;
+	/* Link speeds available in kernel v4.6. */
+#ifdef HAVE_ETHTOOL_LINK_MODE_25G
+	if (sc & (ETHTOOL_LINK_MODE_25000baseCR_Full_BIT |
+		  ETHTOOL_LINK_MODE_25000baseKR_Full_BIT |
+		  ETHTOOL_LINK_MODE_25000baseSR_Full_BIT))
+		priv->link_speed_capa |= ETH_LINK_SPEED_25G;
+#endif
+#ifdef HAVE_ETHTOOL_LINK_MODE_50G
+	if (sc & (ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT |
+		  ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT))
+		priv->link_speed_capa |= ETH_LINK_SPEED_50G;
+#endif
+#ifdef HAVE_ETHTOOL_LINK_MODE_100G
+	if (sc & (ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT |
+		  ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT |
+		  ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT |
+		  ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT))
+		priv->link_speed_capa |= ETH_LINK_SPEED_100G;
+#endif
+	dev_link.link_duplex = ((edata.duplex == DUPLEX_HALF) ?
+				ETH_LINK_HALF_DUPLEX : ETH_LINK_FULL_DUPLEX);
+	dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
+				  ETH_LINK_SPEED_FIXED);
+	if (memcmp(&dev_link, &dev->data->dev_link, sizeof(dev_link))) {
+		/* Link status changed. */
+		dev->data->dev_link = dev_link;
+		return 0;
+	}
+#else
+	(void)dev;
+	(void)wait_to_complete;
+#endif
+	/* Link status is still the same. */
+	return -1;
+}
+
+/**
+ * DPDK callback to retrieve physical link information (unlocked version).
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param wait_to_complete
+ *   Wait for request completion (ignored).
+ */
+int
+mlx5_link_update_unlocked(struct rte_eth_dev *dev, int wait_to_complete)
+{
+	int ret;
+
+	ret = mlx5_link_update_unlocked_gs(dev, wait_to_complete);
+	if (ret < 0)
+		ret = mlx5_link_update_unlocked_gset(dev, wait_to_complete);
+	return ret;
+}
+
+/**
  * DPDK callback to retrieve physical link information.
  *
  * @param dev
-- 
2.1.4

      parent reply	other threads:[~2016-11-09  9:58 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-08 10:36 [dpdk-stable] [PATCH 00/14] Patches for 16.07.2 stable branch Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 01/14] net/mlx5: support Mellanox OFED 3.4 Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 02/14] net/mlx5: fix possible NULL dereference in Rx path Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 03/14] net/mlx5: fix inconsistent return value in flow director Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 04/14] net/mlx5: fix Rx VLAN offload capability report Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 05/14] net/mlx5: fix removing VLAN filter Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 06/14] net/mlx5: refactor allocation of flow director queues Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 07/14] net/mlx5: fix flow director drop mode Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 08/14] net/mlx5: re-factorize functions Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 09/14] net/mlx5: fix inline logic Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 10/14] net/mlx5: fix Rx function selection Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 11/14] net/mlx5: fix link status report Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 12/14] net/mlx5: fix initialization in secondary process Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 13/14] net/mlx5: fix link speed capability information Nelio Laranjeiro
2016-11-08 10:36 ` [dpdk-stable] [PATCH 14/14] net/mlx5: fix support for newer link speeds Nelio Laranjeiro
2016-11-09  5:39 ` [dpdk-stable] [PATCH 00/14] Patches for 16.07.2 stable branch Yuanhan Liu
2016-11-09  9:38   ` Nélio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 00/12] " Nelio Laranjeiro
2016-11-09 11:01   ` Yuanhan Liu
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 01/12] net/mlx5: support Mellanox OFED 3.4 Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 02/12] net/mlx5: fix possible NULL dereference in Rx path Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 03/12] net/mlx5: fix inconsistent return value in flow director Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 04/12] net/mlx5: fix Rx VLAN offload capability report Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 05/12] net/mlx5: fix removing VLAN filter Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 06/12] net/mlx5: refactor allocation of flow director queues Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 07/12] net/mlx5: fix flow director drop mode Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 08/12] net/mlx5: re-factorize functions Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 09/12] net/mlx5: fix inline logic Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 10/12] net/mlx5: fix initialization in secondary process Nelio Laranjeiro
2016-11-09  9:57 ` [dpdk-stable] [PATCH v2 11/12] net/mlx5: fix link speed capability information Nelio Laranjeiro
2016-11-09  9:57 ` Nelio Laranjeiro [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df459d3d9e7bcc3c7774a619002dfaa465d4a3e8.1478683594.git.nelio.laranjeiro@6wind.com \
    --to=nelio.laranjeiro@6wind.com \
    --cc=adrien.mazarguil@6wind.com \
    --cc=stable@dpdk.org \
    --cc=yuanhan.liu@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).