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