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