]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
net: dsa: create a helper for locating EtherType DSA headers on TX
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 10 Aug 2021 13:13:56 +0000 (16:13 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 11 Aug 2021 13:44:58 +0000 (14:44 +0100)
Create a similar helper for locating the offset to the DSA header
relative to skb->data, and make the existing EtherType header taggers to
use it.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa_priv.h
net/dsa/tag_dsa.c
net/dsa/tag_lan9303.c
net/dsa/tag_mtk.c
net/dsa/tag_qca.c
net/dsa/tag_rtl4_a.c
net/dsa/tag_sja1105.c

index ee194df6890261789901c50f6bd21be0737e81b3..9ea637832ea9f4f499b703d5aea36e85e1877e94 100644 (file)
@@ -521,6 +521,15 @@ static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb)
        return skb->data - 2;
 }
 
+/* On TX, skb->data points to skb_mac_header(skb), which means that EtherType
+ * header taggers start exactly where the EtherType is (the EtherType is
+ * treated as part of the DSA header).
+ */
+static inline void *dsa_etype_header_pos_tx(struct sk_buff *skb)
+{
+       return skb->data + 2 * ETH_ALEN;
+}
+
 /* switch.c */
 int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
index 2eeabab27078a5f0ecb2244caa7da61ef5d9abd1..77d0ce89ab77abb174aae90c5094f7a1a3ec5ae2 100644 (file)
@@ -170,7 +170,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
                }
 
                /* Construct tagged DSA tag from 802.1Q tag. */
-               dsa_header = skb->data + 2 * ETH_ALEN + extra;
+               dsa_header = dsa_etype_header_pos_tx(skb) + extra;
                dsa_header[0] = (cmd << 6) | 0x20 | tag_dev;
                dsa_header[1] = tag_port << 3;
 
@@ -184,7 +184,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
                dsa_alloc_etype_header(skb, DSA_HLEN + extra);
 
                /* Construct untagged DSA tag. */
-               dsa_header = skb->data + 2 * ETH_ALEN + extra;
+               dsa_header = dsa_etype_header_pos_tx(skb) + extra;
 
                dsa_header[0] = (cmd << 6) | tag_dev;
                dsa_header[1] = tag_port << 3;
@@ -360,7 +360,7 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
        if (!skb)
                return NULL;
 
-       edsa_header = skb->data + 2 * ETH_ALEN;
+       edsa_header = dsa_etype_header_pos_tx(skb);
        edsa_header[0] = (ETH_P_EDSA >> 8) & 0xff;
        edsa_header[1] = ETH_P_EDSA & 0xff;
        edsa_header[2] = 0x00;
index d06951273127024b7f69431287a38fda307a5f4f..cb548188f81340d702aa07532b3fa9988a0cc9cd 100644 (file)
@@ -64,7 +64,8 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
        /* make room between MACs and Ether-Type */
        dsa_alloc_etype_header(skb, LAN9303_TAG_LEN);
 
-       lan9303_tag = (__be16 *)(skb->data + 2 * ETH_ALEN);
+       lan9303_tag = dsa_etype_header_pos_tx(skb);
+
        tag = lan9303_xmit_use_arl(dp, skb->data) ?
                LAN9303_TAG_TX_USE_ALR :
                dp->index | LAN9303_TAG_TX_STP_OVERRIDE;
index a75f99e5fbe39cd385b858585f872e086069438e..415d8ece242aff5303a43f08ba02269de2aa8b8e 100644 (file)
@@ -44,7 +44,7 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
                dsa_alloc_etype_header(skb, MTK_HDR_LEN);
        }
 
-       mtk_tag = skb->data + 2 * ETH_ALEN;
+       mtk_tag = dsa_etype_header_pos_tx(skb);
 
        /* Mark tag attribute on special tag insertion to notify hardware
         * whether that's a combined special tag with 802.1Q header.
index 79a81569d7ec177a5f3e8d6143061cbd926851ce..1ea9401b8ace1ed1aec244ea81762f8a18a98655 100644 (file)
@@ -37,7 +37,7 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
        skb_push(skb, QCA_HDR_LEN);
 
        dsa_alloc_etype_header(skb, QCA_HDR_LEN);
-       phdr = (__be16 *)(skb->data + 2 * ETH_ALEN);
+       phdr = dsa_etype_header_pos_tx(skb);
 
        /* Set the version field, and set destination port information */
        hdr = QCA_HDR_VERSION << QCA_HDR_XMIT_VERSION_S |
index 947247d2124e430cb9c01e9504f471fae4a1691a..40811bab4d094e6e4d2f0e68a4b50bdc47a5bce8 100644 (file)
@@ -48,7 +48,7 @@ static struct sk_buff *rtl4a_tag_xmit(struct sk_buff *skb,
        skb_push(skb, RTL4_A_HDR_LEN);
 
        dsa_alloc_etype_header(skb, RTL4_A_HDR_LEN);
-       tag = skb->data + 2 * ETH_ALEN;
+       tag = dsa_etype_header_pos_tx(skb);
 
        /* Set Ethertype */
        p = (__be16 *)tag;
index 4f90e2756124f67b637136abc81bd0808c1d67db..1406bc41d345cc884fd98b421e3caf498f90a4a2 100644 (file)
@@ -188,7 +188,6 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
        u16 tx_vid = dsa_8021q_tx_vid(dp->ds, dp->index);
        u16 queue_mapping = skb_get_queue_mapping(skb);
        u8 pcp = netdev_txq_to_tc(netdev, queue_mapping);
-       struct ethhdr *eth_hdr;
        __be32 *tx_trailer;
        __be16 *tx_header;
        int trailer_pos;
@@ -210,23 +209,20 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
 
        trailer_pos = skb->len;
 
-       /* On TX, skb->data points to skb_mac_header(skb) */
-       eth_hdr = (struct ethhdr *)skb->data;
-       tx_header = (__be16 *)(eth_hdr + 1);
+       tx_header = dsa_etype_header_pos_tx(skb);
        tx_trailer = skb_put(skb, SJA1110_TX_TRAILER_LEN);
 
-       eth_hdr->h_proto = htons(ETH_P_SJA1110);
-
-       *tx_header = htons(SJA1110_HEADER_HOST_TO_SWITCH |
-                          SJA1110_TX_HEADER_HAS_TRAILER |
-                          SJA1110_TX_HEADER_TRAILER_POS(trailer_pos));
+       tx_header[0] = htons(ETH_P_SJA1110);
+       tx_header[1] = htons(SJA1110_HEADER_HOST_TO_SWITCH |
+                            SJA1110_TX_HEADER_HAS_TRAILER |
+                            SJA1110_TX_HEADER_TRAILER_POS(trailer_pos));
        *tx_trailer = cpu_to_be32(SJA1110_TX_TRAILER_PRIO(pcp) |
                                  SJA1110_TX_TRAILER_SWITCHID(dp->ds->index) |
                                  SJA1110_TX_TRAILER_DESTPORTS(BIT(dp->index)));
        if (clone) {
                u8 ts_id = SJA1105_SKB_CB(clone)->ts_id;
 
-               *tx_header |= htons(SJA1110_TX_HEADER_TAKE_TS);
+               tx_header[1] |= htons(SJA1110_TX_HEADER_TAKE_TS);
                *tx_trailer |= cpu_to_be32(SJA1110_TX_TRAILER_TSTAMP_ID(ts_id));
        }