From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Chaoyong He <chaoyong.he@corigine.com>,
Long Wu <long.wu@corigine.com>,
Peng Zhang <peng.zhang@corigine.com>
Subject: [PATCH v2 04/10] net/nfp: improve the logic readability
Date: Sat, 12 Oct 2024 10:41:01 +0800 [thread overview]
Message-ID: <20241012024107.3795935-5-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20241012024107.3795935-1-chaoyong.he@corigine.com>
Try our best to make the logic in secondary proess the same with the
primary process and improve the readability, by add helper functions
and rename function.
Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
drivers/net/nfp/nfp_ethdev.c | 86 +++++++++++++++-----------------
drivers/net/nfp/nfp_net_common.c | 22 +++++++-
drivers/net/nfp/nfp_net_common.h | 3 +-
3 files changed, 63 insertions(+), 48 deletions(-)
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 121f82af6d..405386e882 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -1764,19 +1764,9 @@ nfp_enable_multi_pf(struct nfp_pf_dev *pf_dev)
static bool
nfp_app_fw_nic_total_phyports_check(struct nfp_pf_dev *pf_dev)
{
- int ret;
- uint8_t id;
uint8_t total_phyports;
- char vnic_name[RTE_ETH_NAME_MAX_LEN];
- /* Read the number of vNIC's created for the PF */
- id = nfp_function_id_get(pf_dev, 0);
- snprintf(vnic_name, sizeof(vnic_name), "nfd_cfg_pf%u_num_ports", id);
- total_phyports = nfp_rtsym_read_le(pf_dev->sym_tbl, vnic_name, &ret);
- if (ret != 0 || total_phyports == 0 || total_phyports > 8) {
- PMD_INIT_LOG(ERR, "%s symbol with wrong value", vnic_name);
- return false;
- }
+ total_phyports = nfp_net_get_phyports_from_fw(pf_dev);
if (pf_dev->multi_pf.enabled) {
if (!nfp_check_multi_pf_from_fw(total_phyports)) {
@@ -1797,6 +1787,20 @@ nfp_app_fw_nic_total_phyports_check(struct nfp_pf_dev *pf_dev)
return true;
}
+static void
+nfp_port_name_generate(char *port_name,
+ size_t length,
+ int port_id,
+ struct nfp_pf_dev *pf_dev)
+{
+ const char *name = pf_dev->pci_dev->device.name;
+
+ if (pf_dev->multi_pf.enabled)
+ snprintf(port_name, length, "%s", name);
+ else
+ snprintf(port_name, length, "%s_port%u", name, port_id);
+}
+
static int
nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
{
@@ -1849,12 +1853,7 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
/* Loop through all physical ports on PF */
for (i = 0; i < pf_dev->total_phyports; i++) {
- if (pf_dev->multi_pf.enabled)
- snprintf(port_name, sizeof(port_name), "%s",
- pf_dev->pci_dev->device.name);
- else
- snprintf(port_name, sizeof(port_name), "%s_port%u",
- pf_dev->pci_dev->device.name, i);
+ nfp_port_name_generate(port_name, sizeof(port_name), i, pf_dev);
id = nfp_function_id_get(pf_dev, i);
hw_init.idx = id;
@@ -1870,15 +1869,10 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
return 0;
port_cleanup:
- for (i = 0; i < pf_dev->total_phyports; i++) {
+ for (uint32_t j = 0; j < i; j++) {
struct rte_eth_dev *eth_dev;
- if (pf_dev->multi_pf.enabled)
- snprintf(port_name, sizeof(port_name), "%s",
- pf_dev->pci_dev->device.name);
- else
- snprintf(port_name, sizeof(port_name), "%s_port%u",
- pf_dev->pci_dev->device.name, i);
+ nfp_port_name_generate(port_name, sizeof(port_name), j, pf_dev);
eth_dev = rte_eth_dev_get_by_name(port_name);
if (eth_dev != NULL)
rte_eth_dev_destroy(eth_dev, nfp_net_uninit);
@@ -2369,7 +2363,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev)
pf_dev->nfp_eth_table = nfp_eth_table;
pf_dev->multi_pf.enabled = nfp_check_multi_pf_from_nsp(pci_dev, cpp);
pf_dev->multi_pf.function_id = function_id;
- pf_dev->total_phyports = nfp_net_get_port_num(pf_dev);
+ pf_dev->total_phyports = nfp_net_get_phyports_from_nsp(pf_dev);
ret = nfp_net_force_port_down(pf_dev);
if (ret != 0) {
@@ -2547,42 +2541,37 @@ static int
nfp_secondary_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
{
uint32_t i;
- int err = 0;
int ret = 0;
- uint8_t function_id;
uint32_t total_vnics;
- char pf_name[RTE_ETH_NAME_MAX_LEN];
+ char port_name[RTE_ETH_NAME_MAX_LEN];
struct nfp_pf_dev *pf_dev = hw_priv->pf_dev;
- /* Read the number of vNIC's created for the PF */
- function_id = (pf_dev->pci_dev->addr.function) & 0x07;
- snprintf(pf_name, sizeof(pf_name), "nfd_cfg_pf%u_num_ports", function_id);
- total_vnics = nfp_rtsym_read_le(pf_dev->sym_tbl, pf_name, &err);
- if (err != 0 || total_vnics == 0 || total_vnics > 8) {
- PMD_INIT_LOG(ERR, "%s symbol with wrong value", pf_name);
- return -ENODEV;
- }
+ total_vnics = nfp_net_get_phyports_from_fw(pf_dev);
for (i = 0; i < total_vnics; i++) {
- char port_name[RTE_ETH_NAME_MAX_LEN];
-
- if (nfp_check_multi_pf_from_fw(total_vnics))
- snprintf(port_name, sizeof(port_name), "%s",
- pf_dev->pci_dev->device.name);
- else
- snprintf(port_name, sizeof(port_name), "%s_port%u",
- pf_dev->pci_dev->device.name, i);
+ nfp_port_name_generate(port_name, sizeof(port_name), i, pf_dev);
PMD_INIT_LOG(DEBUG, "Secondary attaching to port %s", port_name);
ret = rte_eth_dev_create(&pf_dev->pci_dev->device, port_name, 0,
NULL, NULL, nfp_secondary_net_init, hw_priv);
if (ret != 0) {
PMD_INIT_LOG(ERR, "Secondary process attach to port %s failed", port_name);
- ret = -ENODEV;
- break;
+ goto port_cleanup;
}
}
+ return 0;
+
+port_cleanup:
+ for (uint32_t j = 0; j < i; j++) {
+ struct rte_eth_dev *eth_dev;
+
+ nfp_port_name_generate(port_name, sizeof(port_name), j, pf_dev);
+ eth_dev = rte_eth_dev_get_by_name(port_name);
+ if (eth_dev != NULL)
+ rte_eth_dev_destroy(eth_dev, NULL);
+ }
+
return ret;
}
@@ -2714,6 +2703,11 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
pf_dev->sym_tbl = sym_tbl;
+ /* Read the number of physical ports from firmware */
+ pf_dev->multi_pf.function_id = function_id;
+ pf_dev->total_phyports = nfp_net_get_phyports_from_fw(pf_dev);
+ pf_dev->multi_pf.enabled = nfp_check_multi_pf_from_fw(pf_dev->total_phyports);
+
/* Read the app ID of the firmware loaded */
snprintf(app_name, sizeof(app_name), "_pf%u_net_app_id", function_id);
app_fw_id = nfp_rtsym_read_le(sym_tbl, app_name, &ret);
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 99f6b61947..86a1fbfaf2 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -14,6 +14,7 @@
#include "nfdk/nfp_nfdk.h"
#include "nfpcore/nfp_mip.h"
#include "nfpcore/nfp_nsp.h"
+#include "nfpcore/nfp_rtsym.h"
#include "nfp_logs.h"
#include "nfp_net_meta.h"
@@ -2724,7 +2725,7 @@ nfp_net_fec_set(struct rte_eth_dev *dev,
}
uint32_t
-nfp_net_get_port_num(struct nfp_pf_dev *pf_dev)
+nfp_net_get_phyports_from_nsp(struct nfp_pf_dev *pf_dev)
{
if (pf_dev->multi_pf.enabled)
return 1;
@@ -2732,6 +2733,25 @@ nfp_net_get_port_num(struct nfp_pf_dev *pf_dev)
return pf_dev->nfp_eth_table->count;
}
+uint32_t
+nfp_net_get_phyports_from_fw(struct nfp_pf_dev *pf_dev)
+{
+ int ret = 0;
+ uint8_t total_phyports;
+ char pf_name[RTE_ETH_NAME_MAX_LEN];
+
+ /* Read the number of vNIC's created for the PF */
+ snprintf(pf_name, sizeof(pf_name), "nfd_cfg_pf%u_num_ports",
+ pf_dev->multi_pf.function_id);
+ total_phyports = nfp_rtsym_read_le(pf_dev->sym_tbl, pf_name, &ret);
+ if (ret != 0 || total_phyports == 0 || total_phyports > 8) {
+ PMD_INIT_LOG(ERR, "%s symbol with wrong value", pf_name);
+ return 0;
+ }
+
+ return total_phyports;
+}
+
uint8_t
nfp_function_id_get(const struct nfp_pf_dev *pf_dev,
uint8_t port_id)
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index fb244383b7..8429db68f0 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -374,7 +374,8 @@ void nfp_net_get_fw_version(struct nfp_cpp *cpp,
uint32_t *fw_version);
int nfp_net_txrwb_alloc(struct rte_eth_dev *eth_dev);
void nfp_net_txrwb_free(struct rte_eth_dev *eth_dev);
-uint32_t nfp_net_get_port_num(struct nfp_pf_dev *pf_dev);
+uint32_t nfp_net_get_phyports_from_nsp(struct nfp_pf_dev *pf_dev);
+uint32_t nfp_net_get_phyports_from_fw(struct nfp_pf_dev *pf_dev);
uint8_t nfp_function_id_get(const struct nfp_pf_dev *pf_dev,
uint8_t port_id);
int nfp_net_vf_config_app_init(struct nfp_net_hw *net_hw,
--
2.39.1
next prev parent reply other threads:[~2024-10-12 2:42 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 9:17 [PATCH 00/10] modify some logic of NFP PMD Chaoyong He
2024-10-10 9:17 ` [PATCH 01/10] net/nfp: use strlcpy for copying string Chaoyong He
2024-10-10 15:08 ` Stephen Hemminger
2024-10-10 9:17 ` [PATCH 02/10] net/nfp: fix malloc name problem in secondary process Chaoyong He
2024-10-10 15:07 ` Stephen Hemminger
2024-10-11 2:31 ` Chaoyong He
2024-10-10 9:17 ` [PATCH 03/10] net/nfp: simplify some function parameters Chaoyong He
2024-10-10 15:08 ` Stephen Hemminger
2024-10-10 9:17 ` [PATCH 04/10] net/nfp: improve the logic readability Chaoyong He
2024-10-10 15:10 ` Stephen Hemminger
2024-10-11 2:36 ` Chaoyong He
2024-10-10 9:17 ` [PATCH 05/10] net/nfp: fix problem caused by configure function Chaoyong He
2024-10-10 15:13 ` Stephen Hemminger
2024-10-10 9:17 ` [PATCH 06/10] net/nfp: add check logic for port up/down function Chaoyong He
2024-10-10 15:14 ` Stephen Hemminger
2024-10-10 9:17 ` [PATCH 07/10] net/nfp: fix problem caused by commit end function Chaoyong He
2024-10-10 15:15 ` Stephen Hemminger
2024-10-10 9:17 ` [PATCH 08/10] net/nfp: fix problem caused by FEC set Chaoyong He
2024-10-10 15:15 ` Stephen Hemminger
2024-10-10 9:17 ` [PATCH 09/10] net/nfp: modify the comment of some control messages Chaoyong He
2024-10-10 15:15 ` Stephen Hemminger
2024-10-10 9:17 ` [PATCH 10/10] net/nfp: fix memory leak in VF initialization logic Chaoyong He
2024-10-10 15:19 ` Stephen Hemminger
2024-10-11 2:38 ` Chaoyong He
2024-10-12 2:40 ` [PATCH v2 00/10] modify some logic of NFP PMD Chaoyong He
2024-10-12 2:40 ` [PATCH v2 01/10] net/nfp: use strlcpy for copying string Chaoyong He
2024-10-12 2:40 ` [PATCH v2 02/10] net/nfp: fix malloc name problem in secondary process Chaoyong He
2024-10-12 2:45 ` Stephen Hemminger
2024-10-12 2:47 ` Chaoyong He
2024-10-12 2:41 ` [PATCH v2 03/10] net/nfp: simplify some function parameters Chaoyong He
2024-10-12 2:41 ` Chaoyong He [this message]
2024-10-12 2:41 ` [PATCH v2 05/10] net/nfp: fix problem caused by configure function Chaoyong He
2024-10-12 2:41 ` [PATCH v2 06/10] net/nfp: add check logic for port up/down function Chaoyong He
2024-10-12 2:41 ` [PATCH v2 07/10] net/nfp: fix problem caused by commit end function Chaoyong He
2024-10-12 2:41 ` [PATCH v2 08/10] net/nfp: fix problem caused by FEC set Chaoyong He
2024-10-12 2:41 ` [PATCH v2 09/10] net/nfp: modify the comment of some control messages Chaoyong He
2024-10-12 2:41 ` [PATCH v2 10/10] net/nfp: fix memory leak in VF initialization logic Chaoyong He
2024-10-13 2:49 ` [PATCH v2 00/10] modify some logic of NFP 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=20241012024107.3795935-5-chaoyong.he@corigine.com \
--to=chaoyong.he@corigine.com \
--cc=dev@dpdk.org \
--cc=long.wu@corigine.com \
--cc=oss-drivers@corigine.com \
--cc=peng.zhang@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).