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 --- .../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 5f96910df5383..3036d6b6f043c 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); @@ -101,10 +101,8 @@ static void lan969x_fdma_free_pages(struct sparx5_rx *rx) } } -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; } @@ -261,9 +258,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; @@ -279,7 +276,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; } } @@ -411,9 +408,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); @@ -423,7 +421,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); @@ -432,7 +430,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; @@ -447,9 +445,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 f1d44e5e080b6..537c945409bba 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); @@ -264,9 +263,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; @@ -282,9 +280,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; @@ -299,7 +296,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; @@ -308,8 +305,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 */ @@ -324,7 +321,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; @@ -332,8 +329,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; } @@ -427,6 +424,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 */ @@ -443,14 +441,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