Skip to content

Commit ea440cd

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dsa: tag_ocelot: use VLAN information from tagging header when available
When the Extraction Frame Header contains a valid classified VLAN, use that instead of the VLAN header present in the packet. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 70edfae commit ea440cd

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎net/dsa/tag_ocelot.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,14 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb,
184184
struct net_device *netdev,
185185
struct packet_type *pt)
186186
{
187+
struct dsa_port *cpu_dp = netdev->dsa_ptr;
188+
struct dsa_switch *ds = cpu_dp->ds;
189+
struct ocelot *ocelot = ds->priv;
187190
u64 src_port, qos_class;
191+
u64 vlan_tci, tag_type;
188192
u8 *start = skb->data;
189193
u8 *extraction;
194+
u16 vlan_tpid;
190195

191196
/* Revert skb->data by the amount consumed by the DSA master,
192197
* so it points to the beginning of the frame.
@@ -214,6 +219,8 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb,
214219

215220
packing(extraction, &src_port, 46, 43, OCELOT_TAG_LEN, UNPACK, 0);
216221
packing(extraction, &qos_class, 19, 17, OCELOT_TAG_LEN, UNPACK, 0);
222+
packing(extraction, &tag_type, 16, 16, OCELOT_TAG_LEN, UNPACK, 0);
223+
packing(extraction, &vlan_tci, 15, 0, OCELOT_TAG_LEN, UNPACK, 0);
217224

218225
skb->dev = dsa_master_find_slave(netdev, 0, src_port);
219226
if (!skb->dev)
@@ -228,6 +235,33 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb,
228235
skb->offload_fwd_mark = 1;
229236
skb->priority = qos_class;
230237

238+
/* Ocelot switches copy frames unmodified to the CPU. However, it is
239+
* possible for the user to request a VLAN modification through
240+
* VCAP_IS1_ACT_VID_REPLACE_ENA. In this case, what will happen is that
241+
* the VLAN ID field from the Extraction Header gets updated, but the
242+
* 802.1Q header does not (the classified VLAN only becomes visible on
243+
* egress through the "port tag" of front-panel ports).
244+
* So, for traffic extracted by the CPU, we want to pick up the
245+
* classified VLAN and manually replace the existing 802.1Q header from
246+
* the packet with it, so that the operating system is always up to
247+
* date with the result of tc-vlan actions.
248+
* NOTE: In VLAN-unaware mode, we don't want to do that, we want the
249+
* frame to remain unmodified, because the classified VLAN is always
250+
* equal to the pvid of the ingress port and should not be used for
251+
* processing.
252+
*/
253+
vlan_tpid = tag_type ? ETH_P_8021AD : ETH_P_8021Q;
254+
255+
if (ocelot->ports[src_port]->vlan_aware &&
256+
eth_hdr(skb)->h_proto == htons(vlan_tpid)) {
257+
u16 dummy_vlan_tci;
258+
259+
skb_push_rcsum(skb, ETH_HLEN);
260+
__skb_vlan_pop(skb, &dummy_vlan_tci);
261+
skb_pull_rcsum(skb, ETH_HLEN);
262+
__vlan_hwaccel_put_tag(skb, htons(vlan_tpid), vlan_tci);
263+
}
264+
231265
return skb;
232266
}
233267

0 commit comments

Comments
 (0)