linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] marvell sky2 driver: fix so it works without unaligned accesses
@ 2012-04-03 15:13 Chris Metcalf
  2012-04-03 16:17 ` Stephen Hemminger
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Chris Metcalf @ 2012-04-03 15:13 UTC (permalink / raw)
  To: Stephen Hemminger, netdev, linux-kernel

The driver uses a receive_new() routine that ends up requiring unaligned
accesses in IP header processing.  If the architecture doesn't support
efficient unaligned accesses, just copy all ingress packets to the bounce
buffers instead.

This allows the driver to be used on the Tilera TILEmpower-Gx, since
the tile architecture doesn't currently handle kernel unaligned accesses,
just userspace.

Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
---
 drivers/net/ethernet/marvell/sky2.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index 879b0a4..7a15482 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -2490,6 +2490,7 @@ static struct sk_buff *receive_copy(struct sky2_port *sky2,
 	return skb;
 }
 
+#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 /* Adjust length of skb with fragments to match received data */
 static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
 			  unsigned int length)
@@ -2555,6 +2556,7 @@ nomap:
 nobuf:
 	return NULL;
 }
+#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */
 
 /*
  * Receive one packet.
@@ -2598,10 +2600,12 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
 		goto error;
 
 okay:
-	if (length < copybreak)
-		skb = receive_copy(sky2, re, length);
-	else
+#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+	if (length >= copybreak)
 		skb = receive_new(sky2, re, length);
+	else
+#endif
+		skb = receive_copy(sky2, re, length);
 
 	dev->stats.rx_dropped += (skb == NULL);
 
-- 
1.6.5.2


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

* Re: [PATCH] marvell sky2 driver: fix so it works without unaligned accesses
  2012-04-03 15:13 [PATCH] marvell sky2 driver: fix so it works without unaligned accesses Chris Metcalf
@ 2012-04-03 16:17 ` Stephen Hemminger
  2012-04-03 16:18 ` Eric Dumazet
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Stephen Hemminger @ 2012-04-03 16:17 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: netdev, linux-kernel

On Tue, 3 Apr 2012 11:13:56 -0400
Chris Metcalf <cmetcalf@tilera.com> wrote:

> The driver uses a receive_new() routine that ends up requiring unaligned
> accesses in IP header processing.  If the architecture doesn't support
> efficient unaligned accesses, just copy all ingress packets to the bounce
> buffers instead.
> 
> This allows the driver to be used on the Tilera TILEmpower-Gx, since
> the tile architecture doesn't currently handle kernel unaligned accesses,
> just userspace.
> 
> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>

There are many other encapsulation cases where IP header won't be
aligned. Why not just set copybreak module option to a very large value?

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

* Re: [PATCH] marvell sky2 driver: fix so it works without unaligned accesses
  2012-04-03 15:13 [PATCH] marvell sky2 driver: fix so it works without unaligned accesses Chris Metcalf
  2012-04-03 16:17 ` Stephen Hemminger
