patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Yongseok Koh <yskoh@mellanox.com>
To: yliu@fridaylinux.org
Cc: stable@dpdk.org, shahafs@mellanox.com,
	adrien.mazarguil@6wind.com, nelio.laranjeiro@6wind.com
Subject: [dpdk-stable] [PATCH 33/67] net/mlx5: fix link status to use wait to complete
Date: Mon,  4 Jun 2018 17:10:55 -0700	[thread overview]
Message-ID: <20180605001129.13184-34-yskoh@mellanox.com> (raw)
In-Reply-To: <20180605001129.13184-1-yskoh@mellanox.com>

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

[ backported from upstream commit cfee94752b8f8f09b984335ae77b29af15b967fd ]

Wait to complete is present to let the application get a correct status
when it requires it, it should not be ignored.

Fixes: e313ef4c2fe8 ("net/mlx5: fix link state on device start")
Fixes: cb8faed7dde8 ("mlx5: support link status update")
Cc: stable@dpdk.org

Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 drivers/net/mlx5/mlx5.h        |   1 -
 drivers/net/mlx5/mlx5_defs.h   |   4 +-
 drivers/net/mlx5/mlx5_ethdev.c | 148 ++++++++++++++++-------------------------
 3 files changed, 58 insertions(+), 95 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 58713a136..75aa853f2 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -128,7 +128,6 @@ struct priv {
 	unsigned int mps:2; /* Multi-packet send mode (0: disabled). */
 	unsigned int mpw_hdr_dseg:1; /* Enable DSEGs in the title WQEBB. */
 	unsigned int cqe_comp:1; /* Whether CQE compression is enabled. */
-	unsigned int pending_alarm:1; /* An alarm is pending. */
 	unsigned int tso:1; /* Whether TSO is supported. */
 	unsigned int tunnel_en:1;
 	unsigned int isolated:1; /* Whether isolated mode is enabled. */
diff --git a/drivers/net/mlx5/mlx5_defs.h b/drivers/net/mlx5/mlx5_defs.h
index 9c740f5e1..d70635767 100644
--- a/drivers/net/mlx5/mlx5_defs.h
+++ b/drivers/net/mlx5/mlx5_defs.h
@@ -110,8 +110,8 @@
 /* Supported RSS */
 #define MLX5_RSS_HF_MASK (~(ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP))
 
-/* Maximum number of attempts to query link status before giving up. */
-#define MLX5_MAX_LINK_QUERY_ATTEMPTS 5
+/* Timeout in seconds to get a valid link status. */
+#define MLX5_LINK_STATUS_TIMEOUT 10
 
 /* Reserved address space for UAR mapping. */
 #define MLX5_UAR_SIZE (1ULL << 32)
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index d0bf5a788..18e1e534c 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -52,6 +52,7 @@
 #include <fcntl.h>
 #include <stdalign.h>
 #include <sys/un.h>
+#include <time.h>
 
 #include <rte_atomic.h>
 #include <rte_ethdev.h>
@@ -59,7 +60,6 @@
 #include <rte_mbuf.h>
 #include <rte_common.h>
 #include <rte_interrupts.h>
-#include <rte_alarm.h>
 #include <rte_malloc.h>
 
 #include "mlx5.h"
@@ -495,12 +495,15 @@ mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev)
  *
  * @param dev
  *   Pointer to Ethernet device structure.
