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 | |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 226 | static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm, |
| 227 | struct ieee80211_sta *sta) |
| 228 | { |
| 229 | unsigned long used_hw_queues; |
| 230 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 231 | unsigned int wdg_timeout = |
| 232 | iwl_mvm_get_wd_timeout(mvm, NULL, true, false); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 233 | u32 ac; |
| 234 | |
| 235 | lockdep_assert_held(&mvm->mutex); |
| 236 | |
| 237 | used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL); |
| 238 | |
| 239 | /* Find available queues, and allocate them to the ACs */ |
| 240 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 241 | u8 queue = find_first_zero_bit(&used_hw_queues, |
| 242 | mvm->first_agg_queue); |
| 243 | |
| 244 | if (queue >= mvm->first_agg_queue) { |
| 245 | IWL_ERR(mvm, "Failed to allocate STA queue\n"); |
| 246 | return -EBUSY; |
| 247 | } |
| 248 | |
| 249 | __set_bit(queue, &used_hw_queues); |
| 250 | mvmsta->hw_queue[ac] = queue; |
| 251 | } |
| 252 | |
| 253 | /* Found a place for all queues - enable them */ |
| 254 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 255 | iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac], |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 256 | mvmsta->hw_queue[ac], |
Liad Kaufman | 5c1156e | 2015-07-22 17:59:53 +0300 | [diff] [blame] | 257 | iwl_mvm_ac_to_tx_fifo[ac], 0, |
| 258 | wdg_timeout); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 259 | mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]); |
| 260 | } |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm, |
| 266 | struct ieee80211_sta *sta) |
| 267 | { |
| 268 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 269 | unsigned long sta_msk; |
| 270 | int i; |
| 271 | |
| 272 | lockdep_assert_held(&mvm->mutex); |
| 273 | |
| 274 | /* disable the TDLS STA-specific queues */ |
| 275 | sta_msk = mvmsta->tfd_queue_msk; |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 276 | 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] | 277 | iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 278 | } |
| 279 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 280 | static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm, |
| 281 | struct ieee80211_sta *sta, u8 ac, int tid, |
| 282 | struct ieee80211_hdr *hdr) |
| 283 | { |
| 284 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 285 | struct iwl_trans_txq_scd_cfg cfg = { |
| 286 | .fifo = iwl_mvm_ac_to_tx_fifo[ac], |
| 287 | .sta_id = mvmsta->sta_id, |
| 288 | .tid = tid, |
| 289 | .frame_limit = IWL_FRAME_LIMIT, |
| 290 | }; |
| 291 | unsigned int wdg_timeout = |
| 292 | iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); |
| 293 | u8 mac_queue = mvmsta->vif->hw_queue[ac]; |
| 294 | int queue = -1; |
| 295 | int ssn; |
| 296 | |
| 297 | lockdep_assert_held(&mvm->mutex); |
| 298 | |
| 299 | spin_lock(&mvm->queue_info_lock); |
| 300 | |
| 301 | /* |
| 302 | * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one |
| 303 | * exists |
| 304 | */ |
| 305 | if (!ieee80211_is_data_qos(hdr->frame_control) || |
| 306 | ieee80211_is_qos_nullfunc(hdr->frame_control)) { |
| 307 | queue = iwl_mvm_find_free_queue(mvm, IWL_MVM_DQA_MIN_MGMT_QUEUE, |
| 308 | IWL_MVM_DQA_MAX_MGMT_QUEUE); |
| 309 | if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) |
| 310 | IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n", |
| 311 | queue); |
| 312 | |
| 313 | /* If no such queue is found, we'll use a DATA queue instead */ |
| 314 | } |
| 315 | |
| 316 | if (queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) { |
| 317 | queue = mvmsta->reserved_queue; |
| 318 | IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue); |
| 319 | } |
| 320 | |
| 321 | if (queue < 0) |
| 322 | queue = iwl_mvm_find_free_queue(mvm, IWL_MVM_DQA_MIN_DATA_QUEUE, |
| 323 | IWL_MVM_DQA_MAX_DATA_QUEUE); |
| 324 | if (queue >= 0) |
| 325 | mvm->queue_info[queue].setup_reserved = false; |
| 326 | |
| 327 | spin_unlock(&mvm->queue_info_lock); |
| 328 | |
| 329 | /* TODO: support shared queues for same RA */ |
| 330 | if (queue < 0) |
| 331 | return -ENOSPC; |
| 332 | |
| 333 | /* |
| 334 | * Actual en/disablement of aggregations is through the ADD_STA HCMD, |
| 335 | * but for configuring the SCD to send A-MPDUs we need to mark the queue |
| 336 | * as aggregatable. |
| 337 | * Mark all DATA queues as allowing to be aggregated at some point |
| 338 | */ |
| 339 | cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE); |
| 340 | |
| 341 | IWL_DEBUG_TX_QUEUES(mvm, "Allocating queue #%d to sta %d on tid %d\n", |
| 342 | queue, mvmsta->sta_id, tid); |
| 343 | |
| 344 | ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl)); |
| 345 | iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg, |
| 346 | wdg_timeout); |
| 347 | |
| 348 | spin_lock_bh(&mvmsta->lock); |
| 349 | mvmsta->tid_data[tid].txq_id = queue; |
| 350 | mvmsta->tfd_queue_msk |= BIT(queue); |
| 351 | |
| 352 | if (mvmsta->reserved_queue == queue) |
| 353 | mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE; |
| 354 | spin_unlock_bh(&mvmsta->lock); |
| 355 | |
| 356 | return iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES); |
| 357 | } |
| 358 | |
| 359 | static inline u8 iwl_mvm_tid_to_ac_queue(int tid) |
| 360 | { |
| 361 | if (tid == IWL_MAX_TID_COUNT) |
| 362 | return IEEE80211_AC_VO; /* MGMT */ |
| 363 | |
| 364 | return tid_to_mac80211_ac[tid]; |
| 365 | } |
| 366 | |
| 367 | static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm, |
| 368 | struct ieee80211_sta *sta, int tid) |
| 369 | { |
| 370 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 371 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 372 | struct sk_buff *skb; |
| 373 | struct ieee80211_hdr *hdr; |
| 374 | struct sk_buff_head deferred_tx; |
| 375 | u8 mac_queue; |
| 376 | bool no_queue = false; /* Marks if there is a problem with the queue */ |
| 377 | u8 ac; |
| 378 | |
| 379 | lockdep_assert_held(&mvm->mutex); |
| 380 | |
| 381 | skb = skb_peek(&tid_data->deferred_tx_frames); |
| 382 | if (!skb) |
| 383 | return; |
| 384 | hdr = (void *)skb->data; |
| 385 | |
| 386 | ac = iwl_mvm_tid_to_ac_queue(tid); |
| 387 | mac_queue = IEEE80211_SKB_CB(skb)->hw_queue; |
| 388 | |
| 389 | if (tid_data->txq_id == IEEE80211_INVAL_HW_QUEUE && |
| 390 | iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) { |
| 391 | IWL_ERR(mvm, |
| 392 | "Can't alloc TXQ for sta %d tid %d - dropping frame\n", |
| 393 | mvmsta->sta_id, tid); |
| 394 | |
| 395 | /* |
| 396 | * Mark queue as problematic so later the deferred traffic is |
| 397 | * freed, as we can do nothing with it |
| 398 | */ |
| 399 | no_queue = true; |
| 400 | } |
| 401 | |
| 402 | __skb_queue_head_init(&deferred_tx); |
| 403 | |
| 404 | spin_lock(&mvmsta->lock); |
| 405 | skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx); |
| 406 | spin_unlock(&mvmsta->lock); |
| 407 | |
| 408 | /* Disable bottom-halves when entering TX path */ |
| 409 | local_bh_disable(); |
| 410 | while ((skb = __skb_dequeue(&deferred_tx))) |
| 411 | if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta)) |
| 412 | ieee80211_free_txskb(mvm->hw, skb); |
| 413 | local_bh_enable(); |
| 414 | |
| 415 | /* Wake queue */ |
| 416 | iwl_mvm_start_mac_queues(mvm, BIT(mac_queue)); |
| 417 | } |
| 418 | |
| 419 | void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk) |
| 420 | { |
| 421 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, |
| 422 | add_stream_wk); |
| 423 | struct ieee80211_sta *sta; |
| 424 | struct iwl_mvm_sta *mvmsta; |
| 425 | unsigned long deferred_tid_traffic; |
| 426 | int sta_id, tid; |
| 427 | |
| 428 | mutex_lock(&mvm->mutex); |
| 429 | |
| 430 | /* Go over all stations with deferred traffic */ |
| 431 | for_each_set_bit(sta_id, mvm->sta_deferred_frames, |
| 432 | IWL_MVM_STATION_COUNT) { |
| 433 | clear_bit(sta_id, mvm->sta_deferred_frames); |
| 434 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 435 | lockdep_is_held(&mvm->mutex)); |
| 436 | if (IS_ERR_OR_NULL(sta)) |
| 437 | continue; |
| 438 | |
| 439 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 440 | deferred_tid_traffic = mvmsta->deferred_traffic_tid_map; |
| 441 | |
| 442 | for_each_set_bit(tid, &deferred_tid_traffic, |
| 443 | IWL_MAX_TID_COUNT + 1) |
| 444 | iwl_mvm_tx_deferred_stream(mvm, sta, tid); |
| 445 | } |
| 446 | |
| 447 | mutex_unlock(&mvm->mutex); |
| 448 | } |
| 449 | |
| 450 | static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm, |
| 451 | struct ieee80211_sta *sta) |
| 452 | { |
| 453 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 454 | int queue; |
| 455 | |
| 456 | spin_lock_bh(&mvm->queue_info_lock); |
| 457 | |
| 458 | /* Make sure we have free resources for this STA */ |
| 459 | queue = iwl_mvm_find_free_queue(mvm, IWL_MVM_DQA_MIN_DATA_QUEUE, |
| 460 | IWL_MVM_DQA_MAX_DATA_QUEUE); |
| 461 | if (queue < 0) { |
| 462 | spin_unlock_bh(&mvm->queue_info_lock); |
| 463 | IWL_ERR(mvm, "No available queues for new station\n"); |
| 464 | return -ENOSPC; |
| 465 | } |
| 466 | mvm->queue_info[queue].setup_reserved = true; |
| 467 | |
| 468 | spin_unlock_bh(&mvm->queue_info_lock); |
| 469 | |
| 470 | mvmsta->reserved_queue = queue; |
| 471 | |
| 472 | IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n", |
| 473 | queue, mvmsta->sta_id); |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 478 | int iwl_mvm_add_sta(struct iwl_mvm *mvm, |
| 479 | struct ieee80211_vif *vif, |
| 480 | struct ieee80211_sta *sta) |
| 481 | { |
| 482 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 483 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 484 | struct iwl_mvm_rxq_dup_data *dup_data; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 485 | int i, ret, sta_id; |
| 486 | |
| 487 | lockdep_assert_held(&mvm->mutex); |
| 488 | |
| 489 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 490 | sta_id = iwl_mvm_find_free_sta_id(mvm, |
| 491 | ieee80211_vif_type_p2p(vif)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 492 | else |
| 493 | sta_id = mvm_sta->sta_id; |
| 494 | |
Johannes Berg | 36f4631 | 2015-03-10 20:32:08 +0100 | [diff] [blame] | 495 | if (sta_id == IWL_MVM_STATION_COUNT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 496 | return -ENOSPC; |
| 497 | |
| 498 | spin_lock_init(&mvm_sta->lock); |
| 499 | |
| 500 | mvm_sta->sta_id = sta_id; |
| 501 | mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 502 | mvmvif->color); |
| 503 | mvm_sta->vif = vif; |
| 504 | mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 505 | mvm_sta->tx_protection = 0; |
| 506 | mvm_sta->tt_tx_protection = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 507 | |
| 508 | /* HW restart, don't assume the memory has been zeroed */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 509 | atomic_set(&mvm->pending_frames[sta_id], 0); |
Liad Kaufman | 69191af | 2015-09-01 18:50:22 +0300 | [diff] [blame] | 510 | mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 511 | mvm_sta->tfd_queue_msk = 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 512 | |
| 513 | /* allocate new queues for a TDLS station */ |
| 514 | if (sta->tdls) { |
| 515 | ret = iwl_mvm_tdls_sta_init(mvm, sta); |
| 516 | if (ret) |
| 517 | return ret; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 518 | } else if (!iwl_mvm_is_dqa_supported(mvm)) { |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 519 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 520 | if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE) |
| 521 | mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]); |
| 522 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 523 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 524 | /* for HW restart - reset everything but the sequence number */ |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 525 | for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 526 | u16 seq = mvm_sta->tid_data[i].seq_number; |
| 527 | memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); |
| 528 | mvm_sta->tid_data[i].seq_number = seq; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 529 | |
| 530 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 531 | continue; |
| 532 | |
| 533 | /* |
| 534 | * Mark all queues for this STA as unallocated and defer TX |
| 535 | * frames until the queue is allocated |
| 536 | */ |
| 537 | mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; |
| 538 | skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 539 | } |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 540 | mvm_sta->deferred_traffic_tid_map = 0; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 541 | mvm_sta->agg_tids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 542 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 543 | if (iwl_mvm_has_new_rx_api(mvm) && |
| 544 | !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 545 | dup_data = kcalloc(mvm->trans->num_rx_queues, |
| 546 | sizeof(*dup_data), |
| 547 | GFP_KERNEL); |
| 548 | if (!dup_data) |
| 549 | return -ENOMEM; |
| 550 | mvm_sta->dup_data = dup_data; |
| 551 | } |
| 552 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 553 | if (iwl_mvm_is_dqa_supported(mvm)) { |
| 554 | ret = iwl_mvm_reserve_sta_stream(mvm, sta); |
| 555 | if (ret) |
| 556 | goto err; |
| 557 | } |
| 558 | |
| 559 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 560 | if (ret) |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 561 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 562 | |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 563 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 564 | if (!sta->tdls) { |
| 565 | WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT); |
| 566 | mvmvif->ap_sta_id = sta_id; |
| 567 | } else { |
| 568 | WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT); |
| 569 | } |
| 570 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 571 | |
| 572 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); |
| 573 | |
| 574 | return 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 575 | |
| 576 | err: |
| 577 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 578 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 581 | int iwl_mvm_update_sta(struct iwl_mvm *mvm, |
| 582 | struct ieee80211_vif *vif, |
| 583 | struct ieee80211_sta *sta) |
| 584 | { |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 585 | return iwl_mvm_sta_send_to_fw(mvm, sta, true, 0); |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 588 | int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 589 | bool drain) |
| 590 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 591 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 592 | int ret; |
| 593 | u32 status; |
| 594 | |
| 595 | lockdep_assert_held(&mvm->mutex); |
| 596 | |
| 597 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 598 | cmd.sta_id = mvmsta->sta_id; |
| 599 | cmd.add_modify = STA_MODE_MODIFY; |
| 600 | cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; |
| 601 | cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); |
| 602 | |
| 603 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 604 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 605 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 606 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 607 | if (ret) |
| 608 | return ret; |
| 609 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 610 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 611 | case ADD_STA_SUCCESS: |
| 612 | IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", |
| 613 | mvmsta->sta_id); |
| 614 | break; |
| 615 | default: |
| 616 | ret = -EIO; |
| 617 | IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", |
| 618 | mvmsta->sta_id); |
| 619 | break; |
| 620 | } |
| 621 | |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | /* |
| 626 | * Remove a station from the FW table. Before sending the command to remove |
| 627 | * the station validate that the station is indeed known to the driver (sanity |
| 628 | * only). |
| 629 | */ |
| 630 | static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) |
| 631 | { |
| 632 | struct ieee80211_sta *sta; |
| 633 | struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { |
| 634 | .sta_id = sta_id, |
| 635 | }; |
| 636 | int ret; |
| 637 | |
| 638 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 639 | lockdep_is_held(&mvm->mutex)); |
| 640 | |
| 641 | /* Note: internal stations are marked as error values */ |
| 642 | if (!sta) { |
| 643 | IWL_ERR(mvm, "Invalid station id\n"); |
| 644 | return -EINVAL; |
| 645 | } |
| 646 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 647 | ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 648 | sizeof(rm_sta_cmd), &rm_sta_cmd); |
| 649 | if (ret) { |
| 650 | IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); |
| 651 | return ret; |
| 652 | } |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | void iwl_mvm_sta_drained_wk(struct work_struct *wk) |
| 658 | { |
| 659 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk); |
| 660 | u8 sta_id; |
| 661 | |
| 662 | /* |
| 663 | * The mutex is needed because of the SYNC cmd, but not only: if the |
| 664 | * work would run concurrently with iwl_mvm_rm_sta, it would run before |
| 665 | * iwl_mvm_rm_sta sets the station as busy, and exit. Then |
| 666 | * iwl_mvm_rm_sta would set the station as busy, and nobody will clean |
| 667 | * that later. |
| 668 | */ |
| 669 | mutex_lock(&mvm->mutex); |
| 670 | |
| 671 | for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) { |
| 672 | int ret; |
| 673 | struct ieee80211_sta *sta = |
| 674 | rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 675 | lockdep_is_held(&mvm->mutex)); |
| 676 | |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 677 | /* |
| 678 | * This station is in use or RCU-removed; the latter happens in |
| 679 | * managed mode, where mac80211 removes the station before we |
| 680 | * can remove it from firmware (we can only do that after the |
| 681 | * MAC is marked unassociated), and possibly while the deauth |
| 682 | * frame to disconnect from the AP is still queued. Then, the |
| 683 | * station pointer is -ENOENT when the last skb is reclaimed. |
| 684 | */ |
| 685 | if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 686 | continue; |
| 687 | |
| 688 | if (PTR_ERR(sta) == -EINVAL) { |
| 689 | IWL_ERR(mvm, "Drained sta %d, but it is internal?\n", |
| 690 | sta_id); |
| 691 | continue; |
| 692 | } |
| 693 | |
| 694 | if (!sta) { |
| 695 | IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n", |
| 696 | sta_id); |
| 697 | continue; |
| 698 | } |
| 699 | |
| 700 | WARN_ON(PTR_ERR(sta) != -EBUSY); |
| 701 | /* This station was removed and we waited until it got drained, |
| 702 | * we can now proceed and remove it. |
| 703 | */ |
| 704 | ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 705 | if (ret) { |
| 706 | IWL_ERR(mvm, |
| 707 | "Couldn't remove sta %d after it was drained\n", |
| 708 | sta_id); |
| 709 | continue; |
| 710 | } |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 711 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 712 | clear_bit(sta_id, mvm->sta_drained); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 713 | |
| 714 | if (mvm->tfd_drained[sta_id]) { |
| 715 | unsigned long i, msk = mvm->tfd_drained[sta_id]; |
| 716 | |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 717 | for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE) |
Arik Nemtsov | 06ecdba | 2015-10-12 14:47:11 +0300 | [diff] [blame] | 718 | iwl_mvm_disable_txq(mvm, i, i, |
| 719 | IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 720 | |
| 721 | mvm->tfd_drained[sta_id] = 0; |
| 722 | IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n", |
| 723 | sta_id, msk); |
| 724 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | mutex_unlock(&mvm->mutex); |
| 728 | } |
| 729 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 730 | static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm, |
| 731 | struct ieee80211_vif *vif, |
| 732 | struct iwl_mvm_sta *mvm_sta) |
| 733 | { |
| 734 | int ac; |
| 735 | int i; |
| 736 | |
| 737 | lockdep_assert_held(&mvm->mutex); |
| 738 | |
| 739 | for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) { |
| 740 | if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE) |
| 741 | continue; |
| 742 | |
| 743 | ac = iwl_mvm_tid_to_ac_queue(i); |
| 744 | iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id, |
| 745 | vif->hw_queue[ac], i, 0); |
| 746 | mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; |
| 747 | } |
| 748 | } |
| 749 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 750 | int iwl_mvm_rm_sta(struct iwl_mvm *mvm, |
| 751 | struct ieee80211_vif *vif, |
| 752 | struct ieee80211_sta *sta) |
| 753 | { |
| 754 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 755 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 756 | int ret; |
| 757 | |
| 758 | lockdep_assert_held(&mvm->mutex); |
| 759 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 760 | if (iwl_mvm_has_new_rx_api(mvm)) |
| 761 | kfree(mvm_sta->dup_data); |
| 762 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 763 | if (vif->type == NL80211_IFTYPE_STATION && |
| 764 | mvmvif->ap_sta_id == mvm_sta->sta_id) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 765 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
| 766 | if (ret) |
| 767 | return ret; |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 768 | /* flush its queues here since we are freeing mvm_sta */ |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 769 | 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] | 770 | if (ret) |
| 771 | return ret; |
| 772 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 773 | mvm_sta->tfd_queue_msk); |
| 774 | if (ret) |
| 775 | return ret; |
| 776 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, false); |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 777 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 778 | /* If DQA is supported - the queues can be disabled now */ |
| 779 | if (iwl_mvm_is_dqa_supported(mvm)) |
| 780 | iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta); |
| 781 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 782 | /* if we are associated - we can't remove the AP STA now */ |
| 783 | if (vif->bss_conf.assoc) |
| 784 | return ret; |
| 785 | |
| 786 | /* unassoc - go ahead - remove the AP STA now */ |
| 787 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 788 | |
| 789 | /* clear d0i3_ap_sta_id if no longer relevant */ |
| 790 | if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id) |
| 791 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /* |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 795 | * This shouldn't happen - the TDLS channel switch should be canceled |
| 796 | * before the STA is removed. |
| 797 | */ |
| 798 | if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) { |
| 799 | mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT; |
| 800 | cancel_delayed_work(&mvm->tdls_cs.dwork); |
| 801 | } |
| 802 | |
| 803 | /* |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 804 | * Make sure that the tx response code sees the station as -EBUSY and |
| 805 | * calls the drain worker. |
| 806 | */ |
| 807 | spin_lock_bh(&mvm_sta->lock); |
| 808 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 809 | * There are frames pending on the AC queues for this station. |
| 810 | * We need to wait until all the frames are drained... |
| 811 | */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 812 | if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 813 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
| 814 | ERR_PTR(-EBUSY)); |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 815 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 816 | |
| 817 | /* disable TDLS sta queues on drain complete */ |
| 818 | if (sta->tdls) { |
| 819 | mvm->tfd_drained[mvm_sta->sta_id] = |
| 820 | mvm_sta->tfd_queue_msk; |
| 821 | IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", |
| 822 | mvm_sta->sta_id); |
| 823 | } |
| 824 | |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 825 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 826 | } else { |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 827 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 828 | |
| 829 | if (sta->tdls) |
| 830 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 831 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 832 | ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 833 | 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] | 834 | } |
| 835 | |
| 836 | return ret; |
| 837 | } |
| 838 | |
| 839 | int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, |
| 840 | struct ieee80211_vif *vif, |
| 841 | u8 sta_id) |
| 842 | { |
| 843 | int ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 844 | |
| 845 | lockdep_assert_held(&mvm->mutex); |
| 846 | |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 847 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 848 | return ret; |
| 849 | } |
| 850 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 851 | int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, |
| 852 | struct iwl_mvm_int_sta *sta, |
| 853 | u32 qmask, enum nl80211_iftype iftype) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 854 | { |
| 855 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 856 | sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 857 | if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT)) |
| 858 | return -ENOSPC; |
| 859 | } |
| 860 | |
| 861 | sta->tfd_queue_msk = qmask; |
| 862 | |
| 863 | /* put a non-NULL value so iterating over the stations won't stop */ |
| 864 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); |
| 865 | return 0; |
| 866 | } |
| 867 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 868 | static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, |
| 869 | struct iwl_mvm_int_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 870 | { |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 871 | 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] | 872 | memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); |
| 873 | sta->sta_id = IWL_MVM_STATION_COUNT; |
| 874 | } |
| 875 | |
| 876 | static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, |
| 877 | struct iwl_mvm_int_sta *sta, |
| 878 | const u8 *addr, |
| 879 | u16 mac_id, u16 color) |
| 880 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 881 | struct iwl_mvm_add_sta_cmd cmd; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 882 | int ret; |
| 883 | u32 status; |
| 884 | |
| 885 | lockdep_assert_held(&mvm->mutex); |
| 886 | |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 887 | memset(&cmd, 0, sizeof(cmd)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 888 | cmd.sta_id = sta->sta_id; |
| 889 | cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, |
| 890 | color)); |
| 891 | |
| 892 | cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 893 | cmd.tid_disable_tx = cpu_to_le16(0xffff); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 894 | |
| 895 | if (addr) |
| 896 | memcpy(cmd.addr, addr, ETH_ALEN); |
| 897 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 898 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 899 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 900 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 901 | if (ret) |
| 902 | return ret; |
| 903 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 904 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 905 | case ADD_STA_SUCCESS: |
| 906 | IWL_DEBUG_INFO(mvm, "Internal station added.\n"); |
| 907 | return 0; |
| 908 | default: |
| 909 | ret = -EIO; |
| 910 | IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", |
| 911 | status); |
| 912 | break; |
| 913 | } |
| 914 | return ret; |
| 915 | } |
| 916 | |
| 917 | int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) |
| 918 | { |
Emmanuel Grumbach | 4cf677f | 2015-01-12 14:38:29 +0200 | [diff] [blame] | 919 | unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ? |
| 920 | mvm->cfg->base_params->wd_timeout : |
| 921 | IWL_WATCHDOG_DISABLED; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 922 | int ret; |
| 923 | |
| 924 | lockdep_assert_held(&mvm->mutex); |
| 925 | |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 926 | /* Map Aux queue to fifo - needs to happen before adding Aux station */ |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 927 | iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue, |
Liad Kaufman | 5c1156e | 2015-07-22 17:59:53 +0300 | [diff] [blame] | 928 | IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout); |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 929 | |
| 930 | /* Allocate aux station and assign to it the aux queue */ |
| 931 | 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] | 932 | NL80211_IFTYPE_UNSPECIFIED); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 933 | if (ret) |
| 934 | return ret; |
| 935 | |
| 936 | ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, |
| 937 | MAC_INDEX_AUX, 0); |
| 938 | |
| 939 | if (ret) |
| 940 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 941 | return ret; |
| 942 | } |
| 943 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 944 | int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 945 | { |
| 946 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 947 | |
| 948 | lockdep_assert_held(&mvm->mutex); |
| 949 | return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr, |
| 950 | mvmvif->id, 0); |
| 951 | } |
| 952 | |
| 953 | int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 954 | { |
| 955 | int ret; |
| 956 | |
| 957 | lockdep_assert_held(&mvm->mutex); |
| 958 | |
| 959 | ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id); |
| 960 | if (ret) |
| 961 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 962 | |
| 963 | return ret; |
| 964 | } |
| 965 | |
| 966 | void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm) |
| 967 | { |
| 968 | iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta); |
| 969 | } |
| 970 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 971 | void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm) |
| 972 | { |
| 973 | lockdep_assert_held(&mvm->mutex); |
| 974 | |
| 975 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 976 | } |
| 977 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 978 | /* |
| 979 | * Send the add station command for the vif's broadcast station. |
| 980 | * Assumes that the station was already allocated. |
| 981 | * |
| 982 | * @mvm: the mvm component |
| 983 | * @vif: the interface to which the broadcast station is added |
| 984 | * @bsta: the broadcast station to add. |
| 985 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 986 | 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] | 987 | { |
| 988 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 989 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 990 | static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
Johannes Berg | a424340 | 2014-01-20 23:46:38 +0100 | [diff] [blame] | 991 | const u8 *baddr = _baddr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 992 | |
| 993 | lockdep_assert_held(&mvm->mutex); |
| 994 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 995 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 996 | baddr = vif->bss_conf.bssid; |
| 997 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 998 | if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT)) |
| 999 | return -ENOSPC; |
| 1000 | |
| 1001 | return iwl_mvm_add_int_sta_common(mvm, bsta, baddr, |
| 1002 | mvmvif->id, mvmvif->color); |
| 1003 | } |
| 1004 | |
| 1005 | /* Send the FW a request to remove the station from it's internal data |
| 1006 | * structures, but DO NOT remove the entry from the local data structures. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1007 | 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] | 1008 | { |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1009 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1010 | int ret; |
| 1011 | |
| 1012 | lockdep_assert_held(&mvm->mutex); |
| 1013 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1014 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1015 | if (ret) |
| 1016 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 1017 | return ret; |
| 1018 | } |
| 1019 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1020 | int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1021 | { |
| 1022 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1023 | u32 qmask; |
| 1024 | |
| 1025 | lockdep_assert_held(&mvm->mutex); |
| 1026 | |
Arik Nemtsov | d92b732e | 2014-09-21 19:00:42 +0300 | [diff] [blame] | 1027 | qmask = iwl_mvm_mac_get_queues_mask(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1028 | |
| 1029 | /* |
| 1030 | * The firmware defines the TFD queue mask to only be relevant |
| 1031 | * for *unicast* queues, so the multicast (CAB) queue shouldn't |
| 1032 | * be included. |
| 1033 | */ |
| 1034 | if (vif->type == NL80211_IFTYPE_AP) |
| 1035 | qmask &= ~BIT(vif->cab_queue); |
| 1036 | |
| 1037 | return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask, |
| 1038 | ieee80211_vif_type_p2p(vif)); |
| 1039 | } |
| 1040 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1041 | /* Allocate a new station entry for the broadcast station to the given vif, |
| 1042 | * and send it to the FW. |
| 1043 | * Note that each P2P mac should have its own broadcast station. |
| 1044 | * |
| 1045 | * @mvm: the mvm component |
| 1046 | * @vif: the interface to which the broadcast station is added |
| 1047 | * @bsta: the broadcast station to add. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1048 | 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] | 1049 | { |
| 1050 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1051 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1052 | int ret; |
| 1053 | |
| 1054 | lockdep_assert_held(&mvm->mutex); |
| 1055 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1056 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1057 | if (ret) |
| 1058 | return ret; |
| 1059 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1060 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1061 | |
| 1062 | if (ret) |
| 1063 | iwl_mvm_dealloc_int_sta(mvm, bsta); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1064 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1065 | return ret; |
| 1066 | } |
| 1067 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1068 | void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1069 | { |
| 1070 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1071 | |
| 1072 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 1073 | } |
| 1074 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1075 | /* |
| 1076 | * Send the FW a request to remove the station from it's internal data |
| 1077 | * structures, and in addition remove it from the local data structure. |
| 1078 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1079 | 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] | 1080 | { |
| 1081 | int ret; |
| 1082 | |
| 1083 | lockdep_assert_held(&mvm->mutex); |
| 1084 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1085 | ret = iwl_mvm_send_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1086 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1087 | iwl_mvm_dealloc_bcast_sta(mvm, vif); |
| 1088 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1089 | return ret; |
| 1090 | } |
| 1091 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 1092 | #define IWL_MAX_RX_BA_SESSIONS 16 |
| 1093 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1094 | int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1095 | int tid, u16 ssn, bool start, u8 buf_size) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1096 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1097 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1098 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1099 | int ret; |
| 1100 | u32 status; |
| 1101 | |
| 1102 | lockdep_assert_held(&mvm->mutex); |
| 1103 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 1104 | if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { |
| 1105 | IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); |
| 1106 | return -ENOSPC; |
| 1107 | } |
| 1108 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1109 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 1110 | cmd.sta_id = mvm_sta->sta_id; |
| 1111 | cmd.add_modify = STA_MODE_MODIFY; |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 1112 | if (start) { |
| 1113 | cmd.add_immediate_ba_tid = (u8) tid; |
| 1114 | cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1115 | cmd.rx_ba_window = cpu_to_le16((u16)buf_size); |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 1116 | } else { |
| 1117 | cmd.remove_immediate_ba_tid = (u8) tid; |
| 1118 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1119 | cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : |
| 1120 | STA_MODIFY_REMOVE_BA_TID; |
| 1121 | |
| 1122 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1123 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1124 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1125 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1126 | if (ret) |
| 1127 | return ret; |
| 1128 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1129 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1130 | case ADD_STA_SUCCESS: |
| 1131 | IWL_DEBUG_INFO(mvm, "RX BA Session %sed in fw\n", |
| 1132 | start ? "start" : "stopp"); |
| 1133 | break; |
| 1134 | case ADD_STA_IMMEDIATE_BA_FAILURE: |
| 1135 | IWL_WARN(mvm, "RX BA Session refused by fw\n"); |
| 1136 | ret = -ENOSPC; |
| 1137 | break; |
| 1138 | default: |
| 1139 | ret = -EIO; |
| 1140 | IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", |
| 1141 | start ? "start" : "stopp", status); |
| 1142 | break; |
| 1143 | } |
| 1144 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 1145 | if (!ret) { |
| 1146 | if (start) |
| 1147 | mvm->rx_ba_sessions++; |
| 1148 | else if (mvm->rx_ba_sessions > 0) |
| 1149 | /* check that restart flow didn't zero the counter */ |
| 1150 | mvm->rx_ba_sessions--; |
| 1151 | } |
| 1152 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1153 | return ret; |
| 1154 | } |
| 1155 | |
| 1156 | static int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 1157 | int tid, u8 queue, bool start) |
| 1158 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1159 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1160 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1161 | int ret; |
| 1162 | u32 status; |
| 1163 | |
| 1164 | lockdep_assert_held(&mvm->mutex); |
| 1165 | |
| 1166 | if (start) { |
| 1167 | mvm_sta->tfd_queue_msk |= BIT(queue); |
| 1168 | mvm_sta->tid_disable_agg &= ~BIT(tid); |
| 1169 | } else { |
| 1170 | mvm_sta->tfd_queue_msk &= ~BIT(queue); |
| 1171 | mvm_sta->tid_disable_agg |= BIT(tid); |
| 1172 | } |
| 1173 | |
| 1174 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 1175 | cmd.sta_id = mvm_sta->sta_id; |
| 1176 | cmd.add_modify = STA_MODE_MODIFY; |
| 1177 | cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX; |
| 1178 | cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 1179 | cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); |
| 1180 | |
| 1181 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1182 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1183 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1184 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1185 | if (ret) |
| 1186 | return ret; |
| 1187 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1188 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1189 | case ADD_STA_SUCCESS: |
| 1190 | break; |
| 1191 | default: |
| 1192 | ret = -EIO; |
| 1193 | IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", |
| 1194 | start ? "start" : "stopp", status); |
| 1195 | break; |
| 1196 | } |
| 1197 | |
| 1198 | return ret; |
| 1199 | } |
| 1200 | |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 1201 | const u8 tid_to_mac80211_ac[] = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1202 | IEEE80211_AC_BE, |
| 1203 | IEEE80211_AC_BK, |
| 1204 | IEEE80211_AC_BK, |
| 1205 | IEEE80211_AC_BE, |
| 1206 | IEEE80211_AC_VI, |
| 1207 | IEEE80211_AC_VI, |
| 1208 | IEEE80211_AC_VO, |
| 1209 | IEEE80211_AC_VO, |
| 1210 | }; |
| 1211 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1212 | static const u8 tid_to_ucode_ac[] = { |
| 1213 | AC_BE, |
| 1214 | AC_BK, |
| 1215 | AC_BK, |
| 1216 | AC_BE, |
| 1217 | AC_VI, |
| 1218 | AC_VI, |
| 1219 | AC_VO, |
| 1220 | AC_VO, |
| 1221 | }; |
| 1222 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1223 | int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1224 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
| 1225 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1226 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1227 | struct iwl_mvm_tid_data *tid_data; |
| 1228 | int txq_id; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1229 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1230 | |
| 1231 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) |
| 1232 | return -EINVAL; |
| 1233 | |
| 1234 | if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { |
| 1235 | IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", |
| 1236 | mvmsta->tid_data[tid].state); |
| 1237 | return -ENXIO; |
| 1238 | } |
| 1239 | |
| 1240 | lockdep_assert_held(&mvm->mutex); |
| 1241 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 1242 | spin_lock_bh(&mvmsta->lock); |
| 1243 | |
| 1244 | /* possible race condition - we entered D0i3 while starting agg */ |
| 1245 | if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) { |
| 1246 | spin_unlock_bh(&mvmsta->lock); |
| 1247 | IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n"); |
| 1248 | return -EIO; |
| 1249 | } |
| 1250 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1251 | spin_lock_bh(&mvm->queue_info_lock); |
| 1252 | |
| 1253 | txq_id = iwl_mvm_find_free_queue(mvm, mvm->first_agg_queue, |
| 1254 | mvm->last_agg_queue); |
| 1255 | if (txq_id < 0) { |
| 1256 | ret = txq_id; |
| 1257 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1258 | IWL_ERR(mvm, "Failed to allocate agg queue\n"); |
| 1259 | goto release_locks; |
| 1260 | } |
| 1261 | mvm->queue_info[txq_id].setup_reserved = true; |
| 1262 | spin_unlock_bh(&mvm->queue_info_lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1263 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1264 | tid_data = &mvmsta->tid_data[tid]; |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 1265 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1266 | tid_data->txq_id = txq_id; |
| 1267 | *ssn = tid_data->ssn; |
| 1268 | |
| 1269 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1270 | "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", |
| 1271 | mvmsta->sta_id, tid, txq_id, tid_data->ssn, |
| 1272 | tid_data->next_reclaimed); |
| 1273 | |
| 1274 | if (tid_data->ssn == tid_data->next_reclaimed) { |
| 1275 | tid_data->state = IWL_AGG_STARTING; |
| 1276 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1277 | } else { |
| 1278 | tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; |
| 1279 | } |
| 1280 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1281 | ret = 0; |
| 1282 | |
| 1283 | release_locks: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1284 | spin_unlock_bh(&mvmsta->lock); |
| 1285 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1286 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | 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] | 1290 | struct ieee80211_sta *sta, u16 tid, u8 buf_size, |
| 1291 | bool amsdu) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1292 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1293 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1294 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 1295 | unsigned int wdg_timeout = |
| 1296 | iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false); |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 1297 | int queue, ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1298 | u16 ssn; |
| 1299 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 1300 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1301 | .sta_id = mvmsta->sta_id, |
| 1302 | .tid = tid, |
| 1303 | .frame_limit = buf_size, |
| 1304 | .aggregate = true, |
| 1305 | }; |
| 1306 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1307 | BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE) |
| 1308 | != IWL_MAX_TID_COUNT); |
| 1309 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1310 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); |
| 1311 | |
| 1312 | spin_lock_bh(&mvmsta->lock); |
| 1313 | ssn = tid_data->ssn; |
| 1314 | queue = tid_data->txq_id; |
| 1315 | tid_data->state = IWL_AGG_ON; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1316 | mvmsta->agg_tids |= BIT(tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1317 | tid_data->ssn = 0xffff; |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 1318 | tid_data->amsdu_in_ampdu_allowed = amsdu; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1319 | spin_unlock_bh(&mvmsta->lock); |
| 1320 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 1321 | 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] | 1322 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 1323 | iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[tid_to_mac80211_ac[tid]], |
| 1324 | ssn, &cfg, wdg_timeout); |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 1325 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1326 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 1327 | if (ret) |
| 1328 | return -EIO; |
| 1329 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1330 | /* No need to mark as reserved */ |
| 1331 | spin_lock_bh(&mvm->queue_info_lock); |
| 1332 | mvm->queue_info[queue].setup_reserved = false; |
| 1333 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1334 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1335 | /* |
| 1336 | * Even though in theory the peer could have different |
| 1337 | * aggregation reorder buffer sizes for different sessions, |
| 1338 | * our ucode doesn't allow for that and has a global limit |
| 1339 | * for each station. Therefore, use the minimum of all the |
| 1340 | * aggregation sessions and our default value. |
| 1341 | */ |
| 1342 | mvmsta->max_agg_bufsize = |
| 1343 | min(mvmsta->max_agg_bufsize, buf_size); |
| 1344 | mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; |
| 1345 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 1346 | IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", |
| 1347 | sta->addr, tid); |
| 1348 | |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 1349 | return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1353 | struct ieee80211_sta *sta, u16 tid) |
| 1354 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1355 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1356 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 1357 | u16 txq_id; |
| 1358 | int err; |
| 1359 | |
Emmanuel Grumbach | f9aa8dd | 2013-03-04 09:11:08 +0200 | [diff] [blame] | 1360 | |
| 1361 | /* |
| 1362 | * If mac80211 is cleaning its state, then say that we finished since |
| 1363 | * our state has been cleared anyway. |
| 1364 | */ |
| 1365 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 1366 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1367 | return 0; |
| 1368 | } |
| 1369 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1370 | spin_lock_bh(&mvmsta->lock); |
| 1371 | |
| 1372 | txq_id = tid_data->txq_id; |
| 1373 | |
| 1374 | IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", |
| 1375 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
| 1376 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1377 | mvmsta->agg_tids &= ~BIT(tid); |
| 1378 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1379 | /* No need to mark as reserved anymore */ |
| 1380 | spin_lock_bh(&mvm->queue_info_lock); |
| 1381 | mvm->queue_info[txq_id].setup_reserved = false; |
| 1382 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1383 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1384 | switch (tid_data->state) { |
| 1385 | case IWL_AGG_ON: |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 1386 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1387 | |
| 1388 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1389 | "ssn = %d, next_recl = %d\n", |
| 1390 | tid_data->ssn, tid_data->next_reclaimed); |
| 1391 | |
| 1392 | /* There are still packets for this RA / TID in the HW */ |
| 1393 | if (tid_data->ssn != tid_data->next_reclaimed) { |
| 1394 | tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA; |
| 1395 | err = 0; |
| 1396 | break; |
| 1397 | } |
| 1398 | |
| 1399 | tid_data->ssn = 0xffff; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1400 | tid_data->state = IWL_AGG_OFF; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1401 | spin_unlock_bh(&mvmsta->lock); |
| 1402 | |
| 1403 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1404 | |
| 1405 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 1406 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1407 | iwl_mvm_disable_txq(mvm, txq_id, |
| 1408 | vif->hw_queue[tid_to_mac80211_ac[tid]], tid, |
| 1409 | 0); |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1410 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1411 | case IWL_AGG_STARTING: |
| 1412 | case IWL_EMPTYING_HW_QUEUE_ADDBA: |
| 1413 | /* |
| 1414 | * The agg session has been stopped before it was set up. This |
| 1415 | * can happen when the AddBA timer times out for example. |
| 1416 | */ |
| 1417 | |
| 1418 | /* No barriers since we are under mutex */ |
| 1419 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1420 | |
| 1421 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1422 | tid_data->state = IWL_AGG_OFF; |
| 1423 | err = 0; |
| 1424 | break; |
| 1425 | default: |
| 1426 | IWL_ERR(mvm, |
| 1427 | "Stopping AGG while state not ON or starting for %d on %d (%d)\n", |
| 1428 | mvmsta->sta_id, tid, tid_data->state); |
| 1429 | IWL_ERR(mvm, |
| 1430 | "\ttid_data->txq_id = %d\n", tid_data->txq_id); |
| 1431 | err = -EINVAL; |
| 1432 | } |
| 1433 | |
| 1434 | spin_unlock_bh(&mvmsta->lock); |
| 1435 | |
| 1436 | return err; |
| 1437 | } |
| 1438 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1439 | int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1440 | struct ieee80211_sta *sta, u16 tid) |
| 1441 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1442 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1443 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 1444 | u16 txq_id; |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1445 | enum iwl_mvm_agg_state old_state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1446 | |
| 1447 | /* |
| 1448 | * First set the agg state to OFF to avoid calling |
| 1449 | * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. |
| 1450 | */ |
| 1451 | spin_lock_bh(&mvmsta->lock); |
| 1452 | txq_id = tid_data->txq_id; |
| 1453 | IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", |
| 1454 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1455 | old_state = tid_data->state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1456 | tid_data->state = IWL_AGG_OFF; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1457 | mvmsta->agg_tids &= ~BIT(tid); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1458 | spin_unlock_bh(&mvmsta->lock); |
| 1459 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1460 | /* No need to mark as reserved */ |
| 1461 | spin_lock_bh(&mvm->queue_info_lock); |
| 1462 | mvm->queue_info[txq_id].setup_reserved = false; |
| 1463 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1464 | |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1465 | if (old_state >= IWL_AGG_ON) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1466 | iwl_mvm_drain_sta(mvm, mvmsta, true); |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 1467 | if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0)) |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1468 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1469 | iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 1470 | mvmsta->tfd_queue_msk); |
| 1471 | iwl_mvm_drain_sta(mvm, mvmsta, false); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1472 | |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1473 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 1474 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1475 | iwl_mvm_disable_txq(mvm, tid_data->txq_id, |
| 1476 | vif->hw_queue[tid_to_mac80211_ac[tid]], tid, |
| 1477 | 0); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1478 | } |
| 1479 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1480 | return 0; |
| 1481 | } |
| 1482 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1483 | static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) |
| 1484 | { |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1485 | int i, max = -1, max_offs = -1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1486 | |
| 1487 | lockdep_assert_held(&mvm->mutex); |
| 1488 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1489 | /* Pick the unused key offset with the highest 'deleted' |
| 1490 | * counter. Every time a key is deleted, all the counters |
| 1491 | * are incremented and the one that was just deleted is |
| 1492 | * reset to zero. Thus, the highest counter is the one |
| 1493 | * that was deleted longest ago. Pick that one. |
| 1494 | */ |
| 1495 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 1496 | if (test_bit(i, mvm->fw_key_table)) |
| 1497 | continue; |
| 1498 | if (mvm->fw_key_deleted[i] > max) { |
| 1499 | max = mvm->fw_key_deleted[i]; |
| 1500 | max_offs = i; |
| 1501 | } |
| 1502 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1503 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1504 | if (max_offs < 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1505 | return STA_KEY_IDX_INVALID; |
| 1506 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1507 | return max_offs; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1508 | } |
| 1509 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1510 | static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm, |
| 1511 | struct ieee80211_vif *vif, |
| 1512 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1513 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 1514 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1515 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1516 | if (sta) |
| 1517 | return iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1518 | |
| 1519 | /* |
| 1520 | * The device expects GTKs for station interfaces to be |
| 1521 | * installed as GTKs for the AP station. If we have no |
| 1522 | * station ID, then use AP's station ID. |
| 1523 | */ |
| 1524 | if (vif->type == NL80211_IFTYPE_STATION && |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1525 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 1526 | u8 sta_id = mvmvif->ap_sta_id; |
| 1527 | |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1528 | sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id], |
| 1529 | lockdep_is_held(&mvm->mutex)); |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1530 | /* |
| 1531 | * It is possible that the 'sta' parameter is NULL, |
| 1532 | * for example when a GTK is removed - the sta_id will then |
| 1533 | * be the AP ID, and no station was passed by mac80211. |
| 1534 | */ |
| 1535 | if (IS_ERR_OR_NULL(sta)) |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1536 | return NULL; |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1537 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1538 | return iwl_mvm_sta_from_mac80211(sta); |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1539 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1540 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1541 | return NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, |
| 1545 | struct iwl_mvm_sta *mvm_sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1546 | struct ieee80211_key_conf *keyconf, bool mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1547 | u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags, |
| 1548 | u8 key_offset) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1549 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1550 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1551 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 1552 | int ret; |
| 1553 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1554 | u16 keyidx; |
| 1555 | int i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1556 | u8 sta_id = mvm_sta->sta_id; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1557 | |
| 1558 | keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 1559 | STA_KEY_FLG_KEYID_MSK; |
| 1560 | key_flags = cpu_to_le16(keyidx); |
| 1561 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); |
| 1562 | |
| 1563 | switch (keyconf->cipher) { |
| 1564 | case WLAN_CIPHER_SUITE_TKIP: |
| 1565 | key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1566 | cmd.tkip_rx_tsc_byte2 = tkip_iv32; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1567 | for (i = 0; i < 5; i++) |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1568 | cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); |
| 1569 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1570 | break; |
| 1571 | case WLAN_CIPHER_SUITE_CCMP: |
| 1572 | key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1573 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1574 | break; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1575 | case WLAN_CIPHER_SUITE_WEP104: |
| 1576 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES); |
John W. Linville | aa0cb08 | 2015-01-12 16:18:11 -0500 | [diff] [blame] | 1577 | /* fall through */ |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1578 | case WLAN_CIPHER_SUITE_WEP40: |
| 1579 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP); |
| 1580 | memcpy(cmd.key + 3, keyconf->key, keyconf->keylen); |
| 1581 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1582 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 1583 | key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); |
| 1584 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1585 | } |
| 1586 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1587 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1588 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 1589 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1590 | cmd.key_offset = key_offset; |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1591 | cmd.key_flags = key_flags; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1592 | cmd.sta_id = sta_id; |
| 1593 | |
| 1594 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1595 | if (cmd_flags & CMD_ASYNC) |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1596 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, |
| 1597 | sizeof(cmd), &cmd); |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1598 | else |
| 1599 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 1600 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1601 | |
| 1602 | switch (status) { |
| 1603 | case ADD_STA_SUCCESS: |
| 1604 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); |
| 1605 | break; |
| 1606 | default: |
| 1607 | ret = -EIO; |
| 1608 | IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); |
| 1609 | break; |
| 1610 | } |
| 1611 | |
| 1612 | return ret; |
| 1613 | } |
| 1614 | |
| 1615 | static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, |
| 1616 | struct ieee80211_key_conf *keyconf, |
| 1617 | u8 sta_id, bool remove_key) |
| 1618 | { |
| 1619 | struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; |
| 1620 | |
| 1621 | /* verify the key details match the required command's expectations */ |
| 1622 | if (WARN_ON((keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC) || |
| 1623 | (keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || |
| 1624 | (keyconf->keyidx != 4 && keyconf->keyidx != 5))) |
| 1625 | return -EINVAL; |
| 1626 | |
| 1627 | igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); |
| 1628 | igtk_cmd.sta_id = cpu_to_le32(sta_id); |
| 1629 | |
| 1630 | if (remove_key) { |
| 1631 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); |
| 1632 | } else { |
| 1633 | struct ieee80211_key_seq seq; |
| 1634 | const u8 *pn; |
| 1635 | |
| 1636 | memcpy(igtk_cmd.IGTK, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1637 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 1638 | pn = seq.aes_cmac.pn; |
| 1639 | igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | |
| 1640 | ((u64) pn[4] << 8) | |
| 1641 | ((u64) pn[3] << 16) | |
| 1642 | ((u64) pn[2] << 24) | |
| 1643 | ((u64) pn[1] << 32) | |
| 1644 | ((u64) pn[0] << 40)); |
| 1645 | } |
| 1646 | |
| 1647 | IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", |
| 1648 | remove_key ? "removing" : "installing", |
| 1649 | igtk_cmd.sta_id); |
| 1650 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1651 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1652 | sizeof(igtk_cmd), &igtk_cmd); |
| 1653 | } |
| 1654 | |
| 1655 | |
| 1656 | static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, |
| 1657 | struct ieee80211_vif *vif, |
| 1658 | struct ieee80211_sta *sta) |
| 1659 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 1660 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1661 | |
| 1662 | if (sta) |
| 1663 | return sta->addr; |
| 1664 | |
| 1665 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1666 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 1667 | u8 sta_id = mvmvif->ap_sta_id; |
| 1668 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1669 | lockdep_is_held(&mvm->mutex)); |
| 1670 | return sta->addr; |
| 1671 | } |
| 1672 | |
| 1673 | |
| 1674 | return NULL; |
| 1675 | } |
| 1676 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1677 | static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 1678 | struct ieee80211_vif *vif, |
| 1679 | struct ieee80211_sta *sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1680 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1681 | u8 key_offset, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1682 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1683 | { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1684 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1685 | int ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1686 | const u8 *addr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1687 | struct ieee80211_key_seq seq; |
| 1688 | u16 p1k[5]; |
| 1689 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1690 | switch (keyconf->cipher) { |
| 1691 | case WLAN_CIPHER_SUITE_TKIP: |
| 1692 | addr = iwl_mvm_get_mac_addr(mvm, vif, sta); |
| 1693 | /* get phase 1 key from mac80211 */ |
| 1694 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 1695 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1696 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1697 | seq.tkip.iv32, p1k, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1698 | break; |
| 1699 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1700 | case WLAN_CIPHER_SUITE_WEP40: |
| 1701 | case WLAN_CIPHER_SUITE_WEP104: |
| 1702 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1703 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1704 | break; |
| 1705 | default: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1706 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1707 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1710 | return ret; |
| 1711 | } |
| 1712 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1713 | 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] | 1714 | struct ieee80211_key_conf *keyconf, |
| 1715 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1716 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1717 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1718 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 1719 | int ret; |
| 1720 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1721 | |
Emmanuel Grumbach | 8115efb | 2013-02-05 10:08:35 +0200 | [diff] [blame] | 1722 | key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 1723 | STA_KEY_FLG_KEYID_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1724 | key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); |
| 1725 | key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); |
| 1726 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1727 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1728 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 1729 | |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1730 | cmd.key_flags = key_flags; |
| 1731 | cmd.key_offset = keyconf->hw_key_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1732 | cmd.sta_id = sta_id; |
| 1733 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1734 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1735 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 1736 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1737 | |
| 1738 | switch (status) { |
| 1739 | case ADD_STA_SUCCESS: |
| 1740 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); |
| 1741 | break; |
| 1742 | default: |
| 1743 | ret = -EIO; |
| 1744 | IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); |
| 1745 | break; |
| 1746 | } |
| 1747 | |
| 1748 | return ret; |
| 1749 | } |
| 1750 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1751 | int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 1752 | struct ieee80211_vif *vif, |
| 1753 | struct ieee80211_sta *sta, |
| 1754 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1755 | u8 key_offset) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1756 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1757 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1758 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1759 | u8 sta_id; |
| 1760 | int ret; |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 1761 | static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0}; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1762 | |
| 1763 | lockdep_assert_held(&mvm->mutex); |
| 1764 | |
| 1765 | /* Get the station id from the mvm local station table */ |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1766 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 1767 | if (!mvm_sta) { |
| 1768 | IWL_ERR(mvm, "Failed to find station\n"); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1769 | return -EINVAL; |
| 1770 | } |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1771 | sta_id = mvm_sta->sta_id; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1772 | |
| 1773 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { |
| 1774 | ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false); |
| 1775 | goto end; |
| 1776 | } |
| 1777 | |
| 1778 | /* |
| 1779 | * It is possible that the 'sta' parameter is NULL, and thus |
| 1780 | * there is a need to retrieve the sta from the local station table. |
| 1781 | */ |
| 1782 | if (!sta) { |
| 1783 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1784 | lockdep_is_held(&mvm->mutex)); |
| 1785 | if (IS_ERR_OR_NULL(sta)) { |
| 1786 | IWL_ERR(mvm, "Invalid station id\n"); |
| 1787 | return -EINVAL; |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif)) |
| 1792 | return -EINVAL; |
| 1793 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1794 | /* If the key_offset is not pre-assigned, we need to find a |
| 1795 | * new offset to use. In normal cases, the offset is not |
| 1796 | * pre-assigned, but during HW_RESTART we want to reuse the |
| 1797 | * same indices, so we pass them when this function is called. |
| 1798 | * |
| 1799 | * In D3 entry, we need to hardcoded the indices (because the |
| 1800 | * firmware hardcodes the PTK offset to 0). In this case, we |
| 1801 | * need to make sure we don't overwrite the hw_key_idx in the |
| 1802 | * keyconf structure, because otherwise we cannot configure |
| 1803 | * the original ones back when resuming. |
| 1804 | */ |
| 1805 | if (key_offset == STA_KEY_IDX_INVALID) { |
| 1806 | key_offset = iwl_mvm_set_fw_key_idx(mvm); |
| 1807 | if (key_offset == STA_KEY_IDX_INVALID) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1808 | return -ENOSPC; |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1809 | keyconf->hw_key_idx = key_offset; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1810 | } |
| 1811 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1812 | 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] | 1813 | if (ret) |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1814 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1815 | |
| 1816 | /* |
| 1817 | * For WEP, the same key is used for multicast and unicast. Upload it |
| 1818 | * again, using the same key offset, and now pointing the other one |
| 1819 | * to the same key slot (offset). |
| 1820 | * If this fails, remove the original as well. |
| 1821 | */ |
| 1822 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 1823 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) { |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1824 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, |
| 1825 | key_offset, !mcast); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1826 | if (ret) { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1827 | __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 1828 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1829 | } |
| 1830 | } |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1831 | |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 1832 | __set_bit(key_offset, mvm->fw_key_table); |
| 1833 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1834 | end: |
| 1835 | IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", |
| 1836 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 1837 | sta ? sta->addr : zero_addr, ret); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1838 | return ret; |
| 1839 | } |
| 1840 | |
| 1841 | int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, |
| 1842 | struct ieee80211_vif *vif, |
| 1843 | struct ieee80211_sta *sta, |
| 1844 | struct ieee80211_key_conf *keyconf) |
| 1845 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1846 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1847 | struct iwl_mvm_sta *mvm_sta; |
| 1848 | u8 sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1849 | int ret, i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1850 | |
| 1851 | lockdep_assert_held(&mvm->mutex); |
| 1852 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1853 | /* Get the station from the mvm local station table */ |
| 1854 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1855 | |
| 1856 | IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", |
| 1857 | keyconf->keyidx, sta_id); |
| 1858 | |
| 1859 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) |
| 1860 | return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); |
| 1861 | |
| 1862 | if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) { |
| 1863 | IWL_ERR(mvm, "offset %d not used in fw key table.\n", |
| 1864 | keyconf->hw_key_idx); |
| 1865 | return -ENOENT; |
| 1866 | } |
| 1867 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1868 | /* track which key was deleted last */ |
| 1869 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 1870 | if (mvm->fw_key_deleted[i] < U8_MAX) |
| 1871 | mvm->fw_key_deleted[i]++; |
| 1872 | } |
| 1873 | mvm->fw_key_deleted[keyconf->hw_key_idx] = 0; |
| 1874 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1875 | if (!mvm_sta) { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1876 | IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); |
| 1877 | return 0; |
| 1878 | } |
| 1879 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1880 | sta_id = mvm_sta->sta_id; |
| 1881 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1882 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
| 1883 | if (ret) |
| 1884 | return ret; |
| 1885 | |
| 1886 | /* delete WEP key twice to get rid of (now useless) offset */ |
| 1887 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 1888 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 1889 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast); |
| 1890 | |
| 1891 | return ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1892 | } |
| 1893 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1894 | void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, |
| 1895 | struct ieee80211_vif *vif, |
| 1896 | struct ieee80211_key_conf *keyconf, |
| 1897 | struct ieee80211_sta *sta, u32 iv32, |
| 1898 | u16 *phase1key) |
| 1899 | { |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1900 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1901 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1902 | |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1903 | rcu_read_lock(); |
| 1904 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1905 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 1906 | if (WARN_ON_ONCE(!mvm_sta)) |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1907 | goto unlock; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1908 | iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1909 | iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx); |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1910 | |
| 1911 | unlock: |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1912 | rcu_read_unlock(); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1913 | } |
| 1914 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1915 | void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, |
| 1916 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1917 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1918 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1919 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1920 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1921 | .sta_id = mvmsta->sta_id, |
Emmanuel Grumbach | 5af0177 | 2013-06-09 12:59:24 +0300 | [diff] [blame] | 1922 | .station_flags_msk = cpu_to_le32(STA_FLG_PS), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1923 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1924 | }; |
| 1925 | int ret; |
| 1926 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1927 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 1928 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1929 | if (ret) |
| 1930 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 1931 | } |
| 1932 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1933 | void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, |
| 1934 | struct ieee80211_sta *sta, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1935 | enum ieee80211_frame_release_type reason, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1936 | u16 cnt, u16 tids, bool more_data, |
| 1937 | bool agg) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1938 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1939 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1940 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1941 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1942 | .sta_id = mvmsta->sta_id, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1943 | .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, |
| 1944 | .sleep_tx_count = cpu_to_le16(cnt), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1945 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1946 | }; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1947 | int tid, ret; |
| 1948 | unsigned long _tids = tids; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1949 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1950 | /* convert TIDs to ACs - we don't support TSPEC so that's OK |
| 1951 | * Note that this field is reserved and unused by firmware not |
| 1952 | * supporting GO uAPSD, so it's safe to always do this. |
| 1953 | */ |
| 1954 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) |
| 1955 | cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); |
| 1956 | |
| 1957 | /* If we're releasing frames from aggregation queues then check if the |
| 1958 | * all queues combined that we're releasing frames from have |
| 1959 | * - more frames than the service period, in which case more_data |
| 1960 | * needs to be set |
| 1961 | * - fewer than 'cnt' frames, in which case we need to adjust the |
| 1962 | * firmware command (but do that unconditionally) |
| 1963 | */ |
| 1964 | if (agg) { |
| 1965 | int remaining = cnt; |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1966 | int sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1967 | |
| 1968 | spin_lock_bh(&mvmsta->lock); |
| 1969 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { |
| 1970 | struct iwl_mvm_tid_data *tid_data; |
| 1971 | u16 n_queued; |
| 1972 | |
| 1973 | tid_data = &mvmsta->tid_data[tid]; |
| 1974 | if (WARN(tid_data->state != IWL_AGG_ON && |
| 1975 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA, |
| 1976 | "TID %d state is %d\n", |
| 1977 | tid, tid_data->state)) { |
| 1978 | spin_unlock_bh(&mvmsta->lock); |
| 1979 | ieee80211_sta_eosp(sta); |
| 1980 | return; |
| 1981 | } |
| 1982 | |
| 1983 | n_queued = iwl_mvm_tid_queued(tid_data); |
| 1984 | if (n_queued > remaining) { |
| 1985 | more_data = true; |
| 1986 | remaining = 0; |
| 1987 | break; |
| 1988 | } |
| 1989 | remaining -= n_queued; |
| 1990 | } |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1991 | sleep_tx_count = cnt - remaining; |
| 1992 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) |
| 1993 | mvmsta->sleep_tx_count = sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1994 | spin_unlock_bh(&mvmsta->lock); |
| 1995 | |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1996 | cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1997 | if (WARN_ON(cnt - remaining == 0)) { |
| 1998 | ieee80211_sta_eosp(sta); |
| 1999 | return; |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | /* Note: this is ignored by firmware not supporting GO uAPSD */ |
| 2004 | if (more_data) |
| 2005 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA); |
| 2006 | |
| 2007 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { |
| 2008 | mvmsta->next_status_eosp = true; |
| 2009 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL); |
| 2010 | } else { |
| 2011 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD); |
| 2012 | } |
| 2013 | |
Emmanuel Grumbach | 156f92f | 2015-11-24 14:55:18 +0200 | [diff] [blame] | 2014 | /* block the Tx queues until the FW updated the sleep Tx count */ |
| 2015 | iwl_trans_block_txq_ptrs(mvm->trans, true); |
| 2016 | |
| 2017 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, |
| 2018 | CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK, |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2019 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2020 | if (ret) |
| 2021 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 2022 | } |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2023 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 2024 | void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, |
| 2025 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2026 | { |
| 2027 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 2028 | struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; |
| 2029 | struct ieee80211_sta *sta; |
| 2030 | u32 sta_id = le32_to_cpu(notif->sta_id); |
| 2031 | |
| 2032 | if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 2033 | return; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2034 | |
| 2035 | rcu_read_lock(); |
| 2036 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 2037 | if (!IS_ERR_OR_NULL(sta)) |
| 2038 | ieee80211_sta_eosp(sta); |
| 2039 | rcu_read_unlock(); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2040 | } |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 2041 | |
| 2042 | void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm, |
| 2043 | struct iwl_mvm_sta *mvmsta, bool disable) |
| 2044 | { |
| 2045 | struct iwl_mvm_add_sta_cmd cmd = { |
| 2046 | .add_modify = STA_MODE_MODIFY, |
| 2047 | .sta_id = mvmsta->sta_id, |
| 2048 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, |
| 2049 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), |
| 2050 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
| 2051 | }; |
| 2052 | int ret; |
| 2053 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2054 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 2055 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 2056 | if (ret) |
| 2057 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 2058 | } |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 2059 | |
| 2060 | void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm, |
| 2061 | struct ieee80211_sta *sta, |
| 2062 | bool disable) |
| 2063 | { |
| 2064 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 2065 | |
| 2066 | spin_lock_bh(&mvm_sta->lock); |
| 2067 | |
| 2068 | if (mvm_sta->disable_tx == disable) { |
| 2069 | spin_unlock_bh(&mvm_sta->lock); |
| 2070 | return; |
| 2071 | } |
| 2072 | |
| 2073 | mvm_sta->disable_tx = disable; |
| 2074 | |
| 2075 | /* |
Sara Sharon | 0d365ae | 2015-03-31 12:24:05 +0300 | [diff] [blame] | 2076 | * Tell mac80211 to start/stop queuing tx for this station, |
| 2077 | * but don't stop queuing if there are still pending frames |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 2078 | * for this station. |
| 2079 | */ |
| 2080 | if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) |
| 2081 | ieee80211_sta_block_awake(mvm->hw, sta, disable); |
| 2082 | |
| 2083 | iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable); |
| 2084 | |
| 2085 | spin_unlock_bh(&mvm_sta->lock); |
| 2086 | } |
| 2087 | |
| 2088 | void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm, |
| 2089 | struct iwl_mvm_vif *mvmvif, |
| 2090 | bool disable) |
| 2091 | { |
| 2092 | struct ieee80211_sta *sta; |
| 2093 | struct iwl_mvm_sta *mvm_sta; |
| 2094 | int i; |
| 2095 | |
| 2096 | lockdep_assert_held(&mvm->mutex); |
| 2097 | |
| 2098 | /* Block/unblock all the stations of the given mvmvif */ |
| 2099 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 2100 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 2101 | lockdep_is_held(&mvm->mutex)); |
| 2102 | if (IS_ERR_OR_NULL(sta)) |
| 2103 | continue; |
| 2104 | |
| 2105 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 2106 | if (mvm_sta->mac_id_n_color != |
| 2107 | FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)) |
| 2108 | continue; |
| 2109 | |
| 2110 | iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable); |
| 2111 | } |
| 2112 | } |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 2113 | |
| 2114 | void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 2115 | { |
| 2116 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2117 | struct iwl_mvm_sta *mvmsta; |
| 2118 | |
| 2119 | rcu_read_lock(); |
| 2120 | |
| 2121 | mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id); |
| 2122 | |
| 2123 | if (!WARN_ON(!mvmsta)) |
| 2124 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true); |
| 2125 | |
| 2126 | rcu_read_unlock(); |
| 2127 | } |