net/nfp: add support reading linkspeed from port table

Message ID 20221209024359.15245-1-chaoyong.he@corigine.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/nfp: add support reading linkspeed from port table |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS

Commit Message

Chaoyong He Dec. 9, 2022, 2:43 a.m. UTC
  From: Long Wu <long.wu@corigine.com>

The NFP PMD driver retrieves the linkspeed by reading the
NFP_NET_CFG_STS_LINK register. This register is not set by all versions
of the firmware.

Add a second preferred method to read the linkspeed from the port table
instead, while keeping the old lookup method as a fallback in case that
is not supported.

Signed-off-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
---
 drivers/net/nfp/nfp_common.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
  

Comments

Ferruh Yigit Jan. 18, 2023, 3:34 p.m. UTC | #1
On 12/9/2022 2:43 AM, Chaoyong He wrote:
> From: Long Wu <long.wu@corigine.com>
> 
> The NFP PMD driver retrieves the linkspeed by reading the
> NFP_NET_CFG_STS_LINK register. This register is not set by all versions
> of the firmware.
> 
> Add a second preferred method to read the linkspeed from the port table
> instead, while keeping the old lookup method as a fallback in case that
> is not supported.
> 
> Signed-off-by: Long Wu <long.wu@corigine.com>
> Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index 71711bfa22..71f649e606 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -492,7 +492,9 @@  nfp_net_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
 {
 	struct nfp_net_hw *hw;
 	struct rte_eth_link link;
+	struct nfp_eth_table *nfp_eth_table;
 	uint32_t nn_link_status;
+	uint32_t i;
 	int ret;
 
 	static const uint32_t ls_to_ethtool[] = {
@@ -519,13 +521,28 @@  nfp_net_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
 
 	link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
 
-	nn_link_status = (nn_link_status >> NFP_NET_CFG_STS_LINK_RATE_SHIFT) &
-			 NFP_NET_CFG_STS_LINK_RATE_MASK;
+	if (hw->pf_dev != NULL) {
+		nfp_eth_table = hw->pf_dev->nfp_eth_table;
+		if (nfp_eth_table != NULL) {
+			link.link_speed = nfp_eth_table->ports[hw->idx].speed;
+			for (i = 0; i < RTE_DIM(ls_to_ethtool); i++) {
+				if (ls_to_ethtool[i] == link.link_speed)
+					break;
+			}
+			if (i == RTE_DIM(ls_to_ethtool))
+				link.link_speed = RTE_ETH_SPEED_NUM_NONE;
+		} else {
+			link.link_speed = RTE_ETH_SPEED_NUM_NONE;
+		}
+	} else {
+		nn_link_status = (nn_link_status >> NFP_NET_CFG_STS_LINK_RATE_SHIFT) &
+				NFP_NET_CFG_STS_LINK_RATE_MASK;
 
-	if (nn_link_status >= RTE_DIM(ls_to_ethtool))
-		link.link_speed = RTE_ETH_SPEED_NUM_NONE;
-	else
-		link.link_speed = ls_to_ethtool[nn_link_status];
+		if (nn_link_status >= RTE_DIM(ls_to_ethtool))
+			link.link_speed = RTE_ETH_SPEED_NUM_NONE;
+		else
+			link.link_speed = ls_to_ethtool[nn_link_status];
+	}
 
 	ret = rte_eth_linkstatus_set(dev, &link);
 	if (ret == 0) {