1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2017 Intel Deutschland GmbH
9 * Copyright(c) 2018 Intel Corporation
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * The full GNU General Public License is included in this distribution
21 * in the file called COPYING.
23 * Contact Information:
24 * Intel Linux Wireless <linuxwifi@intel.com>
25 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
29 * Copyright(c) 2017 Intel Deutschland GmbH
30 * Copyright(c) 2018 Intel Corporation
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * * Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in
41 * the documentation and/or other materials provided with the
43 * * Neither the name Intel Corporation nor the names of its
44 * contributors may be used to endorse or promote products derived
45 * from this software without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
51 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *****************************************************************************/
63 #include "iwl-op-mode.h"
66 static u8 rs_fw_bw_from_sta_bw(struct ieee80211_sta *sta)
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:
77 return IWL_TLC_MNG_CH_WIDTH_20MHZ;
81 static u8 rs_fw_set_active_chains(u8 chains)
86 fw_chains |= IWL_TLC_MNG_CHAIN_A_MSK;
88 fw_chains |= IWL_TLC_MNG_CHAIN_B_MSK;
91 "tlc offload doesn't support antenna C. chains: 0x%x\n",
97 static u8 rs_fw_sgi_cw_support(struct ieee80211_sta *sta)
99 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
100 struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
103 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
104 supp |= BIT(IWL_TLC_MNG_CH_WIDTH_20MHZ);
105 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
106 supp |= BIT(IWL_TLC_MNG_CH_WIDTH_40MHZ);
107 if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_80)
108 supp |= BIT(IWL_TLC_MNG_CH_WIDTH_80MHZ);
109 if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_160)
110 supp |= BIT(IWL_TLC_MNG_CH_WIDTH_160MHZ);
115 static u16 rs_fw_set_config_flags(struct iwl_mvm *mvm,
116 struct ieee80211_sta *sta)
118 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
119 struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
120 struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
121 bool vht_ena = vht_cap && vht_cap->vht_supported;
124 if (mvm->cfg->ht_params->stbc &&
125 (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) > 1)) {
126 if (he_cap && he_cap->has_he) {
127 if (he_cap->he_cap_elem.phy_cap_info[2] &
128 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ)
129 flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK;
131 if (he_cap->he_cap_elem.phy_cap_info[7] &
132 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ)
133 flags |= IWL_TLC_MNG_CFG_FLAGS_HE_STBC_160MHZ_MSK;
134 } else if ((ht_cap &&
135 (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC)) ||
137 (vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK)))
138 flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK;
141 if (mvm->cfg->ht_params->ldpc &&
142 ((ht_cap && (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)) ||
143 (vht_ena && (vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC))))
144 flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK;
146 if (he_cap && he_cap->has_he &&
147 (he_cap->he_cap_elem.phy_cap_info[3] &
148 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK)) {
149 flags |= IWL_TLC_MNG_CFG_FLAGS_HE_DCM_NSS_1_MSK;
151 if (he_cap->he_cap_elem.phy_cap_info[3] &
152 IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_2)
153 flags |= IWL_TLC_MNG_CFG_FLAGS_HE_DCM_NSS_2_MSK;
160 int rs_fw_vht_highest_rx_mcs_index(const struct ieee80211_sta_vht_cap *vht_cap,
163 u16 rx_mcs = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) &
164 (0x3 << (2 * (nss - 1)));
165 rx_mcs >>= (2 * (nss - 1));
168 case IEEE80211_VHT_MCS_SUPPORT_0_7:
169 return IWL_TLC_MNG_HT_RATE_MCS7;
170 case IEEE80211_VHT_MCS_SUPPORT_0_8:
171 return IWL_TLC_MNG_HT_RATE_MCS8;
172 case IEEE80211_VHT_MCS_SUPPORT_0_9:
173 return IWL_TLC_MNG_HT_RATE_MCS9;
183 rs_fw_vht_set_enabled_rates(const struct ieee80211_sta *sta,
184 const struct ieee80211_sta_vht_cap *vht_cap,
185 struct iwl_tlc_config_cmd *cmd)
190 for (i = 0; i < sta->rx_nss; i++) {
194 highest_mcs = rs_fw_vht_highest_rx_mcs_index(vht_cap, i + 1);
198 supp = BIT(highest_mcs + 1) - 1;
199 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
200 supp &= ~BIT(IWL_TLC_MNG_HT_RATE_MCS9);
202 cmd->ht_rates[i][0] = cpu_to_le16(supp);
203 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
204 cmd->ht_rates[i][1] = cmd->ht_rates[i][0];
208 static u16 rs_fw_he_ieee80211_mcs_to_rs_mcs(u16 mcs)
211 case IEEE80211_HE_MCS_SUPPORT_0_7:
212 return BIT(IWL_TLC_MNG_HT_RATE_MCS7 + 1) - 1;
213 case IEEE80211_HE_MCS_SUPPORT_0_9:
214 return BIT(IWL_TLC_MNG_HT_RATE_MCS9 + 1) - 1;
215 case IEEE80211_HE_MCS_SUPPORT_0_11:
216 return BIT(IWL_TLC_MNG_HT_RATE_MCS11 + 1) - 1;
217 case IEEE80211_HE_MCS_NOT_SUPPORTED:
221 WARN(1, "invalid HE MCS %d\n", mcs);
226 rs_fw_he_set_enabled_rates(const struct ieee80211_sta *sta,
227 const struct ieee80211_sta_he_cap *he_cap,
228 struct iwl_tlc_config_cmd *cmd)
230 u16 mcs_160 = le16_to_cpu(sta->he_cap.he_mcs_nss_supp.rx_mcs_160);
231 u16 mcs_80 = le16_to_cpu(sta->he_cap.he_mcs_nss_supp.rx_mcs_80);
234 for (i = 0; i < sta->rx_nss && i < MAX_NSS; i++) {
235 u16 _mcs_160 = (mcs_160 >> (2 * i)) & 0x3;
236 u16 _mcs_80 = (mcs_80 >> (2 * i)) & 0x3;
238 cmd->ht_rates[i][0] =
239 cpu_to_le16(rs_fw_he_ieee80211_mcs_to_rs_mcs(_mcs_80));
240 cmd->ht_rates[i][1] =
241 cpu_to_le16(rs_fw_he_ieee80211_mcs_to_rs_mcs(_mcs_160));
245 static void rs_fw_set_supp_rates(struct ieee80211_sta *sta,
246 struct ieee80211_supported_band *sband,
247 struct iwl_tlc_config_cmd *cmd)
251 unsigned long supp; /* must be unsigned long for for_each_set_bit */
252 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
253 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
254 const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
258 tmp = sta->supp_rates[sband->band];
259 for_each_set_bit(i, &tmp, BITS_PER_LONG)
260 supp |= BIT(sband->bitrates[i].hw_value);
262 cmd->non_ht_rates = cpu_to_le16(supp);
263 cmd->mode = IWL_TLC_MNG_MODE_NON_HT;
266 if (he_cap && he_cap->has_he) {
267 cmd->mode = IWL_TLC_MNG_MODE_HE;
268 rs_fw_he_set_enabled_rates(sta, he_cap, cmd);
269 } else if (vht_cap && vht_cap->vht_supported) {
270 cmd->mode = IWL_TLC_MNG_MODE_VHT;
271 rs_fw_vht_set_enabled_rates(sta, vht_cap, cmd);
272 } else if (ht_cap && ht_cap->ht_supported) {
273 cmd->mode = IWL_TLC_MNG_MODE_HT;
274 cmd->ht_rates[0][0] = cpu_to_le16(ht_cap->mcs.rx_mask[0]);
275 cmd->ht_rates[1][0] = cpu_to_le16(ht_cap->mcs.rx_mask[1]);
279 void iwl_mvm_tlc_update_notif(struct iwl_mvm *mvm,
280 struct iwl_rx_cmd_buffer *rxb)
282 struct iwl_rx_packet *pkt = rxb_addr(rxb);
283 struct iwl_tlc_update_notif *notif;
284 struct ieee80211_sta *sta;
285 struct iwl_mvm_sta *mvmsta;
286 struct iwl_lq_sta_rs_fw *lq_sta;
291 notif = (void *)pkt->data;
292 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
293 if (IS_ERR_OR_NULL(sta)) {
294 IWL_ERR(mvm, "Invalid sta id (%d) in FW TLC notification\n",
299 mvmsta = iwl_mvm_sta_from_mac80211(sta);
302 IWL_ERR(mvm, "Invalid sta id (%d) in FW TLC notification\n",
307 flags = le32_to_cpu(notif->flags);
309 lq_sta = &mvmsta->lq_sta.rs_fw;
311 if (flags & IWL_TLC_NOTIF_FLAG_RATE) {
312 lq_sta->last_rate_n_flags = le32_to_cpu(notif->rate);
313 IWL_DEBUG_RATE(mvm, "new rate_n_flags: 0x%X\n",
314 lq_sta->last_rate_n_flags);
317 if (flags & IWL_TLC_NOTIF_FLAG_AMSDU) {
318 u16 size = le32_to_cpu(notif->amsdu_size);
320 if (WARN_ON(sta->max_amsdu_len < size))
323 mvmsta->amsdu_enabled = le32_to_cpu(notif->amsdu_enabled);
324 mvmsta->max_amsdu_len = size;
327 "AMSDU update. AMSDU size: %d, AMSDU selected size: %d, AMSDU TID bitmap 0x%X\n",
328 le32_to_cpu(notif->amsdu_size), size,
329 mvmsta->amsdu_enabled);
335 void rs_fw_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
336 enum nl80211_band band, bool update)
338 struct ieee80211_hw *hw = mvm->hw;
339 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
340 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
341 u32 cmd_id = iwl_cmd_id(TLC_MNG_CONFIG_CMD, DATA_PATH_GROUP, 0);
342 struct ieee80211_supported_band *sband;
343 struct iwl_tlc_config_cmd cfg_cmd = {
344 .sta_id = mvmsta->sta_id,
345 .max_ch_width = update ?
346 rs_fw_bw_from_sta_bw(sta) : RATE_MCS_CHAN_WIDTH_20,
347 .flags = cpu_to_le16(rs_fw_set_config_flags(mvm, sta)),
348 .chains = rs_fw_set_active_chains(iwl_mvm_get_valid_tx_ant(mvm)),
349 .max_mpdu_len = cpu_to_le16(sta->max_amsdu_len),
350 .sgi_ch_width_supp = rs_fw_sgi_cw_support(sta),
351 .amsdu = iwl_mvm_is_csum_supported(mvm),
355 memset(lq_sta, 0, offsetof(typeof(*lq_sta), pers));
357 #ifdef CONFIG_IWLWIFI_DEBUGFS
358 iwl_mvm_reset_frame_stats(mvm);
360 sband = hw->wiphy->bands[band];
361 rs_fw_set_supp_rates(sta, sband, &cfg_cmd);
363 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(cfg_cmd), &cfg_cmd);
365 IWL_ERR(mvm, "Failed to send rate scale config (%d)\n", ret);
368 int rs_fw_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
371 /* TODO: need to introduce a new FW cmd since LQ cmd is not relevant */
372 IWL_DEBUG_RATE(mvm, "tx protection - not implemented yet.\n");
376 void iwl_mvm_rs_add_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta)
378 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
380 IWL_DEBUG_RATE(mvm, "create station rate scale window\n");
382 lq_sta->pers.drv = mvm;
383 lq_sta->pers.sta_id = mvmsta->sta_id;
384 lq_sta->pers.chains = 0;
385 memset(lq_sta->pers.chain_signal, 0, sizeof(lq_sta->pers.chain_signal));
386 lq_sta->pers.last_rssi = S8_MIN;
387 lq_sta->last_rate_n_flags = 0;
389 #ifdef CONFIG_MAC80211_DEBUGFS
390 lq_sta->pers.dbg_fixed_rate = 0;