power.c 30 KB

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