power.c 31 KB

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