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