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 | |
| 896 | /* allocate new queues for a TDLS station */ |
| 897 | if (sta->tdls) { |
| 898 | ret = iwl_mvm_tdls_sta_init(mvm, sta); |
| 899 | if (ret) |
| 900 | return ret; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 901 | } else if (!iwl_mvm_is_dqa_supported(mvm)) { |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 902 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 903 | if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE) |
| 904 | mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]); |
| 905 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 906 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 907 | /* for HW restart - reset everything but the sequence number */ |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 908 | for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 909 | u16 seq = mvm_sta->tid_data[i].seq_number; |
| 910 | memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); |
| 911 | mvm_sta->tid_data[i].seq_number = seq; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 912 | |
| 913 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 914 | continue; |
| 915 | |
| 916 | /* |
| 917 | * Mark all queues for this STA as unallocated and defer TX |
| 918 | * frames until the queue is allocated |
| 919 | */ |
| 920 | mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; |
| 921 | skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 922 | } |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 923 | mvm_sta->deferred_traffic_tid_map = 0; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 924 | mvm_sta->agg_tids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 925 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 926 | if (iwl_mvm_has_new_rx_api(mvm) && |
| 927 | !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 928 | dup_data = kcalloc(mvm->trans->num_rx_queues, |
| 929 | sizeof(*dup_data), |
| 930 | GFP_KERNEL); |
| 931 | if (!dup_data) |
| 932 | return -ENOMEM; |
| 933 | mvm_sta->dup_data = dup_data; |
| 934 | } |
| 935 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 936 | if (iwl_mvm_is_dqa_supported(mvm)) { |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 937 | ret = iwl_mvm_reserve_sta_stream(mvm, sta, |
| 938 | ieee80211_vif_type_p2p(vif)); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 939 | if (ret) |
| 940 | goto err; |
| 941 | } |
| 942 | |
| 943 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 944 | if (ret) |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 945 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 946 | |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 947 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 948 | if (!sta->tdls) { |
| 949 | WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT); |
| 950 | mvmvif->ap_sta_id = sta_id; |
| 951 | } else { |
| 952 | WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT); |
| 953 | } |
| 954 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 955 | |
| 956 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); |
| 957 | |
| 958 | return 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 959 | |
| 960 | err: |
| 961 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 962 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 965 | int iwl_mvm_update_sta(struct iwl_mvm *mvm, |
| 966 | struct ieee80211_vif *vif, |
| 967 | struct ieee80211_sta *sta) |
| 968 | { |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 969 | return iwl_mvm_sta_send_to_fw(mvm, sta, true, 0); |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 970 | } |
| 971 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 972 | int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 973 | bool drain) |
| 974 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 975 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 976 | int ret; |
| 977 | u32 status; |
| 978 | |
| 979 | lockdep_assert_held(&mvm->mutex); |
| 980 | |
| 981 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 982 | cmd.sta_id = mvmsta->sta_id; |
| 983 | cmd.add_modify = STA_MODE_MODIFY; |
| 984 | cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; |
| 985 | cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); |
| 986 | |
| 987 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 988 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 989 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 990 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 991 | if (ret) |
| 992 | return ret; |
| 993 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 994 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 995 | case ADD_STA_SUCCESS: |
| 996 | IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", |
| 997 | mvmsta->sta_id); |
| 998 | break; |
| 999 | default: |
| 1000 | ret = -EIO; |
| 1001 | IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", |
| 1002 | mvmsta->sta_id); |
| 1003 | break; |
| 1004 | } |
| 1005 | |
| 1006 | return ret; |
| 1007 | } |
| 1008 | |
| 1009 | /* |
| 1010 | * Remove a station from the FW table. Before sending the command to remove |
| 1011 | * the station validate that the station is indeed known to the driver (sanity |
| 1012 | * only). |
| 1013 | */ |
| 1014 | static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) |
| 1015 | { |
| 1016 | struct ieee80211_sta *sta; |
| 1017 | struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { |
| 1018 | .sta_id = sta_id, |
| 1019 | }; |
| 1020 | int ret; |
| 1021 | |
| 1022 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1023 | lockdep_is_held(&mvm->mutex)); |
| 1024 | |
| 1025 | /* Note: internal stations are marked as error values */ |
| 1026 | if (!sta) { |
| 1027 | IWL_ERR(mvm, "Invalid station id\n"); |
| 1028 | return -EINVAL; |
| 1029 | } |
| 1030 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1031 | ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1032 | sizeof(rm_sta_cmd), &rm_sta_cmd); |
| 1033 | if (ret) { |
| 1034 | IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); |
| 1035 | return ret; |
| 1036 | } |
| 1037 | |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | void iwl_mvm_sta_drained_wk(struct work_struct *wk) |
| 1042 | { |
| 1043 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk); |
| 1044 | u8 sta_id; |
| 1045 | |
| 1046 | /* |
| 1047 | * The mutex is needed because of the SYNC cmd, but not only: if the |
| 1048 | * work would run concurrently with iwl_mvm_rm_sta, it would run before |
| 1049 | * iwl_mvm_rm_sta sets the station as busy, and exit. Then |
| 1050 | * iwl_mvm_rm_sta would set the station as busy, and nobody will clean |
| 1051 | * that later. |
| 1052 | */ |
| 1053 | mutex_lock(&mvm->mutex); |
| 1054 | |
| 1055 | for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) { |
| 1056 | int ret; |
| 1057 | struct ieee80211_sta *sta = |
| 1058 | rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1059 | lockdep_is_held(&mvm->mutex)); |
| 1060 | |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 1061 | /* |
| 1062 | * This station is in use or RCU-removed; the latter happens in |
| 1063 | * managed mode, where mac80211 removes the station before we |
| 1064 | * can remove it from firmware (we can only do that after the |
| 1065 | * MAC is marked unassociated), and possibly while the deauth |
| 1066 | * frame to disconnect from the AP is still queued. Then, the |
| 1067 | * station pointer is -ENOENT when the last skb is reclaimed. |
| 1068 | */ |
| 1069 | if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1070 | continue; |
| 1071 | |
| 1072 | if (PTR_ERR(sta) == -EINVAL) { |
| 1073 | IWL_ERR(mvm, "Drained sta %d, but it is internal?\n", |
| 1074 | sta_id); |
| 1075 | continue; |
| 1076 | } |
| 1077 | |
| 1078 | if (!sta) { |
| 1079 | IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n", |
| 1080 | sta_id); |
| 1081 | continue; |
| 1082 | } |
| 1083 | |
| 1084 | WARN_ON(PTR_ERR(sta) != -EBUSY); |
| 1085 | /* This station was removed and we waited until it got drained, |
| 1086 | * we can now proceed and remove it. |
| 1087 | */ |
| 1088 | ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 1089 | if (ret) { |
| 1090 | IWL_ERR(mvm, |
| 1091 | "Couldn't remove sta %d after it was drained\n", |
| 1092 | sta_id); |
| 1093 | continue; |
| 1094 | } |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1095 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1096 | clear_bit(sta_id, mvm->sta_drained); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1097 | |
| 1098 | if (mvm->tfd_drained[sta_id]) { |
| 1099 | unsigned long i, msk = mvm->tfd_drained[sta_id]; |
| 1100 | |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 1101 | for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE) |
Arik Nemtsov | 06ecdba | 2015-10-12 14:47:11 +0300 | [diff] [blame] | 1102 | iwl_mvm_disable_txq(mvm, i, i, |
| 1103 | IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1104 | |
| 1105 | mvm->tfd_drained[sta_id] = 0; |
| 1106 | IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n", |
| 1107 | sta_id, msk); |
| 1108 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | mutex_unlock(&mvm->mutex); |
| 1112 | } |
| 1113 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1114 | static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm, |
| 1115 | struct ieee80211_vif *vif, |
| 1116 | struct iwl_mvm_sta *mvm_sta) |
| 1117 | { |
| 1118 | int ac; |
| 1119 | int i; |
| 1120 | |
| 1121 | lockdep_assert_held(&mvm->mutex); |
| 1122 | |
| 1123 | for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) { |
| 1124 | if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE) |
| 1125 | continue; |
| 1126 | |
| 1127 | ac = iwl_mvm_tid_to_ac_queue(i); |
| 1128 | iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id, |
| 1129 | vif->hw_queue[ac], i, 0); |
| 1130 | mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; |
| 1131 | } |
| 1132 | } |
| 1133 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1134 | int iwl_mvm_rm_sta(struct iwl_mvm *mvm, |
| 1135 | struct ieee80211_vif *vif, |
| 1136 | struct ieee80211_sta *sta) |
| 1137 | { |
| 1138 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1139 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1140 | int ret; |
| 1141 | |
| 1142 | lockdep_assert_held(&mvm->mutex); |
| 1143 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1144 | if (iwl_mvm_has_new_rx_api(mvm)) |
| 1145 | kfree(mvm_sta->dup_data); |
| 1146 | |
Liad Kaufman | a6f035a | 2015-08-24 15:23:14 +0300 | [diff] [blame] | 1147 | if ((vif->type == NL80211_IFTYPE_STATION && |
| 1148 | mvmvif->ap_sta_id == mvm_sta->sta_id) || |
| 1149 | iwl_mvm_is_dqa_supported(mvm)){ |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1150 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
| 1151 | if (ret) |
| 1152 | return ret; |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 1153 | /* flush its queues here since we are freeing mvm_sta */ |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 1154 | 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] | 1155 | if (ret) |
| 1156 | return ret; |
| 1157 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 1158 | mvm_sta->tfd_queue_msk); |
| 1159 | if (ret) |
| 1160 | return ret; |
| 1161 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, false); |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 1162 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1163 | /* If DQA is supported - the queues can be disabled now */ |
| 1164 | if (iwl_mvm_is_dqa_supported(mvm)) |
| 1165 | iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta); |
| 1166 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1167 | /* if we are associated - we can't remove the AP STA now */ |
| 1168 | if (vif->bss_conf.assoc) |
| 1169 | return ret; |
| 1170 | |
| 1171 | /* unassoc - go ahead - remove the AP STA now */ |
| 1172 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 1173 | |
| 1174 | /* clear d0i3_ap_sta_id if no longer relevant */ |
| 1175 | if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id) |
| 1176 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | /* |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 1180 | * This shouldn't happen - the TDLS channel switch should be canceled |
| 1181 | * before the STA is removed. |
| 1182 | */ |
| 1183 | if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) { |
| 1184 | mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT; |
| 1185 | cancel_delayed_work(&mvm->tdls_cs.dwork); |
| 1186 | } |
| 1187 | |
| 1188 | /* |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1189 | * Make sure that the tx response code sees the station as -EBUSY and |
| 1190 | * calls the drain worker. |
| 1191 | */ |
| 1192 | spin_lock_bh(&mvm_sta->lock); |
| 1193 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1194 | * There are frames pending on the AC queues for this station. |
| 1195 | * We need to wait until all the frames are drained... |
| 1196 | */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1197 | if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1198 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
| 1199 | ERR_PTR(-EBUSY)); |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1200 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1201 | |
| 1202 | /* disable TDLS sta queues on drain complete */ |
| 1203 | if (sta->tdls) { |
| 1204 | mvm->tfd_drained[mvm_sta->sta_id] = |
| 1205 | mvm_sta->tfd_queue_msk; |
| 1206 | IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", |
| 1207 | mvm_sta->sta_id); |
| 1208 | } |
| 1209 | |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1210 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1211 | } else { |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1212 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1213 | |
| 1214 | if (sta->tdls) |
| 1215 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 1216 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1217 | ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1218 | 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] | 1219 | } |
| 1220 | |
| 1221 | return ret; |
| 1222 | } |
| 1223 | |
| 1224 | int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, |
| 1225 | struct ieee80211_vif *vif, |
| 1226 | u8 sta_id) |
| 1227 | { |
| 1228 | int ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 1229 | |
| 1230 | lockdep_assert_held(&mvm->mutex); |
| 1231 | |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1232 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1233 | return ret; |
| 1234 | } |
| 1235 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 1236 | int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, |
| 1237 | struct iwl_mvm_int_sta *sta, |
| 1238 | u32 qmask, enum nl80211_iftype iftype) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1239 | { |
| 1240 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 1241 | sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1242 | if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT)) |
| 1243 | return -ENOSPC; |
| 1244 | } |
| 1245 | |
| 1246 | sta->tfd_queue_msk = qmask; |
| 1247 | |
| 1248 | /* put a non-NULL value so iterating over the stations won't stop */ |
| 1249 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 1253 | static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, |
| 1254 | struct iwl_mvm_int_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1255 | { |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1256 | 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] | 1257 | memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); |
| 1258 | sta->sta_id = IWL_MVM_STATION_COUNT; |
| 1259 | } |
| 1260 | |
| 1261 | static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, |
| 1262 | struct iwl_mvm_int_sta *sta, |
| 1263 | const u8 *addr, |
| 1264 | u16 mac_id, u16 color) |
| 1265 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1266 | struct iwl_mvm_add_sta_cmd cmd; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1267 | int ret; |
| 1268 | u32 status; |
| 1269 | |
| 1270 | lockdep_assert_held(&mvm->mutex); |
| 1271 | |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1272 | memset(&cmd, 0, sizeof(cmd)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1273 | cmd.sta_id = sta->sta_id; |
| 1274 | cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, |
| 1275 | color)); |
| 1276 | |
| 1277 | cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 1278 | cmd.tid_disable_tx = cpu_to_le16(0xffff); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1279 | |
| 1280 | if (addr) |
| 1281 | memcpy(cmd.addr, addr, ETH_ALEN); |
| 1282 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1283 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1284 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1285 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1286 | if (ret) |
| 1287 | return ret; |
| 1288 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1289 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1290 | case ADD_STA_SUCCESS: |
| 1291 | IWL_DEBUG_INFO(mvm, "Internal station added.\n"); |
| 1292 | return 0; |
| 1293 | default: |
| 1294 | ret = -EIO; |
| 1295 | IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", |
| 1296 | status); |
| 1297 | break; |
| 1298 | } |
| 1299 | return ret; |
| 1300 | } |
| 1301 | |
| 1302 | int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) |
| 1303 | { |
Emmanuel Grumbach | 4cf677f | 2015-01-12 14:38:29 +0200 | [diff] [blame] | 1304 | unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ? |
| 1305 | mvm->cfg->base_params->wd_timeout : |
| 1306 | IWL_WATCHDOG_DISABLED; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1307 | int ret; |
| 1308 | |
| 1309 | lockdep_assert_held(&mvm->mutex); |
| 1310 | |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 1311 | /* Map Aux queue to fifo - needs to happen before adding Aux station */ |
Liad Kaufman | 28d0793 | 2015-09-01 16:36:25 +0300 | [diff] [blame^] | 1312 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 1313 | iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue, |
| 1314 | IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout); |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 1315 | |
| 1316 | /* Allocate aux station and assign to it the aux queue */ |
| 1317 | 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] | 1318 | NL80211_IFTYPE_UNSPECIFIED); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1319 | if (ret) |
| 1320 | return ret; |
| 1321 | |
Liad Kaufman | 28d0793 | 2015-09-01 16:36:25 +0300 | [diff] [blame^] | 1322 | if (iwl_mvm_is_dqa_supported(mvm)) { |
| 1323 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1324 | .fifo = IWL_MVM_TX_FIFO_MCAST, |
| 1325 | .sta_id = mvm->aux_sta.sta_id, |
| 1326 | .tid = IWL_MAX_TID_COUNT, |
| 1327 | .aggregate = false, |
| 1328 | .frame_limit = IWL_FRAME_LIMIT, |
| 1329 | }; |
| 1330 | |
| 1331 | iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg, |
| 1332 | wdg_timeout); |
| 1333 | } |
| 1334 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1335 | ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, |
| 1336 | MAC_INDEX_AUX, 0); |
| 1337 | |
| 1338 | if (ret) |
| 1339 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 1340 | return ret; |
| 1341 | } |
| 1342 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 1343 | int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1344 | { |
| 1345 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1346 | |
| 1347 | lockdep_assert_held(&mvm->mutex); |
| 1348 | return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr, |
| 1349 | mvmvif->id, 0); |
| 1350 | } |
| 1351 | |
| 1352 | int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1353 | { |
| 1354 | int ret; |
| 1355 | |
| 1356 | lockdep_assert_held(&mvm->mutex); |
| 1357 | |
| 1358 | ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id); |
| 1359 | if (ret) |
| 1360 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 1361 | |
| 1362 | return ret; |
| 1363 | } |
| 1364 | |
| 1365 | void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm) |
| 1366 | { |
| 1367 | iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta); |
| 1368 | } |
| 1369 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 1370 | void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm) |
| 1371 | { |
| 1372 | lockdep_assert_held(&mvm->mutex); |
| 1373 | |
| 1374 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 1375 | } |
| 1376 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1377 | /* |
| 1378 | * Send the add station command for the vif's broadcast station. |
| 1379 | * Assumes that the station was already allocated. |
| 1380 | * |
| 1381 | * @mvm: the mvm component |
| 1382 | * @vif: the interface to which the broadcast station is added |
| 1383 | * @bsta: the broadcast station to add. |
| 1384 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1385 | 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] | 1386 | { |
| 1387 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1388 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1389 | static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
Johannes Berg | a424340 | 2014-01-20 23:46:38 +0100 | [diff] [blame] | 1390 | const u8 *baddr = _baddr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1391 | |
| 1392 | lockdep_assert_held(&mvm->mutex); |
| 1393 | |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1394 | if (iwl_mvm_is_dqa_supported(mvm)) { |
| 1395 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1396 | .fifo = IWL_MVM_TX_FIFO_VO, |
| 1397 | .sta_id = mvmvif->bcast_sta.sta_id, |
| 1398 | .tid = IWL_MAX_TID_COUNT, |
| 1399 | .aggregate = false, |
| 1400 | .frame_limit = IWL_FRAME_LIMIT, |
| 1401 | }; |
| 1402 | unsigned int wdg_timeout = |
| 1403 | iwl_mvm_get_wd_timeout(mvm, vif, false, false); |
| 1404 | int queue; |
| 1405 | |
| 1406 | if ((vif->type == NL80211_IFTYPE_AP) && |
| 1407 | (mvmvif->bcast_sta.tfd_queue_msk & |
| 1408 | BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE))) |
| 1409 | queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE; |
Liad Kaufman | 4c96513 | 2015-08-09 19:26:56 +0300 | [diff] [blame] | 1410 | else if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) && |
| 1411 | (mvmvif->bcast_sta.tfd_queue_msk & |
| 1412 | BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE))) |
| 1413 | queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE; |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1414 | else if (WARN(1, "Missed required TXQ for adding bcast STA\n")) |
| 1415 | return -EINVAL; |
| 1416 | |
| 1417 | iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, &cfg, |
| 1418 | wdg_timeout); |
| 1419 | } |
| 1420 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1421 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 1422 | baddr = vif->bss_conf.bssid; |
| 1423 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1424 | if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT)) |
| 1425 | return -ENOSPC; |
| 1426 | |
| 1427 | return iwl_mvm_add_int_sta_common(mvm, bsta, baddr, |
| 1428 | mvmvif->id, mvmvif->color); |
| 1429 | } |
| 1430 | |
| 1431 | /* Send the FW a request to remove the station from it's internal data |
| 1432 | * structures, but DO NOT remove the entry from the local data structures. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1433 | 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] | 1434 | { |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1435 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1436 | int ret; |
| 1437 | |
| 1438 | lockdep_assert_held(&mvm->mutex); |
| 1439 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1440 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1441 | if (ret) |
| 1442 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 1443 | return ret; |
| 1444 | } |
| 1445 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1446 | int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1447 | { |
| 1448 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1449 | u32 qmask = 0; |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1450 | |
| 1451 | lockdep_assert_held(&mvm->mutex); |
| 1452 | |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1453 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 1454 | qmask = iwl_mvm_mac_get_queues_mask(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1455 | |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1456 | if (vif->type == NL80211_IFTYPE_AP) { |
| 1457 | /* |
| 1458 | * The firmware defines the TFD queue mask to only be relevant |
| 1459 | * for *unicast* queues, so the multicast (CAB) queue shouldn't |
| 1460 | * be included. |
| 1461 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1462 | qmask &= ~BIT(vif->cab_queue); |
| 1463 | |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1464 | if (iwl_mvm_is_dqa_supported(mvm)) |
| 1465 | qmask |= BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE); |
Liad Kaufman | 4c96513 | 2015-08-09 19:26:56 +0300 | [diff] [blame] | 1466 | } else if (iwl_mvm_is_dqa_supported(mvm) && |
| 1467 | vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 1468 | qmask |= BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE); |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1469 | } |
| 1470 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1471 | return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask, |
| 1472 | ieee80211_vif_type_p2p(vif)); |
| 1473 | } |
| 1474 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1475 | /* Allocate a new station entry for the broadcast station to the given vif, |
| 1476 | * and send it to the FW. |
| 1477 | * Note that each P2P mac should have its own broadcast station. |
| 1478 | * |
| 1479 | * @mvm: the mvm component |
| 1480 | * @vif: the interface to which the broadcast station is added |
| 1481 | * @bsta: the broadcast station to add. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1482 | 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] | 1483 | { |
| 1484 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1485 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1486 | int ret; |
| 1487 | |
| 1488 | lockdep_assert_held(&mvm->mutex); |
| 1489 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1490 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1491 | if (ret) |
| 1492 | return ret; |
| 1493 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1494 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1495 | |
| 1496 | if (ret) |
| 1497 | iwl_mvm_dealloc_int_sta(mvm, bsta); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1498 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1499 | return ret; |
| 1500 | } |
| 1501 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1502 | void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1503 | { |
| 1504 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1505 | |
| 1506 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 1507 | } |
| 1508 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1509 | /* |
| 1510 | * Send the FW a request to remove the station from it's internal data |
| 1511 | * structures, and in addition remove it from the local data structure. |
| 1512 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1513 | 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] | 1514 | { |
| 1515 | int ret; |
| 1516 | |
| 1517 | lockdep_assert_held(&mvm->mutex); |
| 1518 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1519 | ret = iwl_mvm_send_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1520 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1521 | iwl_mvm_dealloc_bcast_sta(mvm, vif); |
| 1522 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1523 | return ret; |
| 1524 | } |
| 1525 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 1526 | #define IWL_MAX_RX_BA_SESSIONS 16 |
| 1527 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1528 | 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] | 1529 | { |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1530 | struct iwl_mvm_delba_notif notif = { |
| 1531 | .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA, |
| 1532 | .metadata.sync = 1, |
| 1533 | .delba.baid = baid, |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1534 | }; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1535 | iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif)); |
| 1536 | }; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1537 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1538 | static void iwl_mvm_free_reorder(struct iwl_mvm *mvm, |
| 1539 | struct iwl_mvm_baid_data *data) |
| 1540 | { |
| 1541 | int i; |
| 1542 | |
| 1543 | iwl_mvm_sync_rxq_del_ba(mvm, data->baid); |
| 1544 | |
| 1545 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { |
| 1546 | int j; |
| 1547 | struct iwl_mvm_reorder_buffer *reorder_buf = |
| 1548 | &data->reorder_buf[i]; |
| 1549 | |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 1550 | spin_lock_bh(&reorder_buf->lock); |
| 1551 | if (likely(!reorder_buf->num_stored)) { |
| 1552 | spin_unlock_bh(&reorder_buf->lock); |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1553 | continue; |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 1554 | } |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1555 | |
| 1556 | /* |
| 1557 | * This shouldn't happen in regular DELBA since the internal |
| 1558 | * delBA notification should trigger a release of all frames in |
| 1559 | * the reorder buffer. |
| 1560 | */ |
| 1561 | WARN_ON(1); |
| 1562 | |
| 1563 | for (j = 0; j < reorder_buf->buf_size; j++) |
| 1564 | __skb_queue_purge(&reorder_buf->entries[j]); |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 1565 | /* |
| 1566 | * Prevent timer re-arm. This prevents a very far fetched case |
| 1567 | * where we timed out on the notification. There may be prior |
| 1568 | * RX frames pending in the RX queue before the notification |
| 1569 | * that might get processed between now and the actual deletion |
| 1570 | * and we would re-arm the timer although we are deleting the |
| 1571 | * reorder buffer. |
| 1572 | */ |
| 1573 | reorder_buf->removed = true; |
| 1574 | spin_unlock_bh(&reorder_buf->lock); |
| 1575 | del_timer_sync(&reorder_buf->reorder_timer); |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm, |
| 1580 | u32 sta_id, |
| 1581 | struct iwl_mvm_baid_data *data, |
| 1582 | u16 ssn, u8 buf_size) |
| 1583 | { |
| 1584 | int i; |
| 1585 | |
| 1586 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { |
| 1587 | struct iwl_mvm_reorder_buffer *reorder_buf = |
| 1588 | &data->reorder_buf[i]; |
| 1589 | int j; |
| 1590 | |
| 1591 | reorder_buf->num_stored = 0; |
| 1592 | reorder_buf->head_sn = ssn; |
| 1593 | reorder_buf->buf_size = buf_size; |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 1594 | /* rx reorder timer */ |
| 1595 | reorder_buf->reorder_timer.function = |
| 1596 | iwl_mvm_reorder_timer_expired; |
| 1597 | reorder_buf->reorder_timer.data = (unsigned long)reorder_buf; |
| 1598 | init_timer(&reorder_buf->reorder_timer); |
| 1599 | spin_lock_init(&reorder_buf->lock); |
| 1600 | reorder_buf->mvm = mvm; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1601 | reorder_buf->queue = i; |
| 1602 | reorder_buf->sta_id = sta_id; |
| 1603 | for (j = 0; j < reorder_buf->buf_size; j++) |
| 1604 | __skb_queue_head_init(&reorder_buf->entries[j]); |
| 1605 | } |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1606 | } |
| 1607 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1608 | 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] | 1609 | int tid, u16 ssn, bool start, u8 buf_size, u16 timeout) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1610 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1611 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1612 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1613 | struct iwl_mvm_baid_data *baid_data = NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1614 | int ret; |
| 1615 | u32 status; |
| 1616 | |
| 1617 | lockdep_assert_held(&mvm->mutex); |
| 1618 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 1619 | if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { |
| 1620 | IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); |
| 1621 | return -ENOSPC; |
| 1622 | } |
| 1623 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1624 | if (iwl_mvm_has_new_rx_api(mvm) && start) { |
| 1625 | /* |
| 1626 | * Allocate here so if allocation fails we can bail out early |
| 1627 | * before starting the BA session in the firmware |
| 1628 | */ |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1629 | baid_data = kzalloc(sizeof(*baid_data) + |
| 1630 | mvm->trans->num_rx_queues * |
| 1631 | sizeof(baid_data->reorder_buf[0]), |
| 1632 | GFP_KERNEL); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1633 | if (!baid_data) |
| 1634 | return -ENOMEM; |
| 1635 | } |
| 1636 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1637 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 1638 | cmd.sta_id = mvm_sta->sta_id; |
| 1639 | cmd.add_modify = STA_MODE_MODIFY; |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 1640 | if (start) { |
| 1641 | cmd.add_immediate_ba_tid = (u8) tid; |
| 1642 | cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1643 | cmd.rx_ba_window = cpu_to_le16((u16)buf_size); |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 1644 | } else { |
| 1645 | cmd.remove_immediate_ba_tid = (u8) tid; |
| 1646 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1647 | cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : |
| 1648 | STA_MODIFY_REMOVE_BA_TID; |
| 1649 | |
| 1650 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1651 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1652 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1653 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1654 | if (ret) |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1655 | goto out_free; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1656 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1657 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1658 | case ADD_STA_SUCCESS: |
| 1659 | IWL_DEBUG_INFO(mvm, "RX BA Session %sed in fw\n", |
| 1660 | start ? "start" : "stopp"); |
| 1661 | break; |
| 1662 | case ADD_STA_IMMEDIATE_BA_FAILURE: |
| 1663 | IWL_WARN(mvm, "RX BA Session refused by fw\n"); |
| 1664 | ret = -ENOSPC; |
| 1665 | break; |
| 1666 | default: |
| 1667 | ret = -EIO; |
| 1668 | IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", |
| 1669 | start ? "start" : "stopp", status); |
| 1670 | break; |
| 1671 | } |
| 1672 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1673 | if (ret) |
| 1674 | goto out_free; |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 1675 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1676 | if (start) { |
| 1677 | u8 baid; |
| 1678 | |
| 1679 | mvm->rx_ba_sessions++; |
| 1680 | |
| 1681 | if (!iwl_mvm_has_new_rx_api(mvm)) |
| 1682 | return 0; |
| 1683 | |
| 1684 | if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) { |
| 1685 | ret = -EINVAL; |
| 1686 | goto out_free; |
| 1687 | } |
| 1688 | baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >> |
| 1689 | IWL_ADD_STA_BAID_SHIFT); |
| 1690 | baid_data->baid = baid; |
| 1691 | baid_data->timeout = timeout; |
| 1692 | baid_data->last_rx = jiffies; |
| 1693 | init_timer(&baid_data->session_timer); |
| 1694 | baid_data->session_timer.function = |
| 1695 | iwl_mvm_rx_agg_session_expired; |
| 1696 | baid_data->session_timer.data = |
| 1697 | (unsigned long)&mvm->baid_map[baid]; |
| 1698 | baid_data->mvm = mvm; |
| 1699 | baid_data->tid = tid; |
| 1700 | baid_data->sta_id = mvm_sta->sta_id; |
| 1701 | |
| 1702 | mvm_sta->tid_to_baid[tid] = baid; |
| 1703 | if (timeout) |
| 1704 | mod_timer(&baid_data->session_timer, |
| 1705 | TU_TO_EXP_TIME(timeout * 2)); |
| 1706 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1707 | iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id, |
| 1708 | baid_data, ssn, buf_size); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1709 | /* |
| 1710 | * protect the BA data with RCU to cover a case where our |
| 1711 | * internal RX sync mechanism will timeout (not that it's |
| 1712 | * supposed to happen) and we will free the session data while |
| 1713 | * RX is being processed in parallel |
| 1714 | */ |
| 1715 | WARN_ON(rcu_access_pointer(mvm->baid_map[baid])); |
| 1716 | rcu_assign_pointer(mvm->baid_map[baid], baid_data); |
| 1717 | } else if (mvm->rx_ba_sessions > 0) { |
| 1718 | u8 baid = mvm_sta->tid_to_baid[tid]; |
| 1719 | |
| 1720 | /* check that restart flow didn't zero the counter */ |
| 1721 | mvm->rx_ba_sessions--; |
| 1722 | if (!iwl_mvm_has_new_rx_api(mvm)) |
| 1723 | return 0; |
| 1724 | |
| 1725 | if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID)) |
| 1726 | return -EINVAL; |
| 1727 | |
| 1728 | baid_data = rcu_access_pointer(mvm->baid_map[baid]); |
| 1729 | if (WARN_ON(!baid_data)) |
| 1730 | return -EINVAL; |
| 1731 | |
| 1732 | /* synchronize all rx queues so we can safely delete */ |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 1733 | iwl_mvm_free_reorder(mvm, baid_data); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1734 | del_timer_sync(&baid_data->session_timer); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 1735 | RCU_INIT_POINTER(mvm->baid_map[baid], NULL); |
| 1736 | kfree_rcu(baid_data, rcu_head); |
| 1737 | } |
| 1738 | return 0; |
| 1739 | |
| 1740 | out_free: |
| 1741 | kfree(baid_data); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1742 | return ret; |
| 1743 | } |
| 1744 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 1745 | int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 1746 | int tid, u8 queue, bool start) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1747 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1748 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1749 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1750 | int ret; |
| 1751 | u32 status; |
| 1752 | |
| 1753 | lockdep_assert_held(&mvm->mutex); |
| 1754 | |
| 1755 | if (start) { |
| 1756 | mvm_sta->tfd_queue_msk |= BIT(queue); |
| 1757 | mvm_sta->tid_disable_agg &= ~BIT(tid); |
| 1758 | } else { |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1759 | /* In DQA-mode the queue isn't removed on agg termination */ |
| 1760 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 1761 | mvm_sta->tfd_queue_msk &= ~BIT(queue); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1762 | mvm_sta->tid_disable_agg |= BIT(tid); |
| 1763 | } |
| 1764 | |
| 1765 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 1766 | cmd.sta_id = mvm_sta->sta_id; |
| 1767 | cmd.add_modify = STA_MODE_MODIFY; |
| 1768 | cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX; |
| 1769 | cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 1770 | cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); |
| 1771 | |
| 1772 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1773 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1774 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1775 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1776 | if (ret) |
| 1777 | return ret; |
| 1778 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1779 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1780 | case ADD_STA_SUCCESS: |
| 1781 | break; |
| 1782 | default: |
| 1783 | ret = -EIO; |
| 1784 | IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", |
| 1785 | start ? "start" : "stopp", status); |
| 1786 | break; |
| 1787 | } |
| 1788 | |
| 1789 | return ret; |
| 1790 | } |
| 1791 | |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 1792 | const u8 tid_to_mac80211_ac[] = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1793 | IEEE80211_AC_BE, |
| 1794 | IEEE80211_AC_BK, |
| 1795 | IEEE80211_AC_BK, |
| 1796 | IEEE80211_AC_BE, |
| 1797 | IEEE80211_AC_VI, |
| 1798 | IEEE80211_AC_VI, |
| 1799 | IEEE80211_AC_VO, |
| 1800 | IEEE80211_AC_VO, |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 1801 | 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] | 1802 | }; |
| 1803 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1804 | static const u8 tid_to_ucode_ac[] = { |
| 1805 | AC_BE, |
| 1806 | AC_BK, |
| 1807 | AC_BK, |
| 1808 | AC_BE, |
| 1809 | AC_VI, |
| 1810 | AC_VI, |
| 1811 | AC_VO, |
| 1812 | AC_VO, |
| 1813 | }; |
| 1814 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1815 | int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1816 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
| 1817 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1818 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1819 | struct iwl_mvm_tid_data *tid_data; |
| 1820 | int txq_id; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1821 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1822 | |
| 1823 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) |
| 1824 | return -EINVAL; |
| 1825 | |
| 1826 | if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { |
| 1827 | IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", |
| 1828 | mvmsta->tid_data[tid].state); |
| 1829 | return -ENXIO; |
| 1830 | } |
| 1831 | |
| 1832 | lockdep_assert_held(&mvm->mutex); |
| 1833 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 1834 | spin_lock_bh(&mvmsta->lock); |
| 1835 | |
| 1836 | /* possible race condition - we entered D0i3 while starting agg */ |
| 1837 | if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) { |
| 1838 | spin_unlock_bh(&mvmsta->lock); |
| 1839 | IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n"); |
| 1840 | return -EIO; |
| 1841 | } |
| 1842 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1843 | spin_lock_bh(&mvm->queue_info_lock); |
| 1844 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1845 | /* |
| 1846 | * Note the possible cases: |
| 1847 | * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed |
| 1848 | * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free |
| 1849 | * one and mark it as reserved |
| 1850 | * 3. In DQA mode, but no traffic yet on this TID: same treatment as in |
| 1851 | * non-DQA mode, since the TXQ hasn't yet been allocated |
| 1852 | */ |
| 1853 | txq_id = mvmsta->tid_data[tid].txq_id; |
| 1854 | if (!iwl_mvm_is_dqa_supported(mvm) || |
| 1855 | mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) { |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 1856 | txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
| 1857 | mvm->first_agg_queue, |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1858 | mvm->last_agg_queue); |
| 1859 | if (txq_id < 0) { |
| 1860 | ret = txq_id; |
| 1861 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1862 | IWL_ERR(mvm, "Failed to allocate agg queue\n"); |
| 1863 | goto release_locks; |
| 1864 | } |
| 1865 | |
| 1866 | /* TXQ hasn't yet been enabled, so mark it only as reserved */ |
| 1867 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1868 | } |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1869 | spin_unlock_bh(&mvm->queue_info_lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1870 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1871 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1872 | "AGG for tid %d will be on queue #%d\n", |
| 1873 | tid, txq_id); |
| 1874 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1875 | tid_data = &mvmsta->tid_data[tid]; |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 1876 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1877 | tid_data->txq_id = txq_id; |
| 1878 | *ssn = tid_data->ssn; |
| 1879 | |
| 1880 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1881 | "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", |
| 1882 | mvmsta->sta_id, tid, txq_id, tid_data->ssn, |
| 1883 | tid_data->next_reclaimed); |
| 1884 | |
| 1885 | if (tid_data->ssn == tid_data->next_reclaimed) { |
| 1886 | tid_data->state = IWL_AGG_STARTING; |
| 1887 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1888 | } else { |
| 1889 | tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; |
| 1890 | } |
| 1891 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1892 | ret = 0; |
| 1893 | |
| 1894 | release_locks: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1895 | spin_unlock_bh(&mvmsta->lock); |
| 1896 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1897 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | 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] | 1901 | struct ieee80211_sta *sta, u16 tid, u8 buf_size, |
| 1902 | bool amsdu) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1903 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1904 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1905 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 1906 | unsigned int wdg_timeout = |
| 1907 | iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false); |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 1908 | int queue, ret; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1909 | bool alloc_queue = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1910 | u16 ssn; |
| 1911 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 1912 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1913 | .sta_id = mvmsta->sta_id, |
| 1914 | .tid = tid, |
| 1915 | .frame_limit = buf_size, |
| 1916 | .aggregate = true, |
| 1917 | }; |
| 1918 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1919 | BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE) |
| 1920 | != IWL_MAX_TID_COUNT); |
| 1921 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1922 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); |
| 1923 | |
| 1924 | spin_lock_bh(&mvmsta->lock); |
| 1925 | ssn = tid_data->ssn; |
| 1926 | queue = tid_data->txq_id; |
| 1927 | tid_data->state = IWL_AGG_ON; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1928 | mvmsta->agg_tids |= BIT(tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1929 | tid_data->ssn = 0xffff; |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 1930 | tid_data->amsdu_in_ampdu_allowed = amsdu; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1931 | spin_unlock_bh(&mvmsta->lock); |
| 1932 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 1933 | 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] | 1934 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1935 | /* In DQA mode, the existing queue might need to be reconfigured */ |
| 1936 | if (iwl_mvm_is_dqa_supported(mvm)) { |
| 1937 | spin_lock_bh(&mvm->queue_info_lock); |
| 1938 | /* Maybe there is no need to even alloc a queue... */ |
| 1939 | if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY) |
| 1940 | alloc_queue = false; |
| 1941 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1942 | |
| 1943 | /* |
| 1944 | * Only reconfig the SCD for the queue if the window size has |
| 1945 | * changed from current (become smaller) |
| 1946 | */ |
| 1947 | if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) { |
| 1948 | /* |
| 1949 | * If reconfiguring an existing queue, it first must be |
| 1950 | * drained |
| 1951 | */ |
| 1952 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 1953 | BIT(queue)); |
| 1954 | if (ret) { |
| 1955 | IWL_ERR(mvm, |
| 1956 | "Error draining queue before reconfig\n"); |
| 1957 | return ret; |
| 1958 | } |
| 1959 | |
| 1960 | ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo, |
| 1961 | mvmsta->sta_id, tid, |
| 1962 | buf_size, ssn); |
| 1963 | if (ret) { |
| 1964 | IWL_ERR(mvm, |
| 1965 | "Error reconfiguring TXQ #%d\n", queue); |
| 1966 | return ret; |
| 1967 | } |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | if (alloc_queue) |
| 1972 | iwl_mvm_enable_txq(mvm, queue, |
| 1973 | vif->hw_queue[tid_to_mac80211_ac[tid]], ssn, |
| 1974 | &cfg, wdg_timeout); |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 1975 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1976 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 1977 | if (ret) |
| 1978 | return -EIO; |
| 1979 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1980 | /* No need to mark as reserved */ |
| 1981 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1982 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1983 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1984 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1985 | /* |
| 1986 | * Even though in theory the peer could have different |
| 1987 | * aggregation reorder buffer sizes for different sessions, |
| 1988 | * our ucode doesn't allow for that and has a global limit |
| 1989 | * for each station. Therefore, use the minimum of all the |
| 1990 | * aggregation sessions and our default value. |
| 1991 | */ |
| 1992 | mvmsta->max_agg_bufsize = |
| 1993 | min(mvmsta->max_agg_bufsize, buf_size); |
| 1994 | mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; |
| 1995 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 1996 | IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", |
| 1997 | sta->addr, tid); |
| 1998 | |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 1999 | return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2003 | struct ieee80211_sta *sta, u16 tid) |
| 2004 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2005 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2006 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 2007 | u16 txq_id; |
| 2008 | int err; |
| 2009 | |
Emmanuel Grumbach | f9aa8dd | 2013-03-04 09:11:08 +0200 | [diff] [blame] | 2010 | |
| 2011 | /* |
| 2012 | * If mac80211 is cleaning its state, then say that we finished since |
| 2013 | * our state has been cleared anyway. |
| 2014 | */ |
| 2015 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 2016 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2017 | return 0; |
| 2018 | } |
| 2019 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2020 | spin_lock_bh(&mvmsta->lock); |
| 2021 | |
| 2022 | txq_id = tid_data->txq_id; |
| 2023 | |
| 2024 | IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", |
| 2025 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
| 2026 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2027 | mvmsta->agg_tids &= ~BIT(tid); |
| 2028 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2029 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2030 | /* |
| 2031 | * The TXQ is marked as reserved only if no traffic came through yet |
| 2032 | * This means no traffic has been sent on this TID (agg'd or not), so |
| 2033 | * we no longer have use for the queue. Since it hasn't even been |
| 2034 | * allocated through iwl_mvm_enable_txq, so we can just mark it back as |
| 2035 | * free. |
| 2036 | */ |
| 2037 | if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) |
| 2038 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2039 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2040 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2041 | switch (tid_data->state) { |
| 2042 | case IWL_AGG_ON: |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 2043 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2044 | |
| 2045 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2046 | "ssn = %d, next_recl = %d\n", |
| 2047 | tid_data->ssn, tid_data->next_reclaimed); |
| 2048 | |
| 2049 | /* There are still packets for this RA / TID in the HW */ |
| 2050 | if (tid_data->ssn != tid_data->next_reclaimed) { |
| 2051 | tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA; |
| 2052 | err = 0; |
| 2053 | break; |
| 2054 | } |
| 2055 | |
| 2056 | tid_data->ssn = 0xffff; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2057 | tid_data->state = IWL_AGG_OFF; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2058 | spin_unlock_bh(&mvmsta->lock); |
| 2059 | |
| 2060 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2061 | |
| 2062 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 2063 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2064 | if (!iwl_mvm_is_dqa_supported(mvm)) { |
| 2065 | int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; |
| 2066 | |
| 2067 | iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0); |
| 2068 | } |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2069 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2070 | case IWL_AGG_STARTING: |
| 2071 | case IWL_EMPTYING_HW_QUEUE_ADDBA: |
| 2072 | /* |
| 2073 | * The agg session has been stopped before it was set up. This |
| 2074 | * can happen when the AddBA timer times out for example. |
| 2075 | */ |
| 2076 | |
| 2077 | /* No barriers since we are under mutex */ |
| 2078 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2079 | |
| 2080 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2081 | tid_data->state = IWL_AGG_OFF; |
| 2082 | err = 0; |
| 2083 | break; |
| 2084 | default: |
| 2085 | IWL_ERR(mvm, |
| 2086 | "Stopping AGG while state not ON or starting for %d on %d (%d)\n", |
| 2087 | mvmsta->sta_id, tid, tid_data->state); |
| 2088 | IWL_ERR(mvm, |
| 2089 | "\ttid_data->txq_id = %d\n", tid_data->txq_id); |
| 2090 | err = -EINVAL; |
| 2091 | } |
| 2092 | |
| 2093 | spin_unlock_bh(&mvmsta->lock); |
| 2094 | |
| 2095 | return err; |
| 2096 | } |
| 2097 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2098 | int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2099 | struct ieee80211_sta *sta, u16 tid) |
| 2100 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2101 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2102 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 2103 | u16 txq_id; |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2104 | enum iwl_mvm_agg_state old_state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2105 | |
| 2106 | /* |
| 2107 | * First set the agg state to OFF to avoid calling |
| 2108 | * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. |
| 2109 | */ |
| 2110 | spin_lock_bh(&mvmsta->lock); |
| 2111 | txq_id = tid_data->txq_id; |
| 2112 | IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", |
| 2113 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2114 | old_state = tid_data->state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2115 | tid_data->state = IWL_AGG_OFF; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2116 | mvmsta->agg_tids &= ~BIT(tid); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2117 | spin_unlock_bh(&mvmsta->lock); |
| 2118 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2119 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2120 | /* |
| 2121 | * The TXQ is marked as reserved only if no traffic came through yet |
| 2122 | * This means no traffic has been sent on this TID (agg'd or not), so |
| 2123 | * we no longer have use for the queue. Since it hasn't even been |
| 2124 | * allocated through iwl_mvm_enable_txq, so we can just mark it back as |
| 2125 | * free. |
| 2126 | */ |
| 2127 | if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) |
| 2128 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2129 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2130 | |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2131 | if (old_state >= IWL_AGG_ON) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 2132 | iwl_mvm_drain_sta(mvm, mvmsta, true); |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 2133 | if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0)) |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2134 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 2135 | iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 2136 | mvmsta->tfd_queue_msk); |
| 2137 | iwl_mvm_drain_sta(mvm, mvmsta, false); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2138 | |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2139 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 2140 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2141 | if (!iwl_mvm_is_dqa_supported(mvm)) { |
| 2142 | int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; |
| 2143 | |
| 2144 | iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue, |
| 2145 | tid, 0); |
| 2146 | } |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2147 | } |
| 2148 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2149 | return 0; |
| 2150 | } |
| 2151 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2152 | static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) |
| 2153 | { |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2154 | int i, max = -1, max_offs = -1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2155 | |
| 2156 | lockdep_assert_held(&mvm->mutex); |
| 2157 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2158 | /* Pick the unused key offset with the highest 'deleted' |
| 2159 | * counter. Every time a key is deleted, all the counters |
| 2160 | * are incremented and the one that was just deleted is |
| 2161 | * reset to zero. Thus, the highest counter is the one |
| 2162 | * that was deleted longest ago. Pick that one. |
| 2163 | */ |
| 2164 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 2165 | if (test_bit(i, mvm->fw_key_table)) |
| 2166 | continue; |
| 2167 | if (mvm->fw_key_deleted[i] > max) { |
| 2168 | max = mvm->fw_key_deleted[i]; |
| 2169 | max_offs = i; |
| 2170 | } |
| 2171 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2172 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2173 | if (max_offs < 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2174 | return STA_KEY_IDX_INVALID; |
| 2175 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2176 | return max_offs; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2177 | } |
| 2178 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2179 | static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm, |
| 2180 | struct ieee80211_vif *vif, |
| 2181 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2182 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 2183 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2184 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2185 | if (sta) |
| 2186 | return iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2187 | |
| 2188 | /* |
| 2189 | * The device expects GTKs for station interfaces to be |
| 2190 | * installed as GTKs for the AP station. If we have no |
| 2191 | * station ID, then use AP's station ID. |
| 2192 | */ |
| 2193 | if (vif->type == NL80211_IFTYPE_STATION && |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2194 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 2195 | u8 sta_id = mvmvif->ap_sta_id; |
| 2196 | |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2197 | /* |
| 2198 | * It is possible that the 'sta' parameter is NULL, |
| 2199 | * for example when a GTK is removed - the sta_id will then |
| 2200 | * be the AP ID, and no station was passed by mac80211. |
| 2201 | */ |
Sara Sharon | 13303c0 | 2016-04-10 15:51:54 +0300 | [diff] [blame] | 2202 | return iwl_mvm_sta_from_staid_protected(mvm, sta_id); |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2203 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2204 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2205 | return NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, |
| 2209 | struct iwl_mvm_sta *mvm_sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2210 | struct ieee80211_key_conf *keyconf, bool mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2211 | u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags, |
| 2212 | u8 key_offset) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2213 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2214 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2215 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 2216 | int ret; |
| 2217 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2218 | u16 keyidx; |
| 2219 | int i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2220 | u8 sta_id = mvm_sta->sta_id; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2221 | |
| 2222 | keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 2223 | STA_KEY_FLG_KEYID_MSK; |
| 2224 | key_flags = cpu_to_le16(keyidx); |
| 2225 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); |
| 2226 | |
| 2227 | switch (keyconf->cipher) { |
| 2228 | case WLAN_CIPHER_SUITE_TKIP: |
| 2229 | key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2230 | cmd.tkip_rx_tsc_byte2 = tkip_iv32; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2231 | for (i = 0; i < 5; i++) |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2232 | cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); |
| 2233 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2234 | break; |
| 2235 | case WLAN_CIPHER_SUITE_CCMP: |
| 2236 | key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2237 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2238 | break; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2239 | case WLAN_CIPHER_SUITE_WEP104: |
| 2240 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES); |
John W. Linville | aa0cb08 | 2015-01-12 16:18:11 -0500 | [diff] [blame] | 2241 | /* fall through */ |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2242 | case WLAN_CIPHER_SUITE_WEP40: |
| 2243 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP); |
| 2244 | memcpy(cmd.key + 3, keyconf->key, keyconf->keylen); |
| 2245 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2246 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 2247 | key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); |
| 2248 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2249 | } |
| 2250 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2251 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2252 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 2253 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2254 | cmd.key_offset = key_offset; |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2255 | cmd.key_flags = key_flags; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2256 | cmd.sta_id = sta_id; |
| 2257 | |
| 2258 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2259 | if (cmd_flags & CMD_ASYNC) |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2260 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, |
| 2261 | sizeof(cmd), &cmd); |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2262 | else |
| 2263 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 2264 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2265 | |
| 2266 | switch (status) { |
| 2267 | case ADD_STA_SUCCESS: |
| 2268 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); |
| 2269 | break; |
| 2270 | default: |
| 2271 | ret = -EIO; |
| 2272 | IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); |
| 2273 | break; |
| 2274 | } |
| 2275 | |
| 2276 | return ret; |
| 2277 | } |
| 2278 | |
| 2279 | static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, |
| 2280 | struct ieee80211_key_conf *keyconf, |
| 2281 | u8 sta_id, bool remove_key) |
| 2282 | { |
| 2283 | struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; |
| 2284 | |
| 2285 | /* verify the key details match the required command's expectations */ |
| 2286 | if (WARN_ON((keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC) || |
| 2287 | (keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || |
| 2288 | (keyconf->keyidx != 4 && keyconf->keyidx != 5))) |
| 2289 | return -EINVAL; |
| 2290 | |
| 2291 | igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); |
| 2292 | igtk_cmd.sta_id = cpu_to_le32(sta_id); |
| 2293 | |
| 2294 | if (remove_key) { |
| 2295 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); |
| 2296 | } else { |
| 2297 | struct ieee80211_key_seq seq; |
| 2298 | const u8 *pn; |
| 2299 | |
| 2300 | memcpy(igtk_cmd.IGTK, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2301 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 2302 | pn = seq.aes_cmac.pn; |
| 2303 | igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | |
| 2304 | ((u64) pn[4] << 8) | |
| 2305 | ((u64) pn[3] << 16) | |
| 2306 | ((u64) pn[2] << 24) | |
| 2307 | ((u64) pn[1] << 32) | |
| 2308 | ((u64) pn[0] << 40)); |
| 2309 | } |
| 2310 | |
| 2311 | IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", |
| 2312 | remove_key ? "removing" : "installing", |
| 2313 | igtk_cmd.sta_id); |
| 2314 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2315 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2316 | sizeof(igtk_cmd), &igtk_cmd); |
| 2317 | } |
| 2318 | |
| 2319 | |
| 2320 | static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, |
| 2321 | struct ieee80211_vif *vif, |
| 2322 | struct ieee80211_sta *sta) |
| 2323 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 2324 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2325 | |
| 2326 | if (sta) |
| 2327 | return sta->addr; |
| 2328 | |
| 2329 | if (vif->type == NL80211_IFTYPE_STATION && |
| 2330 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 2331 | u8 sta_id = mvmvif->ap_sta_id; |
| 2332 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 2333 | lockdep_is_held(&mvm->mutex)); |
| 2334 | return sta->addr; |
| 2335 | } |
| 2336 | |
| 2337 | |
| 2338 | return NULL; |
| 2339 | } |
| 2340 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2341 | static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 2342 | struct ieee80211_vif *vif, |
| 2343 | struct ieee80211_sta *sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2344 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2345 | u8 key_offset, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2346 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2347 | { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2348 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2349 | int ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2350 | const u8 *addr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2351 | struct ieee80211_key_seq seq; |
| 2352 | u16 p1k[5]; |
| 2353 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2354 | switch (keyconf->cipher) { |
| 2355 | case WLAN_CIPHER_SUITE_TKIP: |
| 2356 | addr = iwl_mvm_get_mac_addr(mvm, vif, sta); |
| 2357 | /* get phase 1 key from mac80211 */ |
| 2358 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 2359 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2360 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2361 | seq.tkip.iv32, p1k, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2362 | break; |
| 2363 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2364 | case WLAN_CIPHER_SUITE_WEP40: |
| 2365 | case WLAN_CIPHER_SUITE_WEP104: |
| 2366 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2367 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2368 | break; |
| 2369 | default: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2370 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2371 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2372 | } |
| 2373 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2374 | return ret; |
| 2375 | } |
| 2376 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2377 | 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] | 2378 | struct ieee80211_key_conf *keyconf, |
| 2379 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2380 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2381 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2382 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 2383 | int ret; |
| 2384 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2385 | |
Emmanuel Grumbach | 8115efb | 2013-02-05 10:08:35 +0200 | [diff] [blame] | 2386 | key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 2387 | STA_KEY_FLG_KEYID_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2388 | key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); |
| 2389 | key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); |
| 2390 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2391 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2392 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 2393 | |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 2394 | cmd.key_flags = key_flags; |
| 2395 | cmd.key_offset = keyconf->hw_key_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2396 | cmd.sta_id = sta_id; |
| 2397 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2398 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2399 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 2400 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2401 | |
| 2402 | switch (status) { |
| 2403 | case ADD_STA_SUCCESS: |
| 2404 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); |
| 2405 | break; |
| 2406 | default: |
| 2407 | ret = -EIO; |
| 2408 | IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); |
| 2409 | break; |
| 2410 | } |
| 2411 | |
| 2412 | return ret; |
| 2413 | } |
| 2414 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2415 | int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 2416 | struct ieee80211_vif *vif, |
| 2417 | struct ieee80211_sta *sta, |
| 2418 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2419 | u8 key_offset) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2420 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2421 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2422 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2423 | u8 sta_id; |
| 2424 | int ret; |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 2425 | static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0}; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2426 | |
| 2427 | lockdep_assert_held(&mvm->mutex); |
| 2428 | |
| 2429 | /* Get the station id from the mvm local station table */ |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2430 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 2431 | if (!mvm_sta) { |
| 2432 | IWL_ERR(mvm, "Failed to find station\n"); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2433 | return -EINVAL; |
| 2434 | } |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2435 | sta_id = mvm_sta->sta_id; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2436 | |
| 2437 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { |
| 2438 | ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false); |
| 2439 | goto end; |
| 2440 | } |
| 2441 | |
| 2442 | /* |
| 2443 | * It is possible that the 'sta' parameter is NULL, and thus |
| 2444 | * there is a need to retrieve the sta from the local station table. |
| 2445 | */ |
| 2446 | if (!sta) { |
| 2447 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 2448 | lockdep_is_held(&mvm->mutex)); |
| 2449 | if (IS_ERR_OR_NULL(sta)) { |
| 2450 | IWL_ERR(mvm, "Invalid station id\n"); |
| 2451 | return -EINVAL; |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif)) |
| 2456 | return -EINVAL; |
| 2457 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2458 | /* If the key_offset is not pre-assigned, we need to find a |
| 2459 | * new offset to use. In normal cases, the offset is not |
| 2460 | * pre-assigned, but during HW_RESTART we want to reuse the |
| 2461 | * same indices, so we pass them when this function is called. |
| 2462 | * |
| 2463 | * In D3 entry, we need to hardcoded the indices (because the |
| 2464 | * firmware hardcodes the PTK offset to 0). In this case, we |
| 2465 | * need to make sure we don't overwrite the hw_key_idx in the |
| 2466 | * keyconf structure, because otherwise we cannot configure |
| 2467 | * the original ones back when resuming. |
| 2468 | */ |
| 2469 | if (key_offset == STA_KEY_IDX_INVALID) { |
| 2470 | key_offset = iwl_mvm_set_fw_key_idx(mvm); |
| 2471 | if (key_offset == STA_KEY_IDX_INVALID) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2472 | return -ENOSPC; |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2473 | keyconf->hw_key_idx = key_offset; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2474 | } |
| 2475 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2476 | 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] | 2477 | if (ret) |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2478 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2479 | |
| 2480 | /* |
| 2481 | * For WEP, the same key is used for multicast and unicast. Upload it |
| 2482 | * again, using the same key offset, and now pointing the other one |
| 2483 | * to the same key slot (offset). |
| 2484 | * If this fails, remove the original as well. |
| 2485 | */ |
| 2486 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 2487 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) { |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2488 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, |
| 2489 | key_offset, !mcast); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2490 | if (ret) { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2491 | __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 2492 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2493 | } |
| 2494 | } |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2495 | |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 2496 | __set_bit(key_offset, mvm->fw_key_table); |
| 2497 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2498 | end: |
| 2499 | IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", |
| 2500 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 2501 | sta ? sta->addr : zero_addr, ret); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2502 | return ret; |
| 2503 | } |
| 2504 | |
| 2505 | int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, |
| 2506 | struct ieee80211_vif *vif, |
| 2507 | struct ieee80211_sta *sta, |
| 2508 | struct ieee80211_key_conf *keyconf) |
| 2509 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2510 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2511 | struct iwl_mvm_sta *mvm_sta; |
| 2512 | u8 sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2513 | int ret, i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2514 | |
| 2515 | lockdep_assert_held(&mvm->mutex); |
| 2516 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2517 | /* Get the station from the mvm local station table */ |
| 2518 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2519 | |
| 2520 | IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", |
| 2521 | keyconf->keyidx, sta_id); |
| 2522 | |
| 2523 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) |
| 2524 | return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); |
| 2525 | |
| 2526 | if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) { |
| 2527 | IWL_ERR(mvm, "offset %d not used in fw key table.\n", |
| 2528 | keyconf->hw_key_idx); |
| 2529 | return -ENOENT; |
| 2530 | } |
| 2531 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2532 | /* track which key was deleted last */ |
| 2533 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 2534 | if (mvm->fw_key_deleted[i] < U8_MAX) |
| 2535 | mvm->fw_key_deleted[i]++; |
| 2536 | } |
| 2537 | mvm->fw_key_deleted[keyconf->hw_key_idx] = 0; |
| 2538 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2539 | if (!mvm_sta) { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2540 | IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); |
| 2541 | return 0; |
| 2542 | } |
| 2543 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2544 | sta_id = mvm_sta->sta_id; |
| 2545 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2546 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
| 2547 | if (ret) |
| 2548 | return ret; |
| 2549 | |
| 2550 | /* delete WEP key twice to get rid of (now useless) offset */ |
| 2551 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 2552 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 2553 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast); |
| 2554 | |
| 2555 | return ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 2556 | } |
| 2557 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2558 | void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, |
| 2559 | struct ieee80211_vif *vif, |
| 2560 | struct ieee80211_key_conf *keyconf, |
| 2561 | struct ieee80211_sta *sta, u32 iv32, |
| 2562 | u16 *phase1key) |
| 2563 | { |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 2564 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2565 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2566 | |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 2567 | rcu_read_lock(); |
| 2568 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2569 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 2570 | if (WARN_ON_ONCE(!mvm_sta)) |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 2571 | goto unlock; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2572 | iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2573 | iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx); |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 2574 | |
| 2575 | unlock: |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 2576 | rcu_read_unlock(); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2577 | } |
| 2578 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 2579 | void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, |
| 2580 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2581 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2582 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2583 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2584 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 2585 | .sta_id = mvmsta->sta_id, |
Emmanuel Grumbach | 5af0177 | 2013-06-09 12:59:24 +0300 | [diff] [blame] | 2586 | .station_flags_msk = cpu_to_le32(STA_FLG_PS), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 2587 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2588 | }; |
| 2589 | int ret; |
| 2590 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2591 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 2592 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2593 | if (ret) |
| 2594 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 2595 | } |
| 2596 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 2597 | void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, |
| 2598 | struct ieee80211_sta *sta, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2599 | enum ieee80211_frame_release_type reason, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2600 | u16 cnt, u16 tids, bool more_data, |
| 2601 | bool agg) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2602 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2603 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2604 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2605 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 2606 | .sta_id = mvmsta->sta_id, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2607 | .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, |
| 2608 | .sleep_tx_count = cpu_to_le16(cnt), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 2609 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2610 | }; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2611 | int tid, ret; |
| 2612 | unsigned long _tids = tids; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2613 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2614 | /* convert TIDs to ACs - we don't support TSPEC so that's OK |
| 2615 | * Note that this field is reserved and unused by firmware not |
| 2616 | * supporting GO uAPSD, so it's safe to always do this. |
| 2617 | */ |
| 2618 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) |
| 2619 | cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); |
| 2620 | |
| 2621 | /* If we're releasing frames from aggregation queues then check if the |
| 2622 | * all queues combined that we're releasing frames from have |
| 2623 | * - more frames than the service period, in which case more_data |
| 2624 | * needs to be set |
| 2625 | * - fewer than 'cnt' frames, in which case we need to adjust the |
| 2626 | * firmware command (but do that unconditionally) |
| 2627 | */ |
| 2628 | if (agg) { |
| 2629 | int remaining = cnt; |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 2630 | int sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2631 | |
| 2632 | spin_lock_bh(&mvmsta->lock); |
| 2633 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { |
| 2634 | struct iwl_mvm_tid_data *tid_data; |
| 2635 | u16 n_queued; |
| 2636 | |
| 2637 | tid_data = &mvmsta->tid_data[tid]; |
| 2638 | if (WARN(tid_data->state != IWL_AGG_ON && |
| 2639 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA, |
| 2640 | "TID %d state is %d\n", |
| 2641 | tid, tid_data->state)) { |
| 2642 | spin_unlock_bh(&mvmsta->lock); |
| 2643 | ieee80211_sta_eosp(sta); |
| 2644 | return; |
| 2645 | } |
| 2646 | |
| 2647 | n_queued = iwl_mvm_tid_queued(tid_data); |
| 2648 | if (n_queued > remaining) { |
| 2649 | more_data = true; |
| 2650 | remaining = 0; |
| 2651 | break; |
| 2652 | } |
| 2653 | remaining -= n_queued; |
| 2654 | } |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 2655 | sleep_tx_count = cnt - remaining; |
| 2656 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) |
| 2657 | mvmsta->sleep_tx_count = sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2658 | spin_unlock_bh(&mvmsta->lock); |
| 2659 | |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 2660 | cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2661 | if (WARN_ON(cnt - remaining == 0)) { |
| 2662 | ieee80211_sta_eosp(sta); |
| 2663 | return; |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | /* Note: this is ignored by firmware not supporting GO uAPSD */ |
| 2668 | if (more_data) |
| 2669 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA); |
| 2670 | |
| 2671 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { |
| 2672 | mvmsta->next_status_eosp = true; |
| 2673 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL); |
| 2674 | } else { |
| 2675 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD); |
| 2676 | } |
| 2677 | |
Emmanuel Grumbach | 156f92f | 2015-11-24 14:55:18 +0200 | [diff] [blame] | 2678 | /* block the Tx queues until the FW updated the sleep Tx count */ |
| 2679 | iwl_trans_block_txq_ptrs(mvm->trans, true); |
| 2680 | |
| 2681 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, |
| 2682 | CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK, |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2683 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2684 | if (ret) |
| 2685 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 2686 | } |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2687 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 2688 | void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, |
| 2689 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2690 | { |
| 2691 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 2692 | struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; |
| 2693 | struct ieee80211_sta *sta; |
| 2694 | u32 sta_id = le32_to_cpu(notif->sta_id); |
| 2695 | |
| 2696 | if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 2697 | return; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2698 | |
| 2699 | rcu_read_lock(); |
| 2700 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 2701 | if (!IS_ERR_OR_NULL(sta)) |
| 2702 | ieee80211_sta_eosp(sta); |
| 2703 | rcu_read_unlock(); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2704 | } |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 2705 | |
| 2706 | void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm, |
| 2707 | struct iwl_mvm_sta *mvmsta, bool disable) |
| 2708 | { |
| 2709 | struct iwl_mvm_add_sta_cmd cmd = { |
| 2710 | .add_modify = STA_MODE_MODIFY, |
| 2711 | .sta_id = mvmsta->sta_id, |
| 2712 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, |
| 2713 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), |
| 2714 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
| 2715 | }; |
| 2716 | int ret; |
| 2717 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2718 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 2719 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 2720 | if (ret) |
| 2721 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 2722 | } |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 2723 | |
| 2724 | void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm, |
| 2725 | struct ieee80211_sta *sta, |
| 2726 | bool disable) |
| 2727 | { |
| 2728 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 2729 | |
| 2730 | spin_lock_bh(&mvm_sta->lock); |
| 2731 | |
| 2732 | if (mvm_sta->disable_tx == disable) { |
| 2733 | spin_unlock_bh(&mvm_sta->lock); |
| 2734 | return; |
| 2735 | } |
| 2736 | |
| 2737 | mvm_sta->disable_tx = disable; |
| 2738 | |
| 2739 | /* |
Sara Sharon | 0d365ae | 2015-03-31 12:24:05 +0300 | [diff] [blame] | 2740 | * Tell mac80211 to start/stop queuing tx for this station, |
| 2741 | * but don't stop queuing if there are still pending frames |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 2742 | * for this station. |
| 2743 | */ |
| 2744 | if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) |
| 2745 | ieee80211_sta_block_awake(mvm->hw, sta, disable); |
| 2746 | |
| 2747 | iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable); |
| 2748 | |
| 2749 | spin_unlock_bh(&mvm_sta->lock); |
| 2750 | } |
| 2751 | |
| 2752 | void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm, |
| 2753 | struct iwl_mvm_vif *mvmvif, |
| 2754 | bool disable) |
| 2755 | { |
| 2756 | struct ieee80211_sta *sta; |
| 2757 | struct iwl_mvm_sta *mvm_sta; |
| 2758 | int i; |
| 2759 | |
| 2760 | lockdep_assert_held(&mvm->mutex); |
| 2761 | |
| 2762 | /* Block/unblock all the stations of the given mvmvif */ |
| 2763 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 2764 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 2765 | lockdep_is_held(&mvm->mutex)); |
| 2766 | if (IS_ERR_OR_NULL(sta)) |
| 2767 | continue; |
| 2768 | |
| 2769 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 2770 | if (mvm_sta->mac_id_n_color != |
| 2771 | FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)) |
| 2772 | continue; |
| 2773 | |
| 2774 | iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable); |
| 2775 | } |
| 2776 | } |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 2777 | |
| 2778 | void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 2779 | { |
| 2780 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2781 | struct iwl_mvm_sta *mvmsta; |
| 2782 | |
| 2783 | rcu_read_lock(); |
| 2784 | |
| 2785 | mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id); |
| 2786 | |
| 2787 | if (!WARN_ON(!mvmsta)) |
| 2788 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true); |
| 2789 | |
| 2790 | rcu_read_unlock(); |
| 2791 | } |