rs-fw.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /******************************************************************************
  2. *
  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.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2017 Intel Deutschland GmbH
  9. * Copyright(c) 2018 Intel Corporation
  10. *
  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.
  14. *
  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.
  19. *
  20. * The full GNU General Public License is included in this distribution
  21. * in the file called COPYING.
  22. *
  23. * Contact Information:
  24. * Intel Linux Wireless <linuxwifi@intel.com>
  25. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  26. *
  27. * BSD LICENSE
  28. *
  29. * Copyright(c) 2017 Intel Deutschland GmbH
  30. * Copyright(c) 2018 Intel Corporation
  31. * All rights reserved.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted provided that the following conditions
  35. * are met:
  36. *
  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
  42. * distribution.
  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.
  46. *
  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.
  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. static u8 rs_fw_bw_from_sta_bw(struct ieee80211_sta *sta)
  66. {
  67. switch (sta->bandwidth) {
  68. case IEEE80211_STA_RX_BW_160:
  69. return IWL_TLC_MNG_CH_WIDTH_160MHZ;
  70. case IEEE80211_STA_RX_BW_80:
  71. return IWL_TLC_MNG_CH_WIDTH_80MHZ;
  72. case IEEE80211_STA_RX_BW_40:
  73. return IWL_TLC_MNG_CH_WIDTH_40MHZ;
  74. case IEEE80211_STA_RX_BW_20:
  75. default:
  76. return IWL_TLC_MNG_CH_WIDTH_20MHZ;
  77. }
  78. }
  79. static u8 rs_fw_set_active_chains(u8 chains)
  80. {
  81. u8 fw_chains = 0;
  82. if (chains & ANT_A)
  83. fw_chains |= IWL_TLC_MNG_CHAIN_A_MSK;
  84. if (chains & ANT_B)
  85. fw_chains |= IWL_TLC_MNG_CHAIN_B_MSK;
  86. if (chains & ANT_C)
  87. WARN(false,
  88. "tlc offload doesn't support antenna C. chains: 0x%x\n",
  89. chains);
  90. return fw_chains;
  91. }
  92. static u8 rs_fw_sgi_cw_support(struct ieee80211_sta *sta)
  93. {
  94. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  95. struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  96. struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
  97. u8 supp = 0;
  98. if (he_cap && he_cap->has_he)
  99. return 0;
  100. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
  101. supp |= BIT(IWL_TLC_MNG_CH_WIDTH_20MHZ);
  102. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
  103. supp |= BIT(IWL_TLC_MNG_CH_WIDTH_40MHZ);
  104. if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_80)
  105. supp |= BIT(IWL_TLC_MNG_CH_WIDTH_80MHZ);
  106. if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_160)
  107. supp |= BIT(IWL_TLC_MNG_CH_WIDTH_160MHZ);
  108. return supp;
  109. }
  110. static u16 rs_fw_set_config_flags(struct iwl_mvm *mvm,
  111. struct ieee80211_sta *sta)
  112. {
  113. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  114. struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  115. bool vht_ena = vht_cap && vht_cap->vht_supported;
  116. u16 flags = 0;
  117. if (mvm->cfg->ht_params->stbc &&
  118. (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) > 1) &&
  119. ((ht_cap && (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC)) ||
  120. (vht_ena && (vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK))))
  121. flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK;
  122. if (mvm->cfg->ht_params->ldpc &&
  123. ((ht_cap && (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)) ||
  124. (vht_ena && (vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC))))
  125. flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK;
  126. return flags;
  127. }
  128. static
  129. int rs_fw_vht_highest_rx_mcs_index(const struct ieee80211_sta_vht_cap *vht_cap,
  130. int nss)
  131. {
  132. u16 rx_mcs = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) &
  133. (0x3 << (2 * (nss - 1)));
  134. rx_mcs >>= (2 * (nss - 1));
  135. switch (rx_mcs) {
  136. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  137. return IWL_TLC_MNG_HT_RATE_MCS7;
  138. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  139. return IWL_TLC_MNG_HT_RATE_MCS8;
  140. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  141. return IWL_TLC_MNG_HT_RATE_MCS9;
  142. default:
  143. WARN_ON_ONCE(1);
  144. break;
  145. }
  146. return 0;
  147. }
  148. static void
  149. rs_fw_vht_set_enabled_rates(const struct ieee80211_sta *sta,
  150. const struct ieee80211_sta_vht_cap *vht_cap,
  151. struct iwl_tlc_config_cmd *cmd)
  152. {
  153. u16 supp;
  154. int i, highest_mcs;
  155. for (i = 0; i < sta->rx_nss; i++) {
  156. if (i == MAX_NSS)
  157. break;
  158. highest_mcs = rs_fw_vht_highest_rx_mcs_index(vht_cap, i + 1);
  159. if (!highest_mcs)
  160. continue;
  161. supp = BIT(highest_mcs + 1) - 1;
  162. if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
  163. supp &= ~BIT(IWL_TLC_MNG_HT_RATE_MCS9);
  164. cmd->ht_rates[i][0] = cpu_to_le16(supp);
  165. if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
  166. cmd->ht_rates[i][1] = cmd->ht_rates[i][0];
  167. }
  168. }
  169. static u16 rs_fw_he_ieee80211_mcs_to_rs_mcs(u16 mcs)
  170. {
  171. switch (mcs) {
  172. case IEEE80211_HE_MCS_SUPPORT_0_7:
  173. return BIT(IWL_TLC_MNG_HT_RATE_MCS7 + 1) - 1;
  174. case IEEE80211_HE_MCS_SUPPORT_0_9:
  175. return BIT(IWL_TLC_MNG_HT_RATE_MCS9 + 1) - 1;
  176. case IEEE80211_HE_MCS_SUPPORT_0_11:
  177. return BIT(IWL_TLC_MNG_HT_RATE_MCS11 + 1) - 1;
  178. case IEEE80211_HE_MCS_NOT_SUPPORTED:
  179. return 0;
  180. }
  181. WARN(1, "invalid HE MCS %d\n", mcs);
  182. return 0;
  183. }
  184. static void
  185. rs_fw_he_set_enabled_rates(const struct ieee80211_sta *sta,
  186. const struct ieee80211_sta_he_cap *he_cap,
  187. struct iwl_tlc_config_cmd *cmd)
  188. {
  189. u16 mcs_160 = le16_to_cpu(sta->he_cap.he_mcs_nss_supp.rx_mcs_160);
  190. u16 mcs_80 = le16_to_cpu(sta->he_cap.he_mcs_nss_supp.rx_mcs_80);
  191. int i;
  192. for (i = 0; i < sta->rx_nss && i < MAX_NSS; i++) {
  193. u16 _mcs_160 = (mcs_160 >> (2 * i)) & 0x3;
  194. u16 _mcs_80 = (mcs_80 >> (2 * i)) & 0x3;
  195. cmd->ht_rates[i][0] =
  196. cpu_to_le16(rs_fw_he_ieee80211_mcs_to_rs_mcs(_mcs_80));
  197. cmd->ht_rates[i][1] =
  198. cpu_to_le16(rs_fw_he_ieee80211_mcs_to_rs_mcs(_mcs_160));
  199. }
  200. }
  201. static void rs_fw_set_supp_rates(struct ieee80211_sta *sta,
  202. struct ieee80211_supported_band *sband,
  203. struct iwl_tlc_config_cmd *cmd)
  204. {
  205. int i;
  206. unsigned long tmp;
  207. unsigned long supp; /* must be unsigned long for for_each_set_bit */
  208. const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  209. const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  210. const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
  211. /* non HT rates */
  212. supp = 0;
  213. tmp = sta->supp_rates[sband->band];
  214. for_each_set_bit(i, &tmp, BITS_PER_LONG)
  215. supp |= BIT(sband->bitrates[i].hw_value);
  216. cmd->non_ht_rates = cpu_to_le16(supp);
  217. cmd->mode = IWL_TLC_MNG_MODE_NON_HT;
  218. /* HT/VHT rates */
  219. if (he_cap && he_cap->has_he) {
  220. cmd->mode = IWL_TLC_MNG_MODE_HE;
  221. rs_fw_he_set_enabled_rates(sta, he_cap, cmd);
  222. } else if (vht_cap && vht_cap->vht_supported) {
  223. cmd->mode = IWL_TLC_MNG_MODE_VHT;
  224. rs_fw_vht_set_enabled_rates(sta, vht_cap, cmd);
  225. } else if (ht_cap && ht_cap->ht_supported) {
  226. cmd->mode = IWL_TLC_MNG_MODE_HT;
  227. cmd->ht_rates[0][0] = cpu_to_le16(ht_cap->mcs.rx_mask[0]);
  228. cmd->ht_rates[1][0] = cpu_to_le16(ht_cap->mcs.rx_mask[1]);
  229. }
  230. }
  231. void iwl_mvm_tlc_update_notif(struct iwl_mvm *mvm,
  232. struct iwl_rx_cmd_buffer *rxb)
  233. {
  234. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  235. struct iwl_tlc_update_notif *notif;
  236. struct ieee80211_sta *sta;
  237. struct iwl_mvm_sta *mvmsta;
  238. struct iwl_lq_sta_rs_fw *lq_sta;
  239. u32 flags;
  240. rcu_read_lock();
  241. notif = (void *)pkt->data;
  242. sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
  243. if (IS_ERR_OR_NULL(sta)) {
  244. IWL_ERR(mvm, "Invalid sta id (%d) in FW TLC notification\n",
  245. notif->sta_id);
  246. goto out;
  247. }
  248. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  249. if (!mvmsta) {
  250. IWL_ERR(mvm, "Invalid sta id (%d) in FW TLC notification\n",
  251. notif->sta_id);
  252. goto out;
  253. }
  254. flags = le32_to_cpu(notif->flags);
  255. lq_sta = &mvmsta->lq_sta.rs_fw;
  256. if (flags & IWL_TLC_NOTIF_FLAG_RATE) {
  257. lq_sta->last_rate_n_flags = le32_to_cpu(notif->rate);
  258. IWL_DEBUG_RATE(mvm, "new rate_n_flags: 0x%X\n",
  259. lq_sta->last_rate_n_flags);
  260. }
  261. if (flags & IWL_TLC_NOTIF_FLAG_AMSDU) {
  262. u16 size = le32_to_cpu(notif->amsdu_size);
  263. if (WARN_ON(sta->max_amsdu_len < size))
  264. goto out;
  265. mvmsta->amsdu_enabled = le32_to_cpu(notif->amsdu_enabled);
  266. mvmsta->max_amsdu_len = size;
  267. IWL_DEBUG_RATE(mvm,
  268. "AMSDU update. AMSDU size: %d, AMSDU selected size: %d, AMSDU TID bitmap 0x%X\n",
  269. le32_to_cpu(notif->amsdu_size), size,
  270. mvmsta->amsdu_enabled);
  271. }
  272. out:
  273. rcu_read_unlock();
  274. }
  275. void rs_fw_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
  276. enum nl80211_band band, bool update)
  277. {
  278. struct ieee80211_hw *hw = mvm->hw;
  279. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  280. struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
  281. u32 cmd_id = iwl_cmd_id(TLC_MNG_CONFIG_CMD, DATA_PATH_GROUP, 0);
  282. struct ieee80211_supported_band *sband;
  283. struct iwl_tlc_config_cmd cfg_cmd = {
  284. .sta_id = mvmsta->sta_id,
  285. .max_ch_width = update ?
  286. rs_fw_bw_from_sta_bw(sta) : RATE_MCS_CHAN_WIDTH_20,
  287. .flags = cpu_to_le16(rs_fw_set_config_flags(mvm, sta)),
  288. .chains = rs_fw_set_active_chains(iwl_mvm_get_valid_tx_ant(mvm)),
  289. .max_mpdu_len = cpu_to_le16(sta->max_amsdu_len),
  290. .sgi_ch_width_supp = rs_fw_sgi_cw_support(sta),
  291. .amsdu = iwl_mvm_is_csum_supported(mvm),
  292. };
  293. int ret;
  294. memset(lq_sta, 0, offsetof(typeof(*lq_sta), pers));
  295. #ifdef CONFIG_IWLWIFI_DEBUGFS
  296. iwl_mvm_reset_frame_stats(mvm);
  297. #endif
  298. sband = hw->wiphy->bands[band];
  299. rs_fw_set_supp_rates(sta, sband, &cfg_cmd);
  300. ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(cfg_cmd), &cfg_cmd);
  301. if (ret)
  302. IWL_ERR(mvm, "Failed to send rate scale config (%d)\n", ret);
  303. }
  304. int rs_fw_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
  305. bool enable)
  306. {
  307. /* TODO: need to introduce a new FW cmd since LQ cmd is not relevant */
  308. IWL_DEBUG_RATE(mvm, "tx protection - not implemented yet.\n");
  309. return 0;
  310. }
  311. void iwl_mvm_rs_add_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta)
  312. {
  313. struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
  314. IWL_DEBUG_RATE(mvm, "create station rate scale window\n");
  315. lq_sta->pers.drv = mvm;
  316. lq_sta->pers.sta_id = mvmsta->sta_id;
  317. lq_sta->pers.chains = 0;
  318. memset(lq_sta->pers.chain_signal, 0, sizeof(lq_sta->pers.chain_signal));
  319. lq_sta->pers.last_rssi = S8_MIN;
  320. lq_sta->last_rate_n_flags = 0;
  321. #ifdef CONFIG_MAC80211_DEBUGFS
  322. lq_sta->pers.dbg_fixed_rate = 0;
  323. #endif
  324. }