Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved. |
| 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 10 | * Copyright(c) 2016 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of version 2 of the GNU General Public License as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 24 | * USA |
| 25 | * |
| 26 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 27 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 28 | * |
| 29 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 30 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 31 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 32 | * |
| 33 | * BSD LICENSE |
| 34 | * |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 35 | * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved. |
| 36 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 37 | * Copyright(c) 2016 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 38 | * All rights reserved. |
| 39 | * |
| 40 | * Redistribution and use in source and binary forms, with or without |
| 41 | * modification, are permitted provided that the following conditions |
| 42 | * are met: |
| 43 | * |
| 44 | * * Redistributions of source code must retain the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer. |
| 46 | * * Redistributions in binary form must reproduce the above copyright |
| 47 | * notice, this list of conditions and the following disclaimer in |
| 48 | * the documentation and/or other materials provided with the |
| 49 | * distribution. |
| 50 | * * Neither the name Intel Corporation nor the names of its |
| 51 | * contributors may be used to endorse or promote products derived |
| 52 | * from this software without specific prior written permission. |
| 53 | * |
| 54 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 55 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 56 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 57 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 58 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 59 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 60 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 61 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 62 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 63 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 64 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 65 | * |
| 66 | *****************************************************************************/ |
| 67 | #include <net/mac80211.h> |
| 68 | |
| 69 | #include "mvm.h" |
| 70 | #include "sta.h" |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 71 | #include "rs.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 72 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 73 | /* |
| 74 | * New version of ADD_STA_sta command added new fields at the end of the |
| 75 | * structure, so sending the size of the relevant API's structure is enough to |
| 76 | * support both API versions. |
| 77 | */ |
| 78 | static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm *mvm) |
| 79 | { |
| 80 | return iwl_mvm_has_new_rx_api(mvm) ? |
| 81 | sizeof(struct iwl_mvm_add_sta_cmd) : |
| 82 | sizeof(struct iwl_mvm_add_sta_cmd_v7); |
| 83 | } |
| 84 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 85 | static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm, |
| 86 | enum nl80211_iftype iftype) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 87 | { |
| 88 | int sta_id; |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 89 | u32 reserved_ids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 90 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 91 | BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 92 | WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)); |
| 93 | |
| 94 | lockdep_assert_held(&mvm->mutex); |
| 95 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 96 | /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */ |
| 97 | if (iftype != NL80211_IFTYPE_STATION) |
| 98 | reserved_ids = BIT(0); |
| 99 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 100 | /* Don't take rcu_read_lock() since we are protected by mvm->mutex */ |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 101 | for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) { |
| 102 | if (BIT(sta_id) & reserved_ids) |
| 103 | continue; |
| 104 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 105 | if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 106 | lockdep_is_held(&mvm->mutex))) |
| 107 | return sta_id; |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 108 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 109 | return IWL_MVM_STATION_COUNT; |
| 110 | } |
| 111 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 112 | /* send station add/update command to firmware */ |
| 113 | int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 114 | bool update, unsigned int flags) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 115 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 116 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 4b8265a | 2014-07-13 08:58:04 +0300 | [diff] [blame] | 117 | struct iwl_mvm_add_sta_cmd add_sta_cmd = { |
| 118 | .sta_id = mvm_sta->sta_id, |
| 119 | .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color), |
| 120 | .add_modify = update ? 1 : 0, |
| 121 | .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK | |
| 122 | STA_FLG_MIMO_EN_MSK), |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 123 | .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg), |
Emmanuel Grumbach | 4b8265a | 2014-07-13 08:58:04 +0300 | [diff] [blame] | 124 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 125 | int ret; |
| 126 | u32 status; |
| 127 | u32 agg_size = 0, mpdu_dens = 0; |
| 128 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 129 | if (!update || (flags & STA_MODIFY_QUEUES)) { |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 130 | add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 131 | memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 132 | |
| 133 | if (flags & STA_MODIFY_QUEUES) |
| 134 | add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES; |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 135 | } |
Johannes Berg | 5bc5aaa | 2013-02-12 14:35:36 +0100 | [diff] [blame] | 136 | |
| 137 | switch (sta->bandwidth) { |
| 138 | case IEEE80211_STA_RX_BW_160: |
| 139 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ); |
| 140 | /* fall through */ |
| 141 | case IEEE80211_STA_RX_BW_80: |
| 142 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ); |
| 143 | /* fall through */ |
| 144 | case IEEE80211_STA_RX_BW_40: |
| 145 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ); |
| 146 | /* fall through */ |
| 147 | case IEEE80211_STA_RX_BW_20: |
| 148 | if (sta->ht_cap.ht_supported) |
| 149 | add_sta_cmd.station_flags |= |
| 150 | cpu_to_le32(STA_FLG_FAT_EN_20MHZ); |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | switch (sta->rx_nss) { |
| 155 | case 1: |
| 156 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); |
| 157 | break; |
| 158 | case 2: |
| 159 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2); |
| 160 | break; |
| 161 | case 3 ... 8: |
| 162 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3); |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | switch (sta->smps_mode) { |
| 167 | case IEEE80211_SMPS_AUTOMATIC: |
| 168 | case IEEE80211_SMPS_NUM_MODES: |
| 169 | WARN_ON(1); |
| 170 | break; |
| 171 | case IEEE80211_SMPS_STATIC: |
| 172 | /* override NSS */ |
| 173 | add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK); |
| 174 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); |
| 175 | break; |
| 176 | case IEEE80211_SMPS_DYNAMIC: |
| 177 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT); |
| 178 | break; |
| 179 | case IEEE80211_SMPS_OFF: |
| 180 | /* nothing */ |
| 181 | break; |
| 182 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 183 | |
| 184 | if (sta->ht_cap.ht_supported) { |
| 185 | add_sta_cmd.station_flags_msk |= |
| 186 | cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK | |
| 187 | STA_FLG_AGG_MPDU_DENS_MSK); |
| 188 | |
| 189 | mpdu_dens = sta->ht_cap.ampdu_density; |
| 190 | } |
| 191 | |
| 192 | if (sta->vht_cap.vht_supported) { |
| 193 | agg_size = sta->vht_cap.cap & |
| 194 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; |
| 195 | agg_size >>= |
| 196 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 197 | } else if (sta->ht_cap.ht_supported) { |
| 198 | agg_size = sta->ht_cap.ampdu_factor; |
| 199 | } |
| 200 | |
| 201 | add_sta_cmd.station_flags |= |
| 202 | cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT); |
| 203 | add_sta_cmd.station_flags |= |
| 204 | cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT); |
| 205 | |
| 206 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 207 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 208 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 209 | &add_sta_cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 210 | if (ret) |
| 211 | return ret; |
| 212 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 213 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 214 | case ADD_STA_SUCCESS: |
| 215 | IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n"); |
| 216 | break; |
| 217 | default: |
| 218 | ret = -EIO; |
| 219 | IWL_ERR(mvm, "ADD_STA failed\n"); |
| 220 | break; |
| 221 | } |
| 222 | |
| 223 | return ret; |
| 224 | } |
| 225 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 226 | static void iwl_mvm_rx_agg_session_expired(unsigned long data) |
| 227 | { |
| 228 | struct iwl_mvm_baid_data __rcu **rcu_ptr = (void *)data; |
| 229 | struct iwl_mvm_baid_data *ba_data; |
| 230 | struct ieee80211_sta *sta; |
| 231 | struct iwl_mvm_sta *mvm_sta; |
| 232 | unsigned long timeout; |
| 233 | |
| 234 | rcu_read_lock(); |
| 235 | |
| 236 | ba_data = rcu_dereference(*rcu_ptr); |
| 237 | |
| 238 | if (WARN_ON(!ba_data)) |
| 239 | goto unlock; |
| 240 | |
| 241 | if (!ba_data->timeout) |
| 242 | goto unlock; |
| 243 | |
| 244 | timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2); |
| 245 | if (time_is_after_jiffies(timeout)) { |
| 246 | mod_timer(&ba_data->session_timer, timeout); |
| 247 | goto unlock; |
| 248 | } |
| 249 | |
| 250 | /* Timer expired */ |
| 251 | sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]); |
| 252 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 253 | ieee80211_stop_rx_ba_session_offl(mvm_sta->vif, |
| 254 | sta->addr, ba_data->tid); |
| 255 | unlock: |
| 256 | rcu_read_unlock(); |
| 257 | } |
| 258 | |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 259 | static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm, |
| 260 | struct ieee80211_sta *sta) |
| 261 | { |
| 262 | unsigned long used_hw_queues; |
| 263 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 264 | unsigned int wdg_timeout = |
| 265 | iwl_mvm_get_wd_timeout(mvm, NULL, true, false); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 266 | u32 ac; |
| 267 | |
| 268 | lockdep_assert_held(&mvm->mutex); |
| 269 | |
| 270 | used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL); |
| 271 | |
| 272 | /* Find available queues, and allocate them to the ACs */ |
| 273 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 274 | u8 queue = find_first_zero_bit(&used_hw_queues, |
| 275 | mvm->first_agg_queue); |
| 276 | |
| 277 | if (queue >= mvm->first_agg_queue) { |
| 278 | IWL_ERR(mvm, "Failed to allocate STA queue\n"); |
| 279 | return -EBUSY; |
| 280 | } |
| 281 | |
| 282 | __set_bit(queue, &used_hw_queues); |
| 283 | mvmsta->hw_queue[ac] = queue; |
| 284 | } |
| 285 | |
| 286 | /* Found a place for all queues - enable them */ |
| 287 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 288 | iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac], |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 289 | mvmsta->hw_queue[ac], |
Liad Kaufman | 5c1156e | 2015-07-22 17:59:53 +0300 | [diff] [blame] | 290 | iwl_mvm_ac_to_tx_fifo[ac], 0, |
| 291 | wdg_timeout); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 292 | mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]); |
| 293 | } |
| 294 | |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm, |
| 299 | struct ieee80211_sta *sta) |
| 300 | { |
| 301 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 302 | unsigned long sta_msk; |
| 303 | int i; |
| 304 | |
| 305 | lockdep_assert_held(&mvm->mutex); |
| 306 | |
| 307 | /* disable the TDLS STA-specific queues */ |
| 308 | sta_msk = mvmsta->tfd_queue_msk; |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 309 | for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE) |
Arik Nemtsov | 06ecdba | 2015-10-12 14:47:11 +0300 | [diff] [blame] | 310 | iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 311 | } |
| 312 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 313 | /* Disable aggregations for a bitmap of TIDs for a given station */ |
| 314 | static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue, |
| 315 | unsigned long disable_agg_tids, |
| 316 | bool remove_queue) |
| 317 | { |
| 318 | struct iwl_mvm_add_sta_cmd cmd = {}; |
| 319 | struct ieee80211_sta *sta; |
| 320 | struct iwl_mvm_sta *mvmsta; |
| 321 | u32 status; |
| 322 | u8 sta_id; |
| 323 | int ret; |
| 324 | |
| 325 | spin_lock_bh(&mvm->queue_info_lock); |
| 326 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 327 | spin_unlock_bh(&mvm->queue_info_lock); |
| 328 | |
| 329 | rcu_read_lock(); |
| 330 | |
| 331 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 332 | |
| 333 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { |
| 334 | rcu_read_unlock(); |
| 335 | return -EINVAL; |
| 336 | } |
| 337 | |
| 338 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 339 | |
| 340 | mvmsta->tid_disable_agg |= disable_agg_tids; |
| 341 | |
| 342 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 343 | cmd.sta_id = mvmsta->sta_id; |
| 344 | cmd.add_modify = STA_MODE_MODIFY; |
| 345 | cmd.modify_mask = STA_MODIFY_QUEUES; |
| 346 | if (disable_agg_tids) |
| 347 | cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX; |
| 348 | if (remove_queue) |
| 349 | cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL; |
| 350 | cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk); |
| 351 | cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg); |
| 352 | |
| 353 | rcu_read_unlock(); |
| 354 | |
| 355 | /* Notify FW of queue removal from the STA queues */ |
| 356 | status = ADD_STA_SUCCESS; |
| 357 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 358 | iwl_mvm_add_sta_cmd_size(mvm), |
| 359 | &cmd, &status); |
| 360 | |
| 361 | return ret; |
| 362 | } |
| 363 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 364 | static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue) |
| 365 | { |
| 366 | struct ieee80211_sta *sta; |
| 367 | struct iwl_mvm_sta *mvmsta; |
| 368 | unsigned long tid_bitmap; |
| 369 | unsigned long agg_tids = 0; |
| 370 | s8 sta_id; |
| 371 | int tid; |
| 372 | |
| 373 | lockdep_assert_held(&mvm->mutex); |
| 374 | |
| 375 | spin_lock_bh(&mvm->queue_info_lock); |
| 376 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 377 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; |
| 378 | spin_unlock_bh(&mvm->queue_info_lock); |
| 379 | |
| 380 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 381 | lockdep_is_held(&mvm->mutex)); |
| 382 | |
| 383 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) |
| 384 | return -EINVAL; |
| 385 | |
| 386 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 387 | |
| 388 | spin_lock_bh(&mvmsta->lock); |
| 389 | for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) { |
| 390 | if (mvmsta->tid_data[tid].state == IWL_AGG_ON) |
| 391 | agg_tids |= BIT(tid); |
| 392 | } |
| 393 | spin_unlock_bh(&mvmsta->lock); |
| 394 | |
| 395 | return agg_tids; |
| 396 | } |
| 397 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 398 | /* |
| 399 | * Remove a queue from a station's resources. |
| 400 | * Note that this only marks as free. It DOESN'T delete a BA agreement, and |
| 401 | * doesn't disable the queue |
| 402 | */ |
| 403 | static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue) |
| 404 | { |
| 405 | struct ieee80211_sta *sta; |
| 406 | struct iwl_mvm_sta *mvmsta; |
| 407 | unsigned long tid_bitmap; |
| 408 | unsigned long disable_agg_tids = 0; |
| 409 | u8 sta_id; |
| 410 | int tid; |
| 411 | |
| 412 | lockdep_assert_held(&mvm->mutex); |
| 413 | |
| 414 | spin_lock_bh(&mvm->queue_info_lock); |
| 415 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 416 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; |
| 417 | spin_unlock_bh(&mvm->queue_info_lock); |
| 418 | |
| 419 | rcu_read_lock(); |
| 420 | |
| 421 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 422 | |
| 423 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { |
| 424 | rcu_read_unlock(); |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 429 | |
| 430 | spin_lock_bh(&mvmsta->lock); |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 431 | /* Unmap MAC queues and TIDs from this queue */ |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 432 | for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) { |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 433 | if (mvmsta->tid_data[tid].state == IWL_AGG_ON) |
| 434 | disable_agg_tids |= BIT(tid); |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 435 | mvmsta->tid_data[tid].txq_id = IEEE80211_INVAL_HW_QUEUE; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 436 | } |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 437 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 438 | mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */ |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 439 | spin_unlock_bh(&mvmsta->lock); |
| 440 | |
| 441 | rcu_read_unlock(); |
| 442 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 443 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 444 | /* Unmap MAC queues and TIDs from this queue */ |
| 445 | mvm->queue_info[queue].hw_queue_to_mac80211 = 0; |
| 446 | mvm->queue_info[queue].hw_queue_refcount = 0; |
| 447 | mvm->queue_info[queue].tid_bitmap = 0; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 448 | spin_unlock_bh(&mvm->queue_info_lock); |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 449 | |
| 450 | return disable_agg_tids; |
| 451 | } |
| 452 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 453 | static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm, |
| 454 | unsigned long tfd_queue_mask, u8 ac) |
| 455 | { |
| 456 | int queue = 0; |
| 457 | u8 ac_to_queue[IEEE80211_NUM_ACS]; |
| 458 | int i; |
| 459 | |
| 460 | lockdep_assert_held(&mvm->queue_info_lock); |
| 461 | |
| 462 | memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue)); |
| 463 | |
| 464 | /* See what ACs the existing queues for this STA have */ |
| 465 | for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) { |
| 466 | /* Only DATA queues can be shared */ |
| 467 | if (i < IWL_MVM_DQA_MIN_DATA_QUEUE && |
| 468 | i != IWL_MVM_DQA_BSS_CLIENT_QUEUE) |
| 469 | continue; |
| 470 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 471 | /* Don't try and take queues being reconfigured */ |
| 472 | if (mvm->queue_info[queue].status == |
| 473 | IWL_MVM_QUEUE_RECONFIGURING) |
| 474 | continue; |
| 475 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 476 | ac_to_queue[mvm->queue_info[i].mac80211_ac] = i; |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * The queue to share is chosen only from DATA queues as follows (in |
| 481 | * descending priority): |
| 482 | * 1. An AC_BE queue |
| 483 | * 2. Same AC queue |
| 484 | * 3. Highest AC queue that is lower than new AC |
| 485 | * 4. Any existing AC (there always is at least 1 DATA queue) |
| 486 | */ |
| 487 | |
| 488 | /* Priority 1: An AC_BE queue */ |
| 489 | if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE) |
| 490 | queue = ac_to_queue[IEEE80211_AC_BE]; |
| 491 | /* Priority 2: Same AC queue */ |
| 492 | else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE) |
| 493 | queue = ac_to_queue[ac]; |
| 494 | /* Priority 3a: If new AC is VO and VI exists - use VI */ |
| 495 | else if (ac == IEEE80211_AC_VO && |
| 496 | ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE) |
| 497 | queue = ac_to_queue[IEEE80211_AC_VI]; |
| 498 | /* Priority 3b: No BE so only AC less than the new one is BK */ |
| 499 | else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE) |
| 500 | queue = ac_to_queue[IEEE80211_AC_BK]; |
| 501 | /* Priority 4a: No BE nor BK - use VI if exists */ |
| 502 | else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE) |
| 503 | queue = ac_to_queue[IEEE80211_AC_VI]; |
| 504 | /* Priority 4b: No BE, BK nor VI - use VO if exists */ |
| 505 | else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE) |
| 506 | queue = ac_to_queue[IEEE80211_AC_VO]; |
| 507 | |
| 508 | /* Make sure queue found (or not) is legal */ |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 509 | if (!iwl_mvm_is_dqa_data_queue(mvm, queue) && |
| 510 | !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) && |
| 511 | (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) { |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 512 | IWL_ERR(mvm, "No DATA queues available to share\n"); |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 513 | return -ENOSPC; |
| 514 | } |
| 515 | |
| 516 | /* Make sure the queue isn't in the middle of being reconfigured */ |
| 517 | if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_RECONFIGURING) { |
| 518 | IWL_ERR(mvm, |
| 519 | "TXQ %d is in the middle of re-config - try again\n", |
| 520 | queue); |
| 521 | return -EBUSY; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | return queue; |
| 525 | } |
| 526 | |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 527 | /* |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 528 | * If a given queue has a higher AC than the TID stream that is being compared |
| 529 | * to, the queue needs to be redirected to the lower AC. This function does that |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 530 | * in such a case, otherwise - if no redirection required - it does nothing, |
| 531 | * unless the %force param is true. |
| 532 | */ |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 533 | int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid, |
| 534 | int ac, int ssn, unsigned int wdg_timeout, |
| 535 | bool force) |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 536 | { |
| 537 | struct iwl_scd_txq_cfg_cmd cmd = { |
| 538 | .scd_queue = queue, |
Liad Kaufman | f7c692d | 2016-03-08 10:41:32 +0200 | [diff] [blame] | 539 | .action = SCD_CFG_DISABLE_QUEUE, |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 540 | }; |
| 541 | bool shared_queue; |
| 542 | unsigned long mq; |
| 543 | int ret; |
| 544 | |
| 545 | /* |
| 546 | * If the AC is lower than current one - FIFO needs to be redirected to |
| 547 | * the lowest one of the streams in the queue. Check if this is needed |
| 548 | * here. |
| 549 | * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with |
| 550 | * value 3 and VO with value 0, so to check if ac X is lower than ac Y |
| 551 | * we need to check if the numerical value of X is LARGER than of Y. |
| 552 | */ |
| 553 | spin_lock_bh(&mvm->queue_info_lock); |
| 554 | if (ac <= mvm->queue_info[queue].mac80211_ac && !force) { |
| 555 | spin_unlock_bh(&mvm->queue_info_lock); |
| 556 | |
| 557 | IWL_DEBUG_TX_QUEUES(mvm, |
| 558 | "No redirection needed on TXQ #%d\n", |
| 559 | queue); |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | cmd.sta_id = mvm->queue_info[queue].ra_sta_id; |
| 564 | cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac]; |
Liad Kaufman | edbe961 | 2016-02-02 15:43:32 +0200 | [diff] [blame] | 565 | cmd.tid = mvm->queue_info[queue].txq_tid; |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 566 | mq = mvm->queue_info[queue].hw_queue_to_mac80211; |
| 567 | shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1); |
| 568 | spin_unlock_bh(&mvm->queue_info_lock); |
| 569 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 570 | IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n", |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 571 | queue, iwl_mvm_ac_to_tx_fifo[ac]); |
| 572 | |
| 573 | /* Stop MAC queues and wait for this queue to empty */ |
| 574 | iwl_mvm_stop_mac_queues(mvm, mq); |
| 575 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, BIT(queue)); |
| 576 | if (ret) { |
| 577 | IWL_ERR(mvm, "Error draining queue %d before reconfig\n", |
| 578 | queue); |
| 579 | ret = -EIO; |
| 580 | goto out; |
| 581 | } |
| 582 | |
| 583 | /* Before redirecting the queue we need to de-activate it */ |
| 584 | iwl_trans_txq_disable(mvm->trans, queue, false); |
| 585 | ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd); |
| 586 | if (ret) |
| 587 | IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue, |
| 588 | ret); |
| 589 | |
| 590 | /* Make sure the SCD wrptr is correctly set before reconfiguring */ |
Sara Sharon | ca3b9c6 | 2016-06-30 16:14:02 +0300 | [diff] [blame] | 591 | iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout); |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 592 | |
Liad Kaufman | edbe961 | 2016-02-02 15:43:32 +0200 | [diff] [blame] | 593 | /* Update the TID "owner" of the queue */ |
| 594 | spin_lock_bh(&mvm->queue_info_lock); |
| 595 | mvm->queue_info[queue].txq_tid = tid; |
| 596 | spin_unlock_bh(&mvm->queue_info_lock); |
| 597 | |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 598 | /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */ |
| 599 | |
| 600 | /* Redirect to lower AC */ |
| 601 | iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac], |
| 602 | cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF, |
| 603 | ssn); |
| 604 | |
| 605 | /* Update AC marking of the queue */ |
| 606 | spin_lock_bh(&mvm->queue_info_lock); |
| 607 | mvm->queue_info[queue].mac80211_ac = ac; |
| 608 | spin_unlock_bh(&mvm->queue_info_lock); |
| 609 | |
| 610 | /* |
| 611 | * Mark queue as shared in transport if shared |
| 612 | * Note this has to be done after queue enablement because enablement |
| 613 | * can also set this value, and there is no indication there to shared |
| 614 | * queues |
| 615 | */ |
| 616 | if (shared_queue) |
| 617 | iwl_trans_txq_set_shared_mode(mvm->trans, queue, true); |
| 618 | |
| 619 | out: |
| 620 | /* Continue using the MAC queues */ |
| 621 | iwl_mvm_start_mac_queues(mvm, mq); |
| 622 | |
| 623 | return ret; |
| 624 | } |
| 625 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 626 | static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm, |
| 627 | struct ieee80211_sta *sta, u8 ac, int tid, |
| 628 | struct ieee80211_hdr *hdr) |
| 629 | { |
| 630 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 631 | struct iwl_trans_txq_scd_cfg cfg = { |
| 632 | .fifo = iwl_mvm_ac_to_tx_fifo[ac], |
| 633 | .sta_id = mvmsta->sta_id, |
| 634 | .tid = tid, |
| 635 | .frame_limit = IWL_FRAME_LIMIT, |
| 636 | }; |
| 637 | unsigned int wdg_timeout = |
| 638 | iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); |
| 639 | u8 mac_queue = mvmsta->vif->hw_queue[ac]; |
| 640 | int queue = -1; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 641 | bool using_inactive_queue = false; |
| 642 | unsigned long disable_agg_tids = 0; |
| 643 | enum iwl_mvm_agg_state queue_state; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 644 | bool shared_queue = false; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 645 | int ssn; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 646 | unsigned long tfd_queue_mask; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 647 | int ret; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 648 | |
| 649 | lockdep_assert_held(&mvm->mutex); |
| 650 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 651 | spin_lock_bh(&mvmsta->lock); |
| 652 | tfd_queue_mask = mvmsta->tfd_queue_msk; |
| 653 | spin_unlock_bh(&mvmsta->lock); |
| 654 | |
Liad Kaufman | d2515a9 | 2016-03-23 16:31:08 +0200 | [diff] [blame] | 655 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 656 | |
| 657 | /* |
| 658 | * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one |
| 659 | * exists |
| 660 | */ |
| 661 | if (!ieee80211_is_data_qos(hdr->frame_control) || |
| 662 | ieee80211_is_qos_nullfunc(hdr->frame_control)) { |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 663 | queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
| 664 | IWL_MVM_DQA_MIN_MGMT_QUEUE, |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 665 | IWL_MVM_DQA_MAX_MGMT_QUEUE); |
| 666 | if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) |
| 667 | IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n", |
| 668 | queue); |
| 669 | |
| 670 | /* If no such queue is found, we'll use a DATA queue instead */ |
| 671 | } |
| 672 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 673 | if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) && |
| 674 | (mvm->queue_info[mvmsta->reserved_queue].status == |
| 675 | IWL_MVM_QUEUE_RESERVED || |
| 676 | mvm->queue_info[mvmsta->reserved_queue].status == |
| 677 | IWL_MVM_QUEUE_INACTIVE)) { |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 678 | queue = mvmsta->reserved_queue; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 679 | mvm->queue_info[queue].reserved = true; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 680 | IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue); |
| 681 | } |
| 682 | |
| 683 | if (queue < 0) |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 684 | queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
| 685 | IWL_MVM_DQA_MIN_DATA_QUEUE, |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 686 | IWL_MVM_DQA_MAX_DATA_QUEUE); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 687 | |
| 688 | /* |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 689 | * Check if this queue is already allocated but inactive. |
| 690 | * In such a case, we'll need to first free this queue before enabling |
| 691 | * it again, so we'll mark it as reserved to make sure no new traffic |
| 692 | * arrives on it |
| 693 | */ |
| 694 | if (queue > 0 && |
| 695 | mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) { |
| 696 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED; |
| 697 | using_inactive_queue = true; |
| 698 | IWL_DEBUG_TX_QUEUES(mvm, |
| 699 | "Re-assigning TXQ %d: sta_id=%d, tid=%d\n", |
| 700 | queue, mvmsta->sta_id, tid); |
| 701 | } |
| 702 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 703 | /* No free queue - we'll have to share */ |
| 704 | if (queue <= 0) { |
| 705 | queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac); |
| 706 | if (queue > 0) { |
| 707 | shared_queue = true; |
| 708 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED; |
| 709 | } |
| 710 | } |
| 711 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 712 | /* |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 713 | * Mark TXQ as ready, even though it hasn't been fully configured yet, |
| 714 | * to make sure no one else takes it. |
| 715 | * This will allow avoiding re-acquiring the lock at the end of the |
| 716 | * configuration. On error we'll mark it back as free. |
| 717 | */ |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 718 | if ((queue > 0) && !shared_queue) |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 719 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 720 | |
Liad Kaufman | d2515a9 | 2016-03-23 16:31:08 +0200 | [diff] [blame] | 721 | spin_unlock_bh(&mvm->queue_info_lock); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 722 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 723 | /* This shouldn't happen - out of queues */ |
| 724 | if (WARN_ON(queue <= 0)) { |
| 725 | IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n", |
| 726 | tid, cfg.sta_id); |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 727 | return queue; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 728 | } |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 729 | |
| 730 | /* |
| 731 | * Actual en/disablement of aggregations is through the ADD_STA HCMD, |
| 732 | * but for configuring the SCD to send A-MPDUs we need to mark the queue |
| 733 | * as aggregatable. |
| 734 | * Mark all DATA queues as allowing to be aggregated at some point |
| 735 | */ |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 736 | cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE || |
| 737 | queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 738 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 739 | /* |
| 740 | * If this queue was previously inactive (idle) - we need to free it |
| 741 | * first |
| 742 | */ |
| 743 | if (using_inactive_queue) { |
| 744 | struct iwl_scd_txq_cfg_cmd cmd = { |
| 745 | .scd_queue = queue, |
Liad Kaufman | f7c692d | 2016-03-08 10:41:32 +0200 | [diff] [blame] | 746 | .action = SCD_CFG_DISABLE_QUEUE, |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 747 | }; |
Liad Kaufman | d55092b | 2016-08-03 18:41:27 +0300 | [diff] [blame] | 748 | u8 txq_curr_ac; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 749 | |
| 750 | disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue); |
| 751 | |
Liad Kaufman | 93f436e | 2015-08-31 13:41:26 +0300 | [diff] [blame] | 752 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | d55092b | 2016-08-03 18:41:27 +0300 | [diff] [blame] | 753 | txq_curr_ac = mvm->queue_info[queue].mac80211_ac; |
Liad Kaufman | 93f436e | 2015-08-31 13:41:26 +0300 | [diff] [blame] | 754 | cmd.sta_id = mvm->queue_info[queue].ra_sta_id; |
Liad Kaufman | d55092b | 2016-08-03 18:41:27 +0300 | [diff] [blame] | 755 | cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[txq_curr_ac]; |
Liad Kaufman | edbe961 | 2016-02-02 15:43:32 +0200 | [diff] [blame] | 756 | cmd.tid = mvm->queue_info[queue].txq_tid; |
Liad Kaufman | 93f436e | 2015-08-31 13:41:26 +0300 | [diff] [blame] | 757 | spin_unlock_bh(&mvm->queue_info_lock); |
| 758 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 759 | /* Disable the queue */ |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 760 | if (disable_agg_tids) |
| 761 | iwl_mvm_invalidate_sta_queue(mvm, queue, |
| 762 | disable_agg_tids, false); |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 763 | iwl_trans_txq_disable(mvm->trans, queue, false); |
| 764 | ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), |
| 765 | &cmd); |
| 766 | if (ret) { |
| 767 | IWL_ERR(mvm, |
| 768 | "Failed to free inactive queue %d (ret=%d)\n", |
| 769 | queue, ret); |
| 770 | |
| 771 | /* Re-mark the inactive queue as inactive */ |
| 772 | spin_lock_bh(&mvm->queue_info_lock); |
| 773 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE; |
| 774 | spin_unlock_bh(&mvm->queue_info_lock); |
| 775 | |
| 776 | return ret; |
| 777 | } |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 778 | |
| 779 | /* If TXQ is allocated to another STA, update removal in FW */ |
| 780 | if (cmd.sta_id != mvmsta->sta_id) |
| 781 | iwl_mvm_invalidate_sta_queue(mvm, queue, 0, true); |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 782 | } |
| 783 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 784 | IWL_DEBUG_TX_QUEUES(mvm, |
| 785 | "Allocating %squeue #%d to sta %d on tid %d\n", |
| 786 | shared_queue ? "shared " : "", queue, |
| 787 | mvmsta->sta_id, tid); |
| 788 | |
| 789 | if (shared_queue) { |
| 790 | /* Disable any open aggs on this queue */ |
| 791 | disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue); |
| 792 | |
| 793 | if (disable_agg_tids) { |
| 794 | IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n", |
| 795 | queue); |
| 796 | iwl_mvm_invalidate_sta_queue(mvm, queue, |
| 797 | disable_agg_tids, false); |
| 798 | } |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 799 | } |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 800 | |
| 801 | ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl)); |
| 802 | iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg, |
| 803 | wdg_timeout); |
| 804 | |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 805 | /* |
| 806 | * Mark queue as shared in transport if shared |
| 807 | * Note this has to be done after queue enablement because enablement |
| 808 | * can also set this value, and there is no indication there to shared |
| 809 | * queues |
| 810 | */ |
| 811 | if (shared_queue) |
| 812 | iwl_trans_txq_set_shared_mode(mvm->trans, queue, true); |
| 813 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 814 | spin_lock_bh(&mvmsta->lock); |
| 815 | mvmsta->tid_data[tid].txq_id = queue; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 816 | mvmsta->tid_data[tid].is_tid_active = true; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 817 | mvmsta->tfd_queue_msk |= BIT(queue); |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 818 | queue_state = mvmsta->tid_data[tid].state; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 819 | |
| 820 | if (mvmsta->reserved_queue == queue) |
| 821 | mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE; |
| 822 | spin_unlock_bh(&mvmsta->lock); |
| 823 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 824 | if (!shared_queue) { |
| 825 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES); |
| 826 | if (ret) |
| 827 | goto out_err; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 828 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 829 | /* If we need to re-enable aggregations... */ |
| 830 | if (queue_state == IWL_AGG_ON) { |
| 831 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 832 | if (ret) |
| 833 | goto out_err; |
| 834 | } |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 835 | } else { |
| 836 | /* Redirect queue, if needed */ |
| 837 | ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn, |
| 838 | wdg_timeout, false); |
| 839 | if (ret) |
| 840 | goto out_err; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 841 | } |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 842 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 843 | return 0; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 844 | |
| 845 | out_err: |
| 846 | iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0); |
| 847 | |
| 848 | return ret; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 849 | } |
| 850 | |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 851 | static void iwl_mvm_change_queue_owner(struct iwl_mvm *mvm, int queue) |
| 852 | { |
| 853 | struct iwl_scd_txq_cfg_cmd cmd = { |
| 854 | .scd_queue = queue, |
| 855 | .action = SCD_CFG_UPDATE_QUEUE_TID, |
| 856 | }; |
| 857 | s8 sta_id; |
| 858 | int tid; |
| 859 | unsigned long tid_bitmap; |
| 860 | int ret; |
| 861 | |
| 862 | lockdep_assert_held(&mvm->mutex); |
| 863 | |
| 864 | spin_lock_bh(&mvm->queue_info_lock); |
| 865 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 866 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; |
| 867 | spin_unlock_bh(&mvm->queue_info_lock); |
| 868 | |
| 869 | if (WARN(!tid_bitmap, "TXQ %d has no tids assigned to it\n", queue)) |
| 870 | return; |
| 871 | |
| 872 | /* Find any TID for queue */ |
| 873 | tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1); |
| 874 | cmd.tid = tid; |
| 875 | cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; |
| 876 | |
| 877 | ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd); |
Liad Kaufman | 341ca40 | 2016-09-18 14:51:59 +0300 | [diff] [blame] | 878 | if (ret) { |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 879 | IWL_ERR(mvm, "Failed to update owner of TXQ %d (ret=%d)\n", |
| 880 | queue, ret); |
Liad Kaufman | 341ca40 | 2016-09-18 14:51:59 +0300 | [diff] [blame] | 881 | return; |
| 882 | } |
| 883 | |
| 884 | spin_lock_bh(&mvm->queue_info_lock); |
| 885 | mvm->queue_info[queue].txq_tid = tid; |
| 886 | spin_unlock_bh(&mvm->queue_info_lock); |
| 887 | IWL_DEBUG_TX_QUEUES(mvm, "Changed TXQ %d ownership to tid %d\n", |
| 888 | queue, tid); |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 889 | } |
| 890 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 891 | static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue) |
| 892 | { |
| 893 | struct ieee80211_sta *sta; |
| 894 | struct iwl_mvm_sta *mvmsta; |
| 895 | s8 sta_id; |
| 896 | int tid = -1; |
| 897 | unsigned long tid_bitmap; |
| 898 | unsigned int wdg_timeout; |
| 899 | int ssn; |
| 900 | int ret = true; |
| 901 | |
| 902 | lockdep_assert_held(&mvm->mutex); |
| 903 | |
| 904 | spin_lock_bh(&mvm->queue_info_lock); |
| 905 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 906 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; |
| 907 | spin_unlock_bh(&mvm->queue_info_lock); |
| 908 | |
| 909 | /* Find TID for queue, and make sure it is the only one on the queue */ |
| 910 | tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1); |
| 911 | if (tid_bitmap != BIT(tid)) { |
| 912 | IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n", |
| 913 | queue, tid_bitmap); |
| 914 | return; |
| 915 | } |
| 916 | |
| 917 | IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue, |
| 918 | tid); |
| 919 | |
| 920 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 921 | lockdep_is_held(&mvm->mutex)); |
| 922 | |
| 923 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) |
| 924 | return; |
| 925 | |
| 926 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 927 | wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); |
| 928 | |
| 929 | ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number); |
| 930 | |
| 931 | ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, |
| 932 | tid_to_mac80211_ac[tid], ssn, |
| 933 | wdg_timeout, true); |
| 934 | if (ret) { |
| 935 | IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue); |
| 936 | return; |
| 937 | } |
| 938 | |
| 939 | /* If aggs should be turned back on - do it */ |
| 940 | if (mvmsta->tid_data[tid].state == IWL_AGG_ON) { |
Emmanuel Grumbach | 9cd70e8 | 2016-09-20 13:40:33 +0300 | [diff] [blame] | 941 | struct iwl_mvm_add_sta_cmd cmd = {0}; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 942 | |
| 943 | mvmsta->tid_disable_agg &= ~BIT(tid); |
| 944 | |
| 945 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 946 | cmd.sta_id = mvmsta->sta_id; |
| 947 | cmd.add_modify = STA_MODE_MODIFY; |
| 948 | cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 949 | cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk); |
| 950 | cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg); |
| 951 | |
| 952 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 953 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
| 954 | if (!ret) { |
| 955 | IWL_DEBUG_TX_QUEUES(mvm, |
| 956 | "TXQ #%d is now aggregated again\n", |
| 957 | queue); |
| 958 | |
| 959 | /* Mark queue intenally as aggregating again */ |
| 960 | iwl_trans_txq_set_shared_mode(mvm->trans, queue, false); |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | spin_lock_bh(&mvm->queue_info_lock); |
| 965 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
| 966 | spin_unlock_bh(&mvm->queue_info_lock); |
| 967 | } |
| 968 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 969 | static inline u8 iwl_mvm_tid_to_ac_queue(int tid) |
| 970 | { |
| 971 | if (tid == IWL_MAX_TID_COUNT) |
| 972 | return IEEE80211_AC_VO; /* MGMT */ |
| 973 | |
| 974 | return tid_to_mac80211_ac[tid]; |
| 975 | } |
| 976 | |
| 977 | static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm, |
| 978 | struct ieee80211_sta *sta, int tid) |
| 979 | { |
| 980 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 981 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 982 | struct sk_buff *skb; |
| 983 | struct ieee80211_hdr *hdr; |
| 984 | struct sk_buff_head deferred_tx; |
| 985 | u8 mac_queue; |
| 986 | bool no_queue = false; /* Marks if there is a problem with the queue */ |
| 987 | u8 ac; |
| 988 | |
| 989 | lockdep_assert_held(&mvm->mutex); |
| 990 | |
| 991 | skb = skb_peek(&tid_data->deferred_tx_frames); |
| 992 | if (!skb) |
| 993 | return; |
| 994 | hdr = (void *)skb->data; |
| 995 | |
| 996 | ac = iwl_mvm_tid_to_ac_queue(tid); |
| 997 | mac_queue = IEEE80211_SKB_CB(skb)->hw_queue; |
| 998 | |
| 999 | if (tid_data->txq_id == IEEE80211_INVAL_HW_QUEUE && |
| 1000 | iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) { |
| 1001 | IWL_ERR(mvm, |
| 1002 | "Can't alloc TXQ for sta %d tid %d - dropping frame\n", |
| 1003 | mvmsta->sta_id, tid); |
| 1004 | |
| 1005 | /* |
| 1006 | * Mark queue as problematic so later the deferred traffic is |
| 1007 | * freed, as we can do nothing with it |
| 1008 | */ |
| 1009 | no_queue = true; |
| 1010 | } |
| 1011 | |
| 1012 | __skb_queue_head_init(&deferred_tx); |
| 1013 | |
Liad Kaufman | d2515a9 | 2016-03-23 16:31:08 +0200 | [diff] [blame] | 1014 | /* Disable bottom-halves when entering TX path */ |
| 1015 | local_bh_disable(); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1016 | spin_lock(&mvmsta->lock); |
| 1017 | skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx); |
| 1018 | spin_unlock(&mvmsta->lock); |
| 1019 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1020 | while ((skb = __skb_dequeue(&deferred_tx))) |
| 1021 | if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta)) |
| 1022 | ieee80211_free_txskb(mvm->hw, skb); |
| 1023 | local_bh_enable(); |
| 1024 | |
| 1025 | /* Wake queue */ |
| 1026 | iwl_mvm_start_mac_queues(mvm, BIT(mac_queue)); |
| 1027 | } |
| 1028 | |
| 1029 | void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk) |
| 1030 | { |
| 1031 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, |
| 1032 | add_stream_wk); |
| 1033 | struct ieee80211_sta *sta; |
| 1034 | struct iwl_mvm_sta *mvmsta; |
| 1035 | unsigned long deferred_tid_traffic; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1036 | int queue, sta_id, tid; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1037 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 1038 | /* Check inactivity of queues */ |
| 1039 | iwl_mvm_inactivity_check(mvm); |
| 1040 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1041 | mutex_lock(&mvm->mutex); |
| 1042 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1043 | /* Reconfigure queues requiring reconfiguation */ |
| 1044 | for (queue = 0; queue < IWL_MAX_HW_QUEUES; queue++) { |
| 1045 | bool reconfig; |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 1046 | bool change_owner; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1047 | |
| 1048 | spin_lock_bh(&mvm->queue_info_lock); |
| 1049 | reconfig = (mvm->queue_info[queue].status == |
| 1050 | IWL_MVM_QUEUE_RECONFIGURING); |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 1051 | |
| 1052 | /* |
| 1053 | * We need to take into account a situation in which a TXQ was |
| 1054 | * allocated to TID x, and then turned shared by adding TIDs y |
| 1055 | * and z. If TID x becomes inactive and is removed from the TXQ, |
| 1056 | * ownership must be given to one of the remaining TIDs. |
| 1057 | * This is mainly because if TID x continues - a new queue can't |
| 1058 | * be allocated for it as long as it is an owner of another TXQ. |
| 1059 | */ |
| 1060 | change_owner = !(mvm->queue_info[queue].tid_bitmap & |
| 1061 | BIT(mvm->queue_info[queue].txq_tid)) && |
| 1062 | (mvm->queue_info[queue].status == |
| 1063 | IWL_MVM_QUEUE_SHARED); |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1064 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1065 | |
| 1066 | if (reconfig) |
| 1067 | iwl_mvm_unshare_queue(mvm, queue); |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 1068 | else if (change_owner) |
| 1069 | iwl_mvm_change_queue_owner(mvm, queue); |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1070 | } |
| 1071 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1072 | /* Go over all stations with deferred traffic */ |
| 1073 | for_each_set_bit(sta_id, mvm->sta_deferred_frames, |
| 1074 | IWL_MVM_STATION_COUNT) { |
| 1075 | clear_bit(sta_id, mvm->sta_deferred_frames); |
| 1076 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1077 | lockdep_is_held(&mvm->mutex)); |
| 1078 | if (IS_ERR_OR_NULL(sta)) |
| 1079 | continue; |
| 1080 | |
| 1081 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 1082 | deferred_tid_traffic = mvmsta->deferred_traffic_tid_map; |
| 1083 | |
| 1084 | for_each_set_bit(tid, &deferred_tid_traffic, |
| 1085 | IWL_MAX_TID_COUNT + 1) |
| 1086 | iwl_mvm_tx_deferred_stream(mvm, sta, tid); |
| 1087 | } |
| 1088 | |
| 1089 | mutex_unlock(&mvm->mutex); |
| 1090 | } |
| 1091 | |
| 1092 | static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm, |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1093 | struct ieee80211_sta *sta, |
| 1094 | enum nl80211_iftype vif_type) |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1095 | { |
| 1096 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 1097 | int queue; |
| 1098 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 1099 | /* |
| 1100 | * Check for inactive queues, so we don't reach a situation where we |
| 1101 | * can't add a STA due to a shortage in queues that doesn't really exist |
| 1102 | */ |
| 1103 | iwl_mvm_inactivity_check(mvm); |
| 1104 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1105 | spin_lock_bh(&mvm->queue_info_lock); |
| 1106 | |
| 1107 | /* Make sure we have free resources for this STA */ |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1108 | if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls && |
| 1109 | !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount && |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1110 | (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status == |
| 1111 | IWL_MVM_QUEUE_FREE)) |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1112 | queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE; |
| 1113 | else |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 1114 | queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
| 1115 | IWL_MVM_DQA_MIN_DATA_QUEUE, |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1116 | IWL_MVM_DQA_MAX_DATA_QUEUE); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1117 | if (queue < 0) { |
| 1118 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1119 | IWL_ERR(mvm, "No available queues for new station\n"); |
| 1120 | return -ENOSPC; |
| 1121 | } |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1122 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1123 | |
| 1124 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1125 | |
| 1126 | mvmsta->reserved_queue = queue; |
| 1127 | |
| 1128 | IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n", |
| 1129 | queue, mvmsta->sta_id); |
| 1130 | |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1134 | /* |
| 1135 | * In DQA mode, after a HW restart the queues should be allocated as before, in |
| 1136 | * order to avoid race conditions when there are shared queues. This function |
| 1137 | * does the re-mapping and queue allocation. |
| 1138 | * |
| 1139 | * Note that re-enabling aggregations isn't done in this function. |
| 1140 | */ |
| 1141 | static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm *mvm, |
| 1142 | struct iwl_mvm_sta *mvm_sta) |
| 1143 | { |
| 1144 | unsigned int wdg_timeout = |
| 1145 | iwl_mvm_get_wd_timeout(mvm, mvm_sta->vif, false, false); |
| 1146 | int i; |
| 1147 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1148 | .sta_id = mvm_sta->sta_id, |
| 1149 | .frame_limit = IWL_FRAME_LIMIT, |
| 1150 | }; |
| 1151 | |
| 1152 | /* Make sure reserved queue is still marked as such (or allocated) */ |
| 1153 | mvm->queue_info[mvm_sta->reserved_queue].status = |
| 1154 | IWL_MVM_QUEUE_RESERVED; |
| 1155 | |
| 1156 | for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { |
| 1157 | struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i]; |
| 1158 | int txq_id = tid_data->txq_id; |
| 1159 | int ac; |
| 1160 | u8 mac_queue; |
| 1161 | |
| 1162 | if (txq_id == IEEE80211_INVAL_HW_QUEUE) |
| 1163 | continue; |
| 1164 | |
| 1165 | skb_queue_head_init(&tid_data->deferred_tx_frames); |
| 1166 | |
| 1167 | ac = tid_to_mac80211_ac[i]; |
| 1168 | mac_queue = mvm_sta->vif->hw_queue[ac]; |
| 1169 | |
| 1170 | cfg.tid = i; |
| 1171 | cfg.fifo = iwl_mvm_ac_to_tx_fifo[ac]; |
| 1172 | cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE || |
| 1173 | txq_id == IWL_MVM_DQA_BSS_CLIENT_QUEUE); |
| 1174 | |
| 1175 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1176 | "Re-mapping sta %d tid %d to queue %d\n", |
| 1177 | mvm_sta->sta_id, i, txq_id); |
| 1178 | |
| 1179 | iwl_mvm_enable_txq(mvm, txq_id, mac_queue, |
| 1180 | IEEE80211_SEQ_TO_SN(tid_data->seq_number), |
| 1181 | &cfg, wdg_timeout); |
| 1182 | |
| 1183 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY; |
| 1184 | } |
| 1185 | |
| 1186 | atomic_set(&mvm->pending_frames[mvm_sta->sta_id], 0); |
| 1187 | } |
| 1188 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1189 | int iwl_mvm_add_sta(struct iwl_mvm *mvm, |
| 1190 | struct ieee80211_vif *vif, |
| 1191 | struct ieee80211_sta *sta) |
| 1192 | { |
| 1193 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1194 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1195 | struct iwl_mvm_rxq_dup_data *dup_data; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1196 | int i, ret, sta_id; |
| 1197 | |
| 1198 | lockdep_assert_held(&mvm->mutex); |
| 1199 | |
| 1200 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 1201 | sta_id = iwl_mvm_find_free_sta_id(mvm, |
| 1202 | ieee80211_vif_type_p2p(vif)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1203 | else |
| 1204 | sta_id = mvm_sta->sta_id; |
| 1205 | |
Johannes Berg | 36f4631 | 2015-03-10 20:32:08 +0100 | [diff] [blame] | 1206 | if (sta_id == IWL_MVM_STATION_COUNT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1207 | return -ENOSPC; |
| 1208 | |
| 1209 | spin_lock_init(&mvm_sta->lock); |
| 1210 | |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1211 | /* In DQA mode, if this is a HW restart, re-alloc existing queues */ |
| 1212 | if (iwl_mvm_is_dqa_supported(mvm) && |
| 1213 | test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 1214 | iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta); |
| 1215 | goto update_fw; |
| 1216 | } |
| 1217 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1218 | mvm_sta->sta_id = sta_id; |
| 1219 | mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 1220 | mvmvif->color); |
| 1221 | mvm_sta->vif = vif; |
| 1222 | mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 1223 | mvm_sta->tx_protection = 0; |
| 1224 | mvm_sta->tt_tx_protection = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1225 | |
| 1226 | /* HW restart, don't assume the memory has been zeroed */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1227 | atomic_set(&mvm->pending_frames[sta_id], 0); |
Liad Kaufman | 69191af | 2015-09-01 18:50:22 +0300 | [diff] [blame] | 1228 | mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1229 | mvm_sta->tfd_queue_msk = 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1230 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1231 | /* |
| 1232 | * Allocate new queues for a TDLS station, unless we're in DQA mode, |
| 1233 | * and then they'll be allocated dynamically |
| 1234 | */ |
| 1235 | if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) { |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1236 | ret = iwl_mvm_tdls_sta_init(mvm, sta); |
| 1237 | if (ret) |
| 1238 | return ret; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1239 | } else if (!iwl_mvm_is_dqa_supported(mvm)) { |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1240 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 1241 | if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE) |
| 1242 | mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]); |
| 1243 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1244 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1245 | /* for HW restart - reset everything but the sequence number */ |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1246 | for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1247 | u16 seq = mvm_sta->tid_data[i].seq_number; |
| 1248 | memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); |
| 1249 | mvm_sta->tid_data[i].seq_number = seq; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1250 | |
| 1251 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 1252 | continue; |
| 1253 | |
| 1254 | /* |
| 1255 | * Mark all queues for this STA as unallocated and defer TX |
| 1256 | * frames until the queue is allocated |
| 1257 | */ |
| 1258 | mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; |
| 1259 | skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1260 | } |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1261 | mvm_sta->deferred_traffic_tid_map = 0; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1262 | mvm_sta->agg_tids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1263 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1264 | if (iwl_mvm_has_new_rx_api(mvm) && |
| 1265 | !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 1266 | dup_data = kcalloc(mvm->trans->num_rx_queues, |
| 1267 | sizeof(*dup_data), |
| 1268 | GFP_KERNEL); |
| 1269 | if (!dup_data) |
| 1270 | return -ENOMEM; |
| 1271 | mvm_sta->dup_data = dup_data; |
| 1272 | } |
| 1273 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1274 | if (iwl_mvm_is_dqa_supported(mvm)) { |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1275 | ret = iwl_mvm_reserve_sta_stream(mvm, sta, |
| 1276 | ieee80211_vif_type_p2p(vif)); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1277 | if (ret) |
| 1278 | goto err; |
| 1279 | } |
| 1280 | |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1281 | update_fw: |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1282 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1283 | if (ret) |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1284 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1285 | |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 1286 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 1287 | if (!sta->tdls) { |
| 1288 | WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT); |
| 1289 | mvmvif->ap_sta_id = sta_id; |
| 1290 | } else { |
| 1291 | WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT); |
| 1292 | } |
| 1293 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1294 | |
| 1295 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); |
| 1296 | |
| 1297 | return 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1298 | |
| 1299 | err: |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1300 | if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) |
| 1301 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1302 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 1306 | bool drain) |
| 1307 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1308 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1309 | int ret; |
| 1310 | u32 status; |
| 1311 | |
| 1312 | lockdep_assert_held(&mvm->mutex); |
| 1313 | |
| 1314 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 1315 | cmd.sta_id = mvmsta->sta_id; |
| 1316 | cmd.add_modify = STA_MODE_MODIFY; |
| 1317 | cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; |
| 1318 | cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); |
| 1319 | |
| 1320 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1321 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1322 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1323 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1324 | if (ret) |
| 1325 | return ret; |
| 1326 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1327 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1328 | case ADD_STA_SUCCESS: |
| 1329 | IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", |
| 1330 | mvmsta->sta_id); |
| 1331 | break; |
| 1332 | default: |
| 1333 | ret = -EIO; |
| 1334 | IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", |
| 1335 | mvmsta->sta_id); |
| 1336 | break; |
| 1337 | } |
| 1338 | |
| 1339 | return ret; |
| 1340 | } |
| 1341 | |
| 1342 | /* |
| 1343 | * Remove a station from the FW table. Before sending the command to remove |
| 1344 | * the station validate that the station is indeed known to the driver (sanity |
| 1345 | * only). |
| 1346 | */ |
| 1347 | static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) |
| 1348 | { |
| 1349 | struct ieee80211_sta *sta; |
| 1350 | struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { |
| 1351 | .sta_id = sta_id, |
| 1352 | }; |
| 1353 | int ret; |
| 1354 | |
| 1355 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1356 | lockdep_is_held(&mvm->mutex)); |
| 1357 | |
| 1358 | /* Note: internal stations are marked as error values */ |
| 1359 | if (!sta) { |
| 1360 | IWL_ERR(mvm, "Invalid station id\n"); |
| 1361 | return -EINVAL; |
| 1362 | } |
| 1363 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1364 | ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1365 | sizeof(rm_sta_cmd), &rm_sta_cmd); |
| 1366 | if (ret) { |
| 1367 | IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); |
| 1368 | return ret; |
| 1369 | } |
| 1370 | |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
| 1374 | void iwl_mvm_sta_drained_wk(struct work_struct *wk) |
| 1375 | { |
| 1376 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk); |
| 1377 | u8 sta_id; |
| 1378 | |
| 1379 | /* |
| 1380 | * The mutex is needed because of the SYNC cmd, but not only: if the |
| 1381 | * work would run concurrently with iwl_mvm_rm_sta, it would run before |
| 1382 | * iwl_mvm_rm_sta sets the station as busy, and exit. Then |
| 1383 | * iwl_mvm_rm_sta would set the station as busy, and nobody will clean |
| 1384 | * that later. |
| 1385 | */ |
| 1386 | mutex_lock(&mvm->mutex); |
| 1387 | |
| 1388 | for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) { |
| 1389 | int ret; |
| 1390 | struct ieee80211_sta *sta = |
| 1391 | rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1392 | lockdep_is_held(&mvm->mutex)); |
| 1393 | |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 1394 | /* |
| 1395 | * This station is in use or RCU-removed; the latter happens in |
| 1396 | * managed mode, where mac80211 removes the station before we |
| 1397 | * can remove it from firmware (we can only do that after the |
| 1398 | * MAC is marked unassociated), and possibly while the deauth |
| 1399 | * frame to disconnect from the AP is still queued. Then, the |
| 1400 | * station pointer is -ENOENT when the last skb is reclaimed. |
| 1401 | */ |
| 1402 | if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1403 | continue; |
| 1404 | |
| 1405 | if (PTR_ERR(sta) == -EINVAL) { |
| 1406 | IWL_ERR(mvm, "Drained sta %d, but it is internal?\n", |
| 1407 | sta_id); |
| 1408 | continue; |
| 1409 | } |
| 1410 | |
| 1411 | if (!sta) { |
| 1412 | IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n", |
| 1413 | sta_id); |
| 1414 | continue; |
| 1415 | } |
| 1416 | |
| 1417 | WARN_ON(PTR_ERR(sta) != -EBUSY); |
| 1418 | /* This station was removed and we waited until it got drained, |
| 1419 | * we can now proceed and remove it. |
| 1420 | */ |
| 1421 | ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 1422 | if (ret) { |
| 1423 | IWL_ERR(mvm, |
| 1424 | "Couldn't remove sta %d after it was drained\n", |
| 1425 | sta_id); |
| 1426 | continue; |
| 1427 | } |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1428 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1429 | clear_bit(sta_id, mvm->sta_drained); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1430 | |
| 1431 | if (mvm->tfd_drained[sta_id]) { |
| 1432 | unsigned long i, msk = mvm->tfd_drained[sta_id]; |
| 1433 | |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 1434 | for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE) |
Arik Nemtsov | 06ecdba | 2015-10-12 14:47:11 +0300 | [diff] [blame] | 1435 | iwl_mvm_disable_txq(mvm, i, i, |
| 1436 | IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1437 | |
| 1438 | mvm->tfd_drained[sta_id] = 0; |
| 1439 | IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n", |
| 1440 | sta_id, msk); |
| 1441 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | mutex_unlock(&mvm->mutex); |
| 1445 | } |
| 1446 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1447 | static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm, |
| 1448 | struct ieee80211_vif *vif, |
| 1449 | struct iwl_mvm_sta *mvm_sta) |
| 1450 | { |
| 1451 | int ac; |
| 1452 | int i; |
| 1453 | |
| 1454 | lockdep_assert_held(&mvm->mutex); |
| 1455 | |
| 1456 | for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) { |
| 1457 | if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE) |
| 1458 | continue; |
| 1459 | |
| 1460 | ac = iwl_mvm_tid_to_ac_queue(i); |
| 1461 | iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id, |
| 1462 | vif->hw_queue[ac], i, 0); |
| 1463 | mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; |
| 1464 | } |
| 1465 | } |
| 1466 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1467 | int iwl_mvm_rm_sta(struct iwl_mvm *mvm, |
| 1468 | struct ieee80211_vif *vif, |
| 1469 | struct ieee80211_sta *sta) |
| 1470 | { |
| 1471 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1472 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1473 | int ret; |
| 1474 | |
| 1475 | lockdep_assert_held(&mvm->mutex); |
| 1476 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1477 | if (iwl_mvm_has_new_rx_api(mvm)) |
| 1478 | kfree(mvm_sta->dup_data); |
| 1479 | |
Liad Kaufman | a6f035a | 2015-08-24 15:23:14 +0300 | [diff] [blame] | 1480 | if ((vif->type == NL80211_IFTYPE_STATION && |
| 1481 | mvmvif->ap_sta_id == mvm_sta->sta_id) || |
| 1482 | iwl_mvm_is_dqa_supported(mvm)){ |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1483 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
| 1484 | if (ret) |
| 1485 | return ret; |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 1486 | /* flush its queues here since we are freeing mvm_sta */ |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 1487 | ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0); |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1488 | if (ret) |
| 1489 | return ret; |
| 1490 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 1491 | mvm_sta->tfd_queue_msk); |
| 1492 | if (ret) |
| 1493 | return ret; |
| 1494 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, false); |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 1495 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1496 | /* If DQA is supported - the queues can be disabled now */ |
Liad Kaufman | 5621474 | 2016-09-22 15:14:08 +0300 | [diff] [blame^] | 1497 | if (iwl_mvm_is_dqa_supported(mvm)) |
| 1498 | iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta); |
| 1499 | |
| 1500 | /* If there is a TXQ still marked as reserved - free it */ |
| 1501 | if (iwl_mvm_is_dqa_supported(mvm) && |
| 1502 | mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) { |
Liad Kaufman | a0315dea | 2016-07-07 13:25:59 +0300 | [diff] [blame] | 1503 | u8 reserved_txq = mvm_sta->reserved_queue; |
| 1504 | enum iwl_mvm_queue_status *status; |
| 1505 | |
Liad Kaufman | a0315dea | 2016-07-07 13:25:59 +0300 | [diff] [blame] | 1506 | /* |
| 1507 | * If no traffic has gone through the reserved TXQ - it |
| 1508 | * is still marked as IWL_MVM_QUEUE_RESERVED, and |
| 1509 | * should be manually marked as free again |
| 1510 | */ |
| 1511 | spin_lock_bh(&mvm->queue_info_lock); |
| 1512 | status = &mvm->queue_info[reserved_txq].status; |
| 1513 | if (WARN((*status != IWL_MVM_QUEUE_RESERVED) && |
| 1514 | (*status != IWL_MVM_QUEUE_FREE), |
| 1515 | "sta_id %d reserved txq %d status %d", |
| 1516 | mvm_sta->sta_id, reserved_txq, *status)) { |
| 1517 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1518 | return -EINVAL; |
| 1519 | } |
| 1520 | |
| 1521 | *status = IWL_MVM_QUEUE_FREE; |
| 1522 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1523 | } |
| 1524 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1525 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1526 | mvmvif->ap_sta_id == mvm_sta->sta_id) { |
| 1527 | /* if associated - we can't remove the AP STA now */ |
| 1528 | if (vif->bss_conf.assoc) |
| 1529 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1530 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1531 | /* unassoc - go ahead - remove the AP STA now */ |
| 1532 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 1533 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1534 | /* clear d0i3_ap_sta_id if no longer relevant */ |
| 1535 | if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id) |
| 1536 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; |
| 1537 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | /* |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 1541 | * This shouldn't happen - the TDLS channel switch should be canceled |
| 1542 | * before the STA is removed. |
| 1543 | */ |
| 1544 | if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) { |
| 1545 | mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT; |
| 1546 | cancel_delayed_work(&mvm->tdls_cs.dwork); |
| 1547 | } |
| 1548 | |
| 1549 | /* |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1550 | * Make sure that the tx response code sees the station as -EBUSY and |
| 1551 | * calls the drain worker. |
| 1552 | */ |
| 1553 | spin_lock_bh(&mvm_sta->lock); |
| 1554 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1555 | * There are frames pending on the AC queues for this station. |
| 1556 | * We need to wait until all the frames are drained... |
| 1557 | */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1558 | if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1559 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
| 1560 | ERR_PTR(-EBUSY)); |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1561 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1562 | |
| 1563 | /* disable TDLS sta queues on drain complete */ |
| 1564 | if (sta->tdls) { |
| 1565 | mvm->tfd_drained[mvm_sta->sta_id] = |
| 1566 | mvm_sta->tfd_queue_msk; |
| 1567 | IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", |
| 1568 | mvm_sta->sta_id); |
| 1569 | } |
| 1570 | |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1571 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1572 | } else { |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1573 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1574 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1575 | if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1576 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 1577 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1578 | ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1579 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | return ret; |
| 1583 | } |
| 1584 | |
| 1585 | int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, |
| 1586 | struct ieee80211_vif *vif, |
| 1587 | u8 sta_id) |
| 1588 | { |
| 1589 | int ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 1590 | |
| 1591 | lockdep_assert_held(&mvm->mutex); |
| 1592 | |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1593 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1594 | return ret; |
| 1595 | } |
| 1596 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 1597 | int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, |
| 1598 | struct iwl_mvm_int_sta *sta, |
| 1599 | u32 qmask, enum nl80211_iftype iftype) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1600 | { |
| 1601 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 1602 | sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1603 | if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT)) |
| 1604 | return -ENOSPC; |
| 1605 | } |
| 1606 | |
| 1607 | sta->tfd_queue_msk = qmask; |
| 1608 | |
| 1609 | /* put a non-NULL value so iterating over the stations won't stop */ |
| 1610 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); |
| 1611 | return 0; |
| 1612 | } |
| 1613 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 1614 | static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, |
| 1615 | struct iwl_mvm_int_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1616 | { |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1617 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1618 | memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); |
| 1619 | sta->sta_id = IWL_MVM_STATION_COUNT; |
| 1620 | } |
| 1621 | |
| 1622 | static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, |
| 1623 | struct iwl_mvm_int_sta *sta, |
| 1624 | const u8 *addr, |
| 1625 | u16 mac_id, u16 color) |
| 1626 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1627 | struct iwl_mvm_add_sta_cmd cmd; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1628 | int ret; |
| 1629 | u32 status; |
| 1630 | |
| 1631 | lockdep_assert_held(&mvm->mutex); |
| 1632 | |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1633 | memset(&cmd, 0, sizeof(cmd)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1634 | cmd.sta_id = sta->sta_id; |
| 1635 | cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, |
| 1636 | color)); |
| 1637 | |
| 1638 | cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 1639 | cmd.tid_disable_tx = cpu_to_le16(0xffff); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1640 | |
| 1641 | if (addr) |
| 1642 | memcpy(cmd.addr, addr, ETH_ALEN); |
| 1643 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1644 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1645 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1646 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1647 | if (ret) |
| 1648 | return ret; |
| 1649 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1650 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1651 | case ADD_STA_SUCCESS: |
| 1652 | IWL_DEBUG_INFO(mvm, "Internal station added.\n"); |
| 1653 | return 0; |
| 1654 | default: |
| 1655 | ret = -EIO; |
| 1656 | IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", |
| 1657 | status); |
| 1658 | break; |
| 1659 | } |
| 1660 | return ret; |
| 1661 | } |
| 1662 | |
| 1663 | int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) |
| 1664 | { |
Emmanuel Grumbach | 4cf677f | 2015-01-12 14:38:29 +0200 | [diff] [blame] | 1665 | unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ? |
| 1666 | mvm->cfg->base_params->wd_timeout : |
| 1667 | IWL_WATCHDOG_DISABLED; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1668 | int ret; |
| 1669 | |
| 1670 | lockdep_assert_held(&mvm->mutex); |
| 1671 | |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 1672 | /* Map Aux queue to fifo - needs to happen before adding Aux station */ |
Liad Kaufman | 28d0793 | 2015-09-01 16:36:25 +0300 | [diff] [blame] | 1673 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 1674 | iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue, |
| 1675 | IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout); |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 1676 | |
| 1677 | /* Allocate aux station and assign to it the aux queue */ |
| 1678 | ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue), |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 1679 | NL80211_IFTYPE_UNSPECIFIED); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1680 | if (ret) |
| 1681 | return ret; |
| 1682 | |
Liad Kaufman | 28d0793 | 2015-09-01 16:36:25 +0300 | [diff] [blame] | 1683 | if (iwl_mvm_is_dqa_supported(mvm)) { |
| 1684 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1685 | .fifo = IWL_MVM_TX_FIFO_MCAST, |
| 1686 | .sta_id = mvm->aux_sta.sta_id, |
| 1687 | .tid = IWL_MAX_TID_COUNT, |
| 1688 | .aggregate = false, |
| 1689 | .frame_limit = IWL_FRAME_LIMIT, |
| 1690 | }; |
| 1691 | |
| 1692 | iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg, |
| 1693 | wdg_timeout); |
| 1694 | } |
| 1695 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1696 | ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, |
| 1697 | MAC_INDEX_AUX, 0); |
| 1698 | |
| 1699 | if (ret) |
| 1700 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 1701 | return ret; |
| 1702 | } |
| 1703 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 1704 | int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1705 | { |
| 1706 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1707 | |
| 1708 | lockdep_assert_held(&mvm->mutex); |
| 1709 | return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr, |
| 1710 | mvmvif->id, 0); |
| 1711 | } |
| 1712 | |
| 1713 | int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1714 | { |
| 1715 | int ret; |
| 1716 | |
| 1717 | lockdep_assert_held(&mvm->mutex); |
| 1718 | |
| 1719 | ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id); |
| 1720 | if (ret) |
| 1721 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 1722 | |
| 1723 | return ret; |
| 1724 | } |
| 1725 | |
| 1726 | void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm) |
| 1727 | { |
| 1728 | iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta); |
| 1729 | } |
| 1730 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 1731 | void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm) |
| 1732 | { |
| 1733 | lockdep_assert_held(&mvm->mutex); |
| 1734 | |
| 1735 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 1736 | } |
| 1737 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1738 | /* |
| 1739 | * Send the add station command for the vif's broadcast station. |
| 1740 | * Assumes that the station was already allocated. |
| 1741 | * |
| 1742 | * @mvm: the mvm component |
| 1743 | * @vif: the interface to which the broadcast station is added |
| 1744 | * @bsta: the broadcast station to add. |
| 1745 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1746 | int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1747 | { |
| 1748 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1749 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1750 | static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
Johannes Berg | a424340 | 2014-01-20 23:46:38 +0100 | [diff] [blame] | 1751 | const u8 *baddr = _baddr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1752 | |
| 1753 | lockdep_assert_held(&mvm->mutex); |
| 1754 | |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1755 | if (iwl_mvm_is_dqa_supported(mvm)) { |
| 1756 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1757 | .fifo = IWL_MVM_TX_FIFO_VO, |
| 1758 | .sta_id = mvmvif->bcast_sta.sta_id, |
| 1759 | .tid = IWL_MAX_TID_COUNT, |
| 1760 | .aggregate = false, |
| 1761 | .frame_limit = IWL_FRAME_LIMIT, |
| 1762 | }; |
| 1763 | unsigned int wdg_timeout = |
| 1764 | iwl_mvm_get_wd_timeout(mvm, vif, false, false); |
| 1765 | int queue; |
| 1766 | |
| 1767 | if ((vif->type == NL80211_IFTYPE_AP) && |
| 1768 | (mvmvif->bcast_sta.tfd_queue_msk & |
| 1769 | BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE))) |
| 1770 | queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE; |
Liad Kaufman | 4c96513 | 2015-08-09 19:26:56 +0300 | [diff] [blame] | 1771 | else if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) && |
| 1772 | (mvmvif->bcast_sta.tfd_queue_msk & |
| 1773 | BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE))) |
| 1774 | queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE; |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1775 | else if (WARN(1, "Missed required TXQ for adding bcast STA\n")) |
| 1776 | return -EINVAL; |
| 1777 | |
| 1778 | iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, &cfg, |
| 1779 | wdg_timeout); |
| 1780 | } |
| 1781 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1782 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 1783 | baddr = vif->bss_conf.bssid; |
| 1784 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1785 | if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT)) |
| 1786 | return -ENOSPC; |
| 1787 | |
| 1788 | return iwl_mvm_add_int_sta_common(mvm, bsta, baddr, |
| 1789 | mvmvif->id, mvmvif->color); |
| 1790 | } |
| 1791 | |
| 1792 | /* Send the FW a request to remove the station from it's internal data |
| 1793 | * structures, but DO NOT remove the entry from the local data structures. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1794 | int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1795 | { |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1796 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1797 | int ret; |
| 1798 | |
| 1799 | lockdep_assert_held(&mvm->mutex); |
| 1800 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1801 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1802 | if (ret) |
| 1803 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 1804 | return ret; |
| 1805 | } |
| 1806 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1807 | int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1808 | { |
| 1809 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1810 | u32 qmask = 0; |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1811 | |
| 1812 | lockdep_assert_held(&mvm->mutex); |
| 1813 | |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1814 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 1815 | qmask = iwl_mvm_mac_get_queues_mask(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1816 | |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1817 | if (vif->type == NL80211_IFTYPE_AP) { |
| 1818 | /* |
| 1819 | * The firmware defines the TFD queue mask to only be relevant |
| 1820 | * for *unicast* queues, so the multicast (CAB) queue shouldn't |
| 1821 | * be included. |
| 1822 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1823 | qmask &= ~BIT(vif->cab_queue); |
| 1824 | |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1825 | if (iwl_mvm_is_dqa_supported(mvm)) |
| 1826 | qmask |= BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE); |
Liad Kaufman | 4c96513 | 2015-08-09 19:26:56 +0300 | [diff] [blame] | 1827 | } else if (iwl_mvm_is_dqa_supported(mvm) && |
| 1828 | vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 1829 | qmask |= BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE); |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1830 | } |
| 1831 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1832 | return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask, |
| 1833 | ieee80211_vif_type_p2p(vif)); |
| 1834 | } |
| 1835 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1836 | /* Allocate a new station entry for the broadcast station to the given vif, |
| 1837 | * and send it to the FW. |
| 1838 | * Note that each P2P mac should have its own broadcast station. |
| 1839 | * |
| 1840 | * @mvm: the mvm component |
| 1841 | * @vif: the interface to which the broadcast station is added |
| 1842 | * @bsta: the broadcast station to add. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1843 | int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1844 | { |
| 1845 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1846 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1847 | int ret; |
| 1848 | |
| 1849 | lockdep_assert_held(&mvm->mutex); |
| 1850 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1851 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1852 | if (ret) |
| 1853 | return ret; |
| 1854 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1855 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1856 | |
| 1857 | if (ret) |
| 1858 | iwl_mvm_dealloc_int_sta(mvm, bsta); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1859 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1860 | return ret; |
| 1861 | } |
| 1862 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1863 | void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1864 | { |
| 1865 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1866 | |
| 1867 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 1868 | } |
| 1869 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1870 | /* |
| 1871 | * Send the FW a request to remove the station from it's internal data |
| 1872 | * structures, and in addition remove it from the local data structure. |
| 1873 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1874 | int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1875 | { |
| 1876 | int ret; |
| 1877 | |
| 1878 | lockdep_assert_held(&mvm->mutex); |
| 1879 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1880 | ret = iwl_mvm_send_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1881 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1882 | iwl_mvm_dealloc_bcast_sta(mvm, vif); |
| 1883 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1884 | return ret; |
| 1885 | } |
| 1886 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 1887 | #define IWL_MAX_RX_BA_SESSIONS 16 |
| 1888 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1889 | static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid) |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1890 | { |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1891 | struct iwl_mvm_delba_notif notif = { |
| 1892 | .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA, |
| 1893 | .metadata.sync = 1, |
| 1894 | .delba.baid = baid, |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1895 | }; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1896 | iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif)); |
| 1897 | }; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1898 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1899 | static void iwl_mvm_free_reorder(struct iwl_mvm *mvm, |
| 1900 | struct iwl_mvm_baid_data *data) |
| 1901 | { |
| 1902 | int i; |
| 1903 | |
| 1904 | iwl_mvm_sync_rxq_del_ba(mvm, data->baid); |
| 1905 | |
| 1906 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { |
| 1907 | int j; |
| 1908 | struct iwl_mvm_reorder_buffer *reorder_buf = |
| 1909 | &data->reorder_buf[i]; |
| 1910 | |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 1911 | spin_lock_bh(&reorder_buf->lock); |
| 1912 | if (likely(!reorder_buf->num_stored)) { |
| 1913 | spin_unlock_bh(&reorder_buf->lock); |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1914 | continue; |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 1915 | } |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1916 | |
| 1917 | /* |
| 1918 | * This shouldn't happen in regular DELBA since the internal |
| 1919 | * delBA notification should trigger a release of all frames in |
| 1920 | * the reorder buffer. |
| 1921 | */ |
| 1922 | WARN_ON(1); |
| 1923 | |
| 1924 | for (j = 0; j < reorder_buf->buf_size; j++) |
| 1925 | __skb_queue_purge(&reorder_buf->entries[j]); |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 1926 | /* |
| 1927 | * Prevent timer re-arm. This prevents a very far fetched case |
| 1928 | * where we timed out on the notification. There may be prior |
| 1929 | * RX frames pending in the RX queue before the notification |
| 1930 | * that might get processed between now and the actual deletion |
| 1931 | * and we would re-arm the timer although we are deleting the |
| 1932 | * reorder buffer. |
| 1933 | */ |
| 1934 | reorder_buf->removed = true; |
| 1935 | spin_unlock_bh(&reorder_buf->lock); |
| 1936 | del_timer_sync(&reorder_buf->reorder_timer); |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm, |
| 1941 | u32 sta_id, |
| 1942 | struct iwl_mvm_baid_data *data, |
| 1943 | u16 ssn, u8 buf_size) |
| 1944 | { |
| 1945 | int i; |
| 1946 | |
| 1947 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { |
| 1948 | struct iwl_mvm_reorder_buffer *reorder_buf = |
| 1949 | &data->reorder_buf[i]; |
| 1950 | int j; |
| 1951 | |
| 1952 | reorder_buf->num_stored = 0; |
| 1953 | reorder_buf->head_sn = ssn; |
| 1954 | reorder_buf->buf_size = buf_size; |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 1955 | /* rx reorder timer */ |
| 1956 | reorder_buf->reorder_timer.function = |
| 1957 | iwl_mvm_reorder_timer_expired; |
| 1958 | reorder_buf->reorder_timer.data = (unsigned long)reorder_buf; |
| 1959 | init_timer(&reorder_buf->reorder_timer); |
| 1960 | spin_lock_init(&reorder_buf->lock); |
| 1961 | reorder_buf->mvm = mvm; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1962 | reorder_buf->queue = i; |
| 1963 | reorder_buf->sta_id = sta_id; |
| 1964 | for (j = 0; j < reorder_buf->buf_size; j++) |
| 1965 | __skb_queue_head_init(&reorder_buf->entries[j]); |
| 1966 | } |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1967 | } |
| 1968 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1969 | int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1970 | int tid, u16 ssn, bool start, u8 buf_size, u16 timeout) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1971 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1972 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1973 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1974 | struct iwl_mvm_baid_data *baid_data = NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1975 | int ret; |
| 1976 | u32 status; |
| 1977 | |
| 1978 | lockdep_assert_held(&mvm->mutex); |
| 1979 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 1980 | if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { |
| 1981 | IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); |
| 1982 | return -ENOSPC; |
| 1983 | } |
| 1984 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1985 | if (iwl_mvm_has_new_rx_api(mvm) && start) { |
| 1986 | /* |
| 1987 | * Allocate here so if allocation fails we can bail out early |
| 1988 | * before starting the BA session in the firmware |
| 1989 | */ |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1990 | baid_data = kzalloc(sizeof(*baid_data) + |
| 1991 | mvm->trans->num_rx_queues * |
| 1992 | sizeof(baid_data->reorder_buf[0]), |
| 1993 | GFP_KERNEL); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1994 | if (!baid_data) |
| 1995 | return -ENOMEM; |
| 1996 | } |
| 1997 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1998 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 1999 | cmd.sta_id = mvm_sta->sta_id; |
| 2000 | cmd.add_modify = STA_MODE_MODIFY; |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 2001 | if (start) { |
| 2002 | cmd.add_immediate_ba_tid = (u8) tid; |
| 2003 | cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2004 | cmd.rx_ba_window = cpu_to_le16((u16)buf_size); |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 2005 | } else { |
| 2006 | cmd.remove_immediate_ba_tid = (u8) tid; |
| 2007 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2008 | cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : |
| 2009 | STA_MODIFY_REMOVE_BA_TID; |
| 2010 | |
| 2011 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2012 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 2013 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2014 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2015 | if (ret) |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2016 | goto out_free; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2017 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 2018 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2019 | case ADD_STA_SUCCESS: |
Sara Sharon | 35263a0 | 2016-06-21 12:12:10 +0300 | [diff] [blame] | 2020 | IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n", |
| 2021 | start ? "start" : "stopp"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2022 | break; |
| 2023 | case ADD_STA_IMMEDIATE_BA_FAILURE: |
| 2024 | IWL_WARN(mvm, "RX BA Session refused by fw\n"); |
| 2025 | ret = -ENOSPC; |
| 2026 | break; |
| 2027 | default: |
| 2028 | ret = -EIO; |
| 2029 | IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", |
| 2030 | start ? "start" : "stopp", status); |
| 2031 | break; |
| 2032 | } |
| 2033 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2034 | if (ret) |
| 2035 | goto out_free; |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 2036 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2037 | if (start) { |
| 2038 | u8 baid; |
| 2039 | |
| 2040 | mvm->rx_ba_sessions++; |
| 2041 | |
| 2042 | if (!iwl_mvm_has_new_rx_api(mvm)) |
| 2043 | return 0; |
| 2044 | |
| 2045 | if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) { |
| 2046 | ret = -EINVAL; |
| 2047 | goto out_free; |
| 2048 | } |
| 2049 | baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >> |
| 2050 | IWL_ADD_STA_BAID_SHIFT); |
| 2051 | baid_data->baid = baid; |
| 2052 | baid_data->timeout = timeout; |
| 2053 | baid_data->last_rx = jiffies; |
Wei Yongjun | 72c240f | 2016-07-12 11:40:57 +0000 | [diff] [blame] | 2054 | setup_timer(&baid_data->session_timer, |
| 2055 | iwl_mvm_rx_agg_session_expired, |
| 2056 | (unsigned long)&mvm->baid_map[baid]); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2057 | baid_data->mvm = mvm; |
| 2058 | baid_data->tid = tid; |
| 2059 | baid_data->sta_id = mvm_sta->sta_id; |
| 2060 | |
| 2061 | mvm_sta->tid_to_baid[tid] = baid; |
| 2062 | if (timeout) |
| 2063 | mod_timer(&baid_data->session_timer, |
| 2064 | TU_TO_EXP_TIME(timeout * 2)); |
| 2065 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2066 | iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id, |
| 2067 | baid_data, ssn, buf_size); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2068 | /* |
| 2069 | * protect the BA data with RCU to cover a case where our |
| 2070 | * internal RX sync mechanism will timeout (not that it's |
| 2071 | * supposed to happen) and we will free the session data while |
| 2072 | * RX is being processed in parallel |
| 2073 | */ |
Sara Sharon | 35263a0 | 2016-06-21 12:12:10 +0300 | [diff] [blame] | 2074 | IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n", |
| 2075 | mvm_sta->sta_id, tid, baid); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2076 | WARN_ON(rcu_access_pointer(mvm->baid_map[baid])); |
| 2077 | rcu_assign_pointer(mvm->baid_map[baid], baid_data); |
Sara Sharon | 60dec52 | 2016-06-21 14:14:08 +0300 | [diff] [blame] | 2078 | } else { |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2079 | u8 baid = mvm_sta->tid_to_baid[tid]; |
| 2080 | |
Sara Sharon | 60dec52 | 2016-06-21 14:14:08 +0300 | [diff] [blame] | 2081 | if (mvm->rx_ba_sessions > 0) |
| 2082 | /* check that restart flow didn't zero the counter */ |
| 2083 | mvm->rx_ba_sessions--; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2084 | if (!iwl_mvm_has_new_rx_api(mvm)) |
| 2085 | return 0; |
| 2086 | |
| 2087 | if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID)) |
| 2088 | return -EINVAL; |
| 2089 | |
| 2090 | baid_data = rcu_access_pointer(mvm->baid_map[baid]); |
| 2091 | if (WARN_ON(!baid_data)) |
| 2092 | return -EINVAL; |
| 2093 | |
| 2094 | /* synchronize all rx queues so we can safely delete */ |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2095 | iwl_mvm_free_reorder(mvm, baid_data); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2096 | del_timer_sync(&baid_data->session_timer); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2097 | RCU_INIT_POINTER(mvm->baid_map[baid], NULL); |
| 2098 | kfree_rcu(baid_data, rcu_head); |
Sara Sharon | 35263a0 | 2016-06-21 12:12:10 +0300 | [diff] [blame] | 2099 | IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2100 | } |
| 2101 | return 0; |
| 2102 | |
| 2103 | out_free: |
| 2104 | kfree(baid_data); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2105 | return ret; |
| 2106 | } |
| 2107 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 2108 | int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 2109 | int tid, u8 queue, bool start) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2110 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 2111 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2112 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2113 | int ret; |
| 2114 | u32 status; |
| 2115 | |
| 2116 | lockdep_assert_held(&mvm->mutex); |
| 2117 | |
| 2118 | if (start) { |
| 2119 | mvm_sta->tfd_queue_msk |= BIT(queue); |
| 2120 | mvm_sta->tid_disable_agg &= ~BIT(tid); |
| 2121 | } else { |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2122 | /* In DQA-mode the queue isn't removed on agg termination */ |
| 2123 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 2124 | mvm_sta->tfd_queue_msk &= ~BIT(queue); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2125 | mvm_sta->tid_disable_agg |= BIT(tid); |
| 2126 | } |
| 2127 | |
| 2128 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 2129 | cmd.sta_id = mvm_sta->sta_id; |
| 2130 | cmd.add_modify = STA_MODE_MODIFY; |
| 2131 | cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX; |
| 2132 | cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 2133 | cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); |
| 2134 | |
| 2135 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2136 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 2137 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2138 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2139 | if (ret) |
| 2140 | return ret; |
| 2141 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 2142 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2143 | case ADD_STA_SUCCESS: |
| 2144 | break; |
| 2145 | default: |
| 2146 | ret = -EIO; |
| 2147 | IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", |
| 2148 | start ? "start" : "stopp", status); |
| 2149 | break; |
| 2150 | } |
| 2151 | |
| 2152 | return ret; |
| 2153 | } |
| 2154 | |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 2155 | const u8 tid_to_mac80211_ac[] = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2156 | IEEE80211_AC_BE, |
| 2157 | IEEE80211_AC_BK, |
| 2158 | IEEE80211_AC_BK, |
| 2159 | IEEE80211_AC_BE, |
| 2160 | IEEE80211_AC_VI, |
| 2161 | IEEE80211_AC_VI, |
| 2162 | IEEE80211_AC_VO, |
| 2163 | IEEE80211_AC_VO, |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 2164 | IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2165 | }; |
| 2166 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2167 | static const u8 tid_to_ucode_ac[] = { |
| 2168 | AC_BE, |
| 2169 | AC_BK, |
| 2170 | AC_BK, |
| 2171 | AC_BE, |
| 2172 | AC_VI, |
| 2173 | AC_VI, |
| 2174 | AC_VO, |
| 2175 | AC_VO, |
| 2176 | }; |
| 2177 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2178 | int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2179 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
| 2180 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2181 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2182 | struct iwl_mvm_tid_data *tid_data; |
| 2183 | int txq_id; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2184 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2185 | |
| 2186 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) |
| 2187 | return -EINVAL; |
| 2188 | |
| 2189 | if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { |
| 2190 | IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", |
| 2191 | mvmsta->tid_data[tid].state); |
| 2192 | return -ENXIO; |
| 2193 | } |
| 2194 | |
| 2195 | lockdep_assert_held(&mvm->mutex); |
| 2196 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 2197 | spin_lock_bh(&mvmsta->lock); |
| 2198 | |
| 2199 | /* possible race condition - we entered D0i3 while starting agg */ |
| 2200 | if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) { |
| 2201 | spin_unlock_bh(&mvmsta->lock); |
| 2202 | IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n"); |
| 2203 | return -EIO; |
| 2204 | } |
| 2205 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2206 | spin_lock(&mvm->queue_info_lock); |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2207 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2208 | /* |
| 2209 | * Note the possible cases: |
| 2210 | * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed |
| 2211 | * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free |
| 2212 | * one and mark it as reserved |
| 2213 | * 3. In DQA mode, but no traffic yet on this TID: same treatment as in |
| 2214 | * non-DQA mode, since the TXQ hasn't yet been allocated |
| 2215 | */ |
| 2216 | txq_id = mvmsta->tid_data[tid].txq_id; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2217 | if (iwl_mvm_is_dqa_supported(mvm) && |
| 2218 | unlikely(mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_SHARED)) { |
| 2219 | ret = -ENXIO; |
| 2220 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2221 | "Can't start tid %d agg on shared queue!\n", |
| 2222 | tid); |
| 2223 | goto release_locks; |
| 2224 | } else if (!iwl_mvm_is_dqa_supported(mvm) || |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2225 | mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) { |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 2226 | txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
| 2227 | mvm->first_agg_queue, |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2228 | mvm->last_agg_queue); |
| 2229 | if (txq_id < 0) { |
| 2230 | ret = txq_id; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2231 | IWL_ERR(mvm, "Failed to allocate agg queue\n"); |
| 2232 | goto release_locks; |
| 2233 | } |
| 2234 | |
| 2235 | /* TXQ hasn't yet been enabled, so mark it only as reserved */ |
| 2236 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2237 | } |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2238 | |
| 2239 | spin_unlock(&mvm->queue_info_lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2240 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2241 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2242 | "AGG for tid %d will be on queue #%d\n", |
| 2243 | tid, txq_id); |
| 2244 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2245 | tid_data = &mvmsta->tid_data[tid]; |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 2246 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2247 | tid_data->txq_id = txq_id; |
| 2248 | *ssn = tid_data->ssn; |
| 2249 | |
| 2250 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2251 | "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", |
| 2252 | mvmsta->sta_id, tid, txq_id, tid_data->ssn, |
| 2253 | tid_data->next_reclaimed); |
| 2254 | |
| 2255 | if (tid_data->ssn == tid_data->next_reclaimed) { |
| 2256 | tid_data->state = IWL_AGG_STARTING; |
| 2257 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2258 | } else { |
| 2259 | tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; |
| 2260 | } |
| 2261 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2262 | ret = 0; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2263 | goto out; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2264 | |
| 2265 | release_locks: |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2266 | spin_unlock(&mvm->queue_info_lock); |
| 2267 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2268 | spin_unlock_bh(&mvmsta->lock); |
| 2269 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2270 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 2274 | struct ieee80211_sta *sta, u16 tid, u8 buf_size, |
| 2275 | bool amsdu) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2276 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2277 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2278 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 2279 | unsigned int wdg_timeout = |
| 2280 | iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false); |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 2281 | int queue, ret; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2282 | bool alloc_queue = true; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2283 | enum iwl_mvm_queue_status queue_status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2284 | u16 ssn; |
| 2285 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 2286 | struct iwl_trans_txq_scd_cfg cfg = { |
| 2287 | .sta_id = mvmsta->sta_id, |
| 2288 | .tid = tid, |
| 2289 | .frame_limit = buf_size, |
| 2290 | .aggregate = true, |
| 2291 | }; |
| 2292 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2293 | BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE) |
| 2294 | != IWL_MAX_TID_COUNT); |
| 2295 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2296 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); |
| 2297 | |
| 2298 | spin_lock_bh(&mvmsta->lock); |
| 2299 | ssn = tid_data->ssn; |
| 2300 | queue = tid_data->txq_id; |
| 2301 | tid_data->state = IWL_AGG_ON; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2302 | mvmsta->agg_tids |= BIT(tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2303 | tid_data->ssn = 0xffff; |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 2304 | tid_data->amsdu_in_ampdu_allowed = amsdu; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2305 | spin_unlock_bh(&mvmsta->lock); |
| 2306 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 2307 | cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2308 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2309 | spin_lock_bh(&mvm->queue_info_lock); |
| 2310 | queue_status = mvm->queue_info[queue].status; |
| 2311 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2312 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2313 | /* In DQA mode, the existing queue might need to be reconfigured */ |
| 2314 | if (iwl_mvm_is_dqa_supported(mvm)) { |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2315 | /* Maybe there is no need to even alloc a queue... */ |
| 2316 | if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY) |
| 2317 | alloc_queue = false; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2318 | |
| 2319 | /* |
| 2320 | * Only reconfig the SCD for the queue if the window size has |
| 2321 | * changed from current (become smaller) |
| 2322 | */ |
| 2323 | if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) { |
| 2324 | /* |
| 2325 | * If reconfiguring an existing queue, it first must be |
| 2326 | * drained |
| 2327 | */ |
| 2328 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 2329 | BIT(queue)); |
| 2330 | if (ret) { |
| 2331 | IWL_ERR(mvm, |
| 2332 | "Error draining queue before reconfig\n"); |
| 2333 | return ret; |
| 2334 | } |
| 2335 | |
| 2336 | ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo, |
| 2337 | mvmsta->sta_id, tid, |
| 2338 | buf_size, ssn); |
| 2339 | if (ret) { |
| 2340 | IWL_ERR(mvm, |
| 2341 | "Error reconfiguring TXQ #%d\n", queue); |
| 2342 | return ret; |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | if (alloc_queue) |
| 2348 | iwl_mvm_enable_txq(mvm, queue, |
| 2349 | vif->hw_queue[tid_to_mac80211_ac[tid]], ssn, |
| 2350 | &cfg, wdg_timeout); |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 2351 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2352 | /* Send ADD_STA command to enable aggs only if the queue isn't shared */ |
| 2353 | if (queue_status != IWL_MVM_QUEUE_SHARED) { |
| 2354 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 2355 | if (ret) |
| 2356 | return -EIO; |
| 2357 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2358 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2359 | /* No need to mark as reserved */ |
| 2360 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2361 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2362 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2363 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2364 | /* |
| 2365 | * Even though in theory the peer could have different |
| 2366 | * aggregation reorder buffer sizes for different sessions, |
| 2367 | * our ucode doesn't allow for that and has a global limit |
| 2368 | * for each station. Therefore, use the minimum of all the |
| 2369 | * aggregation sessions and our default value. |
| 2370 | */ |
| 2371 | mvmsta->max_agg_bufsize = |
| 2372 | min(mvmsta->max_agg_bufsize, buf_size); |
| 2373 | mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; |
| 2374 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2375 | IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", |
| 2376 | sta->addr, tid); |
| 2377 | |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 2378 | return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2382 | struct ieee80211_sta *sta, u16 tid) |
| 2383 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2384 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2385 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 2386 | u16 txq_id; |
| 2387 | int err; |
| 2388 | |
Emmanuel Grumbach | f9aa8dd | 2013-03-04 09:11:08 +0200 | [diff] [blame] | 2389 | /* |
| 2390 | * If mac80211 is cleaning its state, then say that we finished since |
| 2391 | * our state has been cleared anyway. |
| 2392 | */ |
| 2393 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 2394 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2395 | return 0; |
| 2396 | } |
| 2397 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2398 | spin_lock_bh(&mvmsta->lock); |
| 2399 | |
| 2400 | txq_id = tid_data->txq_id; |
| 2401 | |
| 2402 | IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", |
| 2403 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
| 2404 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2405 | mvmsta->agg_tids &= ~BIT(tid); |
| 2406 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2407 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2408 | /* |
| 2409 | * The TXQ is marked as reserved only if no traffic came through yet |
| 2410 | * This means no traffic has been sent on this TID (agg'd or not), so |
| 2411 | * we no longer have use for the queue. Since it hasn't even been |
| 2412 | * allocated through iwl_mvm_enable_txq, so we can just mark it back as |
| 2413 | * free. |
| 2414 | */ |
| 2415 | if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) |
| 2416 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2417 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2418 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2419 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2420 | switch (tid_data->state) { |
| 2421 | case IWL_AGG_ON: |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 2422 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2423 | |
| 2424 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2425 | "ssn = %d, next_recl = %d\n", |
| 2426 | tid_data->ssn, tid_data->next_reclaimed); |
| 2427 | |
| 2428 | /* There are still packets for this RA / TID in the HW */ |
| 2429 | if (tid_data->ssn != tid_data->next_reclaimed) { |
| 2430 | tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA; |
| 2431 | err = 0; |
| 2432 | break; |
| 2433 | } |
| 2434 | |
| 2435 | tid_data->ssn = 0xffff; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2436 | tid_data->state = IWL_AGG_OFF; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2437 | spin_unlock_bh(&mvmsta->lock); |
| 2438 | |
| 2439 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2440 | |
| 2441 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 2442 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2443 | if (!iwl_mvm_is_dqa_supported(mvm)) { |
| 2444 | int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; |
| 2445 | |
| 2446 | iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0); |
| 2447 | } |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2448 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2449 | case IWL_AGG_STARTING: |
| 2450 | case IWL_EMPTYING_HW_QUEUE_ADDBA: |
| 2451 | /* |
| 2452 | * The agg session has been stopped before it was set up. This |
| 2453 | * can happen when the AddBA timer times out for example. |
| 2454 | */ |
| 2455 | |
| 2456 | /* No barriers since we are under mutex */ |
| 2457 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2458 | |
| 2459 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2460 | tid_data->state = IWL_AGG_OFF; |
| 2461 | err = 0; |
| 2462 | break; |
| 2463 | default: |
| 2464 | IWL_ERR(mvm, |
| 2465 | "Stopping AGG while state not ON or starting for %d on %d (%d)\n", |
| 2466 | mvmsta->sta_id, tid, tid_data->state); |
| 2467 | IWL_ERR(mvm, |
| 2468 | "\ttid_data->txq_id = %d\n", tid_data->txq_id); |
| 2469 | err = -EINVAL; |
| 2470 | } |
| 2471 | |
| 2472 | spin_unlock_bh(&mvmsta->lock); |
| 2473 | |
| 2474 | return err; |
| 2475 | } |
| 2476 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2477 | int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2478 | struct ieee80211_sta *sta, u16 tid) |
| 2479 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2480 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2481 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 2482 | u16 txq_id; |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2483 | enum iwl_mvm_agg_state old_state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2484 | |
| 2485 | /* |
| 2486 | * First set the agg state to OFF to avoid calling |
| 2487 | * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. |
| 2488 | */ |
| 2489 | spin_lock_bh(&mvmsta->lock); |
| 2490 | txq_id = tid_data->txq_id; |
| 2491 | IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", |
| 2492 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2493 | old_state = tid_data->state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2494 | tid_data->state = IWL_AGG_OFF; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2495 | mvmsta->agg_tids &= ~BIT(tid); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2496 | spin_unlock_bh(&mvmsta->lock); |
| 2497 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2498 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2499 | /* |
| 2500 | * The TXQ is marked as reserved only if no traffic came through yet |
| 2501 | * This means no traffic has been sent on this TID (agg'd or not), so |
| 2502 | * we no longer have use for the queue. Since it hasn't even been |
| 2503 | * allocated through iwl_mvm_enable_txq, so we can just mark it back as |
| 2504 | * free. |
| 2505 | */ |
| 2506 | if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) |
| 2507 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2508 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2509 | |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2510 | if (old_state >= IWL_AGG_ON) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 2511 | iwl_mvm_drain_sta(mvm, mvmsta, true); |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 2512 | if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0)) |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2513 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 2514 | iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 2515 | mvmsta->tfd_queue_msk); |
| 2516 | iwl_mvm_drain_sta(mvm, mvmsta, false); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2517 | |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2518 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 2519 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2520 | if (!iwl_mvm_is_dqa_supported(mvm)) { |
| 2521 | int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; |
| 2522 | |
| 2523 | iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue, |
| 2524 | tid, 0); |
| 2525 | } |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2526 | } |
| 2527 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2528 | return 0; |
| 2529 | } |
| 2530 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2531 | static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) |
| 2532 | { |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2533 | int i, max = -1, max_offs = -1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2534 | |
| 2535 | lockdep_assert_held(&mvm->mutex); |
| 2536 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2537 | /* Pick the unused key offset with the highest 'deleted' |
| 2538 | * counter. Every time a key is deleted, all the counters |
| 2539 | * are incremented and the one that was just deleted is |
| 2540 | * reset to zero. Thus, the highest counter is the one |
| 2541 | * that was deleted longest ago. Pick that one. |
| 2542 | */ |
| 2543 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 2544 | if (test_bit(i, mvm->fw_key_table)) |
| 2545 | continue; |
| 2546 | if (mvm->fw_key_deleted[i] > max) { |
| 2547 | max = mvm->fw_key_deleted[i]; |
| 2548 | max_offs = i; |
| 2549 | } |
| 2550 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2551 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2552 | if (max_offs < 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2553 | return STA_KEY_IDX_INVALID; |
| 2554 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2555 | return max_offs; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2556 | } |
| 2557 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2558 | static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm, |
| 2559 | struct ieee80211_vif *vif, |
| 2560 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2561 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 2562 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2563 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2564 | if (sta) |
| 2565 | return iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2566 | |
| 2567 | /* |
| 2568 | * The device expects GTKs for station interfaces to be |
| 2569 | * installed as GTKs for the AP station. If we have no |
| 2570 | * station ID, then use AP's station ID. |
| 2571 | */ |
| 2572 | if (vif->type == NL80211_IFTYPE_STATION && |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2573 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 2574 | u8 sta_id = mvmvif->ap_sta_id; |
| 2575 | |
Emmanuel Grumbach | 7d6a1ab | 2016-05-15 10:20:29 +0300 | [diff] [blame] | 2576 | sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id], |
| 2577 | lockdep_is_held(&mvm->mutex)); |
| 2578 | |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2579 | /* |
| 2580 | * It is possible that the 'sta' parameter is NULL, |
| 2581 | * for example when a GTK is removed - the sta_id will then |
| 2582 | * be the AP ID, and no station was passed by mac80211. |
| 2583 | */ |
Emmanuel Grumbach | 7d6a1ab | 2016-05-15 10:20:29 +0300 | [diff] [blame] | 2584 | if (IS_ERR_OR_NULL(sta)) |
| 2585 | return NULL; |
| 2586 | |
| 2587 | return iwl_mvm_sta_from_mac80211(sta); |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2588 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2589 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2590 | return NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, |
| 2594 | struct iwl_mvm_sta *mvm_sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2595 | struct ieee80211_key_conf *keyconf, bool mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2596 | u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags, |
| 2597 | u8 key_offset) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2598 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2599 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2600 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 2601 | int ret; |
| 2602 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2603 | u16 keyidx; |
| 2604 | int i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2605 | u8 sta_id = mvm_sta->sta_id; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2606 | |
| 2607 | keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 2608 | STA_KEY_FLG_KEYID_MSK; |
| 2609 | key_flags = cpu_to_le16(keyidx); |
| 2610 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); |
| 2611 | |
| 2612 | switch (keyconf->cipher) { |
| 2613 | case WLAN_CIPHER_SUITE_TKIP: |
| 2614 | key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2615 | cmd.tkip_rx_tsc_byte2 = tkip_iv32; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2616 | for (i = 0; i < 5; i++) |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2617 | cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); |
| 2618 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2619 | break; |
| 2620 | case WLAN_CIPHER_SUITE_CCMP: |
| 2621 | key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2622 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2623 | break; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2624 | case WLAN_CIPHER_SUITE_WEP104: |
| 2625 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES); |
John W. Linville | aa0cb08 | 2015-01-12 16:18:11 -0500 | [diff] [blame] | 2626 | /* fall through */ |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2627 | case WLAN_CIPHER_SUITE_WEP40: |
| 2628 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP); |
| 2629 | memcpy(cmd.key + 3, keyconf->key, keyconf->keylen); |
| 2630 | break; |
Ayala Beker | 2a53d16 | 2016-04-07 16:21:57 +0300 | [diff] [blame] | 2631 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 2632 | key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES); |
| 2633 | /* fall through */ |
| 2634 | case WLAN_CIPHER_SUITE_GCMP: |
| 2635 | key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP); |
| 2636 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
| 2637 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2638 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 2639 | key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); |
| 2640 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2641 | } |
| 2642 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2643 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2644 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 2645 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2646 | cmd.key_offset = key_offset; |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2647 | cmd.key_flags = key_flags; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2648 | cmd.sta_id = sta_id; |
| 2649 | |
| 2650 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2651 | if (cmd_flags & CMD_ASYNC) |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2652 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, |
| 2653 | sizeof(cmd), &cmd); |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2654 | else |
| 2655 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 2656 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2657 | |
| 2658 | switch (status) { |
| 2659 | case ADD_STA_SUCCESS: |
| 2660 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); |
| 2661 | break; |
| 2662 | default: |
| 2663 | ret = -EIO; |
| 2664 | IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); |
| 2665 | break; |
| 2666 | } |
| 2667 | |
| 2668 | return ret; |
| 2669 | } |
| 2670 | |
| 2671 | static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, |
| 2672 | struct ieee80211_key_conf *keyconf, |
| 2673 | u8 sta_id, bool remove_key) |
| 2674 | { |
| 2675 | struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; |
| 2676 | |
| 2677 | /* verify the key details match the required command's expectations */ |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2678 | if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || |
| 2679 | (keyconf->keyidx != 4 && keyconf->keyidx != 5) || |
| 2680 | (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC && |
| 2681 | keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 && |
| 2682 | keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256))) |
| 2683 | return -EINVAL; |
| 2684 | |
| 2685 | if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) && |
| 2686 | keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2687 | return -EINVAL; |
| 2688 | |
| 2689 | igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); |
| 2690 | igtk_cmd.sta_id = cpu_to_le32(sta_id); |
| 2691 | |
| 2692 | if (remove_key) { |
| 2693 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); |
| 2694 | } else { |
| 2695 | struct ieee80211_key_seq seq; |
| 2696 | const u8 *pn; |
| 2697 | |
Ayala Beker | aa95052 | 2016-06-01 00:28:09 +0300 | [diff] [blame] | 2698 | switch (keyconf->cipher) { |
| 2699 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 2700 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM); |
| 2701 | break; |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2702 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 2703 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 2704 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP); |
| 2705 | break; |
Ayala Beker | aa95052 | 2016-06-01 00:28:09 +0300 | [diff] [blame] | 2706 | default: |
| 2707 | return -EINVAL; |
| 2708 | } |
| 2709 | |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2710 | memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen); |
| 2711 | if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) |
| 2712 | igtk_cmd.ctrl_flags |= |
| 2713 | cpu_to_le32(STA_KEY_FLG_KEY_32BYTES); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2714 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 2715 | pn = seq.aes_cmac.pn; |
| 2716 | igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | |
| 2717 | ((u64) pn[4] << 8) | |
| 2718 | ((u64) pn[3] << 16) | |
| 2719 | ((u64) pn[2] << 24) | |
| 2720 | ((u64) pn[1] << 32) | |
| 2721 | ((u64) pn[0] << 40)); |
| 2722 | } |
| 2723 | |
| 2724 | IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", |
| 2725 | remove_key ? "removing" : "installing", |
| 2726 | igtk_cmd.sta_id); |
| 2727 | |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2728 | if (!iwl_mvm_has_new_rx_api(mvm)) { |
| 2729 | struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = { |
| 2730 | .ctrl_flags = igtk_cmd.ctrl_flags, |
| 2731 | .key_id = igtk_cmd.key_id, |
| 2732 | .sta_id = igtk_cmd.sta_id, |
| 2733 | .receive_seq_cnt = igtk_cmd.receive_seq_cnt |
| 2734 | }; |
| 2735 | |
| 2736 | memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk, |
| 2737 | ARRAY_SIZE(igtk_cmd_v1.igtk)); |
| 2738 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
| 2739 | sizeof(igtk_cmd_v1), &igtk_cmd_v1); |
| 2740 | } |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2741 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2742 | sizeof(igtk_cmd), &igtk_cmd); |
| 2743 | } |
| 2744 | |
| 2745 | |
| 2746 | static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, |
| 2747 | struct ieee80211_vif *vif, |
| 2748 | struct ieee80211_sta *sta) |
| 2749 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 2750 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2751 | |
| 2752 | if (sta) |
| 2753 | return sta->addr; |
| 2754 | |
| 2755 | if (vif->type == NL80211_IFTYPE_STATION && |
| 2756 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 2757 | u8 sta_id = mvmvif->ap_sta_id; |
| 2758 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 2759 | lockdep_is_held(&mvm->mutex)); |
| 2760 | return sta->addr; |
| 2761 | } |
| 2762 | |
| 2763 | |
| 2764 | return NULL; |
| 2765 | } |
| 2766 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2767 | static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 2768 | struct ieee80211_vif *vif, |
| 2769 | struct ieee80211_sta *sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2770 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2771 | u8 key_offset, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2772 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2773 | { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2774 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2775 | int ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2776 | const u8 *addr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2777 | struct ieee80211_key_seq seq; |
| 2778 | u16 p1k[5]; |
| 2779 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2780 | switch (keyconf->cipher) { |
| 2781 | case WLAN_CIPHER_SUITE_TKIP: |
| 2782 | addr = iwl_mvm_get_mac_addr(mvm, vif, sta); |
| 2783 | /* get phase 1 key from mac80211 */ |
| 2784 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 2785 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2786 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2787 | seq.tkip.iv32, p1k, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2788 | break; |
| 2789 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2790 | case WLAN_CIPHER_SUITE_WEP40: |
| 2791 | case WLAN_CIPHER_SUITE_WEP104: |
Ayala Beker | 2a53d16 | 2016-04-07 16:21:57 +0300 | [diff] [blame] | 2792 | case WLAN_CIPHER_SUITE_GCMP: |
| 2793 | case WLAN_CIPHER_SUITE_GCMP_256: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2794 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2795 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2796 | break; |
| 2797 | default: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2798 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2799 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2800 | } |
| 2801 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2802 | return ret; |
| 2803 | } |
| 2804 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2805 | static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2806 | struct ieee80211_key_conf *keyconf, |
| 2807 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2808 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2809 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2810 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 2811 | int ret; |
| 2812 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2813 | |
Emmanuel Grumbach | 8115efb | 2013-02-05 10:08:35 +0200 | [diff] [blame] | 2814 | key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 2815 | STA_KEY_FLG_KEYID_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2816 | key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); |
| 2817 | key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); |
| 2818 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2819 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2820 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 2821 | |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2822 | cmd.key_flags = key_flags; |
| 2823 | cmd.key_offset = keyconf->hw_key_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2824 | cmd.sta_id = sta_id; |
| 2825 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2826 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2827 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 2828 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2829 | |
| 2830 | switch (status) { |
| 2831 | case ADD_STA_SUCCESS: |
| 2832 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); |
| 2833 | break; |
| 2834 | default: |
| 2835 | ret = -EIO; |
| 2836 | IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); |
| 2837 | break; |
| 2838 | } |
| 2839 | |
| 2840 | return ret; |
| 2841 | } |
| 2842 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2843 | int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 2844 | struct ieee80211_vif *vif, |
| 2845 | struct ieee80211_sta *sta, |
| 2846 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2847 | u8 key_offset) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2848 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2849 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2850 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2851 | u8 sta_id; |
| 2852 | int ret; |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 2853 | static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0}; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2854 | |
| 2855 | lockdep_assert_held(&mvm->mutex); |
| 2856 | |
| 2857 | /* Get the station id from the mvm local station table */ |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2858 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 2859 | if (!mvm_sta) { |
| 2860 | IWL_ERR(mvm, "Failed to find station\n"); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2861 | return -EINVAL; |
| 2862 | } |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2863 | sta_id = mvm_sta->sta_id; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2864 | |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2865 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
| 2866 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || |
| 2867 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2868 | ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false); |
| 2869 | goto end; |
| 2870 | } |
| 2871 | |
| 2872 | /* |
| 2873 | * It is possible that the 'sta' parameter is NULL, and thus |
| 2874 | * there is a need to retrieve the sta from the local station table. |
| 2875 | */ |
| 2876 | if (!sta) { |
| 2877 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 2878 | lockdep_is_held(&mvm->mutex)); |
| 2879 | if (IS_ERR_OR_NULL(sta)) { |
| 2880 | IWL_ERR(mvm, "Invalid station id\n"); |
| 2881 | return -EINVAL; |
| 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif)) |
| 2886 | return -EINVAL; |
| 2887 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2888 | /* If the key_offset is not pre-assigned, we need to find a |
| 2889 | * new offset to use. In normal cases, the offset is not |
| 2890 | * pre-assigned, but during HW_RESTART we want to reuse the |
| 2891 | * same indices, so we pass them when this function is called. |
| 2892 | * |
| 2893 | * In D3 entry, we need to hardcoded the indices (because the |
| 2894 | * firmware hardcodes the PTK offset to 0). In this case, we |
| 2895 | * need to make sure we don't overwrite the hw_key_idx in the |
| 2896 | * keyconf structure, because otherwise we cannot configure |
| 2897 | * the original ones back when resuming. |
| 2898 | */ |
| 2899 | if (key_offset == STA_KEY_IDX_INVALID) { |
| 2900 | key_offset = iwl_mvm_set_fw_key_idx(mvm); |
| 2901 | if (key_offset == STA_KEY_IDX_INVALID) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2902 | return -ENOSPC; |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2903 | keyconf->hw_key_idx = key_offset; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2904 | } |
| 2905 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2906 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast); |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 2907 | if (ret) |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2908 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2909 | |
| 2910 | /* |
| 2911 | * For WEP, the same key is used for multicast and unicast. Upload it |
| 2912 | * again, using the same key offset, and now pointing the other one |
| 2913 | * to the same key slot (offset). |
| 2914 | * If this fails, remove the original as well. |
| 2915 | */ |
| 2916 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 2917 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) { |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2918 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, |
| 2919 | key_offset, !mcast); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2920 | if (ret) { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2921 | __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 2922 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2923 | } |
| 2924 | } |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2925 | |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 2926 | __set_bit(key_offset, mvm->fw_key_table); |
| 2927 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2928 | end: |
| 2929 | IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", |
| 2930 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 2931 | sta ? sta->addr : zero_addr, ret); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2932 | return ret; |
| 2933 | } |
| 2934 | |
| 2935 | int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, |
| 2936 | struct ieee80211_vif *vif, |
| 2937 | struct ieee80211_sta *sta, |
| 2938 | struct ieee80211_key_conf *keyconf) |
| 2939 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2940 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2941 | struct iwl_mvm_sta *mvm_sta; |
| 2942 | u8 sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2943 | int ret, i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2944 | |
| 2945 | lockdep_assert_held(&mvm->mutex); |
| 2946 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2947 | /* Get the station from the mvm local station table */ |
| 2948 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2949 | |
| 2950 | IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", |
| 2951 | keyconf->keyidx, sta_id); |
| 2952 | |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2953 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
| 2954 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || |
| 2955 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2956 | return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); |
| 2957 | |
| 2958 | if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) { |
| 2959 | IWL_ERR(mvm, "offset %d not used in fw key table.\n", |
| 2960 | keyconf->hw_key_idx); |
| 2961 | return -ENOENT; |
| 2962 | } |
| 2963 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2964 | /* track which key was deleted last */ |
| 2965 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 2966 | if (mvm->fw_key_deleted[i] < U8_MAX) |
| 2967 | mvm->fw_key_deleted[i]++; |
| 2968 | } |
| 2969 | mvm->fw_key_deleted[keyconf->hw_key_idx] = 0; |
| 2970 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2971 | if (!mvm_sta) { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2972 | IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); |
| 2973 | return 0; |
| 2974 | } |
| 2975 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2976 | sta_id = mvm_sta->sta_id; |
| 2977 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2978 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
| 2979 | if (ret) |
| 2980 | return ret; |
| 2981 | |
| 2982 | /* delete WEP key twice to get rid of (now useless) offset */ |
| 2983 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 2984 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 2985 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast); |
| 2986 | |
| 2987 | return ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2988 | } |
| 2989 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2990 | void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, |
| 2991 | struct ieee80211_vif *vif, |
| 2992 | struct ieee80211_key_conf *keyconf, |
| 2993 | struct ieee80211_sta *sta, u32 iv32, |
| 2994 | u16 *phase1key) |
| 2995 | { |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 2996 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2997 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2998 | |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 2999 | rcu_read_lock(); |
| 3000 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 3001 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 3002 | if (WARN_ON_ONCE(!mvm_sta)) |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 3003 | goto unlock; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3004 | iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3005 | iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx); |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 3006 | |
| 3007 | unlock: |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 3008 | rcu_read_unlock(); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3009 | } |
| 3010 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3011 | void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, |
| 3012 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3013 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 3014 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 3015 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3016 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3017 | .sta_id = mvmsta->sta_id, |
Emmanuel Grumbach | 5af0177 | 2013-06-09 12:59:24 +0300 | [diff] [blame] | 3018 | .station_flags_msk = cpu_to_le32(STA_FLG_PS), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3019 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3020 | }; |
| 3021 | int ret; |
| 3022 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 3023 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 3024 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3025 | if (ret) |
| 3026 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3027 | } |
| 3028 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3029 | void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, |
| 3030 | struct ieee80211_sta *sta, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3031 | enum ieee80211_frame_release_type reason, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3032 | u16 cnt, u16 tids, bool more_data, |
| 3033 | bool agg) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3034 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 3035 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 3036 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3037 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3038 | .sta_id = mvmsta->sta_id, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3039 | .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, |
| 3040 | .sleep_tx_count = cpu_to_le16(cnt), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3041 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3042 | }; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3043 | int tid, ret; |
| 3044 | unsigned long _tids = tids; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3045 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3046 | /* convert TIDs to ACs - we don't support TSPEC so that's OK |
| 3047 | * Note that this field is reserved and unused by firmware not |
| 3048 | * supporting GO uAPSD, so it's safe to always do this. |
| 3049 | */ |
| 3050 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) |
| 3051 | cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); |
| 3052 | |
| 3053 | /* If we're releasing frames from aggregation queues then check if the |
| 3054 | * all queues combined that we're releasing frames from have |
| 3055 | * - more frames than the service period, in which case more_data |
| 3056 | * needs to be set |
| 3057 | * - fewer than 'cnt' frames, in which case we need to adjust the |
| 3058 | * firmware command (but do that unconditionally) |
| 3059 | */ |
| 3060 | if (agg) { |
| 3061 | int remaining = cnt; |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 3062 | int sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3063 | |
| 3064 | spin_lock_bh(&mvmsta->lock); |
| 3065 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { |
| 3066 | struct iwl_mvm_tid_data *tid_data; |
| 3067 | u16 n_queued; |
| 3068 | |
| 3069 | tid_data = &mvmsta->tid_data[tid]; |
| 3070 | if (WARN(tid_data->state != IWL_AGG_ON && |
| 3071 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA, |
| 3072 | "TID %d state is %d\n", |
| 3073 | tid, tid_data->state)) { |
| 3074 | spin_unlock_bh(&mvmsta->lock); |
| 3075 | ieee80211_sta_eosp(sta); |
| 3076 | return; |
| 3077 | } |
| 3078 | |
| 3079 | n_queued = iwl_mvm_tid_queued(tid_data); |
| 3080 | if (n_queued > remaining) { |
| 3081 | more_data = true; |
| 3082 | remaining = 0; |
| 3083 | break; |
| 3084 | } |
| 3085 | remaining -= n_queued; |
| 3086 | } |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 3087 | sleep_tx_count = cnt - remaining; |
| 3088 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) |
| 3089 | mvmsta->sleep_tx_count = sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3090 | spin_unlock_bh(&mvmsta->lock); |
| 3091 | |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 3092 | cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3093 | if (WARN_ON(cnt - remaining == 0)) { |
| 3094 | ieee80211_sta_eosp(sta); |
| 3095 | return; |
| 3096 | } |
| 3097 | } |
| 3098 | |
| 3099 | /* Note: this is ignored by firmware not supporting GO uAPSD */ |
| 3100 | if (more_data) |
| 3101 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA); |
| 3102 | |
| 3103 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { |
| 3104 | mvmsta->next_status_eosp = true; |
| 3105 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL); |
| 3106 | } else { |
| 3107 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD); |
| 3108 | } |
| 3109 | |
Emmanuel Grumbach | 156f92f | 2015-11-24 14:55:18 +0200 | [diff] [blame] | 3110 | /* block the Tx queues until the FW updated the sleep Tx count */ |
| 3111 | iwl_trans_block_txq_ptrs(mvm->trans, true); |
| 3112 | |
| 3113 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, |
| 3114 | CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK, |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 3115 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3116 | if (ret) |
| 3117 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3118 | } |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3119 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 3120 | void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, |
| 3121 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3122 | { |
| 3123 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 3124 | struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; |
| 3125 | struct ieee80211_sta *sta; |
| 3126 | u32 sta_id = le32_to_cpu(notif->sta_id); |
| 3127 | |
| 3128 | if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 3129 | return; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3130 | |
| 3131 | rcu_read_lock(); |
| 3132 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 3133 | if (!IS_ERR_OR_NULL(sta)) |
| 3134 | ieee80211_sta_eosp(sta); |
| 3135 | rcu_read_unlock(); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3136 | } |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 3137 | |
| 3138 | void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm, |
| 3139 | struct iwl_mvm_sta *mvmsta, bool disable) |
| 3140 | { |
| 3141 | struct iwl_mvm_add_sta_cmd cmd = { |
| 3142 | .add_modify = STA_MODE_MODIFY, |
| 3143 | .sta_id = mvmsta->sta_id, |
| 3144 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, |
| 3145 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), |
| 3146 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
| 3147 | }; |
| 3148 | int ret; |
| 3149 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 3150 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 3151 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 3152 | if (ret) |
| 3153 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3154 | } |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3155 | |
| 3156 | void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm, |
| 3157 | struct ieee80211_sta *sta, |
| 3158 | bool disable) |
| 3159 | { |
| 3160 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 3161 | |
| 3162 | spin_lock_bh(&mvm_sta->lock); |
| 3163 | |
| 3164 | if (mvm_sta->disable_tx == disable) { |
| 3165 | spin_unlock_bh(&mvm_sta->lock); |
| 3166 | return; |
| 3167 | } |
| 3168 | |
| 3169 | mvm_sta->disable_tx = disable; |
| 3170 | |
| 3171 | /* |
Sara Sharon | 0d365ae | 2015-03-31 12:24:05 +0300 | [diff] [blame] | 3172 | * Tell mac80211 to start/stop queuing tx for this station, |
| 3173 | * but don't stop queuing if there are still pending frames |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3174 | * for this station. |
| 3175 | */ |
| 3176 | if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) |
| 3177 | ieee80211_sta_block_awake(mvm->hw, sta, disable); |
| 3178 | |
| 3179 | iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable); |
| 3180 | |
| 3181 | spin_unlock_bh(&mvm_sta->lock); |
| 3182 | } |
| 3183 | |
| 3184 | void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm, |
| 3185 | struct iwl_mvm_vif *mvmvif, |
| 3186 | bool disable) |
| 3187 | { |
| 3188 | struct ieee80211_sta *sta; |
| 3189 | struct iwl_mvm_sta *mvm_sta; |
| 3190 | int i; |
| 3191 | |
| 3192 | lockdep_assert_held(&mvm->mutex); |
| 3193 | |
| 3194 | /* Block/unblock all the stations of the given mvmvif */ |
| 3195 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 3196 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 3197 | lockdep_is_held(&mvm->mutex)); |
| 3198 | if (IS_ERR_OR_NULL(sta)) |
| 3199 | continue; |
| 3200 | |
| 3201 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 3202 | if (mvm_sta->mac_id_n_color != |
| 3203 | FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)) |
| 3204 | continue; |
| 3205 | |
| 3206 | iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable); |
| 3207 | } |
| 3208 | } |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 3209 | |
| 3210 | void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 3211 | { |
| 3212 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 3213 | struct iwl_mvm_sta *mvmsta; |
| 3214 | |
| 3215 | rcu_read_lock(); |
| 3216 | |
| 3217 | mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id); |
| 3218 | |
| 3219 | if (!WARN_ON(!mvmsta)) |
| 3220 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true); |
| 3221 | |
| 3222 | rcu_read_unlock(); |
| 3223 | } |