Skip to content

Commit b91dcb2

Browse files
Danielmachonkuba-moo
authored andcommitted
net: sparx5: split sparx5_fdma_{start(),stop()}
The two functions: sparx5_fdma_{start(),stop()} are responsible for a number of things, namely: allocation and initialization of FDMA buffers, activation FDMA channels in hardware and activation of the NAPI instance. This patch splits the buffer allocation and initialization into init and deinit functions, and the channel and NAPI activation into start and stop functions. This serves two purposes: 1) the start() and stop() functions can be reused for lan969x and 2) prepares for future MTU change support, where we must be able to stop and start the FDMA channels and NAPI instance, without free'ing and reallocating the FDMA buffers. Reviewed-by: Steen Hegelund <[email protected]> Signed-off-by: Daniel Machon <[email protected]> Link: https://patch.msgid.link/20250113-sparx5-lan969x-switch-driver-5-v2-2-c468f02fd623@microchip.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4a7d78c commit b91dcb2

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,6 @@ static int sparx5_fdma_rx_alloc(struct sparx5 *sparx5)
260260
fdma_dcbs_init(fdma, FDMA_DCB_INFO_DATAL(fdma->db_size),
261261
FDMA_DCB_STATUS_INTR);
262262

263-
netif_napi_add_weight(rx->ndev, &rx->napi, sparx5_fdma_napi_callback,
264-
FDMA_WEIGHT);
265-
napi_enable(&rx->napi);
266-
sparx5_fdma_rx_activate(sparx5, rx);
267263
return 0;
268264
}
269265

@@ -410,7 +406,7 @@ static void sparx5_fdma_injection_mode(struct sparx5 *sparx5)
410406
}
411407
}
412408

413-
int sparx5_fdma_start(struct sparx5 *sparx5)
409+
int sparx5_fdma_init(struct sparx5 *sparx5)
414410
{
415411
int err;
416412

@@ -443,24 +439,52 @@ int sparx5_fdma_start(struct sparx5 *sparx5)
443439
return err;
444440
}
445441

442+
int sparx5_fdma_deinit(struct sparx5 *sparx5)
443+
{
444+
sparx5_fdma_stop(sparx5);
445+
fdma_free_phys(&sparx5->rx.fdma);
446+
fdma_free_phys(&sparx5->tx.fdma);
447+
448+
return 0;
449+
}
450+
446451
static u32 sparx5_fdma_port_ctrl(struct sparx5 *sparx5)
447452
{
448453
return spx5_rd(sparx5, FDMA_PORT_CTRL(0));
449454
}
450455

456+
int sparx5_fdma_start(struct sparx5 *sparx5)
457+
{
458+
struct sparx5_rx *rx = &sparx5->rx;
459+
460+
netif_napi_add_weight(rx->ndev,
461+
&rx->napi,
462+
sparx5_fdma_napi_callback,
463+
FDMA_WEIGHT);
464+
465+
napi_enable(&rx->napi);
466+
467+
sparx5_fdma_rx_activate(sparx5, rx);
468+
469+
return 0;
470+
}
471+
451472
int sparx5_fdma_stop(struct sparx5 *sparx5)
452473
{
474+
struct sparx5_rx *rx = &sparx5->rx;
475+
struct sparx5_tx *tx = &sparx5->tx;
453476
u32 val;
454477

455-
napi_disable(&sparx5->rx.napi);
478+
napi_disable(&rx->napi);
479+
456480
/* Stop the fdma and channel interrupts */
457-
sparx5_fdma_rx_deactivate(sparx5, &sparx5->rx);
458-
sparx5_fdma_tx_deactivate(sparx5, &sparx5->tx);
481+
sparx5_fdma_rx_deactivate(sparx5, rx);
482+
sparx5_fdma_tx_deactivate(sparx5, tx);
483+
459484
/* Wait for the RX channel to stop */
460485
read_poll_timeout(sparx5_fdma_port_ctrl, val,
461486
FDMA_PORT_CTRL_XTR_BUF_IS_EMPTY_GET(val) == 0,
462487
500, 10000, 0, sparx5);
463-
fdma_free_phys(&sparx5->rx.fdma);
464-
fdma_free_phys(&sparx5->tx.fdma);
488+
465489
return 0;
466490
}

drivers/net/ethernet/microchip/sparx5/sparx5_main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,11 @@ static int sparx5_start(struct sparx5 *sparx5)
792792
sparx5_fdma_handler,
793793
0,
794794
"sparx5-fdma", sparx5);
795-
if (!err)
796-
err = sparx5_fdma_start(sparx5);
795+
if (!err) {
796+
err = sparx5_fdma_init(sparx5);
797+
if (!err)
798+
sparx5_fdma_start(sparx5);
799+
}
797800
if (err)
798801
sparx5->fdma_irq = -ENXIO;
799802
} else {

drivers/net/ethernet/microchip/sparx5/sparx5_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ int sparx5_manual_injection_mode(struct sparx5 *sparx5);
436436
void sparx5_port_inj_timer_setup(struct sparx5_port *port);
437437

438438
/* sparx5_fdma.c */
439+
int sparx5_fdma_init(struct sparx5 *sparx5);
440+
int sparx5_fdma_deinit(struct sparx5 *sparx5);
439441
int sparx5_fdma_start(struct sparx5 *sparx5);
440442
int sparx5_fdma_stop(struct sparx5 *sparx5);
441443
int sparx5_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb);

0 commit comments

Comments
 (0)