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 *
68c2ecf20Sopenharmony_ci * Contact Information:
78c2ecf20Sopenharmony_ci *  Intel Linux Wireless <linuxwifi@intel.com>
88c2ecf20Sopenharmony_ci * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *****************************************************************************/
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef __iwl_agn_rs_h__
138c2ecf20Sopenharmony_ci#define __iwl_agn_rs_h__
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <net/mac80211.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "iwl-config.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include "commands.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct iwl_rate_info {
228c2ecf20Sopenharmony_ci	u8 plcp;	/* uCode API:  IWL_RATE_6M_PLCP, etc. */
238c2ecf20Sopenharmony_ci	u8 plcp_siso;	/* uCode API:  IWL_RATE_SISO_6M_PLCP, etc. */
248c2ecf20Sopenharmony_ci	u8 plcp_mimo2;	/* uCode API:  IWL_RATE_MIMO2_6M_PLCP, etc. */
258c2ecf20Sopenharmony_ci	u8 plcp_mimo3;  /* uCode API:  IWL_RATE_MIMO3_6M_PLCP, etc. */
268c2ecf20Sopenharmony_ci	u8 ieee;	/* MAC header:  IWL_RATE_6M_IEEE, etc. */
278c2ecf20Sopenharmony_ci	u8 prev_ieee;    /* previous rate in IEEE speeds */
288c2ecf20Sopenharmony_ci	u8 next_ieee;    /* next rate in IEEE speeds */
298c2ecf20Sopenharmony_ci	u8 prev_rs;      /* previous rate used in rs algo */
308c2ecf20Sopenharmony_ci	u8 next_rs;      /* next rate used in rs algo */
318c2ecf20Sopenharmony_ci	u8 prev_rs_tgg;  /* previous rate used in TGG rs algo */
328c2ecf20Sopenharmony_ci	u8 next_rs_tgg;  /* next rate used in TGG rs algo */
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/*
368c2ecf20Sopenharmony_ci * These serve as indexes into
378c2ecf20Sopenharmony_ci * struct iwl_rate_info iwl_rates[IWL_RATE_COUNT];
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_cienum {
408c2ecf20Sopenharmony_ci	IWL_RATE_1M_INDEX = 0,
418c2ecf20Sopenharmony_ci	IWL_RATE_2M_INDEX,
428c2ecf20Sopenharmony_ci	IWL_RATE_5M_INDEX,
438c2ecf20Sopenharmony_ci	IWL_RATE_11M_INDEX,
448c2ecf20Sopenharmony_ci	IWL_RATE_6M_INDEX,
458c2ecf20Sopenharmony_ci	IWL_RATE_9M_INDEX,
468c2ecf20Sopenharmony_ci	IWL_RATE_12M_INDEX,
478c2ecf20Sopenharmony_ci	IWL_RATE_18M_INDEX,
488c2ecf20Sopenharmony_ci	IWL_RATE_24M_INDEX,
498c2ecf20Sopenharmony_ci	IWL_RATE_36M_INDEX,
508c2ecf20Sopenharmony_ci	IWL_RATE_48M_INDEX,
518c2ecf20Sopenharmony_ci	IWL_RATE_54M_INDEX,
528c2ecf20Sopenharmony_ci	IWL_RATE_60M_INDEX,
538c2ecf20Sopenharmony_ci	IWL_RATE_COUNT, /*FIXME:RS:change to IWL_RATE_INDEX_COUNT,*/
548c2ecf20Sopenharmony_ci	IWL_RATE_COUNT_LEGACY = IWL_RATE_COUNT - 1,	/* Excluding 60M */
558c2ecf20Sopenharmony_ci	IWL_RATE_INVM_INDEX = IWL_RATE_COUNT,
568c2ecf20Sopenharmony_ci	IWL_RATE_INVALID = IWL_RATE_COUNT,
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cienum {
608c2ecf20Sopenharmony_ci	IWL_RATE_6M_INDEX_TABLE = 0,
618c2ecf20Sopenharmony_ci	IWL_RATE_9M_INDEX_TABLE,
628c2ecf20Sopenharmony_ci	IWL_RATE_12M_INDEX_TABLE,
638c2ecf20Sopenharmony_ci	IWL_RATE_18M_INDEX_TABLE,
648c2ecf20Sopenharmony_ci	IWL_RATE_24M_INDEX_TABLE,
658c2ecf20Sopenharmony_ci	IWL_RATE_36M_INDEX_TABLE,
668c2ecf20Sopenharmony_ci	IWL_RATE_48M_INDEX_TABLE,
678c2ecf20Sopenharmony_ci	IWL_RATE_54M_INDEX_TABLE,
688c2ecf20Sopenharmony_ci	IWL_RATE_1M_INDEX_TABLE,
698c2ecf20Sopenharmony_ci	IWL_RATE_2M_INDEX_TABLE,
708c2ecf20Sopenharmony_ci	IWL_RATE_5M_INDEX_TABLE,
718c2ecf20Sopenharmony_ci	IWL_RATE_11M_INDEX_TABLE,
728c2ecf20Sopenharmony_ci	IWL_RATE_INVM_INDEX_TABLE = IWL_RATE_INVM_INDEX - 1,
738c2ecf20Sopenharmony_ci};
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cienum {
768c2ecf20Sopenharmony_ci	IWL_FIRST_OFDM_RATE = IWL_RATE_6M_INDEX,
778c2ecf20Sopenharmony_ci	IWL_LAST_OFDM_RATE = IWL_RATE_60M_INDEX,
788c2ecf20Sopenharmony_ci	IWL_FIRST_CCK_RATE = IWL_RATE_1M_INDEX,
798c2ecf20Sopenharmony_ci	IWL_LAST_CCK_RATE = IWL_RATE_11M_INDEX,
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/* #define vs. enum to keep from defaulting to 'large integer' */
838c2ecf20Sopenharmony_ci#define	IWL_RATE_6M_MASK   (1 << IWL_RATE_6M_INDEX)
848c2ecf20Sopenharmony_ci#define	IWL_RATE_9M_MASK   (1 << IWL_RATE_9M_INDEX)
858c2ecf20Sopenharmony_ci#define	IWL_RATE_12M_MASK  (1 << IWL_RATE_12M_INDEX)
868c2ecf20Sopenharmony_ci#define	IWL_RATE_18M_MASK  (1 << IWL_RATE_18M_INDEX)
878c2ecf20Sopenharmony_ci#define	IWL_RATE_24M_MASK  (1 << IWL_RATE_24M_INDEX)
888c2ecf20Sopenharmony_ci#define	IWL_RATE_36M_MASK  (1 << IWL_RATE_36M_INDEX)
898c2ecf20Sopenharmony_ci#define	IWL_RATE_48M_MASK  (1 << IWL_RATE_48M_INDEX)
908c2ecf20Sopenharmony_ci#define	IWL_RATE_54M_MASK  (1 << IWL_RATE_54M_INDEX)
918c2ecf20Sopenharmony_ci#define IWL_RATE_60M_MASK  (1 << IWL_RATE_60M_INDEX)
928c2ecf20Sopenharmony_ci#define	IWL_RATE_1M_MASK   (1 << IWL_RATE_1M_INDEX)
938c2ecf20Sopenharmony_ci#define	IWL_RATE_2M_MASK   (1 << IWL_RATE_2M_INDEX)
948c2ecf20Sopenharmony_ci#define	IWL_RATE_5M_MASK   (1 << IWL_RATE_5M_INDEX)
958c2ecf20Sopenharmony_ci#define	IWL_RATE_11M_MASK  (1 << IWL_RATE_11M_INDEX)
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* uCode API values for legacy bit rates, both OFDM and CCK */
988c2ecf20Sopenharmony_cienum {
998c2ecf20Sopenharmony_ci	IWL_RATE_6M_PLCP  = 13,
1008c2ecf20Sopenharmony_ci	IWL_RATE_9M_PLCP  = 15,
1018c2ecf20Sopenharmony_ci	IWL_RATE_12M_PLCP = 5,
1028c2ecf20Sopenharmony_ci	IWL_RATE_18M_PLCP = 7,
1038c2ecf20Sopenharmony_ci	IWL_RATE_24M_PLCP = 9,
1048c2ecf20Sopenharmony_ci	IWL_RATE_36M_PLCP = 11,
1058c2ecf20Sopenharmony_ci	IWL_RATE_48M_PLCP = 1,
1068c2ecf20Sopenharmony_ci	IWL_RATE_54M_PLCP = 3,
1078c2ecf20Sopenharmony_ci	IWL_RATE_60M_PLCP = 3,/*FIXME:RS:should be removed*/
1088c2ecf20Sopenharmony_ci	IWL_RATE_1M_PLCP  = 10,
1098c2ecf20Sopenharmony_ci	IWL_RATE_2M_PLCP  = 20,
1108c2ecf20Sopenharmony_ci	IWL_RATE_5M_PLCP  = 55,
1118c2ecf20Sopenharmony_ci	IWL_RATE_11M_PLCP = 110,
1128c2ecf20Sopenharmony_ci	/*FIXME:RS:change to IWL_RATE_LEGACY_??M_PLCP */
1138c2ecf20Sopenharmony_ci	/*FIXME:RS:add IWL_RATE_LEGACY_INVM_PLCP = 0,*/
1148c2ecf20Sopenharmony_ci};
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/* uCode API values for OFDM high-throughput (HT) bit rates */
1178c2ecf20Sopenharmony_cienum {
1188c2ecf20Sopenharmony_ci	IWL_RATE_SISO_6M_PLCP = 0,
1198c2ecf20Sopenharmony_ci	IWL_RATE_SISO_12M_PLCP = 1,
1208c2ecf20Sopenharmony_ci	IWL_RATE_SISO_18M_PLCP = 2,
1218c2ecf20Sopenharmony_ci	IWL_RATE_SISO_24M_PLCP = 3,
1228c2ecf20Sopenharmony_ci	IWL_RATE_SISO_36M_PLCP = 4,
1238c2ecf20Sopenharmony_ci	IWL_RATE_SISO_48M_PLCP = 5,
1248c2ecf20Sopenharmony_ci	IWL_RATE_SISO_54M_PLCP = 6,
1258c2ecf20Sopenharmony_ci	IWL_RATE_SISO_60M_PLCP = 7,
1268c2ecf20Sopenharmony_ci	IWL_RATE_MIMO2_6M_PLCP  = 0x8,
1278c2ecf20Sopenharmony_ci	IWL_RATE_MIMO2_12M_PLCP = 0x9,
1288c2ecf20Sopenharmony_ci	IWL_RATE_MIMO2_18M_PLCP = 0xa,
1298c2ecf20Sopenharmony_ci	IWL_RATE_MIMO2_24M_PLCP = 0xb,
1308c2ecf20Sopenharmony_ci	IWL_RATE_MIMO2_36M_PLCP = 0xc,
1318c2ecf20Sopenharmony_ci	IWL_RATE_MIMO2_48M_PLCP = 0xd,
1328c2ecf20Sopenharmony_ci	IWL_RATE_MIMO2_54M_PLCP = 0xe,
1338c2ecf20Sopenharmony_ci	IWL_RATE_MIMO2_60M_PLCP = 0xf,
1348c2ecf20Sopenharmony_ci	IWL_RATE_MIMO3_6M_PLCP  = 0x10,
1358c2ecf20Sopenharmony_ci	IWL_RATE_MIMO3_12M_PLCP = 0x11,
1368c2ecf20Sopenharmony_ci	IWL_RATE_MIMO3_18M_PLCP = 0x12,
1378c2ecf20Sopenharmony_ci	IWL_RATE_MIMO3_24M_PLCP = 0x13,
1388c2ecf20Sopenharmony_ci	IWL_RATE_MIMO3_36M_PLCP = 0x14,
1398c2ecf20Sopenharmony_ci	IWL_RATE_MIMO3_48M_PLCP = 0x15,
1408c2ecf20Sopenharmony_ci	IWL_RATE_MIMO3_54M_PLCP = 0x16,
1418c2ecf20Sopenharmony_ci	IWL_RATE_MIMO3_60M_PLCP = 0x17,
1428c2ecf20Sopenharmony_ci	IWL_RATE_SISO_INVM_PLCP,
1438c2ecf20Sopenharmony_ci	IWL_RATE_MIMO2_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP,
1448c2ecf20Sopenharmony_ci	IWL_RATE_MIMO3_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP,
1458c2ecf20Sopenharmony_ci};
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/* MAC header values for bit rates */
1488c2ecf20Sopenharmony_cienum {
1498c2ecf20Sopenharmony_ci	IWL_RATE_6M_IEEE  = 12,
1508c2ecf20Sopenharmony_ci	IWL_RATE_9M_IEEE  = 18,
1518c2ecf20Sopenharmony_ci	IWL_RATE_12M_IEEE = 24,
1528c2ecf20Sopenharmony_ci	IWL_RATE_18M_IEEE = 36,
1538c2ecf20Sopenharmony_ci	IWL_RATE_24M_IEEE = 48,
1548c2ecf20Sopenharmony_ci	IWL_RATE_36M_IEEE = 72,
1558c2ecf20Sopenharmony_ci	IWL_RATE_48M_IEEE = 96,
1568c2ecf20Sopenharmony_ci	IWL_RATE_54M_IEEE = 108,
1578c2ecf20Sopenharmony_ci	IWL_RATE_60M_IEEE = 120,
1588c2ecf20Sopenharmony_ci	IWL_RATE_1M_IEEE  = 2,
1598c2ecf20Sopenharmony_ci	IWL_RATE_2M_IEEE  = 4,
1608c2ecf20Sopenharmony_ci	IWL_RATE_5M_IEEE  = 11,
1618c2ecf20Sopenharmony_ci	IWL_RATE_11M_IEEE = 22,
1628c2ecf20Sopenharmony_ci};
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci#define IWL_RATES_MASK ((1 << IWL_RATE_COUNT) - 1)
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#define IWL_INVALID_VALUE    -1
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci#define IWL_MIN_RSSI_VAL                 -100
1698c2ecf20Sopenharmony_ci#define IWL_MAX_RSSI_VAL                    0
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/* These values specify how many Tx frame attempts before
1728c2ecf20Sopenharmony_ci * searching for a new modulation mode */
1738c2ecf20Sopenharmony_ci#define IWL_LEGACY_FAILURE_LIMIT	160
1748c2ecf20Sopenharmony_ci#define IWL_LEGACY_SUCCESS_LIMIT	480
1758c2ecf20Sopenharmony_ci#define IWL_LEGACY_TABLE_COUNT		160
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#define IWL_NONE_LEGACY_FAILURE_LIMIT	400
1788c2ecf20Sopenharmony_ci#define IWL_NONE_LEGACY_SUCCESS_LIMIT	4500
1798c2ecf20Sopenharmony_ci#define IWL_NONE_LEGACY_TABLE_COUNT	1500
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/* Success ratio (ACKed / attempted tx frames) values (perfect is 128 * 100) */
1828c2ecf20Sopenharmony_ci#define IWL_RS_GOOD_RATIO		12800	/* 100% */
1838c2ecf20Sopenharmony_ci#define IWL_RATE_SCALE_SWITCH		10880	/*  85% */
1848c2ecf20Sopenharmony_ci#define IWL_RATE_HIGH_TH		10880	/*  85% */
1858c2ecf20Sopenharmony_ci#define IWL_RATE_INCREASE_TH		6400	/*  50% */
1868c2ecf20Sopenharmony_ci#define IWL_RATE_DECREASE_TH		1920	/*  15% */
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/* possible actions when in legacy mode */
1898c2ecf20Sopenharmony_ci#define IWL_LEGACY_SWITCH_ANTENNA1      0
1908c2ecf20Sopenharmony_ci#define IWL_LEGACY_SWITCH_ANTENNA2      1
1918c2ecf20Sopenharmony_ci#define IWL_LEGACY_SWITCH_SISO          2
1928c2ecf20Sopenharmony_ci#define IWL_LEGACY_SWITCH_MIMO2_AB      3
1938c2ecf20Sopenharmony_ci#define IWL_LEGACY_SWITCH_MIMO2_AC      4
1948c2ecf20Sopenharmony_ci#define IWL_LEGACY_SWITCH_MIMO2_BC      5
1958c2ecf20Sopenharmony_ci#define IWL_LEGACY_SWITCH_MIMO3_ABC     6
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci/* possible actions when in siso mode */
1988c2ecf20Sopenharmony_ci#define IWL_SISO_SWITCH_ANTENNA1        0
1998c2ecf20Sopenharmony_ci#define IWL_SISO_SWITCH_ANTENNA2        1
2008c2ecf20Sopenharmony_ci#define IWL_SISO_SWITCH_MIMO2_AB        2
2018c2ecf20Sopenharmony_ci#define IWL_SISO_SWITCH_MIMO2_AC        3
2028c2ecf20Sopenharmony_ci#define IWL_SISO_SWITCH_MIMO2_BC        4
2038c2ecf20Sopenharmony_ci#define IWL_SISO_SWITCH_GI              5
2048c2ecf20Sopenharmony_ci#define IWL_SISO_SWITCH_MIMO3_ABC       6
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci/* possible actions when in mimo mode */
2088c2ecf20Sopenharmony_ci#define IWL_MIMO2_SWITCH_ANTENNA1       0
2098c2ecf20Sopenharmony_ci#define IWL_MIMO2_SWITCH_ANTENNA2       1
2108c2ecf20Sopenharmony_ci#define IWL_MIMO2_SWITCH_SISO_A         2
2118c2ecf20Sopenharmony_ci#define IWL_MIMO2_SWITCH_SISO_B         3
2128c2ecf20Sopenharmony_ci#define IWL_MIMO2_SWITCH_SISO_C         4
2138c2ecf20Sopenharmony_ci#define IWL_MIMO2_SWITCH_GI             5
2148c2ecf20Sopenharmony_ci#define IWL_MIMO2_SWITCH_MIMO3_ABC      6
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci/* possible actions when in mimo3 mode */
2188c2ecf20Sopenharmony_ci#define IWL_MIMO3_SWITCH_ANTENNA1       0
2198c2ecf20Sopenharmony_ci#define IWL_MIMO3_SWITCH_ANTENNA2       1
2208c2ecf20Sopenharmony_ci#define IWL_MIMO3_SWITCH_SISO_A         2
2218c2ecf20Sopenharmony_ci#define IWL_MIMO3_SWITCH_SISO_B         3
2228c2ecf20Sopenharmony_ci#define IWL_MIMO3_SWITCH_SISO_C         4
2238c2ecf20Sopenharmony_ci#define IWL_MIMO3_SWITCH_MIMO2_AB       5
2248c2ecf20Sopenharmony_ci#define IWL_MIMO3_SWITCH_MIMO2_AC       6
2258c2ecf20Sopenharmony_ci#define IWL_MIMO3_SWITCH_MIMO2_BC       7
2268c2ecf20Sopenharmony_ci#define IWL_MIMO3_SWITCH_GI             8
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci#define IWL_MAX_11N_MIMO3_SEARCH IWL_MIMO3_SWITCH_GI
2308c2ecf20Sopenharmony_ci#define IWL_MAX_SEARCH IWL_MIMO2_SWITCH_MIMO3_ABC
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci/*FIXME:RS:add possible actions for MIMO3*/
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci#define IWL_ACTION_LIMIT		3	/* # possible actions */
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci#define LQ_SIZE		2	/* 2 mode tables:  "Active" and "Search" */
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci/* load per tid defines for A-MPDU activation */
2398c2ecf20Sopenharmony_ci#define IWL_AGG_TPT_THREHOLD	0
2408c2ecf20Sopenharmony_ci#define IWL_AGG_LOAD_THRESHOLD	10
2418c2ecf20Sopenharmony_ci#define IWL_AGG_ALL_TID		0xff
2428c2ecf20Sopenharmony_ci#define TID_QUEUE_CELL_SPACING	50	/*mS */
2438c2ecf20Sopenharmony_ci#define TID_QUEUE_MAX_SIZE	20
2448c2ecf20Sopenharmony_ci#define TID_ROUND_VALUE		5	/* mS */
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci#define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING)
2478c2ecf20Sopenharmony_ci#define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y))
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ciextern const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT];
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_cienum iwl_table_type {
2528c2ecf20Sopenharmony_ci	LQ_NONE,
2538c2ecf20Sopenharmony_ci	LQ_G,		/* legacy types */
2548c2ecf20Sopenharmony_ci	LQ_A,
2558c2ecf20Sopenharmony_ci	LQ_SISO,	/* high-throughput types */
2568c2ecf20Sopenharmony_ci	LQ_MIMO2,
2578c2ecf20Sopenharmony_ci	LQ_MIMO3,
2588c2ecf20Sopenharmony_ci	LQ_MAX,
2598c2ecf20Sopenharmony_ci};
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci#define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A))
2628c2ecf20Sopenharmony_ci#define is_siso(tbl) ((tbl) == LQ_SISO)
2638c2ecf20Sopenharmony_ci#define is_mimo2(tbl) ((tbl) == LQ_MIMO2)
2648c2ecf20Sopenharmony_ci#define is_mimo3(tbl) ((tbl) == LQ_MIMO3)
2658c2ecf20Sopenharmony_ci#define is_mimo(tbl) (is_mimo2(tbl) || is_mimo3(tbl))
2668c2ecf20Sopenharmony_ci#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl))
2678c2ecf20Sopenharmony_ci#define is_a_band(tbl) ((tbl) == LQ_A)
2688c2ecf20Sopenharmony_ci#define is_g_and(tbl) ((tbl) == LQ_G)
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci#define IWL_MAX_MCS_DISPLAY_SIZE	12
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_cistruct iwl_rate_mcs_info {
2738c2ecf20Sopenharmony_ci	char	mbps[IWL_MAX_MCS_DISPLAY_SIZE];
2748c2ecf20Sopenharmony_ci	char	mcs[IWL_MAX_MCS_DISPLAY_SIZE];
2758c2ecf20Sopenharmony_ci};
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci/**
2788c2ecf20Sopenharmony_ci * struct iwl_rate_scale_data -- tx success history for one rate
2798c2ecf20Sopenharmony_ci */
2808c2ecf20Sopenharmony_cistruct iwl_rate_scale_data {
2818c2ecf20Sopenharmony_ci	u64 data;		/* bitmap of successful frames */
2828c2ecf20Sopenharmony_ci	s32 success_counter;	/* number of frames successful */
2838c2ecf20Sopenharmony_ci	s32 success_ratio;	/* per-cent * 128  */
2848c2ecf20Sopenharmony_ci	s32 counter;		/* number of frames attempted */
2858c2ecf20Sopenharmony_ci	s32 average_tpt;	/* success ratio * expected throughput */
2868c2ecf20Sopenharmony_ci	unsigned long stamp;
2878c2ecf20Sopenharmony_ci};
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci/**
2908c2ecf20Sopenharmony_ci * struct iwl_scale_tbl_info -- tx params and success history for all rates
2918c2ecf20Sopenharmony_ci *
2928c2ecf20Sopenharmony_ci * There are two of these in struct iwl_lq_sta,
2938c2ecf20Sopenharmony_ci * one for "active", and one for "search".
2948c2ecf20Sopenharmony_ci */
2958c2ecf20Sopenharmony_cistruct iwl_scale_tbl_info {
2968c2ecf20Sopenharmony_ci	enum iwl_table_type lq_type;
2978c2ecf20Sopenharmony_ci	u8 ant_type;
2988c2ecf20Sopenharmony_ci	u8 is_SGI;	/* 1 = short guard interval */
2998c2ecf20Sopenharmony_ci	u8 is_ht40;	/* 1 = 40 MHz channel width */
3008c2ecf20Sopenharmony_ci	u8 is_dup;	/* 1 = duplicated data streams */
3018c2ecf20Sopenharmony_ci	u8 action;	/* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */
3028c2ecf20Sopenharmony_ci	u8 max_search;	/* maximun number of tables we can search */
3038c2ecf20Sopenharmony_ci	const u16 *expected_tpt;	/* throughput metrics; expected_tpt_G, etc. */
3048c2ecf20Sopenharmony_ci	u32 current_rate;  /* rate_n_flags, uCode API format */
3058c2ecf20Sopenharmony_ci	struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
3068c2ecf20Sopenharmony_ci};
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cistruct iwl_traffic_load {
3098c2ecf20Sopenharmony_ci	unsigned long time_stamp;	/* age of the oldest statistics */
3108c2ecf20Sopenharmony_ci	u32 packet_count[TID_QUEUE_MAX_SIZE];   /* packet count in this time
3118c2ecf20Sopenharmony_ci						 * slice */
3128c2ecf20Sopenharmony_ci	u32 total;			/* total num of packets during the
3138c2ecf20Sopenharmony_ci					 * last TID_MAX_TIME_DIFF */
3148c2ecf20Sopenharmony_ci	u8 queue_count;			/* number of queues that has
3158c2ecf20Sopenharmony_ci					 * been used since the last cleanup */
3168c2ecf20Sopenharmony_ci	u8 head;			/* start of the circular buffer */
3178c2ecf20Sopenharmony_ci};
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci/**
3208c2ecf20Sopenharmony_ci * struct iwl_lq_sta -- driver's rate scaling private structure
3218c2ecf20Sopenharmony_ci *
3228c2ecf20Sopenharmony_ci * Pointer to this gets passed back and forth between driver and mac80211.
3238c2ecf20Sopenharmony_ci */
3248c2ecf20Sopenharmony_cistruct iwl_lq_sta {
3258c2ecf20Sopenharmony_ci	u8 active_tbl;		/* index of active table, range 0-1 */
3268c2ecf20Sopenharmony_ci	u8 enable_counter;	/* indicates HT mode */
3278c2ecf20Sopenharmony_ci	u8 stay_in_tbl;		/* 1: disallow, 0: allow search for new mode */
3288c2ecf20Sopenharmony_ci	u8 search_better_tbl;	/* 1: currently trying alternate mode */
3298c2ecf20Sopenharmony_ci	s32 last_tpt;
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci	/* The following determine when to search for a new mode */
3328c2ecf20Sopenharmony_ci	u32 table_count_limit;
3338c2ecf20Sopenharmony_ci	u32 max_failure_limit;	/* # failed frames before new search */
3348c2ecf20Sopenharmony_ci	u32 max_success_limit;	/* # successful frames before new search */
3358c2ecf20Sopenharmony_ci	u32 table_count;
3368c2ecf20Sopenharmony_ci	u32 total_failed;	/* total failed frames, any/all rates */
3378c2ecf20Sopenharmony_ci	u32 total_success;	/* total successful frames, any/all rates */
3388c2ecf20Sopenharmony_ci	u64 flush_timer;	/* time staying in mode before new search */
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	u8 action_counter;	/* # mode-switch actions tried */
3418c2ecf20Sopenharmony_ci	u8 is_green;
3428c2ecf20Sopenharmony_ci	u8 is_dup;
3438c2ecf20Sopenharmony_ci	enum nl80211_band band;
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	/* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
3468c2ecf20Sopenharmony_ci	u32 supp_rates;
3478c2ecf20Sopenharmony_ci	u16 active_legacy_rate;
3488c2ecf20Sopenharmony_ci	u16 active_siso_rate;
3498c2ecf20Sopenharmony_ci	u16 active_mimo2_rate;
3508c2ecf20Sopenharmony_ci	u16 active_mimo3_rate;
3518c2ecf20Sopenharmony_ci	s8 max_rate_idx;     /* Max rate set by user */
3528c2ecf20Sopenharmony_ci	u8 missed_rate_counter;
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	struct iwl_link_quality_cmd lq;
3558c2ecf20Sopenharmony_ci	struct iwl_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
3568c2ecf20Sopenharmony_ci	struct iwl_traffic_load load[IWL_MAX_TID_COUNT];
3578c2ecf20Sopenharmony_ci	u8 tx_agg_tid_en;
3588c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_DEBUGFS
3598c2ecf20Sopenharmony_ci	u32 dbg_fixed_rate;
3608c2ecf20Sopenharmony_ci#endif
3618c2ecf20Sopenharmony_ci	struct iwl_priv *drv;
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	/* used to be in sta_info */
3648c2ecf20Sopenharmony_ci	int last_txrate_idx;
3658c2ecf20Sopenharmony_ci	/* last tx rate_n_flags */
3668c2ecf20Sopenharmony_ci	u32 last_rate_n_flags;
3678c2ecf20Sopenharmony_ci	/* packets destined for this STA are aggregated */
3688c2ecf20Sopenharmony_ci	u8 is_agg;
3698c2ecf20Sopenharmony_ci	/* BT traffic this sta was last updated in */
3708c2ecf20Sopenharmony_ci	u8 last_bt_traffic;
3718c2ecf20Sopenharmony_ci};
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_cistatic inline u8 first_antenna(u8 mask)
3748c2ecf20Sopenharmony_ci{
3758c2ecf20Sopenharmony_ci	if (mask & ANT_A)
3768c2ecf20Sopenharmony_ci		return ANT_A;
3778c2ecf20Sopenharmony_ci	if (mask & ANT_B)
3788c2ecf20Sopenharmony_ci		return ANT_B;
3798c2ecf20Sopenharmony_ci	return ANT_C;
3808c2ecf20Sopenharmony_ci}
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci/* Initialize station's rate scaling information after adding station */
3848c2ecf20Sopenharmony_civoid iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta,
3858c2ecf20Sopenharmony_ci		      u8 sta_id);
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci/**
3888c2ecf20Sopenharmony_ci * iwl_rate_control_register - Register the rate control algorithm callbacks
3898c2ecf20Sopenharmony_ci *
3908c2ecf20Sopenharmony_ci * Since the rate control algorithm is hardware specific, there is no need
3918c2ecf20Sopenharmony_ci * or reason to place it as a stand alone module.  The driver can call
3928c2ecf20Sopenharmony_ci * iwl_rate_control_register in order to register the rate control callbacks
3938c2ecf20Sopenharmony_ci * with the mac80211 subsystem.  This should be performed prior to calling
3948c2ecf20Sopenharmony_ci * ieee80211_register_hw
3958c2ecf20Sopenharmony_ci *
3968c2ecf20Sopenharmony_ci */
3978c2ecf20Sopenharmony_ciint iwlagn_rate_control_register(void);
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci/**
4008c2ecf20Sopenharmony_ci * iwl_rate_control_unregister - Unregister the rate control callbacks
4018c2ecf20Sopenharmony_ci *
4028c2ecf20Sopenharmony_ci * This should be called after calling ieee80211_unregister_hw, but before
4038c2ecf20Sopenharmony_ci * the driver is unloaded.
4048c2ecf20Sopenharmony_ci */
4058c2ecf20Sopenharmony_civoid iwlagn_rate_control_unregister(void);
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci#endif /* __iwl_agn__rs__ */
408