30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
107 return restriction->
is_ht;
110 static bool iwl_within_ct_kill_margin(
struct iwl_priv *
priv)
113 bool within_margin =
false;
121 return within_margin;
126 bool is_ct_kill =
false;
128 if (iwl_within_ct_kill_margin(priv)) {
157 #define CT_KILL_EXIT_DURATION (5)
158 #define CT_KILL_WAITING_DURATION (300)
168 static void iwl_tt_check_exit_ct_kill(
unsigned long data)
191 spin_unlock_irqrestore(&priv->
trans->reg_lock, flags);
202 static void iwl_perform_ct_kill_task(
struct iwl_priv *priv,
210 "Schedule 5 seconds CT_KILL Timer\n");
220 static void iwl_tt_ready_for_ct_kill(
unsigned long data)
231 "temperature timer expired\n");
234 iwl_perform_ct_kill_task(priv,
true);
238 static void iwl_prepare_ct_kill_task(
struct iwl_priv *priv)
248 #define IWL_MINIMAL_POWER_THRESHOLD (CT_KILL_THRESHOLD_LEGACY)
249 #define IWL_REDUCED_PERFORMANCE_THRESHOLD_2 (100)
250 #define IWL_REDUCED_PERFORMANCE_THRESHOLD_1 (90)
261 static void iwl_legacy_tt_handler(
struct iwl_priv *priv,
s32 temp,
bool force)
266 #ifdef CONFIG_IWLWIFI_DEBUG
267 if ((tt->tt_previous_temp) &&
268 (temp > tt->tt_previous_temp) &&
269 ((temp - tt->tt_previous_temp) >
272 "Temperature increase %d degree Celsius\n",
273 (temp - tt->tt_previous_temp));
276 old_state = tt->
state;
287 #ifdef CONFIG_IWLWIFI_DEBUG
288 tt->tt_previous_temp =
temp;
292 if (tt->
state != old_state) {
321 tt->
state = old_state;
322 IWL_ERR(priv,
"Cannot update power mode, "
323 "TT state not updated\n");
328 iwl_perform_ct_kill_task(priv,
true);
330 iwl_prepare_ct_kill_task(priv);
331 tt->
state = old_state;
335 iwl_perform_ct_kill_task(priv,
false);
366 static void iwl_advance_tt_handler(
struct iwl_priv *priv,
s32 temp,
bool force)
374 old_state = tt->
state;
387 ((old_state * (IWL_TI_STATE_MAX - 1)) +
i);
388 if (temp >= transaction->
tt_low &&
389 temp <= transaction->
tt_high) {
390 #ifdef CONFIG_IWLWIFI_DEBUG
391 if ((tt->tt_previous_temp) &&
392 (temp > tt->tt_previous_temp) &&
393 ((temp - tt->tt_previous_temp) >
396 "Temperature increase %d "
398 (temp - tt->tt_previous_temp));
400 tt->tt_previous_temp =
temp;
459 IWL_ERR(priv,
"Cannot update power mode, "
460 "TT state not updated\n");
463 tt->
state = old_state;
466 "Thermal Throttling to new state: %u\n",
472 "Enter IWL_TI_CT_KILL\n");
474 iwl_perform_ct_kill_task(priv,
true);
476 iwl_prepare_ct_kill_task(priv);
477 tt->
state = old_state;
482 iwl_perform_ct_kill_task(priv,
false);
507 if (!iwl_is_ready(priv))
511 IWL_ERR(priv,
"Device reached critical temperature "
512 "- ucode going to sleep!\n");
514 iwl_legacy_tt_handler(priv,
518 iwl_advance_tt_handler(priv,
528 static void iwl_bg_ct_exit(
struct work_struct *work)
536 if (!iwl_is_ready(priv))
544 "Device temperature below critical"
552 iwl_legacy_tt_handler(priv,
579 static void iwl_bg_tt_work(
struct work_struct *work)
588 iwl_legacy_tt_handler(priv, temp,
false);
590 iwl_advance_tt_handler(priv, temp,
false);
621 iwl_tt_check_exit_ct_kill;
626 iwl_tt_ready_for_ct_kill;
632 if (priv->
cfg->base_params->adv_thermal_throttle) {
638 (IWL_TI_STATE_MAX - 1),
642 IWL_ERR(priv,
"Fallback to Legacy Throttling\n");
650 (
IWL_TI_0 * (IWL_TI_STATE_MAX - 1));
651 memcpy(transaction, &tt_range_0[0], size);
653 (
IWL_TI_1 * (IWL_TI_STATE_MAX - 1));
654 memcpy(transaction, &tt_range_1[0], size);
656 (
IWL_TI_2 * (IWL_TI_STATE_MAX - 1));
657 memcpy(transaction, &tt_range_2[0], size);
660 memcpy(transaction, &tt_range_3[0], size);
664 &restriction_range[0], size);