DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jiawen Wu <jiawenwu@trustnetic.com>
To: dev@dpdk.org
Cc: Jiawen Wu <jiawenwu@trustnetic.com>
Subject: [dpdk-dev] [PATCH v1 06/20] net/txgbe: get link status of VF device
Date: Fri, 22 Jan 2021 17:47:46 +0800	[thread overview]
Message-ID: <20210122094800.197748-7-jiawenwu@trustnetic.com> (raw)
In-Reply-To: <20210122094800.197748-1-jiawenwu@trustnetic.com>

Add support to get link speed, duplex mode and state of VF device.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 doc/guides/nics/features/txgbe_vf.ini |   1 +
 drivers/net/txgbe/base/txgbe_vf.c     | 100 ++++++++++++++++++++++++++
 drivers/net/txgbe/base/txgbe_vf.h     |   2 +
 drivers/net/txgbe/txgbe_ethdev_vf.c   |   9 +++
 4 files changed, 112 insertions(+)

diff --git a/doc/guides/nics/features/txgbe_vf.ini b/doc/guides/nics/features/txgbe_vf.ini
index 574287cc7..4f1f801d3 100644
--- a/doc/guides/nics/features/txgbe_vf.ini
+++ b/doc/guides/nics/features/txgbe_vf.ini
@@ -4,6 +4,7 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
 Rx interrupt         = Y
 CRC offload          = P
 VLAN offload         = P
diff --git a/drivers/net/txgbe/base/txgbe_vf.c b/drivers/net/txgbe/base/txgbe_vf.c
index bcd34bfa2..5183c0ac7 100644
--- a/drivers/net/txgbe/base/txgbe_vf.c
+++ b/drivers/net/txgbe/base/txgbe_vf.c
@@ -27,6 +27,9 @@ s32 txgbe_init_ops_vf(struct txgbe_hw *hw)
 	mac->stop_hw = txgbe_stop_hw_vf;
 	mac->negotiate_api_version = txgbevf_negotiate_api_version;
 
+	/* Link */
+	mac->check_link = txgbe_check_mac_link_vf;
+
 	/* RAR, Multicast, VLAN */
 	mac->set_rar = txgbe_set_rar_vf;
 	mac->set_uc_addr = txgbevf_set_uc_addr_vf;
@@ -297,6 +300,103 @@ s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
 	return ret_val;
 }
 
