162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/******************************************************************************
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Portions of this file are derived from the ipw3945 project, as well
762306a36Sopenharmony_ci * as portions of the ieee80211 subsystem header files.
862306a36Sopenharmony_ci *****************************************************************************/
962306a36Sopenharmony_ci#ifndef __iwl_tt_setting_h__
1062306a36Sopenharmony_ci#define __iwl_tt_setting_h__
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include "commands.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#define IWL_ABSOLUTE_ZERO		0
1562306a36Sopenharmony_ci#define IWL_ABSOLUTE_MAX		0xFFFFFFFF
1662306a36Sopenharmony_ci#define IWL_TT_INCREASE_MARGIN	5
1762306a36Sopenharmony_ci#define IWL_TT_CT_KILL_MARGIN	3
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cienum iwl_antenna_ok {
2062306a36Sopenharmony_ci	IWL_ANT_OK_NONE,
2162306a36Sopenharmony_ci	IWL_ANT_OK_SINGLE,
2262306a36Sopenharmony_ci	IWL_ANT_OK_MULTI,
2362306a36Sopenharmony_ci};
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/* Thermal Throttling State Machine states */
2662306a36Sopenharmony_cienum  iwl_tt_state {
2762306a36Sopenharmony_ci	IWL_TI_0,	/* normal temperature, system power state */
2862306a36Sopenharmony_ci	IWL_TI_1,	/* high temperature detect, low power state */
2962306a36Sopenharmony_ci	IWL_TI_2,	/* higher temperature detected, lower power state */
3062306a36Sopenharmony_ci	IWL_TI_CT_KILL, /* critical temperature detected, lowest power state */
3162306a36Sopenharmony_ci	IWL_TI_STATE_MAX
3262306a36Sopenharmony_ci};
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/**
3562306a36Sopenharmony_ci * struct iwl_tt_restriction - Thermal Throttling restriction table
3662306a36Sopenharmony_ci * @tx_stream: number of tx stream allowed
3762306a36Sopenharmony_ci * @is_ht: ht enable/disable
3862306a36Sopenharmony_ci * @rx_stream: number of rx stream allowed
3962306a36Sopenharmony_ci *
4062306a36Sopenharmony_ci * This table is used by advance thermal throttling management
4162306a36Sopenharmony_ci * based on the current thermal throttling state, and determines
4262306a36Sopenharmony_ci * the number of tx/rx streams and the status of HT operation.
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_cistruct iwl_tt_restriction {
4562306a36Sopenharmony_ci	enum iwl_antenna_ok tx_stream;
4662306a36Sopenharmony_ci	enum iwl_antenna_ok rx_stream;
4762306a36Sopenharmony_ci	bool is_ht;
4862306a36Sopenharmony_ci};
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/**
5162306a36Sopenharmony_ci * struct iwl_tt_trans - Thermal Throttling transaction table
5262306a36Sopenharmony_ci * @next_state:  next thermal throttling mode
5362306a36Sopenharmony_ci * @tt_low: low temperature threshold to change state
5462306a36Sopenharmony_ci * @tt_high: high temperature threshold to change state
5562306a36Sopenharmony_ci *
5662306a36Sopenharmony_ci * This is used by the advanced thermal throttling algorithm
5762306a36Sopenharmony_ci * to determine the next thermal state to go based on the
5862306a36Sopenharmony_ci * current temperature.
5962306a36Sopenharmony_ci */
6062306a36Sopenharmony_cistruct iwl_tt_trans {
6162306a36Sopenharmony_ci	enum iwl_tt_state next_state;
6262306a36Sopenharmony_ci	u32 tt_low;
6362306a36Sopenharmony_ci	u32 tt_high;
6462306a36Sopenharmony_ci};
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci/**
6762306a36Sopenharmony_ci * struct iwl_tt_mgnt - Thermal Throttling Management structure
6862306a36Sopenharmony_ci * @advanced_tt:    advanced thermal throttle required
6962306a36Sopenharmony_ci * @state:          current Thermal Throttling state
7062306a36Sopenharmony_ci * @tt_power_mode:  Thermal Throttling power mode index
7162306a36Sopenharmony_ci *		    being used to set power level when
7262306a36Sopenharmony_ci *		    when thermal throttling state != IWL_TI_0
7362306a36Sopenharmony_ci *		    the tt_power_mode should set to different
7462306a36Sopenharmony_ci *		    power mode based on the current tt state
7562306a36Sopenharmony_ci * @tt_previous_temperature: last measured temperature
7662306a36Sopenharmony_ci * @iwl_tt_restriction: ptr to restriction tbl, used by advance
7762306a36Sopenharmony_ci *		    thermal throttling to determine how many tx/rx streams
7862306a36Sopenharmony_ci *		    should be used in tt state; and can HT be enabled or not
7962306a36Sopenharmony_ci * @iwl_tt_trans: ptr to adv trans table, used by advance thermal throttling
8062306a36Sopenharmony_ci *		    state transaction
8162306a36Sopenharmony_ci * @ct_kill_toggle: used to toggle the CSR bit when checking uCode temperature
8262306a36Sopenharmony_ci * @ct_kill_exit_tm: timer to exit thermal kill
8362306a36Sopenharmony_ci */
8462306a36Sopenharmony_cistruct iwl_tt_mgmt {
8562306a36Sopenharmony_ci	enum iwl_tt_state state;
8662306a36Sopenharmony_ci	bool advanced_tt;
8762306a36Sopenharmony_ci	u8 tt_power_mode;
8862306a36Sopenharmony_ci	bool ct_kill_toggle;
8962306a36Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG
9062306a36Sopenharmony_ci	s32 tt_previous_temp;
9162306a36Sopenharmony_ci#endif
9262306a36Sopenharmony_ci	struct iwl_tt_restriction *restriction;
9362306a36Sopenharmony_ci	struct iwl_tt_trans *transaction;
9462306a36Sopenharmony_ci	struct timer_list ct_kill_exit_tm;
9562306a36Sopenharmony_ci	struct timer_list ct_kill_waiting_tm;
9662306a36Sopenharmony_ci};
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ciu8 iwl_tt_current_power_mode(struct iwl_priv *priv);
9962306a36Sopenharmony_cibool iwl_tt_is_low_power_state(struct iwl_priv *priv);
10062306a36Sopenharmony_cibool iwl_ht_enabled(struct iwl_priv *priv);
10162306a36Sopenharmony_cienum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv);
10262306a36Sopenharmony_cienum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv);
10362306a36Sopenharmony_civoid iwl_tt_enter_ct_kill(struct iwl_priv *priv);
10462306a36Sopenharmony_civoid iwl_tt_exit_ct_kill(struct iwl_priv *priv);
10562306a36Sopenharmony_civoid iwl_tt_handler(struct iwl_priv *priv);
10662306a36Sopenharmony_civoid iwl_tt_initialize(struct iwl_priv *priv);
10762306a36Sopenharmony_civoid iwl_tt_exit(struct iwl_priv *priv);
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci#endif  /* __iwl_tt_setting_h__ */
110