aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWey-Yi Guy <wey-yi.w.guy@intel.com>2010-07-31 11:34:07 -0400
committerJohn W. Linville <linville@tuxdriver.com>2010-08-24 16:28:07 -0400
commit0975cc8fbf5b61b188734f2edd9e588c7edff2a1 (patch)
tree9ea25bdc70467af87ba49c2a55128cc999647046
parent36d344131c154c0fb7dd6a3703fc1b29c56a75a1 (diff)
iwlwifi: separate thermal throttling function
"Thermal Throttling" is an advance feature which only available for newer _agn devices. Move from iwl-core to iwl-agn for better code organization. Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/iwlwifi/Makefile1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-1000.c5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tt.c696
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tt.h129
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c46
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c48
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.c640
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.h93
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c9
13 files changed, 917 insertions, 776 deletions
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile
index 728bb858ba97..493163925a45 100644
--- a/drivers/net/wireless/iwlwifi/Makefile
+++ b/drivers/net/wireless/iwlwifi/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_IWLAGN) += iwlagn.o
12iwlagn-objs := iwl-agn.o iwl-agn-rs.o iwl-agn-led.o iwl-agn-ict.o 12iwlagn-objs := iwl-agn.o iwl-agn-rs.o iwl-agn-led.o iwl-agn-ict.o
13iwlagn-objs += iwl-agn-ucode.o iwl-agn-hcmd.o iwl-agn-tx.o 13iwlagn-objs += iwl-agn-ucode.o iwl-agn-hcmd.o iwl-agn-tx.o
14iwlagn-objs += iwl-agn-lib.o iwl-agn-rx.o iwl-agn-calib.o 14iwlagn-objs += iwl-agn-lib.o iwl-agn-rx.o iwl-agn-calib.o
15iwlagn-objs += iwl-agn-tt.o
15iwlagn-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-agn-debugfs.o 16iwlagn-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-agn-debugfs.o
16 17
17iwlagn-$(CONFIG_IWL4965) += iwl-4965.o 18iwlagn-$(CONFIG_IWL4965) += iwl-4965.o
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
index fec026212326..f687a190f917 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
@@ -229,6 +229,11 @@ static struct iwl_lib_ops iwl1000_lib = {
229 .check_ack_health = iwl_good_ack_health, 229 .check_ack_health = iwl_good_ack_health,
230 .txfifo_flush = iwlagn_txfifo_flush, 230 .txfifo_flush = iwlagn_txfifo_flush,
231 .dev_txfifo_flush = iwlagn_dev_txfifo_flush, 231 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
232 .tt_ops = {
233 .lower_power_detection = iwl_tt_is_low_power_state,
234 .tt_power_mode = iwl_tt_current_power_mode,
235 .ct_kill_check = iwl_check_for_ct_kill,
236 }
232}; 237};
233 238
234static const struct iwl_ops iwl1000_ops = { 239static const struct iwl_ops iwl1000_ops = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index aacf3770f075..54083a39c724 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -405,6 +405,11 @@ static struct iwl_lib_ops iwl5000_lib = {
405 .check_ack_health = iwl_good_ack_health, 405 .check_ack_health = iwl_good_ack_health,
406 .txfifo_flush = iwlagn_txfifo_flush, 406 .txfifo_flush = iwlagn_txfifo_flush,
407 .dev_txfifo_flush = iwlagn_dev_txfifo_flush, 407 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
408 .tt_ops = {
409 .lower_power_detection = iwl_tt_is_low_power_state,
410 .tt_power_mode = iwl_tt_current_power_mode,
411 .ct_kill_check = iwl_check_for_ct_kill,
412 }
408}; 413};
409 414
410static struct iwl_lib_ops iwl5150_lib = { 415static struct iwl_lib_ops iwl5150_lib = {
@@ -470,6 +475,11 @@ static struct iwl_lib_ops iwl5150_lib = {
470 .check_ack_health = iwl_good_ack_health, 475 .check_ack_health = iwl_good_ack_health,
471 .txfifo_flush = iwlagn_txfifo_flush, 476 .txfifo_flush = iwlagn_txfifo_flush,
472 .dev_txfifo_flush = iwlagn_dev_txfifo_flush, 477 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
478 .tt_ops = {
479 .lower_power_detection = iwl_tt_is_low_power_state,
480 .tt_power_mode = iwl_tt_current_power_mode,
481 .ct_kill_check = iwl_check_for_ct_kill,
482 }
473}; 483};
474 484
475static const struct iwl_ops iwl5000_ops = { 485static const struct iwl_ops iwl5000_ops = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index af4fd50f3405..7902de172a38 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -330,6 +330,11 @@ static struct iwl_lib_ops iwl6000_lib = {
330 .check_ack_health = iwl_good_ack_health, 330 .check_ack_health = iwl_good_ack_health,
331 .txfifo_flush = iwlagn_txfifo_flush, 331 .txfifo_flush = iwlagn_txfifo_flush,
332 .dev_txfifo_flush = iwlagn_dev_txfifo_flush, 332 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
333 .tt_ops = {
334 .lower_power_detection = iwl_tt_is_low_power_state,
335 .tt_power_mode = iwl_tt_current_power_mode,
336 .ct_kill_check = iwl_check_for_ct_kill,
337 }
333}; 338};
334 339
335static const struct iwl_ops iwl6000_ops = { 340static const struct iwl_ops iwl6000_ops = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tt.c b/drivers/net/wireless/iwlwifi/iwl-agn-tt.c
new file mode 100644
index 000000000000..30298ea56a24
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tt.c
@@ -0,0 +1,696 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Intel Corporation. All rights reserved.
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:
25 * Intel Linux Wireless <ilw@linux.intel.com>
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>
32#include <linux/slab.h>
33#include <linux/init.h>
34
35#include <net/mac80211.h>
36
37#include "iwl-eeprom.h"
38#include "iwl-dev.h"
39#include "iwl-core.h"
40#include "iwl-io.h"
41#include "iwl-commands.h"
42#include "iwl-debug.h"
43#include "iwl-agn-tt.h"
44
45/* default Thermal Throttling transaction table
46 * Current state | Throttling Down | Throttling Up
47 *=============================================================================
48 * Condition Nxt State Condition Nxt State Condition Nxt State
49 *-----------------------------------------------------------------------------
50 * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A
51 * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0
52 * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1
53 * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0
54 *=============================================================================
55 */
56static const struct iwl_tt_trans tt_range_0[IWL_TI_STATE_MAX - 1] = {
57 {IWL_TI_0, IWL_ABSOLUTE_ZERO, 104},
58 {IWL_TI_1, 105, CT_KILL_THRESHOLD - 1},
59 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
60};
61static const struct iwl_tt_trans tt_range_1[IWL_TI_STATE_MAX - 1] = {
62 {IWL_TI_0, IWL_ABSOLUTE_ZERO, 95},
63 {IWL_TI_2, 110, CT_KILL_THRESHOLD - 1},
64 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
65};
66static const struct iwl_tt_trans tt_range_2[IWL_TI_STATE_MAX - 1] = {
67 {IWL_TI_1, IWL_ABSOLUTE_ZERO, 100},
68 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX},
69 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
70};
71static const struct iwl_tt_trans tt_range_3[IWL_TI_STATE_MAX - 1] = {
72 {IWL_TI_0, IWL_ABSOLUTE_ZERO, CT_KILL_EXIT_THRESHOLD},
73 {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX},
74 {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX}
75};
76
77/* Advance Thermal Throttling default restriction table */
78static const struct iwl_tt_restriction restriction_range[IWL_TI_STATE_MAX] = {
79 {IWL_ANT_OK_MULTI, IWL_ANT_OK_MULTI, true },
80 {IWL_ANT_OK_SINGLE, IWL_ANT_OK_MULTI, true },
81 {IWL_ANT_OK_SINGLE, IWL_ANT_OK_SINGLE, false },
82 {IWL_ANT_OK_NONE, IWL_ANT_OK_NONE, false }
83};
84
85bool iwl_tt_is_low_power_state(struct iwl_priv *priv)
86{
87 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
88
89 if (tt->state >= IWL_TI_1)
90 return true;
91 return false;
92}
93
94u8 iwl_tt_current_power_mode(struct iwl_priv *priv)
95{
96 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
97
98 return tt->tt_power_mode;
99}
100
101bool iwl_ht_enabled(struct iwl_priv *priv)
102{
103 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
104 struct iwl_tt_restriction *restriction;
105
106 if (!priv->thermal_throttle.advanced_tt)
107 return true;
108 restriction = tt->restriction + tt->state;
109 return restriction->is_ht;
110}
111
112static bool iwl_within_ct_kill_margin(struct iwl_priv *priv)
113{
114 s32 temp = priv->temperature; /* degrees CELSIUS except specified */
115 bool within_margin = false;
116
117 if (priv->cfg->temperature_kelvin)
118 temp = KELVIN_TO_CELSIUS(priv->temperature);
119
120 if (!priv->thermal_throttle.advanced_tt)
121 within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >=
122 CT_KILL_THRESHOLD_LEGACY) ? true : false;
123 else
124 within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >=
125 CT_KILL_THRESHOLD) ? true : false;
126 return within_margin;
127}
128
129bool iwl_check_for_ct_kill(struct iwl_priv *priv)
130{
131 bool is_ct_kill = false;
132
133 if (iwl_within_ct_kill_margin(priv)) {
134 iwl_tt_enter_ct_kill(priv);
135 is_ct_kill = true;
136 }
137 return is_ct_kill;
138}
139
140enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv)
141{
142 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
143 struct iwl_tt_restriction *restriction;
144
145 if (!priv->thermal_throttle.advanced_tt)
146 return IWL_ANT_OK_MULTI;
147 restriction = tt->restriction + tt->state;
148 return restriction->tx_stream;
149}
150
151enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv)
152{
153 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
154 struct iwl_tt_restriction *restriction;
155
156 if (!priv->thermal_throttle.advanced_tt)
157 return IWL_ANT_OK_MULTI;
158 restriction = tt->restriction + tt->state;
159 return restriction->rx_stream;
160}
161
162#define CT_KILL_EXIT_DURATION (5) /* 5 seconds duration */
163#define CT_KILL_WAITING_DURATION (300) /* 300ms duration */
164
165/*
166 * toggle the bit to wake up uCode and check the temperature
167 * if the temperature is below CT, uCode will stay awake and send card
168 * state notification with CT_KILL bit clear to inform Thermal Throttling
169 * Management to change state. Otherwise, uCode will go back to sleep
170 * without doing anything, driver should continue the 5 seconds timer
171 * to wake up uCode for temperature check until temperature drop below CT
172 */
173static void iwl_tt_check_exit_ct_kill(unsigned long data)
174{
175 struct iwl_priv *priv = (struct iwl_priv *)data;
176 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
177 unsigned long flags;
178
179 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
180 return;
181
182 if (tt->state == IWL_TI_CT_KILL) {
183 if (priv->thermal_throttle.ct_kill_toggle) {
184 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
185 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
186 priv->thermal_throttle.ct_kill_toggle = false;
187 } else {
188 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
189 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
190 priv->thermal_throttle.ct_kill_toggle = true;
191 }
192 iwl_read32(priv, CSR_UCODE_DRV_GP1);
193 spin_lock_irqsave(&priv->reg_lock, flags);
194 if (!iwl_grab_nic_access(priv))
195 iwl_release_nic_access(priv);
196 spin_unlock_irqrestore(&priv->reg_lock, flags);
197
198 /* Reschedule the ct_kill timer to occur in
199 * CT_KILL_EXIT_DURATION seconds to ensure we get a
200 * thermal update */
201 IWL_DEBUG_POWER(priv, "schedule ct_kill exit timer\n");
202 mod_timer(&priv->thermal_throttle.ct_kill_exit_tm,
203 jiffies + CT_KILL_EXIT_DURATION * HZ);
204 }
205}
206
207static void iwl_perform_ct_kill_task(struct iwl_priv *priv,
208 bool stop)
209{
210 if (stop) {
211 IWL_DEBUG_POWER(priv, "Stop all queues\n");
212 if (priv->mac80211_registered)
213 ieee80211_stop_queues(priv->hw);
214 IWL_DEBUG_POWER(priv,
215 "Schedule 5 seconds CT_KILL Timer\n");
216 mod_timer(&priv->thermal_throttle.ct_kill_exit_tm,
217 jiffies + CT_KILL_EXIT_DURATION * HZ);
218 } else {
219 IWL_DEBUG_POWER(priv, "Wake all queues\n");
220 if (priv->mac80211_registered)
221 ieee80211_wake_queues(priv->hw);
222 }
223}
224
225static void iwl_tt_ready_for_ct_kill(unsigned long data)
226{
227 struct iwl_priv *priv = (struct iwl_priv *)data;
228 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
229
230 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
231 return;
232
233 /* temperature timer expired, ready to go into CT_KILL state */
234 if (tt->state != IWL_TI_CT_KILL) {
235 IWL_DEBUG_POWER(priv, "entering CT_KILL state when "
236 "temperature timer expired\n");
237 tt->state = IWL_TI_CT_KILL;
238 set_bit(STATUS_CT_KILL, &priv->status);
239 iwl_perform_ct_kill_task(priv, true);
240 }
241}
242
243static void iwl_prepare_ct_kill_task(struct iwl_priv *priv)
244{
245 IWL_DEBUG_POWER(priv, "Prepare to enter IWL_TI_CT_KILL\n");
246 /* make request to retrieve statistics information */
247 iwl_send_statistics_request(priv, CMD_SYNC, false);
248 /* Reschedule the ct_kill wait timer */
249 mod_timer(&priv->thermal_throttle.ct_kill_waiting_tm,
250 jiffies + msecs_to_jiffies(CT_KILL_WAITING_DURATION));
251}
252
253#define IWL_MINIMAL_POWER_THRESHOLD (CT_KILL_THRESHOLD_LEGACY)
254#define IWL_REDUCED_PERFORMANCE_THRESHOLD_2 (100)
255#define IWL_REDUCED_PERFORMANCE_THRESHOLD_1 (90)
256
257/*
258 * Legacy thermal throttling
259 * 1) Avoid NIC destruction due to high temperatures
260 * Chip will identify dangerously high temperatures that can
261 * harm the device and will power down
262 * 2) Avoid the NIC power down due to high temperature
263 * Throttle early enough to lower the power consumption before
264 * drastic steps are needed
265 */
266static void iwl_legacy_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
267{
268 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
269 enum iwl_tt_state old_state;
270
271#ifdef CONFIG_IWLWIFI_DEBUG
272 if ((tt->tt_previous_temp) &&
273 (temp > tt->tt_previous_temp) &&
274 ((temp - tt->tt_previous_temp) >
275 IWL_TT_INCREASE_MARGIN)) {
276 IWL_DEBUG_POWER(priv,
277 "Temperature increase %d degree Celsius\n",
278 (temp - tt->tt_previous_temp));
279 }
280#endif
281 old_state = tt->state;
282 /* in Celsius */
283 if (temp >= IWL_MINIMAL_POWER_THRESHOLD)
284 tt->state = IWL_TI_CT_KILL;
285 else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_2)
286 tt->state = IWL_TI_2;
287 else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_1)
288 tt->state = IWL_TI_1;
289 else
290 tt->state = IWL_TI_0;
291
292#ifdef CONFIG_IWLWIFI_DEBUG
293 tt->tt_previous_temp = temp;
294#endif
295 /* stop ct_kill_waiting_tm timer */
296 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
297 if (tt->state != old_state) {
298 switch (tt->state) {
299 case IWL_TI_0:
300 /*
301 * When the system is ready to go back to IWL_TI_0
302 * we only have to call iwl_power_update_mode() to
303 * do so.
304 */
305 break;
306 case IWL_TI_1:
307 tt->tt_power_mode = IWL_POWER_INDEX_3;
308 break;
309 case IWL_TI_2:
310 tt->tt_power_mode = IWL_POWER_INDEX_4;
311 break;
312 default:
313 tt->tt_power_mode = IWL_POWER_INDEX_5;
314 break;
315 }
316 mutex_lock(&priv->mutex);
317 if (old_state == IWL_TI_CT_KILL)
318 clear_bit(STATUS_CT_KILL, &priv->status);
319 if (tt->state != IWL_TI_CT_KILL &&
320 iwl_power_update_mode(priv, true)) {
321 /* TT state not updated
322 * try again during next temperature read
323 */
324 if (old_state == IWL_TI_CT_KILL)
325 set_bit(STATUS_CT_KILL, &priv->status);
326 tt->state = old_state;
327 IWL_ERR(priv, "Cannot update power mode, "
328 "TT state not updated\n");
329 } else {
330 if (tt->state == IWL_TI_CT_KILL) {
331 if (force) {
332 set_bit(STATUS_CT_KILL, &priv->status);
333 iwl_perform_ct_kill_task(priv, true);
334 } else {
335 iwl_prepare_ct_kill_task(priv);
336 tt->state = old_state;
337 }
338 } else if (old_state == IWL_TI_CT_KILL &&
339 tt->state != IWL_TI_CT_KILL)
340 iwl_perform_ct_kill_task(priv, false);
341 IWL_DEBUG_POWER(priv, "Temperature state changed %u\n",
342 tt->state);
343 IWL_DEBUG_POWER(priv, "Power Index change to %u\n",
344 tt->tt_power_mode);
345 }
346 mutex_unlock(&priv->mutex);
347 }
348}
349
350/*
351 * Advance thermal throttling
352 * 1) Avoid NIC destruction due to high temperatures
353 * Chip will identify dangerously high temperatures that can
354 * harm the device and will power down
355 * 2) Avoid the NIC power down due to high temperature
356 * Throttle early enough to lower the power consumption before
357 * drastic steps are needed
358 * Actions include relaxing the power down sleep thresholds and
359 * decreasing the number of TX streams
360 * 3) Avoid throughput performance impact as much as possible
361 *
362 *=============================================================================
363 * Condition Nxt State Condition Nxt State Condition Nxt State
364 *-----------------------------------------------------------------------------
365 * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A
366 * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0
367 * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1
368 * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0
369 *=============================================================================
370 */
371static void iwl_advance_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
372{
373 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
374 int i;
375 bool changed = false;
376 enum iwl_tt_state old_state;
377 struct iwl_tt_trans *transaction;
378
379 old_state = tt->state;
380 for (i = 0; i < IWL_TI_STATE_MAX - 1; i++) {
381 /* based on the current TT state,
382 * find the curresponding transaction table
383 * each table has (IWL_TI_STATE_MAX - 1) entries
384 * tt->transaction + ((old_state * (IWL_TI_STATE_MAX - 1))
385 * will advance to the correct table.
386 * then based on the current temperature
387 * find the next state need to transaction to
388 * go through all the possible (IWL_TI_STATE_MAX - 1) entries
389 * in the current table to see if transaction is needed
390 */
391 transaction = tt->transaction +
392 ((old_state * (IWL_TI_STATE_MAX - 1)) + i);
393 if (temp >= transaction->tt_low &&
394 temp <= transaction->tt_high) {
395#ifdef CONFIG_IWLWIFI_DEBUG
396 if ((tt->tt_previous_temp) &&
397 (temp > tt->tt_previous_temp) &&
398 ((temp - tt->tt_previous_temp) >
399 IWL_TT_INCREASE_MARGIN)) {
400 IWL_DEBUG_POWER(priv,
401 "Temperature increase %d "
402 "degree Celsius\n",
403 (temp - tt->tt_previous_temp));
404 }
405 tt->tt_previous_temp = temp;
406#endif
407 if (old_state !=
408 transaction->next_state) {
409 changed = true;
410 tt->state =
411 transaction->next_state;
412 }
413 break;
414 }
415 }
416 /* stop ct_kill_waiting_tm timer */
417 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
418 if (changed) {
419 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
420
421 if (tt->state >= IWL_TI_1) {
422 /* force PI = IWL_POWER_INDEX_5 in the case of TI > 0 */
423 tt->tt_power_mode = IWL_POWER_INDEX_5;
424 if (!iwl_ht_enabled(priv))
425 /* disable HT */
426 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
427 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
428 RXON_FLG_HT40_PROT_MSK |
429 RXON_FLG_HT_PROT_MSK);
430 else {
431 /* check HT capability and set
432 * according to the system HT capability
433 * in case get disabled before */
434 iwl_set_rxon_ht(priv, &priv->current_ht_config);
435 }
436
437 } else {
438 /*
439 * restore system power setting -- it will be
440 * recalculated automatically.
441 */
442
443 /* check HT capability and set
444 * according to the system HT capability
445 * in case get disabled before */
446 iwl_set_rxon_ht(priv, &priv->current_ht_config);
447 }
448 mutex_lock(&priv->mutex);
449 if (old_state == IWL_TI_CT_KILL)
450 clear_bit(STATUS_CT_KILL, &priv->status);
451 if (tt->state != IWL_TI_CT_KILL &&
452 iwl_power_update_mode(priv, true)) {
453 /* TT state not updated
454 * try again during next temperature read
455 */
456 IWL_ERR(priv, "Cannot update power mode, "
457 "TT state not updated\n");
458 if (old_state == IWL_TI_CT_KILL)
459 set_bit(STATUS_CT_KILL, &priv->status);
460 tt->state = old_state;
461 } else {
462 IWL_DEBUG_POWER(priv,
463 "Thermal Throttling to new state: %u\n",
464 tt->state);
465 if (old_state != IWL_TI_CT_KILL &&
466 tt->state == IWL_TI_CT_KILL) {
467 if (force) {
468 IWL_DEBUG_POWER(priv,
469 "Enter IWL_TI_CT_KILL\n");
470 set_bit(STATUS_CT_KILL, &priv->status);
471 iwl_perform_ct_kill_task(priv, true);
472 } else {
473 iwl_prepare_ct_kill_task(priv);
474 tt->state = old_state;
475 }
476 } else if (old_state == IWL_TI_CT_KILL &&
477 tt->state != IWL_TI_CT_KILL) {
478 IWL_DEBUG_POWER(priv, "Exit IWL_TI_CT_KILL\n");
479 iwl_perform_ct_kill_task(priv, false);
480 }
481 }
482 mutex_unlock(&priv->mutex);
483 }
484}
485
486/* Card State Notification indicated reach critical temperature
487 * if PSP not enable, no Thermal Throttling function will be performed
488 * just set the GP1 bit to acknowledge the event
489 * otherwise, go into IWL_TI_CT_KILL state
490 * since Card State Notification will not provide any temperature reading
491 * for Legacy mode
492 * so just pass the CT_KILL temperature to iwl_legacy_tt_handler()
493 * for advance mode
494 * pass CT_KILL_THRESHOLD+1 to make sure move into IWL_TI_CT_KILL state
495 */
496static void iwl_bg_ct_enter(struct work_struct *work)
497{
498 struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_enter);
499 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
500
501 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
502 return;
503
504 if (!iwl_is_ready(priv))
505 return;
506
507 if (tt->state != IWL_TI_CT_KILL) {
508 IWL_ERR(priv, "Device reached critical temperature "
509 "- ucode going to sleep!\n");
510 if (!priv->thermal_throttle.advanced_tt)
511 iwl_legacy_tt_handler(priv,
512 IWL_MINIMAL_POWER_THRESHOLD,
513 true);
514 else
515 iwl_advance_tt_handler(priv,
516 CT_KILL_THRESHOLD + 1, true);
517 }
518}
519
520/* Card State Notification indicated out of critical temperature
521 * since Card State Notification will not provide any temperature reading
522 * so pass the IWL_REDUCED_PERFORMANCE_THRESHOLD_2 temperature
523 * to iwl_legacy_tt_handler() to get out of IWL_CT_KILL state
524 */
525static void iwl_bg_ct_exit(struct work_struct *work)
526{
527 struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_exit);
528 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
529
530 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
531 return;
532
533 if (!iwl_is_ready(priv))
534 return;
535
536 /* stop ct_kill_exit_tm timer */
537 del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm);
538
539 if (tt->state == IWL_TI_CT_KILL) {
540 IWL_ERR(priv,
541 "Device temperature below critical"
542 "- ucode awake!\n");
543 /*
544 * exit from CT_KILL state
545 * reset the current temperature reading
546 */
547 priv->temperature = 0;
548 if (!priv->thermal_throttle.advanced_tt)
549 iwl_legacy_tt_handler(priv,
550 IWL_REDUCED_PERFORMANCE_THRESHOLD_2,
551 true);
552 else
553 iwl_advance_tt_handler(priv, CT_KILL_EXIT_THRESHOLD,
554 true);
555 }
556}
557
558void iwl_tt_enter_ct_kill(struct iwl_priv *priv)
559{
560 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
561 return;
562
563 IWL_DEBUG_POWER(priv, "Queueing critical temperature enter.\n");
564 queue_work(priv->workqueue, &priv->ct_enter);
565}
566EXPORT_SYMBOL(iwl_tt_enter_ct_kill);
567
568void iwl_tt_exit_ct_kill(struct iwl_priv *priv)
569{
570 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
571 return;
572
573 IWL_DEBUG_POWER(priv, "Queueing critical temperature exit.\n");
574 queue_work(priv->workqueue, &priv->ct_exit);
575}
576EXPORT_SYMBOL(iwl_tt_exit_ct_kill);
577
578static void iwl_bg_tt_work(struct work_struct *work)
579{
580 struct iwl_priv *priv = container_of(work, struct iwl_priv, tt_work);
581 s32 temp = priv->temperature; /* degrees CELSIUS except specified */
582
583 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
584 return;
585
586 if (priv->cfg->temperature_kelvin)
587 temp = KELVIN_TO_CELSIUS(priv->temperature);
588
589 if (!priv->thermal_throttle.advanced_tt)
590 iwl_legacy_tt_handler(priv, temp, false);
591 else
592 iwl_advance_tt_handler(priv, temp, false);
593}
594
595void iwl_tt_handler(struct iwl_priv *priv)
596{
597 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
598 return;
599
600 IWL_DEBUG_POWER(priv, "Queueing thermal throttling work.\n");
601 queue_work(priv->workqueue, &priv->tt_work);
602}
603EXPORT_SYMBOL(iwl_tt_handler);
604
605/* Thermal throttling initialization
606 * For advance thermal throttling:
607 * Initialize Thermal Index and temperature threshold table
608 * Initialize thermal throttling restriction table
609 */
610void iwl_tt_initialize(struct iwl_priv *priv)
611{
612 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
613 int size = sizeof(struct iwl_tt_trans) * (IWL_TI_STATE_MAX - 1);
614 struct iwl_tt_trans *transaction;
615
616 IWL_DEBUG_POWER(priv, "Initialize Thermal Throttling\n");
617
618 memset(tt, 0, sizeof(struct iwl_tt_mgmt));
619
620 tt->state = IWL_TI_0;
621 init_timer(&priv->thermal_throttle.ct_kill_exit_tm);
622 priv->thermal_throttle.ct_kill_exit_tm.data = (unsigned long)priv;
623 priv->thermal_throttle.ct_kill_exit_tm.function =
624 iwl_tt_check_exit_ct_kill;
625 init_timer(&priv->thermal_throttle.ct_kill_waiting_tm);
626 priv->thermal_throttle.ct_kill_waiting_tm.data =
627 (unsigned long)priv;
628 priv->thermal_throttle.ct_kill_waiting_tm.function =
629 iwl_tt_ready_for_ct_kill;
630 /* setup deferred ct kill work */
631 INIT_WORK(&priv->tt_work, iwl_bg_tt_work);
632 INIT_WORK(&priv->ct_enter, iwl_bg_ct_enter);
633 INIT_WORK(&priv->ct_exit, iwl_bg_ct_exit);
634
635 if (priv->cfg->adv_thermal_throttle) {
636 IWL_DEBUG_POWER(priv, "Advanced Thermal Throttling\n");
637 tt->restriction = kzalloc(sizeof(struct iwl_tt_restriction) *
638 IWL_TI_STATE_MAX, GFP_KERNEL);
639 tt->transaction = kzalloc(sizeof(struct iwl_tt_trans) *
640 IWL_TI_STATE_MAX * (IWL_TI_STATE_MAX - 1),
641 GFP_KERNEL);
642 if (!tt->restriction || !tt->transaction) {
643 IWL_ERR(priv, "Fallback to Legacy Throttling\n");
644 priv->thermal_throttle.advanced_tt = false;
645 kfree(tt->restriction);
646 tt->restriction = NULL;
647 kfree(tt->transaction);
648 tt->transaction = NULL;
649 } else {
650 transaction = tt->transaction +
651 (IWL_TI_0 * (IWL_TI_STATE_MAX - 1));
652 memcpy(transaction, &tt_range_0[0], size);
653 transaction = tt->transaction +
654 (IWL_TI_1 * (IWL_TI_STATE_MAX - 1));
655 memcpy(transaction, &tt_range_1[0], size);
656 transaction = tt->transaction +
657 (IWL_TI_2 * (IWL_TI_STATE_MAX - 1));
658 memcpy(transaction, &tt_range_2[0], size);
659 transaction = tt->transaction +
660 (IWL_TI_CT_KILL * (IWL_TI_STATE_MAX - 1));
661 memcpy(transaction, &tt_range_3[0], size);
662 size = sizeof(struct iwl_tt_restriction) *
663 IWL_TI_STATE_MAX;
664 memcpy(tt->restriction,
665 &restriction_range[0], size);
666 priv->thermal_throttle.advanced_tt = true;
667 }
668 } else {
669 IWL_DEBUG_POWER(priv, "Legacy Thermal Throttling\n");
670 priv->thermal_throttle.advanced_tt = false;
671 }
672}
673EXPORT_SYMBOL(iwl_tt_initialize);
674
675/* cleanup thermal throttling management related memory and timer */
676void iwl_tt_exit(struct iwl_priv *priv)
677{
678 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
679
680 /* stop ct_kill_exit_tm timer if activated */
681 del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm);
682 /* stop ct_kill_waiting_tm timer if activated */
683 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
684 cancel_work_sync(&priv->tt_work);
685 cancel_work_sync(&priv->ct_enter);
686 cancel_work_sync(&priv->ct_exit);
687
688 if (priv->thermal_throttle.advanced_tt) {
689 /* free advance thermal throttling memory */
690 kfree(tt->restriction);
691 tt->restriction = NULL;
692 kfree(tt->transaction);
693 tt->transaction = NULL;
694 }
695}
696EXPORT_SYMBOL(iwl_tt_exit);
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tt.h b/drivers/net/wireless/iwlwifi/iwl-agn-tt.h
new file mode 100644
index 000000000000..d55060427cac
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tt.h
@@ -0,0 +1,129 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Intel Corporation. All rights reserved.
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:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28#ifndef __iwl_tt_setting_h__
29#define __iwl_tt_setting_h__
30
31#include "iwl-commands.h"
32
33#define IWL_ABSOLUTE_ZERO 0
34#define IWL_ABSOLUTE_MAX 0xFFFFFFFF
35#define IWL_TT_INCREASE_MARGIN 5
36#define IWL_TT_CT_KILL_MARGIN 3
37
38enum iwl_antenna_ok {
39 IWL_ANT_OK_NONE,
40 IWL_ANT_OK_SINGLE,
41 IWL_ANT_OK_MULTI,
42};
43
44/* Thermal Throttling State Machine states */
45enum iwl_tt_state {
46 IWL_TI_0, /* normal temperature, system power state */
47 IWL_TI_1, /* high temperature detect, low power state */
48 IWL_TI_2, /* higher temperature detected, lower power state */
49 IWL_TI_CT_KILL, /* critical temperature detected, lowest power state */
50 IWL_TI_STATE_MAX
51};
52
53/**
54 * struct iwl_tt_restriction - Thermal Throttling restriction table
55 * @tx_stream: number of tx stream allowed
56 * @is_ht: ht enable/disable
57 * @rx_stream: number of rx stream allowed
58 *
59 * This table is used by advance thermal throttling management
60 * based on the current thermal throttling state, and determines
61 * the number of tx/rx streams and the status of HT operation.
62 */
63struct iwl_tt_restriction {
64 enum iwl_antenna_ok tx_stream;
65 enum iwl_antenna_ok rx_stream;
66 bool is_ht;
67};
68
69/**
70 * struct iwl_tt_trans - Thermal Throttling transaction table
71 * @next_state: next thermal throttling mode
72 * @tt_low: low temperature threshold to change state
73 * @tt_high: high temperature threshold to change state
74 *
75 * This is used by the advanced thermal throttling algorithm
76 * to determine the next thermal state to go based on the
77 * current temperature.
78 */
79struct iwl_tt_trans {
80 enum iwl_tt_state next_state;
81 u32 tt_low;
82 u32 tt_high;
83};
84
85/**
86 * struct iwl_tt_mgnt - Thermal Throttling Management structure
87 * @advanced_tt: advanced thermal throttle required
88 * @state: current Thermal Throttling state
89 * @tt_power_mode: Thermal Throttling power mode index
90 * being used to set power level when
91 * when thermal throttling state != IWL_TI_0
92 * the tt_power_mode should set to different
93 * power mode based on the current tt state
94 * @tt_previous_temperature: last measured temperature
95 * @iwl_tt_restriction: ptr to restriction tbl, used by advance
96 * thermal throttling to determine how many tx/rx streams
97 * should be used in tt state; and can HT be enabled or not
98 * @iwl_tt_trans: ptr to adv trans table, used by advance thermal throttling
99 * state transaction
100 * @ct_kill_toggle: used to toggle the CSR bit when checking uCode temperature
101 * @ct_kill_exit_tm: timer to exit thermal kill
102 */
103struct iwl_tt_mgmt {
104 enum iwl_tt_state state;
105 bool advanced_tt;
106 u8 tt_power_mode;
107 bool ct_kill_toggle;
108#ifdef CONFIG_IWLWIFI_DEBUG
109 s32 tt_previous_temp;
110#endif
111 struct iwl_tt_restriction *restriction;
112 struct iwl_tt_trans *transaction;
113 struct timer_list ct_kill_exit_tm;
114 struct timer_list ct_kill_waiting_tm;
115};
116
117u8 iwl_tt_current_power_mode(struct iwl_priv *priv);
118bool iwl_tt_is_low_power_state(struct iwl_priv *priv);
119bool iwl_ht_enabled(struct iwl_priv *priv);
120bool iwl_check_for_ct_kill(struct iwl_priv *priv);
121enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv);
122enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv);
123void iwl_tt_enter_ct_kill(struct iwl_priv *priv);
124void iwl_tt_exit_ct_kill(struct iwl_priv *priv);
125void iwl_tt_handler(struct iwl_priv *priv);
126void iwl_tt_initialize(struct iwl_priv *priv);
127void iwl_tt_exit(struct iwl_priv *priv);
128
129#endif /* __iwl_tt_setting_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 21a52ae05c0d..bce77eeb31c0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -2592,6 +2592,52 @@ int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
2592 return pos; 2592 return pos;
2593} 2593}
2594 2594
2595static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
2596{
2597 struct iwl_ct_kill_config cmd;
2598 struct iwl_ct_kill_throttling_config adv_cmd;
2599 unsigned long flags;
2600 int ret = 0;
2601
2602 spin_lock_irqsave(&priv->lock, flags);
2603 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2604 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
2605 spin_unlock_irqrestore(&priv->lock, flags);
2606 priv->thermal_throttle.ct_kill_toggle = false;
2607
2608 if (priv->cfg->support_ct_kill_exit) {
2609 adv_cmd.critical_temperature_enter =
2610 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2611 adv_cmd.critical_temperature_exit =
2612 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
2613
2614 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2615 sizeof(adv_cmd), &adv_cmd);
2616 if (ret)
2617 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2618 else
2619 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2620 "succeeded, "
2621 "critical temperature enter is %d,"
2622 "exit is %d\n",
2623 priv->hw_params.ct_kill_threshold,
2624 priv->hw_params.ct_kill_exit_threshold);
2625 } else {
2626 cmd.critical_temperature_R =
2627 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2628
2629 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2630 sizeof(cmd), &cmd);
2631 if (ret)
2632 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2633 else
2634 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2635 "succeeded, "
2636 "critical temperature is %d\n",
2637 priv->hw_params.ct_kill_threshold);
2638 }
2639}
2640
2595/** 2641/**
2596 * iwl_alive_start - called after REPLY_ALIVE notification received 2642 * iwl_alive_start - called after REPLY_ALIVE notification received
2597 * from protocol/runtime uCode (initialization uCode's 2643 * from protocol/runtime uCode (initialization uCode's
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index ccdf3c02bb3c..b5045c62de7e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -1514,54 +1514,6 @@ int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
1514} 1514}
1515EXPORT_SYMBOL(iwl_send_statistics_request); 1515EXPORT_SYMBOL(iwl_send_statistics_request);
1516 1516
1517void iwl_rf_kill_ct_config(struct iwl_priv *priv)
1518{
1519 struct iwl_ct_kill_config cmd;
1520 struct iwl_ct_kill_throttling_config adv_cmd;
1521 unsigned long flags;
1522 int ret = 0;
1523
1524 spin_lock_irqsave(&priv->lock, flags);
1525 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
1526 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1527 spin_unlock_irqrestore(&priv->lock, flags);
1528 priv->thermal_throttle.ct_kill_toggle = false;
1529
1530 if (priv->cfg->support_ct_kill_exit) {
1531 adv_cmd.critical_temperature_enter =
1532 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1533 adv_cmd.critical_temperature_exit =
1534 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
1535
1536 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1537 sizeof(adv_cmd), &adv_cmd);
1538 if (ret)
1539 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1540 else
1541 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1542 "succeeded, "
1543 "critical temperature enter is %d,"
1544 "exit is %d\n",
1545 priv->hw_params.ct_kill_threshold,
1546 priv->hw_params.ct_kill_exit_threshold);
1547 } else {
1548 cmd.critical_temperature_R =
1549 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1550
1551 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1552 sizeof(cmd), &cmd);
1553 if (ret)
1554 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1555 else
1556 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1557 "succeeded, "
1558 "critical temperature is %d\n",
1559 priv->hw_params.ct_kill_threshold);
1560 }
1561}
1562EXPORT_SYMBOL(iwl_rf_kill_ct_config);
1563
1564
1565/* 1517/*
1566 * CARD_STATE_CMD 1518 * CARD_STATE_CMD
1567 * 1519 *
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index 7f1aaf206078..e6d127df01ea 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -136,6 +136,12 @@ struct iwl_temp_ops {
136 void (*set_calib_version)(struct iwl_priv *priv); 136 void (*set_calib_version)(struct iwl_priv *priv);
137}; 137};
138 138
139struct iwl_tt_ops {
140 bool (*lower_power_detection)(struct iwl_priv *priv);
141 u8 (*tt_power_mode)(struct iwl_priv *priv);
142 bool (*ct_kill_check)(struct iwl_priv *priv);
143};
144
139struct iwl_lib_ops { 145struct iwl_lib_ops {
140 /* set hw dependent parameters */ 146 /* set hw dependent parameters */
141 int (*set_hw_params)(struct iwl_priv *priv); 147 int (*set_hw_params)(struct iwl_priv *priv);
@@ -212,6 +218,9 @@ struct iwl_lib_ops {
212 void (*dev_txfifo_flush)(struct iwl_priv *priv, u16 flush_control); 218 void (*dev_txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
213 219
214 struct iwl_debugfs_ops debugfs_ops; 220 struct iwl_debugfs_ops debugfs_ops;
221
222 /* thermal throttling */
223 struct iwl_tt_ops tt_ops;
215}; 224};
216 225
217struct iwl_led_ops { 226struct iwl_led_ops {
@@ -693,7 +702,6 @@ static inline int iwl_is_ready_rf(struct iwl_priv *priv)
693 return iwl_is_ready(priv); 702 return iwl_is_ready(priv);
694} 703}
695 704
696extern void iwl_rf_kill_ct_config(struct iwl_priv *priv);
697extern void iwl_send_bt_config(struct iwl_priv *priv); 705extern void iwl_send_bt_config(struct iwl_priv *priv);
698extern int iwl_send_statistics_request(struct iwl_priv *priv, 706extern int iwl_send_statistics_request(struct iwl_priv *priv,
699 u8 flags, bool clear); 707 u8 flags, bool clear);
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index 149619fb1c07..a2927b3a606e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -47,6 +47,7 @@
47#include "iwl-led.h" 47#include "iwl-led.h"
48#include "iwl-power.h" 48#include "iwl-power.h"
49#include "iwl-agn-rs.h" 49#include "iwl-agn-rs.h"
50#include "iwl-agn-tt.h"
50 51
51struct iwl_tx_queue; 52struct iwl_tx_queue;
52 53
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.c b/drivers/net/wireless/iwlwifi/iwl-power.c
index cda6a94d6cc9..da1f2ae24472 100644
--- a/drivers/net/wireless/iwlwifi/iwl-power.c
+++ b/drivers/net/wireless/iwlwifi/iwl-power.c
@@ -192,47 +192,6 @@ static void iwl_static_sleep_cmd(struct iwl_priv *priv,
192 IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1); 192 IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1);
193} 193}
194 194
195/* default Thermal Throttling transaction table
196 * Current state | Throttling Down | Throttling Up
197 *=============================================================================
198 * Condition Nxt State Condition Nxt State Condition Nxt State
199 *-----------------------------------------------------------------------------
200 * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A
201 * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0
202 * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1
203 * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0
204 *=============================================================================
205 */
206static const struct iwl_tt_trans tt_range_0[IWL_TI_STATE_MAX - 1] = {
207 {IWL_TI_0, IWL_ABSOLUTE_ZERO, 104},
208 {IWL_TI_1, 105, CT_KILL_THRESHOLD - 1},
209 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
210};
211static const struct iwl_tt_trans tt_range_1[IWL_TI_STATE_MAX - 1] = {
212 {IWL_TI_0, IWL_ABSOLUTE_ZERO, 95},
213 {IWL_TI_2, 110, CT_KILL_THRESHOLD - 1},
214 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
215};
216static const struct iwl_tt_trans tt_range_2[IWL_TI_STATE_MAX - 1] = {
217 {IWL_TI_1, IWL_ABSOLUTE_ZERO, 100},
218 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX},
219 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
220};
221static const struct iwl_tt_trans tt_range_3[IWL_TI_STATE_MAX - 1] = {
222 {IWL_TI_0, IWL_ABSOLUTE_ZERO, CT_KILL_EXIT_THRESHOLD},
223 {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX},
224 {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX}
225};
226
227/* Advance Thermal Throttling default restriction table */
228static const struct iwl_tt_restriction restriction_range[IWL_TI_STATE_MAX] = {
229 {IWL_ANT_OK_MULTI, IWL_ANT_OK_MULTI, true },
230 {IWL_ANT_OK_SINGLE, IWL_ANT_OK_MULTI, true },
231 {IWL_ANT_OK_SINGLE, IWL_ANT_OK_SINGLE, false },
232 {IWL_ANT_OK_NONE, IWL_ANT_OK_NONE, false }
233};
234
235
236static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv, 195static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv,
237 struct iwl_powertable_cmd *cmd) 196 struct iwl_powertable_cmd *cmd)
238{ 197{
@@ -308,7 +267,6 @@ static int iwl_set_power(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd)
308int iwl_power_update_mode(struct iwl_priv *priv, bool force) 267int iwl_power_update_mode(struct iwl_priv *priv, bool force)
309{ 268{
310 int ret = 0; 269 int ret = 0;
311 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
312 bool enabled = priv->hw->conf.flags & IEEE80211_CONF_PS; 270 bool enabled = priv->hw->conf.flags & IEEE80211_CONF_PS;
313 bool update_chains; 271 bool update_chains;
314 struct iwl_powertable_cmd cmd; 272 struct iwl_powertable_cmd cmd;
@@ -325,9 +283,15 @@ int iwl_power_update_mode(struct iwl_priv *priv, bool force)
325 else if (priv->cfg->supports_idle && 283 else if (priv->cfg->supports_idle &&
326 priv->hw->conf.flags & IEEE80211_CONF_IDLE) 284 priv->hw->conf.flags & IEEE80211_CONF_IDLE)
327 iwl_static_sleep_cmd(priv, &cmd, IWL_POWER_INDEX_5, 20); 285 iwl_static_sleep_cmd(priv, &cmd, IWL_POWER_INDEX_5, 20);
328 else if (tt->state >= IWL_TI_1) 286 else if (priv->cfg->ops->lib->tt_ops.lower_power_detection &&
329 iwl_static_sleep_cmd(priv, &cmd, tt->tt_power_mode, dtimper); 287 priv->cfg->ops->lib->tt_ops.tt_power_mode) {
330 else if (!enabled) 288 if (priv->cfg->ops->lib->tt_ops.lower_power_detection(priv)) {
289 /* in thermal throttling low power state */
290 iwl_static_sleep_cmd(priv, &cmd,
291 priv->cfg->ops->lib->tt_ops.tt_power_mode(priv),
292 dtimper);
293 }
294 } else if (!enabled)
331 iwl_power_sleep_cam_cmd(priv, &cmd); 295 iwl_power_sleep_cam_cmd(priv, &cmd);
332 else if (priv->power_data.debug_sleep_level_override >= 0) 296 else if (priv->power_data.debug_sleep_level_override >= 0)
333 iwl_static_sleep_cmd(priv, &cmd, 297 iwl_static_sleep_cmd(priv, &cmd,
@@ -367,592 +331,6 @@ int iwl_power_update_mode(struct iwl_priv *priv, bool force)
367} 331}
368EXPORT_SYMBOL(iwl_power_update_mode); 332EXPORT_SYMBOL(iwl_power_update_mode);
369 333
370bool iwl_ht_enabled(struct iwl_priv *priv)
371{
372 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
373 struct iwl_tt_restriction *restriction;
374
375 if (!priv->thermal_throttle.advanced_tt)
376 return true;
377 restriction = tt->restriction + tt->state;
378 return restriction->is_ht;
379}
380EXPORT_SYMBOL(iwl_ht_enabled);
381
382bool iwl_within_ct_kill_margin(struct iwl_priv *priv)
383{
384 s32 temp = priv->temperature; /* degrees CELSIUS except specified */
385 bool within_margin = false;
386
387 if (priv->cfg->temperature_kelvin)
388 temp = KELVIN_TO_CELSIUS(priv->temperature);
389
390 if (!priv->thermal_throttle.advanced_tt)
391 within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >=
392 CT_KILL_THRESHOLD_LEGACY) ? true : false;
393 else
394 within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >=
395 CT_KILL_THRESHOLD) ? true : false;
396 return within_margin;
397}
398
399enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv)
400{
401 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
402 struct iwl_tt_restriction *restriction;
403
404 if (!priv->thermal_throttle.advanced_tt)
405 return IWL_ANT_OK_MULTI;
406 restriction = tt->restriction + tt->state;
407 return restriction->tx_stream;
408}
409EXPORT_SYMBOL(iwl_tx_ant_restriction);
410
411enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv)
412{
413 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
414 struct iwl_tt_restriction *restriction;
415
416 if (!priv->thermal_throttle.advanced_tt)
417 return IWL_ANT_OK_MULTI;
418 restriction = tt->restriction + tt->state;
419 return restriction->rx_stream;
420}
421
422#define CT_KILL_EXIT_DURATION (5) /* 5 seconds duration */
423#define CT_KILL_WAITING_DURATION (300) /* 300ms duration */
424
425/*
426 * toggle the bit to wake up uCode and check the temperature
427 * if the temperature is below CT, uCode will stay awake and send card
428 * state notification with CT_KILL bit clear to inform Thermal Throttling
429 * Management to change state. Otherwise, uCode will go back to sleep
430 * without doing anything, driver should continue the 5 seconds timer
431 * to wake up uCode for temperature check until temperature drop below CT
432 */
433static void iwl_tt_check_exit_ct_kill(unsigned long data)
434{
435 struct iwl_priv *priv = (struct iwl_priv *)data;
436 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
437 unsigned long flags;
438
439 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
440 return;
441
442 if (tt->state == IWL_TI_CT_KILL) {
443 if (priv->thermal_throttle.ct_kill_toggle) {
444 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
445 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
446 priv->thermal_throttle.ct_kill_toggle = false;
447 } else {
448 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
449 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
450 priv->thermal_throttle.ct_kill_toggle = true;
451 }
452 iwl_read32(priv, CSR_UCODE_DRV_GP1);
453 spin_lock_irqsave(&priv->reg_lock, flags);
454 if (!iwl_grab_nic_access(priv))
455 iwl_release_nic_access(priv);
456 spin_unlock_irqrestore(&priv->reg_lock, flags);
457
458 /* Reschedule the ct_kill timer to occur in
459 * CT_KILL_EXIT_DURATION seconds to ensure we get a
460 * thermal update */
461 IWL_DEBUG_POWER(priv, "schedule ct_kill exit timer\n");
462 mod_timer(&priv->thermal_throttle.ct_kill_exit_tm, jiffies +
463 CT_KILL_EXIT_DURATION * HZ);
464 }
465}
466
467static void iwl_perform_ct_kill_task(struct iwl_priv *priv,
468 bool stop)
469{
470 if (stop) {
471 IWL_DEBUG_POWER(priv, "Stop all queues\n");
472 if (priv->mac80211_registered)
473 ieee80211_stop_queues(priv->hw);
474 IWL_DEBUG_POWER(priv,
475 "Schedule 5 seconds CT_KILL Timer\n");
476 mod_timer(&priv->thermal_throttle.ct_kill_exit_tm, jiffies +
477 CT_KILL_EXIT_DURATION * HZ);
478 } else {
479 IWL_DEBUG_POWER(priv, "Wake all queues\n");
480 if (priv->mac80211_registered)
481 ieee80211_wake_queues(priv->hw);
482 }
483}
484
485static void iwl_tt_ready_for_ct_kill(unsigned long data)
486{
487 struct iwl_priv *priv = (struct iwl_priv *)data;
488 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
489
490 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
491 return;
492
493 /* temperature timer expired, ready to go into CT_KILL state */
494 if (tt->state != IWL_TI_CT_KILL) {
495 IWL_DEBUG_POWER(priv, "entering CT_KILL state when temperature timer expired\n");
496 tt->state = IWL_TI_CT_KILL;
497 set_bit(STATUS_CT_KILL, &priv->status);
498 iwl_perform_ct_kill_task(priv, true);
499 }
500}
501
502static void iwl_prepare_ct_kill_task(struct iwl_priv *priv)
503{
504 IWL_DEBUG_POWER(priv, "Prepare to enter IWL_TI_CT_KILL\n");
505 /* make request to retrieve statistics information */
506 iwl_send_statistics_request(priv, CMD_SYNC, false);
507 /* Reschedule the ct_kill wait timer */
508 mod_timer(&priv->thermal_throttle.ct_kill_waiting_tm,
509 jiffies + msecs_to_jiffies(CT_KILL_WAITING_DURATION));
510}
511
512#define IWL_MINIMAL_POWER_THRESHOLD (CT_KILL_THRESHOLD_LEGACY)
513#define IWL_REDUCED_PERFORMANCE_THRESHOLD_2 (100)
514#define IWL_REDUCED_PERFORMANCE_THRESHOLD_1 (90)
515
516/*
517 * Legacy thermal throttling
518 * 1) Avoid NIC destruction due to high temperatures
519 * Chip will identify dangerously high temperatures that can
520 * harm the device and will power down
521 * 2) Avoid the NIC power down due to high temperature
522 * Throttle early enough to lower the power consumption before
523 * drastic steps are needed
524 */
525static void iwl_legacy_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
526{
527 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
528 enum iwl_tt_state old_state;
529
530#ifdef CONFIG_IWLWIFI_DEBUG
531 if ((tt->tt_previous_temp) &&
532 (temp > tt->tt_previous_temp) &&
533 ((temp - tt->tt_previous_temp) >
534 IWL_TT_INCREASE_MARGIN)) {
535 IWL_DEBUG_POWER(priv,
536 "Temperature increase %d degree Celsius\n",
537 (temp - tt->tt_previous_temp));
538 }
539#endif
540 old_state = tt->state;
541 /* in Celsius */
542 if (temp >= IWL_MINIMAL_POWER_THRESHOLD)
543 tt->state = IWL_TI_CT_KILL;
544 else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_2)
545 tt->state = IWL_TI_2;
546 else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_1)
547 tt->state = IWL_TI_1;
548 else
549 tt->state = IWL_TI_0;
550
551#ifdef CONFIG_IWLWIFI_DEBUG
552 tt->tt_previous_temp = temp;
553#endif
554 /* stop ct_kill_waiting_tm timer */
555 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
556 if (tt->state != old_state) {
557 switch (tt->state) {
558 case IWL_TI_0:
559 /*
560 * When the system is ready to go back to IWL_TI_0
561 * we only have to call iwl_power_update_mode() to
562 * do so.
563 */
564 break;
565 case IWL_TI_1:
566 tt->tt_power_mode = IWL_POWER_INDEX_3;
567 break;
568 case IWL_TI_2:
569 tt->tt_power_mode = IWL_POWER_INDEX_4;
570 break;
571 default:
572 tt->tt_power_mode = IWL_POWER_INDEX_5;
573 break;
574 }
575 mutex_lock(&priv->mutex);
576 if (old_state == IWL_TI_CT_KILL)
577 clear_bit(STATUS_CT_KILL, &priv->status);
578 if (tt->state != IWL_TI_CT_KILL &&
579 iwl_power_update_mode(priv, true)) {
580 /* TT state not updated
581 * try again during next temperature read
582 */
583 if (old_state == IWL_TI_CT_KILL)
584 set_bit(STATUS_CT_KILL, &priv->status);
585 tt->state = old_state;
586 IWL_ERR(priv, "Cannot update power mode, "
587 "TT state not updated\n");
588 } else {
589 if (tt->state == IWL_TI_CT_KILL) {
590 if (force) {
591 set_bit(STATUS_CT_KILL, &priv->status);
592 iwl_perform_ct_kill_task(priv, true);
593 } else {
594 iwl_prepare_ct_kill_task(priv);
595 tt->state = old_state;
596 }
597 } else if (old_state == IWL_TI_CT_KILL &&
598 tt->state != IWL_TI_CT_KILL)
599 iwl_perform_ct_kill_task(priv, false);
600 IWL_DEBUG_POWER(priv, "Temperature state changed %u\n",
601 tt->state);
602 IWL_DEBUG_POWER(priv, "Power Index change to %u\n",
603 tt->tt_power_mode);
604 }
605 mutex_unlock(&priv->mutex);
606 }
607}
608
609/*
610 * Advance thermal throttling
611 * 1) Avoid NIC destruction due to high temperatures
612 * Chip will identify dangerously high temperatures that can
613 * harm the device and will power down
614 * 2) Avoid the NIC power down due to high temperature
615 * Throttle early enough to lower the power consumption before
616 * drastic steps are needed
617 * Actions include relaxing the power down sleep thresholds and
618 * decreasing the number of TX streams
619 * 3) Avoid throughput performance impact as much as possible
620 *
621 *=============================================================================
622 * Condition Nxt State Condition Nxt State Condition Nxt State
623 *-----------------------------------------------------------------------------
624 * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A
625 * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0
626 * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1
627 * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0
628 *=============================================================================
629 */
630static void iwl_advance_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
631{
632 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
633 int i;
634 bool changed = false;
635 enum iwl_tt_state old_state;
636 struct iwl_tt_trans *transaction;
637
638 old_state = tt->state;
639 for (i = 0; i < IWL_TI_STATE_MAX - 1; i++) {
640 /* based on the current TT state,
641 * find the curresponding transaction table
642 * each table has (IWL_TI_STATE_MAX - 1) entries
643 * tt->transaction + ((old_state * (IWL_TI_STATE_MAX - 1))
644 * will advance to the correct table.
645 * then based on the current temperature
646 * find the next state need to transaction to
647 * go through all the possible (IWL_TI_STATE_MAX - 1) entries
648 * in the current table to see if transaction is needed
649 */
650 transaction = tt->transaction +
651 ((old_state * (IWL_TI_STATE_MAX - 1)) + i);
652 if (temp >= transaction->tt_low &&
653 temp <= transaction->tt_high) {
654#ifdef CONFIG_IWLWIFI_DEBUG
655 if ((tt->tt_previous_temp) &&
656 (temp > tt->tt_previous_temp) &&
657 ((temp - tt->tt_previous_temp) >
658 IWL_TT_INCREASE_MARGIN)) {
659 IWL_DEBUG_POWER(priv,
660 "Temperature increase %d "
661 "degree Celsius\n",
662 (temp - tt->tt_previous_temp));
663 }
664 tt->tt_previous_temp = temp;
665#endif
666 if (old_state !=
667 transaction->next_state) {
668 changed = true;
669 tt->state =
670 transaction->next_state;
671 }
672 break;
673 }
674 }
675 /* stop ct_kill_waiting_tm timer */
676 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
677 if (changed) {
678 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
679
680 if (tt->state >= IWL_TI_1) {
681 /* force PI = IWL_POWER_INDEX_5 in the case of TI > 0 */
682 tt->tt_power_mode = IWL_POWER_INDEX_5;
683 if (!iwl_ht_enabled(priv))
684 /* disable HT */
685 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
686 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
687 RXON_FLG_HT40_PROT_MSK |
688 RXON_FLG_HT_PROT_MSK);
689 else {
690 /* check HT capability and set
691 * according to the system HT capability
692 * in case get disabled before */
693 iwl_set_rxon_ht(priv, &priv->current_ht_config);
694 }
695
696 } else {
697 /*
698 * restore system power setting -- it will be
699 * recalculated automatically.
700 */
701
702 /* check HT capability and set
703 * according to the system HT capability
704 * in case get disabled before */
705 iwl_set_rxon_ht(priv, &priv->current_ht_config);
706 }
707 mutex_lock(&priv->mutex);
708 if (old_state == IWL_TI_CT_KILL)
709 clear_bit(STATUS_CT_KILL, &priv->status);
710 if (tt->state != IWL_TI_CT_KILL &&
711 iwl_power_update_mode(priv, true)) {
712 /* TT state not updated
713 * try again during next temperature read
714 */
715 IWL_ERR(priv, "Cannot update power mode, "
716 "TT state not updated\n");
717 if (old_state == IWL_TI_CT_KILL)
718 set_bit(STATUS_CT_KILL, &priv->status);
719 tt->state = old_state;
720 } else {
721 IWL_DEBUG_POWER(priv,
722 "Thermal Throttling to new state: %u\n",
723 tt->state);
724 if (old_state != IWL_TI_CT_KILL &&
725 tt->state == IWL_TI_CT_KILL) {
726 if (force) {
727 IWL_DEBUG_POWER(priv,
728 "Enter IWL_TI_CT_KILL\n");
729 set_bit(STATUS_CT_KILL, &priv->status);
730 iwl_perform_ct_kill_task(priv, true);
731 } else {
732 iwl_prepare_ct_kill_task(priv);
733 tt->state = old_state;
734 }
735 } else if (old_state == IWL_TI_CT_KILL &&
736 tt->state != IWL_TI_CT_KILL) {
737 IWL_DEBUG_POWER(priv, "Exit IWL_TI_CT_KILL\n");
738 iwl_perform_ct_kill_task(priv, false);
739 }
740 }
741 mutex_unlock(&priv->mutex);
742 }
743}
744
745/* Card State Notification indicated reach critical temperature
746 * if PSP not enable, no Thermal Throttling function will be performed
747 * just set the GP1 bit to acknowledge the event
748 * otherwise, go into IWL_TI_CT_KILL state
749 * since Card State Notification will not provide any temperature reading
750 * for Legacy mode
751 * so just pass the CT_KILL temperature to iwl_legacy_tt_handler()
752 * for advance mode
753 * pass CT_KILL_THRESHOLD+1 to make sure move into IWL_TI_CT_KILL state
754 */
755static void iwl_bg_ct_enter(struct work_struct *work)
756{
757 struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_enter);
758 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
759
760 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
761 return;
762
763 if (!iwl_is_ready(priv))
764 return;
765
766 if (tt->state != IWL_TI_CT_KILL) {
767 IWL_ERR(priv, "Device reached critical temperature "
768 "- ucode going to sleep!\n");
769 if (!priv->thermal_throttle.advanced_tt)
770 iwl_legacy_tt_handler(priv,
771 IWL_MINIMAL_POWER_THRESHOLD,
772 true);
773 else
774 iwl_advance_tt_handler(priv,
775 CT_KILL_THRESHOLD + 1, true);
776 }
777}
778
779/* Card State Notification indicated out of critical temperature
780 * since Card State Notification will not provide any temperature reading
781 * so pass the IWL_REDUCED_PERFORMANCE_THRESHOLD_2 temperature
782 * to iwl_legacy_tt_handler() to get out of IWL_CT_KILL state
783 */
784static void iwl_bg_ct_exit(struct work_struct *work)
785{
786 struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_exit);
787 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
788
789 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
790 return;
791
792 if (!iwl_is_ready(priv))
793 return;
794
795 /* stop ct_kill_exit_tm timer */
796 del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm);
797
798 if (tt->state == IWL_TI_CT_KILL) {
799 IWL_ERR(priv,
800 "Device temperature below critical"
801 "- ucode awake!\n");
802 /*
803 * exit from CT_KILL state
804 * reset the current temperature reading
805 */
806 priv->temperature = 0;
807 if (!priv->thermal_throttle.advanced_tt)
808 iwl_legacy_tt_handler(priv,
809 IWL_REDUCED_PERFORMANCE_THRESHOLD_2,
810 true);
811 else
812 iwl_advance_tt_handler(priv, CT_KILL_EXIT_THRESHOLD,
813 true);
814 }
815}
816
817void iwl_tt_enter_ct_kill(struct iwl_priv *priv)
818{
819 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
820 return;
821
822 IWL_DEBUG_POWER(priv, "Queueing critical temperature enter.\n");
823 queue_work(priv->workqueue, &priv->ct_enter);
824}
825EXPORT_SYMBOL(iwl_tt_enter_ct_kill);
826
827void iwl_tt_exit_ct_kill(struct iwl_priv *priv)
828{
829 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
830 return;
831
832 IWL_DEBUG_POWER(priv, "Queueing critical temperature exit.\n");
833 queue_work(priv->workqueue, &priv->ct_exit);
834}
835EXPORT_SYMBOL(iwl_tt_exit_ct_kill);
836
837static void iwl_bg_tt_work(struct work_struct *work)
838{
839 struct iwl_priv *priv = container_of(work, struct iwl_priv, tt_work);
840 s32 temp = priv->temperature; /* degrees CELSIUS except specified */
841
842 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
843 return;
844
845 if (priv->cfg->temperature_kelvin)
846 temp = KELVIN_TO_CELSIUS(priv->temperature);
847
848 if (!priv->thermal_throttle.advanced_tt)
849 iwl_legacy_tt_handler(priv, temp, false);
850 else
851 iwl_advance_tt_handler(priv, temp, false);
852}
853
854void iwl_tt_handler(struct iwl_priv *priv)
855{
856 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
857 return;
858
859 IWL_DEBUG_POWER(priv, "Queueing thermal throttling work.\n");
860 queue_work(priv->workqueue, &priv->tt_work);
861}
862EXPORT_SYMBOL(iwl_tt_handler);
863
864/* Thermal throttling initialization
865 * For advance thermal throttling:
866 * Initialize Thermal Index and temperature threshold table
867 * Initialize thermal throttling restriction table
868 */
869void iwl_tt_initialize(struct iwl_priv *priv)
870{
871 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
872 int size = sizeof(struct iwl_tt_trans) * (IWL_TI_STATE_MAX - 1);
873 struct iwl_tt_trans *transaction;
874
875 IWL_DEBUG_POWER(priv, "Initialize Thermal Throttling\n");
876
877 memset(tt, 0, sizeof(struct iwl_tt_mgmt));
878
879 tt->state = IWL_TI_0;
880 init_timer(&priv->thermal_throttle.ct_kill_exit_tm);
881 priv->thermal_throttle.ct_kill_exit_tm.data = (unsigned long)priv;
882 priv->thermal_throttle.ct_kill_exit_tm.function =
883 iwl_tt_check_exit_ct_kill;
884 init_timer(&priv->thermal_throttle.ct_kill_waiting_tm);
885 priv->thermal_throttle.ct_kill_waiting_tm.data = (unsigned long)priv;
886 priv->thermal_throttle.ct_kill_waiting_tm.function =
887 iwl_tt_ready_for_ct_kill;
888 /* setup deferred ct kill work */
889 INIT_WORK(&priv->tt_work, iwl_bg_tt_work);
890 INIT_WORK(&priv->ct_enter, iwl_bg_ct_enter);
891 INIT_WORK(&priv->ct_exit, iwl_bg_ct_exit);
892
893 if (priv->cfg->adv_thermal_throttle) {
894 IWL_DEBUG_POWER(priv, "Advanced Thermal Throttling\n");
895 tt->restriction = kzalloc(sizeof(struct iwl_tt_restriction) *
896 IWL_TI_STATE_MAX, GFP_KERNEL);
897 tt->transaction = kzalloc(sizeof(struct iwl_tt_trans) *
898 IWL_TI_STATE_MAX * (IWL_TI_STATE_MAX - 1),
899 GFP_KERNEL);
900 if (!tt->restriction || !tt->transaction) {
901 IWL_ERR(priv, "Fallback to Legacy Throttling\n");
902 priv->thermal_throttle.advanced_tt = false;
903 kfree(tt->restriction);
904 tt->restriction = NULL;
905 kfree(tt->transaction);
906 tt->transaction = NULL;
907 } else {
908 transaction = tt->transaction +
909 (IWL_TI_0 * (IWL_TI_STATE_MAX - 1));
910 memcpy(transaction, &tt_range_0[0], size);
911 transaction = tt->transaction +
912 (IWL_TI_1 * (IWL_TI_STATE_MAX - 1));
913 memcpy(transaction, &tt_range_1[0], size);
914 transaction = tt->transaction +
915 (IWL_TI_2 * (IWL_TI_STATE_MAX - 1));
916 memcpy(transaction, &tt_range_2[0], size);
917 transaction = tt->transaction +
918 (IWL_TI_CT_KILL * (IWL_TI_STATE_MAX - 1));
919 memcpy(transaction, &tt_range_3[0], size);
920 size = sizeof(struct iwl_tt_restriction) *
921 IWL_TI_STATE_MAX;
922 memcpy(tt->restriction,
923 &restriction_range[0], size);
924 priv->thermal_throttle.advanced_tt = true;
925 }
926 } else {
927 IWL_DEBUG_POWER(priv, "Legacy Thermal Throttling\n");
928 priv->thermal_throttle.advanced_tt = false;
929 }
930}
931EXPORT_SYMBOL(iwl_tt_initialize);
932
933/* cleanup thermal throttling management related memory and timer */
934void iwl_tt_exit(struct iwl_priv *priv)
935{
936 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
937
938 /* stop ct_kill_exit_tm timer if activated */
939 del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm);
940 /* stop ct_kill_waiting_tm timer if activated */
941 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
942 cancel_work_sync(&priv->tt_work);
943 cancel_work_sync(&priv->ct_enter);
944 cancel_work_sync(&priv->ct_exit);
945
946 if (priv->thermal_throttle.advanced_tt) {
947 /* free advance thermal throttling memory */
948 kfree(tt->restriction);
949 tt->restriction = NULL;
950 kfree(tt->transaction);
951 tt->transaction = NULL;
952 }
953}
954EXPORT_SYMBOL(iwl_tt_exit);
955
956/* initialize to default */ 334/* initialize to default */
957void iwl_power_initialize(struct iwl_priv *priv) 335void iwl_power_initialize(struct iwl_priv *priv)
958{ 336{
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.h b/drivers/net/wireless/iwlwifi/iwl-power.h
index 5db91c10dcc8..df81565a7cc4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-power.h
+++ b/drivers/net/wireless/iwlwifi/iwl-power.h
@@ -30,90 +30,6 @@
30 30
31#include "iwl-commands.h" 31#include "iwl-commands.h"
32 32
33#define IWL_ABSOLUTE_ZERO 0
34#define IWL_ABSOLUTE_MAX 0xFFFFFFFF
35#define IWL_TT_INCREASE_MARGIN 5
36#define IWL_TT_CT_KILL_MARGIN 3
37
38enum iwl_antenna_ok {
39 IWL_ANT_OK_NONE,
40 IWL_ANT_OK_SINGLE,
41 IWL_ANT_OK_MULTI,
42};
43
44/* Thermal Throttling State Machine states */
45enum iwl_tt_state {
46 IWL_TI_0, /* normal temperature, system power state */
47 IWL_TI_1, /* high temperature detect, low power state */
48 IWL_TI_2, /* higher temperature detected, lower power state */
49 IWL_TI_CT_KILL, /* critical temperature detected, lowest power state */
50 IWL_TI_STATE_MAX
51};
52
53/**
54 * struct iwl_tt_restriction - Thermal Throttling restriction table
55 * @tx_stream: number of tx stream allowed
56 * @is_ht: ht enable/disable
57 * @rx_stream: number of rx stream allowed
58 *
59 * This table is used by advance thermal throttling management
60 * based on the current thermal throttling state, and determines
61 * the number of tx/rx streams and the status of HT operation.
62 */
63struct iwl_tt_restriction {
64 enum iwl_antenna_ok tx_stream;
65 enum iwl_antenna_ok rx_stream;
66 bool is_ht;
67};
68
69/**
70 * struct iwl_tt_trans - Thermal Throttling transaction table
71 * @next_state: next thermal throttling mode
72 * @tt_low: low temperature threshold to change state
73 * @tt_high: high temperature threshold to change state
74 *
75 * This is used by the advanced thermal throttling algorithm
76 * to determine the next thermal state to go based on the
77 * current temperature.
78 */
79struct iwl_tt_trans {
80 enum iwl_tt_state next_state;
81 u32 tt_low;
82 u32 tt_high;
83};
84
85/**
86 * struct iwl_tt_mgnt - Thermal Throttling Management structure
87 * @advanced_tt: advanced thermal throttle required
88 * @state: current Thermal Throttling state
89 * @tt_power_mode: Thermal Throttling power mode index
90 * being used to set power level when
91 * when thermal throttling state != IWL_TI_0
92 * the tt_power_mode should set to different
93 * power mode based on the current tt state
94 * @tt_previous_temperature: last measured temperature
95 * @iwl_tt_restriction: ptr to restriction tbl, used by advance
96 * thermal throttling to determine how many tx/rx streams
97 * should be used in tt state; and can HT be enabled or not
98 * @iwl_tt_trans: ptr to adv trans table, used by advance thermal throttling
99 * state transaction
100 * @ct_kill_toggle: used to toggle the CSR bit when checking uCode temperature
101 * @ct_kill_exit_tm: timer to exit thermal kill
102 */
103struct iwl_tt_mgmt {
104 enum iwl_tt_state state;
105 bool advanced_tt;
106 u8 tt_power_mode;
107 bool ct_kill_toggle;
108#ifdef CONFIG_IWLWIFI_DEBUG
109 s32 tt_previous_temp;
110#endif
111 struct iwl_tt_restriction *restriction;
112 struct iwl_tt_trans *transaction;
113 struct timer_list ct_kill_exit_tm;
114 struct timer_list ct_kill_waiting_tm;
115};
116
117enum iwl_power_level { 33enum iwl_power_level {
118 IWL_POWER_INDEX_1, 34 IWL_POWER_INDEX_1,
119 IWL_POWER_INDEX_2, 35 IWL_POWER_INDEX_2,
@@ -130,15 +46,6 @@ struct iwl_power_mgr {
130}; 46};
131 47
132int iwl_power_update_mode(struct iwl_priv *priv, bool force); 48int iwl_power_update_mode(struct iwl_priv *priv, bool force);
133bool iwl_ht_enabled(struct iwl_priv *priv);
134bool iwl_within_ct_kill_margin(struct iwl_priv *priv);
135enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv);
136enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv);
137void iwl_tt_enter_ct_kill(struct iwl_priv *priv);
138void iwl_tt_exit_ct_kill(struct iwl_priv *priv);
139void iwl_tt_handler(struct iwl_priv *priv);
140void iwl_tt_initialize(struct iwl_priv *priv);
141void iwl_tt_exit(struct iwl_priv *priv);
142void iwl_power_initialize(struct iwl_priv *priv); 49void iwl_power_initialize(struct iwl_priv *priv);
143 50
144extern bool no_sleep_autoadjust; 51extern bool no_sleep_autoadjust;
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index a81989c06983..c308dab14673 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -422,6 +422,7 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
422 int len; 422 int len;
423 u32 idx; 423 u32 idx;
424 u16 fix_size; 424 u16 fix_size;
425 bool is_ct_kill = false;
425 426
426 cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len); 427 cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len);
427 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); 428 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
@@ -443,9 +444,11 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
443 444
444 if (iwl_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) { 445 if (iwl_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) {
445 IWL_ERR(priv, "No space in command queue\n"); 446 IWL_ERR(priv, "No space in command queue\n");
446 if (iwl_within_ct_kill_margin(priv)) 447 if (priv->cfg->ops->lib->tt_ops.ct_kill_check) {
447 iwl_tt_enter_ct_kill(priv); 448 is_ct_kill =
448 else { 449 priv->cfg->ops->lib->tt_ops.ct_kill_check(priv);
450 }
451 if (!is_ct_kill) {
449 IWL_ERR(priv, "Restarting adapter due to queue full\n"); 452 IWL_ERR(priv, "Restarting adapter due to queue full\n");
450 queue_work(priv->workqueue, &priv->restart); 453 queue_work(priv->workqueue, &priv->restart);
451 } 454 }