+/**
+ *  txgbe_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 txgbe_check_mac_link_vf(struct txgbe_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 = wait_to_complete == 0;
+	struct txgbe_mbx_info *mbx = &hw->mbx;
+	struct txgbe_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, TXGBE_VFSTATUS);
+	if (!(links_reg & TXGBE_VFSTATUS_UP))
+		goto out;
+
+	/* for SFP+ modules and DA cables it can take up to 500usecs
+	 * before the link status is correct
+	 */
+	if (mac->type == txgbe_mac_raptor_vf && wait_to_complete) {
+		if (po32m(hw, TXGBE_VFSTATUS, TXGBE_VFSTATUS_UP,
+			0, NULL, 5, 100))
+			goto out;
+	}
+
+	switch (links_reg & TXGBE_VFSTATUS_BW_MASK) {
+	case TXGBE_VFSTATUS_BW_10G:
+		*speed = TXGBE_LINK_SPEED_10GB_FULL;
+		break;
+	case TXGBE_VFSTATUS_BW_1G:
+		*speed = TXGBE_LINK_SPEED_1GB_FULL;
+		break;
+	case TXGBE_VFSTATUS_BW_100M:
+		*speed = TXGBE_LINK_SPEED_100M_FULL;
+		break;
+	default:
+		*speed = TXGBE_LINK_SPEED_UNKNOWN;
+	}
+
+	if (no_pflink_check) {
+		if (*speed == TXGBE_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 & TXGBE_VT_MSGTYPE_CTS)) {
+		/* msg is not CTS and is NACK we must have lost CTS status */
+		if (in_msg & TXGBE_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;
+}
+
 /**
  *  txgbevf_negotiate_api_version - Negotiate supported API version
  *  @hw: pointer to the HW structure
diff --git a/drivers/net/txgbe/base/txgbe_vf.h b/drivers/net/txgbe/base/txgbe_vf.h
index f8c6532f6..f40a8f084 100644
--- a/drivers/net/txgbe/base/txgbe_vf.h
+++ b/drivers/net/txgbe/base/txgbe_vf.h
@@ -15,6 +15,8 @@ s32 txgbe_start_hw_vf(struct txgbe_hw *hw);
 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw);
 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw);
 s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr);
+s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
+			    bool *link_up, bool autoneg_wait_to_complete);
 s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
 		     u32 enable_addr);
 s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr);
diff --git a/drivers/net/txgbe/txgbe_ethdev_vf.c b/drivers/net/txgbe/txgbe_ethdev_vf.c
index 5e0297da7..3936f41b4 100644
--- a/drivers/net/txgbe/txgbe_ethdev_vf.c
+++ b/drivers/net/txgbe/txgbe_ethdev_vf.c
@@ -18,6 +18,8 @@
 #define TXGBEVF_PMD_NAME "rte_txgbevf_pmd" /* PMD name */
 static int txgbevf_dev_info_get(struct rte_eth_dev *dev,
 				 struct rte_eth_dev_info *dev_info);
+static int txgbevf_dev_link_update(struct rte_eth_dev *dev,
+				   int wait_to_complete);
 static int txgbevf_dev_close(struct rte_eth_dev *dev);
 static void txgbevf_intr_disable(struct rte_eth_dev *dev);
 static void txgbevf_intr_enable(struct rte_eth_dev *dev);
@@ -321,6 +323,12 @@ txgbevf_dev_info_get(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+txgbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
+{
+	return txgbe_dev_link_update_share(dev, wait_to_complete);
+}
+
 /*
  * Virtual Function operations
  */
@@ -656,6 +664,7 @@ txgbevf_dev_interrupt_handler(void *param)
  * operation have been implemented
  */
 static const struct eth_dev_ops txgbevf_eth_dev_ops = {
+	.link_update          = txgbevf_dev_link_update,
 	.dev_infos_get        = txgbevf_dev_info_get,
 	.rx_queue_intr_enable = txgbevf_dev_rx_queue_intr_enable,
 	.rx_queue_intr_disable = txgbevf_dev_rx_queue_intr_disable,
-- 
2.27.0




  parent reply	other threads:[~2021-01-22  9:48 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22  9:47 [dpdk-dev] [PATCH v1 00/20] net/txgbe: add VF driver support Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 01/20] net/txgbe: add ethdev probe and remove for VF device Jiawen Wu
2021-02-02 17:48   ` Ferruh Yigit
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 02/20] net/txgbe: add base code for VF driver Jiawen Wu
2021-02-02 17:51   ` Ferruh Yigit
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 03/20] net/txgbe: support add and remove VF device MAC address Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 04/20] net/txgbe: get VF device information Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 05/20] net/txgbe: add interrupt operation for VF device Jiawen Wu
2021-02-02 17:49   ` Ferruh Yigit
2021-01-22  9:47 ` Jiawen Wu [this message]
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 07/20] net/txgbe: add Rx and Tx unit init " Jiawen Wu
2021-02-02 17:49   ` Ferruh Yigit
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 08/20] net/txgbe: add VF device stats and xstats get operation Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 09/20] net/txgbe: add VLAN handle support to VF driver Jiawen Wu
2021-02-02 17:52   ` Ferruh Yigit
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 10/20] net/txgbe: add RSS support for VF device Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 11/20] net/txgbe: add VF device promiscuous and allmulticast mode Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 12/20] net/txgbe: support multicast MAC filter for VF driver Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 13/20] net/txgbe: support to update MTU on VF device Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 14/20] net/txgbe: support register dump " Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 15/20] net/txgbe: start and stop " Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 16/20] net/txgbe: add some supports as PF driver implemented Jiawen Wu
2021-02-02 17:50   ` Ferruh Yigit
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 17/20] net/txgbe: support VF representor Jiawen Wu
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 18/20] net/txgbe: hardware support for " Jiawen Wu
2021-02-02 17:50   ` Ferruh Yigit
2021-01-22  9:47 ` [dpdk-dev] [PATCH v1 19/20] net/txgbe: support VLAN filter " Jiawen Wu
2021-01-22  9:48 ` [dpdk-dev] [PATCH v1 20/20] doc: update release note for txgbe Jiawen Wu
2021-02-02 17:50   ` Ferruh Yigit
2021-02-02 18:07 ` [dpdk-dev] [PATCH v1 00/20] net/txgbe: add VF driver support Ferruh Yigit
2021-02-03  7:48   ` Jiawen Wu
2021-02-10 13:24     ` Ferruh Yigit

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=20210122094800.197748-7-jiawenwu@trustnetic.com \
    --to=jiawenwu@trustnetic.com \
    --cc=dev@dpdk.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).