[7/7] net/nfp: support setting FEC mode

Message ID 20231211030858.1693240-8-chaoyong.he@corigine.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series support link auto negotiation |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS

Commit Message

Chaoyong He Dec. 11, 2023, 3:08 a.m. UTC
  From: Zerun Fu <zerun.fu@corigine.com>

Add support for configuring FEC mode. This feature allows to set any
currently supported FEC mode.

Signed-off-by: Zerun Fu <zerun.fu@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
---
 drivers/net/nfp/nfp_ethdev.c      |  1 +
 drivers/net/nfp/nfp_net_common.c  | 54 +++++++++++++++++++++++++++++++
 drivers/net/nfp/nfp_net_common.h  |  2 ++
 drivers/net/nfp/nfpcore/nfp_nsp.h |  1 +
 4 files changed, 58 insertions(+)
  

Patch

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index e3f5fe7917..185b570892 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -761,6 +761,7 @@  static const struct eth_dev_ops nfp_net_eth_dev_ops = {
 	.flow_ops_get           = nfp_net_flow_ops_get,
 	.fec_get_capability     = nfp_net_fec_get_capability,
 	.fec_get                = nfp_net_fec_get,
+	.fec_set                = nfp_net_fec_set,
 };
 
 static inline void
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 063c048675..eeb0aaae26 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -2386,3 +2386,57 @@  nfp_net_fec_get(struct rte_eth_dev *dev,
 
 	return 0;
 }
+
+static enum nfp_eth_fec
+nfp_net_fec_rte_to_nfp(uint32_t fec)
+{
+	switch (fec) {
+	case RTE_BIT32(RTE_ETH_FEC_AUTO):
+		return NFP_FEC_AUTO_BIT;
+	case RTE_BIT32(RTE_ETH_FEC_NOFEC):
+		return NFP_FEC_DISABLED_BIT;
+	case RTE_BIT32(RTE_ETH_FEC_RS):
+		return NFP_FEC_REED_SOLOMON_BIT;
+	case RTE_BIT32(RTE_ETH_FEC_BASER):
+		return NFP_FEC_BASER_BIT;
+	default:
+		return NFP_FEC_INVALID_BIT;
+	}
+}
+
+int
+nfp_net_fec_set(struct rte_eth_dev *dev,
+		uint32_t fec_capa)
+{
+	enum nfp_eth_fec fec;
+	struct nfp_net_hw *hw;
+	uint32_t supported_fec;
+	struct nfp_eth_table *nfp_eth_table;
+	struct nfp_eth_table_port *eth_port;
+
+	hw = nfp_net_get_hw(dev);
+	if (hw->pf_dev == NULL)
+		return -EINVAL;
+
+	nfp_eth_table = hw->pf_dev->nfp_eth_table;
+	eth_port = &nfp_eth_table->ports[hw->idx];
+
+	supported_fec = nfp_eth_supported_fec_modes(eth_port);
+	if (supported_fec == 0) {
+		PMD_DRV_LOG(ERR, "NFP can not support FEC.");
+		return -ENOTSUP;
+	}
+
+	fec = nfp_net_fec_rte_to_nfp(fec_capa);
+	if (fec == NFP_FEC_INVALID_BIT) {
+		PMD_DRV_LOG(ERR, "FEC modes is invalid.");
+		return -EINVAL;
+	}
+
+	if ((RTE_BIT32(fec) & supported_fec) == 0) {
+		PMD_DRV_LOG(ERR, "Unsupported FEC mode is set.");
+		return -EIO;
+	}
+
+	return nfp_eth_set_fec(hw->cpp, eth_port->index, fec);
+}
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index fa88323b7c..66c900e3b8 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -293,6 +293,8 @@  int nfp_net_fec_get_capability(struct rte_eth_dev *dev,
 		unsigned int num);
 int nfp_net_fec_get(struct rte_eth_dev *dev,
 		uint32_t *fec_capa);
+int nfp_net_fec_set(struct rte_eth_dev *dev,
+		uint32_t fec_capa);
 
 #define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\
 	((struct nfp_app_fw_nic *)app_fw_priv)
diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h
index 41e8402154..2ce05c2ec9 100644
--- a/drivers/net/nfp/nfpcore/nfp_nsp.h
+++ b/drivers/net/nfp/nfpcore/nfp_nsp.h
@@ -100,6 +100,7 @@  enum nfp_eth_fec {
 	NFP_FEC_BASER_BIT,
 	NFP_FEC_REED_SOLOMON_BIT,
 	NFP_FEC_DISABLED_BIT,
+	NFP_FEC_INVALID_BIT,
 };
 
 #define NFP_FEC_AUTO            RTE_BIT32(NFP_FEC_AUTO_BIT)