From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com,
Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH 02/10] net/nfp: add a check function for the NFD version
Date: Wed, 7 Jun 2023 09:57:01 +0800 [thread overview]
Message-ID: <20230607015709.336420-3-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20230607015709.336420-1-chaoyong.he@corigine.com>
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(-)
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;
- }
}
--
2.39.1
next prev parent reply other threads:[~2023-06-07 1:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 1:56 [PATCH 00/10] support rte_flow for flower firmware with NFDk Chaoyong He
2023-06-07 1:57 ` [PATCH 01/10] net/nfp: fix the problem of rtsym Chaoyong He
2023-06-07 1:57 ` Chaoyong He [this message]
2023-06-07 1:57 ` [PATCH 03/10] net/nfp: refactor the insert metadata logic of NFD3 Chaoyong He
2023-06-07 1:57 ` [PATCH 04/10] net/nfp: add the insert metadata logic of NFDk Chaoyong He
2023-06-07 1:57 ` [PATCH 05/10] net/nfp: add a dispatch layer for Tx function of ctrl VNIC Chaoyong He
2023-06-07 1:57 ` [PATCH 06/10] net/nfp: add the xmit function of NFDk for " Chaoyong He
2023-06-07 1:57 ` [PATCH 07/10] net/nfp: add a dispatch layer for Tx function of representor Chaoyong He
2023-06-07 1:57 ` [PATCH 08/10] net/nfp: merge the xmit function of NFD3 Chaoyong He
2023-06-07 1:57 ` [PATCH 09/10] net/nfp: add the xmit function of NFDk for PF representor Chaoyong He
2023-06-07 1:57 ` [PATCH 10/10] net/nfp: merge the recv function Chaoyong He
2023-06-07 14:23 ` [PATCH 00/10] support rte_flow for flower firmware with NFDk 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=20230607015709.336420-3-chaoyong.he@corigine.com \
--to=chaoyong.he@corigine.com \
--cc=dev@dpdk.org \
--cc=niklas.soderlund@corigine.com \
--cc=oss-drivers@corigine.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).