blob: 1e47a0c19b75291eabe81cf23714d040056883b8 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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
37struct 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 Berg8ca151b2013-01-24 14:25:36 +010041 u8 prev_rs; /* previous rate used in rs algo */
42 u8 next_rs; /* next rate used in rs algo */
Johannes Berg8ca151b2013-01-24 14:25:36 +010043};
44
45#define IWL_RATE_60M_PLCP 3
46
47enum {
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
54enum {
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 */
87enum {
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 Berg8ca151b2013-01-24 14:25:36 +0100117#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 */
Eyal Shapira4837b442013-07-28 23:02:46 +0000142enum {
143 IWL_LEGACY_SWITCH_ANTENNA,
144 IWL_LEGACY_SWITCH_SISO,
145 IWL_LEGACY_SWITCH_MIMO2,
146 IWL_LEGACY_FIRST_ACTION = IWL_LEGACY_SWITCH_ANTENNA,
147 IWL_LEGACY_LAST_ACTION = IWL_LEGACY_SWITCH_MIMO2,
148};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100149
150/* possible actions when in siso mode */
Eyal Shapira4837b442013-07-28 23:02:46 +0000151enum {
152 IWL_SISO_SWITCH_ANTENNA,
153 IWL_SISO_SWITCH_MIMO2,
154 IWL_SISO_SWITCH_GI,
155 IWL_SISO_FIRST_ACTION = IWL_SISO_SWITCH_ANTENNA,
156 IWL_SISO_LAST_ACTION = IWL_SISO_SWITCH_GI,
157};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100158
159/* possible actions when in mimo mode */
Eyal Shapira4837b442013-07-28 23:02:46 +0000160enum {
161 IWL_MIMO2_SWITCH_SISO_A,
162 IWL_MIMO2_SWITCH_SISO_B,
163 IWL_MIMO2_SWITCH_GI,
164 IWL_MIMO2_FIRST_ACTION = IWL_MIMO2_SWITCH_SISO_A,
165 IWL_MIMO2_LAST_ACTION = IWL_MIMO2_SWITCH_GI,
166};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100167
Eyal Shapira4837b442013-07-28 23:02:46 +0000168#define IWL_MAX_SEARCH IWL_MIMO2_LAST_ACTION
Johannes Berg8ca151b2013-01-24 14:25:36 +0100169
170#define IWL_ACTION_LIMIT 3 /* # possible actions */
171
172#define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) /* 4 milliseconds */
173#define LINK_QUAL_AGG_TIME_LIMIT_MAX (8000)
174#define LINK_QUAL_AGG_TIME_LIMIT_MIN (100)
175
176#define LINK_QUAL_AGG_DISABLE_START_DEF (3)
177#define LINK_QUAL_AGG_DISABLE_START_MAX (255)
178#define LINK_QUAL_AGG_DISABLE_START_MIN (0)
179
180#define LINK_QUAL_AGG_FRAME_LIMIT_DEF (63)
181#define LINK_QUAL_AGG_FRAME_LIMIT_MAX (63)
182#define LINK_QUAL_AGG_FRAME_LIMIT_MIN (0)
183
184#define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */
185
186/* load per tid defines for A-MPDU activation */
187#define IWL_AGG_TPT_THREHOLD 0
188#define IWL_AGG_LOAD_THRESHOLD 10
189#define IWL_AGG_ALL_TID 0xff
190#define TID_QUEUE_CELL_SPACING 50 /*mS */
191#define TID_QUEUE_MAX_SIZE 20
192#define TID_ROUND_VALUE 5 /* mS */
193
194#define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING)
195#define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y))
196
197enum iwl_table_type {
198 LQ_NONE,
199 LQ_G, /* legacy types */
200 LQ_A,
201 LQ_SISO, /* high-throughput types */
202 LQ_MIMO2,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100203 LQ_MAX,
204};
205
206#define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A))
207#define is_siso(tbl) ((tbl) == LQ_SISO)
208#define is_mimo2(tbl) ((tbl) == LQ_MIMO2)
Eyal Shapirad972ab32013-07-28 23:02:45 +0000209#define is_mimo(tbl) is_mimo2(tbl)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100210#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl))
211#define is_a_band(tbl) ((tbl) == LQ_A)
212#define is_g_and(tbl) ((tbl) == LQ_G)
213
214#define IWL_MAX_MCS_DISPLAY_SIZE 12
215
216struct iwl_rate_mcs_info {
217 char mbps[IWL_MAX_MCS_DISPLAY_SIZE];
218 char mcs[IWL_MAX_MCS_DISPLAY_SIZE];
219};
220
221/**
222 * struct iwl_rate_scale_data -- tx success history for one rate
223 */
224struct iwl_rate_scale_data {
225 u64 data; /* bitmap of successful frames */
226 s32 success_counter; /* number of frames successful */
227 s32 success_ratio; /* per-cent * 128 */
228 s32 counter; /* number of frames attempted */
229 s32 average_tpt; /* success ratio * expected throughput */
230 unsigned long stamp;
231};
232
233/**
234 * struct iwl_scale_tbl_info -- tx params and success history for all rates
235 *
236 * There are two of these in struct iwl_lq_sta,
237 * one for "active", and one for "search".
238 */
239struct iwl_scale_tbl_info {
240 enum iwl_table_type lq_type;
241 u8 ant_type;
242 u8 is_SGI; /* 1 = short guard interval */
243 u8 is_ht40; /* 1 = 40 MHz channel width */
244 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */
245 u8 max_search; /* maximun number of tables we can search */
246 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */
247 u32 current_rate; /* rate_n_flags, uCode API format */
248 struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
249};
250
Johannes Berg8ca151b2013-01-24 14:25:36 +0100251/**
252 * struct iwl_lq_sta -- driver's rate scaling private structure
253 *
254 * Pointer to this gets passed back and forth between driver and mac80211.
255 */
256struct iwl_lq_sta {
257 u8 active_tbl; /* index of active table, range 0-1 */
258 u8 enable_counter; /* indicates HT mode */
259 u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */
260 u8 search_better_tbl; /* 1: currently trying alternate mode */
261 s32 last_tpt;
262
263 /* The following determine when to search for a new mode */
264 u32 table_count_limit;
265 u32 max_failure_limit; /* # failed frames before new search */
266 u32 max_success_limit; /* # successful frames before new search */
267 u32 table_count;
268 u32 total_failed; /* total failed frames, any/all rates */
269 u32 total_success; /* total successful frames, any/all rates */
270 u64 flush_timer; /* time staying in mode before new search */
271
272 u8 action_counter; /* # mode-switch actions tried */
273 u8 is_green;
274 enum ieee80211_band band;
275
276 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
277 u32 supp_rates;
278 u16 active_legacy_rate;
279 u16 active_siso_rate;
280 u16 active_mimo2_rate;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100281 s8 max_rate_idx; /* Max rate set by user */
282 u8 missed_rate_counter;
283
284 struct iwl_lq_cmd lq;
285 struct iwl_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100286 u8 tx_agg_tid_en;
287#ifdef CONFIG_MAC80211_DEBUGFS
288 struct dentry *rs_sta_dbgfs_scale_table_file;
289 struct dentry *rs_sta_dbgfs_stats_table_file;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100290 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
291 u32 dbg_fixed_rate;
292#endif
293 struct iwl_mvm *drv;
294
295 /* used to be in sta_info */
296 int last_txrate_idx;
297 /* last tx rate_n_flags */
298 u32 last_rate_n_flags;
299 /* packets destined for this STA are aggregated */
300 u8 is_agg;
301 /* BT traffic this sta was last updated in */
302 u8 last_bt_traffic;
303};
304
Emmanuel Grumbach36946ce2013-05-28 23:12:47 +0300305enum iwl_bt_coex_profile_traffic_load {
306 IWL_BT_COEX_TRAFFIC_LOAD_NONE = 0,
307 IWL_BT_COEX_TRAFFIC_LOAD_LOW = 1,
308 IWL_BT_COEX_TRAFFIC_LOAD_HIGH = 2,
309 IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS = 3,
310/*
311 * There are no more even though below is a u8, the
312 * indication from the BT device only has two bits.
313 */
314};
315
316
Johannes Berg8ca151b2013-01-24 14:25:36 +0100317static inline u8 num_of_ant(u8 mask)
318{
319 return !!((mask) & ANT_A) +
320 !!((mask) & ANT_B) +
321 !!((mask) & ANT_C);
322}
323
324/* Initialize station's rate scaling information after adding station */
325extern void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm,
326 struct ieee80211_sta *sta,
327 enum ieee80211_band band);
328
329/**
330 * iwl_rate_control_register - Register the rate control algorithm callbacks
331 *
332 * Since the rate control algorithm is hardware specific, there is no need
333 * or reason to place it as a stand alone module. The driver can call
334 * iwl_rate_control_register in order to register the rate control callbacks
335 * with the mac80211 subsystem. This should be performed prior to calling
336 * ieee80211_register_hw
337 *
338 */
339extern int iwl_mvm_rate_control_register(void);
340
341/**
342 * iwl_rate_control_unregister - Unregister the rate control callbacks
343 *
344 * This should be called after calling ieee80211_unregister_hw, but before
345 * the driver is unloaded.
346 */
347extern void iwl_mvm_rate_control_unregister(void);
348
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300349struct iwl_mvm_sta;
350
Johannes Berge126b5d2013-06-28 13:39:18 +0200351int iwl_mvm_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
352 bool enable);
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300353
Johannes Berg8ca151b2013-01-24 14:25:36 +0100354#endif /* __rs__ */