power.c 31 KB

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