Commit | Line | Data |
---|---|---|
0c817338 LF |
1 | /****************************************************************************** |
2 | * | |
a8d76066 | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
0c817338 LF |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
0c817338 LF |
14 | * The full GNU General Public License is included in this distribution in the |
15 | * file called LICENSE. | |
16 | * | |
17 | * Contact Information: | |
18 | * wlanfae <wlanfae@realtek.com> | |
19 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, | |
20 | * Hsinchu 300, Taiwan. | |
21 | * | |
22 | * Larry Finger <Larry.Finger@lwfinger.net> | |
23 | * | |
24 | *****************************************************************************/ | |
25 | ||
26 | #include "wifi.h" | |
27 | #include "base.h" | |
28 | #include "rc.h" | |
29 | ||
30 | /* | |
31 | *Finds the highest rate index we can use | |
32 | *if skb is special data like DHCP/EAPOL, we set should | |
33 | *it to lowest rate CCK_1M, otherwise we set rate to | |
f3a97e93 LF |
34 | *highest rate based on wireless mode used for iwconfig |
35 | *show Tx rate. | |
0c817338 LF |
36 | */ |
37 | static u8 _rtl_rc_get_highest_rix(struct rtl_priv *rtlpriv, | |
c6a9de08 | 38 | struct ieee80211_sta *sta, |
0c817338 LF |
39 | struct sk_buff *skb, bool not_data) |
40 | { | |
c6a9de08 C |
41 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
42 | struct rtl_phy *rtlphy = &(rtlpriv->phy); | |
43 | struct rtl_sta_info *sta_entry = NULL; | |
73fb2705 | 44 | u16 wireless_mode = 0; |
0c817338 LF |
45 | |
46 | /* | |
47 | *this rate is no use for true rate, firmware | |
48 | *will control rate at all it just used for | |
49 | *1.show in iwconfig in B/G mode | |
50 | *2.in rtl_get_tcb_desc when we check rate is | |
51 | * 1M we will not use FW rate but user rate. | |
52 | */ | |
f3a97e93 LF |
53 | |
54 | if (sta) { | |
55 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; | |
56 | wireless_mode = sta_entry->wireless_mode; | |
c6a9de08 C |
57 | } |
58 | ||
cad737df TY |
59 | if (rtl_is_special_data(rtlpriv->mac80211.hw, skb, true, false) || |
60 | not_data) { | |
c6a9de08 C |
61 | return 0; |
62 | } else { | |
63 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { | |
64 | if (wireless_mode == WIRELESS_MODE_B) { | |
65 | return B_MODE_MAX_RIX; | |
66 | } else if (wireless_mode == WIRELESS_MODE_G) { | |
67 | return G_MODE_MAX_RIX; | |
f3a97e93 | 68 | } else if (wireless_mode == WIRELESS_MODE_N_24G) { |
c6a9de08 C |
69 | if (get_rf_type(rtlphy) != RF_2T2R) |
70 | return N_MODE_MCS7_RIX; | |
71 | else | |
72 | return N_MODE_MCS15_RIX; | |
f3a97e93 LF |
73 | } else if (wireless_mode == WIRELESS_MODE_AC_24G) { |
74 | return AC_MODE_MCS9_RIX; | |
c6a9de08 | 75 | } |
f3a97e93 | 76 | return 0; |
c6a9de08 C |
77 | } else { |
78 | if (wireless_mode == WIRELESS_MODE_A) { | |
79 | return A_MODE_MAX_RIX; | |
f3a97e93 | 80 | } else if (wireless_mode == WIRELESS_MODE_N_5G) { |
c6a9de08 C |
81 | if (get_rf_type(rtlphy) != RF_2T2R) |
82 | return N_MODE_MCS7_RIX; | |
83 | else | |
84 | return N_MODE_MCS15_RIX; | |
f3a97e93 LF |
85 | } else if (wireless_mode == WIRELESS_MODE_AC_5G) { |
86 | return AC_MODE_MCS9_RIX; | |
c6a9de08 | 87 | } |
f3a97e93 | 88 | return 0; |
c6a9de08 | 89 | } |
0c817338 LF |
90 | } |
91 | } | |
92 | ||
93 | static void _rtl_rc_rate_set_series(struct rtl_priv *rtlpriv, | |
c6a9de08 | 94 | struct ieee80211_sta *sta, |
0c817338 LF |
95 | struct ieee80211_tx_rate *rate, |
96 | struct ieee80211_tx_rate_control *txrc, | |
c6a9de08 | 97 | u8 tries, char rix, int rtsctsenable, |
0c817338 LF |
98 | bool not_data) |
99 | { | |
100 | struct rtl_mac *mac = rtl_mac(rtlpriv); | |
f3a97e93 | 101 | struct rtl_sta_info *sta_entry = NULL; |
73fb2705 | 102 | u16 wireless_mode = 0; |
f3a97e93 | 103 | u8 sgi_20 = 0, sgi_40 = 0, sgi_80 = 0; |
0c817338 | 104 | |
c6a9de08 C |
105 | if (sta) { |
106 | sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20; | |
107 | sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40; | |
f3a97e93 LF |
108 | sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80; |
109 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; | |
110 | wireless_mode = sta_entry->wireless_mode; | |
c6a9de08 | 111 | } |
0c817338 | 112 | rate->count = tries; |
c6a9de08 | 113 | rate->idx = rix >= 0x00 ? rix : 0x00; |
f3a97e93 LF |
114 | if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE && |
115 | wireless_mode == WIRELESS_MODE_AC_5G) | |
116 | rate->idx += 0x10;/*2NSS for 8812AE*/ | |
0c817338 LF |
117 | |
118 | if (!not_data) { | |
119 | if (txrc->short_preamble) | |
120 | rate->flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE; | |
c6a9de08 | 121 | if (mac->opmode == NL80211_IFTYPE_AP || |
f3a97e93 LF |
122 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
123 | if (sta && (sta->ht_cap.cap & | |
124 | IEEE80211_HT_CAP_SUP_WIDTH_20_40)) | |
c6a9de08 | 125 | rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; |
f3a97e93 LF |
126 | if (sta && (sta->vht_cap.vht_supported)) |
127 | rate->flags |= IEEE80211_TX_RC_80_MHZ_WIDTH; | |
c6a9de08 C |
128 | } else { |
129 | if (mac->bw_40) | |
130 | rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; | |
f3a97e93 LF |
131 | if (mac->bw_80) |
132 | rate->flags |= IEEE80211_TX_RC_80_MHZ_WIDTH; | |
c6a9de08 | 133 | } |
f3a97e93 LF |
134 | |
135 | if (sgi_20 || sgi_40 || sgi_80) | |
0c817338 | 136 | rate->flags |= IEEE80211_TX_RC_SHORT_GI; |
f3a97e93 LF |
137 | if (sta && sta->ht_cap.ht_supported && |
138 | ((wireless_mode == WIRELESS_MODE_N_5G) || | |
139 | (wireless_mode == WIRELESS_MODE_N_24G))) | |
0c817338 | 140 | rate->flags |= IEEE80211_TX_RC_MCS; |
d76d65fd LF |
141 | if (sta && sta->vht_cap.vht_supported && |
142 | (wireless_mode == WIRELESS_MODE_AC_5G || | |
143 | wireless_mode == WIRELESS_MODE_AC_24G || | |
144 | wireless_mode == WIRELESS_MODE_AC_ONLY)) | |
145 | rate->flags |= IEEE80211_TX_RC_VHT_MCS; | |
0c817338 LF |
146 | } |
147 | } | |
148 | ||
149 | static void rtl_get_rate(void *ppriv, struct ieee80211_sta *sta, | |
f3a97e93 LF |
150 | void *priv_sta, |
151 | struct ieee80211_tx_rate_control *txrc) | |
0c817338 LF |
152 | { |
153 | struct rtl_priv *rtlpriv = ppriv; | |
154 | struct sk_buff *skb = txrc->skb; | |
155 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); | |
156 | struct ieee80211_tx_rate *rates = tx_info->control.rates; | |
c6a9de08 | 157 | __le16 fc = rtl_get_fc(skb); |
0c817338 LF |
158 | u8 try_per_rate, i, rix; |
159 | bool not_data = !ieee80211_is_data(fc); | |
160 | ||
161 | if (rate_control_send_low(sta, priv_sta, txrc)) | |
162 | return; | |
163 | ||
c6a9de08 | 164 | rix = _rtl_rc_get_highest_rix(rtlpriv, sta, skb, not_data); |
0c817338 | 165 | try_per_rate = 1; |
c6a9de08 | 166 | _rtl_rc_rate_set_series(rtlpriv, sta, &rates[0], txrc, |
0c817338 LF |
167 | try_per_rate, rix, 1, not_data); |
168 | ||
169 | if (!not_data) { | |
170 | for (i = 1; i < 4; i++) | |
c6a9de08 | 171 | _rtl_rc_rate_set_series(rtlpriv, sta, &rates[i], |
0c817338 LF |
172 | txrc, i, (rix - i), 1, |
173 | not_data); | |
174 | } | |
175 | } | |
176 | ||
c6a9de08 | 177 | static bool _rtl_tx_aggr_check(struct rtl_priv *rtlpriv, |
f3a97e93 | 178 | struct rtl_sta_info *sta_entry, u16 tid) |
0c817338 LF |
179 | { |
180 | struct rtl_mac *mac = rtl_mac(rtlpriv); | |
181 | ||
182 | if (mac->act_scanning) | |
183 | return false; | |
184 | ||
c6a9de08 | 185 | if (mac->opmode == NL80211_IFTYPE_STATION && |
f3a97e93 | 186 | mac->cnt_after_linked < 3) |
0c817338 LF |
187 | return false; |
188 | ||
c6a9de08 | 189 | if (sta_entry->tids[tid].agg.agg_state == RTL_AGG_STOP) |
0c817338 LF |
190 | return true; |
191 | ||
192 | return false; | |
193 | } | |
194 | ||
195 | /*mac80211 Rate Control callbacks*/ | |
196 | static void rtl_tx_status(void *ppriv, | |
197 | struct ieee80211_supported_band *sband, | |
198 | struct ieee80211_sta *sta, void *priv_sta, | |
199 | struct sk_buff *skb) | |
200 | { | |
201 | struct rtl_priv *rtlpriv = ppriv; | |
202 | struct rtl_mac *mac = rtl_mac(rtlpriv); | |
c6a9de08 C |
203 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
204 | __le16 fc = rtl_get_fc(skb); | |
205 | struct rtl_sta_info *sta_entry; | |
0c817338 LF |
206 | |
207 | if (!priv_sta || !ieee80211_is_data(fc)) | |
208 | return; | |
209 | ||
cad737df | 210 | if (rtl_is_special_data(mac->hw, skb, true, true)) |
0c817338 LF |
211 | return; |
212 | ||
f3a97e93 LF |
213 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) || |
214 | is_broadcast_ether_addr(ieee80211_get_DA(hdr))) | |
0c817338 LF |
215 | return; |
216 | ||
c6a9de08 C |
217 | if (sta) { |
218 | /* Check if aggregation has to be enabled for this tid */ | |
219 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; | |
e10542c4 | 220 | if ((sta->ht_cap.ht_supported) && |
f3a97e93 | 221 | !(skb->protocol == cpu_to_be16(ETH_P_PAE))) { |
c6a9de08 C |
222 | if (ieee80211_is_data_qos(fc)) { |
223 | u8 tid = rtl_get_tid(skb); | |
224 | if (_rtl_tx_aggr_check(rtlpriv, sta_entry, | |
f3a97e93 | 225 | tid)) { |
c6a9de08 | 226 | sta_entry->tids[tid].agg.agg_state = |
f3a97e93 LF |
227 | RTL_AGG_PROGRESS; |
228 | ieee80211_start_tx_ba_session(sta, tid, | |
229 | 5000); | |
c6a9de08 C |
230 | } |
231 | } | |
0c817338 LF |
232 | } |
233 | } | |
234 | } | |
235 | ||
c88d0dc1 CI |
236 | static void rtl_rate_init(void *ppriv, |
237 | struct ieee80211_supported_band *sband, | |
3de805cf | 238 | struct cfg80211_chan_def *chandef, |
c88d0dc1 CI |
239 | struct ieee80211_sta *sta, void *priv_sta) |
240 | { | |
241 | } | |
242 | ||
f3a97e93 LF |
243 | static void rtl_rate_update(void *ppriv, |
244 | struct ieee80211_supported_band *sband, | |
245 | struct cfg80211_chan_def *chandef, | |
246 | struct ieee80211_sta *sta, void *priv_sta, | |
247 | u32 changed) | |
248 | { | |
249 | } | |
250 | ||
251 | static void *rtl_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) | |
0c817338 LF |
252 | { |
253 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
254 | return rtlpriv; | |
255 | } | |
256 | ||
257 | static void rtl_rate_free(void *rtlpriv) | |
258 | { | |
259 | return; | |
260 | } | |
261 | ||
262 | static void *rtl_rate_alloc_sta(void *ppriv, | |
263 | struct ieee80211_sta *sta, gfp_t gfp) | |
264 | { | |
265 | struct rtl_priv *rtlpriv = ppriv; | |
266 | struct rtl_rate_priv *rate_priv; | |
267 | ||
268 | rate_priv = kzalloc(sizeof(struct rtl_rate_priv), gfp); | |
269 | if (!rate_priv) { | |
270 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | |
f30d7507 | 271 | "Unable to allocate private rc structure\n"); |
0c817338 LF |
272 | return NULL; |
273 | } | |
274 | ||
275 | rtlpriv->rate_priv = rate_priv; | |
276 | ||
277 | return rate_priv; | |
278 | } | |
279 | ||
280 | static void rtl_rate_free_sta(void *rtlpriv, | |
281 | struct ieee80211_sta *sta, void *priv_sta) | |
282 | { | |
283 | struct rtl_rate_priv *rate_priv = priv_sta; | |
284 | kfree(rate_priv); | |
285 | } | |
286 | ||
f3a97e93 | 287 | static struct rate_control_ops rtl_rate_ops = { |
0c817338 LF |
288 | .name = "rtl_rc", |
289 | .alloc = rtl_rate_alloc, | |
290 | .free = rtl_rate_free, | |
291 | .alloc_sta = rtl_rate_alloc_sta, | |
292 | .free_sta = rtl_rate_free_sta, | |
c88d0dc1 | 293 | .rate_init = rtl_rate_init, |
f3a97e93 | 294 | .rate_update = rtl_rate_update, |
0c817338 LF |
295 | .tx_status = rtl_tx_status, |
296 | .get_rate = rtl_get_rate, | |
297 | }; | |
298 | ||
299 | int rtl_rate_control_register(void) | |
300 | { | |
301 | return ieee80211_rate_control_register(&rtl_rate_ops); | |
302 | } | |
303 | ||
304 | void rtl_rate_control_unregister(void) | |
305 | { | |
306 | ieee80211_rate_control_unregister(&rtl_rate_ops); | |
307 | } |