All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Min Hu (Connor)" <humin29@huawei.com>
To: <dev@dpdk.org>
Cc: <ferruh.yigit@intel.com>
Subject: [dpdk-dev] [PATCH 7/7] net/hns3: move the link speeds check to dev configure
Date: Sat, 17 Apr 2021 17:54:59 +0800	[thread overview]
Message-ID: <1618653299-40380-8-git-send-email-humin29@huawei.com> (raw)
In-Reply-To: <1618653299-40380-1-git-send-email-humin29@huawei.com>

From: Huisong Li <lihuisong@huawei.com>

This patch moves the check for "link_speeds" in dev_conf to dev_configure,
so that users know whether "link_speeds" is valid in advance.

Fixes: 0d90a6b8e59f ("net/hns3: support link speed autoneg for PF")
Fixes: 30b08275cb87 ("net/hns3: support fixed link speed")

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c | 57 +++++++++++++++++++++++++++++++++---------
 1 file changed, 45 insertions(+), 12 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index bcbebd0..a3ea513 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -105,6 +105,7 @@ static int hns3_remove_mc_addr(struct hns3_hw *hw,
 static int hns3_restore_fec(struct hns3_hw *hw);
 static int hns3_query_dev_fec_info(struct hns3_hw *hw);
 static int hns3_do_stop(struct hns3_adapter *hns);
+static int hns3_check_port_speed(struct hns3_hw *hw, uint32_t link_speeds);
 
 void hns3_ether_format_addr(char *buf, uint16_t size,
 			    const struct rte_ether_addr *ether_addr)
@@ -2431,6 +2432,46 @@ hns3_refresh_mtu(struct rte_eth_dev *dev, struct rte_eth_conf *conf)
 }
 
 static int
+hns3_check_link_speed(struct hns3_hw *hw, uint32_t link_speeds)
+{
+	int ret;
+
+	/*
+	 * Some hardware doesn't support auto-negotiation, but users may not
+	 * configure link_speeds (default 0), which means auto-negotiation.
+	 * In this case, a warning message need to be printed, instead of
+	 * an error.
+	 */
+	if (link_speeds == ETH_LINK_SPEED_AUTONEG &&
+	    hw->mac.support_autoneg == 0) {
+		hns3_warn(hw, "auto-negotiation is not supported, use default fixed speed!");
+		return 0;
+	}
+
+	if (link_speeds != ETH_LINK_SPEED_AUTONEG) {
+		ret = hns3_check_port_speed(hw, link_speeds);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int
+hns3_check_dev_conf(struct rte_eth_dev *dev)
+{
+	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_eth_conf *conf = &dev->data->dev_conf;
+	int ret;
+
+	ret = hns3_check_mq_mode(dev);
+	if (ret)
+		return ret;
+
+	return hns3_check_link_speed(hw, conf->link_speeds);
+}
+
+static int
 hns3_dev_configure(struct rte_eth_dev *dev)
 {
 	struct hns3_adapter *hns = dev->data->dev_private;
@@ -2465,7 +2506,7 @@ hns3_dev_configure(struct rte_eth_dev *dev)
 	}
 
 	hw->adapter_state = HNS3_NIC_CONFIGURING;
-	ret = hns3_check_mq_mode(dev);
+	ret = hns3_check_dev_conf(dev);
 	if (ret)
 		goto cfg_err;
 
@@ -5466,14 +5507,11 @@ hns3_set_fiber_port_link_speed(struct hns3_hw *hw,
 
 	/*
 	 * Some hardware doesn't support auto-negotiation, but users may not
-	 * configure link_speeds (default 0), which means auto-negotiation
-	 * In this case, a warning message need to be printed, instead of
-	 * an error.
+	 * configure link_speeds (default 0), which means auto-negotiation.
+	 * In this case, it should return success.
 	 */
-	if (cfg->autoneg) {
-		hns3_warn(hw, "auto-negotiation is not supported.");
+	if (cfg->autoneg)
 		return 0;
-	}
 
 	return hns3_cfg_mac_speed_dup(hw, cfg->speed, cfg->duplex);
 }
@@ -5514,16 +5552,11 @@ hns3_apply_link_speed(struct hns3_hw *hw)
 {
 	struct rte_eth_conf *conf = &hw->data->dev_conf;
 	struct hns3_set_link_speed_cfg cfg;
-	int ret;
 
 	memset(&cfg, 0, sizeof(struct hns3_set_link_speed_cfg));
 	cfg.autoneg = (conf->link_speeds == ETH_LINK_SPEED_AUTONEG) ?
 			ETH_LINK_AUTONEG : ETH_LINK_FIXED;
 	if (cfg.autoneg != ETH_LINK_AUTONEG) {
-		ret = hns3_check_port_speed(hw, conf->link_speeds);
-		if (ret)
-			return ret;
-
 		cfg.speed = hns3_get_link_speed(conf->link_speeds);
 		cfg.duplex = hns3_get_link_duplex(conf->link_speeds);
 	}
-- 
2.7.4


  parent reply	other threads:[~2021-04-17  9:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-17  9:54 [dpdk-dev] [PATCH 0/7] features and bugfix for hns3 PMD Min Hu (Connor)
2021-04-17  9:54 ` [dpdk-dev] [PATCH 1/7] net/hns3: check max SIMD bitwidth Min Hu (Connor)
2021-04-20  0:16   ` Ferruh Yigit
2021-04-17  9:54 ` [dpdk-dev] [PATCH 2/7] net/hns3: Rx vector add compile-time verify Min Hu (Connor)
2021-04-17  9:54 ` [dpdk-dev] [PATCH 3/7] net/hns3: remove redundant code about mbx Min Hu (Connor)
2021-04-17  9:54 ` [dpdk-dev] [PATCH 4/7] net/hns3: fix the check for DCB mode Min Hu (Connor)
2021-04-17  9:54 ` [dpdk-dev] [PATCH 5/7] net/hns3: fix the check for VMDq mode Min Hu (Connor)
2021-04-17  9:54 ` [dpdk-dev] [PATCH 6/7] net/hns3: fix FDIR lock bug Min Hu (Connor)
2021-04-17  9:54 ` Min Hu (Connor) [this message]
2021-04-20  0:42 ` [dpdk-dev] [PATCH 0/7] features and bugfix for hns3 PMD 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=1618653299-40380-8-git-send-email-humin29@huawei.com \
    --to=humin29@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@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.