All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zaiyu Wang <zaiyuwang@trustnetic.com>
To: dev@dpdk.org
Cc: Zaiyu Wang <zaiyuwang@trustnetic.com>,
	Jiawen Wu <jiawenwu@trustnetic.com>
Subject: [PATCH 10/15] net/ngbe: add link update ops for VF device
Date: Thu,  9 Jan 2025 12:02:20 +0800	[thread overview]
Message-ID: <20250109040227.1016-11-zaiyuwang@trustnetic.com> (raw)
In-Reply-To: <20250109040227.1016-1-zaiyuwang@trustnetic.com>

Add support to check link feature for VF device, including link speed,
duplex mode and link state.

Signed-off-by: Zaiyu Wang <zaiyuwang@trustnetic.com>
---
 doc/guides/nics/features/ngbe_vf.ini |  1 +
 drivers/net/ngbe/base/ngbe_vf.c      | 96 ++++++++++++++++++++++++++++
 drivers/net/ngbe/base/ngbe_vf.h      |  2 +
 drivers/net/ngbe/ngbe_ethdev_vf.c    |  9 +++
 4 files changed, 108 insertions(+)

diff --git a/doc/guides/nics/features/ngbe_vf.ini b/doc/guides/nics/features/ngbe_vf.ini
index e7eaee1e44..b5c4981195 100644
--- a/doc/guides/nics/features/ngbe_vf.ini
+++ b/doc/guides/nics/features/ngbe_vf.ini
@@ -4,6 +4,7 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
 Unicast MAC filter   = Y
 Rx interrupt         = Y
 MTU update           = Y
diff --git a/drivers/net/ngbe/base/ngbe_vf.c b/drivers/net/ngbe/base/ngbe_vf.c
index d50806876f..b6556520bd 100644
--- a/drivers/net/ngbe/base/ngbe_vf.c
+++ b/drivers/net/ngbe/base/ngbe_vf.c
@@ -335,6 +335,99 @@ s32 ngbevf_set_uc_addr_vf(struct ngbe_hw *hw, u32 index, u8 *addr)
 	return ret_val;
 }
 
+/**
+ *  ngbe_check_mac_link_vf - Get link/speed status
+ *  @hw: pointer to hardware structure
+ *  @speed: pointer to link speed
+ *  @link_up: true is link is up, false otherwise
+ *  @autoneg_wait_to_complete: true when waiting for completion is needed
+ *
+ *  Reads the links register to determine if link is up and the current speed
+ **/
+s32 ngbe_check_mac_link_vf(struct ngbe_hw *hw, u32 *speed,
+			    bool *link_up, bool wait_to_complete)
+{
+	/**
+	 * for a quick link status checking, wait_to_compelet == 0,
+	 * skip PF link status checking
+	 */
+	bool no_pflink_check = 0;
+	struct ngbe_mbx_info *mbx = &hw->mbx;
+	struct ngbe_mac_info *mac = &hw->mac;
+	s32 ret_val = 0;
+	u32 links_reg;
+	u32 in_msg = 0;
+
+	UNREFERENCED_PARAMETER(wait_to_complete);
+
+	/* If we were hit with a reset drop the link */
+	if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
+		mac->get_link_status = true;
+
+	if (!mac->get_link_status)
+		goto out;
+
+	/* if link status is down no point in checking to see if pf is up */
+	links_reg = rd32(hw, NGBE_VFSTATUS);
+	if (!(links_reg & NGBE_VFSTATUS_BW_MASK))
+		goto out;
+
+	/* for SFP+ modules and DA cables it can take up to 500usecs
+	 * before the link status is correct
+	 */
+	if (mac->type == ngbe_mac_em_vf) {
+		if (po32m(hw, NGBE_VFSTATUS, NGBE_VFSTATUS_BW_MASK,
+			0, NULL, 5, 100))
+			goto out;
+	}
+
+	if (links_reg & NGBE_VFSTATUS_BW_1G)
+		*speed = NGBE_LINK_SPEED_1GB_FULL;
+	else if (links_reg & NGBE_VFSTATUS_BW_100M)
+		*speed = NGBE_LINK_SPEED_100M_FULL;
+	else if (links_reg & NGBE_VFSTATUS_BW_10M)
+		*speed = NGBE_LINK_SPEED_10M_FULL;
+	else
+		*speed = NGBE_LINK_SPEED_UNKNOWN;
+
+	if (no_pflink_check) {
+		if (*speed == NGBE_LINK_SPEED_UNKNOWN)
+			mac->get_link_status = true;
+		else
+			mac->get_link_status = false;
+
+		goto out;
+	}
+
+	/* if the read failed it could just be a mailbox collision, best wait
+	 * until we are called again and don't report an error
+	 */
+	if (mbx->read(hw, &in_msg, 1, 0))
+		goto out;
+
+	if (!(in_msg & NGBE_VT_MSGTYPE_CTS)) {
+		/* msg is not CTS and is NACK we must have lost CTS status */
+		if (in_msg & NGBE_VT_MSGTYPE_NACK)
+			ret_val = -1;
+		goto out;
+	}
+
+	/* the pf is talking, if we timed out in the past we reinit */
+	if (!mbx->timeout) {
+		ret_val = -1;
+		goto out;
+	}
+
+	/* if we passed all the tests above then the link is up and we no
+	 * longer need to check for link
+	 */
+	mac->get_link_status = false;
+
+out:
+	*link_up = !mac->get_link_status;
+	return ret_val;
+}
+
 /**
  *  ngbevf_rlpml_set_vf - Set the maximum receive packet length
  *  @hw: pointer to the HW structure
@@ -469,6 +562,9 @@ s32 ngbe_init_ops_vf(struct ngbe_hw *hw)
 	mac->get_mac_addr = ngbe_get_mac_addr_vf;
 	mac->negotiate_api_version = ngbevf_negotiate_api_version;
 
+	/* Link */
+	mac->check_link = ngbe_check_mac_link_vf;
+
 	/* RAR, Multicast, VLAN */
 	mac->set_rar = ngbe_set_rar_vf;
 	mac->set_uc_addr = ngbevf_set_uc_addr_vf;
