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