18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/******************************************************************************
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
58c2ecf20Sopenharmony_ci * Copyright(c) 2015 Intel Mobile Communications GmbH
68c2ecf20Sopenharmony_ci * Copyright(c) 2017 Intel Deutschland GmbH
78c2ecf20Sopenharmony_ci * Copyright(c) 2018 - 2019 Intel Corporation
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 *****************************************************************************/
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifndef __rs_h__
168c2ecf20Sopenharmony_ci#define __rs_h__
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <net/mac80211.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include "iwl-config.h"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include "fw-api.h"
238c2ecf20Sopenharmony_ci#include "iwl-trans.h"
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define RS_NAME "iwl-mvm-rs"
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistruct iwl_rs_rate_info {
288c2ecf20Sopenharmony_ci	u8 plcp;	  /* uCode API:  IWL_RATE_6M_PLCP, etc. */
298c2ecf20Sopenharmony_ci	u8 plcp_ht_siso;  /* uCode API:  IWL_RATE_SISO_6M_PLCP, etc. */
308c2ecf20Sopenharmony_ci	u8 plcp_ht_mimo2; /* uCode API:  IWL_RATE_MIMO2_6M_PLCP, etc. */
318c2ecf20Sopenharmony_ci	u8 plcp_vht_siso;
328c2ecf20Sopenharmony_ci	u8 plcp_vht_mimo2;
338c2ecf20Sopenharmony_ci	u8 prev_rs;      /* previous rate used in rs algo */
348c2ecf20Sopenharmony_ci	u8 next_rs;      /* next rate used in rs algo */
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define IWL_RATE_60M_PLCP 3
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cienum {
408c2ecf20Sopenharmony_ci	IWL_RATE_INVM_INDEX = IWL_RATE_COUNT,
418c2ecf20Sopenharmony_ci	IWL_RATE_INVALID = IWL_RATE_COUNT,
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define LINK_QUAL_MAX_RETRY_NUM 16
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cienum {
478c2ecf20Sopenharmony_ci	IWL_RATE_6M_INDEX_TABLE = 0,
488c2ecf20Sopenharmony_ci	IWL_RATE_9M_INDEX_TABLE,
498c2ecf20Sopenharmony_ci	IWL_RATE_12M_INDEX_TABLE,
508c2ecf20Sopenharmony_ci	IWL_RATE_18M_INDEX_TABLE,
518c2ecf20Sopenharmony_ci	IWL_RATE_24M_INDEX_TABLE,
528c2ecf20Sopenharmony_ci	IWL_RATE_36M_INDEX_TABLE,
538c2ecf20Sopenharmony_ci	IWL_RATE_48M_INDEX_TABLE,
548c2ecf20Sopenharmony_ci	IWL_RATE_54M_INDEX_TABLE,
558c2ecf20Sopenharmony_ci	IWL_RATE_1M_INDEX_TABLE,
568c2ecf20Sopenharmony_ci	IWL_RATE_2M_INDEX_TABLE,
578c2ecf20Sopenharmony_ci	IWL_RATE_5M_INDEX_TABLE,
588c2ecf20Sopenharmony_ci	IWL_RATE_11M_INDEX_TABLE,
598c2ecf20Sopenharmony_ci	IWL_RATE_INVM_INDEX_TABLE = IWL_RATE_INVM_INDEX - 1,
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci/* #define vs. enum to keep from defaulting to 'large integer' */
638c2ecf20Sopenharmony_ci#define	IWL_RATE_6M_MASK   (1 << IWL_RATE_6M_INDEX)
648c2ecf20Sopenharmony_ci#define	IWL_RATE_9M_MASK   (1 << IWL_RATE_9M_INDEX)
658c2ecf20Sopenharmony_ci#define	IWL_RATE_12M_MASK  (1 << IWL_RATE_12M_INDEX)
668c2ecf20Sopenharmony_ci#define	IWL_RATE_18M_MASK  (1 << IWL_RATE_18M_INDEX)
678c2ecf20Sopenharmony_ci#define	IWL_RATE_24M_MASK  (1 << IWL_RATE_24M_INDEX)
688c2ecf20Sopenharmony_ci#define	IWL_RATE_36M_MASK  (1 << IWL_RATE_36M_INDEX)
698c2ecf20Sopenharmony_ci#define	IWL_RATE_48M_MASK  (1 << IWL_RATE_48M_INDEX)
708c2ecf20Sopenharmony_ci#define	IWL_RATE_54M_MASK  (1 << IWL_RATE_54M_INDEX)
718c2ecf20Sopenharmony_ci#define IWL_RATE_60M_MASK  (1 << IWL_RATE_60M_INDEX)
728c2ecf20Sopenharmony_ci#define	IWL_RATE_1M_MASK   (1 << IWL_RATE_1M_INDEX)
738c2ecf20Sopenharmony_ci#define	IWL_RATE_2M_MASK   (1 << IWL_RATE_2M_INDEX)
748c2ecf20Sopenharmony_ci#define	IWL_RATE_5M_MASK   (1 << IWL_RATE_5M_INDEX)
758c2ecf20Sopenharmony_ci#define	IWL_RATE_11M_MASK  (1 << IWL_RATE_11M_INDEX)
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/* uCode API values for HT/VHT bit rates */
798c2ecf20Sopenharmony_cienum {
808c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_0_PLCP = 0,
818c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_1_PLCP = 1,
828c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_2_PLCP = 2,
838c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_3_PLCP = 3,
848c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_4_PLCP = 4,
858c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_5_PLCP = 5,
868c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_6_PLCP = 6,
878c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_7_PLCP = 7,
888c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_0_PLCP = 0x8,
898c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_1_PLCP = 0x9,
908c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_2_PLCP = 0xA,
918c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_3_PLCP = 0xB,
928c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_4_PLCP = 0xC,
938c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_5_PLCP = 0xD,
948c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_6_PLCP = 0xE,
958c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_7_PLCP = 0xF,
968c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_0_PLCP = 0,
978c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_1_PLCP = 1,
988c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_2_PLCP = 2,
998c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_3_PLCP = 3,
1008c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_4_PLCP = 4,
1018c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_5_PLCP = 5,
1028c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_6_PLCP = 6,
1038c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_7_PLCP = 7,
1048c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_8_PLCP = 8,
1058c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_9_PLCP = 9,
1068c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_0_PLCP = 0x10,
1078c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_1_PLCP = 0x11,
1088c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_2_PLCP = 0x12,
1098c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_3_PLCP = 0x13,
1108c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_4_PLCP = 0x14,
1118c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_5_PLCP = 0x15,
1128c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_6_PLCP = 0x16,
1138c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_7_PLCP = 0x17,
1148c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_8_PLCP = 0x18,
1158c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_9_PLCP = 0x19,
1168c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_INV_PLCP,
1178c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_INV_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
1188c2ecf20Sopenharmony_ci	IWL_RATE_VHT_SISO_MCS_INV_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
1198c2ecf20Sopenharmony_ci	IWL_RATE_VHT_MIMO2_MCS_INV_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
1208c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_8_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
1218c2ecf20Sopenharmony_ci	IWL_RATE_HT_SISO_MCS_9_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
1228c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_8_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
1238c2ecf20Sopenharmony_ci	IWL_RATE_HT_MIMO2_MCS_9_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define IWL_RATES_MASK ((1 << IWL_RATE_COUNT) - 1)
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define IWL_INVALID_VALUE    -1
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define TPC_MAX_REDUCTION		15
1318c2ecf20Sopenharmony_ci#define TPC_NO_REDUCTION		0
1328c2ecf20Sopenharmony_ci#define TPC_INVALID			0xff
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#define LINK_QUAL_AGG_FRAME_LIMIT_DEF	(63)
1358c2ecf20Sopenharmony_ci#define LINK_QUAL_AGG_FRAME_LIMIT_MAX	(63)
1368c2ecf20Sopenharmony_ci/*
1378c2ecf20Sopenharmony_ci * FIXME - various places in firmware API still use u8,
1388c2ecf20Sopenharmony_ci * e.g. LQ command and SCD config command.
1398c2ecf20Sopenharmony_ci * This should be 256 instead.
1408c2ecf20Sopenharmony_ci */
1418c2ecf20Sopenharmony_ci#define LINK_QUAL_AGG_FRAME_LIMIT_GEN2_DEF	(255)
1428c2ecf20Sopenharmony_ci#define LINK_QUAL_AGG_FRAME_LIMIT_GEN2_MAX	(255)
1438c2ecf20Sopenharmony_ci#define LINK_QUAL_AGG_FRAME_LIMIT_MIN	(0)
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci#define LQ_SIZE		2	/* 2 mode tables:  "Active" and "Search" */
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/* load per tid defines for A-MPDU activation */
1488c2ecf20Sopenharmony_ci#define IWL_AGG_TPT_THREHOLD	0
1498c2ecf20Sopenharmony_ci#define IWL_AGG_ALL_TID		0xff
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cienum iwl_table_type {
1528c2ecf20Sopenharmony_ci	LQ_NONE,
1538c2ecf20Sopenharmony_ci	LQ_LEGACY_G,	/* legacy types */
1548c2ecf20Sopenharmony_ci	LQ_LEGACY_A,
1558c2ecf20Sopenharmony_ci	LQ_HT_SISO,	/* HT types */
1568c2ecf20Sopenharmony_ci	LQ_HT_MIMO2,
1578c2ecf20Sopenharmony_ci	LQ_VHT_SISO,    /* VHT types */
1588c2ecf20Sopenharmony_ci	LQ_VHT_MIMO2,
1598c2ecf20Sopenharmony_ci	LQ_HE_SISO,     /* HE types */
1608c2ecf20Sopenharmony_ci	LQ_HE_MIMO2,
1618c2ecf20Sopenharmony_ci	LQ_MAX,
1628c2ecf20Sopenharmony_ci};
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cistruct rs_rate {
1658c2ecf20Sopenharmony_ci	int index;
1668c2ecf20Sopenharmony_ci	enum iwl_table_type type;
1678c2ecf20Sopenharmony_ci	u8 ant;
1688c2ecf20Sopenharmony_ci	u32 bw;
1698c2ecf20Sopenharmony_ci	bool sgi;
1708c2ecf20Sopenharmony_ci	bool ldpc;
1718c2ecf20Sopenharmony_ci	bool stbc;
1728c2ecf20Sopenharmony_ci	bool bfer;
1738c2ecf20Sopenharmony_ci};
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#define is_type_legacy(type) (((type) == LQ_LEGACY_G) || \
1778c2ecf20Sopenharmony_ci			      ((type) == LQ_LEGACY_A))
1788c2ecf20Sopenharmony_ci#define is_type_ht_siso(type) ((type) == LQ_HT_SISO)
1798c2ecf20Sopenharmony_ci#define is_type_ht_mimo2(type) ((type) == LQ_HT_MIMO2)
1808c2ecf20Sopenharmony_ci#define is_type_vht_siso(type) ((type) == LQ_VHT_SISO)
1818c2ecf20Sopenharmony_ci#define is_type_vht_mimo2(type) ((type) == LQ_VHT_MIMO2)
1828c2ecf20Sopenharmony_ci#define is_type_he_siso(type) ((type) == LQ_HE_SISO)
1838c2ecf20Sopenharmony_ci#define is_type_he_mimo2(type) ((type) == LQ_HE_MIMO2)
1848c2ecf20Sopenharmony_ci#define is_type_siso(type) (is_type_ht_siso(type) || is_type_vht_siso(type) || \
1858c2ecf20Sopenharmony_ci			    is_type_he_siso(type))
1868c2ecf20Sopenharmony_ci#define is_type_mimo2(type) (is_type_ht_mimo2(type) || \
1878c2ecf20Sopenharmony_ci			     is_type_vht_mimo2(type) || is_type_he_mimo2(type))
1888c2ecf20Sopenharmony_ci#define is_type_mimo(type) (is_type_mimo2(type))
1898c2ecf20Sopenharmony_ci#define is_type_ht(type) (is_type_ht_siso(type) || is_type_ht_mimo2(type))
1908c2ecf20Sopenharmony_ci#define is_type_vht(type) (is_type_vht_siso(type) || is_type_vht_mimo2(type))
1918c2ecf20Sopenharmony_ci#define is_type_he(type) (is_type_he_siso(type) || is_type_he_mimo2(type))
1928c2ecf20Sopenharmony_ci#define is_type_a_band(type) ((type) == LQ_LEGACY_A)
1938c2ecf20Sopenharmony_ci#define is_type_g_band(type) ((type) == LQ_LEGACY_G)
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci#define is_legacy(rate)       is_type_legacy((rate)->type)
1968c2ecf20Sopenharmony_ci#define is_ht_siso(rate)      is_type_ht_siso((rate)->type)
1978c2ecf20Sopenharmony_ci#define is_ht_mimo2(rate)     is_type_ht_mimo2((rate)->type)
1988c2ecf20Sopenharmony_ci#define is_vht_siso(rate)     is_type_vht_siso((rate)->type)
1998c2ecf20Sopenharmony_ci#define is_vht_mimo2(rate)    is_type_vht_mimo2((rate)->type)
2008c2ecf20Sopenharmony_ci#define is_siso(rate)         is_type_siso((rate)->type)
2018c2ecf20Sopenharmony_ci#define is_mimo2(rate)        is_type_mimo2((rate)->type)
2028c2ecf20Sopenharmony_ci#define is_mimo(rate)         is_type_mimo((rate)->type)
2038c2ecf20Sopenharmony_ci#define is_ht(rate)           is_type_ht((rate)->type)
2048c2ecf20Sopenharmony_ci#define is_vht(rate)          is_type_vht((rate)->type)
2058c2ecf20Sopenharmony_ci#define is_he(rate)           is_type_he((rate)->type)
2068c2ecf20Sopenharmony_ci#define is_a_band(rate)       is_type_a_band((rate)->type)
2078c2ecf20Sopenharmony_ci#define is_g_band(rate)       is_type_g_band((rate)->type)
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#define is_ht20(rate)         ((rate)->bw == RATE_MCS_CHAN_WIDTH_20)
2108c2ecf20Sopenharmony_ci#define is_ht40(rate)         ((rate)->bw == RATE_MCS_CHAN_WIDTH_40)
2118c2ecf20Sopenharmony_ci#define is_ht80(rate)         ((rate)->bw == RATE_MCS_CHAN_WIDTH_80)
2128c2ecf20Sopenharmony_ci#define is_ht160(rate)        ((rate)->bw == RATE_MCS_CHAN_WIDTH_160)
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci#define IWL_MAX_MCS_DISPLAY_SIZE	12
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_cistruct iwl_rate_mcs_info {
2178c2ecf20Sopenharmony_ci	char	mbps[IWL_MAX_MCS_DISPLAY_SIZE];
2188c2ecf20Sopenharmony_ci	char	mcs[IWL_MAX_MCS_DISPLAY_SIZE];
2198c2ecf20Sopenharmony_ci};
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/**
2228c2ecf20Sopenharmony_ci * struct iwl_lq_sta_rs_fw - rate and related statistics for RS in FW
2238c2ecf20Sopenharmony_ci * @last_rate_n_flags: last rate reported by FW
2248c2ecf20Sopenharmony_ci * @sta_id: the id of the station
2258c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_DEBUGFS
2268c2ecf20Sopenharmony_ci * @dbg_fixed_rate: for debug, use fixed rate if not 0
2278c2ecf20Sopenharmony_ci * @dbg_agg_frame_count_lim: for debug, max number of frames in A-MPDU
2288c2ecf20Sopenharmony_ci#endif
2298c2ecf20Sopenharmony_ci * @chains: bitmask of chains reported in %chain_signal
2308c2ecf20Sopenharmony_ci * @chain_signal: per chain signal strength
2318c2ecf20Sopenharmony_ci * @last_rssi: last rssi reported
2328c2ecf20Sopenharmony_ci * @drv: pointer back to the driver data
2338c2ecf20Sopenharmony_ci */
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_cistruct iwl_lq_sta_rs_fw {
2368c2ecf20Sopenharmony_ci	/* last tx rate_n_flags */
2378c2ecf20Sopenharmony_ci	u32 last_rate_n_flags;
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	/* persistent fields - initialized only once - keep last! */
2408c2ecf20Sopenharmony_ci	struct lq_sta_pers_rs_fw {
2418c2ecf20Sopenharmony_ci		u32 sta_id;
2428c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_DEBUGFS
2438c2ecf20Sopenharmony_ci		u32 dbg_fixed_rate;
2448c2ecf20Sopenharmony_ci		u16 dbg_agg_frame_count_lim;
2458c2ecf20Sopenharmony_ci#endif
2468c2ecf20Sopenharmony_ci		u8 chains;
2478c2ecf20Sopenharmony_ci		s8 chain_signal[IEEE80211_MAX_CHAINS];
2488c2ecf20Sopenharmony_ci		s8 last_rssi;
2498c2ecf20Sopenharmony_ci		struct iwl_mvm *drv;
2508c2ecf20Sopenharmony_ci	} pers;
2518c2ecf20Sopenharmony_ci};
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci/**
2548c2ecf20Sopenharmony_ci * struct iwl_rate_scale_data -- tx success history for one rate
2558c2ecf20Sopenharmony_ci */
2568c2ecf20Sopenharmony_cistruct iwl_rate_scale_data {
2578c2ecf20Sopenharmony_ci	u64 data;		/* bitmap of successful frames */
2588c2ecf20Sopenharmony_ci	s32 success_counter;	/* number of frames successful */
2598c2ecf20Sopenharmony_ci	s32 success_ratio;	/* per-cent * 128  */
2608c2ecf20Sopenharmony_ci	s32 counter;		/* number of frames attempted */
2618c2ecf20Sopenharmony_ci	s32 average_tpt;	/* success ratio * expected throughput */
2628c2ecf20Sopenharmony_ci};
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci/* Possible Tx columns
2658c2ecf20Sopenharmony_ci * Tx Column = a combo of legacy/siso/mimo x antenna x SGI
2668c2ecf20Sopenharmony_ci */
2678c2ecf20Sopenharmony_cienum rs_column {
2688c2ecf20Sopenharmony_ci	RS_COLUMN_LEGACY_ANT_A = 0,
2698c2ecf20Sopenharmony_ci	RS_COLUMN_LEGACY_ANT_B,
2708c2ecf20Sopenharmony_ci	RS_COLUMN_SISO_ANT_A,
2718c2ecf20Sopenharmony_ci	RS_COLUMN_SISO_ANT_B,
2728c2ecf20Sopenharmony_ci	RS_COLUMN_SISO_ANT_A_SGI,
2738c2ecf20Sopenharmony_ci	RS_COLUMN_SISO_ANT_B_SGI,
2748c2ecf20Sopenharmony_ci	RS_COLUMN_MIMO2,
2758c2ecf20Sopenharmony_ci	RS_COLUMN_MIMO2_SGI,
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	RS_COLUMN_LAST = RS_COLUMN_MIMO2_SGI,
2788c2ecf20Sopenharmony_ci	RS_COLUMN_COUNT = RS_COLUMN_LAST + 1,
2798c2ecf20Sopenharmony_ci	RS_COLUMN_INVALID,
2808c2ecf20Sopenharmony_ci};
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_cienum rs_ss_force_opt {
2838c2ecf20Sopenharmony_ci	RS_SS_FORCE_NONE = 0,
2848c2ecf20Sopenharmony_ci	RS_SS_FORCE_STBC,
2858c2ecf20Sopenharmony_ci	RS_SS_FORCE_BFER,
2868c2ecf20Sopenharmony_ci	RS_SS_FORCE_SISO,
2878c2ecf20Sopenharmony_ci};
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci/* Packet stats per rate */
2908c2ecf20Sopenharmony_cistruct rs_rate_stats {
2918c2ecf20Sopenharmony_ci	u64 success;
2928c2ecf20Sopenharmony_ci	u64 total;
2938c2ecf20Sopenharmony_ci};
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci/**
2968c2ecf20Sopenharmony_ci * struct iwl_scale_tbl_info -- tx params and success history for all rates
2978c2ecf20Sopenharmony_ci *
2988c2ecf20Sopenharmony_ci * There are two of these in struct iwl_lq_sta,
2998c2ecf20Sopenharmony_ci * one for "active", and one for "search".
3008c2ecf20Sopenharmony_ci */
3018c2ecf20Sopenharmony_cistruct iwl_scale_tbl_info {
3028c2ecf20Sopenharmony_ci	struct rs_rate rate;
3038c2ecf20Sopenharmony_ci	enum rs_column column;
3048c2ecf20Sopenharmony_ci	const u16 *expected_tpt;	/* throughput metrics; expected_tpt_G, etc. */
3058c2ecf20Sopenharmony_ci	struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
3068c2ecf20Sopenharmony_ci	/* per txpower-reduction history */
3078c2ecf20Sopenharmony_ci	struct iwl_rate_scale_data tpc_win[TPC_MAX_REDUCTION + 1];
3088c2ecf20Sopenharmony_ci};
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_cienum {
3118c2ecf20Sopenharmony_ci	RS_STATE_SEARCH_CYCLE_STARTED,
3128c2ecf20Sopenharmony_ci	RS_STATE_SEARCH_CYCLE_ENDED,
3138c2ecf20Sopenharmony_ci	RS_STATE_STAY_IN_COLUMN,
3148c2ecf20Sopenharmony_ci};
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci/**
3178c2ecf20Sopenharmony_ci * struct iwl_lq_sta -- driver's rate scaling private structure
3188c2ecf20Sopenharmony_ci *
3198c2ecf20Sopenharmony_ci * Pointer to this gets passed back and forth between driver and mac80211.
3208c2ecf20Sopenharmony_ci */
3218c2ecf20Sopenharmony_cistruct iwl_lq_sta {
3228c2ecf20Sopenharmony_ci	u8 active_tbl;		/* index of active table, range 0-1 */
3238c2ecf20Sopenharmony_ci	u8 rs_state;            /* RS_STATE_* */
3248c2ecf20Sopenharmony_ci	u8 search_better_tbl;	/* 1: currently trying alternate mode */
3258c2ecf20Sopenharmony_ci	s32 last_tpt;
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	/* The following determine when to search for a new mode */
3288c2ecf20Sopenharmony_ci	u32 table_count_limit;
3298c2ecf20Sopenharmony_ci	u32 max_failure_limit;	/* # failed frames before new search */
3308c2ecf20Sopenharmony_ci	u32 max_success_limit;	/* # successful frames before new search */
3318c2ecf20Sopenharmony_ci	u32 table_count;
3328c2ecf20Sopenharmony_ci	u32 total_failed;	/* total failed frames, any/all rates */
3338c2ecf20Sopenharmony_ci	u32 total_success;	/* total successful frames, any/all rates */
3348c2ecf20Sopenharmony_ci	u64 flush_timer;	/* time staying in mode before new search */
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	u32 visited_columns;    /* Bitmask marking which Tx columns were
3378c2ecf20Sopenharmony_ci				 * explored during a search cycle
3388c2ecf20Sopenharmony_ci				 */
3398c2ecf20Sopenharmony_ci	u64 last_tx;
3408c2ecf20Sopenharmony_ci	bool is_vht;
3418c2ecf20Sopenharmony_ci	bool ldpc;              /* LDPC Rx is supported by the STA */
3428c2ecf20Sopenharmony_ci	bool stbc_capable;      /* Tx STBC is supported by chip and Rx by STA */
3438c2ecf20Sopenharmony_ci	bool bfer_capable;      /* Remote supports beamformee and we BFer */
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	enum nl80211_band band;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	/* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
3488c2ecf20Sopenharmony_ci	unsigned long active_legacy_rate;
3498c2ecf20Sopenharmony_ci	unsigned long active_siso_rate;
3508c2ecf20Sopenharmony_ci	unsigned long active_mimo2_rate;
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	/* Highest rate per Tx mode */
3538c2ecf20Sopenharmony_ci	u8 max_legacy_rate_idx;
3548c2ecf20Sopenharmony_ci	u8 max_siso_rate_idx;
3558c2ecf20Sopenharmony_ci	u8 max_mimo2_rate_idx;
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	/* Optimal rate based on RSSI and STA caps.
3588c2ecf20Sopenharmony_ci	 * Used only to reflect link speed to userspace.
3598c2ecf20Sopenharmony_ci	 */
3608c2ecf20Sopenharmony_ci	struct rs_rate optimal_rate;
3618c2ecf20Sopenharmony_ci	unsigned long optimal_rate_mask;
3628c2ecf20Sopenharmony_ci	const struct rs_init_rate_info *optimal_rates;
3638c2ecf20Sopenharmony_ci	int optimal_nentries;
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci	u8 missed_rate_counter;
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	struct iwl_lq_cmd lq;
3688c2ecf20Sopenharmony_ci	struct iwl_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
3698c2ecf20Sopenharmony_ci	u8 tx_agg_tid_en;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	/* last tx rate_n_flags */
3728c2ecf20Sopenharmony_ci	u32 last_rate_n_flags;
3738c2ecf20Sopenharmony_ci	/* packets destined for this STA are aggregated */
3748c2ecf20Sopenharmony_ci	u8 is_agg;
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	/* tx power reduce for this sta */
3778c2ecf20Sopenharmony_ci	int tpc_reduce;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	/* persistent fields - initialized only once - keep last! */
3808c2ecf20Sopenharmony_ci	struct lq_sta_pers {
3818c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_DEBUGFS
3828c2ecf20Sopenharmony_ci		u32 dbg_fixed_rate;
3838c2ecf20Sopenharmony_ci		u8 dbg_fixed_txp_reduction;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci		/* force STBC/BFER/SISO for testing */
3868c2ecf20Sopenharmony_ci		enum rs_ss_force_opt ss_force;
3878c2ecf20Sopenharmony_ci#endif
3888c2ecf20Sopenharmony_ci		u8 chains;
3898c2ecf20Sopenharmony_ci		s8 chain_signal[IEEE80211_MAX_CHAINS];
3908c2ecf20Sopenharmony_ci		s8 last_rssi;
3918c2ecf20Sopenharmony_ci		struct rs_rate_stats tx_stats[RS_COLUMN_COUNT][IWL_RATE_COUNT];
3928c2ecf20Sopenharmony_ci		struct iwl_mvm *drv;
3938c2ecf20Sopenharmony_ci		spinlock_t lock; /* for races in reinit/update table */
3948c2ecf20Sopenharmony_ci	} pers;
3958c2ecf20Sopenharmony_ci};
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci/* ieee80211_tx_info's status_driver_data[0] is packed with lq color and txp
3988c2ecf20Sopenharmony_ci * Note, it's iwlmvm <-> mac80211 interface.
3998c2ecf20Sopenharmony_ci * bits 0-7: reduced tx power
4008c2ecf20Sopenharmony_ci * bits 8-10: LQ command's color
4018c2ecf20Sopenharmony_ci */
4028c2ecf20Sopenharmony_ci#define RS_DRV_DATA_TXP_MSK 0xff
4038c2ecf20Sopenharmony_ci#define RS_DRV_DATA_LQ_COLOR_POS 8
4048c2ecf20Sopenharmony_ci#define RS_DRV_DATA_LQ_COLOR_MSK (7 << RS_DRV_DATA_LQ_COLOR_POS)
4058c2ecf20Sopenharmony_ci#define RS_DRV_DATA_LQ_COLOR_GET(_f) (((_f) & RS_DRV_DATA_LQ_COLOR_MSK) >>\
4068c2ecf20Sopenharmony_ci				      RS_DRV_DATA_LQ_COLOR_POS)
4078c2ecf20Sopenharmony_ci#define RS_DRV_DATA_PACK(_c, _p) ((void *)(uintptr_t)\
4088c2ecf20Sopenharmony_ci				  (((uintptr_t)_p) |\
4098c2ecf20Sopenharmony_ci				   ((_c) << RS_DRV_DATA_LQ_COLOR_POS)))
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci/* Initialize station's rate scaling information after adding station */
4128c2ecf20Sopenharmony_civoid iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
4138c2ecf20Sopenharmony_ci			  enum nl80211_band band, bool init);
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci/* Notify RS about Tx status */
4168c2ecf20Sopenharmony_civoid iwl_mvm_rs_tx_status(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
4178c2ecf20Sopenharmony_ci			  int tid, struct ieee80211_tx_info *info, bool ndp);
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci/**
4208c2ecf20Sopenharmony_ci * iwl_rate_control_register - Register the rate control algorithm callbacks
4218c2ecf20Sopenharmony_ci *
4228c2ecf20Sopenharmony_ci * Since the rate control algorithm is hardware specific, there is no need
4238c2ecf20Sopenharmony_ci * or reason to place it as a stand alone module.  The driver can call
4248c2ecf20Sopenharmony_ci * iwl_rate_control_register in order to register the rate control callbacks
4258c2ecf20Sopenharmony_ci * with the mac80211 subsystem.  This should be performed prior to calling
4268c2ecf20Sopenharmony_ci * ieee80211_register_hw
4278c2ecf20Sopenharmony_ci *
4288c2ecf20Sopenharmony_ci */
4298c2ecf20Sopenharmony_ciint iwl_mvm_rate_control_register(void);
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/**
4328c2ecf20Sopenharmony_ci * iwl_rate_control_unregister - Unregister the rate control callbacks
4338c2ecf20Sopenharmony_ci *
4348c2ecf20Sopenharmony_ci * This should be called after calling ieee80211_unregister_hw, but before
4358c2ecf20Sopenharmony_ci * the driver is unloaded.
4368c2ecf20Sopenharmony_ci */
4378c2ecf20Sopenharmony_civoid iwl_mvm_rate_control_unregister(void);
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_cistruct iwl_mvm_sta;
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ciint iwl_mvm_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
4428c2ecf20Sopenharmony_ci			  bool enable);
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUGFS
4458c2ecf20Sopenharmony_civoid iwl_mvm_reset_frame_stats(struct iwl_mvm *mvm);
4468c2ecf20Sopenharmony_ci#endif
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_civoid iwl_mvm_rs_add_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta);
4498c2ecf20Sopenharmony_civoid rs_fw_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
4508c2ecf20Sopenharmony_ci		     enum nl80211_band band, bool update);
4518c2ecf20Sopenharmony_ciint rs_fw_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
4528c2ecf20Sopenharmony_ci			bool enable);
4538c2ecf20Sopenharmony_civoid iwl_mvm_tlc_update_notif(struct iwl_mvm *mvm,
4548c2ecf20Sopenharmony_ci			      struct iwl_rx_cmd_buffer *rxb);
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ciu16 rs_fw_get_max_amsdu_len(struct ieee80211_sta *sta);
4578c2ecf20Sopenharmony_ci#endif /* __rs__ */
458