power.c 31 KB

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