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 |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of version 2 of the GNU General Public License as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 23 | * USA |
| 24 | * |
| 25 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 26 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 27 | * |
| 28 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame^] | 29 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 31 | * |
| 32 | * BSD LICENSE |
| 33 | * |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 34 | * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved. |
| 35 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 36 | * All rights reserved. |
| 37 | * |
| 38 | * Redistribution and use in source and binary forms, with or without |
| 39 | * modification, are permitted provided that the following conditions |
| 40 | * are met: |
| 41 | * |
| 42 | * * Redistributions of source code must retain the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer. |
| 44 | * * Redistributions in binary form must reproduce the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer in |
| 46 | * the documentation and/or other materials provided with the |
| 47 | * distribution. |
| 48 | * * Neither the name Intel Corporation nor the names of its |
| 49 | * contributors may be used to endorse or promote products derived |
| 50 | * from this software without specific prior written permission. |
| 51 | * |
| 52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 53 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 54 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 55 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 56 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 57 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 58 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 59 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 60 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 61 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 63 | * |
| 64 | *****************************************************************************/ |
| 65 | #include <net/mac80211.h> |
| 66 | |
| 67 | #include "mvm.h" |
| 68 | #include "sta.h" |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 69 | #include "rs.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 70 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 71 | static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm, |
| 72 | enum nl80211_iftype iftype) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 73 | { |
| 74 | int sta_id; |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 75 | u32 reserved_ids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 76 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 77 | BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 78 | WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)); |
| 79 | |
| 80 | lockdep_assert_held(&mvm->mutex); |
| 81 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 82 | /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */ |
| 83 | if (iftype != NL80211_IFTYPE_STATION) |
| 84 | reserved_ids = BIT(0); |
| 85 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 86 | /* 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] | 87 | for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) { |
| 88 | if (BIT(sta_id) & reserved_ids) |
| 89 | continue; |
| 90 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 91 | if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 92 | lockdep_is_held(&mvm->mutex))) |
| 93 | return sta_id; |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 94 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 95 | return IWL_MVM_STATION_COUNT; |
| 96 | } |
| 97 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 98 | /* send station add/update command to firmware */ |
| 99 | int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 100 | bool update) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 101 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 102 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 4b8265a | 2014-07-13 08:58:04 +0300 | [diff] [blame] | 103 | struct iwl_mvm_add_sta_cmd add_sta_cmd = { |
| 104 | .sta_id = mvm_sta->sta_id, |
| 105 | .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color), |
| 106 | .add_modify = update ? 1 : 0, |
| 107 | .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK | |
| 108 | STA_FLG_MIMO_EN_MSK), |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 109 | .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg), |
Emmanuel Grumbach | 4b8265a | 2014-07-13 08:58:04 +0300 | [diff] [blame] | 110 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 111 | int ret; |
| 112 | u32 status; |
| 113 | u32 agg_size = 0, mpdu_dens = 0; |
| 114 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 115 | if (!update) { |
| 116 | add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 117 | memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN); |
| 118 | } |
Johannes Berg | 5bc5aaa | 2013-02-12 14:35:36 +0100 | [diff] [blame] | 119 | |
| 120 | switch (sta->bandwidth) { |
| 121 | case IEEE80211_STA_RX_BW_160: |
| 122 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ); |
| 123 | /* fall through */ |
| 124 | case IEEE80211_STA_RX_BW_80: |
| 125 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ); |
| 126 | /* fall through */ |
| 127 | case IEEE80211_STA_RX_BW_40: |
| 128 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ); |
| 129 | /* fall through */ |
| 130 | case IEEE80211_STA_RX_BW_20: |
| 131 | if (sta->ht_cap.ht_supported) |
| 132 | add_sta_cmd.station_flags |= |
| 133 | cpu_to_le32(STA_FLG_FAT_EN_20MHZ); |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | switch (sta->rx_nss) { |
| 138 | case 1: |
| 139 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); |
| 140 | break; |
| 141 | case 2: |
| 142 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2); |
| 143 | break; |
| 144 | case 3 ... 8: |
| 145 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3); |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | switch (sta->smps_mode) { |
| 150 | case IEEE80211_SMPS_AUTOMATIC: |
| 151 | case IEEE80211_SMPS_NUM_MODES: |
| 152 | WARN_ON(1); |
| 153 | break; |
| 154 | case IEEE80211_SMPS_STATIC: |
| 155 | /* override NSS */ |
| 156 | add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK); |
| 157 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); |
| 158 | break; |
| 159 | case IEEE80211_SMPS_DYNAMIC: |
| 160 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT); |
| 161 | break; |
| 162 | case IEEE80211_SMPS_OFF: |
| 163 | /* nothing */ |
| 164 | break; |
| 165 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 166 | |
| 167 | if (sta->ht_cap.ht_supported) { |
| 168 | add_sta_cmd.station_flags_msk |= |
| 169 | cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK | |
| 170 | STA_FLG_AGG_MPDU_DENS_MSK); |
| 171 | |
| 172 | mpdu_dens = sta->ht_cap.ampdu_density; |
| 173 | } |
| 174 | |
| 175 | if (sta->vht_cap.vht_supported) { |
| 176 | agg_size = sta->vht_cap.cap & |
| 177 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; |
| 178 | agg_size >>= |
| 179 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 180 | } else if (sta->ht_cap.ht_supported) { |
| 181 | agg_size = sta->ht_cap.ampdu_factor; |
| 182 | } |
| 183 | |
| 184 | add_sta_cmd.station_flags |= |
| 185 | cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT); |
| 186 | add_sta_cmd.station_flags |= |
| 187 | cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT); |
| 188 | |
| 189 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 190 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(add_sta_cmd), |
| 191 | &add_sta_cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 192 | if (ret) |
| 193 | return ret; |
| 194 | |
| 195 | switch (status) { |
| 196 | case ADD_STA_SUCCESS: |
| 197 | IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n"); |
| 198 | break; |
| 199 | default: |
| 200 | ret = -EIO; |
| 201 | IWL_ERR(mvm, "ADD_STA failed\n"); |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | return ret; |
| 206 | } |
| 207 | |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 208 | static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm, |
| 209 | struct ieee80211_sta *sta) |
| 210 | { |
| 211 | unsigned long used_hw_queues; |
| 212 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 213 | unsigned int wdg_timeout = |
| 214 | iwl_mvm_get_wd_timeout(mvm, NULL, true, false); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 215 | u32 ac; |
| 216 | |
| 217 | lockdep_assert_held(&mvm->mutex); |
| 218 | |
| 219 | used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL); |
| 220 | |
| 221 | /* Find available queues, and allocate them to the ACs */ |
| 222 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 223 | u8 queue = find_first_zero_bit(&used_hw_queues, |
| 224 | mvm->first_agg_queue); |
| 225 | |
| 226 | if (queue >= mvm->first_agg_queue) { |
| 227 | IWL_ERR(mvm, "Failed to allocate STA queue\n"); |
| 228 | return -EBUSY; |
| 229 | } |
| 230 | |
| 231 | __set_bit(queue, &used_hw_queues); |
| 232 | mvmsta->hw_queue[ac] = queue; |
| 233 | } |
| 234 | |
| 235 | /* Found a place for all queues - enable them */ |
| 236 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 237 | iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac], |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 238 | mvmsta->hw_queue[ac], |
Liad Kaufman | 5c1156e | 2015-07-22 17:59:53 +0300 | [diff] [blame] | 239 | iwl_mvm_ac_to_tx_fifo[ac], 0, |
| 240 | wdg_timeout); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 241 | mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]); |
| 242 | } |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm, |
| 248 | struct ieee80211_sta *sta) |
| 249 | { |
| 250 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 251 | unsigned long sta_msk; |
| 252 | int i; |
| 253 | |
| 254 | lockdep_assert_held(&mvm->mutex); |
| 255 | |
| 256 | /* disable the TDLS STA-specific queues */ |
| 257 | sta_msk = mvmsta->tfd_queue_msk; |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 258 | 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] | 259 | iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 260 | } |
| 261 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 262 | int iwl_mvm_add_sta(struct iwl_mvm *mvm, |
| 263 | struct ieee80211_vif *vif, |
| 264 | struct ieee80211_sta *sta) |
| 265 | { |
| 266 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 267 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 268 | int i, ret, sta_id; |
| 269 | |
| 270 | lockdep_assert_held(&mvm->mutex); |
| 271 | |
| 272 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 273 | sta_id = iwl_mvm_find_free_sta_id(mvm, |
| 274 | ieee80211_vif_type_p2p(vif)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 275 | else |
| 276 | sta_id = mvm_sta->sta_id; |
| 277 | |
Johannes Berg | 36f4631 | 2015-03-10 20:32:08 +0100 | [diff] [blame] | 278 | if (sta_id == IWL_MVM_STATION_COUNT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 279 | return -ENOSPC; |
| 280 | |
Gregory Greenman | 9493908 | 2015-08-24 14:38:35 +0300 | [diff] [blame] | 281 | if (vif->type == NL80211_IFTYPE_AP) { |
| 282 | mvmvif->ap_assoc_sta_count++; |
Ilan Peer | f82c833 | 2015-09-10 12:54:38 +0300 | [diff] [blame] | 283 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
Gregory Greenman | 9493908 | 2015-08-24 14:38:35 +0300 | [diff] [blame] | 284 | } |
| 285 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 286 | spin_lock_init(&mvm_sta->lock); |
| 287 | |
| 288 | mvm_sta->sta_id = sta_id; |
| 289 | mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 290 | mvmvif->color); |
| 291 | mvm_sta->vif = vif; |
| 292 | mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 293 | mvm_sta->tx_protection = 0; |
| 294 | mvm_sta->tt_tx_protection = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 295 | |
| 296 | /* HW restart, don't assume the memory has been zeroed */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 297 | atomic_set(&mvm->pending_frames[sta_id], 0); |
Liad Kaufman | 69191af | 2015-09-01 18:50:22 +0300 | [diff] [blame] | 298 | mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 299 | mvm_sta->tfd_queue_msk = 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 300 | |
| 301 | /* allocate new queues for a TDLS station */ |
| 302 | if (sta->tdls) { |
| 303 | ret = iwl_mvm_tdls_sta_init(mvm, sta); |
| 304 | if (ret) |
| 305 | return ret; |
| 306 | } else { |
| 307 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 308 | if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE) |
| 309 | mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]); |
| 310 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 311 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 312 | /* for HW restart - reset everything but the sequence number */ |
| 313 | for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 314 | u16 seq = mvm_sta->tid_data[i].seq_number; |
| 315 | memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); |
| 316 | mvm_sta->tid_data[i].seq_number = seq; |
| 317 | } |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 318 | mvm_sta->agg_tids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 319 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 320 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 321 | if (ret) |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 322 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 323 | |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 324 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 325 | if (!sta->tdls) { |
| 326 | WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT); |
| 327 | mvmvif->ap_sta_id = sta_id; |
| 328 | } else { |
| 329 | WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT); |
| 330 | } |
| 331 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 332 | |
| 333 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); |
| 334 | |
| 335 | return 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 336 | |
| 337 | err: |
| 338 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 339 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 342 | int iwl_mvm_update_sta(struct iwl_mvm *mvm, |
| 343 | struct ieee80211_vif *vif, |
| 344 | struct ieee80211_sta *sta) |
| 345 | { |
| 346 | return iwl_mvm_sta_send_to_fw(mvm, sta, true); |
| 347 | } |
| 348 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 349 | int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 350 | bool drain) |
| 351 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 352 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 353 | int ret; |
| 354 | u32 status; |
| 355 | |
| 356 | lockdep_assert_held(&mvm->mutex); |
| 357 | |
| 358 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 359 | cmd.sta_id = mvmsta->sta_id; |
| 360 | cmd.add_modify = STA_MODE_MODIFY; |
| 361 | cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; |
| 362 | cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); |
| 363 | |
| 364 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 365 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(cmd), |
| 366 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 367 | if (ret) |
| 368 | return ret; |
| 369 | |
| 370 | switch (status) { |
| 371 | case ADD_STA_SUCCESS: |
| 372 | IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", |
| 373 | mvmsta->sta_id); |
| 374 | break; |
| 375 | default: |
| 376 | ret = -EIO; |
| 377 | IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", |
| 378 | mvmsta->sta_id); |
| 379 | break; |
| 380 | } |
| 381 | |
| 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | /* |
| 386 | * Remove a station from the FW table. Before sending the command to remove |
| 387 | * the station validate that the station is indeed known to the driver (sanity |
| 388 | * only). |
| 389 | */ |
| 390 | static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) |
| 391 | { |
| 392 | struct ieee80211_sta *sta; |
| 393 | struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { |
| 394 | .sta_id = sta_id, |
| 395 | }; |
| 396 | int ret; |
| 397 | |
| 398 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 399 | lockdep_is_held(&mvm->mutex)); |
| 400 | |
| 401 | /* Note: internal stations are marked as error values */ |
| 402 | if (!sta) { |
| 403 | IWL_ERR(mvm, "Invalid station id\n"); |
| 404 | return -EINVAL; |
| 405 | } |
| 406 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 407 | ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 408 | sizeof(rm_sta_cmd), &rm_sta_cmd); |
| 409 | if (ret) { |
| 410 | IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); |
| 411 | return ret; |
| 412 | } |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | void iwl_mvm_sta_drained_wk(struct work_struct *wk) |
| 418 | { |
| 419 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk); |
| 420 | u8 sta_id; |
| 421 | |
| 422 | /* |
| 423 | * The mutex is needed because of the SYNC cmd, but not only: if the |
| 424 | * work would run concurrently with iwl_mvm_rm_sta, it would run before |
| 425 | * iwl_mvm_rm_sta sets the station as busy, and exit. Then |
| 426 | * iwl_mvm_rm_sta would set the station as busy, and nobody will clean |
| 427 | * that later. |
| 428 | */ |
| 429 | mutex_lock(&mvm->mutex); |
| 430 | |
| 431 | for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) { |
| 432 | int ret; |
| 433 | struct ieee80211_sta *sta = |
| 434 | rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 435 | lockdep_is_held(&mvm->mutex)); |
| 436 | |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 437 | /* |
| 438 | * This station is in use or RCU-removed; the latter happens in |
| 439 | * managed mode, where mac80211 removes the station before we |
| 440 | * can remove it from firmware (we can only do that after the |
| 441 | * MAC is marked unassociated), and possibly while the deauth |
| 442 | * frame to disconnect from the AP is still queued. Then, the |
| 443 | * station pointer is -ENOENT when the last skb is reclaimed. |
| 444 | */ |
| 445 | if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 446 | continue; |
| 447 | |
| 448 | if (PTR_ERR(sta) == -EINVAL) { |
| 449 | IWL_ERR(mvm, "Drained sta %d, but it is internal?\n", |
| 450 | sta_id); |
| 451 | continue; |
| 452 | } |
| 453 | |
| 454 | if (!sta) { |
| 455 | IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n", |
| 456 | sta_id); |
| 457 | continue; |
| 458 | } |
| 459 | |
| 460 | WARN_ON(PTR_ERR(sta) != -EBUSY); |
| 461 | /* This station was removed and we waited until it got drained, |
| 462 | * we can now proceed and remove it. |
| 463 | */ |
| 464 | ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 465 | if (ret) { |
| 466 | IWL_ERR(mvm, |
| 467 | "Couldn't remove sta %d after it was drained\n", |
| 468 | sta_id); |
| 469 | continue; |
| 470 | } |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 471 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 472 | clear_bit(sta_id, mvm->sta_drained); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 473 | |
| 474 | if (mvm->tfd_drained[sta_id]) { |
| 475 | unsigned long i, msk = mvm->tfd_drained[sta_id]; |
| 476 | |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 477 | for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE) |
Arik Nemtsov | 06ecdba | 2015-10-12 14:47:11 +0300 | [diff] [blame] | 478 | iwl_mvm_disable_txq(mvm, i, i, |
| 479 | IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 480 | |
| 481 | mvm->tfd_drained[sta_id] = 0; |
| 482 | IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n", |
| 483 | sta_id, msk); |
| 484 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | mutex_unlock(&mvm->mutex); |
| 488 | } |
| 489 | |
| 490 | int iwl_mvm_rm_sta(struct iwl_mvm *mvm, |
| 491 | struct ieee80211_vif *vif, |
| 492 | struct ieee80211_sta *sta) |
| 493 | { |
| 494 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 495 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 496 | int ret; |
| 497 | |
| 498 | lockdep_assert_held(&mvm->mutex); |
| 499 | |
| 500 | if (vif->type == NL80211_IFTYPE_STATION && |
| 501 | mvmvif->ap_sta_id == mvm_sta->sta_id) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 502 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
| 503 | if (ret) |
| 504 | return ret; |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 505 | /* flush its queues here since we are freeing mvm_sta */ |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 506 | 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] | 507 | if (ret) |
| 508 | return ret; |
| 509 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 510 | mvm_sta->tfd_queue_msk); |
| 511 | if (ret) |
| 512 | return ret; |
| 513 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, false); |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 514 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 515 | /* if we are associated - we can't remove the AP STA now */ |
| 516 | if (vif->bss_conf.assoc) |
| 517 | return ret; |
| 518 | |
| 519 | /* unassoc - go ahead - remove the AP STA now */ |
| 520 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 521 | |
| 522 | /* clear d0i3_ap_sta_id if no longer relevant */ |
| 523 | if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id) |
| 524 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /* |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 528 | * This shouldn't happen - the TDLS channel switch should be canceled |
| 529 | * before the STA is removed. |
| 530 | */ |
| 531 | if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) { |
| 532 | mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT; |
| 533 | cancel_delayed_work(&mvm->tdls_cs.dwork); |
| 534 | } |
| 535 | |
| 536 | /* |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 537 | * Make sure that the tx response code sees the station as -EBUSY and |
| 538 | * calls the drain worker. |
| 539 | */ |
| 540 | spin_lock_bh(&mvm_sta->lock); |
| 541 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 542 | * There are frames pending on the AC queues for this station. |
| 543 | * We need to wait until all the frames are drained... |
| 544 | */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 545 | if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 546 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
| 547 | ERR_PTR(-EBUSY)); |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 548 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 549 | |
| 550 | /* disable TDLS sta queues on drain complete */ |
| 551 | if (sta->tdls) { |
| 552 | mvm->tfd_drained[mvm_sta->sta_id] = |
| 553 | mvm_sta->tfd_queue_msk; |
| 554 | IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", |
| 555 | mvm_sta->sta_id); |
| 556 | } |
| 557 | |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 558 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 559 | } else { |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 560 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 561 | |
| 562 | if (sta->tdls) |
| 563 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 564 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 565 | ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 566 | 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] | 567 | } |
| 568 | |
| 569 | return ret; |
| 570 | } |
| 571 | |
| 572 | int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, |
| 573 | struct ieee80211_vif *vif, |
| 574 | u8 sta_id) |
| 575 | { |
| 576 | int ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 577 | |
| 578 | lockdep_assert_held(&mvm->mutex); |
| 579 | |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 580 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 581 | return ret; |
| 582 | } |
| 583 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 584 | static int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, |
| 585 | struct iwl_mvm_int_sta *sta, |
| 586 | u32 qmask, enum nl80211_iftype iftype) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 587 | { |
| 588 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 589 | sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 590 | if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT)) |
| 591 | return -ENOSPC; |
| 592 | } |
| 593 | |
| 594 | sta->tfd_queue_msk = qmask; |
| 595 | |
| 596 | /* put a non-NULL value so iterating over the stations won't stop */ |
| 597 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); |
| 598 | return 0; |
| 599 | } |
| 600 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 601 | static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, |
| 602 | struct iwl_mvm_int_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 603 | { |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 604 | 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] | 605 | memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); |
| 606 | sta->sta_id = IWL_MVM_STATION_COUNT; |
| 607 | } |
| 608 | |
| 609 | static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, |
| 610 | struct iwl_mvm_int_sta *sta, |
| 611 | const u8 *addr, |
| 612 | u16 mac_id, u16 color) |
| 613 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 614 | struct iwl_mvm_add_sta_cmd cmd; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 615 | int ret; |
| 616 | u32 status; |
| 617 | |
| 618 | lockdep_assert_held(&mvm->mutex); |
| 619 | |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 620 | memset(&cmd, 0, sizeof(cmd)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 621 | cmd.sta_id = sta->sta_id; |
| 622 | cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, |
| 623 | color)); |
| 624 | |
| 625 | cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 626 | cmd.tid_disable_tx = cpu_to_le16(0xffff); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 627 | |
| 628 | if (addr) |
| 629 | memcpy(cmd.addr, addr, ETH_ALEN); |
| 630 | |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 631 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(cmd), |
| 632 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 633 | if (ret) |
| 634 | return ret; |
| 635 | |
| 636 | switch (status) { |
| 637 | case ADD_STA_SUCCESS: |
| 638 | IWL_DEBUG_INFO(mvm, "Internal station added.\n"); |
| 639 | return 0; |
| 640 | default: |
| 641 | ret = -EIO; |
| 642 | IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", |
| 643 | status); |
| 644 | break; |
| 645 | } |
| 646 | return ret; |
| 647 | } |
| 648 | |
| 649 | int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) |
| 650 | { |
Emmanuel Grumbach | 4cf677f | 2015-01-12 14:38:29 +0200 | [diff] [blame] | 651 | unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ? |
| 652 | mvm->cfg->base_params->wd_timeout : |
| 653 | IWL_WATCHDOG_DISABLED; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 654 | int ret; |
| 655 | |
| 656 | lockdep_assert_held(&mvm->mutex); |
| 657 | |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 658 | /* Map Aux queue to fifo - needs to happen before adding Aux station */ |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 659 | iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue, |
Liad Kaufman | 5c1156e | 2015-07-22 17:59:53 +0300 | [diff] [blame] | 660 | IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout); |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 661 | |
| 662 | /* Allocate aux station and assign to it the aux queue */ |
| 663 | 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] | 664 | NL80211_IFTYPE_UNSPECIFIED); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 665 | if (ret) |
| 666 | return ret; |
| 667 | |
| 668 | ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, |
| 669 | MAC_INDEX_AUX, 0); |
| 670 | |
| 671 | if (ret) |
| 672 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 673 | return ret; |
| 674 | } |
| 675 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 676 | void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm) |
| 677 | { |
| 678 | lockdep_assert_held(&mvm->mutex); |
| 679 | |
| 680 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 681 | } |
| 682 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 683 | /* |
| 684 | * Send the add station command for the vif's broadcast station. |
| 685 | * Assumes that the station was already allocated. |
| 686 | * |
| 687 | * @mvm: the mvm component |
| 688 | * @vif: the interface to which the broadcast station is added |
| 689 | * @bsta: the broadcast station to add. |
| 690 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 691 | 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] | 692 | { |
| 693 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 694 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 695 | static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
Johannes Berg | a424340 | 2014-01-20 23:46:38 +0100 | [diff] [blame] | 696 | const u8 *baddr = _baddr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 697 | |
| 698 | lockdep_assert_held(&mvm->mutex); |
| 699 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 700 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 701 | baddr = vif->bss_conf.bssid; |
| 702 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 703 | if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT)) |
| 704 | return -ENOSPC; |
| 705 | |
| 706 | return iwl_mvm_add_int_sta_common(mvm, bsta, baddr, |
| 707 | mvmvif->id, mvmvif->color); |
| 708 | } |
| 709 | |
| 710 | /* Send the FW a request to remove the station from it's internal data |
| 711 | * structures, but DO NOT remove the entry from the local data structures. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 712 | 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] | 713 | { |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 714 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 715 | int ret; |
| 716 | |
| 717 | lockdep_assert_held(&mvm->mutex); |
| 718 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 719 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 720 | if (ret) |
| 721 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 722 | return ret; |
| 723 | } |
| 724 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 725 | int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 726 | { |
| 727 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 728 | u32 qmask; |
| 729 | |
| 730 | lockdep_assert_held(&mvm->mutex); |
| 731 | |
Arik Nemtsov | d92b732e | 2014-09-21 19:00:42 +0300 | [diff] [blame] | 732 | qmask = iwl_mvm_mac_get_queues_mask(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 733 | |
| 734 | /* |
| 735 | * The firmware defines the TFD queue mask to only be relevant |
| 736 | * for *unicast* queues, so the multicast (CAB) queue shouldn't |
| 737 | * be included. |
| 738 | */ |
| 739 | if (vif->type == NL80211_IFTYPE_AP) |
| 740 | qmask &= ~BIT(vif->cab_queue); |
| 741 | |
| 742 | return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask, |
| 743 | ieee80211_vif_type_p2p(vif)); |
| 744 | } |
| 745 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 746 | /* Allocate a new station entry for the broadcast station to the given vif, |
| 747 | * and send it to the FW. |
| 748 | * Note that each P2P mac should have its own broadcast station. |
| 749 | * |
| 750 | * @mvm: the mvm component |
| 751 | * @vif: the interface to which the broadcast station is added |
| 752 | * @bsta: the broadcast station to add. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 753 | 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] | 754 | { |
| 755 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 756 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 757 | int ret; |
| 758 | |
| 759 | lockdep_assert_held(&mvm->mutex); |
| 760 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 761 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 762 | if (ret) |
| 763 | return ret; |
| 764 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 765 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 766 | |
| 767 | if (ret) |
| 768 | iwl_mvm_dealloc_int_sta(mvm, bsta); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 769 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 770 | return ret; |
| 771 | } |
| 772 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 773 | void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 774 | { |
| 775 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 776 | |
| 777 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 778 | } |
| 779 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 780 | /* |
| 781 | * Send the FW a request to remove the station from it's internal data |
| 782 | * structures, and in addition remove it from the local data structure. |
| 783 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 784 | 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] | 785 | { |
| 786 | int ret; |
| 787 | |
| 788 | lockdep_assert_held(&mvm->mutex); |
| 789 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 790 | ret = iwl_mvm_send_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 791 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 792 | iwl_mvm_dealloc_bcast_sta(mvm, vif); |
| 793 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 794 | return ret; |
| 795 | } |
| 796 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 797 | #define IWL_MAX_RX_BA_SESSIONS 16 |
| 798 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 799 | int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 800 | int tid, u16 ssn, bool start) |
| 801 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 802 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 803 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 804 | int ret; |
| 805 | u32 status; |
| 806 | |
| 807 | lockdep_assert_held(&mvm->mutex); |
| 808 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 809 | if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { |
| 810 | IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); |
| 811 | return -ENOSPC; |
| 812 | } |
| 813 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 814 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 815 | cmd.sta_id = mvm_sta->sta_id; |
| 816 | cmd.add_modify = STA_MODE_MODIFY; |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 817 | if (start) { |
| 818 | cmd.add_immediate_ba_tid = (u8) tid; |
| 819 | cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); |
| 820 | } else { |
| 821 | cmd.remove_immediate_ba_tid = (u8) tid; |
| 822 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 823 | cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : |
| 824 | STA_MODIFY_REMOVE_BA_TID; |
| 825 | |
| 826 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 827 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(cmd), |
| 828 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 829 | if (ret) |
| 830 | return ret; |
| 831 | |
| 832 | switch (status) { |
| 833 | case ADD_STA_SUCCESS: |
| 834 | IWL_DEBUG_INFO(mvm, "RX BA Session %sed in fw\n", |
| 835 | start ? "start" : "stopp"); |
| 836 | break; |
| 837 | case ADD_STA_IMMEDIATE_BA_FAILURE: |
| 838 | IWL_WARN(mvm, "RX BA Session refused by fw\n"); |
| 839 | ret = -ENOSPC; |
| 840 | break; |
| 841 | default: |
| 842 | ret = -EIO; |
| 843 | IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", |
| 844 | start ? "start" : "stopp", status); |
| 845 | break; |
| 846 | } |
| 847 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 848 | if (!ret) { |
| 849 | if (start) |
| 850 | mvm->rx_ba_sessions++; |
| 851 | else if (mvm->rx_ba_sessions > 0) |
| 852 | /* check that restart flow didn't zero the counter */ |
| 853 | mvm->rx_ba_sessions--; |
| 854 | } |
| 855 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 856 | return ret; |
| 857 | } |
| 858 | |
| 859 | static int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 860 | int tid, u8 queue, bool start) |
| 861 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 862 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 863 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 864 | int ret; |
| 865 | u32 status; |
| 866 | |
| 867 | lockdep_assert_held(&mvm->mutex); |
| 868 | |
| 869 | if (start) { |
| 870 | mvm_sta->tfd_queue_msk |= BIT(queue); |
| 871 | mvm_sta->tid_disable_agg &= ~BIT(tid); |
| 872 | } else { |
| 873 | mvm_sta->tfd_queue_msk &= ~BIT(queue); |
| 874 | mvm_sta->tid_disable_agg |= BIT(tid); |
| 875 | } |
| 876 | |
| 877 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 878 | cmd.sta_id = mvm_sta->sta_id; |
| 879 | cmd.add_modify = STA_MODE_MODIFY; |
| 880 | cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX; |
| 881 | cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 882 | cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); |
| 883 | |
| 884 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 885 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(cmd), |
| 886 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 887 | if (ret) |
| 888 | return ret; |
| 889 | |
| 890 | switch (status) { |
| 891 | case ADD_STA_SUCCESS: |
| 892 | break; |
| 893 | default: |
| 894 | ret = -EIO; |
| 895 | IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", |
| 896 | start ? "start" : "stopp", status); |
| 897 | break; |
| 898 | } |
| 899 | |
| 900 | return ret; |
| 901 | } |
| 902 | |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 903 | const u8 tid_to_mac80211_ac[] = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 904 | IEEE80211_AC_BE, |
| 905 | IEEE80211_AC_BK, |
| 906 | IEEE80211_AC_BK, |
| 907 | IEEE80211_AC_BE, |
| 908 | IEEE80211_AC_VI, |
| 909 | IEEE80211_AC_VI, |
| 910 | IEEE80211_AC_VO, |
| 911 | IEEE80211_AC_VO, |
| 912 | }; |
| 913 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 914 | static const u8 tid_to_ucode_ac[] = { |
| 915 | AC_BE, |
| 916 | AC_BK, |
| 917 | AC_BK, |
| 918 | AC_BE, |
| 919 | AC_VI, |
| 920 | AC_VI, |
| 921 | AC_VO, |
| 922 | AC_VO, |
| 923 | }; |
| 924 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 925 | int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 926 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
| 927 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 928 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 929 | struct iwl_mvm_tid_data *tid_data; |
| 930 | int txq_id; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 931 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 932 | |
| 933 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) |
| 934 | return -EINVAL; |
| 935 | |
| 936 | if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { |
| 937 | IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", |
| 938 | mvmsta->tid_data[tid].state); |
| 939 | return -ENXIO; |
| 940 | } |
| 941 | |
| 942 | lockdep_assert_held(&mvm->mutex); |
| 943 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 944 | spin_lock_bh(&mvmsta->lock); |
| 945 | |
| 946 | /* possible race condition - we entered D0i3 while starting agg */ |
| 947 | if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) { |
| 948 | spin_unlock_bh(&mvmsta->lock); |
| 949 | IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n"); |
| 950 | return -EIO; |
| 951 | } |
| 952 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 953 | spin_lock_bh(&mvm->queue_info_lock); |
| 954 | |
| 955 | txq_id = iwl_mvm_find_free_queue(mvm, mvm->first_agg_queue, |
| 956 | mvm->last_agg_queue); |
| 957 | if (txq_id < 0) { |
| 958 | ret = txq_id; |
| 959 | spin_unlock_bh(&mvm->queue_info_lock); |
| 960 | IWL_ERR(mvm, "Failed to allocate agg queue\n"); |
| 961 | goto release_locks; |
| 962 | } |
| 963 | mvm->queue_info[txq_id].setup_reserved = true; |
| 964 | spin_unlock_bh(&mvm->queue_info_lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 965 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 966 | tid_data = &mvmsta->tid_data[tid]; |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 967 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 968 | tid_data->txq_id = txq_id; |
| 969 | *ssn = tid_data->ssn; |
| 970 | |
| 971 | IWL_DEBUG_TX_QUEUES(mvm, |
| 972 | "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", |
| 973 | mvmsta->sta_id, tid, txq_id, tid_data->ssn, |
| 974 | tid_data->next_reclaimed); |
| 975 | |
| 976 | if (tid_data->ssn == tid_data->next_reclaimed) { |
| 977 | tid_data->state = IWL_AGG_STARTING; |
| 978 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 979 | } else { |
| 980 | tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; |
| 981 | } |
| 982 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 983 | ret = 0; |
| 984 | |
| 985 | release_locks: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 986 | spin_unlock_bh(&mvmsta->lock); |
| 987 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 988 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 992 | struct ieee80211_sta *sta, u16 tid, u8 buf_size) |
| 993 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 994 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 995 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 996 | unsigned int wdg_timeout = |
| 997 | iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 998 | int queue, fifo, ret; |
| 999 | u16 ssn; |
| 1000 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1001 | BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE) |
| 1002 | != IWL_MAX_TID_COUNT); |
| 1003 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1004 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); |
| 1005 | |
| 1006 | spin_lock_bh(&mvmsta->lock); |
| 1007 | ssn = tid_data->ssn; |
| 1008 | queue = tid_data->txq_id; |
| 1009 | tid_data->state = IWL_AGG_ON; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1010 | mvmsta->agg_tids |= BIT(tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1011 | tid_data->ssn = 0xffff; |
| 1012 | spin_unlock_bh(&mvmsta->lock); |
| 1013 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1014 | fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1015 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1016 | iwl_mvm_enable_agg_txq(mvm, queue, |
| 1017 | vif->hw_queue[tid_to_mac80211_ac[tid]], fifo, |
| 1018 | mvmsta->sta_id, tid, buf_size, ssn, wdg_timeout); |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 1019 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1020 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 1021 | if (ret) |
| 1022 | return -EIO; |
| 1023 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1024 | /* No need to mark as reserved */ |
| 1025 | spin_lock_bh(&mvm->queue_info_lock); |
| 1026 | mvm->queue_info[queue].setup_reserved = false; |
| 1027 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1028 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1029 | /* |
| 1030 | * Even though in theory the peer could have different |
| 1031 | * aggregation reorder buffer sizes for different sessions, |
| 1032 | * our ucode doesn't allow for that and has a global limit |
| 1033 | * for each station. Therefore, use the minimum of all the |
| 1034 | * aggregation sessions and our default value. |
| 1035 | */ |
| 1036 | mvmsta->max_agg_bufsize = |
| 1037 | min(mvmsta->max_agg_bufsize, buf_size); |
| 1038 | mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; |
| 1039 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 1040 | IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", |
| 1041 | sta->addr, tid); |
| 1042 | |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 1043 | return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1047 | struct ieee80211_sta *sta, u16 tid) |
| 1048 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1049 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1050 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 1051 | u16 txq_id; |
| 1052 | int err; |
| 1053 | |
Emmanuel Grumbach | f9aa8dd | 2013-03-04 09:11:08 +0200 | [diff] [blame] | 1054 | |
| 1055 | /* |
| 1056 | * If mac80211 is cleaning its state, then say that we finished since |
| 1057 | * our state has been cleared anyway. |
| 1058 | */ |
| 1059 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 1060 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1064 | spin_lock_bh(&mvmsta->lock); |
| 1065 | |
| 1066 | txq_id = tid_data->txq_id; |
| 1067 | |
| 1068 | IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", |
| 1069 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
| 1070 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1071 | mvmsta->agg_tids &= ~BIT(tid); |
| 1072 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1073 | /* No need to mark as reserved anymore */ |
| 1074 | spin_lock_bh(&mvm->queue_info_lock); |
| 1075 | mvm->queue_info[txq_id].setup_reserved = false; |
| 1076 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1077 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1078 | switch (tid_data->state) { |
| 1079 | case IWL_AGG_ON: |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 1080 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1081 | |
| 1082 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1083 | "ssn = %d, next_recl = %d\n", |
| 1084 | tid_data->ssn, tid_data->next_reclaimed); |
| 1085 | |
| 1086 | /* There are still packets for this RA / TID in the HW */ |
| 1087 | if (tid_data->ssn != tid_data->next_reclaimed) { |
| 1088 | tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA; |
| 1089 | err = 0; |
| 1090 | break; |
| 1091 | } |
| 1092 | |
| 1093 | tid_data->ssn = 0xffff; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1094 | tid_data->state = IWL_AGG_OFF; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1095 | spin_unlock_bh(&mvmsta->lock); |
| 1096 | |
| 1097 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1098 | |
| 1099 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 1100 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1101 | iwl_mvm_disable_txq(mvm, txq_id, |
| 1102 | vif->hw_queue[tid_to_mac80211_ac[tid]], tid, |
| 1103 | 0); |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1104 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1105 | case IWL_AGG_STARTING: |
| 1106 | case IWL_EMPTYING_HW_QUEUE_ADDBA: |
| 1107 | /* |
| 1108 | * The agg session has been stopped before it was set up. This |
| 1109 | * can happen when the AddBA timer times out for example. |
| 1110 | */ |
| 1111 | |
| 1112 | /* No barriers since we are under mutex */ |
| 1113 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1114 | |
| 1115 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1116 | tid_data->state = IWL_AGG_OFF; |
| 1117 | err = 0; |
| 1118 | break; |
| 1119 | default: |
| 1120 | IWL_ERR(mvm, |
| 1121 | "Stopping AGG while state not ON or starting for %d on %d (%d)\n", |
| 1122 | mvmsta->sta_id, tid, tid_data->state); |
| 1123 | IWL_ERR(mvm, |
| 1124 | "\ttid_data->txq_id = %d\n", tid_data->txq_id); |
| 1125 | err = -EINVAL; |
| 1126 | } |
| 1127 | |
| 1128 | spin_unlock_bh(&mvmsta->lock); |
| 1129 | |
| 1130 | return err; |
| 1131 | } |
| 1132 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1133 | int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1134 | struct ieee80211_sta *sta, u16 tid) |
| 1135 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1136 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1137 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 1138 | u16 txq_id; |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1139 | enum iwl_mvm_agg_state old_state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1140 | |
| 1141 | /* |
| 1142 | * First set the agg state to OFF to avoid calling |
| 1143 | * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. |
| 1144 | */ |
| 1145 | spin_lock_bh(&mvmsta->lock); |
| 1146 | txq_id = tid_data->txq_id; |
| 1147 | IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", |
| 1148 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1149 | old_state = tid_data->state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1150 | tid_data->state = IWL_AGG_OFF; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1151 | mvmsta->agg_tids &= ~BIT(tid); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1152 | spin_unlock_bh(&mvmsta->lock); |
| 1153 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1154 | /* No need to mark as reserved */ |
| 1155 | spin_lock_bh(&mvm->queue_info_lock); |
| 1156 | mvm->queue_info[txq_id].setup_reserved = false; |
| 1157 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1158 | |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1159 | if (old_state >= IWL_AGG_ON) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1160 | iwl_mvm_drain_sta(mvm, mvmsta, true); |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 1161 | if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0)) |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1162 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1163 | iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 1164 | mvmsta->tfd_queue_msk); |
| 1165 | iwl_mvm_drain_sta(mvm, mvmsta, false); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1166 | |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1167 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 1168 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1169 | iwl_mvm_disable_txq(mvm, tid_data->txq_id, |
| 1170 | vif->hw_queue[tid_to_mac80211_ac[tid]], tid, |
| 1171 | 0); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1172 | } |
| 1173 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1174 | return 0; |
| 1175 | } |
| 1176 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1177 | static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) |
| 1178 | { |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1179 | int i, max = -1, max_offs = -1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1180 | |
| 1181 | lockdep_assert_held(&mvm->mutex); |
| 1182 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1183 | /* Pick the unused key offset with the highest 'deleted' |
| 1184 | * counter. Every time a key is deleted, all the counters |
| 1185 | * are incremented and the one that was just deleted is |
| 1186 | * reset to zero. Thus, the highest counter is the one |
| 1187 | * that was deleted longest ago. Pick that one. |
| 1188 | */ |
| 1189 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 1190 | if (test_bit(i, mvm->fw_key_table)) |
| 1191 | continue; |
| 1192 | if (mvm->fw_key_deleted[i] > max) { |
| 1193 | max = mvm->fw_key_deleted[i]; |
| 1194 | max_offs = i; |
| 1195 | } |
| 1196 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1197 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1198 | if (max_offs < 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1199 | return STA_KEY_IDX_INVALID; |
| 1200 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1201 | __set_bit(max_offs, mvm->fw_key_table); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1202 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1203 | return max_offs; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1204 | } |
| 1205 | |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1206 | static u8 iwl_mvm_get_key_sta_id(struct iwl_mvm *mvm, |
| 1207 | struct ieee80211_vif *vif, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1208 | struct ieee80211_sta *sta) |
| 1209 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 1210 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1211 | |
| 1212 | if (sta) { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1213 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1214 | |
| 1215 | return mvm_sta->sta_id; |
| 1216 | } |
| 1217 | |
| 1218 | /* |
| 1219 | * The device expects GTKs for station interfaces to be |
| 1220 | * installed as GTKs for the AP station. If we have no |
| 1221 | * station ID, then use AP's station ID. |
| 1222 | */ |
| 1223 | if (vif->type == NL80211_IFTYPE_STATION && |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1224 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 1225 | u8 sta_id = mvmvif->ap_sta_id; |
| 1226 | |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1227 | sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id], |
| 1228 | lockdep_is_held(&mvm->mutex)); |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1229 | /* |
| 1230 | * It is possible that the 'sta' parameter is NULL, |
| 1231 | * for example when a GTK is removed - the sta_id will then |
| 1232 | * be the AP ID, and no station was passed by mac80211. |
| 1233 | */ |
| 1234 | if (IS_ERR_OR_NULL(sta)) |
| 1235 | return IWL_MVM_STATION_COUNT; |
| 1236 | |
| 1237 | return sta_id; |
| 1238 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1239 | |
Emmanuel Grumbach | 881acd8 | 2013-03-19 16:16:00 +0200 | [diff] [blame] | 1240 | return IWL_MVM_STATION_COUNT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, |
| 1244 | struct iwl_mvm_sta *mvm_sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1245 | struct ieee80211_key_conf *keyconf, bool mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1246 | u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags, |
| 1247 | u8 key_offset) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1248 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1249 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1250 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 1251 | int ret; |
| 1252 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1253 | u16 keyidx; |
| 1254 | int i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1255 | u8 sta_id = mvm_sta->sta_id; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1256 | |
| 1257 | keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 1258 | STA_KEY_FLG_KEYID_MSK; |
| 1259 | key_flags = cpu_to_le16(keyidx); |
| 1260 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); |
| 1261 | |
| 1262 | switch (keyconf->cipher) { |
| 1263 | case WLAN_CIPHER_SUITE_TKIP: |
| 1264 | key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1265 | cmd.tkip_rx_tsc_byte2 = tkip_iv32; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1266 | for (i = 0; i < 5; i++) |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1267 | cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); |
| 1268 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1269 | break; |
| 1270 | case WLAN_CIPHER_SUITE_CCMP: |
| 1271 | key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1272 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1273 | break; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1274 | case WLAN_CIPHER_SUITE_WEP104: |
| 1275 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES); |
John W. Linville | aa0cb08 | 2015-01-12 16:18:11 -0500 | [diff] [blame] | 1276 | /* fall through */ |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1277 | case WLAN_CIPHER_SUITE_WEP40: |
| 1278 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP); |
| 1279 | memcpy(cmd.key + 3, keyconf->key, keyconf->keylen); |
| 1280 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1281 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 1282 | key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); |
| 1283 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1284 | } |
| 1285 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1286 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1287 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 1288 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1289 | cmd.key_offset = key_offset; |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1290 | cmd.key_flags = key_flags; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1291 | cmd.sta_id = sta_id; |
| 1292 | |
| 1293 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1294 | if (cmd_flags & CMD_ASYNC) |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1295 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, |
| 1296 | sizeof(cmd), &cmd); |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1297 | else |
| 1298 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 1299 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1300 | |
| 1301 | switch (status) { |
| 1302 | case ADD_STA_SUCCESS: |
| 1303 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); |
| 1304 | break; |
| 1305 | default: |
| 1306 | ret = -EIO; |
| 1307 | IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); |
| 1308 | break; |
| 1309 | } |
| 1310 | |
| 1311 | return ret; |
| 1312 | } |
| 1313 | |
| 1314 | static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, |
| 1315 | struct ieee80211_key_conf *keyconf, |
| 1316 | u8 sta_id, bool remove_key) |
| 1317 | { |
| 1318 | struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; |
| 1319 | |
| 1320 | /* verify the key details match the required command's expectations */ |
| 1321 | if (WARN_ON((keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC) || |
| 1322 | (keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || |
| 1323 | (keyconf->keyidx != 4 && keyconf->keyidx != 5))) |
| 1324 | return -EINVAL; |
| 1325 | |
| 1326 | igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); |
| 1327 | igtk_cmd.sta_id = cpu_to_le32(sta_id); |
| 1328 | |
| 1329 | if (remove_key) { |
| 1330 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); |
| 1331 | } else { |
| 1332 | struct ieee80211_key_seq seq; |
| 1333 | const u8 *pn; |
| 1334 | |
| 1335 | memcpy(igtk_cmd.IGTK, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1336 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 1337 | pn = seq.aes_cmac.pn; |
| 1338 | igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | |
| 1339 | ((u64) pn[4] << 8) | |
| 1340 | ((u64) pn[3] << 16) | |
| 1341 | ((u64) pn[2] << 24) | |
| 1342 | ((u64) pn[1] << 32) | |
| 1343 | ((u64) pn[0] << 40)); |
| 1344 | } |
| 1345 | |
| 1346 | IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", |
| 1347 | remove_key ? "removing" : "installing", |
| 1348 | igtk_cmd.sta_id); |
| 1349 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1350 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1351 | sizeof(igtk_cmd), &igtk_cmd); |
| 1352 | } |
| 1353 | |
| 1354 | |
| 1355 | static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, |
| 1356 | struct ieee80211_vif *vif, |
| 1357 | struct ieee80211_sta *sta) |
| 1358 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 1359 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1360 | |
| 1361 | if (sta) |
| 1362 | return sta->addr; |
| 1363 | |
| 1364 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1365 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 1366 | u8 sta_id = mvmvif->ap_sta_id; |
| 1367 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1368 | lockdep_is_held(&mvm->mutex)); |
| 1369 | return sta->addr; |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | return NULL; |
| 1374 | } |
| 1375 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1376 | static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 1377 | struct ieee80211_vif *vif, |
| 1378 | struct ieee80211_sta *sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1379 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1380 | u8 key_offset, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1381 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1382 | { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1383 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1384 | int ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1385 | const u8 *addr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1386 | struct ieee80211_key_seq seq; |
| 1387 | u16 p1k[5]; |
| 1388 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1389 | switch (keyconf->cipher) { |
| 1390 | case WLAN_CIPHER_SUITE_TKIP: |
| 1391 | addr = iwl_mvm_get_mac_addr(mvm, vif, sta); |
| 1392 | /* get phase 1 key from mac80211 */ |
| 1393 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 1394 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1395 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1396 | seq.tkip.iv32, p1k, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1397 | break; |
| 1398 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1399 | case WLAN_CIPHER_SUITE_WEP40: |
| 1400 | case WLAN_CIPHER_SUITE_WEP104: |
| 1401 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1402 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1403 | break; |
| 1404 | default: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1405 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1406 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1409 | return ret; |
| 1410 | } |
| 1411 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1412 | 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] | 1413 | struct ieee80211_key_conf *keyconf, |
| 1414 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1415 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1416 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1417 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 1418 | int ret; |
| 1419 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1420 | |
Emmanuel Grumbach | 8115efb | 2013-02-05 10:08:35 +0200 | [diff] [blame] | 1421 | key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 1422 | STA_KEY_FLG_KEYID_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1423 | key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); |
| 1424 | key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); |
| 1425 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1426 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1427 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 1428 | |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1429 | cmd.key_flags = key_flags; |
| 1430 | cmd.key_offset = keyconf->hw_key_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1431 | cmd.sta_id = sta_id; |
| 1432 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1433 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1434 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 1435 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1436 | |
| 1437 | switch (status) { |
| 1438 | case ADD_STA_SUCCESS: |
| 1439 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); |
| 1440 | break; |
| 1441 | default: |
| 1442 | ret = -EIO; |
| 1443 | IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); |
| 1444 | break; |
| 1445 | } |
| 1446 | |
| 1447 | return ret; |
| 1448 | } |
| 1449 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1450 | int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 1451 | struct ieee80211_vif *vif, |
| 1452 | struct ieee80211_sta *sta, |
| 1453 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1454 | u8 key_offset) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1455 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1456 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1457 | u8 sta_id; |
| 1458 | int ret; |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 1459 | static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0}; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1460 | |
| 1461 | lockdep_assert_held(&mvm->mutex); |
| 1462 | |
| 1463 | /* Get the station id from the mvm local station table */ |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1464 | sta_id = iwl_mvm_get_key_sta_id(mvm, vif, sta); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1465 | if (sta_id == IWL_MVM_STATION_COUNT) { |
| 1466 | IWL_ERR(mvm, "Failed to find station id\n"); |
| 1467 | return -EINVAL; |
| 1468 | } |
| 1469 | |
| 1470 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { |
| 1471 | ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false); |
| 1472 | goto end; |
| 1473 | } |
| 1474 | |
| 1475 | /* |
| 1476 | * It is possible that the 'sta' parameter is NULL, and thus |
| 1477 | * there is a need to retrieve the sta from the local station table. |
| 1478 | */ |
| 1479 | if (!sta) { |
| 1480 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1481 | lockdep_is_held(&mvm->mutex)); |
| 1482 | if (IS_ERR_OR_NULL(sta)) { |
| 1483 | IWL_ERR(mvm, "Invalid station id\n"); |
| 1484 | return -EINVAL; |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif)) |
| 1489 | return -EINVAL; |
| 1490 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1491 | /* If the key_offset is not pre-assigned, we need to find a |
| 1492 | * new offset to use. In normal cases, the offset is not |
| 1493 | * pre-assigned, but during HW_RESTART we want to reuse the |
| 1494 | * same indices, so we pass them when this function is called. |
| 1495 | * |
| 1496 | * In D3 entry, we need to hardcoded the indices (because the |
| 1497 | * firmware hardcodes the PTK offset to 0). In this case, we |
| 1498 | * need to make sure we don't overwrite the hw_key_idx in the |
| 1499 | * keyconf structure, because otherwise we cannot configure |
| 1500 | * the original ones back when resuming. |
| 1501 | */ |
| 1502 | if (key_offset == STA_KEY_IDX_INVALID) { |
| 1503 | key_offset = iwl_mvm_set_fw_key_idx(mvm); |
| 1504 | if (key_offset == STA_KEY_IDX_INVALID) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1505 | return -ENOSPC; |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1506 | keyconf->hw_key_idx = key_offset; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1507 | } |
| 1508 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1509 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1510 | if (ret) { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1511 | __clear_bit(keyconf->hw_key_idx, mvm->fw_key_table); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1512 | goto end; |
| 1513 | } |
| 1514 | |
| 1515 | /* |
| 1516 | * For WEP, the same key is used for multicast and unicast. Upload it |
| 1517 | * again, using the same key offset, and now pointing the other one |
| 1518 | * to the same key slot (offset). |
| 1519 | * If this fails, remove the original as well. |
| 1520 | */ |
| 1521 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 1522 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) { |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1523 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, |
| 1524 | key_offset, !mcast); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1525 | if (ret) { |
| 1526 | __clear_bit(keyconf->hw_key_idx, mvm->fw_key_table); |
| 1527 | __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
| 1528 | } |
| 1529 | } |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1530 | |
| 1531 | end: |
| 1532 | IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", |
| 1533 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 1534 | sta ? sta->addr : zero_addr, ret); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1535 | return ret; |
| 1536 | } |
| 1537 | |
| 1538 | int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, |
| 1539 | struct ieee80211_vif *vif, |
| 1540 | struct ieee80211_sta *sta, |
| 1541 | struct ieee80211_key_conf *keyconf) |
| 1542 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1543 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1544 | u8 sta_id; |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1545 | int ret, i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1546 | |
| 1547 | lockdep_assert_held(&mvm->mutex); |
| 1548 | |
| 1549 | /* Get the station id from the mvm local station table */ |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1550 | sta_id = iwl_mvm_get_key_sta_id(mvm, vif, sta); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1551 | |
| 1552 | IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", |
| 1553 | keyconf->keyidx, sta_id); |
| 1554 | |
| 1555 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) |
| 1556 | return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); |
| 1557 | |
| 1558 | if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) { |
| 1559 | IWL_ERR(mvm, "offset %d not used in fw key table.\n", |
| 1560 | keyconf->hw_key_idx); |
| 1561 | return -ENOENT; |
| 1562 | } |
| 1563 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1564 | /* track which key was deleted last */ |
| 1565 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 1566 | if (mvm->fw_key_deleted[i] < U8_MAX) |
| 1567 | mvm->fw_key_deleted[i]++; |
| 1568 | } |
| 1569 | mvm->fw_key_deleted[keyconf->hw_key_idx] = 0; |
| 1570 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1571 | if (sta_id == IWL_MVM_STATION_COUNT) { |
| 1572 | IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1576 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
| 1577 | if (ret) |
| 1578 | return ret; |
| 1579 | |
| 1580 | /* delete WEP key twice to get rid of (now useless) offset */ |
| 1581 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 1582 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 1583 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast); |
| 1584 | |
| 1585 | return ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1586 | } |
| 1587 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1588 | void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, |
| 1589 | struct ieee80211_vif *vif, |
| 1590 | struct ieee80211_key_conf *keyconf, |
| 1591 | struct ieee80211_sta *sta, u32 iv32, |
| 1592 | u16 *phase1key) |
| 1593 | { |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1594 | struct iwl_mvm_sta *mvm_sta; |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1595 | u8 sta_id; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1596 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1597 | |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1598 | rcu_read_lock(); |
| 1599 | |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1600 | sta_id = iwl_mvm_get_key_sta_id(mvm, vif, sta); |
| 1601 | if (WARN_ON_ONCE(sta_id == IWL_MVM_STATION_COUNT)) |
| 1602 | goto unlock; |
| 1603 | |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1604 | if (!sta) { |
| 1605 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 1606 | if (WARN_ON(IS_ERR_OR_NULL(sta))) { |
| 1607 | rcu_read_unlock(); |
| 1608 | return; |
| 1609 | } |
| 1610 | } |
| 1611 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1612 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1613 | iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1614 | iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx); |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1615 | |
| 1616 | unlock: |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1617 | rcu_read_unlock(); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1618 | } |
| 1619 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1620 | void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, |
| 1621 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1622 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1623 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1624 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1625 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1626 | .sta_id = mvmsta->sta_id, |
Emmanuel Grumbach | 5af0177 | 2013-06-09 12:59:24 +0300 | [diff] [blame] | 1627 | .station_flags_msk = cpu_to_le32(STA_FLG_PS), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1628 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1629 | }; |
| 1630 | int ret; |
| 1631 | |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1632 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, sizeof(cmd), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1633 | if (ret) |
| 1634 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 1635 | } |
| 1636 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1637 | void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, |
| 1638 | struct ieee80211_sta *sta, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1639 | enum ieee80211_frame_release_type reason, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1640 | u16 cnt, u16 tids, bool more_data, |
| 1641 | bool agg) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1642 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1643 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1644 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1645 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1646 | .sta_id = mvmsta->sta_id, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1647 | .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, |
| 1648 | .sleep_tx_count = cpu_to_le16(cnt), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1649 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1650 | }; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1651 | int tid, ret; |
| 1652 | unsigned long _tids = tids; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1653 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1654 | /* convert TIDs to ACs - we don't support TSPEC so that's OK |
| 1655 | * Note that this field is reserved and unused by firmware not |
| 1656 | * supporting GO uAPSD, so it's safe to always do this. |
| 1657 | */ |
| 1658 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) |
| 1659 | cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); |
| 1660 | |
| 1661 | /* If we're releasing frames from aggregation queues then check if the |
| 1662 | * all queues combined that we're releasing frames from have |
| 1663 | * - more frames than the service period, in which case more_data |
| 1664 | * needs to be set |
| 1665 | * - fewer than 'cnt' frames, in which case we need to adjust the |
| 1666 | * firmware command (but do that unconditionally) |
| 1667 | */ |
| 1668 | if (agg) { |
| 1669 | int remaining = cnt; |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1670 | int sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1671 | |
| 1672 | spin_lock_bh(&mvmsta->lock); |
| 1673 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { |
| 1674 | struct iwl_mvm_tid_data *tid_data; |
| 1675 | u16 n_queued; |
| 1676 | |
| 1677 | tid_data = &mvmsta->tid_data[tid]; |
| 1678 | if (WARN(tid_data->state != IWL_AGG_ON && |
| 1679 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA, |
| 1680 | "TID %d state is %d\n", |
| 1681 | tid, tid_data->state)) { |
| 1682 | spin_unlock_bh(&mvmsta->lock); |
| 1683 | ieee80211_sta_eosp(sta); |
| 1684 | return; |
| 1685 | } |
| 1686 | |
| 1687 | n_queued = iwl_mvm_tid_queued(tid_data); |
| 1688 | if (n_queued > remaining) { |
| 1689 | more_data = true; |
| 1690 | remaining = 0; |
| 1691 | break; |
| 1692 | } |
| 1693 | remaining -= n_queued; |
| 1694 | } |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1695 | sleep_tx_count = cnt - remaining; |
| 1696 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) |
| 1697 | mvmsta->sleep_tx_count = sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1698 | spin_unlock_bh(&mvmsta->lock); |
| 1699 | |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1700 | cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1701 | if (WARN_ON(cnt - remaining == 0)) { |
| 1702 | ieee80211_sta_eosp(sta); |
| 1703 | return; |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | /* Note: this is ignored by firmware not supporting GO uAPSD */ |
| 1708 | if (more_data) |
| 1709 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA); |
| 1710 | |
| 1711 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { |
| 1712 | mvmsta->next_status_eosp = true; |
| 1713 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL); |
| 1714 | } else { |
| 1715 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD); |
| 1716 | } |
| 1717 | |
Emmanuel Grumbach | 156f92f | 2015-11-24 14:55:18 +0200 | [diff] [blame] | 1718 | /* block the Tx queues until the FW updated the sleep Tx count */ |
| 1719 | iwl_trans_block_txq_ptrs(mvm->trans, true); |
| 1720 | |
| 1721 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, |
| 1722 | CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK, |
| 1723 | sizeof(cmd), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1724 | if (ret) |
| 1725 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 1726 | } |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1727 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1728 | void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, |
| 1729 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1730 | { |
| 1731 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 1732 | struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; |
| 1733 | struct ieee80211_sta *sta; |
| 1734 | u32 sta_id = le32_to_cpu(notif->sta_id); |
| 1735 | |
| 1736 | if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1737 | return; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1738 | |
| 1739 | rcu_read_lock(); |
| 1740 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 1741 | if (!IS_ERR_OR_NULL(sta)) |
| 1742 | ieee80211_sta_eosp(sta); |
| 1743 | rcu_read_unlock(); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1744 | } |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 1745 | |
| 1746 | void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm, |
| 1747 | struct iwl_mvm_sta *mvmsta, bool disable) |
| 1748 | { |
| 1749 | struct iwl_mvm_add_sta_cmd cmd = { |
| 1750 | .add_modify = STA_MODE_MODIFY, |
| 1751 | .sta_id = mvmsta->sta_id, |
| 1752 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, |
| 1753 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), |
| 1754 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
| 1755 | }; |
| 1756 | int ret; |
| 1757 | |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 1758 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, sizeof(cmd), &cmd); |
| 1759 | if (ret) |
| 1760 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 1761 | } |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 1762 | |
| 1763 | void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm, |
| 1764 | struct ieee80211_sta *sta, |
| 1765 | bool disable) |
| 1766 | { |
| 1767 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 1768 | |
| 1769 | spin_lock_bh(&mvm_sta->lock); |
| 1770 | |
| 1771 | if (mvm_sta->disable_tx == disable) { |
| 1772 | spin_unlock_bh(&mvm_sta->lock); |
| 1773 | return; |
| 1774 | } |
| 1775 | |
| 1776 | mvm_sta->disable_tx = disable; |
| 1777 | |
| 1778 | /* |
Sara Sharon | 0d365ae | 2015-03-31 12:24:05 +0300 | [diff] [blame] | 1779 | * Tell mac80211 to start/stop queuing tx for this station, |
| 1780 | * but don't stop queuing if there are still pending frames |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 1781 | * for this station. |
| 1782 | */ |
| 1783 | if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) |
| 1784 | ieee80211_sta_block_awake(mvm->hw, sta, disable); |
| 1785 | |
| 1786 | iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable); |
| 1787 | |
| 1788 | spin_unlock_bh(&mvm_sta->lock); |
| 1789 | } |
| 1790 | |
| 1791 | void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm, |
| 1792 | struct iwl_mvm_vif *mvmvif, |
| 1793 | bool disable) |
| 1794 | { |
| 1795 | struct ieee80211_sta *sta; |
| 1796 | struct iwl_mvm_sta *mvm_sta; |
| 1797 | int i; |
| 1798 | |
| 1799 | lockdep_assert_held(&mvm->mutex); |
| 1800 | |
| 1801 | /* Block/unblock all the stations of the given mvmvif */ |
| 1802 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 1803 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 1804 | lockdep_is_held(&mvm->mutex)); |
| 1805 | if (IS_ERR_OR_NULL(sta)) |
| 1806 | continue; |
| 1807 | |
| 1808 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 1809 | if (mvm_sta->mac_id_n_color != |
| 1810 | FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)) |
| 1811 | continue; |
| 1812 | |
| 1813 | iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable); |
| 1814 | } |
| 1815 | } |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 1816 | |
| 1817 | void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1818 | { |
| 1819 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1820 | struct iwl_mvm_sta *mvmsta; |
| 1821 | |
| 1822 | rcu_read_lock(); |
| 1823 | |
| 1824 | mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id); |
| 1825 | |
| 1826 | if (!WARN_ON(!mvmsta)) |
| 1827 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true); |
| 1828 | |
| 1829 | rcu_read_unlock(); |
| 1830 | } |