power.c 31 KB

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