[PATCH v10 1/8] net/nfb: prepare for indirect queue mapping scheme

spinler
2026-02-17T07:10:51Z

The NFB driver is being enhanced to create one ethdev per physical
Ethernet port instead of one ethdev per PCI device. This requires
an indirect mapping layer because DPDK queue indices no longer
directly correspond to firmware queue indices.

This change adds queue_map_rx and queue_map_tx arrays to track the
mapping between DPDK queue indices and firmware queue IDs, preparing
for the multi-port implementation in subsequent patches.

Signed-off-by: Martin Spinler <spinler@cesnet.cz>
---
drivers/net/nfb/nfb.h | 6 ++++++
drivers/net/nfb/nfb_ethdev.c | 28 ++++++++++++++++++++++++++++
drivers/net/nfb/nfb_rx.c | 33 ++++++++++++++++++---------------
drivers/net/nfb/nfb_rx.h | 9 ++++-----
drivers/net/nfb/nfb_tx.c | 30 ++++++++++++++++++------------
drivers/net/nfb/nfb_tx.h | 7 +++----
6 files changed, 77 insertions(+), 36 deletions(-)

diff --git a/drivers/net/nfb/nfb.h b/drivers/net/nfb/nfb.h
index 90b04c6151..fa51afc7de 100644
--- a/drivers/net/nfb/nfb.h
+++ b/drivers/net/nfb/nfb.h
@@ -60,6 +60,12 @@ struct pmd_internals {
struct pmd_priv {
uint16_t max_rx_queues;
uint16_t max_tx_queues;
+
+ /** Mapping from DPDK RX queue index to firmware queue ID */
+ int *queue_map_rx;
+ /** Mapping from DPDK TX queue index to firmware queue ID */
+ int *queue_map_tx;
+ bool ready; /**< This structure is initialized for usage in secondary process */
};

#endif /* _NFB_H_ */
diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c
index 967f127f40..c0a2905249 100644
--- a/drivers/net/nfb/nfb_ethdev.c
+++ b/drivers/net/nfb/nfb_ethdev.c
@@ -509,6 +509,7 @@ static const struct eth_dev_ops ops = {
static int
nfb_eth_dev_init(struct rte_eth_dev *dev)
{
+ int i;
int ret;
uint32_t mac_count;
struct rte_eth_dev_data *data = dev->data;
@@ -577,6 +578,20 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
priv->max_rx_queues = max_rx_queues;
priv->max_tx_queues = max_tx_queues;

+ priv->queue_map_rx = rte_calloc("NFB queue map", max_rx_queues + max_tx_queues,
+ sizeof(*priv->queue_map_rx), 0);
+ if (priv->queue_map_rx == NULL) {
+ ret = -ENOMEM;
+ goto err_alloc_queue_map;
+ }
+ priv->queue_map_tx = priv->queue_map_rx + max_rx_queues;
+
+ /* default queue mapping is 1:1 */
+ for (i = 0; i < max_rx_queues; i++)
+ priv->queue_map_rx[i] = i;
+ for (i = 0; i < max_tx_queues; i++)
+ priv->queue_map_tx[i] = i;
+
/* Allocate space for MAC addresses */
mac_count = nfb_eth_get_max_mac_address_count(dev);
data->mac_addrs = rte_zmalloc(data->name,
@@ -599,6 +614,12 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
data->all_multicast = nfb_eth_allmulticast_get(dev);

data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
+ priv->ready = true;
+ } else {
+ if (!priv->ready) {
+ ret = -EBADFD;
+ goto err_secondary_not_ready;
+ }
}

NFB_LOG(INFO, "NFB device (" PCI_PRI_FMT ") successfully initialized",
@@ -608,6 +629,9 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
return 0;

err_malloc_mac_addrs:
+ rte_free(priv->queue_map_rx);
+err_alloc_queue_map:
+err_secondary_not_ready:
nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
nfb_close(internals->nfb);
@@ -633,6 +657,10 @@ 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;
+ struct pmd_priv *priv = dev->data->dev_private;
+
+ if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+ rte_free(priv->queue_map_rx);

nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
diff --git a/drivers/net/nfb/nfb_rx.c b/drivers/net/nfb/nfb_rx.c
index 413d275853..5b8579e280 100644
--- a/drivers/net/nfb/nfb_rx.c
+++ b/drivers/net/nfb/nfb_rx.c
@@ -61,12 +61,16 @@ nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
struct rte_mempool *mb_pool)
{
struct pmd_internals *internals = dev->process_private;
+ struct pmd_priv *priv = dev->data->dev_private;

- struct ndp_rx_queue *rxq;
int ret;
+ int qid;
+ struct ndp_rx_queue *rxq;
+
+ if (rx_queue_id >= priv->max_rx_queues)
+ return -EINVAL;

- rxq = rte_zmalloc_socket("ndp rx queue",
- sizeof(struct ndp_rx_queue),
+ rxq = rte_zmalloc_socket("ndp rx queue", sizeof(struct ndp_rx_queue),
RTE_CACHE_LINE_SIZE, socket_id);

if (rxq == NULL) {
@@ -77,23 +81,23 @@ nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,

rxq->flags = 0;

- ret = nfb_eth_rx_queue_init(internals->nfb,
- rx_queue_id,
- dev->data->port_id,
- mb_pool,
- rxq);
+ qid = priv->queue_map_rx[rx_queue_id];

- if (ret == 0)
- dev->data->rx_queues[rx_queue_id] = rxq;
- else
- rte_free(rxq);
+ ret = nfb_eth_rx_queue_init(internals->nfb, qid, dev->data->port_id, mb_pool, rxq);
+ if (ret)
+ goto err_queue_init;
+
+ dev->data->rx_queues[rx_queue_id] = rxq;
+ return 0;

+err_queue_init:
+ rte_free(rxq);
return ret;
}

int
nfb_eth_rx_queue_init(struct nfb_device *nfb,
- uint16_t rx_queue_id,
+ int qid,
uint16_t port_id,
struct rte_mempool *mb_pool,
struct ndp_rx_queue *rxq)
@@ -104,12 +108,11 @@ nfb_eth_rx_queue_init(struct nfb_device *nfb,
if (nfb == NULL)
return -EINVAL;

- rxq->queue = ndp_open_rx_queue(nfb, rx_queue_id);
+ rxq->queue = ndp_open_rx_queue(nfb, qid);
if (rxq->queue == NULL)
return -EINVAL;

rxq->nfb = nfb;
- rxq->rx_queue_id = rx_queue_id;
rxq->in_port = port_id;
rxq->mb_pool = mb_pool;
rxq->buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
diff --git a/drivers/net/nfb/nfb_rx.h b/drivers/net/nfb/nfb_rx.h
index 67b3b00e2a..831945c577 100644
--- a/drivers/net/nfb/nfb_rx.h
+++ b/drivers/net/nfb/nfb_rx.h
@@ -30,7 +30,6 @@ nfb_timestamp_dynfield(struct rte_mbuf *mbuf)
struct ndp_rx_queue {
struct nfb_device *nfb; /* nfb dev structure */
struct ndp_queue *queue; /* rx queue */
- uint16_t rx_queue_id; /* index */
uint8_t in_port; /* port */
uint8_t flags; /* setup flags */

@@ -47,8 +46,8 @@ struct ndp_rx_queue {
*
* @param nfb
* Pointer to nfb device structure.
- * @param rx_queue_id
- * RX queue index.
+ * @param qid
+ * RX queue ID.
* @param port_id
* Device [external] port identifier.
* @param mb_pool
@@ -60,7 +59,7 @@ struct ndp_rx_queue {
*/
int
nfb_eth_rx_queue_init(struct nfb_device *nfb,
- uint16_t rx_queue_id,
+ int qid,
uint16_t port_id,
struct rte_mempool *mb_pool,
struct ndp_rx_queue *rxq);
@@ -70,7 +69,7 @@ nfb_eth_rx_queue_init(struct nfb_device *nfb,
*
* @param dev
* Pointer to Ethernet device structure.
- * @param idx
+ * @param rx_queue_id
* RX queue index.
* @param desc
* Number of descriptors to configure in queue.
diff --git a/drivers/net/nfb/nfb_tx.c b/drivers/net/nfb/nfb_tx.c
index 1f997ce22f..1a7dcc3d30 100644
--- a/drivers/net/nfb/nfb_tx.c
+++ b/drivers/net/nfb/nfb_tx.c
@@ -54,11 +54,16 @@ nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
const struct rte_eth_txconf *tx_conf __rte_unused)
{
struct pmd_internals *internals = dev->process_private;
+ struct pmd_priv *priv = dev->data->dev_private;
+
int ret;
+ int qid;
struct ndp_tx_queue *txq;

- txq = rte_zmalloc_socket("ndp tx queue",
- sizeof(struct ndp_tx_queue),
+ if (tx_queue_id >= priv->max_tx_queues)
+ return -EINVAL;
+
+ txq = rte_zmalloc_socket("ndp tx queue", sizeof(struct ndp_tx_queue),
RTE_CACHE_LINE_SIZE, socket_id);

if (txq == NULL) {
@@ -67,32 +72,33 @@ nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
return -ENOMEM;
}

- ret = nfb_eth_tx_queue_init(internals->nfb,
- tx_queue_id,
- txq);
+ qid = priv->queue_map_tx[tx_queue_id];

- if (ret == 0)
- dev->data->tx_queues[tx_queue_id] = txq;
- else
- rte_free(txq);
+ ret = nfb_eth_tx_queue_init(internals->nfb, qid, txq);
+ if (ret)
+ goto err_queue_init;

+ dev->data->tx_queues[tx_queue_id] = txq;
+ return 0;
+
+err_queue_init:
+ rte_free(txq);
return ret;
}

int
nfb_eth_tx_queue_init(struct nfb_device *nfb,
- uint16_t tx_queue_id,
+ int qid,
struct ndp_tx_queue *txq)
{
if (nfb == NULL)
return -EINVAL;

- txq->queue = ndp_open_tx_queue(nfb, tx_queue_id);
+ txq->queue = ndp_open_tx_queue(nfb, qid);
if (txq->queue == NULL)
return -EINVAL;

txq->nfb = nfb;
- txq->tx_queue_id = tx_queue_id;

txq->tx_pkts = 0;
txq->tx_bytes = 0;
diff --git a/drivers/net/nfb/nfb_tx.h b/drivers/net/nfb/nfb_tx.h
index f107cf914b..c253af1a86 100644
--- a/drivers/net/nfb/nfb_tx.h
+++ b/drivers/net/nfb/nfb_tx.h
@@ -17,7 +17,6 @@
struct ndp_tx_queue {
struct nfb_device *nfb; /* nfb dev structure */
struct ndp_queue *queue; /* tx queue */
- uint16_t tx_queue_id; /* index */
volatile uint64_t tx_pkts; /* packets transmitted */
volatile uint64_t tx_bytes; /* bytes transmitted */
volatile uint64_t err_pkts; /* erroneous packets */
@@ -54,8 +53,8 @@ nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
*
* @param nfb
* Pointer to nfb device structure.
- * @param tx_queue_id
- * TX queue index.
+ * @param qid
+ * TX queue ID.
* @param[out] txq
* Pointer to ndp_tx_queue output structure
*
@@ -64,7 +63,7 @@ nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
*/
int
nfb_eth_tx_queue_init(struct nfb_device *nfb,
- uint16_t tx_queue_id,
+ int qid,
struct ndp_tx_queue *txq);

/**
--
2.53.0