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