All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: dsa: lan9303: handle hwaccel VLAN tags
@ 2022-02-15 14:59 Mans Rullgard
  2022-02-15 20:36 ` Vladimir Oltean
  0 siblings, 1 reply; 3+ messages in thread
From: Mans Rullgard @ 2022-02-15 14:59 UTC (permalink / raw)
  To: Andrew Lunn, Vivien Didelot, Florian Fainelli, Vladimir Oltean,
	David S. Miller, Jakub Kicinski, Juergen Borleis, netdev,
	linux-kernel

Check for a hwaccel VLAN tag on rx and use it if present.  Otherwise,
use __skb_vlan_pop() like the other tag parsers do.  This fixes the case
where the VLAN tag has already been consumed by the master.

Signed-off-by: Mans Rullgard <mans@mansr.com>
---
 net/dsa/tag_lan9303.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index cb548188f813..7fe180941ac4 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -77,7 +77,6 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
 
 static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
 {
-	__be16 *lan9303_tag;
 	u16 lan9303_tag1;
 	unsigned int source_port;
 
@@ -87,14 +86,15 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
 		return NULL;
 	}
 
-	lan9303_tag = dsa_etype_header_pos_rx(skb);
-
-	if (lan9303_tag[0] != htons(ETH_P_8021Q)) {
-		dev_warn_ratelimited(&dev->dev, "Dropping packet due to invalid VLAN marker\n");
-		return NULL;
+	skb_push_rcsum(skb, ETH_HLEN);
+	if (skb_vlan_tag_present(skb)) {
+		lan9303_tag1 = skb_vlan_tag_get(skb);
+		__vlan_hwaccel_clear_tag(skb);
+	} else {
+		__skb_vlan_pop(skb, &lan9303_tag1);
 	}
+	skb_pull_rcsum(skb, ETH_HLEN);
 
-	lan9303_tag1 = ntohs(lan9303_tag[1]);
 	source_port = lan9303_tag1 & 0x3;
 
 	skb->dev = dsa_master_find_slave(dev, 0, source_port);
@@ -103,13 +103,6 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
 		return NULL;
 	}
 
-	/* remove the special VLAN tag between the MAC addresses
-	 * and the current ethertype field.
-	 */
-	skb_pull_rcsum(skb, 2 + 2);
-
-	dsa_strip_etype_header(skb, LAN9303_TAG_LEN);
-
 	if (!(lan9303_tag1 & LAN9303_TAG_RX_TRAPPED_TO_CPU))
 		dsa_default_offload_fwd_mark(skb);
 
-- 
2.35.1


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

* Re: [PATCH] net: dsa: lan9303: handle hwaccel VLAN tags
  2022-02-15 14:59 [PATCH] net: dsa: lan9303: handle hwaccel VLAN tags Mans Rullgard
@ 2022-02-15 20:36 ` Vladimir Oltean
  2022-02-16 12:48   ` Måns Rullgård
  0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Oltean @ 2022-02-15 20:36 UTC (permalink / raw)
  To: Mans Rullgard
  Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, David S. Miller,
	Jakub Kicinski, Juergen Borleis, netdev, linux-kernel

On Tue, Feb 15, 2022 at 02:59:13PM +0000, Mans Rullgard wrote:
> Check for a hwaccel VLAN tag on rx and use it if present.  Otherwise,
> use __skb_vlan_pop() like the other tag parsers do.  This fixes the case
> where the VLAN tag has already been consumed by the master.
> 
> Signed-off-by: Mans Rullgard <mans@mansr.com>
> ---
>  net/dsa/tag_lan9303.c | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
> index cb548188f813..7fe180941ac4 100644
> --- a/net/dsa/tag_lan9303.c
> +++ b/net/dsa/tag_lan9303.c
> @@ -77,7 +77,6 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
>  
>  static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
>  {
> -	__be16 *lan9303_tag;
>  	u16 lan9303_tag1;
>  	unsigned int source_port;
>  
> @@ -87,14 +86,15 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
>  		return NULL;
>  	}
>  
> -	lan9303_tag = dsa_etype_header_pos_rx(skb);
> -
> -	if (lan9303_tag[0] != htons(ETH_P_8021Q)) {
> -		dev_warn_ratelimited(&dev->dev, "Dropping packet due to invalid VLAN marker\n");
> -		return NULL;
> +	skb_push_rcsum(skb, ETH_HLEN);
> +	if (skb_vlan_tag_present(skb)) {
> +		lan9303_tag1 = skb_vlan_tag_get(skb);
> +		__vlan_hwaccel_clear_tag(skb);
> +	} else {
> +		__skb_vlan_pop(skb, &lan9303_tag1);

Sorry for the bad example, there is no reason to call skb_push_rcsum()
and skb_pull_rcsum() if we go through the skb_vlan_tag_present() code
path, just the "else" branch.

>  	}
> +	skb_pull_rcsum(skb, ETH_HLEN);
>  
> -	lan9303_tag1 = ntohs(lan9303_tag[1]);
>  	source_port = lan9303_tag1 & 0x3;
>  
>  	skb->dev = dsa_master_find_slave(dev, 0, source_port);
> @@ -103,13 +103,6 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
>  		return NULL;
>  	}
>  
> -	/* remove the special VLAN tag between the MAC addresses
> -	 * and the current ethertype field.
> -	 */
> -	skb_pull_rcsum(skb, 2 + 2);
> -
> -	dsa_strip_etype_header(skb, LAN9303_TAG_LEN);
> -
>  	if (!(lan9303_tag1 & LAN9303_TAG_RX_TRAPPED_TO_CPU))
>  		dsa_default_offload_fwd_mark(skb);
>  
> -- 
> 2.35.1
> 

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

* Re: [PATCH] net: dsa: lan9303: handle hwaccel VLAN tags
  2022-02-15 20:36 ` Vladimir Oltean