+ * @param[out] link
+ *   Storage for current link status.
  *
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 static int
-mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev)
+mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev,
+			       struct rte_eth_link *link)
 {
 	struct priv *priv = dev->data->dev_private;
 	struct ethtool_cmd edata = {
@@ -550,14 +553,13 @@ 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 (memcmp(&dev_link, &dev->data->dev_link, sizeof(dev_link))) {
-		/* Link status changed. */
-		dev->data->dev_link = dev_link;
-		return 0;
+	if ((dev_link.link_speed && !dev_link.link_status) ||
+	    (!dev_link.link_speed && dev_link.link_status)) {
+		rte_errno = EAGAIN;
+		return -rte_errno;
 	}
-	/* Link status is still the same. */
-	rte_errno = EAGAIN;
-	return -rte_errno;
+	*link = dev_link;
+	return 0;
 }
 
 /**
@@ -565,12 +567,16 @@ mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev)
  *
  * @param dev
  *   Pointer to Ethernet device structure.
+ * @param[out] link
+ *   Storage for current link status.
  *
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 static int
-mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev)
+mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev,
+			     struct rte_eth_link *link)
+
 {
 	struct priv *priv = dev->data->dev_private;
 	struct ethtool_link_settings gcmd = { .cmd = ETHTOOL_GLINKSETTINGS };
@@ -656,14 +662,13 @@ 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 (memcmp(&dev_link, &dev->data->dev_link, sizeof(dev_link))) {
-		/* Link status changed. */
-		dev->data->dev_link = dev_link;
-		return 0;
+	if ((dev_link.link_speed && !dev_link.link_status) ||
+	    (!dev_link.link_speed && dev_link.link_status)) {
+		rte_errno = EAGAIN;
+		return -rte_errno;
 	}
-	/* Link status is still the same. */
-	rte_errno = EAGAIN;
-	return -rte_errno;
+	*link = dev_link;
+	return 0;
 }
 
 /**
@@ -672,20 +677,43 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev)
  * @param dev
  *   Pointer to Ethernet device structure.
  * @param wait_to_complete
- *   Wait for request completion (ignored).
+ *   Wait for request completion.
  *
  * @return
- *   0 on success, a negative errno value otherwise and rte_errno is set.
+ *   0 if link status was not updated, positive if it was, a negative errno
+ *   value otherwise and rte_errno is set.
  */
 int
-mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
+mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
 {
 	int ret;
+	struct rte_eth_link dev_link;
+	time_t start_time = time(NULL);
 
-	ret = mlx5_link_update_unlocked_gset(dev);
-	if (ret)
-		ret = mlx5_link_update_unlocked_gs(dev);
-	return 0;
+	do {
+		ret = mlx5_link_update_unlocked_gset(dev, &dev_link);
+		if (ret)
+			ret = mlx5_link_update_unlocked_gs(dev, &dev_link);
+		if (ret == 0)
+			break;
+		/* Handle wait to complete situation. */
+		if (wait_to_complete && ret == -EAGAIN) {
+			if (abs((int)difftime(time(NULL), start_time)) <
+			    MLX5_LINK_STATUS_TIMEOUT) {
+				usleep(0);
+				continue;
+			} else {
+				rte_errno = EBUSY;
+				return -rte_errno;
+			}
+		} else if (ret < 0) {
+			return ret;
+		}
+	} while (wait_to_complete);
+	ret = !!memcmp(&dev->data->dev_link, &dev_link,
+		       sizeof(struct rte_eth_link));
+	dev->data->dev_link = dev_link;
+	return ret;
 }
 
 /**
@@ -864,47 +892,6 @@ mlx5_ibv_device_to_pci_addr(const struct ibv_device *device,
 }
 
 /**
- * Update the link status.
- *
- * @param dev
- *   Pointer to Ethernet device.
- *
- * @return
- *   Zero if the callback process can be called immediately, negative errno
- *   value otherwise and rte_errno is set.
- */
-static int
-mlx5_link_status_update(struct rte_eth_dev *dev)
-{
-	struct priv *priv = dev->data->dev_private;
-	struct rte_eth_link *link = &dev->data->dev_link;
-	int ret;
-
-	ret = mlx5_link_update(dev, 0);
-	if (ret)
-		return ret;
-	if (((link->link_speed == 0) && link->link_status) ||
-		((link->link_speed != 0) && !link->link_status)) {
-		/*
-		 * Inconsistent status. Event likely occurred before the
-		 * kernel netdevice exposes the new status.
-		 */
-		if (!priv->pending_alarm) {
-			priv->pending_alarm = 1;
-			rte_eal_alarm_set(MLX5_ALARM_TIMEOUT_US,
-					  mlx5_dev_link_status_handler,
-					  priv->dev);
-		}
-		return 1;
-	} else if (unlikely(priv->pending_alarm)) {
-		/* Link interrupt occurred while alarm is already scheduled. */
-		priv->pending_alarm = 0;
-		rte_eal_alarm_cancel(mlx5_dev_link_status_handler, priv->dev);
-	}
-	return 0;
-}
-
-/**
  * Device status handler.
  *
  * @param dev
@@ -922,6 +909,10 @@ mlx5_dev_status_handler(struct rte_eth_dev *dev)
 	struct ibv_async_event event;
 	uint32_t ret = 0;
 
+	if (mlx5_link_update(dev, 0) == -EAGAIN) {
+		usleep(0);
+		return 0;
+	}
 	/* Read all message and acknowledge them. */
 	for (;;) {
 		if (ibv_get_async_event(priv->ctx, &event))
@@ -939,33 +930,10 @@ mlx5_dev_status_handler(struct rte_eth_dev *dev)
 				dev->data->port_id, event.event_type);
 		ibv_ack_async_event(&event);
 	}
