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