patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Dongdong Liu <liudongdong3@huawei.com>
To: <dev@dpdk.org>, <ferruh.yigit@amd.com>, <thomas@monjalon.net>,
	<andrew.rybchenko@oktetlabs.ru>
Cc: <stable@dpdk.org>, <liudongdong3@huawei.com>,
	<haijie1@huawei.com>, Yisen Zhuang <yisen.zhuang@huawei.com>
Subject: [PATCH 7/7] net/hns3: support getting current FEC capability from firmware
Date: Sat, 8 Apr 2023 10:27:39 +0800	[thread overview]
Message-ID: <20230408022740.14522-8-liudongdong3@huawei.com> (raw)
In-Reply-To: <20230408022740.14522-1-liudongdong3@huawei.com>

From: Jie Hai <haijie1@huawei.com>

Obtain the supported FEC capability from the firmware to
enhance code compatibility.

Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_cmd.h    |  9 ++++++++-
 drivers/net/hns3/hns3_ethdev.c | 29 +++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_ethdev.h |  2 ++
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/net/hns3/hns3_cmd.h b/drivers/net/hns3/hns3_cmd.h
index a86f5116e4..fcf9bd90cb 100644
--- a/drivers/net/hns3/hns3_cmd.h
+++ b/drivers/net/hns3/hns3_cmd.h
@@ -789,6 +789,12 @@ struct hns3_sfp_type {
 #define HNS3_FIBER_LINK_SPEED_10M_BIT		BIT(7)
 #define HNS3_FIBER_LINK_SPEED_200G_BIT		BIT(8)
 
+#define HNS3_FIBER_FEC_AUTO_BIT	BIT(0)
+#define HNS3_FIBER_FEC_BASER_BIT	BIT(1)
+#define HNS3_FIBER_FEC_RS_BIT	BIT(2)
+#define HNS3_FIBER_FEC_LLRS_BIT	BIT(3)
+#define HNS3_FIBER_FEC_NOFEC_BIT	BIT(4)
+
 struct hns3_sfp_info_cmd {
 	uint32_t sfp_speed;
 	uint8_t query_type; /* 0: sfp speed, 1: active */
@@ -798,7 +804,8 @@ struct hns3_sfp_info_cmd {
 	uint8_t autoneg_ability;
 	uint32_t supported_speed; /* speed supported by current media */
 	uint32_t module_type;
-	uint8_t rsv1[8];
+	uint8_t fec_ability; /* supported fec modes, see HNS3_FIBER_FEC_XXX_BIT */
+	uint8_t rsv1[7];
 };
 
 #define HNS3_MAC_CFG_FEC_AUTO_EN_B	0
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 8f998947c6..7a6c1308ac 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -4013,6 +4013,7 @@ hns3_get_sfp_info(struct hns3_hw *hw, struct hns3_mac *mac_info)
 		mac_info->support_autoneg = resp->autoneg_ability;
 		mac_info->link_autoneg = (resp->autoneg == 0) ? RTE_ETH_LINK_FIXED
 					: RTE_ETH_LINK_AUTONEG;
+		mac_info->fec_capa = resp->fec_ability;
 	} else {
 		mac_info->query_type = HNS3_DEFAULT_QUERY;
 	}
@@ -4095,6 +4096,7 @@ hns3_update_fiber_link_info(struct hns3_hw *hw)
 		mac->supported_speed = mac_info.supported_speed;
 		mac->support_autoneg = mac_info.support_autoneg;
 		mac->link_autoneg = mac_info.link_autoneg;
+		mac->fec_capa = mac_info.fec_capa;
 
 		return 0;
 	}
@@ -6124,11 +6126,38 @@ hns3_set_fec_hw(struct hns3_hw *hw, uint32_t mode)
 	return ret;
 }
 
+static uint32_t
+hns3_parse_hw_fec_capa(uint8_t hw_fec_capa)
+{
+	const struct {
+		uint32_t hw_fec_capa;
+		uint32_t fec_capa;
+	} fec_capa_map[] = {
+		{ HNS3_FIBER_FEC_AUTO_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) },
+		{ HNS3_FIBER_FEC_BASER_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(BASER) },
+		{ HNS3_FIBER_FEC_RS_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(RS) },
+		{ HNS3_FIBER_FEC_LLRS_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(LLRS) },
+		{ HNS3_FIBER_FEC_NOFEC_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) },
+	};
+	uint32_t capa = 0;
+	uint32_t i;
+
+	for (i = 0; i < RTE_DIM(fec_capa_map); i++) {
+		if ((hw_fec_capa & fec_capa_map[i].hw_fec_capa) != 0)
+			capa |= fec_capa_map[i].fec_capa;
+	}
+
+	return capa;
+}
+
 static uint32_t
 hns3_get_current_speed_fec_cap(struct hns3_mac *mac)
 {
 	uint32_t i;
 
+	if (mac->fec_capa != 0)
+		return hns3_parse_hw_fec_capa(mac->fec_capa);
+
 	for (i = 0; i < RTE_DIM(speed_fec_capa_tbl); i++) {
 		if (mac->link_speed == speed_fec_capa_tbl[i].speed)
 			return speed_fec_capa_tbl[i].capa;
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
index 9acc5a3d7e..ec73792d4f 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -214,6 +214,8 @@ struct hns3_mac {
 	uint32_t advertising;     /* advertised capability in the local part */
 	uint32_t lp_advertising; /* advertised capability in the link partner */
 	uint8_t support_autoneg;
+	/* current supported fec modes. see HNS3_FIBER_FEC_XXX_BIT */
+	uint32_t fec_capa;
 };
 
 struct hns3_fake_queue_data {
-- 
2.22.0


  parent reply	other threads:[~2023-04-08  2:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-08  2:27 [PATCH 0/7] add setting and querying of LLRS FEC mode Dongdong Liu
2023-04-08  2:27 ` [PATCH 1/7] net/hns3: fix fec mode for 200G ports Dongdong Liu
2023-04-08  2:27 ` [PATCH 2/7] net/hns3: fix fec mode check error Dongdong Liu
2023-04-08  2:27 ` [PATCH 3/7] net/hns3: fix missing FEC capability Dongdong Liu
2023-04-08  2:27 ` [PATCH 4/7] ethdev: introduce low latency RS FEC Dongdong Liu
2023-06-01  8:30   ` Ferruh Yigit
2023-04-08  2:27 ` [PATCH 5/7] app/testpmd: add setting and querying of LLRS FEC mode Dongdong Liu
2023-04-28  6:50   ` Singh, Aman Deep
2023-04-08  2:27 ` [PATCH 6/7] net/hns3: add LLRS FEC mode support for 200G ports Dongdong Liu
2023-04-08  2:27 ` Dongdong Liu [this message]
2023-06-01  8:30 ` [PATCH 0/7] add setting and querying of LLRS FEC mode 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=20230408022740.14522-8-liudongdong3@huawei.com \
    --to=liudongdong3@huawei.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=haijie1@huawei.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    --cc=yisen.zhuang@huawei.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 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).