[v2,1/2] net/bnxt: fix the check for validating link speed

Message ID 20200522174209.19402-2-kalesh-anakkur.purayil@broadcom.com (mailing list archive)
State Accepted, archived
Delegated to: Ajit Khaparde
Headers
Series bnxt fixes |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing fail Testing issues
ci/Intel-compilation success Compilation OK

Commit Message

Kalesh A P May 22, 2020, 5:42 p.m. UTC
  From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>

bnxt PMD uses the macro BNXT_SUPPORTED_SPEEDS to validate
the user requested speed. But this has all the speed values
supported by the PMD and is not chip specific.

The check against this macro returns success when the user
tries set the speed to 100G on a port even if the chip does
not support 100G speed.

Fixed it to use bnxt_get_speed_capabilities() to check the
supported speeds by the chip.

Fixes: 1d0704f4d793 ("net/bnxt: add device configure operation")
Cc: stable@dpdk.org

Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt.h        |  1 +
 drivers/net/bnxt/bnxt_ethdev.c |  2 +-
 drivers/net/bnxt/bnxt_hwrm.c   | 14 +++++++++-----
 3 files changed, 11 insertions(+), 6 deletions(-)
  

Patch

diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index 446764c..2c3aef6 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -780,4 +780,5 @@  void bnxt_cancel_fc_thread(struct bnxt *bp);
 void bnxt_flow_cnt_alarm_cb(void *arg);
 int bnxt_flow_stats_req(struct bnxt *bp);
 int bnxt_flow_stats_cnt(struct bnxt *bp);
+uint32_t bnxt_get_speed_capabilities(struct bnxt *bp);
 #endif
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index ae495da..e635781 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -778,7 +778,7 @@  static int bnxt_shutdown_nic(struct bnxt *bp)
  * Device configuration and status function
  */
 
-static uint32_t bnxt_get_speed_capabilities(struct bnxt *bp)
+uint32_t bnxt_get_speed_capabilities(struct bnxt *bp)
 {
 	uint32_t link_speed = bp->link_info->support_speeds;
 	uint32_t speed_capa = 0;
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index c1798b5..945bc90 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -2788,13 +2788,18 @@  static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
 		ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G | \
 		ETH_LINK_SPEED_100G | ETH_LINK_SPEED_200G)
 
-static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
+static int bnxt_validate_link_speed(struct bnxt *bp)
 {
+	uint32_t link_speed = bp->eth_dev->data->dev_conf.link_speeds;
+	uint16_t port_id = bp->eth_dev->data->port_id;
+	uint32_t link_speed_capa;
 	uint32_t one_speed;
 
 	if (link_speed == ETH_LINK_SPEED_AUTONEG)
 		return 0;
 
+	link_speed_capa = bnxt_get_speed_capabilities(bp);
+
 	if (link_speed & ETH_LINK_SPEED_FIXED) {
 		one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
 
@@ -2804,14 +2809,14 @@  static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
 				link_speed, port_id);
 			return -EINVAL;
 		}
-		if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
+		if ((one_speed & link_speed_capa) != one_speed) {
 			PMD_DRV_LOG(ERR,
 				"Unsupported advertised speed (%u) for port %u\n",
 				link_speed, port_id);
 			return -EINVAL;
 		}
 	} else {
-		if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
+		if (!(link_speed & link_speed_capa)) {
 			PMD_DRV_LOG(ERR,
 				"Unsupported advertised speeds (%u) for port %u\n",
 				link_speed, port_id);
@@ -2957,8 +2962,7 @@  int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
 	if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
 		return 0;
 
-	rc = bnxt_valid_link_speed(dev_conf->link_speeds,
-			bp->eth_dev->data->port_id);
+	rc = bnxt_validate_link_speed(bp);
 	if (rc)
 		goto error;