Skip to content

Commit a72808b

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: create a helper for locating EtherType DSA headers on TX
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 <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5d928ff commit a72808b

File tree

7 files changed

+23
-17
lines changed

7 files changed

+23
-17
lines changed

net/dsa/dsa_priv.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,15 @@ static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb)
521521
return skb->data - 2;
522522
}
523523

524+
/* On TX, skb->data points to skb_mac_header(skb), which means that EtherType
525+
* header taggers start exactly where the EtherType is (the EtherType is
526+
* treated as part of the DSA header).
527+
*/
528+
static inline void *dsa_etype_header_pos_tx(struct sk_buff *skb)
529+
{
530+
return skb->data + 2 * ETH_ALEN;
531+
}
532+
524533
/* switch.c */
525534
int dsa_switch_register_notifier(struct dsa_switch *ds);
526535
void dsa_switch_unregister_notifier(struct dsa_switch *ds);

net/dsa/tag_dsa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
170170
}
171171

172172
/* Construct tagged DSA tag from 802.1Q tag. */
173-
dsa_header = skb->data + 2 * ETH_ALEN + extra;
173+
dsa_header = dsa_etype_header_pos_tx(skb) + extra;
174174
dsa_header[0] = (cmd << 6) | 0x20 | tag_dev;
175175
dsa_header[1] = tag_port << 3;
176176

@@ -184,7 +184,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
184184
dsa_alloc_etype_header(skb, DSA_HLEN + extra);
185185

186186
/* Construct untagged DSA tag. */
187-
dsa_header = skb->data + 2 * ETH_ALEN + extra;
187+
dsa_header = dsa_etype_header_pos_tx(skb) + extra;
188188

189189
dsa_header[0] = (cmd << 6) | tag_dev;
190190
dsa_header[1] = tag_port << 3;
@@ -360,7 +360,7 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
360360
if (!skb)
361361
return NULL;
362362

363-
edsa_header = skb->data + 2 * ETH_ALEN;
363+
edsa_header = dsa_etype_header_pos_tx(skb);
364364
edsa_header[0] = (ETH_P_EDSA >> 8) & 0xff;
365365
edsa_header[1] = ETH_P_EDSA & 0xff;
366366
edsa_header[2] = 0x00;

net/dsa/tag_lan9303.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
6464
/* make room between MACs and Ether-Type */
6565
dsa_alloc_etype_header(skb, LAN9303_TAG_LEN);
6666

67-
lan9303_tag = (__be16 *)(skb->data + 2 * ETH_ALEN);
67+
lan9303_tag = dsa_etype_header_pos_tx(skb);
68+
6869
tag = lan9303_xmit_use_arl(dp, skb->data) ?
6970
LAN9303_TAG_TX_USE_ALR :
7071
dp->index | LAN9303_TAG_TX_STP_OVERRIDE;

net/dsa/tag_mtk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
4444
dsa_alloc_etype_header(skb, MTK_HDR_LEN);
4545
}
4646

47-
mtk_tag = skb->data + 2 * ETH_ALEN;
47+
mtk_tag = dsa_etype_header_pos_tx(skb);
4848

4949
/* Mark tag attribute on special tag insertion to notify hardware
5050
* whether that's a combined special tag with 802.1Q header.

net/dsa/tag_qca.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
3737
skb_push(skb, QCA_HDR_LEN);
3838

3939
dsa_alloc_etype_header(skb, QCA_HDR_LEN);
40-
phdr = (__be16 *)(skb->data + 2 * ETH_ALEN);
40+
phdr = dsa_etype_header_pos_tx(skb);
4141

4242
/* Set the version field, and set destination port information */
4343
hdr = QCA_HDR_VERSION << QCA_HDR_XMIT_VERSION_S |

net/dsa/tag_rtl4_a.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static struct sk_buff *rtl4a_tag_xmit(struct sk_buff *skb,
4848
skb_push(skb, RTL4_A_HDR_LEN);
4949

5050
dsa_alloc_etype_header(skb, RTL4_A_HDR_LEN);
51-
tag = skb->data + 2 * ETH_ALEN;
51+
tag = dsa_etype_header_pos_tx(skb);
5252

5353
/* Set Ethertype */
5454
p = (__be16 *)tag;

net/dsa/tag_sja1105.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
188188
u16 tx_vid = dsa_8021q_tx_vid(dp->ds, dp->index);
189189
u16 queue_mapping = skb_get_queue_mapping(skb);
190190
u8 pcp = netdev_txq_to_tc(netdev, queue_mapping);
191-
struct ethhdr *eth_hdr;
192191
__be32 *tx_trailer;
193192
__be16 *tx_header;
194193
int trailer_pos;
@@ -210,23 +209,20 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
210209

211210
trailer_pos = skb->len;
212211

213-
/* On TX, skb->data points to skb_mac_header(skb) */
214-
eth_hdr = (struct ethhdr *)skb->data;
215-
tx_header = (__be16 *)(eth_hdr + 1);
212+
tx_header = dsa_etype_header_pos_tx(skb);
216213
tx_trailer = skb_put(skb, SJA1110_TX_TRAILER_LEN);
217214

218-
eth_hdr->h_proto = htons(ETH_P_SJA1110);
219-
220-
*tx_header = htons(SJA1110_HEADER_HOST_TO_SWITCH |
221-
SJA1110_TX_HEADER_HAS_TRAILER |
222-
SJA1110_TX_HEADER_TRAILER_POS(trailer_pos));
215+
tx_header[0] = htons(ETH_P_SJA1110);
216+
tx_header[1] = htons(SJA1110_HEADER_HOST_TO_SWITCH |
217+
SJA1110_TX_HEADER_HAS_TRAILER |
218+
SJA1110_TX_HEADER_TRAILER_POS(trailer_pos));
223219
*tx_trailer = cpu_to_be32(SJA1110_TX_TRAILER_PRIO(pcp) |
224220
SJA1110_TX_TRAILER_SWITCHID(dp->ds->index) |
225221
SJA1110_TX_TRAILER_DESTPORTS(BIT(dp->index)));
226222
if (clone) {
227223
u8 ts_id = SJA1105_SKB_CB(clone)->ts_id;
228224

229-
*tx_header |= htons(SJA1110_TX_HEADER_TAKE_TS);
225+
tx_header[1] |= htons(SJA1110_TX_HEADER_TAKE_TS);
230226
*tx_trailer |= cpu_to_be32(SJA1110_TX_TRAILER_TSTAMP_ID(ts_id));
231227
}
232228

0 commit comments

Comments
 (0)