@ 2012-04-03 16:18 ` Eric Dumazet
  2012-04-03 21:46 ` David Miller
  2012-04-04 14:13 ` [PATCH v2] " Chris Metcalf
  3 siblings, 0 replies; 10+ messages in thread
From: Eric Dumazet @ 2012-04-03 16:18 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: Stephen Hemminger, netdev, linux-kernel

On Tue, 2012-04-03 at 11:13 -0400, Chris Metcalf wrote:
> The driver uses a receive_new() routine that ends up requiring unaligned
> accesses in IP header processing.  If the architecture doesn't support
> efficient unaligned accesses, just copy all ingress packets to the bounce
> buffers instead.
> 
> This allows the driver to be used on the Tilera TILEmpower-Gx, since
> the tile architecture doesn't currently handle kernel unaligned accesses,
> just userspace.
> 
> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
> ---
>  drivers/net/ethernet/marvell/sky2.c |   10 +++++++---
>  1 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
> index 879b0a4..7a15482 100644
> --- a/drivers/net/ethernet/marvell/sky2.c
> +++ b/drivers/net/ethernet/marvell/sky2.c
> @@ -2490,6 +2490,7 @@ static struct sk_buff *receive_copy(struct sky2_port *sky2,
>  	return skb;
>  }
>  
> +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
>  /* Adjust length of skb with fragments to match received data */
>  static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
>  			  unsigned int length)
> @@ -2555,6 +2556,7 @@ nomap:
>  nobuf:
>  	return NULL;
>  }
> +#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */
>  
>  /*
>   * Receive one packet.
> @@ -2598,10 +2600,12 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
>  		goto error;
>  
>  okay:
> -	if (length < copybreak)
> -		skb = receive_copy(sky2, re, length);
> -	else
> +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
> +	if (length >= copybreak)
>  		skb = receive_new(sky2, re, length);
> +	else
> +#endif
> +		skb = receive_copy(sky2, re, length);
>  
>  	dev->stats.rx_dropped += (skb == NULL);
>  

The (expensive ?) copy should be done only if (sky2->hw->flags &
SKY2_HW_RAM_BUFFER)

diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index b806d9b..3da3cdc 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -2599,7 +2599,11 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
 		goto error;
 
 okay:
-	if (length < copybreak)
+	if ((length < copybreak) 
+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+		|| (sky2->hw->flags & SKY2_HW_RAM_BUFFER)
+#endif
+		)
 		skb = receive_copy(sky2, re, length);
 	else
 		skb = receive_new(sky2, re, length);



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

* Re: [PATCH] marvell sky2 driver: fix so it works without unaligned accesses
  2012-04-03 15:13 [PATCH] marvell sky2 driver: fix so it works without unaligned accesses Chris Metcalf
  2012-04-03 16:17 ` Stephen Hemminger
  2012-04-03 16:18 ` Eric Dumazet
@ 2012-04-03 21:46 ` David Miller
  2012-04-04 14:13 ` [PATCH v2] " Chris Metcalf
  3 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2012-04-03 21:46 UTC (permalink / raw)
  To: cmetcalf; +Cc: shemminger, netdev, linux-kernel

From: Chris Metcalf <cmetcalf@tilera.com>
Date: Tue, 3 Apr 2012 11:13:56 -0400

> The driver uses a receive_new() routine that ends up requiring unaligned
> accesses in IP header processing.  If the architecture doesn't support
> efficient unaligned accesses, just copy all ingress packets to the bounce
> buffers instead.
> 
> This allows the driver to be used on the Tilera TILEmpower-Gx, since
> the tile architecture doesn't currently handle kernel unaligned accesses,
> just userspace.
> 
> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>

As Stephen Hemminger alluded to, adjust the copybreak as needed.

If you look at how other device drivers use this CONFIG variable,
you'll get a better idea of what to do here if you want to adjust
the default copybreak.

Also keep in mind the issue brought up by Eric Dumazet in that
not all kinds of sky2 chips would need this copybreak adjustment,
only ones that have the SKY2_HW_RAM_BUFFER bit cleared.


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

* [PATCH v2] marvell sky2 driver: fix so it works without unaligned accesses
  2012-04-03 15:13 [PATCH] marvell sky2 driver: fix so it works without unaligned accesses Chris Metcalf
                   ` (2 preceding siblings ...)
  2012-04-03 21:46 ` David Miller
@ 2012-04-04 14:13 ` Chris Metcalf
  2012-04-04 16:04   ` Stephen Hemminger
  2012-04-04 18:42   ` Stephen Hemminger
  3 siblings, 2 replies; 10+ messages in thread
From: Chris Metcalf @ 2012-04-04 14:13 UTC (permalink / raw)
  To: Stephen Hemminger, David Miller, netdev, linux-kernel

The driver uses a receive_new() routine that ends up requiring unaligned
accesses in IP header processing.  If the architecture doesn't support
efficient unaligned accesses, and SKY2_HW_RAM_BUFFER is set,
just copy all ingress packets to the bounce buffers instead.
Thanks to Eric Dumazet for pointing out the SKY2_HW_RAM_BUFFER issue.

This allows the driver to be used on the Tilera TILEmpower-Gx, since
the tile architecture doesn't currently handle kernel unaligned accesses,
just userspace.

Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
---
 drivers/net/ethernet/marvell/sky2.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index 423a1a2..2bc6a78 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -2598,7 +2598,11 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
 		goto error;
 
 okay:
-	if (length < copybreak)
+	if ((length < copybreak)
+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+	    || (sky2->hw->flags & SKY2_HW_RAM_BUFFER)
+#endif
+	    )
 		skb = receive_copy(sky2, re, length);
 	else
 		skb = receive_new(sky2, re, length);
-- 
1.6.5.2


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

