14273a380SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2e705c121SKalle Valo /****************************************************************************** 3e705c121SKalle Valo * 4e705c121SKalle Valo * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved. 5e705c121SKalle Valo * Copyright(c) 2015 Intel Mobile Communications GmbH 6ea42d1cbSGregory Greenman * Copyright(c) 2017 Intel Deutschland GmbH 70f8084cdSMordechay Goodstein * Copyright(c) 2018 - 2019 Intel Corporation 8e705c121SKalle Valo * 9e705c121SKalle Valo * Contact Information: 10cb2f8277SEmmanuel Grumbach * Intel Linux Wireless <linuxwifi@intel.com> 11e705c121SKalle Valo * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 12e705c121SKalle Valo * 13e705c121SKalle Valo *****************************************************************************/ 14e705c121SKalle Valo 15e705c121SKalle Valo #ifndef __rs_h__ 16e705c121SKalle Valo #define __rs_h__ 17e705c121SKalle Valo 18e705c121SKalle Valo #include <net/mac80211.h> 19e705c121SKalle Valo 20e705c121SKalle Valo #include "iwl-config.h" 21e705c121SKalle Valo 22e705c121SKalle Valo #include "fw-api.h" 23e705c121SKalle Valo #include "iwl-trans.h" 24e705c121SKalle Valo 259f66a397SGregory Greenman #define RS_NAME "iwl-mvm-rs" 269f66a397SGregory Greenman 27e705c121SKalle Valo struct iwl_rs_rate_info { 28e705c121SKalle Valo u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */ 29e705c121SKalle Valo u8 plcp_ht_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */ 30e705c121SKalle Valo u8 plcp_ht_mimo2; /* uCode API: IWL_RATE_MIMO2_6M_PLCP, etc. */ 31e705c121SKalle Valo u8 plcp_vht_siso; 32e705c121SKalle Valo u8 plcp_vht_mimo2; 33e705c121SKalle Valo u8 prev_rs; /* previous rate used in rs algo */ 34e705c121SKalle Valo u8 next_rs; /* next rate used in rs algo */ 35e705c121SKalle Valo }; 36e705c121SKalle Valo 37e705c121SKalle Valo #define IWL_RATE_60M_PLCP 3 38e705c121SKalle Valo 39e705c121SKalle Valo enum { 40e705c121SKalle Valo IWL_RATE_INVM_INDEX = IWL_RATE_COUNT, 41e705c121SKalle Valo IWL_RATE_INVALID = IWL_RATE_COUNT, 42e705c121SKalle Valo }; 43e705c121SKalle Valo 44e705c121SKalle Valo #define LINK_QUAL_MAX_RETRY_NUM 16 45e705c121SKalle Valo 46e705c121SKalle Valo enum { 47e705c121SKalle Valo IWL_RATE_6M_INDEX_TABLE = 0, 48e705c121SKalle Valo IWL_RATE_9M_INDEX_TABLE, 49e705c121SKalle Valo IWL_RATE_12M_INDEX_TABLE, 50e705c121SKalle Valo IWL_RATE_18M_INDEX_TABLE, 51e705c121SKalle Valo IWL_RATE_24M_INDEX_TABLE, 52e705c121SKalle Valo IWL_RATE_36M_INDEX_TABLE, 53e705c121SKalle Valo IWL_RATE_48M_INDEX_TABLE, 54e705c121SKalle Valo IWL_RATE_54M_INDEX_TABLE, 55e705c121SKalle Valo IWL_RATE_1M_INDEX_TABLE, 56e705c121SKalle Valo IWL_RATE_2M_INDEX_TABLE, 57e705c121SKalle Valo IWL_RATE_5M_INDEX_TABLE, 58e705c121SKalle Valo IWL_RATE_11M_INDEX_TABLE, 59e705c121SKalle Valo IWL_RATE_INVM_INDEX_TABLE = IWL_RATE_INVM_INDEX - 1, 60e705c121SKalle Valo }; 61e705c121SKalle Valo 62e705c121SKalle Valo /* #define vs. enum to keep from defaulting to 'large integer' */ 63e705c121SKalle Valo #define IWL_RATE_6M_MASK (1 << IWL_RATE_6M_INDEX) 64e705c121SKalle Valo #define IWL_RATE_9M_MASK (1 << IWL_RATE_9M_INDEX) 65e705c121SKalle Valo #define IWL_RATE_12M_MASK (1 << IWL_RATE_12M_INDEX) 66e705c121SKalle Valo #define IWL_RATE_18M_MASK (1 << IWL_RATE_18M_INDEX) 67e705c121SKalle Valo #define IWL_RATE_24M_MASK (1 << IWL_RATE_24M_INDEX) 68e705c121SKalle Valo #define IWL_RATE_36M_MASK (1 << IWL_RATE_36M_INDEX) 69e705c121SKalle Valo #define IWL_RATE_48M_MASK (1 << IWL_RATE_48M_INDEX) 70e705c121SKalle Valo #define IWL_RATE_54M_MASK (1 << IWL_RATE_54M_INDEX) 71e705c121SKalle Valo #define IWL_RATE_60M_MASK (1 << IWL_RATE_60M_INDEX) 72e705c121SKalle Valo #define IWL_RATE_1M_MASK (1 << IWL_RATE_1M_INDEX) 73e705c121SKalle Valo #define IWL_RATE_2M_MASK (1 << IWL_RATE_2M_INDEX) 74e705c121SKalle Valo #define IWL_RATE_5M_MASK (1 << IWL_RATE_5M_INDEX) 75e705c121SKalle Valo #define IWL_RATE_11M_MASK (1 << IWL_RATE_11M_INDEX) 76e705c121SKalle Valo 77e705c121SKalle Valo 78e705c121SKalle Valo /* uCode API values for HT/VHT bit rates */ 79e705c121SKalle Valo enum { 80e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_0_PLCP = 0, 81e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_1_PLCP = 1, 82e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_2_PLCP = 2, 83e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_3_PLCP = 3, 84e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_4_PLCP = 4, 85e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_5_PLCP = 5, 86e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_6_PLCP = 6, 87e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_7_PLCP = 7, 88e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_0_PLCP = 0x8, 89e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_1_PLCP = 0x9, 90e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_2_PLCP = 0xA, 91e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_3_PLCP = 0xB, 92e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_4_PLCP = 0xC, 93e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_5_PLCP = 0xD, 94e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_6_PLCP = 0xE, 95e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_7_PLCP = 0xF, 96e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_0_PLCP = 0, 97e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_1_PLCP = 1, 98e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_2_PLCP = 2, 99e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_3_PLCP = 3, 100e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_4_PLCP = 4, 101e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_5_PLCP = 5, 102e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_6_PLCP = 6, 103e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_7_PLCP = 7, 104e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_8_PLCP = 8, 105e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_9_PLCP = 9, 106e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_0_PLCP = 0x10, 107e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_1_PLCP = 0x11, 108e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_2_PLCP = 0x12, 109e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_3_PLCP = 0x13, 110e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_4_PLCP = 0x14, 111e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_5_PLCP = 0x15, 112e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_6_PLCP = 0x16, 113e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_7_PLCP = 0x17, 114e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_8_PLCP = 0x18, 115e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_9_PLCP = 0x19, 116e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_INV_PLCP, 117e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_INV_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP, 118e705c121SKalle Valo IWL_RATE_VHT_SISO_MCS_INV_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP, 119e705c121SKalle Valo IWL_RATE_VHT_MIMO2_MCS_INV_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP, 120e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_8_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP, 121e705c121SKalle Valo IWL_RATE_HT_SISO_MCS_9_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP, 122e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_8_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP, 123e705c121SKalle Valo IWL_RATE_HT_MIMO2_MCS_9_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP, 124e705c121SKalle Valo }; 125e705c121SKalle Valo 126e705c121SKalle Valo #define IWL_RATES_MASK ((1 << IWL_RATE_COUNT) - 1) 127e705c121SKalle Valo 128e705c121SKalle Valo #define IWL_INVALID_VALUE -1 129e705c121SKalle Valo 130e705c121SKalle Valo #define TPC_MAX_REDUCTION 15 131e705c121SKalle Valo #define TPC_NO_REDUCTION 0 132e705c121SKalle Valo #define TPC_INVALID 0xff 133e705c121SKalle Valo 134e705c121SKalle Valo #define LINK_QUAL_AGG_FRAME_LIMIT_DEF (63) 135e705c121SKalle Valo #define LINK_QUAL_AGG_FRAME_LIMIT_MAX (63) 136514c3069SLuca Coelho /* 137514c3069SLuca Coelho * FIXME - various places in firmware API still use u8, 138514c3069SLuca Coelho * e.g. LQ command and SCD config command. 139514c3069SLuca Coelho * This should be 256 instead. 140514c3069SLuca Coelho */ 141514c3069SLuca Coelho #define LINK_QUAL_AGG_FRAME_LIMIT_GEN2_DEF (255) 142514c3069SLuca Coelho #define LINK_QUAL_AGG_FRAME_LIMIT_GEN2_MAX (255) 143e705c121SKalle Valo #define LINK_QUAL_AGG_FRAME_LIMIT_MIN (0) 144e705c121SKalle Valo 145e705c121SKalle Valo #define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */ 146e705c121SKalle Valo 147e705c121SKalle Valo /* load per tid defines for A-MPDU activation */ 148e705c121SKalle Valo #define IWL_AGG_TPT_THREHOLD 0 149e705c121SKalle Valo #define IWL_AGG_ALL_TID 0xff 150e705c121SKalle Valo 151e705c121SKalle Valo enum iwl_table_type { 152e705c121SKalle Valo LQ_NONE, 153e705c121SKalle Valo LQ_LEGACY_G, /* legacy types */ 154e705c121SKalle Valo LQ_LEGACY_A, 155e705c121SKalle Valo LQ_HT_SISO, /* HT types */ 156e705c121SKalle Valo LQ_HT_MIMO2, 157e705c121SKalle Valo LQ_VHT_SISO, /* VHT types */ 158e705c121SKalle Valo LQ_VHT_MIMO2, 159514c3069SLuca Coelho LQ_HE_SISO, /* HE types */ 160514c3069SLuca Coelho LQ_HE_MIMO2, 161e705c121SKalle Valo LQ_MAX, 162e705c121SKalle Valo }; 163e705c121SKalle Valo 164e705c121SKalle Valo struct rs_rate { 165e705c121SKalle Valo int index; 166e705c121SKalle Valo enum iwl_table_type type; 167e705c121SKalle Valo u8 ant; 168e705c121SKalle Valo u32 bw; 169e705c121SKalle Valo bool sgi; 170e705c121SKalle Valo bool ldpc; 171e705c121SKalle Valo bool stbc; 172e705c121SKalle Valo bool bfer; 173e705c121SKalle Valo }; 174e705c121SKalle Valo 175e705c121SKalle Valo 176e705c121SKalle Valo #define is_type_legacy(type) (((type) == LQ_LEGACY_G) || \ 177e705c121SKalle Valo ((type) == LQ_LEGACY_A)) 178e705c121SKalle Valo #define is_type_ht_siso(type) ((type) == LQ_HT_SISO) 179e705c121SKalle Valo #define is_type_ht_mimo2(type) ((type) == LQ_HT_MIMO2) 180e705c121SKalle Valo #define is_type_vht_siso(type) ((type) == LQ_VHT_SISO) 181e705c121SKalle Valo #define is_type_vht_mimo2(type) ((type) == LQ_VHT_MIMO2) 182514c3069SLuca Coelho #define is_type_he_siso(type) ((type) == LQ_HE_SISO) 183514c3069SLuca Coelho #define is_type_he_mimo2(type) ((type) == LQ_HE_MIMO2) 184514c3069SLuca Coelho #define is_type_siso(type) (is_type_ht_siso(type) || is_type_vht_siso(type) || \ 185514c3069SLuca Coelho is_type_he_siso(type)) 186514c3069SLuca Coelho #define is_type_mimo2(type) (is_type_ht_mimo2(type) || \ 187514c3069SLuca Coelho is_type_vht_mimo2(type) || is_type_he_mimo2(type)) 188e705c121SKalle Valo #define is_type_mimo(type) (is_type_mimo2(type)) 189e705c121SKalle Valo #define is_type_ht(type) (is_type_ht_siso(type) || is_type_ht_mimo2(type)) 190e705c121SKalle Valo #define is_type_vht(type) (is_type_vht_siso(type) || is_type_vht_mimo2(type)) 191514c3069SLuca Coelho #define is_type_he(type) (is_type_he_siso(type) || is_type_he_mimo2(type)) 192e705c121SKalle Valo #define is_type_a_band(type) ((type) == LQ_LEGACY_A) 193e705c121SKalle Valo #define is_type_g_band(type) ((type) == LQ_LEGACY_G) 194e705c121SKalle Valo 195e705c121SKalle Valo #define is_legacy(rate) is_type_legacy((rate)->type) 196e705c121SKalle Valo #define is_ht_siso(rate) is_type_ht_siso((rate)->type) 197e705c121SKalle Valo #define is_ht_mimo2(rate) is_type_ht_mimo2((rate)->type) 198e705c121SKalle Valo #define is_vht_siso(rate) is_type_vht_siso((rate)->type) 199e705c121SKalle Valo #define is_vht_mimo2(rate) is_type_vht_mimo2((rate)->type) 200e705c121SKalle Valo #define is_siso(rate) is_type_siso((rate)->type) 201e705c121SKalle Valo #define is_mimo2(rate) is_type_mimo2((rate)->type) 202e705c121SKalle Valo #define is_mimo(rate) is_type_mimo((rate)->type) 203e705c121SKalle Valo #define is_ht(rate) is_type_ht((rate)->type) 204e705c121SKalle Valo #define is_vht(rate) is_type_vht((rate)->type) 205514c3069SLuca Coelho #define is_he(rate) is_type_he((rate)->type) 206e705c121SKalle Valo #define is_a_band(rate) is_type_a_band((rate)->type) 207e705c121SKalle Valo #define is_g_band(rate) is_type_g_band((rate)->type) 208e705c121SKalle Valo 209e705c121SKalle Valo #define is_ht20(rate) ((rate)->bw == RATE_MCS_CHAN_WIDTH_20) 210e705c121SKalle Valo #define is_ht40(rate) ((rate)->bw == RATE_MCS_CHAN_WIDTH_40) 211e705c121SKalle Valo #define is_ht80(rate) ((rate)->bw == RATE_MCS_CHAN_WIDTH_80) 212855f492fSGregory Greenman #define is_ht160(rate) ((rate)->bw == RATE_MCS_CHAN_WIDTH_160) 213e705c121SKalle Valo 214e705c121SKalle Valo #define IWL_MAX_MCS_DISPLAY_SIZE 12 215e705c121SKalle Valo 216e705c121SKalle Valo struct iwl_rate_mcs_info { 217e705c121SKalle Valo char mbps[IWL_MAX_MCS_DISPLAY_SIZE]; 218e705c121SKalle Valo char mcs[IWL_MAX_MCS_DISPLAY_SIZE]; 219e705c121SKalle Valo }; 220e705c121SKalle Valo 221e705c121SKalle Valo /** 222ecaf71deSGregory Greenman * struct iwl_lq_sta_rs_fw - rate and related statistics for RS in FW 223ecaf71deSGregory Greenman * @last_rate_n_flags: last rate reported by FW 224ecaf71deSGregory Greenman * @sta_id: the id of the station 225ecaf71deSGregory Greenman #ifdef CONFIG_MAC80211_DEBUGFS 226ecaf71deSGregory Greenman * @dbg_fixed_rate: for debug, use fixed rate if not 0 227ecaf71deSGregory Greenman * @dbg_agg_frame_count_lim: for debug, max number of frames in A-MPDU 228ecaf71deSGregory Greenman #endif 229ecaf71deSGregory Greenman * @chains: bitmask of chains reported in %chain_signal 230ecaf71deSGregory Greenman * @chain_signal: per chain signal strength 231ecaf71deSGregory Greenman * @last_rssi: last rssi reported 232ecaf71deSGregory Greenman * @drv: pointer back to the driver data 233ecaf71deSGregory Greenman */ 234ecaf71deSGregory Greenman 235ecaf71deSGregory Greenman struct iwl_lq_sta_rs_fw { 236ecaf71deSGregory Greenman /* last tx rate_n_flags */ 237ecaf71deSGregory Greenman u32 last_rate_n_flags; 238ecaf71deSGregory Greenman 239ecaf71deSGregory Greenman /* persistent fields - initialized only once - keep last! */ 240ecaf71deSGregory Greenman struct lq_sta_pers_rs_fw { 241ecaf71deSGregory Greenman u32 sta_id; 242ecaf71deSGregory Greenman #ifdef CONFIG_MAC80211_DEBUGFS 243ecaf71deSGregory Greenman u32 dbg_fixed_rate; 244ecaf71deSGregory Greenman u16 dbg_agg_frame_count_lim; 245ecaf71deSGregory Greenman #endif 246ecaf71deSGregory Greenman u8 chains; 247ecaf71deSGregory Greenman s8 chain_signal[IEEE80211_MAX_CHAINS]; 248ecaf71deSGregory Greenman s8 last_rssi; 249ecaf71deSGregory Greenman struct iwl_mvm *drv; 250ecaf71deSGregory Greenman } pers; 251ecaf71deSGregory Greenman }; 252ecaf71deSGregory Greenman 253ecaf71deSGregory Greenman /** 254e705c121SKalle Valo * struct iwl_rate_scale_data -- tx success history for one rate 255e705c121SKalle Valo */ 256e705c121SKalle Valo struct iwl_rate_scale_data { 257e705c121SKalle Valo u64 data; /* bitmap of successful frames */ 258e705c121SKalle Valo s32 success_counter; /* number of frames successful */ 259e705c121SKalle Valo s32 success_ratio; /* per-cent * 128 */ 260e705c121SKalle Valo s32 counter; /* number of frames attempted */ 261e705c121SKalle Valo s32 average_tpt; /* success ratio * expected throughput */ 262e705c121SKalle Valo }; 263e705c121SKalle Valo 264e705c121SKalle Valo /* Possible Tx columns 265e705c121SKalle Valo * Tx Column = a combo of legacy/siso/mimo x antenna x SGI 266e705c121SKalle Valo */ 267e705c121SKalle Valo enum rs_column { 268e705c121SKalle Valo RS_COLUMN_LEGACY_ANT_A = 0, 269e705c121SKalle Valo RS_COLUMN_LEGACY_ANT_B, 270e705c121SKalle Valo RS_COLUMN_SISO_ANT_A, 271e705c121SKalle Valo RS_COLUMN_SISO_ANT_B, 272e705c121SKalle Valo RS_COLUMN_SISO_ANT_A_SGI, 273e705c121SKalle Valo RS_COLUMN_SISO_ANT_B_SGI, 274e705c121SKalle Valo RS_COLUMN_MIMO2, 275e705c121SKalle Valo RS_COLUMN_MIMO2_SGI, 276e705c121SKalle Valo 277e705c121SKalle Valo RS_COLUMN_LAST = RS_COLUMN_MIMO2_SGI, 278e705c121SKalle Valo RS_COLUMN_COUNT = RS_COLUMN_LAST + 1, 279e705c121SKalle Valo RS_COLUMN_INVALID, 280e705c121SKalle Valo }; 281e705c121SKalle Valo 282e705c121SKalle Valo enum rs_ss_force_opt { 283e705c121SKalle Valo RS_SS_FORCE_NONE = 0, 284e705c121SKalle Valo RS_SS_FORCE_STBC, 285e705c121SKalle Valo RS_SS_FORCE_BFER, 286e705c121SKalle Valo RS_SS_FORCE_SISO, 287e705c121SKalle Valo }; 288e705c121SKalle Valo 289e705c121SKalle Valo /* Packet stats per rate */ 290e705c121SKalle Valo struct rs_rate_stats { 291e705c121SKalle Valo u64 success; 292e705c121SKalle Valo u64 total; 293e705c121SKalle Valo }; 294e705c121SKalle Valo 295e705c121SKalle Valo /** 296e705c121SKalle Valo * struct iwl_scale_tbl_info -- tx params and success history for all rates 297e705c121SKalle Valo * 298e705c121SKalle Valo * There are two of these in struct iwl_lq_sta, 299e705c121SKalle Valo * one for "active", and one for "search". 300e705c121SKalle Valo */ 301e705c121SKalle Valo struct iwl_scale_tbl_info { 302e705c121SKalle Valo struct rs_rate rate; 303e705c121SKalle Valo enum rs_column column; 304e705c121SKalle Valo const u16 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */ 305e705c121SKalle Valo struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */ 306e705c121SKalle Valo /* per txpower-reduction history */ 307e705c121SKalle Valo struct iwl_rate_scale_data tpc_win[TPC_MAX_REDUCTION + 1]; 308e705c121SKalle Valo }; 309e705c121SKalle Valo 310e705c121SKalle Valo enum { 311e705c121SKalle Valo RS_STATE_SEARCH_CYCLE_STARTED, 312e705c121SKalle Valo RS_STATE_SEARCH_CYCLE_ENDED, 313e705c121SKalle Valo RS_STATE_STAY_IN_COLUMN, 314e705c121SKalle Valo }; 315e705c121SKalle Valo 316e705c121SKalle Valo /** 317e705c121SKalle Valo * struct iwl_lq_sta -- driver's rate scaling private structure 318e705c121SKalle Valo * 319e705c121SKalle Valo * Pointer to this gets passed back and forth between driver and mac80211. 320e705c121SKalle Valo */ 321e705c121SKalle Valo struct iwl_lq_sta { 322e705c121SKalle Valo u8 active_tbl; /* index of active table, range 0-1 */ 323e705c121SKalle Valo u8 rs_state; /* RS_STATE_* */ 324e705c121SKalle Valo u8 search_better_tbl; /* 1: currently trying alternate mode */ 325e705c121SKalle Valo s32 last_tpt; 326e705c121SKalle Valo 327e705c121SKalle Valo /* The following determine when to search for a new mode */ 328e705c121SKalle Valo u32 table_count_limit; 329e705c121SKalle Valo u32 max_failure_limit; /* # failed frames before new search */ 330e705c121SKalle Valo u32 max_success_limit; /* # successful frames before new search */ 331e705c121SKalle Valo u32 table_count; 332e705c121SKalle Valo u32 total_failed; /* total failed frames, any/all rates */ 333e705c121SKalle Valo u32 total_success; /* total successful frames, any/all rates */ 334e705c121SKalle Valo u64 flush_timer; /* time staying in mode before new search */ 335e705c121SKalle Valo 336e705c121SKalle Valo u32 visited_columns; /* Bitmask marking which Tx columns were 337e705c121SKalle Valo * explored during a search cycle 338e705c121SKalle Valo */ 339e705c121SKalle Valo u64 last_tx; 340e705c121SKalle Valo bool is_vht; 341e705c121SKalle Valo bool ldpc; /* LDPC Rx is supported by the STA */ 342e705c121SKalle Valo bool stbc_capable; /* Tx STBC is supported by chip and Rx by STA */ 343e705c121SKalle Valo bool bfer_capable; /* Remote supports beamformee and we BFer */ 344e705c121SKalle Valo 34557fbcce3SJohannes Berg enum nl80211_band band; 346e705c121SKalle Valo 347e705c121SKalle Valo /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ 348e705c121SKalle Valo unsigned long active_legacy_rate; 349e705c121SKalle Valo unsigned long active_siso_rate; 350e705c121SKalle Valo unsigned long active_mimo2_rate; 351e705c121SKalle Valo 352e705c121SKalle Valo /* Highest rate per Tx mode */ 353e705c121SKalle Valo u8 max_legacy_rate_idx; 354e705c121SKalle Valo u8 max_siso_rate_idx; 355e705c121SKalle Valo u8 max_mimo2_rate_idx; 356e705c121SKalle Valo 357e705c121SKalle Valo /* Optimal rate based on RSSI and STA caps. 358e705c121SKalle Valo * Used only to reflect link speed to userspace. 359e705c121SKalle Valo */ 360e705c121SKalle Valo struct rs_rate optimal_rate; 361e705c121SKalle Valo unsigned long optimal_rate_mask; 362e705c121SKalle Valo const struct rs_init_rate_info *optimal_rates; 363e705c121SKalle Valo int optimal_nentries; 364e705c121SKalle Valo 365e705c121SKalle Valo u8 missed_rate_counter; 366e705c121SKalle Valo 367e705c121SKalle Valo struct iwl_lq_cmd lq; 368e705c121SKalle Valo struct iwl_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */ 369e705c121SKalle Valo u8 tx_agg_tid_en; 370e705c121SKalle Valo 371e705c121SKalle Valo /* last tx rate_n_flags */ 372e705c121SKalle Valo u32 last_rate_n_flags; 373e705c121SKalle Valo /* packets destined for this STA are aggregated */ 374e705c121SKalle Valo u8 is_agg; 375e705c121SKalle Valo 376e705c121SKalle Valo /* tx power reduce for this sta */ 377e705c121SKalle Valo int tpc_reduce; 378e705c121SKalle Valo 379e705c121SKalle Valo /* persistent fields - initialized only once - keep last! */ 380e705c121SKalle Valo struct lq_sta_pers { 381e705c121SKalle Valo #ifdef CONFIG_MAC80211_DEBUGFS 382e705c121SKalle Valo u32 dbg_fixed_rate; 383e705c121SKalle Valo u8 dbg_fixed_txp_reduction; 384e705c121SKalle Valo 385e705c121SKalle Valo /* force STBC/BFER/SISO for testing */ 386e705c121SKalle Valo enum rs_ss_force_opt ss_force; 387e705c121SKalle Valo #endif 388e705c121SKalle Valo u8 chains; 389e705c121SKalle Valo s8 chain_signal[IEEE80211_MAX_CHAINS]; 390e705c121SKalle Valo s8 last_rssi; 391e705c121SKalle Valo struct rs_rate_stats tx_stats[RS_COLUMN_COUNT][IWL_RATE_COUNT]; 392e705c121SKalle Valo struct iwl_mvm *drv; 393*f5d88fa3SGregory Greenman spinlock_t lock; /* for races in reinit/update table */ 394e705c121SKalle Valo } pers; 395e705c121SKalle Valo }; 396e705c121SKalle Valo 397ea42d1cbSGregory Greenman /* ieee80211_tx_info's status_driver_data[0] is packed with lq color and txp 398ea42d1cbSGregory Greenman * Note, it's iwlmvm <-> mac80211 interface. 399ea42d1cbSGregory Greenman * bits 0-7: reduced tx power 400ea42d1cbSGregory Greenman * bits 8-10: LQ command's color 401ea42d1cbSGregory Greenman */ 402ea42d1cbSGregory Greenman #define RS_DRV_DATA_TXP_MSK 0xff 403ea42d1cbSGregory Greenman #define RS_DRV_DATA_LQ_COLOR_POS 8 404ea42d1cbSGregory Greenman #define RS_DRV_DATA_LQ_COLOR_MSK (7 << RS_DRV_DATA_LQ_COLOR_POS) 405ea42d1cbSGregory Greenman #define RS_DRV_DATA_LQ_COLOR_GET(_f) (((_f) & RS_DRV_DATA_LQ_COLOR_MSK) >>\ 406ea42d1cbSGregory Greenman RS_DRV_DATA_LQ_COLOR_POS) 407ea42d1cbSGregory Greenman #define RS_DRV_DATA_PACK(_c, _p) ((void *)(uintptr_t)\ 408ea42d1cbSGregory Greenman (((uintptr_t)_p) |\ 409ea42d1cbSGregory Greenman ((_c) << RS_DRV_DATA_LQ_COLOR_POS))) 410ea42d1cbSGregory Greenman 411e705c121SKalle Valo /* Initialize station's rate scaling information after adding station */ 412e705c121SKalle Valo void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta, 4133baf7528SAvraham Stern enum nl80211_band band, bool init); 414e705c121SKalle Valo 415e705c121SKalle Valo /* Notify RS about Tx status */ 416e705c121SKalle Valo void iwl_mvm_rs_tx_status(struct iwl_mvm *mvm, struct ieee80211_sta *sta, 417ff7a68d0SMatti Gottlieb int tid, struct ieee80211_tx_info *info, bool ndp); 418e705c121SKalle Valo 419e705c121SKalle Valo /** 420e705c121SKalle Valo * iwl_rate_control_register - Register the rate control algorithm callbacks 421e705c121SKalle Valo * 422e705c121SKalle Valo * Since the rate control algorithm is hardware specific, there is no need 423e705c121SKalle Valo * or reason to place it as a stand alone module. The driver can call 424e705c121SKalle Valo * iwl_rate_control_register in order to register the rate control callbacks 425e705c121SKalle Valo * with the mac80211 subsystem. This should be performed prior to calling 426e705c121SKalle Valo * ieee80211_register_hw 427e705c121SKalle Valo * 428e705c121SKalle Valo */ 429e705c121SKalle Valo int iwl_mvm_rate_control_register(void); 430e705c121SKalle Valo 431e705c121SKalle Valo /** 432e705c121SKalle Valo * iwl_rate_control_unregister - Unregister the rate control callbacks 433e705c121SKalle Valo * 434e705c121SKalle Valo * This should be called after calling ieee80211_unregister_hw, but before 435e705c121SKalle Valo * the driver is unloaded. 436e705c121SKalle Valo */ 437e705c121SKalle Valo void iwl_mvm_rate_control_unregister(void); 438e705c121SKalle Valo 439e705c121SKalle Valo struct iwl_mvm_sta; 440e705c121SKalle Valo 441e705c121SKalle Valo int iwl_mvm_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, 442e705c121SKalle Valo bool enable); 4439f66a397SGregory Greenman 4449f66a397SGregory Greenman #ifdef CONFIG_IWLWIFI_DEBUGFS 4459f66a397SGregory Greenman void iwl_mvm_reset_frame_stats(struct iwl_mvm *mvm); 4469f66a397SGregory Greenman #endif 4479f66a397SGregory Greenman 4489f66a397SGregory Greenman #ifdef CONFIG_MAC80211_DEBUGFS 4499f66a397SGregory Greenman void rs_remove_sta_debugfs(void *mvm, void *mvm_sta); 4509f66a397SGregory Greenman #endif 4519f66a397SGregory Greenman 4529f66a397SGregory Greenman void iwl_mvm_rs_add_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta); 4539f66a397SGregory Greenman void rs_fw_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta, 4542859de76SNaftali Goldstein enum nl80211_band band, bool update); 455110b32f0SGregory Greenman int rs_fw_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, 456110b32f0SGregory Greenman bool enable); 45784226ca1SGregory Greenman void iwl_mvm_tlc_update_notif(struct iwl_mvm *mvm, 45884226ca1SGregory Greenman struct iwl_rx_cmd_buffer *rxb); 459e705c121SKalle Valo #endif /* __rs__ */ 460