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