aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-agn-rs.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c593
1 files changed, 500 insertions, 93 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index cab7842a73aa..ff20e5048a55 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -52,7 +52,7 @@
52/* max allowed rate miss before sync LQ cmd */ 52/* max allowed rate miss before sync LQ cmd */
53#define IWL_MISSED_RATE_MAX 15 53#define IWL_MISSED_RATE_MAX 15
54/* max time to accum history 2 seconds */ 54/* max time to accum history 2 seconds */
55#define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) 55#define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ)
56 56
57static u8 rs_ht_to_legacy[] = { 57static u8 rs_ht_to_legacy[] = {
58 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, 58 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
@@ -100,6 +100,7 @@ struct iwl_scale_tbl_info {
100 u8 is_fat; /* 1 = 40 MHz channel width */ 100 u8 is_fat; /* 1 = 40 MHz channel width */
101 u8 is_dup; /* 1 = duplicated data streams */ 101 u8 is_dup; /* 1 = duplicated data streams */
102 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */ 102 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */
103 u8 max_search; /* maximun number of tables we can search */
103 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */ 104 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */
104 u32 current_rate; /* rate_n_flags, uCode API format */ 105 u32 current_rate; /* rate_n_flags, uCode API format */
105 struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */ 106 struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
@@ -135,7 +136,7 @@ struct iwl_lq_sta {
135 u32 table_count; 136 u32 table_count;
136 u32 total_failed; /* total failed frames, any/all rates */ 137 u32 total_failed; /* total failed frames, any/all rates */
137 u32 total_success; /* total successful frames, any/all rates */ 138 u32 total_success; /* total successful frames, any/all rates */
138 u32 flush_timer; /* time staying in mode before new search */ 139 u64 flush_timer; /* time staying in mode before new search */
139 140
140 u8 action_counter; /* # mode-switch actions tried */ 141 u8 action_counter; /* # mode-switch actions tried */
141 u8 is_green; 142 u8 is_green;
@@ -160,6 +161,7 @@ struct iwl_lq_sta {
160#ifdef CONFIG_MAC80211_DEBUGFS 161#ifdef CONFIG_MAC80211_DEBUGFS
161 struct dentry *rs_sta_dbgfs_scale_table_file; 162 struct dentry *rs_sta_dbgfs_scale_table_file;
162 struct dentry *rs_sta_dbgfs_stats_table_file; 163 struct dentry *rs_sta_dbgfs_stats_table_file;
164 struct dentry *rs_sta_dbgfs_rate_scale_data_file;
163 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file; 165 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
164 u32 dbg_fixed_rate; 166 u32 dbg_fixed_rate;
165#endif 167#endif
@@ -167,10 +169,12 @@ struct iwl_lq_sta {
167 169
168 /* used to be in sta_info */ 170 /* used to be in sta_info */
169 int last_txrate_idx; 171 int last_txrate_idx;
172 /* last tx rate_n_flags */
173 u32 last_rate_n_flags;
170}; 174};
171 175
172static void rs_rate_scale_perform(struct iwl_priv *priv, 176static void rs_rate_scale_perform(struct iwl_priv *priv,
173 struct ieee80211_hdr *hdr, 177 struct sk_buff *skb,
174 struct ieee80211_sta *sta, 178 struct ieee80211_sta *sta,
175 struct iwl_lq_sta *lq_sta); 179 struct iwl_lq_sta *lq_sta);
176static void rs_fill_link_cmd(const struct iwl_priv *priv, 180static void rs_fill_link_cmd(const struct iwl_priv *priv,
@@ -191,7 +195,7 @@ static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
191 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits 195 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
192 * "G" is the only table that supports CCK (the first 4 rates). 196 * "G" is the only table that supports CCK (the first 4 rates).
193 */ 197 */
194/*FIXME:RS:need to separate tables for MIMO2/MIMO3*/ 198
195static s32 expected_tpt_A[IWL_RATE_COUNT] = { 199static s32 expected_tpt_A[IWL_RATE_COUNT] = {
196 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186 200 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
197}; 201};
@@ -208,11 +212,11 @@ static s32 expected_tpt_siso20MHzSGI[IWL_RATE_COUNT] = {
208 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211 212 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
209}; 213};
210 214
211static s32 expected_tpt_mimo20MHz[IWL_RATE_COUNT] = { 215static s32 expected_tpt_mimo2_20MHz[IWL_RATE_COUNT] = {
212 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251 216 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
213}; 217};
214 218
215static s32 expected_tpt_mimo20MHzSGI[IWL_RATE_COUNT] = { 219static s32 expected_tpt_mimo2_20MHzSGI[IWL_RATE_COUNT] = {
216 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257 220 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
217}; 221};
218 222
@@ -224,14 +228,50 @@ static s32 expected_tpt_siso40MHzSGI[IWL_RATE_COUNT] = {
224 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264 228 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
225}; 229};
226 230
227static s32 expected_tpt_mimo40MHz[IWL_RATE_COUNT] = { 231static s32 expected_tpt_mimo2_40MHz[IWL_RATE_COUNT] = {
228 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289 232 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
229}; 233};
230 234
231static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = { 235static s32 expected_tpt_mimo2_40MHzSGI[IWL_RATE_COUNT] = {
232 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293 236 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
233}; 237};
234 238
239/* Expected throughput metric MIMO3 */
240static s32 expected_tpt_mimo3_20MHz[IWL_RATE_COUNT] = {
241 0, 0, 0, 0, 99, 99, 153, 186, 208, 239, 256, 263, 268
242};
243
244static s32 expected_tpt_mimo3_20MHzSGI[IWL_RATE_COUNT] = {
245 0, 0, 0, 0, 106, 106, 162, 194, 215, 246, 262, 268, 273
246};
247
248static s32 expected_tpt_mimo3_40MHz[IWL_RATE_COUNT] = {
249 0, 0, 0, 0, 152, 152, 211, 239, 255, 279, 290, 294, 297
250};
251
252static s32 expected_tpt_mimo3_40MHzSGI[IWL_RATE_COUNT] = {
253 0, 0, 0, 0, 160, 160, 219, 245, 261, 284, 294, 297, 300
254};
255
256/* mbps, mcs */
257const static struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = {
258 {"1", ""},
259 {"2", ""},
260 {"5.5", ""},
261 {"11", ""},
262 {"6", "BPSK 1/2"},
263 {"9", "BPSK 1/2"},
264 {"12", "QPSK 1/2"},
265 {"18", "QPSK 3/4"},
266 {"24", "16QAM 1/2"},
267 {"36", "16QAM 3/4"},
268 {"48", "64QAM 2/3"},
269 {"54", "64QAM 3/4"},
270 {"60", "64QAM 5/6"}
271};
272
273#define MCS_INDEX_PER_STREAM (8)
274
235static inline u8 rs_extract_rate(u32 rate_n_flags) 275static inline u8 rs_extract_rate(u32 rate_n_flags)
236{ 276{
237 return (u8)(rate_n_flags & 0xFF); 277 return (u8)(rate_n_flags & 0xFF);
@@ -543,6 +583,7 @@ static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
543 tbl->is_dup = 0; 583 tbl->is_dup = 0;
544 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS); 584 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
545 tbl->lq_type = LQ_NONE; 585 tbl->lq_type = LQ_NONE;
586 tbl->max_search = IWL_MAX_SEARCH;
546 587
547 /* legacy rate format */ 588 /* legacy rate format */
548 if (!(rate_n_flags & RATE_MCS_HT_MSK)) { 589 if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
@@ -576,8 +617,10 @@ static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
576 tbl->lq_type = LQ_MIMO2; 617 tbl->lq_type = LQ_MIMO2;
577 /* MIMO3 */ 618 /* MIMO3 */
578 } else { 619 } else {
579 if (num_of_ant == 3) 620 if (num_of_ant == 3) {
621 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
580 tbl->lq_type = LQ_MIMO3; 622 tbl->lq_type = LQ_MIMO3;
623 }
581 } 624 }
582 } 625 }
583 return 0; 626 return 0;
@@ -611,19 +654,19 @@ static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
611 return 1; 654 return 1;
612} 655}
613 656
614/* FIXME:RS: in 4965 we don't use greenfield at all */ 657/* in 4965 we don't use greenfield at all */
615/* FIXME:RS: don't use greenfield for now in TX */ 658static inline u8 rs_use_green(struct iwl_priv *priv,
616#if 0 659 struct ieee80211_conf *conf)
617static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
618{ 660{
619 return (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && 661 u8 is_green;
620 priv->current_ht_config.is_green_field && 662
621 !priv->current_ht_config.non_GF_STA_present; 663 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)
622} 664 is_green = 0;
623#endif 665 else
624static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf) 666 is_green = (conf_is_ht(conf) &&
625{ 667 priv->current_ht_config.is_green_field &&
626 return 0; 668 !priv->current_ht_config.non_GF_STA_present);
669 return is_green;
627} 670}
628 671
629/** 672/**
@@ -735,6 +778,7 @@ static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
735 778
736 tbl->is_fat = 0; 779 tbl->is_fat = 0;
737 tbl->is_SGI = 0; 780 tbl->is_SGI = 0;
781 tbl->max_search = IWL_MAX_SEARCH;
738 } 782 }
739 783
740 rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type); 784 rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
@@ -793,7 +837,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
793 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n"); 837 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
794 838
795 if (!ieee80211_is_data(hdr->frame_control) || 839 if (!ieee80211_is_data(hdr->frame_control) ||
796 is_multicast_ether_addr(hdr->addr1)) 840 info->flags & IEEE80211_TX_CTL_NO_ACK)
797 return; 841 return;
798 842
799 /* This packet was aggregated but doesn't carry rate scale info */ 843 /* This packet was aggregated but doesn't carry rate scale info */
@@ -902,6 +946,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
902 * else look up the rate that was, finally, successful. 946 * else look up the rate that was, finally, successful.
903 */ 947 */
904 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags); 948 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags);
949 lq_sta->last_rate_n_flags = tx_rate;
905 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index); 950 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
906 951
907 /* Update frame history window with "success" if Tx got ACKed ... */ 952 /* Update frame history window with "success" if Tx got ACKed ... */
@@ -958,7 +1003,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
958 1003
959 /* See if there's a better rate or modulation mode to try. */ 1004 /* See if there's a better rate or modulation mode to try. */
960 if (sta && sta->supp_rates[sband->band]) 1005 if (sta && sta->supp_rates[sband->band])
961 rs_rate_scale_perform(priv, hdr, sta, lq_sta); 1006 rs_rate_scale_perform(priv, skb, sta, lq_sta);
962out: 1007out:
963 return; 1008 return;
964} 1009}
@@ -988,6 +1033,8 @@ static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy,
988 lq_sta->table_count = 0; 1033 lq_sta->table_count = 0;
989 lq_sta->total_failed = 0; 1034 lq_sta->total_failed = 0;
990 lq_sta->total_success = 0; 1035 lq_sta->total_success = 0;
1036 lq_sta->flush_timer = jiffies;
1037 lq_sta->action_counter = 0;
991} 1038}
992 1039
993/* 1040/*
@@ -1011,17 +1058,26 @@ static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta,
1011 tbl->expected_tpt = expected_tpt_siso20MHzSGI; 1058 tbl->expected_tpt = expected_tpt_siso20MHzSGI;
1012 else 1059 else
1013 tbl->expected_tpt = expected_tpt_siso20MHz; 1060 tbl->expected_tpt = expected_tpt_siso20MHz;
1014 1061 } else if (is_mimo2(tbl->lq_type)) {
1015 } else if (is_mimo(tbl->lq_type)) { /* FIXME:need to separate mimo2/3 */
1016 if (tbl->is_fat && !lq_sta->is_dup) 1062 if (tbl->is_fat && !lq_sta->is_dup)
1017 if (tbl->is_SGI) 1063 if (tbl->is_SGI)
1018 tbl->expected_tpt = expected_tpt_mimo40MHzSGI; 1064 tbl->expected_tpt = expected_tpt_mimo2_40MHzSGI;
1019 else 1065 else
1020 tbl->expected_tpt = expected_tpt_mimo40MHz; 1066 tbl->expected_tpt = expected_tpt_mimo2_40MHz;
1021 else if (tbl->is_SGI) 1067 else if (tbl->is_SGI)
1022 tbl->expected_tpt = expected_tpt_mimo20MHzSGI; 1068 tbl->expected_tpt = expected_tpt_mimo2_20MHzSGI;
1023 else 1069 else
1024 tbl->expected_tpt = expected_tpt_mimo20MHz; 1070 tbl->expected_tpt = expected_tpt_mimo2_20MHz;
1071 } else if (is_mimo3(tbl->lq_type)) {
1072 if (tbl->is_fat && !lq_sta->is_dup)
1073 if (tbl->is_SGI)
1074 tbl->expected_tpt = expected_tpt_mimo3_40MHzSGI;
1075 else
1076 tbl->expected_tpt = expected_tpt_mimo3_40MHz;
1077 else if (tbl->is_SGI)
1078 tbl->expected_tpt = expected_tpt_mimo3_20MHzSGI;
1079 else
1080 tbl->expected_tpt = expected_tpt_mimo3_20MHz;
1025 } else 1081 } else
1026 tbl->expected_tpt = expected_tpt_G; 1082 tbl->expected_tpt = expected_tpt_G;
1027} 1083}
@@ -1130,7 +1186,7 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
1130} 1186}
1131 1187
1132/* 1188/*
1133 * Set up search table for MIMO 1189 * Set up search table for MIMO2
1134 */ 1190 */
1135static int rs_switch_to_mimo2(struct iwl_priv *priv, 1191static int rs_switch_to_mimo2(struct iwl_priv *priv,
1136 struct iwl_lq_sta *lq_sta, 1192 struct iwl_lq_sta *lq_sta,
@@ -1158,10 +1214,10 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
1158 tbl->lq_type = LQ_MIMO2; 1214 tbl->lq_type = LQ_MIMO2;
1159 tbl->is_dup = lq_sta->is_dup; 1215 tbl->is_dup = lq_sta->is_dup;
1160 tbl->action = 0; 1216 tbl->action = 0;
1217 tbl->max_search = IWL_MAX_SEARCH;
1161 rate_mask = lq_sta->active_mimo2_rate; 1218 rate_mask = lq_sta->active_mimo2_rate;
1162 1219
1163 if (priv->current_ht_config.supported_chan_width 1220 if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
1164 == IWL_CHANNEL_WIDTH_40MHZ)
1165 tbl->is_fat = 1; 1221 tbl->is_fat = 1;
1166 else 1222 else
1167 tbl->is_fat = 0; 1223 tbl->is_fat = 0;
@@ -1183,7 +1239,73 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
1183 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); 1239 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1184 1240
1185 IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask); 1241 IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask);
1242 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1243 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
1244 rate, rate_mask);
1245 return -1;
1246 }
1247 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
1248
1249 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
1250 tbl->current_rate, is_green);
1251 return 0;
1252}
1253
1254/*
1255 * Set up search table for MIMO3
1256 */
1257static int rs_switch_to_mimo3(struct iwl_priv *priv,
1258 struct iwl_lq_sta *lq_sta,
1259 struct ieee80211_conf *conf,
1260 struct ieee80211_sta *sta,
1261 struct iwl_scale_tbl_info *tbl, int index)
1262{
1263 u16 rate_mask;
1264 s32 rate;
1265 s8 is_green = lq_sta->is_green;
1266
1267 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1268 return -1;
1269
1270 if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
1271 == WLAN_HT_CAP_SM_PS_STATIC)
1272 return -1;
1273
1274 /* Need both Tx chains/antennas to support MIMO */
1275 if (priv->hw_params.tx_chains_num < 3)
1276 return -1;
1277
1278 IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n");
1279
1280 tbl->lq_type = LQ_MIMO3;
1281 tbl->is_dup = lq_sta->is_dup;
1282 tbl->action = 0;
1283 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
1284 rate_mask = lq_sta->active_mimo3_rate;
1285
1286 if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
1287 tbl->is_fat = 1;
1288 else
1289 tbl->is_fat = 0;
1186 1290
1291 /* FIXME: - don't toggle SGI here
1292 if (tbl->is_fat) {
1293 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
1294 tbl->is_SGI = 1;
1295 else
1296 tbl->is_SGI = 0;
1297 } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY)
1298 tbl->is_SGI = 1;
1299 else
1300 tbl->is_SGI = 0;
1301 */
1302
1303 rs_set_expected_tpt_table(lq_sta, tbl);
1304
1305 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1306
1307 IWL_DEBUG_RATE(priv, "LQ: MIMO3 best rate %d mask %X\n",
1308 rate, rate_mask);
1187 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { 1309 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1188 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n", 1310 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
1189 rate, rate_mask); 1311 rate, rate_mask);
@@ -1217,10 +1339,10 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1217 tbl->is_dup = lq_sta->is_dup; 1339 tbl->is_dup = lq_sta->is_dup;
1218 tbl->lq_type = LQ_SISO; 1340 tbl->lq_type = LQ_SISO;
1219 tbl->action = 0; 1341 tbl->action = 0;
1342 tbl->max_search = IWL_MAX_SEARCH;
1220 rate_mask = lq_sta->active_siso_rate; 1343 rate_mask = lq_sta->active_siso_rate;
1221 1344
1222 if (priv->current_ht_config.supported_chan_width 1345 if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
1223 == IWL_CHANNEL_WIDTH_40MHZ)
1224 tbl->is_fat = 1; 1346 tbl->is_fat = 1;
1225 else 1347 else
1226 tbl->is_fat = 0; 1348 tbl->is_fat = 0;
@@ -1274,15 +1396,15 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1274 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1396 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1275 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1397 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1276 int ret = 0; 1398 int ret = 0;
1399 u8 update_search_tbl_counter = 0;
1277 1400
1278 for (; ;) { 1401 for (; ;) {
1402 lq_sta->action_counter++;
1279 switch (tbl->action) { 1403 switch (tbl->action) {
1280 case IWL_LEGACY_SWITCH_ANTENNA1: 1404 case IWL_LEGACY_SWITCH_ANTENNA1:
1281 case IWL_LEGACY_SWITCH_ANTENNA2: 1405 case IWL_LEGACY_SWITCH_ANTENNA2:
1282 IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n"); 1406 IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n");
1283 1407
1284 lq_sta->action_counter++;
1285
1286 if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 && 1408 if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
1287 tx_chains_num <= 1) || 1409 tx_chains_num <= 1) ||
1288 (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 && 1410 (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
@@ -1298,6 +1420,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1298 1420
1299 if (rs_toggle_antenna(valid_tx_ant, 1421 if (rs_toggle_antenna(valid_tx_ant,
1300 &search_tbl->current_rate, search_tbl)) { 1422 &search_tbl->current_rate, search_tbl)) {
1423 update_search_tbl_counter = 1;
1301 rs_set_expected_tpt_table(lq_sta, search_tbl); 1424 rs_set_expected_tpt_table(lq_sta, search_tbl);
1302 goto out; 1425 goto out;
1303 } 1426 }
@@ -1342,9 +1465,29 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1342 goto out; 1465 goto out;
1343 } 1466 }
1344 break; 1467 break;
1468
1469 case IWL_LEGACY_SWITCH_MIMO3_ABC:
1470 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO3\n");
1471
1472 /* Set up search table to try MIMO3 */
1473 memcpy(search_tbl, tbl, sz);
1474 search_tbl->is_SGI = 0;
1475
1476 search_tbl->ant_type = ANT_ABC;
1477
1478 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1479 break;
1480
1481 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1482 search_tbl, index);
1483 if (!ret) {
1484 lq_sta->action_counter = 0;
1485 goto out;
1486 }
1487 break;
1345 } 1488 }
1346 tbl->action++; 1489 tbl->action++;
1347 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2_BC) 1490 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
1348 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; 1491 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1349 1492
1350 if (tbl->action == start_action) 1493 if (tbl->action == start_action)
@@ -1357,8 +1500,10 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1357out: 1500out:
1358 lq_sta->search_better_tbl = 1; 1501 lq_sta->search_better_tbl = 1;
1359 tbl->action++; 1502 tbl->action++;
1360 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2_BC) 1503 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
1361 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; 1504 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1505 if (update_search_tbl_counter)
1506 search_tbl->action = tbl->action;
1362 return 0; 1507 return 0;
1363 1508
1364} 1509}
@@ -1381,6 +1526,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1381 u8 start_action = tbl->action; 1526 u8 start_action = tbl->action;
1382 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1527 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1383 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1528 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1529 u8 update_search_tbl_counter = 0;
1384 int ret; 1530 int ret;
1385 1531
1386 for (;;) { 1532 for (;;) {
@@ -1401,8 +1547,10 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1401 1547
1402 memcpy(search_tbl, tbl, sz); 1548 memcpy(search_tbl, tbl, sz);
1403 if (rs_toggle_antenna(valid_tx_ant, 1549 if (rs_toggle_antenna(valid_tx_ant,
1404 &search_tbl->current_rate, search_tbl)) 1550 &search_tbl->current_rate, search_tbl)) {
1551 update_search_tbl_counter = 1;
1405 goto out; 1552 goto out;
1553 }
1406 break; 1554 break;
1407 case IWL_SISO_SWITCH_MIMO2_AB: 1555 case IWL_SISO_SWITCH_MIMO2_AB:
1408 case IWL_SISO_SWITCH_MIMO2_AC: 1556 case IWL_SISO_SWITCH_MIMO2_AC:
@@ -1456,10 +1604,25 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1456 search_tbl->current_rate = 1604 search_tbl->current_rate =
1457 rate_n_flags_from_tbl(priv, search_tbl, 1605 rate_n_flags_from_tbl(priv, search_tbl,
1458 index, is_green); 1606 index, is_green);
1607 update_search_tbl_counter = 1;
1459 goto out; 1608 goto out;
1609 case IWL_SISO_SWITCH_MIMO3_ABC:
1610 IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n");
1611 memcpy(search_tbl, tbl, sz);
1612 search_tbl->is_SGI = 0;
1613 search_tbl->ant_type = ANT_ABC;
1614
1615 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1616 break;
1617
1618 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1619 search_tbl, index);
1620 if (!ret)
1621 goto out;
1622 break;
1460 } 1623 }
1461 tbl->action++; 1624 tbl->action++;
1462 if (tbl->action > IWL_SISO_SWITCH_GI) 1625 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
1463 tbl->action = IWL_SISO_SWITCH_ANTENNA1; 1626 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1464 1627
1465 if (tbl->action == start_action) 1628 if (tbl->action == start_action)
@@ -1471,15 +1634,18 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1471 out: 1634 out:
1472 lq_sta->search_better_tbl = 1; 1635 lq_sta->search_better_tbl = 1;
1473 tbl->action++; 1636 tbl->action++;
1474 if (tbl->action > IWL_SISO_SWITCH_GI) 1637 if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
1475 tbl->action = IWL_SISO_SWITCH_ANTENNA1; 1638 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1639 if (update_search_tbl_counter)
1640 search_tbl->action = tbl->action;
1641
1476 return 0; 1642 return 0;
1477} 1643}
1478 1644
1479/* 1645/*
1480 * Try to switch to new modulation mode from MIMO 1646 * Try to switch to new modulation mode from MIMO2
1481 */ 1647 */
1482static int rs_move_mimo_to_other(struct iwl_priv *priv, 1648static int rs_move_mimo2_to_other(struct iwl_priv *priv,
1483 struct iwl_lq_sta *lq_sta, 1649 struct iwl_lq_sta *lq_sta,
1484 struct ieee80211_conf *conf, 1650 struct ieee80211_conf *conf,
1485 struct ieee80211_sta *sta, int index) 1651 struct ieee80211_sta *sta, int index)
@@ -1494,6 +1660,7 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1494 u8 start_action = tbl->action; 1660 u8 start_action = tbl->action;
1495 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1661 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1496 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1662 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1663 u8 update_search_tbl_counter = 0;
1497 int ret; 1664 int ret;
1498 1665
1499 for (;;) { 1666 for (;;) {
@@ -1501,7 +1668,7 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1501 switch (tbl->action) { 1668 switch (tbl->action) {
1502 case IWL_MIMO2_SWITCH_ANTENNA1: 1669 case IWL_MIMO2_SWITCH_ANTENNA1:
1503 case IWL_MIMO2_SWITCH_ANTENNA2: 1670 case IWL_MIMO2_SWITCH_ANTENNA2:
1504 IWL_DEBUG_RATE(priv, "LQ: MIMO toggle Antennas\n"); 1671 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle Antennas\n");
1505 1672
1506 if (tx_chains_num <= 2) 1673 if (tx_chains_num <= 2)
1507 break; 1674 break;
@@ -1511,8 +1678,10 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1511 1678
1512 memcpy(search_tbl, tbl, sz); 1679 memcpy(search_tbl, tbl, sz);
1513 if (rs_toggle_antenna(valid_tx_ant, 1680 if (rs_toggle_antenna(valid_tx_ant,
1514 &search_tbl->current_rate, search_tbl)) 1681 &search_tbl->current_rate, search_tbl)) {
1682 update_search_tbl_counter = 1;
1515 goto out; 1683 goto out;
1684 }
1516 break; 1685 break;
1517 case IWL_MIMO2_SWITCH_SISO_A: 1686 case IWL_MIMO2_SWITCH_SISO_A:
1518 case IWL_MIMO2_SWITCH_SISO_B: 1687 case IWL_MIMO2_SWITCH_SISO_B:
@@ -1549,9 +1718,9 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1549 HT_SHORT_GI_40MHZ)) 1718 HT_SHORT_GI_40MHZ))
1550 break; 1719 break;
1551 1720
1552 IWL_DEBUG_RATE(priv, "LQ: MIMO toggle SGI/NGI\n"); 1721 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle SGI/NGI\n");
1553 1722
1554 /* Set up new search table for MIMO */ 1723 /* Set up new search table for MIMO2 */
1555 memcpy(search_tbl, tbl, sz); 1724 memcpy(search_tbl, tbl, sz);
1556 search_tbl->is_SGI = !tbl->is_SGI; 1725 search_tbl->is_SGI = !tbl->is_SGI;
1557 rs_set_expected_tpt_table(lq_sta, search_tbl); 1726 rs_set_expected_tpt_table(lq_sta, search_tbl);
@@ -1569,11 +1738,27 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1569 search_tbl->current_rate = 1738 search_tbl->current_rate =
1570 rate_n_flags_from_tbl(priv, search_tbl, 1739 rate_n_flags_from_tbl(priv, search_tbl,
1571 index, is_green); 1740 index, is_green);
1741 update_search_tbl_counter = 1;
1572 goto out; 1742 goto out;
1573 1743
1744 case IWL_MIMO2_SWITCH_MIMO3_ABC:
1745 IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n");
1746 memcpy(search_tbl, tbl, sz);
1747 search_tbl->is_SGI = 0;
1748 search_tbl->ant_type = ANT_ABC;
1749
1750 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1751 break;
1752
1753 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1754 search_tbl, index);
1755 if (!ret)
1756 goto out;
1757
1758 break;
1574 } 1759 }
1575 tbl->action++; 1760 tbl->action++;
1576 if (tbl->action > IWL_MIMO2_SWITCH_GI) 1761 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1577 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; 1762 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1578 1763
1579 if (tbl->action == start_action) 1764 if (tbl->action == start_action)
@@ -1584,8 +1769,153 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1584 out: 1769 out:
1585 lq_sta->search_better_tbl = 1; 1770 lq_sta->search_better_tbl = 1;
1586 tbl->action++; 1771 tbl->action++;
1587 if (tbl->action > IWL_MIMO2_SWITCH_GI) 1772 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1588 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; 1773 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1774 if (update_search_tbl_counter)
1775 search_tbl->action = tbl->action;
1776
1777 return 0;
1778
1779}
1780
1781/*
1782 * Try to switch to new modulation mode from MIMO3
1783 */
1784static int rs_move_mimo3_to_other(struct iwl_priv *priv,
1785 struct iwl_lq_sta *lq_sta,
1786 struct ieee80211_conf *conf,
1787 struct ieee80211_sta *sta, int index)
1788{
1789 s8 is_green = lq_sta->is_green;
1790 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1791 struct iwl_scale_tbl_info *search_tbl =
1792 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1793 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1794 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1795 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1796 u8 start_action = tbl->action;
1797 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1798 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1799 int ret;
1800 u8 update_search_tbl_counter = 0;
1801
1802 for (;;) {
1803 lq_sta->action_counter++;
1804 switch (tbl->action) {
1805 case IWL_MIMO3_SWITCH_ANTENNA1:
1806 case IWL_MIMO3_SWITCH_ANTENNA2:
1807 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n");
1808
1809 if (tx_chains_num <= 3)
1810 break;
1811
1812 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1813 break;
1814
1815 memcpy(search_tbl, tbl, sz);
1816 if (rs_toggle_antenna(valid_tx_ant,
1817 &search_tbl->current_rate, search_tbl))
1818 goto out;
1819 break;
1820 case IWL_MIMO3_SWITCH_SISO_A:
1821 case IWL_MIMO3_SWITCH_SISO_B:
1822 case IWL_MIMO3_SWITCH_SISO_C:
1823 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n");
1824
1825 /* Set up new search table for SISO */
1826 memcpy(search_tbl, tbl, sz);
1827
1828 if (tbl->action == IWL_MIMO3_SWITCH_SISO_A)
1829 search_tbl->ant_type = ANT_A;
1830 else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B)
1831 search_tbl->ant_type = ANT_B;
1832 else
1833 search_tbl->ant_type = ANT_C;
1834
1835 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1836 break;
1837
1838 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
1839 search_tbl, index);
1840 if (!ret)
1841 goto out;
1842
1843 break;
1844
1845 case IWL_MIMO3_SWITCH_MIMO2_AB:
1846 case IWL_MIMO3_SWITCH_MIMO2_AC:
1847 case IWL_MIMO3_SWITCH_MIMO2_BC:
1848 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to MIMO2\n");
1849
1850 memcpy(search_tbl, tbl, sz);
1851 search_tbl->is_SGI = 0;
1852 if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB)
1853 search_tbl->ant_type = ANT_AB;
1854 else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC)
1855 search_tbl->ant_type = ANT_AC;
1856 else
1857 search_tbl->ant_type = ANT_BC;
1858
1859 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1860 break;
1861
1862 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
1863 search_tbl, index);
1864 if (!ret)
1865 goto out;
1866
1867 break;
1868
1869 case IWL_MIMO3_SWITCH_GI:
1870 if (!tbl->is_fat &&
1871 !(priv->current_ht_config.sgf &
1872 HT_SHORT_GI_20MHZ))
1873 break;
1874 if (tbl->is_fat &&
1875 !(priv->current_ht_config.sgf &
1876 HT_SHORT_GI_40MHZ))
1877 break;
1878
1879 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle SGI/NGI\n");
1880
1881 /* Set up new search table for MIMO */
1882 memcpy(search_tbl, tbl, sz);
1883 search_tbl->is_SGI = !tbl->is_SGI;
1884 rs_set_expected_tpt_table(lq_sta, search_tbl);
1885 /*
1886 * If active table already uses the fastest possible
1887 * modulation (dual stream with short guard interval),
1888 * and it's working well, there's no need to look
1889 * for a better type of modulation!
1890 */
1891 if (tbl->is_SGI) {
1892 s32 tpt = lq_sta->last_tpt / 100;
1893 if (tpt >= search_tbl->expected_tpt[index])
1894 break;
1895 }
1896 search_tbl->current_rate =
1897 rate_n_flags_from_tbl(priv, search_tbl,
1898 index, is_green);
1899 update_search_tbl_counter = 1;
1900 goto out;
1901 }
1902 tbl->action++;
1903 if (tbl->action > IWL_MIMO3_SWITCH_GI)
1904 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
1905
1906 if (tbl->action == start_action)
1907 break;
1908 }
1909 search_tbl->lq_type = LQ_NONE;
1910 return 0;
1911 out:
1912 lq_sta->search_better_tbl = 1;
1913 tbl->action++;
1914 if (tbl->action > IWL_MIMO3_SWITCH_GI)
1915 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
1916 if (update_search_tbl_counter)
1917 search_tbl->action = tbl->action;
1918
1589 return 0; 1919 return 0;
1590 1920
1591} 1921}
@@ -1616,8 +1946,8 @@ static void rs_stay_in_table(struct iwl_lq_sta *lq_sta)
1616 /* Elapsed time using current modulation mode */ 1946 /* Elapsed time using current modulation mode */
1617 if (lq_sta->flush_timer) 1947 if (lq_sta->flush_timer)
1618 flush_interval_passed = 1948 flush_interval_passed =
1619 time_after(jiffies, 1949 time_after(jiffies,
1620 (unsigned long)(lq_sta->flush_timer + 1950 (unsigned long)(lq_sta->flush_timer +
1621 IWL_RATE_SCALE_FLUSH_INTVL)); 1951 IWL_RATE_SCALE_FLUSH_INTVL));
1622 1952
1623 /* 1953 /*
@@ -1676,12 +2006,14 @@ static void rs_stay_in_table(struct iwl_lq_sta *lq_sta)
1676 * Do rate scaling and search for new modulation mode. 2006 * Do rate scaling and search for new modulation mode.
1677 */ 2007 */
1678static void rs_rate_scale_perform(struct iwl_priv *priv, 2008static void rs_rate_scale_perform(struct iwl_priv *priv,
1679 struct ieee80211_hdr *hdr, 2009 struct sk_buff *skb,
1680 struct ieee80211_sta *sta, 2010 struct ieee80211_sta *sta,
1681 struct iwl_lq_sta *lq_sta) 2011 struct iwl_lq_sta *lq_sta)
1682{ 2012{
1683 struct ieee80211_hw *hw = priv->hw; 2013 struct ieee80211_hw *hw = priv->hw;
1684 struct ieee80211_conf *conf = &hw->conf; 2014 struct ieee80211_conf *conf = &hw->conf;
2015 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2016 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1685 int low = IWL_RATE_INVALID; 2017 int low = IWL_RATE_INVALID;
1686 int high = IWL_RATE_INVALID; 2018 int high = IWL_RATE_INVALID;
1687 int index; 2019 int index;
@@ -1707,11 +2039,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1707 2039
1708 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n"); 2040 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n");
1709 2041
1710 /* Send management frames and broadcast/multicast data using 2042 /* Send management frames and NO_ACK data using lowest rate. */
1711 * lowest rate. */
1712 /* TODO: this could probably be improved.. */ 2043 /* TODO: this could probably be improved.. */
1713 if (!ieee80211_is_data(hdr->frame_control) || 2044 if (!ieee80211_is_data(hdr->frame_control) ||
1714 is_multicast_ether_addr(hdr->addr1)) 2045 info->flags & IEEE80211_TX_CTL_NO_ACK)
1715 return; 2046 return;
1716 2047
1717 if (!sta || !lq_sta) 2048 if (!sta || !lq_sta)
@@ -1732,6 +2063,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1732 active_tbl = 1 - lq_sta->active_tbl; 2063 active_tbl = 1 - lq_sta->active_tbl;
1733 2064
1734 tbl = &(lq_sta->lq_info[active_tbl]); 2065 tbl = &(lq_sta->lq_info[active_tbl]);
2066 if (is_legacy(tbl->lq_type))
2067 lq_sta->is_green = 0;
2068 else
2069 lq_sta->is_green = rs_use_green(priv, conf);
1735 is_green = lq_sta->is_green; 2070 is_green = lq_sta->is_green;
1736 2071
1737 /* current tx rate */ 2072 /* current tx rate */
@@ -1951,6 +2286,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1951 update_lq = 1; 2286 update_lq = 1;
1952 index = low; 2287 index = low;
1953 } 2288 }
2289
1954 break; 2290 break;
1955 case 1: 2291 case 1:
1956 /* Increase starting rate, update uCode's rate table */ 2292 /* Increase starting rate, update uCode's rate table */
@@ -1997,8 +2333,10 @@ lq_update:
1997 rs_move_legacy_other(priv, lq_sta, conf, sta, index); 2333 rs_move_legacy_other(priv, lq_sta, conf, sta, index);
1998 else if (is_siso(tbl->lq_type)) 2334 else if (is_siso(tbl->lq_type))
1999 rs_move_siso_to_other(priv, lq_sta, conf, sta, index); 2335 rs_move_siso_to_other(priv, lq_sta, conf, sta, index);
2336 else if (is_mimo2(tbl->lq_type))
2337 rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index);
2000 else 2338 else
2001 rs_move_mimo_to_other(priv, lq_sta, conf, sta, index); 2339 rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index);
2002 2340
2003 /* If new "search" mode was selected, set up in uCode table */ 2341 /* If new "search" mode was selected, set up in uCode table */
2004 if (lq_sta->search_better_tbl) { 2342 if (lq_sta->search_better_tbl) {
@@ -2014,8 +2352,11 @@ lq_update:
2014 tbl->current_rate, index); 2352 tbl->current_rate, index);
2015 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); 2353 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
2016 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 2354 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2017 } 2355 } else
2356 done_search = 1;
2357 }
2018 2358
2359 if (done_search && !lq_sta->stay_in_tbl) {
2019 /* If the "active" (non-search) mode was legacy, 2360 /* If the "active" (non-search) mode was legacy,
2020 * and we've tried switching antennas, 2361 * and we've tried switching antennas,
2021 * but we haven't been able to try HT modes (not available), 2362 * but we haven't been able to try HT modes (not available),
@@ -2023,8 +2364,7 @@ lq_update:
2023 * before next round of mode comparisons. */ 2364 * before next round of mode comparisons. */
2024 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); 2365 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
2025 if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) && 2366 if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) &&
2026 lq_sta->action_counter >= 1) { 2367 lq_sta->action_counter > tbl1->max_search) {
2027 lq_sta->action_counter = 0;
2028 IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n"); 2368 IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n");
2029 rs_set_stay_in_table(priv, 1, lq_sta); 2369 rs_set_stay_in_table(priv, 1, lq_sta);
2030 } 2370 }
@@ -2033,7 +2373,7 @@ lq_update:
2033 * have been tried and compared, stay in this best modulation 2373 * have been tried and compared, stay in this best modulation
2034 * mode for a while before next round of mode comparisons. */ 2374 * mode for a while before next round of mode comparisons. */
2035 if (lq_sta->enable_counter && 2375 if (lq_sta->enable_counter &&
2036 (lq_sta->action_counter >= IWL_ACTION_LIMIT)) { 2376 (lq_sta->action_counter >= tbl1->max_search)) {
2037 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) && 2377 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
2038 (lq_sta->tx_agg_tid_en & (1 << tid)) && 2378 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
2039 (tid != MAX_TID_COUNT)) { 2379 (tid != MAX_TID_COUNT)) {
@@ -2047,20 +2387,8 @@ lq_update:
2047 lq_sta, sta); 2387 lq_sta, sta);
2048 } 2388 }
2049 } 2389 }
2050 lq_sta->action_counter = 0;
2051 rs_set_stay_in_table(priv, 0, lq_sta); 2390 rs_set_stay_in_table(priv, 0, lq_sta);
2052 } 2391 }
2053
2054 /*
2055 * Else, don't search for a new modulation mode.
2056 * Put new timestamp in stay-in-modulation-mode flush timer if:
2057 * 1) Not changing rates right now
2058 * 2) Not just finishing up a search
2059 * 3) flush timer is empty
2060 */
2061 } else {
2062 if ((!update_lq) && (!done_search) && (!lq_sta->flush_timer))
2063 lq_sta->flush_timer = jiffies;
2064 } 2392 }
2065 2393
2066out: 2394out:
@@ -2156,16 +2484,17 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2156 if (sta) 2484 if (sta)
2157 mask_bit = sta->supp_rates[sband->band]; 2485 mask_bit = sta->supp_rates[sband->band];
2158 2486
2159 /* Send management frames and broadcast/multicast data using lowest 2487 /* Send management frames and NO_ACK data using lowest rate. */
2160 * rate. */
2161 if (!ieee80211_is_data(hdr->frame_control) || 2488 if (!ieee80211_is_data(hdr->frame_control) ||
2162 is_multicast_ether_addr(hdr->addr1) || !sta || !lq_sta) { 2489 info->flags & IEEE80211_TX_CTL_NO_ACK || !sta || !lq_sta) {
2163 if (!mask_bit) 2490 if (!mask_bit)
2164 info->control.rates[0].idx = 2491 info->control.rates[0].idx =
2165 rate_lowest_index(sband, NULL); 2492 rate_lowest_index(sband, NULL);
2166 else 2493 else
2167 info->control.rates[0].idx = 2494 info->control.rates[0].idx =
2168 rate_lowest_index(sband, sta); 2495 rate_lowest_index(sband, sta);
2496 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
2497 info->control.rates[0].count = 1;
2169 return; 2498 return;
2170 } 2499 }
2171 2500
@@ -2178,8 +2507,8 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2178 if (sta_id == IWL_INVALID_STATION) { 2507 if (sta_id == IWL_INVALID_STATION) {
2179 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", 2508 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n",
2180 hdr->addr1); 2509 hdr->addr1);
2181 sta_id = iwl_add_station_flags(priv, hdr->addr1, 2510 sta_id = iwl_add_station(priv, hdr->addr1,
2182 0, CMD_ASYNC, NULL); 2511 false, CMD_ASYNC, NULL);
2183 } 2512 }
2184 if ((sta_id != IWL_INVALID_STATION)) { 2513 if ((sta_id != IWL_INVALID_STATION)) {
2185 lq_sta->lq.sta_id = sta_id; 2514 lq_sta->lq.sta_id = sta_id;
@@ -2189,12 +2518,33 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2189 } 2518 }
2190 } 2519 }
2191 2520
2192 if (rate_idx < 0 || rate_idx > IWL_RATE_COUNT) 2521 if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
2193 rate_idx = rate_lowest_index(sband, sta);
2194 else if (sband->band == IEEE80211_BAND_5GHZ)
2195 rate_idx -= IWL_FIRST_OFDM_RATE; 2522 rate_idx -= IWL_FIRST_OFDM_RATE;
2196 2523 /* 6M and 9M shared same MCS index */
2524 rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
2525 if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2526 IWL_RATE_MIMO3_6M_PLCP)
2527 rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM);
2528 else if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
2529 IWL_RATE_MIMO2_6M_PLCP)
2530 rate_idx = rate_idx + MCS_INDEX_PER_STREAM;
2531 info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
2532 if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
2533 info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI;
2534 if (lq_sta->last_rate_n_flags & RATE_MCS_DUP_MSK)
2535 info->control.rates[0].flags |= IEEE80211_TX_RC_DUP_DATA;
2536 if (lq_sta->last_rate_n_flags & RATE_MCS_FAT_MSK)
2537 info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2538 if (lq_sta->last_rate_n_flags & RATE_MCS_GF_MSK)
2539 info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD;
2540 } else {
2541 if (rate_idx < 0 || rate_idx > IWL_RATE_COUNT)
2542 rate_idx = rate_lowest_index(sband, sta);
2543 else if (sband->band == IEEE80211_BAND_5GHZ)
2544 rate_idx -= IWL_FIRST_OFDM_RATE;
2545 }
2197 info->control.rates[0].idx = rate_idx; 2546 info->control.rates[0].idx = rate_idx;
2547
2198} 2548}
2199 2549
2200static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta, 2550static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta,
@@ -2246,15 +2596,16 @@ static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
2246 2596
2247 lq_sta->ibss_sta_added = 0; 2597 lq_sta->ibss_sta_added = 0;
2248 if (priv->iw_mode == NL80211_IFTYPE_AP) { 2598 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2249 u8 sta_id = iwl_find_station(priv, sta->addr); 2599 u8 sta_id = iwl_find_station(priv,
2600 sta->addr);
2250 2601
2251 /* for IBSS the call are from tasklet */ 2602 /* for IBSS the call are from tasklet */
2252 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr); 2603 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr);
2253 2604
2254 if (sta_id == IWL_INVALID_STATION) { 2605 if (sta_id == IWL_INVALID_STATION) {
2255 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr); 2606 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr);
2256 sta_id = iwl_add_station_flags(priv, sta->addr, 2607 sta_id = iwl_add_station(priv, sta->addr, false,
2257 0, CMD_ASYNC, NULL); 2608 CMD_ASYNC, NULL);
2258 } 2609 }
2259 if ((sta_id != IWL_INVALID_STATION)) { 2610 if ((sta_id != IWL_INVALID_STATION)) {
2260 lq_sta->lq.sta_id = sta_id; 2611 lq_sta->lq.sta_id = sta_id;
@@ -2436,9 +2787,10 @@ static void rs_fill_link_cmd(const struct iwl_priv *priv,
2436 repeat_rate--; 2787 repeat_rate--;
2437 } 2788 }
2438 2789
2439 lq_cmd->agg_params.agg_frame_cnt_limit = 64; 2790 lq_cmd->agg_params.agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_MAX;
2440 lq_cmd->agg_params.agg_dis_start_th = 3; 2791 lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
2441 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000); 2792 lq_cmd->agg_params.agg_time_limit =
2793 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
2442} 2794}
2443 2795
2444static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) 2796static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
@@ -2539,6 +2891,7 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2539 char *buff; 2891 char *buff;
2540 int desc = 0; 2892 int desc = 0;
2541 int i = 0; 2893 int i = 0;
2894 int index = 0;
2542 ssize_t ret; 2895 ssize_t ret;
2543 2896
2544 struct iwl_lq_sta *lq_sta = file->private_data; 2897 struct iwl_lq_sta *lq_sta = file->private_data;
@@ -2568,8 +2921,11 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2568 ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3")); 2921 ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3"));
2569 desc += sprintf(buff+desc, " %s", 2922 desc += sprintf(buff+desc, " %s",
2570 (tbl->is_fat) ? "40MHz" : "20MHz"); 2923 (tbl->is_fat) ? "40MHz" : "20MHz");
2571 desc += sprintf(buff+desc, " %s\n", (tbl->is_SGI) ? "SGI" : ""); 2924 desc += sprintf(buff+desc, " %s %s\n", (tbl->is_SGI) ? "SGI" : "",
2925 (lq_sta->is_green) ? "GF enabled" : "");
2572 } 2926 }
2927 desc += sprintf(buff+desc, "last tx rate=0x%X\n",
2928 lq_sta->last_rate_n_flags);
2573 desc += sprintf(buff+desc, "general:" 2929 desc += sprintf(buff+desc, "general:"
2574 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n", 2930 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2575 lq_sta->lq.general_params.flags, 2931 lq_sta->lq.general_params.flags,
@@ -2590,10 +2946,19 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2590 lq_sta->lq.general_params.start_rate_index[2], 2946 lq_sta->lq.general_params.start_rate_index[2],
2591 lq_sta->lq.general_params.start_rate_index[3]); 2947 lq_sta->lq.general_params.start_rate_index[3]);
2592 2948
2593 2949 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
2594 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) 2950 index = iwl_hwrate_to_plcp_idx(
2595 desc += sprintf(buff+desc, " rate[%d] 0x%X\n", 2951 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
2596 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags)); 2952 if (is_legacy(tbl->lq_type)) {
2953 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
2954 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
2955 iwl_rate_mcs[index].mbps);
2956 } else {
2957 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps (%s)\n",
2958 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
2959 iwl_rate_mcs[index].mbps, iwl_rate_mcs[index].mcs);
2960 }
2961 }
2597 2962
2598 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); 2963 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2599 kfree(buff); 2964 kfree(buff);
@@ -2620,13 +2985,14 @@ static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
2620 return -ENOMEM; 2985 return -ENOMEM;
2621 2986
2622 for (i = 0; i < LQ_SIZE; i++) { 2987 for (i = 0; i < LQ_SIZE; i++) {
2623 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n" 2988 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d GF=%d\n"
2624 "rate=0x%X\n", 2989 "rate=0x%X\n",
2625 lq_sta->active_tbl == i ? "*" : "x", 2990 lq_sta->active_tbl == i ? "*" : "x",
2626 lq_sta->lq_info[i].lq_type, 2991 lq_sta->lq_info[i].lq_type,
2627 lq_sta->lq_info[i].is_SGI, 2992 lq_sta->lq_info[i].is_SGI,
2628 lq_sta->lq_info[i].is_fat, 2993 lq_sta->lq_info[i].is_fat,
2629 lq_sta->lq_info[i].is_dup, 2994 lq_sta->lq_info[i].is_dup,
2995 lq_sta->is_green,
2630 lq_sta->lq_info[i].current_rate); 2996 lq_sta->lq_info[i].current_rate);
2631 for (j = 0; j < IWL_RATE_COUNT; j++) { 2997 for (j = 0; j < IWL_RATE_COUNT; j++) {
2632 desc += sprintf(buff+desc, 2998 desc += sprintf(buff+desc,
@@ -2646,6 +3012,43 @@ static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
2646 .open = open_file_generic, 3012 .open = open_file_generic,
2647}; 3013};
2648 3014
3015static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
3016 char __user *user_buf, size_t count, loff_t *ppos)
3017{
3018 char buff[120];
3019 int desc = 0;
3020 ssize_t ret;
3021
3022 struct iwl_lq_sta *lq_sta = file->private_data;
3023 struct iwl_priv *priv;
3024 struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
3025
3026 priv = lq_sta->drv;
3027
3028 if (is_Ht(tbl->lq_type))
3029 desc += sprintf(buff+desc,
3030 "Bit Rate= %d Mb/s\n",
3031 tbl->expected_tpt[lq_sta->last_txrate_idx]);
3032 else
3033 desc += sprintf(buff+desc,
3034 "Bit Rate= %d Mb/s\n",
3035 iwl_rates[lq_sta->last_txrate_idx].ieee >> 1);
3036 desc += sprintf(buff+desc,
3037 "Signal Level= %d dBm\tNoise Level= %d dBm\n",
3038 priv->last_rx_rssi, priv->last_rx_noise);
3039 desc += sprintf(buff+desc,
3040 "Tsf= 0x%llx\tBeacon time= 0x%08X\n",
3041 priv->last_tsf, priv->last_beacon_time);
3042
3043 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
3044 return ret;
3045}
3046
3047static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
3048 .read = rs_sta_dbgfs_rate_scale_data_read,
3049 .open = open_file_generic,
3050};
3051
2649static void rs_add_debugfs(void *priv, void *priv_sta, 3052static void rs_add_debugfs(void *priv, void *priv_sta,
2650 struct dentry *dir) 3053 struct dentry *dir)
2651{ 3054{
@@ -2656,6 +3059,9 @@ static void rs_add_debugfs(void *priv, void *priv_sta,
2656 lq_sta->rs_sta_dbgfs_stats_table_file = 3059 lq_sta->rs_sta_dbgfs_stats_table_file =
2657 debugfs_create_file("rate_stats_table", 0600, dir, 3060 debugfs_create_file("rate_stats_table", 0600, dir,
2658 lq_sta, &rs_sta_dbgfs_stats_table_ops); 3061 lq_sta, &rs_sta_dbgfs_stats_table_ops);
3062 lq_sta->rs_sta_dbgfs_rate_scale_data_file =
3063 debugfs_create_file("rate_scale_data", 0600, dir,
3064 lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
2659 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file = 3065 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
2660 debugfs_create_u8("tx_agg_tid_enable", 0600, dir, 3066 debugfs_create_u8("tx_agg_tid_enable", 0600, dir,
2661 &lq_sta->tx_agg_tid_en); 3067 &lq_sta->tx_agg_tid_en);
@@ -2667,6 +3073,7 @@ static void rs_remove_debugfs(void *priv, void *priv_sta)
2667 struct iwl_lq_sta *lq_sta = priv_sta; 3073 struct iwl_lq_sta *lq_sta = priv_sta;
2668 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file); 3074 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
2669 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); 3075 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
3076 debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
2670 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file); 3077 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
2671} 3078}
2672#endif 3079#endif