Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 3 | * Copyright(c) 2007 - 2009 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> |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | |
| 34 | #include <net/mac80211.h> |
| 35 | |
| 36 | #include "iwl-eeprom.h" |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 37 | #include "iwl-dev.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 38 | #include "iwl-core.h" |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 39 | #include "iwl-io.h" |
Tomas Winkler | 5a36ba0 | 2008-04-24 11:55:37 -0700 | [diff] [blame] | 40 | #include "iwl-commands.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 41 | #include "iwl-debug.h" |
| 42 | #include "iwl-power.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 43 | |
| 44 | /* |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 45 | * 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] | 46 | * |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 47 | * We calculate a sleep command based on the required latency, which |
| 48 | * we get from mac80211. In order to handle thermal throttling, we can |
| 49 | * also use pre-defined power levels. |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 50 | */ |
| 51 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 52 | /* |
| 53 | * For now, keep using power level 1 instead of automatically |
| 54 | * adjusting ... |
| 55 | */ |
| 56 | bool no_sleep_autoadjust = true; |
| 57 | module_param(no_sleep_autoadjust, bool, S_IRUGO); |
| 58 | MODULE_PARM_DESC(no_sleep_autoadjust, |
| 59 | "don't automatically adjust sleep level " |
| 60 | "according to maximum network latency"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 61 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 62 | /* |
| 63 | * This defines the old power levels. They are still used by default |
| 64 | * (level 1) and for thermal throttle (levels 3 through 5) |
| 65 | */ |
| 66 | |
| 67 | struct iwl_power_vec_entry { |
| 68 | struct iwl_powertable_cmd cmd; |
| 69 | u8 no_dtim; |
| 70 | }; |
| 71 | |
| 72 | #define IWL_DTIM_RANGE_0_MAX 2 |
| 73 | #define IWL_DTIM_RANGE_1_MAX 10 |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 74 | |
Johannes Berg | 7af2c46 | 2009-05-08 13:44:38 -0700 | [diff] [blame] | 75 | #define NOSLP cpu_to_le16(0), 0, 0 |
| 76 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
| 77 | #define TU_TO_USEC 1024 |
| 78 | #define SLP_TOUT(T) cpu_to_le32((T) * TU_TO_USEC) |
| 79 | #define SLP_VEC(X0, X1, X2, X3, X4) {cpu_to_le32(X0), \ |
| 80 | cpu_to_le32(X1), \ |
| 81 | cpu_to_le32(X2), \ |
| 82 | cpu_to_le32(X3), \ |
| 83 | cpu_to_le32(X4)} |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 84 | /* default power management (not Tx power) table values */ |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 85 | /* for DTIM period 0 through IWL_DTIM_RANGE_0_MAX */ |
Johannes Berg | 7af2c46 | 2009-05-08 13:44:38 -0700 | [diff] [blame] | 86 | static const struct iwl_power_vec_entry range_0[IWL_POWER_NUM] = { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 87 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, |
| 88 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, |
| 89 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 2, 2, 2, 0xFF)}, 0}, |
| 90 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 2, 4, 4, 0xFF)}, 1}, |
| 91 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 2, 4, 6, 0xFF)}, 2} |
| 92 | }; |
| 93 | |
| 94 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 95 | /* for DTIM period IWL_DTIM_RANGE_0_MAX + 1 through IWL_DTIM_RANGE_1_MAX */ |
Johannes Berg | 7af2c46 | 2009-05-08 13:44:38 -0700 | [diff] [blame] | 96 | static const struct iwl_power_vec_entry range_1[IWL_POWER_NUM] = { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 97 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 98 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0}, |
| 99 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 4, 6, 7, 9)}, 0}, |
| 100 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 4, 6, 9, 10)}, 1}, |
| 101 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 7, 10, 10)}, 2} |
| 102 | }; |
| 103 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 104 | /* for DTIM period > IWL_DTIM_RANGE_1_MAX */ |
Johannes Berg | 7af2c46 | 2009-05-08 13:44:38 -0700 | [diff] [blame] | 105 | static const struct iwl_power_vec_entry range_2[IWL_POWER_NUM] = { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 106 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 107 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 108 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 109 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 110 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 111 | }; |
| 112 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 113 | static void iwl_static_sleep_cmd(struct iwl_priv *priv, |
| 114 | struct iwl_powertable_cmd *cmd, |
| 115 | enum iwl_power_level lvl, int period) |
| 116 | { |
| 117 | const struct iwl_power_vec_entry *table; |
| 118 | int max_sleep, i; |
| 119 | bool skip; |
| 120 | |
| 121 | table = range_2; |
| 122 | if (period < IWL_DTIM_RANGE_1_MAX) |
| 123 | table = range_1; |
| 124 | if (period < IWL_DTIM_RANGE_0_MAX) |
| 125 | table = range_0; |
| 126 | |
| 127 | BUG_ON(lvl < 0 || lvl >= IWL_POWER_NUM); |
| 128 | |
| 129 | *cmd = table[lvl].cmd; |
| 130 | |
| 131 | if (period == 0) { |
| 132 | skip = false; |
| 133 | period = 1; |
| 134 | } else { |
| 135 | skip = !!table[lvl].no_dtim; |
| 136 | } |
| 137 | |
| 138 | if (skip) { |
| 139 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 140 | max_sleep = le32_to_cpu(slp_itrvl); |
| 141 | if (max_sleep == 0xFF) |
| 142 | max_sleep = period * (skip + 1); |
| 143 | else if (max_sleep > period) |
| 144 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 145 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 146 | } else { |
| 147 | max_sleep = period; |
| 148 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 149 | } |
| 150 | |
| 151 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) |
| 152 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 153 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 154 | |
| 155 | if (priv->power_data.pci_pm) |
| 156 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 157 | else |
| 158 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 159 | |
| 160 | IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1); |
| 161 | } |
| 162 | |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 163 | /* default Thermal Throttling transaction table |
| 164 | * Current state | Throttling Down | Throttling Up |
| 165 | *============================================================================= |
| 166 | * Condition Nxt State Condition Nxt State Condition Nxt State |
| 167 | *----------------------------------------------------------------------------- |
| 168 | * IWL_TI_0 T >= 115 CT_KILL 115>T>=105 TI_1 N/A N/A |
| 169 | * IWL_TI_1 T >= 115 CT_KILL 115>T>=110 TI_2 T<=95 TI_0 |
| 170 | * IWL_TI_2 T >= 115 CT_KILL T<=100 TI_1 |
| 171 | * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0 |
| 172 | *============================================================================= |
| 173 | */ |
| 174 | static const struct iwl_tt_trans tt_range_0[IWL_TI_STATE_MAX - 1] = { |
| 175 | {IWL_TI_0, IWL_ABSOLUTE_ZERO, 104}, |
| 176 | {IWL_TI_1, 105, CT_KILL_THRESHOLD}, |
| 177 | {IWL_TI_CT_KILL, CT_KILL_THRESHOLD + 1, IWL_ABSOLUTE_MAX} |
| 178 | }; |
| 179 | static const struct iwl_tt_trans tt_range_1[IWL_TI_STATE_MAX - 1] = { |
| 180 | {IWL_TI_0, IWL_ABSOLUTE_ZERO, 95}, |
| 181 | {IWL_TI_2, 110, CT_KILL_THRESHOLD}, |
| 182 | {IWL_TI_CT_KILL, CT_KILL_THRESHOLD + 1, IWL_ABSOLUTE_MAX} |
| 183 | }; |
| 184 | static const struct iwl_tt_trans tt_range_2[IWL_TI_STATE_MAX - 1] = { |
| 185 | {IWL_TI_1, IWL_ABSOLUTE_ZERO, 100}, |
| 186 | {IWL_TI_CT_KILL, CT_KILL_THRESHOLD + 1, IWL_ABSOLUTE_MAX}, |
| 187 | {IWL_TI_CT_KILL, CT_KILL_THRESHOLD + 1, IWL_ABSOLUTE_MAX} |
| 188 | }; |
| 189 | static const struct iwl_tt_trans tt_range_3[IWL_TI_STATE_MAX - 1] = { |
| 190 | {IWL_TI_0, IWL_ABSOLUTE_ZERO, CT_KILL_EXIT_THRESHOLD}, |
| 191 | {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX}, |
| 192 | {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX} |
| 193 | }; |
| 194 | |
| 195 | /* Advance Thermal Throttling default restriction table */ |
| 196 | static const struct iwl_tt_restriction restriction_range[IWL_TI_STATE_MAX] = { |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 197 | {IWL_ANT_OK_MULTI, IWL_ANT_OK_MULTI, true }, |
| 198 | {IWL_ANT_OK_SINGLE, IWL_ANT_OK_MULTI, true }, |
| 199 | {IWL_ANT_OK_SINGLE, IWL_ANT_OK_SINGLE, false }, |
| 200 | {IWL_ANT_OK_NONE, IWL_ANT_OK_NONE, false } |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 201 | }; |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 202 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 203 | |
| 204 | static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv, |
| 205 | struct iwl_powertable_cmd *cmd) |
Mohamed Abbas | ca57961 | 2008-07-18 13:52:57 +0800 | [diff] [blame] | 206 | { |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 207 | memset(cmd, 0, sizeof(*cmd)); |
| 208 | |
| 209 | if (priv->power_data.pci_pm) |
| 210 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 211 | |
| 212 | IWL_DEBUG_POWER(priv, "Sleep command for CAM\n"); |
Mohamed Abbas | ca57961 | 2008-07-18 13:52:57 +0800 | [diff] [blame] | 213 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 214 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 215 | static void iwl_power_fill_sleep_cmd(struct iwl_priv *priv, |
| 216 | struct iwl_powertable_cmd *cmd, |
| 217 | int dynps_ms, int wakeup_period) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 218 | { |
Tomas Winkler | e7b6358 | 2008-09-03 11:26:49 +0800 | [diff] [blame] | 219 | int i; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 220 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 221 | memset(cmd, 0, sizeof(*cmd)); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 222 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 223 | cmd->flags = IWL_POWER_DRIVER_ALLOW_SLEEP_MSK | |
| 224 | IWL_POWER_FAST_PD; /* no use seeing frames for others */ |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 225 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 226 | if (priv->power_data.pci_pm) |
| 227 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 228 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 229 | cmd->rx_data_timeout = cpu_to_le32(1000 * dynps_ms); |
| 230 | cmd->tx_data_timeout = cpu_to_le32(1000 * dynps_ms); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 231 | |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 232 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 233 | cmd->sleep_interval[i] = cpu_to_le32(wakeup_period); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 234 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 235 | IWL_DEBUG_POWER(priv, "Automatic sleep command\n"); |
| 236 | } |
| 237 | |
| 238 | static int iwl_set_power(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd) |
| 239 | { |
| 240 | IWL_DEBUG_POWER(priv, "Sending power/sleep command\n"); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 241 | IWL_DEBUG_POWER(priv, "Flags value = 0x%08X\n", cmd->flags); |
| 242 | IWL_DEBUG_POWER(priv, "Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 243 | IWL_DEBUG_POWER(priv, "Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 244 | 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] | 245 | le32_to_cpu(cmd->sleep_interval[0]), |
| 246 | le32_to_cpu(cmd->sleep_interval[1]), |
| 247 | le32_to_cpu(cmd->sleep_interval[2]), |
| 248 | le32_to_cpu(cmd->sleep_interval[3]), |
| 249 | le32_to_cpu(cmd->sleep_interval[4])); |
| 250 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 251 | return iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, |
| 252 | sizeof(struct iwl_powertable_cmd), cmd); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 256 | int iwl_power_update_mode(struct iwl_priv *priv, bool force) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 257 | { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 258 | int ret = 0; |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 259 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 260 | bool enabled = (priv->iw_mode == NL80211_IFTYPE_STATION) && |
| 261 | (priv->hw->conf.flags & IEEE80211_CONF_PS); |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 262 | bool update_chains; |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 263 | struct iwl_powertable_cmd cmd; |
| 264 | int dtimper; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 265 | |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 266 | /* Don't update the RX chain when chain noise calibration is running */ |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 267 | update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE || |
| 268 | priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE; |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 269 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 270 | if (priv->vif) |
| 271 | dtimper = priv->vif->bss_conf.dtim_period; |
| 272 | else |
| 273 | dtimper = 1; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 274 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 275 | /* TT power setting overwrites everything */ |
| 276 | if (tt->state >= IWL_TI_1) |
| 277 | iwl_static_sleep_cmd(priv, &cmd, tt->tt_power_mode, dtimper); |
| 278 | else if (!enabled) |
| 279 | iwl_power_sleep_cam_cmd(priv, &cmd); |
| 280 | else if (priv->power_data.debug_sleep_level_override >= 0) |
| 281 | iwl_static_sleep_cmd(priv, &cmd, |
| 282 | priv->power_data.debug_sleep_level_override, |
| 283 | dtimper); |
| 284 | else if (no_sleep_autoadjust) |
| 285 | iwl_static_sleep_cmd(priv, &cmd, IWL_POWER_INDEX_1, dtimper); |
| 286 | else |
| 287 | iwl_power_fill_sleep_cmd(priv, &cmd, |
| 288 | priv->hw->conf.dynamic_ps_timeout, |
| 289 | priv->hw->conf.max_sleep_period); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 290 | |
Johannes Berg | 7af2c46 | 2009-05-08 13:44:38 -0700 | [diff] [blame] | 291 | if (iwl_is_ready_rf(priv) && |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 292 | (memcmp(&priv->power_data.sleep_cmd, &cmd, sizeof(cmd)) || force)) { |
| 293 | if (cmd.flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 294 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 295 | |
Mohamed Abbas | ca57961 | 2008-07-18 13:52:57 +0800 | [diff] [blame] | 296 | ret = iwl_set_power(priv, &cmd); |
Wey-Yi Guy | 3a780d2 | 2009-08-07 15:41:47 -0700 | [diff] [blame] | 297 | if (!ret) { |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 298 | if (!(cmd.flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK)) |
Wey-Yi Guy | 3a780d2 | 2009-08-07 15:41:47 -0700 | [diff] [blame] | 299 | clear_bit(STATUS_POWER_PMI, &priv->status); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 300 | |
Wey-Yi Guy | 3a780d2 | 2009-08-07 15:41:47 -0700 | [diff] [blame] | 301 | if (priv->cfg->ops->lib->update_chain_flags && |
| 302 | update_chains) |
| 303 | priv->cfg->ops->lib->update_chain_flags(priv); |
| 304 | else |
| 305 | IWL_DEBUG_POWER(priv, |
| 306 | "Cannot update the power, chain noise " |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 307 | "calibration running: %d\n", |
| 308 | priv->chain_noise_data.state); |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 309 | memcpy(&priv->power_data.sleep_cmd, &cmd, sizeof(cmd)); |
Wey-Yi Guy | 3a780d2 | 2009-08-07 15:41:47 -0700 | [diff] [blame] | 310 | } else |
| 311 | IWL_ERR(priv, "set power fail, ret = %d", ret); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | return ret; |
| 315 | } |
| 316 | EXPORT_SYMBOL(iwl_power_update_mode); |
| 317 | |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 318 | bool iwl_ht_enabled(struct iwl_priv *priv) |
| 319 | { |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 320 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 321 | struct iwl_tt_restriction *restriction; |
| 322 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 323 | if (!priv->thermal_throttle.advanced_tt) |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 324 | return true; |
| 325 | restriction = tt->restriction + tt->state; |
| 326 | return restriction->is_ht; |
| 327 | } |
| 328 | EXPORT_SYMBOL(iwl_ht_enabled); |
| 329 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 330 | enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv) |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 331 | { |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 332 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 333 | struct iwl_tt_restriction *restriction; |
| 334 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 335 | if (!priv->thermal_throttle.advanced_tt) |
| 336 | return IWL_ANT_OK_MULTI; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 337 | restriction = tt->restriction + tt->state; |
| 338 | return restriction->tx_stream; |
| 339 | } |
| 340 | EXPORT_SYMBOL(iwl_tx_ant_restriction); |
| 341 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 342 | enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv) |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 343 | { |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 344 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 345 | struct iwl_tt_restriction *restriction; |
| 346 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 347 | if (!priv->thermal_throttle.advanced_tt) |
| 348 | return IWL_ANT_OK_MULTI; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 349 | restriction = tt->restriction + tt->state; |
| 350 | return restriction->rx_stream; |
| 351 | } |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 352 | |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 353 | #define CT_KILL_EXIT_DURATION (5) /* 5 seconds duration */ |
| 354 | |
| 355 | /* |
| 356 | * toggle the bit to wake up uCode and check the temperature |
| 357 | * if the temperature is below CT, uCode will stay awake and send card |
| 358 | * state notification with CT_KILL bit clear to inform Thermal Throttling |
| 359 | * Management to change state. Otherwise, uCode will go back to sleep |
| 360 | * without doing anything, driver should continue the 5 seconds timer |
| 361 | * to wake up uCode for temperature check until temperature drop below CT |
| 362 | */ |
| 363 | static void iwl_tt_check_exit_ct_kill(unsigned long data) |
| 364 | { |
| 365 | struct iwl_priv *priv = (struct iwl_priv *)data; |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 366 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 367 | unsigned long flags; |
| 368 | |
| 369 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 370 | return; |
| 371 | |
| 372 | if (tt->state == IWL_TI_CT_KILL) { |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 373 | if (priv->thermal_throttle.ct_kill_toggle) { |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 374 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
| 375 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 376 | priv->thermal_throttle.ct_kill_toggle = false; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 377 | } else { |
| 378 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
| 379 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 380 | priv->thermal_throttle.ct_kill_toggle = true; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 381 | } |
| 382 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 383 | spin_lock_irqsave(&priv->reg_lock, flags); |
| 384 | if (!iwl_grab_nic_access(priv)) |
| 385 | iwl_release_nic_access(priv); |
| 386 | spin_unlock_irqrestore(&priv->reg_lock, flags); |
| 387 | |
| 388 | /* Reschedule the ct_kill timer to occur in |
| 389 | * CT_KILL_EXIT_DURATION seconds to ensure we get a |
| 390 | * thermal update */ |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 391 | mod_timer(&priv->thermal_throttle.ct_kill_exit_tm, jiffies + |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 392 | CT_KILL_EXIT_DURATION * HZ); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | static void iwl_perform_ct_kill_task(struct iwl_priv *priv, |
| 397 | bool stop) |
| 398 | { |
| 399 | if (stop) { |
| 400 | IWL_DEBUG_POWER(priv, "Stop all queues\n"); |
| 401 | if (priv->mac80211_registered) |
| 402 | ieee80211_stop_queues(priv->hw); |
| 403 | IWL_DEBUG_POWER(priv, |
| 404 | "Schedule 5 seconds CT_KILL Timer\n"); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 405 | mod_timer(&priv->thermal_throttle.ct_kill_exit_tm, jiffies + |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 406 | CT_KILL_EXIT_DURATION * HZ); |
| 407 | } else { |
| 408 | IWL_DEBUG_POWER(priv, "Wake all queues\n"); |
| 409 | if (priv->mac80211_registered) |
| 410 | ieee80211_wake_queues(priv->hw); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | #define IWL_MINIMAL_POWER_THRESHOLD (CT_KILL_THRESHOLD_LEGACY) |
| 415 | #define IWL_REDUCED_PERFORMANCE_THRESHOLD_2 (100) |
| 416 | #define IWL_REDUCED_PERFORMANCE_THRESHOLD_1 (90) |
| 417 | |
| 418 | /* |
| 419 | * Legacy thermal throttling |
| 420 | * 1) Avoid NIC destruction due to high temperatures |
| 421 | * Chip will identify dangerously high temperatures that can |
| 422 | * harm the device and will power down |
| 423 | * 2) Avoid the NIC power down due to high temperature |
| 424 | * Throttle early enough to lower the power consumption before |
| 425 | * drastic steps are needed |
| 426 | */ |
| 427 | static void iwl_legacy_tt_handler(struct iwl_priv *priv, s32 temp) |
| 428 | { |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 429 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 430 | enum iwl_tt_state old_state; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 431 | |
| 432 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 433 | if ((tt->tt_previous_temp) && |
| 434 | (temp > tt->tt_previous_temp) && |
| 435 | ((temp - tt->tt_previous_temp) > |
| 436 | IWL_TT_INCREASE_MARGIN)) { |
| 437 | IWL_DEBUG_POWER(priv, |
| 438 | "Temperature increase %d degree Celsius\n", |
| 439 | (temp - tt->tt_previous_temp)); |
| 440 | } |
| 441 | #endif |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 442 | old_state = tt->state; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 443 | /* in Celsius */ |
| 444 | if (temp >= IWL_MINIMAL_POWER_THRESHOLD) |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 445 | tt->state = IWL_TI_CT_KILL; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 446 | else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_2) |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 447 | tt->state = IWL_TI_2; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 448 | else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_1) |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 449 | tt->state = IWL_TI_1; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 450 | else |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 451 | tt->state = IWL_TI_0; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 452 | |
| 453 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 454 | tt->tt_previous_temp = temp; |
| 455 | #endif |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 456 | if (tt->state != old_state) { |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 457 | switch (tt->state) { |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 458 | case IWL_TI_0: |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 459 | /* |
| 460 | * When the system is ready to go back to IWL_TI_0 |
| 461 | * we only have to call iwl_power_update_mode() to |
| 462 | * do so. |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 463 | */ |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 464 | break; |
| 465 | case IWL_TI_1: |
| 466 | tt->tt_power_mode = IWL_POWER_INDEX_3; |
| 467 | break; |
| 468 | case IWL_TI_2: |
| 469 | tt->tt_power_mode = IWL_POWER_INDEX_4; |
| 470 | break; |
| 471 | default: |
| 472 | tt->tt_power_mode = IWL_POWER_INDEX_5; |
| 473 | break; |
| 474 | } |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 475 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 476 | if (iwl_power_update_mode(priv, true)) { |
| 477 | /* TT state not updated |
| 478 | * try again during next temperature read |
| 479 | */ |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 480 | tt->state = old_state; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 481 | IWL_ERR(priv, "Cannot update power mode, " |
| 482 | "TT state not updated\n"); |
| 483 | } else { |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 484 | if (tt->state == IWL_TI_CT_KILL) |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 485 | iwl_perform_ct_kill_task(priv, true); |
Wey-Yi Guy | ee9f298 | 2009-08-07 15:41:46 -0700 | [diff] [blame] | 486 | else if (old_state == IWL_TI_CT_KILL && |
| 487 | tt->state != IWL_TI_CT_KILL) |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 488 | iwl_perform_ct_kill_task(priv, false); |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 489 | IWL_DEBUG_POWER(priv, "Temperature state changed %u\n", |
| 490 | tt->state); |
| 491 | IWL_DEBUG_POWER(priv, "Power Index change to %u\n", |
| 492 | tt->tt_power_mode); |
| 493 | } |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 494 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 498 | /* |
| 499 | * Advance thermal throttling |
| 500 | * 1) Avoid NIC destruction due to high temperatures |
| 501 | * Chip will identify dangerously high temperatures that can |
| 502 | * harm the device and will power down |
| 503 | * 2) Avoid the NIC power down due to high temperature |
| 504 | * Throttle early enough to lower the power consumption before |
| 505 | * drastic steps are needed |
| 506 | * Actions include relaxing the power down sleep thresholds and |
| 507 | * decreasing the number of TX streams |
| 508 | * 3) Avoid throughput performance impact as much as possible |
| 509 | * |
| 510 | *============================================================================= |
| 511 | * Condition Nxt State Condition Nxt State Condition Nxt State |
| 512 | *----------------------------------------------------------------------------- |
| 513 | * IWL_TI_0 T >= 115 CT_KILL 115>T>=105 TI_1 N/A N/A |
| 514 | * IWL_TI_1 T >= 115 CT_KILL 115>T>=110 TI_2 T<=95 TI_0 |
| 515 | * IWL_TI_2 T >= 115 CT_KILL T<=100 TI_1 |
| 516 | * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0 |
| 517 | *============================================================================= |
| 518 | */ |
| 519 | static void iwl_advance_tt_handler(struct iwl_priv *priv, s32 temp) |
| 520 | { |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 521 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 522 | int i; |
| 523 | bool changed = false; |
| 524 | enum iwl_tt_state old_state; |
| 525 | struct iwl_tt_trans *transaction; |
| 526 | |
| 527 | old_state = tt->state; |
| 528 | for (i = 0; i < IWL_TI_STATE_MAX - 1; i++) { |
| 529 | /* based on the current TT state, |
| 530 | * find the curresponding transaction table |
| 531 | * each table has (IWL_TI_STATE_MAX - 1) entries |
| 532 | * tt->transaction + ((old_state * (IWL_TI_STATE_MAX - 1)) |
| 533 | * will advance to the correct table. |
| 534 | * then based on the current temperature |
| 535 | * find the next state need to transaction to |
| 536 | * go through all the possible (IWL_TI_STATE_MAX - 1) entries |
| 537 | * in the current table to see if transaction is needed |
| 538 | */ |
| 539 | transaction = tt->transaction + |
| 540 | ((old_state * (IWL_TI_STATE_MAX - 1)) + i); |
| 541 | if (temp >= transaction->tt_low && |
| 542 | temp <= transaction->tt_high) { |
| 543 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 544 | if ((tt->tt_previous_temp) && |
| 545 | (temp > tt->tt_previous_temp) && |
| 546 | ((temp - tt->tt_previous_temp) > |
| 547 | IWL_TT_INCREASE_MARGIN)) { |
| 548 | IWL_DEBUG_POWER(priv, |
| 549 | "Temperature increase %d " |
| 550 | "degree Celsius\n", |
| 551 | (temp - tt->tt_previous_temp)); |
| 552 | } |
| 553 | tt->tt_previous_temp = temp; |
| 554 | #endif |
| 555 | if (old_state != |
| 556 | transaction->next_state) { |
| 557 | changed = true; |
| 558 | tt->state = |
| 559 | transaction->next_state; |
| 560 | } |
| 561 | break; |
| 562 | } |
| 563 | } |
| 564 | if (changed) { |
| 565 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 566 | |
| 567 | if (tt->state >= IWL_TI_1) { |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 568 | /* force PI = IWL_POWER_INDEX_5 in the case of TI > 0 */ |
| 569 | tt->tt_power_mode = IWL_POWER_INDEX_5; |
| 570 | if (!iwl_ht_enabled(priv)) |
| 571 | /* disable HT */ |
| 572 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | |
| 573 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 574 | RXON_FLG_HT40_PROT_MSK | |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 575 | RXON_FLG_HT_PROT_MSK); |
| 576 | else { |
| 577 | /* check HT capability and set |
| 578 | * according to the system HT capability |
| 579 | * in case get disabled before */ |
| 580 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
| 581 | } |
| 582 | |
| 583 | } else { |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 584 | /* |
| 585 | * restore system power setting -- it will be |
| 586 | * recalculated automatically. |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 587 | */ |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 588 | |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 589 | /* check HT capability and set |
| 590 | * according to the system HT capability |
| 591 | * in case get disabled before */ |
| 592 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
| 593 | } |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 594 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 595 | if (iwl_power_update_mode(priv, true)) { |
| 596 | /* TT state not updated |
| 597 | * try again during next temperature read |
| 598 | */ |
| 599 | IWL_ERR(priv, "Cannot update power mode, " |
| 600 | "TT state not updated\n"); |
| 601 | tt->state = old_state; |
| 602 | } else { |
| 603 | IWL_DEBUG_POWER(priv, |
| 604 | "Thermal Throttling to new state: %u\n", |
| 605 | tt->state); |
| 606 | if (old_state != IWL_TI_CT_KILL && |
| 607 | tt->state == IWL_TI_CT_KILL) { |
| 608 | IWL_DEBUG_POWER(priv, "Enter IWL_TI_CT_KILL\n"); |
| 609 | iwl_perform_ct_kill_task(priv, true); |
| 610 | |
| 611 | } else if (old_state == IWL_TI_CT_KILL && |
| 612 | tt->state != IWL_TI_CT_KILL) { |
| 613 | IWL_DEBUG_POWER(priv, "Exit IWL_TI_CT_KILL\n"); |
| 614 | iwl_perform_ct_kill_task(priv, false); |
| 615 | } |
| 616 | } |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 617 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 621 | /* Card State Notification indicated reach critical temperature |
| 622 | * if PSP not enable, no Thermal Throttling function will be performed |
| 623 | * just set the GP1 bit to acknowledge the event |
| 624 | * otherwise, go into IWL_TI_CT_KILL state |
| 625 | * since Card State Notification will not provide any temperature reading |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 626 | * for Legacy mode |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 627 | * so just pass the CT_KILL temperature to iwl_legacy_tt_handler() |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 628 | * for advance mode |
| 629 | * pass CT_KILL_THRESHOLD+1 to make sure move into IWL_TI_CT_KILL state |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 630 | */ |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 631 | static void iwl_bg_ct_enter(struct work_struct *work) |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 632 | { |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 633 | struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_enter); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 634 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 635 | |
| 636 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 637 | return; |
| 638 | |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 639 | if (!iwl_is_ready(priv)) |
| 640 | return; |
| 641 | |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 642 | if (tt->state != IWL_TI_CT_KILL) { |
| 643 | IWL_ERR(priv, "Device reached critical temperature " |
| 644 | "- ucode going to sleep!\n"); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 645 | if (!priv->thermal_throttle.advanced_tt) |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 646 | iwl_legacy_tt_handler(priv, |
| 647 | IWL_MINIMAL_POWER_THRESHOLD); |
| 648 | else |
| 649 | iwl_advance_tt_handler(priv, |
| 650 | CT_KILL_THRESHOLD + 1); |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 653 | |
| 654 | /* Card State Notification indicated out of critical temperature |
| 655 | * since Card State Notification will not provide any temperature reading |
| 656 | * so pass the IWL_REDUCED_PERFORMANCE_THRESHOLD_2 temperature |
| 657 | * to iwl_legacy_tt_handler() to get out of IWL_CT_KILL state |
| 658 | */ |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 659 | static void iwl_bg_ct_exit(struct work_struct *work) |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 660 | { |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 661 | struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_exit); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 662 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 663 | |
| 664 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 665 | return; |
| 666 | |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 667 | if (!iwl_is_ready(priv)) |
| 668 | return; |
| 669 | |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 670 | /* stop ct_kill_exit_tm timer */ |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 671 | del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm); |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 672 | |
| 673 | if (tt->state == IWL_TI_CT_KILL) { |
| 674 | IWL_ERR(priv, |
| 675 | "Device temperature below critical" |
| 676 | "- ucode awake!\n"); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 677 | if (!priv->thermal_throttle.advanced_tt) |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 678 | iwl_legacy_tt_handler(priv, |
| 679 | IWL_REDUCED_PERFORMANCE_THRESHOLD_2); |
| 680 | else |
| 681 | iwl_advance_tt_handler(priv, CT_KILL_EXIT_THRESHOLD); |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 682 | } |
| 683 | } |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 684 | |
| 685 | void iwl_tt_enter_ct_kill(struct iwl_priv *priv) |
| 686 | { |
| 687 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 688 | return; |
| 689 | |
| 690 | IWL_DEBUG_POWER(priv, "Queueing critical temperature enter.\n"); |
| 691 | queue_work(priv->workqueue, &priv->ct_enter); |
| 692 | } |
| 693 | EXPORT_SYMBOL(iwl_tt_enter_ct_kill); |
| 694 | |
| 695 | void iwl_tt_exit_ct_kill(struct iwl_priv *priv) |
| 696 | { |
| 697 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 698 | return; |
| 699 | |
| 700 | IWL_DEBUG_POWER(priv, "Queueing critical temperature exit.\n"); |
| 701 | queue_work(priv->workqueue, &priv->ct_exit); |
| 702 | } |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 703 | EXPORT_SYMBOL(iwl_tt_exit_ct_kill); |
| 704 | |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 705 | static void iwl_bg_tt_work(struct work_struct *work) |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 706 | { |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 707 | struct iwl_priv *priv = container_of(work, struct iwl_priv, tt_work); |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 708 | s32 temp = priv->temperature; /* degrees CELSIUS except 4965 */ |
| 709 | |
| 710 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 711 | return; |
| 712 | |
| 713 | if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) |
| 714 | temp = KELVIN_TO_CELSIUS(priv->temperature); |
| 715 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 716 | if (!priv->thermal_throttle.advanced_tt) |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 717 | iwl_legacy_tt_handler(priv, temp); |
| 718 | else |
| 719 | iwl_advance_tt_handler(priv, temp); |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 720 | } |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 721 | |
| 722 | void iwl_tt_handler(struct iwl_priv *priv) |
| 723 | { |
| 724 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 725 | return; |
| 726 | |
| 727 | IWL_DEBUG_POWER(priv, "Queueing thermal throttling work.\n"); |
| 728 | queue_work(priv->workqueue, &priv->tt_work); |
| 729 | } |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 730 | EXPORT_SYMBOL(iwl_tt_handler); |
| 731 | |
| 732 | /* Thermal throttling initialization |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 733 | * For advance thermal throttling: |
| 734 | * Initialize Thermal Index and temperature threshold table |
| 735 | * Initialize thermal throttling restriction table |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 736 | */ |
| 737 | void iwl_tt_initialize(struct iwl_priv *priv) |
| 738 | { |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 739 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 740 | int size = sizeof(struct iwl_tt_trans) * (IWL_TI_STATE_MAX - 1); |
| 741 | struct iwl_tt_trans *transaction; |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 742 | |
| 743 | IWL_DEBUG_POWER(priv, "Initialize Thermal Throttling \n"); |
| 744 | |
| 745 | memset(tt, 0, sizeof(struct iwl_tt_mgmt)); |
| 746 | |
| 747 | tt->state = IWL_TI_0; |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 748 | init_timer(&priv->thermal_throttle.ct_kill_exit_tm); |
| 749 | priv->thermal_throttle.ct_kill_exit_tm.data = (unsigned long)priv; |
| 750 | priv->thermal_throttle.ct_kill_exit_tm.function = iwl_tt_check_exit_ct_kill; |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 751 | |
| 752 | /* setup deferred ct kill work */ |
| 753 | INIT_WORK(&priv->tt_work, iwl_bg_tt_work); |
| 754 | INIT_WORK(&priv->ct_enter, iwl_bg_ct_enter); |
| 755 | INIT_WORK(&priv->ct_exit, iwl_bg_ct_exit); |
| 756 | |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 757 | switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) { |
| 758 | case CSR_HW_REV_TYPE_6x00: |
| 759 | case CSR_HW_REV_TYPE_6x50: |
| 760 | IWL_DEBUG_POWER(priv, "Advanced Thermal Throttling\n"); |
| 761 | tt->restriction = kzalloc(sizeof(struct iwl_tt_restriction) * |
| 762 | IWL_TI_STATE_MAX, GFP_KERNEL); |
| 763 | tt->transaction = kzalloc(sizeof(struct iwl_tt_trans) * |
| 764 | IWL_TI_STATE_MAX * (IWL_TI_STATE_MAX - 1), |
| 765 | GFP_KERNEL); |
| 766 | if (!tt->restriction || !tt->transaction) { |
| 767 | IWL_ERR(priv, "Fallback to Legacy Throttling\n"); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 768 | priv->thermal_throttle.advanced_tt = false; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 769 | kfree(tt->restriction); |
| 770 | tt->restriction = NULL; |
| 771 | kfree(tt->transaction); |
| 772 | tt->transaction = NULL; |
| 773 | } else { |
| 774 | transaction = tt->transaction + |
| 775 | (IWL_TI_0 * (IWL_TI_STATE_MAX - 1)); |
| 776 | memcpy(transaction, &tt_range_0[0], size); |
| 777 | transaction = tt->transaction + |
| 778 | (IWL_TI_1 * (IWL_TI_STATE_MAX - 1)); |
| 779 | memcpy(transaction, &tt_range_1[0], size); |
| 780 | transaction = tt->transaction + |
| 781 | (IWL_TI_2 * (IWL_TI_STATE_MAX - 1)); |
| 782 | memcpy(transaction, &tt_range_2[0], size); |
| 783 | transaction = tt->transaction + |
| 784 | (IWL_TI_CT_KILL * (IWL_TI_STATE_MAX - 1)); |
| 785 | memcpy(transaction, &tt_range_3[0], size); |
| 786 | size = sizeof(struct iwl_tt_restriction) * |
| 787 | IWL_TI_STATE_MAX; |
| 788 | memcpy(tt->restriction, |
| 789 | &restriction_range[0], size); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 790 | priv->thermal_throttle.advanced_tt = true; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 791 | } |
| 792 | break; |
| 793 | default: |
| 794 | IWL_DEBUG_POWER(priv, "Legacy Thermal Throttling\n"); |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 795 | priv->thermal_throttle.advanced_tt = false; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 796 | break; |
| 797 | } |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 798 | } |
| 799 | EXPORT_SYMBOL(iwl_tt_initialize); |
| 800 | |
| 801 | /* cleanup thermal throttling management related memory and timer */ |
| 802 | void iwl_tt_exit(struct iwl_priv *priv) |
| 803 | { |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 804 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 805 | |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 806 | /* stop ct_kill_exit_tm timer if activated */ |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 807 | del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm); |
Wey-Yi Guy | a28027cd | 2009-08-07 15:41:45 -0700 | [diff] [blame] | 808 | cancel_work_sync(&priv->tt_work); |
| 809 | cancel_work_sync(&priv->ct_enter); |
| 810 | cancel_work_sync(&priv->ct_exit); |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 811 | |
Johannes Berg | 3ad3b92 | 2009-08-07 15:41:48 -0700 | [diff] [blame] | 812 | if (priv->thermal_throttle.advanced_tt) { |
Wey-Yi Guy | 46f9381 | 2009-07-24 11:13:03 -0700 | [diff] [blame] | 813 | /* free advance thermal throttling memory */ |
| 814 | kfree(tt->restriction); |
| 815 | tt->restriction = NULL; |
| 816 | kfree(tt->transaction); |
| 817 | tt->transaction = NULL; |
| 818 | } |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 819 | } |
| 820 | EXPORT_SYMBOL(iwl_tt_exit); |
| 821 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 822 | /* initialize to default */ |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 823 | void iwl_power_initialize(struct iwl_priv *priv) |
| 824 | { |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame^] | 825 | u16 lctl = iwl_pcie_link_ctl(priv); |
| 826 | |
| 827 | priv->power_data.pci_pm = !(lctl & PCI_CFG_LINK_CTRL_VAL_L0S_EN); |
| 828 | |
| 829 | priv->power_data.debug_sleep_level_override = -1; |
| 830 | |
| 831 | memset(&priv->power_data.sleep_cmd, 0, |
| 832 | sizeof(priv->power_data.sleep_cmd)); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 833 | } |
| 834 | EXPORT_SYMBOL(iwl_power_initialize); |