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