[02/10] net/nfp: add a check function for the NFD version

Message ID 20230607015709.336420-3-chaoyong.he@corigine.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series support rte_flow for flower firmware with NFDk |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He June 7, 2023, 1:57 a.m. UTC
  Add a check function for the NFD version, this will make the logics
which using this version free from validaty check, thus simplify
the driver.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
---
 drivers/net/nfp/flower/nfp_flower.c |  3 +++
 drivers/net/nfp/nfp_common.c        | 37 ++++++++++++++++++-----------
 drivers/net/nfp/nfp_common.h        |  1 +
 drivers/net/nfp/nfp_ethdev.c        | 35 +++++++++------------------
 drivers/net/nfp/nfp_ethdev_vf.c     | 32 ++++++++-----------------
 drivers/net/nfp/nfp_rxtx.c          | 14 ++---------
 6 files changed, 50 insertions(+), 72 deletions(-)
  

Patch

diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c
index c5cc537790..afb4e5b344 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -649,6 +649,9 @@  nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type)
 
 	/* Get some of the read-only fields from the config BAR */
 	nfp_net_cfg_read_version(hw);
+	if (!nfp_net_is_valid_nfd_version(hw->ver))
+		return -EINVAL;
+
 	hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
 	hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
 	/* Set the current MTU to the maximum supported */
diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index 497128f6a6..08f9529ead 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -1162,22 +1162,10 @@  nfp_net_tx_desc_limits(struct nfp_net_hw *hw,
 {
 	uint16_t tx_dpp;
 
-	switch (hw->ver.extend) {
-	case NFP_NET_CFG_VERSION_DP_NFD3:
+	if (hw->ver.extend == NFP_NET_CFG_VERSION_DP_NFD3)
 		tx_dpp = NFD3_TX_DESC_PER_PKT;
-		break;
-	case NFP_NET_CFG_VERSION_DP_NFDK:
-		if (hw->ver.major < 5) {
-			PMD_DRV_LOG(ERR, "NFDK must use ABI 5 or newer, found: %d",
-					hw->ver.major);
-			return -EINVAL;
-		}
+	else
 		tx_dpp = NFDK_TX_DESC_PER_SIMPLE_PKT;
-		break;
-	default:
-		PMD_DRV_LOG(ERR, "The version of firmware is not correct.");
-		return -EINVAL;
-	}
 
 	*max_tx_desc = NFP_NET_MAX_TX_DESC / tx_dpp;
 
@@ -2106,3 +2094,24 @@  nfp_repr_firmware_version_get(struct rte_eth_dev *dev,
 
 	return 0;
 }
+
+bool
+nfp_net_is_valid_nfd_version(struct nfp_net_fw_ver version)
+{
+	uint8_t nfd_version = version.extend;
+
+	if (nfd_version == NFP_NET_CFG_VERSION_DP_NFD3)
+		return true;
+
+	if (nfd_version == NFP_NET_CFG_VERSION_DP_NFDK) {
+		if (version.major < 5) {
+			PMD_INIT_LOG(ERR, "NFDK must use ABI 5 or newer, found: %d",
+					version.major);
+			return false;
+		}
+
+		return true;
+	}
+
+	return false;
+}
diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h
index 2281445861..acb34535c5 100644
--- a/drivers/net/nfp/nfp_common.h
+++ b/drivers/net/nfp/nfp_common.h
@@ -444,6 +444,7 @@  void nfp_net_init_metadata_format(struct nfp_net_hw *hw);
 void nfp_net_cfg_read_version(struct nfp_net_hw *hw);
 int nfp_net_firmware_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size);
 int nfp_repr_firmware_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size);
+bool nfp_net_is_valid_nfd_version(struct nfp_net_fw_ver version);
 
 #define NFP_NET_DEV_PRIVATE_TO_HW(adapter)\
 	(&((struct nfp_net_adapter *)adapter)->hw)
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index e84d2ac82e..0ccb543f14 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -474,31 +474,18 @@  static const struct eth_dev_ops nfp_net_eth_dev_ops = {
 	.fw_version_get         = nfp_net_firmware_version_get,
 };
 
-static inline int
-nfp_net_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev)
+static inline void
+nfp_net_ethdev_ops_mount(struct nfp_net_hw *hw,
+		struct rte_eth_dev *eth_dev)
 {
-	switch (hw->ver.extend) {
-	case NFP_NET_CFG_VERSION_DP_NFD3:
-		eth_dev->tx_pkt_burst = &nfp_net_nfd3_xmit_pkts;
-		break;
-	case NFP_NET_CFG_VERSION_DP_NFDK:
-		if (hw->ver.major < 5) {
-			PMD_DRV_LOG(ERR, "NFDK must use ABI 5 or newer, found: %d",
-					hw->ver.major);
-			return -EINVAL;
-		}
-		eth_dev->tx_pkt_burst = &nfp_net_nfdk_xmit_pkts;
-		break;
-	default:
-		PMD_DRV_LOG(ERR, "The version of firmware is not correct.");
-		return -EINVAL;
-	}
+	if (hw->ver.extend == NFP_NET_CFG_VERSION_DP_NFD3)
+		eth_dev->tx_pkt_burst = nfp_net_nfd3_xmit_pkts;
+	else
+		eth_dev->tx_pkt_burst = nfp_net_nfdk_xmit_pkts;
 
 	eth_dev->dev_ops = &nfp_net_eth_dev_ops;
 	eth_dev->rx_queue_count = nfp_net_rx_queue_count;
 	eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
-
-	return 0;
 }
 
 static int
