mac80211: Update to version 4.19.161-1
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / subsys / 357-mac80211-optimize-skb-resizing.patch
index 5d53425f8dc4d8c4af152f89fb9d84faf415ae30..e7e8a0b286852a353a560e64ab08e8b694438fb6 100644 (file)
@@ -50,33 +50,39 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
        if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
 --- a/net/mac80211/tx.c
 +++ b/net/mac80211/tx.c
-@@ -1914,37 +1914,53 @@ static bool ieee80211_tx(struct ieee8021
+@@ -1914,42 +1914,53 @@ static bool ieee80211_tx(struct ieee8021
  }
  
  /* device xmit handlers */
 -
+-enum ieee80211_encrypt {
+-      ENCRYPT_NO,
+-      ENCRYPT_MGMT,
+-      ENCRYPT_DATA,
+-};
+-
 -static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
 -                              struct sk_buff *skb,
--                              int head_need, bool may_encrypt)
+-                              int head_need,
+-                              enum ieee80211_encrypt encrypt)
 +int ieee80211_skb_resize(struct ieee80211_local *local,
 +                       struct ieee80211_sub_if_data *sdata,
 +                       struct sk_buff *skb, int hdr_len, int hdr_extra)
  {
 -      struct ieee80211_local *local = sdata->local;
-+      struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       struct ieee80211_hdr *hdr;
 -      bool enc_tailroom;
 -      int tail_need = 0;
 -
--      hdr = (struct ieee80211_hdr *) skb->data;
--      enc_tailroom = may_encrypt &&
--                     (sdata->crypto_tx_tailroom_needed_cnt ||
--                      ieee80211_is_mgmt(hdr->frame_control));
+-      enc_tailroom = encrypt == ENCRYPT_MGMT ||
+-                     (encrypt == ENCRYPT_DATA &&
+-                      sdata->crypto_tx_tailroom_needed_cnt);
 -
 -      if (enc_tailroom) {
 -              tail_need = IEEE80211_ENCRYPT_TAILROOM;
 -              tail_need -= skb_tailroom(skb);
 -              tail_need = max_t(int, tail_need, 0);
++      struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
++      struct ieee80211_hdr *hdr;
 +      int head_need, head_max;
 +      int tail_need, tail_max;
 +      bool enc_tailroom = false;
@@ -123,27 +129,34 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
                wiphy_debug(local->hw.wiphy,
                            "failed to reallocate TX buffer\n");
                return -ENOMEM;
-@@ -1960,18 +1976,8 @@ void ieee80211_xmit(struct ieee80211_sub
+@@ -1964,24 +1975,9 @@ void ieee80211_xmit(struct ieee80211_sub
+ {
        struct ieee80211_local *local = sdata->local;
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       struct ieee80211_hdr *hdr;
+-      struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
 -      int headroom;
--      bool may_encrypt;
+-      enum ieee80211_encrypt encrypt;
+-
+-      if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)
+-              encrypt = ENCRYPT_NO;
+-      else if (ieee80211_is_mgmt(hdr->frame_control))
+-              encrypt = ENCRYPT_MGMT;
+-      else
+-              encrypt = ENCRYPT_DATA;
 -
--      may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
 -      headroom = local->tx_headroom;
--      if (may_encrypt)
+-      if (encrypt != ENCRYPT_NO)
 -              headroom += sdata->encrypt_headroom;
 -      headroom -= skb_headroom(skb);
 -      headroom = max_t(int, 0, headroom);
--
--      if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) {
++      struct ieee80211_hdr *hdr;
+-      if (ieee80211_skb_resize(sdata, skb, headroom, encrypt)) {
 +      if (ieee80211_skb_resize(local, sdata, skb, 0, 0)) {
                ieee80211_free_txskb(&local->hw, skb);
                return;
        }
-@@ -2741,30 +2747,14 @@ static struct sk_buff *ieee80211_build_h
+@@ -2752,30 +2748,14 @@ static struct sk_buff *ieee80211_build_h
  
        skb_pull(skb, skip_header_bytes);
        padsize = ieee80211_hdr_padsize(&local->hw, hdrlen);
@@ -167,7 +180,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
 -              head_need += sdata->encrypt_headroom;
 -              head_need += local->tx_headroom;
 -              head_need = max_t(int, 0, head_need);
--              if (ieee80211_skb_resize(sdata, skb, head_need, true)) {
+-              if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) {
 -                      ieee80211_free_txskb(&local->hw, skb);
 -                      skb = NULL;
 -                      return ERR_PTR(-ENOMEM);
@@ -180,7 +193,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
        }
  
        if (encaps_data)
-@@ -3377,7 +3367,6 @@ static bool ieee80211_xmit_fast(struct i
+@@ -3388,7 +3368,6 @@ static bool ieee80211_xmit_fast(struct i
        struct ieee80211_local *local = sdata->local;
        u16 ethertype = (skb->data[12] << 8) | skb->data[13];
        int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
@@ -188,14 +201,14 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
        struct ethhdr eth;
        struct ieee80211_tx_info *info;
        struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
-@@ -3429,10 +3418,7 @@ static bool ieee80211_xmit_fast(struct i
+@@ -3440,10 +3419,7 @@ static bool ieee80211_xmit_fast(struct i
         * as the may-encrypt argument for the resize to not account for
         * more room than we already have in 'extra_head'
         */
 -      if (unlikely(ieee80211_skb_resize(sdata, skb,
 -                                        max_t(int, extra_head + hw_headroom -
 -                                                   skb_headroom(skb), 0),
--                                        false))) {
+-                                        ENCRYPT_NO))) {
 +      if (unlikely(ieee80211_skb_resize(local, sdata, skb, extra_head, 0))) {
                kfree_skb(skb);
                return true;