Skip to content

Commit 86dd986

Browse files
linuswdavem330
authored andcommitted
net: dsa: tag_rtl4_a: Support also egress tags
Support also transmitting frames using the custom "8899 A" 4 byte tag. Qingfang came up with the solution: we need to pad the ethernet frame to 60 bytes using eth_skb_pad(), then the switch will happily accept frames with custom tags. Cc: Mauri Sandberg <[email protected]> Reported-by: DENG Qingfang <[email protected]> Fixes: efd7fe6 ("net: dsa: tag_rtl4_a: Implement Realtek 4 byte A tag") Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c544fcb commit 86dd986

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

net/dsa/tag_rtl4_a.c

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
*
1313
* The 2 bytes tag form a 16 bit big endian word. The exact
1414
* meaning has been guessed from packet dumps from ingress
15-
* frames, as no working egress traffic has been available
16-
* we do not know the format of the egress tags or if they
17-
* are even supported.
15+
* frames.
1816
*/
1917

2018
#include <linux/etherdevice.h>
@@ -36,17 +34,34 @@
3634
static struct sk_buff *rtl4a_tag_xmit(struct sk_buff *skb,
3735
struct net_device *dev)
3836
{
39-
/*
40-
* Just let it pass thru, we don't know if it is possible
41-
* to tag a frame with the 0x8899 ethertype and direct it
42-
* to a specific port, all attempts at reverse-engineering have
43-
* ended up with the frames getting dropped.
44-
*
45-
* The VLAN set-up needs to restrict the frames to the right port.
46-
*
47-
* If you have documentation on the tagging format for RTL8366RB
48-
* (tag type A) then please contribute.
49-
*/
37+
struct dsa_port *dp = dsa_slave_to_port(dev);
38+
u8 *tag;
39+
u16 *p;
40+
u16 out;
41+
42+
/* Pad out to at least 60 bytes */
43+
if (unlikely(eth_skb_pad(skb)))
44+
return NULL;
45+
if (skb_cow_head(skb, RTL4_A_HDR_LEN) < 0)
46+
return NULL;
47+
48+
netdev_dbg(dev, "add realtek tag to package to port %d\n",
49+
dp->index);
50+
skb_push(skb, RTL4_A_HDR_LEN);
51+
52+
memmove(skb->data, skb->data + RTL4_A_HDR_LEN, 2 * ETH_ALEN);
53+
tag = skb->data + 2 * ETH_ALEN;
54+
55+
/* Set Ethertype */
56+
p = (u16 *)tag;
57+
*p = htons(RTL4_A_ETHERTYPE);
58+
59+
out = (RTL4_A_PROTOCOL_RTL8366RB << 12) | (2 << 8);
60+
/* The lower bits is the port numer */
61+
out |= (u8)dp->index;
62+
p = (u16 *)(tag + 2);
63+
*p = htons(out);
64+
5065
return skb;
5166
}
5267

0 commit comments

Comments
 (0)