rs-fw.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. u8 supp = 0;
  97. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
  98. supp |= BIT(IWL_TLC_MNG_CH_WIDTH_20MHZ);
  99. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
  100. supp |= BIT(IWL_TLC_MNG_CH_WIDTH_40MHZ);
  101. if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_80)
  102. supp |= BIT(IWL_TLC_MNG_CH_WIDTH_80MHZ);
  103. if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_160)
  104. supp |= BIT(IWL_TLC_MNG_CH_WIDTH_160MHZ);
  105. return supp;
  106. }
  107. static u16 rs_fw_set_config_flags(struct iwl_mvm *mvm,
  108. struct ieee80211_sta *sta)
  109. {
  110. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  111. struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  112. bool vht_ena = vht_cap && vht_cap->vht_supported;
  113. u16 flags = 0;
  114. if (mvm->cfg->ht_params->stbc &&
  115. (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) > 1) &&
  116. ((ht_cap && (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC)) ||
  117. (vht_ena && (vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK))))
  118. flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK;
  119. if (mvm->cfg->ht_params->ldpc &&
  120. ((ht_cap && (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)) ||
  121. (vht_ena && (vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC))))
  122. flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK;
  123. return flags;
  124. }
  125. static
  126. int rs_fw_vht_highest_rx_mcs_index(const struct ieee80211_sta_vht_cap *vht_cap,
  127. int nss)
  128. {
  129. u16 rx_mcs = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) &
  130. (0x3 << (2 * (nss - 1)));
  131. rx_mcs >>= (2 * (nss - 1));
  132. switch (rx_mcs) {
  133. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  134. return IWL_TLC_MNG_HT_RATE_MCS7;
  135. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  136. return IWL_TLC_MNG_HT_RATE_MCS8;
  137. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  138. return IWL_TLC_MNG_HT_RATE_MCS9;
  139. default:
  140. WARN_ON_ONCE(1);
  141. break;
  142. }
  143. return 0;
  144. }
  145. static void
  146. rs_fw_vht_set_enabled_rates(const struct ieee80211_sta *sta,
  147. const struct ieee80211_sta_vht_cap *vht_cap,
  148. struct iwl_tlc_config_cmd *cmd)
  149. {
  150. u16 supp;
  151. int i, highest_mcs;
  152. for (i = 0; i < sta->rx_nss; i++) {
  153. if (i == MAX_NSS)
  154. break;
  155. highest_mcs = rs_fw_vht_highest_rx_mcs_index(vht_cap, i + 1);
  156. if (!highest_mcs)
  157. continue;
  158. supp = BIT(highest_mcs + 1) - 1;
  159. if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
  160. supp &= ~BIT(IWL_TLC_MNG_HT_RATE_MCS9);
  161. cmd->ht_rates[i][0] = cpu_to_le16(supp);
  162. if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
  163. cmd->ht_rates[i][1] = cmd->ht_rates[i][0];
  164. }
  165. }
  166. static void rs_fw_set_supp_rates(struct ieee80211_sta *sta,
  167. struct ieee80211_supported_band *sband,
  168. struct iwl_tlc_config_cmd *cmd)
  169. {
  170. int i;
  171. unsigned long tmp;
  172. unsigned long supp; /* must be unsigned long for for_each_set_bit */
  173. const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  174. const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  175. /* non HT rates */
  176. supp = 0;
  177. tmp = sta->supp_rates[sband->band];
  178. for_each_set_bit(i, &tmp, BITS_PER_LONG)
  179. supp |= BIT(sband->bitrates[i].hw_value);
  180. cmd->non_ht_rates = cpu_to_le16(supp);
  181. cmd->mode = IWL_TLC_MNG_MODE_NON_HT;
  182. if (vht_cap && vht_cap->vht_supported) {
  183. cmd->mode = IWL_TLC_MNG_MODE_VHT;
  184. rs_fw_vht_set_enabled_rates(sta, vht_cap, cmd);
  185. } else if (ht_cap && ht_cap->ht_supported) {
  186. cmd->mode = IWL_TLC_MNG_MODE_HT;
  187. cmd->ht_rates[0][0] = cpu_to_le16(ht_cap->mcs.rx_mask[0]);
  188. cmd->ht_rates[1][0] = cpu_to_le16(ht_cap->mcs.rx_mask[1]);
  189. }
  190. }
  191. void iwl_mvm_tlc_update_notif(struct iwl_mvm *mvm,
  192. struct iwl_rx_cmd_buffer *rxb)
  193. {
  194. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  195. struct iwl_tlc_update_notif *notif;
  196. struct ieee80211_sta *sta;
  197. struct iwl_mvm_sta *mvmsta;
  198. struct iwl_lq_sta_rs_fw *lq_sta;
  199. u32 flags;
  200. rcu_read_lock();
  201. notif = (void *)pkt->data;
  202. sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
  203. if (IS_ERR_OR_NULL(sta)) {
  204. IWL_ERR(mvm, "Invalid sta id (%d) in FW TLC notification\n",
  205. notif->sta_id);
  206. goto out;
  207. }
  208. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  209. if (!mvmsta) {
  210. IWL_ERR(mvm, "Invalid sta id (%d) in FW TLC notification\n",
  211. notif->sta_id);
  212. goto out;
  213. }
  214. flags = le32_to_cpu(notif->flags);
  215. lq_sta = &mvmsta->lq_sta.rs_fw;
  216. if (flags & IWL_TLC_NOTIF_FLAG_RATE) {
  217. lq_sta->last_rate_n_flags = le32_to_cpu(notif->rate);
  218. IWL_DEBUG_RATE(mvm, "new rate_n_flags: 0x%X\n",
  219. lq_sta->last_rate_n_flags);
  220. }
  221. if (flags & IWL_TLC_NOTIF_FLAG_AMSDU) {
  222. u16 size = le32_to_cpu(notif->amsdu_size);
  223. if (WARN_ON(sta->max_amsdu_len < size))
  224. goto out;
  225. mvmsta->amsdu_enabled = le32_to_cpu(notif->amsdu_enabled);
  226. mvmsta->max_amsdu_len = size;
  227. IWL_DEBUG_RATE(mvm,
  228. "AMSDU update. AMSDU size: %d, AMSDU selected size: %d, AMSDU TID bitmap 0x%X\n",
  229. le32_to_cpu(notif->amsdu_size), size,
  230. mvmsta->amsdu_enabled);
  231. }
  232. out:
  233. rcu_read_unlock();
  234. }
  235. void rs_fw_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
  236. enum nl80211_band band)
  237. {
  238. struct ieee80211_hw *hw = mvm->hw;
  239. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  240. struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
  241. u32 cmd_id = iwl_cmd_id(TLC_MNG_CONFIG_CMD, DATA_PATH_GROUP, 0);
  242. struct ieee80211_supported_band *sband;
  243. struct iwl_tlc_config_cmd cfg_cmd = {
  244. .sta_id = mvmsta->sta_id,
  245. .max_ch_width = rs_fw_bw_from_sta_bw(sta),
  246. .flags = cpu_to_le16(rs_fw_set_config_flags(mvm, sta)),
  247. .chains = rs_fw_set_active_chains(iwl_mvm_get_valid_tx_ant(mvm)),
  248. .max_mpdu_len = cpu_to_le16(sta->max_amsdu_len),
  249. .sgi_ch_width_supp = rs_fw_sgi_cw_support(sta),
  250. .amsdu = iwl_mvm_is_csum_supported(mvm),
  251. };
  252. int ret;
  253. memset(lq_sta, 0, offsetof(typeof(*lq_sta), pers));
  254. #ifdef CONFIG_IWLWIFI_DEBUGFS
  255. iwl_mvm_reset_frame_stats(mvm);
  256. #endif
  257. sband = hw->wiphy->bands[band];
  258. rs_fw_set_supp_rates(sta, sband, &cfg_cmd);
  259. ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(cfg_cmd), &cfg_cmd);
  260. if (ret)
  261. IWL_ERR(mvm, "Failed to send rate scale config (%d)\n", ret);
  262. }
  263. int rs_fw_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
  264. bool enable)
  265. {
  266. /* TODO: need to introduce a new FW cmd since LQ cmd is not relevant */
  267. IWL_DEBUG_RATE(mvm, "tx protection - not implemented yet.\n");
  268. return 0;
  269. }
  270. void iwl_mvm_rs_add_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta)
  271. {
  272. struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
  273. IWL_DEBUG_RATE(mvm, "create station rate scale window\n");
  274. lq_sta->pers.drv = mvm;
  275. lq_sta->pers.sta_id = mvmsta->sta_id;
  276. lq_sta->pers.chains = 0;
  277. memset(lq_sta->pers.chain_signal, 0, sizeof(lq_sta->pers.chain_signal));
  278. lq_sta->pers.last_rssi = S8_MIN;
  279. lq_sta->last_rate_n_flags = 0;
  280. #ifdef CONFIG_MAC80211_DEBUGFS
  281. lq_sta->pers.dbg_fixed_rate = 0;
  282. #endif
  283. }