[PATCH v5 4/6] net/nfb: use process private variable for internal data

spinler
2026-02-02T19:34:04Z

Internal structures of libnfb can't be shared between processes.
Move these structures from dev_private to process_private, which allows
secondary process to correctly initialize and uninitialize the eth_dev.

Fixes: 6435f9a0ac22 ("net/nfb: add new netcope driver")
Cc: stable@dpdk.org

Signed-off-by: Martin Spinler <spinler@cesnet.cz>
---
drivers/net/nfb/nfb.h | 11 +++-
drivers/net/nfb/nfb_ethdev.c | 103 +++++++++++++++++++++--------------
drivers/net/nfb/nfb_rx.c | 2 +-
drivers/net/nfb/nfb_rxmode.c | 12 ++--
drivers/net/nfb/nfb_tx.c | 2 +-
5 files changed, 79 insertions(+), 51 deletions(-)

diff --git a/drivers/net/nfb/nfb.h b/drivers/net/nfb/nfb.h
index 917b830283..90b04c6151 100644
--- a/drivers/net/nfb/nfb.h
+++ b/drivers/net/nfb/nfb.h
@@ -41,14 +41,23 @@ extern int nfb_logtype;

#define RTE_NFB_DRIVER_NAME net_nfb

-
+/*
+ * Handles obtained from the libnfb: each process must use own instance.
+ * Stored inside dev->process_private.
+ */
struct pmd_internals {
uint16_t max_rxmac;
uint16_t max_txmac;
struct nc_rxmac *rxmac[RTE_MAX_NC_RXMAC];
struct nc_txmac *txmac[RTE_MAX_NC_TXMAC];
struct nfb_device *nfb;
+};

