power.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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 - 2013 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <linux/kernel.h>
  64. #include <linux/module.h>
  65. #include <linux/slab.h>
  66. #include <linux/init.h>
  67. #include <net/mac80211.h>
  68. #include "iwl-debug.h"
  69. #include "mvm.h"
  70. #include "iwl-modparams.h"
  71. #include "fw-api-power.h"
  72. #define POWER_KEEP_ALIVE_PERIOD_SEC 25
  73. int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
  74. struct iwl_beacon_filter_cmd *cmd)
  75. {
  76. int ret;
  77. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, CMD_SYNC,
  78. sizeof(struct iwl_beacon_filter_cmd), cmd);
  79. if (!ret) {
  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. }
  103. return ret;
  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. int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
  121. struct ieee80211_vif *vif, bool enable)
  122. {
  123. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  124. struct iwl_beacon_filter_cmd cmd = {
  125. IWL_BF_CMD_CONFIG_DEFAULTS,
  126. .bf_enable_beacon_filter = cpu_to_le32(1),
  127. .ba_enable_beacon_abort = cpu_to_le32(enable),
  128. };
  129. if (!mvmvif->bf_data.bf_enabled)
  130. return 0;
  131. if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
  132. cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
  133. mvmvif->bf_data.ba_enabled = enable;
  134. iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
  135. iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
  136. return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
  137. }
  138. static void iwl_mvm_power_log(struct iwl_mvm *mvm,
  139. struct iwl_mac_power_cmd *cmd)
  140. {
  141. IWL_DEBUG_POWER(mvm,
  142. "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
  143. cmd->id_and_color, iwlmvm_mod_params.power_scheme,
  144. le16_to_cpu(cmd->flags));
  145. IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
  146. le16_to_cpu(cmd->keep_alive_seconds));
  147. if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
  148. IWL_DEBUG_POWER(mvm, "Disable power management\n");
  149. return;
  150. }
  151. IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
  152. le32_to_cpu(cmd->rx_data_timeout));
  153. IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
  154. le32_to_cpu(cmd->tx_data_timeout));
  155. if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
  156. IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
  157. cmd->skip_dtim_periods);
  158. if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
  159. IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
  160. cmd->lprx_rssi_threshold);
  161. if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
  162. IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
  163. IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
  164. le32_to_cpu(cmd->rx_data_timeout_uapsd));
  165. IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
  166. le32_to_cpu(cmd->tx_data_timeout_uapsd));
  167. IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
  168. IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
  169. IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
  170. }
  171. }
  172. static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
  173. struct ieee80211_vif *vif,
  174. struct iwl_mac_power_cmd *cmd)
  175. {
  176. struct ieee80211_hw *hw = mvm->hw;
  177. struct ieee80211_chanctx_conf *chanctx_conf;
  178. struct ieee80211_channel *chan;
  179. int dtimper, dtimper_msec;
  180. int keep_alive;
  181. bool radar_detect = false;
  182. struct iwl_mvm_vif *mvmvif __maybe_unused =
  183. iwl_mvm_vif_from_mac80211(vif);
  184. enum ieee80211_ac_numbers ac;
  185. bool tid_found = false;
  186. cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
  187. mvmvif->color));
  188. dtimper = hw->conf.ps_dtim_period ?: 1;
  189. /*
  190. * Regardless of power management state the driver must set
  191. * keep alive period. FW will use it for sending keep alive NDPs
  192. * immediately after association. Check that keep alive period
  193. * is at least 3 * DTIM
  194. */
  195. dtimper_msec = dtimper * vif->bss_conf.beacon_int;
  196. keep_alive = max_t(int, 3 * dtimper_msec,
  197. MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
  198. keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
  199. cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
  200. if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
  201. return;
  202. cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
  203. #ifdef CONFIG_IWLWIFI_DEBUGFS
  204. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
  205. mvmvif->dbgfs_pm.disable_power_off)
  206. cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
  207. #endif
  208. if (!vif->bss_conf.ps)
  209. return;
  210. cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
  211. if (vif->bss_conf.beacon_rate &&
  212. (vif->bss_conf.beacon_rate->bitrate == 10 ||
  213. vif->bss_conf.beacon_rate->bitrate == 60)) {
  214. cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
  215. cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
  216. }
  217. /* Check if radar detection is required on current channel */
  218. rcu_read_lock();
  219. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  220. WARN_ON(!chanctx_conf);
  221. if (chanctx_conf) {
  222. chan = chanctx_conf->def.chan;
  223. radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
  224. }
  225. rcu_read_unlock();
  226. /* Check skip over DTIM conditions */
  227. if (!radar_detect && (dtimper <= 10) &&
  228. (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
  229. mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
  230. cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  231. cmd->skip_dtim_periods = 3;
  232. }
  233. if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
  234. cmd->rx_data_timeout =
  235. cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
  236. cmd->tx_data_timeout =
  237. cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
  238. } else {
  239. cmd->rx_data_timeout =
  240. cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
  241. cmd->tx_data_timeout =
  242. cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
  243. }
  244. for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
  245. if (!mvmvif->queue_params[ac].uapsd)
  246. continue;
  247. if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
  248. cmd->flags |=
  249. cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
  250. cmd->uapsd_ac_flags |= BIT(ac);
  251. /* QNDP TID - the highest TID with no admission control */
  252. if (!tid_found && !mvmvif->queue_params[ac].acm) {
  253. tid_found = true;
  254. switch (ac) {
  255. case IEEE80211_AC_VO:
  256. cmd->qndp_tid = 6;
  257. break;
  258. case IEEE80211_AC_VI:
  259. cmd->qndp_tid = 5;
  260. break;
  261. case IEEE80211_AC_BE:
  262. cmd->qndp_tid = 0;
  263. break;
  264. case IEEE80211_AC_BK:
  265. cmd->qndp_tid = 1;
  266. break;
  267. }
  268. }
  269. }
  270. if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
  271. cmd->rx_data_timeout_uapsd =
  272. cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
  273. cmd->tx_data_timeout_uapsd =
  274. cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
  275. if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
  276. BIT(IEEE80211_AC_VI) |
  277. BIT(IEEE80211_AC_BE) |
  278. BIT(IEEE80211_AC_BK))) {
  279. cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
  280. cmd->snooze_interval =
  281. cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
  282. cmd->snooze_window =
  283. (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
  284. cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
  285. cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
  286. }
  287. cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
  288. cmd->heavy_tx_thld_packets =
  289. IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
  290. cmd->heavy_rx_thld_packets =
  291. IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
  292. cmd->heavy_tx_thld_percentage =
  293. IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
  294. cmd->heavy_rx_thld_percentage =
  295. IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
  296. }
  297. #ifdef CONFIG_IWLWIFI_DEBUGFS
  298. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
  299. cmd->keep_alive_seconds =
  300. cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
  301. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
  302. if (mvmvif->dbgfs_pm.skip_over_dtim)
  303. cmd->flags |=
  304. cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  305. else
  306. cmd->flags &=
  307. cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
  308. }
  309. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
  310. cmd->rx_data_timeout =
  311. cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
  312. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
  313. cmd->tx_data_timeout =
  314. cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
  315. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
  316. cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
  317. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
  318. if (mvmvif->dbgfs_pm.lprx_ena)
  319. cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
  320. else
  321. cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
  322. }
  323. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
  324. cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
  325. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
  326. if (mvmvif->dbgfs_pm.snooze_ena)
  327. cmd->flags |=
  328. cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
  329. else
  330. cmd->flags &=
  331. cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
  332. }
  333. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  334. }
  335. static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm,
  336. struct ieee80211_vif *vif)
  337. {
  338. int ret;
  339. bool ba_enable;
  340. struct iwl_mac_power_cmd cmd = {};
  341. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  342. return 0;
  343. /*
  344. * TODO: The following vif_count verification is temporary condition.
  345. * Avoid power mode update if more than one interface is currently
  346. * active. Remove this condition when FW will support power management
  347. * on multiple MACs.
  348. */
  349. IWL_DEBUG_POWER(mvm, "Currently %d interfaces active\n",
  350. mvm->vif_count);
  351. if (mvm->vif_count > 1)
  352. return 0;
  353. iwl_mvm_power_build_cmd(mvm, vif, &cmd);
  354. iwl_mvm_power_log(mvm, &cmd);
  355. ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC,
  356. sizeof(cmd), &cmd);
  357. if (ret)
  358. return ret;
  359. ba_enable = !!(cmd.flags &
  360. cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK));
  361. return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable);
  362. }
  363. static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm,
  364. struct ieee80211_vif *vif)
  365. {
  366. struct iwl_mac_power_cmd cmd = {};
  367. struct iwl_mvm_vif *mvmvif __maybe_unused =
  368. iwl_mvm_vif_from_mac80211(vif);
  369. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  370. return 0;
  371. cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
  372. mvmvif->color));
  373. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
  374. cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
  375. #ifdef CONFIG_IWLWIFI_DEBUGFS
  376. if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
  377. mvmvif->dbgfs_pm.disable_power_off)
  378. cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
  379. #endif
  380. iwl_mvm_power_log(mvm, &cmd);
  381. return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_ASYNC,
  382. sizeof(cmd), &cmd);
  383. }
  384. #ifdef CONFIG_IWLWIFI_DEBUGFS
  385. static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
  386. struct ieee80211_vif *vif, char *buf,
  387. int bufsz)
  388. {
  389. struct iwl_mac_power_cmd cmd = {};
  390. int pos = 0;
  391. iwl_mvm_power_build_cmd(mvm, vif, &cmd);
  392. pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n",
  393. (cmd.flags &
  394. cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ?
  395. 0 : 1);
  396. pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
  397. iwlmvm_mod_params.power_scheme);
  398. pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
  399. le16_to_cpu(cmd.flags));
  400. pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
  401. le16_to_cpu(cmd.keep_alive_seconds));
  402. if (cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) {
  403. pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
  404. (cmd.flags &
  405. cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ?
  406. 1 : 0);
  407. pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
  408. cmd.skip_dtim_periods);
  409. if (!(cmd.flags &
  410. cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
  411. pos += scnprintf(buf+pos, bufsz-pos,
  412. "rx_data_timeout = %d\n",
  413. le32_to_cpu(cmd.rx_data_timeout));
  414. pos += scnprintf(buf+pos, bufsz-pos,
  415. "tx_data_timeout = %d\n",
  416. le32_to_cpu(cmd.tx_data_timeout));
  417. }
  418. if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
  419. pos += scnprintf(buf+pos, bufsz-pos,
  420. "lprx_rssi_threshold = %d\n",
  421. cmd.lprx_rssi_threshold);
  422. if (cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
  423. pos +=
  424. scnprintf(buf+pos, bufsz-pos,
  425. "rx_data_timeout_uapsd = %d\n",
  426. le32_to_cpu(cmd.rx_data_timeout_uapsd));
  427. pos +=
  428. scnprintf(buf+pos, bufsz-pos,
  429. "tx_data_timeout_uapsd = %d\n",
  430. le32_to_cpu(cmd.tx_data_timeout_uapsd));
  431. pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n",
  432. cmd.qndp_tid);
  433. pos += scnprintf(buf+pos, bufsz-pos,
  434. "uapsd_ac_flags = 0x%x\n",
  435. cmd.uapsd_ac_flags);
  436. pos += scnprintf(buf+pos, bufsz-pos,
  437. "uapsd_max_sp = %d\n",
  438. cmd.uapsd_max_sp);
  439. pos += scnprintf(buf+pos, bufsz-pos,
  440. "heavy_tx_thld_packets = %d\n",
  441. cmd.heavy_tx_thld_packets);
  442. pos += scnprintf(buf+pos, bufsz-pos,
  443. "heavy_rx_thld_packets = %d\n",
  444. cmd.heavy_rx_thld_packets);
  445. pos += scnprintf(buf+pos, bufsz-pos,
  446. "heavy_tx_thld_percentage = %d\n",
  447. cmd.heavy_tx_thld_percentage);
  448. pos += scnprintf(buf+pos, bufsz-pos,
  449. "heavy_rx_thld_percentage = %d\n",
  450. cmd.heavy_rx_thld_percentage);
  451. pos +=
  452. scnprintf(buf+pos, bufsz-pos, "snooze_enable = %d\n",
  453. (cmd.flags &
  454. cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) ?
  455. 1 : 0);
  456. }
  457. if (cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
  458. pos += scnprintf(buf+pos, bufsz-pos,
  459. "snooze_interval = %d\n",
  460. cmd.snooze_interval);
  461. pos += scnprintf(buf+pos, bufsz-pos,
  462. "snooze_window = %d\n",
  463. cmd.snooze_window);
  464. }
  465. }
  466. return pos;
  467. }
  468. void
  469. iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
  470. struct iwl_beacon_filter_cmd *cmd)
  471. {
  472. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  473. struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
  474. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
  475. cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
  476. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
  477. cmd->bf_roaming_energy_delta =
  478. cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
  479. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
  480. cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
  481. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
  482. cmd->bf_temp_threshold =
  483. cpu_to_le32(dbgfs_bf->bf_temp_threshold);
  484. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
  485. cmd->bf_temp_fast_filter =
  486. cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
  487. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
  488. cmd->bf_temp_slow_filter =
  489. cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
  490. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
  491. cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
  492. if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
  493. cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
  494. if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
  495. cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
  496. if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
  497. cmd->ba_enable_beacon_abort =
  498. cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
  499. }
  500. #endif
  501. int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
  502. struct ieee80211_vif *vif)
  503. {
  504. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  505. struct iwl_beacon_filter_cmd cmd = {
  506. IWL_BF_CMD_CONFIG_DEFAULTS,
  507. .bf_enable_beacon_filter = cpu_to_le32(1),
  508. };
  509. int ret;
  510. if (mvmvif != mvm->bf_allowed_vif ||
  511. vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  512. return 0;
  513. iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
  514. iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
  515. ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
  516. if (!ret)
  517. mvmvif->bf_data.bf_enabled = true;
  518. return ret;
  519. }
  520. int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
  521. struct ieee80211_vif *vif)
  522. {
  523. struct iwl_beacon_filter_cmd cmd = {};
  524. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  525. int ret;
  526. if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) ||
  527. vif->type != NL80211_IFTYPE_STATION || vif->p2p)
  528. return 0;
  529. ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
  530. if (!ret)
  531. mvmvif->bf_data.bf_enabled = false;
  532. return ret;
  533. }
  534. int iwl_mvm_update_beacon_filter(struct iwl_mvm *mvm,
  535. struct ieee80211_vif *vif)
  536. {
  537. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  538. if (!mvmvif->bf_data.bf_enabled)
  539. return 0;
  540. return iwl_mvm_enable_beacon_filter(mvm, vif);
  541. }
  542. const struct iwl_mvm_power_ops pm_mac_ops = {
  543. .power_update_mode = iwl_mvm_power_mac_update_mode,
  544. .power_disable = iwl_mvm_power_mac_disable,
  545. #ifdef CONFIG_IWLWIFI_DEBUGFS
  546. .power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read,
  547. #endif
  548. };