diff --git a/drivers/net/ngbe/base/ngbe_vf.h b/drivers/net/ngbe/base/ngbe_vf.h
index 596f41dcb0..5cf225dd35 100644
--- a/drivers/net/ngbe/base/ngbe_vf.h
+++ b/drivers/net/ngbe/base/ngbe_vf.h
@@ -17,6 +17,8 @@ s32 ngbe_start_hw_vf(struct ngbe_hw *hw);
 s32 ngbe_reset_hw_vf(struct ngbe_hw *hw);
 s32 ngbe_stop_hw_vf(struct ngbe_hw *hw);
 s32 ngbe_get_mac_addr_vf(struct ngbe_hw *hw, u8 *mac_addr);
+s32 ngbe_check_mac_link_vf(struct ngbe_hw *hw, u32 *speed,
+			    bool *link_up, bool autoneg_wait_to_complete);
 s32 ngbe_set_rar_vf(struct ngbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
 		     u32 enable_addr);
 s32 ngbevf_set_uc_addr_vf(struct ngbe_hw *hw, u32 index, u8 *addr);
diff --git a/drivers/net/ngbe/ngbe_ethdev_vf.c b/drivers/net/ngbe/ngbe_ethdev_vf.c
index 7783fb6537..1f3f957d8a 100644
--- a/drivers/net/ngbe/ngbe_ethdev_vf.c
+++ b/drivers/net/ngbe/ngbe_ethdev_vf.c
@@ -20,6 +20,8 @@
 static int ngbevf_dev_info_get(struct rte_eth_dev *dev,
 				 struct rte_eth_dev_info *dev_info);
 static int ngbevf_dev_close(struct rte_eth_dev *dev);
+static int ngbevf_dev_link_update(struct rte_eth_dev *dev,
+				   int wait_to_complete);
 static void ngbevf_intr_disable(struct rte_eth_dev *dev);
 static void ngbevf_intr_enable(struct rte_eth_dev *dev);
 static int ngbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
