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