18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/******************************************************************************
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Portions of this file are derived from the ipw3945 project, as well
78c2ecf20Sopenharmony_ci * as portions of the ieee80211 subsystem header files.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Contact Information:
108c2ecf20Sopenharmony_ci *  Intel Linux Wireless <linuxwifi@intel.com>
118c2ecf20Sopenharmony_ci * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
128c2ecf20Sopenharmony_ci *****************************************************************************/
138c2ecf20Sopenharmony_ci#ifndef __iwl_tt_setting_h__
148c2ecf20Sopenharmony_ci#define __iwl_tt_setting_h__
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "commands.h"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define IWL_ABSOLUTE_ZERO		0
198c2ecf20Sopenharmony_ci#define IWL_ABSOLUTE_MAX		0xFFFFFFFF
208c2ecf20Sopenharmony_ci#define IWL_TT_INCREASE_MARGIN	5
218c2ecf20Sopenharmony_ci#define IWL_TT_CT_KILL_MARGIN	3
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cienum iwl_antenna_ok {
248c2ecf20Sopenharmony_ci	IWL_ANT_OK_NONE,
258c2ecf20Sopenharmony_ci	IWL_ANT_OK_SINGLE,
268c2ecf20Sopenharmony_ci	IWL_ANT_OK_MULTI,
278c2ecf20Sopenharmony_ci};
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* Thermal Throttling State Machine states */
308c2ecf20Sopenharmony_cienum  iwl_tt_state {
318c2ecf20Sopenharmony_ci	IWL_TI_0,	/* normal temperature, system power state */
328c2ecf20Sopenharmony_ci	IWL_TI_1,	/* high temperature detect, low power state */
338c2ecf20Sopenharmony_ci	IWL_TI_2,	/* higher temperature detected, lower power state */
348c2ecf20Sopenharmony_ci	IWL_TI_CT_KILL, /* critical temperature detected, lowest power state */
358c2ecf20Sopenharmony_ci	IWL_TI_STATE_MAX
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/**
398c2ecf20Sopenharmony_ci * struct iwl_tt_restriction - Thermal Throttling restriction table
408c2ecf20Sopenharmony_ci * @tx_stream: number of tx stream allowed
418c2ecf20Sopenharmony_ci * @is_ht: ht enable/disable
428c2ecf20Sopenharmony_ci * @rx_stream: number of rx stream allowed
438c2ecf20Sopenharmony_ci *
448c2ecf20Sopenharmony_ci * This table is used by advance thermal throttling management
458c2ecf20Sopenharmony_ci * based on the current thermal throttling state, and determines
468c2ecf20Sopenharmony_ci * the number of tx/rx streams and the status of HT operation.
478c2ecf20Sopenharmony_ci */
488c2ecf20Sopenharmony_cistruct iwl_tt_restriction {
498c2ecf20Sopenharmony_ci	enum iwl_antenna_ok tx_stream;
508c2ecf20Sopenharmony_ci	enum iwl_antenna_ok rx_stream;
518c2ecf20Sopenharmony_ci	bool is_ht;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/**
558c2ecf20Sopenharmony_ci * struct iwl_tt_trans - Thermal Throttling transaction table
568c2ecf20Sopenharmony_ci * @next_state:  next thermal throttling mode
578c2ecf20Sopenharmony_ci * @tt_low: low temperature threshold to change state
588c2ecf20Sopenharmony_ci * @tt_high: high temperature threshold to change state
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci * This is used by the advanced thermal throttling algorithm
618c2ecf20Sopenharmony_ci * to determine the next thermal state to go based on the
628c2ecf20Sopenharmony_ci * current temperature.
638c2ecf20Sopenharmony_ci */
648c2ecf20Sopenharmony_cistruct iwl_tt_trans {
658c2ecf20Sopenharmony_ci	enum iwl_tt_state next_state;
668c2ecf20Sopenharmony_ci	u32 tt_low;
678c2ecf20Sopenharmony_ci	u32 tt_high;
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/**
718c2ecf20Sopenharmony_ci * struct iwl_tt_mgnt - Thermal Throttling Management structure
728c2ecf20Sopenharmony_ci * @advanced_tt:    advanced thermal throttle required
738c2ecf20Sopenharmony_ci * @state:          current Thermal Throttling state
748c2ecf20Sopenharmony_ci * @tt_power_mode:  Thermal Throttling power mode index
758c2ecf20Sopenharmony_ci *		    being used to set power level when
768c2ecf20Sopenharmony_ci *		    when thermal throttling state != IWL_TI_0
778c2ecf20Sopenharmony_ci *		    the tt_power_mode should set to different
788c2ecf20Sopenharmony_ci *		    power mode based on the current tt state
798c2ecf20Sopenharmony_ci * @tt_previous_temperature: last measured temperature
808c2ecf20Sopenharmony_ci * @iwl_tt_restriction: ptr to restriction tbl, used by advance
818c2ecf20Sopenharmony_ci *		    thermal throttling to determine how many tx/rx streams
828c2ecf20Sopenharmony_ci *		    should be used in tt state; and can HT be enabled or not
838c2ecf20Sopenharmony_ci * @iwl_tt_trans: ptr to adv trans table, used by advance thermal throttling
848c2ecf20Sopenharmony_ci *		    state transaction
858c2ecf20Sopenharmony_ci * @ct_kill_toggle: used to toggle the CSR bit when checking uCode temperature
868c2ecf20Sopenharmony_ci * @ct_kill_exit_tm: timer to exit thermal kill
878c2ecf20Sopenharmony_ci */
888c2ecf20Sopenharmony_cistruct iwl_tt_mgmt {
898c2ecf20Sopenharmony_ci	enum iwl_tt_state state;
908c2ecf20Sopenharmony_ci	bool advanced_tt;
918c2ecf20Sopenharmony_ci	u8 tt_power_mode;
928c2ecf20Sopenharmony_ci	bool ct_kill_toggle;
938c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG
948c2ecf20Sopenharmony_ci	s32 tt_previous_temp;
958c2ecf20Sopenharmony_ci#endif
968c2ecf20Sopenharmony_ci	struct iwl_tt_restriction *restriction;
978c2ecf20Sopenharmony_ci	struct iwl_tt_trans *transaction;
988c2ecf20Sopenharmony_ci	struct timer_list ct_kill_exit_tm;
998c2ecf20Sopenharmony_ci	struct timer_list ct_kill_waiting_tm;
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciu8 iwl_tt_current_power_mode(struct iwl_priv *priv);
1038c2ecf20Sopenharmony_cibool iwl_tt_is_low_power_state(struct iwl_priv *priv);
1048c2ecf20Sopenharmony_cibool iwl_ht_enabled(struct iwl_priv *priv);
1058c2ecf20Sopenharmony_cienum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv);
1068c2ecf20Sopenharmony_cienum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv);
1078c2ecf20Sopenharmony_civoid iwl_tt_enter_ct_kill(struct iwl_priv *priv);
1088c2ecf20Sopenharmony_civoid iwl_tt_exit_ct_kill(struct iwl_priv *priv);
1098c2ecf20Sopenharmony_civoid iwl_tt_handler(struct iwl_priv *priv);
1108c2ecf20Sopenharmony_civoid iwl_tt_initialize(struct iwl_priv *priv);
1118c2ecf20Sopenharmony_civoid iwl_tt_exit(struct iwl_priv *priv);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci#endif  /* __iwl_tt_setting_h__ */
114