@@ -348,6 +350,12 @@ ngbevf_dev_info_get(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+ngbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
+{
+	return ngbe_dev_link_update_share(dev, wait_to_complete);
+}
+
 static void
 ngbevf_intr_disable(struct rte_eth_dev *dev)
 {
@@ -938,6 +946,7 @@ ngbevf_dev_interrupt_handler(void *param)
  */
 static const struct eth_dev_ops ngbevf_eth_dev_ops = {
 	.dev_configure        = ngbevf_dev_configure,
+	.link_update          = ngbevf_dev_link_update,
 	.promiscuous_enable   = ngbevf_dev_promiscuous_enable,
 	.promiscuous_disable  = ngbevf_dev_promiscuous_disable,
 	.allmulticast_enable  = ngbevf_dev_allmulticast_enable,
-- 
2.21.0.windows.1



  parent reply	other threads:[~2025-01-09  4:04 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-09  4:02 [PATCH 00/15] net/ngbe: add VF driver support Zaiyu Wang
2025-01-09  4:02 ` [PATCH 01/15] net/ngbe: add ethdev probe and remove for VF device Zaiyu Wang
2025-01-09  4:02 ` [PATCH 02/15] net/ngbe: add support for PF-VF mailbox interface Zaiyu Wang
2025-01-09  4:02 ` [PATCH 03/15] net/ngbe: add hardware configuration code for VF device Zaiyu Wang
2025-01-09  4:02 ` [PATCH 04/15] net/ngbe: add promiscuous and allmulticast ops " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 05/15] net/ngbe: add set MTU " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 06/15] net/ngbe: add add/remove/set mac addr " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 07/15] net/ngbe: add datapath init code " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 08/15] net/ngbe: add vlan related ops " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 09/15] net/ngbe: add interrupt support " Zaiyu Wang
2025-01-09  4:02 ` Zaiyu Wang [this message]
2025-01-09  4:02 ` [PATCH 11/15] net/ngbe: add stats and xstats ops " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 12/15] net/ngbe: add start/stop/reset/close " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 13/15] net/ngbe: add multicast MAC filter " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 14/15] net/ngbe: add dump registers " Zaiyu Wang
2025-01-09  4:02 ` [PATCH 15/15] net/ngbe: add some ops which PF has implemented Zaiyu Wang
2025-01-10  4:17 ` [PATCH 00/15] net/ngbe: add VF driver support Stephen Hemminger
2025-01-17 10:40 ` [PATCH v2 " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 01/15] net/ngbe: add ethdev probe and remove for VF device Zaiyu Wang
2025-01-17 16:51     ` Stephen Hemminger
2025-01-20  8:29       ` Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 02/15] net/ngbe: add support for PF-VF mailbox interface Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 03/15] net/ngbe: add hardware configuration code for VF device Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 04/15] net/ngbe: add promiscuous and allmulticast ops " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 05/15] net/ngbe: add set MTU " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 06/15] net/ngbe: add add/remove/set mac addr " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 07/15] net/ngbe: add datapath init code " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 08/15] net/ngbe: add VLAN related ops " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 09/15] net/ngbe: add interrupt support " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 10/15] net/ngbe: add link update ops " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 11/15] net/ngbe: add stats and xstats " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 12/15] net/ngbe: add start/stop/reset/close " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 13/15] net/ngbe: add multicast MAC filter " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 14/15] net/ngbe: add dump registers " Zaiyu Wang
2025-01-17 10:41   ` [PATCH v2 15/15] net/ngbe: add some ops which PF has implemented Zaiyu Wang
2025-01-17 11:44 ` [PATCH v3 00/15] net/ngbe: add VF driver support Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 01/15] net/ngbe: add ethdev probe and remove for VF device Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 02/15] net/ngbe: add support for PF-VF mailbox interface Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 03/15] net/ngbe: add hardware configuration code for VF device Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 04/15] net/ngbe: add promiscuous and allmulticast ops " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 05/15] net/ngbe: add set MTU " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 06/15] net/ngbe: add add/remove/set mac addr " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 07/15] net/ngbe: add datapath init code " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 08/15] net/ngbe: add VLAN related ops " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 09/15] net/ngbe: add interrupt support " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 10/15] net/ngbe: add link update ops " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 11/15] net/ngbe: add stats and xstats " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 12/15] net/ngbe: add start/stop/reset/close " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 13/15] net/ngbe: add multicast MAC filter " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 14/15] net/ngbe: add dump registers " Zaiyu Wang
2025-01-17 11:44   ` [PATCH v3 15/15] net/ngbe: add some ops which PF has implemented Zaiyu Wang
2025-01-20  9:42 ` [PATCH v4 00/15] net/ngbe: add VF driver support Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 01/15] net/ngbe: add ethdev probe and remove for VF device Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 02/15] net/ngbe: add support for PF-VF mailbox interface Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 03/15] net/ngbe: add hardware configuration code for VF device Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 04/15] net/ngbe: add promiscuous and allmulticast ops " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 05/15] net/ngbe: add set MTU " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 06/15] net/ngbe: add add/remove/set mac addr " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 07/15] net/ngbe: add datapath init code " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 08/15] net/ngbe: add VLAN related ops " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 09/15] net/ngbe: add interrupt support " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 10/15] net/ngbe: add link update ops " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 11/15] net/ngbe: add stats and xstats " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 12/15] net/ngbe: add start/stop/reset/close " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 13/15] net/ngbe: add multicast MAC filter " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 14/15] net/ngbe: add dump registers " Zaiyu Wang
2025-01-20  9:42   ` [PATCH v4 15/15] net/ngbe: add some ops which PF has implemented Zaiyu Wang
2025-01-21 15:56   ` [PATCH v4 00/15] net/ngbe: add VF driver support Stephen Hemminger

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=20250109040227.1016-11-zaiyuwang@trustnetic.com \
    --to=zaiyuwang@trustnetic.com \
    --cc=dev@dpdk.org \
    --cc=jiawenwu@trustnetic.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.