linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU
@ 2024-02-13 12:17 Horatiu Vultur
  2024-02-13 16:22 ` Daniel Machon
  2024-02-13 17:26 ` Florian Fainelli
  0 siblings, 2 replies; 6+ messages in thread
From: Horatiu Vultur @ 2024-02-13 12:17 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
	daniel.machon, UNGLinuxDriver
  Cc: u.kleine-koenig, rmk+kernel, vladimir.oltean, jacob.e.keller,
	yuehaibing, netdev, linux-arm-kernel, linux-kernel,
	Horatiu Vultur

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>
---
 drivers/net/ethernet/microchip/sparx5/sparx5_main.c   | 1 +
 drivers/net/ethernet/microchip/sparx5/sparx5_main.h   | 1 +
 drivers/net/ethernet/microchip/sparx5/sparx5_packet.c | 2 ++
 3 files changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
index d1f7fc8b1b71a..3c066b62e6894 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
@@ -757,6 +757,7 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, sparx5);
 	sparx5->pdev = pdev;
 	sparx5->dev = &pdev->dev;
+	spin_lock_init(&sparx5->tx_lock);
 
 	/* Do switch core reset if available */
 	reset = devm_reset_control_get_optional_shared(&pdev->dev, "switch");
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
index 6f565c0c0c3dc..316fed5f27355 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
@@ -280,6 +280,7 @@ struct sparx5 {
 	int xtr_irq;
 	/* Frame DMA */
 	int fdma_irq;
+	spinlock_t tx_lock; /* lock for frame transmission */
 	struct sparx5_rx rx;
 	struct sparx5_tx tx;
 	/* PTP */
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
index 6db6ac6a3bbc2..ac7e1cffbcecf 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
@@ -244,10 +244,12 @@ netdev_tx_t sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev)
 	}
 
 	skb_tx_timestamp(skb);
+	spin_lock(&sparx5->tx_lock);
 	if (sparx5->fdma_irq > 0)
 		ret = sparx5_fdma_xmit(sparx5, ifh, skb);
 	else
 		ret = sparx5_inject(sparx5, ifh, skb, dev);
+	spin_unlock(&sparx5->tx_lock);
 
 	if (ret == -EBUSY)
 		goto busy;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU
  2024-02-13 12:17 [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU Horatiu Vultur
@ 2024-02-13 16:22 ` Daniel Machon
  2024-02-13 17:26 ` Florian Fainelli
  1 sibling, 0 replies; 6+ messages in thread
From: Daniel Machon @ 2024-02-13 16:22 UTC (permalink / raw)
  To: Horatiu Vultur
  Cc: davem, edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
	UNGLinuxDriver, u.kleine-koenig, rmk+kernel, vladimir.oltean,
	jacob.e.keller, yuehaibing, netdev, linux-arm-kernel,
	linux-kernel

> 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.

Reviewed-by: Daniel Machon <daniel.machon@microchip.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU
  2024-02-13 12:17 [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU Horatiu Vultur
  2024-02-13 16:22 ` Daniel Machon
@ 2024-02-13 17:26 ` Florian Fainelli
  2024-02-14  8:14   ` Horatiu Vultur
  1 sibling, 1 reply; 6+ messages in thread
From: Florian Fainelli @ 2024-02-13 17:26 UTC (permalink / raw)
  To: Horatiu Vultur, davem, edumazet, kuba, pabeni, lars.povlsen,
	Steen.Hegelund, daniel.machon, UNGLinuxDriver
  Cc: u.kleine-koenig, rmk+kernel, vladimir.oltean, jacob.e.keller,
	yuehaibing, netdev, linux-arm-kernel, linux-kernel

On 2/13/24 04:17, Horatiu Vultur wrote:
> 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>

Any reason you targeted 'net-next' rather than 'net', as this appears to 
be clearly a bug fix here?
-- 
Florian


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU
  2024-02-13 17:26 ` Florian Fainelli
@ 2024-02-14  8:14   ` Horatiu Vultur
  2024-02-14 15:09     ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Horatiu Vultur @ 2024-02-14  8:14 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: davem, edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
	daniel.machon, UNGLinuxDriver, u.kleine-koenig, rmk+kernel,
	vladimir.oltean, jacob.e.keller, yuehaibing, netdev,
	linux-arm-kernel, linux-kernel

The 02/13/2024 09:26, Florian Fainelli wrote:
> 
> On 2/13/24 04:17, Horatiu Vultur wrote:
> > 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>
> 
> Any reason you targeted 'net-next' rather than 'net', as this appears to
> be clearly a bug fix here?

Yes, it is a bug but it is not something that happens all the
time and I thought this fits more into the lines of 'This could be a
problem ...' therefore I had targeted 'net-next'.
But if you consider that I should target 'net' instead of 'net-next' I
can do that.

> --
> Florian
> 

-- 
/Horatiu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU
  2024-02-14  8:14   ` Horatiu Vultur
@ 2024-02-14 15:09     ` Jakub Kicinski
  2024-02-15  8:07       ` Horatiu Vultur
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2024-02-14 15:09 UTC (permalink / raw)
  To: Horatiu Vultur
  Cc: Florian Fainelli, davem, edumazet, pabeni, lars.povlsen,
	Steen.Hegelund, daniel.machon, UNGLinuxDriver, u.kleine-koenig,
	rmk+kernel, vladimir.oltean, jacob.e.keller, yuehaibing, netdev,
	linux-arm-kernel, linux-kernel

On Wed, 14 Feb 2024 09:14:42 +0100 Horatiu Vultur wrote:
> > Any reason you targeted 'net-next' rather than 'net', as this appears to
> > be clearly a bug fix here?  
> 
> Yes, it is a bug but it is not something that happens all the
> time and I thought this fits more into the lines of 'This could be a
> problem ...' therefore I had targeted 'net-next'.
> But if you consider that I should target 'net' instead of 'net-next' I
> can do that.

Definitely a bug fix worthy of net, yes, please.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU
  2024-02-14 15:09     ` Jakub Kicinski
@ 2024-02-15  8:07       ` Horatiu Vultur
  0 siblings, 0 replies; 6+ messages in thread
From: Horatiu Vultur @ 2024-02-15  8:07 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Florian Fainelli, davem, edumazet, pabeni, lars.povlsen,
	Steen.Hegelund, daniel.machon, UNGLinuxDriver, u.kleine-koenig,
	rmk+kernel, vladimir.oltean, jacob.e.keller, yuehaibing, netdev,
	linux-arm-kernel, linux-kernel

The 02/14/2024 07:09, Jakub Kicinski wrote:
> 
> On Wed, 14 Feb 2024 09:14:42 +0100 Horatiu Vultur wrote:
> > > Any reason you targeted 'net-next' rather than 'net', as this appears to
> > > be clearly a bug fix here?
> >
> > Yes, it is a bug but it is not something that happens all the
> > time and I thought this fits more into the lines of 'This could be a
> > problem ...' therefore I had targeted 'net-next'.
> > But if you consider that I should target 'net' instead of 'net-next' I
> > can do that.
> 
> Definitely a bug fix worthy of net, yes, please.

Perfect, I will do that.

> 

-- 
/Horatiu

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-02-15  8:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13 12:17 [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU Horatiu Vultur
2024-02-13 16:22 ` Daniel Machon
2024-02-13 17:26 ` Florian Fainelli
2024-02-14  8:14   ` Horatiu Vultur
2024-02-14 15:09     ` Jakub Kicinski
2024-02-15  8:07       ` Horatiu Vultur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).