power.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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) 2012 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  10. * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  24. * USA
  25. *
  26. * The full GNU General Public License is included in this distribution
  27. * in the file called COPYING.
  28. *
  29. * Contact Information:
  30. * Intel Linux Wireless <linuxwifi@intel.com>
  31. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  32. *
  33. * BSD LICENSE
  34. *
  35. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  36. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  37. * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #include <linux/kernel.h>
  68. #include <linux/module.h>
  69. #include <linux/slab.h>
  70. #include <linux/etherdevice.h>
  71. #include <net/mac80211.h>
  72. #include "iwl-debug.h"
  73. #include "mvm.h"
  74. #include "iwl-modparams.h"
  75. #include "fw-api-power.h"
  76. #define POWER_KEEP_ALIVE_PERIOD_SEC 25
  77. static
  78. int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
  79. struct iwl_beacon_filter_cmd *cmd,
  80. u32 flags)
  81. {
  82. IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
  83. le32_to_cpu(cmd->ba_enable_beacon_abort));
  84. IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
  85. le32_to_cpu(cmd->ba_escape_timer));
  86. IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
  87. le32_to_cpu(cmd->bf_debug_flag));
  88. IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
  89. le32_to_cpu(cmd->bf_enable_beacon_filter));
  90. IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
  91. le32_to_cpu(cmd->bf_energy_delta));
  92. IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
  93. le32_to_cpu(cmd->bf_escape_timer));
  94. IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
  95. le32_to_cpu(cmd->bf_roaming_energy_delta));
  96. IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
  97. le32_to_cpu(cmd->bf_roaming_state));
  98. IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n",
  99. le32_to_cpu(cmd->bf_temp_threshold));
  100. IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n",
  101. le32_to_cpu(cmd->bf_temp_fast_filter));
  102. IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n",
  103. le32_to_cpu(cmd->bf_temp_slow_filter));
  104. return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags,
  105. sizeof(struct iwl_beacon_filter_cmd), cmd);
  106. }
  107. static
  108. void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
  109. struct ieee80211_vif *vif,
  110. struct iwl_beacon_filter_cmd *cmd,
  111. bool d0i3)
  112. {
  113. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  114. if (vif->bss_conf.cqm_rssi_thold && !d0i3) {
  115. cmd->bf_energy_delta =
  116. cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
  117. /* fw uses an absolute value for this */
  118. cmd->bf_roaming_state =
  119. cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
  120. }
  121. cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
  122. }
  123. static void iwl_mvm_power_log(struct iwl_mvm *mvm,
  124. struct iwl_mac_power_cmd *cmd)
  125. {
  126. IWL_DEBUG_POWER(mvm,
  127. "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
  128. cmd->id_and_color, iwlmvm_mod_params.power_scheme,
  129. le16_to_cpu(cmd->flags));
  130. IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
  131. le16_to_cpu(cmd->keep_alive_seconds));
  132. if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
  133. IWL_DEBUG_POWER(mvm, "Disable power management\n");
  134. return;
  135. }
  136. IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
  137. le32_to_cpu(cmd->rx_data_timeout));
  138. IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
  139. le32_to_cpu(cmd->tx_data_timeout));
  140. if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
  141. IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
  142. cmd->skip_dtim_periods);
  143. if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
  144. IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
  145. cmd->lprx_rssi_threshold);
  146. if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
  147. IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
  148. IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
  149. le32_to_cpu(cmd->rx_data_timeout_uapsd));
  150. IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
  151. le32_to_cpu(cmd->tx_data_timeout_uapsd));
  152. IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
  153. IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
  154. IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
  155. }
  156. }
  157. static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
  158. struct ieee80211_vif *vif,
  159. struct iwl_mac_power_cmd *cmd)
  160. {
  161. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  162. enum ieee80211_ac_numbers ac;
  163. bool tid_found = false;
  164. #ifdef CONFIG_IWLWIFI_DEBUGFS
  165. /* set advanced pm flag with no uapsd ACs to enable ps-poll */
  166. if (mvmvif->dbgfs_pm.use_ps_poll) {
  167. cmd->flags |= cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
  168. return;
  169. }
  170. #endif
  171. for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
  172. if (!mvmvif->queue_params[ac].uapsd)
  173. continue;
  174. if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
  175. cmd->flags |=
  176. cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
  177. cmd->uapsd_ac_flags |= BIT(ac);
  178. /* QNDP TID - the highest TID with no admission control */
  179. if (!tid_found && !mvmvif->queue_params[ac].acm) {
  180. tid_found = true;
  181. switch (ac) {
  182. case IEEE80211_AC_VO:
  183. cmd->qndp_tid = 6;
  184. break;
  185. case IEEE80211_AC_VI:
  186. cmd->qndp_tid = 5;
  187. break;
  188. case IEEE80211_AC_BE:
  189. cmd->qndp_tid = 0;
  190. break;
  191. case IEEE80211_AC_BK:
  192. cmd->qndp_tid = 1;
  193. break;
  194. }
  195. }
  196. }
  197. cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
  198. if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
  199. BIT(IEEE80211_AC_VI) |
  200. BIT(IEEE80211_AC_BE) |
  201. BIT(IEEE80211_AC_BK))) {
  202. cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
  203. cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
  204. cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
  205. cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
  206. cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
  207. }
  208. cmd->uapsd_max_sp = mvm->hw->uapsd_max_sp_len;
  209. if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
  210. cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
  211. cmd->rx_data_timeout_uapsd =
  212. cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
  213. cmd->tx_data_timeout_uapsd =
  214. cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
  215. } else {
  216. cmd->rx_data_timeout_uapsd =
  217. cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
  218. cmd->tx_data_timeout_uapsd =
  219. cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
  220. }
  221. if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
  222. cmd->heavy_tx_thld_packets =
  223. IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
  224. cmd->heavy_rx_thld_packets =
  225. IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
  226. } else {
  227. cmd->heavy_tx_thld_packets =
  228. IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
  229. cmd->heavy_rx_thld_packets =
  230. IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
  231. }
  232. cmd->heavy_tx_thld_percentage =
  233. IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
  234. cmd->heavy_rx_thld_percentage =
  235. IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
  236. }
  237. static void iwl_mvm_p2p_standalone_iterator(void *_data, u8 *mac,
  238. struct ieee80211_vif *vif)
  239. {
  240. bool *is_p2p_standalone = _data;
  241. switch (ieee80211_vif_type_p2p(vif)) {
  242. case NL80211_IFTYPE_P2P_GO:
  243. case NL80211_IFTYPE_AP:
  244. *is_p2p_standalone = false;
  245. break;
  246. case NL80211_IFTYPE_STATION:
  247. if (vif->bss_conf.assoc)
  248. *is_p2p_standalone = false;
  249. break;
  250. default:
  251. break;
  252. }
  253. }
  254. static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
  255. struct ieee80211_vif *vif)
  256. {
  257. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  258. if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
  259. ETH_ALEN))
  260. return false;
  261. /*
  262. * Avoid using uAPSD if P2P client is associated to GO that uses
  263. * opportunistic power save. This is due to current FW limitation.
  264. */
  265. if (vif->p2p &&
  266. (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
  267. IEEE80211_P2P_OPPPS_ENABLE_BIT))
  268. return false;
  269. /*
  270. * Avoid using uAPSD if client is in DCM -
  271. * low latency issue in Miracast
  272. */
  273. if (iwl_mvm_phy_ctx_count(mvm) >= 2)
  274. return false;
  275. if (vif->p2p) {
  276. /* Allow U-APSD only if p2p is stand alone */
  277. bool is_p2p_standalone = true;
  278. if (!iwl_mvm_is_p2p_scm_uapsd_supported(mvm))
  279. return false;
  280. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  281. IEEE80211_IFACE_ITER_NORMAL,
  282. iwl_mvm_p2p_standalone_iterator,
  283. &is_p2p_standalone);
  284. if (!is_p2p_standalone)
  285. return false;
  286. }
  287. return true;
  288. }
  289. static bool iwl_mvm_power_is_radar(struct ieee80211_vif *vif)
  290. {
  291. struct ieee80211_chanctx_conf *chanctx_conf;
  292. struct ieee80211_channel *chan;
  293. bool radar_detect = false;
  294. rcu_read_lock();
  295. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  296. WARN_ON(!chanctx_conf);
  297. if (chanctx_conf) {
  298. chan = chanctx_conf->def.chan;
  299. radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
  300. }
  301. rcu_read_unlock();
  302. return radar_detect;
  303. }
  304. static void iwl_mvm_power_config_skip_dtim(struct iwl_mvm *mvm,
  305. struct ieee80211_vif *vif,
  306. struct iwl_mac_power_cmd *cmd,
  307. bool host_awake)
  308. {
  309. int dtimper = vif->bss_conf.dtim_period ?: 1;
  310. int skip;
  311. /* disable, in case we're supposed to override */
  312. cmd->skip_dtim_periods = 0;
  313. cmd->flags &= ~cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  314. if (iwl_mvm_power_is_radar(vif))
  315. return;
  316. if (dtimper >= 10)
  317. return;
  318. /* TODO: check that multicast wake lock is off */
  319. if (host_awake) {
  320. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_LP)
  321. return;
  322. skip = 2;
  323. } else {
  324. int dtimper_tu = dtimper * vif->bss_conf.beacon_int;
  325. if (WARN_ON(!dtimper_tu))
  326. return;
  327. /* configure skip over dtim up to 306TU - 314 msec */
  328. skip = max_t(u8, 1, 306 / dtimper_tu);
  329. }
  330. /* the firmware really expects "look at every X DTIMs", so add 1 */
  331. cmd->skip_dtim_periods = 1 + skip;
  332. cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  333. }
  334. static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
  335. struct ieee80211_vif *vif,
  336. struct iwl_mac_power_cmd *cmd,
  337. bool host_awake)
  338. {
  339. int dtimper, bi;
  340. int keep_alive;
  341. struct iwl_mvm_vif *mvmvif __maybe_unused =
  342. iwl_mvm_vif_from_mac80211(vif);
  343. cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
  344. mvmvif->color));
  345. dtimper = vif->bss_conf.dtim_period;
  346. bi = vif->bss_conf.beacon_int;
  347. /*
  348. * Regardless of power management state the driver must set
  349. * keep alive period. FW will use it for sending keep alive NDPs
  350. * immediately after association. Check that keep alive period
  351. * is at least 3 * DTIM
  352. */
  353. keep_alive = DIV_ROUND_UP(ieee80211_tu_to_usec(3 * dtimper * bi),
  354. USEC_PER_SEC);
  355. keep_alive = max(keep_alive, POWER_KEEP_ALIVE_PERIOD_SEC);
  356. cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
  357. if (mvm->ps_disabled)
  358. return;
  359. cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
  360. if (!vif->bss_conf.ps || !mvmvif->pm_enabled)
  361. return;
  362. if (iwl_mvm_vif_low_latency(mvmvif) && vif->p2p &&
  363. (!fw_has_capa(&mvm->fw->ucode_capa,
  364. IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS) ||
  365. !IWL_MVM_P2P_LOWLATENCY_PS_ENABLE))
  366. return;
  367. cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
  368. if (vif->bss_conf.beacon_rate &&
  369. (vif->bss_conf.beacon_rate->bitrate == 10 ||
  370. vif->bss_conf.beacon_rate->bitrate == 60)) {
  371. cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
  372. cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
  373. }
  374. iwl_mvm_power_config_skip_dtim(mvm, vif, cmd, host_awake);
  375. if (!host_awake) {
  376. cmd->rx_data_timeout =
  377. cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
  378. cmd->tx_data_timeout =
  379. cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
  380. } else if (iwl_mvm_vif_low_latency(mvmvif) && vif->p2p &&
  381. fw_has_capa(&mvm->fw->ucode_capa,
  382. IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS)) {
  383. cmd->tx_data_timeout =
  384. cpu_to_le32(IWL_MVM_SHORT_PS_TX_DATA_TIMEOUT);
  385. cmd->rx_data_timeout =
  386. cpu_to_le32(IWL_MVM_SHORT_PS_RX_DATA_TIMEOUT);
  387. } else {
  388. cmd->rx_data_timeout =
  389. cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
  390. cmd->tx_data_timeout =
  391. cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
  392. }
  393. if (iwl_mvm_power_allow_uapsd(mvm, vif))
  394. iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
  395. #ifdef CONFIG_IWLWIFI_DEBUGFS
  396. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
  397. cmd->keep_alive_seconds =
  398. cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
  399. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
  400. if (mvmvif->dbgfs_pm.skip_over_dtim)
  401. cmd->flags |=
  402. cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  403. else
  404. cmd->flags &=
  405. cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  406. }
  407. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
  408. cmd->rx_data_timeout =
  409. cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
  410. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
  411. cmd->tx_data_timeout =
  412. cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
  413. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
  414. cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
  415. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
  416. if (mvmvif->dbgfs_pm.lprx_ena)
  417. cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
  418. else
  419. cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
  420. }
  421. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
  422. cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
  423. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
  424. if (mvmvif->dbgfs_pm.snooze_ena)
  425. cmd->flags |=
  426. cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
  427. else
  428. cmd->flags &=
  429. cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
  430. }
  431. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
  432. u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
  433. if (mvmvif->dbgfs_pm.uapsd_misbehaving)
  434. cmd->flags |= cpu_to_le16(flag);
  435. else
  436. cmd->flags &= cpu_to_le16(flag);
  437. }
  438. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  439. }
  440. static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
  441. struct ieee80211_vif *vif)
  442. {
  443. struct iwl_mac_power_cmd cmd = {};
  444. iwl_mvm_power_build_cmd(mvm, vif, &cmd,
  445. mvm->cur_ucode != IWL_UCODE_WOWLAN);
  446. iwl_mvm_power_log(mvm, &cmd);
  447. #ifdef CONFIG_IWLWIFI_DEBUGFS
  448. memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
  449. #endif
  450. return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
  451. sizeof(cmd), &cmd);
  452. }
  453. int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
  454. {
  455. struct iwl_device_power_cmd cmd = {
  456. .flags = 0,
  457. };
  458. if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
  459. mvm->ps_disabled = true;
  460. if (!mvm->ps_disabled)
  461. cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
  462. #ifdef CONFIG_IWLWIFI_DEBUGFS
  463. if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
  464. mvm->disable_power_off)
  465. cmd.flags &=
  466. cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
  467. #endif
  468. IWL_DEBUG_POWER(mvm,
  469. "Sending device power command with flags = 0x%X\n",
  470. cmd.flags);
  471. return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
  472. &cmd);
  473. }
  474. void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  475. {
  476. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  477. if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
  478. ETH_ALEN))
  479. eth_zero_addr(mvmvif->uapsd_misbehaving_bssid);
  480. }
  481. static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
  482. struct ieee80211_vif *vif)
  483. {
  484. u8 *ap_sta_id = _data;
  485. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  486. /* The ap_sta_id is not expected to change during current association
  487. * so no explicit protection is needed
  488. */
  489. if (mvmvif->ap_sta_id == *ap_sta_id)
  490. memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
  491. ETH_ALEN);
  492. }
  493. void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
  494. struct iwl_rx_cmd_buffer *rxb)
  495. {
  496. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  497. struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
  498. u8 ap_sta_id = le32_to_cpu(notif->sta_id);
  499. ieee80211_iterate_active_interfaces_atomic(
  500. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  501. iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
  502. }
  503. struct iwl_power_vifs {
  504. struct iwl_mvm *mvm;
  505. struct ieee80211_vif *bss_vif;
  506. struct ieee80211_vif *p2p_vif;
  507. struct ieee80211_vif *ap_vif;
  508. struct ieee80211_vif *monitor_vif;
  509. bool p2p_active;
  510. bool bss_active;
  511. bool ap_active;
  512. bool monitor_active;
  513. };
  514. static void iwl_mvm_power_disable_pm_iterator(void *_data, u8* mac,
  515. struct ieee80211_vif *vif)
  516. {
  517. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  518. mvmvif->pm_enabled = false;
  519. }
  520. static void iwl_mvm_power_ps_disabled_iterator(void *_data, u8* mac,
  521. struct ieee80211_vif *vif)
  522. {
  523. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  524. bool *disable_ps = _data;
  525. if (mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < NUM_PHY_CTX)
  526. *disable_ps |= mvmvif->ps_disabled;
  527. }
  528. static void iwl_mvm_power_get_vifs_iterator(void *_data, u8 *mac,
  529. struct ieee80211_vif *vif)
  530. {
  531. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  532. struct iwl_power_vifs *power_iterator = _data;
  533. bool active = mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < NUM_PHY_CTX;
  534. switch (ieee80211_vif_type_p2p(vif)) {
  535. case NL80211_IFTYPE_P2P_DEVICE:
  536. break;
  537. case NL80211_IFTYPE_P2P_GO:
  538. case NL80211_IFTYPE_AP:
  539. /* only a single MAC of the same type */
  540. WARN_ON(power_iterator->ap_vif);
  541. power_iterator->ap_vif = vif;
  542. if (active)
  543. power_iterator->ap_active = true;
  544. break;
  545. case NL80211_IFTYPE_MONITOR:
  546. /* only a single MAC of the same type */
  547. WARN_ON(power_iterator->monitor_vif);
  548. power_iterator->monitor_vif = vif;
  549. if (active)
  550. power_iterator->monitor_active = true;
  551. break;
  552. case NL80211_IFTYPE_P2P_CLIENT:
  553. /* only a single MAC of the same type */
  554. WARN_ON(power_iterator->p2p_vif);
  555. power_iterator->p2p_vif = vif;
  556. if (active)
  557. power_iterator->p2p_active = true;
  558. break;
  559. case NL80211_IFTYPE_STATION:
  560. power_iterator->bss_vif = vif;
  561. if (active)
  562. power_iterator->bss_active = true;
  563. break;
  564. default:
  565. break;
  566. }
  567. }
  568. static void iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
  569. struct iwl_power_vifs *vifs)
  570. {
  571. struct iwl_mvm_vif *bss_mvmvif = NULL;
  572. struct iwl_mvm_vif *p2p_mvmvif = NULL;
  573. struct iwl_mvm_vif *ap_mvmvif = NULL;
  574. bool client_same_channel = false;
  575. bool ap_same_channel = false;
  576. lockdep_assert_held(&mvm->mutex);
  577. /* set pm_enable to false */
  578. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  579. IEEE80211_IFACE_ITER_NORMAL,
  580. iwl_mvm_power_disable_pm_iterator,
  581. NULL);
  582. if (vifs->bss_vif)
  583. bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
  584. if (vifs->p2p_vif)
  585. p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
  586. if (vifs->ap_vif)
  587. ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
  588. /* don't allow PM if any TDLS stations exist */
  589. if (iwl_mvm_tdls_sta_count(mvm, NULL))
  590. return;
  591. /* enable PM on bss if bss stand alone */
  592. if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active) {
  593. bss_mvmvif->pm_enabled = true;
  594. return;
  595. }
  596. /* enable PM on p2p if p2p stand alone */
  597. if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active) {
  598. p2p_mvmvif->pm_enabled = true;
  599. return;
  600. }
  601. if (vifs->bss_active && vifs->p2p_active)
  602. client_same_channel = (bss_mvmvif->phy_ctxt->id ==
  603. p2p_mvmvif->phy_ctxt->id);
  604. if (vifs->bss_active && vifs->ap_active)
  605. ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
  606. ap_mvmvif->phy_ctxt->id);
  607. /* clients are not stand alone: enable PM if DCM */
  608. if (!(client_same_channel || ap_same_channel)) {
  609. if (vifs->bss_active)
  610. bss_mvmvif->pm_enabled = true;
  611. if (vifs->p2p_active)
  612. p2p_mvmvif->pm_enabled = true;
  613. return;
  614. }
  615. /*
  616. * There is only one channel in the system and there are only
  617. * bss and p2p clients that share it
  618. */
  619. if (client_same_channel && !vifs->ap_active) {
  620. /* share same channel*/
  621. bss_mvmvif->pm_enabled = true;
  622. p2p_mvmvif->pm_enabled = true;
  623. }
  624. }
  625. #ifdef CONFIG_IWLWIFI_DEBUGFS
  626. int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
  627. struct ieee80211_vif *vif, char *buf,
  628. int bufsz)
  629. {
  630. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  631. struct iwl_mac_power_cmd cmd = {};
  632. int pos = 0;
  633. mutex_lock(&mvm->mutex);
  634. memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
  635. mutex_unlock(&mvm->mutex);
  636. pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
  637. iwlmvm_mod_params.power_scheme);
  638. pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
  639. le16_to_cpu(cmd.flags));
  640. pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
  641. le16_to_cpu(cmd.keep_alive_seconds));
  642. if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
  643. return pos;
  644. pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
  645. (cmd.flags &
  646. cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
  647. pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
  648. cmd.skip_dtim_periods);
  649. if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
  650. pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
  651. le32_to_cpu(cmd.rx_data_timeout));
  652. pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
  653. le32_to_cpu(cmd.tx_data_timeout));
  654. }
  655. if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
  656. pos += scnprintf(buf+pos, bufsz-pos,
  657. "lprx_rssi_threshold = %d\n",
  658. cmd.lprx_rssi_threshold);
  659. if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
  660. return pos;
  661. pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
  662. le32_to_cpu(cmd.rx_data_timeout_uapsd));
  663. pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
  664. le32_to_cpu(cmd.tx_data_timeout_uapsd));
  665. pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
  666. pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
  667. cmd.uapsd_ac_flags);
  668. pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
  669. cmd.uapsd_max_sp);
  670. pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
  671. cmd.heavy_tx_thld_packets);
  672. pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
  673. cmd.heavy_rx_thld_packets);
  674. pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
  675. cmd.heavy_tx_thld_percentage);
  676. pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
  677. cmd.heavy_rx_thld_percentage);
  678. pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
  679. (cmd.flags &
  680. cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
  681. 1 : 0);
  682. if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
  683. return pos;
  684. pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
  685. cmd.snooze_interval);
  686. pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
  687. cmd.snooze_window);
  688. return pos;
  689. }
  690. void
  691. iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
  692. struct iwl_beacon_filter_cmd *cmd)
  693. {
  694. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  695. struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
  696. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
  697. cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
  698. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
  699. cmd->bf_roaming_energy_delta =
  700. cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
  701. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
  702. cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
  703. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
  704. cmd->bf_temp_threshold =
  705. cpu_to_le32(dbgfs_bf->bf_temp_threshold);
  706. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
  707. cmd->bf_temp_fast_filter =
  708. cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
  709. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
  710. cmd->bf_temp_slow_filter =
  711. cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
  712. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
  713. cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
  714. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
  715. cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
  716. if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
  717. cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
  718. if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
  719. cmd->ba_enable_beacon_abort =
  720. cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
  721. }
  722. #endif
  723. static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
  724. struct ieee80211_vif *vif,
  725. struct iwl_beacon_filter_cmd *cmd,
  726. u32 cmd_flags,
  727. bool d0i3)
  728. {
  729. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  730. int ret;
  731. if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
  732. vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  733. return 0;
  734. iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd, d0i3);
  735. if (!d0i3)
  736. iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
  737. ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
  738. /* don't change bf_enabled in case of temporary d0i3 configuration */
  739. if (!ret && !d0i3)
  740. mvmvif->bf_data.bf_enabled = true;
  741. return ret;
  742. }
  743. int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
  744. struct ieee80211_vif *vif,
  745. u32 flags)
  746. {
  747. struct iwl_beacon_filter_cmd cmd = {
  748. IWL_BF_CMD_CONFIG_DEFAULTS,
  749. .bf_enable_beacon_filter = cpu_to_le32(1),
  750. };
  751. return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
  752. }
  753. static int _iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
  754. struct ieee80211_vif *vif,
  755. u32 flags, bool d0i3)
  756. {
  757. struct iwl_beacon_filter_cmd cmd = {};
  758. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  759. int ret;
  760. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  761. return 0;
  762. ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
  763. /* don't change bf_enabled in case of temporary d0i3 configuration */
  764. if (!ret && !d0i3)
  765. mvmvif->bf_data.bf_enabled = false;
  766. return ret;
  767. }
  768. int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
  769. struct ieee80211_vif *vif,
  770. u32 flags)
  771. {
  772. return _iwl_mvm_disable_beacon_filter(mvm, vif, flags, false);
  773. }
  774. static int iwl_mvm_power_set_ps(struct iwl_mvm *mvm)
  775. {
  776. bool disable_ps;
  777. int ret;
  778. /* disable PS if CAM */
  779. disable_ps = (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM);
  780. /* ...or if any of the vifs require PS to be off */
  781. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  782. IEEE80211_IFACE_ITER_NORMAL,
  783. iwl_mvm_power_ps_disabled_iterator,
  784. &disable_ps);
  785. /* update device power state if it has changed */
  786. if (mvm->ps_disabled != disable_ps) {
  787. bool old_ps_disabled = mvm->ps_disabled;
  788. mvm->ps_disabled = disable_ps;
  789. ret = iwl_mvm_power_update_device(mvm);
  790. if (ret) {
  791. mvm->ps_disabled = old_ps_disabled;
  792. return ret;
  793. }
  794. }
  795. return 0;
  796. }
  797. static int iwl_mvm_power_set_ba(struct iwl_mvm *mvm,
  798. struct ieee80211_vif *vif)
  799. {
  800. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  801. struct iwl_beacon_filter_cmd cmd = {
  802. IWL_BF_CMD_CONFIG_DEFAULTS,
  803. .bf_enable_beacon_filter = cpu_to_le32(1),
  804. };
  805. if (!mvmvif->bf_data.bf_enabled)
  806. return 0;
  807. if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
  808. cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
  809. mvmvif->bf_data.ba_enabled = !(!mvmvif->pm_enabled ||
  810. mvm->ps_disabled ||
  811. !vif->bss_conf.ps ||
  812. iwl_mvm_vif_low_latency(mvmvif));
  813. return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
  814. }
  815. int iwl_mvm_power_update_ps(struct iwl_mvm *mvm)
  816. {
  817. struct iwl_power_vifs vifs = {
  818. .mvm = mvm,
  819. };
  820. int ret;
  821. lockdep_assert_held(&mvm->mutex);
  822. /* get vifs info */
  823. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  824. IEEE80211_IFACE_ITER_NORMAL,
  825. iwl_mvm_power_get_vifs_iterator, &vifs);
  826. ret = iwl_mvm_power_set_ps(mvm);
  827. if (ret)
  828. return ret;
  829. if (vifs.bss_vif)
  830. return iwl_mvm_power_set_ba(mvm, vifs.bss_vif);
  831. return 0;
  832. }
  833. int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
  834. {
  835. struct iwl_power_vifs vifs = {
  836. .mvm = mvm,
  837. };
  838. int ret;
  839. lockdep_assert_held(&mvm->mutex);
  840. /* get vifs info */
  841. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  842. IEEE80211_IFACE_ITER_NORMAL,
  843. iwl_mvm_power_get_vifs_iterator, &vifs);
  844. iwl_mvm_power_set_pm(mvm, &vifs);
  845. ret = iwl_mvm_power_set_ps(mvm);
  846. if (ret)
  847. return ret;
  848. if (vifs.bss_vif) {
  849. ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
  850. if (ret)
  851. return ret;
  852. }
  853. if (vifs.p2p_vif) {
  854. ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
  855. if (ret)
  856. return ret;
  857. }
  858. if (vifs.bss_vif)
  859. return iwl_mvm_power_set_ba(mvm, vifs.bss_vif);
  860. return 0;
  861. }
  862. int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
  863. struct ieee80211_vif *vif,
  864. bool enable, u32 flags)
  865. {
  866. int ret;
  867. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  868. struct iwl_mac_power_cmd cmd = {};
  869. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  870. return 0;
  871. if (!vif->bss_conf.assoc)
  872. return 0;
  873. iwl_mvm_power_build_cmd(mvm, vif, &cmd, !enable);
  874. iwl_mvm_power_log(mvm, &cmd);
  875. #ifdef CONFIG_IWLWIFI_DEBUGFS
  876. memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
  877. #endif
  878. ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
  879. sizeof(cmd), &cmd);
  880. if (ret)
  881. return ret;
  882. /* configure beacon filtering */
  883. if (mvmvif != mvm->bf_allowed_vif)
  884. return 0;
  885. if (enable) {
  886. struct iwl_beacon_filter_cmd cmd_bf = {
  887. IWL_BF_CMD_CONFIG_D0I3,
  888. .bf_enable_beacon_filter = cpu_to_le32(1),
  889. };
  890. /*
  891. * When beacon storing is supported - disable beacon filtering
  892. * altogether - the latest beacon will be sent when exiting d0i3
  893. */
  894. if (fw_has_capa(&mvm->fw->ucode_capa,
  895. IWL_UCODE_TLV_CAPA_BEACON_STORING))
  896. ret = _iwl_mvm_disable_beacon_filter(mvm, vif, flags,
  897. true);
  898. else
  899. ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
  900. flags, true);
  901. } else {
  902. if (mvmvif->bf_data.bf_enabled)
  903. ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
  904. else
  905. ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
  906. }
  907. return ret;
  908. }