power.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  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. *
  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) 2012 - 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 <linux/kernel.h>
  64. #include <linux/module.h>
  65. #include <linux/slab.h>
  66. #include <net/mac80211.h>
  67. #include "iwl-debug.h"
  68. #include "mvm.h"
  69. #include "iwl-modparams.h"
  70. #include "fw-api-power.h"
  71. #define POWER_KEEP_ALIVE_PERIOD_SEC 25
  72. static
  73. int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
  74. struct iwl_beacon_filter_cmd *cmd,
  75. u32 flags)
  76. {
  77. IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
  78. le32_to_cpu(cmd->ba_enable_beacon_abort));
  79. IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
  80. le32_to_cpu(cmd->ba_escape_timer));
  81. IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
  82. le32_to_cpu(cmd->bf_debug_flag));
  83. IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
  84. le32_to_cpu(cmd->bf_enable_beacon_filter));
  85. IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
  86. le32_to_cpu(cmd->bf_energy_delta));
  87. IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
  88. le32_to_cpu(cmd->bf_escape_timer));
  89. IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
  90. le32_to_cpu(cmd->bf_roaming_energy_delta));
  91. IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
  92. le32_to_cpu(cmd->bf_roaming_state));
  93. IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n",
  94. le32_to_cpu(cmd->bf_temp_threshold));
  95. IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n",
  96. le32_to_cpu(cmd->bf_temp_fast_filter));
  97. IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n",
  98. le32_to_cpu(cmd->bf_temp_slow_filter));
  99. return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags,
  100. sizeof(struct iwl_beacon_filter_cmd), cmd);
  101. }
  102. static
  103. void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
  104. struct ieee80211_vif *vif,
  105. struct iwl_beacon_filter_cmd *cmd)
  106. {
  107. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  108. if (vif->bss_conf.cqm_rssi_thold) {
  109. cmd->bf_energy_delta =
  110. cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
  111. /* fw uses an absolute value for this */
  112. cmd->bf_roaming_state =
  113. cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
  114. }
  115. cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
  116. }
  117. static void iwl_mvm_power_log(struct iwl_mvm *mvm,
  118. struct iwl_mac_power_cmd *cmd)
  119. {
  120. IWL_DEBUG_POWER(mvm,
  121. "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
  122. cmd->id_and_color, iwlmvm_mod_params.power_scheme,
  123. le16_to_cpu(cmd->flags));
  124. IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
  125. le16_to_cpu(cmd->keep_alive_seconds));
  126. if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
  127. IWL_DEBUG_POWER(mvm, "Disable power management\n");
  128. return;
  129. }
  130. IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
  131. le32_to_cpu(cmd->rx_data_timeout));
  132. IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
  133. le32_to_cpu(cmd->tx_data_timeout));
  134. if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
  135. IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
  136. cmd->skip_dtim_periods);
  137. if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
  138. IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
  139. cmd->lprx_rssi_threshold);
  140. if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
  141. IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
  142. IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
  143. le32_to_cpu(cmd->rx_data_timeout_uapsd));
  144. IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
  145. le32_to_cpu(cmd->tx_data_timeout_uapsd));
  146. IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
  147. IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
  148. IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
  149. }
  150. }
  151. static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
  152. struct ieee80211_vif *vif,
  153. struct iwl_mac_power_cmd *cmd)
  154. {
  155. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  156. enum ieee80211_ac_numbers ac;
  157. bool tid_found = false;
  158. for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
  159. if (!mvmvif->queue_params[ac].uapsd)
  160. continue;
  161. if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
  162. cmd->flags |=
  163. cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
  164. cmd->uapsd_ac_flags |= BIT(ac);
  165. /* QNDP TID - the highest TID with no admission control */
  166. if (!tid_found && !mvmvif->queue_params[ac].acm) {
  167. tid_found = true;
  168. switch (ac) {
  169. case IEEE80211_AC_VO:
  170. cmd->qndp_tid = 6;
  171. break;
  172. case IEEE80211_AC_VI:
  173. cmd->qndp_tid = 5;
  174. break;
  175. case IEEE80211_AC_BE:
  176. cmd->qndp_tid = 0;
  177. break;
  178. case IEEE80211_AC_BK:
  179. cmd->qndp_tid = 1;
  180. break;
  181. }
  182. }
  183. }
  184. if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
  185. return;
  186. cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
  187. if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
  188. BIT(IEEE80211_AC_VI) |
  189. BIT(IEEE80211_AC_BE) |
  190. BIT(IEEE80211_AC_BK))) {
  191. cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
  192. cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
  193. cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
  194. cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
  195. cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
  196. }
  197. cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
  198. if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
  199. cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
  200. cmd->rx_data_timeout_uapsd =
  201. cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
  202. cmd->tx_data_timeout_uapsd =
  203. cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
  204. } else {
  205. cmd->rx_data_timeout_uapsd =
  206. cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
  207. cmd->tx_data_timeout_uapsd =
  208. cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
  209. }
  210. if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
  211. cmd->heavy_tx_thld_packets =
  212. IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
  213. cmd->heavy_rx_thld_packets =
  214. IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
  215. } else {
  216. cmd->heavy_tx_thld_packets =
  217. IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
  218. cmd->heavy_rx_thld_packets =
  219. IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
  220. }
  221. cmd->heavy_tx_thld_percentage =
  222. IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
  223. cmd->heavy_rx_thld_percentage =
  224. IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
  225. }
  226. static void iwl_mvm_binding_iterator(void *_data, u8 *mac,
  227. struct ieee80211_vif *vif)
  228. {
  229. unsigned long *data = _data;
  230. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  231. if (!mvmvif->phy_ctxt)
  232. return;
  233. if (vif->type == NL80211_IFTYPE_STATION ||
  234. vif->type == NL80211_IFTYPE_AP)
  235. __set_bit(mvmvif->phy_ctxt->id, data);
  236. }
  237. static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
  238. struct ieee80211_vif *vif)
  239. {
  240. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  241. unsigned long phy_ctxt_counter = 0;
  242. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  243. IEEE80211_IFACE_ITER_NORMAL,
  244. iwl_mvm_binding_iterator,
  245. &phy_ctxt_counter);
  246. if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
  247. ETH_ALEN))
  248. return false;
  249. if (vif->p2p &&
  250. !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD))
  251. return false;
  252. /*
  253. * Avoid using uAPSD if P2P client is associated to GO that uses
  254. * opportunistic power save. This is due to current FW limitation.
  255. */
  256. if (vif->p2p &&
  257. (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
  258. IEEE80211_P2P_OPPPS_ENABLE_BIT))
  259. return false;
  260. /*
  261. * Avoid using uAPSD if client is in DCM -
  262. * low latency issue in Miracast
  263. */
  264. if (hweight8(phy_ctxt_counter) >= 2)
  265. return false;
  266. return true;
  267. }
  268. static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
  269. struct ieee80211_vif *vif,
  270. struct iwl_mac_power_cmd *cmd)
  271. {
  272. struct ieee80211_hw *hw = mvm->hw;
  273. struct ieee80211_chanctx_conf *chanctx_conf;
  274. struct ieee80211_channel *chan;
  275. int dtimper, dtimper_msec;
  276. int keep_alive;
  277. bool radar_detect = false;
  278. struct iwl_mvm_vif *mvmvif __maybe_unused =
  279. iwl_mvm_vif_from_mac80211(vif);
  280. cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
  281. mvmvif->color));
  282. dtimper = hw->conf.ps_dtim_period ?: 1;
  283. /*
  284. * Regardless of power management state the driver must set
  285. * keep alive period. FW will use it for sending keep alive NDPs
  286. * immediately after association. Check that keep alive period
  287. * is at least 3 * DTIM
  288. */
  289. dtimper_msec = dtimper * vif->bss_conf.beacon_int;
  290. keep_alive = max_t(int, 3 * dtimper_msec,
  291. MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
  292. keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
  293. cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
  294. if (mvm->ps_disabled)
  295. return;
  296. cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
  297. if (!vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif) ||
  298. !mvmvif->pm_enabled)
  299. return;
  300. cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
  301. if (vif->bss_conf.beacon_rate &&
  302. (vif->bss_conf.beacon_rate->bitrate == 10 ||
  303. vif->bss_conf.beacon_rate->bitrate == 60)) {
  304. cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
  305. cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
  306. }
  307. /* Check if radar detection is required on current channel */
  308. rcu_read_lock();
  309. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  310. WARN_ON(!chanctx_conf);
  311. if (chanctx_conf) {
  312. chan = chanctx_conf->def.chan;
  313. radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
  314. }
  315. rcu_read_unlock();
  316. /* Check skip over DTIM conditions */
  317. if (!radar_detect && (dtimper <= 10) &&
  318. (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
  319. mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
  320. cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  321. cmd->skip_dtim_periods = 3;
  322. }
  323. if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
  324. cmd->rx_data_timeout =
  325. cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
  326. cmd->tx_data_timeout =
  327. cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
  328. } else {
  329. cmd->rx_data_timeout =
  330. cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
  331. cmd->tx_data_timeout =
  332. cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
  333. }
  334. if (iwl_mvm_power_allow_uapsd(mvm, vif))
  335. iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
  336. #ifdef CONFIG_IWLWIFI_DEBUGFS
  337. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
  338. cmd->keep_alive_seconds =
  339. cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
  340. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
  341. if (mvmvif->dbgfs_pm.skip_over_dtim)
  342. cmd->flags |=
  343. cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  344. else
  345. cmd->flags &=
  346. cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  347. }
  348. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
  349. cmd->rx_data_timeout =
  350. cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
  351. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
  352. cmd->tx_data_timeout =
  353. cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
  354. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
  355. cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
  356. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
  357. if (mvmvif->dbgfs_pm.lprx_ena)
  358. cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
  359. else
  360. cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
  361. }
  362. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
  363. cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
  364. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
  365. if (mvmvif->dbgfs_pm.snooze_ena)
  366. cmd->flags |=
  367. cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
  368. else
  369. cmd->flags &=
  370. cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
  371. }
  372. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
  373. u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
  374. if (mvmvif->dbgfs_pm.uapsd_misbehaving)
  375. cmd->flags |= cpu_to_le16(flag);
  376. else
  377. cmd->flags &= cpu_to_le16(flag);
  378. }
  379. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  380. }
  381. static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
  382. struct ieee80211_vif *vif)
  383. {
  384. struct iwl_mac_power_cmd cmd = {};
  385. iwl_mvm_power_build_cmd(mvm, vif, &cmd);
  386. iwl_mvm_power_log(mvm, &cmd);
  387. #ifdef CONFIG_IWLWIFI_DEBUGFS
  388. memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
  389. #endif
  390. return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
  391. sizeof(cmd), &cmd);
  392. }
  393. int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
  394. {
  395. struct iwl_device_power_cmd cmd = {
  396. .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK),
  397. };
  398. if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
  399. mvm->ps_disabled = true;
  400. if (mvm->ps_disabled)
  401. cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK);
  402. #ifdef CONFIG_IWLWIFI_DEBUGFS
  403. if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
  404. mvm->disable_power_off)
  405. cmd.flags &=
  406. cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
  407. #endif
  408. IWL_DEBUG_POWER(mvm,
  409. "Sending device power command with flags = 0x%X\n",
  410. cmd.flags);
  411. return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
  412. &cmd);
  413. }
  414. void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  415. {
  416. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  417. if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
  418. ETH_ALEN))
  419. memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN);
  420. }
  421. static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
  422. struct ieee80211_vif *vif)
  423. {
  424. u8 *ap_sta_id = _data;
  425. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  426. /* The ap_sta_id is not expected to change during current association
  427. * so no explicit protection is needed
  428. */
  429. if (mvmvif->ap_sta_id == *ap_sta_id)
  430. memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
  431. ETH_ALEN);
  432. }
  433. int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
  434. struct iwl_rx_cmd_buffer *rxb,
  435. struct iwl_device_cmd *cmd)
  436. {
  437. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  438. struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
  439. u8 ap_sta_id = le32_to_cpu(notif->sta_id);
  440. ieee80211_iterate_active_interfaces_atomic(
  441. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  442. iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
  443. return 0;
  444. }
  445. struct iwl_power_vifs {
  446. struct ieee80211_vif *bf_vif;
  447. struct ieee80211_vif *bss_vif;
  448. struct ieee80211_vif *p2p_vif;
  449. struct ieee80211_vif *ap_vif;
  450. struct ieee80211_vif *monitor_vif;
  451. bool p2p_active;
  452. bool bss_active;
  453. bool ap_active;
  454. bool monitor_active;
  455. };
  456. static void iwl_mvm_power_iterator(void *_data, u8 *mac,
  457. struct ieee80211_vif *vif)
  458. {
  459. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  460. struct iwl_power_vifs *power_iterator = _data;
  461. mvmvif->pm_enabled = false;
  462. switch (ieee80211_vif_type_p2p(vif)) {
  463. case NL80211_IFTYPE_P2P_DEVICE:
  464. break;
  465. case NL80211_IFTYPE_P2P_GO:
  466. case NL80211_IFTYPE_AP:
  467. /* only a single MAC of the same type */
  468. WARN_ON(power_iterator->ap_vif);
  469. power_iterator->ap_vif = vif;
  470. if (mvmvif->phy_ctxt)
  471. if (mvmvif->phy_ctxt->id < MAX_PHYS)
  472. power_iterator->ap_active = true;
  473. break;
  474. case NL80211_IFTYPE_MONITOR:
  475. /* only a single MAC of the same type */
  476. WARN_ON(power_iterator->monitor_vif);
  477. power_iterator->monitor_vif = vif;
  478. if (mvmvif->phy_ctxt)
  479. if (mvmvif->phy_ctxt->id < MAX_PHYS)
  480. power_iterator->monitor_active = true;
  481. break;
  482. case NL80211_IFTYPE_P2P_CLIENT:
  483. /* only a single MAC of the same type */
  484. WARN_ON(power_iterator->p2p_vif);
  485. power_iterator->p2p_vif = vif;
  486. if (mvmvif->phy_ctxt)
  487. if (mvmvif->phy_ctxt->id < MAX_PHYS)
  488. power_iterator->p2p_active = true;
  489. break;
  490. case NL80211_IFTYPE_STATION:
  491. /* only a single MAC of the same type */
  492. WARN_ON(power_iterator->bss_vif);
  493. power_iterator->bss_vif = vif;
  494. if (mvmvif->phy_ctxt)
  495. if (mvmvif->phy_ctxt->id < MAX_PHYS)
  496. power_iterator->bss_active = true;
  497. if (mvmvif->bf_data.bf_enabled &&
  498. !WARN_ON(power_iterator->bf_vif))
  499. power_iterator->bf_vif = vif;
  500. break;
  501. default:
  502. break;
  503. }
  504. }
  505. static void
  506. iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
  507. struct iwl_power_vifs *vifs)
  508. {
  509. struct iwl_mvm_vif *bss_mvmvif = NULL;
  510. struct iwl_mvm_vif *p2p_mvmvif = NULL;
  511. struct iwl_mvm_vif *ap_mvmvif = NULL;
  512. bool client_same_channel = false;
  513. bool ap_same_channel = false;
  514. lockdep_assert_held(&mvm->mutex);
  515. /* get vifs info + set pm_enable to false */
  516. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  517. IEEE80211_IFACE_ITER_NORMAL,
  518. iwl_mvm_power_iterator, vifs);
  519. if (vifs->bss_vif)
  520. bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
  521. if (vifs->p2p_vif)
  522. p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
  523. if (vifs->ap_vif)
  524. ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
  525. /* enable PM on bss if bss stand alone */
  526. if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active) {
  527. bss_mvmvif->pm_enabled = true;
  528. return;
  529. }
  530. /* enable PM on p2p if p2p stand alone */
  531. if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active) {
  532. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
  533. p2p_mvmvif->pm_enabled = true;
  534. return;
  535. }
  536. if (vifs->bss_active && vifs->p2p_active)
  537. client_same_channel = (bss_mvmvif->phy_ctxt->id ==
  538. p2p_mvmvif->phy_ctxt->id);
  539. if (vifs->bss_active && vifs->ap_active)
  540. ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
  541. ap_mvmvif->phy_ctxt->id);
  542. /* clients are not stand alone: enable PM if DCM */
  543. if (!(client_same_channel || ap_same_channel) &&
  544. (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) {
  545. if (vifs->bss_active)
  546. bss_mvmvif->pm_enabled = true;
  547. if (vifs->p2p_active &&
  548. (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM))
  549. p2p_mvmvif->pm_enabled = true;
  550. return;
  551. }
  552. /*
  553. * There is only one channel in the system and there are only
  554. * bss and p2p clients that share it
  555. */
  556. if (client_same_channel && !vifs->ap_active &&
  557. (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) {
  558. /* share same channel*/
  559. bss_mvmvif->pm_enabled = true;
  560. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
  561. p2p_mvmvif->pm_enabled = true;
  562. }
  563. }
  564. #ifdef CONFIG_IWLWIFI_DEBUGFS
  565. int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
  566. struct ieee80211_vif *vif, char *buf,
  567. int bufsz)
  568. {
  569. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  570. struct iwl_mac_power_cmd cmd = {};
  571. int pos = 0;
  572. mutex_lock(&mvm->mutex);
  573. memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
  574. mutex_unlock(&mvm->mutex);
  575. pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
  576. iwlmvm_mod_params.power_scheme);
  577. pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
  578. le16_to_cpu(cmd.flags));
  579. pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
  580. le16_to_cpu(cmd.keep_alive_seconds));
  581. if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
  582. return pos;
  583. pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
  584. (cmd.flags &
  585. cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
  586. pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
  587. cmd.skip_dtim_periods);
  588. if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
  589. pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
  590. le32_to_cpu(cmd.rx_data_timeout));
  591. pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
  592. le32_to_cpu(cmd.tx_data_timeout));
  593. }
  594. if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
  595. pos += scnprintf(buf+pos, bufsz-pos,
  596. "lprx_rssi_threshold = %d\n",
  597. cmd.lprx_rssi_threshold);
  598. if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
  599. return pos;
  600. pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
  601. le32_to_cpu(cmd.rx_data_timeout_uapsd));
  602. pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
  603. le32_to_cpu(cmd.tx_data_timeout_uapsd));
  604. pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
  605. pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
  606. cmd.uapsd_ac_flags);
  607. pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
  608. cmd.uapsd_max_sp);
  609. pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
  610. cmd.heavy_tx_thld_packets);
  611. pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
  612. cmd.heavy_rx_thld_packets);
  613. pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
  614. cmd.heavy_tx_thld_percentage);
  615. pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
  616. cmd.heavy_rx_thld_percentage);
  617. pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
  618. (cmd.flags &
  619. cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
  620. 1 : 0);
  621. if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
  622. return pos;
  623. pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
  624. cmd.snooze_interval);
  625. pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
  626. cmd.snooze_window);
  627. return pos;
  628. }
  629. void
  630. iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
  631. struct iwl_beacon_filter_cmd *cmd)
  632. {
  633. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  634. struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
  635. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
  636. cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
  637. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
  638. cmd->bf_roaming_energy_delta =
  639. cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
  640. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
  641. cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
  642. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
  643. cmd->bf_temp_threshold =
  644. cpu_to_le32(dbgfs_bf->bf_temp_threshold);
  645. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
  646. cmd->bf_temp_fast_filter =
  647. cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
  648. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
  649. cmd->bf_temp_slow_filter =
  650. cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
  651. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
  652. cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
  653. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
  654. cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
  655. if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
  656. cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
  657. if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
  658. cmd->ba_enable_beacon_abort =
  659. cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
  660. }
  661. #endif
  662. static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
  663. struct ieee80211_vif *vif,
  664. struct iwl_beacon_filter_cmd *cmd,
  665. u32 cmd_flags,
  666. bool d0i3)
  667. {
  668. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  669. int ret;
  670. if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
  671. vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  672. return 0;
  673. iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd);
  674. if (!d0i3)
  675. iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
  676. ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
  677. /* don't change bf_enabled in case of temporary d0i3 configuration */
  678. if (!ret && !d0i3)
  679. mvmvif->bf_data.bf_enabled = true;
  680. return ret;
  681. }
  682. int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
  683. struct ieee80211_vif *vif,
  684. u32 flags)
  685. {
  686. struct iwl_beacon_filter_cmd cmd = {
  687. IWL_BF_CMD_CONFIG_DEFAULTS,
  688. .bf_enable_beacon_filter = cpu_to_le32(1),
  689. };
  690. return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
  691. }
  692. static int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
  693. struct ieee80211_vif *vif,
  694. bool enable)
  695. {
  696. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  697. struct iwl_beacon_filter_cmd cmd = {
  698. IWL_BF_CMD_CONFIG_DEFAULTS,
  699. .bf_enable_beacon_filter = cpu_to_le32(1),
  700. };
  701. if (!mvmvif->bf_data.bf_enabled)
  702. return 0;
  703. if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
  704. cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
  705. mvmvif->bf_data.ba_enabled = enable;
  706. return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
  707. }
  708. int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
  709. struct ieee80211_vif *vif,
  710. u32 flags)
  711. {
  712. struct iwl_beacon_filter_cmd cmd = {};
  713. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  714. int ret;
  715. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  716. return 0;
  717. ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
  718. if (!ret)
  719. mvmvif->bf_data.bf_enabled = false;
  720. return ret;
  721. }
  722. int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
  723. {
  724. struct iwl_mvm_vif *mvmvif;
  725. struct iwl_power_vifs vifs = {};
  726. bool ba_enable;
  727. int ret;
  728. lockdep_assert_held(&mvm->mutex);
  729. iwl_mvm_power_set_pm(mvm, &vifs);
  730. /* disable PS if CAM */
  731. if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) {
  732. mvm->ps_disabled = true;
  733. } else {
  734. /* don't update device power state unless we add / remove monitor */
  735. if (vifs.monitor_vif) {
  736. if (vifs.monitor_active)
  737. mvm->ps_disabled = true;
  738. ret = iwl_mvm_power_update_device(mvm);
  739. if (ret)
  740. return ret;
  741. }
  742. }
  743. if (vifs.bss_vif) {
  744. ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
  745. if (ret)
  746. return ret;
  747. }
  748. if (vifs.p2p_vif) {
  749. ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
  750. if (ret)
  751. return ret;
  752. }
  753. if (!vifs.bf_vif)
  754. return 0;
  755. mvmvif = iwl_mvm_vif_from_mac80211(vifs.bf_vif);
  756. ba_enable = !(!mvmvif->pm_enabled || mvm->ps_disabled ||
  757. !vifs.bf_vif->bss_conf.ps ||
  758. iwl_mvm_vif_low_latency(mvmvif));
  759. return iwl_mvm_update_beacon_abort(mvm, vifs.bf_vif, ba_enable);
  760. }
  761. int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
  762. struct ieee80211_vif *vif,
  763. bool enable, u32 flags)
  764. {
  765. int ret;
  766. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  767. struct iwl_mac_power_cmd cmd = {};
  768. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  769. return 0;
  770. if (!vif->bss_conf.assoc)
  771. return 0;
  772. iwl_mvm_power_build_cmd(mvm, vif, &cmd);
  773. if (enable) {
  774. /* configure skip over dtim up to 300 msec */
  775. int dtimper = mvm->hw->conf.ps_dtim_period ?: 1;
  776. int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
  777. if (WARN_ON(!dtimper_msec))
  778. return 0;
  779. cmd.skip_dtim_periods = 300 / dtimper_msec;
  780. if (cmd.skip_dtim_periods)
  781. cmd.flags |=
  782. cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  783. }
  784. iwl_mvm_power_log(mvm, &cmd);
  785. #ifdef CONFIG_IWLWIFI_DEBUGFS
  786. memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
  787. #endif
  788. ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
  789. sizeof(cmd), &cmd);
  790. if (ret)
  791. return ret;
  792. /* configure beacon filtering */
  793. if (mvmvif != mvm->bf_allowed_vif)
  794. return 0;
  795. if (enable) {
  796. struct iwl_beacon_filter_cmd cmd_bf = {
  797. IWL_BF_CMD_CONFIG_D0I3,
  798. .bf_enable_beacon_filter = cpu_to_le32(1),
  799. };
  800. ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
  801. flags, true);
  802. } else {
  803. if (mvmvif->bf_data.bf_enabled)
  804. ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
  805. else
  806. ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
  807. }
  808. return ret;
  809. }