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