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/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)
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);
20 - fc = hdr->frame_control;
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);
28 static void rc_send_low_basicrate(struct ieee80211_tx_rate *rate,
29 @@ -396,6 +392,10 @@ static bool rate_control_send_low(struct
31 bool use_basicrate = false;
33 + if (ieee80211_is_tx_data(txrc->skb) &&
34 + info->flags & IEEE80211_TX_CTL_NO_ACK)
37 if (!pubsta || rc_no_data_or_no_ack_use_min(txrc)) {
38 __rate_control_send_low(txrc->hw, sband, pubsta, info,
40 @@ -870,7 +870,6 @@ void ieee80211_get_tx_rates(struct ieee8
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;
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];
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);
57 --- a/net/mac80211/tx.c
58 +++ b/net/mac80211/tx.c
59 @@ -679,6 +679,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
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;
66 memset(&txrc, 0, sizeof(txrc));
67 @@ -720,7 +721,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
68 * just wants a probe response.
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;
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,
82 + encap ? ((struct ethhdr *)hdr)->h_dest : hdr->addr1,
86 @@ -776,7 +778,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
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;
94 tx->sta->tx_stats.last_rate = txrc.reported_rate;
95 @@ -3660,8 +3662,16 @@ begin:
97 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
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);
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
117 ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
118 struct ieee80211_vif *vif);
121 + * ieee80211_is_tx_data - check if frame is a data frame
123 + * The function is used to check if a frame is a data frame. Frames with
124 + * hardware encapsulation enabled are data frames.
126 + * @skb: the frame to be transmitted.
128 +static inline bool ieee80211_is_tx_data(struct sk_buff *skb)
130 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
131 + struct ieee80211_hdr *hdr = (void *) skb->data;
133 + return info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP ||
134 + ieee80211_is_data(hdr->frame_control);
137 #endif /* MAC80211_H */