Commit f7c39e3d1e094af1c3e0676b76c00d8c1f8e7774

Authored by Florian Fainelli
Committed by David S. Miller
1 parent 5ed4e3eb02

net: dsa: tag_brcm: Prepare for supporting prepended tag

In preparation for supporting the same Broadcom tag format, but instead
of inserted between the MAC SA and EtherType, prepended to the Ethernet
frame, restructure the code a little bit to make that possible and take
an offset parameter.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 34 additions and 11 deletions Side-by-side Diff

... ... @@ -59,7 +59,9 @@
59 59 #define BRCM_EG_TC_MASK 0x7
60 60 #define BRCM_EG_PID_MASK 0x1f
61 61  
62   -static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev)
  62 +static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
  63 + struct net_device *dev,
  64 + unsigned int offset)
63 65 {
64 66 struct dsa_port *dp = dsa_slave_to_port(dev);
65 67 u16 queue = skb_get_queue_mapping(skb);
66 68  
... ... @@ -70,10 +72,10 @@
70 72  
71 73 skb_push(skb, BRCM_TAG_LEN);
72 74  
73   - memmove(skb->data, skb->data + BRCM_TAG_LEN, 2 * ETH_ALEN);
  75 + if (offset)
  76 + memmove(skb->data, skb->data + BRCM_TAG_LEN, offset);
74 77  
75   - /* Build the tag after the MAC Source Address */
76   - brcm_tag = skb->data + 2 * ETH_ALEN;
  78 + brcm_tag = skb->data + offset;
77 79  
78 80 /* Set the ingress opcode, traffic class, tag enforcment is
79 81 * deprecated
80 82  
81 83  
... ... @@ -94,17 +96,25 @@
94 96 return skb;
95 97 }
96 98  
97   -static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
98   - struct packet_type *pt)
  99 +static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb,
  100 + struct net_device *dev)
99 101 {
  102 + /* Build the tag after the MAC Source Address */
  103 + return brcm_tag_xmit_ll(skb, dev, 2 * ETH_ALEN);
  104 +}
  105 +
  106 +static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
  107 + struct net_device *dev,
  108 + struct packet_type *pt,
  109 + unsigned int offset)
  110 +{
100 111 int source_port;
101 112 u8 *brcm_tag;
102 113  
103 114 if (unlikely(!pskb_may_pull(skb, BRCM_TAG_LEN)))
104 115 return NULL;
105 116  
106   - /* skb->data points to the EtherType, the tag is right before it */
107   - brcm_tag = skb->data - 2;
  117 + brcm_tag = skb->data - offset;
108 118  
109 119 /* The opcode should never be different than 0b000 */
110 120 if (unlikely((brcm_tag[0] >> BRCM_OPCODE_SHIFT) & BRCM_OPCODE_MASK))
111 121  
112 122  
... ... @@ -126,12 +136,25 @@
126 136 /* Remove Broadcom tag and update checksum */
127 137 skb_pull_rcsum(skb, BRCM_TAG_LEN);
128 138  
  139 + return skb;
  140 +}
  141 +
  142 +static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
  143 + struct packet_type *pt)
  144 +{
  145 + struct sk_buff *nskb;
  146 +
  147 + /* skb->data points to the EtherType, the tag is right before it */
  148 + nskb = brcm_tag_rcv_ll(skb, dev, pt, 2);
  149 + if (!nskb)
  150 + return nskb;
  151 +
129 152 /* Move the Ethernet DA and SA */
130   - memmove(skb->data - ETH_HLEN,
131   - skb->data - ETH_HLEN - BRCM_TAG_LEN,
  153 + memmove(nskb->data - ETH_HLEN,
  154 + nskb->data - ETH_HLEN - BRCM_TAG_LEN,
132 155 2 * ETH_ALEN);
133 156  
134   - return skb;
  157 + return nskb;
135 158 }
136 159  
137 160 const struct dsa_device_ops brcm_netdev_ops = {