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 8/8] net/nfp: unify port create and destroy interface
Date: Fri, 19 Apr 2024 13:23:49 +0800 [thread overview]
Message-ID: <20240419052349.1294696-9-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240419052349.1294696-1-chaoyong.he@corigine.com>
The interface 'rte_eth_dev_create()' and 'rte_eth_dev_destroy()' are
available for both primary and secondary process.
Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Signed-off-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
drivers/net/nfp/flower/nfp_flower.c | 31 +++--
.../net/nfp/flower/nfp_flower_representor.c | 18 +--
drivers/net/nfp/nfp_ethdev.c | 112 +++++++++---------
3 files changed, 80 insertions(+), 81 deletions(-)
diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c
index 76e5d674f1..0edebd574a 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -798,25 +798,36 @@ nfp_uninit_app_fw_flower(struct nfp_net_hw_priv *hw_priv)
rte_free(app_fw_flower);
}
+static int
+nfp_secondary_flower_init(struct rte_eth_dev *eth_dev,
+ void *para)
+{
+ eth_dev->process_private = para;
+ eth_dev->dev_ops = &nfp_flower_pf_vnic_ops;
+ eth_dev->rx_pkt_burst = nfp_net_recv_pkts;
+ eth_dev->tx_pkt_burst = nfp_flower_pf_xmit_pkts;
+
+ return 0;
+}
+
int
nfp_secondary_init_app_fw_flower(struct nfp_net_hw_priv *hw_priv)
{
- struct rte_eth_dev *eth_dev;
- const char *port_name = "pf_vnic_eth_dev";
+ int ret;
+ const char *pci_name;
+ char port_name[RTE_ETH_NAME_MAX_LEN];
+
+ pci_name = strchr(hw_priv->pf_dev->pci_dev->name, ':') + 1;
+ snprintf(port_name, RTE_ETH_NAME_MAX_LEN, "%s_repr_pf", pci_name);
PMD_INIT_LOG(DEBUG, "Secondary attaching to port %s", port_name);
- eth_dev = rte_eth_dev_attach_secondary(port_name);
- if (eth_dev == NULL) {
+ ret = rte_eth_dev_create(&hw_priv->pf_dev->pci_dev->device, port_name, 0, NULL,
+ NULL, nfp_secondary_flower_init, hw_priv);
+ if (ret != 0) {
PMD_INIT_LOG(ERR, "Secondary process attach to port %s failed", port_name);
return -ENODEV;
}
- eth_dev->process_private = hw_priv;
- eth_dev->dev_ops = &nfp_flower_pf_vnic_ops;
- eth_dev->rx_pkt_burst = nfp_net_recv_pkts;
- eth_dev->tx_pkt_burst = nfp_flower_pf_xmit_pkts;
- rte_eth_dev_probing_finish(eth_dev);
-
return 0;
}
diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index 60f02ad919..f9001ab1f0 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -683,10 +683,8 @@ nfp_flower_repr_free_all(struct nfp_app_fw_flower *app_fw_flower)
repr = app_fw_flower->vf_reprs[i];
if (repr != NULL) {
eth_dev = rte_eth_dev_get_by_name(repr->name);
- if (eth_dev != NULL) {
- nfp_flower_repr_free(eth_dev, NFP_REPR_TYPE_VF);
- app_fw_flower->vf_reprs[i] = NULL;
- }
+ if (eth_dev != NULL)
+ rte_eth_dev_destroy(eth_dev, nfp_flower_repr_uninit);
}
}
@@ -694,20 +692,16 @@ nfp_flower_repr_free_all(struct nfp_app_fw_flower *app_fw_flower)
repr = app_fw_flower->phy_reprs[i];
if (repr != NULL) {
eth_dev = rte_eth_dev_get_by_name(repr->name);
- if (eth_dev != NULL) {
- nfp_flower_repr_free(eth_dev, NFP_REPR_TYPE_PHYS_PORT);
- app_fw_flower->phy_reprs[i] = NULL;
- }
+ if (eth_dev != NULL)
+ rte_eth_dev_destroy(eth_dev, nfp_flower_repr_uninit);
}
}
repr = app_fw_flower->pf_repr;
if (repr != NULL) {
eth_dev = rte_eth_dev_get_by_name(repr->name);
- if (eth_dev != NULL) {
- nfp_flower_repr_free(eth_dev, NFP_REPR_TYPE_PF);
- app_fw_flower->pf_repr = NULL;
- }
+ if (eth_dev != NULL)
+ rte_eth_dev_destroy(eth_dev, nfp_flower_pf_repr_uninit);
}
}
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index d450c9472e..cdc946faff 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -34,6 +34,16 @@
#define NFP_PF_DRIVER_NAME net_nfp_pf
#define NFP_PF_FORCE_RELOAD_FW "force_reload_fw"
+struct nfp_net_init {
+ /** Sequential physical port number, only valid for CoreNIC firmware */
+ uint8_t idx;
+
+ /** Internal port number as seen from NFP */
+ uint8_t nfp_idx;
+
+ struct nfp_net_hw_priv *hw_priv;
+};
+
static int
nfp_devarg_handle_int(const char *key,
const char *value,
@@ -559,7 +569,7 @@ nfp_net_keepalive_stop(struct nfp_multi_pf *multi_pf)
rte_eal_alarm_cancel(nfp_net_beat_timer, (void *)multi_pf);
}
-static void
+static int
nfp_net_uninit(struct rte_eth_dev *eth_dev)
{
struct nfp_net_hw *net_hw;
@@ -577,6 +587,8 @@ nfp_net_uninit(struct rte_eth_dev *eth_dev)
nfp_ipsec_uninit(eth_dev);
if (net_hw->mac_stats_area != NULL)
nfp_cpp_area_release_free(net_hw->mac_stats_area);
+
+ return 0;
}
static void
@@ -875,7 +887,8 @@ nfp_net_ethdev_ops_mount(struct nfp_net_hw *hw,
}
static int
-nfp_net_init(struct rte_eth_dev *eth_dev)
+nfp_net_init(struct rte_eth_dev *eth_dev,
+ void *para)
{
int err;
uint16_t port;
@@ -884,6 +897,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
struct nfp_hw *hw;
struct nfp_net_hw *net_hw;
struct nfp_pf_dev *pf_dev;
+ struct nfp_net_init *hw_init;
struct rte_pci_device *pci_dev;
struct nfp_net_hw_priv *hw_priv;
struct nfp_app_fw_nic *app_fw_nic;
@@ -891,6 +905,11 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
net_hw = eth_dev->data->dev_private;
+ hw_init = para;
+ net_hw->idx = hw_init->idx;
+ net_hw->nfp_idx = hw_init->nfp_idx;
+ eth_dev->process_private = hw_init->hw_priv;
+
/* Use backpointer here to the PF of this eth_dev */
hw_priv = eth_dev->process_private;
pf_dev = hw_priv->pf_dev;
@@ -898,7 +917,10 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
/* Use backpointer to the CoreNIC app struct */
app_fw_nic = NFP_PRIV_TO_APP_FW_NIC(pf_dev->app_fw_priv);
- port = ((struct nfp_net_hw *)eth_dev->data->dev_private)->idx;
+ /* Add this device to the PF's array of physical ports */
+ app_fw_nic->ports[net_hw->idx] = net_hw;
+
+ port = net_hw->idx;
if (port > 7) {
PMD_DRV_LOG(ERR, "Port value is wrong");
return -ENODEV;
@@ -1475,15 +1497,15 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
uint8_t id;
int ret = 0;
uint32_t total_vnics;
- struct nfp_net_hw *hw;
- unsigned int numa_node;
- struct rte_eth_dev *eth_dev;
struct nfp_app_fw_nic *app_fw_nic;
struct nfp_eth_table *nfp_eth_table;
char bar_name[RTE_ETH_NAME_MAX_LEN];
char port_name[RTE_ETH_NAME_MAX_LEN];
char vnic_name[RTE_ETH_NAME_MAX_LEN];
struct nfp_pf_dev *pf_dev = hw_priv->pf_dev;
+ struct nfp_net_init hw_init = {
+ .hw_priv = hw_priv,
+ };
nfp_eth_table = pf_dev->nfp_eth_table;
PMD_INIT_LOG(INFO, "Total physical ports: %d", nfp_eth_table->count);
@@ -1543,7 +1565,6 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
PMD_INIT_LOG(DEBUG, "ctrl bar: %p", pf_dev->ctrl_bar);
/* Loop through all physical ports on PF */
- numa_node = rte_socket_id();
for (i = 0; i < app_fw_nic->total_phyports; i++) {
if (pf_dev->multi_pf.enabled)
snprintf(port_name, sizeof(port_name), "%s",
@@ -1552,46 +1573,14 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
snprintf(port_name, sizeof(port_name), "%s_port%u",
pf_dev->pci_dev->device.name, i);
- /* Allocate a eth_dev for this phyport */
- eth_dev = rte_eth_dev_allocate(port_name);
- if (eth_dev == NULL) {
- ret = -ENODEV;
- goto port_cleanup;
- }
-
- /* Allocate memory for this phyport */
- eth_dev->data->dev_private = rte_zmalloc_socket(port_name,
- sizeof(struct nfp_net_hw),
- RTE_CACHE_LINE_SIZE, numa_node);
- if (eth_dev->data->dev_private == NULL) {
- ret = -ENOMEM;
- rte_eth_dev_release_port(eth_dev);
- goto port_cleanup;
- }
-
- hw = eth_dev->data->dev_private;
id = nfp_function_id_get(pf_dev, i);
-
- /* Add this device to the PF's array of physical ports */
- app_fw_nic->ports[id] = hw;
-
- hw->idx = id;
- hw->nfp_idx = nfp_eth_table->ports[id].index;
-
- eth_dev->device = &pf_dev->pci_dev->device;
- eth_dev->process_private = hw_priv;
-
- /*
- * Ctrl/tx/rx BAR mappings and remaining init happens in
- * @nfp_net_init()
- */
- ret = nfp_net_init(eth_dev);
- if (ret != 0) {
- ret = -ENODEV;
+ hw_init.idx = id;
+ hw_init.nfp_idx = nfp_eth_table->ports[id].index;
+ ret = rte_eth_dev_create(&pf_dev->pci_dev->device, port_name,
+ sizeof(struct nfp_net_hw), NULL, NULL,
+ nfp_net_init, &hw_init);
+ if (ret != 0)
goto port_cleanup;
- }
-
- rte_eth_dev_probing_finish(eth_dev);
} /* End loop, all ports on this PF */
@@ -1608,10 +1597,8 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
snprintf(port_name, sizeof(port_name), "%s_port%u",
pf_dev->pci_dev->device.name, i);
eth_dev = rte_eth_dev_get_by_name(port_name);
- if (eth_dev != NULL) {
- nfp_net_uninit(eth_dev);
- rte_eth_dev_release_port(eth_dev);
- }
+ if (eth_dev != NULL)
+ rte_eth_dev_destroy(eth_dev, nfp_net_uninit);
}
nfp_cpp_area_release_free(pf_dev->ctrl_area);
app_cleanup:
@@ -2012,6 +1999,20 @@ nfp_pf_init(struct rte_pci_device *pci_dev)
return ret;
}
+static int
+nfp_secondary_net_init(struct rte_eth_dev *eth_dev,
+ void *para)
+{
+ struct nfp_net_hw *net_hw;
+
+ net_hw = eth_dev->data->dev_private;
+ nfp_net_ethdev_ops_mount(net_hw, eth_dev);
+
+ eth_dev->process_private = para;
+
+ return 0;
+}
+
static int
nfp_secondary_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
{
@@ -2020,7 +2021,6 @@ nfp_secondary_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
int ret = 0;
uint8_t function_id;
uint32_t total_vnics;
- struct nfp_net_hw *hw;
char pf_name[RTE_ETH_NAME_MAX_LEN];
struct nfp_pf_dev *pf_dev = hw_priv->pf_dev;
@@ -2034,7 +2034,6 @@ nfp_secondary_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
}
for (i = 0; i < total_vnics; i++) {
- struct rte_eth_dev *eth_dev;
char port_name[RTE_ETH_NAME_MAX_LEN];
if (nfp_check_multi_pf_from_fw(total_vnics))
@@ -2045,18 +2044,13 @@ nfp_secondary_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
pf_dev->pci_dev->device.name, i);
PMD_INIT_LOG(DEBUG, "Secondary attaching to port %s", port_name);
- eth_dev = rte_eth_dev_attach_secondary(port_name);
- if (eth_dev == NULL) {
+ 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;
}
-
- eth_dev->process_private = hw_priv;
- hw = eth_dev->data->dev_private;
- nfp_net_ethdev_ops_mount(hw, eth_dev);
-
- rte_eth_dev_probing_finish(eth_dev);
}
return ret;
--
2.39.1
next prev parent reply other threads:[~2024-04-19 5:25 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 3:12 [PATCH 0/8] refactor logic to support secondary process Chaoyong He
2024-04-19 3:12 ` [PATCH 1/8] net/nfp: fix resource leak of " Chaoyong He
2024-04-19 3:12 ` [PATCH 2/8] net/nfp: fix configuration BAR problem Chaoyong He
2024-04-19 3:12 ` [PATCH 3/8] net/nfp: adjust the data field of Rx/Tx queue Chaoyong He
2024-04-19 3:12 ` [PATCH 4/8] net/nfp: add the process private structure Chaoyong He
2024-04-19 3:12 ` [PATCH 5/8] net/nfp: move device info data field Chaoyong He
2024-04-19 3:12 ` [PATCH 6/8] net/nfp: unify CPP acquire method Chaoyong He
2024-04-19 3:12 ` [PATCH 7/8] net/nfp: remove ethernet device data field Chaoyong He
2024-04-19 3:12 ` [PATCH 8/8] net/nfp: unify port create and destroy interface Chaoyong He
2024-04-19 5:23 ` [PATCH 0/8] refactor logic to support secondary process Chaoyong He
2024-04-19 5:23 ` [PATCH v2 1/8] net/nfp: fix resource leak of " Chaoyong He
2024-04-19 5:23 ` [PATCH v2 2/8] net/nfp: fix configuration BAR problem Chaoyong He
2024-04-19 5:23 ` [PATCH v2 3/8] net/nfp: adjust the data field of Rx/Tx queue Chaoyong He
2024-04-19 5:23 ` [PATCH v2 4/8] net/nfp: add the process private structure Chaoyong He
2024-04-19 5:23 ` [PATCH v2 5/8] net/nfp: move device info data field Chaoyong He
2024-04-19 5:23 ` [PATCH v2 6/8] net/nfp: unify CPP acquire method Chaoyong He
2024-04-19 5:23 ` [PATCH v2 7/8] net/nfp: remove ethernet device data field Chaoyong He
2024-04-19 5:23 ` Chaoyong He [this message]
2024-05-20 22:19 ` [PATCH 0/8] refactor logic to support secondary process Ferruh Yigit
2024-05-21 2:17 ` Chaoyong He
2024-05-21 11:09 ` Ferruh Yigit
2024-05-21 11:24 ` Chaoyong He
2024-05-21 12:54 ` Ferruh Yigit
2024-05-21 15:08 ` 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=20240419052349.1294696-9-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).