// SPDX-License-Identifier: GPL-2.0-only /****************************************************************************** * * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved. * Copyright (C) 2018, 2020 Intel Corporation * * Portions of this file are derived from the ipw3945 project, as well * as portions of the ieee80211 subsystem header files.
*****************************************************************************/
/* * toggle the bit to wake up uCode and check the temperature * if the temperature is below CT, uCode will stay awake and send card * state notification with CT_KILL bit clear to inform Thermal Throttling * Management to change state. Otherwise, uCode will go back to sleep * without doing anything, driver should continue the 5 seconds timer * to wake up uCode for temperature check until temperature drop below CT
*/ staticvoid iwl_tt_check_exit_ct_kill(struct timer_list *t)
{ struct iwl_priv *priv = timer_container_of(priv, t,
thermal_throttle.ct_kill_exit_tm); struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return;
if (tt->state == IWL_TI_CT_KILL) { if (priv->thermal_throttle.ct_kill_toggle) {
iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
priv->thermal_throttle.ct_kill_toggle = false;
} else {
iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET,
CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
priv->thermal_throttle.ct_kill_toggle = true;
}
iwl_read32(priv->trans, CSR_UCODE_DRV_GP1); if (iwl_trans_grab_nic_access(priv->trans))
iwl_trans_release_nic_access(priv->trans);
/* Reschedule the ct_kill timer to occur in * CT_KILL_EXIT_DURATION seconds to ensure we get a
* thermal update */
IWL_DEBUG_TEMP(priv, "schedule ct_kill exit timer\n");
mod_timer(&priv->thermal_throttle.ct_kill_exit_tm,
jiffies + CT_KILL_EXIT_DURATION * HZ);
}
}
staticvoid iwl_perform_ct_kill_task(struct iwl_priv *priv, bool stop)
{ if (stop) {
IWL_DEBUG_TEMP(priv, "Stop all queues\n"); if (priv->mac80211_registered)
ieee80211_stop_queues(priv->hw);
IWL_DEBUG_TEMP(priv, "Schedule 5 seconds CT_KILL Timer\n");
mod_timer(&priv->thermal_throttle.ct_kill_exit_tm,
jiffies + CT_KILL_EXIT_DURATION * HZ);
} else {
IWL_DEBUG_TEMP(priv, "Wake all queues\n"); if (priv->mac80211_registered)
ieee80211_wake_queues(priv->hw);
}
}
if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return;
/* temperature timer expired, ready to go into CT_KILL state */ if (tt->state != IWL_TI_CT_KILL) {
IWL_DEBUG_TEMP(priv, "entering CT_KILL state when " "temperature timer expired\n");
tt->state = IWL_TI_CT_KILL;
set_bit(STATUS_CT_KILL, &priv->status);
iwl_perform_ct_kill_task(priv, true);
}
}
staticvoid iwl_prepare_ct_kill_task(struct iwl_priv *priv)
{
IWL_DEBUG_TEMP(priv, "Prepare to enter IWL_TI_CT_KILL\n"); /* make request to retrieve statistics information */
iwl_send_statistics_request(priv, 0, false); /* Reschedule the ct_kill wait timer */
mod_timer(&priv->thermal_throttle.ct_kill_waiting_tm,
jiffies + msecs_to_jiffies(CT_KILL_WAITING_DURATION));
}
/* * Legacy thermal throttling * 1) Avoid NIC destruction due to high temperatures * Chip will identify dangerously high temperatures that can * harm the device and will power down * 2) Avoid the NIC power down due to high temperature * Throttle early enough to lower the power consumption before * drastic steps are needed
*/ staticvoid iwl_legacy_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
{ struct iwl_tt_mgmt *tt = &priv->thermal_throttle; enum iwl_tt_state old_state;
#ifdef CONFIG_IWLWIFI_DEBUG
tt->tt_previous_temp = temp; #endif /* stop ct_kill_waiting_tm timer */
timer_delete_sync(&priv->thermal_throttle.ct_kill_waiting_tm); if (tt->state != old_state) { switch (tt->state) { case IWL_TI_0: /* * When the system is ready to go back to IWL_TI_0 * we only have to call iwl_power_update_mode() to * do so.
*/ break; case IWL_TI_1:
tt->tt_power_mode = IWL_POWER_INDEX_3; break; case IWL_TI_2:
tt->tt_power_mode = IWL_POWER_INDEX_4; break; default:
tt->tt_power_mode = IWL_POWER_INDEX_5; break;
}
mutex_lock(&priv->mutex); if (old_state == IWL_TI_CT_KILL)
clear_bit(STATUS_CT_KILL, &priv->status); if (tt->state != IWL_TI_CT_KILL &&
iwl_power_update_mode(priv, true)) { /* TT state not updated * try again during next temperature read
*/ if (old_state == IWL_TI_CT_KILL)
set_bit(STATUS_CT_KILL, &priv->status);
tt->state = old_state;
IWL_ERR(priv, "Cannot update power mode, " "TT state not updated\n");
} else { if (tt->state == IWL_TI_CT_KILL) { if (force) {
set_bit(STATUS_CT_KILL, &priv->status);
iwl_perform_ct_kill_task(priv, true);
} else {
iwl_prepare_ct_kill_task(priv);
tt->state = old_state;
}
} elseif (old_state == IWL_TI_CT_KILL) {
iwl_perform_ct_kill_task(priv, false);
}
IWL_DEBUG_TEMP(priv, "Temperature state changed %u\n",
tt->state);
IWL_DEBUG_TEMP(priv, "Power Index change to %u\n",
tt->tt_power_mode);
}
mutex_unlock(&priv->mutex);
}
}
/* * Advance thermal throttling * 1) Avoid NIC destruction due to high temperatures * Chip will identify dangerously high temperatures that can * harm the device and will power down * 2) Avoid the NIC power down due to high temperature * Throttle early enough to lower the power consumption before * drastic steps are needed * Actions include relaxing the power down sleep thresholds and * decreasing the number of TX streams * 3) Avoid throughput performance impact as much as possible * *============================================================================= * Condition Nxt State Condition Nxt State Condition Nxt State *----------------------------------------------------------------------------- * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0 * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1 * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0 *=============================================================================
*/ staticvoid iwl_advance_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
{ struct iwl_tt_mgmt *tt = &priv->thermal_throttle; int i; bool changed = false; enum iwl_tt_state old_state; struct iwl_tt_trans *transaction;
old_state = tt->state; for (i = 0; i < IWL_TI_STATE_MAX - 1; i++) { /* based on the current TT state, * find the curresponding transaction table * each table has (IWL_TI_STATE_MAX - 1) entries * tt->transaction + ((old_state * (IWL_TI_STATE_MAX - 1)) * will advance to the correct table. * then based on the current temperature * find the next state need to transaction to * go through all the possible (IWL_TI_STATE_MAX - 1) entries * in the current table to see if transaction is needed
*/
transaction = tt->transaction +
((old_state * (IWL_TI_STATE_MAX - 1)) + i); if (temp >= transaction->tt_low &&
temp <= transaction->tt_high) { #ifdef CONFIG_IWLWIFI_DEBUG if ((tt->tt_previous_temp) &&
(temp > tt->tt_previous_temp) &&
((temp - tt->tt_previous_temp) >
IWL_TT_INCREASE_MARGIN)) {
IWL_DEBUG_TEMP(priv, "Temperature increase %d " "degree Celsius\n",
(temp - tt->tt_previous_temp));
}
tt->tt_previous_temp = temp; #endif if (old_state !=
transaction->next_state) {
changed = true;
tt->state =
transaction->next_state;
} break;
}
} /* stop ct_kill_waiting_tm timer */
timer_delete_sync(&priv->thermal_throttle.ct_kill_waiting_tm); if (changed) { if (tt->state >= IWL_TI_1) { /* force PI = IWL_POWER_INDEX_5 in the case of TI > 0 */
tt->tt_power_mode = IWL_POWER_INDEX_5;
if (!iwl_ht_enabled(priv)) { struct iwl_rxon_context *ctx;
/* disable HT */
rxon->flags &= ~(
RXON_FLG_CHANNEL_MODE_MSK |
RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
RXON_FLG_HT40_PROT_MSK |
RXON_FLG_HT_PROT_MSK);
}
} else { /* check HT capability and set * according to the system HT capability
* in case get disabled before */
iwl_set_rxon_ht(priv, &priv->current_ht_config);
}
} else { /* * restore system power setting -- it will be * recalculated automatically.
*/
/* check HT capability and set * according to the system HT capability
* in case get disabled before */
iwl_set_rxon_ht(priv, &priv->current_ht_config);
}
mutex_lock(&priv->mutex); if (old_state == IWL_TI_CT_KILL)
clear_bit(STATUS_CT_KILL, &priv->status); if (tt->state != IWL_TI_CT_KILL &&
iwl_power_update_mode(priv, true)) { /* TT state not updated * try again during next temperature read
*/
IWL_ERR(priv, "Cannot update power mode, " "TT state not updated\n"); if (old_state == IWL_TI_CT_KILL)
set_bit(STATUS_CT_KILL, &priv->status);
tt->state = old_state;
} else {
IWL_DEBUG_TEMP(priv, "Thermal Throttling to new state: %u\n",
tt->state); if (old_state != IWL_TI_CT_KILL &&
tt->state == IWL_TI_CT_KILL) { if (force) {
IWL_DEBUG_TEMP(priv, "Enter IWL_TI_CT_KILL\n");
set_bit(STATUS_CT_KILL, &priv->status);
iwl_perform_ct_kill_task(priv, true);
} else {
tt->state = old_state;
iwl_prepare_ct_kill_task(priv);
}
} elseif (old_state == IWL_TI_CT_KILL &&
tt->state != IWL_TI_CT_KILL) {
IWL_DEBUG_TEMP(priv, "Exit IWL_TI_CT_KILL\n");
iwl_perform_ct_kill_task(priv, false);
}
}
mutex_unlock(&priv->mutex);
}
}
/* Card State Notification indicated reach critical temperature * if PSP not enable, no Thermal Throttling function will be performed * just set the GP1 bit to acknowledge the event * otherwise, go into IWL_TI_CT_KILL state * since Card State Notification will not provide any temperature reading * for Legacy mode * so just pass the CT_KILL temperature to iwl_legacy_tt_handler() * for advance mode * pass CT_KILL_THRESHOLD+1 to make sure move into IWL_TI_CT_KILL state
*/ staticvoid iwl_bg_ct_enter(struct work_struct *work)
{ struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_enter); struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return;
if (!iwl_is_ready(priv)) return;
if (tt->state != IWL_TI_CT_KILL) {
IWL_ERR(priv, "Device reached critical temperature " "- ucode going to sleep!\n"); if (!priv->thermal_throttle.advanced_tt)
iwl_legacy_tt_handler(priv,
IWL_MINIMAL_POWER_THRESHOLD, true); else
iwl_advance_tt_handler(priv,
CT_KILL_THRESHOLD + 1, true);
}
}
/* Card State Notification indicated out of critical temperature * since Card State Notification will not provide any temperature reading * so pass the IWL_REDUCED_PERFORMANCE_THRESHOLD_2 temperature * to iwl_legacy_tt_handler() to get out of IWL_CT_KILL state
*/ staticvoid iwl_bg_ct_exit(struct work_struct *work)
{ struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_exit); struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return;
if (tt->state == IWL_TI_CT_KILL) {
IWL_ERR(priv, "Device temperature below critical" "- ucode awake!\n"); /* * exit from CT_KILL state * reset the current temperature reading
*/
priv->temperature = 0; if (!priv->thermal_throttle.advanced_tt)
iwl_legacy_tt_handler(priv,
IWL_REDUCED_PERFORMANCE_THRESHOLD_2, true); else
iwl_advance_tt_handler(priv, CT_KILL_EXIT_THRESHOLD, true);
}
}
void iwl_tt_enter_ct_kill(struct iwl_priv *priv)
{ if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return;
IWL_DEBUG_TEMP(priv, "Queueing critical temperature enter.\n");
queue_work(priv->workqueue, &priv->ct_enter);
}
void iwl_tt_exit_ct_kill(struct iwl_priv *priv)
{ if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return;
IWL_DEBUG_TEMP(priv, "Queueing critical temperature exit.\n");
queue_work(priv->workqueue, &priv->ct_exit);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.