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