* Re: [PATCH v2] marvell sky2 driver: fix so it works without unaligned accesses
  2012-04-04 14:13 ` [PATCH v2] " Chris Metcalf
@ 2012-04-04 16:04   ` Stephen Hemminger
  2012-04-04 18:42   ` Stephen Hemminger
  1 sibling, 0 replies; 10+ messages in thread
From: Stephen Hemminger @ 2012-04-04 16:04 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: David Miller, netdev, linux-kernel

On Wed, 4 Apr 2012 10:13:32 -0400
Chris Metcalf <cmetcalf@tilera.com> wrote:

> The driver uses a receive_new() routine that ends up requiring unaligned
> accesses in IP header processing.  If the architecture doesn't support
> efficient unaligned accesses, and SKY2_HW_RAM_BUFFER is set,
> just copy all ingress packets to the bounce buffers instead.
> Thanks to Eric Dumazet for pointing out the SKY2_HW_RAM_BUFFER issue.
> 
> This allows the driver to be used on the Tilera TILEmpower-Gx, since
> the tile architecture doesn't currently handle kernel unaligned accesses,
> just userspace.
> 
> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>

Still kind of ugly, I will cleanup


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

* Re: [PATCH v2] marvell sky2 driver: fix so it works without unaligned accesses
  2012-04-04 14:13 ` [PATCH v2] " Chris Metcalf
  2012-04-04 16:04   ` Stephen Hemminger
@ 2012-04-04 18:42   ` Stephen Hemminger
  2012-04-04 21:52     ` Chris Metcalf
  1 sibling, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2012-04-04 18:42 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: David Miller, netdev, linux-kernel

On Wed, 4 Apr 2012 10:13:32 -0400
Chris Metcalf <cmetcalf@tilera.com> wrote:

> The driver uses a receive_new() routine that ends up requiring unaligned
> accesses in IP header processing.  If the architecture doesn't support
> efficient unaligned accesses, and SKY2_HW_RAM_BUFFER is set,
> just copy all ingress packets to the bounce buffers instead.
> Thanks to Eric Dumazet for pointing out the SKY2_HW_RAM_BUFFER issue.
> 
> This allows the driver to be used on the Tilera TILEmpower-Gx, since
> the tile architecture doesn't currently handle kernel unaligned accesses,
> just userspace.
> 
> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
> ---
>  drivers/net/ethernet/marvell/sky2.c |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)

What about the following (compile tested only)
--- a/drivers/net/ethernet/marvell/sky2.c	2012-04-04 08:49:05.954853108 -0700
+++ b/drivers/net/ethernet/marvell/sky2.c	2012-04-04 11:30:54.201432707 -0700
@@ -2468,6 +2468,17 @@ static int sky2_change_mtu(struct net_de
 	return err;
 }
 
+static inline bool needs_copy(const struct rx_ring_info *re,
+			      unsigned length)
+{
+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+	/* Some architectures need the IP header to be aligned */
+	if (!IS_ALIGNED(re->data_addr + ETH_HLEN, sizeof(u32)))
+		return 1;
+#endif
+	return length < copybreak;
+}
+
 /* For small just reuse existing skb for next receive */
 static struct sk_buff *receive_copy(struct sky2_port *sky2,
 				    const struct rx_ring_info *re,
@@ -2605,7 +2616,7 @@ static struct sk_buff *sky2_receive(stru
 		goto error;
 
 okay:
-	if (length < copybreak)
+	if (needs_copy(re, length))
 		skb = receive_copy(sky2, re, length);
 	else
 		skb = receive_new(sky2, re, length);

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

* Re: [PATCH v2] marvell sky2 driver: fix so it works without unaligned accesses
  2012-04-04 18:42   ` Stephen Hemminger
@ 2012-04-04 21:52     ` Chris Metcalf
  2012-04-04 22:10       ` [PATCH v3] sky2: copy received packets on inefficient unaligned architecture Stephen Hemminger
  0 siblings, 1 reply; 10+ messages in thread
From: Chris Metcalf @ 2012-04-04 21:52 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: David Miller, netdev, linux-kernel

