mt76: do not always copy ethhdr in reverse_frag0_hdr_trans
authorLorenzo Bianconi <lorenzo@kernel.org>
Tue, 11 Jan 2022 15:10:05 +0000 (16:10 +0100)
committerFelix Fietkau <nbd@nbd.name>
Thu, 3 Feb 2022 15:15:05 +0000 (16:15 +0100)
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 <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7615/mac.c
drivers/net/wireless/mediatek/mt76/mt7915/mac.c
drivers/net/wireless/mediatek/mt76/mt7921/mac.c

index 1b350cc1d631aecf31f435197f965a1db59de0a7..f035cd880696a30abf9da0778adb4dc54cb4105a 100644 (file)
@@ -253,12 +253,12 @@ static void mt7615_mac_fill_tm_rx(struct mt7615_phy *phy, __le32 *rxv)
 static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
 {
        struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
+       struct ethhdr *eth_hdr = (struct ethhdr *)(skb->data + hdr_gap);
        struct mt7615_sta *msta = (struct mt7615_sta *)status->wcid;
+       __le32 *rxd = (__le32 *)skb->data;
        struct ieee80211_sta *sta;
        struct ieee80211_vif *vif;
        struct ieee80211_hdr hdr;
-       struct ethhdr eth_hdr;
-       __le32 *rxd = (__le32 *)skb->data;
        __le32 qos_ctrl, ht_ctrl;
 
        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)
        vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
 
        /* store the info from RXD and ethhdr to avoid being overridden */
-       memcpy(&eth_hdr, skb->data + hdr_gap, sizeof(eth_hdr));
        hdr.frame_control = FIELD_GET(MT_RXD4_FRAME_CONTROL, rxd[4]);
        hdr.seq_ctrl = FIELD_GET(MT_RXD6_SEQ_CTRL, rxd[6]);
        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)
                ether_addr_copy(hdr.addr3, vif->bss_conf.bssid);
                break;
        case IEEE80211_FCTL_FROMDS:
-               ether_addr_copy(hdr.addr3, eth_hdr.h_source);
+               ether_addr_copy(hdr.addr3, eth_hdr->h_source);
                break;
        case IEEE80211_FCTL_TODS:
-               ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
+               ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
                break;
        case IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS:
-               ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
-               ether_addr_copy(hdr.addr4, eth_hdr.h_source);
+               ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
+               ether_addr_copy(hdr.addr4, eth_hdr->h_source);
                break;
        default:
                break;
        }
 
        skb_pull(skb, hdr_gap + sizeof(struct ethhdr) - 2);
-       if (eth_hdr.h_proto == htons(ETH_P_AARP) ||
-           eth_hdr.h_proto == htons(ETH_P_IPX))
+       if (eth_hdr->h_proto == cpu_to_be16(ETH_P_AARP) ||
+           eth_hdr->h_proto == cpu_to_be16(ETH_P_IPX))
                ether_addr_copy(skb_push(skb, ETH_ALEN), bridge_tunnel_header);
-       else if (eth_hdr.h_proto >= htons(ETH_P_802_3_MIN))
+       else if (eth_hdr->h_proto >= cpu_to_be16(ETH_P_802_3_MIN))
                ether_addr_copy(skb_push(skb, ETH_ALEN), rfc1042_header);
        else
                skb_pull(skb, 2);
index 59f0334ef8d23253868bc599659530644025cbad..08ee78f6309b3dfaa8c9e3728cdf63b0a119ef61 100644 (file)
@@ -392,12 +392,12 @@ mt7915_mac_decode_he_radiotap(struct sk_buff *skb, __le32 *rxv, u32 mode)
 static int mt7915_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
 {
        struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
+       struct ethhdr *eth_hdr = (struct ethhdr *)(skb->data + hdr_gap);
        struct mt7915_sta *msta = (struct mt7915_sta *)status->wcid;
+       __le32 *rxd = (__le32 *)skb->data;
        struct ieee80211_sta *sta;
        struct ieee80211_vif *vif;
        struct ieee80211_hdr hdr;
-       struct ethhdr eth_hdr;
-       __le32 *rxd = (__le32 *)skb->data;
        __le32 qos_ctrl, ht_ctrl;
 
        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)
        vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
 
        /* store the info from RXD and ethhdr to avoid being overridden */
