sf.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 SF_FULL_ON state.
  97. */
  98. static const __le32 sf_full_timeout[SF_NUM_SCENARIO][SF_NUM_TIMEOUT_TYPES] = {
  99. {
  100. cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER),
  101. cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER)
  102. },
  103. {
  104. cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER),
  105. cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER)
  106. },
  107. {
  108. cpu_to_le32(SF_MCAST_AGING_TIMER),
  109. cpu_to_le32(SF_MCAST_IDLE_TIMER)
  110. },
  111. {
  112. cpu_to_le32(SF_BA_AGING_TIMER),
  113. cpu_to_le32(SF_BA_IDLE_TIMER)
  114. },
  115. {
  116. cpu_to_le32(SF_TX_RE_AGING_TIMER),
  117. cpu_to_le32(SF_TX_RE_IDLE_TIMER)
  118. },
  119. };
  120. static void iwl_mvm_fill_sf_command(struct iwl_sf_cfg_cmd *sf_cmd,
  121. struct ieee80211_sta *sta)
  122. {
  123. int i, j, watermark;
  124. sf_cmd->watermark[SF_LONG_DELAY_ON] = cpu_to_le32(SF_W_MARK_SCAN);
  125. /*
  126. * If we are in association flow - check antenna configuration
  127. * capabilities of the AP station, and choose the watermark accordingly.
  128. */
  129. if (sta) {
  130. if (sta->ht_cap.ht_supported || sta->vht_cap.vht_supported) {
  131. switch (sta->rx_nss) {
  132. case 1:
  133. watermark = SF_W_MARK_SISO;
  134. break;
  135. case 2:
  136. watermark = SF_W_MARK_MIMO2;
  137. break;
  138. default:
  139. watermark = SF_W_MARK_MIMO3;
  140. break;
  141. }
  142. } else {
  143. watermark = SF_W_MARK_LEGACY;
  144. }
  145. /* default watermark value for unassociated mode. */
  146. } else {
  147. watermark = SF_W_MARK_MIMO2;
  148. }
  149. sf_cmd->watermark[SF_FULL_ON] = cpu_to_le32(watermark);
  150. for (i = 0; i < SF_NUM_SCENARIO; i++) {
  151. for (j = 0; j < SF_NUM_TIMEOUT_TYPES; j++) {
  152. sf_cmd->long_delay_timeouts[i][j] =
  153. cpu_to_le32(SF_LONG_DELAY_AGING_TIMER);
  154. }
  155. }
  156. BUILD_BUG_ON(sizeof(sf_full_timeout) !=
  157. sizeof(__le32) * SF_NUM_SCENARIO * SF_NUM_TIMEOUT_TYPES);
  158. memcpy(sf_cmd->full_on_timeouts, sf_full_timeout,
  159. sizeof(sf_full_timeout));
  160. }
  161. static int iwl_mvm_sf_config(struct iwl_mvm *mvm, u8 sta_id,
  162. enum iwl_sf_state new_state)
  163. {
  164. struct iwl_sf_cfg_cmd sf_cmd = {
  165. .state = cpu_to_le32(new_state),
  166. };
  167. struct ieee80211_sta *sta;
  168. int ret = 0;
  169. if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_SF_NO_DUMMY_NOTIF &&
  170. mvm->cfg->disable_dummy_notification)
  171. sf_cmd.state |= cpu_to_le32(SF_CFG_DUMMY_NOTIF_OFF);
  172. /*
  173. * If an associated AP sta changed its antenna configuration, the state
  174. * will remain FULL_ON but SF parameters need to be reconsidered.
  175. */
  176. if (new_state != SF_FULL_ON && mvm->sf_state == new_state)
  177. return 0;
  178. switch (new_state) {
  179. case SF_UNINIT:
  180. break;
  181. case SF_FULL_ON:
  182. if (sta_id == IWL_MVM_STATION_COUNT) {
  183. IWL_ERR(mvm,
  184. "No station: Cannot switch SF to FULL_ON\n");
  185. return -EINVAL;
  186. }
  187. rcu_read_lock();
  188. sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
  189. if (IS_ERR_OR_NULL(sta)) {
  190. IWL_ERR(mvm, "Invalid station id\n");
  191. rcu_read_unlock();
  192. return -EINVAL;
  193. }
  194. iwl_mvm_fill_sf_command(&sf_cmd, sta);
  195. rcu_read_unlock();
  196. break;
  197. case SF_INIT_OFF:
  198. iwl_mvm_fill_sf_command(&sf_cmd, NULL);
  199. break;
  200. default:
  201. WARN_ONCE(1, "Invalid state: %d. not sending Smart Fifo cmd\n",
  202. new_state);
  203. return -EINVAL;
  204. }
  205. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_SF_CFG_CMD, CMD_ASYNC,
  206. sizeof(sf_cmd), &sf_cmd);
  207. if (!ret)
  208. mvm->sf_state = new_state;
  209. return ret;
  210. }
  211. /*
  212. * Update Smart fifo:
  213. * Count bound interfaces that are not to be removed, ignoring p2p devices,
  214. * and set new state accordingly.
  215. */
  216. int iwl_mvm_sf_update(struct iwl_mvm *mvm, struct ieee80211_vif *changed_vif,
  217. bool remove_vif)
  218. {
  219. enum iwl_sf_state new_state;
  220. u8 sta_id = IWL_MVM_STATION_COUNT;
  221. struct iwl_mvm_vif *mvmvif = NULL;
  222. struct iwl_mvm_active_iface_iterator_data data = {
  223. .ignore_vif = changed_vif,
  224. .sta_vif_state = SF_UNINIT,
  225. .sta_vif_ap_sta_id = IWL_MVM_STATION_COUNT,
  226. };
  227. /*
  228. * Ignore the call if we are in HW Restart flow, or if the handled
  229. * vif is a p2p device.
  230. */
  231. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
  232. (changed_vif && changed_vif->type == NL80211_IFTYPE_P2P_DEVICE))
  233. return 0;
  234. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  235. IEEE80211_IFACE_ITER_NORMAL,
  236. iwl_mvm_bound_iface_iterator,
  237. &data);
  238. /* If changed_vif exists and is not to be removed, add to the count */
  239. if (changed_vif && !remove_vif)
  240. data.num_active_macs++;
  241. switch (data.num_active_macs) {
  242. case 0:
  243. /* If there are no active macs - change state to SF_INIT_OFF */
  244. new_state = SF_INIT_OFF;
  245. break;
  246. case 1:
  247. if (remove_vif) {
  248. /* The one active mac left is of type station
  249. * and we filled the relevant data during iteration
  250. */
  251. new_state = data.sta_vif_state;
  252. sta_id = data.sta_vif_ap_sta_id;
  253. } else {
  254. if (WARN_ON(!changed_vif))
  255. return -EINVAL;
  256. if (changed_vif->type != NL80211_IFTYPE_STATION) {
  257. new_state = SF_UNINIT;
  258. } else if (changed_vif->bss_conf.assoc &&
  259. changed_vif->bss_conf.dtim_period) {
  260. mvmvif = iwl_mvm_vif_from_mac80211(changed_vif);
  261. sta_id = mvmvif->ap_sta_id;
  262. new_state = SF_FULL_ON;
  263. } else {
  264. new_state = SF_INIT_OFF;
  265. }
  266. }
  267. break;
  268. default:
  269. /* If there are multiple active macs - change to SF_UNINIT */
  270. new_state = SF_UNINIT;
  271. }
  272. return iwl_mvm_sf_config(mvm, sta_id, new_state);
  273. }