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