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