On 4/4/2012 2:42 PM, Stephen Hemminger wrote:
> On Wed, 4 Apr 2012 10:13:32 -0400
> Chris Metcalf <cmetcalf@tilera.com> wrote:
>
>> The driver uses a receive_new() routine that ends up requiring unaligned
>> accesses in IP header processing.  If the architecture doesn't support
>> efficient unaligned accesses, and SKY2_HW_RAM_BUFFER is set,
>> just copy all ingress packets to the bounce buffers instead.
>> Thanks to Eric Dumazet for pointing out the SKY2_HW_RAM_BUFFER issue.
>>
>> This allows the driver to be used on the Tilera TILEmpower-Gx, since
>> the tile architecture doesn't currently handle kernel unaligned accesses,
>> just userspace.
>>
>> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
>> ---
>>  drivers/net/ethernet/marvell/sky2.c |    6 +++++-
>>  1 files changed, 5 insertions(+), 1 deletions(-)
> What about the following (compile tested only)
> --- a/drivers/net/ethernet/marvell/sky2.c	2012-04-04 08:49:05.954853108 -0700
> +++ b/drivers/net/ethernet/marvell/sky2.c	2012-04-04 11:30:54.201432707 -0700
> @@ -2468,6 +2468,17 @@ static int sky2_change_mtu(struct net_de
>  	return err;
>  }
>  
> +static inline bool needs_copy(const struct rx_ring_info *re,
> +			      unsigned length)
> +{
> +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
> +	/* Some architectures need the IP header to be aligned */
> +	if (!IS_ALIGNED(re->data_addr + ETH_HLEN, sizeof(u32)))
> +		return 1;
> +#endif
> +	return length < copybreak;
> +}
> +
>  /* For small just reuse existing skb for next receive */
>  static struct sk_buff *receive_copy(struct sky2_port *sky2,
>  				    const struct rx_ring_info *re,
> @@ -2605,7 +2616,7 @@ static struct sk_buff *sky2_receive(stru
>  		goto error;
>  
>  okay:
> -	if (length < copybreak)
> +	if (needs_copy(re, length))
>  		skb = receive_copy(sky2, re, length);
>  	else
>  		skb = receive_new(sky2, re, length);

Acked-by: Chris Metcalf <cmetcalf@tilera.com>

This works on our TILEmpower-Gx boxes and seems like it's likely more
efficient.  I believe kernel style says you should "return true" rather
than "return 1" from a "bool" routine, though.

Thanks!

-- 
Chris Metcalf, Tilera Corp.
http://www.tilera.com


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

* [PATCH v3] sky2: copy received packets on inefficient unaligned architecture
  2012-04-04 21:52     ` Chris Metcalf
@ 2012-04-04 22:10       ` Stephen Hemminger
  2012-04-04 22:14         ` David Miller
  0 siblings, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2012-04-04 22:10 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: David Miller, netdev, linux-kernel

Modified from original patch from Chris.

The sky2 driver has to have 8 byte alignment of receive buffer
on some chip versions. On architectures which don't support efficient
unaligned access this doesn't work very well. The solution is to
just copy all received packets which is what the driver already
does for small packets.

This allows the driver to be used on the Tilera TILEmpower-Gx, since
the tile architecture doesn't currently handle kernel unaligned accesses,
just userspace.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Chris Metcalf <cmetcalf@tilera.com>

--- a/drivers/net/ethernet/marvell/sky2.c	2012-04-04 08:49:05.954853108 -0700
+++ b/drivers/net/ethernet/marvell/sky2.c	2012-04-04 15:03:41.725705876 -0700
@@ -2468,6 +2468,17 @@ static int sky2_change_mtu(struct net_de
 	return err;
 }
 
+static inline bool needs_copy(const struct rx_ring_info *re,
+			      unsigned length)
+{
+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+	/* Some architectures need the IP header to be aligned */
+	if (!IS_ALIGNED(re->data_addr + ETH_HLEN, sizeof(u32)))
+		return true;
+#endif
+	return length < copybreak;
+}
+
 /* For small just reuse existing skb for next receive */
 static struct sk_buff *receive_copy(struct sky2_port *sky2,
 				    const struct rx_ring_info *re,
@@ -2605,7 +2616,7 @@ static struct sk_buff *sky2_receive(stru
 		goto error;
 
 okay:
-	if (length < copybreak)
+	if (needs_copy(re, length))
 		skb = receive_copy(sky2, re, length);
 	else
 		skb = receive_new(sky2, re, length);


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

* Re: [PATCH v3] sky2: copy received packets on inefficient unaligned architecture
  2012-04-04 22:10       ` [PATCH v3] sky2: copy received packets on inefficient unaligned architecture Stephen Hemminger
@ 2012-04-04 22:14         ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2012-04-04 22:14 UTC (permalink / raw)
  To: shemminger; +Cc: cmetcalf, netdev, linux-kernel

From: Stephen Hemminger <shemminger@vyatta.com>
Date: Wed, 4 Apr 2012 15:10:27 -0700

> Modified from original patch from Chris.
> 
> The sky2 driver has to have 8 byte alignment of receive buffer
> on some chip versions. On architectures which don't support efficient
> unaligned access this doesn't work very well. The solution is to
> just copy all received packets which is what the driver already
> does for small packets.
> 
> This allows the driver to be used on the Tilera TILEmpower-Gx, since
> the tile architecture doesn't currently handle kernel unaligned accesses,
> just userspace.
> 
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> Acked-by: Chris Metcalf <cmetcalf@tilera.com>

Applied.

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

end of thread, other threads:[~2012-04-04 22:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-03 15:13 [PATCH] marvell sky2 driver: fix so it works without unaligned accesses Chris Metcalf
2012-04-03 16:17 ` Stephen Hemminger
2012-04-03 16:18 ` Eric Dumazet
2012-04-03 21:46 ` David Miller
2012-04-04 14:13 ` [PATCH v2] " Chris Metcalf
2012-04-04 16:04   ` Stephen Hemminger
2012-04-04 18:42   ` Stephen Hemminger
2012-04-04 21:52     ` Chris Metcalf
2012-04-04 22:10       ` [PATCH v3] sky2: copy received packets on inefficient unaligned architecture Stephen Hemminger
2012-04-04 22:14         ` David Miller

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