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