-	if (ret & (1 << RTE_ETH_EVENT_INTR_LSC))
-		if (mlx5_link_status_update(dev))
-			ret &= ~(1 << RTE_ETH_EVENT_INTR_LSC);
 	return ret;
 }
 
 /**
- * Handle delayed link status event.
- *
- * @param arg
- *   Registered argument.
- */
-void
-mlx5_dev_link_status_handler(void *arg)
-{
-	struct rte_eth_dev *dev = arg;
-	struct priv *priv = dev->data->dev_private;
-	int ret;
-
-	priv->pending_alarm = 0;
-	ret = mlx5_link_status_update(dev);
-	if (!ret)
-		_rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL,
-					      NULL);
-}
-
-/**
  * Handle interrupts from the NIC.
  *
  * @param[in] intr_handle
@@ -1020,10 +988,6 @@ mlx5_dev_interrupt_handler_uninstall(struct rte_eth_dev *dev)
 	if (priv->primary_socket)
 		rte_intr_callback_unregister(&priv->intr_handle_socket,
 					     mlx5_dev_handler_socket, dev);
-	if (priv->pending_alarm) {
-		priv->pending_alarm = 0;
-		rte_eal_alarm_cancel(mlx5_dev_link_status_handler, dev);
-	}
 	priv->intr_handle.fd = 0;
 	priv->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 	priv->intr_handle_socket.fd = 0;
-- 
2.11.0

  parent reply	other threads:[~2018-06-05  0:12 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05  0:10 [dpdk-stable] [PATCH 00/67] net/mlx5: backport patches for v17.11.3 LTS Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 01/67] net/mlx5: remove get priv internal function Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 02/67] net/mlx4: store RSS hash result in mbufs Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 03/67] net/mlx5: fix synchronization on polling Rx completions Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 04/67] net/mlx5: fix allocation when no memory on device NUMA node Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 05/67] net/mlx5: fix flow director conversion Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 06/67] net/mlx5: fix reception of multiple MAC addresses Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 07/67] net/mlx5: fix secondary process mempool registration Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 08/67] net/mlx5: remove assert un-accessible from secondary process Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 09/67] net/mlx5: warn for unsuccessful memory registration Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 10/67] net/mlx5: map UAR address around huge pages Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 11/67] net/mlx4: fix single port configuration Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 12/67] net/mlx4: fix broadcast Rx Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 13/67] net/mlx4: fix removal detection of stopped port Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 14/67] net/mlx5: fix CRC strip capability query Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 15/67] net/mlx5: fix close after start failure Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 16/67] net/mlx: control netdevices through ioctl only Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 17/67] net/mlx5: fix disabling Tx packet inlining Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 18/67] net/mlx5: fix sriov flag Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 19/67] net/mlx5: name parameters in function prototypes Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 20/67] net/mlx5: mark parameters with unused attribute Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 21/67] net/mlx5: normalize function prototypes Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 22/67] net/mlx5: add missing function documentation Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 23/67] net/mlx5: remove useless empty lines Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 24/67] net/mlx5: remove control path locks Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 25/67] net/mlx5: prefix all functions with mlx5 Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 26/67] net/mlx5: change non failing function return values Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 27/67] net/mlx5: standardize on negative errno values Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 28/67] net/mlx5: use port id in PMD log Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 29/67] net/mlx5: use dynamic logging Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 30/67] net/mlx5: remove kernel version check Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 31/67] net/mlx5: change pkt burst select function prototype Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 32/67] net/mlx5: fix link status behavior Yongseok Koh
2018-06-05  0:10 ` Yongseok Koh [this message]
2018-06-05  0:10 ` [dpdk-stable] [PATCH 34/67] net/mlx5: change tunnel flow priority Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 35/67] net/mlx5: improve flow error explanation Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 36/67] net/mlx5: refuse empty VLAN flow specification Yongseok Koh
2018-06-05  0:10 ` [dpdk-stable] [PATCH 37/67] net/mlx5: fix icc build Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 38/67] net/mlx5: setup RSS regardless of queue count Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 39/67] net/mlx5: enforce RSS key length limitation Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 40/67] net/mlx5: fix RSS key length query Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 41/67] net/mlx4: fix a typo in header file Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 42/67] net/mlx5: remove 32-bit support Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 43/67] net/mlx5: remove excessive data prefetch Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 44/67] net/mlx5: fix link status initialization Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 45/67] net/mlx4: fix RSS resource leak in case of error Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 46/67] net/mlx5: fix RSS flow action bounds check Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 47/67] net/mlx5: fix invalid flow item check Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 48/67] net/mlx5: split L3/L4 in flow director Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 49/67] net/mlx5: fix flow director mask Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 50/67] net/mlx5: fix flow director rule deletion crash Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 51/67] net/mlx4: fix Rx resource leak in case of error Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 52/67] net/mlx5: fix ethtool link setting call order Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 53/67] net/mlx5: fix socket connection return value Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 54/67] net/mlx5: add data-plane debug message macro Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 55/67] net/mlx5: fix probe return value polarity Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 56/67] net/mlx5: fix flow validation Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 57/67] net/mlx4: fix UDP flow rule limitation enforcement Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 58/67] net/mlx5: fix double free on error handling Yongseok Koh
2018-06-05  0:11 ` [dpdk-stable] [PATCH 59/67] net/mlx5: fix resource leak in case of error Yongseok Koh

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=20180605001129.13184-34-yskoh@mellanox.com \
    --to=yskoh@mellanox.com \
    --cc=adrien.mazarguil@6wind.com \
    --cc=nelio.laranjeiro@6wind.com \
    --cc=shahafs@mellanox.com \
    --cc=stable@dpdk.org \
    --cc=yliu@fridaylinux.org \
    /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).