blob: 4c22c0a092376560c9e6d9d06e0f73c47531972d [file] [log] [blame]
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +03001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +03009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +030034 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64#include "mvm.h"
65#include "iwl-config.h"
66#include "iwl-io.h"
67#include "iwl-csr.h"
68#include "iwl-prph.h"
69
70#define OTP_DTS_DIODE_DEVIATION 96 /*in words*/
71/* VBG - Voltage Band Gap error data (temperature offset) */
72#define OTP_WP_DTS_VBG (OTP_DTS_DIODE_DEVIATION + 2)
73#define MEAS_VBG_MIN_VAL 2300
74#define MEAS_VBG_MAX_VAL 3000
75#define MEAS_VBG_DEFAULT_VAL 2700
76#define DTS_DIODE_VALID(flags) (flags & DTS_DIODE_REG_FLAGS_PASS_ONCE)
77#define MIN_TEMPERATURE 0
78#define MAX_TEMPERATURE 125
79#define TEMPERATURE_ERROR (MAX_TEMPERATURE + 1)
80#define PTAT_DIGITAL_VALUE_MIN_VALUE 0
81#define PTAT_DIGITAL_VALUE_MAX_VALUE 0xFF
82#define DTS_VREFS_NUM 5
83static inline u32 DTS_DIODE_GET_VREFS_ID(u32 flags)
84{
85 return (flags & DTS_DIODE_REG_FLAGS_VREFS_ID) >>
86 DTS_DIODE_REG_FLAGS_VREFS_ID_POS;
87}
88
89#define CALC_VREFS_MIN_DIFF 43
90#define CALC_VREFS_MAX_DIFF 51
91#define CALC_LUT_SIZE (1 + CALC_VREFS_MAX_DIFF - CALC_VREFS_MIN_DIFF)
92#define CALC_LUT_INDEX_OFFSET CALC_VREFS_MIN_DIFF
93#define CALC_TEMPERATURE_RESULT_SHIFT_OFFSET 23
94
95/*
96 * @digital_value: The diode's digital-value sampled (temperature/voltage)
97 * @vref_low: The lower voltage-reference (the vref just below the diode's
98 * sampled digital-value)
99 * @vref_high: The higher voltage-reference (the vref just above the diode's
100 * sampled digital-value)
101 * @flags: bits[1:0]: The ID of the Vrefs pair (lowVref,highVref)
102 * bits[6:2]: Reserved.
103 * bits[7:7]: Indicates completion of at least 1 successful sample
104 * since last DTS reset.
105 */
106struct iwl_mvm_dts_diode_bits {
107 u8 digital_value;
108 u8 vref_low;
109 u8 vref_high;
110 u8 flags;
111} __packed;
112
113union dts_diode_results {
114 u32 reg_value;
115 struct iwl_mvm_dts_diode_bits bits;
116} __packed;
117
118static s16 iwl_mvm_dts_get_volt_band_gap(struct iwl_mvm *mvm)
119{
120 struct iwl_nvm_section calib_sec;
121 const __le16 *calib;
122 u16 vbg;
123
124 /* TODO: move parsing to NVM code */
125 calib_sec = mvm->nvm_sections[NVM_SECTION_TYPE_CALIBRATION];
126 calib = (__le16 *)calib_sec.data;
127
128 vbg = le16_to_cpu(calib[OTP_WP_DTS_VBG]);
129
130 if (vbg < MEAS_VBG_MIN_VAL || vbg > MEAS_VBG_MAX_VAL)
131 vbg = MEAS_VBG_DEFAULT_VAL;
132
133 return vbg;
134}
135
136static u16 iwl_mvm_dts_get_ptat_deviation_offset(struct iwl_mvm *mvm)
137{
138 const u8 *calib;
139 u8 ptat, pa1, pa2, median;
140
141 /* TODO: move parsing to NVM code */
142 calib = mvm->nvm_sections[NVM_SECTION_TYPE_CALIBRATION].data;
Eytan Lifshitz51ea1c72014-07-02 20:52:02 +0300143 ptat = calib[OTP_DTS_DIODE_DEVIATION * 2];
144 pa1 = calib[OTP_DTS_DIODE_DEVIATION * 2 + 1];
145 pa2 = calib[OTP_DTS_DIODE_DEVIATION * 2 + 2];
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300146
147 /* get the median: */
148 if (ptat > pa1) {
149 if (ptat > pa2)
150 median = (pa1 > pa2) ? pa1 : pa2;
151 else
152 median = ptat;
153 } else {
154 if (pa1 > pa2)
155 median = (ptat > pa2) ? ptat : pa2;
156 else
157 median = pa1;
158 }
159
160 return ptat - median;
161}
162
163static u8 iwl_mvm_dts_calibrate_ptat_deviation(struct iwl_mvm *mvm, u8 value)
164{
165 /* Calibrate the PTAT digital value, based on PTAT deviation data: */
166 s16 new_val = value - iwl_mvm_dts_get_ptat_deviation_offset(mvm);
167
168 if (new_val > PTAT_DIGITAL_VALUE_MAX_VALUE)
169 new_val = PTAT_DIGITAL_VALUE_MAX_VALUE;
170 else if (new_val < PTAT_DIGITAL_VALUE_MIN_VALUE)
171 new_val = PTAT_DIGITAL_VALUE_MIN_VALUE;
172
173 return new_val;
174}
175
176static bool dts_get_adjacent_vrefs(struct iwl_mvm *mvm,
177 union dts_diode_results *avg_ptat)
178{
179 u8 vrefs_results[DTS_VREFS_NUM];
180 u8 low_vref_index = 0, flags;
181 u32 reg;
182
183 reg = iwl_read_prph(mvm->trans, DTSC_VREF_AVG);
184 memcpy(vrefs_results, &reg, sizeof(reg));
185 reg = iwl_read_prph(mvm->trans, DTSC_VREF5_AVG);
186 vrefs_results[4] = reg & 0xff;
187
188 if (avg_ptat->bits.digital_value < vrefs_results[0] ||
189 avg_ptat->bits.digital_value > vrefs_results[4])
190 return false;
191
192 if (avg_ptat->bits.digital_value > vrefs_results[3])
193 low_vref_index = 3;
194 else if (avg_ptat->bits.digital_value > vrefs_results[2])
195 low_vref_index = 2;
196 else if (avg_ptat->bits.digital_value > vrefs_results[1])
197 low_vref_index = 1;
198
199 avg_ptat->bits.vref_low = vrefs_results[low_vref_index];
200 avg_ptat->bits.vref_high = vrefs_results[low_vref_index + 1];
201 flags = avg_ptat->bits.flags;
202 avg_ptat->bits.flags =
203 (flags & ~DTS_DIODE_REG_FLAGS_VREFS_ID) |
204 (low_vref_index & DTS_DIODE_REG_FLAGS_VREFS_ID);
205 return true;
206}
207
208/*
209 * return true it the results are valid, and false otherwise.
210 */
211static bool dts_read_ptat_avg_results(struct iwl_mvm *mvm,
212 union dts_diode_results *avg_ptat)
213{
214 u32 reg;
215 u8 tmp;
216
217 /* fill the diode value and pass_once with avg-reg results */
218 reg = iwl_read_prph(mvm->trans, DTSC_PTAT_AVG);
219 reg &= DTS_DIODE_REG_DIG_VAL | DTS_DIODE_REG_PASS_ONCE;
220 avg_ptat->reg_value = reg;
221
222 /* calibrate the PTAT digital value */
223 tmp = avg_ptat->bits.digital_value;
224 tmp = iwl_mvm_dts_calibrate_ptat_deviation(mvm, tmp);
225 avg_ptat->bits.digital_value = tmp;
226
227 /*
228 * fill vrefs fields, based on the avgVrefs results
229 * and the diode value
230 */
231 return dts_get_adjacent_vrefs(mvm, avg_ptat) &&
232 DTS_DIODE_VALID(avg_ptat->bits.flags);
233}
234
235static s32 calculate_nic_temperature(union dts_diode_results avg_ptat,
236 u16 volt_band_gap)
237{
238 u32 tmp_result;
239 u8 vrefs_diff;
240 /*
241 * For temperature calculation (at the end, shift right by 23)
242 * LUT[(D2-D1)] = ROUND{ 2^23 / ((D2-D1)*9*10) }
243 * (D2-D1) == 43 44 45 46 47 48 49 50 51
244 */
245 static const u16 calc_lut[CALC_LUT_SIZE] = {
246 2168, 2118, 2071, 2026, 1983, 1942, 1902, 1864, 1828,
247 };
248
249 /*
250 * The diff between the high and low voltage-references is assumed
251 * to be strictly be in range of [60,68]
252 */
253 vrefs_diff = avg_ptat.bits.vref_high - avg_ptat.bits.vref_low;
254
255 if (vrefs_diff < CALC_VREFS_MIN_DIFF ||
256 vrefs_diff > CALC_VREFS_MAX_DIFF)
257 return TEMPERATURE_ERROR;
258
259 /* calculate the result: */
260 tmp_result =
261 vrefs_diff * (DTS_DIODE_GET_VREFS_ID(avg_ptat.bits.flags) + 9);
262 tmp_result += avg_ptat.bits.digital_value;
263 tmp_result -= avg_ptat.bits.vref_high;
264
265 /* multiply by the LUT value (based on the diff) */
266 tmp_result *= calc_lut[vrefs_diff - CALC_LUT_INDEX_OFFSET];
267
268 /*
269 * Get the BandGap (the voltage refereces source) error data
270 * (temperature offset)
271 */
272 tmp_result *= volt_band_gap;
273
274 /*
275 * here, tmp_result value can be up to 32-bits. We want to right-shift
276 * it *without* sign-extend.
277 */
278 tmp_result = tmp_result >> CALC_TEMPERATURE_RESULT_SHIFT_OFFSET;
279
280 /*
281 * at this point, tmp_result should be in the range:
282 * 200 <= tmp_result <= 365
283 */
284 return (s16)tmp_result - 240;
285}
286
287static s32 check_nic_temperature(struct iwl_mvm *mvm)
288{
289 u16 volt_band_gap;
290 union dts_diode_results avg_ptat;
291
292 volt_band_gap = iwl_mvm_dts_get_volt_band_gap(mvm);
293
294 /* disable DTS */
295 iwl_write_prph(mvm->trans, SHR_MISC_WFM_DTS_EN, 0);
296
297 /* SV initialization */
298 iwl_write_prph(mvm->trans, SHR_MISC_WFM_DTS_EN, 1);
299 iwl_write_prph(mvm->trans, DTSC_CFG_MODE,
300 DTSC_CFG_MODE_PERIODIC);
301
302 /* wait for results */
303 msleep(100);
304 if (!dts_read_ptat_avg_results(mvm, &avg_ptat))
305 return TEMPERATURE_ERROR;
306
307 /* disable DTS */
308 iwl_write_prph(mvm->trans, SHR_MISC_WFM_DTS_EN, 0);
309
310 return calculate_nic_temperature(avg_ptat, volt_band_gap);
311}
312
313static void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm)
314{
315 u32 duration = mvm->thermal_throttle.params->ct_kill_duration;
316
Luciano Coelhob689fa72014-08-20 17:26:58 +0300317 if (test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status))
318 return;
319
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300320 IWL_ERR(mvm, "Enter CT Kill\n");
321 iwl_mvm_set_hw_ctkill_state(mvm, true);
Luciano Coelhoefc36db2014-08-20 17:58:20 +0300322
323 /* Don't schedule an exit work if we're in test mode, since
324 * the temperature will not change unless we manually set it
325 * again (or disable testing).
326 */
327 if (!mvm->temperature_test)
328 schedule_delayed_work(&mvm->thermal_throttle.ct_kill_exit,
329 round_jiffies_relative(duration * HZ));
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300330}
331
332static void iwl_mvm_exit_ctkill(struct iwl_mvm *mvm)
333{
Luciano Coelhob689fa72014-08-20 17:26:58 +0300334 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status))
335 return;
336
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300337 IWL_ERR(mvm, "Exit CT Kill\n");
338 iwl_mvm_set_hw_ctkill_state(mvm, false);
339}
340
341static void check_exit_ctkill(struct work_struct *work)
342{
343 struct iwl_mvm_tt_mgmt *tt;
344 struct iwl_mvm *mvm;
345 u32 duration;
346 s32 temp;
347
348 tt = container_of(work, struct iwl_mvm_tt_mgmt, ct_kill_exit.work);
349 mvm = container_of(tt, struct iwl_mvm, thermal_throttle);
350
351 duration = tt->params->ct_kill_duration;
352
Eliad Peller576eeee2014-07-01 18:38:38 +0300353 /* make sure the device is available for direct read/writes */
354 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_CHECK_CTKILL))
355 goto reschedule;
356
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300357 iwl_trans_start_hw(mvm->trans);
358 temp = check_nic_temperature(mvm);
Arik Nemtsova4082842013-11-24 19:10:46 +0200359 iwl_trans_stop_device(mvm->trans);
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300360
Eliad Peller576eeee2014-07-01 18:38:38 +0300361 iwl_mvm_unref(mvm, IWL_MVM_REF_CHECK_CTKILL);
362
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300363 if (temp < MIN_TEMPERATURE || temp > MAX_TEMPERATURE) {
364 IWL_DEBUG_TEMP(mvm, "Failed to measure NIC temperature\n");
365 goto reschedule;
366 }
367 IWL_DEBUG_TEMP(mvm, "NIC temperature: %d\n", temp);
368
369 if (temp <= tt->params->ct_kill_exit) {
370 iwl_mvm_exit_ctkill(mvm);
371 return;
372 }
373
374reschedule:
375 schedule_delayed_work(&mvm->thermal_throttle.ct_kill_exit,
376 round_jiffies(duration * HZ));
377}
378
379static void iwl_mvm_tt_smps_iterator(void *_data, u8 *mac,
380 struct ieee80211_vif *vif)
381{
382 struct iwl_mvm *mvm = _data;
383 enum ieee80211_smps_mode smps_mode;
384
385 lockdep_assert_held(&mvm->mutex);
386
387 if (mvm->thermal_throttle.dynamic_smps)
388 smps_mode = IEEE80211_SMPS_DYNAMIC;
389 else
390 smps_mode = IEEE80211_SMPS_AUTOMATIC;
391
Eytan Lifshitzfded3132013-06-04 12:28:51 +0300392 if (vif->type != NL80211_IFTYPE_STATION)
393 return;
394
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300395 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, smps_mode);
396}
397
398static void iwl_mvm_tt_tx_protection(struct iwl_mvm *mvm, bool enable)
399{
400 struct ieee80211_sta *sta;
401 struct iwl_mvm_sta *mvmsta;
402 int i, err;
403
404 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
405 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
406 lockdep_is_held(&mvm->mutex));
407 if (IS_ERR_OR_NULL(sta))
408 continue;
Johannes Berg5b577a92013-11-14 18:20:04 +0100409 mvmsta = iwl_mvm_sta_from_mac80211(sta);
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300410 if (enable == mvmsta->tt_tx_protection)
411 continue;
Johannes Berge126b5d2013-06-28 13:39:18 +0200412 err = iwl_mvm_tx_protection(mvm, mvmsta, enable);
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300413 if (err) {
414 IWL_ERR(mvm, "Failed to %s Tx protection\n",
415 enable ? "enable" : "disable");
416 } else {
417 IWL_DEBUG_TEMP(mvm, "%s Tx protection\n",
418 enable ? "Enable" : "Disable");
419 mvmsta->tt_tx_protection = enable;
420 }
421 }
422}
423
Ido Yariv0c0e2c72014-01-16 21:12:02 -0500424void iwl_mvm_tt_tx_backoff(struct iwl_mvm *mvm, u32 backoff)
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300425{
426 struct iwl_host_cmd cmd = {
427 .id = REPLY_THERMAL_MNG_BACKOFF,
428 .len = { sizeof(u32), },
429 .data = { &backoff, },
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300430 };
431
Ido Yariv0c0e2c72014-01-16 21:12:02 -0500432 backoff = max(backoff, mvm->thermal_throttle.min_backoff);
433
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300434 if (iwl_mvm_send_cmd(mvm, &cmd) == 0) {
435 IWL_DEBUG_TEMP(mvm, "Set Thermal Tx backoff to: %u\n",
436 backoff);
437 mvm->thermal_throttle.tx_backoff = backoff;
438 } else {
439 IWL_ERR(mvm, "Failed to change Thermal Tx backoff\n");
440 }
441}
442
443void iwl_mvm_tt_handler(struct iwl_mvm *mvm)
444{
445 const struct iwl_tt_params *params = mvm->thermal_throttle.params;
446 struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle;
447 s32 temperature = mvm->temperature;
eytan lifshitzdafe6c42013-06-18 14:28:56 +0300448 bool throttle_enable = false;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300449 int i;
450 u32 tx_backoff;
451
452 IWL_DEBUG_TEMP(mvm, "NIC temperature: %d\n", mvm->temperature);
453
454 if (params->support_ct_kill && temperature >= params->ct_kill_entry) {
455 iwl_mvm_enter_ctkill(mvm);
456 return;
457 }
458
Luciano Coelhob689fa72014-08-20 17:26:58 +0300459 if (params->support_ct_kill &&
460 temperature <= tt->params->ct_kill_exit) {
461 iwl_mvm_exit_ctkill(mvm);
462 return;
463 }
464
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300465 if (params->support_dynamic_smps) {
466 if (!tt->dynamic_smps &&
467 temperature >= params->dynamic_smps_entry) {
468 IWL_DEBUG_TEMP(mvm, "Enable dynamic SMPS\n");
469 tt->dynamic_smps = true;
470 ieee80211_iterate_active_interfaces_atomic(
471 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
472 iwl_mvm_tt_smps_iterator, mvm);
eytan lifshitzdafe6c42013-06-18 14:28:56 +0300473 throttle_enable = true;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300474 } else if (tt->dynamic_smps &&
475 temperature <= params->dynamic_smps_exit) {
476 IWL_DEBUG_TEMP(mvm, "Disable dynamic SMPS\n");
477 tt->dynamic_smps = false;
478 ieee80211_iterate_active_interfaces_atomic(
479 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
480 iwl_mvm_tt_smps_iterator, mvm);
481 }
482 }
483
484 if (params->support_tx_protection) {
eytan lifshitzdafe6c42013-06-18 14:28:56 +0300485 if (temperature >= params->tx_protection_entry) {
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300486 iwl_mvm_tt_tx_protection(mvm, true);
eytan lifshitzdafe6c42013-06-18 14:28:56 +0300487 throttle_enable = true;
488 } else if (temperature <= params->tx_protection_exit) {
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300489 iwl_mvm_tt_tx_protection(mvm, false);
eytan lifshitzdafe6c42013-06-18 14:28:56 +0300490 }
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300491 }
492
493 if (params->support_tx_backoff) {
Eytan Lifshitz1b8ebbd2014-04-01 16:44:21 +0300494 tx_backoff = tt->min_backoff;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300495 for (i = 0; i < TT_TX_BACKOFF_SIZE; i++) {
496 if (temperature < params->tx_backoff[i].temperature)
497 break;
Eytan Lifshitz1b8ebbd2014-04-01 16:44:21 +0300498 tx_backoff = max(tt->min_backoff,
499 params->tx_backoff[i].backoff);
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300500 }
Eytan Lifshitz1b8ebbd2014-04-01 16:44:21 +0300501 if (tx_backoff != tt->min_backoff)
eytan lifshitzdafe6c42013-06-18 14:28:56 +0300502 throttle_enable = true;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300503 if (tt->tx_backoff != tx_backoff)
504 iwl_mvm_tt_tx_backoff(mvm, tx_backoff);
505 }
eytan lifshitzdafe6c42013-06-18 14:28:56 +0300506
507 if (!tt->throttle && throttle_enable) {
508 IWL_WARN(mvm,
509 "Due to high temperature thermal throttling initiated\n");
510 tt->throttle = true;
Eytan Lifshitz19a04bd2014-04-02 21:37:57 +0300511 } else if (tt->throttle && !tt->dynamic_smps &&
512 tt->tx_backoff == tt->min_backoff &&
eytan lifshitzdafe6c42013-06-18 14:28:56 +0300513 temperature <= params->tx_protection_exit) {
514 IWL_WARN(mvm,
515 "Temperature is back to normal thermal throttling stopped\n");
516 tt->throttle = false;
517 }
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300518}
519
520static const struct iwl_tt_params iwl7000_tt_params = {
521 .ct_kill_entry = 118,
522 .ct_kill_exit = 96,
523 .ct_kill_duration = 5,
524 .dynamic_smps_entry = 114,
525 .dynamic_smps_exit = 110,
526 .tx_protection_entry = 114,
527 .tx_protection_exit = 108,
528 .tx_backoff = {
529 {.temperature = 112, .backoff = 200},
530 {.temperature = 113, .backoff = 600},
531 {.temperature = 114, .backoff = 1200},
532 {.temperature = 115, .backoff = 2000},
533 {.temperature = 116, .backoff = 4000},
534 {.temperature = 117, .backoff = 10000},
535 },
536 .support_ct_kill = true,
537 .support_dynamic_smps = true,
538 .support_tx_protection = true,
539 .support_tx_backoff = true,
540};
541
Eytan Lifshitz6be497f2013-07-24 14:49:18 +0300542static const struct iwl_tt_params iwl7000_high_temp_tt_params = {
543 .ct_kill_entry = 118,
544 .ct_kill_exit = 96,
545 .ct_kill_duration = 5,
546 .dynamic_smps_entry = 114,
547 .dynamic_smps_exit = 110,
548 .tx_protection_entry = 114,
549 .tx_protection_exit = 108,
550 .tx_backoff = {
551 {.temperature = 112, .backoff = 300},
552 {.temperature = 113, .backoff = 800},
553 {.temperature = 114, .backoff = 1500},
554 {.temperature = 115, .backoff = 3000},
555 {.temperature = 116, .backoff = 5000},
556 {.temperature = 117, .backoff = 10000},
557 },
558 .support_ct_kill = true,
559 .support_dynamic_smps = true,
560 .support_tx_protection = true,
561 .support_tx_backoff = true,
562};
563
Ido Yariv0c0e2c72014-01-16 21:12:02 -0500564void iwl_mvm_tt_initialize(struct iwl_mvm *mvm, u32 min_backoff)
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300565{
566 struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle;
567
568 IWL_DEBUG_TEMP(mvm, "Initialize Thermal Throttling\n");
Eytan Lifshitz6be497f2013-07-24 14:49:18 +0300569
570 if (mvm->cfg->high_temp)
571 tt->params = &iwl7000_high_temp_tt_params;
572 else
573 tt->params = &iwl7000_tt_params;
574
eytan lifshitzdafe6c42013-06-18 14:28:56 +0300575 tt->throttle = false;
Ido Yariv0c0e2c72014-01-16 21:12:02 -0500576 tt->min_backoff = min_backoff;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300577 INIT_DELAYED_WORK(&tt->ct_kill_exit, check_exit_ctkill);
578}
579
580void iwl_mvm_tt_exit(struct iwl_mvm *mvm)
581{
582 cancel_delayed_work_sync(&mvm->thermal_throttle.ct_kill_exit);
583 IWL_DEBUG_TEMP(mvm, "Exit Thermal Throttling\n");
584}