1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60#include "rs.h"
61#include "fw-api.h"
62#include "sta.h"
63#include "iwl-op-mode.h"
64#include "mvm.h"
65
66static u8 rs_fw_bw_from_sta_bw(struct ieee80211_sta *sta)
67{
68 switch (sta->bandwidth) {
69 case IEEE80211_STA_RX_BW_160:
70 return IWL_TLC_MNG_CH_WIDTH_160MHZ;
71 case IEEE80211_STA_RX_BW_80:
72 return IWL_TLC_MNG_CH_WIDTH_80MHZ;
73 case IEEE80211_STA_RX_BW_40:
74 return IWL_TLC_MNG_CH_WIDTH_40MHZ;
75 case IEEE80211_STA_RX_BW_20:
76 default:
77 return IWL_TLC_MNG_CH_WIDTH_20MHZ;
78 }
79}
80
81static u8 rs_fw_set_active_chains(u8 chains)
82{
83 u8 fw_chains = 0;
84
85 if (chains & ANT_A)
86 fw_chains |= IWL_TLC_MNG_CHAIN_A_MSK;
87 if (chains & ANT_B)
88 fw_chains |= IWL_TLC_MNG_CHAIN_B_MSK;
89 if (chains & ANT_C)
90 WARN(false,
91 "tlc offload doesn't support antenna C. chains: 0x%x\n",
92 chains);
93
94 return fw_chains;
95}
96
97static u8 rs_fw_sgi_cw_support(struct ieee80211_sta *sta)
98{
99 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
100 struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
101 struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
102 u8 supp = 0;
103
104 if (he_cap->has_he)
105 return 0;
106
107 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
108 supp |= BIT(IWL_TLC_MNG_CH_WIDTH_20MHZ);
109 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
110 supp |= BIT(IWL_TLC_MNG_CH_WIDTH_40MHZ);
111 if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_80)
112 supp |= BIT(IWL_TLC_MNG_CH_WIDTH_80MHZ);
113 if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_160)
114 supp |= BIT(IWL_TLC_MNG_CH_WIDTH_160MHZ);
115
116 return supp;
117}
118
119static u16 rs_fw_get_config_flags(struct iwl_mvm *mvm,
120 struct ieee80211_sta *sta,
121 struct ieee80211_supported_band *sband)
122{
123 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
124 struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
125 struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
126 bool vht_ena = vht_cap->vht_supported;
127 u16 flags = 0;
128
129 if (mvm->cfg->ht_params->stbc &&
130 (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) > 1)) {
131 if (he_cap->has_he) {
132 if (he_cap->he_cap_elem.phy_cap_info[2] &
133 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ)
134 flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK;
135
136 if (he_cap->he_cap_elem.phy_cap_info[7] &
137 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ)
138 flags |= IWL_TLC_MNG_CFG_FLAGS_HE_STBC_160MHZ_MSK;
139 } else if ((ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) ||
140 (vht_ena &&
141 (vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK)))
142 flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK;
143 }
144
145 if (mvm->cfg->ht_params->ldpc &&
146 ((ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) ||
147 (vht_ena && (vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC))))
148 flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK;
149
150
151 if (sband->iftype_data && sband->iftype_data->he_cap.has_he &&
152 !(sband->iftype_data->he_cap.he_cap_elem.phy_cap_info[1] &
153 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD))
154 flags &= ~IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK;
155
156 if (he_cap->has_he &&
157 (he_cap->he_cap_elem.phy_cap_info[3] &
158 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK))
159 flags |= IWL_TLC_MNG_CFG_FLAGS_HE_DCM_NSS_1_MSK;
160
161 return flags;
162}
163
164static
165int rs_fw_vht_highest_rx_mcs_index(const struct ieee80211_sta_vht_cap *vht_cap,
166 int nss)
167{
168 u16 rx_mcs = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) &
169 (0x3 << (2 * (nss - 1)));
170 rx_mcs >>= (2 * (nss - 1));
171
172 switch (rx_mcs) {
173 case IEEE80211_VHT_MCS_SUPPORT_0_7:
174 return IWL_TLC_MNG_HT_RATE_MCS7;
175 case IEEE80211_VHT_MCS_SUPPORT_0_8:
176 return IWL_TLC_MNG_HT_RATE_MCS8;
177 case IEEE80211_VHT_MCS_SUPPORT_0_9:
178 return IWL_TLC_MNG_HT_RATE_MCS9;
179 default:
180 WARN_ON_ONCE(1);
181 break;
182 }
183
184 return 0;
185}
186
187static void
188rs_fw_vht_set_enabled_rates(const struct ieee80211_sta *sta,
189 const struct ieee80211_sta_vht_cap *vht_cap,
190 struct iwl_tlc_config_cmd *cmd)
191{
192 u16 supp;
193 int i, highest_mcs;
194
195 for (i = 0; i < sta->rx_nss; i++) {
196 if (i == IWL_TLC_NSS_MAX)
197 break;
198
199 highest_mcs = rs_fw_vht_highest_rx_mcs_index(vht_cap, i + 1);
200 if (!highest_mcs)
201 continue;
202
203 supp = BIT(highest_mcs + 1) - 1;
204 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
205 supp &= ~BIT(IWL_TLC_MNG_HT_RATE_MCS9);
206
207 cmd->ht_rates[i][IWL_TLC_HT_BW_NONE_160] = cpu_to_le16(supp);
208 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
209 cmd->ht_rates[i][IWL_TLC_HT_BW_160] =
210 cmd->ht_rates[i][IWL_TLC_HT_BW_NONE_160];
211 }
212}
213
214static u16 rs_fw_he_ieee80211_mcs_to_rs_mcs(u16 mcs)
215{
216 switch (mcs) {
217 case IEEE80211_HE_MCS_SUPPORT_0_7:
218 return BIT(IWL_TLC_MNG_HT_RATE_MCS7 + 1) - 1;
219 case IEEE80211_HE_MCS_SUPPORT_0_9:
220 return BIT(IWL_TLC_MNG_HT_RATE_MCS9 + 1) - 1;
221 case IEEE80211_HE_MCS_SUPPORT_0_11:
222 return BIT(IWL_TLC_MNG_HT_RATE_MCS11 + 1) - 1;
223 case IEEE80211_HE_MCS_NOT_SUPPORTED:
224 return 0;
225 }
226
227 WARN(1, "invalid HE MCS %d\n", mcs);
228 return 0;
229}
230
231static void
232rs_fw_he_set_enabled_rates(const struct ieee80211_sta *sta,
233 struct ieee80211_supported_band *sband,
234 struct iwl_tlc_config_cmd *cmd)
235{
236 const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
237 u16 mcs_160 = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
238 u16 mcs_80 = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
239 u16 tx_mcs_80 =
240 le16_to_cpu(sband->iftype_data->he_cap.he_mcs_nss_supp.tx_mcs_80);
241 u16 tx_mcs_160 =
242 le16_to_cpu(sband->iftype_data->he_cap.he_mcs_nss_supp.tx_mcs_160);
243 int i;
244
245 for (i = 0; i < sta->rx_nss && i < IWL_TLC_NSS_MAX; i++) {
246 u16 _mcs_160 = (mcs_160 >> (2 * i)) & 0x3;
247 u16 _mcs_80 = (mcs_80 >> (2 * i)) & 0x3;
248 u16 _tx_mcs_160 = (tx_mcs_160 >> (2 * i)) & 0x3;
249 u16 _tx_mcs_80 = (tx_mcs_80 >> (2 * i)) & 0x3;
250
251
252 if (_mcs_80 == IEEE80211_HE_MCS_NOT_SUPPORTED ||
253 _tx_mcs_80 == IEEE80211_HE_MCS_NOT_SUPPORTED) {
254 _mcs_80 = IEEE80211_HE_MCS_NOT_SUPPORTED;
255 _tx_mcs_80 = IEEE80211_HE_MCS_NOT_SUPPORTED;
256 }
257 if (_mcs_80 > _tx_mcs_80)
258 _mcs_80 = _tx_mcs_80;
259 cmd->ht_rates[i][IWL_TLC_HT_BW_NONE_160] =
260 cpu_to_le16(rs_fw_he_ieee80211_mcs_to_rs_mcs(_mcs_80));
261
262
263 if (_mcs_160 == IEEE80211_HE_MCS_NOT_SUPPORTED ||
264 _tx_mcs_160 == IEEE80211_HE_MCS_NOT_SUPPORTED) {
265 _mcs_160 = IEEE80211_HE_MCS_NOT_SUPPORTED;
266 _tx_mcs_160 = IEEE80211_HE_MCS_NOT_SUPPORTED;
267 }
268 if (_mcs_160 > _tx_mcs_160)
269 _mcs_160 = _tx_mcs_160;
270 cmd->ht_rates[i][IWL_TLC_HT_BW_160] =
271 cpu_to_le16(rs_fw_he_ieee80211_mcs_to_rs_mcs(_mcs_160));
272 }
273}
274
275static void rs_fw_set_supp_rates(struct ieee80211_sta *sta,
276 struct ieee80211_supported_band *sband,
277 struct iwl_tlc_config_cmd *cmd)
278{
279 int i;
280 unsigned long tmp;
281 unsigned long supp;
282 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
283 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
284 const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
285
286
287 supp = 0;
288 tmp = sta->supp_rates[sband->band];
289 for_each_set_bit(i, &tmp, BITS_PER_LONG)
290 supp |= BIT(sband->bitrates[i].hw_value);
291
292 cmd->non_ht_rates = cpu_to_le16(supp);
293 cmd->mode = IWL_TLC_MNG_MODE_NON_HT;
294
295
296 if (he_cap->has_he) {
297 cmd->mode = IWL_TLC_MNG_MODE_HE;
298 rs_fw_he_set_enabled_rates(sta, sband, cmd);
299 } else if (vht_cap->vht_supported) {
300 cmd->mode = IWL_TLC_MNG_MODE_VHT;
301 rs_fw_vht_set_enabled_rates(sta, vht_cap, cmd);
302 } else if (ht_cap->ht_supported) {
303 cmd->mode = IWL_TLC_MNG_MODE_HT;
304 cmd->ht_rates[IWL_TLC_NSS_1][IWL_TLC_HT_BW_NONE_160] =
305 cpu_to_le16(ht_cap->mcs.rx_mask[0]);
306 cmd->ht_rates[IWL_TLC_NSS_2][IWL_TLC_HT_BW_NONE_160] =
307 cpu_to_le16(ht_cap->mcs.rx_mask[1]);
308 }
309}
310
311void iwl_mvm_tlc_update_notif(struct iwl_mvm *mvm,
312 struct iwl_rx_cmd_buffer *rxb)
313{
314 struct iwl_rx_packet *pkt = rxb_addr(rxb);
315 struct iwl_tlc_update_notif *notif;
316 struct ieee80211_sta *sta;
317 struct iwl_mvm_sta *mvmsta;
318 struct iwl_lq_sta_rs_fw *lq_sta;
319 u32 flags;
320
321 rcu_read_lock();
322
323 notif = (void *)pkt->data;
324 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
325 if (IS_ERR_OR_NULL(sta)) {
326 IWL_ERR(mvm, "Invalid sta id (%d) in FW TLC notification\n",
327 notif->sta_id);
328 goto out;
329 }
330
331 mvmsta = iwl_mvm_sta_from_mac80211(sta);
332
333 if (!mvmsta) {
334 IWL_ERR(mvm, "Invalid sta id (%d) in FW TLC notification\n",
335 notif->sta_id);
336 goto out;
337 }
338
339 flags = le32_to_cpu(notif->flags);
340
341 lq_sta = &mvmsta->lq_sta.rs_fw;
342
343 if (flags & IWL_TLC_NOTIF_FLAG_RATE) {
344 lq_sta->last_rate_n_flags = le32_to_cpu(notif->rate);
345 IWL_DEBUG_RATE(mvm, "new rate_n_flags: 0x%X\n",
346 lq_sta->last_rate_n_flags);
347 }
348
349 if (flags & IWL_TLC_NOTIF_FLAG_AMSDU && !mvmsta->orig_amsdu_len) {
350 u16 size = le32_to_cpu(notif->amsdu_size);
351 int i;
352
353 if (WARN_ON(sta->max_amsdu_len < size))
354 goto out;
355
356 mvmsta->amsdu_enabled = le32_to_cpu(notif->amsdu_enabled);
357 mvmsta->max_amsdu_len = size;
358 sta->max_rc_amsdu_len = mvmsta->max_amsdu_len;
359
360 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
361 if (mvmsta->amsdu_enabled & BIT(i))
362 sta->max_tid_amsdu_len[i] =
363 iwl_mvm_max_amsdu_size(mvm, sta, i);
364 else
365
366
367
368
369 sta->max_tid_amsdu_len[i] = 1;
370 }
371
372 IWL_DEBUG_RATE(mvm,
373 "AMSDU update. AMSDU size: %d, AMSDU selected size: %d, AMSDU TID bitmap 0x%X\n",
374 le32_to_cpu(notif->amsdu_size), size,
375 mvmsta->amsdu_enabled);
376 }
377out:
378 rcu_read_unlock();
379}
380
381static u16 rs_fw_get_max_amsdu_len(struct ieee80211_sta *sta)
382{
383 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
384 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
385
386 if (vht_cap->vht_supported) {
387 switch (vht_cap->cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK) {
388 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
389 return IEEE80211_MAX_MPDU_LEN_VHT_11454;
390 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
391 return IEEE80211_MAX_MPDU_LEN_VHT_7991;
392 default:
393 return IEEE80211_MAX_MPDU_LEN_VHT_3895;
394 }
395
396 } else if (ht_cap->ht_supported) {
397 if (ht_cap->cap & IEEE80211_HT_CAP_MAX_AMSDU)
398
399
400
401
402
403 return IEEE80211_MAX_MPDU_LEN_HT_BA;
404 else
405 return IEEE80211_MAX_MPDU_LEN_HT_3839;
406 }
407
408
409 return 0;
410}
411
412void rs_fw_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
413 enum nl80211_band band, bool update)
414{
415 struct ieee80211_hw *hw = mvm->hw;
416 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
417 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
418 u32 cmd_id = iwl_cmd_id(TLC_MNG_CONFIG_CMD, DATA_PATH_GROUP, 0);
419 struct ieee80211_supported_band *sband = hw->wiphy->bands[band];
420 u16 max_amsdu_len = rs_fw_get_max_amsdu_len(sta);
421 struct iwl_tlc_config_cmd cfg_cmd = {
422 .sta_id = mvmsta->sta_id,
423 .max_ch_width = update ?
424 rs_fw_bw_from_sta_bw(sta) : RATE_MCS_CHAN_WIDTH_20,
425 .flags = cpu_to_le16(rs_fw_get_config_flags(mvm, sta, sband)),
426 .chains = rs_fw_set_active_chains(iwl_mvm_get_valid_tx_ant(mvm)),
427 .sgi_ch_width_supp = rs_fw_sgi_cw_support(sta),
428 .max_mpdu_len = cpu_to_le16(max_amsdu_len),
429 .amsdu = iwl_mvm_is_csum_supported(mvm),
430 };
431 int ret;
432
433 memset(lq_sta, 0, offsetof(typeof(*lq_sta), pers));
434
435#ifdef CONFIG_IWLWIFI_DEBUGFS
436 iwl_mvm_reset_frame_stats(mvm);
437#endif
438 rs_fw_set_supp_rates(sta, sband, &cfg_cmd);
439
440
441
442
443
444 sta->max_amsdu_len = max_amsdu_len;
445
446 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, CMD_ASYNC, sizeof(cfg_cmd),
447 &cfg_cmd);
448 if (ret)
449 IWL_ERR(mvm, "Failed to send rate scale config (%d)\n", ret);
450}
451
452int rs_fw_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
453 bool enable)
454{
455
456 IWL_DEBUG_RATE(mvm, "tx protection - not implemented yet.\n");
457 return 0;
458}
459
460void iwl_mvm_rs_add_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta)
461{
462 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
463
464 IWL_DEBUG_RATE(mvm, "create station rate scale window\n");
465
466 lq_sta->pers.drv = mvm;
467 lq_sta->pers.sta_id = mvmsta->sta_id;
468 lq_sta->pers.chains = 0;
469 memset(lq_sta->pers.chain_signal, 0, sizeof(lq_sta->pers.chain_signal));
470 lq_sta->pers.last_rssi = S8_MIN;
471 lq_sta->last_rate_n_flags = 0;
472
473#ifdef CONFIG_MAC80211_DEBUGFS
474 lq_sta->pers.dbg_fixed_rate = 0;
475#endif
476}
477