6acb814b28467083983e497537b2342ab3cc13a1
[openwrt/staging/dedeckeh.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/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 @@ -870,7 +866,6 @@ void ieee80211_get_tx_rates(struct ieee8
30 int max_rates)
31 {
32 struct ieee80211_sub_if_data *sdata;
33 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
35 struct ieee80211_supported_band *sband;
36
37 @@ -882,7 +877,7 @@ void ieee80211_get_tx_rates(struct ieee8
38 sdata = vif_to_sdata(vif);
39 sband = sdata->local->hw.wiphy->bands[info->band];
40
41 - if (ieee80211_is_data(hdr->frame_control))
42 + if (ieee80211_is_tx_data(skb))
43 rate_control_apply_mask(sdata, sta, sband, dest, max_rates);
44
45 if (dest[0].idx < 0)
46 --- a/net/mac80211/tx.c
47 +++ b/net/mac80211/tx.c
48 @@ -666,6 +666,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
49 u32 len;
50 struct ieee80211_tx_rate_control txrc;
51 struct ieee80211_sta_rates *ratetbl = NULL;
52 + bool encap = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
53 bool assoc = false;
54
55 memset(&txrc, 0, sizeof(txrc));
56 @@ -707,7 +708,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
57 * just wants a probe response.
58 */
59 if (tx->sdata->vif.bss_conf.use_short_preamble &&
60 - (ieee80211_is_data(hdr->frame_control) ||
61 + (ieee80211_is_tx_data(tx->skb) ||
62 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
63 txrc.short_preamble = true;
64
65 @@ -729,7 +730,8 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
66 "%s: Dropped data frame as no usable bitrate found while "
67 "scanning and associated. Target station: "
68 "%pM on %d GHz band\n",
69 - tx->sdata->name, hdr->addr1,
70 + tx->sdata->name,
71 + encap ? ((struct ethhdr *)hdr)->h_dest : hdr->addr1,
72 info->band ? 5 : 2))
73 return TX_DROP;
74
75 @@ -763,7 +765,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
76
77 if (txrc.reported_rate.idx < 0) {
78 txrc.reported_rate = tx->rate;
79 - if (tx->sta && ieee80211_is_data(hdr->frame_control))
80 + if (tx->sta && ieee80211_is_tx_data(tx->skb))
81 tx->sta->tx_stats.last_rate = txrc.reported_rate;
82 } else if (tx->sta)
83 tx->sta->tx_stats.last_rate = txrc.reported_rate;
84 @@ -3631,8 +3633,16 @@ begin:
85 else
86 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
87
88 - if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)
89 + if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
90 + if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
91 + r = ieee80211_tx_h_rate_ctrl(&tx);
92 + if (r != TX_CONTINUE) {
93 + ieee80211_free_txskb(&local->hw, skb);
94 + goto begin;
95 + }
96 + }
97 goto encap_out;
98 + }
99
100 if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) {
101 struct sta_info *sta = container_of(txq->sta, struct sta_info,
102 --- a/include/net/mac80211.h
103 +++ b/include/net/mac80211.h
104 @@ -6754,4 +6754,22 @@ struct sk_buff *ieee80211_get_fils_disco
105 struct sk_buff *
106 ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
107 struct ieee80211_vif *vif);
108 +
109 +/**
110 + * ieee80211_is_tx_data - check if frame is a data frame
111 + *
112 + * The function is used to check if a frame is a data frame. Frames with
113 + * hardware encapsulation enabled are data frames.
114 + *
115 + * @skb: the frame to be transmitted.
116 + */
117 +static inline bool ieee80211_is_tx_data(struct sk_buff *skb)
118 +{
119 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
120 + struct ieee80211_hdr *hdr = (void *) skb->data;
121 +
122 + return info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP ||
123 + ieee80211_is_data(hdr->frame_control);
124 +}
125 +
126 #endif /* MAC80211_H */