sf.c 8.6 KB

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