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
5 The software rate control cannot deal with encap offload, so fix it.
7 Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
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);
16 +static inline bool ieee80211_is_tx_data(struct sk_buff *skb)
18 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
19 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
21 + return info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP ||
22 + ieee80211_is_data(hdr->frame_control);
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)
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);
38 - fc = hdr->frame_control;
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);
46 static void rc_send_low_basicrate(struct ieee80211_tx_rate *rate,
47 @@ -870,7 +866,6 @@ void ieee80211_get_tx_rates(struct ieee8
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;
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];
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);
64 --- a/net/mac80211/tx.c
65 +++ b/net/mac80211/tx.c
66 @@ -679,6 +679,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
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;
73 memset(&txrc, 0, sizeof(txrc));
74 @@ -720,7 +721,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
75 * just wants a probe response.
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;
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,
89 + encap ? ((struct ethhdr *)hdr)->h_dest : hdr->addr1,
93 @@ -776,7 +778,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
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;
101 tx->sta->tx_stats.last_rate = txrc.reported_rate;
102 @@ -3660,8 +3662,16 @@ begin:
104 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
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);
118 if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) {
119 struct sta_info *sta = container_of(txq->sta, struct sta_info,