2020-12-10 00:06:03 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
|
|
|
|
/*
|
2023-03-28 10:59:01 +03:00
|
|
|
* Copyright (C) 2012-2014, 2019-2022 Intel Corporation
|
2020-12-10 00:06:03 +02:00
|
|
|
* Copyright (C) 2013-2014 Intel Mobile Communications GmbH
|
|
|
|
* Copyright (C) 2015-2016 Intel Deutschland GmbH
|
|
|
|
*/
|
2015-12-29 09:54:49 +02:00
|
|
|
#include <linux/sort.h>
|
|
|
|
|
2013-05-19 19:14:41 +03:00
|
|
|
#include "mvm.h"
|
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
#define IWL_MVM_TEMP_NOTIF_WAIT_TIMEOUT HZ
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2017-06-27 14:13:02 +03:00
|
|
|
void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm)
|
2013-05-19 19:14:41 +03:00
|
|
|
{
|
2014-12-15 14:15:15 +02:00
|
|
|
struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle;
|
2015-04-19 12:26:39 +03:00
|
|
|
u32 duration = tt->params.ct_kill_duration;
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
if (test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status))
|
|
|
|
return;
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
IWL_ERR(mvm, "Enter CT Kill\n");
|
|
|
|
iwl_mvm_set_hw_ctkill_state(mvm, true);
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2015-12-29 09:54:49 +02:00
|
|
|
if (!iwl_mvm_is_tt_in_fw(mvm)) {
|
|
|
|
tt->throttle = false;
|
|
|
|
tt->dynamic_smps = false;
|
|
|
|
}
|
2014-12-15 14:15:15 +02:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
/* Don't schedule an exit work if we're in test mode, since
|
|
|
|
* the temperature will not change unless we manually set it
|
|
|
|
* again (or disable testing).
|
|
|
|
*/
|
|
|
|
if (!mvm->temperature_test)
|
2014-12-15 14:15:15 +02:00
|
|
|
schedule_delayed_work(&tt->ct_kill_exit,
|
2014-09-04 12:29:15 +03:00
|
|
|
round_jiffies_relative(duration * HZ));
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
static void iwl_mvm_exit_ctkill(struct iwl_mvm *mvm)
|
2013-05-19 19:14:41 +03:00
|
|
|
{
|
2014-09-04 12:29:15 +03:00
|
|
|
if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status))
|
|
|
|
return;
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
IWL_ERR(mvm, "Exit CT Kill\n");
|
|
|
|
iwl_mvm_set_hw_ctkill_state(mvm, false);
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
|
|
|
|
2021-02-05 11:06:41 +02:00
|
|
|
static void iwl_mvm_tt_temp_changed(struct iwl_mvm *mvm, u32 temp)
|
2014-11-04 16:17:46 +02:00
|
|
|
{
|
|
|
|
/* ignore the notification if we are in test mode */
|
|
|
|
if (mvm->temperature_test)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mvm->temperature == temp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mvm->temperature = temp;
|
|
|
|
iwl_mvm_tt_handler(mvm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iwl_mvm_temp_notif_parse(struct iwl_mvm *mvm,
|
|
|
|
struct iwl_rx_packet *pkt)
|
2013-05-19 19:14:41 +03:00
|
|
|
{
|
2015-12-29 09:54:49 +02:00
|
|
|
struct iwl_dts_measurement_notif_v1 *notif_v1;
|
2014-09-04 12:29:15 +03:00
|
|
|
int len = iwl_rx_packet_payload_len(pkt);
|
2014-11-04 16:17:46 +02:00
|
|
|
int temp;
|
2014-09-04 12:29:15 +03:00
|
|
|
|
2015-12-29 09:54:49 +02:00
|
|
|
/* we can use notif_v1 only, because v2 only adds an additional
|
|
|
|
* parameter, which is not used in this function.
|
|
|
|
*/
|
|
|
|
if (WARN_ON_ONCE(len < sizeof(*notif_v1))) {
|
2014-09-04 12:29:15 +03:00
|
|
|
IWL_ERR(mvm, "Invalid DTS_MEASUREMENT_NOTIFICATION\n");
|
2014-11-04 16:17:46 +02:00
|
|
|
return -EINVAL;
|
2014-09-04 12:29:15 +03:00
|
|
|
}
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2015-12-29 09:54:49 +02:00
|
|
|
notif_v1 = (void *)pkt->data;
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2015-12-29 09:54:49 +02:00
|
|
|
temp = le32_to_cpu(notif_v1->temp);
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
/* shouldn't be negative, but since it's s32, make sure it isn't */
|
2014-11-04 16:17:46 +02:00
|
|
|
if (WARN_ON_ONCE(temp < 0))
|
|
|
|
temp = 0;
|
|
|
|
|
|
|
|
IWL_DEBUG_TEMP(mvm, "DTS_MEASUREMENT_NOTIFICATION - %d\n", temp);
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool iwl_mvm_temp_notif_wait(struct iwl_notif_wait_data *notif_wait,
|
|
|
|
struct iwl_rx_packet *pkt, void *data)
|
|
|
|
{
|
|
|
|
struct iwl_mvm *mvm =
|
|
|
|
container_of(notif_wait, struct iwl_mvm, notif_wait);
|
|
|
|
int *temp = data;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = iwl_mvm_temp_notif_parse(mvm, pkt);
|
|
|
|
if (ret < 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
*temp = ret;
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
return true;
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
|
|
|
|
2015-06-23 21:22:09 +02:00
|
|
|
void iwl_mvm_temp_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
|
2014-11-06 10:34:49 +02:00
|
|
|
{
|
|
|
|
struct iwl_rx_packet *pkt = rxb_addr(rxb);
|
2015-12-29 09:54:49 +02:00
|
|
|
struct iwl_dts_measurement_notif_v2 *notif_v2;
|
|
|
|
int len = iwl_rx_packet_payload_len(pkt);
|
2014-11-06 10:34:49 +02:00
|
|
|
int temp;
|
2015-12-29 09:54:49 +02:00
|
|
|
u32 ths_crossed;
|
2014-11-06 10:34:49 +02:00
|
|
|
|
|
|
|
/* the notification is handled synchronously in ctkill, so skip here */
|
|
|
|
if (test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status))
|
2015-06-23 21:22:09 +02:00
|
|
|
return;
|
2014-11-06 10:34:49 +02:00
|
|
|
|
|
|
|
temp = iwl_mvm_temp_notif_parse(mvm, pkt);
|
2015-12-29 09:54:49 +02:00
|
|
|
|
|
|
|
if (!iwl_mvm_is_tt_in_fw(mvm)) {
|
|
|
|
if (temp >= 0)
|
|
|
|
iwl_mvm_tt_temp_changed(mvm, temp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WARN_ON_ONCE(len < sizeof(*notif_v2))) {
|
|
|
|
IWL_ERR(mvm, "Invalid DTS_MEASUREMENT_NOTIFICATION\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
notif_v2 = (void *)pkt->data;
|
|
|
|
ths_crossed = le32_to_cpu(notif_v2->threshold_idx);
|
|
|
|
|
|
|
|
/* 0xFF in ths_crossed means the notification is not related
|
|
|
|
* to a trip, so we can ignore it here.
|
|
|
|
*/
|
|
|
|
if (ths_crossed == 0xFF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IWL_DEBUG_TEMP(mvm, "Temp = %d Threshold crossed = %d\n",
|
|
|
|
temp, ths_crossed);
|
|
|
|
|
|
|
|
#ifdef CONFIG_THERMAL
|
|
|
|
if (WARN_ON(ths_crossed >= IWL_MAX_DTS_TRIPS))
|
2015-06-23 21:22:09 +02:00
|
|
|
return;
|
2014-11-06 10:34:49 +02:00
|
|
|
|
2016-02-28 10:15:08 +02:00
|
|
|
if (mvm->tz_device.tzone) {
|
|
|
|
struct iwl_mvm_thermal_device *tz_dev = &mvm->tz_device;
|
|
|
|
|
2021-01-21 21:34:04 -05:00
|
|
|
thermal_zone_device_update(tz_dev->tzone,
|
|
|
|
THERMAL_TRIP_VIOLATED);
|
2016-02-28 10:15:08 +02:00
|
|
|
}
|
2015-12-29 09:54:49 +02:00
|
|
|
#endif /* CONFIG_THERMAL */
|
2014-11-06 10:34:49 +02:00
|
|
|
}
|
|
|
|
|
2015-12-16 16:34:55 +02:00
|
|
|
void iwl_mvm_ct_kill_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
|
|
|
|
{
|
|
|
|
struct iwl_rx_packet *pkt = rxb_addr(rxb);
|
|
|
|
struct ct_kill_notif *notif;
|
|
|
|
|
|
|
|
notif = (struct ct_kill_notif *)pkt->data;
|
|
|
|
IWL_DEBUG_TEMP(mvm, "CT Kill notification temperature = %d\n",
|
|
|
|
notif->temperature);
|
2022-01-29 13:16:22 +02:00
|
|
|
if (iwl_fw_lookup_notif_ver(mvm->fw, PHY_OPS_GROUP,
|
|
|
|
CT_KILL_NOTIFICATION, 0) > 1)
|
|
|
|
IWL_DEBUG_TEMP(mvm,
|
|
|
|
"CT kill notification DTS bitmap = 0x%x, Scheme = %d\n",
|
|
|
|
notif->dts, notif->scheme);
|
2015-12-16 16:34:55 +02:00
|
|
|
|
|
|
|
iwl_mvm_enter_ctkill(mvm);
|
|
|
|
}
|
|
|
|
|
2020-09-30 16:31:22 +03:00
|
|
|
/*
|
|
|
|
* send the DTS_MEASUREMENT_TRIGGER command with or without waiting for a
|
|
|
|
* response. If we get a response then the measurement is stored in 'temp'
|
|
|
|
*/
|
|
|
|
static int iwl_mvm_send_temp_cmd(struct iwl_mvm *mvm, bool response, s32 *temp)
|
2013-05-19 19:14:41 +03:00
|
|
|
{
|
2020-09-30 16:31:22 +03:00
|
|
|
struct iwl_host_cmd cmd = {};
|
|
|
|
struct iwl_dts_measurement_cmd dts_cmd = {
|
2014-09-04 12:29:15 +03:00
|
|
|
.flags = cpu_to_le32(DTS_TRIGGER_CMD_FLAGS_TEMP),
|
2013-05-19 19:14:41 +03:00
|
|
|
};
|
2020-09-30 16:31:22 +03:00
|
|
|
struct iwl_ext_dts_measurement_cmd ext_cmd = {
|
2020-01-31 15:45:26 +02:00
|
|
|
.control_mode = cpu_to_le32(DTS_DIRECT_WITHOUT_MEASURE),
|
2015-10-06 12:22:47 +03:00
|
|
|
};
|
2020-09-30 16:31:22 +03:00
|
|
|
struct iwl_dts_measurement_resp *resp;
|
|
|
|
void *cmd_ptr;
|
|
|
|
int ret;
|
|
|
|
u32 cmd_flags = 0;
|
|
|
|
u16 len;
|
|
|
|
|
|
|
|
/* Check which command format is used (regular/extended) */
|
|
|
|
if (fw_has_capa(&mvm->fw->ucode_capa,
|
|
|
|
IWL_UCODE_TLV_CAPA_EXTENDED_DTS_MEASURE)) {
|
|
|
|
len = sizeof(ext_cmd);
|
|
|
|
cmd_ptr = &ext_cmd;
|
|
|
|
} else {
|
|
|
|
len = sizeof(dts_cmd);
|
|
|
|
cmd_ptr = &dts_cmd;
|
|
|
|
}
|
|
|
|
/* The command version where we get a response is zero length */
|
|
|
|
if (response) {
|
|
|
|
cmd_flags = CMD_WANT_SKB;
|
|
|
|
len = 0;
|
|
|
|
}
|
2015-09-01 19:34:38 +03:00
|
|
|
|
2020-09-30 16:31:22 +03:00
|
|
|
cmd.id = WIDE_ID(PHY_OPS_GROUP, CMD_DTS_MEASUREMENT_TRIGGER_WIDE);
|
|
|
|
cmd.len[0] = len;
|
|
|
|
cmd.flags = cmd_flags;
|
|
|
|
cmd.data[0] = cmd_ptr;
|
|
|
|
|
|
|
|
IWL_DEBUG_TEMP(mvm,
|
|
|
|
"Sending temperature measurement command - %s response\n",
|
|
|
|
response ? "with" : "without");
|
|
|
|
ret = iwl_mvm_send_cmd(mvm, &cmd);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
IWL_ERR(mvm,
|
|
|
|
"Failed to send the temperature measurement command (err=%d)\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-10-06 12:22:47 +03:00
|
|
|
|
2020-09-30 16:31:22 +03:00
|
|
|
if (response) {
|
|
|
|
resp = (void *)cmd.resp_pkt->data;
|
|
|
|
*temp = le32_to_cpu(resp->temp);
|
|
|
|
IWL_DEBUG_TEMP(mvm,
|
|
|
|
"Got temperature measurement response: temp=%d\n",
|
|
|
|
*temp);
|
|
|
|
iwl_free_resp(&cmd);
|
|
|
|
}
|
2015-10-06 12:22:47 +03:00
|
|
|
|
2020-09-30 16:31:22 +03:00
|
|
|
return ret;
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
|
|
|
|
2015-12-27 13:45:42 +02:00
|
|
|
int iwl_mvm_get_temp(struct iwl_mvm *mvm, s32 *temp)
|
2013-05-19 19:14:41 +03:00
|
|
|
{
|
2014-09-04 12:29:15 +03:00
|
|
|
struct iwl_notification_wait wait_temp_notif;
|
2015-09-01 19:34:38 +03:00
|
|
|
static u16 temp_notif[] = { WIDE_ID(PHY_OPS_GROUP,
|
|
|
|
DTS_MEASUREMENT_NOTIF_WIDE) };
|
2015-12-27 13:45:42 +02:00
|
|
|
int ret;
|
2020-09-30 16:31:22 +03:00
|
|
|
u8 cmd_ver;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If command version is 1 we send the command and immediately get
|
|
|
|
* a response. For older versions we send the command and wait for a
|
|
|
|
* notification (no command TLV for previous versions).
|
|
|
|
*/
|
iwlwifi: make iwl_fw_lookup_cmd_ver() take a cmd_id
Instead of taking the group/command separately, make the function
take a combined command ID. In many cases, this allows us to pass
an existing command ID (e.g. cmd.id), or introduce a new variable
for it, so that we don't use the command ID twice.
This way, we can also use LONG_GROUP implicitly, so we don't need
to spell that out for many commands.
Apart from mvm.h, fw/img.{c,h} changes and some copyright and
indentation updates, this was done with spatch:
@@
identifier cmd;
expression fw, G, C, def;
@@
struct iwl_host_cmd cmd = {
.id = WIDE_ID(G, C),
...
};
...
-iwl_fw_lookup_cmd_ver(fw, G, C, def)
+iwl_fw_lookup_cmd_ver(fw, cmd.id, def)
@@
identifier cmd;
expression fw, C, def;
@@
struct iwl_host_cmd cmd = {
.id = C,
...
};
...
-iwl_fw_lookup_cmd_ver(fw, \(IWL_ALWAYS_LONG_GROUP\|LONG_GROUP\), C, def)
+iwl_fw_lookup_cmd_ver(fw, cmd.id, def)
@@
identifier func;
expression fw, G, C, mvm, flags, cmd, size, def;
type rettype;
@@
rettype func(...)
{
+u32 cmd_id = WIDE_ID(G, C);
...
-iwl_fw_lookup_cmd_ver(fw, G, C, def)
+iwl_fw_lookup_cmd_ver(fw, cmd_id, def)
...
-iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(G, C), flags, cmd, size)
+iwl_mvm_send_cmd_pdu(mvm, cmd_id, flags, cmd, size)
...
}
@@
identifier func;
expression fw, G, C, mvm, flags, cmd, size, def;
type rettype;
@@
rettype func(...)
{
+u32 cmd_id = C;
...
-iwl_fw_lookup_cmd_ver(fw, \(IWL_ALWAYS_LONG_GROUP\|LONG_GROUP\), C, def)
+iwl_fw_lookup_cmd_ver(fw, cmd_id, def)
...
-iwl_mvm_send_cmd_pdu(mvm, C, flags, cmd, size)
+iwl_mvm_send_cmd_pdu(mvm, cmd_id, flags, cmd, size)
...
}
@@
expression fw, C, def;
@@
-iwl_fw_lookup_cmd_ver(fw, \(IWL_ALWAYS_LONG_GROUP\|LONG_GROUP\), C, def)
+iwl_fw_lookup_cmd_ver(fw, C, def)
@@
expression fw, C, G, def;
@@
-iwl_fw_lookup_cmd_ver(fw, G, C, def)
+iwl_fw_lookup_cmd_ver(fw, WIDE_ID(G, C), def)
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20220128153014.c4ac213cef5c.I6fd9a4fcbcf16ef3a3ae20a2b08ee54ebe06f96f@changeid
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
2022-01-28 15:34:25 +02:00
|
|
|
cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw,
|
|
|
|
WIDE_ID(PHY_OPS_GROUP, CMD_DTS_MEASUREMENT_TRIGGER_WIDE),
|
2020-09-30 16:31:22 +03:00
|
|
|
IWL_FW_CMD_VER_UNKNOWN);
|
|
|
|
if (cmd_ver == 1)
|
|
|
|
return iwl_mvm_send_temp_cmd(mvm, true, temp);
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
lockdep_assert_held(&mvm->mutex);
|
2014-08-20 17:26:58 +03:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
iwl_init_notification_wait(&mvm->notif_wait, &wait_temp_notif,
|
|
|
|
temp_notif, ARRAY_SIZE(temp_notif),
|
2015-12-27 13:45:42 +02:00
|
|
|
iwl_mvm_temp_notif_wait, temp);
|
2014-08-20 17:58:20 +03:00
|
|
|
|
2020-09-30 16:31:22 +03:00
|
|
|
ret = iwl_mvm_send_temp_cmd(mvm, false, temp);
|
2014-09-04 12:29:15 +03:00
|
|
|
if (ret) {
|
|
|
|
iwl_remove_notification(&mvm->notif_wait, &wait_temp_notif);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
ret = iwl_wait_notification(&mvm->notif_wait, &wait_temp_notif,
|
|
|
|
IWL_MVM_TEMP_NOTIF_WAIT_TIMEOUT);
|
2015-12-27 13:45:42 +02:00
|
|
|
if (ret)
|
2021-02-10 17:23:48 +02:00
|
|
|
IWL_WARN(mvm, "Getting the temperature timed out\n");
|
2014-08-20 17:26:58 +03:00
|
|
|
|
2015-12-27 13:45:42 +02:00
|
|
|
return ret;
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_exit_ctkill(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct iwl_mvm_tt_mgmt *tt;
|
|
|
|
struct iwl_mvm *mvm;
|
|
|
|
u32 duration;
|
|
|
|
s32 temp;
|
2015-12-27 13:45:42 +02:00
|
|
|
int ret;
|
2013-05-19 19:14:41 +03:00
|
|
|
|
|
|
|
tt = container_of(work, struct iwl_mvm_tt_mgmt, ct_kill_exit.work);
|
|
|
|
mvm = container_of(tt, struct iwl_mvm, thermal_throttle);
|
|
|
|
|
2015-12-16 16:34:55 +02:00
|
|
|
if (iwl_mvm_is_tt_in_fw(mvm)) {
|
|
|
|
iwl_mvm_exit_ctkill(mvm);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-19 12:26:39 +03:00
|
|
|
duration = tt->params.ct_kill_duration;
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2020-10-08 18:09:45 +03:00
|
|
|
flush_work(&mvm->roc_done_wk);
|
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
mutex_lock(&mvm->mutex);
|
|
|
|
|
|
|
|
if (__iwl_mvm_mac_start(mvm))
|
|
|
|
goto reschedule;
|
|
|
|
|
2015-12-27 13:45:42 +02:00
|
|
|
ret = iwl_mvm_get_temp(mvm, &temp);
|
2013-05-19 19:14:41 +03:00
|
|
|
|
2014-09-04 12:29:15 +03:00
|
|
|
__iwl_mvm_mac_stop(mvm);
|
|
|
|
|
2015-12-27 13:45:42 +02:00
|
|
|
if (ret)
|
2013-05-19 19:14:41 +03:00
|
|
|
goto reschedule;
|
2014-09-04 12:29:15 +03:00
|
|
|
|
2013-05-19 19:14:41 +03:00
|
|
|
IWL_DEBUG_TEMP(mvm, "NIC temperature: %d\n", temp);
|
|
|
|
|
2015-04-19 12:26:39 +03:00
|
|
|
if (temp <= tt->params.ct_kill_exit) {
|
2014-09-04 12:29:15 +03:00
|
|
|
mutex_unlock(&mvm->mutex);
|
2013-05-19 19:14:41 +03:00
|
|
|
iwl_mvm_exit_ctkill(mvm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
reschedule:
|
2014-09-04 12:29:15 +03:00
|
|
|
mutex_unlock(&mvm->mutex);
|
2013-05-19 19:14:41 +03:00
|
|
|
schedule_delayed_work(&mvm->thermal_throttle.ct_kill_exit,
|
|
|
|
round_jiffies(duration * HZ));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void iwl_mvm_tt_smps_iterator(void *_data, u8 *mac,
|
|
|
|
struct ieee80211_vif *vif)
|
|
|
|
{
|
|
|
|
struct iwl_mvm *mvm = _data;
|
|
|
|
enum ieee80211_smps_mode smps_mode;
|
|
|
|
|
|
|
|
lockdep_assert_held(&mvm->mutex);
|
|
|
|
|
|
|
|
if (mvm->thermal_throttle.dynamic_smps)
|
|
|
|
smps_mode = IEEE80211_SMPS_DYNAMIC;
|
|
|
|
else
|
|
|
|
smps_mode = IEEE80211_SMPS_AUTOMATIC;
|
|
|
|
|
2013-06-04 12:28:51 +03:00
|
|
|
if (vif->type != NL80211_IFTYPE_STATION)
|
|
|
|
return;
|
|
|
|
|
2023-03-28 10:59:01 +03:00
|
|
|
iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, smps_mode, 0);
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void iwl_mvm_tt_tx_protection(struct iwl_mvm *mvm, bool enable)
|
|
|
|
{
|
|
|
|
struct iwl_mvm_sta *mvmsta;
|
|
|
|
int i, err;
|
|
|
|
|
2020-10-08 18:09:37 +03:00
|
|
|
for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
|
2016-04-10 15:51:54 +03:00
|
|
|
mvmsta = iwl_mvm_sta_from_staid_protected(mvm, i);
|
|
|
|
if (!mvmsta)
|
2013-05-19 19:14:41 +03:00
|
|
|
continue;
|
2016-04-10 15:51:54 +03:00
|
|
|
|
2013-05-19 19:14:41 +03:00
|
|
|
if (enable == mvmsta->tt_tx_protection)
|
|
|
|
continue;
|
2013-06-28 13:39:18 +02:00
|
|
|
err = iwl_mvm_tx_protection(mvm, mvmsta, enable);
|
2013-05-19 19:14:41 +03:00
|
|
|
if (err) {
|
|
|
|
IWL_ERR(mvm, "Failed to %s Tx protection\n",
|
|
|
|
enable ? "enable" : "disable");
|
|
|
|
} else {
|
|
|
|
IWL_DEBUG_TEMP(mvm, "%s Tx protection\n",
|
|
|
|
enable ? "Enable" : "Disable");
|
|
|
|
mvmsta->tt_tx_protection = enable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-16 21:12:02 -05:00
|
|
|
void iwl_mvm_tt_tx_backoff(struct iwl_mvm *mvm, u32 backoff)
|
2013-05-19 19:14:41 +03:00
|
|
|
{
|
|
|
|
struct iwl_host_cmd cmd = {
|
|
|
|
.id = REPLY_THERMAL_MNG_BACKOFF,
|
|
|
|
.len = { sizeof(u32), },
|
|
|
|
.data = { &backoff, },
|
|
|
|
};
|
|
|
|
|
2014-01-16 21:12:02 -05:00
|
|
|
backoff = max(backoff, mvm->thermal_throttle.min_backoff);
|
|
|
|
|
2013-05-19 19:14:41 +03:00
|
|
|
if (iwl_mvm_send_cmd(mvm, &cmd) == 0) {
|
|
|
|
IWL_DEBUG_TEMP(mvm, "Set Thermal Tx backoff to: %u\n",
|
|
|
|
backoff);
|
|
|
|
mvm->thermal_throttle.tx_backoff = backoff;
|
|
|
|
} else {
|
|
|
|
IWL_ERR(mvm, "Failed to change Thermal Tx backoff\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void iwl_mvm_tt_handler(struct iwl_mvm *mvm)
|
|
|
|
{
|
2015-04-19 12:26:39 +03:00
|
|
|
struct iwl_tt_params *params = &mvm->thermal_throttle.params;
|
2013-05-19 19:14:41 +03:00
|
|
|
struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle;
|
|
|
|
s32 temperature = mvm->temperature;
|
2013-06-18 14:28:56 +03:00
|
|
|
bool throttle_enable = false;
|
2013-05-19 19:14:41 +03:00
|
|
|
int i;
|
|
|
|
u32 tx_backoff;
|
|
|
|
|
|
|
|
IWL_DEBUG_TEMP(mvm, "NIC temperature: %d\n", mvm->temperature);
|
|
|
|
|
|
|
|
if (params->support_ct_kill && temperature >= params->ct_kill_entry) {
|
|
|
|
iwl_mvm_enter_ctkill(mvm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-20 17:26:58 +03:00
|
|
|
if (params->support_ct_kill &&
|
2015-04-19 12:26:39 +03:00
|
|
|
temperature <= params->ct_kill_exit) {
|
2014-08-20 17:26:58 +03:00
|
|
|
iwl_mvm_exit_ctkill(mvm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-19 19:14:41 +03:00
|
|
|
if (params->support_dynamic_smps) {
|
|
|
|
if (!tt->dynamic_smps &&
|
|
|
|
temperature >= params->dynamic_smps_entry) {
|
|
|
|
IWL_DEBUG_TEMP(mvm, "Enable dynamic SMPS\n");
|
|
|
|
tt->dynamic_smps = true;
|
|
|
|
ieee80211_iterate_active_interfaces_atomic(
|
|
|
|
mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
|
|
|
|
iwl_mvm_tt_smps_iterator, mvm);
|
2013-06-18 14:28:56 +03:00
|
|
|
throttle_enable = true;
|
2013-05-19 19:14:41 +03:00
|
|
|
} else if (tt->dynamic_smps &&
|
|
|
|
temperature <= params->dynamic_smps_exit) {
|
|
|
|
IWL_DEBUG_TEMP(mvm, "Disable dynamic SMPS\n");
|
|
|
|
tt->dynamic_smps = false;
|
|
|
|
ieee80211_iterate_active_interfaces_atomic(
|
|
|
|
mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
|
|
|
|
iwl_mvm_tt_smps_iterator, mvm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params->support_tx_protection) {
|
2013-06-18 14:28:56 +03:00
|
|
|
if (temperature >= params->tx_protection_entry) {
|
2013-05-19 19:14:41 +03:00
|
|
|
iwl_mvm_tt_tx_protection(mvm, true);
|
2013-06-18 14:28:56 +03:00
|
|
|
throttle_enable = true;
|
|
|
|
} else if (temperature <= params->tx_protection_exit) {
|
2013-05-19 19:14:41 +03:00
|
|
|
iwl_mvm_tt_tx_protection(mvm, false);
|
2013-06-18 14:28:56 +03:00
|
|
|
}
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (params->support_tx_backoff) {
|
2014-04-01 16:44:21 +03:00
|
|
|
tx_backoff = tt->min_backoff;
|
2013-05-19 19:14:41 +03:00
|
|
|
for (i = 0; i < TT_TX_BACKOFF_SIZE; i++) {
|
|
|
|
if (temperature < params->tx_backoff[i].temperature)
|
|
|
|
break;
|
2014-04-01 16:44:21 +03:00
|
|
|
tx_backoff = max(tt->min_backoff,
|
|
|
|
params->tx_backoff[i].backoff);
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
2014-04-01 16:44:21 +03:00
|
|
|
if (tx_backoff != tt->min_backoff)
|
2013-06-18 14:28:56 +03:00
|
|
|
throttle_enable = true;
|
2013-05-19 19:14:41 +03:00
|
|
|
if (tt->tx_backoff != tx_backoff)
|
|
|
|
iwl_mvm_tt_tx_backoff(mvm, tx_backoff);
|
|
|
|
}
|
2013-06-18 14:28:56 +03:00
|
|
|
|
|
|
|
if (!tt->throttle && throttle_enable) {
|
|
|
|
IWL_WARN(mvm,
|
|
|
|
"Due to high temperature thermal throttling initiated\n");
|
|
|
|
tt->throttle = true;
|
2014-04-02 21:37:57 +03:00
|
|
|
} else if (tt->throttle && !tt->dynamic_smps &&
|
|
|
|
tt->tx_backoff == tt->min_backoff &&
|
2013-06-18 14:28:56 +03:00
|
|
|
temperature <= params->tx_protection_exit) {
|
|
|
|
IWL_WARN(mvm,
|
|
|
|
"Temperature is back to normal thermal throttling stopped\n");
|
|
|
|
tt->throttle = false;
|
|
|
|
}
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
|
|
|
|
2015-04-19 12:26:39 +03:00
|
|
|
static const struct iwl_tt_params iwl_mvm_default_tt_params = {
|
2013-05-19 19:14:41 +03:00
|
|
|
.ct_kill_entry = 118,
|
|
|
|
.ct_kill_exit = 96,
|
|
|
|
.ct_kill_duration = 5,
|
|
|
|
.dynamic_smps_entry = 114,
|
|
|
|
.dynamic_smps_exit = 110,
|
|
|
|
.tx_protection_entry = 114,
|
|
|
|
.tx_protection_exit = 108,
|
|
|
|
.tx_backoff = {
|
|
|
|
{.temperature = 112, .backoff = 200},
|
|
|
|
{.temperature = 113, .backoff = 600},
|
|
|
|
{.temperature = 114, .backoff = 1200},
|
|
|
|
{.temperature = 115, .backoff = 2000},
|
|
|
|
{.temperature = 116, .backoff = 4000},
|
|
|
|
{.temperature = 117, .backoff = 10000},
|
|
|
|
},
|
|
|
|
.support_ct_kill = true,
|
|
|
|
.support_dynamic_smps = true,
|
|
|
|
.support_tx_protection = true,
|
|
|
|
.support_tx_backoff = true,
|
|
|
|
};
|
|
|
|
|
2016-02-14 14:03:10 +02:00
|
|
|
/* budget in mWatt */
|
|
|
|
static const u32 iwl_mvm_cdev_budgets[] = {
|
2019-11-15 09:28:20 +02:00
|
|
|
2400, /* cooling state 0 */
|
|
|
|
2000, /* cooling state 1 */
|
|
|
|
1800, /* cooling state 2 */
|
|
|
|
1600, /* cooling state 3 */
|
|
|
|
1400, /* cooling state 4 */
|
|
|
|
1200, /* cooling state 5 */
|
|
|
|
1000, /* cooling state 6 */
|
|
|
|
900, /* cooling state 7 */
|
|
|
|
800, /* cooling state 8 */
|
|
|
|
700, /* cooling state 9 */
|
|
|
|
650, /* cooling state 10 */
|
|
|
|
600, /* cooling state 11 */
|
|
|
|
550, /* cooling state 12 */
|
|
|
|
500, /* cooling state 13 */
|
|
|
|
450, /* cooling state 14 */
|
|
|
|
400, /* cooling state 15 */
|
|
|
|
350, /* cooling state 16 */
|
|
|
|
300, /* cooling state 17 */
|
|
|
|
250, /* cooling state 18 */
|
|
|
|
200, /* cooling state 19 */
|
|
|
|
150, /* cooling state 20 */
|
2016-02-14 14:03:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int iwl_mvm_ctdp_command(struct iwl_mvm *mvm, u32 op, u32 state)
|
2016-02-24 12:19:22 +02:00
|
|
|
{
|
|
|
|
struct iwl_mvm_ctdp_cmd cmd = {
|
|
|
|
.operation = cpu_to_le32(op),
|
2016-02-14 14:03:10 +02:00
|
|
|
.budget = cpu_to_le32(iwl_mvm_cdev_budgets[state]),
|
2016-02-24 12:19:22 +02:00
|
|
|
.window_size = 0,
|
|
|
|
};
|
|
|
|
int ret;
|
|
|
|
u32 status;
|
|
|
|
|
|
|
|
lockdep_assert_held(&mvm->mutex);
|
|
|
|
|
2017-09-02 11:25:40 +03:00
|
|
|
status = 0;
|
2016-02-24 12:19:22 +02:00
|
|
|
ret = iwl_mvm_send_cmd_pdu_status(mvm, WIDE_ID(PHY_OPS_GROUP,
|
|
|
|
CTDP_CONFIG_CMD),
|
|
|
|
sizeof(cmd), &cmd, &status);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
IWL_ERR(mvm, "cTDP command failed (err=%d)\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case CTDP_CMD_OPERATION_START:
|
|
|
|
#ifdef CONFIG_THERMAL
|
2016-02-14 14:03:10 +02:00
|
|
|
mvm->cooling_dev.cur_state = state;
|
2016-02-24 12:19:22 +02:00
|
|
|
#endif /* CONFIG_THERMAL */
|
|
|
|
break;
|
|
|
|
case CTDP_CMD_OPERATION_REPORT:
|
|
|
|
IWL_DEBUG_TEMP(mvm, "cTDP avg energy in mWatt = %d\n", status);
|
|
|
|
/* when the function is called with CTDP_CMD_OPERATION_REPORT
|
|
|
|
* option the function should return the average budget value
|
|
|
|
* that is received from the FW.
|
|
|
|
* The budget can't be less or equal to 0, so it's possible
|
|
|
|
* to distinguish between error values and budgets.
|
|
|
|
*/
|
|
|
|
return status;
|
|
|
|
case CTDP_CMD_OPERATION_STOP:
|
|
|
|
IWL_DEBUG_TEMP(mvm, "cTDP stopped successfully\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-29 09:54:49 +02:00
|
|
|
#ifdef CONFIG_THERMAL
|
|
|
|
static int compare_temps(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
return ((s16)le16_to_cpu(*(__le16 *)a) -
|
|
|
|
(s16)le16_to_cpu(*(__le16 *)b));
|
|
|
|
}
|
2024-02-07 20:12:38 +01:00
|
|
|
|
|
|
|
struct iwl_trip_walk_data {
|
|
|
|
__le16 *thresholds;
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int iwl_trip_temp_cb(struct thermal_trip *trip, void *arg)
|
|
|
|
{
|
|
|
|
struct iwl_trip_walk_data *twd = arg;
|
|
|
|
|
|
|
|
if (trip->temperature == THERMAL_TEMP_INVALID)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
twd->thresholds[twd->count++] = cpu_to_le16((s16)(trip->temperature / 1000));
|
|
|
|
return 0;
|
|
|
|
}
|
2019-09-18 16:49:03 +03:00
|
|
|
#endif
|
2015-12-29 09:54:49 +02:00
|
|
|
|
|
|
|
int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm)
|
|
|
|
{
|
|
|
|
struct temp_report_ths_cmd cmd = {0};
|
2019-09-18 16:49:03 +03:00
|
|
|
int ret;
|
|
|
|
#ifdef CONFIG_THERMAL
|
2024-02-07 20:12:38 +01:00
|
|
|
struct iwl_trip_walk_data twd = { .thresholds = cmd.thresholds, .count = 0 };
|
2015-12-29 09:54:49 +02:00
|
|
|
|
|
|
|
lockdep_assert_held(&mvm->mutex);
|
|
|
|
|
2016-02-28 10:15:08 +02:00
|
|
|
if (!mvm->tz_device.tzone)
|
2019-09-18 16:49:03 +03:00
|
|
|
goto send;
|
2016-02-28 10:15:08 +02:00
|
|
|
|
2024-02-07 20:12:38 +01:00
|
|
|
/*
|
|
|
|
* The thermal core holds an array of temperature trips that are
|
|
|
|
* unsorted and uncompressed, the FW should get it compressed and
|
|
|
|
* sorted.
|
2015-12-29 09:54:49 +02:00
|
|
|
*/
|
|
|
|
|
2022-10-14 09:32:50 +02:00
|
|
|
/* compress trips to cmd array, remove uninitialized values*/
|
2024-02-07 20:12:38 +01:00
|
|
|
for_each_thermal_trip(mvm->tz_device.tzone, iwl_trip_temp_cb, &twd);
|
2015-12-29 09:54:49 +02:00
|
|
|
|
2024-02-07 20:12:38 +01:00
|
|
|
cmd.num_temps = cpu_to_le32(twd.count);
|
|
|
|
if (twd.count)
|
|
|
|
sort(cmd.thresholds, twd.count, sizeof(s16), compare_temps, NULL);
|
2015-12-29 09:54:49 +02:00
|
|
|
|
|
|
|
send:
|
2019-09-18 16:49:03 +03:00
|
|
|
#endif
|
2015-12-29 09:54:49 +02:00
|
|
|
ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(PHY_OPS_GROUP,
|
|
|
|
TEMP_REPORTING_THRESHOLDS_CMD),
|
|
|
|
0, sizeof(cmd), &cmd);
|
|
|
|
if (ret)
|
|
|
|
IWL_ERR(mvm, "TEMP_REPORT_THS_CMD command failed (err=%d)\n",
|
|
|
|
ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-18 16:49:03 +03:00
|
|
|
#ifdef CONFIG_THERMAL
|
2015-12-29 09:54:49 +02:00
|
|
|
static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device,
|
|
|
|
int *temperature)
|
|
|
|
{
|
2023-03-01 21:14:32 +01:00
|
|
|
struct iwl_mvm *mvm = thermal_zone_device_priv(device);
|
2015-12-29 09:54:49 +02:00
|
|
|
int ret;
|
|
|
|
int temp;
|
|
|
|
|
|
|
|
mutex_lock(&mvm->mutex);
|
|
|
|
|
2017-03-22 22:05:12 +01:00
|
|
|
if (!iwl_mvm_firmware_running(mvm) ||
|
2017-06-02 11:56:58 +02:00
|
|
|
mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) {
|
2017-09-18 14:39:26 +03:00
|
|
|
ret = -ENODATA;
|
2015-12-29 09:54:49 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = iwl_mvm_get_temp(mvm, &temp);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
*temperature = temp * 1000;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&mvm->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device,
|
|
|
|
int trip, int temp)
|
|
|
|
{
|
2023-03-01 21:14:32 +01:00
|
|
|
struct iwl_mvm *mvm = thermal_zone_device_priv(device);
|
2022-10-14 09:32:50 +02:00
|
|
|
int ret;
|
2015-12-29 09:54:49 +02:00
|
|
|
|
|
|
|
mutex_lock(&mvm->mutex);
|
|
|
|
|
2017-03-22 22:05:12 +01:00
|
|
|
if (!iwl_mvm_firmware_running(mvm) ||
|
2017-06-02 11:56:58 +02:00
|
|
|
mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) {
|
2015-12-29 09:54:49 +02:00
|
|
|
ret = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((temp / 1000) > S16_MAX) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = iwl_mvm_send_temp_report_ths_cmd(mvm);
|
|
|
|
out:
|
|
|
|
mutex_unlock(&mvm->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct thermal_zone_device_ops tzone_ops = {
|
|
|
|
.get_temp = iwl_mvm_tzone_get_temp,
|
|
|
|
.set_trip_temp = iwl_mvm_tzone_set_trip_temp,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm)
|
|
|
|
{
|
2020-06-29 14:29:22 +02:00
|
|
|
int i, ret;
|
2020-01-31 15:45:24 +02:00
|
|
|
char name[16];
|
|
|
|
static atomic_t counter = ATOMIC_INIT(0);
|
2015-12-29 09:54:49 +02:00
|
|
|
|
|
|
|
if (!iwl_mvm_is_tt_in_fw(mvm)) {
|
|
|
|
mvm->tz_device.tzone = NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BUILD_BUG_ON(ARRAY_SIZE(name) >= THERMAL_NAME_LENGTH);
|
|
|
|
|
2020-01-31 15:45:24 +02:00
|
|
|
sprintf(name, "iwlwifi_%u", atomic_inc_return(&counter) & 0xFF);
|
2024-02-07 20:10:24 +01:00
|
|
|
/*
|
|
|
|
* 0 is a valid temperature,
|
|
|
|
* so initialize the array with S16_MIN which invalid temperature
|
|
|
|
*/
|
|
|
|
for (i = 0 ; i < IWL_MAX_DTS_TRIPS; i++) {
|
|
|
|
mvm->tz_device.trips[i].temperature = THERMAL_TEMP_INVALID;
|
|
|
|
mvm->tz_device.trips[i].type = THERMAL_TRIP_PASSIVE;
|
2024-02-12 19:38:07 +01:00
|
|
|
mvm->tz_device.trips[i].flags = THERMAL_TRIP_FLAG_RW_TEMP;
|
2024-02-07 20:10:24 +01:00
|
|
|
}
|
2022-10-14 09:32:50 +02:00
|
|
|
mvm->tz_device.tzone = thermal_zone_device_register_with_trips(name,
|
|
|
|
mvm->tz_device.trips,
|
2015-12-29 09:54:49 +02:00
|
|
|
IWL_MAX_DTS_TRIPS,
|
|
|
|
mvm, &tzone_ops,
|
|
|
|
NULL, 0, 0);
|
|
|
|
if (IS_ERR(mvm->tz_device.tzone)) {
|
|
|
|
IWL_DEBUG_TEMP(mvm,
|
|
|
|
"Failed to register to thermal zone (err = %ld)\n",
|
|
|
|
PTR_ERR(mvm->tz_device.tzone));
|
2016-02-28 10:15:08 +02:00
|
|
|
mvm->tz_device.tzone = NULL;
|
2015-12-29 09:54:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-29 14:29:22 +02:00
|
|
|
ret = thermal_zone_device_enable(mvm->tz_device.tzone);
|
|
|
|
if (ret) {
|
|
|
|
IWL_DEBUG_TEMP(mvm, "Failed to enable thermal zone\n");
|
|
|
|
thermal_zone_device_unregister(mvm->tz_device.tzone);
|
2022-10-14 09:32:50 +02:00
|
|
|
}
|
2015-12-29 09:54:49 +02:00
|
|
|
}
|
|
|
|
|
2016-01-05 10:34:47 +02:00
|
|
|
static int iwl_mvm_tcool_get_max_state(struct thermal_cooling_device *cdev,
|
|
|
|
unsigned long *state)
|
|
|
|
{
|
|
|
|
*state = ARRAY_SIZE(iwl_mvm_cdev_budgets) - 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iwl_mvm_tcool_get_cur_state(struct thermal_cooling_device *cdev,
|
|
|
|
unsigned long *state)
|
|
|
|
{
|
|
|
|
struct iwl_mvm *mvm = (struct iwl_mvm *)(cdev->devdata);
|
|
|
|
|
|
|
|
*state = mvm->cooling_dev.cur_state;
|
2016-02-14 14:03:10 +02:00
|
|
|
|
2016-01-05 10:34:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iwl_mvm_tcool_set_cur_state(struct thermal_cooling_device *cdev,
|
|
|
|
unsigned long new_state)
|
|
|
|
{
|
|
|
|
struct iwl_mvm *mvm = (struct iwl_mvm *)(cdev->devdata);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&mvm->mutex);
|
|
|
|
|
2017-03-22 22:05:12 +01:00
|
|
|
if (!iwl_mvm_firmware_running(mvm) ||
|
2017-06-02 11:56:58 +02:00
|
|
|
mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) {
|
2017-03-22 22:00:10 +01:00
|
|
|
ret = -EIO;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
2016-01-05 10:34:47 +02:00
|
|
|
if (new_state >= ARRAY_SIZE(iwl_mvm_cdev_budgets)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
|
2016-02-14 14:03:10 +02:00
|
|
|
new_state);
|
2016-01-05 10:34:47 +02:00
|
|
|
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&mvm->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-06-21 14:10:42 +05:30
|
|
|
static const struct thermal_cooling_device_ops tcooling_ops = {
|
2016-01-05 10:34:47 +02:00
|
|
|
.get_max_state = iwl_mvm_tcool_get_max_state,
|
|
|
|
.get_cur_state = iwl_mvm_tcool_get_cur_state,
|
|
|
|
.set_cur_state = iwl_mvm_tcool_set_cur_state,
|
|
|
|
};
|
|
|
|
|
2016-02-28 10:15:08 +02:00
|
|
|
static void iwl_mvm_cooling_device_register(struct iwl_mvm *mvm)
|
2016-01-05 10:34:47 +02:00
|
|
|
{
|
|
|
|
char name[] = "iwlwifi";
|
|
|
|
|
2016-02-28 10:15:08 +02:00
|
|
|
if (!iwl_mvm_is_ctdp_supported(mvm))
|
|
|
|
return;
|
2016-01-05 10:34:47 +02:00
|
|
|
|
|
|
|
BUILD_BUG_ON(ARRAY_SIZE(name) >= THERMAL_NAME_LENGTH);
|
|
|
|
|
|
|
|
mvm->cooling_dev.cdev =
|
|
|
|
thermal_cooling_device_register(name,
|
|
|
|
mvm,
|
|
|
|
&tcooling_ops);
|
|
|
|
|
|
|
|
if (IS_ERR(mvm->cooling_dev.cdev)) {
|
|
|
|
IWL_DEBUG_TEMP(mvm,
|
|
|
|
"Failed to register to cooling device (err = %ld)\n",
|
|
|
|
PTR_ERR(mvm->cooling_dev.cdev));
|
2016-02-28 10:15:08 +02:00
|
|
|
mvm->cooling_dev.cdev = NULL;
|
|
|
|
return;
|
2016-01-05 10:34:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 09:54:49 +02:00
|
|
|
static void iwl_mvm_thermal_zone_unregister(struct iwl_mvm *mvm)
|
|
|
|
{
|
2016-02-28 10:15:08 +02:00
|
|
|
if (!iwl_mvm_is_tt_in_fw(mvm) || !mvm->tz_device.tzone)
|
2015-12-29 09:54:49 +02:00
|
|
|
return;
|
|
|
|
|
2016-02-28 10:15:08 +02:00
|
|
|
IWL_DEBUG_TEMP(mvm, "Thermal zone device unregister\n");
|
2017-01-17 14:22:24 -08:00
|
|
|
if (mvm->tz_device.tzone) {
|
|
|
|
thermal_zone_device_unregister(mvm->tz_device.tzone);
|
|
|
|
mvm->tz_device.tzone = NULL;
|
|
|
|
}
|
2015-12-29 09:54:49 +02:00
|
|
|
}
|
2016-01-05 10:34:47 +02:00
|
|
|
|
|
|
|
static void iwl_mvm_cooling_device_unregister(struct iwl_mvm *mvm)
|
|
|
|
{
|
2016-02-28 10:15:08 +02:00
|
|
|
if (!iwl_mvm_is_ctdp_supported(mvm) || !mvm->cooling_dev.cdev)
|
2016-01-05 10:34:47 +02:00
|
|
|
return;
|
|
|
|
|
2016-02-28 10:15:08 +02:00
|
|
|
IWL_DEBUG_TEMP(mvm, "Cooling device unregister\n");
|
2017-01-17 14:22:24 -08:00
|
|
|
if (mvm->cooling_dev.cdev) {
|
|
|
|
thermal_cooling_device_unregister(mvm->cooling_dev.cdev);
|
|
|
|
mvm->cooling_dev.cdev = NULL;
|
|
|
|
}
|
2016-01-05 10:34:47 +02:00
|
|
|
}
|
2015-12-29 09:54:49 +02:00
|
|
|
#endif /* CONFIG_THERMAL */
|
|
|
|
|
|
|
|
void iwl_mvm_thermal_initialize(struct iwl_mvm *mvm, u32 min_backoff)
|
2013-05-19 19:14:41 +03:00
|
|
|
{
|
|
|
|
struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle;
|
|
|
|
|
|
|
|
IWL_DEBUG_TEMP(mvm, "Initialize Thermal Throttling\n");
|
2013-07-24 14:49:18 +03:00
|
|
|
|
2015-04-19 12:26:39 +03:00
|
|
|
if (mvm->cfg->thermal_params)
|
|
|
|
tt->params = *mvm->cfg->thermal_params;
|
2013-07-24 14:49:18 +03:00
|
|
|
else
|
2015-04-19 12:26:39 +03:00
|
|
|
tt->params = iwl_mvm_default_tt_params;
|
2013-07-24 14:49:18 +03:00
|
|
|
|
2013-06-18 14:28:56 +03:00
|
|
|
tt->throttle = false;
|
2014-12-15 14:15:15 +02:00
|
|
|
tt->dynamic_smps = false;
|
2014-01-16 21:12:02 -05:00
|
|
|
tt->min_backoff = min_backoff;
|
2013-05-19 19:14:41 +03:00
|
|
|
INIT_DELAYED_WORK(&tt->ct_kill_exit, check_exit_ctkill);
|
2015-12-29 09:54:49 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_THERMAL
|
2016-01-05 10:34:47 +02:00
|
|
|
iwl_mvm_cooling_device_register(mvm);
|
2015-12-29 09:54:49 +02:00
|
|
|
iwl_mvm_thermal_zone_register(mvm);
|
|
|
|
#endif
|
2017-03-16 13:00:59 +02:00
|
|
|
mvm->init_status |= IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE;
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|
|
|
|
|
2015-12-29 09:54:49 +02:00
|
|
|
void iwl_mvm_thermal_exit(struct iwl_mvm *mvm)
|
2013-05-19 19:14:41 +03:00
|
|
|
{
|
2017-03-16 13:00:59 +02:00
|
|
|
if (!(mvm->init_status & IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE))
|
|
|
|
return;
|
|
|
|
|
2013-05-19 19:14:41 +03:00
|
|
|
cancel_delayed_work_sync(&mvm->thermal_throttle.ct_kill_exit);
|
|
|
|
IWL_DEBUG_TEMP(mvm, "Exit Thermal Throttling\n");
|
2015-12-29 09:54:49 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_THERMAL
|
2016-01-05 10:34:47 +02:00
|
|
|
iwl_mvm_cooling_device_unregister(mvm);
|
2015-12-29 09:54:49 +02:00
|
|
|
iwl_mvm_thermal_zone_unregister(mvm);
|
|
|
|
#endif
|
2017-03-16 13:00:59 +02:00
|
|
|
mvm->init_status &= ~IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE;
|
2013-05-19 19:14:41 +03:00
|
|
|
}
|