+/*
+ * Common data, single instance usable in all processes.
+ * Inited in the RTE_PROC_PRIMARY, stored in dev->data->dev_private.
+ */
+struct pmd_priv {
uint16_t max_rx_queues;
uint16_t max_tx_queues;
};
diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c
index 5b1df83b7f..34949d6b1f 100644
--- a/drivers/net/nfb/nfb_ethdev.c
+++ b/drivers/net/nfb/nfb_ethdev.c
@@ -184,7 +184,7 @@ static int
nfb_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
{
int ret;
- struct pmd_internals *internals = dev->data->dev_private;
+ struct pmd_internals *internals = dev->process_private;
struct rte_eth_conf *dev_conf = &dev->data->dev_conf;

if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
@@ -207,7 +207,7 @@ nfb_eth_get_max_mac_address_count(struct rte_eth_dev *dev)
uint16_t i;
uint32_t c;
uint32_t ret = (uint32_t)-1;
- struct pmd_internals *internals = dev->data->dev_private;
+ struct pmd_internals *internals = dev->process_private;

/*
* Go through all RX MAC components in firmware and find
@@ -237,13 +237,13 @@ static int
nfb_eth_dev_info(struct rte_eth_dev *dev,
struct rte_eth_dev_info *dev_info)
{
- struct pmd_internals *internals = dev->data->dev_private;
+ struct pmd_priv *priv = dev->data->dev_private;

dev_info->max_mac_addrs = nfb_eth_get_max_mac_address_count(dev);

dev_info->max_rx_pktlen = (uint32_t)-1;
- dev_info->max_rx_queues = internals->max_rx_queues;
- dev_info->max_tx_queues = internals->max_tx_queues;
+ dev_info->max_rx_queues = priv->max_rx_queues;
+ dev_info->max_tx_queues = priv->max_tx_queues;
dev_info->speed_capa = RTE_ETH_LINK_SPEED_100G;
dev_info->rx_offload_capa =
RTE_ETH_RX_OFFLOAD_TIMESTAMP;
@@ -262,20 +262,20 @@ nfb_eth_dev_info(struct rte_eth_dev *dev,
static int
nfb_eth_dev_close(struct rte_eth_dev *dev)
{
- struct pmd_internals *internals = dev->data->dev_private;
+ struct pmd_internals *internals = dev->process_private;
uint16_t i;
uint16_t nb_rx = dev->data->nb_rx_queues;
uint16_t nb_tx = dev->data->nb_tx_queues;
int ret;

+ nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
+ nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
+
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
return 0;

ret = nfb_eth_dev_stop(dev);

- nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
- nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
-
for (i = 0; i < nb_rx; i++) {
nfb_eth_rx_queue_release(dev, i);
dev->data->rx_queues[i] = NULL;
@@ -310,7 +310,7 @@ nfb_eth_link_update(struct rte_eth_dev *dev,
struct rte_eth_link link;
memset(&link, 0, sizeof(link));

- struct pmd_internals *internals = dev->data->dev_private;
+ struct pmd_internals *internals = dev->process_private;

status.speed = MAC_SPEED_UNKNOWN;

@@ -365,7 +365,7 @@ static int
nfb_eth_dev_set_link_up(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = (struct pmd_internals *)
- dev->data->dev_private;
+ dev->process_private;

uint16_t i;
for (i = 0; i < internals->max_rxmac; ++i)
@@ -390,7 +390,7 @@ static int
nfb_eth_dev_set_link_down(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = (struct pmd_internals *)
- dev->data->dev_private;
+ dev->process_private;

uint16_t i;
for (i = 0; i < internals->max_rxmac; ++i)
@@ -431,9 +431,8 @@ nfb_eth_mac_addr_set(struct rte_eth_dev *dev,
{
unsigned int i;
uint64_t mac;
- struct rte_eth_dev_data *data = dev->data;
struct pmd_internals *internals = (struct pmd_internals *)
- data->dev_private;
+ dev->process_private;

mac = nfb_eth_mac_addr_conv(mac_addr);
/* Until no real multi-port support, configure all RX MACs the same */
@@ -449,9 +448,8 @@ nfb_eth_mac_addr_add(struct rte_eth_dev *dev,
{
unsigned int i;
uint64_t mac;
- struct rte_eth_dev_data *data = dev->data;
struct pmd_internals *internals = (struct pmd_internals *)
- data->dev_private;
+ dev->process_private;

mac = nfb_eth_mac_addr_conv(mac_addr);
for (i = 0; i < internals->max_rxmac; ++i)
@@ -464,9 +462,8 @@ static void
nfb_eth_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
{
unsigned int i;
- struct rte_eth_dev_data *data = dev->data;
struct pmd_internals *internals = (struct pmd_internals *)
- data->dev_private;
+ dev->process_private;

for (i = 0; i < internals->max_rxmac; ++i)
nc_rxmac_set_mac(internals->rxmac[i], index, 0, 0);
@@ -512,19 +509,31 @@ static const struct eth_dev_ops ops = {
static int
nfb_eth_dev_init(struct rte_eth_dev *dev)
{
+ int ret;
uint32_t mac_count;
struct rte_eth_dev_data *data = dev->data;
- struct pmd_internals *internals = (struct pmd_internals *)
- data->dev_private;
+ struct pmd_internals *internals;
+ struct pmd_priv *priv = data->dev_private;
struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
struct rte_pci_addr *pci_addr = &pci_dev->addr;
struct rte_ether_addr eth_addr_init;
+ uint16_t max_rx_queues, max_tx_queues;
char nfb_dev[PATH_MAX];

NFB_LOG(INFO, "Initializing NFB device (" PCI_PRI_FMT ")",
pci_addr->domain, pci_addr->bus, pci_addr->devid,
pci_addr->function);

+ internals = rte_zmalloc_socket("nfb_internals",
+ sizeof(struct pmd_internals), RTE_CACHE_LINE_SIZE,
+ dev->device->numa_node);
+ if (internals == NULL) {
+ ret = -ENOMEM;
+ return ret;
+ }
+
+ dev->process_private = internals;
+
snprintf(nfb_dev, sizeof(nfb_dev),
"/dev/nfb/by-pci-slot/" PCI_PRI_FMT,
pci_addr->domain, pci_addr->bus, pci_addr->devid,
@@ -538,13 +547,14 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
internals->nfb = nfb_open(nfb_dev);
if (internals->nfb == NULL) {
NFB_LOG(ERR, "nfb_open(): failed to open %s", nfb_dev);
+ rte_free(internals);
return -EINVAL;
}
- internals->max_rx_queues = ndp_get_rx_queue_available_count(internals->nfb);
- internals->max_tx_queues = ndp_get_tx_queue_available_count(internals->nfb);
+ max_rx_queues = ndp_get_rx_queue_available_count(internals->nfb);
+ max_tx_queues = ndp_get_tx_queue_available_count(internals->nfb);

NFB_LOG(INFO, "Available NDP queues RX: %u TX: %u",
- internals->max_rx_queues, internals->max_tx_queues);
+ max_rx_queues, max_tx_queues);

nfb_nc_rxmac_init(internals->nfb,
internals->rxmac,
@@ -563,28 +573,34 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
/* Get link state */
nfb_eth_link_update(dev, 0);

- /* Allocate space for MAC addresses */
- mac_count = nfb_eth_get_max_mac_address_count(dev);
- data->mac_addrs = rte_zmalloc(data->name,
- sizeof(struct rte_ether_addr) * mac_count, RTE_CACHE_LINE_SIZE);
- if (data->mac_addrs == NULL) {
- NFB_LOG(ERR, "Could not alloc space for MAC address");
- nfb_close(internals->nfb);
- return -EINVAL;
- }
+ if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+ priv->max_rx_queues = max_rx_queues;
+ priv->max_tx_queues = max_tx_queues;

- rte_eth_random_addr(eth_addr_init.addr_bytes);
- eth_addr_init.addr_bytes[0] = eth_addr.addr_bytes[0];
- eth_addr_init.addr_bytes[1] = eth_addr.addr_bytes[1];
- eth_addr_init.addr_bytes[2] = eth_addr.addr_bytes[2];
+ /* Allocate space for MAC addresses */
+ mac_count = nfb_eth_get_max_mac_address_count(dev);
+ data->mac_addrs = rte_zmalloc(data->name,
+ sizeof(struct rte_ether_addr) * mac_count, RTE_CACHE_LINE_SIZE);
+ if (data->mac_addrs == NULL) {
+ NFB_LOG(ERR, "Could not alloc space for MAC address");
+ nfb_close(internals->nfb);
+ rte_free(internals);
+ return -EINVAL;
+ }

- nfb_eth_mac_addr_set(dev, &eth_addr_init);
- rte_ether_addr_copy(&eth_addr_init, &dev->data->mac_addrs[0]);
+ rte_eth_random_addr(eth_addr_init.addr_bytes);
+ eth_addr_init.addr_bytes[0] = eth_addr.addr_bytes[0];
+ eth_addr_init.addr_bytes[1] = eth_addr.addr_bytes[1];
+ eth_addr_init.addr_bytes[2] = eth_addr.addr_bytes[2];

- data->promiscuous = nfb_eth_promiscuous_get(dev);
- data->all_multicast = nfb_eth_allmulticast_get(dev);
+ nfb_eth_mac_addr_set(dev, &eth_addr_init);
+ rte_ether_addr_copy(&eth_addr_init, &data->mac_addrs[0]);

- dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
+ data->promiscuous = nfb_eth_promiscuous_get(dev);
+ data->all_multicast = nfb_eth_allmulticast_get(dev);
+
+ data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
+ }

NFB_LOG(INFO, "NFB device (" PCI_PRI_FMT ") successfully initialized",
pci_addr->domain, pci_addr->bus, pci_addr->devid,
@@ -607,9 +623,12 @@ nfb_eth_dev_uninit(struct rte_eth_dev *dev)
{
struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
struct rte_pci_addr *pci_addr = &pci_dev->addr;
+ struct pmd_internals *internals = dev->process_private;

nfb_eth_dev_close(dev);

+ rte_free(internals);
+
NFB_LOG(INFO, "NFB device (" PCI_PRI_FMT ") successfully uninitialized",
pci_addr->domain, pci_addr->bus, pci_addr->devid,
pci_addr->function);
@@ -644,7 +663,7 @@ nfb_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
struct rte_pci_device *pci_dev)
{
return rte_eth_dev_pci_generic_probe(pci_dev,
- sizeof(struct pmd_internals), nfb_eth_dev_init);
+ sizeof(struct pmd_priv), nfb_eth_dev_init);
}

/**
diff --git a/drivers/net/nfb/nfb_rx.c b/drivers/net/nfb/nfb_rx.c
index 462bc3b50d..413d275853 100644
--- a/drivers/net/nfb/nfb_rx.c
+++ b/drivers/net/nfb/nfb_rx.c
@@ -60,7 +60,7 @@ nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
const struct rte_eth_rxconf *rx_conf __rte_unused,
struct rte_mempool *mb_pool)
{
- struct pmd_internals *internals = dev->data->dev_private;
+ struct pmd_internals *internals = dev->process_private;

struct ndp_rx_queue *rxq;
int ret;
diff --git a/drivers/net/nfb/nfb_rxmode.c b/drivers/net/nfb/nfb_rxmode.c
index ca6e4d5578..dc560d638b 100644
--- a/drivers/net/nfb/nfb_rxmode.c
+++ b/drivers/net/nfb/nfb_rxmode.c
@@ -11,7 +11,7 @@ int
nfb_eth_promiscuous_enable(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = (struct pmd_internals *)
- dev->data->dev_private;
+ dev->process_private;
uint16_t i;

for (i = 0; i < internals->max_rxmac; ++i) {
@@ -26,7 +26,7 @@ int
nfb_eth_promiscuous_disable(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = (struct pmd_internals *)
- dev->data->dev_private;
+ dev->process_private;
uint16_t i;
enum nc_rxmac_mac_filter filter = RXMAC_MAC_FILTER_TABLE_BCAST;

@@ -44,7 +44,7 @@ int
nfb_eth_promiscuous_get(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = (struct pmd_internals *)
- dev->data->dev_private;
+ dev->process_private;

struct nc_rxmac_status status;
status.mac_filter = RXMAC_MAC_FILTER_PROMISCUOUS;
@@ -59,7 +59,7 @@ int
nfb_eth_allmulticast_enable(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = (struct pmd_internals *)
- dev->data->dev_private;
+ dev->process_private;

uint16_t i;
if (dev->data->promiscuous)
@@ -76,7 +76,7 @@ int
nfb_eth_allmulticast_disable(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = (struct pmd_internals *)
- dev->data->dev_private;
+ dev->process_private;

uint16_t i;

@@ -95,7 +95,7 @@ int
nfb_eth_allmulticast_get(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = (struct pmd_internals *)
- dev->data->dev_private;
+ dev->process_private;

struct nc_rxmac_status status;
status.mac_filter = RXMAC_MAC_FILTER_PROMISCUOUS;
diff --git a/drivers/net/nfb/nfb_tx.c b/drivers/net/nfb/nfb_tx.c
index cf99268c43..1f997ce22f 100644
--- a/drivers/net/nfb/nfb_tx.c
+++ b/drivers/net/nfb/nfb_tx.c
@@ -53,7 +53,7 @@ nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
unsigned int socket_id,
const struct rte_eth_txconf *tx_conf __rte_unused)
{
- struct pmd_internals *internals = dev->data->dev_private;
+ struct pmd_internals *internals = dev->process_private;
int ret;
struct ndp_tx_queue *txq;

--
2.52.0