Skip to content

Commit eea7437

Browse files
LorenzoBianconinbd168
authored andcommitted
mt76: do not always copy ethhdr in reverse_frag0_hdr_trans
Do not always copy ethernet header in mt{7615,7915,7921}_reverse_frag0_hdr_trans and use a pointer instead. Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
1 parent 5b7cc6d commit eea7437

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

drivers/net/wireless/mediatek/mt76/mt7615/mac.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ static void mt7615_mac_fill_tm_rx(struct mt7615_phy *phy, __le32 *rxv)
253253
static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
254254
{
255255
struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
256+
struct ethhdr *eth_hdr = (struct ethhdr *)(skb->data + hdr_gap);
256257
struct mt7615_sta *msta = (struct mt7615_sta *)status->wcid;
258+
__le32 *rxd = (__le32 *)skb->data;
257259
struct ieee80211_sta *sta;
258260
struct ieee80211_vif *vif;
259261
struct ieee80211_hdr hdr;
260-
struct ethhdr eth_hdr;
261-
__le32 *rxd = (__le32 *)skb->data;
262262
__le32 qos_ctrl, ht_ctrl;
263263

264264
if (FIELD_GET(MT_RXD1_NORMAL_ADDR_TYPE, le32_to_cpu(rxd[1])) !=
@@ -275,7 +275,6 @@ static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
275275
vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
276276

277277
/* store the info from RXD and ethhdr to avoid being overridden */
278-
memcpy(&eth_hdr, skb->data + hdr_gap, sizeof(eth_hdr));
279278
hdr.frame_control = FIELD_GET(MT_RXD4_FRAME_CONTROL, rxd[4]);
280279
hdr.seq_ctrl = FIELD_GET(MT_RXD6_SEQ_CTRL, rxd[6]);
281280
qos_ctrl = FIELD_GET(MT_RXD6_QOS_CTL, rxd[6]);
@@ -290,24 +289,24 @@ static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
290289
ether_addr_copy(hdr.addr3, vif->bss_conf.bssid);
291290
break;
292291
case IEEE80211_FCTL_FROMDS:
293-
ether_addr_copy(hdr.addr3, eth_hdr.h_source);
292+
ether_addr_copy(hdr.addr3, eth_hdr->h_source);
294293
break;
295294
case IEEE80211_FCTL_TODS:
296-
ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
295+
ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
297296
break;
298297
case IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS:
299-
ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
300-
ether_addr_copy(hdr.addr4, eth_hdr.h_source);
298+
ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
299+
ether_addr_copy(hdr.addr4, eth_hdr->h_source);
301300
break;
302301
default:
303302
break;
304303
}
305304

306305
skb_pull(skb, hdr_gap + sizeof(struct ethhdr) - 2);
307-
if (eth_hdr.h_proto == htons(ETH_P_AARP) ||
308-
eth_hdr.h_proto == htons(ETH_P_IPX))
306+
if (eth_hdr->h_proto == cpu_to_be16(ETH_P_AARP) ||
307+
eth_hdr->h_proto == cpu_to_be16(ETH_P_IPX))
309308
ether_addr_copy(skb_push(skb, ETH_ALEN), bridge_tunnel_header);
310-
else if (eth_hdr.h_proto >= htons(ETH_P_802_3_MIN))
309+
else if (eth_hdr->h_proto >= cpu_to_be16(ETH_P_802_3_MIN))
311310
ether_addr_copy(skb_push(skb, ETH_ALEN), rfc1042_header);
312311
else
313312
skb_pull(skb, 2);

drivers/net/wireless/mediatek/mt76/mt7915/mac.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,12 @@ mt7915_mac_decode_he_radiotap(struct sk_buff *skb, __le32 *rxv, u32 mode)
392392
static int mt7915_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
393393
{
394394
struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
395+
struct ethhdr *eth_hdr = (struct ethhdr *)(skb->data + hdr_gap);
395396
struct mt7915_sta *msta = (struct mt7915_sta *)status->wcid;
397+
__le32 *rxd = (__le32 *)skb->data;
396398
struct ieee80211_sta *sta;
397399
struct ieee80211_vif *vif;
398400
struct ieee80211_hdr hdr;
399-
struct ethhdr eth_hdr;
400-
__le32 *rxd = (__le32 *)skb->data;
401401
__le32 qos_ctrl, ht_ctrl;
402402

403403
if (FIELD_GET(MT_RXD3_NORMAL_ADDR_TYPE, le32_to_cpu(rxd[3])) !=
@@ -414,7 +414,6 @@ static int mt7915_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
414414
vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
415415

416416
/* store the info from RXD and ethhdr to avoid being overridden */
417-
memcpy(&eth_hdr, skb->data + hdr_gap, sizeof(eth_hdr));
418417
hdr.frame_control = FIELD_GET(MT_RXD6_FRAME_CONTROL, rxd[6]);
419418
hdr.seq_ctrl = FIELD_GET(MT_RXD8_SEQ_CTRL, rxd[8]);
420419
qos_ctrl = FIELD_GET(MT_RXD8_QOS_CTL, rxd[8]);
@@ -429,24 +428,24 @@ static int mt7915_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
429428
ether_addr_copy(hdr.addr3, vif->bss_conf.bssid);
430429
break;
431430
case IEEE80211_FCTL_FROMDS:
432-
ether_addr_copy(hdr.addr3, eth_hdr.h_source);
431+
ether_addr_copy(hdr.addr3, eth_hdr->h_source);
433432
break;
434433
case IEEE80211_FCTL_TODS:
435-
ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
434+
ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
436435
break;
437436
case IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS:
438-
ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
439-
ether_addr_copy(hdr.addr4, eth_hdr.h_source);
437+
ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
438+
ether_addr_copy(hdr.addr4, eth_hdr->h_source);
440439
break;
441440
default:
442441
break;
443442
}
444443

445444
skb_pull(skb, hdr_gap + sizeof(struct ethhdr) - 2);
446-
if (eth_hdr.h_proto == htons(ETH_P_AARP) ||
447-
eth_hdr.h_proto == htons(ETH_P_IPX))
445+
if (eth_hdr->h_proto == cpu_to_be16(ETH_P_AARP) ||
446+
eth_hdr->h_proto == cpu_to_be16(ETH_P_IPX))
448447
ether_addr_copy(skb_push(skb, ETH_ALEN), bridge_tunnel_header);
449-
else if (eth_hdr.h_proto >= htons(ETH_P_802_3_MIN))
448+
else if (eth_hdr->h_proto >= cpu_to_be16(ETH_P_802_3_MIN))
450449
ether_addr_copy(skb_push(skb, ETH_ALEN), rfc1042_header);
451450
else
452451
skb_pull(skb, 2);

drivers/net/wireless/mediatek/mt76/mt7921/mac.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ mt7921_mac_assoc_rssi(struct mt7921_dev *dev, struct sk_buff *skb)
401401
static int mt7921_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
402402
{
403403
struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
404+
struct ethhdr *eth_hdr = (struct ethhdr *)(skb->data + hdr_gap);
404405
struct mt7921_sta *msta = (struct mt7921_sta *)status->wcid;
406+
__le32 *rxd = (__le32 *)skb->data;
405407
struct ieee80211_sta *sta;
406408
struct ieee80211_vif *vif;
407409
struct ieee80211_hdr hdr;
408-
struct ethhdr eth_hdr;
409-
__le32 *rxd = (__le32 *)skb->data;
410410
__le32 qos_ctrl, ht_ctrl;
411411

412412
if (FIELD_GET(MT_RXD3_NORMAL_ADDR_TYPE, le32_to_cpu(rxd[3])) !=
@@ -423,7 +423,6 @@ static int mt7921_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
423423
vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
424424

425425
/* store the info from RXD and ethhdr to avoid being overridden */
426-
memcpy(&eth_hdr, skb->data + hdr_gap, sizeof(eth_hdr));
427426
hdr.frame_control = FIELD_GET(MT_RXD6_FRAME_CONTROL, rxd[6]);
428427
hdr.seq_ctrl = FIELD_GET(MT_RXD8_SEQ_CTRL, rxd[8]);
429428
qos_ctrl = FIELD_GET(MT_RXD8_QOS_CTL, rxd[8]);
@@ -438,24 +437,24 @@ static int mt7921_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
438437
ether_addr_copy(hdr.addr3, vif->bss_conf.bssid);
439438
break;
440439
case IEEE80211_FCTL_FROMDS:
441-
ether_addr_copy(hdr.addr3, eth_hdr.h_source);
440+
ether_addr_copy(hdr.addr3, eth_hdr->h_source);
442441
break;
443442
case IEEE80211_FCTL_TODS:
444-
ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
443+
ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
445444
break;
446445
case IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS:
447-
ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
448-
ether_addr_copy(hdr.addr4, eth_hdr.h_source);
446+
ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
447+
ether_addr_copy(hdr.addr4, eth_hdr->h_source);
449448
break;
450449
default:
451450
break;
452451
}
453452

454453
skb_pull(skb, hdr_gap + sizeof(struct ethhdr) - 2);
455-
if (eth_hdr.h_proto == htons(ETH_P_AARP) ||
456-
eth_hdr.h_proto == htons(ETH_P_IPX))
454+
if (eth_hdr->h_proto == cpu_to_be16(ETH_P_AARP) ||
455+
eth_hdr->h_proto == cpu_to_be16(ETH_P_IPX))
457456
ether_addr_copy(skb_push(skb, ETH_ALEN), bridge_tunnel_header);
458-
else if (eth_hdr.h_proto >= htons(ETH_P_802_3_MIN))
457+
else if (eth_hdr->h_proto >= cpu_to_be16(ETH_P_802_3_MIN))
459458
ether_addr_copy(skb_push(skb, ETH_ALEN), rfc1042_header);
460459
else
461460
skb_pull(skb, 2);

0 commit comments

Comments
 (0)