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