Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 1f44780 | 2010-01-15 13:43:41 -0800 | [diff] [blame] | 3 | * Copyright(c) 2007 - 2010 Intel Corporation. All rights reserved. |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | *****************************************************************************/ |
| 28 | |
| 29 | |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 33 | #include <linux/init.h> |
| 34 | |
| 35 | #include <net/mac80211.h> |
| 36 | |
| 37 | #include "iwl-eeprom.h" |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 38 | #include "iwl-dev.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 39 | #include "iwl-core.h" |
Wey-Yi Guy | 39b73fb | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 40 | #include "iwl-io.h" |
Tomas Winkler | 5a36ba0 | 2008-04-24 11:55:37 -0700 | [diff] [blame] | 41 | #include "iwl-commands.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 42 | #include "iwl-debug.h" |
| 43 | #include "iwl-power.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 44 | |
| 45 | /* |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 46 | * Setting power level allows the card to go to sleep when not busy. |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 47 | * |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 48 | * We calculate a sleep command based on the required latency, which |
| 49 | * we get from mac80211. In order to handle thermal throttling, we can |
| 50 | * also use pre-defined power levels. |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 51 | */ |
| 52 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 53 | /* |
| 54 | * For now, keep using power level 1 instead of automatically |
| 55 | * adjusting ... |
| 56 | */ |
| 57 | bool no_sleep_autoadjust = true; |
| 58 | module_param(no_sleep_autoadjust, bool, S_IRUGO); |
| 59 | MODULE_PARM_DESC(no_sleep_autoadjust, |
| 60 | "don't automatically adjust sleep level " |
| 61 | "according to maximum network latency"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 62 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 63 | /* |
| 64 | * This defines the old power levels. They are still used by default |
| 65 | * (level 1) and for thermal throttle (levels 3 through 5) |
| 66 | */ |
| 67 | |
| 68 | struct iwl_power_vec_entry { |
| 69 | struct iwl_powertable_cmd cmd; |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 70 | u8 no_dtim; /* number of skip dtim */ |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | #define IWL_DTIM_RANGE_0_MAX 2 |
| 74 | #define IWL_DTIM_RANGE_1_MAX 10 |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 75 | |
Johannes Berg | 7af2c46 | 2009-05-08 13:44:38 -0700 | [diff] [blame] | 76 | #define NOSLP cpu_to_le16(0), 0, 0 |
| 77 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
| 78 | #define TU_TO_USEC 1024 |
| 79 | #define SLP_TOUT(T) cpu_to_le32((T) * TU_TO_USEC) |
| 80 | #define SLP_VEC(X0, X1, X2, X3, X4) {cpu_to_le32(X0), \ |
| 81 | cpu_to_le32(X1), \ |
| 82 | cpu_to_le32(X2), \ |
| 83 | cpu_to_le32(X3), \ |
| 84 | cpu_to_le32(X4)} |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 85 | /* default power management (not Tx power) table values */ |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 86 | /* for DTIM period 0 through IWL_DTIM_RANGE_0_MAX */ |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 87 | /* DTIM 0 - 2 */ |
Johannes Berg | 7af2c46 | 2009-05-08 13:44:38 -0700 | [diff] [blame] | 88 | static const struct iwl_power_vec_entry range_0[IWL_POWER_NUM] = { |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 89 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 1, 2, 2, 0xFF)}, 0}, |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 90 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, |
| 91 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 2, 2, 2, 0xFF)}, 0}, |
| 92 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 2, 4, 4, 0xFF)}, 1}, |
| 93 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 2, 4, 6, 0xFF)}, 2} |
| 94 | }; |
| 95 | |
| 96 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 97 | /* for DTIM period IWL_DTIM_RANGE_0_MAX + 1 through IWL_DTIM_RANGE_1_MAX */ |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 98 | /* DTIM 3 - 10 */ |
Johannes Berg | 7af2c46 | 2009-05-08 13:44:38 -0700 | [diff] [blame] | 99 | static const struct iwl_power_vec_entry range_1[IWL_POWER_NUM] = { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 100 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 101 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0}, |
| 102 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 4, 6, 7, 9)}, 0}, |
| 103 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 4, 6, 9, 10)}, 1}, |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 104 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 6, 10, 10)}, 2} |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 107 | /* for DTIM period > IWL_DTIM_RANGE_1_MAX */ |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 108 | /* DTIM 11 - */ |
Johannes Berg | 7af2c46 | 2009-05-08 13:44:38 -0700 | [diff] [blame] | 109 | static const struct iwl_power_vec_entry range_2[IWL_POWER_NUM] = { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 110 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 111 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 112 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 113 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 114 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 115 | }; |
| 116 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 117 | static void iwl_static_sleep_cmd(struct iwl_priv *priv, |
| 118 | struct iwl_powertable_cmd *cmd, |
| 119 | enum iwl_power_level lvl, int period) |
| 120 | { |
| 121 | const struct iwl_power_vec_entry *table; |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 122 | int max_sleep[IWL_POWER_VEC_SIZE] = { 0 }; |
| 123 | int i; |
| 124 | u8 skip; |
| 125 | u32 slp_itrvl; |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 126 | |
| 127 | table = range_2; |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 128 | if (period <= IWL_DTIM_RANGE_1_MAX) |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 129 | table = range_1; |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 130 | if (period <= IWL_DTIM_RANGE_0_MAX) |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 131 | table = range_0; |
| 132 | |
| 133 | BUG_ON(lvl < 0 || lvl >= IWL_POWER_NUM); |
| 134 | |
| 135 | *cmd = table[lvl].cmd; |
| 136 | |
| 137 | if (period == 0) { |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 138 | skip = 0; |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 139 | period = 1; |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 140 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) |
| 141 | max_sleep[i] = 1; |
| 142 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 143 | } else { |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 144 | skip = table[lvl].no_dtim; |
| 145 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) |
| 146 | max_sleep[i] = le32_to_cpu(cmd->sleep_interval[i]); |
| 147 | max_sleep[IWL_POWER_VEC_SIZE - 1] = skip + 1; |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 150 | slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]); |
| 151 | /* figure out the listen interval based on dtim period and skip */ |
| 152 | if (slp_itrvl == 0xFF) |
| 153 | cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] = |
| 154 | cpu_to_le32(period * (skip + 1)); |
| 155 | |
| 156 | slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]); |
| 157 | if (slp_itrvl > period) |
| 158 | cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] = |
| 159 | cpu_to_le32((slp_itrvl / period) * period); |
| 160 | |
| 161 | if (skip) |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 162 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 163 | else |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 164 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 165 | |
Wey-Yi Guy | 1f37daf | 2010-11-23 10:58:55 -0800 | [diff] [blame^] | 166 | if (priv->cfg->base_params->shadow_reg_enable) |
| 167 | cmd->flags |= IWL_POWER_SHADOW_REG_ENA; |
| 168 | else |
| 169 | cmd->flags &= ~IWL_POWER_SHADOW_REG_ENA; |
| 170 | |
Wey-Yi Guy | e366176 | 2010-11-23 10:58:54 -0800 | [diff] [blame] | 171 | if (priv->cfg->bt_params && |
| 172 | priv->cfg->bt_params->advanced_bt_coexist) { |
| 173 | if (!priv->cfg->bt_params->bt_sco_disable) |
| 174 | cmd->flags |= IWL_POWER_BT_SCO_ENA; |
| 175 | else |
| 176 | cmd->flags &= ~IWL_POWER_BT_SCO_ENA; |
| 177 | } |
| 178 | |
| 179 | |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 180 | slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]); |
Wey-Yi Guy | 570af86 | 2009-10-23 13:42:33 -0700 | [diff] [blame] | 181 | if (slp_itrvl > IWL_CONN_MAX_LISTEN_INTERVAL) |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 182 | cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] = |
Wey-Yi Guy | 570af86 | 2009-10-23 13:42:33 -0700 | [diff] [blame] | 183 | cpu_to_le32(IWL_CONN_MAX_LISTEN_INTERVAL); |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 184 | |
| 185 | /* enforce max sleep interval */ |
| 186 | for (i = IWL_POWER_VEC_SIZE - 1; i >= 0 ; i--) { |
| 187 | if (le32_to_cpu(cmd->sleep_interval[i]) > |
| 188 | (max_sleep[i] * period)) |
| 189 | cmd->sleep_interval[i] = |
| 190 | cpu_to_le32(max_sleep[i] * period); |
| 191 | if (i != (IWL_POWER_VEC_SIZE - 1)) { |
| 192 | if (le32_to_cpu(cmd->sleep_interval[i]) > |
| 193 | le32_to_cpu(cmd->sleep_interval[i+1])) |
| 194 | cmd->sleep_interval[i] = |
| 195 | cmd->sleep_interval[i+1]; |
| 196 | } |
| 197 | } |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 198 | |
| 199 | if (priv->power_data.pci_pm) |
| 200 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 201 | else |
| 202 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 203 | |
Wey-Yi Guy | 4ad177b | 2009-10-16 14:25:58 -0700 | [diff] [blame] | 204 | IWL_DEBUG_POWER(priv, "numSkipDtim = %u, dtimPeriod = %d\n", |
| 205 | skip, period); |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 206 | IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1); |
| 207 | } |
| 208 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 209 | static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv, |
| 210 | struct iwl_powertable_cmd *cmd) |
Mohamed Abbas | ca57961 | 2008-07-18 13:52:57 +0800 | [diff] [blame] | 211 | { |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 212 | memset(cmd, 0, sizeof(*cmd)); |
| 213 | |
| 214 | if (priv->power_data.pci_pm) |
| 215 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 216 | |
| 217 | IWL_DEBUG_POWER(priv, "Sleep command for CAM\n"); |
Mohamed Abbas | ca57961 | 2008-07-18 13:52:57 +0800 | [diff] [blame] | 218 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 219 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 220 | static void iwl_power_fill_sleep_cmd(struct iwl_priv *priv, |
| 221 | struct iwl_powertable_cmd *cmd, |
| 222 | int dynps_ms, int wakeup_period) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 223 | { |
Johannes Berg | 4c561a0 | 2009-08-28 09:44:48 -0700 | [diff] [blame] | 224 | /* |
| 225 | * These are the original power level 3 sleep successions. The |
| 226 | * device may behave better with such succession and was also |
| 227 | * only tested with that. Just like the original sleep commands, |
| 228 | * also adjust the succession here to the wakeup_period below. |
| 229 | * The ranges are the same as for the sleep commands, 0-2, 3-9 |
| 230 | * and >10, which is selected based on the DTIM interval for |
| 231 | * the sleep index but here we use the wakeup period since that |
| 232 | * is what we need to do for the latency requirements. |
| 233 | */ |
| 234 | static const u8 slp_succ_r0[IWL_POWER_VEC_SIZE] = { 2, 2, 2, 2, 2 }; |
| 235 | static const u8 slp_succ_r1[IWL_POWER_VEC_SIZE] = { 2, 4, 6, 7, 9 }; |
| 236 | static const u8 slp_succ_r2[IWL_POWER_VEC_SIZE] = { 2, 7, 9, 9, 0xFF }; |
| 237 | const u8 *slp_succ = slp_succ_r0; |
Tomas Winkler | e7b6358 | 2008-09-03 11:26:49 +0800 | [diff] [blame] | 238 | int i; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 239 | |
Johannes Berg | 4c561a0 | 2009-08-28 09:44:48 -0700 | [diff] [blame] | 240 | if (wakeup_period > IWL_DTIM_RANGE_0_MAX) |
| 241 | slp_succ = slp_succ_r1; |
| 242 | if (wakeup_period > IWL_DTIM_RANGE_1_MAX) |
| 243 | slp_succ = slp_succ_r2; |
| 244 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 245 | memset(cmd, 0, sizeof(*cmd)); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 246 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 247 | cmd->flags = IWL_POWER_DRIVER_ALLOW_SLEEP_MSK | |
| 248 | IWL_POWER_FAST_PD; /* no use seeing frames for others */ |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 249 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 250 | if (priv->power_data.pci_pm) |
| 251 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 252 | |
Wey-Yi Guy | 1f37daf | 2010-11-23 10:58:55 -0800 | [diff] [blame^] | 253 | if (priv->cfg->base_params->shadow_reg_enable) |
| 254 | cmd->flags |= IWL_POWER_SHADOW_REG_ENA; |
| 255 | else |
| 256 | cmd->flags &= ~IWL_POWER_SHADOW_REG_ENA; |
| 257 | |
Wey-Yi Guy | e366176 | 2010-11-23 10:58:54 -0800 | [diff] [blame] | 258 | if (priv->cfg->bt_params && |
| 259 | priv->cfg->bt_params->advanced_bt_coexist) { |
| 260 | if (!priv->cfg->bt_params->bt_sco_disable) |
| 261 | cmd->flags |= IWL_POWER_BT_SCO_ENA; |
| 262 | else |
| 263 | cmd->flags &= ~IWL_POWER_BT_SCO_ENA; |
| 264 | } |
| 265 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 266 | cmd->rx_data_timeout = cpu_to_le32(1000 * dynps_ms); |
| 267 | cmd->tx_data_timeout = cpu_to_le32(1000 * dynps_ms); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 268 | |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 269 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) |
Johannes Berg | 4c561a0 | 2009-08-28 09:44:48 -0700 | [diff] [blame] | 270 | cmd->sleep_interval[i] = |
| 271 | cpu_to_le32(min_t(int, slp_succ[i], wakeup_period)); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 272 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 273 | IWL_DEBUG_POWER(priv, "Automatic sleep command\n"); |
| 274 | } |
| 275 | |
| 276 | static int iwl_set_power(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd) |
| 277 | { |
| 278 | IWL_DEBUG_POWER(priv, "Sending power/sleep command\n"); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 279 | IWL_DEBUG_POWER(priv, "Flags value = 0x%08X\n", cmd->flags); |
| 280 | IWL_DEBUG_POWER(priv, "Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 281 | IWL_DEBUG_POWER(priv, "Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 282 | IWL_DEBUG_POWER(priv, "Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 283 | le32_to_cpu(cmd->sleep_interval[0]), |
| 284 | le32_to_cpu(cmd->sleep_interval[1]), |
| 285 | le32_to_cpu(cmd->sleep_interval[2]), |
| 286 | le32_to_cpu(cmd->sleep_interval[3]), |
| 287 | le32_to_cpu(cmd->sleep_interval[4])); |
| 288 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 289 | return iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, |
| 290 | sizeof(struct iwl_powertable_cmd), cmd); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Stanislaw Gruszka | ac4f545 | 2010-10-22 17:04:29 +0200 | [diff] [blame] | 293 | static void iwl_power_build_cmd(struct iwl_priv *priv, |
| 294 | struct iwl_powertable_cmd *cmd) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 295 | { |
Johannes Berg | 4d69592 | 2010-01-21 05:24:04 -0800 | [diff] [blame] | 296 | bool enabled = priv->hw->conf.flags & IEEE80211_CONF_PS; |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 297 | int dtimper; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 298 | |
Stanislaw Gruszka | ac4f545 | 2010-10-22 17:04:29 +0200 | [diff] [blame] | 299 | dtimper = priv->hw->conf.ps_dtim_period ?: 1; |
| 300 | |
| 301 | if (priv->cfg->base_params->broken_powersave) |
| 302 | iwl_power_sleep_cam_cmd(priv, cmd); |
| 303 | else if (priv->cfg->base_params->supports_idle && |
| 304 | priv->hw->conf.flags & IEEE80211_CONF_IDLE) |
| 305 | iwl_static_sleep_cmd(priv, cmd, IWL_POWER_INDEX_5, 20); |
| 306 | else if (priv->cfg->ops->lib->tt_ops.lower_power_detection && |
| 307 | priv->cfg->ops->lib->tt_ops.tt_power_mode && |
| 308 | priv->cfg->ops->lib->tt_ops.lower_power_detection(priv)) { |
| 309 | /* in thermal throttling low power state */ |
| 310 | iwl_static_sleep_cmd(priv, cmd, |
| 311 | priv->cfg->ops->lib->tt_ops.tt_power_mode(priv), dtimper); |
| 312 | } else if (!enabled) |
| 313 | iwl_power_sleep_cam_cmd(priv, cmd); |
| 314 | else if (priv->power_data.debug_sleep_level_override >= 0) |
| 315 | iwl_static_sleep_cmd(priv, cmd, |
| 316 | priv->power_data.debug_sleep_level_override, |
| 317 | dtimper); |
| 318 | else if (no_sleep_autoadjust) |
| 319 | iwl_static_sleep_cmd(priv, cmd, IWL_POWER_INDEX_1, dtimper); |
| 320 | else |
| 321 | iwl_power_fill_sleep_cmd(priv, cmd, |
| 322 | priv->hw->conf.dynamic_ps_timeout, |
| 323 | priv->hw->conf.max_sleep_period); |
| 324 | } |
| 325 | |
| 326 | int iwl_power_set_mode(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd, |
| 327 | bool force) |
| 328 | { |
| 329 | int ret; |
| 330 | bool update_chains; |
| 331 | |
| 332 | lockdep_assert_held(&priv->mutex); |
| 333 | |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 334 | /* Don't update the RX chain when chain noise calibration is running */ |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 335 | update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE || |
| 336 | priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE; |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 337 | |
Stanislaw Gruszka | ac4f545 | 2010-10-22 17:04:29 +0200 | [diff] [blame] | 338 | if (!memcmp(&priv->power_data.sleep_cmd, cmd, sizeof(*cmd)) && !force) |
| 339 | return 0; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 340 | |
Stanislaw Gruszka | ac4f545 | 2010-10-22 17:04:29 +0200 | [diff] [blame] | 341 | if (!iwl_is_ready_rf(priv)) |
| 342 | return -EIO; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 343 | |
Stanislaw Gruszka | ac4f545 | 2010-10-22 17:04:29 +0200 | [diff] [blame] | 344 | /* scan complete use sleep_power_next, need to be updated */ |
| 345 | memcpy(&priv->power_data.sleep_cmd_next, cmd, sizeof(*cmd)); |
| 346 | if (test_bit(STATUS_SCANNING, &priv->status) && !force) { |
| 347 | IWL_DEBUG_INFO(priv, "Defer power set mode while scanning\n"); |
| 348 | return 0; |
| 349 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 350 | |
Stanislaw Gruszka | ac4f545 | 2010-10-22 17:04:29 +0200 | [diff] [blame] | 351 | if (cmd->flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK) |
| 352 | set_bit(STATUS_POWER_PMI, &priv->status); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 353 | |
Stanislaw Gruszka | ac4f545 | 2010-10-22 17:04:29 +0200 | [diff] [blame] | 354 | ret = iwl_set_power(priv, cmd); |
| 355 | if (!ret) { |
| 356 | if (!(cmd->flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK)) |
| 357 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 358 | |
| 359 | if (priv->cfg->ops->lib->update_chain_flags && update_chains) |
| 360 | priv->cfg->ops->lib->update_chain_flags(priv); |
| 361 | else if (priv->cfg->ops->lib->update_chain_flags) |
| 362 | IWL_DEBUG_POWER(priv, |
Wey-Yi Guy | 3a780d2 | 2009-08-07 15:41:47 -0700 | [diff] [blame] | 363 | "Cannot update the power, chain noise " |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 364 | "calibration running: %d\n", |
| 365 | priv->chain_noise_data.state); |
Stanislaw Gruszka | ac4f545 | 2010-10-22 17:04:29 +0200 | [diff] [blame] | 366 | |
| 367 | memcpy(&priv->power_data.sleep_cmd, cmd, sizeof(*cmd)); |
| 368 | } else |
| 369 | IWL_ERR(priv, "set power fail, ret = %d", ret); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 370 | |
| 371 | return ret; |
| 372 | } |
Stanislaw Gruszka | ac4f545 | 2010-10-22 17:04:29 +0200 | [diff] [blame] | 373 | EXPORT_SYMBOL(iwl_power_set_mode); |
| 374 | |
| 375 | int iwl_power_update_mode(struct iwl_priv *priv, bool force) |
| 376 | { |
| 377 | struct iwl_powertable_cmd cmd; |
| 378 | |
| 379 | iwl_power_build_cmd(priv, &cmd); |
| 380 | return iwl_power_set_mode(priv, &cmd, force); |
| 381 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 382 | EXPORT_SYMBOL(iwl_power_update_mode); |
| 383 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 384 | /* initialize to default */ |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 385 | void iwl_power_initialize(struct iwl_priv *priv) |
| 386 | { |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 387 | u16 lctl = iwl_pcie_link_ctl(priv); |
| 388 | |
| 389 | priv->power_data.pci_pm = !(lctl & PCI_CFG_LINK_CTRL_VAL_L0S_EN); |
| 390 | |
| 391 | priv->power_data.debug_sleep_level_override = -1; |
| 392 | |
| 393 | memset(&priv->power_data.sleep_cmd, 0, |
| 394 | sizeof(priv->power_data.sleep_cmd)); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 395 | } |
| 396 | EXPORT_SYMBOL(iwl_power_initialize); |