@ 2022-02-16 12:48   ` Måns Rullgård
  0 siblings, 0 replies; 3+ messages in thread
From: Måns Rullgård @ 2022-02-16 12:48 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, David S. Miller,
	Jakub Kicinski, Juergen Borleis, netdev, linux-kernel

Vladimir Oltean <olteanv@gmail.com> writes:

> On Tue, Feb 15, 2022 at 02:59:13PM +0000, Mans Rullgard wrote:
>> Check for a hwaccel VLAN tag on rx and use it if present.  Otherwise,
>> use __skb_vlan_pop() like the other tag parsers do.  This fixes the case
>> where the VLAN tag has already been consumed by the master.
>> 
>> Signed-off-by: Mans Rullgard <mans@mansr.com>
>> ---
>>  net/dsa/tag_lan9303.c | 21 +++++++--------------
>>  1 file changed, 7 insertions(+), 14 deletions(-)
>> 
>> diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
>> index cb548188f813..7fe180941ac4 100644
>> --- a/net/dsa/tag_lan9303.c
>> +++ b/net/dsa/tag_lan9303.c
>> @@ -77,7 +77,6 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
>>  
>>  static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
>>  {
>> -	__be16 *lan9303_tag;
>>  	u16 lan9303_tag1;
>>  	unsigned int source_port;
>>  
>> @@ -87,14 +86,15 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
>>  		return NULL;
>>  	}
>>  
>> -	lan9303_tag = dsa_etype_header_pos_rx(skb);
>> -
>> -	if (lan9303_tag[0] != htons(ETH_P_8021Q)) {
>> -		dev_warn_ratelimited(&dev->dev, "Dropping packet due to invalid VLAN marker\n");
>> -		return NULL;
>> +	skb_push_rcsum(skb, ETH_HLEN);
>> +	if (skb_vlan_tag_present(skb)) {
>> +		lan9303_tag1 = skb_vlan_tag_get(skb);
>> +		__vlan_hwaccel_clear_tag(skb);
>> +	} else {
>> +		__skb_vlan_pop(skb, &lan9303_tag1);
>
> Sorry for the bad example, there is no reason to call skb_push_rcsum()
> and skb_pull_rcsum() if we go through the skb_vlan_tag_present() code
> path, just the "else" branch.

I could have realised that myself, had I not simply blindly copied the
example.  Anyway, new patch sent.

-- 
Måns Rullgård

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

end of thread, other threads:[~2022-02-16 12:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 14:59 [PATCH] net: dsa: lan9303: handle hwaccel VLAN tags Mans Rullgard
2022-02-15 20:36 ` Vladimir Oltean
2022-02-16 12:48   ` Måns Rullgård

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.