All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Daly <jeffd@silicom-usa.com>
To: dev@dpdk.org
Cc: Stephen Douthit <stephend@silicom-usa.com>,
	Qiming Yang <qiming.yang@intel.com>,
	Wenjun Wu <wenjun1.wu@intel.com>
Subject: [PATCH v2 2/3] ixgbe: move periodic link service work into separate function
Date: Thu, 19 May 2022 15:37:37 -0400	[thread overview]
Message-ID: <2c2f2e569754a9cf3d07950eb67b544bfb54eece.1652988826.git.jeffd@silicom-usa.com> (raw)
In-Reply-To: <cover.1652988826.git.jeffd@silicom-usa.com>

The link update originally direct coded into the periodic service thread
and is made separate in preparation for additional SFP handling code.

Signed-off-by: Jeff Daly <jeffd@silicom-usa.com>
Suggested-by: Stephen Douthit <stephend@silicom-usa.com>
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 99 ++++++++++++++++++++++----------
 drivers/net/ixgbe/ixgbe_ethdev.h |  1 +
 2 files changed, 71 insertions(+), 29 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 81b15ad28212..f1694ef76b14 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -4131,48 +4131,89 @@ ixgbevf_check_link(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
 	return ret_val;
 }
 
-static void *
-ixgbe_dev_setup_link_thread_handler(void *param)
+static void
+ixgbe_link_service(struct rte_eth_dev *dev)
 {
-	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct ixgbe_interrupt *intr =
 		IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
-	u32 speed, start, ticks, service_ms;
+	bool link_up, autoneg = false, have_int = false;
+	u32 speed;
 	s32 err;
-	bool link_up, autoneg = false;
 
-	pthread_detach(pthread_self());
+	/* Test if we have a LSC interrupt for this platform, if not we need to
+	 * manually check the link register since IXGBE_FLAG_NEED_LINK_CONFIG
+	 * will never be set in the interrupt handler
+	 */
+#ifndef RTE_EXEC_ENV_FREEBSD
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
+	if (rte_intr_allow_others(intr_handle)) {
+		/* check if LSC interrupt is enabled */
+		if (dev->data->dev_conf.intr_conf.lsc)
+			have_int = true;
+	}
+#endif /* #ifdef RTE_EXEC_ENV_FREEBSD */
 
-	while (1) {
-		service_ms = 100;
-		if (intr->flags & IXGBE_FLAG_NEED_LINK_CONFIG) {
-			speed = hw->phy.autoneg_advertised;
+	/* Skip if we still need to setup an SFP, or if no link config requested
+	 */
+	if ((intr->flags & IXGBE_FLAG_NEED_SFP_SETUP) ||
+	    (!(intr->flags & IXGBE_FLAG_NEED_LINK_CONFIG) && have_int))
+		return;
+
+	if (!have_int && !(intr->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) {
+		err = ixgbe_check_link(hw, &speed, &link_up, 0);
+		if (!err && !link_up) {
+			intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
+			PMD_DRV_LOG(DEBUG, "Link down, no LSC, set NEED_LINK_CONFIG\n");
+		} else {
+			return;
+		}
+	}
+
+	speed = hw->phy.autoneg_advertised;
+	if (!speed)
+		ixgbe_get_link_capabilities(hw, &speed, &autoneg);
 
-			if (!speed)
-				ixgbe_get_link_capabilities(hw, &speed, &autoneg);
+	err = ixgbe_setup_link(hw, speed, true);
+	if (err) {
+		PMD_DRV_LOG(ERR, "ixgbe_setup_link failed %d\n", err);
+		return;
+	}
 
-			err = ixgbe_setup_link(hw, speed, true);
+	intr->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
+}
 
-			if (err == IXGBE_SUCCESS)
-				err = ixgbe_check_link(hw, &speed, &link_up, 0);
+static void *
+ixgbe_dev_setup_link_thread_handler(void *param)
+{
+	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
+	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	u32 speed, start, ticks, service_ms;
+	s32 err;
+	bool link_up  = false;
 
-			/* Run the service thread handler more frequently when link is
-			 * down to reduce link up latency (every 200ms vs 1s)
-			 *
-			 * Use a number of smaller sleeps to decrease exit latency when
-			 * ixgbe_dev_stop() wants this thread to join
-			 */
-			if (err == IXGBE_SUCCESS && link_up) {
-				service_ms = 2000;
-				intr->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
-			}
+	pthread_detach(pthread_self());
 
-			if (!ixgbe_dev_link_update(dev, 0)) {
-				ixgbe_dev_link_status_print(dev);
-				rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
-			}
+	while (1) {
+		ixgbe_link_service(dev);
+
+		if (!ixgbe_dev_link_update(dev, 0)) {
+			ixgbe_dev_link_status_print(dev);
+			rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
 		}
+		/* Run the service thread handler more frequently when link is
+		 * down to reduce link up latency (every 200ms vs 1s)
+		 *
+		 * Use a number of smaller sleeps to decrease exit latency when
+		 * ixgbe_dev_stop() wants this thread to join
+		 */
+
+		err = ixgbe_check_link(hw, &speed, &link_up, 0);
+		if (err == IXGBE_SUCCESS && link_up)
+			service_ms = 2000;
+		else
+			service_ms = 100;
 
 		/* Call msec_delay in a loop with several smaller sleeps to
 		 * provide periodic thread cancellation points
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 69e0e82a5b1a..4f17fabf4073 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -29,6 +29,7 @@
 #define IXGBE_FLAG_PHY_INTERRUPT    (uint32_t)(1 << 2)
 #define IXGBE_FLAG_MACSEC           (uint32_t)(1 << 3)
 #define IXGBE_FLAG_NEED_LINK_CONFIG (uint32_t)(1 << 4)
+#define IXGBE_FLAG_NEED_SFP_SETUP   ((uint32_t)(1 << 5))
 
 /*
  * Defines that were not part of ixgbe_type.h as they are not used by the
-- 
2.25.1


  parent reply	other threads:[~2022-05-19 19:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1652988826.git.jeffd@silicom-usa.com>
2022-05-19 19:37 ` [PATCH v2 1/3] ixgbe: make link update thread periodic Jeff Daly
2022-05-19 19:37 ` Jeff Daly [this message]
2022-05-19 19:37 ` [PATCH v2 3/3] ixgbe: make hotplug detection aware of changed SFPs Jeff Daly

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=2c2f2e569754a9cf3d07950eb67b544bfb54eece.1652988826.git.jeffd@silicom-usa.com \
    --to=jeffd@silicom-usa.com \
    --cc=dev@dpdk.org \
    --cc=qiming.yang@intel.com \
    --cc=stephend@silicom-usa.com \
    --cc=wenjun1.wu@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.