Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: sparx5: Add spinlock for frame transmission from CPU

Both registers used when doing manual injection or fdma injection are
shared between all the net devices of the switch. It was noticed that
when having two process which each of them trying to inject frames on
different ethernet ports, that the HW started to behave strange, by
sending out more frames then expected. When doing fdma injection it is
required to set the frame in the DCB and then make sure that the next
pointer of the last DCB is invalid. But because there is no locks for
this, then easily this pointer between the DCB can be broken and then it
would create a loop of DCBs. And that means that the HW will
continuously transmit these frames in a loop. Until the SW will break
this loop.
Therefore to fix this issue, add a spin lock for when accessing the
registers for manual or fdma injection.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
Fixes: f3cad2611a77 ("net: sparx5: add hostmode with phylink support")
Link: https://lore.kernel.org/r/20240219080043.1561014-1-horatiu.vultur@microchip.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Horatiu Vultur and committed by
Jakub Kicinski
603ead96 1fde0ca3

+4
+1
drivers/net/ethernet/microchip/sparx5/sparx5_main.c
··· 757 757 platform_set_drvdata(pdev, sparx5); 758 758 sparx5->pdev = pdev; 759 759 sparx5->dev = &pdev->dev; 760 + spin_lock_init(&sparx5->tx_lock); 760 761 761 762 /* Do switch core reset if available */ 762 763 reset = devm_reset_control_get_optional_shared(&pdev->dev, "switch");
+1
drivers/net/ethernet/microchip/sparx5/sparx5_main.h
··· 280 280 int xtr_irq; 281 281 /* Frame DMA */ 282 282 int fdma_irq; 283 + spinlock_t tx_lock; /* lock for frame transmission */ 283 284 struct sparx5_rx rx; 284 285 struct sparx5_tx tx; 285 286 /* PTP */
+2
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
··· 244 244 } 245 245 246 246 skb_tx_timestamp(skb); 247 + spin_lock(&sparx5->tx_lock); 247 248 if (sparx5->fdma_irq > 0) 248 249 ret = sparx5_fdma_xmit(sparx5, ifh, skb); 249 250 else 250 251 ret = sparx5_inject(sparx5, ifh, skb, dev); 252 + spin_unlock(&sparx5->tx_lock); 251 253 252 254 if (ret == -EBUSY) 253 255 goto busy;