[PATCH net-next 4/9] net: sparx5/lan969x: pass the FDMA rings to the init and alloc functions
From: Daniel Machon
Date: Thu Nov 05 2026 - 09:04:49 EST
The FDMA RX and TX rings are initialized and allocated by functions that
take struct sparx5, and operate on the rings in it. The RX buffer
callbacks also find the RX ring through struct sparx5, and the DB size
is computed in the RX and TX init functions.
In preparation for MTU support, where a new set of rings must be set up
while the FDMA keeps running on the current ones, make these functions
operate on the ring passed to them, and pass the DB size to the Sparx5
init functions. Find the RX ring in the RX buffer callbacks from the FDMA
that is passed to them. On lan969x, TX frames are mapped directly from
the skbs, so only the RX ring has to be replaced. Therefore, only its RX
functions take a ring, and its RX init function keeps computing the DB
size.
No functional change intended.
Signed-off-by: Daniel Machon <daniel.machon@xxxxxxxxxxxxx>
---
.../microchip/sparx5/lan969x/lan969x_fdma.c | 28 ++++++++++----------
.../net/ethernet/microchip/sparx5/sparx5_fdma.c | 30 ++++++++++------------
2 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c
index d162bea02cbfb..5a6521ff774d8 100644
--- a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c
+++ b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c
@@ -25,7 +25,7 @@ static int lan969x_fdma_tx_dataptr_cb(struct fdma *fdma, int dcb, int db,
static int lan969x_fdma_rx_dataptr_cb(struct fdma *fdma, int dcb, int db,
u64 *dataptr)
{
- struct sparx5_rx *rx = &FDMA_PRIV(fdma)->rx;
+ struct sparx5_rx *rx = container_of(fdma, struct sparx5_rx, fdma);
struct page *page;
page = page_pool_dev_alloc_pages(rx->page_pool);
@@ -104,10 +104,8 @@ static void lan969x_fdma_free_pages(struct sparx5_rx *rx)
/* Return the pages in the RX ring to the page_pool, and free the page_pool
* and the RX DCBs.
*/
-static void lan969x_fdma_rx_free(struct sparx5 *sparx5)
+static void lan969x_fdma_rx_free(struct sparx5 *sparx5, struct sparx5_rx *rx)
{
- struct sparx5_rx *rx = &sparx5->rx;
-
lan969x_fdma_free_pages(rx);
fdma_free_coherent(sparx5->dev, &rx->fdma);
page_pool_destroy(rx->page_pool);
@@ -163,9 +161,8 @@ static struct sk_buff *lan969x_fdma_rx_get_frame(struct sparx5 *sparx5,
return NULL;
}
-static int lan969x_fdma_rx_alloc(struct sparx5 *sparx5)
+static int lan969x_fdma_rx_alloc(struct sparx5 *sparx5, struct sparx5_rx *rx)
{
- struct sparx5_rx *rx = &sparx5->rx;
struct fdma *fdma = &rx->fdma;
int err;
@@ -195,7 +192,7 @@ static int lan969x_fdma_rx_alloc(struct sparx5 *sparx5)
FDMA_DCB_INFO_DATAL(fdma->db_size),
FDMA_DCB_STATUS_INTR);
if (err)
- lan969x_fdma_rx_free(sparx5);
+ lan969x_fdma_rx_free(sparx5, rx);
return err;
}
@@ -232,9 +229,9 @@ static void lan969x_fdma_tx_free(struct sparx5 *sparx5)
kfree(tx->dbs);
}
-static void lan969x_fdma_rx_init(struct sparx5 *sparx5)
+static void lan969x_fdma_rx_init(struct sparx5 *sparx5, struct sparx5_rx *rx)
{
- struct fdma *fdma = &sparx5->rx.fdma;
+ struct fdma *fdma = &rx->fdma;
fdma->channel_id = FDMA_XTR_CHANNEL;
fdma->n_dcbs = FDMA_DCB_MAX;
@@ -250,7 +247,7 @@ static void lan969x_fdma_rx_init(struct sparx5 *sparx5)
struct sparx5_port *port = sparx5->ports[idx];
if (port && port->ndev) {
- sparx5->rx.ndev = port->ndev;
+ rx->ndev = port->ndev;
break;
}
}
@@ -383,9 +380,10 @@ int lan969x_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb,
int lan969x_fdma_init(struct sparx5 *sparx5)
{
+ struct sparx5_rx *rx = &sparx5->rx;
int err;
- lan969x_fdma_rx_init(sparx5);
+ lan969x_fdma_rx_init(sparx5, rx);
lan969x_fdma_tx_init(sparx5);
sparx5_fdma_injection_mode(sparx5);
@@ -395,7 +393,7 @@ int lan969x_fdma_init(struct sparx5 *sparx5)
return err;
}
- err = lan969x_fdma_rx_alloc(sparx5);
+ err = lan969x_fdma_rx_alloc(sparx5, rx);
if (err) {
dev_err(sparx5->dev, "Failed to allocate RX buffers: %d\n",
err);
@@ -404,7 +402,7 @@ int lan969x_fdma_init(struct sparx5 *sparx5)
err = lan969x_fdma_tx_alloc(sparx5);
if (err) {
- lan969x_fdma_rx_free(sparx5);
+ lan969x_fdma_rx_free(sparx5, rx);
dev_err(sparx5->dev, "Failed to allocate TX buffers: %d\n",
err);
return err;
@@ -419,9 +417,11 @@ int lan969x_fdma_init(struct sparx5 *sparx5)
int lan969x_fdma_deinit(struct sparx5 *sparx5)
{
+ struct sparx5_rx *rx = &sparx5->rx;
+
sparx5_fdma_stop(sparx5);
lan969x_fdma_tx_free(sparx5);
- lan969x_fdma_rx_free(sparx5);
+ lan969x_fdma_rx_free(sparx5, rx);
return 0;
}
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
index f4e8ac00dbe2f..7ac5887abe6ee 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
@@ -35,8 +35,7 @@ static int sparx5_fdma_tx_dataptr_cb(struct fdma *fdma, int dcb, int db,
static int sparx5_fdma_rx_dataptr_cb(struct fdma *fdma, int dcb, int db,
u64 *dataptr)
{
- struct sparx5 *sparx5 = fdma->priv;
- struct sparx5_rx *rx = &sparx5->rx;
+ struct sparx5_rx *rx = container_of(fdma, struct sparx5_rx, fdma);
struct sk_buff *skb;
skb = __netdev_alloc_skb(rx->ndev, fdma->db_size, GFP_ATOMIC);
@@ -258,9 +257,8 @@ static void sparx5_fdma_rx_free(struct sparx5_rx *rx)
fdma_free_phys(fdma);
}
-static int sparx5_fdma_rx_alloc(struct sparx5 *sparx5)
+static int sparx5_fdma_rx_alloc(struct sparx5_rx *rx)
{
- struct sparx5_rx *rx = &sparx5->rx;
struct fdma *fdma = &rx->fdma;
int err;
@@ -276,9 +274,8 @@ static int sparx5_fdma_rx_alloc(struct sparx5 *sparx5)
return err;
}
-static int sparx5_fdma_tx_alloc(struct sparx5 *sparx5)
+static int sparx5_fdma_tx_alloc(struct sparx5_tx *tx)
{
- struct sparx5_tx *tx = &sparx5->tx;
struct fdma *fdma = &tx->fdma;
int err;
@@ -293,7 +290,7 @@ static int sparx5_fdma_tx_alloc(struct sparx5 *sparx5)
}
static void sparx5_fdma_rx_init(struct sparx5 *sparx5,
- struct sparx5_rx *rx, int channel)
+ struct sparx5_rx *rx, int channel, u32 db_size)
{
struct fdma *fdma = &rx->fdma;
int idx;
@@ -302,8 +299,8 @@ static void sparx5_fdma_rx_init(struct sparx5 *sparx5,
fdma->n_dcbs = FDMA_DCB_MAX;
fdma->n_dbs = FDMA_RX_DCB_MAX_DBS;
fdma->priv = sparx5;
- fdma->db_size = ALIGN(FDMA_XTR_BUFFER_SIZE, PAGE_SIZE);
- fdma->size = fdma_get_size(&sparx5->rx.fdma);
+ fdma->db_size = db_size;
+ fdma->size = fdma_get_size(fdma);
fdma->ops.dataptr_cb = &sparx5_fdma_rx_dataptr_cb;
fdma->ops.nextptr_cb = &fdma_nextptr_cb;
/* Fetch a netdev for SKB and NAPI use, any will do */
@@ -318,7 +315,7 @@ static void sparx5_fdma_rx_init(struct sparx5 *sparx5,
}
static void sparx5_fdma_tx_init(struct sparx5 *sparx5,
- struct sparx5_tx *tx, int channel)
+ struct sparx5_tx *tx, int channel, u32 db_size)
{
struct fdma *fdma = &tx->fdma;
@@ -326,8 +323,8 @@ static void sparx5_fdma_tx_init(struct sparx5 *sparx5,
fdma->n_dcbs = FDMA_DCB_MAX;
fdma->n_dbs = FDMA_TX_DCB_MAX_DBS;
fdma->priv = sparx5;
- fdma->db_size = ALIGN(FDMA_XTR_BUFFER_SIZE, PAGE_SIZE);
- fdma->size = fdma_get_size_contiguous(&sparx5->tx.fdma);
+ fdma->db_size = db_size;
+ fdma->size = fdma_get_size_contiguous(fdma);
fdma->ops.dataptr_cb = &sparx5_fdma_tx_dataptr_cb;
fdma->ops.nextptr_cb = &fdma_nextptr_cb;
}
@@ -421,6 +418,7 @@ void sparx5_fdma_injection_mode(struct sparx5 *sparx5)
int sparx5_fdma_init(struct sparx5 *sparx5)
{
+ u32 db_size = ALIGN(FDMA_XTR_BUFFER_SIZE, PAGE_SIZE);
int err;
/* Reset FDMA state */
@@ -437,14 +435,14 @@ int sparx5_fdma_init(struct sparx5 *sparx5)
sparx5, CPU_PROC_CTRL);
sparx5_fdma_injection_mode(sparx5);
- sparx5_fdma_rx_init(sparx5, &sparx5->rx, FDMA_XTR_CHANNEL);
- sparx5_fdma_tx_init(sparx5, &sparx5->tx, FDMA_INJ_CHANNEL);
- err = sparx5_fdma_rx_alloc(sparx5);
+ sparx5_fdma_rx_init(sparx5, &sparx5->rx, FDMA_XTR_CHANNEL, db_size);
+ sparx5_fdma_tx_init(sparx5, &sparx5->tx, FDMA_INJ_CHANNEL, db_size);
+ err = sparx5_fdma_rx_alloc(&sparx5->rx);
if (err) {
dev_err(sparx5->dev, "Could not allocate RX buffers: %d\n", err);
return err;
}
- err = sparx5_fdma_tx_alloc(sparx5);
+ err = sparx5_fdma_tx_alloc(&sparx5->tx);
if (err) {
sparx5_fdma_rx_free(&sparx5->rx);
dev_err(sparx5->dev, "Could not allocate TX buffers: %d\n", err);
--
2.34.1