rs-fw.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * The full GNU General Public License is included in this distribution
  20. * in the file called COPYING.
  21. *
  22. * Contact Information:
  23. * Intel Linux Wireless <linuxwifi@intel.com>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. * BSD LICENSE
  27. *
  28. * Copyright(c) 2017 Intel Deutschland GmbH
  29. * All rights reserved.
  30. *
  31. * Redistribution and use in source and binary forms, with or without
  32. * modification, are permitted provided that the following conditions
  33. * are met:
  34. *
  35. * * Redistributions of source code must retain the above copyright
  36. * notice, this list of conditions and the following disclaimer.
  37. * * Redistributions in binary form must reproduce the above copyright
  38. * notice, this list of conditions and the following disclaimer in
  39. * the documentation and/or other materials provided with the
  40. * distribution.
  41. * * Neither the name Intel Corporation nor the names of its
  42. * contributors may be used to endorse or promote products derived
  43. * from this software without specific prior written permission.
  44. *
  45. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  46. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  47. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  48. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  49. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  50. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  51. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  52. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  53. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  54. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  55. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  56. *
  57. *****************************************************************************/
  58. #include "rs.h"
  59. #include "fw-api.h"
  60. #include "sta.h"
  61. #include "iwl-op-mode.h"
  62. #include "mvm.h"
  63. static u8 rs_fw_bw_from_sta_bw(struct ieee80211_sta *sta)
  64. {
  65. switch (sta->bandwidth) {
  66. case IEEE80211_STA_RX_BW_160:
  67. return IWL_TLC_MNG_MAX_CH_WIDTH_160MHZ;
  68. case IEEE80211_STA_RX_BW_80:
  69. return IWL_TLC_MNG_MAX_CH_WIDTH_80MHZ;
  70. case IEEE80211_STA_RX_BW_40:
  71. return IWL_TLC_MNG_MAX_CH_WIDTH_40MHZ;
  72. case IEEE80211_STA_RX_BW_20:
  73. default:
  74. return IWL_TLC_MNG_MAX_CH_WIDTH_20MHZ;
  75. }
  76. }
  77. static u8 rs_fw_set_active_chains(u8 chains)
  78. {
  79. u8 fw_chains = 0;
  80. if (chains & ANT_A)
  81. fw_chains |= IWL_TLC_MNG_CHAIN_A_MSK;
  82. if (chains & ANT_B)
  83. fw_chains |= IWL_TLC_MNG_CHAIN_B_MSK;
  84. if (chains & ANT_C)
  85. fw_chains |= IWL_TLC_MNG_CHAIN_C_MSK;
  86. return fw_chains;
  87. }
  88. static u8 rs_fw_sgi_cw_support(struct ieee80211_sta *sta)
  89. {
  90. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  91. struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  92. u8 supp = 0;
  93. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
  94. supp |= IWL_TLC_MNG_SGI_20MHZ_MSK;
  95. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
  96. supp |= IWL_TLC_MNG_SGI_40MHZ_MSK;
  97. if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_80)
  98. supp |= IWL_TLC_MNG_SGI_80MHZ_MSK;
  99. if (vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_160)
  100. supp |= IWL_TLC_MNG_SGI_160MHZ_MSK;
  101. return supp;
  102. }
  103. static u16 rs_fw_set_config_flags(struct iwl_mvm *mvm,
  104. struct ieee80211_sta *sta)
  105. {
  106. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  107. struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  108. bool vht_ena = vht_cap && vht_cap->vht_supported;
  109. u16 flags = IWL_TLC_MNG_CFG_FLAGS_CCK_MSK |
  110. IWL_TLC_MNG_CFG_FLAGS_DCM_MSK |
  111. IWL_TLC_MNG_CFG_FLAGS_DD_MSK;
  112. if (mvm->cfg->ht_params->stbc &&
  113. (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) > 1) &&
  114. ((ht_cap && (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC)) ||
  115. (vht_ena && (vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK))))
  116. flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK;
  117. if (mvm->cfg->ht_params->ldpc &&
  118. ((ht_cap && (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)) ||
  119. (vht_ena && (vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC))))
  120. flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK;
  121. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
  122. (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) > 1) &&
  123. (vht_cap->cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE))
  124. flags |= IWL_TLC_MNG_CFG_FLAGS_BF_MSK;
  125. return flags;
  126. }
  127. static
  128. int rs_fw_vht_highest_rx_mcs_index(struct ieee80211_sta_vht_cap *vht_cap,
  129. int nss)
  130. {
  131. u16 rx_mcs = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) &
  132. (0x3 << (2 * (nss - 1)));
  133. rx_mcs >>= (2 * (nss - 1));
  134. switch (rx_mcs) {
  135. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  136. return IWL_TLC_MNG_HT_RATE_MCS7;
  137. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  138. return IWL_TLC_MNG_HT_RATE_MCS8;
  139. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  140. return IWL_TLC_MNG_HT_RATE_MCS9;
  141. default:
  142. WARN_ON_ONCE(1);
  143. break;
  144. }
  145. return 0;
  146. }
  147. static void rs_fw_vht_set_enabled_rates(struct ieee80211_sta *sta,
  148. struct ieee80211_sta_vht_cap *vht_cap,
  149. struct iwl_tlc_config_cmd *cmd)
  150. {
  151. u16 supp;
  152. int i, highest_mcs;
  153. for (i = 0; i < sta->rx_nss; i++) {
  154. if (i == MAX_RS_ANT_NUM)
  155. break;
  156. highest_mcs = rs_fw_vht_highest_rx_mcs_index(vht_cap, i + 1);
  157. if (!highest_mcs)
  158. continue;
  159. supp = BIT(highest_mcs + 1) - 1;
  160. if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
  161. supp &= ~BIT(IWL_TLC_MNG_HT_RATE_MCS9);
  162. cmd->ht_supp_rates[i] = cpu_to_le16(supp);
  163. }
  164. }
  165. static void rs_fw_set_supp_rates(struct ieee80211_sta *sta,
  166. struct ieee80211_supported_band *sband,
  167. struct iwl_tlc_config_cmd *cmd)
  168. {
  169. int i;
  170. unsigned long tmp;
  171. unsigned long supp; /* must be unsigned long for for_each_set_bit */
  172. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  173. struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  174. /* non HT rates */
  175. supp = 0;
  176. tmp = sta->supp_rates[sband->band];
  177. for_each_set_bit(i, &tmp, BITS_PER_LONG)
  178. supp |= BIT(sband->bitrates[i].hw_value);
  179. cmd->non_ht_supp_rates = cpu_to_le16(supp);
  180. cmd->mode = IWL_TLC_MNG_MODE_NON_HT;
  181. /* HT/VHT rates */
  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_supp_rates[0] = cpu_to_le16(ht_cap->mcs.rx_mask[0]);
  188. cmd->ht_supp_rates[1] = cpu_to_le16(ht_cap->mcs.rx_mask[1]);
  189. }
  190. }
  191. static void rs_fw_tlc_mng_notif_req_config(struct iwl_mvm *mvm, u8 sta_id)
  192. {
  193. u32 cmd_id = iwl_cmd_id(TLC_MNG_NOTIF_REQ_CMD, DATA_PATH_GROUP, 0);
  194. struct iwl_tlc_notif_req_config_cmd cfg_cmd = {
  195. .sta_id = sta_id,
  196. .flags = cpu_to_le16(IWL_TLC_NOTIF_INIT_RATE_MSK),
  197. .interval = cpu_to_le16(IWL_TLC_NOTIF_REQ_INTERVAL),
  198. };
  199. int ret;
  200. ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(cfg_cmd), &cfg_cmd);
  201. if (ret)
  202. IWL_ERR(mvm, "Failed to send TLC notif request (%d)\n", ret);
  203. }
  204. void iwl_mvm_tlc_update_notif(struct iwl_mvm *mvm, struct iwl_rx_packet *pkt)
  205. {
  206. struct iwl_tlc_update_notif *notif;
  207. struct iwl_mvm_sta *mvmsta;
  208. struct iwl_lq_sta_rs_fw *lq_sta;
  209. rcu_read_lock();
  210. notif = (void *)pkt->data;
  211. mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, notif->sta_id);
  212. if (!mvmsta) {
  213. IWL_ERR(mvm, "Invalid sta id (%d) in FW TLC notification\n",
  214. notif->sta_id);
  215. goto out;
  216. }
  217. lq_sta = &mvmsta->lq_sta.rs_fw;
  218. if (le16_to_cpu(notif->flags) & IWL_TLC_NOTIF_INIT_RATE_MSK) {
  219. lq_sta->last_rate_n_flags =
  220. le32_to_cpu(notif->values[IWL_TLC_NOTIF_INIT_RATE_POS]);
  221. IWL_DEBUG_RATE(mvm, "new rate_n_flags: 0x%X\n",
  222. lq_sta->last_rate_n_flags);
  223. }
  224. out:
  225. rcu_read_unlock();
  226. }
  227. void rs_fw_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
  228. enum nl80211_band band)
  229. {
  230. struct ieee80211_hw *hw = mvm->hw;
  231. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  232. struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
  233. u32 cmd_id = iwl_cmd_id(TLC_MNG_CONFIG_CMD, DATA_PATH_GROUP, 0);
  234. struct ieee80211_supported_band *sband;
  235. struct iwl_tlc_config_cmd cfg_cmd = {
  236. .sta_id = mvmsta->sta_id,
  237. .max_supp_ch_width = rs_fw_bw_from_sta_bw(sta),
  238. .flags = cpu_to_le16(rs_fw_set_config_flags(mvm, sta)),
  239. .chains = rs_fw_set_active_chains(iwl_mvm_get_valid_tx_ant(mvm)),
  240. .max_supp_ss = sta->rx_nss,
  241. .max_ampdu_cnt = cpu_to_le32(mvmsta->max_agg_bufsize),
  242. .sgi_ch_width_supp = rs_fw_sgi_cw_support(sta),
  243. };
  244. int ret;
  245. memset(lq_sta, 0, offsetof(typeof(*lq_sta), pers));
  246. #ifdef CONFIG_IWLWIFI_DEBUGFS
  247. iwl_mvm_reset_frame_stats(mvm);
  248. #endif
  249. sband = hw->wiphy->bands[band];
  250. rs_fw_set_supp_rates(sta, sband, &cfg_cmd);
  251. ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(cfg_cmd), &cfg_cmd);
  252. if (ret)
  253. IWL_ERR(mvm, "Failed to send rate scale config (%d)\n", ret);
  254. rs_fw_tlc_mng_notif_req_config(mvm, cfg_cmd.sta_id);
  255. }
  256. int rs_fw_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
  257. bool enable)
  258. {
  259. /* TODO: need to introduce a new FW cmd since LQ cmd is not relevant */
  260. IWL_DEBUG_RATE(mvm, "tx protection - not implemented yet.\n");
  261. return 0;
  262. }
  263. void iwl_mvm_rs_add_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta)
  264. {
  265. struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
  266. IWL_DEBUG_RATE(mvm, "create station rate scale window\n");
  267. lq_sta->pers.drv = mvm;
  268. lq_sta->pers.sta_id = mvmsta->sta_id;
  269. lq_sta->pers.chains = 0;
  270. memset(lq_sta->pers.chain_signal, 0, sizeof(lq_sta->pers.chain_signal));
  271. lq_sta->pers.last_rssi = S8_MIN;
  272. lq_sta->last_rate_n_flags = 0;
  273. #ifdef CONFIG_MAC80211_DEBUGFS
  274. lq_sta->pers.dbg_fixed_rate = 0;
  275. #endif
  276. }