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 | |
| 66 | #include <linux/etherdevice.h> |
| 67 | #include <net/mac80211.h> |
| 68 | #include "iwl-io.h" |
| 69 | #include "iwl-prph.h" |
| 70 | #include "fw-api.h" |
| 71 | #include "mvm.h" |
Andrei Otcheretianski | 7f0a7c6 | 2014-05-04 11:48:12 +0300 | [diff] [blame] | 72 | #include "time-event.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 73 | |
| 74 | const u8 iwl_mvm_ac_to_tx_fifo[] = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 75 | IWL_MVM_TX_FIFO_VO, |
Emmanuel Grumbach | 3dd9479 | 2013-12-19 16:50:49 +0200 | [diff] [blame] | 76 | IWL_MVM_TX_FIFO_VI, |
| 77 | IWL_MVM_TX_FIFO_BE, |
| 78 | IWL_MVM_TX_FIFO_BK, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | struct iwl_mvm_mac_iface_iterator_data { |
| 82 | struct iwl_mvm *mvm; |
| 83 | struct ieee80211_vif *vif; |
| 84 | unsigned long available_mac_ids[BITS_TO_LONGS(NUM_MAC_INDEX_DRIVER)]; |
| 85 | unsigned long available_tsf_ids[BITS_TO_LONGS(NUM_TSF_IDS)]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 86 | enum iwl_tsf_id preferred_tsf; |
| 87 | bool found_vif; |
| 88 | }; |
| 89 | |
Arik Nemtsov | a74346d | 2014-09-21 19:07:30 +0300 | [diff] [blame^] | 90 | struct iwl_mvm_hw_queues_iface_iterator_data { |
| 91 | struct ieee80211_vif *exclude_vif; |
| 92 | unsigned long used_hw_queues; |
| 93 | }; |
| 94 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 95 | static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac, |
| 96 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 97 | { |
| 98 | struct iwl_mvm_mac_iface_iterator_data *data = _data; |
| 99 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Ilan Peer | 2c3e62a | 2014-02-02 21:54:35 +0200 | [diff] [blame] | 100 | u16 min_bi; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 101 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 102 | /* Skip the interface for which we are trying to assign a tsf_id */ |
| 103 | if (vif == data->vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 104 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * The TSF is a hardware/firmware resource, there are 4 and |
| 108 | * the driver should assign and free them as needed. However, |
| 109 | * there are cases where 2 MACs should share the same TSF ID |
| 110 | * for the purpose of clock sync, an optimization to avoid |
| 111 | * clock drift causing overlapping TBTTs/DTIMs for a GO and |
| 112 | * client in the system. |
| 113 | * |
| 114 | * The firmware will decide according to the MAC type which |
| 115 | * will be the master and slave. Clients that need to sync |
| 116 | * with a remote station will be the master, and an AP or GO |
| 117 | * will be the slave. |
| 118 | * |
| 119 | * Depending on the new interface type it can be slaved to |
| 120 | * or become the master of an existing interface. |
| 121 | */ |
| 122 | switch (data->vif->type) { |
| 123 | case NL80211_IFTYPE_STATION: |
| 124 | /* |
Ilan Peer | 2c3e62a | 2014-02-02 21:54:35 +0200 | [diff] [blame] | 125 | * The new interface is a client, so if the one we're iterating |
| 126 | * is an AP, and the beacon interval of the AP is a multiple or |
| 127 | * divisor of the beacon interval of the client, the same TSF |
| 128 | * should be used to avoid drift between the new client and |
| 129 | * existing AP. The existing AP will get drift updates from the |
| 130 | * new client context in this case. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 131 | */ |
Ilan Peer | 2c3e62a | 2014-02-02 21:54:35 +0200 | [diff] [blame] | 132 | if (vif->type != NL80211_IFTYPE_AP || |
| 133 | data->preferred_tsf != NUM_TSF_IDS || |
| 134 | !test_bit(mvmvif->tsf_id, data->available_tsf_ids)) |
| 135 | break; |
| 136 | |
| 137 | min_bi = min(data->vif->bss_conf.beacon_int, |
| 138 | vif->bss_conf.beacon_int); |
| 139 | |
| 140 | if (!min_bi) |
| 141 | break; |
| 142 | |
| 143 | if ((data->vif->bss_conf.beacon_int - |
| 144 | vif->bss_conf.beacon_int) % min_bi == 0) { |
| 145 | data->preferred_tsf = mvmvif->tsf_id; |
| 146 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 147 | } |
| 148 | break; |
Ilan Peer | 2c3e62a | 2014-02-02 21:54:35 +0200 | [diff] [blame] | 149 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 150 | case NL80211_IFTYPE_AP: |
| 151 | /* |
Ilan Peer | 2c3e62a | 2014-02-02 21:54:35 +0200 | [diff] [blame] | 152 | * The new interface is AP/GO, so if its beacon interval is a |
| 153 | * multiple or a divisor of the beacon interval of an existing |
| 154 | * interface, it should get drift updates from an existing |
| 155 | * client or use the same TSF as an existing GO. There's no |
| 156 | * drift between TSFs internally but if they used different |
| 157 | * TSFs then a new client MAC could update one of them and |
| 158 | * cause drift that way. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 159 | */ |
Ilan Peer | 2c3e62a | 2014-02-02 21:54:35 +0200 | [diff] [blame] | 160 | if ((vif->type != NL80211_IFTYPE_AP && |
| 161 | vif->type != NL80211_IFTYPE_STATION) || |
| 162 | data->preferred_tsf != NUM_TSF_IDS || |
| 163 | !test_bit(mvmvif->tsf_id, data->available_tsf_ids)) |
| 164 | break; |
| 165 | |
| 166 | min_bi = min(data->vif->bss_conf.beacon_int, |
| 167 | vif->bss_conf.beacon_int); |
| 168 | |
| 169 | if (!min_bi) |
| 170 | break; |
| 171 | |
| 172 | if ((data->vif->bss_conf.beacon_int - |
| 173 | vif->bss_conf.beacon_int) % min_bi == 0) { |
| 174 | data->preferred_tsf = mvmvif->tsf_id; |
| 175 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 176 | } |
| 177 | break; |
| 178 | default: |
| 179 | /* |
| 180 | * For all other interface types there's no need to |
| 181 | * take drift into account. Either they're exclusive |
| 182 | * like IBSS and monitor, or we don't care much about |
| 183 | * their TSF (like P2P Device), but we won't be able |
| 184 | * to share the TSF resource. |
| 185 | */ |
| 186 | break; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * Unless we exited above, we can't share the TSF resource |
| 191 | * that the virtual interface we're iterating over is using |
| 192 | * with the new one, so clear the available bit and if this |
| 193 | * was the preferred one, reset that as well. |
| 194 | */ |
| 195 | __clear_bit(mvmvif->tsf_id, data->available_tsf_ids); |
| 196 | |
| 197 | if (data->preferred_tsf == mvmvif->tsf_id) |
| 198 | data->preferred_tsf = NUM_TSF_IDS; |
| 199 | } |
| 200 | |
Johannes Berg | 110cf81 | 2014-08-01 23:14:24 +0200 | [diff] [blame] | 201 | /* |
| 202 | * Get the mask of the queues used by the vif |
| 203 | */ |
Arik Nemtsov | d92b732e | 2014-09-21 19:00:42 +0300 | [diff] [blame] | 204 | u32 iwl_mvm_mac_get_queues_mask(struct ieee80211_vif *vif) |
Johannes Berg | 110cf81 | 2014-08-01 23:14:24 +0200 | [diff] [blame] | 205 | { |
| 206 | u32 qmask = 0, ac; |
| 207 | |
| 208 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) |
| 209 | return BIT(IWL_MVM_OFFCHANNEL_QUEUE); |
| 210 | |
| 211 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 212 | qmask |= BIT(vif->hw_queue[ac]); |
| 213 | |
| 214 | if (vif->type == NL80211_IFTYPE_AP) |
| 215 | qmask |= BIT(vif->cab_queue); |
| 216 | |
| 217 | return qmask; |
| 218 | } |
| 219 | |
Arik Nemtsov | a74346d | 2014-09-21 19:07:30 +0300 | [diff] [blame^] | 220 | static void iwl_mvm_iface_hw_queues_iter(void *_data, u8 *mac, |
| 221 | struct ieee80211_vif *vif) |
| 222 | { |
| 223 | struct iwl_mvm_hw_queues_iface_iterator_data *data = _data; |
| 224 | |
| 225 | /* exclude the given vif */ |
| 226 | if (vif == data->exclude_vif) |
| 227 | return; |
| 228 | |
| 229 | data->used_hw_queues |= iwl_mvm_mac_get_queues_mask(vif); |
| 230 | } |
| 231 | |
| 232 | static void iwl_mvm_mac_sta_hw_queues_iter(void *_data, |
| 233 | struct ieee80211_sta *sta) |
| 234 | { |
| 235 | struct iwl_mvm_hw_queues_iface_iterator_data *data = _data; |
| 236 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 237 | |
| 238 | /* Mark the queues used by the sta */ |
| 239 | data->used_hw_queues |= mvmsta->tfd_queue_msk; |
| 240 | } |
| 241 | |
| 242 | unsigned long iwl_mvm_get_used_hw_queues(struct iwl_mvm *mvm, |
| 243 | struct ieee80211_vif *exclude_vif) |
| 244 | { |
| 245 | struct iwl_mvm_hw_queues_iface_iterator_data data = { |
| 246 | .exclude_vif = exclude_vif, |
| 247 | .used_hw_queues = |
| 248 | BIT(IWL_MVM_OFFCHANNEL_QUEUE) | |
| 249 | BIT(mvm->aux_queue) | |
| 250 | BIT(IWL_MVM_CMD_QUEUE), |
| 251 | }; |
| 252 | |
| 253 | lockdep_assert_held(&mvm->mutex); |
| 254 | |
| 255 | /* mark all VIF used hw queues */ |
| 256 | ieee80211_iterate_active_interfaces_atomic( |
| 257 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 258 | iwl_mvm_iface_hw_queues_iter, &data); |
| 259 | |
| 260 | /* don't assign the same hw queues as TDLS stations */ |
| 261 | ieee80211_iterate_stations_atomic(mvm->hw, |
| 262 | iwl_mvm_mac_sta_hw_queues_iter, |
| 263 | &data); |
| 264 | |
| 265 | return data.used_hw_queues; |
| 266 | } |
| 267 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 268 | static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac, |
| 269 | struct ieee80211_vif *vif) |
| 270 | { |
| 271 | struct iwl_mvm_mac_iface_iterator_data *data = _data; |
| 272 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 273 | |
| 274 | /* Iterator may already find the interface being added -- skip it */ |
| 275 | if (vif == data->vif) { |
| 276 | data->found_vif = true; |
| 277 | return; |
| 278 | } |
| 279 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 280 | /* Mark MAC IDs as used by clearing the available bit, and |
| 281 | * (below) mark TSFs as used if their existing use is not |
| 282 | * compatible with the new interface type. |
| 283 | * No locking or atomic bit operations are needed since the |
| 284 | * data is on the stack of the caller function. |
| 285 | */ |
| 286 | __clear_bit(mvmvif->id, data->available_mac_ids); |
| 287 | |
| 288 | /* find a suitable tsf_id */ |
| 289 | iwl_mvm_mac_tsf_id_iter(_data, mac, vif); |
| 290 | } |
| 291 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 292 | void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm, |
| 293 | struct ieee80211_vif *vif) |
| 294 | { |
| 295 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 296 | struct iwl_mvm_mac_iface_iterator_data data = { |
| 297 | .mvm = mvm, |
| 298 | .vif = vif, |
| 299 | .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 }, |
| 300 | /* no preference yet */ |
| 301 | .preferred_tsf = NUM_TSF_IDS, |
| 302 | }; |
| 303 | |
| 304 | ieee80211_iterate_active_interfaces_atomic( |
| 305 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 306 | iwl_mvm_mac_tsf_id_iter, &data); |
| 307 | |
| 308 | if (data.preferred_tsf != NUM_TSF_IDS) |
| 309 | mvmvif->tsf_id = data.preferred_tsf; |
| 310 | else if (!test_bit(mvmvif->tsf_id, data.available_tsf_ids)) |
| 311 | mvmvif->tsf_id = find_first_bit(data.available_tsf_ids, |
| 312 | NUM_TSF_IDS); |
| 313 | } |
| 314 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 315 | static int iwl_mvm_mac_ctxt_allocate_resources(struct iwl_mvm *mvm, |
| 316 | struct ieee80211_vif *vif) |
| 317 | { |
| 318 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 319 | struct iwl_mvm_mac_iface_iterator_data data = { |
| 320 | .mvm = mvm, |
| 321 | .vif = vif, |
| 322 | .available_mac_ids = { (1 << NUM_MAC_INDEX_DRIVER) - 1 }, |
| 323 | .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 }, |
| 324 | /* no preference yet */ |
| 325 | .preferred_tsf = NUM_TSF_IDS, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 326 | .found_vif = false, |
| 327 | }; |
| 328 | u32 ac; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 329 | int ret, i; |
Johannes Berg | 110cf81 | 2014-08-01 23:14:24 +0200 | [diff] [blame] | 330 | unsigned long used_hw_queues; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 331 | |
| 332 | /* |
| 333 | * Allocate a MAC ID and a TSF for this MAC, along with the queues |
| 334 | * and other resources. |
| 335 | */ |
| 336 | |
| 337 | /* |
| 338 | * Before the iterator, we start with all MAC IDs and TSFs available. |
| 339 | * |
| 340 | * During iteration, all MAC IDs are cleared that are in use by other |
| 341 | * virtual interfaces, and all TSF IDs are cleared that can't be used |
| 342 | * by this new virtual interface because they're used by an interface |
| 343 | * that can't share it with the new one. |
| 344 | * At the same time, we check if there's a preferred TSF in the case |
| 345 | * that we should share it with another interface. |
| 346 | */ |
| 347 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 348 | /* Currently, MAC ID 0 should be used only for the managed/IBSS vif */ |
| 349 | switch (vif->type) { |
| 350 | case NL80211_IFTYPE_ADHOC: |
| 351 | break; |
| 352 | case NL80211_IFTYPE_STATION: |
| 353 | if (!vif->p2p) |
| 354 | break; |
| 355 | /* fall through */ |
| 356 | default: |
Ilan Peer | ec8b688 | 2013-02-13 13:27:18 +0200 | [diff] [blame] | 357 | __clear_bit(0, data.available_mac_ids); |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 358 | } |
Ilan Peer | ec8b688 | 2013-02-13 13:27:18 +0200 | [diff] [blame] | 359 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 360 | ieee80211_iterate_active_interfaces_atomic( |
| 361 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 362 | iwl_mvm_mac_iface_iterator, &data); |
| 363 | |
Arik Nemtsov | a74346d | 2014-09-21 19:07:30 +0300 | [diff] [blame^] | 364 | used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, vif); |
| 365 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 366 | /* |
| 367 | * In the case we're getting here during resume, it's similar to |
| 368 | * firmware restart, and with RESUME_ALL the iterator will find |
| 369 | * the vif being added already. |
| 370 | * We don't want to reassign any IDs in either case since doing |
| 371 | * so would probably assign different IDs (as interfaces aren't |
| 372 | * necessarily added in the same order), but the old IDs were |
| 373 | * preserved anyway, so skip ID assignment for both resume and |
| 374 | * recovery. |
| 375 | */ |
| 376 | if (data.found_vif) |
| 377 | return 0; |
| 378 | |
| 379 | /* Therefore, in recovery, we can't get here */ |
Ilan Peer | fd11bd0 | 2013-06-16 12:18:11 +0300 | [diff] [blame] | 380 | if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))) |
| 381 | return -EBUSY; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 382 | |
| 383 | mvmvif->id = find_first_bit(data.available_mac_ids, |
| 384 | NUM_MAC_INDEX_DRIVER); |
| 385 | if (mvmvif->id == NUM_MAC_INDEX_DRIVER) { |
| 386 | IWL_ERR(mvm, "Failed to init MAC context - no free ID!\n"); |
| 387 | ret = -EIO; |
| 388 | goto exit_fail; |
| 389 | } |
| 390 | |
| 391 | if (data.preferred_tsf != NUM_TSF_IDS) |
| 392 | mvmvif->tsf_id = data.preferred_tsf; |
| 393 | else |
| 394 | mvmvif->tsf_id = find_first_bit(data.available_tsf_ids, |
| 395 | NUM_TSF_IDS); |
| 396 | if (mvmvif->tsf_id == NUM_TSF_IDS) { |
| 397 | IWL_ERR(mvm, "Failed to init MAC context - no free TSF!\n"); |
| 398 | ret = -EIO; |
| 399 | goto exit_fail; |
| 400 | } |
| 401 | |
| 402 | mvmvif->color = 0; |
| 403 | |
Ilan Peer | 1e849c9 | 2013-02-13 12:26:39 +0200 | [diff] [blame] | 404 | INIT_LIST_HEAD(&mvmvif->time_event_data.list); |
| 405 | mvmvif->time_event_data.id = TE_MAX; |
| 406 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 407 | /* No need to allocate data queues to P2P Device MAC.*/ |
| 408 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 409 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 410 | vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE; |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | /* Find available queues, and allocate them to the ACs */ |
| 416 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
Johannes Berg | 110cf81 | 2014-08-01 23:14:24 +0200 | [diff] [blame] | 417 | u8 queue = find_first_zero_bit(&used_hw_queues, |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 418 | mvm->first_agg_queue); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 419 | |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 420 | if (queue >= mvm->first_agg_queue) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 421 | IWL_ERR(mvm, "Failed to allocate queue\n"); |
| 422 | ret = -EIO; |
| 423 | goto exit_fail; |
| 424 | } |
| 425 | |
Johannes Berg | 110cf81 | 2014-08-01 23:14:24 +0200 | [diff] [blame] | 426 | __set_bit(queue, &used_hw_queues); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 427 | vif->hw_queue[ac] = queue; |
| 428 | } |
| 429 | |
| 430 | /* Allocate the CAB queue for softAP and GO interfaces */ |
| 431 | if (vif->type == NL80211_IFTYPE_AP) { |
Johannes Berg | 110cf81 | 2014-08-01 23:14:24 +0200 | [diff] [blame] | 432 | u8 queue = find_first_zero_bit(&used_hw_queues, |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 433 | mvm->first_agg_queue); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 434 | |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 435 | if (queue >= mvm->first_agg_queue) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 436 | IWL_ERR(mvm, "Failed to allocate cab queue\n"); |
| 437 | ret = -EIO; |
| 438 | goto exit_fail; |
| 439 | } |
| 440 | |
| 441 | vif->cab_queue = queue; |
| 442 | } else { |
| 443 | vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; |
| 444 | } |
| 445 | |
| 446 | mvmvif->bcast_sta.sta_id = IWL_MVM_STATION_COUNT; |
| 447 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 448 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 449 | for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) |
| 450 | mvmvif->smps_requests[i] = IEEE80211_SMPS_AUTOMATIC; |
| 451 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 452 | return 0; |
| 453 | |
| 454 | exit_fail: |
| 455 | memset(mvmvif, 0, sizeof(struct iwl_mvm_vif)); |
| 456 | memset(vif->hw_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(vif->hw_queue)); |
| 457 | vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; |
| 458 | return ret; |
| 459 | } |
| 460 | |
| 461 | int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 462 | { |
| 463 | u32 ac; |
| 464 | int ret; |
| 465 | |
| 466 | lockdep_assert_held(&mvm->mutex); |
| 467 | |
| 468 | ret = iwl_mvm_mac_ctxt_allocate_resources(mvm, vif); |
| 469 | if (ret) |
| 470 | return ret; |
| 471 | |
| 472 | switch (vif->type) { |
| 473 | case NL80211_IFTYPE_P2P_DEVICE: |
Avri Altman | 3edf8ff | 2014-07-30 11:41:01 +0300 | [diff] [blame] | 474 | iwl_mvm_enable_ac_txq(mvm, IWL_MVM_OFFCHANNEL_QUEUE, |
| 475 | IWL_MVM_TX_FIFO_VO); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 476 | break; |
| 477 | case NL80211_IFTYPE_AP: |
Avri Altman | 3edf8ff | 2014-07-30 11:41:01 +0300 | [diff] [blame] | 478 | iwl_mvm_enable_ac_txq(mvm, vif->cab_queue, |
| 479 | IWL_MVM_TX_FIFO_MCAST); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 480 | /* fall through */ |
| 481 | default: |
| 482 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
Avri Altman | 3edf8ff | 2014-07-30 11:41:01 +0300 | [diff] [blame] | 483 | iwl_mvm_enable_ac_txq(mvm, vif->hw_queue[ac], |
| 484 | iwl_mvm_ac_to_tx_fifo[ac]); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 485 | break; |
| 486 | } |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | void iwl_mvm_mac_ctxt_release(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 492 | { |
| 493 | int ac; |
| 494 | |
| 495 | lockdep_assert_held(&mvm->mutex); |
| 496 | |
| 497 | switch (vif->type) { |
| 498 | case NL80211_IFTYPE_P2P_DEVICE: |
Avri Altman | 3edf8ff | 2014-07-30 11:41:01 +0300 | [diff] [blame] | 499 | iwl_mvm_disable_txq(mvm, IWL_MVM_OFFCHANNEL_QUEUE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 500 | break; |
| 501 | case NL80211_IFTYPE_AP: |
Avri Altman | 3edf8ff | 2014-07-30 11:41:01 +0300 | [diff] [blame] | 502 | iwl_mvm_disable_txq(mvm, vif->cab_queue); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 503 | /* fall through */ |
| 504 | default: |
| 505 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
Avri Altman | 3edf8ff | 2014-07-30 11:41:01 +0300 | [diff] [blame] | 506 | iwl_mvm_disable_txq(mvm, vif->hw_queue[ac]); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | |
| 510 | static void iwl_mvm_ack_rates(struct iwl_mvm *mvm, |
| 511 | struct ieee80211_vif *vif, |
| 512 | enum ieee80211_band band, |
| 513 | u8 *cck_rates, u8 *ofdm_rates) |
| 514 | { |
| 515 | struct ieee80211_supported_band *sband; |
| 516 | unsigned long basic = vif->bss_conf.basic_rates; |
| 517 | int lowest_present_ofdm = 100; |
| 518 | int lowest_present_cck = 100; |
| 519 | u8 cck = 0; |
| 520 | u8 ofdm = 0; |
| 521 | int i; |
| 522 | |
| 523 | sband = mvm->hw->wiphy->bands[band]; |
| 524 | |
| 525 | for_each_set_bit(i, &basic, BITS_PER_LONG) { |
| 526 | int hw = sband->bitrates[i].hw_value; |
| 527 | if (hw >= IWL_FIRST_OFDM_RATE) { |
| 528 | ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE); |
| 529 | if (lowest_present_ofdm > hw) |
| 530 | lowest_present_ofdm = hw; |
| 531 | } else { |
| 532 | BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0); |
| 533 | |
| 534 | cck |= BIT(hw); |
| 535 | if (lowest_present_cck > hw) |
| 536 | lowest_present_cck = hw; |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | /* |
| 541 | * Now we've got the basic rates as bitmaps in the ofdm and cck |
| 542 | * variables. This isn't sufficient though, as there might not |
| 543 | * be all the right rates in the bitmap. E.g. if the only basic |
| 544 | * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps |
| 545 | * and 6 Mbps because the 802.11-2007 standard says in 9.6: |
| 546 | * |
| 547 | * [...] a STA responding to a received frame shall transmit |
| 548 | * its Control Response frame [...] at the highest rate in the |
| 549 | * BSSBasicRateSet parameter that is less than or equal to the |
| 550 | * rate of the immediately previous frame in the frame exchange |
| 551 | * sequence ([...]) and that is of the same modulation class |
| 552 | * ([...]) as the received frame. If no rate contained in the |
| 553 | * BSSBasicRateSet parameter meets these conditions, then the |
| 554 | * control frame sent in response to a received frame shall be |
| 555 | * transmitted at the highest mandatory rate of the PHY that is |
| 556 | * less than or equal to the rate of the received frame, and |
| 557 | * that is of the same modulation class as the received frame. |
| 558 | * |
| 559 | * As a consequence, we need to add all mandatory rates that are |
| 560 | * lower than all of the basic rates to these bitmaps. |
| 561 | */ |
| 562 | |
| 563 | if (IWL_RATE_24M_INDEX < lowest_present_ofdm) |
| 564 | ofdm |= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE; |
| 565 | if (IWL_RATE_12M_INDEX < lowest_present_ofdm) |
| 566 | ofdm |= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE; |
| 567 | /* 6M already there or needed so always add */ |
| 568 | ofdm |= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE; |
| 569 | |
| 570 | /* |
| 571 | * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP. |
| 572 | * Note, however: |
| 573 | * - if no CCK rates are basic, it must be ERP since there must |
| 574 | * be some basic rates at all, so they're OFDM => ERP PHY |
| 575 | * (or we're in 5 GHz, and the cck bitmap will never be used) |
| 576 | * - if 11M is a basic rate, it must be ERP as well, so add 5.5M |
| 577 | * - if 5.5M is basic, 1M and 2M are mandatory |
| 578 | * - if 2M is basic, 1M is mandatory |
| 579 | * - if 1M is basic, that's the only valid ACK rate. |
| 580 | * As a consequence, it's not as complicated as it sounds, just add |
| 581 | * any lower rates to the ACK rate bitmap. |
| 582 | */ |
| 583 | if (IWL_RATE_11M_INDEX < lowest_present_cck) |
| 584 | cck |= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE; |
| 585 | if (IWL_RATE_5M_INDEX < lowest_present_cck) |
| 586 | cck |= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE; |
| 587 | if (IWL_RATE_2M_INDEX < lowest_present_cck) |
| 588 | cck |= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE; |
| 589 | /* 1M already there or needed so always add */ |
| 590 | cck |= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE; |
| 591 | |
| 592 | *cck_rates = cck; |
| 593 | *ofdm_rates = ofdm; |
| 594 | } |
| 595 | |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 596 | static void iwl_mvm_mac_ctxt_set_ht_flags(struct iwl_mvm *mvm, |
| 597 | struct ieee80211_vif *vif, |
| 598 | struct iwl_mac_ctx_cmd *cmd) |
| 599 | { |
| 600 | /* for both sta and ap, ht_operation_mode hold the protection_mode */ |
| 601 | u8 protection_mode = vif->bss_conf.ht_operation_mode & |
| 602 | IEEE80211_HT_OP_MODE_PROTECTION; |
| 603 | /* The fw does not distinguish between ht and fat */ |
| 604 | u32 ht_flag = MAC_PROT_FLG_HT_PROT | MAC_PROT_FLG_FAT_PROT; |
| 605 | |
| 606 | IWL_DEBUG_RATE(mvm, "protection mode set to %d\n", protection_mode); |
| 607 | /* |
| 608 | * See section 9.23.3.1 of IEEE 80211-2012. |
| 609 | * Nongreenfield HT STAs Present is not supported. |
| 610 | */ |
| 611 | switch (protection_mode) { |
| 612 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 613 | break; |
| 614 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 615 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 616 | cmd->protection_flags |= cpu_to_le32(ht_flag); |
| 617 | break; |
| 618 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 619 | /* Protect when channel wider than 20MHz */ |
| 620 | if (vif->bss_conf.chandef.width > NL80211_CHAN_WIDTH_20) |
| 621 | cmd->protection_flags |= cpu_to_le32(ht_flag); |
| 622 | break; |
| 623 | default: |
| 624 | IWL_ERR(mvm, "Illegal protection mode %d\n", |
| 625 | protection_mode); |
| 626 | break; |
| 627 | } |
| 628 | } |
| 629 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 630 | static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm *mvm, |
| 631 | struct ieee80211_vif *vif, |
| 632 | struct iwl_mac_ctx_cmd *cmd, |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 633 | const u8 *bssid_override, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 634 | u32 action) |
| 635 | { |
| 636 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 637 | struct ieee80211_chanctx_conf *chanctx; |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 638 | bool ht_enabled = !!(vif->bss_conf.ht_operation_mode & |
| 639 | IEEE80211_HT_OP_MODE_PROTECTION); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 640 | u8 cck_ack_rates, ofdm_ack_rates; |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 641 | const u8 *bssid = bssid_override ?: vif->bss_conf.bssid; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 642 | int i; |
| 643 | |
| 644 | cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 645 | mvmvif->color)); |
| 646 | cmd->action = cpu_to_le32(action); |
| 647 | |
| 648 | switch (vif->type) { |
| 649 | case NL80211_IFTYPE_STATION: |
| 650 | if (vif->p2p) |
| 651 | cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_STA); |
| 652 | else |
| 653 | cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_BSS_STA); |
| 654 | break; |
| 655 | case NL80211_IFTYPE_AP: |
| 656 | cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_GO); |
| 657 | break; |
| 658 | case NL80211_IFTYPE_MONITOR: |
| 659 | cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_LISTENER); |
| 660 | break; |
| 661 | case NL80211_IFTYPE_P2P_DEVICE: |
| 662 | cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_DEVICE); |
| 663 | break; |
| 664 | case NL80211_IFTYPE_ADHOC: |
| 665 | cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_IBSS); |
| 666 | break; |
| 667 | default: |
| 668 | WARN_ON_ONCE(1); |
| 669 | } |
| 670 | |
| 671 | cmd->tsf_id = cpu_to_le32(mvmvif->tsf_id); |
| 672 | |
| 673 | memcpy(cmd->node_addr, vif->addr, ETH_ALEN); |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 674 | |
| 675 | if (bssid) |
| 676 | memcpy(cmd->bssid_addr, bssid, ETH_ALEN); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 677 | else |
| 678 | eth_broadcast_addr(cmd->bssid_addr); |
| 679 | |
| 680 | rcu_read_lock(); |
| 681 | chanctx = rcu_dereference(vif->chanctx_conf); |
| 682 | iwl_mvm_ack_rates(mvm, vif, chanctx ? chanctx->def.chan->band |
| 683 | : IEEE80211_BAND_2GHZ, |
| 684 | &cck_ack_rates, &ofdm_ack_rates); |
| 685 | rcu_read_unlock(); |
| 686 | |
| 687 | cmd->cck_rates = cpu_to_le32((u32)cck_ack_rates); |
| 688 | cmd->ofdm_rates = cpu_to_le32((u32)ofdm_ack_rates); |
| 689 | |
| 690 | cmd->cck_short_preamble = |
| 691 | cpu_to_le32(vif->bss_conf.use_short_preamble ? |
| 692 | MAC_FLG_SHORT_PREAMBLE : 0); |
| 693 | cmd->short_slot = |
| 694 | cpu_to_le32(vif->bss_conf.use_short_slot ? |
| 695 | MAC_FLG_SHORT_SLOT : 0); |
| 696 | |
Emmanuel Grumbach | 3dd9479 | 2013-12-19 16:50:49 +0200 | [diff] [blame] | 697 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
| 698 | u8 txf = iwl_mvm_ac_to_tx_fifo[i]; |
| 699 | |
| 700 | cmd->ac[txf].cw_min = |
| 701 | cpu_to_le16(mvmvif->queue_params[i].cw_min); |
| 702 | cmd->ac[txf].cw_max = |
| 703 | cpu_to_le16(mvmvif->queue_params[i].cw_max); |
| 704 | cmd->ac[txf].edca_txop = |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 705 | cpu_to_le16(mvmvif->queue_params[i].txop * 32); |
Emmanuel Grumbach | 3dd9479 | 2013-12-19 16:50:49 +0200 | [diff] [blame] | 706 | cmd->ac[txf].aifsn = mvmvif->queue_params[i].aifs; |
| 707 | cmd->ac[txf].fifos_mask = BIT(txf); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 708 | } |
| 709 | |
Emmanuel Grumbach | 86a91ec | 2013-05-26 20:47:53 +0300 | [diff] [blame] | 710 | /* in AP mode, the MCAST FIFO takes the EDCA params from VO */ |
| 711 | if (vif->type == NL80211_IFTYPE_AP) |
Emmanuel Grumbach | 3dd9479 | 2013-12-19 16:50:49 +0200 | [diff] [blame] | 712 | cmd->ac[IWL_MVM_TX_FIFO_VO].fifos_mask |= |
| 713 | BIT(IWL_MVM_TX_FIFO_MCAST); |
Emmanuel Grumbach | 86a91ec | 2013-05-26 20:47:53 +0300 | [diff] [blame] | 714 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 715 | if (vif->bss_conf.qos) |
| 716 | cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA); |
| 717 | |
Emmanuel Grumbach | dc271ee | 2014-07-03 20:46:35 +0300 | [diff] [blame] | 718 | if (vif->bss_conf.use_cts_prot) |
Dor Shaish | cc7ee2b | 2013-02-18 13:51:36 +0200 | [diff] [blame] | 719 | cmd->protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT); |
Emmanuel Grumbach | dc271ee | 2014-07-03 20:46:35 +0300 | [diff] [blame] | 720 | |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 721 | IWL_DEBUG_RATE(mvm, "use_cts_prot %d, ht_operation_mode %d\n", |
| 722 | vif->bss_conf.use_cts_prot, |
| 723 | vif->bss_conf.ht_operation_mode); |
| 724 | if (vif->bss_conf.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 725 | cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_TGN); |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 726 | if (ht_enabled) |
| 727 | iwl_mvm_mac_ctxt_set_ht_flags(mvm, vif, cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 728 | |
| 729 | cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP); |
| 730 | } |
| 731 | |
| 732 | static int iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm *mvm, |
| 733 | struct iwl_mac_ctx_cmd *cmd) |
| 734 | { |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 735 | int ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 736 | sizeof(*cmd), cmd); |
| 737 | if (ret) |
| 738 | IWL_ERR(mvm, "Failed to send MAC context (action:%d): %d\n", |
| 739 | le32_to_cpu(cmd->action), ret); |
| 740 | return ret; |
| 741 | } |
| 742 | |
Luciano Coelho | cf52023 | 2014-05-13 16:52:54 +0300 | [diff] [blame] | 743 | static int iwl_mvm_mac_ctxt_cmd_sta(struct iwl_mvm *mvm, |
| 744 | struct ieee80211_vif *vif, |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 745 | u32 action, bool force_assoc_off, |
| 746 | const u8 *bssid_override) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 747 | { |
Luciano Coelho | cf52023 | 2014-05-13 16:52:54 +0300 | [diff] [blame] | 748 | struct iwl_mac_ctx_cmd cmd = {}; |
| 749 | struct iwl_mac_data_sta *ctxt_sta; |
| 750 | |
| 751 | WARN_ON(vif->type != NL80211_IFTYPE_STATION); |
| 752 | |
| 753 | /* Fill the common data for all mac context types */ |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 754 | iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, bssid_override, action); |
Luciano Coelho | cf52023 | 2014-05-13 16:52:54 +0300 | [diff] [blame] | 755 | |
| 756 | if (vif->p2p) { |
| 757 | struct ieee80211_p2p_noa_attr *noa = |
| 758 | &vif->bss_conf.p2p_noa_attr; |
| 759 | |
| 760 | cmd.p2p_sta.ctwin = cpu_to_le32(noa->oppps_ctwindow & |
| 761 | IEEE80211_P2P_OPPPS_CTWINDOW_MASK); |
| 762 | ctxt_sta = &cmd.p2p_sta.sta; |
| 763 | } else { |
Luciano Coelho | cf52023 | 2014-05-13 16:52:54 +0300 | [diff] [blame] | 764 | ctxt_sta = &cmd.sta; |
| 765 | } |
| 766 | |
Johannes Berg | 210a544 | 2013-01-24 23:48:23 +0100 | [diff] [blame] | 767 | /* We need the dtim_period to set the MAC as associated */ |
Alexander Bondar | ba28392 | 2013-05-02 16:34:48 +0300 | [diff] [blame] | 768 | if (vif->bss_conf.assoc && vif->bss_conf.dtim_period && |
| 769 | !force_assoc_off) { |
Johannes Berg | d2931bb | 2013-02-05 18:10:04 +0100 | [diff] [blame] | 770 | u32 dtim_offs; |
| 771 | |
| 772 | /* |
| 773 | * The DTIM count counts down, so when it is N that means N |
| 774 | * more beacon intervals happen until the DTIM TBTT. Therefore |
| 775 | * add this to the current time. If that ends up being in the |
| 776 | * future, the firmware will handle it. |
| 777 | * |
| 778 | * Also note that the system_timestamp (which we get here as |
| 779 | * "sync_device_ts") and TSF timestamp aren't at exactly the |
| 780 | * same offset in the frame -- the TSF is at the first symbol |
| 781 | * of the TSF, the system timestamp is at signal acquisition |
| 782 | * time. This means there's an offset between them of at most |
| 783 | * a few hundred microseconds (24 * 8 bits + PLCP time gives |
| 784 | * 384us in the longest case), this is currently not relevant |
| 785 | * as the firmware wakes up around 2ms before the TBTT. |
| 786 | */ |
| 787 | dtim_offs = vif->bss_conf.sync_dtim_count * |
| 788 | vif->bss_conf.beacon_int; |
| 789 | /* convert TU to usecs */ |
| 790 | dtim_offs *= 1024; |
| 791 | |
| 792 | ctxt_sta->dtim_tsf = |
| 793 | cpu_to_le64(vif->bss_conf.sync_tsf + dtim_offs); |
| 794 | ctxt_sta->dtim_time = |
| 795 | cpu_to_le32(vif->bss_conf.sync_device_ts + dtim_offs); |
| 796 | |
| 797 | IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n", |
| 798 | le64_to_cpu(ctxt_sta->dtim_tsf), |
| 799 | le32_to_cpu(ctxt_sta->dtim_time), |
| 800 | dtim_offs); |
| 801 | |
Johannes Berg | 210a544 | 2013-01-24 23:48:23 +0100 | [diff] [blame] | 802 | ctxt_sta->is_assoc = cpu_to_le32(1); |
Johannes Berg | d2931bb | 2013-02-05 18:10:04 +0100 | [diff] [blame] | 803 | } else { |
Johannes Berg | 210a544 | 2013-01-24 23:48:23 +0100 | [diff] [blame] | 804 | ctxt_sta->is_assoc = cpu_to_le32(0); |
Luciano Coelho | 7c8b3bc | 2014-07-30 15:04:08 +0300 | [diff] [blame] | 805 | |
| 806 | /* Allow beacons to pass through as long as we are not |
| 807 | * associated, or we do not have dtim period information. |
| 808 | */ |
| 809 | cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON); |
Johannes Berg | d2931bb | 2013-02-05 18:10:04 +0100 | [diff] [blame] | 810 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 811 | |
| 812 | ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int); |
| 813 | ctxt_sta->bi_reciprocal = |
| 814 | cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int)); |
| 815 | ctxt_sta->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int * |
| 816 | vif->bss_conf.dtim_period); |
| 817 | ctxt_sta->dtim_reciprocal = |
| 818 | cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int * |
| 819 | vif->bss_conf.dtim_period)); |
| 820 | |
| 821 | ctxt_sta->listen_interval = cpu_to_le32(mvm->hw->conf.listen_interval); |
| 822 | ctxt_sta->assoc_id = cpu_to_le32(vif->bss_conf.aid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 823 | |
| 824 | return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd); |
| 825 | } |
| 826 | |
| 827 | static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm *mvm, |
| 828 | struct ieee80211_vif *vif, |
| 829 | u32 action) |
| 830 | { |
| 831 | struct iwl_mac_ctx_cmd cmd = {}; |
| 832 | |
| 833 | WARN_ON(vif->type != NL80211_IFTYPE_MONITOR); |
| 834 | |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 835 | iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action); |
Johannes Berg | 5358549 | 2013-03-18 13:04:50 +0100 | [diff] [blame] | 836 | |
| 837 | cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROMISC | |
| 838 | MAC_FILTER_IN_CONTROL_AND_MGMT | |
| 839 | MAC_FILTER_IN_BEACON | |
Johannes Berg | fb8b8ee | 2013-10-21 12:37:53 +0200 | [diff] [blame] | 840 | MAC_FILTER_IN_PROBE_REQUEST | |
| 841 | MAC_FILTER_IN_CRC32); |
| 842 | mvm->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS; |
Johannes Berg | 5358549 | 2013-03-18 13:04:50 +0100 | [diff] [blame] | 843 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 844 | return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd); |
| 845 | } |
| 846 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 847 | static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm *mvm, |
| 848 | struct ieee80211_vif *vif, |
| 849 | u32 action) |
| 850 | { |
| 851 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 852 | struct iwl_mac_ctx_cmd cmd = {}; |
| 853 | |
| 854 | WARN_ON(vif->type != NL80211_IFTYPE_ADHOC); |
| 855 | |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 856 | iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action); |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 857 | |
| 858 | cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_BEACON | |
| 859 | MAC_FILTER_IN_PROBE_REQUEST); |
| 860 | |
| 861 | /* cmd.ibss.beacon_time/cmd.ibss.beacon_tsf are curently ignored */ |
| 862 | cmd.ibss.bi = cpu_to_le32(vif->bss_conf.beacon_int); |
| 863 | cmd.ibss.bi_reciprocal = |
| 864 | cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int)); |
| 865 | |
| 866 | /* TODO: Assumes that the beacon id == mac context id */ |
| 867 | cmd.ibss.beacon_template = cpu_to_le32(mvmvif->id); |
| 868 | |
| 869 | return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd); |
| 870 | } |
| 871 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 872 | struct iwl_mvm_go_iterator_data { |
| 873 | bool go_active; |
| 874 | }; |
| 875 | |
| 876 | static void iwl_mvm_go_iterator(void *_data, u8 *mac, struct ieee80211_vif *vif) |
| 877 | { |
| 878 | struct iwl_mvm_go_iterator_data *data = _data; |
| 879 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 880 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 881 | if (vif->type == NL80211_IFTYPE_AP && vif->p2p && |
| 882 | mvmvif->ap_ibss_active) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 883 | data->go_active = true; |
| 884 | } |
| 885 | |
| 886 | static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm *mvm, |
| 887 | struct ieee80211_vif *vif, |
| 888 | u32 action) |
| 889 | { |
| 890 | struct iwl_mac_ctx_cmd cmd = {}; |
| 891 | struct iwl_mvm_go_iterator_data data = {}; |
| 892 | |
| 893 | WARN_ON(vif->type != NL80211_IFTYPE_P2P_DEVICE); |
| 894 | |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 895 | iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 896 | |
| 897 | cmd.protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT); |
Ilan Peer | 1dcd15e | 2013-02-14 14:25:24 +0200 | [diff] [blame] | 898 | |
| 899 | /* Override the filter flags to accept only probe requests */ |
| 900 | cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 901 | |
| 902 | /* |
| 903 | * This flag should be set to true when the P2P Device is |
| 904 | * discoverable and there is at least another active P2P GO. Settings |
| 905 | * this flag will allow the P2P Device to be discoverable on other |
| 906 | * channels in addition to its listen channel. |
| 907 | * Note that this flag should not be set in other cases as it opens the |
| 908 | * Rx filters on all MAC and increases the number of interrupts. |
| 909 | */ |
| 910 | ieee80211_iterate_active_interfaces_atomic( |
| 911 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 912 | iwl_mvm_go_iterator, &data); |
| 913 | |
| 914 | cmd.p2p_dev.is_disc_extended = cpu_to_le32(data.go_active ? 1 : 0); |
| 915 | return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd); |
| 916 | } |
| 917 | |
| 918 | static void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm, |
| 919 | struct iwl_mac_beacon_cmd *beacon_cmd, |
| 920 | u8 *beacon, u32 frame_size) |
| 921 | { |
| 922 | u32 tim_idx; |
| 923 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon; |
| 924 | |
| 925 | /* The index is relative to frame start but we start looking at the |
| 926 | * variable-length part of the beacon. */ |
| 927 | tim_idx = mgmt->u.beacon.variable - beacon; |
| 928 | |
| 929 | /* Parse variable-length elements of beacon to find WLAN_EID_TIM */ |
| 930 | while ((tim_idx < (frame_size - 2)) && |
| 931 | (beacon[tim_idx] != WLAN_EID_TIM)) |
| 932 | tim_idx += beacon[tim_idx+1] + 2; |
| 933 | |
| 934 | /* If TIM field was found, set variables */ |
| 935 | if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) { |
| 936 | beacon_cmd->tim_idx = cpu_to_le32(tim_idx); |
| 937 | beacon_cmd->tim_size = cpu_to_le32((u32)beacon[tim_idx+1]); |
| 938 | } else { |
| 939 | IWL_WARN(mvm, "Unable to find TIM Element in beacon\n"); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | static int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm, |
| 944 | struct ieee80211_vif *vif, |
| 945 | struct sk_buff *beacon) |
| 946 | { |
| 947 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 948 | struct iwl_host_cmd cmd = { |
| 949 | .id = BEACON_TEMPLATE_CMD, |
| 950 | .flags = CMD_ASYNC, |
| 951 | }; |
| 952 | struct iwl_mac_beacon_cmd beacon_cmd = {}; |
| 953 | struct ieee80211_tx_info *info; |
| 954 | u32 beacon_skb_len; |
Emmanuel Grumbach | 75f6b9b | 2014-06-02 10:03:33 +0300 | [diff] [blame] | 955 | u32 rate, tx_flags; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 956 | |
| 957 | if (WARN_ON(!beacon)) |
| 958 | return -EINVAL; |
| 959 | |
| 960 | beacon_skb_len = beacon->len; |
| 961 | |
| 962 | /* TODO: for now the beacon template id is set to be the mac context id. |
| 963 | * Might be better to handle it as another resource ... */ |
| 964 | beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id); |
Emmanuel Grumbach | 75f6b9b | 2014-06-02 10:03:33 +0300 | [diff] [blame] | 965 | info = IEEE80211_SKB_CB(beacon); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 966 | |
| 967 | /* Set up TX command fields */ |
| 968 | beacon_cmd.tx.len = cpu_to_le16((u16)beacon_skb_len); |
| 969 | beacon_cmd.tx.sta_id = mvmvif->bcast_sta.sta_id; |
| 970 | beacon_cmd.tx.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); |
Emmanuel Grumbach | 75f6b9b | 2014-06-02 10:03:33 +0300 | [diff] [blame] | 971 | tx_flags = TX_CMD_FLG_SEQ_CTL | TX_CMD_FLG_TSF; |
| 972 | tx_flags |= |
| 973 | iwl_mvm_bt_coex_tx_prio(mvm, (void *)beacon->data, info, 0) << |
| 974 | TX_CMD_FLG_BT_PRIO_POS; |
| 975 | beacon_cmd.tx.tx_flags = cpu_to_le32(tx_flags); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 976 | |
| 977 | mvm->mgmt_last_antenna_idx = |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 978 | iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 979 | mvm->mgmt_last_antenna_idx); |
| 980 | |
| 981 | beacon_cmd.tx.rate_n_flags = |
| 982 | cpu_to_le32(BIT(mvm->mgmt_last_antenna_idx) << |
| 983 | RATE_MCS_ANT_POS); |
| 984 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 985 | if (info->band == IEEE80211_BAND_5GHZ || vif->p2p) { |
| 986 | rate = IWL_FIRST_OFDM_RATE; |
| 987 | } else { |
| 988 | rate = IWL_FIRST_CCK_RATE; |
| 989 | beacon_cmd.tx.rate_n_flags |= cpu_to_le32(RATE_MCS_CCK_MSK); |
| 990 | } |
| 991 | beacon_cmd.tx.rate_n_flags |= |
| 992 | cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(rate)); |
| 993 | |
| 994 | /* Set up TX beacon command fields */ |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 995 | if (vif->type == NL80211_IFTYPE_AP) |
| 996 | iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd, |
| 997 | beacon->data, |
| 998 | beacon_skb_len); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 999 | |
| 1000 | /* Submit command */ |
| 1001 | cmd.len[0] = sizeof(beacon_cmd); |
| 1002 | cmd.data[0] = &beacon_cmd; |
| 1003 | cmd.dataflags[0] = 0; |
| 1004 | cmd.len[1] = beacon_skb_len; |
| 1005 | cmd.data[1] = beacon->data; |
| 1006 | cmd.dataflags[1] = IWL_HCMD_DFL_DUP; |
| 1007 | |
| 1008 | return iwl_mvm_send_cmd(mvm, &cmd); |
| 1009 | } |
| 1010 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1011 | /* The beacon template for the AP/GO/IBSS has changed and needs update */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1012 | int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm, |
| 1013 | struct ieee80211_vif *vif) |
| 1014 | { |
| 1015 | struct sk_buff *beacon; |
| 1016 | int ret; |
| 1017 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1018 | WARN_ON(vif->type != NL80211_IFTYPE_AP && |
| 1019 | vif->type != NL80211_IFTYPE_ADHOC); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1020 | |
Andrei Otcheretianski | fe88766 | 2014-04-10 21:46:16 +0300 | [diff] [blame] | 1021 | beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1022 | if (!beacon) |
| 1023 | return -ENOMEM; |
| 1024 | |
| 1025 | ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon); |
| 1026 | dev_kfree_skb(beacon); |
| 1027 | return ret; |
| 1028 | } |
| 1029 | |
Ilan Peer | 3a3cb92 | 2013-06-13 08:30:12 +0300 | [diff] [blame] | 1030 | struct iwl_mvm_mac_ap_iterator_data { |
| 1031 | struct iwl_mvm *mvm; |
| 1032 | struct ieee80211_vif *vif; |
| 1033 | u32 beacon_device_ts; |
| 1034 | u16 beacon_int; |
| 1035 | }; |
| 1036 | |
| 1037 | /* Find the beacon_device_ts and beacon_int for a managed interface */ |
| 1038 | static void iwl_mvm_mac_ap_iterator(void *_data, u8 *mac, |
| 1039 | struct ieee80211_vif *vif) |
| 1040 | { |
| 1041 | struct iwl_mvm_mac_ap_iterator_data *data = _data; |
| 1042 | |
| 1043 | if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc) |
| 1044 | return; |
| 1045 | |
| 1046 | /* Station client has higher priority over P2P client*/ |
| 1047 | if (vif->p2p && data->beacon_device_ts) |
| 1048 | return; |
| 1049 | |
| 1050 | data->beacon_device_ts = vif->bss_conf.sync_device_ts; |
| 1051 | data->beacon_int = vif->bss_conf.beacon_int; |
| 1052 | } |
| 1053 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1054 | /* |
| 1055 | * Fill the specific data for mac context of type AP of P2P GO |
| 1056 | */ |
| 1057 | static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm *mvm, |
| 1058 | struct ieee80211_vif *vif, |
Johannes Berg | 506a81e | 2013-02-28 14:05:14 +0100 | [diff] [blame] | 1059 | struct iwl_mac_data_ap *ctxt_ap, |
| 1060 | bool add) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1061 | { |
| 1062 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Ilan Peer | 3a3cb92 | 2013-06-13 08:30:12 +0300 | [diff] [blame] | 1063 | struct iwl_mvm_mac_ap_iterator_data data = { |
| 1064 | .mvm = mvm, |
| 1065 | .vif = vif, |
| 1066 | .beacon_device_ts = 0 |
| 1067 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1068 | |
| 1069 | ctxt_ap->bi = cpu_to_le32(vif->bss_conf.beacon_int); |
| 1070 | ctxt_ap->bi_reciprocal = |
| 1071 | cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int)); |
| 1072 | ctxt_ap->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int * |
| 1073 | vif->bss_conf.dtim_period); |
| 1074 | ctxt_ap->dtim_reciprocal = |
| 1075 | cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int * |
| 1076 | vif->bss_conf.dtim_period)); |
| 1077 | |
| 1078 | ctxt_ap->mcast_qid = cpu_to_le32(vif->cab_queue); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1079 | |
Johannes Berg | 506a81e | 2013-02-28 14:05:14 +0100 | [diff] [blame] | 1080 | /* |
Ilan Peer | 3a3cb92 | 2013-06-13 08:30:12 +0300 | [diff] [blame] | 1081 | * Only set the beacon time when the MAC is being added, when we |
Johannes Berg | 506a81e | 2013-02-28 14:05:14 +0100 | [diff] [blame] | 1082 | * just modify the MAC then we should keep the time -- the firmware |
| 1083 | * can otherwise have a "jumping" TBTT. |
| 1084 | */ |
Ilan Peer | 3a3cb92 | 2013-06-13 08:30:12 +0300 | [diff] [blame] | 1085 | if (add) { |
| 1086 | /* |
| 1087 | * If there is a station/P2P client interface which is |
| 1088 | * associated, set the AP's TBTT far enough from the station's |
| 1089 | * TBTT. Otherwise, set it to the current system time |
| 1090 | */ |
| 1091 | ieee80211_iterate_active_interfaces_atomic( |
| 1092 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 1093 | iwl_mvm_mac_ap_iterator, &data); |
| 1094 | |
| 1095 | if (data.beacon_device_ts) { |
Ilan Peer | 9f8f8ca | 2013-12-24 17:17:05 +0200 | [diff] [blame] | 1096 | u32 rand = (prandom_u32() % (64 - 36)) + 36; |
Ilan Peer | 3a3cb92 | 2013-06-13 08:30:12 +0300 | [diff] [blame] | 1097 | mvmvif->ap_beacon_time = data.beacon_device_ts + |
| 1098 | ieee80211_tu_to_usec(data.beacon_int * rand / |
| 1099 | 100); |
| 1100 | } else { |
| 1101 | mvmvif->ap_beacon_time = |
| 1102 | iwl_read_prph(mvm->trans, |
| 1103 | DEVICE_SYSTEM_TIME_REG); |
| 1104 | } |
| 1105 | } |
Johannes Berg | 506a81e | 2013-02-28 14:05:14 +0100 | [diff] [blame] | 1106 | |
| 1107 | ctxt_ap->beacon_time = cpu_to_le32(mvmvif->ap_beacon_time); |
Johannes Berg | 506a81e | 2013-02-28 14:05:14 +0100 | [diff] [blame] | 1108 | ctxt_ap->beacon_tsf = 0; /* unused */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1109 | |
| 1110 | /* TODO: Assume that the beacon id == mac context id */ |
| 1111 | ctxt_ap->beacon_template = cpu_to_le32(mvmvif->id); |
| 1112 | } |
| 1113 | |
| 1114 | static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm *mvm, |
| 1115 | struct ieee80211_vif *vif, |
| 1116 | u32 action) |
| 1117 | { |
| 1118 | struct iwl_mac_ctx_cmd cmd = {}; |
| 1119 | |
| 1120 | WARN_ON(vif->type != NL80211_IFTYPE_AP || vif->p2p); |
| 1121 | |
| 1122 | /* Fill the common data for all mac context types */ |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1123 | iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1124 | |
Eliad Peller | 4601879 | 2014-07-16 13:24:36 +0300 | [diff] [blame] | 1125 | /* |
| 1126 | * pass probe requests and beacons from other APs (needed |
| 1127 | * for ht protection) |
| 1128 | */ |
| 1129 | cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST | |
| 1130 | MAC_FILTER_IN_BEACON); |
Ilan Peer | 1dcd15e | 2013-02-14 14:25:24 +0200 | [diff] [blame] | 1131 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1132 | /* Fill the data specific for ap mode */ |
Johannes Berg | 506a81e | 2013-02-28 14:05:14 +0100 | [diff] [blame] | 1133 | iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.ap, |
| 1134 | action == FW_CTXT_ACTION_ADD); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1135 | |
| 1136 | return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd); |
| 1137 | } |
| 1138 | |
| 1139 | static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm *mvm, |
| 1140 | struct ieee80211_vif *vif, |
| 1141 | u32 action) |
| 1142 | { |
| 1143 | struct iwl_mac_ctx_cmd cmd = {}; |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 1144 | struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1145 | |
| 1146 | WARN_ON(vif->type != NL80211_IFTYPE_AP || !vif->p2p); |
| 1147 | |
| 1148 | /* Fill the common data for all mac context types */ |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1149 | iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1150 | |
Eliad Peller | 4601879 | 2014-07-16 13:24:36 +0300 | [diff] [blame] | 1151 | /* |
| 1152 | * pass probe requests and beacons from other APs (needed |
| 1153 | * for ht protection) |
| 1154 | */ |
| 1155 | cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST | |
| 1156 | MAC_FILTER_IN_BEACON); |
| 1157 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1158 | /* Fill the data specific for GO mode */ |
Johannes Berg | 506a81e | 2013-02-28 14:05:14 +0100 | [diff] [blame] | 1159 | iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.go.ap, |
| 1160 | action == FW_CTXT_ACTION_ADD); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1161 | |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 1162 | cmd.go.ctwin = cpu_to_le32(noa->oppps_ctwindow & |
| 1163 | IEEE80211_P2P_OPPPS_CTWINDOW_MASK); |
| 1164 | cmd.go.opp_ps_enabled = |
| 1165 | cpu_to_le32(!!(noa->oppps_ctwindow & |
| 1166 | IEEE80211_P2P_OPPPS_ENABLE_BIT)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1167 | |
| 1168 | return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd); |
| 1169 | } |
| 1170 | |
| 1171 | static int iwl_mvm_mac_ctx_send(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1172 | u32 action, bool force_assoc_off, |
| 1173 | const u8 *bssid_override) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1174 | { |
| 1175 | switch (vif->type) { |
| 1176 | case NL80211_IFTYPE_STATION: |
Luciano Coelho | cf52023 | 2014-05-13 16:52:54 +0300 | [diff] [blame] | 1177 | return iwl_mvm_mac_ctxt_cmd_sta(mvm, vif, action, |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1178 | force_assoc_off, |
| 1179 | bssid_override); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1180 | break; |
| 1181 | case NL80211_IFTYPE_AP: |
| 1182 | if (!vif->p2p) |
| 1183 | return iwl_mvm_mac_ctxt_cmd_ap(mvm, vif, action); |
| 1184 | else |
| 1185 | return iwl_mvm_mac_ctxt_cmd_go(mvm, vif, action); |
| 1186 | break; |
| 1187 | case NL80211_IFTYPE_MONITOR: |
| 1188 | return iwl_mvm_mac_ctxt_cmd_listener(mvm, vif, action); |
| 1189 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1190 | return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm, vif, action); |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1191 | case NL80211_IFTYPE_ADHOC: |
| 1192 | return iwl_mvm_mac_ctxt_cmd_ibss(mvm, vif, action); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1193 | default: |
| 1194 | break; |
| 1195 | } |
| 1196 | |
| 1197 | return -EOPNOTSUPP; |
| 1198 | } |
| 1199 | |
| 1200 | int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1201 | { |
| 1202 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1203 | int ret; |
| 1204 | |
| 1205 | if (WARN_ONCE(mvmvif->uploaded, "Adding active MAC %pM/%d\n", |
| 1206 | vif->addr, ieee80211_vif_type_p2p(vif))) |
| 1207 | return -EIO; |
| 1208 | |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 1209 | ret = iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_ADD, |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1210 | true, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1211 | if (ret) |
| 1212 | return ret; |
| 1213 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1214 | /* will only do anything at resume from D3 time */ |
| 1215 | iwl_mvm_set_last_nonqos_seq(mvm, vif); |
| 1216 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1217 | mvmvif->uploaded = true; |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 1221 | int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1222 | bool force_assoc_off, const u8 *bssid_override) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1223 | { |
| 1224 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1225 | |
| 1226 | if (WARN_ONCE(!mvmvif->uploaded, "Changing inactive MAC %pM/%d\n", |
| 1227 | vif->addr, ieee80211_vif_type_p2p(vif))) |
| 1228 | return -EIO; |
| 1229 | |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 1230 | return iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_MODIFY, |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1231 | force_assoc_off, bssid_override); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1235 | { |
| 1236 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1237 | struct iwl_mac_ctx_cmd cmd; |
| 1238 | int ret; |
| 1239 | |
| 1240 | if (WARN_ONCE(!mvmvif->uploaded, "Removing inactive MAC %pM/%d\n", |
| 1241 | vif->addr, ieee80211_vif_type_p2p(vif))) |
| 1242 | return -EIO; |
| 1243 | |
| 1244 | memset(&cmd, 0, sizeof(cmd)); |
| 1245 | |
| 1246 | cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 1247 | mvmvif->color)); |
| 1248 | cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE); |
| 1249 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1250 | ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1251 | sizeof(cmd), &cmd); |
| 1252 | if (ret) { |
| 1253 | IWL_ERR(mvm, "Failed to remove MAC context: %d\n", ret); |
| 1254 | return ret; |
| 1255 | } |
| 1256 | |
| 1257 | mvmvif->uploaded = false; |
Johannes Berg | fb8b8ee | 2013-10-21 12:37:53 +0200 | [diff] [blame] | 1258 | |
| 1259 | if (vif->type == NL80211_IFTYPE_MONITOR) |
| 1260 | mvm->hw->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS; |
| 1261 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1262 | return 0; |
| 1263 | } |
Ilan Peer | 571765c | 2013-03-05 15:26:03 +0200 | [diff] [blame] | 1264 | |
Andrei Otcheretianski | 7f0a7c6 | 2014-05-04 11:48:12 +0300 | [diff] [blame] | 1265 | static void iwl_mvm_csa_count_down(struct iwl_mvm *mvm, |
| 1266 | struct ieee80211_vif *csa_vif, u32 gp2) |
| 1267 | { |
| 1268 | struct iwl_mvm_vif *mvmvif = |
| 1269 | iwl_mvm_vif_from_mac80211(csa_vif); |
| 1270 | |
| 1271 | if (!ieee80211_csa_is_complete(csa_vif)) { |
| 1272 | int c = ieee80211_csa_update_counter(csa_vif); |
| 1273 | |
| 1274 | iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif); |
| 1275 | if (csa_vif->p2p && |
| 1276 | !iwl_mvm_te_scheduled(&mvmvif->time_event_data) && gp2) { |
| 1277 | u32 rel_time = (c + 1) * |
| 1278 | csa_vif->bss_conf.beacon_int - |
Luciano Coelho | f991e17 | 2014-08-26 16:14:10 +0300 | [diff] [blame] | 1279 | IWL_MVM_CHANNEL_SWITCH_TIME_GO; |
Andrei Otcheretianski | 7f0a7c6 | 2014-05-04 11:48:12 +0300 | [diff] [blame] | 1280 | u32 apply_time = gp2 + rel_time * 1024; |
| 1281 | |
Luciano Coelho | f991e17 | 2014-08-26 16:14:10 +0300 | [diff] [blame] | 1282 | iwl_mvm_schedule_csa_period(mvm, csa_vif, |
| 1283 | IWL_MVM_CHANNEL_SWITCH_TIME_GO - |
| 1284 | IWL_MVM_CHANNEL_SWITCH_MARGIN, |
| 1285 | apply_time); |
Andrei Otcheretianski | 7f0a7c6 | 2014-05-04 11:48:12 +0300 | [diff] [blame] | 1286 | } |
| 1287 | } else if (!iwl_mvm_te_scheduled(&mvmvif->time_event_data)) { |
| 1288 | /* we don't have CSA NoA scheduled yet, switch now */ |
| 1289 | ieee80211_csa_finish(csa_vif); |
| 1290 | RCU_INIT_POINTER(mvm->csa_vif, NULL); |
| 1291 | } |
| 1292 | } |
| 1293 | |
Ilan Peer | 571765c | 2013-03-05 15:26:03 +0200 | [diff] [blame] | 1294 | int iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm, |
| 1295 | struct iwl_rx_cmd_buffer *rxb, |
| 1296 | struct iwl_device_cmd *cmd) |
| 1297 | { |
| 1298 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
David Spinadel | 1c87bba | 2014-02-27 16:41:52 +0200 | [diff] [blame] | 1299 | struct iwl_mvm_tx_resp *beacon_notify_hdr; |
Andrei Otcheretianski | 664322f | 2014-06-05 16:40:36 +0300 | [diff] [blame] | 1300 | struct ieee80211_vif *csa_vif; |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 1301 | struct ieee80211_vif *tx_blocked_vif; |
David Spinadel | 1c87bba | 2014-02-27 16:41:52 +0200 | [diff] [blame] | 1302 | u64 tsf; |
Ilan Peer | 571765c | 2013-03-05 15:26:03 +0200 | [diff] [blame] | 1303 | |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 1304 | lockdep_assert_held(&mvm->mutex); |
| 1305 | |
David Spinadel | 1c87bba | 2014-02-27 16:41:52 +0200 | [diff] [blame] | 1306 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_CAPA_EXTENDED_BEACON) { |
| 1307 | struct iwl_extended_beacon_notif *beacon = (void *)pkt->data; |
| 1308 | |
| 1309 | beacon_notify_hdr = &beacon->beacon_notify_hdr; |
| 1310 | tsf = le64_to_cpu(beacon->tsf); |
| 1311 | mvm->ap_last_beacon_gp2 = le32_to_cpu(beacon->gp2); |
| 1312 | } else { |
| 1313 | struct iwl_beacon_notif *beacon = (void *)pkt->data; |
| 1314 | |
| 1315 | beacon_notify_hdr = &beacon->beacon_notify_hdr; |
| 1316 | tsf = le64_to_cpu(beacon->tsf); |
| 1317 | } |
| 1318 | |
| 1319 | IWL_DEBUG_RX(mvm, |
| 1320 | "beacon status %#x retries:%d tsf:0x%16llX gp2:0x%X rate:%d\n", |
| 1321 | le16_to_cpu(beacon_notify_hdr->status.status) & |
| 1322 | TX_STATUS_MSK, |
| 1323 | beacon_notify_hdr->failure_frame, tsf, |
| 1324 | mvm->ap_last_beacon_gp2, |
| 1325 | le32_to_cpu(beacon_notify_hdr->initial_rate)); |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 1326 | |
Andrei Otcheretianski | 664322f | 2014-06-05 16:40:36 +0300 | [diff] [blame] | 1327 | csa_vif = rcu_dereference_protected(mvm->csa_vif, |
| 1328 | lockdep_is_held(&mvm->mutex)); |
Andrei Otcheretianski | 7f0a7c6 | 2014-05-04 11:48:12 +0300 | [diff] [blame] | 1329 | if (unlikely(csa_vif && csa_vif->csa_active)) |
| 1330 | iwl_mvm_csa_count_down(mvm, csa_vif, mvm->ap_last_beacon_gp2); |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 1331 | |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 1332 | tx_blocked_vif = rcu_dereference_protected(mvm->csa_tx_blocked_vif, |
| 1333 | lockdep_is_held(&mvm->mutex)); |
| 1334 | if (unlikely(tx_blocked_vif)) { |
| 1335 | struct iwl_mvm_vif *mvmvif = |
| 1336 | iwl_mvm_vif_from_mac80211(tx_blocked_vif); |
| 1337 | |
| 1338 | /* |
| 1339 | * The channel switch is started and we have blocked the |
| 1340 | * stations. If this is the first beacon (the timeout wasn't |
| 1341 | * set), set the unblock timeout, otherwise countdown |
| 1342 | */ |
| 1343 | if (!mvm->csa_tx_block_bcn_timeout) |
| 1344 | mvm->csa_tx_block_bcn_timeout = |
| 1345 | IWL_MVM_CS_UNBLOCK_TX_TIMEOUT; |
| 1346 | else |
| 1347 | mvm->csa_tx_block_bcn_timeout--; |
| 1348 | |
| 1349 | /* Check if the timeout is expired, and unblock tx */ |
| 1350 | if (mvm->csa_tx_block_bcn_timeout == 0) { |
| 1351 | iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false); |
| 1352 | RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); |
| 1353 | } |
| 1354 | } |
| 1355 | |
Ilan Peer | 571765c | 2013-03-05 15:26:03 +0200 | [diff] [blame] | 1356 | return 0; |
| 1357 | } |
Hila Gonen | d64048e | 2013-03-13 18:00:03 +0200 | [diff] [blame] | 1358 | |
| 1359 | static void iwl_mvm_beacon_loss_iterator(void *_data, u8 *mac, |
| 1360 | struct ieee80211_vif *vif) |
| 1361 | { |
Ilan Peer | 12d423e | 2013-12-24 22:08:14 +0200 | [diff] [blame] | 1362 | struct iwl_missed_beacons_notif *missed_beacons = _data; |
Hila Gonen | d64048e | 2013-03-13 18:00:03 +0200 | [diff] [blame] | 1363 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1364 | |
Ilan Peer | 12d423e | 2013-12-24 22:08:14 +0200 | [diff] [blame] | 1365 | if (mvmvif->id != (u16)le32_to_cpu(missed_beacons->mac_id)) |
| 1366 | return; |
| 1367 | |
| 1368 | /* |
| 1369 | * TODO: the threshold should be adjusted based on latency conditions, |
| 1370 | * and/or in case of a CS flow on one of the other AP vifs. |
| 1371 | */ |
| 1372 | if (le32_to_cpu(missed_beacons->consec_missed_beacons_since_last_rx) > |
| 1373 | IWL_MVM_MISSED_BEACONS_THRESHOLD) |
Hila Gonen | d64048e | 2013-03-13 18:00:03 +0200 | [diff] [blame] | 1374 | ieee80211_beacon_loss(vif); |
| 1375 | } |
| 1376 | |
| 1377 | int iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm, |
| 1378 | struct iwl_rx_cmd_buffer *rxb, |
| 1379 | struct iwl_device_cmd *cmd) |
| 1380 | { |
| 1381 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Ilan Peer | 12d423e | 2013-12-24 22:08:14 +0200 | [diff] [blame] | 1382 | struct iwl_missed_beacons_notif *mb = (void *)pkt->data; |
| 1383 | |
| 1384 | IWL_DEBUG_INFO(mvm, |
| 1385 | "missed bcn mac_id=%u, consecutive=%u (%u, %u, %u)\n", |
| 1386 | le32_to_cpu(mb->mac_id), |
| 1387 | le32_to_cpu(mb->consec_missed_beacons), |
| 1388 | le32_to_cpu(mb->consec_missed_beacons_since_last_rx), |
| 1389 | le32_to_cpu(mb->num_recvd_beacons), |
| 1390 | le32_to_cpu(mb->num_expected_beacons)); |
Hila Gonen | d64048e | 2013-03-13 18:00:03 +0200 | [diff] [blame] | 1391 | |
| 1392 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, |
| 1393 | IEEE80211_IFACE_ITER_NORMAL, |
| 1394 | iwl_mvm_beacon_loss_iterator, |
Ilan Peer | 12d423e | 2013-12-24 22:08:14 +0200 | [diff] [blame] | 1395 | mb); |
Hila Gonen | d64048e | 2013-03-13 18:00:03 +0200 | [diff] [blame] | 1396 | return 0; |
| 1397 | } |