-       memcpy(&eth_hdr, skb->data + hdr_gap, sizeof(eth_hdr));
        hdr.frame_control = FIELD_GET(MT_RXD6_FRAME_CONTROL, rxd[6]);
        hdr.seq_ctrl = FIELD_GET(MT_RXD8_SEQ_CTRL, rxd[8]);
        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)
                ether_addr_copy(hdr.addr3, vif->bss_conf.bssid);
                break;
        case IEEE80211_FCTL_FROMDS:
-               ether_addr_copy(hdr.addr3, eth_hdr.h_source);
+               ether_addr_copy(hdr.addr3, eth_hdr->h_source);
                break;
        case IEEE80211_FCTL_TODS:
-               ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
+               ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
                break;
        case IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS:
-               ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
-               ether_addr_copy(hdr.addr4, eth_hdr.h_source);
+               ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
+               ether_addr_copy(hdr.addr4, eth_hdr->h_source);
                break;
        default:
                break;
        }
 
        skb_pull(skb, hdr_gap + sizeof(struct ethhdr) - 2);
-       if (eth_hdr.h_proto == htons(ETH_P_AARP) ||
-           eth_hdr.h_proto == htons(ETH_P_IPX))
+       if (eth_hdr->h_proto == cpu_to_be16(ETH_P_AARP) ||
+           eth_hdr->h_proto == cpu_to_be16(ETH_P_IPX))
                ether_addr_copy(skb_push(skb, ETH_ALEN), bridge_tunnel_header);
-       else if (eth_hdr.h_proto >= htons(ETH_P_802_3_MIN))
+       else if (eth_hdr->h_proto >= cpu_to_be16(ETH_P_802_3_MIN))
                ether_addr_copy(skb_push(skb, ETH_ALEN), rfc1042_header);
        else
                skb_pull(skb, 2);
index 25d09ed207f048444477e9d6a23cded3dd859a98..d17558349a17a57994af927eed2286fc9aabbf82 100644 (file)
@@ -401,12 +401,12 @@ mt7921_mac_assoc_rssi(struct mt7921_dev *dev, struct sk_buff *skb)
 static int mt7921_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
 {
        struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
+       struct ethhdr *eth_hdr = (struct ethhdr *)(skb->data + hdr_gap);
        struct mt7921_sta *msta = (struct mt7921_sta *)status->wcid;
+       __le32 *rxd = (__le32 *)skb->data;
        struct ieee80211_sta *sta;
        struct ieee80211_vif *vif;
        struct ieee80211_hdr hdr;
-       struct ethhdr eth_hdr;
-       __le32 *rxd = (__le32 *)skb->data;
        __le32 qos_ctrl, ht_ctrl;
 
        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)
        vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
 
        /* store the info from RXD and ethhdr to avoid being overridden */
-       memcpy(&eth_hdr, skb->data + hdr_gap, sizeof(eth_hdr));
        hdr.frame_control = FIELD_GET(MT_RXD6_FRAME_CONTROL, rxd[6]);
        hdr.seq_ctrl = FIELD_GET(MT_RXD8_SEQ_CTRL, rxd[8]);
        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)
                ether_addr_copy(hdr.addr3, vif->bss_conf.bssid);
                break;
        case IEEE80211_FCTL_FROMDS:
-               ether_addr_copy(hdr.addr3, eth_hdr.h_source);
+               ether_addr_copy(hdr.addr3, eth_hdr->h_source);
                break;
        case IEEE80211_FCTL_TODS:
-               ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
+               ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
                break;
        case IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS:
-               ether_addr_copy(hdr.addr3, eth_hdr.h_dest);
-               ether_addr_copy(hdr.addr4, eth_hdr.h_source);
+               ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
+               ether_addr_copy(hdr.addr4, eth_hdr->h_source);
                break;
        default:
                break;
        }
 
        skb_pull(skb, hdr_gap + sizeof(struct ethhdr) - 2);
-       if (eth_hdr.h_proto == htons(ETH_P_AARP) ||
-           eth_hdr.h_proto == htons(ETH_P_IPX))
+       if (eth_hdr->h_proto == cpu_to_be16(ETH_P_AARP) ||
+           eth_hdr->h_proto == cpu_to_be16(ETH_P_IPX))
                ether_addr_copy(skb_push(skb, ETH_ALEN), bridge_tunnel_header);
-       else if (eth_hdr.h_proto >= htons(ETH_P_802_3_MIN))
+       else if (eth_hdr->h_proto >= cpu_to_be16(ETH_P_802_3_MIN))
                ether_addr_copy(skb_push(skb, ETH_ALEN), rfc1042_header);
        else
                skb_pull(skb, 2);