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. |
Eyal Shapira | fcc5e85 | 2015-04-12 23:45:27 +0300 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Gregory Greenman | 69c7fda | 2015-12-29 11:26:35 +0200 | [diff] [blame] | 5 | * Copyright(c) 2016 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 19 | * |
| 20 | * The full GNU General Public License is included in this distribution in the |
| 21 | * file called LICENSE. |
| 22 | * |
| 23 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 24 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 25 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | * |
| 27 | *****************************************************************************/ |
| 28 | #include <linux/kernel.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 29 | #include <linux/skbuff.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <net/mac80211.h> |
| 32 | |
| 33 | #include <linux/netdevice.h> |
| 34 | #include <linux/etherdevice.h> |
| 35 | #include <linux/delay.h> |
| 36 | |
| 37 | #include <linux/workqueue.h> |
| 38 | #include "rs.h" |
| 39 | #include "fw-api.h" |
| 40 | #include "sta.h" |
| 41 | #include "iwl-op-mode.h" |
| 42 | #include "mvm.h" |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 43 | #include "debugfs.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 44 | |
| 45 | #define RS_NAME "iwl-mvm-rs" |
| 46 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 47 | #define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 48 | |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 49 | /* Calculations of success ratio are done in fixed point where 12800 is 100%. |
| 50 | * Use this macro when dealing with thresholds consts set as a percentage |
| 51 | */ |
| 52 | #define RS_PERCENT(x) (128 * x) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 53 | |
| 54 | static u8 rs_ht_to_legacy[] = { |
Eyal Shapira | da87d7d | 2013-11-28 12:27:03 +0200 | [diff] [blame] | 55 | [IWL_RATE_MCS_0_INDEX] = IWL_RATE_6M_INDEX, |
| 56 | [IWL_RATE_MCS_1_INDEX] = IWL_RATE_9M_INDEX, |
| 57 | [IWL_RATE_MCS_2_INDEX] = IWL_RATE_12M_INDEX, |
| 58 | [IWL_RATE_MCS_3_INDEX] = IWL_RATE_18M_INDEX, |
| 59 | [IWL_RATE_MCS_4_INDEX] = IWL_RATE_24M_INDEX, |
| 60 | [IWL_RATE_MCS_5_INDEX] = IWL_RATE_36M_INDEX, |
| 61 | [IWL_RATE_MCS_6_INDEX] = IWL_RATE_48M_INDEX, |
| 62 | [IWL_RATE_MCS_7_INDEX] = IWL_RATE_54M_INDEX, |
| 63 | [IWL_RATE_MCS_8_INDEX] = IWL_RATE_54M_INDEX, |
| 64 | [IWL_RATE_MCS_9_INDEX] = IWL_RATE_54M_INDEX, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | static const u8 ant_toggle_lookup[] = { |
Eliad Peller | ef4394b | 2013-07-16 18:07:20 +0300 | [diff] [blame] | 68 | [ANT_NONE] = ANT_NONE, |
| 69 | [ANT_A] = ANT_B, |
| 70 | [ANT_B] = ANT_C, |
| 71 | [ANT_AB] = ANT_BC, |
| 72 | [ANT_C] = ANT_A, |
| 73 | [ANT_AC] = ANT_AB, |
| 74 | [ANT_BC] = ANT_AC, |
| 75 | [ANT_ABC] = ANT_ABC, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 78 | #define IWL_DECLARE_RATE_INFO(r, s, rp, rn) \ |
| 79 | [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \ |
| 80 | IWL_RATE_HT_SISO_MCS_##s##_PLCP, \ |
| 81 | IWL_RATE_HT_MIMO2_MCS_##s##_PLCP, \ |
| 82 | IWL_RATE_VHT_SISO_MCS_##s##_PLCP, \ |
| 83 | IWL_RATE_VHT_MIMO2_MCS_##s##_PLCP,\ |
| 84 | IWL_RATE_##rp##M_INDEX, \ |
Eyal Shapira | ab055ce | 2013-08-04 13:10:31 +0300 | [diff] [blame] | 85 | IWL_RATE_##rn##M_INDEX } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 86 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 87 | #define IWL_DECLARE_MCS_RATE(s) \ |
| 88 | [IWL_RATE_MCS_##s##_INDEX] = { IWL_RATE_INVM_PLCP, \ |
| 89 | IWL_RATE_HT_SISO_MCS_##s##_PLCP, \ |
| 90 | IWL_RATE_HT_MIMO2_MCS_##s##_PLCP, \ |
| 91 | IWL_RATE_VHT_SISO_MCS_##s##_PLCP, \ |
| 92 | IWL_RATE_VHT_MIMO2_MCS_##s##_PLCP, \ |
| 93 | IWL_RATE_INVM_INDEX, \ |
| 94 | IWL_RATE_INVM_INDEX } |
| 95 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 96 | /* |
| 97 | * Parameter order: |
Eyal Shapira | ab055ce | 2013-08-04 13:10:31 +0300 | [diff] [blame] | 98 | * rate, ht rate, prev rate, next rate |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 99 | * |
| 100 | * If there isn't a valid next or previous rate then INV is used which |
| 101 | * maps to IWL_RATE_INVALID |
| 102 | * |
| 103 | */ |
| 104 | static const struct iwl_rs_rate_info iwl_rates[IWL_RATE_COUNT] = { |
Eyal Shapira | ab055ce | 2013-08-04 13:10:31 +0300 | [diff] [blame] | 105 | IWL_DECLARE_RATE_INFO(1, INV, INV, 2), /* 1mbps */ |
| 106 | IWL_DECLARE_RATE_INFO(2, INV, 1, 5), /* 2mbps */ |
| 107 | IWL_DECLARE_RATE_INFO(5, INV, 2, 11), /*5.5mbps */ |
| 108 | IWL_DECLARE_RATE_INFO(11, INV, 9, 12), /* 11mbps */ |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 109 | IWL_DECLARE_RATE_INFO(6, 0, 5, 11), /* 6mbps ; MCS 0 */ |
| 110 | IWL_DECLARE_RATE_INFO(9, INV, 6, 11), /* 9mbps */ |
| 111 | IWL_DECLARE_RATE_INFO(12, 1, 11, 18), /* 12mbps ; MCS 1 */ |
| 112 | IWL_DECLARE_RATE_INFO(18, 2, 12, 24), /* 18mbps ; MCS 2 */ |
| 113 | IWL_DECLARE_RATE_INFO(24, 3, 18, 36), /* 24mbps ; MCS 3 */ |
| 114 | IWL_DECLARE_RATE_INFO(36, 4, 24, 48), /* 36mbps ; MCS 4 */ |
| 115 | IWL_DECLARE_RATE_INFO(48, 5, 36, 54), /* 48mbps ; MCS 5 */ |
| 116 | IWL_DECLARE_RATE_INFO(54, 6, 48, INV), /* 54mbps ; MCS 6 */ |
| 117 | IWL_DECLARE_MCS_RATE(7), /* MCS 7 */ |
| 118 | IWL_DECLARE_MCS_RATE(8), /* MCS 8 */ |
| 119 | IWL_DECLARE_MCS_RATE(9), /* MCS 9 */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 122 | enum rs_action { |
| 123 | RS_ACTION_STAY = 0, |
| 124 | RS_ACTION_DOWNSCALE = -1, |
| 125 | RS_ACTION_UPSCALE = 1, |
| 126 | }; |
| 127 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 128 | enum rs_column_mode { |
| 129 | RS_INVALID = 0, |
| 130 | RS_LEGACY, |
| 131 | RS_SISO, |
| 132 | RS_MIMO2, |
| 133 | }; |
| 134 | |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 135 | #define MAX_NEXT_COLUMNS 7 |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 136 | #define MAX_COLUMN_CHECKS 3 |
| 137 | |
Eyal Shapira | 0b8d17f | 2015-02-02 15:21:27 +0200 | [diff] [blame] | 138 | struct rs_tx_column; |
| 139 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 140 | typedef bool (*allow_column_func_t) (struct iwl_mvm *mvm, |
| 141 | struct ieee80211_sta *sta, |
Eyal Shapira | bb8f44c | 2015-05-27 22:00:03 +0300 | [diff] [blame] | 142 | struct rs_rate *rate, |
Eyal Shapira | 0b8d17f | 2015-02-02 15:21:27 +0200 | [diff] [blame] | 143 | const struct rs_tx_column *next_col); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 144 | |
| 145 | struct rs_tx_column { |
| 146 | enum rs_column_mode mode; |
| 147 | u8 ant; |
| 148 | bool sgi; |
| 149 | enum rs_column next_columns[MAX_NEXT_COLUMNS]; |
| 150 | allow_column_func_t checks[MAX_COLUMN_CHECKS]; |
| 151 | }; |
| 152 | |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 153 | static bool rs_ant_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Eyal Shapira | bb8f44c | 2015-05-27 22:00:03 +0300 | [diff] [blame] | 154 | struct rs_rate *rate, |
Eyal Shapira | 0b8d17f | 2015-02-02 15:21:27 +0200 | [diff] [blame] | 155 | const struct rs_tx_column *next_col) |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 156 | { |
Eyal Shapira | 0b8d17f | 2015-02-02 15:21:27 +0200 | [diff] [blame] | 157 | return iwl_mvm_bt_coex_is_ant_avail(mvm, next_col->ant); |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 160 | static bool rs_mimo_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Eyal Shapira | bb8f44c | 2015-05-27 22:00:03 +0300 | [diff] [blame] | 161 | struct rs_rate *rate, |
Eyal Shapira | 0b8d17f | 2015-02-02 15:21:27 +0200 | [diff] [blame] | 162 | const struct rs_tx_column *next_col) |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 163 | { |
Eyal Shapira | 7ac4a50 | 2015-02-01 21:46:00 +0200 | [diff] [blame] | 164 | struct iwl_mvm_sta *mvmsta; |
| 165 | struct iwl_mvm_vif *mvmvif; |
| 166 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 167 | if (!sta->ht_cap.ht_supported) |
| 168 | return false; |
| 169 | |
| 170 | if (sta->smps_mode == IEEE80211_SMPS_STATIC) |
| 171 | return false; |
| 172 | |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 173 | if (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) < 2) |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 174 | return false; |
| 175 | |
| 176 | if (!iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta)) |
| 177 | return false; |
| 178 | |
Eyal Shapira | 7ac4a50 | 2015-02-01 21:46:00 +0200 | [diff] [blame] | 179 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 180 | mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); |
Eyal Shapira | 7ac4a50 | 2015-02-01 21:46:00 +0200 | [diff] [blame] | 181 | |
Emmanuel Grumbach | 5f0d98f | 2014-10-30 10:19:38 +0200 | [diff] [blame] | 182 | if (mvm->nvm_data->sku_cap_mimo_disabled) |
| 183 | return false; |
| 184 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 185 | return true; |
| 186 | } |
| 187 | |
| 188 | static bool rs_siso_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Eyal Shapira | bb8f44c | 2015-05-27 22:00:03 +0300 | [diff] [blame] | 189 | struct rs_rate *rate, |
Eyal Shapira | 0b8d17f | 2015-02-02 15:21:27 +0200 | [diff] [blame] | 190 | const struct rs_tx_column *next_col) |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 191 | { |
| 192 | if (!sta->ht_cap.ht_supported) |
| 193 | return false; |
| 194 | |
| 195 | return true; |
| 196 | } |
| 197 | |
| 198 | static bool rs_sgi_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Eyal Shapira | bb8f44c | 2015-05-27 22:00:03 +0300 | [diff] [blame] | 199 | struct rs_rate *rate, |
Eyal Shapira | 0b8d17f | 2015-02-02 15:21:27 +0200 | [diff] [blame] | 200 | const struct rs_tx_column *next_col) |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 201 | { |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 202 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
| 203 | struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; |
| 204 | |
| 205 | if (is_ht20(rate) && (ht_cap->cap & |
| 206 | IEEE80211_HT_CAP_SGI_20)) |
| 207 | return true; |
| 208 | if (is_ht40(rate) && (ht_cap->cap & |
| 209 | IEEE80211_HT_CAP_SGI_40)) |
| 210 | return true; |
| 211 | if (is_ht80(rate) && (vht_cap->cap & |
| 212 | IEEE80211_VHT_CAP_SHORT_GI_80)) |
| 213 | return true; |
| 214 | |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | static const struct rs_tx_column rs_tx_columns[] = { |
| 219 | [RS_COLUMN_LEGACY_ANT_A] = { |
| 220 | .mode = RS_LEGACY, |
| 221 | .ant = ANT_A, |
| 222 | .next_columns = { |
| 223 | RS_COLUMN_LEGACY_ANT_B, |
| 224 | RS_COLUMN_SISO_ANT_A, |
Eyal Shapira | 31b2045 | 2014-04-08 17:52:27 +0300 | [diff] [blame] | 225 | RS_COLUMN_MIMO2, |
Eyal Shapira | d8fff91 | 2014-04-06 05:27:36 +0300 | [diff] [blame] | 226 | RS_COLUMN_INVALID, |
| 227 | RS_COLUMN_INVALID, |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 228 | RS_COLUMN_INVALID, |
| 229 | RS_COLUMN_INVALID, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 230 | }, |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 231 | .checks = { |
| 232 | rs_ant_allow, |
| 233 | }, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 234 | }, |
| 235 | [RS_COLUMN_LEGACY_ANT_B] = { |
| 236 | .mode = RS_LEGACY, |
| 237 | .ant = ANT_B, |
| 238 | .next_columns = { |
| 239 | RS_COLUMN_LEGACY_ANT_A, |
| 240 | RS_COLUMN_SISO_ANT_B, |
Eyal Shapira | 31b2045 | 2014-04-08 17:52:27 +0300 | [diff] [blame] | 241 | RS_COLUMN_MIMO2, |
Eyal Shapira | d8fff91 | 2014-04-06 05:27:36 +0300 | [diff] [blame] | 242 | RS_COLUMN_INVALID, |
| 243 | RS_COLUMN_INVALID, |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 244 | RS_COLUMN_INVALID, |
| 245 | RS_COLUMN_INVALID, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 246 | }, |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 247 | .checks = { |
| 248 | rs_ant_allow, |
| 249 | }, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 250 | }, |
| 251 | [RS_COLUMN_SISO_ANT_A] = { |
| 252 | .mode = RS_SISO, |
| 253 | .ant = ANT_A, |
| 254 | .next_columns = { |
| 255 | RS_COLUMN_SISO_ANT_B, |
| 256 | RS_COLUMN_MIMO2, |
| 257 | RS_COLUMN_SISO_ANT_A_SGI, |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 258 | RS_COLUMN_LEGACY_ANT_A, |
| 259 | RS_COLUMN_LEGACY_ANT_B, |
Eyal Shapira | d8fff91 | 2014-04-06 05:27:36 +0300 | [diff] [blame] | 260 | RS_COLUMN_INVALID, |
Eyal Shapira | 31b2045 | 2014-04-08 17:52:27 +0300 | [diff] [blame] | 261 | RS_COLUMN_INVALID, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 262 | }, |
| 263 | .checks = { |
| 264 | rs_siso_allow, |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 265 | rs_ant_allow, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 266 | }, |
| 267 | }, |
| 268 | [RS_COLUMN_SISO_ANT_B] = { |
| 269 | .mode = RS_SISO, |
| 270 | .ant = ANT_B, |
| 271 | .next_columns = { |
| 272 | RS_COLUMN_SISO_ANT_A, |
| 273 | RS_COLUMN_MIMO2, |
| 274 | RS_COLUMN_SISO_ANT_B_SGI, |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 275 | RS_COLUMN_LEGACY_ANT_A, |
| 276 | RS_COLUMN_LEGACY_ANT_B, |
Eyal Shapira | d8fff91 | 2014-04-06 05:27:36 +0300 | [diff] [blame] | 277 | RS_COLUMN_INVALID, |
Eyal Shapira | 31b2045 | 2014-04-08 17:52:27 +0300 | [diff] [blame] | 278 | RS_COLUMN_INVALID, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 279 | }, |
| 280 | .checks = { |
| 281 | rs_siso_allow, |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 282 | rs_ant_allow, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 283 | }, |
| 284 | }, |
| 285 | [RS_COLUMN_SISO_ANT_A_SGI] = { |
| 286 | .mode = RS_SISO, |
| 287 | .ant = ANT_A, |
| 288 | .sgi = true, |
| 289 | .next_columns = { |
| 290 | RS_COLUMN_SISO_ANT_B_SGI, |
| 291 | RS_COLUMN_MIMO2_SGI, |
| 292 | RS_COLUMN_SISO_ANT_A, |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 293 | RS_COLUMN_LEGACY_ANT_A, |
| 294 | RS_COLUMN_LEGACY_ANT_B, |
Eyal Shapira | 31b2045 | 2014-04-08 17:52:27 +0300 | [diff] [blame] | 295 | RS_COLUMN_INVALID, |
| 296 | RS_COLUMN_INVALID, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 297 | }, |
| 298 | .checks = { |
| 299 | rs_siso_allow, |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 300 | rs_ant_allow, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 301 | rs_sgi_allow, |
| 302 | }, |
| 303 | }, |
| 304 | [RS_COLUMN_SISO_ANT_B_SGI] = { |
| 305 | .mode = RS_SISO, |
| 306 | .ant = ANT_B, |
| 307 | .sgi = true, |
| 308 | .next_columns = { |
| 309 | RS_COLUMN_SISO_ANT_A_SGI, |
| 310 | RS_COLUMN_MIMO2_SGI, |
| 311 | RS_COLUMN_SISO_ANT_B, |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 312 | RS_COLUMN_LEGACY_ANT_A, |
| 313 | RS_COLUMN_LEGACY_ANT_B, |
Eyal Shapira | 31b2045 | 2014-04-08 17:52:27 +0300 | [diff] [blame] | 314 | RS_COLUMN_INVALID, |
| 315 | RS_COLUMN_INVALID, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 316 | }, |
| 317 | .checks = { |
| 318 | rs_siso_allow, |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 319 | rs_ant_allow, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 320 | rs_sgi_allow, |
| 321 | }, |
| 322 | }, |
| 323 | [RS_COLUMN_MIMO2] = { |
| 324 | .mode = RS_MIMO2, |
| 325 | .ant = ANT_AB, |
| 326 | .next_columns = { |
| 327 | RS_COLUMN_SISO_ANT_A, |
| 328 | RS_COLUMN_MIMO2_SGI, |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 329 | RS_COLUMN_LEGACY_ANT_A, |
| 330 | RS_COLUMN_LEGACY_ANT_B, |
Eyal Shapira | 31b2045 | 2014-04-08 17:52:27 +0300 | [diff] [blame] | 331 | RS_COLUMN_INVALID, |
| 332 | RS_COLUMN_INVALID, |
| 333 | RS_COLUMN_INVALID, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 334 | }, |
| 335 | .checks = { |
| 336 | rs_mimo_allow, |
| 337 | }, |
| 338 | }, |
| 339 | [RS_COLUMN_MIMO2_SGI] = { |
| 340 | .mode = RS_MIMO2, |
| 341 | .ant = ANT_AB, |
| 342 | .sgi = true, |
| 343 | .next_columns = { |
| 344 | RS_COLUMN_SISO_ANT_A_SGI, |
| 345 | RS_COLUMN_MIMO2, |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 346 | RS_COLUMN_LEGACY_ANT_A, |
| 347 | RS_COLUMN_LEGACY_ANT_B, |
Eyal Shapira | 31b2045 | 2014-04-08 17:52:27 +0300 | [diff] [blame] | 348 | RS_COLUMN_INVALID, |
| 349 | RS_COLUMN_INVALID, |
| 350 | RS_COLUMN_INVALID, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 351 | }, |
| 352 | .checks = { |
| 353 | rs_mimo_allow, |
| 354 | rs_sgi_allow, |
| 355 | }, |
| 356 | }, |
| 357 | }; |
| 358 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 359 | static inline u8 rs_extract_rate(u32 rate_n_flags) |
| 360 | { |
| 361 | /* also works for HT because bits 7:6 are zero there */ |
| 362 | return (u8)(rate_n_flags & RATE_LEGACY_RATE_MSK); |
| 363 | } |
| 364 | |
| 365 | static int iwl_hwrate_to_plcp_idx(u32 rate_n_flags) |
| 366 | { |
| 367 | int idx = 0; |
| 368 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 369 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 370 | idx = rate_n_flags & RATE_HT_MCS_RATE_CODE_MSK; |
| 371 | idx += IWL_RATE_MCS_0_INDEX; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 372 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 373 | /* skip 9M not supported in HT*/ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 374 | if (idx >= IWL_RATE_9M_INDEX) |
| 375 | idx += 1; |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 376 | if ((idx >= IWL_FIRST_HT_RATE) && (idx <= IWL_LAST_HT_RATE)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 377 | return idx; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 378 | } else if (rate_n_flags & RATE_MCS_VHT_MSK) { |
| 379 | idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK; |
| 380 | idx += IWL_RATE_MCS_0_INDEX; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 381 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 382 | /* skip 9M not supported in VHT*/ |
| 383 | if (idx >= IWL_RATE_9M_INDEX) |
| 384 | idx++; |
| 385 | if ((idx >= IWL_FIRST_VHT_RATE) && (idx <= IWL_LAST_VHT_RATE)) |
| 386 | return idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 387 | } else { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 388 | /* legacy rate format, search for match in table */ |
| 389 | |
| 390 | u8 legacy_rate = rs_extract_rate(rate_n_flags); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 391 | for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++) |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 392 | if (iwl_rates[idx].plcp == legacy_rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 393 | return idx; |
| 394 | } |
| 395 | |
Eyal Shapira | 560843f | 2014-01-05 21:04:19 +0200 | [diff] [blame] | 396 | return IWL_RATE_INVALID; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static void rs_rate_scale_perform(struct iwl_mvm *mvm, |
Eyal Shapira | 1ebc8f2 | 2014-09-14 15:23:23 +0300 | [diff] [blame] | 400 | struct ieee80211_sta *sta, |
| 401 | struct iwl_lq_sta *lq_sta, |
Matti Gottlieb | ff7a68d | 2016-05-17 10:50:08 +0300 | [diff] [blame^] | 402 | int tid, bool ndp); |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 403 | static void rs_fill_lq_cmd(struct iwl_mvm *mvm, |
| 404 | struct ieee80211_sta *sta, |
| 405 | struct iwl_lq_sta *lq_sta, |
| 406 | const struct rs_rate *initial_rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 407 | 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] | 408 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 409 | /** |
| 410 | * The following tables contain the expected throughput metrics for all rates |
| 411 | * |
| 412 | * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits |
| 413 | * |
| 414 | * where invalid entries are zeros. |
| 415 | * |
| 416 | * CCK rates are only valid in legacy table and will only be used in G |
| 417 | * (2.4 GHz) band. |
| 418 | */ |
| 419 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 420 | static const u16 expected_tpt_legacy[IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 421 | 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] | 422 | }; |
| 423 | |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 424 | /* Expected TpT tables. 4 indexes: |
| 425 | * 0 - NGI, 1 - SGI, 2 - AGG+NGI, 3 - AGG+SGI |
| 426 | */ |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 427 | static const u16 expected_tpt_siso_20MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 428 | {0, 0, 0, 0, 42, 0, 76, 102, 124, 159, 183, 193, 202, 216, 0}, |
| 429 | {0, 0, 0, 0, 46, 0, 82, 110, 132, 168, 192, 202, 210, 225, 0}, |
| 430 | {0, 0, 0, 0, 49, 0, 97, 145, 192, 285, 375, 420, 464, 551, 0}, |
| 431 | {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] | 432 | }; |
| 433 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 434 | static const u16 expected_tpt_siso_40MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 435 | {0, 0, 0, 0, 77, 0, 127, 160, 184, 220, 242, 250, 257, 269, 275}, |
| 436 | {0, 0, 0, 0, 83, 0, 135, 169, 193, 229, 250, 257, 264, 275, 280}, |
| 437 | {0, 0, 0, 0, 101, 0, 199, 295, 389, 570, 744, 828, 911, 1070, 1173}, |
| 438 | {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] | 439 | }; |
| 440 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 441 | static const u16 expected_tpt_siso_80MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 442 | {0, 0, 0, 0, 130, 0, 191, 223, 244, 273, 288, 294, 298, 305, 308}, |
| 443 | {0, 0, 0, 0, 138, 0, 200, 231, 251, 279, 293, 298, 302, 308, 312}, |
| 444 | {0, 0, 0, 0, 217, 0, 429, 634, 834, 1220, 1585, 1760, 1931, 2258, 2466}, |
| 445 | {0, 0, 0, 0, 241, 0, 475, 701, 921, 1343, 1741, 1931, 2117, 2468, 2691}, |
| 446 | }; |
| 447 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 448 | static const u16 expected_tpt_mimo2_20MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 449 | {0, 0, 0, 0, 74, 0, 123, 155, 179, 213, 235, 243, 250, 261, 0}, |
| 450 | {0, 0, 0, 0, 81, 0, 131, 164, 187, 221, 242, 250, 256, 267, 0}, |
| 451 | {0, 0, 0, 0, 98, 0, 193, 286, 375, 550, 718, 799, 878, 1032, 0}, |
| 452 | {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] | 453 | }; |
| 454 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 455 | static const u16 expected_tpt_mimo2_40MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 456 | {0, 0, 0, 0, 123, 0, 182, 214, 235, 264, 279, 285, 289, 296, 300}, |
| 457 | {0, 0, 0, 0, 131, 0, 191, 222, 242, 270, 284, 289, 293, 300, 303}, |
| 458 | {0, 0, 0, 0, 200, 0, 390, 571, 741, 1067, 1365, 1505, 1640, 1894, 2053}, |
| 459 | {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] | 460 | }; |
| 461 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 462 | static const u16 expected_tpt_mimo2_80MHz[4][IWL_RATE_COUNT] = { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 463 | {0, 0, 0, 0, 182, 0, 240, 264, 278, 299, 308, 311, 313, 317, 319}, |
| 464 | {0, 0, 0, 0, 190, 0, 247, 269, 282, 302, 310, 313, 315, 319, 320}, |
| 465 | {0, 0, 0, 0, 428, 0, 833, 1215, 1577, 2254, 2863, 3147, 3418, 3913, 4219}, |
| 466 | {0, 0, 0, 0, 474, 0, 920, 1338, 1732, 2464, 3116, 3418, 3705, 4225, 4545}, |
| 467 | }; |
| 468 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 469 | /* mbps, mcs */ |
| 470 | static const struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = { |
| 471 | { "1", "BPSK DSSS"}, |
| 472 | { "2", "QPSK DSSS"}, |
| 473 | {"5.5", "BPSK CCK"}, |
| 474 | { "11", "QPSK CCK"}, |
| 475 | { "6", "BPSK 1/2"}, |
| 476 | { "9", "BPSK 1/2"}, |
| 477 | { "12", "QPSK 1/2"}, |
| 478 | { "18", "QPSK 3/4"}, |
| 479 | { "24", "16QAM 1/2"}, |
| 480 | { "36", "16QAM 3/4"}, |
| 481 | { "48", "64QAM 2/3"}, |
| 482 | { "54", "64QAM 3/4"}, |
| 483 | { "60", "64QAM 5/6"}, |
| 484 | }; |
| 485 | |
| 486 | #define MCS_INDEX_PER_STREAM (8) |
| 487 | |
Emmanuel Grumbach | 9d10849 | 2013-12-03 11:50:30 +0200 | [diff] [blame] | 488 | static const char *rs_pretty_ant(u8 ant) |
| 489 | { |
| 490 | static const char * const ant_name[] = { |
| 491 | [ANT_NONE] = "None", |
| 492 | [ANT_A] = "A", |
| 493 | [ANT_B] = "B", |
| 494 | [ANT_AB] = "AB", |
| 495 | [ANT_C] = "C", |
| 496 | [ANT_AC] = "AC", |
| 497 | [ANT_BC] = "BC", |
| 498 | [ANT_ABC] = "ABC", |
| 499 | }; |
| 500 | |
| 501 | if (ant > ANT_ABC) |
| 502 | return "UNKNOWN"; |
| 503 | |
| 504 | return ant_name[ant]; |
| 505 | } |
| 506 | |
| 507 | static const char *rs_pretty_lq_type(enum iwl_table_type type) |
| 508 | { |
| 509 | static const char * const lq_types[] = { |
| 510 | [LQ_NONE] = "NONE", |
| 511 | [LQ_LEGACY_A] = "LEGACY_A", |
| 512 | [LQ_LEGACY_G] = "LEGACY_G", |
| 513 | [LQ_HT_SISO] = "HT SISO", |
| 514 | [LQ_HT_MIMO2] = "HT MIMO", |
| 515 | [LQ_VHT_SISO] = "VHT SISO", |
| 516 | [LQ_VHT_MIMO2] = "VHT MIMO", |
| 517 | }; |
| 518 | |
| 519 | if (type < LQ_NONE || type >= LQ_MAX) |
| 520 | return "UNKNOWN"; |
| 521 | |
| 522 | return lq_types[type]; |
| 523 | } |
| 524 | |
Eyal Shapira | cc60c6e | 2015-09-19 23:37:45 +0300 | [diff] [blame] | 525 | static char *rs_pretty_rate(const struct rs_rate *rate) |
| 526 | { |
| 527 | static char buf[40]; |
| 528 | static const char * const legacy_rates[] = { |
| 529 | [IWL_RATE_1M_INDEX] = "1M", |
| 530 | [IWL_RATE_2M_INDEX] = "2M", |
| 531 | [IWL_RATE_5M_INDEX] = "5.5M", |
| 532 | [IWL_RATE_11M_INDEX] = "11M", |
| 533 | [IWL_RATE_6M_INDEX] = "6M", |
| 534 | [IWL_RATE_9M_INDEX] = "9M", |
| 535 | [IWL_RATE_12M_INDEX] = "12M", |
| 536 | [IWL_RATE_18M_INDEX] = "18M", |
| 537 | [IWL_RATE_24M_INDEX] = "24M", |
| 538 | [IWL_RATE_36M_INDEX] = "36M", |
| 539 | [IWL_RATE_48M_INDEX] = "48M", |
| 540 | [IWL_RATE_54M_INDEX] = "54M", |
| 541 | }; |
| 542 | static const char *const ht_vht_rates[] = { |
| 543 | [IWL_RATE_MCS_0_INDEX] = "MCS0", |
| 544 | [IWL_RATE_MCS_1_INDEX] = "MCS1", |
| 545 | [IWL_RATE_MCS_2_INDEX] = "MCS2", |
| 546 | [IWL_RATE_MCS_3_INDEX] = "MCS3", |
| 547 | [IWL_RATE_MCS_4_INDEX] = "MCS4", |
| 548 | [IWL_RATE_MCS_5_INDEX] = "MCS5", |
| 549 | [IWL_RATE_MCS_6_INDEX] = "MCS6", |
| 550 | [IWL_RATE_MCS_7_INDEX] = "MCS7", |
| 551 | [IWL_RATE_MCS_8_INDEX] = "MCS8", |
| 552 | [IWL_RATE_MCS_9_INDEX] = "MCS9", |
| 553 | }; |
| 554 | const char *rate_str; |
| 555 | |
Eyal Shapira | e8b3f7b | 2015-11-19 18:37:31 +0200 | [diff] [blame] | 556 | if (is_type_legacy(rate->type) && (rate->index <= IWL_RATE_54M_INDEX)) |
Eyal Shapira | cc60c6e | 2015-09-19 23:37:45 +0300 | [diff] [blame] | 557 | rate_str = legacy_rates[rate->index]; |
Eyal Shapira | e8b3f7b | 2015-11-19 18:37:31 +0200 | [diff] [blame] | 558 | else if ((is_type_ht(rate->type) || is_type_vht(rate->type)) && |
Eyal Shapira | 4494541 | 2016-02-01 09:07:05 +0200 | [diff] [blame] | 559 | (rate->index >= IWL_RATE_MCS_0_INDEX) && |
Eyal Shapira | e8b3f7b | 2015-11-19 18:37:31 +0200 | [diff] [blame] | 560 | (rate->index <= IWL_RATE_MCS_9_INDEX)) |
Eyal Shapira | cc60c6e | 2015-09-19 23:37:45 +0300 | [diff] [blame] | 561 | rate_str = ht_vht_rates[rate->index]; |
| 562 | else |
| 563 | rate_str = "BAD_RATE"; |
| 564 | |
| 565 | sprintf(buf, "(%s|%s|%s)", rs_pretty_lq_type(rate->type), |
| 566 | rs_pretty_ant(rate->ant), rate_str); |
| 567 | return buf; |
| 568 | } |
| 569 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 570 | static inline void rs_dump_rate(struct iwl_mvm *mvm, const struct rs_rate *rate, |
| 571 | const char *prefix) |
| 572 | { |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 573 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | cc60c6e | 2015-09-19 23:37:45 +0300 | [diff] [blame] | 574 | "%s: %s BW: %d SGI: %d LDPC: %d STBC: %d\n", |
| 575 | prefix, rs_pretty_rate(rate), rate->bw, |
| 576 | rate->sgi, rate->ldpc, rate->stbc); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 577 | } |
| 578 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 579 | static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window) |
| 580 | { |
| 581 | window->data = 0; |
| 582 | window->success_counter = 0; |
| 583 | window->success_ratio = IWL_INVALID_VALUE; |
| 584 | window->counter = 0; |
| 585 | window->average_tpt = IWL_INVALID_VALUE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Eyal Shapira | b804eeb | 2014-04-06 04:27:06 +0300 | [diff] [blame] | 588 | static void rs_rate_scale_clear_tbl_windows(struct iwl_mvm *mvm, |
| 589 | struct iwl_scale_tbl_info *tbl) |
Eliad Peller | 3ca71f6 | 2014-03-10 16:33:43 +0200 | [diff] [blame] | 590 | { |
| 591 | int i; |
| 592 | |
Eyal Shapira | b804eeb | 2014-04-06 04:27:06 +0300 | [diff] [blame] | 593 | IWL_DEBUG_RATE(mvm, "Clearing up window stats\n"); |
Eliad Peller | 3ca71f6 | 2014-03-10 16:33:43 +0200 | [diff] [blame] | 594 | for (i = 0; i < IWL_RATE_COUNT; i++) |
| 595 | rs_rate_scale_clear_window(&tbl->win[i]); |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 596 | |
| 597 | for (i = 0; i < ARRAY_SIZE(tbl->tpc_win); i++) |
| 598 | rs_rate_scale_clear_window(&tbl->tpc_win[i]); |
Eliad Peller | 3ca71f6 | 2014-03-10 16:33:43 +0200 | [diff] [blame] | 599 | } |
| 600 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 601 | static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type) |
| 602 | { |
| 603 | return (ant_type & valid_antenna) == ant_type; |
| 604 | } |
| 605 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 606 | static int rs_tl_turn_on_agg_for_tid(struct iwl_mvm *mvm, |
Eyal Shapira | 40ce5ed | 2015-09-19 23:54:38 +0300 | [diff] [blame] | 607 | struct iwl_lq_sta *lq_data, u8 tid, |
| 608 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 609 | { |
| 610 | int ret = -EAGAIN; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 611 | |
Emmanuel Grumbach | 44cc429 | 2013-06-18 06:33:49 +0300 | [diff] [blame] | 612 | IWL_DEBUG_HT(mvm, "Starting Tx agg: STA: %pM tid: %d\n", |
| 613 | sta->addr, tid); |
| 614 | ret = ieee80211_start_tx_ba_session(sta, tid, 5000); |
| 615 | if (ret == -EAGAIN) { |
| 616 | /* |
| 617 | * driver and mac80211 is out of sync |
| 618 | * this might be cause by reloading firmware |
| 619 | * stop the tx ba session here |
| 620 | */ |
| 621 | IWL_ERR(mvm, "Fail start Tx agg on tid: %d\n", |
| 622 | tid); |
| 623 | ieee80211_stop_tx_ba_session(sta, tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 624 | } |
| 625 | return ret; |
| 626 | } |
| 627 | |
| 628 | static void rs_tl_turn_on_agg(struct iwl_mvm *mvm, u8 tid, |
| 629 | struct iwl_lq_sta *lq_data, |
| 630 | struct ieee80211_sta *sta) |
| 631 | { |
| 632 | if (tid < IWL_MAX_TID_COUNT) |
| 633 | rs_tl_turn_on_agg_for_tid(mvm, lq_data, tid, sta); |
| 634 | else |
| 635 | IWL_ERR(mvm, "tid exceeds max TID count: %d/%d\n", |
| 636 | tid, IWL_MAX_TID_COUNT); |
| 637 | } |
| 638 | |
| 639 | static inline int get_num_of_ant_from_rate(u32 rate_n_flags) |
| 640 | { |
| 641 | return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) + |
| 642 | !!(rate_n_flags & RATE_MCS_ANT_B_MSK) + |
| 643 | !!(rate_n_flags & RATE_MCS_ANT_C_MSK); |
| 644 | } |
| 645 | |
| 646 | /* |
| 647 | * Static function to get the expected throughput from an iwl_scale_tbl_info |
| 648 | * that wraps a NULL pointer check |
| 649 | */ |
| 650 | static s32 get_expected_tpt(struct iwl_scale_tbl_info *tbl, int rs_index) |
| 651 | { |
| 652 | if (tbl->expected_tpt) |
| 653 | return tbl->expected_tpt[rs_index]; |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * rs_collect_tx_data - Update the success/failure sliding window |
| 659 | * |
| 660 | * We keep a sliding window of the last 62 packets transmitted |
| 661 | * at this rate. window->data contains the bitmask of successful |
| 662 | * packets. |
| 663 | */ |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 664 | static int _rs_collect_tx_data(struct iwl_mvm *mvm, |
| 665 | struct iwl_scale_tbl_info *tbl, |
Eliad Peller | 0bd3c5a | 2014-03-10 16:07:04 +0200 | [diff] [blame] | 666 | int scale_index, int attempts, int successes, |
| 667 | struct iwl_rate_scale_data *window) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 668 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 669 | static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1)); |
| 670 | s32 fail_count, tpt; |
| 671 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 672 | /* Get expected throughput */ |
| 673 | tpt = get_expected_tpt(tbl, scale_index); |
| 674 | |
| 675 | /* |
| 676 | * Keep track of only the latest 62 tx frame attempts in this rate's |
| 677 | * history window; anything older isn't really relevant any more. |
| 678 | * If we have filled up the sliding window, drop the oldest attempt; |
| 679 | * if the oldest attempt (highest bit in bitmap) shows "success", |
| 680 | * subtract "1" from the success counter (this is the main reason |
| 681 | * we keep these bitmaps!). |
| 682 | */ |
| 683 | while (attempts > 0) { |
| 684 | if (window->counter >= IWL_RATE_MAX_WINDOW) { |
| 685 | /* remove earliest */ |
| 686 | window->counter = IWL_RATE_MAX_WINDOW - 1; |
| 687 | |
| 688 | if (window->data & mask) { |
| 689 | window->data &= ~mask; |
| 690 | window->success_counter--; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | /* Increment frames-attempted counter */ |
| 695 | window->counter++; |
| 696 | |
| 697 | /* Shift bitmap by one frame to throw away oldest history */ |
| 698 | window->data <<= 1; |
| 699 | |
| 700 | /* Mark the most recent #successes attempts as successful */ |
| 701 | if (successes > 0) { |
| 702 | window->success_counter++; |
| 703 | window->data |= 0x1; |
| 704 | successes--; |
| 705 | } |
| 706 | |
| 707 | attempts--; |
| 708 | } |
| 709 | |
| 710 | /* Calculate current success ratio, avoid divide-by-0! */ |
| 711 | if (window->counter > 0) |
| 712 | window->success_ratio = 128 * (100 * window->success_counter) |
| 713 | / window->counter; |
| 714 | else |
| 715 | window->success_ratio = IWL_INVALID_VALUE; |
| 716 | |
| 717 | fail_count = window->counter - window->success_counter; |
| 718 | |
| 719 | /* Calculate average throughput, if we have enough history. */ |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 720 | if ((fail_count >= IWL_MVM_RS_RATE_MIN_FAILURE_TH) || |
| 721 | (window->success_counter >= IWL_MVM_RS_RATE_MIN_SUCCESS_TH)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 722 | window->average_tpt = (window->success_ratio * tpt + 64) / 128; |
| 723 | else |
| 724 | window->average_tpt = IWL_INVALID_VALUE; |
| 725 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 726 | return 0; |
| 727 | } |
| 728 | |
Gregory Greenman | 69c7fda | 2015-12-29 11:26:35 +0200 | [diff] [blame] | 729 | static int rs_collect_tpc_data(struct iwl_mvm *mvm, |
| 730 | struct iwl_lq_sta *lq_sta, |
| 731 | struct iwl_scale_tbl_info *tbl, |
| 732 | int scale_index, int attempts, int successes, |
| 733 | u8 reduced_txp) |
Eliad Peller | 0bd3c5a | 2014-03-10 16:07:04 +0200 | [diff] [blame] | 734 | { |
| 735 | struct iwl_rate_scale_data *window = NULL; |
Gregory Greenman | 69c7fda | 2015-12-29 11:26:35 +0200 | [diff] [blame] | 736 | |
| 737 | if (WARN_ON_ONCE(reduced_txp > TPC_MAX_REDUCTION)) |
| 738 | return -EINVAL; |
| 739 | |
| 740 | window = &tbl->tpc_win[reduced_txp]; |
| 741 | return _rs_collect_tx_data(mvm, tbl, scale_index, attempts, successes, |
| 742 | window); |
| 743 | } |
| 744 | |
| 745 | static int rs_collect_tlc_data(struct iwl_mvm *mvm, |
| 746 | struct iwl_lq_sta *lq_sta, |
| 747 | struct iwl_scale_tbl_info *tbl, |
| 748 | int scale_index, int attempts, int successes) |
| 749 | { |
| 750 | struct iwl_rate_scale_data *window = NULL; |
Eliad Peller | 0bd3c5a | 2014-03-10 16:07:04 +0200 | [diff] [blame] | 751 | |
| 752 | if (scale_index < 0 || scale_index >= IWL_RATE_COUNT) |
| 753 | return -EINVAL; |
| 754 | |
Eyal Shapira | 757cf23b | 2014-03-24 02:12:00 +0200 | [diff] [blame] | 755 | if (tbl->column != RS_COLUMN_INVALID) { |
Eyal Shapira | f58220f | 2014-08-16 01:30:30 +0300 | [diff] [blame] | 756 | struct lq_sta_pers *pers = &lq_sta->pers; |
| 757 | |
| 758 | pers->tx_stats[tbl->column][scale_index].total += attempts; |
| 759 | pers->tx_stats[tbl->column][scale_index].success += successes; |
Eyal Shapira | 757cf23b | 2014-03-24 02:12:00 +0200 | [diff] [blame] | 760 | } |
| 761 | |
Eliad Peller | 0bd3c5a | 2014-03-10 16:07:04 +0200 | [diff] [blame] | 762 | /* Select window for current tx bit rate */ |
| 763 | window = &(tbl->win[scale_index]); |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 764 | return _rs_collect_tx_data(mvm, tbl, scale_index, attempts, successes, |
Eliad Peller | 0bd3c5a | 2014-03-10 16:07:04 +0200 | [diff] [blame] | 765 | window); |
| 766 | } |
| 767 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 768 | /* Convert rs_rate object into ucode rate bitmask */ |
| 769 | static u32 ucode_rate_from_rs_rate(struct iwl_mvm *mvm, |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 770 | struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 771 | { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 772 | u32 ucode_rate = 0; |
| 773 | int index = rate->index; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 774 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 775 | ucode_rate |= ((rate->ant << RATE_MCS_ANT_POS) & |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 776 | RATE_MCS_ANT_ABC_MSK); |
| 777 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 778 | if (is_legacy(rate)) { |
| 779 | ucode_rate |= iwl_rates[index].plcp; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 780 | if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 781 | ucode_rate |= RATE_MCS_CCK_MSK; |
| 782 | return ucode_rate; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 783 | } |
| 784 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 785 | if (is_ht(rate)) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 786 | if (index < IWL_FIRST_HT_RATE || index > IWL_LAST_HT_RATE) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 787 | IWL_ERR(mvm, "Invalid HT rate index %d\n", index); |
Eyal Shapira | 4e82dd3 | 2013-08-04 23:58:37 +0300 | [diff] [blame] | 788 | index = IWL_LAST_HT_RATE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 789 | } |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 790 | ucode_rate |= RATE_MCS_HT_MSK; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 791 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 792 | if (is_ht_siso(rate)) |
| 793 | ucode_rate |= iwl_rates[index].plcp_ht_siso; |
| 794 | else if (is_ht_mimo2(rate)) |
| 795 | ucode_rate |= iwl_rates[index].plcp_ht_mimo2; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 796 | else |
Eyal Shapira | d972ab3 | 2013-07-28 23:02:45 +0000 | [diff] [blame] | 797 | WARN_ON_ONCE(1); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 798 | } else if (is_vht(rate)) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 799 | if (index < IWL_FIRST_VHT_RATE || index > IWL_LAST_VHT_RATE) { |
| 800 | IWL_ERR(mvm, "Invalid VHT rate index %d\n", index); |
| 801 | index = IWL_LAST_VHT_RATE; |
| 802 | } |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 803 | ucode_rate |= RATE_MCS_VHT_MSK; |
| 804 | if (is_vht_siso(rate)) |
| 805 | ucode_rate |= iwl_rates[index].plcp_vht_siso; |
| 806 | else if (is_vht_mimo2(rate)) |
| 807 | ucode_rate |= iwl_rates[index].plcp_vht_mimo2; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 808 | else |
| 809 | WARN_ON_ONCE(1); |
| 810 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 811 | } else { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 812 | IWL_ERR(mvm, "Invalid rate->type %d\n", rate->type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 813 | } |
| 814 | |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 815 | if (is_siso(rate) && rate->stbc) { |
| 816 | /* To enable STBC we need to set both a flag and ANT_AB */ |
| 817 | ucode_rate |= RATE_MCS_ANT_AB_MSK; |
| 818 | ucode_rate |= RATE_MCS_VHT_STBC_MSK; |
| 819 | } |
| 820 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 821 | ucode_rate |= rate->bw; |
| 822 | if (rate->sgi) |
| 823 | ucode_rate |= RATE_MCS_SGI_MSK; |
Eyal Shapira | a3576ff | 2014-08-09 10:57:59 +0300 | [diff] [blame] | 824 | if (rate->ldpc) |
| 825 | ucode_rate |= RATE_MCS_LDPC_MSK; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 826 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 827 | return ucode_rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 828 | } |
| 829 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 830 | /* Convert a ucode rate into an rs_rate object */ |
| 831 | static int rs_rate_from_ucode_rate(const u32 ucode_rate, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 832 | enum nl80211_band band, |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 833 | struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 834 | { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 835 | u32 ant_msk = ucode_rate & RATE_MCS_ANT_ABC_MSK; |
| 836 | u8 num_of_ant = get_num_of_ant_from_rate(ucode_rate); |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 837 | u8 nss; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 838 | |
Emmanuel Grumbach | 9e898f1 | 2013-12-22 10:55:47 +0200 | [diff] [blame] | 839 | memset(rate, 0, sizeof(*rate)); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 840 | rate->index = iwl_hwrate_to_plcp_idx(ucode_rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 841 | |
Eyal Shapira | 560843f | 2014-01-05 21:04:19 +0200 | [diff] [blame] | 842 | if (rate->index == IWL_RATE_INVALID) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 843 | return -EINVAL; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 844 | |
| 845 | rate->ant = (ant_msk >> RATE_MCS_ANT_POS); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 846 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 847 | /* Legacy */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 848 | if (!(ucode_rate & RATE_MCS_HT_MSK) && |
| 849 | !(ucode_rate & RATE_MCS_VHT_MSK)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 850 | if (num_of_ant == 1) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 851 | if (band == NL80211_BAND_5GHZ) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 852 | rate->type = LQ_LEGACY_A; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 853 | else |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 854 | rate->type = LQ_LEGACY_G; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 855 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 856 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 857 | return 0; |
| 858 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 859 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 860 | /* HT or VHT */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 861 | if (ucode_rate & RATE_MCS_SGI_MSK) |
| 862 | rate->sgi = true; |
Eyal Shapira | a3576ff | 2014-08-09 10:57:59 +0300 | [diff] [blame] | 863 | if (ucode_rate & RATE_MCS_LDPC_MSK) |
| 864 | rate->ldpc = true; |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 865 | if (ucode_rate & RATE_MCS_VHT_STBC_MSK) |
| 866 | rate->stbc = true; |
Eyal Shapira | ba69d0e | 2015-01-30 01:38:29 +0200 | [diff] [blame] | 867 | if (ucode_rate & RATE_MCS_BF_MSK) |
| 868 | rate->bfer = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 869 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 870 | rate->bw = ucode_rate & RATE_MCS_CHAN_WIDTH_MSK; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 871 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 872 | if (ucode_rate & RATE_MCS_HT_MSK) { |
| 873 | nss = ((ucode_rate & RATE_HT_MCS_NSS_MSK) >> |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 874 | RATE_HT_MCS_NSS_POS) + 1; |
| 875 | |
| 876 | if (nss == 1) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 877 | rate->type = LQ_HT_SISO; |
Eyal Shapira | ba69d0e | 2015-01-30 01:38:29 +0200 | [diff] [blame] | 878 | WARN_ONCE(!rate->stbc && !rate->bfer && num_of_ant != 1, |
| 879 | "stbc %d bfer %d", |
| 880 | rate->stbc, rate->bfer); |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 881 | } else if (nss == 2) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 882 | rate->type = LQ_HT_MIMO2; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 883 | WARN_ON_ONCE(num_of_ant != 2); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 884 | } else { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 885 | WARN_ON_ONCE(1); |
| 886 | } |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 887 | } else if (ucode_rate & RATE_MCS_VHT_MSK) { |
| 888 | nss = ((ucode_rate & RATE_VHT_MCS_NSS_MSK) >> |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 889 | RATE_VHT_MCS_NSS_POS) + 1; |
| 890 | |
| 891 | if (nss == 1) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 892 | rate->type = LQ_VHT_SISO; |
Eyal Shapira | ba69d0e | 2015-01-30 01:38:29 +0200 | [diff] [blame] | 893 | WARN_ONCE(!rate->stbc && !rate->bfer && num_of_ant != 1, |
| 894 | "stbc %d bfer %d", |
| 895 | rate->stbc, rate->bfer); |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 896 | } else if (nss == 2) { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 897 | rate->type = LQ_VHT_MIMO2; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 898 | WARN_ON_ONCE(num_of_ant != 2); |
| 899 | } else { |
| 900 | WARN_ON_ONCE(1); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 901 | } |
| 902 | } |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 903 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 904 | WARN_ON_ONCE(rate->bw == RATE_MCS_CHAN_WIDTH_160); |
| 905 | WARN_ON_ONCE(rate->bw == RATE_MCS_CHAN_WIDTH_80 && |
| 906 | !is_vht(rate)); |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 907 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | /* switch to another antenna/antennas and return 1 */ |
| 912 | /* if no other valid antenna found, return 0 */ |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 913 | static int rs_toggle_antenna(u32 valid_ant, struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 914 | { |
| 915 | u8 new_ant_type; |
| 916 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 917 | if (!rate->ant || rate->ant > ANT_ABC) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 918 | return 0; |
| 919 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 920 | if (!rs_is_valid_ant(valid_ant, rate->ant)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 921 | return 0; |
| 922 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 923 | new_ant_type = ant_toggle_lookup[rate->ant]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 924 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 925 | while ((new_ant_type != rate->ant) && |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 926 | !rs_is_valid_ant(valid_ant, new_ant_type)) |
| 927 | new_ant_type = ant_toggle_lookup[new_ant_type]; |
| 928 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 929 | if (new_ant_type == rate->ant) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 930 | return 0; |
| 931 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 932 | rate->ant = new_ant_type; |
| 933 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 934 | return 1; |
| 935 | } |
| 936 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 937 | static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta, |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 938 | struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 939 | { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 940 | if (is_legacy(rate)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 941 | return lq_sta->active_legacy_rate; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 942 | else if (is_siso(rate)) |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 943 | return lq_sta->active_siso_rate; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 944 | else if (is_mimo2(rate)) |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 945 | return lq_sta->active_mimo2_rate; |
| 946 | |
| 947 | WARN_ON_ONCE(1); |
| 948 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | static u16 rs_get_adjacent_rate(struct iwl_mvm *mvm, u8 index, u16 rate_mask, |
| 952 | int rate_type) |
| 953 | { |
| 954 | u8 high = IWL_RATE_INVALID; |
| 955 | u8 low = IWL_RATE_INVALID; |
| 956 | |
| 957 | /* 802.11A or ht walks to the next literal adjacent rate in |
| 958 | * the rate table */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 959 | if (is_type_a_band(rate_type) || !is_type_legacy(rate_type)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 960 | int i; |
| 961 | u32 mask; |
| 962 | |
| 963 | /* Find the previous rate that is in the rate mask */ |
| 964 | i = index - 1; |
| 965 | for (mask = (1 << i); i >= 0; i--, mask >>= 1) { |
| 966 | if (rate_mask & mask) { |
| 967 | low = i; |
| 968 | break; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | /* Find the next rate that is in the rate mask */ |
| 973 | i = index + 1; |
| 974 | for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) { |
| 975 | if (rate_mask & mask) { |
| 976 | high = i; |
| 977 | break; |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | return (high << 8) | low; |
| 982 | } |
| 983 | |
| 984 | low = index; |
| 985 | while (low != IWL_RATE_INVALID) { |
| 986 | low = iwl_rates[low].prev_rs; |
| 987 | if (low == IWL_RATE_INVALID) |
| 988 | break; |
| 989 | if (rate_mask & (1 << low)) |
| 990 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | high = index; |
| 994 | while (high != IWL_RATE_INVALID) { |
| 995 | high = iwl_rates[high].next_rs; |
| 996 | if (high == IWL_RATE_INVALID) |
| 997 | break; |
| 998 | if (rate_mask & (1 << high)) |
| 999 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | return (high << 8) | low; |
| 1003 | } |
| 1004 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1005 | static inline bool rs_rate_supported(struct iwl_lq_sta *lq_sta, |
| 1006 | struct rs_rate *rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1007 | { |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1008 | return BIT(rate->index) & rs_get_supported_rates(lq_sta, rate); |
| 1009 | } |
| 1010 | |
| 1011 | /* Get the next supported lower rate in the current column. |
| 1012 | * Return true if bottom rate in the current column was reached |
| 1013 | */ |
| 1014 | static bool rs_get_lower_rate_in_column(struct iwl_lq_sta *lq_sta, |
| 1015 | struct rs_rate *rate) |
| 1016 | { |
| 1017 | u8 low; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1018 | u16 high_low; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1019 | u16 rate_mask; |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 1020 | struct iwl_mvm *mvm = lq_sta->pers.drv; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1021 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1022 | rate_mask = rs_get_supported_rates(lq_sta, rate); |
| 1023 | high_low = rs_get_adjacent_rate(mvm, rate->index, rate_mask, |
| 1024 | rate->type); |
| 1025 | low = high_low & 0xff; |
| 1026 | |
| 1027 | /* Bottom rate of column reached */ |
| 1028 | if (low == IWL_RATE_INVALID) |
| 1029 | return true; |
| 1030 | |
| 1031 | rate->index = low; |
| 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | /* Get the next rate to use following a column downgrade */ |
| 1036 | static void rs_get_lower_rate_down_column(struct iwl_lq_sta *lq_sta, |
| 1037 | struct rs_rate *rate) |
| 1038 | { |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 1039 | struct iwl_mvm *mvm = lq_sta->pers.drv; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1040 | |
| 1041 | if (is_legacy(rate)) { |
| 1042 | /* No column to downgrade from Legacy */ |
| 1043 | return; |
| 1044 | } else if (is_siso(rate)) { |
| 1045 | /* Downgrade to Legacy if we were in SISO */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1046 | if (lq_sta->band == NL80211_BAND_5GHZ) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1047 | rate->type = LQ_LEGACY_A; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1048 | else |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1049 | rate->type = LQ_LEGACY_G; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1050 | |
Eyal Shapira | a56db7d | 2013-11-28 12:35:42 +0200 | [diff] [blame] | 1051 | rate->bw = RATE_MCS_CHAN_WIDTH_20; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1052 | |
Emmanuel Grumbach | b800040 | 2014-02-03 22:17:19 +0200 | [diff] [blame] | 1053 | WARN_ON_ONCE(rate->index < IWL_RATE_MCS_0_INDEX || |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1054 | rate->index > IWL_RATE_MCS_9_INDEX); |
| 1055 | |
| 1056 | rate->index = rs_ht_to_legacy[rate->index]; |
Eyal Shapira | a3576ff | 2014-08-09 10:57:59 +0300 | [diff] [blame] | 1057 | rate->ldpc = false; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1058 | } else { |
| 1059 | /* Downgrade to SISO with same MCS if in MIMO */ |
| 1060 | rate->type = is_vht_mimo2(rate) ? |
| 1061 | LQ_VHT_SISO : LQ_HT_SISO; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1064 | if (num_of_ant(rate->ant) > 1) |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 1065 | rate->ant = first_antenna(iwl_mvm_get_valid_tx_ant(mvm)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1066 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1067 | /* Relevant in both switching to SISO or Legacy */ |
| 1068 | rate->sgi = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1069 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 1070 | if (!rs_rate_supported(lq_sta, rate)) |
| 1071 | rs_get_lower_rate_in_column(lq_sta, rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
Eyal Shapira | ba69d0e | 2015-01-30 01:38:29 +0200 | [diff] [blame] | 1074 | /* Check if both rates are identical |
| 1075 | * allow_ant_mismatch enables matching a SISO rate on ANT_A or ANT_B |
| 1076 | * with a rate indicating STBC/BFER and ANT_AB. |
| 1077 | */ |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1078 | static inline bool rs_rate_equal(struct rs_rate *a, |
Eyal Shapira | ba69d0e | 2015-01-30 01:38:29 +0200 | [diff] [blame] | 1079 | struct rs_rate *b, |
| 1080 | bool allow_ant_mismatch) |
| 1081 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1082 | { |
Eyal Shapira | ba69d0e | 2015-01-30 01:38:29 +0200 | [diff] [blame] | 1083 | bool ant_match = (a->ant == b->ant) && (a->stbc == b->stbc) && |
| 1084 | (a->bfer == b->bfer); |
| 1085 | |
| 1086 | if (allow_ant_mismatch) { |
| 1087 | if (a->stbc || a->bfer) { |
| 1088 | WARN_ONCE(a->ant != ANT_AB, "stbc %d bfer %d ant %d", |
| 1089 | a->stbc, a->bfer, a->ant); |
| 1090 | ant_match |= (b->ant == ANT_A || b->ant == ANT_B); |
| 1091 | } else if (b->stbc || b->bfer) { |
| 1092 | WARN_ONCE(b->ant != ANT_AB, "stbc %d bfer %d ant %d", |
| 1093 | b->stbc, b->bfer, b->ant); |
| 1094 | ant_match |= (a->ant == ANT_A || a->ant == ANT_B); |
| 1095 | } |
| 1096 | } |
| 1097 | |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1098 | return (a->type == b->type) && (a->bw == b->bw) && (a->sgi == b->sgi) && |
Eyal Shapira | ba69d0e | 2015-01-30 01:38:29 +0200 | [diff] [blame] | 1099 | (a->ldpc == b->ldpc) && (a->index == b->index) && ant_match; |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | /* Check if both rates share the same column */ |
| 1103 | static inline bool rs_rate_column_match(struct rs_rate *a, |
| 1104 | struct rs_rate *b) |
| 1105 | { |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 1106 | bool ant_match; |
| 1107 | |
Eyal Shapira | ba69d0e | 2015-01-30 01:38:29 +0200 | [diff] [blame] | 1108 | if (a->stbc || a->bfer) |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 1109 | ant_match = (b->ant == ANT_A || b->ant == ANT_B); |
| 1110 | else |
| 1111 | ant_match = (a->ant == b->ant); |
| 1112 | |
| 1113 | return (a->type == b->type) && (a->bw == b->bw) && (a->sgi == b->sgi) |
| 1114 | && ant_match; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1115 | } |
| 1116 | |
Eyal Shapira | ad82d8a | 2015-03-08 19:43:41 +0200 | [diff] [blame] | 1117 | static inline enum rs_column rs_get_column_from_rate(struct rs_rate *rate) |
| 1118 | { |
| 1119 | if (is_legacy(rate)) { |
| 1120 | if (rate->ant == ANT_A) |
| 1121 | return RS_COLUMN_LEGACY_ANT_A; |
| 1122 | |
| 1123 | if (rate->ant == ANT_B) |
| 1124 | return RS_COLUMN_LEGACY_ANT_B; |
| 1125 | |
| 1126 | goto err; |
| 1127 | } |
| 1128 | |
| 1129 | if (is_siso(rate)) { |
| 1130 | if (rate->ant == ANT_A || rate->stbc || rate->bfer) |
| 1131 | return rate->sgi ? RS_COLUMN_SISO_ANT_A_SGI : |
| 1132 | RS_COLUMN_SISO_ANT_A; |
| 1133 | |
| 1134 | if (rate->ant == ANT_B) |
| 1135 | return rate->sgi ? RS_COLUMN_SISO_ANT_B_SGI : |
| 1136 | RS_COLUMN_SISO_ANT_B; |
| 1137 | |
| 1138 | goto err; |
| 1139 | } |
| 1140 | |
| 1141 | if (is_mimo(rate)) |
| 1142 | return rate->sgi ? RS_COLUMN_MIMO2_SGI : RS_COLUMN_MIMO2; |
| 1143 | |
| 1144 | err: |
| 1145 | return RS_COLUMN_INVALID; |
| 1146 | } |
| 1147 | |
Eyal Shapira | 1ebc8f2 | 2014-09-14 15:23:23 +0300 | [diff] [blame] | 1148 | static u8 rs_get_tid(struct ieee80211_hdr *hdr) |
| 1149 | { |
| 1150 | u8 tid = IWL_MAX_TID_COUNT; |
| 1151 | |
| 1152 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 1153 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
| 1154 | tid = qc[0] & 0xf; |
| 1155 | } |
| 1156 | |
| 1157 | if (unlikely(tid > IWL_MAX_TID_COUNT)) |
| 1158 | tid = IWL_MAX_TID_COUNT; |
| 1159 | |
| 1160 | return tid; |
| 1161 | } |
| 1162 | |
| 1163 | void iwl_mvm_rs_tx_status(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Matti Gottlieb | ff7a68d | 2016-05-17 10:50:08 +0300 | [diff] [blame^] | 1164 | int tid, struct ieee80211_tx_info *info, bool ndp) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1165 | { |
| 1166 | int legacy_success; |
| 1167 | int retries; |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1168 | int i; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1169 | struct iwl_lq_cmd *table; |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1170 | u32 lq_hwrate; |
| 1171 | struct rs_rate lq_rate, tx_resp_rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1172 | struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl; |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 1173 | u8 reduced_txp = (uintptr_t)info->status.status_driver_data[0]; |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1174 | u32 tx_resp_hwrate = (uintptr_t)info->status.status_driver_data[1]; |
Eyal Shapira | 1ebc8f2 | 2014-09-14 15:23:23 +0300 | [diff] [blame] | 1175 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 1176 | struct iwl_lq_sta *lq_sta = &mvmsta->lq_sta; |
Johannes Berg | 859d914 | 2015-06-01 17:11:11 +0200 | [diff] [blame] | 1177 | bool allow_ant_mismatch = fw_has_api(&mvm->fw->ucode_capa, |
| 1178 | IWL_UCODE_TLV_API_LQ_SS_PARAMS); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1179 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1180 | /* Treat uninitialized rate scaling data same as non-existing. */ |
| 1181 | if (!lq_sta) { |
| 1182 | IWL_DEBUG_RATE(mvm, "Station rate scaling not created yet.\n"); |
| 1183 | return; |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 1184 | } else if (!lq_sta->pers.drv) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1185 | IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n"); |
| 1186 | return; |
| 1187 | } |
| 1188 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1189 | /* This packet was aggregated but doesn't carry status info */ |
| 1190 | if ((info->flags & IEEE80211_TX_CTL_AMPDU) && |
| 1191 | !(info->flags & IEEE80211_TX_STAT_AMPDU)) |
| 1192 | return; |
| 1193 | |
Eyal Shapira | ad82d8a | 2015-03-08 19:43:41 +0200 | [diff] [blame] | 1194 | rs_rate_from_ucode_rate(tx_resp_hwrate, info->band, &tx_resp_rate); |
| 1195 | |
| 1196 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 1197 | /* Disable last tx check if we are debugging with fixed rate but |
| 1198 | * update tx stats */ |
| 1199 | if (lq_sta->pers.dbg_fixed_rate) { |
| 1200 | int index = tx_resp_rate.index; |
| 1201 | enum rs_column column; |
| 1202 | int attempts, success; |
| 1203 | |
| 1204 | column = rs_get_column_from_rate(&tx_resp_rate); |
| 1205 | if (WARN_ONCE(column == RS_COLUMN_INVALID, |
| 1206 | "Can't map rate 0x%x to column", |
| 1207 | tx_resp_hwrate)) |
| 1208 | return; |
| 1209 | |
| 1210 | if (info->flags & IEEE80211_TX_STAT_AMPDU) { |
| 1211 | attempts = info->status.ampdu_len; |
| 1212 | success = info->status.ampdu_ack_len; |
| 1213 | } else { |
| 1214 | attempts = info->status.rates[0].count; |
| 1215 | success = !!(info->flags & IEEE80211_TX_STAT_ACK); |
| 1216 | } |
| 1217 | |
| 1218 | lq_sta->pers.tx_stats[column][index].total += attempts; |
| 1219 | lq_sta->pers.tx_stats[column][index].success += success; |
| 1220 | |
| 1221 | IWL_DEBUG_RATE(mvm, "Fixed rate 0x%x success %d attempts %d\n", |
| 1222 | tx_resp_hwrate, success, attempts); |
| 1223 | return; |
| 1224 | } |
| 1225 | #endif |
| 1226 | |
Eyal Shapira | 87d5e41 | 2014-04-06 18:13:22 +0300 | [diff] [blame] | 1227 | if (time_after(jiffies, |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 1228 | (unsigned long)(lq_sta->last_tx + |
| 1229 | (IWL_MVM_RS_IDLE_TIMEOUT * HZ)))) { |
Johannes Berg | efad21d2 | 2014-11-03 15:51:47 +0100 | [diff] [blame] | 1230 | int t; |
| 1231 | |
Eyal Shapira | 87d5e41 | 2014-04-06 18:13:22 +0300 | [diff] [blame] | 1232 | IWL_DEBUG_RATE(mvm, "Tx idle for too long. reinit rs\n"); |
Johannes Berg | efad21d2 | 2014-11-03 15:51:47 +0100 | [diff] [blame] | 1233 | for (t = 0; t < IWL_MAX_TID_COUNT; t++) |
| 1234 | ieee80211_stop_tx_ba_session(sta, t); |
Eyal Shapira | 87d5e41 | 2014-04-06 18:13:22 +0300 | [diff] [blame] | 1235 | |
Eyal Shapira | 1ebc8f2 | 2014-09-14 15:23:23 +0300 | [diff] [blame] | 1236 | iwl_mvm_rs_rate_init(mvm, sta, info->band, false); |
Eyal Shapira | 87d5e41 | 2014-04-06 18:13:22 +0300 | [diff] [blame] | 1237 | return; |
| 1238 | } |
| 1239 | lq_sta->last_tx = jiffies; |
| 1240 | |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1241 | /* Ignore this Tx frame response if its initial rate doesn't match |
| 1242 | * that of latest Link Quality command. There may be stragglers |
| 1243 | * from a previous Link Quality command, but we're no longer interested |
| 1244 | * in those; they're either from the "active" mode while we're trying |
| 1245 | * to check "search" mode, or a prior "search" mode after we've moved |
| 1246 | * to a new "search" mode (which might become the new "active" mode). |
| 1247 | */ |
| 1248 | table = &lq_sta->lq; |
| 1249 | lq_hwrate = le32_to_cpu(table->rs_table[0]); |
| 1250 | rs_rate_from_ucode_rate(lq_hwrate, info->band, &lq_rate); |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1251 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1252 | /* Here we actually compare this rate to the latest LQ command */ |
Eyal Shapira | ba69d0e | 2015-01-30 01:38:29 +0200 | [diff] [blame] | 1253 | if (!rs_rate_equal(&tx_resp_rate, &lq_rate, allow_ant_mismatch)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1254 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1255 | "initial tx resp rate 0x%x does not match 0x%x\n", |
| 1256 | tx_resp_hwrate, lq_hwrate); |
| 1257 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1258 | /* |
| 1259 | * Since rates mis-match, the last LQ command may have failed. |
| 1260 | * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with |
| 1261 | * ... driver. |
| 1262 | */ |
| 1263 | lq_sta->missed_rate_counter++; |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 1264 | if (lq_sta->missed_rate_counter > IWL_MVM_RS_MISSED_RATE_MAX) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1265 | lq_sta->missed_rate_counter = 0; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1266 | IWL_DEBUG_RATE(mvm, |
| 1267 | "Too many rates mismatch. Send sync LQ. rs_state %d\n", |
| 1268 | lq_sta->rs_state); |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 1269 | iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1270 | } |
| 1271 | /* Regardless, ignore this status info for outdated rate */ |
| 1272 | return; |
| 1273 | } else |
| 1274 | /* Rate did match, so reset the missed_rate_counter */ |
| 1275 | lq_sta->missed_rate_counter = 0; |
| 1276 | |
Eyal Shapira | 26a2cc0 | 2014-11-05 12:03:59 +0200 | [diff] [blame] | 1277 | if (!lq_sta->search_better_tbl) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1278 | curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1279 | other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); |
Eyal Shapira | 26a2cc0 | 2014-11-05 12:03:59 +0200 | [diff] [blame] | 1280 | } else { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1281 | curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); |
| 1282 | other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Eyal Shapira | 26a2cc0 | 2014-11-05 12:03:59 +0200 | [diff] [blame] | 1283 | } |
| 1284 | |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1285 | if (WARN_ON_ONCE(!rs_rate_column_match(&lq_rate, &curr_tbl->rate))) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1286 | IWL_DEBUG_RATE(mvm, |
| 1287 | "Neither active nor search matches tx rate\n"); |
| 1288 | tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1289 | rs_dump_rate(mvm, &tmp_tbl->rate, "ACTIVE"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1290 | tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1291 | rs_dump_rate(mvm, &tmp_tbl->rate, "SEARCH"); |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1292 | rs_dump_rate(mvm, &lq_rate, "ACTUAL"); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1293 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1294 | /* |
| 1295 | * no matching table found, let's by-pass the data collection |
| 1296 | * and continue to perform rate scale to find the rate table |
| 1297 | */ |
| 1298 | rs_stay_in_table(lq_sta, true); |
| 1299 | goto done; |
| 1300 | } |
| 1301 | |
| 1302 | /* |
| 1303 | * Updating the frame history depends on whether packets were |
| 1304 | * aggregated. |
| 1305 | * |
| 1306 | * For aggregation, all packets were transmitted at the same rate, the |
| 1307 | * first index into rate scale table. |
| 1308 | */ |
| 1309 | if (info->flags & IEEE80211_TX_STAT_AMPDU) { |
Gregory Greenman | 69c7fda | 2015-12-29 11:26:35 +0200 | [diff] [blame] | 1310 | rs_collect_tpc_data(mvm, lq_sta, curr_tbl, lq_rate.index, |
| 1311 | info->status.ampdu_len, |
| 1312 | info->status.ampdu_ack_len, |
| 1313 | reduced_txp); |
| 1314 | |
| 1315 | /* ampdu_ack_len = 0 marks no BA was received. For TLC, treat |
| 1316 | * it as a single frame loss as we don't want the success ratio |
| 1317 | * to dip too quickly because a BA wasn't received. |
| 1318 | * For TPC, there's no need for this optimisation since we want |
| 1319 | * to recover very quickly from a bad power reduction and, |
| 1320 | * therefore we'd like the success ratio to get an immediate hit |
| 1321 | * when failing to get a BA, so we'd switch back to a lower or |
| 1322 | * zero power reduction. When FW transmits agg with a rate |
| 1323 | * different from the initial rate, it will not use reduced txp |
| 1324 | * and will send BA notification twice (one empty with reduced |
| 1325 | * txp equal to the value from LQ and one with reduced txp 0). |
| 1326 | * We need to update counters for each txp level accordingly. |
Eyal Shapira | d6bda66 | 2014-11-12 13:30:20 +0200 | [diff] [blame] | 1327 | */ |
| 1328 | if (info->status.ampdu_ack_len == 0) |
| 1329 | info->status.ampdu_len = 1; |
| 1330 | |
Gregory Greenman | 69c7fda | 2015-12-29 11:26:35 +0200 | [diff] [blame] | 1331 | rs_collect_tlc_data(mvm, lq_sta, curr_tbl, lq_rate.index, |
| 1332 | info->status.ampdu_len, |
| 1333 | info->status.ampdu_ack_len); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1334 | |
| 1335 | /* Update success/fail counts if not searching for new mode */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1336 | if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1337 | lq_sta->total_success += info->status.ampdu_ack_len; |
| 1338 | lq_sta->total_failed += (info->status.ampdu_len - |
| 1339 | info->status.ampdu_ack_len); |
| 1340 | } |
| 1341 | } else { |
Liad Kaufman | 90cb123 | 2015-03-29 11:39:34 +0300 | [diff] [blame] | 1342 | /* For legacy, update frame history with for each Tx retry. */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1343 | retries = info->status.rates[0].count - 1; |
| 1344 | /* HW doesn't send more than 15 retries */ |
| 1345 | retries = min(retries, 15); |
| 1346 | |
| 1347 | /* The last transmission may have been successful */ |
| 1348 | legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK); |
| 1349 | /* Collect data for each rate used during failed TX attempts */ |
| 1350 | for (i = 0; i <= retries; ++i) { |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1351 | lq_hwrate = le32_to_cpu(table->rs_table[i]); |
| 1352 | rs_rate_from_ucode_rate(lq_hwrate, info->band, |
| 1353 | &lq_rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1354 | /* |
| 1355 | * Only collect stats if retried rate is in the same RS |
| 1356 | * table as active/search. |
| 1357 | */ |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1358 | if (rs_rate_column_match(&lq_rate, &curr_tbl->rate)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1359 | tmp_tbl = curr_tbl; |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1360 | else if (rs_rate_column_match(&lq_rate, |
| 1361 | &other_tbl->rate)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1362 | tmp_tbl = other_tbl; |
Eyal Shapira | 4107dbd | 2013-12-10 12:20:37 +0200 | [diff] [blame] | 1363 | else |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1364 | continue; |
Eyal Shapira | 4107dbd | 2013-12-10 12:20:37 +0200 | [diff] [blame] | 1365 | |
Gregory Greenman | 69c7fda | 2015-12-29 11:26:35 +0200 | [diff] [blame] | 1366 | rs_collect_tpc_data(mvm, lq_sta, tmp_tbl, |
| 1367 | lq_rate.index, 1, |
| 1368 | i < retries ? 0 : legacy_success, |
| 1369 | reduced_txp); |
| 1370 | rs_collect_tlc_data(mvm, lq_sta, tmp_tbl, |
| 1371 | lq_rate.index, 1, |
| 1372 | i < retries ? 0 : legacy_success); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | /* Update success/fail counts if not searching for new mode */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1376 | if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1377 | lq_sta->total_success += legacy_success; |
| 1378 | lq_sta->total_failed += retries + (1 - legacy_success); |
| 1379 | } |
| 1380 | } |
| 1381 | /* The last TX rate is cached in lq_sta; it's set in if/else above */ |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1382 | lq_sta->last_rate_n_flags = lq_hwrate; |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 1383 | IWL_DEBUG_RATE(mvm, "reduced txpower: %d\n", reduced_txp); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1384 | done: |
| 1385 | /* See if there's a better rate or modulation mode to try. */ |
Emmanuel Grumbach | 8dfc275 | 2014-09-21 13:29:48 +0300 | [diff] [blame] | 1386 | if (sta->supp_rates[info->band]) |
Matti Gottlieb | ff7a68d | 2016-05-17 10:50:08 +0300 | [diff] [blame^] | 1387 | rs_rate_scale_perform(mvm, sta, lq_sta, tid, ndp); |
Eyal Shapira | 1ebc8f2 | 2014-09-14 15:23:23 +0300 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | /* |
| 1391 | * mac80211 sends us Tx status |
| 1392 | */ |
| 1393 | static void rs_mac80211_tx_status(void *mvm_r, |
| 1394 | struct ieee80211_supported_band *sband, |
| 1395 | struct ieee80211_sta *sta, void *priv_sta, |
| 1396 | struct sk_buff *skb) |
| 1397 | { |
| 1398 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1399 | struct iwl_op_mode *op_mode = (struct iwl_op_mode *)mvm_r; |
| 1400 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); |
| 1401 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1402 | |
Johannes Berg | dcbc17a | 2015-03-10 21:24:34 +0100 | [diff] [blame] | 1403 | if (!iwl_mvm_sta_from_mac80211(sta)->vif) |
| 1404 | return; |
| 1405 | |
Eyal Shapira | 1ebc8f2 | 2014-09-14 15:23:23 +0300 | [diff] [blame] | 1406 | if (!ieee80211_is_data(hdr->frame_control) || |
| 1407 | info->flags & IEEE80211_TX_CTL_NO_ACK) |
| 1408 | return; |
| 1409 | |
Matti Gottlieb | ff7a68d | 2016-05-17 10:50:08 +0300 | [diff] [blame^] | 1410 | iwl_mvm_rs_tx_status(mvm, sta, rs_get_tid(hdr), info, |
| 1411 | ieee80211_is_qos_nullfunc(hdr->frame_control)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | /* |
| 1415 | * Begin a period of staying with a selected modulation mode. |
| 1416 | * Set "stay_in_tbl" flag to prevent any mode switches. |
| 1417 | * Set frame tx success limits according to legacy vs. high-throughput, |
| 1418 | * and reset overall (spanning all rates) tx success history statistics. |
| 1419 | * These control how long we stay using same modulation mode before |
| 1420 | * searching for a new mode. |
| 1421 | */ |
| 1422 | static void rs_set_stay_in_table(struct iwl_mvm *mvm, u8 is_legacy, |
| 1423 | struct iwl_lq_sta *lq_sta) |
| 1424 | { |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1425 | IWL_DEBUG_RATE(mvm, "Moving to RS_STATE_STAY_IN_COLUMN\n"); |
| 1426 | lq_sta->rs_state = RS_STATE_STAY_IN_COLUMN; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1427 | if (is_legacy) { |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 1428 | lq_sta->table_count_limit = IWL_MVM_RS_LEGACY_TABLE_COUNT; |
| 1429 | lq_sta->max_failure_limit = IWL_MVM_RS_LEGACY_FAILURE_LIMIT; |
| 1430 | lq_sta->max_success_limit = IWL_MVM_RS_LEGACY_SUCCESS_LIMIT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1431 | } else { |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 1432 | lq_sta->table_count_limit = IWL_MVM_RS_NON_LEGACY_TABLE_COUNT; |
| 1433 | lq_sta->max_failure_limit = IWL_MVM_RS_NON_LEGACY_FAILURE_LIMIT; |
| 1434 | lq_sta->max_success_limit = IWL_MVM_RS_NON_LEGACY_SUCCESS_LIMIT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1435 | } |
| 1436 | lq_sta->table_count = 0; |
| 1437 | lq_sta->total_failed = 0; |
| 1438 | lq_sta->total_success = 0; |
| 1439 | lq_sta->flush_timer = jiffies; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1440 | lq_sta->visited_columns = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
Eyal Shapira | 6a028d9 | 2014-12-07 18:18:27 +0200 | [diff] [blame] | 1443 | static inline int rs_get_max_rate_from_mask(unsigned long rate_mask) |
| 1444 | { |
| 1445 | if (rate_mask) |
| 1446 | return find_last_bit(&rate_mask, BITS_PER_LONG); |
| 1447 | return IWL_RATE_INVALID; |
| 1448 | } |
| 1449 | |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 1450 | static int rs_get_max_allowed_rate(struct iwl_lq_sta *lq_sta, |
| 1451 | const struct rs_tx_column *column) |
| 1452 | { |
| 1453 | switch (column->mode) { |
| 1454 | case RS_LEGACY: |
| 1455 | return lq_sta->max_legacy_rate_idx; |
| 1456 | case RS_SISO: |
| 1457 | return lq_sta->max_siso_rate_idx; |
| 1458 | case RS_MIMO2: |
| 1459 | return lq_sta->max_mimo2_rate_idx; |
| 1460 | default: |
| 1461 | WARN_ON_ONCE(1); |
| 1462 | } |
| 1463 | |
| 1464 | return lq_sta->max_legacy_rate_idx; |
| 1465 | } |
| 1466 | |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 1467 | 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] | 1468 | const struct rs_tx_column *column, |
| 1469 | u32 bw) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1470 | { |
| 1471 | /* Used to choose among HT tables */ |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 1472 | const u16 (*ht_tbl_pointer)[IWL_RATE_COUNT]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1473 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1474 | if (WARN_ON_ONCE(column->mode != RS_LEGACY && |
| 1475 | column->mode != RS_SISO && |
| 1476 | column->mode != RS_MIMO2)) |
| 1477 | return expected_tpt_legacy; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1478 | |
| 1479 | /* Legacy rates have only one table */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1480 | if (column->mode == RS_LEGACY) |
| 1481 | return expected_tpt_legacy; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1482 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1483 | ht_tbl_pointer = expected_tpt_mimo2_20MHz; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1484 | /* Choose among many HT tables depending on number of streams |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1485 | * (SISO/MIMO2), channel width (20/40/80), SGI, and aggregation |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1486 | * status */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1487 | if (column->mode == RS_SISO) { |
| 1488 | switch (bw) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1489 | case RATE_MCS_CHAN_WIDTH_20: |
| 1490 | ht_tbl_pointer = expected_tpt_siso_20MHz; |
| 1491 | break; |
| 1492 | case RATE_MCS_CHAN_WIDTH_40: |
| 1493 | ht_tbl_pointer = expected_tpt_siso_40MHz; |
| 1494 | break; |
| 1495 | case RATE_MCS_CHAN_WIDTH_80: |
| 1496 | ht_tbl_pointer = expected_tpt_siso_80MHz; |
| 1497 | break; |
| 1498 | default: |
| 1499 | WARN_ON_ONCE(1); |
| 1500 | } |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1501 | } else if (column->mode == RS_MIMO2) { |
| 1502 | switch (bw) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1503 | case RATE_MCS_CHAN_WIDTH_20: |
| 1504 | ht_tbl_pointer = expected_tpt_mimo2_20MHz; |
| 1505 | break; |
| 1506 | case RATE_MCS_CHAN_WIDTH_40: |
| 1507 | ht_tbl_pointer = expected_tpt_mimo2_40MHz; |
| 1508 | break; |
| 1509 | case RATE_MCS_CHAN_WIDTH_80: |
| 1510 | ht_tbl_pointer = expected_tpt_mimo2_80MHz; |
| 1511 | break; |
| 1512 | default: |
| 1513 | WARN_ON_ONCE(1); |
| 1514 | } |
| 1515 | } else { |
| 1516 | WARN_ON_ONCE(1); |
Eyal Shapira | d972ab3 | 2013-07-28 23:02:45 +0000 | [diff] [blame] | 1517 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1518 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1519 | if (!column->sgi && !lq_sta->is_agg) /* Normal */ |
| 1520 | return ht_tbl_pointer[0]; |
| 1521 | else if (column->sgi && !lq_sta->is_agg) /* SGI */ |
| 1522 | return ht_tbl_pointer[1]; |
| 1523 | else if (!column->sgi && lq_sta->is_agg) /* AGG */ |
| 1524 | return ht_tbl_pointer[2]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1525 | else /* AGG+SGI */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1526 | return ht_tbl_pointer[3]; |
| 1527 | } |
| 1528 | |
| 1529 | static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta, |
| 1530 | struct iwl_scale_tbl_info *tbl) |
| 1531 | { |
| 1532 | struct rs_rate *rate = &tbl->rate; |
| 1533 | const struct rs_tx_column *column = &rs_tx_columns[tbl->column]; |
| 1534 | |
| 1535 | 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] | 1536 | } |
| 1537 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1538 | static s32 rs_get_best_rate(struct iwl_mvm *mvm, |
| 1539 | struct iwl_lq_sta *lq_sta, |
| 1540 | struct iwl_scale_tbl_info *tbl, /* "search" */ |
Eyal Shapira | 8076351 | 2014-04-09 04:31:44 +0300 | [diff] [blame] | 1541 | unsigned long rate_mask, s8 index) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1542 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1543 | struct iwl_scale_tbl_info *active_tbl = |
| 1544 | &(lq_sta->lq_info[lq_sta->active_tbl]); |
Eyal Shapira | 8076351 | 2014-04-09 04:31:44 +0300 | [diff] [blame] | 1545 | s32 success_ratio = active_tbl->win[index].success_ratio; |
| 1546 | u16 expected_current_tpt = active_tbl->expected_tpt[index]; |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 1547 | const u16 *tpt_tbl = tbl->expected_tpt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1548 | u16 high_low; |
Eyal Shapira | 8076351 | 2014-04-09 04:31:44 +0300 | [diff] [blame] | 1549 | u32 target_tpt; |
| 1550 | int rate_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1551 | |
Eyal Shapira | ed21a38 | 2015-09-21 20:03:22 +0300 | [diff] [blame] | 1552 | if (success_ratio >= RS_PERCENT(IWL_MVM_RS_SR_NO_DECREASE)) { |
Eyal Shapira | 8076351 | 2014-04-09 04:31:44 +0300 | [diff] [blame] | 1553 | target_tpt = 100 * expected_current_tpt; |
| 1554 | IWL_DEBUG_RATE(mvm, |
| 1555 | "SR %d high. Find rate exceeding EXPECTED_CURRENT %d\n", |
| 1556 | success_ratio, target_tpt); |
| 1557 | } else { |
| 1558 | target_tpt = lq_sta->last_tpt; |
| 1559 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | ed21a38 | 2015-09-21 20:03:22 +0300 | [diff] [blame] | 1560 | "SR %d not that good. Find rate exceeding ACTUAL_TPT %d\n", |
Eyal Shapira | 8076351 | 2014-04-09 04:31:44 +0300 | [diff] [blame] | 1561 | success_ratio, target_tpt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1562 | } |
| 1563 | |
Eyal Shapira | 8076351 | 2014-04-09 04:31:44 +0300 | [diff] [blame] | 1564 | rate_idx = find_first_bit(&rate_mask, BITS_PER_LONG); |
| 1565 | |
| 1566 | while (rate_idx != IWL_RATE_INVALID) { |
| 1567 | if (target_tpt < (100 * tpt_tbl[rate_idx])) |
| 1568 | break; |
| 1569 | |
| 1570 | high_low = rs_get_adjacent_rate(mvm, rate_idx, rate_mask, |
| 1571 | tbl->rate.type); |
| 1572 | |
| 1573 | rate_idx = (high_low >> 8) & 0xff; |
| 1574 | } |
| 1575 | |
| 1576 | IWL_DEBUG_RATE(mvm, "Best rate found %d target_tp %d expected_new %d\n", |
| 1577 | rate_idx, target_tpt, |
| 1578 | rate_idx != IWL_RATE_INVALID ? |
| 1579 | 100 * tpt_tbl[rate_idx] : IWL_INVALID_VALUE); |
| 1580 | |
| 1581 | return rate_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1582 | } |
| 1583 | |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1584 | static u32 rs_bw_from_sta_bw(struct ieee80211_sta *sta) |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1585 | { |
| 1586 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_80) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1587 | return RATE_MCS_CHAN_WIDTH_80; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1588 | else if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 1589 | return RATE_MCS_CHAN_WIDTH_40; |
| 1590 | |
| 1591 | return RATE_MCS_CHAN_WIDTH_20; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1592 | } |
| 1593 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1594 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1595 | * Check whether we should continue using same modulation mode, or |
| 1596 | * begin search for a new mode, based on: |
| 1597 | * 1) # tx successes or failures while using this mode |
| 1598 | * 2) # times calling this function |
| 1599 | * 3) elapsed time in this mode (not used, for now) |
| 1600 | */ |
| 1601 | static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search) |
| 1602 | { |
| 1603 | struct iwl_scale_tbl_info *tbl; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1604 | int active_tbl; |
| 1605 | int flush_interval_passed = 0; |
| 1606 | struct iwl_mvm *mvm; |
| 1607 | |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 1608 | mvm = lq_sta->pers.drv; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1609 | active_tbl = lq_sta->active_tbl; |
| 1610 | |
| 1611 | tbl = &(lq_sta->lq_info[active_tbl]); |
| 1612 | |
| 1613 | /* 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] | 1614 | if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1615 | /* Elapsed time using current modulation mode */ |
| 1616 | if (lq_sta->flush_timer) |
| 1617 | flush_interval_passed = |
| 1618 | time_after(jiffies, |
| 1619 | (unsigned long)(lq_sta->flush_timer + |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 1620 | (IWL_MVM_RS_STAY_IN_COLUMN_TIMEOUT * HZ))); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1621 | |
| 1622 | /* |
| 1623 | * Check if we should allow search for new modulation mode. |
| 1624 | * If many frames have failed or succeeded, or we've used |
| 1625 | * this same modulation for a long time, allow search, and |
| 1626 | * reset history stats that keep track of whether we should |
| 1627 | * allow a new search. Also (below) reset all bitmaps and |
| 1628 | * stats in active history. |
| 1629 | */ |
| 1630 | if (force_search || |
| 1631 | (lq_sta->total_failed > lq_sta->max_failure_limit) || |
| 1632 | (lq_sta->total_success > lq_sta->max_success_limit) || |
| 1633 | ((!lq_sta->search_better_tbl) && |
| 1634 | (lq_sta->flush_timer) && (flush_interval_passed))) { |
| 1635 | IWL_DEBUG_RATE(mvm, |
| 1636 | "LQ: stay is expired %d %d %d\n", |
| 1637 | lq_sta->total_failed, |
| 1638 | lq_sta->total_success, |
| 1639 | flush_interval_passed); |
| 1640 | |
| 1641 | /* Allow search for new mode */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1642 | lq_sta->rs_state = RS_STATE_SEARCH_CYCLE_STARTED; |
| 1643 | IWL_DEBUG_RATE(mvm, |
| 1644 | "Moving to RS_STATE_SEARCH_CYCLE_STARTED\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1645 | lq_sta->total_failed = 0; |
| 1646 | lq_sta->total_success = 0; |
| 1647 | lq_sta->flush_timer = 0; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1648 | /* mark the current column as visited */ |
| 1649 | lq_sta->visited_columns = BIT(tbl->column); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1650 | /* |
| 1651 | * Else if we've used this modulation mode enough repetitions |
| 1652 | * (regardless of elapsed time or success/failure), reset |
| 1653 | * history bitmaps and rate-specific stats for all rates in |
| 1654 | * active table. |
| 1655 | */ |
| 1656 | } else { |
| 1657 | lq_sta->table_count++; |
| 1658 | if (lq_sta->table_count >= |
| 1659 | lq_sta->table_count_limit) { |
| 1660 | lq_sta->table_count = 0; |
| 1661 | |
| 1662 | IWL_DEBUG_RATE(mvm, |
| 1663 | "LQ: stay in table clear win\n"); |
Eyal Shapira | b804eeb | 2014-04-06 04:27:06 +0300 | [diff] [blame] | 1664 | rs_rate_scale_clear_tbl_windows(mvm, tbl); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | /* If transitioning to allow "search", reset all history |
| 1669 | * bitmaps and stats in active table (this will become the new |
| 1670 | * "search" table). */ |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1671 | if (lq_sta->rs_state == RS_STATE_SEARCH_CYCLE_STARTED) { |
Eyal Shapira | b804eeb | 2014-04-06 04:27:06 +0300 | [diff] [blame] | 1672 | rs_rate_scale_clear_tbl_windows(mvm, tbl); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1673 | } |
| 1674 | } |
| 1675 | } |
| 1676 | |
Emmanuel Grumbach | 04e3a5d | 2015-10-28 09:47:41 +0200 | [diff] [blame] | 1677 | static void rs_set_amsdu_len(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 1678 | struct iwl_scale_tbl_info *tbl, |
| 1679 | enum rs_action scale_action) |
| 1680 | { |
| 1681 | struct iwl_mvm_sta *sta_priv = iwl_mvm_sta_from_mac80211(sta); |
| 1682 | |
| 1683 | if ((!is_vht(&tbl->rate) && !is_ht(&tbl->rate)) || |
| 1684 | tbl->rate.index < IWL_RATE_MCS_5_INDEX || |
| 1685 | scale_action == RS_ACTION_DOWNSCALE) |
| 1686 | sta_priv->tlc_amsdu = false; |
| 1687 | else |
| 1688 | sta_priv->tlc_amsdu = true; |
| 1689 | } |
| 1690 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1691 | /* |
| 1692 | * setup rate table in uCode |
| 1693 | */ |
| 1694 | static void rs_update_rate_tbl(struct iwl_mvm *mvm, |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 1695 | struct ieee80211_sta *sta, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1696 | struct iwl_lq_sta *lq_sta, |
Eyal Shapira | 7b9d74e | 2015-03-29 18:38:07 +0300 | [diff] [blame] | 1697 | struct iwl_scale_tbl_info *tbl) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1698 | { |
Eyal Shapira | 7b9d74e | 2015-03-29 18:38:07 +0300 | [diff] [blame] | 1699 | rs_fill_lq_cmd(mvm, sta, lq_sta, &tbl->rate); |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 1700 | iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1701 | } |
| 1702 | |
Eyal Shapira | 1191f64 | 2015-09-19 23:48:45 +0300 | [diff] [blame] | 1703 | static bool rs_tweak_rate_tbl(struct iwl_mvm *mvm, |
| 1704 | struct ieee80211_sta *sta, |
| 1705 | struct iwl_lq_sta *lq_sta, |
| 1706 | struct iwl_scale_tbl_info *tbl, |
| 1707 | enum rs_action scale_action) |
| 1708 | { |
| 1709 | if (sta->bandwidth != IEEE80211_STA_RX_BW_80) |
| 1710 | return false; |
| 1711 | |
| 1712 | if (!is_vht_siso(&tbl->rate)) |
| 1713 | return false; |
| 1714 | |
| 1715 | if ((tbl->rate.bw == RATE_MCS_CHAN_WIDTH_80) && |
| 1716 | (tbl->rate.index == IWL_RATE_MCS_0_INDEX) && |
| 1717 | (scale_action == RS_ACTION_DOWNSCALE)) { |
| 1718 | tbl->rate.bw = RATE_MCS_CHAN_WIDTH_20; |
| 1719 | tbl->rate.index = IWL_RATE_MCS_4_INDEX; |
| 1720 | IWL_DEBUG_RATE(mvm, "Switch 80Mhz SISO MCS0 -> 20Mhz MCS4\n"); |
| 1721 | goto tweaked; |
| 1722 | } |
| 1723 | |
| 1724 | /* Go back to 80Mhz MCS1 only if we've established that 20Mhz MCS5 is |
| 1725 | * sustainable, i.e. we're past the test window. We can't go back |
| 1726 | * if MCS5 is just tested as this will happen always after switching |
| 1727 | * to 20Mhz MCS4 because the rate stats are cleared. |
| 1728 | */ |
| 1729 | if ((tbl->rate.bw == RATE_MCS_CHAN_WIDTH_20) && |
| 1730 | (((tbl->rate.index == IWL_RATE_MCS_5_INDEX) && |
| 1731 | (scale_action == RS_ACTION_STAY)) || |
| 1732 | ((tbl->rate.index > IWL_RATE_MCS_5_INDEX) && |
| 1733 | (scale_action == RS_ACTION_UPSCALE)))) { |
| 1734 | tbl->rate.bw = RATE_MCS_CHAN_WIDTH_80; |
| 1735 | tbl->rate.index = IWL_RATE_MCS_1_INDEX; |
| 1736 | IWL_DEBUG_RATE(mvm, "Switch 20Mhz SISO MCS5 -> 80Mhz MCS1\n"); |
| 1737 | goto tweaked; |
| 1738 | } |
| 1739 | |
| 1740 | return false; |
| 1741 | |
| 1742 | tweaked: |
| 1743 | rs_set_expected_tpt_table(lq_sta, tbl); |
| 1744 | rs_rate_scale_clear_tbl_windows(mvm, tbl); |
| 1745 | return true; |
| 1746 | } |
| 1747 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1748 | static enum rs_column rs_get_next_column(struct iwl_mvm *mvm, |
| 1749 | struct iwl_lq_sta *lq_sta, |
| 1750 | struct ieee80211_sta *sta, |
| 1751 | struct iwl_scale_tbl_info *tbl) |
| 1752 | { |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 1753 | int i, j, max_rate; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1754 | enum rs_column next_col_id; |
| 1755 | const struct rs_tx_column *curr_col = &rs_tx_columns[tbl->column]; |
| 1756 | const struct rs_tx_column *next_col; |
| 1757 | allow_column_func_t allow_func; |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 1758 | u8 valid_ants = iwl_mvm_get_valid_tx_ant(mvm); |
Johannes Berg | a34529e | 2014-01-20 22:57:21 +0100 | [diff] [blame] | 1759 | const u16 *expected_tpt_tbl; |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 1760 | u16 tpt, max_expected_tpt; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1761 | |
| 1762 | for (i = 0; i < MAX_NEXT_COLUMNS; i++) { |
| 1763 | next_col_id = curr_col->next_columns[i]; |
| 1764 | |
| 1765 | if (next_col_id == RS_COLUMN_INVALID) |
| 1766 | continue; |
| 1767 | |
| 1768 | if (lq_sta->visited_columns & BIT(next_col_id)) { |
| 1769 | IWL_DEBUG_RATE(mvm, "Skip already visited column %d\n", |
| 1770 | next_col_id); |
| 1771 | continue; |
| 1772 | } |
| 1773 | |
| 1774 | next_col = &rs_tx_columns[next_col_id]; |
| 1775 | |
| 1776 | if (!rs_is_valid_ant(valid_ants, next_col->ant)) { |
| 1777 | IWL_DEBUG_RATE(mvm, |
| 1778 | "Skip column %d as ANT config isn't supported by chip. valid_ants 0x%x column ant 0x%x\n", |
| 1779 | next_col_id, valid_ants, next_col->ant); |
| 1780 | continue; |
| 1781 | } |
| 1782 | |
| 1783 | for (j = 0; j < MAX_COLUMN_CHECKS; j++) { |
| 1784 | allow_func = next_col->checks[j]; |
Eyal Shapira | bb8f44c | 2015-05-27 22:00:03 +0300 | [diff] [blame] | 1785 | if (allow_func && !allow_func(mvm, sta, &tbl->rate, |
| 1786 | next_col)) |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1787 | break; |
| 1788 | } |
| 1789 | |
| 1790 | if (j != MAX_COLUMN_CHECKS) { |
| 1791 | IWL_DEBUG_RATE(mvm, |
| 1792 | "Skip column %d: not allowed (check %d failed)\n", |
| 1793 | next_col_id, j); |
| 1794 | |
| 1795 | continue; |
| 1796 | } |
| 1797 | |
| 1798 | tpt = lq_sta->last_tpt / 100; |
| 1799 | expected_tpt_tbl = rs_get_expected_tpt_table(lq_sta, next_col, |
Eyal Shapira | 049e0c3 | 2014-05-01 01:28:48 +0300 | [diff] [blame] | 1800 | rs_bw_from_sta_bw(sta)); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1801 | if (WARN_ON_ONCE(!expected_tpt_tbl)) |
| 1802 | continue; |
| 1803 | |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 1804 | max_rate = rs_get_max_allowed_rate(lq_sta, next_col); |
Eyal Shapira | 6a028d9 | 2014-12-07 18:18:27 +0200 | [diff] [blame] | 1805 | if (max_rate == IWL_RATE_INVALID) { |
| 1806 | IWL_DEBUG_RATE(mvm, |
| 1807 | "Skip column %d: no rate is allowed in this column\n", |
| 1808 | next_col_id); |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 1809 | continue; |
Eyal Shapira | 6a028d9 | 2014-12-07 18:18:27 +0200 | [diff] [blame] | 1810 | } |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1811 | |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 1812 | max_expected_tpt = expected_tpt_tbl[max_rate]; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1813 | if (tpt >= max_expected_tpt) { |
| 1814 | IWL_DEBUG_RATE(mvm, |
| 1815 | "Skip column %d: can't beat current TPT. Max expected %d current %d\n", |
| 1816 | next_col_id, max_expected_tpt, tpt); |
| 1817 | continue; |
| 1818 | } |
| 1819 | |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 1820 | IWL_DEBUG_RATE(mvm, |
| 1821 | "Found potential column %d. Max expected %d current %d\n", |
| 1822 | next_col_id, max_expected_tpt, tpt); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1823 | break; |
| 1824 | } |
| 1825 | |
| 1826 | if (i == MAX_NEXT_COLUMNS) |
| 1827 | return RS_COLUMN_INVALID; |
| 1828 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1829 | return next_col_id; |
| 1830 | } |
| 1831 | |
| 1832 | static int rs_switch_to_column(struct iwl_mvm *mvm, |
| 1833 | struct iwl_lq_sta *lq_sta, |
| 1834 | struct ieee80211_sta *sta, |
| 1835 | enum rs_column col_id) |
| 1836 | { |
| 1837 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
| 1838 | struct iwl_scale_tbl_info *search_tbl = |
| 1839 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
| 1840 | struct rs_rate *rate = &search_tbl->rate; |
| 1841 | const struct rs_tx_column *column = &rs_tx_columns[col_id]; |
| 1842 | const struct rs_tx_column *curr_column = &rs_tx_columns[tbl->column]; |
| 1843 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - |
| 1844 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); |
Eyal Shapira | 8076351 | 2014-04-09 04:31:44 +0300 | [diff] [blame] | 1845 | unsigned long rate_mask = 0; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1846 | u32 rate_idx = 0; |
| 1847 | |
| 1848 | memcpy(search_tbl, tbl, sz); |
| 1849 | |
| 1850 | rate->sgi = column->sgi; |
| 1851 | rate->ant = column->ant; |
| 1852 | |
| 1853 | if (column->mode == RS_LEGACY) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1854 | if (lq_sta->band == NL80211_BAND_5GHZ) |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1855 | rate->type = LQ_LEGACY_A; |
| 1856 | else |
| 1857 | rate->type = LQ_LEGACY_G; |
| 1858 | |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 1859 | rate->bw = RATE_MCS_CHAN_WIDTH_20; |
| 1860 | rate->ldpc = false; |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1861 | rate_mask = lq_sta->active_legacy_rate; |
| 1862 | } else if (column->mode == RS_SISO) { |
| 1863 | rate->type = lq_sta->is_vht ? LQ_VHT_SISO : LQ_HT_SISO; |
| 1864 | rate_mask = lq_sta->active_siso_rate; |
| 1865 | } else if (column->mode == RS_MIMO2) { |
| 1866 | rate->type = lq_sta->is_vht ? LQ_VHT_MIMO2 : LQ_HT_MIMO2; |
| 1867 | rate_mask = lq_sta->active_mimo2_rate; |
| 1868 | } else { |
Dan Carpenter | 7281b16 | 2015-11-21 13:33:38 +0300 | [diff] [blame] | 1869 | WARN_ONCE(1, "Bad column mode"); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1870 | } |
| 1871 | |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 1872 | if (column->mode != RS_LEGACY) { |
| 1873 | rate->bw = rs_bw_from_sta_bw(sta); |
| 1874 | rate->ldpc = lq_sta->ldpc; |
| 1875 | } |
| 1876 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1877 | search_tbl->column = col_id; |
| 1878 | rs_set_expected_tpt_table(lq_sta, search_tbl); |
| 1879 | |
Eyal Shapira | 75d3e2d | 2014-01-07 18:19:35 +0200 | [diff] [blame] | 1880 | lq_sta->visited_columns |= BIT(col_id); |
| 1881 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1882 | /* Get the best matching rate if we're changing modes. e.g. |
| 1883 | * SISO->MIMO, LEGACY->SISO, MIMO->SISO |
| 1884 | */ |
| 1885 | if (curr_column->mode != column->mode) { |
| 1886 | rate_idx = rs_get_best_rate(mvm, lq_sta, search_tbl, |
| 1887 | rate_mask, rate->index); |
| 1888 | |
| 1889 | if ((rate_idx == IWL_RATE_INVALID) || |
| 1890 | !(BIT(rate_idx) & rate_mask)) { |
| 1891 | IWL_DEBUG_RATE(mvm, |
| 1892 | "can not switch with index %d" |
Eyal Shapira | 8076351 | 2014-04-09 04:31:44 +0300 | [diff] [blame] | 1893 | " rate mask %lx\n", |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1894 | rate_idx, rate_mask); |
| 1895 | |
| 1896 | goto err; |
| 1897 | } |
| 1898 | |
| 1899 | rate->index = rate_idx; |
| 1900 | } |
| 1901 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1902 | IWL_DEBUG_RATE(mvm, "Switched to column %d: Index %d\n", |
| 1903 | col_id, rate->index); |
| 1904 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1905 | return 0; |
| 1906 | |
| 1907 | err: |
| 1908 | rate->type = LQ_NONE; |
| 1909 | return -1; |
| 1910 | } |
| 1911 | |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1912 | static enum rs_action rs_get_rate_action(struct iwl_mvm *mvm, |
| 1913 | struct iwl_scale_tbl_info *tbl, |
| 1914 | s32 sr, int low, int high, |
| 1915 | int current_tpt, |
| 1916 | int low_tpt, int high_tpt) |
| 1917 | { |
| 1918 | enum rs_action action = RS_ACTION_STAY; |
| 1919 | |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 1920 | if ((sr <= RS_PERCENT(IWL_MVM_RS_SR_FORCE_DECREASE)) || |
| 1921 | (current_tpt == 0)) { |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1922 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | e53839eb | 2014-04-06 02:42:18 +0300 | [diff] [blame] | 1923 | "Decrease rate because of low SR\n"); |
| 1924 | return RS_ACTION_DOWNSCALE; |
| 1925 | } |
| 1926 | |
| 1927 | if ((low_tpt == IWL_INVALID_VALUE) && |
| 1928 | (high_tpt == IWL_INVALID_VALUE) && |
| 1929 | (high != IWL_RATE_INVALID)) { |
| 1930 | IWL_DEBUG_RATE(mvm, |
| 1931 | "No data about high/low rates. Increase rate\n"); |
| 1932 | return RS_ACTION_UPSCALE; |
| 1933 | } |
| 1934 | |
| 1935 | if ((high_tpt == IWL_INVALID_VALUE) && |
| 1936 | (high != IWL_RATE_INVALID) && |
| 1937 | (low_tpt != IWL_INVALID_VALUE) && |
| 1938 | (low_tpt < current_tpt)) { |
| 1939 | IWL_DEBUG_RATE(mvm, |
| 1940 | "No data about high rate and low rate is worse. Increase rate\n"); |
| 1941 | return RS_ACTION_UPSCALE; |
| 1942 | } |
| 1943 | |
| 1944 | if ((high_tpt != IWL_INVALID_VALUE) && |
| 1945 | (high_tpt > current_tpt)) { |
| 1946 | IWL_DEBUG_RATE(mvm, |
| 1947 | "Higher rate is better. Increate rate\n"); |
| 1948 | return RS_ACTION_UPSCALE; |
| 1949 | } |
| 1950 | |
| 1951 | if ((low_tpt != IWL_INVALID_VALUE) && |
| 1952 | (high_tpt != IWL_INVALID_VALUE) && |
| 1953 | (low_tpt < current_tpt) && |
| 1954 | (high_tpt < current_tpt)) { |
| 1955 | IWL_DEBUG_RATE(mvm, |
| 1956 | "Both high and low are worse. Maintain rate\n"); |
| 1957 | return RS_ACTION_STAY; |
| 1958 | } |
| 1959 | |
| 1960 | if ((low_tpt != IWL_INVALID_VALUE) && |
| 1961 | (low_tpt > current_tpt)) { |
| 1962 | IWL_DEBUG_RATE(mvm, |
| 1963 | "Lower rate is better\n"); |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1964 | action = RS_ACTION_DOWNSCALE; |
Eyal Shapira | e53839eb | 2014-04-06 02:42:18 +0300 | [diff] [blame] | 1965 | goto out; |
| 1966 | } |
| 1967 | |
| 1968 | if ((low_tpt == IWL_INVALID_VALUE) && |
| 1969 | (low != IWL_RATE_INVALID)) { |
| 1970 | IWL_DEBUG_RATE(mvm, |
| 1971 | "No data about lower rate\n"); |
| 1972 | action = RS_ACTION_DOWNSCALE; |
| 1973 | goto out; |
| 1974 | } |
| 1975 | |
| 1976 | IWL_DEBUG_RATE(mvm, "Maintain rate\n"); |
| 1977 | |
| 1978 | out: |
| 1979 | if ((action == RS_ACTION_DOWNSCALE) && (low != IWL_RATE_INVALID)) { |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 1980 | if (sr >= RS_PERCENT(IWL_MVM_RS_SR_NO_DECREASE)) { |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1981 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | e53839eb | 2014-04-06 02:42:18 +0300 | [diff] [blame] | 1982 | "SR is above NO DECREASE. Avoid downscale\n"); |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1983 | action = RS_ACTION_STAY; |
Eyal Shapira | e53839eb | 2014-04-06 02:42:18 +0300 | [diff] [blame] | 1984 | } else if (current_tpt > (100 * tbl->expected_tpt[low])) { |
| 1985 | IWL_DEBUG_RATE(mvm, |
| 1986 | "Current TPT is higher than max expected in low rate. Avoid downscale\n"); |
| 1987 | action = RS_ACTION_STAY; |
| 1988 | } else { |
| 1989 | IWL_DEBUG_RATE(mvm, "Decrease rate\n"); |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1990 | } |
| 1991 | } |
| 1992 | |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 1993 | return action; |
| 1994 | } |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 1995 | |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 1996 | static bool rs_stbc_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 1997 | struct iwl_lq_sta *lq_sta) |
| 1998 | { |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 1999 | /* Our chip supports Tx STBC and the peer is an HT/VHT STA which |
| 2000 | * supports STBC of at least 1*SS |
| 2001 | */ |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 2002 | if (!lq_sta->stbc_capable) |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 2003 | return false; |
| 2004 | |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 2005 | if (!iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta)) |
| 2006 | return false; |
| 2007 | |
| 2008 | return true; |
| 2009 | } |
| 2010 | |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2011 | static void rs_get_adjacent_txp(struct iwl_mvm *mvm, int index, |
| 2012 | int *weaker, int *stronger) |
| 2013 | { |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 2014 | *weaker = index + IWL_MVM_RS_TPC_TX_POWER_STEP; |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2015 | if (*weaker > TPC_MAX_REDUCTION) |
| 2016 | *weaker = TPC_INVALID; |
| 2017 | |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 2018 | *stronger = index - IWL_MVM_RS_TPC_TX_POWER_STEP; |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2019 | if (*stronger < 0) |
| 2020 | *stronger = TPC_INVALID; |
| 2021 | } |
| 2022 | |
Eyal Shapira | 1e9551d | 2014-04-21 21:33:17 +0300 | [diff] [blame] | 2023 | static bool rs_tpc_allowed(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2024 | struct rs_rate *rate, enum nl80211_band band) |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2025 | { |
| 2026 | int index = rate->index; |
Eyal Shapira | 1e9551d | 2014-04-21 21:33:17 +0300 | [diff] [blame] | 2027 | bool cam = (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM); |
| 2028 | bool sta_ps_disabled = (vif->type == NL80211_IFTYPE_STATION && |
| 2029 | !vif->bss_conf.ps); |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2030 | |
Eyal Shapira | 1e9551d | 2014-04-21 21:33:17 +0300 | [diff] [blame] | 2031 | IWL_DEBUG_RATE(mvm, "cam: %d sta_ps_disabled %d\n", |
| 2032 | cam, sta_ps_disabled); |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2033 | /* |
| 2034 | * allow tpc only if power management is enabled, or bt coex |
| 2035 | * activity grade allows it and we are on 2.4Ghz. |
| 2036 | */ |
Eyal Shapira | 1e9551d | 2014-04-21 21:33:17 +0300 | [diff] [blame] | 2037 | if ((cam || sta_ps_disabled) && |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2038 | !iwl_mvm_bt_coex_is_tpc_allowed(mvm, band)) |
| 2039 | return false; |
| 2040 | |
| 2041 | IWL_DEBUG_RATE(mvm, "check rate, table type: %d\n", rate->type); |
| 2042 | if (is_legacy(rate)) |
| 2043 | return index == IWL_RATE_54M_INDEX; |
| 2044 | if (is_ht(rate)) |
| 2045 | return index == IWL_RATE_MCS_7_INDEX; |
| 2046 | if (is_vht(rate)) |
| 2047 | return index == IWL_RATE_MCS_7_INDEX || |
| 2048 | index == IWL_RATE_MCS_8_INDEX || |
| 2049 | index == IWL_RATE_MCS_9_INDEX; |
| 2050 | |
| 2051 | WARN_ON_ONCE(1); |
| 2052 | return false; |
| 2053 | } |
| 2054 | |
| 2055 | enum tpc_action { |
| 2056 | TPC_ACTION_STAY, |
| 2057 | TPC_ACTION_DECREASE, |
| 2058 | TPC_ACTION_INCREASE, |
| 2059 | TPC_ACTION_NO_RESTIRCTION, |
| 2060 | }; |
| 2061 | |
| 2062 | static enum tpc_action rs_get_tpc_action(struct iwl_mvm *mvm, |
| 2063 | s32 sr, int weak, int strong, |
| 2064 | int current_tpt, |
| 2065 | int weak_tpt, int strong_tpt) |
| 2066 | { |
| 2067 | /* stay until we have valid tpt */ |
| 2068 | if (current_tpt == IWL_INVALID_VALUE) { |
| 2069 | IWL_DEBUG_RATE(mvm, "no current tpt. stay.\n"); |
| 2070 | return TPC_ACTION_STAY; |
| 2071 | } |
| 2072 | |
| 2073 | /* Too many failures, increase txp */ |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 2074 | if (sr <= RS_PERCENT(IWL_MVM_RS_TPC_SR_FORCE_INCREASE) || |
| 2075 | current_tpt == 0) { |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2076 | IWL_DEBUG_RATE(mvm, "increase txp because of weak SR\n"); |
| 2077 | return TPC_ACTION_NO_RESTIRCTION; |
| 2078 | } |
| 2079 | |
| 2080 | /* try decreasing first if applicable */ |
Gregory Greenman | 6ad6c01 | 2016-01-27 00:10:15 +0200 | [diff] [blame] | 2081 | if (sr >= RS_PERCENT(IWL_MVM_RS_TPC_SR_NO_INCREASE) && |
| 2082 | weak != TPC_INVALID) { |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2083 | if (weak_tpt == IWL_INVALID_VALUE && |
| 2084 | (strong_tpt == IWL_INVALID_VALUE || |
| 2085 | current_tpt >= strong_tpt)) { |
| 2086 | IWL_DEBUG_RATE(mvm, |
| 2087 | "no weak txp measurement. decrease txp\n"); |
| 2088 | return TPC_ACTION_DECREASE; |
| 2089 | } |
| 2090 | |
| 2091 | if (weak_tpt > current_tpt) { |
| 2092 | IWL_DEBUG_RATE(mvm, |
| 2093 | "lower txp has better tpt. decrease txp\n"); |
| 2094 | return TPC_ACTION_DECREASE; |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | /* next, increase if needed */ |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 2099 | if (sr < RS_PERCENT(IWL_MVM_RS_TPC_SR_NO_INCREASE) && |
| 2100 | strong != TPC_INVALID) { |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2101 | if (weak_tpt == IWL_INVALID_VALUE && |
| 2102 | strong_tpt != IWL_INVALID_VALUE && |
| 2103 | current_tpt < strong_tpt) { |
| 2104 | IWL_DEBUG_RATE(mvm, |
| 2105 | "higher txp has better tpt. increase txp\n"); |
| 2106 | return TPC_ACTION_INCREASE; |
| 2107 | } |
| 2108 | |
| 2109 | if (weak_tpt < current_tpt && |
| 2110 | (strong_tpt == IWL_INVALID_VALUE || |
| 2111 | strong_tpt > current_tpt)) { |
| 2112 | IWL_DEBUG_RATE(mvm, |
| 2113 | "lower txp has worse tpt. increase txp\n"); |
| 2114 | return TPC_ACTION_INCREASE; |
| 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | IWL_DEBUG_RATE(mvm, "no need to increase or decrease txp - stay\n"); |
| 2119 | return TPC_ACTION_STAY; |
| 2120 | } |
| 2121 | |
| 2122 | static bool rs_tpc_perform(struct iwl_mvm *mvm, |
| 2123 | struct ieee80211_sta *sta, |
| 2124 | struct iwl_lq_sta *lq_sta, |
| 2125 | struct iwl_scale_tbl_info *tbl) |
| 2126 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 2127 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2128 | struct ieee80211_vif *vif = mvm_sta->vif; |
| 2129 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2130 | enum nl80211_band band; |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2131 | struct iwl_rate_scale_data *window; |
| 2132 | struct rs_rate *rate = &tbl->rate; |
| 2133 | enum tpc_action action; |
| 2134 | s32 sr; |
| 2135 | u8 cur = lq_sta->lq.reduced_tpc; |
| 2136 | int current_tpt; |
| 2137 | int weak, strong; |
| 2138 | int weak_tpt = IWL_INVALID_VALUE, strong_tpt = IWL_INVALID_VALUE; |
| 2139 | |
Eliad Peller | 9a75b3d | 2014-03-13 17:15:04 +0200 | [diff] [blame] | 2140 | #ifdef CONFIG_MAC80211_DEBUGFS |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 2141 | if (lq_sta->pers.dbg_fixed_txp_reduction <= TPC_MAX_REDUCTION) { |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 2142 | IWL_DEBUG_RATE(mvm, "fixed tpc: %d\n", |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 2143 | lq_sta->pers.dbg_fixed_txp_reduction); |
| 2144 | lq_sta->lq.reduced_tpc = lq_sta->pers.dbg_fixed_txp_reduction; |
| 2145 | return cur != lq_sta->pers.dbg_fixed_txp_reduction; |
Eliad Peller | 9a75b3d | 2014-03-13 17:15:04 +0200 | [diff] [blame] | 2146 | } |
| 2147 | #endif |
| 2148 | |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2149 | rcu_read_lock(); |
| 2150 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 2151 | if (WARN_ON(!chanctx_conf)) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2152 | band = NUM_NL80211_BANDS; |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2153 | else |
| 2154 | band = chanctx_conf->def.chan->band; |
| 2155 | rcu_read_unlock(); |
| 2156 | |
Eyal Shapira | 1e9551d | 2014-04-21 21:33:17 +0300 | [diff] [blame] | 2157 | if (!rs_tpc_allowed(mvm, vif, rate, band)) { |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2158 | IWL_DEBUG_RATE(mvm, |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 2159 | "tpc is not allowed. remove txp restrictions\n"); |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2160 | lq_sta->lq.reduced_tpc = TPC_NO_REDUCTION; |
| 2161 | return cur != TPC_NO_REDUCTION; |
| 2162 | } |
| 2163 | |
| 2164 | rs_get_adjacent_txp(mvm, cur, &weak, &strong); |
| 2165 | |
| 2166 | /* Collect measured throughputs for current and adjacent rates */ |
| 2167 | window = tbl->tpc_win; |
| 2168 | sr = window[cur].success_ratio; |
| 2169 | current_tpt = window[cur].average_tpt; |
| 2170 | if (weak != TPC_INVALID) |
| 2171 | weak_tpt = window[weak].average_tpt; |
| 2172 | if (strong != TPC_INVALID) |
| 2173 | strong_tpt = window[strong].average_tpt; |
| 2174 | |
| 2175 | IWL_DEBUG_RATE(mvm, |
| 2176 | "(TPC: %d): cur_tpt %d SR %d weak %d strong %d weak_tpt %d strong_tpt %d\n", |
| 2177 | cur, current_tpt, sr, weak, strong, |
| 2178 | weak_tpt, strong_tpt); |
| 2179 | |
| 2180 | action = rs_get_tpc_action(mvm, sr, weak, strong, |
| 2181 | current_tpt, weak_tpt, strong_tpt); |
| 2182 | |
| 2183 | /* override actions if we are on the edge */ |
| 2184 | if (weak == TPC_INVALID && action == TPC_ACTION_DECREASE) { |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 2185 | IWL_DEBUG_RATE(mvm, "already in lowest txp, stay\n"); |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2186 | action = TPC_ACTION_STAY; |
| 2187 | } else if (strong == TPC_INVALID && |
| 2188 | (action == TPC_ACTION_INCREASE || |
| 2189 | action == TPC_ACTION_NO_RESTIRCTION)) { |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 2190 | IWL_DEBUG_RATE(mvm, "already in highest txp, stay\n"); |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2191 | action = TPC_ACTION_STAY; |
| 2192 | } |
| 2193 | |
| 2194 | switch (action) { |
| 2195 | case TPC_ACTION_DECREASE: |
| 2196 | lq_sta->lq.reduced_tpc = weak; |
| 2197 | return true; |
| 2198 | case TPC_ACTION_INCREASE: |
| 2199 | lq_sta->lq.reduced_tpc = strong; |
| 2200 | return true; |
| 2201 | case TPC_ACTION_NO_RESTIRCTION: |
| 2202 | lq_sta->lq.reduced_tpc = TPC_NO_REDUCTION; |
| 2203 | return true; |
| 2204 | case TPC_ACTION_STAY: |
| 2205 | /* do nothing */ |
| 2206 | break; |
| 2207 | } |
| 2208 | return false; |
| 2209 | } |
| 2210 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2211 | /* |
| 2212 | * Do rate scaling and search for new modulation mode. |
| 2213 | */ |
| 2214 | static void rs_rate_scale_perform(struct iwl_mvm *mvm, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2215 | struct ieee80211_sta *sta, |
Eyal Shapira | 1ebc8f2 | 2014-09-14 15:23:23 +0300 | [diff] [blame] | 2216 | struct iwl_lq_sta *lq_sta, |
Matti Gottlieb | ff7a68d | 2016-05-17 10:50:08 +0300 | [diff] [blame^] | 2217 | int tid, bool ndp) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2218 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2219 | int low = IWL_RATE_INVALID; |
| 2220 | int high = IWL_RATE_INVALID; |
| 2221 | int index; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2222 | struct iwl_rate_scale_data *window = NULL; |
| 2223 | int current_tpt = IWL_INVALID_VALUE; |
| 2224 | int low_tpt = IWL_INVALID_VALUE; |
| 2225 | int high_tpt = IWL_INVALID_VALUE; |
| 2226 | u32 fail_count; |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 2227 | enum rs_action scale_action = RS_ACTION_STAY; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2228 | u16 rate_mask; |
| 2229 | u8 update_lq = 0; |
| 2230 | struct iwl_scale_tbl_info *tbl, *tbl1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2231 | u8 active_tbl = 0; |
| 2232 | u8 done_search = 0; |
| 2233 | u16 high_low; |
| 2234 | s32 sr; |
Eyal Shapira | 9d015a0 | 2013-11-21 01:12:11 +0200 | [diff] [blame] | 2235 | u8 prev_agg = lq_sta->is_agg; |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 2236 | struct iwl_mvm_sta *sta_priv = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2237 | struct iwl_mvm_tid_data *tid_data; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2238 | struct rs_rate *rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2239 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2240 | lq_sta->is_agg = !!sta_priv->agg_tids; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2241 | |
| 2242 | /* |
| 2243 | * Select rate-scale / modulation-mode table to work with in |
| 2244 | * the rest of this function: "search" if searching for better |
| 2245 | * modulation mode, or "active" if doing rate scaling within a mode. |
| 2246 | */ |
| 2247 | if (!lq_sta->search_better_tbl) |
| 2248 | active_tbl = lq_sta->active_tbl; |
| 2249 | else |
| 2250 | active_tbl = 1 - lq_sta->active_tbl; |
| 2251 | |
| 2252 | tbl = &(lq_sta->lq_info[active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2253 | rate = &tbl->rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2254 | |
Eyal Shapira | 9d015a0 | 2013-11-21 01:12:11 +0200 | [diff] [blame] | 2255 | if (prev_agg != lq_sta->is_agg) { |
| 2256 | IWL_DEBUG_RATE(mvm, |
| 2257 | "Aggregation changed: prev %d current %d. Update expected TPT table\n", |
| 2258 | prev_agg, lq_sta->is_agg); |
| 2259 | rs_set_expected_tpt_table(lq_sta, tbl); |
Eyal Shapira | b804eeb | 2014-04-06 04:27:06 +0300 | [diff] [blame] | 2260 | rs_rate_scale_clear_tbl_windows(mvm, tbl); |
Eyal Shapira | 9d015a0 | 2013-11-21 01:12:11 +0200 | [diff] [blame] | 2261 | } |
| 2262 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2263 | /* current tx rate */ |
Eyal Shapira | fcc5e85 | 2015-04-12 23:45:27 +0300 | [diff] [blame] | 2264 | index = rate->index; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2265 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2266 | /* rates available for this association, and for modulation mode */ |
Eyal Shapira | a8ff14f | 2013-11-23 01:30:44 +0200 | [diff] [blame] | 2267 | rate_mask = rs_get_supported_rates(lq_sta, rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2268 | |
Eyal Shapira | ca6f38f | 2013-12-09 11:14:11 +0200 | [diff] [blame] | 2269 | if (!(BIT(index) & rate_mask)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2270 | IWL_ERR(mvm, "Current Rate is not valid\n"); |
| 2271 | if (lq_sta->search_better_tbl) { |
| 2272 | /* revert to active table if search table is not valid*/ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2273 | rate->type = LQ_NONE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2274 | lq_sta->search_better_tbl = 0; |
| 2275 | tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Eyal Shapira | 7b9d74e | 2015-03-29 18:38:07 +0300 | [diff] [blame] | 2276 | rs_update_rate_tbl(mvm, sta, lq_sta, tbl); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2277 | } |
| 2278 | return; |
| 2279 | } |
| 2280 | |
| 2281 | /* Get expected throughput table and history window for current rate */ |
| 2282 | if (!tbl->expected_tpt) { |
| 2283 | IWL_ERR(mvm, "tbl->expected_tpt is NULL\n"); |
| 2284 | return; |
| 2285 | } |
| 2286 | |
Eyal Shapira | 2536e7c | 2014-08-31 02:33:33 +0300 | [diff] [blame] | 2287 | /* TODO: handle rate_idx_mask and rate_idx_mcs_mask */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2288 | window = &(tbl->win[index]); |
| 2289 | |
| 2290 | /* |
| 2291 | * If there is not enough history to calculate actual average |
| 2292 | * throughput, keep analyzing results of more tx frames, without |
| 2293 | * changing rate or mode (bypass most of the rest of this function). |
| 2294 | * Set up new rate table in uCode only if old rate is not supported |
| 2295 | * in current association (use new rate found above). |
| 2296 | */ |
| 2297 | fail_count = window->counter - window->success_counter; |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 2298 | if ((fail_count < IWL_MVM_RS_RATE_MIN_FAILURE_TH) && |
| 2299 | (window->success_counter < IWL_MVM_RS_RATE_MIN_SUCCESS_TH)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2300 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | cc60c6e | 2015-09-19 23:37:45 +0300 | [diff] [blame] | 2301 | "%s: Test Window: succ %d total %d\n", |
| 2302 | rs_pretty_rate(rate), |
| 2303 | window->success_counter, window->counter); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2304 | |
| 2305 | /* Can't calculate this yet; not enough history */ |
| 2306 | window->average_tpt = IWL_INVALID_VALUE; |
| 2307 | |
| 2308 | /* Should we stay with this modulation mode, |
| 2309 | * or search for a new one? */ |
| 2310 | rs_stay_in_table(lq_sta, false); |
| 2311 | |
Eyal Shapira | fcc5e85 | 2015-04-12 23:45:27 +0300 | [diff] [blame] | 2312 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2313 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2314 | |
| 2315 | /* If we are searching for better modulation mode, check success. */ |
| 2316 | if (lq_sta->search_better_tbl) { |
| 2317 | /* If good success, continue using the "search" mode; |
| 2318 | * no need to send new link quality command, since we're |
| 2319 | * continuing to use the setup that we've been trying. */ |
| 2320 | if (window->average_tpt > lq_sta->last_tpt) { |
| 2321 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2322 | "SWITCHING TO NEW TABLE SR: %d " |
| 2323 | "cur-tpt %d old-tpt %d\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2324 | window->success_ratio, |
| 2325 | window->average_tpt, |
| 2326 | lq_sta->last_tpt); |
| 2327 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2328 | /* Swap tables; "search" becomes "active" */ |
| 2329 | lq_sta->active_tbl = active_tbl; |
| 2330 | current_tpt = window->average_tpt; |
| 2331 | /* Else poor success; go back to mode in "active" table */ |
| 2332 | } else { |
| 2333 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2334 | "GOING BACK TO THE OLD TABLE: SR %d " |
| 2335 | "cur-tpt %d old-tpt %d\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2336 | window->success_ratio, |
| 2337 | window->average_tpt, |
| 2338 | lq_sta->last_tpt); |
| 2339 | |
| 2340 | /* Nullify "search" table */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2341 | rate->type = LQ_NONE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2342 | |
| 2343 | /* Revert to "active" table */ |
| 2344 | active_tbl = lq_sta->active_tbl; |
| 2345 | tbl = &(lq_sta->lq_info[active_tbl]); |
| 2346 | |
| 2347 | /* Revert to "active" rate and throughput info */ |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2348 | index = tbl->rate.index; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2349 | current_tpt = lq_sta->last_tpt; |
| 2350 | |
| 2351 | /* Need to set up a new rate table in uCode */ |
| 2352 | update_lq = 1; |
| 2353 | } |
| 2354 | |
| 2355 | /* Either way, we've made a decision; modulation mode |
| 2356 | * search is done, allow rate adjustment next time. */ |
| 2357 | lq_sta->search_better_tbl = 0; |
| 2358 | done_search = 1; /* Don't switch modes below! */ |
| 2359 | goto lq_update; |
| 2360 | } |
| 2361 | |
| 2362 | /* (Else) not in search of better modulation mode, try for better |
| 2363 | * starting rate, while staying in this mode. */ |
Eyal Shapira | ca6f38f | 2013-12-09 11:14:11 +0200 | [diff] [blame] | 2364 | high_low = rs_get_adjacent_rate(mvm, index, rate_mask, rate->type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2365 | low = high_low & 0xff; |
| 2366 | high = (high_low >> 8) & 0xff; |
| 2367 | |
Eyal Shapira | 2536e7c | 2014-08-31 02:33:33 +0300 | [diff] [blame] | 2368 | /* TODO: handle rate_idx_mask and rate_idx_mcs_mask */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2369 | |
| 2370 | sr = window->success_ratio; |
| 2371 | |
| 2372 | /* Collect measured throughputs for current and adjacent rates */ |
| 2373 | current_tpt = window->average_tpt; |
| 2374 | if (low != IWL_RATE_INVALID) |
| 2375 | low_tpt = tbl->win[low].average_tpt; |
| 2376 | if (high != IWL_RATE_INVALID) |
| 2377 | high_tpt = tbl->win[high].average_tpt; |
| 2378 | |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2379 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | cc60c6e | 2015-09-19 23:37:45 +0300 | [diff] [blame] | 2380 | "%s: cur_tpt %d SR %d low %d high %d low_tpt %d high_tpt %d\n", |
| 2381 | rs_pretty_rate(rate), current_tpt, sr, |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2382 | low, high, low_tpt, high_tpt); |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2383 | |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 2384 | scale_action = rs_get_rate_action(mvm, tbl, sr, low, high, |
| 2385 | current_tpt, low_tpt, high_tpt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2386 | |
Eyal Shapira | 393b9e5 | 2013-11-13 16:46:19 +0200 | [diff] [blame] | 2387 | /* 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] | 2388 | if (is_mimo(rate) && |
Eyal Shapira | 393b9e5 | 2013-11-13 16:46:19 +0200 | [diff] [blame] | 2389 | !iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta)) { |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2390 | IWL_DEBUG_RATE(mvm, |
| 2391 | "BT Coex forbids MIMO. Search for new config\n"); |
Emmanuel Grumbach | 36946ce | 2013-05-28 23:12:47 +0300 | [diff] [blame] | 2392 | rs_stay_in_table(lq_sta, true); |
| 2393 | goto lq_update; |
| 2394 | } |
| 2395 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2396 | switch (scale_action) { |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 2397 | case RS_ACTION_DOWNSCALE: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2398 | /* Decrease starting rate, update uCode's rate table */ |
| 2399 | if (low != IWL_RATE_INVALID) { |
| 2400 | update_lq = 1; |
| 2401 | index = low; |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2402 | } else { |
| 2403 | IWL_DEBUG_RATE(mvm, |
| 2404 | "At the bottom rate. Can't decrease\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | break; |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 2408 | case RS_ACTION_UPSCALE: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2409 | /* Increase starting rate, update uCode's rate table */ |
| 2410 | if (high != IWL_RATE_INVALID) { |
| 2411 | update_lq = 1; |
| 2412 | index = high; |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2413 | } else { |
| 2414 | IWL_DEBUG_RATE(mvm, |
| 2415 | "At the top rate. Can't increase\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | break; |
Eyal Shapira | 4e4b815 | 2013-12-11 00:55:36 +0200 | [diff] [blame] | 2419 | case RS_ACTION_STAY: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2420 | /* No change */ |
Eyal Shapira | e6c8d60 | 2014-04-21 21:49:08 +0300 | [diff] [blame] | 2421 | if (lq_sta->rs_state == RS_STATE_STAY_IN_COLUMN) |
| 2422 | update_lq = rs_tpc_perform(mvm, sta, lq_sta, tbl); |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 2423 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2424 | default: |
| 2425 | break; |
| 2426 | } |
| 2427 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2428 | lq_update: |
| 2429 | /* Replace uCode's rate table for the destination station. */ |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2430 | if (update_lq) { |
| 2431 | tbl->rate.index = index; |
Eyal Shapira | 1191f64 | 2015-09-19 23:48:45 +0300 | [diff] [blame] | 2432 | if (IWL_MVM_RS_80_20_FAR_RANGE_TWEAK) |
| 2433 | rs_tweak_rate_tbl(mvm, sta, lq_sta, tbl, scale_action); |
Emmanuel Grumbach | 04e3a5d | 2015-10-28 09:47:41 +0200 | [diff] [blame] | 2434 | rs_set_amsdu_len(mvm, sta, tbl, scale_action); |
Eyal Shapira | 7b9d74e | 2015-03-29 18:38:07 +0300 | [diff] [blame] | 2435 | rs_update_rate_tbl(mvm, sta, lq_sta, tbl); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2436 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2437 | |
| 2438 | rs_stay_in_table(lq_sta, false); |
| 2439 | |
| 2440 | /* |
| 2441 | * Search for new modulation mode if we're: |
| 2442 | * 1) Not changing rates right now |
| 2443 | * 2) Not just finishing up a search |
| 2444 | * 3) Allowing a new search |
| 2445 | */ |
| 2446 | if (!update_lq && !done_search && |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2447 | lq_sta->rs_state == RS_STATE_SEARCH_CYCLE_STARTED |
| 2448 | && window->counter) { |
| 2449 | enum rs_column next_column; |
| 2450 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2451 | /* Save current throughput to compare with "search" throughput*/ |
| 2452 | lq_sta->last_tpt = current_tpt; |
| 2453 | |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2454 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2455 | "Start Search: update_lq %d done_search %d rs_state %d win->counter %d\n", |
| 2456 | update_lq, done_search, lq_sta->rs_state, |
Eyal Shapira | 4d30ee8 | 2013-11-20 01:45:38 +0200 | [diff] [blame] | 2457 | window->counter); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2458 | |
| 2459 | next_column = rs_get_next_column(mvm, lq_sta, sta, tbl); |
| 2460 | if (next_column != RS_COLUMN_INVALID) { |
| 2461 | int ret = rs_switch_to_column(mvm, lq_sta, sta, |
| 2462 | next_column); |
| 2463 | if (!ret) |
| 2464 | lq_sta->search_better_tbl = 1; |
| 2465 | } else { |
| 2466 | IWL_DEBUG_RATE(mvm, |
| 2467 | "No more columns to explore in search cycle. Go to RS_STATE_SEARCH_CYCLE_ENDED\n"); |
| 2468 | lq_sta->rs_state = RS_STATE_SEARCH_CYCLE_ENDED; |
| 2469 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2470 | |
| 2471 | /* If new "search" mode was selected, set up in uCode table */ |
| 2472 | if (lq_sta->search_better_tbl) { |
| 2473 | /* Access the "search" table, clear its history. */ |
| 2474 | tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); |
Eyal Shapira | b804eeb | 2014-04-06 04:27:06 +0300 | [diff] [blame] | 2475 | rs_rate_scale_clear_tbl_windows(mvm, tbl); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2476 | |
| 2477 | /* Use new "search" start rate */ |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 2478 | index = tbl->rate.index; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2479 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2480 | rs_dump_rate(mvm, &tbl->rate, |
| 2481 | "Switch to SEARCH TABLE:"); |
Eyal Shapira | 7b9d74e | 2015-03-29 18:38:07 +0300 | [diff] [blame] | 2482 | rs_update_rate_tbl(mvm, sta, lq_sta, tbl); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2483 | } else { |
| 2484 | done_search = 1; |
| 2485 | } |
| 2486 | } |
| 2487 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2488 | if (done_search && lq_sta->rs_state == RS_STATE_SEARCH_CYCLE_ENDED) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2489 | /* If the "active" (non-search) mode was legacy, |
| 2490 | * and we've tried switching antennas, |
| 2491 | * but we haven't been able to try HT modes (not available), |
| 2492 | * stay with best antenna legacy modulation for a while |
| 2493 | * before next round of mode comparisons. */ |
| 2494 | tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 2495 | if (is_legacy(&tbl1->rate)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2496 | IWL_DEBUG_RATE(mvm, "LQ: STAY in legacy table\n"); |
Eyal Shapira | fd7dbee | 2014-04-06 04:39:23 +0300 | [diff] [blame] | 2497 | |
| 2498 | if (tid != IWL_MAX_TID_COUNT) { |
| 2499 | tid_data = &sta_priv->tid_data[tid]; |
| 2500 | if (tid_data->state != IWL_AGG_OFF) { |
| 2501 | IWL_DEBUG_RATE(mvm, |
| 2502 | "Stop aggregation on tid %d\n", |
| 2503 | tid); |
| 2504 | ieee80211_stop_tx_ba_session(sta, tid); |
| 2505 | } |
| 2506 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2507 | rs_set_stay_in_table(mvm, 1, lq_sta); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2508 | } else { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2509 | /* If we're in an HT mode, and all 3 mode switch actions |
| 2510 | * have been tried and compared, stay in this best modulation |
| 2511 | * mode for a while before next round of mode comparisons. */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2512 | if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) && |
| 2513 | (lq_sta->tx_agg_tid_en & (1 << tid)) && |
| 2514 | (tid != IWL_MAX_TID_COUNT)) { |
| 2515 | tid_data = &sta_priv->tid_data[tid]; |
Matti Gottlieb | ff7a68d | 2016-05-17 10:50:08 +0300 | [diff] [blame^] | 2516 | if (tid_data->state == IWL_AGG_OFF && !ndp) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2517 | IWL_DEBUG_RATE(mvm, |
| 2518 | "try to aggregate tid %d\n", |
| 2519 | tid); |
| 2520 | rs_tl_turn_on_agg(mvm, tid, |
| 2521 | lq_sta, sta); |
| 2522 | } |
| 2523 | } |
| 2524 | rs_set_stay_in_table(mvm, 0, lq_sta); |
| 2525 | } |
| 2526 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2527 | } |
| 2528 | |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2529 | struct rs_init_rate_info { |
| 2530 | s8 rssi; |
| 2531 | u8 rate_idx; |
| 2532 | }; |
| 2533 | |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2534 | static const struct rs_init_rate_info rs_optimal_rates_24ghz_legacy[] = { |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2535 | { -60, IWL_RATE_54M_INDEX }, |
| 2536 | { -64, IWL_RATE_48M_INDEX }, |
| 2537 | { -68, IWL_RATE_36M_INDEX }, |
| 2538 | { -80, IWL_RATE_24M_INDEX }, |
| 2539 | { -84, IWL_RATE_18M_INDEX }, |
| 2540 | { -85, IWL_RATE_12M_INDEX }, |
| 2541 | { -86, IWL_RATE_11M_INDEX }, |
| 2542 | { -88, IWL_RATE_5M_INDEX }, |
| 2543 | { -90, IWL_RATE_2M_INDEX }, |
| 2544 | { S8_MIN, IWL_RATE_1M_INDEX }, |
| 2545 | }; |
| 2546 | |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2547 | static const struct rs_init_rate_info rs_optimal_rates_5ghz_legacy[] = { |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2548 | { -60, IWL_RATE_54M_INDEX }, |
| 2549 | { -64, IWL_RATE_48M_INDEX }, |
| 2550 | { -72, IWL_RATE_36M_INDEX }, |
| 2551 | { -80, IWL_RATE_24M_INDEX }, |
| 2552 | { -84, IWL_RATE_18M_INDEX }, |
| 2553 | { -85, IWL_RATE_12M_INDEX }, |
| 2554 | { -87, IWL_RATE_9M_INDEX }, |
| 2555 | { S8_MIN, IWL_RATE_6M_INDEX }, |
| 2556 | }; |
| 2557 | |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2558 | static const struct rs_init_rate_info rs_optimal_rates_ht[] = { |
| 2559 | { -60, IWL_RATE_MCS_7_INDEX }, |
| 2560 | { -64, IWL_RATE_MCS_6_INDEX }, |
| 2561 | { -68, IWL_RATE_MCS_5_INDEX }, |
| 2562 | { -72, IWL_RATE_MCS_4_INDEX }, |
| 2563 | { -80, IWL_RATE_MCS_3_INDEX }, |
| 2564 | { -84, IWL_RATE_MCS_2_INDEX }, |
| 2565 | { -85, IWL_RATE_MCS_1_INDEX }, |
| 2566 | { S8_MIN, IWL_RATE_MCS_0_INDEX}, |
| 2567 | }; |
| 2568 | |
| 2569 | static const struct rs_init_rate_info rs_optimal_rates_vht_20mhz[] = { |
| 2570 | { -60, IWL_RATE_MCS_8_INDEX }, |
| 2571 | { -64, IWL_RATE_MCS_7_INDEX }, |
| 2572 | { -68, IWL_RATE_MCS_6_INDEX }, |
| 2573 | { -72, IWL_RATE_MCS_5_INDEX }, |
| 2574 | { -80, IWL_RATE_MCS_4_INDEX }, |
| 2575 | { -84, IWL_RATE_MCS_3_INDEX }, |
| 2576 | { -85, IWL_RATE_MCS_2_INDEX }, |
| 2577 | { -87, IWL_RATE_MCS_1_INDEX }, |
| 2578 | { S8_MIN, IWL_RATE_MCS_0_INDEX}, |
| 2579 | }; |
| 2580 | |
| 2581 | static const struct rs_init_rate_info rs_optimal_rates_vht_40_80mhz[] = { |
| 2582 | { -60, IWL_RATE_MCS_9_INDEX }, |
| 2583 | { -64, IWL_RATE_MCS_8_INDEX }, |
| 2584 | { -68, IWL_RATE_MCS_7_INDEX }, |
| 2585 | { -72, IWL_RATE_MCS_6_INDEX }, |
| 2586 | { -80, IWL_RATE_MCS_5_INDEX }, |
| 2587 | { -84, IWL_RATE_MCS_4_INDEX }, |
| 2588 | { -85, IWL_RATE_MCS_3_INDEX }, |
| 2589 | { -87, IWL_RATE_MCS_2_INDEX }, |
| 2590 | { -88, IWL_RATE_MCS_1_INDEX }, |
| 2591 | { S8_MIN, IWL_RATE_MCS_0_INDEX }, |
| 2592 | }; |
| 2593 | |
Gregory Greenman | 99319b8 | 2015-11-24 19:13:27 +0200 | [diff] [blame] | 2594 | #define IWL_RS_LOW_RSSI_THRESHOLD (-76) /* dBm */ |
| 2595 | |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2596 | /* Init the optimal rate based on STA caps |
| 2597 | * This combined with rssi is used to report the last tx rate |
| 2598 | * to userspace when we haven't transmitted enough frames. |
| 2599 | */ |
| 2600 | static void rs_init_optimal_rate(struct iwl_mvm *mvm, |
| 2601 | struct ieee80211_sta *sta, |
| 2602 | struct iwl_lq_sta *lq_sta) |
| 2603 | { |
| 2604 | struct rs_rate *rate = &lq_sta->optimal_rate; |
| 2605 | |
| 2606 | if (lq_sta->max_mimo2_rate_idx != IWL_RATE_INVALID) |
| 2607 | rate->type = lq_sta->is_vht ? LQ_VHT_MIMO2 : LQ_HT_MIMO2; |
| 2608 | else if (lq_sta->max_siso_rate_idx != IWL_RATE_INVALID) |
| 2609 | rate->type = lq_sta->is_vht ? LQ_VHT_SISO : LQ_HT_SISO; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2610 | else if (lq_sta->band == NL80211_BAND_5GHZ) |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2611 | rate->type = LQ_LEGACY_A; |
| 2612 | else |
| 2613 | rate->type = LQ_LEGACY_G; |
| 2614 | |
| 2615 | rate->bw = rs_bw_from_sta_bw(sta); |
| 2616 | rate->sgi = rs_sgi_allow(mvm, sta, rate, NULL); |
| 2617 | |
| 2618 | /* ANT/LDPC/STBC aren't relevant for the rate reported to userspace */ |
| 2619 | |
| 2620 | if (is_mimo(rate)) { |
| 2621 | lq_sta->optimal_rate_mask = lq_sta->active_mimo2_rate; |
| 2622 | } else if (is_siso(rate)) { |
| 2623 | lq_sta->optimal_rate_mask = lq_sta->active_siso_rate; |
| 2624 | } else { |
| 2625 | lq_sta->optimal_rate_mask = lq_sta->active_legacy_rate; |
| 2626 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2627 | if (lq_sta->band == NL80211_BAND_5GHZ) { |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2628 | lq_sta->optimal_rates = rs_optimal_rates_5ghz_legacy; |
| 2629 | lq_sta->optimal_nentries = |
| 2630 | ARRAY_SIZE(rs_optimal_rates_5ghz_legacy); |
| 2631 | } else { |
| 2632 | lq_sta->optimal_rates = rs_optimal_rates_24ghz_legacy; |
| 2633 | lq_sta->optimal_nentries = |
| 2634 | ARRAY_SIZE(rs_optimal_rates_24ghz_legacy); |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | if (is_vht(rate)) { |
| 2639 | if (rate->bw == RATE_MCS_CHAN_WIDTH_20) { |
| 2640 | lq_sta->optimal_rates = rs_optimal_rates_vht_20mhz; |
| 2641 | lq_sta->optimal_nentries = |
| 2642 | ARRAY_SIZE(rs_optimal_rates_vht_20mhz); |
| 2643 | } else { |
| 2644 | lq_sta->optimal_rates = rs_optimal_rates_vht_40_80mhz; |
| 2645 | lq_sta->optimal_nentries = |
| 2646 | ARRAY_SIZE(rs_optimal_rates_vht_40_80mhz); |
| 2647 | } |
| 2648 | } else if (is_ht(rate)) { |
| 2649 | lq_sta->optimal_rates = rs_optimal_rates_ht; |
| 2650 | lq_sta->optimal_nentries = ARRAY_SIZE(rs_optimal_rates_ht); |
| 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | /* Compute the optimal rate index based on RSSI */ |
| 2655 | static struct rs_rate *rs_get_optimal_rate(struct iwl_mvm *mvm, |
| 2656 | struct iwl_lq_sta *lq_sta) |
| 2657 | { |
| 2658 | struct rs_rate *rate = &lq_sta->optimal_rate; |
| 2659 | int i; |
| 2660 | |
| 2661 | rate->index = find_first_bit(&lq_sta->optimal_rate_mask, |
| 2662 | BITS_PER_LONG); |
| 2663 | |
| 2664 | for (i = 0; i < lq_sta->optimal_nentries; i++) { |
| 2665 | int rate_idx = lq_sta->optimal_rates[i].rate_idx; |
| 2666 | |
| 2667 | if ((lq_sta->pers.last_rssi >= lq_sta->optimal_rates[i].rssi) && |
| 2668 | (BIT(rate_idx) & lq_sta->optimal_rate_mask)) { |
| 2669 | rate->index = rate_idx; |
| 2670 | break; |
| 2671 | } |
| 2672 | } |
| 2673 | |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2674 | return rate; |
| 2675 | } |
| 2676 | |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2677 | /* Choose an initial legacy rate and antenna to use based on the RSSI |
| 2678 | * of last Rx |
| 2679 | */ |
| 2680 | static void rs_get_initial_rate(struct iwl_mvm *mvm, |
Gregory Greenman | 99319b8 | 2015-11-24 19:13:27 +0200 | [diff] [blame] | 2681 | struct ieee80211_sta *sta, |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2682 | struct iwl_lq_sta *lq_sta, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2683 | enum nl80211_band band, |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2684 | struct rs_rate *rate) |
| 2685 | { |
| 2686 | int i, nentries; |
Gregory Greenman | 99319b8 | 2015-11-24 19:13:27 +0200 | [diff] [blame] | 2687 | unsigned long active_rate; |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2688 | s8 best_rssi = S8_MIN; |
| 2689 | u8 best_ant = ANT_NONE; |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 2690 | u8 valid_tx_ant = iwl_mvm_get_valid_tx_ant(mvm); |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2691 | const struct rs_init_rate_info *initial_rates; |
| 2692 | |
| 2693 | for (i = 0; i < ARRAY_SIZE(lq_sta->pers.chain_signal); i++) { |
| 2694 | if (!(lq_sta->pers.chains & BIT(i))) |
| 2695 | continue; |
| 2696 | |
| 2697 | if (lq_sta->pers.chain_signal[i] > best_rssi) { |
| 2698 | best_rssi = lq_sta->pers.chain_signal[i]; |
| 2699 | best_ant = BIT(i); |
| 2700 | } |
| 2701 | } |
| 2702 | |
| 2703 | IWL_DEBUG_RATE(mvm, "Best ANT: %s Best RSSI: %d\n", |
| 2704 | rs_pretty_ant(best_ant), best_rssi); |
| 2705 | |
| 2706 | if (best_ant != ANT_A && best_ant != ANT_B) |
| 2707 | rate->ant = first_antenna(valid_tx_ant); |
| 2708 | else |
| 2709 | rate->ant = best_ant; |
| 2710 | |
| 2711 | rate->sgi = false; |
| 2712 | rate->ldpc = false; |
| 2713 | rate->bw = RATE_MCS_CHAN_WIDTH_20; |
| 2714 | |
| 2715 | rate->index = find_first_bit(&lq_sta->active_legacy_rate, |
| 2716 | BITS_PER_LONG); |
| 2717 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2718 | if (band == NL80211_BAND_5GHZ) { |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2719 | rate->type = LQ_LEGACY_A; |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2720 | initial_rates = rs_optimal_rates_5ghz_legacy; |
| 2721 | nentries = ARRAY_SIZE(rs_optimal_rates_5ghz_legacy); |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2722 | } else { |
| 2723 | rate->type = LQ_LEGACY_G; |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2724 | initial_rates = rs_optimal_rates_24ghz_legacy; |
| 2725 | nentries = ARRAY_SIZE(rs_optimal_rates_24ghz_legacy); |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2726 | } |
| 2727 | |
Gregory Greenman | 99319b8 | 2015-11-24 19:13:27 +0200 | [diff] [blame] | 2728 | if (!IWL_MVM_RS_RSSI_BASED_INIT_RATE) |
| 2729 | goto out; |
| 2730 | |
| 2731 | /* Start from a higher rate if the corresponding debug capability |
| 2732 | * is enabled. The rate is chosen according to AP capabilities. |
| 2733 | * In case of VHT/HT when the rssi is low fallback to the case of |
| 2734 | * legacy rates. |
| 2735 | */ |
| 2736 | if (sta->vht_cap.vht_supported && |
| 2737 | best_rssi > IWL_RS_LOW_RSSI_THRESHOLD) { |
| 2738 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) { |
| 2739 | initial_rates = rs_optimal_rates_vht_40_80mhz; |
| 2740 | nentries = ARRAY_SIZE(rs_optimal_rates_vht_40_80mhz); |
| 2741 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_80) |
| 2742 | rate->bw = RATE_MCS_CHAN_WIDTH_80; |
| 2743 | else |
| 2744 | rate->bw = RATE_MCS_CHAN_WIDTH_40; |
| 2745 | } else if (sta->bandwidth == IEEE80211_STA_RX_BW_20) { |
| 2746 | initial_rates = rs_optimal_rates_vht_20mhz; |
| 2747 | nentries = ARRAY_SIZE(rs_optimal_rates_vht_20mhz); |
| 2748 | rate->bw = RATE_MCS_CHAN_WIDTH_20; |
| 2749 | } else { |
| 2750 | IWL_ERR(mvm, "Invalid BW %d\n", sta->bandwidth); |
| 2751 | goto out; |
| 2752 | } |
| 2753 | active_rate = lq_sta->active_siso_rate; |
| 2754 | rate->type = LQ_VHT_SISO; |
| 2755 | } else if (sta->ht_cap.ht_supported && |
| 2756 | best_rssi > IWL_RS_LOW_RSSI_THRESHOLD) { |
| 2757 | initial_rates = rs_optimal_rates_ht; |
| 2758 | nentries = ARRAY_SIZE(rs_optimal_rates_ht); |
| 2759 | active_rate = lq_sta->active_siso_rate; |
| 2760 | rate->type = LQ_HT_SISO; |
| 2761 | } else { |
| 2762 | active_rate = lq_sta->active_legacy_rate; |
| 2763 | } |
| 2764 | |
| 2765 | for (i = 0; i < nentries; i++) { |
| 2766 | int rate_idx = initial_rates[i].rate_idx; |
| 2767 | |
| 2768 | if ((best_rssi >= initial_rates[i].rssi) && |
| 2769 | (BIT(rate_idx) & active_rate)) { |
| 2770 | rate->index = rate_idx; |
| 2771 | break; |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2772 | } |
| 2773 | } |
| 2774 | |
Gregory Greenman | 99319b8 | 2015-11-24 19:13:27 +0200 | [diff] [blame] | 2775 | out: |
| 2776 | rs_dump_rate(mvm, rate, "INITIAL"); |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | /* Save info about RSSI of last Rx */ |
| 2780 | void rs_update_last_rssi(struct iwl_mvm *mvm, |
| 2781 | struct iwl_lq_sta *lq_sta, |
| 2782 | struct ieee80211_rx_status *rx_status) |
| 2783 | { |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2784 | int i; |
| 2785 | |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2786 | lq_sta->pers.chains = rx_status->chains; |
| 2787 | lq_sta->pers.chain_signal[0] = rx_status->chain_signal[0]; |
| 2788 | lq_sta->pers.chain_signal[1] = rx_status->chain_signal[1]; |
| 2789 | lq_sta->pers.chain_signal[2] = rx_status->chain_signal[2]; |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2790 | lq_sta->pers.last_rssi = S8_MIN; |
| 2791 | |
| 2792 | for (i = 0; i < ARRAY_SIZE(lq_sta->pers.chain_signal); i++) { |
| 2793 | if (!(lq_sta->pers.chains & BIT(i))) |
| 2794 | continue; |
| 2795 | |
| 2796 | if (lq_sta->pers.chain_signal[i] > lq_sta->pers.last_rssi) |
| 2797 | lq_sta->pers.last_rssi = lq_sta->pers.chain_signal[i]; |
| 2798 | } |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2799 | } |
| 2800 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2801 | /** |
| 2802 | * rs_initialize_lq - Initialize a station's hardware rate table |
| 2803 | * |
| 2804 | * The uCode's station table contains a table of fallback rates |
| 2805 | * for automatic fallback during transmission. |
| 2806 | * |
| 2807 | * NOTE: This sets up a default set of values. These will be replaced later |
| 2808 | * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of |
| 2809 | * rc80211_simple. |
| 2810 | * |
| 2811 | * NOTE: Run REPLY_ADD_STA command to set up station table entry, before |
| 2812 | * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, |
| 2813 | * which requires station table entry to exist). |
| 2814 | */ |
| 2815 | static void rs_initialize_lq(struct iwl_mvm *mvm, |
| 2816 | struct ieee80211_sta *sta, |
| 2817 | struct iwl_lq_sta *lq_sta, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2818 | enum nl80211_band band, |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 2819 | bool init) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2820 | { |
| 2821 | struct iwl_scale_tbl_info *tbl; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2822 | struct rs_rate *rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2823 | u8 active_tbl = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2824 | |
| 2825 | if (!sta || !lq_sta) |
| 2826 | return; |
| 2827 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2828 | if (!lq_sta->search_better_tbl) |
| 2829 | active_tbl = lq_sta->active_tbl; |
| 2830 | else |
| 2831 | active_tbl = 1 - lq_sta->active_tbl; |
| 2832 | |
| 2833 | tbl = &(lq_sta->lq_info[active_tbl]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 2834 | rate = &tbl->rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2835 | |
Gregory Greenman | 99319b8 | 2015-11-24 19:13:27 +0200 | [diff] [blame] | 2836 | rs_get_initial_rate(mvm, sta, lq_sta, band, rate); |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2837 | rs_init_optimal_rate(mvm, sta, lq_sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2838 | |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2839 | WARN_ON_ONCE(rate->ant != ANT_A && rate->ant != ANT_B); |
Gregory Greenman | 99319b8 | 2015-11-24 19:13:27 +0200 | [diff] [blame] | 2840 | tbl->column = rs_get_column_from_rate(rate); |
Eyal Shapira | b3b06a3 | 2013-11-24 21:30:13 +0200 | [diff] [blame] | 2841 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2842 | rs_set_expected_tpt_table(lq_sta, tbl); |
Eyal Shapira | 80e9e5c | 2013-12-23 16:26:41 +0200 | [diff] [blame] | 2843 | rs_fill_lq_cmd(mvm, sta, lq_sta, rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2844 | /* TODO restore station should remember the lq cmd */ |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 2845 | iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, init); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | static void rs_get_rate(void *mvm_r, struct ieee80211_sta *sta, void *mvm_sta, |
| 2849 | struct ieee80211_tx_rate_control *txrc) |
| 2850 | { |
| 2851 | struct sk_buff *skb = txrc->skb; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2852 | struct iwl_op_mode *op_mode __maybe_unused = |
| 2853 | (struct iwl_op_mode *)mvm_r; |
| 2854 | struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode); |
| 2855 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2856 | struct iwl_lq_sta *lq_sta = mvm_sta; |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2857 | struct rs_rate *optimal_rate; |
| 2858 | u32 last_ucode_rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2859 | |
Johannes Berg | dcbc17a | 2015-03-10 21:24:34 +0100 | [diff] [blame] | 2860 | if (sta && !iwl_mvm_sta_from_mac80211(sta)->vif) { |
| 2861 | /* if vif isn't initialized mvm doesn't know about |
| 2862 | * this station, so don't do anything with the it |
| 2863 | */ |
| 2864 | sta = NULL; |
| 2865 | mvm_sta = NULL; |
| 2866 | } |
| 2867 | |
Eyal Shapira | 2536e7c | 2014-08-31 02:33:33 +0300 | [diff] [blame] | 2868 | /* TODO: handle rate_idx_mask and rate_idx_mcs_mask */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2869 | |
| 2870 | /* Treat uninitialized rate scaling data same as non-existing. */ |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 2871 | if (lq_sta && !lq_sta->pers.drv) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2872 | IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n"); |
| 2873 | mvm_sta = NULL; |
| 2874 | } |
| 2875 | |
| 2876 | /* Send management frames and NO_ACK data using lowest rate. */ |
| 2877 | if (rate_control_send_low(sta, mvm_sta, txrc)) |
| 2878 | return; |
| 2879 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2880 | iwl_mvm_hwrate_to_tx_rate(lq_sta->last_rate_n_flags, |
| 2881 | info->band, &info->control.rates[0]); |
Moshe Benji | 622ebe9 | 2013-06-03 19:27:16 +0300 | [diff] [blame] | 2882 | info->control.rates[0].count = 1; |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2883 | |
| 2884 | /* Report the optimal rate based on rssi and STA caps if we haven't |
| 2885 | * converged yet (too little traffic) or exploring other modulations |
| 2886 | */ |
| 2887 | if (lq_sta->rs_state != RS_STATE_STAY_IN_COLUMN) { |
| 2888 | optimal_rate = rs_get_optimal_rate(mvm, lq_sta); |
| 2889 | last_ucode_rate = ucode_rate_from_rs_rate(mvm, |
| 2890 | optimal_rate); |
| 2891 | iwl_mvm_hwrate_to_tx_rate(last_ucode_rate, info->band, |
| 2892 | &txrc->reported_rate); |
| 2893 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | static void *rs_alloc_sta(void *mvm_rate, struct ieee80211_sta *sta, |
| 2897 | gfp_t gfp) |
| 2898 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 2899 | struct iwl_mvm_sta *sta_priv = iwl_mvm_sta_from_mac80211(sta); |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 2900 | struct iwl_op_mode *op_mode = (struct iwl_op_mode *)mvm_rate; |
| 2901 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); |
| 2902 | struct iwl_lq_sta *lq_sta = &sta_priv->lq_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2903 | |
| 2904 | IWL_DEBUG_RATE(mvm, "create station rate scale window\n"); |
| 2905 | |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 2906 | lq_sta->pers.drv = mvm; |
| 2907 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 2908 | lq_sta->pers.dbg_fixed_rate = 0; |
| 2909 | lq_sta->pers.dbg_fixed_txp_reduction = TPC_INVALID; |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 2910 | lq_sta->pers.ss_force = RS_SS_FORCE_NONE; |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 2911 | #endif |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 2912 | lq_sta->pers.chains = 0; |
| 2913 | memset(lq_sta->pers.chain_signal, 0, sizeof(lq_sta->pers.chain_signal)); |
Eyal Shapira | b503ed6 | 2015-05-27 22:20:46 +0300 | [diff] [blame] | 2914 | lq_sta->pers.last_rssi = S8_MIN; |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 2915 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2916 | return &sta_priv->lq_sta; |
| 2917 | } |
| 2918 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 2919 | static int rs_vht_highest_rx_mcs_index(struct ieee80211_sta_vht_cap *vht_cap, |
| 2920 | int nss) |
| 2921 | { |
| 2922 | u16 rx_mcs = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) & |
| 2923 | (0x3 << (2 * (nss - 1))); |
| 2924 | rx_mcs >>= (2 * (nss - 1)); |
| 2925 | |
| 2926 | if (rx_mcs == IEEE80211_VHT_MCS_SUPPORT_0_7) |
| 2927 | return IWL_RATE_MCS_7_INDEX; |
| 2928 | else if (rx_mcs == IEEE80211_VHT_MCS_SUPPORT_0_8) |
| 2929 | return IWL_RATE_MCS_8_INDEX; |
| 2930 | else if (rx_mcs == IEEE80211_VHT_MCS_SUPPORT_0_9) |
| 2931 | return IWL_RATE_MCS_9_INDEX; |
| 2932 | |
| 2933 | WARN_ON_ONCE(rx_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED); |
| 2934 | return -1; |
| 2935 | } |
| 2936 | |
Eyal Shapira | 750a1b4 | 2013-11-09 22:48:56 +0200 | [diff] [blame] | 2937 | static void rs_vht_set_enabled_rates(struct ieee80211_sta *sta, |
| 2938 | struct ieee80211_sta_vht_cap *vht_cap, |
| 2939 | struct iwl_lq_sta *lq_sta) |
| 2940 | { |
| 2941 | int i; |
| 2942 | int highest_mcs = rs_vht_highest_rx_mcs_index(vht_cap, 1); |
| 2943 | |
| 2944 | if (highest_mcs >= IWL_RATE_MCS_0_INDEX) { |
| 2945 | for (i = IWL_RATE_MCS_0_INDEX; i <= highest_mcs; i++) { |
| 2946 | if (i == IWL_RATE_9M_INDEX) |
| 2947 | continue; |
| 2948 | |
Eyal Shapira | 271518a | 2013-11-09 23:25:06 +0200 | [diff] [blame] | 2949 | /* VHT MCS9 isn't valid for 20Mhz for NSS=1,2 */ |
| 2950 | if (i == IWL_RATE_MCS_9_INDEX && |
| 2951 | sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 2952 | continue; |
| 2953 | |
Eyal Shapira | 750a1b4 | 2013-11-09 22:48:56 +0200 | [diff] [blame] | 2954 | lq_sta->active_siso_rate |= BIT(i); |
| 2955 | } |
| 2956 | } |
| 2957 | |
Eyal Shapira | ecc90e7 | 2013-11-09 23:31:38 +0200 | [diff] [blame] | 2958 | if (sta->rx_nss < 2) |
| 2959 | return; |
| 2960 | |
Eyal Shapira | 750a1b4 | 2013-11-09 22:48:56 +0200 | [diff] [blame] | 2961 | highest_mcs = rs_vht_highest_rx_mcs_index(vht_cap, 2); |
| 2962 | if (highest_mcs >= IWL_RATE_MCS_0_INDEX) { |
| 2963 | for (i = IWL_RATE_MCS_0_INDEX; i <= highest_mcs; i++) { |
| 2964 | if (i == IWL_RATE_9M_INDEX) |
| 2965 | continue; |
| 2966 | |
Eyal Shapira | 271518a | 2013-11-09 23:25:06 +0200 | [diff] [blame] | 2967 | /* VHT MCS9 isn't valid for 20Mhz for NSS=1,2 */ |
| 2968 | if (i == IWL_RATE_MCS_9_INDEX && |
| 2969 | sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 2970 | continue; |
| 2971 | |
Eyal Shapira | 750a1b4 | 2013-11-09 22:48:56 +0200 | [diff] [blame] | 2972 | lq_sta->active_mimo2_rate |= BIT(i); |
| 2973 | } |
| 2974 | } |
| 2975 | } |
| 2976 | |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 2977 | static void rs_ht_init(struct iwl_mvm *mvm, |
| 2978 | struct ieee80211_sta *sta, |
| 2979 | struct iwl_lq_sta *lq_sta, |
| 2980 | struct ieee80211_sta_ht_cap *ht_cap) |
| 2981 | { |
| 2982 | /* active_siso_rate mask includes 9 MBits (bit 5), |
| 2983 | * and CCK (bits 0-3), supp_rates[] does not; |
| 2984 | * shift to convert format, force 9 MBits off. |
| 2985 | */ |
| 2986 | lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1; |
| 2987 | lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1; |
| 2988 | lq_sta->active_siso_rate &= ~((u16)0x2); |
| 2989 | lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE; |
| 2990 | |
| 2991 | lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1; |
| 2992 | lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1; |
| 2993 | lq_sta->active_mimo2_rate &= ~((u16)0x2); |
| 2994 | lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE; |
| 2995 | |
| 2996 | if (mvm->cfg->ht_params->ldpc && |
| 2997 | (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)) |
| 2998 | lq_sta->ldpc = true; |
| 2999 | |
| 3000 | if (mvm->cfg->ht_params->stbc && |
| 3001 | (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) > 1) && |
| 3002 | (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC)) |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3003 | lq_sta->stbc_capable = true; |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3004 | |
| 3005 | lq_sta->is_vht = false; |
| 3006 | } |
| 3007 | |
| 3008 | static void rs_vht_init(struct iwl_mvm *mvm, |
| 3009 | struct ieee80211_sta *sta, |
| 3010 | struct iwl_lq_sta *lq_sta, |
| 3011 | struct ieee80211_sta_vht_cap *vht_cap) |
| 3012 | { |
| 3013 | rs_vht_set_enabled_rates(sta, vht_cap, lq_sta); |
| 3014 | |
| 3015 | if (mvm->cfg->ht_params->ldpc && |
| 3016 | (vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC)) |
| 3017 | lq_sta->ldpc = true; |
| 3018 | |
| 3019 | if (mvm->cfg->ht_params->stbc && |
| 3020 | (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) > 1) && |
| 3021 | (vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK)) |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3022 | lq_sta->stbc_capable = true; |
| 3023 | |
Johannes Berg | 859d914 | 2015-06-01 17:11:11 +0200 | [diff] [blame] | 3024 | if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_BEAMFORMER) && |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3025 | (num_of_ant(iwl_mvm_get_valid_tx_ant(mvm)) > 1) && |
| 3026 | (vht_cap->cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) |
| 3027 | lq_sta->bfer_capable = true; |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3028 | |
| 3029 | lq_sta->is_vht = true; |
| 3030 | } |
| 3031 | |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3032 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3033 | static void iwl_mvm_reset_frame_stats(struct iwl_mvm *mvm) |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3034 | { |
| 3035 | spin_lock_bh(&mvm->drv_stats_lock); |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3036 | memset(&mvm->drv_rx_stats, 0, sizeof(mvm->drv_rx_stats)); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3037 | spin_unlock_bh(&mvm->drv_stats_lock); |
| 3038 | } |
| 3039 | |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3040 | void iwl_mvm_update_frame_stats(struct iwl_mvm *mvm, u32 rate, bool agg) |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3041 | { |
| 3042 | u8 nss = 0, mcs = 0; |
| 3043 | |
| 3044 | spin_lock(&mvm->drv_stats_lock); |
| 3045 | |
| 3046 | if (agg) |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3047 | mvm->drv_rx_stats.agg_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3048 | |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3049 | mvm->drv_rx_stats.success_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3050 | |
| 3051 | switch (rate & RATE_MCS_CHAN_WIDTH_MSK) { |
| 3052 | case RATE_MCS_CHAN_WIDTH_20: |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3053 | mvm->drv_rx_stats.bw_20_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3054 | break; |
| 3055 | case RATE_MCS_CHAN_WIDTH_40: |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3056 | mvm->drv_rx_stats.bw_40_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3057 | break; |
| 3058 | case RATE_MCS_CHAN_WIDTH_80: |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3059 | mvm->drv_rx_stats.bw_80_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3060 | break; |
| 3061 | default: |
| 3062 | WARN_ONCE(1, "bad BW. rate 0x%x", rate); |
| 3063 | } |
| 3064 | |
| 3065 | if (rate & RATE_MCS_HT_MSK) { |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3066 | mvm->drv_rx_stats.ht_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3067 | mcs = rate & RATE_HT_MCS_RATE_CODE_MSK; |
| 3068 | nss = ((rate & RATE_HT_MCS_NSS_MSK) >> RATE_HT_MCS_NSS_POS) + 1; |
| 3069 | } else if (rate & RATE_MCS_VHT_MSK) { |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3070 | mvm->drv_rx_stats.vht_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3071 | mcs = rate & RATE_VHT_MCS_RATE_CODE_MSK; |
| 3072 | nss = ((rate & RATE_VHT_MCS_NSS_MSK) >> |
| 3073 | RATE_VHT_MCS_NSS_POS) + 1; |
| 3074 | } else { |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3075 | mvm->drv_rx_stats.legacy_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | if (nss == 1) |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3079 | mvm->drv_rx_stats.siso_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3080 | else if (nss == 2) |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3081 | mvm->drv_rx_stats.mimo2_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3082 | |
| 3083 | if (rate & RATE_MCS_SGI_MSK) |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3084 | mvm->drv_rx_stats.sgi_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3085 | else |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3086 | mvm->drv_rx_stats.ngi_frames++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3087 | |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3088 | mvm->drv_rx_stats.last_rates[mvm->drv_rx_stats.last_frame_idx] = rate; |
| 3089 | mvm->drv_rx_stats.last_frame_idx = |
| 3090 | (mvm->drv_rx_stats.last_frame_idx + 1) % |
| 3091 | ARRAY_SIZE(mvm->drv_rx_stats.last_rates); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3092 | |
| 3093 | spin_unlock(&mvm->drv_stats_lock); |
| 3094 | } |
| 3095 | #endif |
| 3096 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3097 | /* |
| 3098 | * Called after adding a new station to initialize rate scaling |
| 3099 | */ |
| 3100 | void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3101 | enum nl80211_band band, bool init) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3102 | { |
| 3103 | int i, j; |
| 3104 | struct ieee80211_hw *hw = mvm->hw; |
| 3105 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 3106 | struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 3107 | struct iwl_mvm_sta *sta_priv = iwl_mvm_sta_from_mac80211(sta); |
| 3108 | struct iwl_lq_sta *lq_sta = &sta_priv->lq_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3109 | struct ieee80211_supported_band *sband; |
| 3110 | unsigned long supp; /* must be unsigned long for for_each_set_bit */ |
| 3111 | |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3112 | /* clear all non-persistent lq data */ |
| 3113 | memset(lq_sta, 0, offsetof(typeof(*lq_sta), pers)); |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 3114 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3115 | sband = hw->wiphy->bands[band]; |
| 3116 | |
| 3117 | lq_sta->lq.sta_id = sta_priv->sta_id; |
Emmanuel Grumbach | 04e3a5d | 2015-10-28 09:47:41 +0200 | [diff] [blame] | 3118 | sta_priv->tlc_amsdu = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3119 | |
| 3120 | for (j = 0; j < LQ_SIZE; j++) |
Eyal Shapira | b804eeb | 2014-04-06 04:27:06 +0300 | [diff] [blame] | 3121 | rs_rate_scale_clear_tbl_windows(mvm, &lq_sta->lq_info[j]); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3122 | |
| 3123 | lq_sta->flush_timer = 0; |
Eyal Shapira | 87d5e41 | 2014-04-06 18:13:22 +0300 | [diff] [blame] | 3124 | lq_sta->last_tx = jiffies; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3125 | |
| 3126 | IWL_DEBUG_RATE(mvm, |
| 3127 | "LQ: *** rate scale station global init for station %d ***\n", |
| 3128 | sta_priv->sta_id); |
| 3129 | /* TODO: what is a good starting rate for STA? About middle? Maybe not |
| 3130 | * the lowest or the highest rate.. Could consider using RSSI from |
| 3131 | * previous packets? Need to have IEEE 802.1X auth succeed immediately |
| 3132 | * after assoc.. */ |
| 3133 | |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 3134 | lq_sta->missed_rate_counter = IWL_MVM_RS_MISSED_RATE_MAX; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3135 | lq_sta->band = sband->band; |
| 3136 | /* |
| 3137 | * active legacy rates as per supported rates bitmap |
| 3138 | */ |
| 3139 | supp = sta->supp_rates[sband->band]; |
| 3140 | lq_sta->active_legacy_rate = 0; |
| 3141 | for_each_set_bit(i, &supp, BITS_PER_LONG) |
| 3142 | lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value); |
| 3143 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 3144 | /* TODO: should probably account for rx_highest for both HT/VHT */ |
Eyal Shapira | 2c59d80 | 2015-01-16 11:01:51 +0200 | [diff] [blame] | 3145 | if (!vht_cap || !vht_cap->vht_supported) |
| 3146 | rs_ht_init(mvm, sta, lq_sta, ht_cap); |
| 3147 | else |
| 3148 | rs_vht_init(mvm, sta, lq_sta, vht_cap); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3149 | |
Eyal Shapira | 6a028d9 | 2014-12-07 18:18:27 +0200 | [diff] [blame] | 3150 | lq_sta->max_legacy_rate_idx = |
| 3151 | rs_get_max_rate_from_mask(lq_sta->active_legacy_rate); |
| 3152 | lq_sta->max_siso_rate_idx = |
| 3153 | rs_get_max_rate_from_mask(lq_sta->active_siso_rate); |
| 3154 | lq_sta->max_mimo2_rate_idx = |
| 3155 | rs_get_max_rate_from_mask(lq_sta->active_mimo2_rate); |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 3156 | |
Eyal Shapira | a3576ff | 2014-08-09 10:57:59 +0300 | [diff] [blame] | 3157 | IWL_DEBUG_RATE(mvm, |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3158 | "LEGACY=%lX SISO=%lX MIMO2=%lX VHT=%d LDPC=%d STBC=%d BFER=%d\n", |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 3159 | lq_sta->active_legacy_rate, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3160 | lq_sta->active_siso_rate, |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 3161 | lq_sta->active_mimo2_rate, |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3162 | lq_sta->is_vht, lq_sta->ldpc, lq_sta->stbc_capable, |
| 3163 | lq_sta->bfer_capable); |
Eyal Shapira | 198266a | 2014-03-31 22:37:39 +0300 | [diff] [blame] | 3164 | IWL_DEBUG_RATE(mvm, "MAX RATE: LEGACY=%d SISO=%d MIMO2=%d\n", |
| 3165 | lq_sta->max_legacy_rate_idx, |
| 3166 | lq_sta->max_siso_rate_idx, |
| 3167 | lq_sta->max_mimo2_rate_idx); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3168 | |
| 3169 | /* These values will be overridden later */ |
| 3170 | lq_sta->lq.single_stream_ant_msk = |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 3171 | first_antenna(iwl_mvm_get_valid_tx_ant(mvm)); |
Eyal Shapira | 809bccf | 2013-11-28 02:25:24 +0200 | [diff] [blame] | 3172 | lq_sta->lq.dual_stream_ant_msk = ANT_AB; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3173 | |
| 3174 | /* as default allow aggregation for all tids */ |
| 3175 | lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3176 | lq_sta->is_agg = 0; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3177 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 3178 | iwl_mvm_reset_frame_stats(mvm); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3179 | #endif |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 3180 | rs_initialize_lq(mvm, sta, lq_sta, band, init); |
| 3181 | } |
| 3182 | |
| 3183 | static void rs_rate_update(void *mvm_r, |
| 3184 | struct ieee80211_supported_band *sband, |
| 3185 | struct cfg80211_chan_def *chandef, |
| 3186 | struct ieee80211_sta *sta, void *priv_sta, |
| 3187 | u32 changed) |
| 3188 | { |
| 3189 | u8 tid; |
| 3190 | struct iwl_op_mode *op_mode = |
| 3191 | (struct iwl_op_mode *)mvm_r; |
| 3192 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); |
| 3193 | |
Johannes Berg | dcbc17a | 2015-03-10 21:24:34 +0100 | [diff] [blame] | 3194 | if (!iwl_mvm_sta_from_mac80211(sta)->vif) |
| 3195 | return; |
| 3196 | |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 3197 | /* Stop any ongoing aggregations as rs starts off assuming no agg */ |
| 3198 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) |
| 3199 | ieee80211_stop_tx_ba_session(sta, tid); |
| 3200 | |
| 3201 | iwl_mvm_rs_rate_init(mvm, sta, sband->band, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3202 | } |
| 3203 | |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3204 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 3205 | static void rs_build_rates_table_from_fixed(struct iwl_mvm *mvm, |
| 3206 | struct iwl_lq_cmd *lq_cmd, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3207 | enum nl80211_band band, |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3208 | u32 ucode_rate) |
| 3209 | { |
| 3210 | struct rs_rate rate; |
| 3211 | int i; |
| 3212 | int num_rates = ARRAY_SIZE(lq_cmd->rs_table); |
| 3213 | __le32 ucode_rate_le32 = cpu_to_le32(ucode_rate); |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3214 | u8 ant = (ucode_rate & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS; |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3215 | |
| 3216 | for (i = 0; i < num_rates; i++) |
| 3217 | lq_cmd->rs_table[i] = ucode_rate_le32; |
| 3218 | |
| 3219 | rs_rate_from_ucode_rate(ucode_rate, band, &rate); |
| 3220 | |
| 3221 | if (is_mimo(&rate)) |
| 3222 | lq_cmd->mimo_delim = num_rates - 1; |
| 3223 | else |
| 3224 | lq_cmd->mimo_delim = 0; |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3225 | |
| 3226 | lq_cmd->reduced_tpc = 0; |
| 3227 | |
| 3228 | if (num_of_ant(ant) == 1) |
| 3229 | lq_cmd->single_stream_ant_msk = ant; |
| 3230 | |
| 3231 | lq_cmd->agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3232 | } |
| 3233 | #endif /* CONFIG_MAC80211_DEBUGFS */ |
| 3234 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3235 | static void rs_fill_rates_for_column(struct iwl_mvm *mvm, |
| 3236 | struct iwl_lq_sta *lq_sta, |
| 3237 | struct rs_rate *rate, |
| 3238 | __le32 *rs_table, int *rs_table_index, |
| 3239 | int num_rates, int num_retries, |
| 3240 | u8 valid_tx_ant, bool toggle_ant) |
| 3241 | { |
| 3242 | int i, j; |
| 3243 | __le32 ucode_rate; |
| 3244 | bool bottom_reached = false; |
| 3245 | int prev_rate_idx = rate->index; |
| 3246 | int end = LINK_QUAL_MAX_RETRY_NUM; |
| 3247 | int index = *rs_table_index; |
| 3248 | |
| 3249 | for (i = 0; i < num_rates && index < end; i++) { |
Eyal Shapira | bd99931 | 2014-12-28 22:12:38 +0200 | [diff] [blame] | 3250 | for (j = 0; j < num_retries && index < end; j++, index++) { |
| 3251 | ucode_rate = cpu_to_le32(ucode_rate_from_rs_rate(mvm, |
| 3252 | rate)); |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3253 | rs_table[index] = ucode_rate; |
Eyal Shapira | bd99931 | 2014-12-28 22:12:38 +0200 | [diff] [blame] | 3254 | if (toggle_ant) |
| 3255 | rs_toggle_antenna(valid_tx_ant, rate); |
| 3256 | } |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3257 | |
| 3258 | prev_rate_idx = rate->index; |
| 3259 | bottom_reached = rs_get_lower_rate_in_column(lq_sta, rate); |
| 3260 | if (bottom_reached && !is_legacy(rate)) |
| 3261 | break; |
| 3262 | } |
| 3263 | |
Eyal Shapira | bd99931 | 2014-12-28 22:12:38 +0200 | [diff] [blame] | 3264 | if (!bottom_reached && !is_legacy(rate)) |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3265 | rate->index = prev_rate_idx; |
| 3266 | |
| 3267 | *rs_table_index = index; |
| 3268 | } |
| 3269 | |
| 3270 | /* Building the rate table is non trivial. When we're in MIMO2/VHT/80Mhz/SGI |
| 3271 | * column the rate table should look like this: |
| 3272 | * |
| 3273 | * rate[0] 0x400D019 VHT | ANT: AB BW: 80Mhz MCS: 9 NSS: 2 SGI |
| 3274 | * rate[1] 0x400D019 VHT | ANT: AB BW: 80Mhz MCS: 9 NSS: 2 SGI |
| 3275 | * rate[2] 0x400D018 VHT | ANT: AB BW: 80Mhz MCS: 8 NSS: 2 SGI |
| 3276 | * rate[3] 0x400D018 VHT | ANT: AB BW: 80Mhz MCS: 8 NSS: 2 SGI |
| 3277 | * rate[4] 0x400D017 VHT | ANT: AB BW: 80Mhz MCS: 7 NSS: 2 SGI |
| 3278 | * rate[5] 0x400D017 VHT | ANT: AB BW: 80Mhz MCS: 7 NSS: 2 SGI |
| 3279 | * rate[6] 0x4005007 VHT | ANT: A BW: 80Mhz MCS: 7 NSS: 1 NGI |
| 3280 | * rate[7] 0x4009006 VHT | ANT: B BW: 80Mhz MCS: 6 NSS: 1 NGI |
| 3281 | * rate[8] 0x4005005 VHT | ANT: A BW: 80Mhz MCS: 5 NSS: 1 NGI |
| 3282 | * rate[9] 0x800B Legacy | ANT: B Rate: 36 Mbps |
| 3283 | * rate[10] 0x4009 Legacy | ANT: A Rate: 24 Mbps |
| 3284 | * rate[11] 0x8007 Legacy | ANT: B Rate: 18 Mbps |
| 3285 | * rate[12] 0x4005 Legacy | ANT: A Rate: 12 Mbps |
| 3286 | * rate[13] 0x800F Legacy | ANT: B Rate: 9 Mbps |
| 3287 | * rate[14] 0x400D Legacy | ANT: A Rate: 6 Mbps |
| 3288 | * rate[15] 0x800D Legacy | ANT: B Rate: 6 Mbps |
| 3289 | */ |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3290 | static void rs_build_rates_table(struct iwl_mvm *mvm, |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 3291 | struct ieee80211_sta *sta, |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3292 | struct iwl_lq_sta *lq_sta, |
| 3293 | const struct rs_rate *initial_rate) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3294 | { |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 3295 | struct rs_rate rate; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3296 | int num_rates, num_retries, index = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3297 | u8 valid_tx_ant = 0; |
| 3298 | struct iwl_lq_cmd *lq_cmd = &lq_sta->lq; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3299 | bool toggle_ant = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3300 | |
Emmanuel Grumbach | 9e898f1 | 2013-12-22 10:55:47 +0200 | [diff] [blame] | 3301 | memcpy(&rate, initial_rate, sizeof(rate)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3302 | |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 3303 | valid_tx_ant = iwl_mvm_get_valid_tx_ant(mvm); |
Eyal Shapira | c5d679a | 2015-01-15 20:22:34 +0200 | [diff] [blame] | 3304 | |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3305 | /* TODO: remove old API when min FW API hits 14 */ |
Johannes Berg | 859d914 | 2015-06-01 17:11:11 +0200 | [diff] [blame] | 3306 | if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_LQ_SS_PARAMS) && |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3307 | rs_stbc_allow(mvm, sta, lq_sta)) |
| 3308 | rate.stbc = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3309 | |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3310 | if (is_siso(&rate)) { |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 3311 | num_rates = IWL_MVM_RS_INITIAL_SISO_NUM_RATES; |
| 3312 | num_retries = IWL_MVM_RS_HT_VHT_RETRIES_PER_RATE; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3313 | } else if (is_mimo(&rate)) { |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 3314 | num_rates = IWL_MVM_RS_INITIAL_MIMO_NUM_RATES; |
| 3315 | num_retries = IWL_MVM_RS_HT_VHT_RETRIES_PER_RATE; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3316 | } else { |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 3317 | num_rates = IWL_MVM_RS_INITIAL_LEGACY_NUM_RATES; |
Eyal Shapira | bd99931 | 2014-12-28 22:12:38 +0200 | [diff] [blame] | 3318 | num_retries = IWL_MVM_RS_INITIAL_LEGACY_RETRIES; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3319 | toggle_ant = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3320 | } |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3321 | |
| 3322 | rs_fill_rates_for_column(mvm, lq_sta, &rate, lq_cmd->rs_table, &index, |
| 3323 | num_rates, num_retries, valid_tx_ant, |
| 3324 | toggle_ant); |
| 3325 | |
| 3326 | rs_get_lower_rate_down_column(lq_sta, &rate); |
| 3327 | |
| 3328 | if (is_siso(&rate)) { |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 3329 | num_rates = IWL_MVM_RS_SECONDARY_SISO_NUM_RATES; |
| 3330 | num_retries = IWL_MVM_RS_SECONDARY_SISO_RETRIES; |
Eyal Shapira | d9088f6 | 2014-03-25 10:25:44 +0200 | [diff] [blame] | 3331 | lq_cmd->mimo_delim = index; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3332 | } else if (is_legacy(&rate)) { |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 3333 | num_rates = IWL_MVM_RS_SECONDARY_LEGACY_NUM_RATES; |
Eyal Shapira | bd99931 | 2014-12-28 22:12:38 +0200 | [diff] [blame] | 3334 | num_retries = IWL_MVM_RS_SECONDARY_LEGACY_RETRIES; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3335 | } else { |
| 3336 | WARN_ON_ONCE(1); |
| 3337 | } |
| 3338 | |
| 3339 | toggle_ant = true; |
| 3340 | |
| 3341 | rs_fill_rates_for_column(mvm, lq_sta, &rate, lq_cmd->rs_table, &index, |
| 3342 | num_rates, num_retries, valid_tx_ant, |
| 3343 | toggle_ant); |
| 3344 | |
| 3345 | rs_get_lower_rate_down_column(lq_sta, &rate); |
| 3346 | |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 3347 | num_rates = IWL_MVM_RS_SECONDARY_LEGACY_NUM_RATES; |
Eyal Shapira | bd99931 | 2014-12-28 22:12:38 +0200 | [diff] [blame] | 3348 | num_retries = IWL_MVM_RS_SECONDARY_LEGACY_RETRIES; |
Eyal Shapira | e07be6d | 2013-12-09 13:02:56 +0200 | [diff] [blame] | 3349 | |
| 3350 | rs_fill_rates_for_column(mvm, lq_sta, &rate, lq_cmd->rs_table, &index, |
| 3351 | num_rates, num_retries, valid_tx_ant, |
| 3352 | toggle_ant); |
| 3353 | |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3354 | } |
| 3355 | |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3356 | struct rs_bfer_active_iter_data { |
| 3357 | struct ieee80211_sta *exclude_sta; |
| 3358 | struct iwl_mvm_sta *bfer_mvmsta; |
| 3359 | }; |
| 3360 | |
| 3361 | static void rs_bfer_active_iter(void *_data, |
| 3362 | struct ieee80211_sta *sta) |
| 3363 | { |
| 3364 | struct rs_bfer_active_iter_data *data = _data; |
| 3365 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 3366 | struct iwl_lq_cmd *lq_cmd = &mvmsta->lq_sta.lq; |
| 3367 | u32 ss_params = le32_to_cpu(lq_cmd->ss_params); |
| 3368 | |
| 3369 | if (sta == data->exclude_sta) |
| 3370 | return; |
| 3371 | |
| 3372 | /* The current sta has BFER allowed */ |
| 3373 | if (ss_params & LQ_SS_BFER_ALLOWED) { |
| 3374 | WARN_ON_ONCE(data->bfer_mvmsta != NULL); |
| 3375 | |
| 3376 | data->bfer_mvmsta = mvmsta; |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | static int rs_bfer_priority(struct iwl_mvm_sta *sta) |
| 3381 | { |
| 3382 | int prio = -1; |
| 3383 | enum nl80211_iftype viftype = ieee80211_vif_type_p2p(sta->vif); |
| 3384 | |
| 3385 | switch (viftype) { |
| 3386 | case NL80211_IFTYPE_AP: |
| 3387 | case NL80211_IFTYPE_P2P_GO: |
| 3388 | prio = 3; |
| 3389 | break; |
| 3390 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3391 | prio = 2; |
| 3392 | break; |
| 3393 | case NL80211_IFTYPE_STATION: |
| 3394 | prio = 1; |
| 3395 | break; |
| 3396 | default: |
| 3397 | WARN_ONCE(true, "viftype %d sta_id %d", viftype, sta->sta_id); |
| 3398 | prio = -1; |
| 3399 | } |
| 3400 | |
| 3401 | return prio; |
| 3402 | } |
| 3403 | |
| 3404 | /* Returns >0 if sta1 has a higher BFER priority compared to sta2 */ |
| 3405 | static int rs_bfer_priority_cmp(struct iwl_mvm_sta *sta1, |
| 3406 | struct iwl_mvm_sta *sta2) |
| 3407 | { |
| 3408 | int prio1 = rs_bfer_priority(sta1); |
| 3409 | int prio2 = rs_bfer_priority(sta2); |
| 3410 | |
| 3411 | if (prio1 > prio2) |
| 3412 | return 1; |
| 3413 | if (prio1 < prio2) |
| 3414 | return -1; |
| 3415 | return 0; |
| 3416 | } |
| 3417 | |
| 3418 | static void rs_set_lq_ss_params(struct iwl_mvm *mvm, |
| 3419 | struct ieee80211_sta *sta, |
| 3420 | struct iwl_lq_sta *lq_sta, |
| 3421 | const struct rs_rate *initial_rate) |
| 3422 | { |
| 3423 | struct iwl_lq_cmd *lq_cmd = &lq_sta->lq; |
| 3424 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 3425 | struct rs_bfer_active_iter_data data = { |
| 3426 | .exclude_sta = sta, |
| 3427 | .bfer_mvmsta = NULL, |
| 3428 | }; |
| 3429 | struct iwl_mvm_sta *bfer_mvmsta = NULL; |
| 3430 | u32 ss_params = LQ_SS_PARAMS_VALID; |
| 3431 | |
| 3432 | if (!iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta)) |
| 3433 | goto out; |
| 3434 | |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3435 | #ifdef CONFIG_MAC80211_DEBUGFS |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3436 | /* Check if forcing the decision is configured. |
| 3437 | * Note that SISO is forced by not allowing STBC or BFER |
| 3438 | */ |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3439 | if (lq_sta->pers.ss_force == RS_SS_FORCE_STBC) |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3440 | ss_params |= (LQ_SS_STBC_1SS_ALLOWED | LQ_SS_FORCE); |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3441 | else if (lq_sta->pers.ss_force == RS_SS_FORCE_BFER) |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3442 | ss_params |= (LQ_SS_BFER_ALLOWED | LQ_SS_FORCE); |
| 3443 | |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3444 | if (lq_sta->pers.ss_force != RS_SS_FORCE_NONE) { |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3445 | IWL_DEBUG_RATE(mvm, "Forcing single stream Tx decision %d\n", |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3446 | lq_sta->pers.ss_force); |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3447 | goto out; |
| 3448 | } |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3449 | #endif |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3450 | |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3451 | if (lq_sta->stbc_capable) |
| 3452 | ss_params |= LQ_SS_STBC_1SS_ALLOWED; |
| 3453 | |
| 3454 | if (!lq_sta->bfer_capable) |
| 3455 | goto out; |
| 3456 | |
| 3457 | ieee80211_iterate_stations_atomic(mvm->hw, |
| 3458 | rs_bfer_active_iter, |
| 3459 | &data); |
| 3460 | bfer_mvmsta = data.bfer_mvmsta; |
| 3461 | |
| 3462 | /* This code is safe as it doesn't run concurrently for different |
| 3463 | * stations. This is guaranteed by the fact that calls to |
| 3464 | * ieee80211_tx_status wouldn't run concurrently for a single HW. |
| 3465 | */ |
| 3466 | if (!bfer_mvmsta) { |
| 3467 | IWL_DEBUG_RATE(mvm, "No sta with BFER allowed found. Allow\n"); |
| 3468 | |
| 3469 | ss_params |= LQ_SS_BFER_ALLOWED; |
| 3470 | goto out; |
| 3471 | } |
| 3472 | |
| 3473 | IWL_DEBUG_RATE(mvm, "Found existing sta %d with BFER activated\n", |
| 3474 | bfer_mvmsta->sta_id); |
| 3475 | |
| 3476 | /* Disallow BFER on another STA if active and we're a higher priority */ |
| 3477 | if (rs_bfer_priority_cmp(mvmsta, bfer_mvmsta) > 0) { |
| 3478 | struct iwl_lq_cmd *bfersta_lq_cmd = &bfer_mvmsta->lq_sta.lq; |
| 3479 | u32 bfersta_ss_params = le32_to_cpu(bfersta_lq_cmd->ss_params); |
| 3480 | |
| 3481 | bfersta_ss_params &= ~LQ_SS_BFER_ALLOWED; |
| 3482 | bfersta_lq_cmd->ss_params = cpu_to_le32(bfersta_ss_params); |
| 3483 | iwl_mvm_send_lq_cmd(mvm, bfersta_lq_cmd, false); |
| 3484 | |
| 3485 | ss_params |= LQ_SS_BFER_ALLOWED; |
| 3486 | IWL_DEBUG_RATE(mvm, |
| 3487 | "Lower priority BFER sta found (%d). Switch BFER\n", |
| 3488 | bfer_mvmsta->sta_id); |
| 3489 | } |
| 3490 | out: |
| 3491 | lq_cmd->ss_params = cpu_to_le32(ss_params); |
| 3492 | } |
| 3493 | |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3494 | static void rs_fill_lq_cmd(struct iwl_mvm *mvm, |
| 3495 | struct ieee80211_sta *sta, |
| 3496 | struct iwl_lq_sta *lq_sta, |
| 3497 | const struct rs_rate *initial_rate) |
| 3498 | { |
| 3499 | struct iwl_lq_cmd *lq_cmd = &lq_sta->lq; |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3500 | struct iwl_mvm_sta *mvmsta; |
| 3501 | struct iwl_mvm_vif *mvmvif; |
| 3502 | |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 3503 | lq_cmd->agg_disable_start_th = IWL_MVM_RS_AGG_DISABLE_START; |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3504 | lq_cmd->agg_time_limit = |
Eyal Shapira | 834437d | 2014-12-17 15:38:58 +0200 | [diff] [blame] | 3505 | cpu_to_le16(IWL_MVM_RS_AGG_TIME_LIMIT); |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3506 | |
| 3507 | #ifdef CONFIG_MAC80211_DEBUGFS |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3508 | if (lq_sta->pers.dbg_fixed_rate) { |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3509 | rs_build_rates_table_from_fixed(mvm, lq_cmd, |
| 3510 | lq_sta->band, |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3511 | lq_sta->pers.dbg_fixed_rate); |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3512 | return; |
| 3513 | } |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3514 | #endif |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3515 | if (WARN_ON_ONCE(!sta || !initial_rate)) |
| 3516 | return; |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3517 | |
Eyal Shapira | d8bafea | 2014-10-23 13:58:38 +0300 | [diff] [blame] | 3518 | rs_build_rates_table(mvm, sta, lq_sta, initial_rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3519 | |
Johannes Berg | 859d914 | 2015-06-01 17:11:11 +0200 | [diff] [blame] | 3520 | if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_LQ_SS_PARAMS)) |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 3521 | rs_set_lq_ss_params(mvm, sta, lq_sta, initial_rate); |
| 3522 | |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3523 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 3524 | mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); |
| 3525 | |
| 3526 | if (num_of_ant(initial_rate->ant) == 1) |
| 3527 | lq_cmd->single_stream_ant_msk = initial_rate->ant; |
| 3528 | |
| 3529 | lq_cmd->agg_frame_cnt_limit = mvmsta->max_agg_bufsize; |
| 3530 | |
| 3531 | /* |
Sara Sharon | 0d365ae | 2015-03-31 12:24:05 +0300 | [diff] [blame] | 3532 | * In case of low latency, tell the firmware to leave a frame in the |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3533 | * Tx Fifo so that it can start a transaction in the same TxOP. This |
| 3534 | * basically allows the firmware to send bursts. |
| 3535 | */ |
Eyal Shapira | 1412ee3 | 2015-10-22 13:10:36 +0300 | [diff] [blame] | 3536 | if (iwl_mvm_vif_low_latency(mvmvif)) |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3537 | lq_cmd->agg_frame_cnt_limit--; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3538 | |
Emmanuel Grumbach | a4db848 | 2014-07-31 13:58:53 +0300 | [diff] [blame] | 3539 | if (mvmsta->vif->p2p) |
| 3540 | lq_cmd->flags |= LQ_FLAG_USE_RTS_MSK; |
| 3541 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3542 | lq_cmd->agg_time_limit = |
Emmanuel Grumbach | 5b7ff61 | 2014-03-11 19:27:45 +0200 | [diff] [blame] | 3543 | cpu_to_le16(iwl_mvm_coex_agg_time_limit(mvm, sta)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) |
| 3547 | { |
| 3548 | return hw->priv; |
| 3549 | } |
| 3550 | /* rate scale requires free function to be implemented */ |
| 3551 | static void rs_free(void *mvm_rate) |
| 3552 | { |
| 3553 | return; |
| 3554 | } |
| 3555 | |
| 3556 | static void rs_free_sta(void *mvm_r, struct ieee80211_sta *sta, |
| 3557 | void *mvm_sta) |
| 3558 | { |
| 3559 | struct iwl_op_mode *op_mode __maybe_unused = mvm_r; |
| 3560 | struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode); |
| 3561 | |
| 3562 | IWL_DEBUG_RATE(mvm, "enter\n"); |
| 3563 | IWL_DEBUG_RATE(mvm, "leave\n"); |
| 3564 | } |
| 3565 | |
| 3566 | #ifdef CONFIG_MAC80211_DEBUGFS |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 3567 | int rs_pretty_print_rate(char *buf, const u32 rate) |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 3568 | { |
| 3569 | |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 3570 | char *type, *bw; |
| 3571 | u8 mcs = 0, nss = 0; |
| 3572 | u8 ant = (rate & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS; |
| 3573 | |
| 3574 | if (!(rate & RATE_MCS_HT_MSK) && |
| 3575 | !(rate & RATE_MCS_VHT_MSK)) { |
| 3576 | int index = iwl_hwrate_to_plcp_idx(rate); |
| 3577 | |
| 3578 | return sprintf(buf, "Legacy | ANT: %s Rate: %s Mbps\n", |
Eyal Shapira | 560843f | 2014-01-05 21:04:19 +0200 | [diff] [blame] | 3579 | rs_pretty_ant(ant), |
| 3580 | index == IWL_RATE_INVALID ? "BAD" : |
| 3581 | iwl_rate_mcs[index].mbps); |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | if (rate & RATE_MCS_VHT_MSK) { |
| 3585 | type = "VHT"; |
| 3586 | mcs = rate & RATE_VHT_MCS_RATE_CODE_MSK; |
| 3587 | nss = ((rate & RATE_VHT_MCS_NSS_MSK) |
| 3588 | >> RATE_VHT_MCS_NSS_POS) + 1; |
| 3589 | } else if (rate & RATE_MCS_HT_MSK) { |
| 3590 | type = "HT"; |
| 3591 | mcs = rate & RATE_HT_MCS_INDEX_MSK; |
| 3592 | } else { |
| 3593 | type = "Unknown"; /* shouldn't happen */ |
| 3594 | } |
| 3595 | |
| 3596 | switch (rate & RATE_MCS_CHAN_WIDTH_MSK) { |
| 3597 | case RATE_MCS_CHAN_WIDTH_20: |
| 3598 | bw = "20Mhz"; |
| 3599 | break; |
| 3600 | case RATE_MCS_CHAN_WIDTH_40: |
| 3601 | bw = "40Mhz"; |
| 3602 | break; |
| 3603 | case RATE_MCS_CHAN_WIDTH_80: |
| 3604 | bw = "80Mhz"; |
| 3605 | break; |
| 3606 | case RATE_MCS_CHAN_WIDTH_160: |
| 3607 | bw = "160Mhz"; |
| 3608 | break; |
| 3609 | default: |
| 3610 | bw = "BAD BW"; |
| 3611 | } |
| 3612 | |
| 3613 | 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] | 3614 | type, rs_pretty_ant(ant), bw, mcs, nss, |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 3615 | (rate & RATE_MCS_SGI_MSK) ? "SGI " : "NGI ", |
Emmanuel Grumbach | 7b1dd04 | 2014-02-04 15:32:43 +0200 | [diff] [blame] | 3616 | (rate & RATE_MCS_HT_STBC_MSK) ? "STBC " : "", |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 3617 | (rate & RATE_MCS_LDPC_MSK) ? "LDPC " : "", |
| 3618 | (rate & RATE_MCS_BF_MSK) ? "BF " : "", |
| 3619 | (rate & RATE_MCS_ZLF_MSK) ? "ZLF " : ""); |
| 3620 | } |
| 3621 | |
Eyal Shapira | a0c38b2 | 2013-12-03 18:34:52 +0200 | [diff] [blame] | 3622 | /** |
| 3623 | * Program the device to use fixed rate for frame transmit |
| 3624 | * This is for debugging/testing only |
| 3625 | * once the device start use fixed rate, we need to reload the module |
| 3626 | * to being back the normal operation. |
| 3627 | */ |
| 3628 | static void rs_program_fix_rate(struct iwl_mvm *mvm, |
| 3629 | struct iwl_lq_sta *lq_sta) |
| 3630 | { |
| 3631 | lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */ |
| 3632 | lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ |
| 3633 | lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ |
| 3634 | |
| 3635 | IWL_DEBUG_RATE(mvm, "sta_id %d rate 0x%X\n", |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3636 | lq_sta->lq.sta_id, lq_sta->pers.dbg_fixed_rate); |
Eyal Shapira | a0c38b2 | 2013-12-03 18:34:52 +0200 | [diff] [blame] | 3637 | |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3638 | if (lq_sta->pers.dbg_fixed_rate) { |
Emmanuel Grumbach | 7ceb98a | 2014-07-28 12:59:45 +0300 | [diff] [blame] | 3639 | rs_fill_lq_cmd(mvm, NULL, lq_sta, NULL); |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3640 | 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] | 3641 | } |
| 3642 | } |
| 3643 | |
Emmanuel Grumbach | 9d10849 | 2013-12-03 11:50:30 +0200 | [diff] [blame] | 3644 | static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file, |
| 3645 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 3646 | { |
| 3647 | struct iwl_lq_sta *lq_sta = file->private_data; |
| 3648 | struct iwl_mvm *mvm; |
| 3649 | char buf[64]; |
| 3650 | size_t buf_size; |
| 3651 | u32 parsed_rate; |
| 3652 | |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3653 | mvm = lq_sta->pers.drv; |
Emmanuel Grumbach | 9d10849 | 2013-12-03 11:50:30 +0200 | [diff] [blame] | 3654 | memset(buf, 0, sizeof(buf)); |
| 3655 | buf_size = min(count, sizeof(buf) - 1); |
| 3656 | if (copy_from_user(buf, user_buf, buf_size)) |
| 3657 | return -EFAULT; |
| 3658 | |
| 3659 | if (sscanf(buf, "%x", &parsed_rate) == 1) |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3660 | lq_sta->pers.dbg_fixed_rate = parsed_rate; |
Emmanuel Grumbach | 9d10849 | 2013-12-03 11:50:30 +0200 | [diff] [blame] | 3661 | else |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3662 | lq_sta->pers.dbg_fixed_rate = 0; |
Emmanuel Grumbach | 9d10849 | 2013-12-03 11:50:30 +0200 | [diff] [blame] | 3663 | |
| 3664 | rs_program_fix_rate(mvm, lq_sta); |
| 3665 | |
| 3666 | return count; |
| 3667 | } |
| 3668 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3669 | static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file, |
| 3670 | char __user *user_buf, size_t count, loff_t *ppos) |
| 3671 | { |
| 3672 | char *buff; |
| 3673 | int desc = 0; |
| 3674 | int i = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3675 | ssize_t ret; |
| 3676 | |
| 3677 | struct iwl_lq_sta *lq_sta = file->private_data; |
Emmanuel Grumbach | 04e3a5d | 2015-10-28 09:47:41 +0200 | [diff] [blame] | 3678 | struct iwl_mvm_sta *mvmsta = |
| 3679 | container_of(lq_sta, struct iwl_mvm_sta, lq_sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3680 | struct iwl_mvm *mvm; |
| 3681 | 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] | 3682 | struct rs_rate *rate = &tbl->rate; |
Eyal Shapira | 16c426f | 2015-02-02 12:46:22 +0200 | [diff] [blame] | 3683 | u32 ss_params; |
Emmanuel Grumbach | 04e3a5d | 2015-10-28 09:47:41 +0200 | [diff] [blame] | 3684 | |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3685 | mvm = lq_sta->pers.drv; |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 3686 | buff = kmalloc(2048, GFP_KERNEL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3687 | if (!buff) |
| 3688 | return -ENOMEM; |
| 3689 | |
| 3690 | 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] | 3691 | desc += sprintf(buff+desc, "failed=%d success=%d rate=0%lX\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3692 | lq_sta->total_failed, lq_sta->total_success, |
| 3693 | lq_sta->active_legacy_rate); |
| 3694 | desc += sprintf(buff+desc, "fixed rate 0x%X\n", |
Eliad Peller | ae969af | 2014-06-11 15:51:33 +0300 | [diff] [blame] | 3695 | lq_sta->pers.dbg_fixed_rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3696 | desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n", |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 3697 | (iwl_mvm_get_valid_tx_ant(mvm) & ANT_A) ? "ANT_A," : "", |
| 3698 | (iwl_mvm_get_valid_tx_ant(mvm) & ANT_B) ? "ANT_B," : "", |
| 3699 | (iwl_mvm_get_valid_tx_ant(mvm) & ANT_C) ? "ANT_C" : ""); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3700 | desc += sprintf(buff+desc, "lq type %s\n", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 3701 | (is_legacy(rate)) ? "legacy" : |
| 3702 | is_vht(rate) ? "VHT" : "HT"); |
| 3703 | if (!is_legacy(rate)) { |
Emmanuel Grumbach | e70fe7e | 2015-03-01 17:18:00 +0200 | [diff] [blame] | 3704 | desc += sprintf(buff + desc, " %s", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 3705 | (is_siso(rate)) ? "SISO" : "MIMO2"); |
Emmanuel Grumbach | e70fe7e | 2015-03-01 17:18:00 +0200 | [diff] [blame] | 3706 | desc += sprintf(buff + desc, " %s", |
| 3707 | (is_ht20(rate)) ? "20MHz" : |
| 3708 | (is_ht40(rate)) ? "40MHz" : |
| 3709 | (is_ht80(rate)) ? "80Mhz" : "BAD BW"); |
Emmanuel Grumbach | 04e3a5d | 2015-10-28 09:47:41 +0200 | [diff] [blame] | 3710 | desc += sprintf(buff + desc, " %s %s %s %s\n", |
Emmanuel Grumbach | e70fe7e | 2015-03-01 17:18:00 +0200 | [diff] [blame] | 3711 | (rate->sgi) ? "SGI" : "NGI", |
| 3712 | (rate->ldpc) ? "LDPC" : "BCC", |
Emmanuel Grumbach | 04e3a5d | 2015-10-28 09:47:41 +0200 | [diff] [blame] | 3713 | (lq_sta->is_agg) ? "AGG on" : "", |
| 3714 | (mvmsta->tlc_amsdu) ? "AMSDU on" : ""); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3715 | } |
| 3716 | desc += sprintf(buff+desc, "last tx rate=0x%X\n", |
| 3717 | lq_sta->last_rate_n_flags); |
| 3718 | desc += sprintf(buff+desc, |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 3719 | "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] | 3720 | lq_sta->lq.flags, |
| 3721 | lq_sta->lq.mimo_delim, |
| 3722 | lq_sta->lq.single_stream_ant_msk, |
| 3723 | lq_sta->lq.dual_stream_ant_msk); |
| 3724 | |
| 3725 | desc += sprintf(buff+desc, |
| 3726 | "agg: time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n", |
| 3727 | le16_to_cpu(lq_sta->lq.agg_time_limit), |
| 3728 | lq_sta->lq.agg_disable_start_th, |
| 3729 | lq_sta->lq.agg_frame_cnt_limit); |
| 3730 | |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 3731 | desc += sprintf(buff+desc, "reduced tpc=%d\n", lq_sta->lq.reduced_tpc); |
Eyal Shapira | 16c426f | 2015-02-02 12:46:22 +0200 | [diff] [blame] | 3732 | ss_params = le32_to_cpu(lq_sta->lq.ss_params); |
| 3733 | desc += sprintf(buff+desc, "single stream params: %s%s%s%s\n", |
| 3734 | (ss_params & LQ_SS_PARAMS_VALID) ? |
Eyal Shapira | db7c689 | 2015-03-02 10:35:19 +0200 | [diff] [blame] | 3735 | "VALID" : "INVALID", |
Eyal Shapira | 16c426f | 2015-02-02 12:46:22 +0200 | [diff] [blame] | 3736 | (ss_params & LQ_SS_BFER_ALLOWED) ? |
Eyal Shapira | db7c689 | 2015-03-02 10:35:19 +0200 | [diff] [blame] | 3737 | ", BFER" : "", |
Eyal Shapira | 16c426f | 2015-02-02 12:46:22 +0200 | [diff] [blame] | 3738 | (ss_params & LQ_SS_STBC_1SS_ALLOWED) ? |
Eyal Shapira | db7c689 | 2015-03-02 10:35:19 +0200 | [diff] [blame] | 3739 | ", STBC" : "", |
Eyal Shapira | 16c426f | 2015-02-02 12:46:22 +0200 | [diff] [blame] | 3740 | (ss_params & LQ_SS_FORCE) ? |
Eyal Shapira | db7c689 | 2015-03-02 10:35:19 +0200 | [diff] [blame] | 3741 | ", FORCE" : ""); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3742 | desc += sprintf(buff+desc, |
| 3743 | "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n", |
| 3744 | lq_sta->lq.initial_rate_index[0], |
| 3745 | lq_sta->lq.initial_rate_index[1], |
| 3746 | lq_sta->lq.initial_rate_index[2], |
| 3747 | lq_sta->lq.initial_rate_index[3]); |
| 3748 | |
| 3749 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
Johannes Berg | cf4ef65 | 2013-12-17 11:34:25 +0100 | [diff] [blame] | 3750 | u32 r = le32_to_cpu(lq_sta->lq.rs_table[i]); |
Eyal Shapira | 1a61b34 | 2013-11-09 02:11:46 +0200 | [diff] [blame] | 3751 | |
Johannes Berg | cf4ef65 | 2013-12-17 11:34:25 +0100 | [diff] [blame] | 3752 | desc += sprintf(buff+desc, " rate[%d] 0x%X ", i, r); |
| 3753 | desc += rs_pretty_print_rate(buff+desc, r); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 3757 | kfree(buff); |
| 3758 | return ret; |
| 3759 | } |
| 3760 | |
| 3761 | static const struct file_operations rs_sta_dbgfs_scale_table_ops = { |
| 3762 | .write = rs_sta_dbgfs_scale_table_write, |
| 3763 | .read = rs_sta_dbgfs_scale_table_read, |
| 3764 | .open = simple_open, |
| 3765 | .llseek = default_llseek, |
| 3766 | }; |
| 3767 | static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file, |
| 3768 | char __user *user_buf, size_t count, loff_t *ppos) |
| 3769 | { |
| 3770 | char *buff; |
| 3771 | int desc = 0; |
| 3772 | int i, j; |
| 3773 | ssize_t ret; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 3774 | struct iwl_scale_tbl_info *tbl; |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 3775 | struct rs_rate *rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3776 | struct iwl_lq_sta *lq_sta = file->private_data; |
| 3777 | |
| 3778 | buff = kmalloc(1024, GFP_KERNEL); |
| 3779 | if (!buff) |
| 3780 | return -ENOMEM; |
| 3781 | |
| 3782 | for (i = 0; i < LQ_SIZE; i++) { |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 3783 | tbl = &(lq_sta->lq_info[i]); |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 3784 | rate = &tbl->rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3785 | desc += sprintf(buff+desc, |
Eyal Shapira | 6a524f4 | 2013-08-11 20:27:18 +0300 | [diff] [blame] | 3786 | "%s type=%d SGI=%d BW=%s DUP=0\n" |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3787 | "index=%d\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3788 | lq_sta->active_tbl == i ? "*" : "x", |
Eyal Shapira | 5aa3355 | 2013-11-23 01:06:36 +0200 | [diff] [blame] | 3789 | rate->type, |
| 3790 | rate->sgi, |
| 3791 | is_ht20(rate) ? "20Mhz" : |
| 3792 | is_ht40(rate) ? "40Mhz" : |
| 3793 | is_ht80(rate) ? "80Mhz" : "ERR", |
Eyal Shapira | 8fc7c58 | 2013-12-04 02:15:46 +0200 | [diff] [blame] | 3794 | rate->index); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3795 | for (j = 0; j < IWL_RATE_COUNT; j++) { |
| 3796 | desc += sprintf(buff+desc, |
| 3797 | "counter=%d success=%d %%=%d\n", |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 3798 | tbl->win[j].counter, |
| 3799 | tbl->win[j].success_counter, |
| 3800 | tbl->win[j].success_ratio); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3801 | } |
| 3802 | } |
| 3803 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); |
| 3804 | kfree(buff); |
| 3805 | return ret; |
| 3806 | } |
| 3807 | |
| 3808 | static const struct file_operations rs_sta_dbgfs_stats_table_ops = { |
| 3809 | .read = rs_sta_dbgfs_stats_table_read, |
| 3810 | .open = simple_open, |
| 3811 | .llseek = default_llseek, |
| 3812 | }; |
| 3813 | |
Eyal Shapira | 757cf23b | 2014-03-24 02:12:00 +0200 | [diff] [blame] | 3814 | static ssize_t rs_sta_dbgfs_drv_tx_stats_read(struct file *file, |
| 3815 | char __user *user_buf, |
| 3816 | size_t count, loff_t *ppos) |
| 3817 | { |
| 3818 | static const char * const column_name[] = { |
| 3819 | [RS_COLUMN_LEGACY_ANT_A] = "LEGACY_ANT_A", |
| 3820 | [RS_COLUMN_LEGACY_ANT_B] = "LEGACY_ANT_B", |
| 3821 | [RS_COLUMN_SISO_ANT_A] = "SISO_ANT_A", |
| 3822 | [RS_COLUMN_SISO_ANT_B] = "SISO_ANT_B", |
| 3823 | [RS_COLUMN_SISO_ANT_A_SGI] = "SISO_ANT_A_SGI", |
| 3824 | [RS_COLUMN_SISO_ANT_B_SGI] = "SISO_ANT_B_SGI", |
| 3825 | [RS_COLUMN_MIMO2] = "MIMO2", |
| 3826 | [RS_COLUMN_MIMO2_SGI] = "MIMO2_SGI", |
| 3827 | }; |
| 3828 | |
| 3829 | static const char * const rate_name[] = { |
| 3830 | [IWL_RATE_1M_INDEX] = "1M", |
| 3831 | [IWL_RATE_2M_INDEX] = "2M", |
| 3832 | [IWL_RATE_5M_INDEX] = "5.5M", |
| 3833 | [IWL_RATE_11M_INDEX] = "11M", |
| 3834 | [IWL_RATE_6M_INDEX] = "6M|MCS0", |
| 3835 | [IWL_RATE_9M_INDEX] = "9M", |
| 3836 | [IWL_RATE_12M_INDEX] = "12M|MCS1", |
| 3837 | [IWL_RATE_18M_INDEX] = "18M|MCS2", |
| 3838 | [IWL_RATE_24M_INDEX] = "24M|MCS3", |
| 3839 | [IWL_RATE_36M_INDEX] = "36M|MCS4", |
| 3840 | [IWL_RATE_48M_INDEX] = "48M|MCS5", |
| 3841 | [IWL_RATE_54M_INDEX] = "54M|MCS6", |
| 3842 | [IWL_RATE_MCS_7_INDEX] = "MCS7", |
| 3843 | [IWL_RATE_MCS_8_INDEX] = "MCS8", |
| 3844 | [IWL_RATE_MCS_9_INDEX] = "MCS9", |
| 3845 | }; |
| 3846 | |
| 3847 | char *buff, *pos, *endpos; |
| 3848 | int col, rate; |
| 3849 | ssize_t ret; |
| 3850 | struct iwl_lq_sta *lq_sta = file->private_data; |
| 3851 | struct rs_rate_stats *stats; |
| 3852 | static const size_t bufsz = 1024; |
| 3853 | |
| 3854 | buff = kmalloc(bufsz, GFP_KERNEL); |
| 3855 | if (!buff) |
| 3856 | return -ENOMEM; |
| 3857 | |
| 3858 | pos = buff; |
| 3859 | endpos = pos + bufsz; |
| 3860 | |
| 3861 | pos += scnprintf(pos, endpos - pos, "COLUMN,"); |
| 3862 | for (rate = 0; rate < IWL_RATE_COUNT; rate++) |
| 3863 | pos += scnprintf(pos, endpos - pos, "%s,", rate_name[rate]); |
| 3864 | pos += scnprintf(pos, endpos - pos, "\n"); |
| 3865 | |
| 3866 | for (col = 0; col < RS_COLUMN_COUNT; col++) { |
| 3867 | pos += scnprintf(pos, endpos - pos, |
| 3868 | "%s,", column_name[col]); |
| 3869 | |
| 3870 | for (rate = 0; rate < IWL_RATE_COUNT; rate++) { |
Eyal Shapira | f58220f | 2014-08-16 01:30:30 +0300 | [diff] [blame] | 3871 | stats = &(lq_sta->pers.tx_stats[col][rate]); |
Eyal Shapira | 757cf23b | 2014-03-24 02:12:00 +0200 | [diff] [blame] | 3872 | pos += scnprintf(pos, endpos - pos, |
| 3873 | "%llu/%llu,", |
| 3874 | stats->success, |
| 3875 | stats->total); |
| 3876 | } |
| 3877 | pos += scnprintf(pos, endpos - pos, "\n"); |
| 3878 | } |
| 3879 | |
| 3880 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff); |
| 3881 | kfree(buff); |
| 3882 | return ret; |
| 3883 | } |
| 3884 | |
| 3885 | static ssize_t rs_sta_dbgfs_drv_tx_stats_write(struct file *file, |
| 3886 | const char __user *user_buf, |
| 3887 | size_t count, loff_t *ppos) |
| 3888 | { |
| 3889 | struct iwl_lq_sta *lq_sta = file->private_data; |
Eyal Shapira | f58220f | 2014-08-16 01:30:30 +0300 | [diff] [blame] | 3890 | memset(lq_sta->pers.tx_stats, 0, sizeof(lq_sta->pers.tx_stats)); |
Eyal Shapira | 757cf23b | 2014-03-24 02:12:00 +0200 | [diff] [blame] | 3891 | |
| 3892 | return count; |
| 3893 | } |
| 3894 | |
| 3895 | static const struct file_operations rs_sta_dbgfs_drv_tx_stats_ops = { |
| 3896 | .read = rs_sta_dbgfs_drv_tx_stats_read, |
| 3897 | .write = rs_sta_dbgfs_drv_tx_stats_write, |
| 3898 | .open = simple_open, |
| 3899 | .llseek = default_llseek, |
| 3900 | }; |
| 3901 | |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3902 | static ssize_t iwl_dbgfs_ss_force_read(struct file *file, |
| 3903 | char __user *user_buf, |
| 3904 | size_t count, loff_t *ppos) |
| 3905 | { |
| 3906 | struct iwl_lq_sta *lq_sta = file->private_data; |
| 3907 | char buf[12]; |
| 3908 | int bufsz = sizeof(buf); |
| 3909 | int pos = 0; |
| 3910 | static const char * const ss_force_name[] = { |
| 3911 | [RS_SS_FORCE_NONE] = "none", |
| 3912 | [RS_SS_FORCE_STBC] = "stbc", |
| 3913 | [RS_SS_FORCE_BFER] = "bfer", |
| 3914 | [RS_SS_FORCE_SISO] = "siso", |
| 3915 | }; |
| 3916 | |
| 3917 | pos += scnprintf(buf+pos, bufsz-pos, "%s\n", |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3918 | ss_force_name[lq_sta->pers.ss_force]); |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3919 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 3920 | } |
| 3921 | |
| 3922 | static ssize_t iwl_dbgfs_ss_force_write(struct iwl_lq_sta *lq_sta, char *buf, |
| 3923 | size_t count, loff_t *ppos) |
| 3924 | { |
| 3925 | struct iwl_mvm *mvm = lq_sta->pers.drv; |
| 3926 | int ret = 0; |
| 3927 | |
| 3928 | if (!strncmp("none", buf, 4)) { |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3929 | lq_sta->pers.ss_force = RS_SS_FORCE_NONE; |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3930 | } else if (!strncmp("siso", buf, 4)) { |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3931 | lq_sta->pers.ss_force = RS_SS_FORCE_SISO; |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3932 | } else if (!strncmp("stbc", buf, 4)) { |
| 3933 | if (lq_sta->stbc_capable) { |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3934 | lq_sta->pers.ss_force = RS_SS_FORCE_STBC; |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3935 | } else { |
| 3936 | IWL_ERR(mvm, |
| 3937 | "can't force STBC. peer doesn't support\n"); |
| 3938 | ret = -EINVAL; |
| 3939 | } |
| 3940 | } else if (!strncmp("bfer", buf, 4)) { |
| 3941 | if (lq_sta->bfer_capable) { |
Eyal Shapira | 878985ce | 2015-02-02 12:14:54 +0200 | [diff] [blame] | 3942 | lq_sta->pers.ss_force = RS_SS_FORCE_BFER; |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3943 | } else { |
| 3944 | IWL_ERR(mvm, |
| 3945 | "can't force BFER. peer doesn't support\n"); |
| 3946 | ret = -EINVAL; |
| 3947 | } |
| 3948 | } else { |
| 3949 | IWL_ERR(mvm, "valid values none|siso|stbc|bfer\n"); |
| 3950 | ret = -EINVAL; |
| 3951 | } |
| 3952 | return ret ?: count; |
| 3953 | } |
| 3954 | |
| 3955 | #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \ |
| 3956 | _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_lq_sta) |
| 3957 | #define MVM_DEBUGFS_ADD_FILE_RS(name, parent, mode) do { \ |
| 3958 | if (!debugfs_create_file(#name, mode, parent, lq_sta, \ |
| 3959 | &iwl_dbgfs_##name##_ops)) \ |
| 3960 | goto err; \ |
| 3961 | } while (0) |
| 3962 | |
| 3963 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(ss_force, 32); |
| 3964 | |
Johannes Berg | dcbc17a | 2015-03-10 21:24:34 +0100 | [diff] [blame] | 3965 | static void rs_add_debugfs(void *mvm, void *priv_sta, struct dentry *dir) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3966 | { |
Johannes Berg | dcbc17a | 2015-03-10 21:24:34 +0100 | [diff] [blame] | 3967 | struct iwl_lq_sta *lq_sta = priv_sta; |
| 3968 | struct iwl_mvm_sta *mvmsta; |
| 3969 | |
| 3970 | mvmsta = container_of(lq_sta, struct iwl_mvm_sta, lq_sta); |
| 3971 | |
| 3972 | if (!mvmsta->vif) |
| 3973 | return; |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3974 | |
Eliad Peller | c6e1faa | 2014-06-15 12:02:20 +0300 | [diff] [blame] | 3975 | debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir, |
| 3976 | lq_sta, &rs_sta_dbgfs_scale_table_ops); |
| 3977 | debugfs_create_file("rate_stats_table", S_IRUSR, dir, |
| 3978 | lq_sta, &rs_sta_dbgfs_stats_table_ops); |
| 3979 | debugfs_create_file("drv_tx_stats", S_IRUSR | S_IWUSR, dir, |
| 3980 | lq_sta, &rs_sta_dbgfs_drv_tx_stats_ops); |
| 3981 | debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir, |
| 3982 | &lq_sta->tx_agg_tid_en); |
| 3983 | debugfs_create_u8("reduced_tpc", S_IRUSR | S_IWUSR, dir, |
| 3984 | &lq_sta->pers.dbg_fixed_txp_reduction); |
Eyal Shapira | 1e9c62f | 2015-01-28 14:44:06 +0200 | [diff] [blame] | 3985 | |
| 3986 | MVM_DEBUGFS_ADD_FILE_RS(ss_force, dir, S_IRUSR | S_IWUSR); |
| 3987 | return; |
| 3988 | err: |
| 3989 | IWL_ERR((struct iwl_mvm *)mvm, "Can't create debugfs entity\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | static void rs_remove_debugfs(void *mvm, void *mvm_sta) |
| 3993 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3994 | } |
| 3995 | #endif |
| 3996 | |
| 3997 | /* |
| 3998 | * Initialization of rate scaling information is done by driver after |
| 3999 | * the station is added. Since mac80211 calls this function before a |
| 4000 | * station is added we ignore it. |
| 4001 | */ |
| 4002 | static void rs_rate_init_stub(void *mvm_r, |
Simon Wunderlich | 3de805c | 2013-07-08 16:55:50 +0200 | [diff] [blame] | 4003 | struct ieee80211_supported_band *sband, |
| 4004 | struct cfg80211_chan_def *chandef, |
| 4005 | struct ieee80211_sta *sta, void *mvm_sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 4006 | { |
| 4007 | } |
Johannes Berg | 631ad70 | 2014-01-20 23:29:34 +0100 | [diff] [blame] | 4008 | |
| 4009 | static const struct rate_control_ops rs_mvm_ops = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 4010 | .name = RS_NAME, |
Eyal Shapira | 1ebc8f2 | 2014-09-14 15:23:23 +0300 | [diff] [blame] | 4011 | .tx_status = rs_mac80211_tx_status, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 4012 | .get_rate = rs_get_rate, |
| 4013 | .rate_init = rs_rate_init_stub, |
| 4014 | .alloc = rs_alloc, |
| 4015 | .free = rs_free, |
| 4016 | .alloc_sta = rs_alloc_sta, |
| 4017 | .free_sta = rs_free_sta, |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 4018 | .rate_update = rs_rate_update, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 4019 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 4020 | .add_sta_debugfs = rs_add_debugfs, |
| 4021 | .remove_sta_debugfs = rs_remove_debugfs, |
| 4022 | #endif |
| 4023 | }; |
| 4024 | |
| 4025 | int iwl_mvm_rate_control_register(void) |
| 4026 | { |
| 4027 | return ieee80211_rate_control_register(&rs_mvm_ops); |
| 4028 | } |
| 4029 | |
| 4030 | void iwl_mvm_rate_control_unregister(void) |
| 4031 | { |
| 4032 | ieee80211_rate_control_unregister(&rs_mvm_ops); |
| 4033 | } |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 4034 | |
| 4035 | /** |
| 4036 | * iwl_mvm_tx_protection - Gets LQ command, change it to enable/disable |
Sara Sharon | 0d365ae | 2015-03-31 12:24:05 +0300 | [diff] [blame] | 4037 | * Tx protection, according to this request and previous requests, |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 4038 | * and send the LQ command. |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 4039 | * @mvmsta: The station |
| 4040 | * @enable: Enable Tx protection? |
| 4041 | */ |
Johannes Berg | e126b5d | 2013-06-28 13:39:18 +0200 | [diff] [blame] | 4042 | int iwl_mvm_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 4043 | bool enable) |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 4044 | { |
Johannes Berg | e126b5d | 2013-06-28 13:39:18 +0200 | [diff] [blame] | 4045 | struct iwl_lq_cmd *lq = &mvmsta->lq_sta.lq; |
| 4046 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 4047 | lockdep_assert_held(&mvm->mutex); |
| 4048 | |
| 4049 | if (enable) { |
| 4050 | if (mvmsta->tx_protection == 0) |
Eyal Shapira | d307ec8 | 2013-11-11 19:56:21 +0200 | [diff] [blame] | 4051 | lq->flags |= LQ_FLAG_USE_RTS_MSK; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 4052 | mvmsta->tx_protection++; |
| 4053 | } else { |
| 4054 | mvmsta->tx_protection--; |
| 4055 | if (mvmsta->tx_protection == 0) |
Eyal Shapira | d307ec8 | 2013-11-11 19:56:21 +0200 | [diff] [blame] | 4056 | lq->flags &= ~LQ_FLAG_USE_RTS_MSK; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 4057 | } |
| 4058 | |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 4059 | return iwl_mvm_send_lq_cmd(mvm, lq, false); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 4060 | } |