Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 3 | * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 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 | #include <linux/kernel.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 27 | #include <linux/skbuff.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <net/mac80211.h> |
| 30 | |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/etherdevice.h> |
| 33 | #include <linux/delay.h> |
| 34 | |
| 35 | #include <linux/workqueue.h> |
| 36 | #include "rs.h" |
| 37 | #include "fw-api.h" |
| 38 | #include "sta.h" |
| 39 | #include "iwl-op-mode.h" |
| 40 | #include "mvm.h" |
| 41 | |
| 42 | #define RS_NAME "iwl-mvm-rs" |
| 43 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 44 | #define NUM_TRY_BEFORE_ANT_TOGGLE 1 |
| 45 | #define RS_LEGACY_RETRIES_PER_RATE 1 |
| 46 | #define RS_HT_VHT_RETRIES_PER_RATE 2 |
| 47 | #define RS_HT_VHT_RETRIES_PER_RATE_TW 1 |
| 48 | #define RS_INITIAL_MIMO_NUM_RATES 3 |
| 49 | #define RS_INITIAL_SISO_NUM_RATES 3 |
| 50 | #define RS_INITIAL_LEGACY_NUM_RATES LINK_QUAL_MAX_RETRY_NUM |
| 51 | #define RS_SECONDARY_LEGACY_NUM_RATES LINK_QUAL_MAX_RETRY_NUM |
| 52 | #define RS_SECONDARY_SISO_NUM_RATES 3 |
| 53 | #define RS_SECONDARY_SISO_RETRIES 1 |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 54 | |
| 55 | #define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */ |
Eyal Shapira | d17334c | 2013-11-20 02:08:12 +0200 | [diff] [blame] | 56 | #define IWL_RATE_MIN_FAILURE_TH 3 /* min failures to calc tpt */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 57 | #define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */ |
| 58 | |
| 59 | /* max allowed rate miss before sync LQ cmd */ |
| 60 | #define IWL_MISSED_RATE_MAX 15 |
Eyal Shapira | 32b0172 | 2013-11-22 09:41:38 +0200 | [diff] [blame] | 61 | #define RS_STAY_IN_COLUMN_TIMEOUT (5*HZ) |
| 62 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 63 | |
| 64 | static u8 rs_ht_to_legacy[] = { |
Eyal Shapira | da87d7d | 2013-11-28 12:27:03 +0200 | [diff] [blame] | 65 | [IWL_RATE_MCS_0_INDEX] = IWL_RATE_6M_INDEX, |
| 66 | [IWL_RATE_MCS_1_INDEX] = IWL_RATE_9M_INDEX, |
| 67 | [IWL_RATE_MCS_2_INDEX] = IWL_RATE_12M_INDEX, |
| 68 | [IWL_RATE_MCS_3_INDEX] = IWL_RATE_18M_INDEX, |
| 69 | [IWL_RATE_MCS_4_INDEX] = IWL_RATE_24M_INDEX, |
| 70 | [IWL_RATE_MCS_5_INDEX] = IWL_RATE_36M_INDEX, |
| 71 | [IWL_RATE_MCS_6_INDEX] = IWL_RATE_48M_INDEX, |
| 72 | [IWL_RATE_MCS_7_INDEX] = IWL_RATE_54M_INDEX, |
| 73 | [IWL_RATE_MCS_8_INDEX] = IWL_RATE_54M_INDEX, |
| 74 | [IWL_RATE_MCS_9_INDEX] = IWL_RATE_54M_INDEX, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | static const u8 ant_toggle_lookup[] = { |
Eliad Peller | ef4394b | 2013-07-16 18:07:20 +0300 | [diff] [blame] | 78 | [ANT_NONE] = ANT_NONE, |
| 79 | [ANT_A] = ANT_B, |
| 80 | [ANT_B] = ANT_C, |
| 81 | [ANT_AB] = ANT_BC, |
| 82 | [ANT_C] = ANT_A, |
| 83 | [ANT_AC] = ANT_AB, |
| 84 | [ANT_BC] = ANT_AC, |
| 85 | [ANT_ABC] = ANT_ABC, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 88 | #define IWL_DECLARE_RATE_INFO(r, s, rp, rn) \ |
| 89 | [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \ |
| 90 | IWL_RATE_HT_SISO_MCS_##s##_PLCP, \ |
| 91 | IWL_RATE_HT_MIMO2_MCS_##s##_PLCP, \ |
| 92 | IWL_RATE_VHT_SISO_MCS_##s##_PLCP, \ |
| 93 | IWL_RATE_VHT_MIMO2_MCS_##s##_PLCP,\ |
| 94 | IWL_RATE_##rp##M_INDEX, \ |
Eyal Shapira | ab055ce | 2013-08-04 13:10:31 +0300 | [diff] [blame] | 95 | IWL_RATE_##rn##M_INDEX } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 96 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 97 | #define IWL_DECLARE_MCS_RATE(s) \ |
| 98 | [IWL_RATE_MCS_##s##_INDEX] = { IWL_RATE_INVM_PLCP, \ |
| 99 | IWL_RATE_HT_SISO_MCS_##s##_PLCP, \ |
| 100 | IWL_RATE_HT_MIMO2_MCS_##s##_PLCP, \ |
| 101 | IWL_RATE_VHT_SISO_MCS_##s##_PLCP, \ |
| 102 | IWL_RATE_VHT_MIMO2_MCS_##s##_PLCP, \ |
| 103 | IWL_RATE_INVM_INDEX, \ |
| 104 | IWL_RATE_INVM_INDEX } |
| 105 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 106 | /* |
| 107 | * Parameter order: |
Eyal Shapira | ab055ce | 2013-08-04 13:10:31 +0300 | [diff] [blame] | 108 | * rate, ht rate, prev rate, next rate |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 109 | * |
| 110 | * If there isn't a valid next or previous rate then INV is used which |
| 111 | * maps to IWL_RATE_INVALID |
| 112 | * |
| 113 | */ |
| 114 | static const struct iwl_rs_rate_info iwl_rates[IWL_RATE_COUNT] = { |
Eyal Shapira | ab055ce | 2013-08-04 13:10:31 +0300 | [diff] [blame] | 115 | IWL_DECLARE_RATE_INFO(1, INV, INV, 2), /* 1mbps */ |
| 116 | IWL_DECLARE_RATE_INFO(2, INV, 1, 5), /* 2mbps */ |
| 117 | IWL_DECLARE_RATE_INFO(5, INV, 2, 11), /*5.5mbps */ |
| 118 | IWL_DECLARE_RATE_INFO(11, INV, 9, 12), /* 11mbps */ |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 119 | IWL_DECLARE_RATE_INFO(6, 0, 5, 11), /* 6mbps ; MCS 0 */ |
| 120 | IWL_DECLARE_RATE_INFO(9, INV, 6, 11), /* 9mbps */ |
| 121 | IWL_DECLARE_RATE_INFO(12, 1, 11, 18), /* 12mbps ; MCS 1 */ |
| 122 | IWL_DECLARE_RATE_INFO(18, 2, 12, 24), /* 18mbps ; MCS 2 */ |
| 123 | IWL_DECLARE_RATE_INFO(24, 3, 18, 36), /* 24mbps ; MCS 3 */ |
| 124 | IWL_DECLARE_RATE_INFO(36, 4, 24, 48), /* 36mbps ; MCS 4 */ |
| 125 | IWL_DECLARE_RATE_INFO(48, 5, 36, 54), /* 48mbps ; MCS 5 */ |
| 126 | IWL_DECLARE_RATE_INFO(54, 6, 48, INV), /* 54mbps ; MCS 6 */ |
| 127 | IWL_DECLARE_MCS_RATE(7), /* MCS 7 */ |
| 128 | IWL_DECLARE_MCS_RATE(8), /* MCS 8 */ |
| 129 | IWL_DECLARE_MCS_RATE(9), /* MCS 9 */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 130 | }; |
| 131 | |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 132 | enum rs_action { |
| 133 | RS_ACTION_STAY = 0, |
| 134 | RS_ACTION_DOWNSCALE = -1, |
| 135 | RS_ACTION_UPSCALE = 1, |
| 136 | }; |
| 137 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 138 | enum rs_column_mode { |
| 139 | RS_INVALID = 0, |
| 140 | RS_LEGACY, |
| 141 | RS_SISO, |
| 142 | RS_MIMO2, |
| 143 | }; |
| 144 | |
| 145 | #define MAX_NEXT_COLUMNS 5 |
| 146 | #define MAX_COLUMN_CHECKS 3 |
| 147 | |
| 148 | typedef bool (*allow_column_func_t) (struct iwl_mvm *mvm, |
| 149 | struct ieee80211_sta *sta, |
| 150 | struct iwl_scale_tbl_info *tbl); |
| 151 | |
| 152 | struct rs_tx_column { |
| 153 | enum rs_column_mode mode; |
| 154 | u8 ant; |
| 155 | bool sgi; |
| 156 | enum rs_column next_columns[MAX_NEXT_COLUMNS]; |
| 157 | allow_column_func_t checks[MAX_COLUMN_CHECKS]; |
| 158 | }; |
| 159 | |
| 160 | static bool rs_mimo_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 161 | struct iwl_scale_tbl_info *tbl) |
| 162 | { |
| 163 | if (!sta->ht_cap.ht_supported) |
| 164 | return false; |
| 165 | |
| 166 | if (sta->smps_mode == IEEE80211_SMPS_STATIC) |
| 167 | return false; |
| 168 | |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 169 | if (num_of_ant(mvm->fw->valid_tx_ant) < 2) |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 170 | return false; |
| 171 | |
| 172 | if (!iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta)) |
| 173 | return false; |
| 174 | |
| 175 | return true; |
| 176 | } |
| 177 | |
| 178 | static bool rs_siso_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 179 | struct iwl_scale_tbl_info *tbl) |
| 180 | { |
| 181 | if (!sta->ht_cap.ht_supported) |
| 182 | return false; |
| 183 | |
| 184 | return true; |
| 185 | } |
| 186 | |
| 187 | static bool rs_sgi_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 188 | struct iwl_scale_tbl_info *tbl) |
| 189 | { |
| 190 | struct rs_rate *rate = &tbl->rate; |
| 191 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
| 192 | struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; |
| 193 | |
| 194 | if (is_ht20(rate) && (ht_cap->cap & |
| 195 | IEEE80211_HT_CAP_SGI_20)) |
| 196 | return true; |
| 197 | if (is_ht40(rate) && (ht_cap->cap & |
| 198 | IEEE80211_HT_CAP_SGI_40)) |
| 199 | return true; |
| 200 | if (is_ht80(rate) && (vht_cap->cap & |
| 201 | IEEE80211_VHT_CAP_SHORT_GI_80)) |
| 202 | return true; |
| 203 | |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | static const struct rs_tx_column rs_tx_columns[] = { |
| 208 | [RS_COLUMN_LEGACY_ANT_A] = { |
| 209 | .mode = RS_LEGACY, |
| 210 | .ant = ANT_A, |
| 211 | .next_columns = { |
| 212 | RS_COLUMN_LEGACY_ANT_B, |
| 213 | RS_COLUMN_SISO_ANT_A, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 214 | RS_COLUMN_SISO_ANT_B, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 215 | RS_COLUMN_MIMO2, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 216 | RS_COLUMN_MIMO2_SGI, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 217 | }, |
| 218 | }, |
| 219 | [RS_COLUMN_LEGACY_ANT_B] = { |
| 220 | .mode = RS_LEGACY, |
| 221 | .ant = ANT_B, |
| 222 | .next_columns = { |
| 223 | RS_COLUMN_LEGACY_ANT_A, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 224 | RS_COLUMN_SISO_ANT_A, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 225 | RS_COLUMN_SISO_ANT_B, |
| 226 | RS_COLUMN_MIMO2, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 227 | RS_COLUMN_MIMO2_SGI, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 228 | }, |
| 229 | }, |
| 230 | [RS_COLUMN_SISO_ANT_A] = { |
| 231 | .mode = RS_SISO, |
| 232 | .ant = ANT_A, |
| 233 | .next_columns = { |
| 234 | RS_COLUMN_SISO_ANT_B, |
| 235 | RS_COLUMN_MIMO2, |
| 236 | RS_COLUMN_SISO_ANT_A_SGI, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 237 | RS_COLUMN_SISO_ANT_B_SGI, |
| 238 | RS_COLUMN_MIMO2_SGI, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 239 | }, |
| 240 | .checks = { |
| 241 | rs_siso_allow, |
| 242 | }, |
| 243 | }, |
| 244 | [RS_COLUMN_SISO_ANT_B] = { |
| 245 | .mode = RS_SISO, |
| 246 | .ant = ANT_B, |
| 247 | .next_columns = { |
| 248 | RS_COLUMN_SISO_ANT_A, |
| 249 | RS_COLUMN_MIMO2, |
| 250 | RS_COLUMN_SISO_ANT_B_SGI, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 251 | RS_COLUMN_SISO_ANT_A_SGI, |
| 252 | RS_COLUMN_MIMO2_SGI, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 253 | }, |
| 254 | .checks = { |
| 255 | rs_siso_allow, |
| 256 | }, |
| 257 | }, |
| 258 | [RS_COLUMN_SISO_ANT_A_SGI] = { |
| 259 | .mode = RS_SISO, |
| 260 | .ant = ANT_A, |
| 261 | .sgi = true, |
| 262 | .next_columns = { |
| 263 | RS_COLUMN_SISO_ANT_B_SGI, |
| 264 | RS_COLUMN_MIMO2_SGI, |
| 265 | RS_COLUMN_SISO_ANT_A, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 266 | RS_COLUMN_SISO_ANT_B, |
| 267 | RS_COLUMN_MIMO2, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 268 | }, |
| 269 | .checks = { |
| 270 | rs_siso_allow, |
| 271 | rs_sgi_allow, |
| 272 | }, |
| 273 | }, |
| 274 | [RS_COLUMN_SISO_ANT_B_SGI] = { |
| 275 | .mode = RS_SISO, |
| 276 | .ant = ANT_B, |
| 277 | .sgi = true, |
| 278 | .next_columns = { |
| 279 | RS_COLUMN_SISO_ANT_A_SGI, |
| 280 | RS_COLUMN_MIMO2_SGI, |
| 281 | RS_COLUMN_SISO_ANT_B, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 282 | RS_COLUMN_SISO_ANT_A, |
| 283 | RS_COLUMN_MIMO2, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 284 | }, |
| 285 | .checks = { |
| 286 | rs_siso_allow, |
| 287 | rs_sgi_allow, |
| 288 | }, |
| 289 | }, |
| 290 | [RS_COLUMN_MIMO2] = { |
| 291 | .mode = RS_MIMO2, |
| 292 | .ant = ANT_AB, |
| 293 | .next_columns = { |
| 294 | RS_COLUMN_SISO_ANT_A, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 295 | RS_COLUMN_SISO_ANT_B, |
| 296 | RS_COLUMN_SISO_ANT_A_SGI, |
| 297 | RS_COLUMN_SISO_ANT_B_SGI, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 298 | RS_COLUMN_MIMO2_SGI, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 299 | }, |
| 300 | .checks = { |
| 301 | rs_mimo_allow, |
| 302 | }, |
| 303 | }, |
| 304 | [RS_COLUMN_MIMO2_SGI] = { |
| 305 | .mode = RS_MIMO2, |
| 306 | .ant = ANT_AB, |
| 307 | .sgi = true, |
| 308 | .next_columns = { |
| 309 | RS_COLUMN_SISO_ANT_A_SGI, |
Eyal Shapira | 8930b05 | 2014-03-16 05:23:21 +0200 | [diff] [blame] | 310 | RS_COLUMN_SISO_ANT_B_SGI, |
| 311 | RS_COLUMN_SISO_ANT_A, |
| 312 | RS_COLUMN_SISO_ANT_B, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 313 | RS_COLUMN_MIMO2, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 314 | }, |
| 315 | .checks = { |
| 316 | rs_mimo_allow, |
| 317 | rs_sgi_allow, |
| 318 | }, |
| 319 | }, |
| 320 | }; |
| 321 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 322 | static inline u8 rs_extract_rate(u32 rate_n_flags) |
| 323 | { |
| 324 | /* also works for HT because bits 7:6 are zero there */ |
| 325 | return (u8)(rate_n_flags & RATE_LEGACY_RATE_MSK); |
| 326 | } |
| 327 | |
| 328 | static int iwl_hwrate_to_plcp_idx(u32 rate_n_flags) |
| 329 | { |
| 330 | int idx = 0; |
| 331 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 332 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 333 | idx = rate_n_flags & RATE_HT_MCS_RATE_CODE_MSK; |
| 334 | idx += IWL_RATE_MCS_0_INDEX; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 335 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 336 | /* skip 9M not supported in HT*/ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 337 | if (idx >= IWL_RATE_9M_INDEX) |
| 338 | idx += 1; |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 339 | if ((idx >= IWL_FIRST_HT_RATE) && (idx <= IWL_LAST_HT_RATE)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 340 | return idx; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 341 | } else if (rate_n_flags & RATE_MCS_VHT_MSK) { |
| 342 | idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK; |
| 343 | idx += IWL_RATE_MCS_0_INDEX; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 344 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 345 | /* skip 9M not supported in VHT*/ |
| 346 | if (idx >= IWL_RATE_9M_INDEX) |
| 347 | idx++; |
| 348 | if ((idx >= IWL_FIRST_VHT_RATE) && (idx <= IWL_LAST_VHT_RATE)) |
| 349 | return idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 350 | } else { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 351 | /* legacy rate format, search for match in table */ |
| 352 | |
| 353 | u8 legacy_rate = rs_extract_rate(rate_n_flags); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 354 | for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++) |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 355 | if (iwl_rates[idx].plcp == legacy_rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 356 | return idx; |
| 357 | } |
| 358 | |
Eyal Shapira | 560843f | 2014-01-05 21:04:19 +0200 | [diff] [blame] | 359 | return IWL_RATE_INVALID; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static void rs_rate_scale_perform(struct iwl_mvm *mvm, |
| 363 | struct sk_buff *skb, |
| 364 | struct ieee80211_sta *sta, |
| 365 | struct iwl_lq_sta *lq_sta); |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 366 | static void rs_fill_lq_cmd(struct iwl_mvm *mvm, |
| 367 | struct ieee80211_sta *sta, |
| 368 | struct iwl_lq_sta *lq_sta, |
| 369 | const struct rs_rate *initial_rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 370 | static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 371 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 372 | /** |
| 373 | * The following tables contain the expected throughput metrics for all rates |
| 374 | * |
| 375 | * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits |
| 376 | * |
| 377 | * where invalid entries are zeros. |
| 378 | * |
| 379 | * CCK rates are only valid in legacy table and will only be used in G |
| 380 | * (2.4 GHz) band. |
| 381 | */ |
| 382 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 383 | static const u16 expected_tpt_legacy[IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 384 | 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0, 0, 0 |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 385 | }; |
| 386 | |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 387 | /* Expected TpT tables. 4 indexes: |
| 388 | * 0 - NGI, 1 - SGI, 2 - AGG+NGI, 3 - AGG+SGI |
| 389 | */ |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 390 | static const u16 expected_tpt_siso_20MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 391 | {0, 0, 0, 0, 42, 0, 76, 102, 124, 159, 183, 193, 202, 216, 0}, |
| 392 | {0, 0, 0, 0, 46, 0, 82, 110, 132, 168, 192, 202, 210, 225, 0}, |
| 393 | {0, 0, 0, 0, 49, 0, 97, 145, 192, 285, 375, 420, 464, 551, 0}, |
| 394 | {0, 0, 0, 0, 54, 0, 108, 160, 213, 315, 415, 465, 513, 608, 0}, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 395 | }; |
| 396 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 397 | static const u16 expected_tpt_siso_40MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 398 | {0, 0, 0, 0, 77, 0, 127, 160, 184, 220, 242, 250, 257, 269, 275}, |
| 399 | {0, 0, 0, 0, 83, 0, 135, 169, 193, 229, 250, 257, 264, 275, 280}, |
| 400 | {0, 0, 0, 0, 101, 0, 199, 295, 389, 570, 744, 828, 911, 1070, 1173}, |
| 401 | {0, 0, 0, 0, 112, 0, 220, 326, 429, 629, 819, 912, 1000, 1173, 1284}, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 402 | }; |
| 403 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 404 | static const u16 expected_tpt_siso_80MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 405 | {0, 0, 0, 0, 130, 0, 191, 223, 244, 273, 288, 294, 298, 305, 308}, |
| 406 | {0, 0, 0, 0, 138, 0, 200, 231, 251, 279, 293, 298, 302, 308, 312}, |
| 407 | {0, 0, 0, 0, 217, 0, 429, 634, 834, 1220, 1585, 1760, 1931, 2258, 2466}, |
| 408 | {0, 0, 0, 0, 241, 0, 475, 701, 921, 1343, 1741, 1931, 2117, 2468, 2691}, |
| 409 | }; |
| 410 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 411 | static const u16 expected_tpt_mimo2_20MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 412 | {0, 0, 0, 0, 74, 0, 123, 155, 179, 213, 235, 243, 250, 261, 0}, |
| 413 | {0, 0, 0, 0, 81, 0, 131, 164, 187, 221, 242, 250, 256, 267, 0}, |
| 414 | {0, 0, 0, 0, 98, 0, 193, 286, 375, 550, 718, 799, 878, 1032, 0}, |
| 415 | {0, 0, 0, 0, 109, 0, 214, 316, 414, 607, 790, 879, 965, 1132, 0}, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 416 | }; |
| 417 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 418 | static const u16 expected_tpt_mimo2_40MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 419 | {0, 0, 0, 0, 123, 0, 182, 214, 235, 264, 279, 285, 289, 296, 300}, |
| 420 | {0, 0, 0, 0, 131, 0, 191, 222, 242, 270, 284, 289, 293, 300, 303}, |
| 421 | {0, 0, 0, 0, 200, 0, 390, 571, 741, 1067, 1365, 1505, 1640, 1894, 2053}, |
| 422 | {0, 0, 0, 0, 221, 0, 430, 630, 816, 1169, 1490, 1641, 1784, 2053, 2221}, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 423 | }; |
| 424 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 425 | static const u16 expected_tpt_mimo2_80MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 426 | {0, 0, 0, 0, 182, 0, 240, 264, 278, 299, 308, 311, 313, 317, 319}, |
| 427 | {0, 0, 0, 0, 190, 0, 247, 269, 282, 302, 310, 313, 315, 319, 320}, |
| 428 | {0, 0, 0, 0, 428, 0, 833, 1215, 1577, 2254, 2863, 3147, 3418, 3913, 4219}, |
| 429 | {0, 0, 0, 0, 474, 0, 920, 1338, 1732, 2464, 3116, 3418, 3705, 4225, 4545}, |
| 430 | }; |
| 431 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 432 | /* mbps, mcs */ |
| 433 | static const struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = { |
| 434 | { "1", "BPSK DSSS"}, |
| 435 | { "2", "QPSK DSSS"}, |
| 436 | {"5.5", "BPSK CCK"}, |
| 437 | { "11", "QPSK CCK"}, |
| 438 | { "6", "BPSK 1/2"}, |
| 439 | { "9", "BPSK 1/2"}, |
| 440 | { "12", "QPSK 1/2"}, |
| 441 | { "18", "QPSK 3/4"}, |
| 442 | { "24", "16QAM 1/2"}, |
| 443 | { "36", "16QAM 3/4"}, |
| 444 | { "48", "64QAM 2/3"}, |
| 445 | { "54", "64QAM 3/4"}, |
| 446 | { "60", "64QAM 5/6"}, |
| 447 | }; |
| 448 | |
| 449 | #define MCS_INDEX_PER_STREAM (8) |
| 450 | |
Emmanuel Grumbach | 9d10849 | 2013-12-03 11:50:30 +0200 | [diff] [blame] | 451 | static const char *rs_pretty_ant(u8 ant) |
| 452 | { |
| 453 | static const char * const ant_name[] = { |
| 454 | [ANT_NONE] = "None", |
| 455 | [ANT_A] = "A", |
| 456 | [ANT_B] = "B", |
| 457 | [ANT_AB] = "AB", |
| 458 | [ANT_C] = "C", |
| 459 | [ANT_AC] = "AC", |
| 460 | [ANT_BC] = "BC", |
| 461 | [ANT_ABC] = "ABC", |
| 462 | }; |
| 463 | |
| 464 | if (ant > ANT_ABC) |
| 465 | return "UNKNOWN"; |
| 466 | |
| 467 | return ant_name[ant]; |
| 468 | } |
| 469 | |
| 470 | static const char *rs_pretty_lq_type(enum iwl_table_type type) |
| 471 | { |
| 472 | static const char * const lq_types[] = { |
| 473 | [LQ_NONE] = "NONE", |
| 474 | [LQ_LEGACY_A] = "LEGACY_A", |
| 475 | [LQ_LEGACY_G] = "LEGACY_G", |
| 476 | [LQ_HT_SISO] = "HT SISO", |
| 477 | [LQ_HT_MIMO2] = "HT MIMO", |
| 478 | [LQ_VHT_SISO] = "VHT SISO", |
| 479 | [LQ_VHT_MIMO2] = "VHT MIMO", |
| 480 | }; |
| 481 | |
| 482 | if (type < LQ_NONE || type >= LQ_MAX) |
| 483 | return "UNKNOWN"; |
| 484 | |
| 485 | return lq_types[type]; |
| 486 | } |
| 487 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 488 | static inline void rs_dump_rate(struct iwl_mvm *mvm, const struct rs_rate *rate, |
| 489 | const char *prefix) |
| 490 | { |
| 491 | IWL_DEBUG_RATE(mvm, "%s: (%s: %d) ANT: %s BW: %d SGI: %d\n", |
| 492 | prefix, rs_pretty_lq_type(rate->type), |
| 493 | rate->index, rs_pretty_ant(rate->ant), |
| 494 | rate->bw, rate->sgi); |
| 495 | } |
| 496 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 497 | static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window) |
| 498 | { |
| 499 | window->data = 0; |
| 500 | window->success_counter = 0; |
| 501 | window->success_ratio = IWL_INVALID_VALUE; |
| 502 | window->counter = 0; |
| 503 | window->average_tpt = IWL_INVALID_VALUE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type) |
| 507 | { |
| 508 | return (ant_type & valid_antenna) == ant_type; |
| 509 | } |
| 510 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 511 | static int rs_tl_turn_on_agg_for_tid(struct iwl_mvm *mvm, |
| 512 | struct iwl_lq_sta *lq_data, u8 tid, |
| 513 | struct ieee80211_sta *sta) |
| 514 | { |
| 515 | int ret = -EAGAIN; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 516 | |
Emmanuel Grumbach | 44cc429 | 2013-06-18 06:33:49 +0300 | [diff] [blame] | 517 | IWL_DEBUG_HT(mvm, "Starting Tx agg: STA: %pM tid: %d\n", |
| 518 | sta->addr, tid); |
| 519 | ret = ieee80211_start_tx_ba_session(sta, tid, 5000); |
| 520 | if (ret == -EAGAIN) { |
| 521 | /* |
| 522 | * driver and mac80211 is out of sync |
| 523 | * this might be cause by reloading firmware |
| 524 | * stop the tx ba session here |
| 525 | */ |
| 526 | IWL_ERR(mvm, "Fail start Tx agg on tid: %d\n", |
| 527 | tid); |
| 528 | ieee80211_stop_tx_ba_session(sta, tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 529 | } |
| 530 | return ret; |
| 531 | } |
| 532 | |
| 533 | static void rs_tl_turn_on_agg(struct iwl_mvm *mvm, u8 tid, |
| 534 | struct iwl_lq_sta *lq_data, |
| 535 | struct ieee80211_sta *sta) |
| 536 | { |
| 537 | if (tid < IWL_MAX_TID_COUNT) |
| 538 | rs_tl_turn_on_agg_for_tid(mvm, lq_data, tid, sta); |
| 539 | else |
| 540 | IWL_ERR(mvm, "tid exceeds max TID count: %d/%d\n", |
| 541 | tid, IWL_MAX_TID_COUNT); |
| 542 | } |
| 543 | |
| 544 | static inline int get_num_of_ant_from_rate(u32 rate_n_flags) |
| 545 | { |
| 546 | return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) + |
| 547 | !!(rate_n_flags & RATE_MCS_ANT_B_MSK) + |
| 548 | !!(rate_n_flags & RATE_MCS_ANT_C_MSK); |
| 549 | } |
| 550 | |
| 551 | /* |
| 552 | * Static function to get the expected throughput from an iwl_scale_tbl_info |
| 553 | * that wraps a NULL pointer check |
| 554 | */ |
| 555 | static s32 get_expected_tpt(struct iwl_scale_tbl_info *tbl, int rs_index) |
| 556 | { |
| 557 | if (tbl->expected_tpt) |
| 558 | return tbl->expected_tpt[rs_index]; |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * rs_collect_tx_data - Update the success/failure sliding window |
| 564 | * |
| 565 | * We keep a sliding window of the last 62 packets transmitted |
| 566 | * at this rate. window->data contains the bitmask of successful |
| 567 | * packets. |
| 568 | */ |
Eliad Peller | 0bd3c5a | 2014-03-10 16:07:04 +0200 | [diff] [blame^] | 569 | static int _rs_collect_tx_data(struct iwl_scale_tbl_info *tbl, |
| 570 | int scale_index, int attempts, int successes, |
| 571 | struct iwl_rate_scale_data *window) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 572 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 573 | static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1)); |
| 574 | s32 fail_count, tpt; |
| 575 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 576 | /* Get expected throughput */ |
| 577 | tpt = get_expected_tpt(tbl, scale_index); |
| 578 | |
| 579 | /* |
| 580 | * Keep track of only the latest 62 tx frame attempts in this rate's |
| 581 | * history window; anything older isn't really relevant any more. |
| 582 | * If we have filled up the sliding window, drop the oldest attempt; |
| 583 | * if the oldest attempt (highest bit in bitmap) shows "success", |
| 584 | * subtract "1" from the success counter (this is the main reason |
| 585 | * we keep these bitmaps!). |
| 586 | */ |
| 587 | while (attempts > 0) { |
| 588 | if (window->counter >= IWL_RATE_MAX_WINDOW) { |
| 589 | /* remove earliest */ |
| 590 | window->counter = IWL_RATE_MAX_WINDOW - 1; |
| 591 | |
| 592 | if (window->data & mask) { |
| 593 | window->data &= ~mask; |
| 594 | window->success_counter--; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | /* Increment frames-attempted counter */ |
| 599 | window->counter++; |
| 600 | |
| 601 | /* Shift bitmap by one frame to throw away oldest history */ |
| 602 | window->data <<= 1; |
| 603 | |
| 604 | /* Mark the most recent #successes attempts as successful */ |
| 605 | if (successes > 0) { |
| 606 | window->success_counter++; |
| 607 | window->data |= 0x1; |
| 608 | successes--; |
| 609 | } |
| 610 | |
| 611 | attempts--; |
| 612 | } |
| 613 | |
| 614 | /* Calculate current success ratio, avoid divide-by-0! */ |
| 615 | if (window->counter > 0) |
| 616 | window->success_ratio = 128 * (100 * window->success_counter) |
| 617 | / window->counter; |
| 618 | else |
| 619 | window->success_ratio = IWL_INVALID_VALUE; |
| 620 | |
| 621 | fail_count = window->counter - window->success_counter; |
| 622 | |
| 623 | /* Calculate average throughput, if we have enough history. */ |
| 624 | if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) || |
| 625 | (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH)) |
| 626 | window->average_tpt = (window->success_ratio * tpt + 64) / 128; |
| 627 | else |
| 628 | window->average_tpt = IWL_INVALID_VALUE; |
| 629 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 630 | return 0; |
| 631 | } |
| 632 | |
Eliad Peller | 0bd3c5a | 2014-03-10 16:07:04 +0200 | [diff] [blame^] | 633 | static int rs_collect_tx_data(struct iwl_scale_tbl_info *tbl, |
| 634 | int scale_index, int attempts, int successes) |
| 635 | { |
| 636 | struct iwl_rate_scale_data *window = NULL; |
| 637 | |
| 638 | if (scale_index < 0 || scale_index >= IWL_RATE_COUNT) |
| 639 | return -EINVAL; |
| 640 | |
| 641 | /* Select window for current tx bit rate */ |
| 642 | window = &(tbl->win[scale_index]); |
| 643 | |
| 644 | return _rs_collect_tx_data(tbl, scale_index, attempts, successes, |
| 645 | window); |
| 646 | } |
| 647 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 648 | /* Convert rs_rate object into ucode rate bitmask */ |
| 649 | static u32 ucode_rate_from_rs_rate(struct iwl_mvm *mvm, |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 650 | struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 651 | { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 652 | u32 ucode_rate = 0; |
| 653 | int index = rate->index; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 654 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 655 | ucode_rate |= ((rate->ant << RATE_MCS_ANT_POS) & |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 656 | RATE_MCS_ANT_ABC_MSK); |
| 657 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 658 | if (is_legacy(rate)) { |
| 659 | ucode_rate |= iwl_rates[index].plcp; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 660 | if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 661 | ucode_rate |= RATE_MCS_CCK_MSK; |
| 662 | return ucode_rate; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 663 | } |
| 664 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 665 | if (is_ht(rate)) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 666 | if (index < IWL_FIRST_HT_RATE || index > IWL_LAST_HT_RATE) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 667 | IWL_ERR(mvm, "Invalid HT rate index %d\n", index); |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 668 | index = IWL_LAST_HT_RATE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 669 | } |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 670 | ucode_rate |= RATE_MCS_HT_MSK; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 671 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 672 | if (is_ht_siso(rate)) |
| 673 | ucode_rate |= iwl_rates[index].plcp_ht_siso; |
| 674 | else if (is_ht_mimo2(rate)) |
| 675 | ucode_rate |= iwl_rates[index].plcp_ht_mimo2; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 676 | else |
Eyal Shapira | d972ab3 | 2013-07-28 23:02:45 +0000 | [diff] [blame] | 677 | WARN_ON_ONCE(1); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 678 | } else if (is_vht(rate)) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 679 | if (index < IWL_FIRST_VHT_RATE || index > IWL_LAST_VHT_RATE) { |
| 680 | IWL_ERR(mvm, "Invalid VHT rate index %d\n", index); |
| 681 | index = IWL_LAST_VHT_RATE; |
| 682 | } |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 683 | ucode_rate |= RATE_MCS_VHT_MSK; |
| 684 | if (is_vht_siso(rate)) |
| 685 | ucode_rate |= iwl_rates[index].plcp_vht_siso; |
| 686 | else if (is_vht_mimo2(rate)) |
| 687 | ucode_rate |= iwl_rates[index].plcp_vht_mimo2; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 688 | else |
| 689 | WARN_ON_ONCE(1); |
| 690 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 691 | } else { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 692 | IWL_ERR(mvm, "Invalid rate->type %d\n", rate->type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 693 | } |
| 694 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 695 | ucode_rate |= rate->bw; |
| 696 | if (rate->sgi) |
| 697 | ucode_rate |= RATE_MCS_SGI_MSK; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 698 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 699 | return ucode_rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 700 | } |
| 701 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 702 | /* Convert a ucode rate into an rs_rate object */ |
| 703 | static int rs_rate_from_ucode_rate(const u32 ucode_rate, |
| 704 | enum ieee80211_band band, |
| 705 | struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 706 | { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 707 | u32 ant_msk = ucode_rate & RATE_MCS_ANT_ABC_MSK; |
| 708 | u8 num_of_ant = get_num_of_ant_from_rate(ucode_rate); |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 709 | u8 nss; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 710 | |
Emmanuel Grumbach | 9e898f1 | 2013-12-22 10:55:47 +0200 | [diff] [blame] | 711 | memset(rate, 0, sizeof(*rate)); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 712 | rate->index = iwl_hwrate_to_plcp_idx(ucode_rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 713 | |
Eyal Shapira | 560843f | 2014-01-05 21:04:19 +0200 | [diff] [blame] | 714 | if (rate->index == IWL_RATE_INVALID) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 715 | return -EINVAL; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 716 | |
| 717 | rate->ant = (ant_msk >> RATE_MCS_ANT_POS); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 718 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 719 | /* Legacy */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 720 | if (!(ucode_rate & RATE_MCS_HT_MSK) && |
| 721 | !(ucode_rate & RATE_MCS_VHT_MSK)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 722 | if (num_of_ant == 1) { |
| 723 | if (band == IEEE80211_BAND_5GHZ) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 724 | rate->type = LQ_LEGACY_A; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 725 | else |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 726 | rate->type = LQ_LEGACY_G; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 727 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 728 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 729 | return 0; |
| 730 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 731 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 732 | /* HT or VHT */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 733 | if (ucode_rate & RATE_MCS_SGI_MSK) |
| 734 | rate->sgi = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 735 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 736 | rate->bw = ucode_rate & RATE_MCS_CHAN_WIDTH_MSK; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 737 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 738 | if (ucode_rate & RATE_MCS_HT_MSK) { |
| 739 | nss = ((ucode_rate & RATE_HT_MCS_NSS_MSK) >> |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 740 | RATE_HT_MCS_NSS_POS) + 1; |
| 741 | |
| 742 | if (nss == 1) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 743 | rate->type = LQ_HT_SISO; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 744 | WARN_ON_ONCE(num_of_ant != 1); |
| 745 | } else if (nss == 2) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 746 | rate->type = LQ_HT_MIMO2; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 747 | WARN_ON_ONCE(num_of_ant != 2); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 748 | } else { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 749 | WARN_ON_ONCE(1); |
| 750 | } |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 751 | } else if (ucode_rate & RATE_MCS_VHT_MSK) { |
| 752 | nss = ((ucode_rate & RATE_VHT_MCS_NSS_MSK) >> |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 753 | RATE_VHT_MCS_NSS_POS) + 1; |
| 754 | |
| 755 | if (nss == 1) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 756 | rate->type = LQ_VHT_SISO; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 757 | WARN_ON_ONCE(num_of_ant != 1); |
| 758 | } else if (nss == 2) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 759 | rate->type = LQ_VHT_MIMO2; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 760 | WARN_ON_ONCE(num_of_ant != 2); |
| 761 | } else { |
| 762 | WARN_ON_ONCE(1); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 763 | } |
| 764 | } |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 765 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 766 | WARN_ON_ONCE(rate->bw == RATE_MCS_CHAN_WIDTH_160); |
| 767 | WARN_ON_ONCE(rate->bw == RATE_MCS_CHAN_WIDTH_80 && |
| 768 | !is_vht(rate)); |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 769 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | /* switch to another antenna/antennas and return 1 */ |
| 774 | /* if no other valid antenna found, return 0 */ |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 775 | static int rs_toggle_antenna(u32 valid_ant, struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 776 | { |
| 777 | u8 new_ant_type; |
| 778 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 779 | if (!rate->ant || rate->ant > ANT_ABC) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 780 | return 0; |
| 781 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 782 | if (!rs_is_valid_ant(valid_ant, rate->ant)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 783 | return 0; |
| 784 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 785 | new_ant_type = ant_toggle_lookup[rate->ant]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 786 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 787 | while ((new_ant_type != rate->ant) && |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 788 | !rs_is_valid_ant(valid_ant, new_ant_type)) |
| 789 | new_ant_type = ant_toggle_lookup[new_ant_type]; |
| 790 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 791 | if (new_ant_type == rate->ant) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 792 | return 0; |
| 793 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 794 | rate->ant = new_ant_type; |
| 795 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 796 | return 1; |
| 797 | } |
| 798 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 799 | static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta, |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 800 | struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 801 | { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 802 | if (is_legacy(rate)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 803 | return lq_sta->active_legacy_rate; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 804 | else if (is_siso(rate)) |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 805 | return lq_sta->active_siso_rate; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 806 | else if (is_mimo2(rate)) |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 807 | return lq_sta->active_mimo2_rate; |
| 808 | |
| 809 | WARN_ON_ONCE(1); |
| 810 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | static u16 rs_get_adjacent_rate(struct iwl_mvm *mvm, u8 index, u16 rate_mask, |
| 814 | int rate_type) |
| 815 | { |
| 816 | u8 high = IWL_RATE_INVALID; |
| 817 | u8 low = IWL_RATE_INVALID; |
| 818 | |
| 819 | /* 802.11A or ht walks to the next literal adjacent rate in |
| 820 | * the rate table */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 821 | if (is_type_a_band(rate_type) || !is_type_legacy(rate_type)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 822 | int i; |
| 823 | u32 mask; |
| 824 | |
| 825 | /* Find the previous rate that is in the rate mask */ |
| 826 | i = index - 1; |
| 827 | for (mask = (1 << i); i >= 0; i--, mask >>= 1) { |
| 828 | if (rate_mask & mask) { |
| 829 | low = i; |
| 830 | break; |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | /* Find the next rate that is in the rate mask */ |
| 835 | i = index + 1; |
| 836 | for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) { |
| 837 | if (rate_mask & mask) { |
| 838 | high = i; |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | return (high << 8) | low; |
| 844 | } |
| 845 | |
| 846 | low = index; |
| 847 | while (low != IWL_RATE_INVALID) { |
| 848 | low = iwl_rates[low].prev_rs; |
| 849 | if (low == IWL_RATE_INVALID) |
| 850 | break; |
| 851 | if (rate_mask & (1 << low)) |
| 852 | break; |
| 853 | IWL_DEBUG_RATE(mvm, "Skipping masked lower rate: %d\n", low); |
| 854 | } |
| 855 | |
| 856 | high = index; |
| 857 | while (high != IWL_RATE_INVALID) { |
| 858 | high = iwl_rates[high].next_rs; |
| 859 | if (high == IWL_RATE_INVALID) |
| 860 | break; |
| 861 | if (rate_mask & (1 << high)) |
| 862 | break; |
| 863 | IWL_DEBUG_RATE(mvm, "Skipping masked higher rate: %d\n", high); |
| 864 | } |
| 865 | |
| 866 | return (high << 8) | low; |
| 867 | } |
| 868 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 869 | static inline bool rs_rate_supported(struct iwl_lq_sta *lq_sta, |
| 870 | struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 871 | { |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 872 | return BIT(rate->index) & rs_get_supported_rates(lq_sta, rate); |
| 873 | } |
| 874 | |
| 875 | /* Get the next supported lower rate in the current column. |
| 876 | * Return true if bottom rate in the current column was reached |
| 877 | */ |
| 878 | static bool rs_get_lower_rate_in_column(struct iwl_lq_sta *lq_sta, |
| 879 | struct rs_rate *rate) |
| 880 | { |
| 881 | u8 low; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 882 | u16 high_low; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 883 | u16 rate_mask; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 884 | struct iwl_mvm *mvm = lq_sta->drv; |
| 885 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 886 | rate_mask = rs_get_supported_rates(lq_sta, rate); |
| 887 | high_low = rs_get_adjacent_rate(mvm, rate->index, rate_mask, |
| 888 | rate->type); |
| 889 | low = high_low & 0xff; |
| 890 | |
| 891 | /* Bottom rate of column reached */ |
| 892 | if (low == IWL_RATE_INVALID) |
| 893 | return true; |
| 894 | |
| 895 | rate->index = low; |
| 896 | return false; |
| 897 | } |
| 898 | |
| 899 | /* Get the next rate to use following a column downgrade */ |
| 900 | static void rs_get_lower_rate_down_column(struct iwl_lq_sta *lq_sta, |
| 901 | struct rs_rate *rate) |
| 902 | { |
| 903 | struct iwl_mvm *mvm = lq_sta->drv; |
| 904 | |
| 905 | if (is_legacy(rate)) { |
| 906 | /* No column to downgrade from Legacy */ |
| 907 | return; |
| 908 | } else if (is_siso(rate)) { |
| 909 | /* Downgrade to Legacy if we were in SISO */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 910 | if (lq_sta->band == IEEE80211_BAND_5GHZ) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 911 | rate->type = LQ_LEGACY_A; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 912 | else |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 913 | rate->type = LQ_LEGACY_G; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 914 | |
Eyal Shapira | a56db7d | 2013-11-28 12:35:42 +0200 | [diff] [blame] | 915 | rate->bw = RATE_MCS_CHAN_WIDTH_20; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 916 | |
Emmanuel Grumbach | b800040 | 2014-02-03 22:17:19 +0200 | [diff] [blame] | 917 | WARN_ON_ONCE(rate->index < IWL_RATE_MCS_0_INDEX || |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 918 | rate->index > IWL_RATE_MCS_9_INDEX); |
| 919 | |
| 920 | rate->index = rs_ht_to_legacy[rate->index]; |
| 921 | } else { |
| 922 | /* Downgrade to SISO with same MCS if in MIMO */ |
| 923 | rate->type = is_vht_mimo2(rate) ? |
| 924 | LQ_VHT_SISO : LQ_HT_SISO; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 925 | } |
| 926 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 927 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 928 | if (num_of_ant(rate->ant) > 1) |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 929 | rate->ant = first_antenna(mvm->fw->valid_tx_ant); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 930 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 931 | /* Relevant in both switching to SISO or Legacy */ |
| 932 | rate->sgi = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 933 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 934 | if (!rs_rate_supported(lq_sta, rate)) |
| 935 | rs_get_lower_rate_in_column(lq_sta, rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 936 | } |
| 937 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 938 | /* Simple function to compare two rate scale table types */ |
| 939 | static inline bool rs_rate_match(struct rs_rate *a, |
| 940 | struct rs_rate *b) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 941 | { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 942 | return (a->type == b->type) && (a->ant == b->ant) && (a->sgi == b->sgi); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 943 | } |
| 944 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 945 | static u32 rs_ch_width_from_mac_flags(enum mac80211_rate_control_flags flags) |
| 946 | { |
| 947 | if (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
| 948 | return RATE_MCS_CHAN_WIDTH_40; |
| 949 | else if (flags & IEEE80211_TX_RC_80_MHZ_WIDTH) |
| 950 | return RATE_MCS_CHAN_WIDTH_80; |
| 951 | else if (flags & IEEE80211_TX_RC_160_MHZ_WIDTH) |
| 952 | return RATE_MCS_CHAN_WIDTH_160; |
| 953 | |
| 954 | return RATE_MCS_CHAN_WIDTH_20; |
| 955 | } |
| 956 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 957 | /* |
| 958 | * mac80211 sends us Tx status |
| 959 | */ |
| 960 | static void rs_tx_status(void *mvm_r, struct ieee80211_supported_band *sband, |
| 961 | struct ieee80211_sta *sta, void *priv_sta, |
| 962 | struct sk_buff *skb) |
| 963 | { |
| 964 | int legacy_success; |
| 965 | int retries; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 966 | int mac_index, i; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 967 | struct iwl_lq_sta *lq_sta = priv_sta; |
| 968 | struct iwl_lq_cmd *table; |
| 969 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 970 | struct iwl_op_mode *op_mode = (struct iwl_op_mode *)mvm_r; |
| 971 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); |
| 972 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 973 | enum mac80211_rate_control_flags mac_flags; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 974 | u32 ucode_rate; |
| 975 | struct rs_rate rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 976 | struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl; |
| 977 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 978 | /* Treat uninitialized rate scaling data same as non-existing. */ |
| 979 | if (!lq_sta) { |
| 980 | IWL_DEBUG_RATE(mvm, "Station rate scaling not created yet.\n"); |
| 981 | return; |
| 982 | } else if (!lq_sta->drv) { |
| 983 | IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n"); |
| 984 | return; |
| 985 | } |
| 986 | |
| 987 | if (!ieee80211_is_data(hdr->frame_control) || |
| 988 | info->flags & IEEE80211_TX_CTL_NO_ACK) |
| 989 | return; |
| 990 | |
| 991 | /* This packet was aggregated but doesn't carry status info */ |
| 992 | if ((info->flags & IEEE80211_TX_CTL_AMPDU) && |
| 993 | !(info->flags & IEEE80211_TX_STAT_AMPDU)) |
| 994 | return; |
| 995 | |
| 996 | /* |
| 997 | * Ignore this Tx frame response if its initial rate doesn't match |
| 998 | * that of latest Link Quality command. There may be stragglers |
| 999 | * from a previous Link Quality command, but we're no longer interested |
| 1000 | * in those; they're either from the "active" mode while we're trying |
| 1001 | * to check "search" mode, or a prior "search" mode after we've moved |
| 1002 | * to a new "search" mode (which might become the new "active" mode). |
| 1003 | */ |
| 1004 | table = &lq_sta->lq; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1005 | ucode_rate = le32_to_cpu(table->rs_table[0]); |
| 1006 | rs_rate_from_ucode_rate(ucode_rate, info->band, &rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1007 | if (info->band == IEEE80211_BAND_5GHZ) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1008 | rate.index -= IWL_FIRST_OFDM_RATE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1009 | mac_flags = info->status.rates[0].flags; |
| 1010 | mac_index = info->status.rates[0].idx; |
| 1011 | /* For HT packets, map MCS to PLCP */ |
| 1012 | if (mac_flags & IEEE80211_TX_RC_MCS) { |
| 1013 | /* Remove # of streams */ |
| 1014 | mac_index &= RATE_HT_MCS_RATE_CODE_MSK; |
| 1015 | if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE)) |
| 1016 | mac_index++; |
| 1017 | /* |
| 1018 | * mac80211 HT index is always zero-indexed; we need to move |
| 1019 | * HT OFDM rates after CCK rates in 2.4 GHz band |
| 1020 | */ |
| 1021 | if (info->band == IEEE80211_BAND_2GHZ) |
| 1022 | mac_index += IWL_FIRST_OFDM_RATE; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1023 | } else if (mac_flags & IEEE80211_TX_RC_VHT_MCS) { |
| 1024 | mac_index &= RATE_VHT_MCS_RATE_CODE_MSK; |
| 1025 | if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE)) |
| 1026 | mac_index++; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1027 | } |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1028 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1029 | /* Here we actually compare this rate to the latest LQ command */ |
| 1030 | if ((mac_index < 0) || |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1031 | (rate.sgi != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI)) || |
| 1032 | (rate.bw != rs_ch_width_from_mac_flags(mac_flags)) || |
| 1033 | (rate.ant != info->status.antenna) || |
| 1034 | (!!(ucode_rate & RATE_MCS_HT_MSK) != |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1035 | !!(mac_flags & IEEE80211_TX_RC_MCS)) || |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1036 | (!!(ucode_rate & RATE_MCS_VHT_MSK) != |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1037 | !!(mac_flags & IEEE80211_TX_RC_VHT_MCS)) || |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1038 | (!!(ucode_rate & RATE_HT_MCS_GF_MSK) != |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1039 | !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD)) || |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1040 | (rate.index != mac_index)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1041 | IWL_DEBUG_RATE(mvm, |
| 1042 | "initial rate %d does not match %d (0x%x)\n", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1043 | mac_index, rate.index, ucode_rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1044 | /* |
| 1045 | * Since rates mis-match, the last LQ command may have failed. |
| 1046 | * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with |
| 1047 | * ... driver. |
| 1048 | */ |
| 1049 | lq_sta->missed_rate_counter++; |
| 1050 | if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) { |
| 1051 | lq_sta->missed_rate_counter = 0; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1052 | IWL_DEBUG_RATE(mvm, |
| 1053 | "Too many rates mismatch. Send sync LQ. rs_state %d\n", |
| 1054 | lq_sta->rs_state); |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 1055 | iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1056 | } |
| 1057 | /* Regardless, ignore this status info for outdated rate */ |
| 1058 | return; |
| 1059 | } else |
| 1060 | /* Rate did match, so reset the missed_rate_counter */ |
| 1061 | lq_sta->missed_rate_counter = 0; |
| 1062 | |
| 1063 | /* Figure out if rate scale algorithm is in active or search table */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1064 | if (rs_rate_match(&rate, |
| 1065 | &(lq_sta->lq_info[lq_sta->active_tbl].rate))) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1066 | curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1067 | other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1068 | } else if (rs_rate_match(&rate, |
| 1069 | &lq_sta->lq_info[1 - lq_sta->active_tbl].rate)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1070 | curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); |
| 1071 | other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1072 | } else { |
| 1073 | IWL_DEBUG_RATE(mvm, |
| 1074 | "Neither active nor search matches tx rate\n"); |
| 1075 | tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1076 | rs_dump_rate(mvm, &tmp_tbl->rate, "ACTIVE"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1077 | tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1078 | rs_dump_rate(mvm, &tmp_tbl->rate, "SEARCH"); |
| 1079 | rs_dump_rate(mvm, &rate, "ACTUAL"); |
| 1080 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1081 | /* |
| 1082 | * no matching table found, let's by-pass the data collection |
| 1083 | * and continue to perform rate scale to find the rate table |
| 1084 | */ |
| 1085 | rs_stay_in_table(lq_sta, true); |
| 1086 | goto done; |
| 1087 | } |
| 1088 | |
| 1089 | /* |
| 1090 | * Updating the frame history depends on whether packets were |
| 1091 | * aggregated. |
| 1092 | * |
| 1093 | * For aggregation, all packets were transmitted at the same rate, the |
| 1094 | * first index into rate scale table. |
| 1095 | */ |
| 1096 | if (info->flags & IEEE80211_TX_STAT_AMPDU) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1097 | ucode_rate = le32_to_cpu(table->rs_table[0]); |
| 1098 | rs_rate_from_ucode_rate(ucode_rate, info->band, &rate); |
| 1099 | rs_collect_tx_data(curr_tbl, rate.index, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1100 | info->status.ampdu_len, |
| 1101 | info->status.ampdu_ack_len); |
| 1102 | |
| 1103 | /* Update success/fail counts if not searching for new mode */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1104 | if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1105 | lq_sta->total_success += info->status.ampdu_ack_len; |
| 1106 | lq_sta->total_failed += (info->status.ampdu_len - |
| 1107 | info->status.ampdu_ack_len); |
| 1108 | } |
| 1109 | } else { |
| 1110 | /* |
| 1111 | * For legacy, update frame history with for each Tx retry. |
| 1112 | */ |
| 1113 | retries = info->status.rates[0].count - 1; |
| 1114 | /* HW doesn't send more than 15 retries */ |
| 1115 | retries = min(retries, 15); |
| 1116 | |
| 1117 | /* The last transmission may have been successful */ |
| 1118 | legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK); |
| 1119 | /* Collect data for each rate used during failed TX attempts */ |
| 1120 | for (i = 0; i <= retries; ++i) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1121 | ucode_rate = le32_to_cpu(table->rs_table[i]); |
| 1122 | rs_rate_from_ucode_rate(ucode_rate, info->band, &rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1123 | /* |
| 1124 | * Only collect stats if retried rate is in the same RS |
| 1125 | * table as active/search. |
| 1126 | */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1127 | if (rs_rate_match(&rate, &curr_tbl->rate)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1128 | tmp_tbl = curr_tbl; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1129 | else if (rs_rate_match(&rate, &other_tbl->rate)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1130 | tmp_tbl = other_tbl; |
Eyal Shapira | 4107dbd | 2013-12-10 12:20:37 +0200 | [diff] [blame] | 1131 | else |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1132 | continue; |
Eyal Shapira | 4107dbd | 2013-12-10 12:20:37 +0200 | [diff] [blame] | 1133 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1134 | rs_collect_tx_data(tmp_tbl, rate.index, 1, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1135 | i < retries ? 0 : legacy_success); |
| 1136 | } |
| 1137 | |
| 1138 | /* Update success/fail counts if not searching for new mode */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1139 | if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1140 | lq_sta->total_success += legacy_success; |
| 1141 | lq_sta->total_failed += retries + (1 - legacy_success); |
| 1142 | } |
| 1143 | } |
| 1144 | /* The last TX rate is cached in lq_sta; it's set in if/else above */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1145 | lq_sta->last_rate_n_flags = ucode_rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1146 | done: |
| 1147 | /* See if there's a better rate or modulation mode to try. */ |
| 1148 | if (sta && sta->supp_rates[sband->band]) |
| 1149 | rs_rate_scale_perform(mvm, skb, sta, lq_sta); |
| 1150 | } |
| 1151 | |
| 1152 | /* |
| 1153 | * Begin a period of staying with a selected modulation mode. |
| 1154 | * Set "stay_in_tbl" flag to prevent any mode switches. |
| 1155 | * Set frame tx success limits according to legacy vs. high-throughput, |
| 1156 | * and reset overall (spanning all rates) tx success history statistics. |
| 1157 | * These control how long we stay using same modulation mode before |
| 1158 | * searching for a new mode. |
| 1159 | */ |
| 1160 | static void rs_set_stay_in_table(struct iwl_mvm *mvm, u8 is_legacy, |
| 1161 | struct iwl_lq_sta *lq_sta) |
| 1162 | { |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1163 | IWL_DEBUG_RATE(mvm, "Moving to RS_STATE_STAY_IN_COLUMN\n"); |
| 1164 | lq_sta->rs_state = RS_STATE_STAY_IN_COLUMN; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1165 | if (is_legacy) { |
| 1166 | lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT; |
| 1167 | lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT; |
| 1168 | lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT; |
| 1169 | } else { |
| 1170 | lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT; |
| 1171 | lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT; |
| 1172 | lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT; |
| 1173 | } |
| 1174 | lq_sta->table_count = 0; |
| 1175 | lq_sta->total_failed = 0; |
| 1176 | lq_sta->total_success = 0; |
| 1177 | lq_sta->flush_timer = jiffies; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1178 | lq_sta->visited_columns = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1179 | } |
| 1180 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 1181 | static const u16 *rs_get_expected_tpt_table(struct iwl_lq_sta *lq_sta, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1182 | const struct rs_tx_column *column, |
| 1183 | u32 bw) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1184 | { |
| 1185 | /* Used to choose among HT tables */ |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 1186 | const u16 (*ht_tbl_pointer)[IWL_RATE_COUNT]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1187 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1188 | if (WARN_ON_ONCE(column->mode != RS_LEGACY && |
| 1189 | column->mode != RS_SISO && |
| 1190 | column->mode != RS_MIMO2)) |
| 1191 | return expected_tpt_legacy; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1192 | |
| 1193 | /* Legacy rates have only one table */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1194 | if (column->mode == RS_LEGACY) |
| 1195 | return expected_tpt_legacy; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1196 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1197 | ht_tbl_pointer = expected_tpt_mimo2_20MHz; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1198 | /* Choose among many HT tables depending on number of streams |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1199 | * (SISO/MIMO2), channel width (20/40/80), SGI, and aggregation |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1200 | * status */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1201 | if (column->mode == RS_SISO) { |
| 1202 | switch (bw) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1203 | case RATE_MCS_CHAN_WIDTH_20: |
| 1204 | ht_tbl_pointer = expected_tpt_siso_20MHz; |
| 1205 | break; |
| 1206 | case RATE_MCS_CHAN_WIDTH_40: |
| 1207 | ht_tbl_pointer = expected_tpt_siso_40MHz; |
| 1208 | break; |
| 1209 | case RATE_MCS_CHAN_WIDTH_80: |
| 1210 | ht_tbl_pointer = expected_tpt_siso_80MHz; |
| 1211 | break; |
| 1212 | default: |
| 1213 | WARN_ON_ONCE(1); |
| 1214 | } |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1215 | } else if (column->mode == RS_MIMO2) { |
| 1216 | switch (bw) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1217 | case RATE_MCS_CHAN_WIDTH_20: |
| 1218 | ht_tbl_pointer = expected_tpt_mimo2_20MHz; |
| 1219 | break; |
| 1220 | case RATE_MCS_CHAN_WIDTH_40: |
| 1221 | ht_tbl_pointer = expected_tpt_mimo2_40MHz; |
| 1222 | break; |
| 1223 | case RATE_MCS_CHAN_WIDTH_80: |
| 1224 | ht_tbl_pointer = expected_tpt_mimo2_80MHz; |
| 1225 | break; |
| 1226 | default: |
| 1227 | WARN_ON_ONCE(1); |
| 1228 | } |
| 1229 | } else { |
| 1230 | WARN_ON_ONCE(1); |
Eyal Shapira | d972ab3 | 2013-07-28 23:02:45 +0000 | [diff] [blame] | 1231 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1232 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1233 | if (!column->sgi && !lq_sta->is_agg) /* Normal */ |
| 1234 | return ht_tbl_pointer[0]; |
| 1235 | else if (column->sgi && !lq_sta->is_agg) /* SGI */ |
| 1236 | return ht_tbl_pointer[1]; |
| 1237 | else if (!column->sgi && lq_sta->is_agg) /* AGG */ |
| 1238 | return ht_tbl_pointer[2]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1239 | else /* AGG+SGI */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1240 | return ht_tbl_pointer[3]; |
| 1241 | } |
| 1242 | |
| 1243 | static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta, |
| 1244 | struct iwl_scale_tbl_info *tbl) |
| 1245 | { |
| 1246 | struct rs_rate *rate = &tbl->rate; |
| 1247 | const struct rs_tx_column *column = &rs_tx_columns[tbl->column]; |
| 1248 | |
| 1249 | tbl->expected_tpt = rs_get_expected_tpt_table(lq_sta, column, rate->bw); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | /* |
| 1253 | * Find starting rate for new "search" high-throughput mode of modulation. |
| 1254 | * Goal is to find lowest expected rate (under perfect conditions) that is |
| 1255 | * above the current measured throughput of "active" mode, to give new mode |
| 1256 | * a fair chance to prove itself without too many challenges. |
| 1257 | * |
| 1258 | * This gets called when transitioning to more aggressive modulation |
| 1259 | * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive |
| 1260 | * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need |
| 1261 | * to decrease to match "active" throughput. When moving from MIMO to SISO, |
| 1262 | * bit rate will typically need to increase, but not if performance was bad. |
| 1263 | */ |
| 1264 | static s32 rs_get_best_rate(struct iwl_mvm *mvm, |
| 1265 | struct iwl_lq_sta *lq_sta, |
| 1266 | struct iwl_scale_tbl_info *tbl, /* "search" */ |
| 1267 | u16 rate_mask, s8 index) |
| 1268 | { |
| 1269 | /* "active" values */ |
| 1270 | struct iwl_scale_tbl_info *active_tbl = |
| 1271 | &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1272 | s32 active_sr = active_tbl->win[index].success_ratio; |
| 1273 | s32 active_tpt = active_tbl->expected_tpt[index]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1274 | /* expected "search" throughput */ |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 1275 | const u16 *tpt_tbl = tbl->expected_tpt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1276 | |
| 1277 | s32 new_rate, high, low, start_hi; |
| 1278 | u16 high_low; |
| 1279 | s8 rate = index; |
| 1280 | |
| 1281 | new_rate = high = low = start_hi = IWL_RATE_INVALID; |
| 1282 | |
| 1283 | while (1) { |
| 1284 | high_low = rs_get_adjacent_rate(mvm, rate, rate_mask, |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1285 | tbl->rate.type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1286 | |
| 1287 | low = high_low & 0xff; |
| 1288 | high = (high_low >> 8) & 0xff; |
| 1289 | |
| 1290 | /* |
| 1291 | * Lower the "search" bit rate, to give new "search" mode |
| 1292 | * approximately the same throughput as "active" if: |
| 1293 | * |
| 1294 | * 1) "Active" mode has been working modestly well (but not |
| 1295 | * great), and expected "search" throughput (under perfect |
| 1296 | * conditions) at candidate rate is above the actual |
| 1297 | * measured "active" throughput (but less than expected |
| 1298 | * "active" throughput under perfect conditions). |
| 1299 | * OR |
| 1300 | * 2) "Active" mode has been working perfectly or very well |
| 1301 | * and expected "search" throughput (under perfect |
| 1302 | * conditions) at candidate rate is above expected |
| 1303 | * "active" throughput (under perfect conditions). |
| 1304 | */ |
| 1305 | if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) && |
Eyal Shapira | c48075d | 2013-11-21 01:18:47 +0200 | [diff] [blame] | 1306 | ((active_sr > RS_SR_FORCE_DECREASE) && |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1307 | (active_sr <= IWL_RATE_HIGH_TH) && |
| 1308 | (tpt_tbl[rate] <= active_tpt))) || |
| 1309 | ((active_sr >= IWL_RATE_SCALE_SWITCH) && |
| 1310 | (tpt_tbl[rate] > active_tpt))) { |
| 1311 | /* (2nd or later pass) |
| 1312 | * If we've already tried to raise the rate, and are |
| 1313 | * now trying to lower it, use the higher rate. */ |
| 1314 | if (start_hi != IWL_RATE_INVALID) { |
| 1315 | new_rate = start_hi; |
| 1316 | break; |
| 1317 | } |
| 1318 | |
| 1319 | new_rate = rate; |
| 1320 | |
| 1321 | /* Loop again with lower rate */ |
| 1322 | if (low != IWL_RATE_INVALID) |
| 1323 | rate = low; |
| 1324 | |
| 1325 | /* Lower rate not available, use the original */ |
| 1326 | else |
| 1327 | break; |
| 1328 | |
| 1329 | /* Else try to raise the "search" rate to match "active" */ |
| 1330 | } else { |
| 1331 | /* (2nd or later pass) |
| 1332 | * If we've already tried to lower the rate, and are |
| 1333 | * now trying to raise it, use the lower rate. */ |
| 1334 | if (new_rate != IWL_RATE_INVALID) |
| 1335 | break; |
| 1336 | |
| 1337 | /* Loop again with higher rate */ |
| 1338 | else if (high != IWL_RATE_INVALID) { |
| 1339 | start_hi = high; |
| 1340 | rate = high; |
| 1341 | |
| 1342 | /* Higher rate not available, use the original */ |
| 1343 | } else { |
| 1344 | new_rate = rate; |
| 1345 | break; |
| 1346 | } |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | return new_rate; |
| 1351 | } |
| 1352 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1353 | static u32 rs_bw_from_sta_bw(struct ieee80211_sta *sta) |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1354 | { |
| 1355 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_80) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1356 | return RATE_MCS_CHAN_WIDTH_80; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1357 | else if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1358 | return RATE_MCS_CHAN_WIDTH_40; |
| 1359 | |
| 1360 | return RATE_MCS_CHAN_WIDTH_20; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1361 | } |
| 1362 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1363 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1364 | * Check whether we should continue using same modulation mode, or |
| 1365 | * begin search for a new mode, based on: |
| 1366 | * 1) # tx successes or failures while using this mode |
| 1367 | * 2) # times calling this function |
| 1368 | * 3) elapsed time in this mode (not used, for now) |
| 1369 | */ |
| 1370 | static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search) |
| 1371 | { |
| 1372 | struct iwl_scale_tbl_info *tbl; |
| 1373 | int i; |
| 1374 | int active_tbl; |
| 1375 | int flush_interval_passed = 0; |
| 1376 | struct iwl_mvm *mvm; |
| 1377 | |
| 1378 | mvm = lq_sta->drv; |
| 1379 | active_tbl = lq_sta->active_tbl; |
| 1380 | |
| 1381 | tbl = &(lq_sta->lq_info[active_tbl]); |
| 1382 | |
| 1383 | /* If we've been disallowing search, see if we should now allow it */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1384 | if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1385 | /* Elapsed time using current modulation mode */ |
| 1386 | if (lq_sta->flush_timer) |
| 1387 | flush_interval_passed = |
| 1388 | time_after(jiffies, |
| 1389 | (unsigned long)(lq_sta->flush_timer + |
Eyal Shapira | 32b0172 | 2013-11-22 09:41:38 +0200 | [diff] [blame] | 1390 | RS_STAY_IN_COLUMN_TIMEOUT)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1391 | |
| 1392 | /* |
| 1393 | * Check if we should allow search for new modulation mode. |
| 1394 | * If many frames have failed or succeeded, or we've used |
| 1395 | * this same modulation for a long time, allow search, and |
| 1396 | * reset history stats that keep track of whether we should |
| 1397 | * allow a new search. Also (below) reset all bitmaps and |
| 1398 | * stats in active history. |
| 1399 | */ |
| 1400 | if (force_search || |
| 1401 | (lq_sta->total_failed > lq_sta->max_failure_limit) || |
| 1402 | (lq_sta->total_success > lq_sta->max_success_limit) || |
| 1403 | ((!lq_sta->search_better_tbl) && |
| 1404 | (lq_sta->flush_timer) && (flush_interval_passed))) { |
| 1405 | IWL_DEBUG_RATE(mvm, |
| 1406 | "LQ: stay is expired %d %d %d\n", |
| 1407 | lq_sta->total_failed, |
| 1408 | lq_sta->total_success, |
| 1409 | flush_interval_passed); |
| 1410 | |
| 1411 | /* Allow search for new mode */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1412 | lq_sta->rs_state = RS_STATE_SEARCH_CYCLE_STARTED; |
| 1413 | IWL_DEBUG_RATE(mvm, |
| 1414 | "Moving to RS_STATE_SEARCH_CYCLE_STARTED\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1415 | lq_sta->total_failed = 0; |
| 1416 | lq_sta->total_success = 0; |
| 1417 | lq_sta->flush_timer = 0; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1418 | /* mark the current column as visited */ |
| 1419 | lq_sta->visited_columns = BIT(tbl->column); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1420 | /* |
| 1421 | * Else if we've used this modulation mode enough repetitions |
| 1422 | * (regardless of elapsed time or success/failure), reset |
| 1423 | * history bitmaps and rate-specific stats for all rates in |
| 1424 | * active table. |
| 1425 | */ |
| 1426 | } else { |
| 1427 | lq_sta->table_count++; |
| 1428 | if (lq_sta->table_count >= |
| 1429 | lq_sta->table_count_limit) { |
| 1430 | lq_sta->table_count = 0; |
| 1431 | |
| 1432 | IWL_DEBUG_RATE(mvm, |
| 1433 | "LQ: stay in table clear win\n"); |
| 1434 | for (i = 0; i < IWL_RATE_COUNT; i++) |
| 1435 | rs_rate_scale_clear_window( |
| 1436 | &(tbl->win[i])); |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | /* If transitioning to allow "search", reset all history |
| 1441 | * bitmaps and stats in active table (this will become the new |
| 1442 | * "search" table). */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1443 | if (lq_sta->rs_state == RS_STATE_SEARCH_CYCLE_STARTED) { |
| 1444 | IWL_DEBUG_RATE(mvm, "Clearing up window stats\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1445 | for (i = 0; i < IWL_RATE_COUNT; i++) |
| 1446 | rs_rate_scale_clear_window(&(tbl->win[i])); |
| 1447 | } |
| 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | /* |
| 1452 | * setup rate table in uCode |
| 1453 | */ |
| 1454 | static void rs_update_rate_tbl(struct iwl_mvm *mvm, |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 1455 | struct ieee80211_sta *sta, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1456 | struct iwl_lq_sta *lq_sta, |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1457 | struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1458 | { |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 1459 | rs_fill_lq_cmd(mvm, sta, lq_sta, rate); |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 1460 | iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1461 | } |
| 1462 | |
Eyal Shapira | 977342b | 2013-07-28 23:02:44 +0000 | [diff] [blame] | 1463 | static u8 rs_get_tid(struct iwl_lq_sta *lq_data, |
| 1464 | struct ieee80211_hdr *hdr) |
| 1465 | { |
| 1466 | u8 tid = IWL_MAX_TID_COUNT; |
| 1467 | |
| 1468 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 1469 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
| 1470 | tid = qc[0] & 0xf; |
| 1471 | } |
| 1472 | |
| 1473 | if (unlikely(tid > IWL_MAX_TID_COUNT)) |
| 1474 | tid = IWL_MAX_TID_COUNT; |
| 1475 | |
| 1476 | return tid; |
| 1477 | } |
| 1478 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1479 | static enum rs_column rs_get_next_column(struct iwl_mvm *mvm, |
| 1480 | struct iwl_lq_sta *lq_sta, |
| 1481 | struct ieee80211_sta *sta, |
| 1482 | struct iwl_scale_tbl_info *tbl) |
| 1483 | { |
| 1484 | int i, j, n; |
| 1485 | enum rs_column next_col_id; |
| 1486 | const struct rs_tx_column *curr_col = &rs_tx_columns[tbl->column]; |
| 1487 | const struct rs_tx_column *next_col; |
| 1488 | allow_column_func_t allow_func; |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 1489 | u8 valid_ants = mvm->fw->valid_tx_ant; |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 1490 | const u16 *expected_tpt_tbl; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1491 | s32 tpt, max_expected_tpt; |
| 1492 | |
| 1493 | for (i = 0; i < MAX_NEXT_COLUMNS; i++) { |
| 1494 | next_col_id = curr_col->next_columns[i]; |
| 1495 | |
| 1496 | if (next_col_id == RS_COLUMN_INVALID) |
| 1497 | continue; |
| 1498 | |
| 1499 | if (lq_sta->visited_columns & BIT(next_col_id)) { |
| 1500 | IWL_DEBUG_RATE(mvm, "Skip already visited column %d\n", |
| 1501 | next_col_id); |
| 1502 | continue; |
| 1503 | } |
| 1504 | |
| 1505 | next_col = &rs_tx_columns[next_col_id]; |
| 1506 | |
| 1507 | if (!rs_is_valid_ant(valid_ants, next_col->ant)) { |
| 1508 | IWL_DEBUG_RATE(mvm, |
| 1509 | "Skip column %d as ANT config isn't supported by chip. valid_ants 0x%x column ant 0x%x\n", |
| 1510 | next_col_id, valid_ants, next_col->ant); |
| 1511 | continue; |
| 1512 | } |
| 1513 | |
| 1514 | for (j = 0; j < MAX_COLUMN_CHECKS; j++) { |
| 1515 | allow_func = next_col->checks[j]; |
| 1516 | if (allow_func && !allow_func(mvm, sta, tbl)) |
| 1517 | break; |
| 1518 | } |
| 1519 | |
| 1520 | if (j != MAX_COLUMN_CHECKS) { |
| 1521 | IWL_DEBUG_RATE(mvm, |
| 1522 | "Skip column %d: not allowed (check %d failed)\n", |
| 1523 | next_col_id, j); |
| 1524 | |
| 1525 | continue; |
| 1526 | } |
| 1527 | |
| 1528 | tpt = lq_sta->last_tpt / 100; |
| 1529 | expected_tpt_tbl = rs_get_expected_tpt_table(lq_sta, next_col, |
| 1530 | tbl->rate.bw); |
| 1531 | if (WARN_ON_ONCE(!expected_tpt_tbl)) |
| 1532 | continue; |
| 1533 | |
| 1534 | max_expected_tpt = 0; |
| 1535 | for (n = 0; n < IWL_RATE_COUNT; n++) |
| 1536 | if (expected_tpt_tbl[n] > max_expected_tpt) |
| 1537 | max_expected_tpt = expected_tpt_tbl[n]; |
| 1538 | |
| 1539 | if (tpt >= max_expected_tpt) { |
| 1540 | IWL_DEBUG_RATE(mvm, |
| 1541 | "Skip column %d: can't beat current TPT. Max expected %d current %d\n", |
| 1542 | next_col_id, max_expected_tpt, tpt); |
| 1543 | continue; |
| 1544 | } |
| 1545 | |
| 1546 | break; |
| 1547 | } |
| 1548 | |
| 1549 | if (i == MAX_NEXT_COLUMNS) |
| 1550 | return RS_COLUMN_INVALID; |
| 1551 | |
| 1552 | IWL_DEBUG_RATE(mvm, "Found potential column %d\n", next_col_id); |
| 1553 | |
| 1554 | return next_col_id; |
| 1555 | } |
| 1556 | |
| 1557 | static int rs_switch_to_column(struct iwl_mvm *mvm, |
| 1558 | struct iwl_lq_sta *lq_sta, |
| 1559 | struct ieee80211_sta *sta, |
| 1560 | enum rs_column col_id) |
| 1561 | { |
| 1562 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1563 | struct iwl_scale_tbl_info *search_tbl = |
| 1564 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
| 1565 | struct rs_rate *rate = &search_tbl->rate; |
| 1566 | const struct rs_tx_column *column = &rs_tx_columns[col_id]; |
| 1567 | const struct rs_tx_column *curr_column = &rs_tx_columns[tbl->column]; |
| 1568 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - |
| 1569 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); |
| 1570 | u16 rate_mask = 0; |
| 1571 | u32 rate_idx = 0; |
| 1572 | |
| 1573 | memcpy(search_tbl, tbl, sz); |
| 1574 | |
| 1575 | rate->sgi = column->sgi; |
| 1576 | rate->ant = column->ant; |
| 1577 | |
| 1578 | if (column->mode == RS_LEGACY) { |
| 1579 | if (lq_sta->band == IEEE80211_BAND_5GHZ) |
| 1580 | rate->type = LQ_LEGACY_A; |
| 1581 | else |
| 1582 | rate->type = LQ_LEGACY_G; |
| 1583 | |
| 1584 | rate_mask = lq_sta->active_legacy_rate; |
| 1585 | } else if (column->mode == RS_SISO) { |
| 1586 | rate->type = lq_sta->is_vht ? LQ_VHT_SISO : LQ_HT_SISO; |
| 1587 | rate_mask = lq_sta->active_siso_rate; |
| 1588 | } else if (column->mode == RS_MIMO2) { |
| 1589 | rate->type = lq_sta->is_vht ? LQ_VHT_MIMO2 : LQ_HT_MIMO2; |
| 1590 | rate_mask = lq_sta->active_mimo2_rate; |
| 1591 | } else { |
| 1592 | WARN_ON_ONCE("Bad column mode"); |
| 1593 | } |
| 1594 | |
| 1595 | rate->bw = rs_bw_from_sta_bw(sta); |
| 1596 | search_tbl->column = col_id; |
| 1597 | rs_set_expected_tpt_table(lq_sta, search_tbl); |
| 1598 | |
Eyal Shapira | 75d3e2d | 2014-01-07 18:19:35 +0200 | [diff] [blame] | 1599 | lq_sta->visited_columns |= BIT(col_id); |
| 1600 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1601 | /* Get the best matching rate if we're changing modes. e.g. |
| 1602 | * SISO->MIMO, LEGACY->SISO, MIMO->SISO |
| 1603 | */ |
| 1604 | if (curr_column->mode != column->mode) { |
| 1605 | rate_idx = rs_get_best_rate(mvm, lq_sta, search_tbl, |
| 1606 | rate_mask, rate->index); |
| 1607 | |
| 1608 | if ((rate_idx == IWL_RATE_INVALID) || |
| 1609 | !(BIT(rate_idx) & rate_mask)) { |
| 1610 | IWL_DEBUG_RATE(mvm, |
| 1611 | "can not switch with index %d" |
| 1612 | " rate mask %x\n", |
| 1613 | rate_idx, rate_mask); |
| 1614 | |
| 1615 | goto err; |
| 1616 | } |
| 1617 | |
| 1618 | rate->index = rate_idx; |
| 1619 | } |
| 1620 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1621 | IWL_DEBUG_RATE(mvm, "Switched to column %d: Index %d\n", |
| 1622 | col_id, rate->index); |
| 1623 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1624 | return 0; |
| 1625 | |
| 1626 | err: |
| 1627 | rate->type = LQ_NONE; |
| 1628 | return -1; |
| 1629 | } |
| 1630 | |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1631 | static enum rs_action rs_get_rate_action(struct iwl_mvm *mvm, |
| 1632 | struct iwl_scale_tbl_info *tbl, |
| 1633 | s32 sr, int low, int high, |
| 1634 | int current_tpt, |
| 1635 | int low_tpt, int high_tpt) |
| 1636 | { |
| 1637 | enum rs_action action = RS_ACTION_STAY; |
| 1638 | |
| 1639 | /* Too many failures, decrease rate */ |
| 1640 | if ((sr <= RS_SR_FORCE_DECREASE) || (current_tpt == 0)) { |
| 1641 | IWL_DEBUG_RATE(mvm, |
| 1642 | "decrease rate because of low SR\n"); |
| 1643 | action = RS_ACTION_DOWNSCALE; |
| 1644 | /* No throughput measured yet for adjacent rates; try increase. */ |
| 1645 | } else if ((low_tpt == IWL_INVALID_VALUE) && |
| 1646 | (high_tpt == IWL_INVALID_VALUE)) { |
| 1647 | if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH) { |
| 1648 | IWL_DEBUG_RATE(mvm, |
| 1649 | "Good SR and no high rate measurement. " |
| 1650 | "Increase rate\n"); |
| 1651 | action = RS_ACTION_UPSCALE; |
| 1652 | } else if (low != IWL_RATE_INVALID) { |
| 1653 | IWL_DEBUG_RATE(mvm, |
| 1654 | "Remain in current rate\n"); |
| 1655 | action = RS_ACTION_STAY; |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | /* Both adjacent throughputs are measured, but neither one has better |
| 1660 | * throughput; we're using the best rate, don't change it! |
| 1661 | */ |
| 1662 | else if ((low_tpt != IWL_INVALID_VALUE) && |
| 1663 | (high_tpt != IWL_INVALID_VALUE) && |
| 1664 | (low_tpt < current_tpt) && |
| 1665 | (high_tpt < current_tpt)) { |
| 1666 | IWL_DEBUG_RATE(mvm, |
| 1667 | "Both high and low are worse. " |
| 1668 | "Maintain rate\n"); |
| 1669 | action = RS_ACTION_STAY; |
| 1670 | } |
| 1671 | |
| 1672 | /* At least one adjacent rate's throughput is measured, |
| 1673 | * and may have better performance. |
| 1674 | */ |
| 1675 | else { |
| 1676 | /* Higher adjacent rate's throughput is measured */ |
| 1677 | if (high_tpt != IWL_INVALID_VALUE) { |
| 1678 | /* Higher rate has better throughput */ |
| 1679 | if (high_tpt > current_tpt && |
| 1680 | sr >= IWL_RATE_INCREASE_TH) { |
| 1681 | IWL_DEBUG_RATE(mvm, |
| 1682 | "Higher rate is better and good " |
| 1683 | "SR. Increate rate\n"); |
| 1684 | action = RS_ACTION_UPSCALE; |
| 1685 | } else { |
| 1686 | IWL_DEBUG_RATE(mvm, |
| 1687 | "Higher rate isn't better OR " |
| 1688 | "no good SR. Maintain rate\n"); |
| 1689 | action = RS_ACTION_STAY; |
| 1690 | } |
| 1691 | |
| 1692 | /* Lower adjacent rate's throughput is measured */ |
| 1693 | } else if (low_tpt != IWL_INVALID_VALUE) { |
| 1694 | /* Lower rate has better throughput */ |
| 1695 | if (low_tpt > current_tpt) { |
| 1696 | IWL_DEBUG_RATE(mvm, |
| 1697 | "Lower rate is better. " |
| 1698 | "Decrease rate\n"); |
| 1699 | action = RS_ACTION_DOWNSCALE; |
| 1700 | } else if (sr >= IWL_RATE_INCREASE_TH) { |
| 1701 | IWL_DEBUG_RATE(mvm, |
| 1702 | "Lower rate isn't better and " |
| 1703 | "good SR. Increase rate\n"); |
| 1704 | action = RS_ACTION_UPSCALE; |
| 1705 | } |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | /* Sanity check; asked for decrease, but success rate or throughput |
| 1710 | * has been good at old rate. Don't change it. |
| 1711 | */ |
| 1712 | if ((action == RS_ACTION_DOWNSCALE) && (low != IWL_RATE_INVALID) && |
| 1713 | ((sr > IWL_RATE_HIGH_TH) || |
| 1714 | (current_tpt > (100 * tbl->expected_tpt[low])))) { |
| 1715 | IWL_DEBUG_RATE(mvm, |
| 1716 | "Sanity check failed. Maintain rate\n"); |
| 1717 | action = RS_ACTION_STAY; |
| 1718 | } |
| 1719 | |
| 1720 | return action; |
| 1721 | } |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1722 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1723 | /* |
| 1724 | * Do rate scaling and search for new modulation mode. |
| 1725 | */ |
| 1726 | static void rs_rate_scale_perform(struct iwl_mvm *mvm, |
| 1727 | struct sk_buff *skb, |
| 1728 | struct ieee80211_sta *sta, |
| 1729 | struct iwl_lq_sta *lq_sta) |
| 1730 | { |
| 1731 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1732 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1733 | int low = IWL_RATE_INVALID; |
| 1734 | int high = IWL_RATE_INVALID; |
| 1735 | int index; |
| 1736 | int i; |
| 1737 | struct iwl_rate_scale_data *window = NULL; |
| 1738 | int current_tpt = IWL_INVALID_VALUE; |
| 1739 | int low_tpt = IWL_INVALID_VALUE; |
| 1740 | int high_tpt = IWL_INVALID_VALUE; |
| 1741 | u32 fail_count; |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1742 | enum rs_action scale_action = RS_ACTION_STAY; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1743 | u16 rate_mask; |
| 1744 | u8 update_lq = 0; |
| 1745 | struct iwl_scale_tbl_info *tbl, *tbl1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1746 | u8 active_tbl = 0; |
| 1747 | u8 done_search = 0; |
| 1748 | u16 high_low; |
| 1749 | s32 sr; |
| 1750 | u8 tid = IWL_MAX_TID_COUNT; |
Eyal Shapira | 9d015a0 | 2013-11-21 01:12:11 +0200 | [diff] [blame] | 1751 | u8 prev_agg = lq_sta->is_agg; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1752 | struct iwl_mvm_sta *sta_priv = (void *)sta->drv_priv; |
| 1753 | struct iwl_mvm_tid_data *tid_data; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1754 | struct rs_rate *rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1755 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1756 | /* Send management frames and NO_ACK data using lowest rate. */ |
| 1757 | /* TODO: this could probably be improved.. */ |
| 1758 | if (!ieee80211_is_data(hdr->frame_control) || |
| 1759 | info->flags & IEEE80211_TX_CTL_NO_ACK) |
| 1760 | return; |
| 1761 | |
Eyal Shapira | 977342b | 2013-07-28 23:02:44 +0000 | [diff] [blame] | 1762 | tid = rs_get_tid(lq_sta, hdr); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1763 | if ((tid != IWL_MAX_TID_COUNT) && |
| 1764 | (lq_sta->tx_agg_tid_en & (1 << tid))) { |
| 1765 | tid_data = &sta_priv->tid_data[tid]; |
| 1766 | if (tid_data->state == IWL_AGG_OFF) |
| 1767 | lq_sta->is_agg = 0; |
| 1768 | else |
| 1769 | lq_sta->is_agg = 1; |
| 1770 | } else { |
| 1771 | lq_sta->is_agg = 0; |
| 1772 | } |
| 1773 | |
| 1774 | /* |
| 1775 | * Select rate-scale / modulation-mode table to work with in |
| 1776 | * the rest of this function: "search" if searching for better |
| 1777 | * modulation mode, or "active" if doing rate scaling within a mode. |
| 1778 | */ |
| 1779 | if (!lq_sta->search_better_tbl) |
| 1780 | active_tbl = lq_sta->active_tbl; |
| 1781 | else |
| 1782 | active_tbl = 1 - lq_sta->active_tbl; |
| 1783 | |
| 1784 | tbl = &(lq_sta->lq_info[active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1785 | rate = &tbl->rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1786 | |
Eyal Shapira | 9d015a0 | 2013-11-21 01:12:11 +0200 | [diff] [blame] | 1787 | if (prev_agg != lq_sta->is_agg) { |
| 1788 | IWL_DEBUG_RATE(mvm, |
| 1789 | "Aggregation changed: prev %d current %d. Update expected TPT table\n", |
| 1790 | prev_agg, lq_sta->is_agg); |
| 1791 | rs_set_expected_tpt_table(lq_sta, tbl); |
| 1792 | } |
| 1793 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1794 | /* current tx rate */ |
| 1795 | index = lq_sta->last_txrate_idx; |
| 1796 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1797 | /* rates available for this association, and for modulation mode */ |
Eyal Shapira | a8ff14f | 2013-11-23 01:30:44 +0200 | [diff] [blame] | 1798 | rate_mask = rs_get_supported_rates(lq_sta, rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1799 | |
Eyal Shapira | ca6f38f | 2013-12-09 11:14:11 +0200 | [diff] [blame] | 1800 | if (!(BIT(index) & rate_mask)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1801 | IWL_ERR(mvm, "Current Rate is not valid\n"); |
| 1802 | if (lq_sta->search_better_tbl) { |
| 1803 | /* revert to active table if search table is not valid*/ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1804 | rate->type = LQ_NONE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1805 | lq_sta->search_better_tbl = 0; |
| 1806 | tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1807 | rs_update_rate_tbl(mvm, sta, lq_sta, &tbl->rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1808 | } |
| 1809 | return; |
| 1810 | } |
| 1811 | |
| 1812 | /* Get expected throughput table and history window for current rate */ |
| 1813 | if (!tbl->expected_tpt) { |
| 1814 | IWL_ERR(mvm, "tbl->expected_tpt is NULL\n"); |
| 1815 | return; |
| 1816 | } |
| 1817 | |
| 1818 | /* force user max rate if set by user */ |
| 1819 | if ((lq_sta->max_rate_idx != -1) && |
| 1820 | (lq_sta->max_rate_idx < index)) { |
| 1821 | index = lq_sta->max_rate_idx; |
| 1822 | update_lq = 1; |
| 1823 | window = &(tbl->win[index]); |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1824 | IWL_DEBUG_RATE(mvm, |
| 1825 | "Forcing user max rate %d\n", |
| 1826 | index); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1827 | goto lq_update; |
| 1828 | } |
| 1829 | |
| 1830 | window = &(tbl->win[index]); |
| 1831 | |
| 1832 | /* |
| 1833 | * If there is not enough history to calculate actual average |
| 1834 | * throughput, keep analyzing results of more tx frames, without |
| 1835 | * changing rate or mode (bypass most of the rest of this function). |
| 1836 | * Set up new rate table in uCode only if old rate is not supported |
| 1837 | * in current association (use new rate found above). |
| 1838 | */ |
| 1839 | fail_count = window->counter - window->success_counter; |
| 1840 | if ((fail_count < IWL_RATE_MIN_FAILURE_TH) && |
| 1841 | (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) { |
| 1842 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1843 | "(%s: %d): Test Window: succ %d total %d\n", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1844 | rs_pretty_lq_type(rate->type), |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1845 | index, window->success_counter, window->counter); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1846 | |
| 1847 | /* Can't calculate this yet; not enough history */ |
| 1848 | window->average_tpt = IWL_INVALID_VALUE; |
| 1849 | |
| 1850 | /* Should we stay with this modulation mode, |
| 1851 | * or search for a new one? */ |
| 1852 | rs_stay_in_table(lq_sta, false); |
| 1853 | |
| 1854 | goto out; |
| 1855 | } |
| 1856 | /* Else we have enough samples; calculate estimate of |
| 1857 | * actual average throughput */ |
| 1858 | if (window->average_tpt != ((window->success_ratio * |
| 1859 | tbl->expected_tpt[index] + 64) / 128)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1860 | window->average_tpt = ((window->success_ratio * |
| 1861 | tbl->expected_tpt[index] + 64) / 128); |
| 1862 | } |
| 1863 | |
| 1864 | /* If we are searching for better modulation mode, check success. */ |
| 1865 | if (lq_sta->search_better_tbl) { |
| 1866 | /* If good success, continue using the "search" mode; |
| 1867 | * no need to send new link quality command, since we're |
| 1868 | * continuing to use the setup that we've been trying. */ |
| 1869 | if (window->average_tpt > lq_sta->last_tpt) { |
| 1870 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1871 | "SWITCHING TO NEW TABLE SR: %d " |
| 1872 | "cur-tpt %d old-tpt %d\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1873 | window->success_ratio, |
| 1874 | window->average_tpt, |
| 1875 | lq_sta->last_tpt); |
| 1876 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1877 | /* Swap tables; "search" becomes "active" */ |
| 1878 | lq_sta->active_tbl = active_tbl; |
| 1879 | current_tpt = window->average_tpt; |
| 1880 | /* Else poor success; go back to mode in "active" table */ |
| 1881 | } else { |
| 1882 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1883 | "GOING BACK TO THE OLD TABLE: SR %d " |
| 1884 | "cur-tpt %d old-tpt %d\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1885 | window->success_ratio, |
| 1886 | window->average_tpt, |
| 1887 | lq_sta->last_tpt); |
| 1888 | |
| 1889 | /* Nullify "search" table */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1890 | rate->type = LQ_NONE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1891 | |
| 1892 | /* Revert to "active" table */ |
| 1893 | active_tbl = lq_sta->active_tbl; |
| 1894 | tbl = &(lq_sta->lq_info[active_tbl]); |
| 1895 | |
| 1896 | /* Revert to "active" rate and throughput info */ |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 1897 | index = tbl->rate.index; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1898 | current_tpt = lq_sta->last_tpt; |
| 1899 | |
| 1900 | /* Need to set up a new rate table in uCode */ |
| 1901 | update_lq = 1; |
| 1902 | } |
| 1903 | |
| 1904 | /* Either way, we've made a decision; modulation mode |
| 1905 | * search is done, allow rate adjustment next time. */ |
| 1906 | lq_sta->search_better_tbl = 0; |
| 1907 | done_search = 1; /* Don't switch modes below! */ |
| 1908 | goto lq_update; |
| 1909 | } |
| 1910 | |
| 1911 | /* (Else) not in search of better modulation mode, try for better |
| 1912 | * starting rate, while staying in this mode. */ |
Eyal Shapira | ca6f38f | 2013-12-09 11:14:11 +0200 | [diff] [blame] | 1913 | high_low = rs_get_adjacent_rate(mvm, index, rate_mask, rate->type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1914 | low = high_low & 0xff; |
| 1915 | high = (high_low >> 8) & 0xff; |
| 1916 | |
| 1917 | /* If user set max rate, dont allow higher than user constrain */ |
| 1918 | if ((lq_sta->max_rate_idx != -1) && |
| 1919 | (lq_sta->max_rate_idx < high)) |
| 1920 | high = IWL_RATE_INVALID; |
| 1921 | |
| 1922 | sr = window->success_ratio; |
| 1923 | |
| 1924 | /* Collect measured throughputs for current and adjacent rates */ |
| 1925 | current_tpt = window->average_tpt; |
| 1926 | if (low != IWL_RATE_INVALID) |
| 1927 | low_tpt = tbl->win[low].average_tpt; |
| 1928 | if (high != IWL_RATE_INVALID) |
| 1929 | high_tpt = tbl->win[high].average_tpt; |
| 1930 | |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1931 | IWL_DEBUG_RATE(mvm, |
| 1932 | "(%s: %d): cur_tpt %d SR %d low %d high %d low_tpt %d high_tpt %d\n", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1933 | rs_pretty_lq_type(rate->type), index, current_tpt, sr, |
| 1934 | low, high, low_tpt, high_tpt); |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1935 | |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1936 | scale_action = rs_get_rate_action(mvm, tbl, sr, low, high, |
| 1937 | current_tpt, low_tpt, high_tpt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1938 | |
Eyal Shapira | 393b9e5 | 2013-11-13 16:46:19 +0200 | [diff] [blame] | 1939 | /* Force a search in case BT doesn't like us being in MIMO */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1940 | if (is_mimo(rate) && |
Eyal Shapira | 393b9e5 | 2013-11-13 16:46:19 +0200 | [diff] [blame] | 1941 | !iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta)) { |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1942 | IWL_DEBUG_RATE(mvm, |
| 1943 | "BT Coex forbids MIMO. Search for new config\n"); |
Emmanuel Grumbach | 36946ce | 2013-05-28 23:12:47 +0300 | [diff] [blame] | 1944 | rs_stay_in_table(lq_sta, true); |
| 1945 | goto lq_update; |
| 1946 | } |
| 1947 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1948 | switch (scale_action) { |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1949 | case RS_ACTION_DOWNSCALE: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1950 | /* Decrease starting rate, update uCode's rate table */ |
| 1951 | if (low != IWL_RATE_INVALID) { |
| 1952 | update_lq = 1; |
| 1953 | index = low; |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1954 | } else { |
| 1955 | IWL_DEBUG_RATE(mvm, |
| 1956 | "At the bottom rate. Can't decrease\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | break; |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1960 | case RS_ACTION_UPSCALE: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1961 | /* Increase starting rate, update uCode's rate table */ |
| 1962 | if (high != IWL_RATE_INVALID) { |
| 1963 | update_lq = 1; |
| 1964 | index = high; |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 1965 | } else { |
| 1966 | IWL_DEBUG_RATE(mvm, |
| 1967 | "At the top rate. Can't increase\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | break; |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1971 | case RS_ACTION_STAY: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1972 | /* No change */ |
| 1973 | default: |
| 1974 | break; |
| 1975 | } |
| 1976 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1977 | lq_update: |
| 1978 | /* Replace uCode's rate table for the destination station. */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1979 | if (update_lq) { |
| 1980 | tbl->rate.index = index; |
| 1981 | rs_update_rate_tbl(mvm, sta, lq_sta, &tbl->rate); |
| 1982 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1983 | |
| 1984 | rs_stay_in_table(lq_sta, false); |
| 1985 | |
| 1986 | /* |
| 1987 | * Search for new modulation mode if we're: |
| 1988 | * 1) Not changing rates right now |
| 1989 | * 2) Not just finishing up a search |
| 1990 | * 3) Allowing a new search |
| 1991 | */ |
| 1992 | if (!update_lq && !done_search && |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1993 | lq_sta->rs_state == RS_STATE_SEARCH_CYCLE_STARTED |
| 1994 | && window->counter) { |
| 1995 | enum rs_column next_column; |
| 1996 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1997 | /* Save current throughput to compare with "search" throughput*/ |
| 1998 | lq_sta->last_tpt = current_tpt; |
| 1999 | |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2000 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2001 | "Start Search: update_lq %d done_search %d rs_state %d win->counter %d\n", |
| 2002 | update_lq, done_search, lq_sta->rs_state, |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2003 | window->counter); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2004 | |
| 2005 | next_column = rs_get_next_column(mvm, lq_sta, sta, tbl); |
| 2006 | if (next_column != RS_COLUMN_INVALID) { |
| 2007 | int ret = rs_switch_to_column(mvm, lq_sta, sta, |
| 2008 | next_column); |
| 2009 | if (!ret) |
| 2010 | lq_sta->search_better_tbl = 1; |
| 2011 | } else { |
| 2012 | IWL_DEBUG_RATE(mvm, |
| 2013 | "No more columns to explore in search cycle. Go to RS_STATE_SEARCH_CYCLE_ENDED\n"); |
| 2014 | lq_sta->rs_state = RS_STATE_SEARCH_CYCLE_ENDED; |
| 2015 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2016 | |
| 2017 | /* If new "search" mode was selected, set up in uCode table */ |
| 2018 | if (lq_sta->search_better_tbl) { |
| 2019 | /* Access the "search" table, clear its history. */ |
| 2020 | tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
| 2021 | for (i = 0; i < IWL_RATE_COUNT; i++) |
| 2022 | rs_rate_scale_clear_window(&(tbl->win[i])); |
| 2023 | |
| 2024 | /* Use new "search" start rate */ |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2025 | index = tbl->rate.index; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2026 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2027 | rs_dump_rate(mvm, &tbl->rate, |
| 2028 | "Switch to SEARCH TABLE:"); |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2029 | rs_fill_lq_cmd(mvm, sta, lq_sta, &tbl->rate); |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 2030 | iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2031 | } else { |
| 2032 | done_search = 1; |
| 2033 | } |
| 2034 | } |
| 2035 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2036 | if (done_search && lq_sta->rs_state == RS_STATE_SEARCH_CYCLE_ENDED) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2037 | /* If the "active" (non-search) mode was legacy, |
| 2038 | * and we've tried switching antennas, |
| 2039 | * but we haven't been able to try HT modes (not available), |
| 2040 | * stay with best antenna legacy modulation for a while |
| 2041 | * before next round of mode comparisons. */ |
| 2042 | tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2043 | if (is_legacy(&tbl1->rate) && !sta->ht_cap.ht_supported) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2044 | IWL_DEBUG_RATE(mvm, "LQ: STAY in legacy table\n"); |
| 2045 | rs_set_stay_in_table(mvm, 1, lq_sta); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2046 | } else { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2047 | /* If we're in an HT mode, and all 3 mode switch actions |
| 2048 | * have been tried and compared, stay in this best modulation |
| 2049 | * mode for a while before next round of mode comparisons. */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2050 | if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) && |
| 2051 | (lq_sta->tx_agg_tid_en & (1 << tid)) && |
| 2052 | (tid != IWL_MAX_TID_COUNT)) { |
| 2053 | tid_data = &sta_priv->tid_data[tid]; |
| 2054 | if (tid_data->state == IWL_AGG_OFF) { |
| 2055 | IWL_DEBUG_RATE(mvm, |
| 2056 | "try to aggregate tid %d\n", |
| 2057 | tid); |
| 2058 | rs_tl_turn_on_agg(mvm, tid, |
| 2059 | lq_sta, sta); |
| 2060 | } |
| 2061 | } |
| 2062 | rs_set_stay_in_table(mvm, 0, lq_sta); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2067 | lq_sta->last_txrate_idx = index; |
| 2068 | } |
| 2069 | |
| 2070 | /** |
| 2071 | * rs_initialize_lq - Initialize a station's hardware rate table |
| 2072 | * |
| 2073 | * The uCode's station table contains a table of fallback rates |
| 2074 | * for automatic fallback during transmission. |
| 2075 | * |
| 2076 | * NOTE: This sets up a default set of values. These will be replaced later |
| 2077 | * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of |
| 2078 | * rc80211_simple. |
| 2079 | * |
| 2080 | * NOTE: Run REPLY_ADD_STA command to set up station table entry, before |
| 2081 | * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, |
| 2082 | * which requires station table entry to exist). |
| 2083 | */ |
| 2084 | static void rs_initialize_lq(struct iwl_mvm *mvm, |
| 2085 | struct ieee80211_sta *sta, |
| 2086 | struct iwl_lq_sta *lq_sta, |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 2087 | enum ieee80211_band band, |
| 2088 | bool init) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2089 | { |
| 2090 | struct iwl_scale_tbl_info *tbl; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2091 | struct rs_rate *rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2092 | int i; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2093 | u8 active_tbl = 0; |
| 2094 | u8 valid_tx_ant; |
| 2095 | |
| 2096 | if (!sta || !lq_sta) |
| 2097 | return; |
| 2098 | |
| 2099 | i = lq_sta->last_txrate_idx; |
| 2100 | |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 2101 | valid_tx_ant = mvm->fw->valid_tx_ant; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2102 | |
| 2103 | if (!lq_sta->search_better_tbl) |
| 2104 | active_tbl = lq_sta->active_tbl; |
| 2105 | else |
| 2106 | active_tbl = 1 - lq_sta->active_tbl; |
| 2107 | |
| 2108 | tbl = &(lq_sta->lq_info[active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2109 | rate = &tbl->rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2110 | |
| 2111 | if ((i < 0) || (i >= IWL_RATE_COUNT)) |
| 2112 | i = 0; |
| 2113 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2114 | rate->index = i; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2115 | rate->ant = first_antenna(valid_tx_ant); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2116 | rate->sgi = false; |
| 2117 | rate->bw = RATE_MCS_CHAN_WIDTH_20; |
| 2118 | if (band == IEEE80211_BAND_5GHZ) |
| 2119 | rate->type = LQ_LEGACY_A; |
| 2120 | else |
| 2121 | rate->type = LQ_LEGACY_G; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2122 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2123 | WARN_ON_ONCE(rate->ant != ANT_A && rate->ant != ANT_B); |
| 2124 | if (rate->ant == ANT_A) |
| 2125 | tbl->column = RS_COLUMN_LEGACY_ANT_A; |
| 2126 | else |
| 2127 | tbl->column = RS_COLUMN_LEGACY_ANT_B; |
| 2128 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2129 | rs_set_expected_tpt_table(lq_sta, tbl); |
Eyal Shapira | 80e9e5c | 2013-12-23 16:26:41 +0200 | [diff] [blame] | 2130 | rs_fill_lq_cmd(mvm, sta, lq_sta, rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2131 | /* TODO restore station should remember the lq cmd */ |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 2132 | iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, init); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | static void rs_get_rate(void *mvm_r, struct ieee80211_sta *sta, void *mvm_sta, |
| 2136 | struct ieee80211_tx_rate_control *txrc) |
| 2137 | { |
| 2138 | struct sk_buff *skb = txrc->skb; |
| 2139 | struct ieee80211_supported_band *sband = txrc->sband; |
| 2140 | struct iwl_op_mode *op_mode __maybe_unused = |
| 2141 | (struct iwl_op_mode *)mvm_r; |
| 2142 | struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode); |
| 2143 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2144 | struct iwl_lq_sta *lq_sta = mvm_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2145 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2146 | /* Get max rate if user set max rate */ |
| 2147 | if (lq_sta) { |
| 2148 | lq_sta->max_rate_idx = txrc->max_rate_idx; |
| 2149 | if ((sband->band == IEEE80211_BAND_5GHZ) && |
| 2150 | (lq_sta->max_rate_idx != -1)) |
| 2151 | lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE; |
| 2152 | if ((lq_sta->max_rate_idx < 0) || |
| 2153 | (lq_sta->max_rate_idx >= IWL_RATE_COUNT)) |
| 2154 | lq_sta->max_rate_idx = -1; |
| 2155 | } |
| 2156 | |
| 2157 | /* Treat uninitialized rate scaling data same as non-existing. */ |
| 2158 | if (lq_sta && !lq_sta->drv) { |
| 2159 | IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n"); |
| 2160 | mvm_sta = NULL; |
| 2161 | } |
| 2162 | |
| 2163 | /* Send management frames and NO_ACK data using lowest rate. */ |
| 2164 | if (rate_control_send_low(sta, mvm_sta, txrc)) |
| 2165 | return; |
| 2166 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2167 | iwl_mvm_hwrate_to_tx_rate(lq_sta->last_rate_n_flags, |
| 2168 | info->band, &info->control.rates[0]); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2169 | |
Moshe Benji | 622ebe9 | 2013-06-03 19:27:16 +0300 | [diff] [blame] | 2170 | info->control.rates[0].count = 1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | static void *rs_alloc_sta(void *mvm_rate, struct ieee80211_sta *sta, |
| 2174 | gfp_t gfp) |
| 2175 | { |
| 2176 | struct iwl_mvm_sta *sta_priv = (struct iwl_mvm_sta *)sta->drv_priv; |
| 2177 | struct iwl_op_mode *op_mode __maybe_unused = |
| 2178 | (struct iwl_op_mode *)mvm_rate; |
| 2179 | struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode); |
| 2180 | |
| 2181 | IWL_DEBUG_RATE(mvm, "create station rate scale window\n"); |
| 2182 | |
| 2183 | return &sta_priv->lq_sta; |
| 2184 | } |
| 2185 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2186 | static int rs_vht_highest_rx_mcs_index(struct ieee80211_sta_vht_cap *vht_cap, |
| 2187 | int nss) |
| 2188 | { |
| 2189 | u16 rx_mcs = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) & |
| 2190 | (0x3 << (2 * (nss - 1))); |
| 2191 | rx_mcs >>= (2 * (nss - 1)); |
| 2192 | |
| 2193 | if (rx_mcs == IEEE80211_VHT_MCS_SUPPORT_0_7) |
| 2194 | return IWL_RATE_MCS_7_INDEX; |
| 2195 | else if (rx_mcs == IEEE80211_VHT_MCS_SUPPORT_0_8) |
| 2196 | return IWL_RATE_MCS_8_INDEX; |
| 2197 | else if (rx_mcs == IEEE80211_VHT_MCS_SUPPORT_0_9) |
| 2198 | return IWL_RATE_MCS_9_INDEX; |
| 2199 | |
| 2200 | WARN_ON_ONCE(rx_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED); |
| 2201 | return -1; |
| 2202 | } |
| 2203 | |
Eyal Shapira | 750a1b4 | 2013-11-09 22:48:56 +0200 | [diff] [blame] | 2204 | static void rs_vht_set_enabled_rates(struct ieee80211_sta *sta, |
| 2205 | struct ieee80211_sta_vht_cap *vht_cap, |
| 2206 | struct iwl_lq_sta *lq_sta) |
| 2207 | { |
| 2208 | int i; |
| 2209 | int highest_mcs = rs_vht_highest_rx_mcs_index(vht_cap, 1); |
| 2210 | |
| 2211 | if (highest_mcs >= IWL_RATE_MCS_0_INDEX) { |
| 2212 | for (i = IWL_RATE_MCS_0_INDEX; i <= highest_mcs; i++) { |
| 2213 | if (i == IWL_RATE_9M_INDEX) |
| 2214 | continue; |
| 2215 | |
Eyal Shapira | 4623a26 | 2013-12-11 09:32:28 +0200 | [diff] [blame] | 2216 | /* Disable MCS9 as a workaround */ |
| 2217 | if (i == IWL_RATE_MCS_9_INDEX) |
| 2218 | continue; |
| 2219 | |
Eyal Shapira | 271518a | 2013-11-09 23:25:06 +0200 | [diff] [blame] | 2220 | /* VHT MCS9 isn't valid for 20Mhz for NSS=1,2 */ |
| 2221 | if (i == IWL_RATE_MCS_9_INDEX && |
| 2222 | sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 2223 | continue; |
| 2224 | |
Eyal Shapira | 750a1b4 | 2013-11-09 22:48:56 +0200 | [diff] [blame] | 2225 | lq_sta->active_siso_rate |= BIT(i); |
| 2226 | } |
| 2227 | } |
| 2228 | |
Eyal Shapira | ecc90e7 | 2013-11-09 23:31:38 +0200 | [diff] [blame] | 2229 | if (sta->rx_nss < 2) |
| 2230 | return; |
| 2231 | |
Eyal Shapira | 750a1b4 | 2013-11-09 22:48:56 +0200 | [diff] [blame] | 2232 | highest_mcs = rs_vht_highest_rx_mcs_index(vht_cap, 2); |
| 2233 | if (highest_mcs >= IWL_RATE_MCS_0_INDEX) { |
| 2234 | for (i = IWL_RATE_MCS_0_INDEX; i <= highest_mcs; i++) { |
| 2235 | if (i == IWL_RATE_9M_INDEX) |
| 2236 | continue; |
| 2237 | |
Eyal Shapira | 4623a26 | 2013-12-11 09:32:28 +0200 | [diff] [blame] | 2238 | /* Disable MCS9 as a workaround */ |
| 2239 | if (i == IWL_RATE_MCS_9_INDEX) |
| 2240 | continue; |
| 2241 | |
Eyal Shapira | 271518a | 2013-11-09 23:25:06 +0200 | [diff] [blame] | 2242 | /* VHT MCS9 isn't valid for 20Mhz for NSS=1,2 */ |
| 2243 | if (i == IWL_RATE_MCS_9_INDEX && |
| 2244 | sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 2245 | continue; |
| 2246 | |
Eyal Shapira | 750a1b4 | 2013-11-09 22:48:56 +0200 | [diff] [blame] | 2247 | lq_sta->active_mimo2_rate |= BIT(i); |
| 2248 | } |
| 2249 | } |
| 2250 | } |
| 2251 | |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 2252 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 2253 | static void iwl_mvm_reset_frame_stats(struct iwl_mvm *mvm, |
| 2254 | struct iwl_mvm_frame_stats *stats) |
| 2255 | { |
| 2256 | spin_lock_bh(&mvm->drv_stats_lock); |
| 2257 | memset(stats, 0, sizeof(*stats)); |
| 2258 | spin_unlock_bh(&mvm->drv_stats_lock); |
| 2259 | } |
| 2260 | |
| 2261 | void iwl_mvm_update_frame_stats(struct iwl_mvm *mvm, |
| 2262 | struct iwl_mvm_frame_stats *stats, |
| 2263 | u32 rate, bool agg) |
| 2264 | { |
| 2265 | u8 nss = 0, mcs = 0; |
| 2266 | |
| 2267 | spin_lock(&mvm->drv_stats_lock); |
| 2268 | |
| 2269 | if (agg) |
| 2270 | stats->agg_frames++; |
| 2271 | |
| 2272 | stats->success_frames++; |
| 2273 | |
| 2274 | switch (rate & RATE_MCS_CHAN_WIDTH_MSK) { |
| 2275 | case RATE_MCS_CHAN_WIDTH_20: |
| 2276 | stats->bw_20_frames++; |
| 2277 | break; |
| 2278 | case RATE_MCS_CHAN_WIDTH_40: |
| 2279 | stats->bw_40_frames++; |
| 2280 | break; |
| 2281 | case RATE_MCS_CHAN_WIDTH_80: |
| 2282 | stats->bw_80_frames++; |
| 2283 | break; |
| 2284 | default: |
| 2285 | WARN_ONCE(1, "bad BW. rate 0x%x", rate); |
| 2286 | } |
| 2287 | |
| 2288 | if (rate & RATE_MCS_HT_MSK) { |
| 2289 | stats->ht_frames++; |
| 2290 | mcs = rate & RATE_HT_MCS_RATE_CODE_MSK; |
| 2291 | nss = ((rate & RATE_HT_MCS_NSS_MSK) >> RATE_HT_MCS_NSS_POS) + 1; |
| 2292 | } else if (rate & RATE_MCS_VHT_MSK) { |
| 2293 | stats->vht_frames++; |
| 2294 | mcs = rate & RATE_VHT_MCS_RATE_CODE_MSK; |
| 2295 | nss = ((rate & RATE_VHT_MCS_NSS_MSK) >> |
| 2296 | RATE_VHT_MCS_NSS_POS) + 1; |
| 2297 | } else { |
| 2298 | stats->legacy_frames++; |
| 2299 | } |
| 2300 | |
| 2301 | if (nss == 1) |
| 2302 | stats->siso_frames++; |
| 2303 | else if (nss == 2) |
| 2304 | stats->mimo2_frames++; |
| 2305 | |
| 2306 | if (rate & RATE_MCS_SGI_MSK) |
| 2307 | stats->sgi_frames++; |
| 2308 | else |
| 2309 | stats->ngi_frames++; |
| 2310 | |
| 2311 | stats->last_rates[stats->last_frame_idx] = rate; |
| 2312 | stats->last_frame_idx = (stats->last_frame_idx + 1) % |
| 2313 | ARRAY_SIZE(stats->last_rates); |
| 2314 | |
| 2315 | spin_unlock(&mvm->drv_stats_lock); |
| 2316 | } |
| 2317 | #endif |
| 2318 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2319 | /* |
| 2320 | * Called after adding a new station to initialize rate scaling |
| 2321 | */ |
| 2322 | void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 2323 | enum ieee80211_band band, bool init) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2324 | { |
| 2325 | int i, j; |
| 2326 | struct ieee80211_hw *hw = mvm->hw; |
| 2327 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2328 | struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2329 | struct iwl_mvm_sta *sta_priv; |
| 2330 | struct iwl_lq_sta *lq_sta; |
| 2331 | struct ieee80211_supported_band *sband; |
| 2332 | unsigned long supp; /* must be unsigned long for for_each_set_bit */ |
| 2333 | |
| 2334 | sta_priv = (struct iwl_mvm_sta *)sta->drv_priv; |
| 2335 | lq_sta = &sta_priv->lq_sta; |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 2336 | memset(lq_sta, 0, sizeof(*lq_sta)); |
| 2337 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2338 | sband = hw->wiphy->bands[band]; |
| 2339 | |
| 2340 | lq_sta->lq.sta_id = sta_priv->sta_id; |
| 2341 | |
| 2342 | for (j = 0; j < LQ_SIZE; j++) |
| 2343 | for (i = 0; i < IWL_RATE_COUNT; i++) |
| 2344 | rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]); |
| 2345 | |
| 2346 | lq_sta->flush_timer = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2347 | |
| 2348 | IWL_DEBUG_RATE(mvm, |
| 2349 | "LQ: *** rate scale station global init for station %d ***\n", |
| 2350 | sta_priv->sta_id); |
| 2351 | /* TODO: what is a good starting rate for STA? About middle? Maybe not |
| 2352 | * the lowest or the highest rate.. Could consider using RSSI from |
| 2353 | * previous packets? Need to have IEEE 802.1X auth succeed immediately |
| 2354 | * after assoc.. */ |
| 2355 | |
| 2356 | lq_sta->max_rate_idx = -1; |
| 2357 | lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2358 | lq_sta->band = sband->band; |
| 2359 | /* |
| 2360 | * active legacy rates as per supported rates bitmap |
| 2361 | */ |
| 2362 | supp = sta->supp_rates[sband->band]; |
| 2363 | lq_sta->active_legacy_rate = 0; |
| 2364 | for_each_set_bit(i, &supp, BITS_PER_LONG) |
| 2365 | lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value); |
| 2366 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2367 | /* TODO: should probably account for rx_highest for both HT/VHT */ |
| 2368 | if (!vht_cap || !vht_cap->vht_supported) { |
| 2369 | /* active_siso_rate mask includes 9 MBits (bit 5), |
| 2370 | * and CCK (bits 0-3), supp_rates[] does not; |
| 2371 | * shift to convert format, force 9 MBits off. |
| 2372 | */ |
| 2373 | lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1; |
| 2374 | lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1; |
| 2375 | lq_sta->active_siso_rate &= ~((u16)0x2); |
| 2376 | lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2377 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2378 | /* Same here */ |
| 2379 | lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1; |
| 2380 | lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1; |
| 2381 | lq_sta->active_mimo2_rate &= ~((u16)0x2); |
| 2382 | lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE; |
| 2383 | |
| 2384 | lq_sta->is_vht = false; |
| 2385 | } else { |
Eyal Shapira | 750a1b4 | 2013-11-09 22:48:56 +0200 | [diff] [blame] | 2386 | rs_vht_set_enabled_rates(sta, vht_cap, lq_sta); |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2387 | lq_sta->is_vht = true; |
| 2388 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2389 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2390 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2391 | "SISO-RATE=%X MIMO2-RATE=%X VHT=%d\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2392 | lq_sta->active_siso_rate, |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2393 | lq_sta->active_mimo2_rate, |
| 2394 | lq_sta->is_vht); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2395 | |
| 2396 | /* These values will be overridden later */ |
| 2397 | lq_sta->lq.single_stream_ant_msk = |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 2398 | first_antenna(mvm->fw->valid_tx_ant); |
Eyal Shapira | 809bccf | 2013-11-28 02:25:24 +0200 | [diff] [blame] | 2399 | lq_sta->lq.dual_stream_ant_msk = ANT_AB; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2400 | |
| 2401 | /* as default allow aggregation for all tids */ |
| 2402 | lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID; |
| 2403 | lq_sta->drv = mvm; |
| 2404 | |
| 2405 | /* Set last_txrate_idx to lowest rate */ |
| 2406 | lq_sta->last_txrate_idx = rate_lowest_index(sband, sta); |
| 2407 | if (sband->band == IEEE80211_BAND_5GHZ) |
| 2408 | lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE; |
| 2409 | lq_sta->is_agg = 0; |
| 2410 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 2411 | lq_sta->dbg_fixed_rate = 0; |
| 2412 | #endif |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 2413 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 2414 | iwl_mvm_reset_frame_stats(mvm, &mvm->drv_rx_stats); |
| 2415 | #endif |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 2416 | rs_initialize_lq(mvm, sta, lq_sta, band, init); |
| 2417 | } |
| 2418 | |
| 2419 | static void rs_rate_update(void *mvm_r, |
| 2420 | struct ieee80211_supported_band *sband, |
| 2421 | struct cfg80211_chan_def *chandef, |
| 2422 | struct ieee80211_sta *sta, void *priv_sta, |
| 2423 | u32 changed) |
| 2424 | { |
| 2425 | u8 tid; |
| 2426 | struct iwl_op_mode *op_mode = |
| 2427 | (struct iwl_op_mode *)mvm_r; |
| 2428 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); |
| 2429 | |
| 2430 | /* Stop any ongoing aggregations as rs starts off assuming no agg */ |
| 2431 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) |
| 2432 | ieee80211_stop_tx_ba_session(sta, tid); |
| 2433 | |
| 2434 | iwl_mvm_rs_rate_init(mvm, sta, sband->band, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2435 | } |
| 2436 | |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2437 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 2438 | static void rs_build_rates_table_from_fixed(struct iwl_mvm *mvm, |
| 2439 | struct iwl_lq_cmd *lq_cmd, |
| 2440 | enum ieee80211_band band, |
| 2441 | u32 ucode_rate) |
| 2442 | { |
| 2443 | struct rs_rate rate; |
| 2444 | int i; |
| 2445 | int num_rates = ARRAY_SIZE(lq_cmd->rs_table); |
| 2446 | __le32 ucode_rate_le32 = cpu_to_le32(ucode_rate); |
| 2447 | |
| 2448 | for (i = 0; i < num_rates; i++) |
| 2449 | lq_cmd->rs_table[i] = ucode_rate_le32; |
| 2450 | |
| 2451 | rs_rate_from_ucode_rate(ucode_rate, band, &rate); |
| 2452 | |
| 2453 | if (is_mimo(&rate)) |
| 2454 | lq_cmd->mimo_delim = num_rates - 1; |
| 2455 | else |
| 2456 | lq_cmd->mimo_delim = 0; |
| 2457 | } |
| 2458 | #endif /* CONFIG_MAC80211_DEBUGFS */ |
| 2459 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 2460 | static void rs_fill_rates_for_column(struct iwl_mvm *mvm, |
| 2461 | struct iwl_lq_sta *lq_sta, |
| 2462 | struct rs_rate *rate, |
| 2463 | __le32 *rs_table, int *rs_table_index, |
| 2464 | int num_rates, int num_retries, |
| 2465 | u8 valid_tx_ant, bool toggle_ant) |
| 2466 | { |
| 2467 | int i, j; |
| 2468 | __le32 ucode_rate; |
| 2469 | bool bottom_reached = false; |
| 2470 | int prev_rate_idx = rate->index; |
| 2471 | int end = LINK_QUAL_MAX_RETRY_NUM; |
| 2472 | int index = *rs_table_index; |
| 2473 | |
| 2474 | for (i = 0; i < num_rates && index < end; i++) { |
| 2475 | ucode_rate = cpu_to_le32(ucode_rate_from_rs_rate(mvm, rate)); |
| 2476 | for (j = 0; j < num_retries && index < end; j++, index++) |
| 2477 | rs_table[index] = ucode_rate; |
| 2478 | |
| 2479 | if (toggle_ant) |
| 2480 | rs_toggle_antenna(valid_tx_ant, rate); |
| 2481 | |
| 2482 | prev_rate_idx = rate->index; |
| 2483 | bottom_reached = rs_get_lower_rate_in_column(lq_sta, rate); |
| 2484 | if (bottom_reached && !is_legacy(rate)) |
| 2485 | break; |
| 2486 | } |
| 2487 | |
| 2488 | if (!bottom_reached) |
| 2489 | rate->index = prev_rate_idx; |
| 2490 | |
| 2491 | *rs_table_index = index; |
| 2492 | } |
| 2493 | |
| 2494 | /* Building the rate table is non trivial. When we're in MIMO2/VHT/80Mhz/SGI |
| 2495 | * column the rate table should look like this: |
| 2496 | * |
| 2497 | * rate[0] 0x400D019 VHT | ANT: AB BW: 80Mhz MCS: 9 NSS: 2 SGI |
| 2498 | * rate[1] 0x400D019 VHT | ANT: AB BW: 80Mhz MCS: 9 NSS: 2 SGI |
| 2499 | * rate[2] 0x400D018 VHT | ANT: AB BW: 80Mhz MCS: 8 NSS: 2 SGI |
| 2500 | * rate[3] 0x400D018 VHT | ANT: AB BW: 80Mhz MCS: 8 NSS: 2 SGI |
| 2501 | * rate[4] 0x400D017 VHT | ANT: AB BW: 80Mhz MCS: 7 NSS: 2 SGI |
| 2502 | * rate[5] 0x400D017 VHT | ANT: AB BW: 80Mhz MCS: 7 NSS: 2 SGI |
| 2503 | * rate[6] 0x4005007 VHT | ANT: A BW: 80Mhz MCS: 7 NSS: 1 NGI |
| 2504 | * rate[7] 0x4009006 VHT | ANT: B BW: 80Mhz MCS: 6 NSS: 1 NGI |
| 2505 | * rate[8] 0x4005005 VHT | ANT: A BW: 80Mhz MCS: 5 NSS: 1 NGI |
| 2506 | * rate[9] 0x800B Legacy | ANT: B Rate: 36 Mbps |
| 2507 | * rate[10] 0x4009 Legacy | ANT: A Rate: 24 Mbps |
| 2508 | * rate[11] 0x8007 Legacy | ANT: B Rate: 18 Mbps |
| 2509 | * rate[12] 0x4005 Legacy | ANT: A Rate: 12 Mbps |
| 2510 | * rate[13] 0x800F Legacy | ANT: B Rate: 9 Mbps |
| 2511 | * rate[14] 0x400D Legacy | ANT: A Rate: 6 Mbps |
| 2512 | * rate[15] 0x800D Legacy | ANT: B Rate: 6 Mbps |
| 2513 | */ |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2514 | static void rs_build_rates_table(struct iwl_mvm *mvm, |
| 2515 | struct iwl_lq_sta *lq_sta, |
| 2516 | const struct rs_rate *initial_rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2517 | { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2518 | struct rs_rate rate; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 2519 | int num_rates, num_retries, index = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2520 | u8 valid_tx_ant = 0; |
| 2521 | struct iwl_lq_cmd *lq_cmd = &lq_sta->lq; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 2522 | bool toggle_ant = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2523 | |
Emmanuel Grumbach | 9e898f1 | 2013-12-22 10:55:47 +0200 | [diff] [blame] | 2524 | memcpy(&rate, initial_rate, sizeof(rate)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2525 | |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 2526 | valid_tx_ant = mvm->fw->valid_tx_ant; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2527 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 2528 | if (is_siso(&rate)) { |
| 2529 | num_rates = RS_INITIAL_SISO_NUM_RATES; |
| 2530 | num_retries = RS_HT_VHT_RETRIES_PER_RATE; |
| 2531 | } else if (is_mimo(&rate)) { |
| 2532 | num_rates = RS_INITIAL_MIMO_NUM_RATES; |
| 2533 | num_retries = RS_HT_VHT_RETRIES_PER_RATE; |
| 2534 | } else { |
| 2535 | num_rates = RS_INITIAL_LEGACY_NUM_RATES; |
| 2536 | num_retries = RS_LEGACY_RETRIES_PER_RATE; |
| 2537 | toggle_ant = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2538 | } |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 2539 | |
| 2540 | rs_fill_rates_for_column(mvm, lq_sta, &rate, lq_cmd->rs_table, &index, |
| 2541 | num_rates, num_retries, valid_tx_ant, |
| 2542 | toggle_ant); |
| 2543 | |
| 2544 | rs_get_lower_rate_down_column(lq_sta, &rate); |
| 2545 | |
| 2546 | if (is_siso(&rate)) { |
| 2547 | num_rates = RS_SECONDARY_SISO_NUM_RATES; |
| 2548 | num_retries = RS_SECONDARY_SISO_RETRIES; |
| 2549 | } else if (is_legacy(&rate)) { |
| 2550 | num_rates = RS_SECONDARY_LEGACY_NUM_RATES; |
| 2551 | num_retries = RS_LEGACY_RETRIES_PER_RATE; |
| 2552 | } else { |
| 2553 | WARN_ON_ONCE(1); |
| 2554 | } |
| 2555 | |
| 2556 | toggle_ant = true; |
| 2557 | |
| 2558 | rs_fill_rates_for_column(mvm, lq_sta, &rate, lq_cmd->rs_table, &index, |
| 2559 | num_rates, num_retries, valid_tx_ant, |
| 2560 | toggle_ant); |
| 2561 | |
| 2562 | rs_get_lower_rate_down_column(lq_sta, &rate); |
| 2563 | |
| 2564 | num_rates = RS_SECONDARY_LEGACY_NUM_RATES; |
| 2565 | num_retries = RS_LEGACY_RETRIES_PER_RATE; |
| 2566 | |
| 2567 | rs_fill_rates_for_column(mvm, lq_sta, &rate, lq_cmd->rs_table, &index, |
| 2568 | num_rates, num_retries, valid_tx_ant, |
| 2569 | toggle_ant); |
| 2570 | |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | static void rs_fill_lq_cmd(struct iwl_mvm *mvm, |
| 2574 | struct ieee80211_sta *sta, |
| 2575 | struct iwl_lq_sta *lq_sta, |
| 2576 | const struct rs_rate *initial_rate) |
| 2577 | { |
| 2578 | struct iwl_lq_cmd *lq_cmd = &lq_sta->lq; |
| 2579 | u8 ant = initial_rate->ant; |
| 2580 | |
| 2581 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 2582 | if (lq_sta->dbg_fixed_rate) { |
| 2583 | rs_build_rates_table_from_fixed(mvm, lq_cmd, |
| 2584 | lq_sta->band, |
| 2585 | lq_sta->dbg_fixed_rate); |
| 2586 | ant = (lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK) >> |
| 2587 | RATE_MCS_ANT_POS; |
| 2588 | } else |
| 2589 | #endif |
| 2590 | rs_build_rates_table(mvm, lq_sta, initial_rate); |
| 2591 | |
| 2592 | if (num_of_ant(ant) == 1) |
| 2593 | lq_cmd->single_stream_ant_msk = ant; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2594 | |
| 2595 | lq_cmd->agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
| 2596 | lq_cmd->agg_disable_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; |
| 2597 | |
| 2598 | lq_cmd->agg_time_limit = |
| 2599 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
Emmanuel Grumbach | e96d551 | 2013-05-28 21:31:50 +0300 | [diff] [blame] | 2600 | |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 2601 | if (sta) |
| 2602 | lq_cmd->agg_time_limit = |
Emmanuel Grumbach | 5b7ff61 | 2014-03-11 19:27:45 +0200 | [diff] [blame] | 2603 | cpu_to_le16(iwl_mvm_coex_agg_time_limit(mvm, sta)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) |
| 2607 | { |
| 2608 | return hw->priv; |
| 2609 | } |
| 2610 | /* rate scale requires free function to be implemented */ |
| 2611 | static void rs_free(void *mvm_rate) |
| 2612 | { |
| 2613 | return; |
| 2614 | } |
| 2615 | |
| 2616 | static void rs_free_sta(void *mvm_r, struct ieee80211_sta *sta, |
| 2617 | void *mvm_sta) |
| 2618 | { |
| 2619 | struct iwl_op_mode *op_mode __maybe_unused = mvm_r; |
| 2620 | struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode); |
| 2621 | |
| 2622 | IWL_DEBUG_RATE(mvm, "enter\n"); |
| 2623 | IWL_DEBUG_RATE(mvm, "leave\n"); |
| 2624 | } |
| 2625 | |
| 2626 | #ifdef CONFIG_MAC80211_DEBUGFS |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 2627 | int rs_pretty_print_rate(char *buf, const u32 rate) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2628 | { |
| 2629 | |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 2630 | char *type, *bw; |
| 2631 | u8 mcs = 0, nss = 0; |
| 2632 | u8 ant = (rate & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS; |
| 2633 | |
| 2634 | if (!(rate & RATE_MCS_HT_MSK) && |
| 2635 | !(rate & RATE_MCS_VHT_MSK)) { |
| 2636 | int index = iwl_hwrate_to_plcp_idx(rate); |
| 2637 | |
| 2638 | return sprintf(buf, "Legacy | ANT: %s Rate: %s Mbps\n", |
Eyal Shapira | 560843f | 2014-01-05 21:04:19 +0200 | [diff] [blame] | 2639 | rs_pretty_ant(ant), |
| 2640 | index == IWL_RATE_INVALID ? "BAD" : |
| 2641 | iwl_rate_mcs[index].mbps); |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | if (rate & RATE_MCS_VHT_MSK) { |
| 2645 | type = "VHT"; |
| 2646 | mcs = rate & RATE_VHT_MCS_RATE_CODE_MSK; |
| 2647 | nss = ((rate & RATE_VHT_MCS_NSS_MSK) |
| 2648 | >> RATE_VHT_MCS_NSS_POS) + 1; |
| 2649 | } else if (rate & RATE_MCS_HT_MSK) { |
| 2650 | type = "HT"; |
| 2651 | mcs = rate & RATE_HT_MCS_INDEX_MSK; |
| 2652 | } else { |
| 2653 | type = "Unknown"; /* shouldn't happen */ |
| 2654 | } |
| 2655 | |
| 2656 | switch (rate & RATE_MCS_CHAN_WIDTH_MSK) { |
| 2657 | case RATE_MCS_CHAN_WIDTH_20: |
| 2658 | bw = "20Mhz"; |
| 2659 | break; |
| 2660 | case RATE_MCS_CHAN_WIDTH_40: |
| 2661 | bw = "40Mhz"; |
| 2662 | break; |
| 2663 | case RATE_MCS_CHAN_WIDTH_80: |
| 2664 | bw = "80Mhz"; |
| 2665 | break; |
| 2666 | case RATE_MCS_CHAN_WIDTH_160: |
| 2667 | bw = "160Mhz"; |
| 2668 | break; |
| 2669 | default: |
| 2670 | bw = "BAD BW"; |
| 2671 | } |
| 2672 | |
| 2673 | return sprintf(buf, "%s | ANT: %s BW: %s MCS: %d NSS: %d %s%s%s%s%s\n", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2674 | type, rs_pretty_ant(ant), bw, mcs, nss, |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 2675 | (rate & RATE_MCS_SGI_MSK) ? "SGI " : "NGI ", |
Emmanuel Grumbach | 7b1dd04 | 2014-02-04 15:32:43 +0200 | [diff] [blame] | 2676 | (rate & RATE_MCS_HT_STBC_MSK) ? "STBC " : "", |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 2677 | (rate & RATE_MCS_LDPC_MSK) ? "LDPC " : "", |
| 2678 | (rate & RATE_MCS_BF_MSK) ? "BF " : "", |
| 2679 | (rate & RATE_MCS_ZLF_MSK) ? "ZLF " : ""); |
| 2680 | } |
| 2681 | |
Eyal Shapira | a0c38b2 | 2013-12-03 18:34:52 +0200 | [diff] [blame] | 2682 | /** |
| 2683 | * Program the device to use fixed rate for frame transmit |
| 2684 | * This is for debugging/testing only |
| 2685 | * once the device start use fixed rate, we need to reload the module |
| 2686 | * to being back the normal operation. |
| 2687 | */ |
| 2688 | static void rs_program_fix_rate(struct iwl_mvm *mvm, |
| 2689 | struct iwl_lq_sta *lq_sta) |
| 2690 | { |
| 2691 | lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */ |
| 2692 | lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ |
| 2693 | lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ |
| 2694 | |
| 2695 | IWL_DEBUG_RATE(mvm, "sta_id %d rate 0x%X\n", |
| 2696 | lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate); |
| 2697 | |
| 2698 | if (lq_sta->dbg_fixed_rate) { |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2699 | struct rs_rate rate; |
| 2700 | rs_rate_from_ucode_rate(lq_sta->dbg_fixed_rate, |
| 2701 | lq_sta->band, &rate); |
Eyal Shapira | 80e9e5c | 2013-12-23 16:26:41 +0200 | [diff] [blame] | 2702 | rs_fill_lq_cmd(mvm, NULL, lq_sta, &rate); |
Eyal Shapira | a0c38b2 | 2013-12-03 18:34:52 +0200 | [diff] [blame] | 2703 | iwl_mvm_send_lq_cmd(lq_sta->drv, &lq_sta->lq, false); |
| 2704 | } |
| 2705 | } |
| 2706 | |
Emmanuel Grumbach | 9d10849 | 2013-12-03 11:50:30 +0200 | [diff] [blame] | 2707 | static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file, |
| 2708 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 2709 | { |
| 2710 | struct iwl_lq_sta *lq_sta = file->private_data; |
| 2711 | struct iwl_mvm *mvm; |
| 2712 | char buf[64]; |
| 2713 | size_t buf_size; |
| 2714 | u32 parsed_rate; |
| 2715 | |
| 2716 | |
| 2717 | mvm = lq_sta->drv; |
| 2718 | memset(buf, 0, sizeof(buf)); |
| 2719 | buf_size = min(count, sizeof(buf) - 1); |
| 2720 | if (copy_from_user(buf, user_buf, buf_size)) |
| 2721 | return -EFAULT; |
| 2722 | |
| 2723 | if (sscanf(buf, "%x", &parsed_rate) == 1) |
| 2724 | lq_sta->dbg_fixed_rate = parsed_rate; |
| 2725 | else |
| 2726 | lq_sta->dbg_fixed_rate = 0; |
| 2727 | |
| 2728 | rs_program_fix_rate(mvm, lq_sta); |
| 2729 | |
| 2730 | return count; |
| 2731 | } |
| 2732 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2733 | static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file, |
| 2734 | char __user *user_buf, size_t count, loff_t *ppos) |
| 2735 | { |
| 2736 | char *buff; |
| 2737 | int desc = 0; |
| 2738 | int i = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2739 | ssize_t ret; |
| 2740 | |
| 2741 | struct iwl_lq_sta *lq_sta = file->private_data; |
| 2742 | struct iwl_mvm *mvm; |
| 2743 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2744 | struct rs_rate *rate = &tbl->rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2745 | mvm = lq_sta->drv; |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 2746 | buff = kmalloc(2048, GFP_KERNEL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2747 | if (!buff) |
| 2748 | return -ENOMEM; |
| 2749 | |
| 2750 | desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id); |
| 2751 | desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n", |
| 2752 | lq_sta->total_failed, lq_sta->total_success, |
| 2753 | lq_sta->active_legacy_rate); |
| 2754 | desc += sprintf(buff+desc, "fixed rate 0x%X\n", |
| 2755 | lq_sta->dbg_fixed_rate); |
| 2756 | desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n", |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 2757 | (mvm->fw->valid_tx_ant & ANT_A) ? "ANT_A," : "", |
| 2758 | (mvm->fw->valid_tx_ant & ANT_B) ? "ANT_B," : "", |
| 2759 | (mvm->fw->valid_tx_ant & ANT_C) ? "ANT_C" : ""); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2760 | desc += sprintf(buff+desc, "lq type %s\n", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2761 | (is_legacy(rate)) ? "legacy" : |
| 2762 | is_vht(rate) ? "VHT" : "HT"); |
| 2763 | if (!is_legacy(rate)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2764 | desc += sprintf(buff+desc, " %s", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2765 | (is_siso(rate)) ? "SISO" : "MIMO2"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2766 | desc += sprintf(buff+desc, " %s", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2767 | (is_ht20(rate)) ? "20MHz" : |
| 2768 | (is_ht40(rate)) ? "40MHz" : |
| 2769 | (is_ht80(rate)) ? "80Mhz" : "BAD BW"); |
Eyal Shapira | 6a524f4 | 2013-08-11 20:27:18 +0300 | [diff] [blame] | 2770 | desc += sprintf(buff+desc, " %s %s\n", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2771 | (rate->sgi) ? "SGI" : "NGI", |
Eyal Shapira | 6a524f4 | 2013-08-11 20:27:18 +0300 | [diff] [blame] | 2772 | (lq_sta->is_agg) ? "AGG on" : ""); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2773 | } |
| 2774 | desc += sprintf(buff+desc, "last tx rate=0x%X\n", |
| 2775 | lq_sta->last_rate_n_flags); |
| 2776 | desc += sprintf(buff+desc, |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 2777 | "general: flags=0x%X mimo-d=%d s-ant=0x%x d-ant=0x%x\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2778 | lq_sta->lq.flags, |
| 2779 | lq_sta->lq.mimo_delim, |
| 2780 | lq_sta->lq.single_stream_ant_msk, |
| 2781 | lq_sta->lq.dual_stream_ant_msk); |
| 2782 | |
| 2783 | desc += sprintf(buff+desc, |
| 2784 | "agg: time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n", |
| 2785 | le16_to_cpu(lq_sta->lq.agg_time_limit), |
| 2786 | lq_sta->lq.agg_disable_start_th, |
| 2787 | lq_sta->lq.agg_frame_cnt_limit); |
| 2788 | |
| 2789 | desc += sprintf(buff+desc, |
| 2790 | "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n", |
| 2791 | lq_sta->lq.initial_rate_index[0], |
| 2792 | lq_sta->lq.initial_rate_index[1], |
| 2793 | lq_sta->lq.initial_rate_index[2], |
| 2794 | lq_sta->lq.initial_rate_index[3]); |
| 2795 | |
| 2796 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
Johannes Berg | cf4ef65 | 2013-12-17 11:34:25 +0100 | [diff] [blame] | 2797 | u32 r = le32_to_cpu(lq_sta->lq.rs_table[i]); |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 2798 | |
Johannes Berg | cf4ef65 | 2013-12-17 11:34:25 +0100 | [diff] [blame] | 2799 | desc += sprintf(buff+desc, " rate[%d] 0x%X ", i, r); |
| 2800 | desc += rs_pretty_print_rate(buff+desc, r); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 2804 | kfree(buff); |
| 2805 | return ret; |
| 2806 | } |
| 2807 | |
| 2808 | static const struct file_operations rs_sta_dbgfs_scale_table_ops = { |
| 2809 | .write = rs_sta_dbgfs_scale_table_write, |
| 2810 | .read = rs_sta_dbgfs_scale_table_read, |
| 2811 | .open = simple_open, |
| 2812 | .llseek = default_llseek, |
| 2813 | }; |
| 2814 | static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file, |
| 2815 | char __user *user_buf, size_t count, loff_t *ppos) |
| 2816 | { |
| 2817 | char *buff; |
| 2818 | int desc = 0; |
| 2819 | int i, j; |
| 2820 | ssize_t ret; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2821 | struct iwl_scale_tbl_info *tbl; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2822 | struct rs_rate *rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2823 | struct iwl_lq_sta *lq_sta = file->private_data; |
| 2824 | |
| 2825 | buff = kmalloc(1024, GFP_KERNEL); |
| 2826 | if (!buff) |
| 2827 | return -ENOMEM; |
| 2828 | |
| 2829 | for (i = 0; i < LQ_SIZE; i++) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2830 | tbl = &(lq_sta->lq_info[i]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2831 | rate = &tbl->rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2832 | desc += sprintf(buff+desc, |
Eyal Shapira | 6a524f4 | 2013-08-11 20:27:18 +0300 | [diff] [blame] | 2833 | "%s type=%d SGI=%d BW=%s DUP=0\n" |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2834 | "index=%d\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2835 | lq_sta->active_tbl == i ? "*" : "x", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2836 | rate->type, |
| 2837 | rate->sgi, |
| 2838 | is_ht20(rate) ? "20Mhz" : |
| 2839 | is_ht40(rate) ? "40Mhz" : |
| 2840 | is_ht80(rate) ? "80Mhz" : "ERR", |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2841 | rate->index); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2842 | for (j = 0; j < IWL_RATE_COUNT; j++) { |
| 2843 | desc += sprintf(buff+desc, |
| 2844 | "counter=%d success=%d %%=%d\n", |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2845 | tbl->win[j].counter, |
| 2846 | tbl->win[j].success_counter, |
| 2847 | tbl->win[j].success_ratio); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2848 | } |
| 2849 | } |
| 2850 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 2851 | kfree(buff); |
| 2852 | return ret; |
| 2853 | } |
| 2854 | |
| 2855 | static const struct file_operations rs_sta_dbgfs_stats_table_ops = { |
| 2856 | .read = rs_sta_dbgfs_stats_table_read, |
| 2857 | .open = simple_open, |
| 2858 | .llseek = default_llseek, |
| 2859 | }; |
| 2860 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2861 | static void rs_add_debugfs(void *mvm, void *mvm_sta, struct dentry *dir) |
| 2862 | { |
| 2863 | struct iwl_lq_sta *lq_sta = mvm_sta; |
| 2864 | lq_sta->rs_sta_dbgfs_scale_table_file = |
| 2865 | debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir, |
| 2866 | lq_sta, &rs_sta_dbgfs_scale_table_ops); |
| 2867 | lq_sta->rs_sta_dbgfs_stats_table_file = |
| 2868 | debugfs_create_file("rate_stats_table", S_IRUSR, dir, |
| 2869 | lq_sta, &rs_sta_dbgfs_stats_table_ops); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2870 | lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file = |
| 2871 | debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir, |
| 2872 | &lq_sta->tx_agg_tid_en); |
| 2873 | } |
| 2874 | |
| 2875 | static void rs_remove_debugfs(void *mvm, void *mvm_sta) |
| 2876 | { |
| 2877 | struct iwl_lq_sta *lq_sta = mvm_sta; |
| 2878 | debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file); |
| 2879 | debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2880 | debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file); |
| 2881 | } |
| 2882 | #endif |
| 2883 | |
| 2884 | /* |
| 2885 | * Initialization of rate scaling information is done by driver after |
| 2886 | * the station is added. Since mac80211 calls this function before a |
| 2887 | * station is added we ignore it. |
| 2888 | */ |
| 2889 | static void rs_rate_init_stub(void *mvm_r, |
Simon Wunderlich | 3de805c | 2013-07-08 16:55:50 +0200 | [diff] [blame] | 2890 | struct ieee80211_supported_band *sband, |
| 2891 | struct cfg80211_chan_def *chandef, |
| 2892 | struct ieee80211_sta *sta, void *mvm_sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2893 | { |
| 2894 | } |
Johannes Berg | 631ad70 | 2014-01-20 23:29:34 +0100 | [diff] [blame] | 2895 | |
| 2896 | static const struct rate_control_ops rs_mvm_ops = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2897 | .name = RS_NAME, |
| 2898 | .tx_status = rs_tx_status, |
| 2899 | .get_rate = rs_get_rate, |
| 2900 | .rate_init = rs_rate_init_stub, |
| 2901 | .alloc = rs_alloc, |
| 2902 | .free = rs_free, |
| 2903 | .alloc_sta = rs_alloc_sta, |
| 2904 | .free_sta = rs_free_sta, |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 2905 | .rate_update = rs_rate_update, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2906 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 2907 | .add_sta_debugfs = rs_add_debugfs, |
| 2908 | .remove_sta_debugfs = rs_remove_debugfs, |
| 2909 | #endif |
| 2910 | }; |
| 2911 | |
| 2912 | int iwl_mvm_rate_control_register(void) |
| 2913 | { |
| 2914 | return ieee80211_rate_control_register(&rs_mvm_ops); |
| 2915 | } |
| 2916 | |
| 2917 | void iwl_mvm_rate_control_unregister(void) |
| 2918 | { |
| 2919 | ieee80211_rate_control_unregister(&rs_mvm_ops); |
| 2920 | } |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2921 | |
| 2922 | /** |
| 2923 | * iwl_mvm_tx_protection - Gets LQ command, change it to enable/disable |
| 2924 | * Tx protection, according to this rquest and previous requests, |
| 2925 | * and send the LQ command. |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2926 | * @mvmsta: The station |
| 2927 | * @enable: Enable Tx protection? |
| 2928 | */ |
Johannes Berg | e126b5d | 2013-06-28 13:39:18 +0200 | [diff] [blame] | 2929 | int iwl_mvm_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 2930 | bool enable) |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2931 | { |
Johannes Berg | e126b5d | 2013-06-28 13:39:18 +0200 | [diff] [blame] | 2932 | struct iwl_lq_cmd *lq = &mvmsta->lq_sta.lq; |
| 2933 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2934 | lockdep_assert_held(&mvm->mutex); |
| 2935 | |
| 2936 | if (enable) { |
| 2937 | if (mvmsta->tx_protection == 0) |
Eyal Shapira | d307ec8 | 2013-11-11 19:56:21 +0200 | [diff] [blame] | 2938 | lq->flags |= LQ_FLAG_USE_RTS_MSK; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2939 | mvmsta->tx_protection++; |
| 2940 | } else { |
| 2941 | mvmsta->tx_protection--; |
| 2942 | if (mvmsta->tx_protection == 0) |
Eyal Shapira | d307ec8 | 2013-11-11 19:56:21 +0200 | [diff] [blame] | 2943 | lq->flags &= ~LQ_FLAG_USE_RTS_MSK; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2944 | } |
| 2945 | |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 2946 | return iwl_mvm_send_lq_cmd(mvm, lq, false); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2947 | } |