43a4a1334df0e47276071ba38ee16671c7247f7d
[openwrt/staging/ldir.git] /
1 From: Ryder Lee <ryder.lee@mediatek.com>
2 Date: Fri, 28 May 2021 14:05:43 +0800
3 Subject: [PATCH] mac80211: add rate control support for encap offload
4
5 The software rate control cannot deal with encap offload, so fix it.
6
7 Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
8 ---
9
10 --- a/net/mac80211/ieee80211_i.h
11 +++ b/net/mac80211/ieee80211_i.h
12 @@ -2024,6 +2024,15 @@ static inline void ieee80211_tx_skb(stru
13 ieee80211_tx_skb_tid(sdata, skb, 7);
14 }
15
16 +static inline bool ieee80211_is_tx_data(struct sk_buff *skb)
17 +{
18 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
19 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
20 +
21 + return info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP ||
22 + ieee80211_is_data(hdr->frame_control);
23 +}
24 +
25 u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
26 struct ieee802_11_elems *elems,
27 u64 filter, u32 crc, u8 *transmitter_bssid,
28 --- a/net/mac80211/rate.c
29 +++ b/net/mac80211/rate.c
30 @@ -297,15 +297,11 @@ void ieee80211_check_rate_mask(struct ie
31 static bool rc_no_data_or_no_ack_use_min(struct ieee80211_tx_rate_control *txrc)
32 {
33 struct sk_buff *skb = txrc->skb;
34 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
35 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
36 - __le16 fc;
37 -
38 - fc = hdr->frame_control;
39
40 return (info->flags & (IEEE80211_TX_CTL_NO_ACK |
41 IEEE80211_TX_CTL_USE_MINRATE)) ||
42 - !ieee80211_is_data(fc);
43 + !ieee80211_is_tx_data(skb);
44 }
45
46 static void rc_send_low_basicrate(struct ieee80211_tx_rate *rate,
47 @@ -870,7 +866,6 @@ void ieee80211_get_tx_rates(struct ieee8
48 int max_rates)
49 {
50 struct ieee80211_sub_if_data *sdata;
51 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
52 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
53 struct ieee80211_supported_band *sband;
54
55 @@ -882,7 +877,7 @@ void ieee80211_get_tx_rates(struct ieee8
56 sdata = vif_to_sdata(vif);
57 sband = sdata->local->hw.wiphy->bands[info->band];
58
59 - if (ieee80211_is_data(hdr->frame_control))
60 + if (ieee80211_is_tx_data(skb))
61 rate_control_apply_mask(sdata, sta, sband, dest, max_rates);
62
63 if (dest[0].idx < 0)
64 --- a/net/mac80211/tx.c
65 +++ b/net/mac80211/tx.c
66 @@ -679,6 +679,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
67 u32 len;
68 struct ieee80211_tx_rate_control txrc;
69 struct ieee80211_sta_rates *ratetbl = NULL;
70 + bool encap = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
71 bool assoc = false;
72
73 memset(&txrc, 0, sizeof(txrc));
74 @@ -720,7 +721,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
75 * just wants a probe response.
76 */
77 if (tx->sdata->vif.bss_conf.use_short_preamble &&
78 - (ieee80211_is_data(hdr->frame_control) ||
79 + (ieee80211_is_tx_data(tx->skb) ||
80 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
81 txrc.short_preamble = true;
82
83 @@ -742,7 +743,8 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
84 "%s: Dropped data frame as no usable bitrate found while "
85 "scanning and associated. Target station: "
86 "%pM on %d GHz band\n",
87 - tx->sdata->name, hdr->addr1,
88 + tx->sdata->name,
89 + encap ? ((struct ethhdr *)hdr)->h_dest : hdr->addr1,
90 info->band ? 5 : 2))
91 return TX_DROP;
92
93 @@ -776,7 +778,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
94
95 if (txrc.reported_rate.idx < 0) {
96 txrc.reported_rate = tx->rate;
97 - if (tx->sta && ieee80211_is_data(hdr->frame_control))
98 + if (tx->sta && ieee80211_is_tx_data(tx->skb))
99 tx->sta->tx_stats.last_rate = txrc.reported_rate;
100 } else if (tx->sta)
101 tx->sta->tx_stats.last_rate = txrc.reported_rate;
102 @@ -3660,8 +3662,16 @@ begin:
103 else
104 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
105
106 - if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)
107 + if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
108 + if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
109 + r = ieee80211_tx_h_rate_ctrl(&tx);
110 + if (r != TX_CONTINUE) {
111 + ieee80211_free_txskb(&local->hw, skb);
112 + goto begin;
113 + }
114 + }
115 goto encap_out;
116 + }
117
118 if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) {
119 struct sta_info *sta = container_of(txq->sta, struct sta_info,