net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Sat, 13 Jul 2024 21:16:10 +0000 (23:16 +0200)
committerJakub Kicinski <kuba@kernel.org>
Mon, 15 Jul 2024 13:55:15 +0000 (06:55 -0700)
tag_sja1105 has a wrapper over dsa_8021q_rcv(): sja1105_vlan_rcv(),
which determines whether the packet came from a bridge with
vlan_filtering=1 (the case resolved via
dsa_find_designated_bridge_port_by_vid()), or if it contains a tag_8021q
header.

Looking at a new tagger implementation for vsc73xx, based also on
tag_8021q, it is becoming clear that the logic is needed there as well.
So instead of forcing each tagger to wrap around dsa_8021q_rcv(), let's
merge the logic into the core.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Tested-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
Link: https://patch.msgid.link/20240713211620.1125910-5-paweldembicki@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/dsa/tag_8021q.c
net/dsa/tag_8021q.h
net/dsa/tag_ocelot_8021q.c
net/dsa/tag_sja1105.c

index 3cb0293793a594922987595cb07a8bfe737cb7d1..2d1c554a63ff138f260fb711330c13e4370230e4 100644 (file)
@@ -507,27 +507,48 @@ EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid);
  * @vbid: pointer to storage for imprecise bridge ID. Must be pre-initialized
  *     with -1. If a positive value is returned, the source_port and switch_id
  *     are invalid.
+ * @vid: pointer to storage for original VID, in case tag_8021q decoding failed.
+ *
+ * If the packet has a tag_8021q header, decode it and set @source_port,
+ * @switch_id and @vbid, and strip the header. Otherwise set @vid and keep the
+ * header in the hwaccel area of the packet.
  */
 void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
-                  int *vbid)
+                  int *vbid, int *vid)
 {
        int tmp_source_port, tmp_switch_id, tmp_vbid;
-       u16 vid, tci;
+       __be16 vlan_proto;
+       u16 tmp_vid, tci;
 
        if (skb_vlan_tag_present(skb)) {
+               vlan_proto = skb->vlan_proto;
                tci = skb_vlan_tag_get(skb);
                __vlan_hwaccel_clear_tag(skb);
        } else {
+               struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
+
+               vlan_proto = hdr->h_vlan_proto;
                skb_push_rcsum(skb, ETH_HLEN);
                __skb_vlan_pop(skb, &tci);
                skb_pull_rcsum(skb, ETH_HLEN);
        }
 
-       vid = tci & VLAN_VID_MASK;
+       tmp_vid = tci & VLAN_VID_MASK;
+       if (!vid_is_dsa_8021q(tmp_vid)) {
+               /* Not a tag_8021q frame, so return the VID to the
+                * caller for further processing, and put the tag back
+                */
+               if (vid)
+                       *vid = tmp_vid;
+
+               __vlan_hwaccel_put_tag(skb, vlan_proto, tci);
+
+               return;
+       }
 
-       tmp_source_port = dsa_8021q_rx_source_port(vid);
-       tmp_switch_id = dsa_8021q_rx_switch_id(vid);
-       tmp_vbid = dsa_tag_8021q_rx_vbid(vid);
+       tmp_source_port = dsa_8021q_rx_source_port(tmp_vid);
+       tmp_switch_id = dsa_8021q_rx_switch_id(tmp_vid);
+       tmp_vbid = dsa_tag_8021q_rx_vbid(tmp_vid);
 
        /* Precise source port information is unknown when receiving from a
         * VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id
@@ -546,5 +567,6 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
                *vbid = tmp_vbid;
 
        skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
+       return;
 }
 EXPORT_SYMBOL_GPL(dsa_8021q_rcv);
index 41f7167ac52049b25a552ab480c8fb588647ae0a..0c6671d7c1c23408e9fc162a1d994804dd5612b5 100644 (file)
@@ -14,7 +14,7 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
                               u16 tpid, u16 tci);
 
 void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
-                  int *vbid);
+                  int *vbid, int *vid);
 
 struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit,
                                                   int vbid);
index b059381310fedb2e2929b9007c09286cd63e1c71..8e8b1bef6af69d726cdf63f71dc7dfaaef238b30 100644 (file)
@@ -81,7 +81,7 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb,
 {
        int src_port, switch_id;
 
-       dsa_8021q_rcv(skb, &src_port, &switch_id, NULL);
+       dsa_8021q_rcv(skb, &src_port, &switch_id, NULL, NULL);
 
        skb->dev = dsa_conduit_find_user(netdev, switch_id, src_port);
        if (!skb->dev)
index 48886d4b7e3e1168e6d85b2b5bbd8c50154121e7..7639ccb94d3591ebca0ecf83c17d841d05a7613c 100644 (file)
@@ -472,37 +472,14 @@ static bool sja1110_skb_has_inband_control_extension(const struct sk_buff *skb)
        return ntohs(eth_hdr(skb)->h_proto) == ETH_P_SJA1110;
 }
 
-/* If the VLAN in the packet is a tag_8021q one, set @source_port and
- * @switch_id and strip the header. Otherwise set @vid and keep it in the
- * packet.
- */
-static void sja1105_vlan_rcv(struct sk_buff *skb, int *source_port,
-                            int *switch_id, int *vbid, u16 *vid)
-{
-       struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
-       u16 vlan_tci;
-
-       if (skb_vlan_tag_present(skb))
-               vlan_tci = skb_vlan_tag_get(skb);
-       else
-               vlan_tci = ntohs(hdr->h_vlan_TCI);
-
-       if (vid_is_dsa_8021q(vlan_tci & VLAN_VID_MASK))
-               return dsa_8021q_rcv(skb, source_port, switch_id, vbid);
-
-       /* Try our best with imprecise RX */
-       *vid = vlan_tci & VLAN_VID_MASK;
-}
-
 static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
                                   struct net_device *netdev)
 {
-       int source_port = -1, switch_id = -1, vbid = -1;
+       int source_port = -1, switch_id = -1, vbid = -1, vid = -1;
        struct sja1105_meta meta = {0};
        struct ethhdr *hdr;
        bool is_link_local;
        bool is_meta;
-       u16 vid;
 
        hdr = eth_hdr(skb);
        is_link_local = sja1105_is_link_local(skb);
@@ -525,7 +502,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
         * a tag_8021q VLAN which we have to strip
         */
        if (sja1105_skb_has_tag_8021q(skb))
-               sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid);
+               dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid);
        else if (source_port == -1 && switch_id == -1)
                /* Packets with no source information have no chance of
                 * getting accepted, drop them straight away.
@@ -660,9 +637,8 @@ static struct sk_buff *sja1110_rcv_inband_control_extension(struct sk_buff *skb,
 static struct sk_buff *sja1110_rcv(struct sk_buff *skb,
                                   struct net_device *netdev)
 {
-       int source_port = -1, switch_id = -1, vbid = -1;
+       int source_port = -1, switch_id = -1, vbid = -1, vid = -1;
        bool host_only = false;
-       u16 vid = 0;
 
        if (sja1110_skb_has_inband_control_extension(skb)) {
                skb = sja1110_rcv_inband_control_extension(skb, &source_port,
@@ -674,7 +650,7 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb,
 
        /* Packets with in-band control extensions might still have RX VLANs */
        if (likely(sja1105_skb_has_tag_8021q(skb)))
-               sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid);
+               dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid);
 
        if (vbid >= 1)
                skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid);