Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2013 Intel Corporation. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | *****************************************************************************/ |
| 26 | |
| 27 | #ifndef __rs_h__ |
| 28 | #define __rs_h__ |
| 29 | |
| 30 | #include <net/mac80211.h> |
| 31 | |
| 32 | #include "iwl-config.h" |
| 33 | |
| 34 | #include "fw-api.h" |
| 35 | #include "iwl-trans.h" |
| 36 | |
| 37 | struct iwl_rs_rate_info { |
| 38 | u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */ |
| 39 | u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */ |
| 40 | u8 plcp_mimo2; /* uCode API: IWL_RATE_MIMO2_6M_PLCP, etc. */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 41 | u8 prev_rs; /* previous rate used in rs algo */ |
| 42 | u8 next_rs; /* next rate used in rs algo */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | #define IWL_RATE_60M_PLCP 3 |
| 46 | |
| 47 | enum { |
| 48 | IWL_RATE_INVM_INDEX = IWL_RATE_COUNT, |
| 49 | IWL_RATE_INVALID = IWL_RATE_COUNT, |
| 50 | }; |
| 51 | |
| 52 | #define LINK_QUAL_MAX_RETRY_NUM 16 |
| 53 | |
| 54 | enum { |
| 55 | IWL_RATE_6M_INDEX_TABLE = 0, |
| 56 | IWL_RATE_9M_INDEX_TABLE, |
| 57 | IWL_RATE_12M_INDEX_TABLE, |
| 58 | IWL_RATE_18M_INDEX_TABLE, |
| 59 | IWL_RATE_24M_INDEX_TABLE, |
| 60 | IWL_RATE_36M_INDEX_TABLE, |
| 61 | IWL_RATE_48M_INDEX_TABLE, |
| 62 | IWL_RATE_54M_INDEX_TABLE, |
| 63 | IWL_RATE_1M_INDEX_TABLE, |
| 64 | IWL_RATE_2M_INDEX_TABLE, |
| 65 | IWL_RATE_5M_INDEX_TABLE, |
| 66 | IWL_RATE_11M_INDEX_TABLE, |
| 67 | IWL_RATE_INVM_INDEX_TABLE = IWL_RATE_INVM_INDEX - 1, |
| 68 | }; |
| 69 | |
| 70 | /* #define vs. enum to keep from defaulting to 'large integer' */ |
| 71 | #define IWL_RATE_6M_MASK (1 << IWL_RATE_6M_INDEX) |
| 72 | #define IWL_RATE_9M_MASK (1 << IWL_RATE_9M_INDEX) |
| 73 | #define IWL_RATE_12M_MASK (1 << IWL_RATE_12M_INDEX) |
| 74 | #define IWL_RATE_18M_MASK (1 << IWL_RATE_18M_INDEX) |
| 75 | #define IWL_RATE_24M_MASK (1 << IWL_RATE_24M_INDEX) |
| 76 | #define IWL_RATE_36M_MASK (1 << IWL_RATE_36M_INDEX) |
| 77 | #define IWL_RATE_48M_MASK (1 << IWL_RATE_48M_INDEX) |
| 78 | #define IWL_RATE_54M_MASK (1 << IWL_RATE_54M_INDEX) |
| 79 | #define IWL_RATE_60M_MASK (1 << IWL_RATE_60M_INDEX) |
| 80 | #define IWL_RATE_1M_MASK (1 << IWL_RATE_1M_INDEX) |
| 81 | #define IWL_RATE_2M_MASK (1 << IWL_RATE_2M_INDEX) |
| 82 | #define IWL_RATE_5M_MASK (1 << IWL_RATE_5M_INDEX) |
| 83 | #define IWL_RATE_11M_MASK (1 << IWL_RATE_11M_INDEX) |
| 84 | |
| 85 | |
| 86 | /* uCode API values for OFDM high-throughput (HT) bit rates */ |
| 87 | enum { |
| 88 | IWL_RATE_SISO_6M_PLCP = 0, |
| 89 | IWL_RATE_SISO_12M_PLCP = 1, |
| 90 | IWL_RATE_SISO_18M_PLCP = 2, |
| 91 | IWL_RATE_SISO_24M_PLCP = 3, |
| 92 | IWL_RATE_SISO_36M_PLCP = 4, |
| 93 | IWL_RATE_SISO_48M_PLCP = 5, |
| 94 | IWL_RATE_SISO_54M_PLCP = 6, |
| 95 | IWL_RATE_SISO_60M_PLCP = 7, |
| 96 | IWL_RATE_MIMO2_6M_PLCP = 0x8, |
| 97 | IWL_RATE_MIMO2_12M_PLCP = 0x9, |
| 98 | IWL_RATE_MIMO2_18M_PLCP = 0xa, |
| 99 | IWL_RATE_MIMO2_24M_PLCP = 0xb, |
| 100 | IWL_RATE_MIMO2_36M_PLCP = 0xc, |
| 101 | IWL_RATE_MIMO2_48M_PLCP = 0xd, |
| 102 | IWL_RATE_MIMO2_54M_PLCP = 0xe, |
| 103 | IWL_RATE_MIMO2_60M_PLCP = 0xf, |
| 104 | IWL_RATE_MIMO3_6M_PLCP = 0x10, |
| 105 | IWL_RATE_MIMO3_12M_PLCP = 0x11, |
| 106 | IWL_RATE_MIMO3_18M_PLCP = 0x12, |
| 107 | IWL_RATE_MIMO3_24M_PLCP = 0x13, |
| 108 | IWL_RATE_MIMO3_36M_PLCP = 0x14, |
| 109 | IWL_RATE_MIMO3_48M_PLCP = 0x15, |
| 110 | IWL_RATE_MIMO3_54M_PLCP = 0x16, |
| 111 | IWL_RATE_MIMO3_60M_PLCP = 0x17, |
| 112 | IWL_RATE_SISO_INVM_PLCP, |
| 113 | IWL_RATE_MIMO2_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP, |
| 114 | IWL_RATE_MIMO3_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP, |
| 115 | }; |
| 116 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 117 | #define IWL_RATES_MASK ((1 << IWL_RATE_COUNT) - 1) |
| 118 | |
| 119 | #define IWL_INVALID_VALUE -1 |
| 120 | |
| 121 | #define IWL_MIN_RSSI_VAL -100 |
| 122 | #define IWL_MAX_RSSI_VAL 0 |
| 123 | |
| 124 | /* These values specify how many Tx frame attempts before |
| 125 | * searching for a new modulation mode */ |
| 126 | #define IWL_LEGACY_FAILURE_LIMIT 160 |
| 127 | #define IWL_LEGACY_SUCCESS_LIMIT 480 |
| 128 | #define IWL_LEGACY_TABLE_COUNT 160 |
| 129 | |
| 130 | #define IWL_NONE_LEGACY_FAILURE_LIMIT 400 |
| 131 | #define IWL_NONE_LEGACY_SUCCESS_LIMIT 4500 |
| 132 | #define IWL_NONE_LEGACY_TABLE_COUNT 1500 |
| 133 | |
| 134 | /* Success ratio (ACKed / attempted tx frames) values (perfect is 128 * 100) */ |
| 135 | #define IWL_RS_GOOD_RATIO 12800 /* 100% */ |
| 136 | #define IWL_RATE_SCALE_SWITCH 10880 /* 85% */ |
| 137 | #define IWL_RATE_HIGH_TH 10880 /* 85% */ |
| 138 | #define IWL_RATE_INCREASE_TH 6400 /* 50% */ |
| 139 | #define IWL_RATE_DECREASE_TH 1920 /* 15% */ |
| 140 | |
| 141 | /* possible actions when in legacy mode */ |
| 142 | #define IWL_LEGACY_SWITCH_ANTENNA1 0 |
| 143 | #define IWL_LEGACY_SWITCH_ANTENNA2 1 |
| 144 | #define IWL_LEGACY_SWITCH_SISO 2 |
Eyal Shapira | d972ab3 | 2013-07-28 23:02:45 +0000 | [diff] [blame] | 145 | #define IWL_LEGACY_SWITCH_MIMO2 3 |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 146 | |
| 147 | /* possible actions when in siso mode */ |
| 148 | #define IWL_SISO_SWITCH_ANTENNA1 0 |
| 149 | #define IWL_SISO_SWITCH_ANTENNA2 1 |
Eyal Shapira | d972ab3 | 2013-07-28 23:02:45 +0000 | [diff] [blame] | 150 | #define IWL_SISO_SWITCH_MIMO2 2 |
| 151 | #define IWL_SISO_SWITCH_GI 3 |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 152 | |
| 153 | /* possible actions when in mimo mode */ |
| 154 | #define IWL_MIMO2_SWITCH_ANTENNA1 0 |
| 155 | #define IWL_MIMO2_SWITCH_ANTENNA2 1 |
| 156 | #define IWL_MIMO2_SWITCH_SISO_A 2 |
| 157 | #define IWL_MIMO2_SWITCH_SISO_B 3 |
Eyal Shapira | d972ab3 | 2013-07-28 23:02:45 +0000 | [diff] [blame] | 158 | #define IWL_MIMO2_SWITCH_GI 4 |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 159 | |
Eyal Shapira | d972ab3 | 2013-07-28 23:02:45 +0000 | [diff] [blame] | 160 | #define IWL_MAX_SEARCH IWL_MIMO2_SWITCH_GI |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 161 | |
| 162 | #define IWL_ACTION_LIMIT 3 /* # possible actions */ |
| 163 | |
| 164 | #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) /* 4 milliseconds */ |
| 165 | #define LINK_QUAL_AGG_TIME_LIMIT_MAX (8000) |
| 166 | #define LINK_QUAL_AGG_TIME_LIMIT_MIN (100) |
| 167 | |
| 168 | #define LINK_QUAL_AGG_DISABLE_START_DEF (3) |
| 169 | #define LINK_QUAL_AGG_DISABLE_START_MAX (255) |
| 170 | #define LINK_QUAL_AGG_DISABLE_START_MIN (0) |
| 171 | |
| 172 | #define LINK_QUAL_AGG_FRAME_LIMIT_DEF (63) |
| 173 | #define LINK_QUAL_AGG_FRAME_LIMIT_MAX (63) |
| 174 | #define LINK_QUAL_AGG_FRAME_LIMIT_MIN (0) |
| 175 | |
| 176 | #define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */ |
| 177 | |
| 178 | /* load per tid defines for A-MPDU activation */ |
| 179 | #define IWL_AGG_TPT_THREHOLD 0 |
| 180 | #define IWL_AGG_LOAD_THRESHOLD 10 |
| 181 | #define IWL_AGG_ALL_TID 0xff |
| 182 | #define TID_QUEUE_CELL_SPACING 50 /*mS */ |
| 183 | #define TID_QUEUE_MAX_SIZE 20 |
| 184 | #define TID_ROUND_VALUE 5 /* mS */ |
| 185 | |
| 186 | #define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING) |
| 187 | #define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y)) |
| 188 | |
| 189 | enum iwl_table_type { |
| 190 | LQ_NONE, |
| 191 | LQ_G, /* legacy types */ |
| 192 | LQ_A, |
| 193 | LQ_SISO, /* high-throughput types */ |
| 194 | LQ_MIMO2, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 195 | LQ_MAX, |
| 196 | }; |
| 197 | |
| 198 | #define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A)) |
| 199 | #define is_siso(tbl) ((tbl) == LQ_SISO) |
| 200 | #define is_mimo2(tbl) ((tbl) == LQ_MIMO2) |
Eyal Shapira | d972ab3 | 2013-07-28 23:02:45 +0000 | [diff] [blame] | 201 | #define is_mimo(tbl) is_mimo2(tbl) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 202 | #define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl)) |
| 203 | #define is_a_band(tbl) ((tbl) == LQ_A) |
| 204 | #define is_g_and(tbl) ((tbl) == LQ_G) |
| 205 | |
| 206 | #define IWL_MAX_MCS_DISPLAY_SIZE 12 |
| 207 | |
| 208 | struct iwl_rate_mcs_info { |
| 209 | char mbps[IWL_MAX_MCS_DISPLAY_SIZE]; |
| 210 | char mcs[IWL_MAX_MCS_DISPLAY_SIZE]; |
| 211 | }; |
| 212 | |
| 213 | /** |
| 214 | * struct iwl_rate_scale_data -- tx success history for one rate |
| 215 | */ |
| 216 | struct iwl_rate_scale_data { |
| 217 | u64 data; /* bitmap of successful frames */ |
| 218 | s32 success_counter; /* number of frames successful */ |
| 219 | s32 success_ratio; /* per-cent * 128 */ |
| 220 | s32 counter; /* number of frames attempted */ |
| 221 | s32 average_tpt; /* success ratio * expected throughput */ |
| 222 | unsigned long stamp; |
| 223 | }; |
| 224 | |
| 225 | /** |
| 226 | * struct iwl_scale_tbl_info -- tx params and success history for all rates |
| 227 | * |
| 228 | * There are two of these in struct iwl_lq_sta, |
| 229 | * one for "active", and one for "search". |
| 230 | */ |
| 231 | struct iwl_scale_tbl_info { |
| 232 | enum iwl_table_type lq_type; |
| 233 | u8 ant_type; |
| 234 | u8 is_SGI; /* 1 = short guard interval */ |
| 235 | u8 is_ht40; /* 1 = 40 MHz channel width */ |
| 236 | u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */ |
| 237 | u8 max_search; /* maximun number of tables we can search */ |
| 238 | s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */ |
| 239 | u32 current_rate; /* rate_n_flags, uCode API format */ |
| 240 | struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */ |
| 241 | }; |
| 242 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 243 | /** |
| 244 | * struct iwl_lq_sta -- driver's rate scaling private structure |
| 245 | * |
| 246 | * Pointer to this gets passed back and forth between driver and mac80211. |
| 247 | */ |
| 248 | struct iwl_lq_sta { |
| 249 | u8 active_tbl; /* index of active table, range 0-1 */ |
| 250 | u8 enable_counter; /* indicates HT mode */ |
| 251 | u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */ |
| 252 | u8 search_better_tbl; /* 1: currently trying alternate mode */ |
| 253 | s32 last_tpt; |
| 254 | |
| 255 | /* The following determine when to search for a new mode */ |
| 256 | u32 table_count_limit; |
| 257 | u32 max_failure_limit; /* # failed frames before new search */ |
| 258 | u32 max_success_limit; /* # successful frames before new search */ |
| 259 | u32 table_count; |
| 260 | u32 total_failed; /* total failed frames, any/all rates */ |
| 261 | u32 total_success; /* total successful frames, any/all rates */ |
| 262 | u64 flush_timer; /* time staying in mode before new search */ |
| 263 | |
| 264 | u8 action_counter; /* # mode-switch actions tried */ |
| 265 | u8 is_green; |
| 266 | enum ieee80211_band band; |
| 267 | |
| 268 | /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ |
| 269 | u32 supp_rates; |
| 270 | u16 active_legacy_rate; |
| 271 | u16 active_siso_rate; |
| 272 | u16 active_mimo2_rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 273 | s8 max_rate_idx; /* Max rate set by user */ |
| 274 | u8 missed_rate_counter; |
| 275 | |
| 276 | struct iwl_lq_cmd lq; |
| 277 | struct iwl_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 278 | u8 tx_agg_tid_en; |
| 279 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 280 | struct dentry *rs_sta_dbgfs_scale_table_file; |
| 281 | struct dentry *rs_sta_dbgfs_stats_table_file; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 282 | struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file; |
| 283 | u32 dbg_fixed_rate; |
| 284 | #endif |
| 285 | struct iwl_mvm *drv; |
| 286 | |
| 287 | /* used to be in sta_info */ |
| 288 | int last_txrate_idx; |
| 289 | /* last tx rate_n_flags */ |
| 290 | u32 last_rate_n_flags; |
| 291 | /* packets destined for this STA are aggregated */ |
| 292 | u8 is_agg; |
| 293 | /* BT traffic this sta was last updated in */ |
| 294 | u8 last_bt_traffic; |
| 295 | }; |
| 296 | |
Emmanuel Grumbach | 36946ce | 2013-05-28 23:12:47 +0300 | [diff] [blame] | 297 | enum iwl_bt_coex_profile_traffic_load { |
| 298 | IWL_BT_COEX_TRAFFIC_LOAD_NONE = 0, |
| 299 | IWL_BT_COEX_TRAFFIC_LOAD_LOW = 1, |
| 300 | IWL_BT_COEX_TRAFFIC_LOAD_HIGH = 2, |
| 301 | IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS = 3, |
| 302 | /* |
| 303 | * There are no more even though below is a u8, the |
| 304 | * indication from the BT device only has two bits. |
| 305 | */ |
| 306 | }; |
| 307 | |
| 308 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 309 | static inline u8 num_of_ant(u8 mask) |
| 310 | { |
| 311 | return !!((mask) & ANT_A) + |
| 312 | !!((mask) & ANT_B) + |
| 313 | !!((mask) & ANT_C); |
| 314 | } |
| 315 | |
| 316 | /* Initialize station's rate scaling information after adding station */ |
Joe Perches | b381839 | 2013-09-23 11:37:59 -0700 | [diff] [blame^] | 317 | void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 318 | enum ieee80211_band band); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 319 | |
| 320 | /** |
| 321 | * iwl_rate_control_register - Register the rate control algorithm callbacks |
| 322 | * |
| 323 | * Since the rate control algorithm is hardware specific, there is no need |
| 324 | * or reason to place it as a stand alone module. The driver can call |
| 325 | * iwl_rate_control_register in order to register the rate control callbacks |
| 326 | * with the mac80211 subsystem. This should be performed prior to calling |
| 327 | * ieee80211_register_hw |
| 328 | * |
| 329 | */ |
Joe Perches | b381839 | 2013-09-23 11:37:59 -0700 | [diff] [blame^] | 330 | int iwl_mvm_rate_control_register(void); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 331 | |
| 332 | /** |
| 333 | * iwl_rate_control_unregister - Unregister the rate control callbacks |
| 334 | * |
| 335 | * This should be called after calling ieee80211_unregister_hw, but before |
| 336 | * the driver is unloaded. |
| 337 | */ |
Joe Perches | b381839 | 2013-09-23 11:37:59 -0700 | [diff] [blame^] | 338 | void iwl_mvm_rate_control_unregister(void); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 339 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 340 | struct iwl_mvm_sta; |
| 341 | |
Johannes Berg | e126b5d | 2013-06-28 13:39:18 +0200 | [diff] [blame] | 342 | int iwl_mvm_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 343 | bool enable); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 344 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 345 | #endif /* __rs__ */ |