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