2a4551023f2f9d1167ce881e5bc20476eb81a7ec
[openwrt/staging/stintel.git] / package / kernel / mac80211 / patches / subsys / 376-mac80211-add-rate-control-support-for-encap-offload.patch
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/rate.c
11 +++ b/net/mac80211/rate.c
12 @@ -297,15 +297,11 @@ void ieee80211_check_rate_mask(struct ie
13 static bool rc_no_data_or_no_ack_use_min(struct ieee80211_tx_rate_control *txrc)
14 {
15 struct sk_buff *skb = txrc->skb;
16 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
17 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
18 - __le16 fc;
19 -
20 - fc = hdr->frame_control;
21
22 return (info->flags & (IEEE80211_TX_CTL_NO_ACK |
23 IEEE80211_TX_CTL_USE_MINRATE)) ||
24 - !ieee80211_is_data(fc);
25 + !ieee80211_is_tx_data(skb);
26 }
27
28 static void rc_send_low_basicrate(struct ieee80211_tx_rate *rate,
29 @@ -396,6 +392,10 @@ static bool rate_control_send_low(struct
30 int mcast_rate;
31 bool use_basicrate = false;
32
33 + if (ieee80211_is_tx_data(txrc->skb) &&
34 + info->flags & IEEE80211_TX_CTL_NO_ACK)
35 + return false;
36 +
37 if (!pubsta || rc_no_data_or_no_ack_use_min(txrc)) {
38 __rate_control_send_low(txrc->hw, sband, pubsta, info,
39 txrc->rate_idx_mask);
40 @@ -870,7 +870,6 @@ void ieee80211_get_tx_rates(struct ieee8
41 int max_rates)
42 {
43 struct ieee80211_sub_if_data *sdata;
44 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
45 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
46 struct ieee80211_supported_band *sband;
47
48 @@ -882,7 +881,7 @@ void ieee80211_get_tx_rates(struct ieee8
49 sdata = vif_to_sdata(vif);
50 sband = sdata->local->hw.wiphy->bands[info->band];
51
52 - if (ieee80211_is_data(hdr->frame_control))
53 + if (ieee80211_is_tx_data(skb))
54 rate_control_apply_mask(sdata, sta, sband, dest, max_rates);
55
56 if (dest[0].idx < 0)
57 --- a/net/mac80211/tx.c
58 +++ b/net/mac80211/tx.c
59 @@ -679,6 +679,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
60 u32 len;
61 struct ieee80211_tx_rate_control txrc;
62 struct ieee80211_sta_rates *ratetbl = NULL;
63 + bool encap = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
64 bool assoc = false;
65
66 memset(&txrc, 0, sizeof(txrc));
67 @@ -720,7 +721,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
68 * just wants a probe response.
69 */
70 if (tx->sdata->vif.bss_conf.use_short_preamble &&
71 - (ieee80211_is_data(hdr->frame_control) ||
72 + (ieee80211_is_tx_data(tx->skb) ||
73 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
74 txrc.short_preamble = true;
75
76 @@ -742,7 +743,8 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
77 "%s: Dropped data frame as no usable bitrate found while "
78 "scanning and associated. Target station: "
79 "%pM on %d GHz band\n",
80 - tx->sdata->name, hdr->addr1,
81 + tx->sdata->name,
82 + encap ? ((struct ethhdr *)hdr)->h_dest : hdr->addr1,
83 info->band ? 5 : 2))
84 return TX_DROP;
85
86 @@ -776,7 +778,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
87
88 if (txrc.reported_rate.idx < 0) {
89 txrc.reported_rate = tx->rate;
90 - if (tx->sta && ieee80211_is_data(hdr->frame_control))
91 + if (tx->sta && ieee80211_is_tx_data(tx->skb))
92 tx->sta->tx_stats.last_rate = txrc.reported_rate;
93 } else if (tx->sta)
94 tx->sta->tx_stats.last_rate = txrc.reported_rate;
95 @@ -3660,8 +3662,16 @@ begin:
96 else
97 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
98
99 - if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)
100 + if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
101 + if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
102 + r = ieee80211_tx_h_rate_ctrl(&tx);
103 + if (r != TX_CONTINUE) {
104 + ieee80211_free_txskb(&local->hw, skb);
105 + goto begin;
106 + }
107 + }
108 goto encap_out;
109 + }
110
111 if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) {
112 struct sta_info *sta = container_of(txq->sta, struct sta_info,
113 --- a/include/net/mac80211.h
114 +++ b/include/net/mac80211.h
115 @@ -6728,4 +6728,22 @@ struct sk_buff *ieee80211_get_fils_disco
116 struct sk_buff *
117 ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
118 struct ieee80211_vif *vif);
119 +
120 +/**
121 + * ieee80211_is_tx_data - check if frame is a data frame
122 + *
123 + * The function is used to check if a frame is a data frame. Frames with
124 + * hardware encapsulation enabled are data frames.
125 + *
126 + * @skb: the frame to be transmitted.
127 + */
128 +static inline bool ieee80211_is_tx_data(struct sk_buff *skb)
129 +{
130 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
131 + struct ieee80211_hdr *hdr = (void *) skb->data;
132 +
133 + return info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP ||
134 + ieee80211_is_data(hdr->frame_control);
135 +}
136 +
137 #endif /* MAC80211_H */