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