@@ -583,12 +570,13 @@  nfp_net_init(struct rte_eth_dev *eth_dev)
 	PMD_INIT_LOG(DEBUG, "MAC stats: %p", hw->mac_stats);
 
 	nfp_net_cfg_read_version(hw);
+	if (!nfp_net_is_valid_nfd_version(hw->ver))
+		return -EINVAL;
 
 	if (nfp_net_check_dma_mask(hw, pci_dev->name) != 0)
 		return -ENODEV;
 
-	if (nfp_net_ethdev_ops_mount(hw, eth_dev))
-		return -EINVAL;
+	nfp_net_ethdev_ops_mount(hw, eth_dev);
 
 	hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
 	hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
@@ -1133,8 +1121,7 @@  nfp_secondary_init_app_fw_nic(struct rte_pci_device *pci_dev,
 
 		eth_dev->process_private = cpp;
 		hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-		if (nfp_net_ethdev_ops_mount(hw, eth_dev))
-			return -EINVAL;
+		nfp_net_ethdev_ops_mount(hw, eth_dev);
 
 		rte_eth_dev_probing_finish(eth_dev);
 	}
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index 71f5020ecd..f971bb8903 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -244,31 +244,18 @@  static const struct eth_dev_ops nfp_netvf_eth_dev_ops = {
 	.fw_version_get         = nfp_net_firmware_version_get,
 };
 
-static inline int
-nfp_netvf_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev)
+static inline void
+nfp_netvf_ethdev_ops_mount(struct nfp_net_hw *hw,
+		struct rte_eth_dev *eth_dev)
 {
-	switch (hw->ver.extend) {
-	case NFP_NET_CFG_VERSION_DP_NFD3:
-		eth_dev->tx_pkt_burst = &nfp_net_nfd3_xmit_pkts;
-		break;
-	case NFP_NET_CFG_VERSION_DP_NFDK:
-		if (hw->ver.major < 5) {
-			PMD_DRV_LOG(ERR, "NFDK must use ABI 5 or newer, found: %d",
-					hw->ver.major);
-			return -EINVAL;
-		}
-		eth_dev->tx_pkt_burst = &nfp_net_nfdk_xmit_pkts;
-		break;
-	default:
-		PMD_DRV_LOG(ERR, "The version of firmware is not correct.");
-		return -EINVAL;
-	}
+	if (hw->ver.extend == NFP_NET_CFG_VERSION_DP_NFD3)
+		eth_dev->tx_pkt_burst = nfp_net_nfd3_xmit_pkts;
+	else
+		eth_dev->tx_pkt_burst = nfp_net_nfdk_xmit_pkts;
 
 	eth_dev->dev_ops = &nfp_netvf_eth_dev_ops;
 	eth_dev->rx_queue_count = nfp_net_rx_queue_count;
 	eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
-
-	return 0;
 }
 
 static int
@@ -300,12 +287,13 @@  nfp_netvf_init(struct rte_eth_dev *eth_dev)
 	PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
 
 	nfp_net_cfg_read_version(hw);
+	if (!nfp_net_is_valid_nfd_version(hw->ver))
+		return -EINVAL;
 
 	if (nfp_net_check_dma_mask(hw, pci_dev->name) != 0)
 		return -ENODEV;
 
-	if (nfp_netvf_ethdev_ops_mount(hw, eth_dev))
-		return -EINVAL;
+	nfp_netvf_ethdev_ops_mount(hw, eth_dev);
 
 	/* For secondary processes, the primary has done all the work */
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c
index 0ac9d6db03..ce9a07309e 100644
--- a/drivers/net/nfp/nfp_rxtx.c
+++ b/drivers/net/nfp/nfp_rxtx.c
@@ -889,20 +889,10 @@  nfp_net_tx_queue_setup(struct rte_eth_dev *dev,
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	switch (hw->ver.extend) {
-	case NFP_NET_CFG_VERSION_DP_NFD3:
+	if (hw->ver.extend == NFP_NET_CFG_VERSION_DP_NFD3)
 		return nfp_net_nfd3_tx_queue_setup(dev, queue_idx,
 				nb_desc, socket_id, tx_conf);
-	case NFP_NET_CFG_VERSION_DP_NFDK:
-		if (hw->ver.major < 5) {
-			PMD_DRV_LOG(ERR, "NFDK must use ABI 5 or newer, found: %d",
-					hw->ver.major);
-			return -EINVAL;
-		}
+	else
 		return nfp_net_nfdk_tx_queue_setup(dev, queue_idx,
 				nb_desc, socket_id, tx_conf);
-	default:
-		PMD_DRV_LOG(ERR, "The version of firmware is not correct.");
-		return -EINVAL;
-	}
 }