sf.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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) 2013 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  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. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include "mvm.h"
  66. /* For counting bound interfaces */
  67. struct iwl_mvm_active_iface_iterator_data {
  68. struct ieee80211_vif *ignore_vif;
  69. u8 sta_vif_ap_sta_id;
  70. enum iwl_sf_state sta_vif_state;
  71. int num_active_macs;
  72. };
  73. /*
  74. * Count bound interfaces which are not p2p, besides data->ignore_vif.
  75. * data->station_vif will point to one bound vif of type station, if exists.
  76. */
  77. static void iwl_mvm_bound_iface_iterator(void *_data, u8 *mac,
  78. struct ieee80211_vif *vif)
  79. {
  80. struct iwl_mvm_active_iface_iterator_data *data = _data;
  81. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  82. if (vif == data->ignore_vif || !mvmvif->phy_ctxt ||
  83. vif->type == NL80211_IFTYPE_P2P_DEVICE)
  84. return;
  85. data->num_active_macs++;
  86. if (vif->type == NL80211_IFTYPE_STATION) {
  87. data->sta_vif_ap_sta_id = mvmvif->ap_sta_id;
  88. if (vif->bss_conf.assoc)
  89. data->sta_vif_state = SF_FULL_ON;
  90. else
  91. data->sta_vif_state = SF_INIT_OFF;
  92. }
  93. }
  94. /*
  95. * Aging and idle timeouts for the different possible scenarios
  96. * in default configuration
  97. */
  98. static const
  99. __le32 sf_full_timeout_def[SF_NUM_SCENARIO][SF_NUM_TIMEOUT_TYPES] = {
  100. {
  101. cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER_DEF),
  102. cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER_DEF)
  103. },
  104. {
  105. cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER_DEF),
  106. cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER_DEF)
  107. },
  108. {
  109. cpu_to_le32(SF_MCAST_AGING_TIMER_DEF),
  110. cpu_to_le32(SF_MCAST_IDLE_TIMER_DEF)
  111. },
  112. {
  113. cpu_to_le32(SF_BA_AGING_TIMER_DEF),
  114. cpu_to_le32(SF_BA_IDLE_TIMER_DEF)
  115. },
  116. {
  117. cpu_to_le32(SF_TX_RE_AGING_TIMER_DEF),
  118. cpu_to_le32(SF_TX_RE_IDLE_TIMER_DEF)
  119. },
  120. };
  121. /*
  122. * Aging and idle timeouts for the different possible scenarios
  123. * in single BSS MAC configuration.
  124. */
  125. static const __le32 sf_full_timeout[SF_NUM_SCENARIO][SF_NUM_TIMEOUT_TYPES] = {
  126. {
  127. cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER),
  128. cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER)
  129. },
  130. {
  131. cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER),
  132. cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER)
  133. },
  134. {
  135. cpu_to_le32(SF_MCAST_AGING_TIMER),
  136. cpu_to_le32(SF_MCAST_IDLE_TIMER)
  137. },
  138. {
  139. cpu_to_le32(SF_BA_AGING_TIMER),
  140. cpu_to_le32(SF_BA_IDLE_TIMER)
  141. },
  142. {
  143. cpu_to_le32(SF_TX_RE_AGING_TIMER),
  144. cpu_to_le32(SF_TX_RE_IDLE_TIMER)
  145. },
  146. };
  147. static void iwl_mvm_fill_sf_command(struct iwl_mvm *mvm,
  148. struct iwl_sf_cfg_cmd *sf_cmd,
  149. struct ieee80211_sta *sta)
  150. {
  151. int i, j, watermark;
  152. sf_cmd->watermark[SF_LONG_DELAY_ON] = cpu_to_le32(SF_W_MARK_SCAN);
  153. /*
  154. * If we are in association flow - check antenna configuration
  155. * capabilities of the AP station, and choose the watermark accordingly.
  156. */
  157. if (sta) {
  158. if (sta->ht_cap.ht_supported || sta->vht_cap.vht_supported) {
  159. switch (sta->rx_nss) {
  160. case 1:
  161. watermark = SF_W_MARK_SISO;
  162. break;
  163. case 2:
  164. watermark = SF_W_MARK_MIMO2;
  165. break;
  166. default:
  167. watermark = SF_W_MARK_MIMO3;
  168. break;
  169. }
  170. } else {
  171. watermark = SF_W_MARK_LEGACY;
  172. }
  173. /* default watermark value for unassociated mode. */
  174. } else {
  175. watermark = SF_W_MARK_MIMO2;
  176. }
  177. sf_cmd->watermark[SF_FULL_ON] = cpu_to_le32(watermark);
  178. for (i = 0; i < SF_NUM_SCENARIO; i++) {
  179. for (j = 0; j < SF_NUM_TIMEOUT_TYPES; j++) {
  180. sf_cmd->long_delay_timeouts[i][j] =
  181. cpu_to_le32(SF_LONG_DELAY_AGING_TIMER);
  182. }
  183. }
  184. if (sta || IWL_UCODE_API(mvm->fw->ucode_ver) < 13) {
  185. BUILD_BUG_ON(sizeof(sf_full_timeout) !=
  186. sizeof(__le32) * SF_NUM_SCENARIO *
  187. SF_NUM_TIMEOUT_TYPES);
  188. memcpy(sf_cmd->full_on_timeouts, sf_full_timeout,
  189. sizeof(sf_full_timeout));
  190. } else {
  191. BUILD_BUG_ON(sizeof(sf_full_timeout_def) !=
  192. sizeof(__le32) * SF_NUM_SCENARIO *
  193. SF_NUM_TIMEOUT_TYPES);
  194. memcpy(sf_cmd->full_on_timeouts, sf_full_timeout_def,
  195. sizeof(sf_full_timeout_def));
  196. }
  197. }
  198. static int iwl_mvm_sf_config(struct iwl_mvm *mvm, u8 sta_id,
  199. enum iwl_sf_state new_state)
  200. {
  201. struct iwl_sf_cfg_cmd sf_cmd = {
  202. .state = cpu_to_le32(new_state),
  203. };
  204. struct ieee80211_sta *sta;
  205. int ret = 0;
  206. if (IWL_UCODE_API(mvm->fw->ucode_ver) < 13)
  207. sf_cmd.state = cpu_to_le32(new_state);
  208. if (mvm->cfg->disable_dummy_notification)
  209. sf_cmd.state |= cpu_to_le32(SF_CFG_DUMMY_NOTIF_OFF);
  210. /*
  211. * If an associated AP sta changed its antenna configuration, the state
  212. * will remain FULL_ON but SF parameters need to be reconsidered.
  213. */
  214. if (new_state != SF_FULL_ON && mvm->sf_state == new_state)
  215. return 0;
  216. switch (new_state) {
  217. case SF_UNINIT:
  218. if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 13)
  219. iwl_mvm_fill_sf_command(mvm, &sf_cmd, NULL);
  220. break;
  221. case SF_FULL_ON:
  222. if (sta_id == IWL_MVM_STATION_COUNT) {
  223. IWL_ERR(mvm,
  224. "No station: Cannot switch SF to FULL_ON\n");
  225. return -EINVAL;
  226. }
  227. rcu_read_lock();
  228. sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
  229. if (IS_ERR_OR_NULL(sta)) {
  230. IWL_ERR(mvm, "Invalid station id\n");
  231. rcu_read_unlock();
  232. return -EINVAL;
  233. }
  234. iwl_mvm_fill_sf_command(mvm, &sf_cmd, sta);
  235. rcu_read_unlock();
  236. break;
  237. case SF_INIT_OFF:
  238. iwl_mvm_fill_sf_command(mvm, &sf_cmd, NULL);
  239. break;
  240. default:
  241. WARN_ONCE(1, "Invalid state: %d. not sending Smart Fifo cmd\n",
  242. new_state);
  243. return -EINVAL;
  244. }
  245. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_SF_CFG_CMD, CMD_ASYNC,
  246. sizeof(sf_cmd), &sf_cmd);
  247. if (!ret)
  248. mvm->sf_state = new_state;
  249. return ret;
  250. }
  251. /*
  252. * Update Smart fifo:
  253. * Count bound interfaces that are not to be removed, ignoring p2p devices,
  254. * and set new state accordingly.
  255. */
  256. int iwl_mvm_sf_update(struct iwl_mvm *mvm, struct ieee80211_vif *changed_vif,
  257. bool remove_vif)
  258. {
  259. enum iwl_sf_state new_state;
  260. u8 sta_id = IWL_MVM_STATION_COUNT;
  261. struct iwl_mvm_vif *mvmvif = NULL;
  262. struct iwl_mvm_active_iface_iterator_data data = {
  263. .ignore_vif = changed_vif,
  264. .sta_vif_state = SF_UNINIT,
  265. .sta_vif_ap_sta_id = IWL_MVM_STATION_COUNT,
  266. };
  267. /*
  268. * Ignore the call if we are in HW Restart flow, or if the handled
  269. * vif is a p2p device.
  270. */
  271. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
  272. (changed_vif && changed_vif->type == NL80211_IFTYPE_P2P_DEVICE))
  273. return 0;
  274. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  275. IEEE80211_IFACE_ITER_NORMAL,
  276. iwl_mvm_bound_iface_iterator,
  277. &data);
  278. /* If changed_vif exists and is not to be removed, add to the count */
  279. if (changed_vif && !remove_vif)
  280. data.num_active_macs++;
  281. switch (data.num_active_macs) {
  282. case 0:
  283. /* If there are no active macs - change state to SF_INIT_OFF */
  284. new_state = SF_INIT_OFF;
  285. break;
  286. case 1:
  287. if (remove_vif) {
  288. /* The one active mac left is of type station
  289. * and we filled the relevant data during iteration
  290. */
  291. new_state = data.sta_vif_state;
  292. sta_id = data.sta_vif_ap_sta_id;
  293. } else {
  294. if (WARN_ON(!changed_vif))
  295. return -EINVAL;
  296. if (changed_vif->type != NL80211_IFTYPE_STATION) {
  297. new_state = SF_UNINIT;
  298. } else if (changed_vif->bss_conf.assoc &&
  299. changed_vif->bss_conf.dtim_period) {
  300. mvmvif = iwl_mvm_vif_from_mac80211(changed_vif);
  301. sta_id = mvmvif->ap_sta_id;
  302. new_state = SF_FULL_ON;
  303. } else {
  304. new_state = SF_INIT_OFF;
  305. }
  306. }
  307. break;
  308. default:
  309. /* If there are multiple active macs - change to SF_UNINIT */
  310. new_state = SF_UNINIT;
  311. }
  312. return iwl_mvm_sf_config(mvm, sta_id, new_state);
  313. }