blob: 0da8787aa25bdcbdb6e1db40506977f6774e606d [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020035 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65#include <linux/kernel.h>
66#include <linux/slab.h>
67#include <linux/skbuff.h>
68#include <linux/netdevice.h>
69#include <linux/etherdevice.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010070#include <linux/ip.h>
Eliad Peller2ee8f022014-01-13 19:07:09 +020071#include <linux/if_arp.h>
Johannes Bergaadede62014-10-09 17:01:36 +020072#include <linux/devcoredump.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010073#include <net/mac80211.h>
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +020074#include <net/ieee80211_radiotap.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010075#include <net/tcp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010076
77#include "iwl-op-mode.h"
78#include "iwl-io.h"
79#include "mvm.h"
80#include "sta.h"
81#include "time-event.h"
82#include "iwl-eeprom-parse.h"
83#include "fw-api-scan.h"
84#include "iwl-phy-db.h"
David Spinadel507cadf2013-07-31 18:07:21 +030085#include "testmode.h"
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +030086#include "iwl-fw-error-dump.h"
87#include "iwl-prph.h"
Eran Harary363039b2014-12-02 15:19:22 +020088#include "iwl-csr.h"
Arik Nemtsov88931cc2014-03-05 12:26:15 +020089#include "iwl-nvm-parse.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010090
91static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
92 {
93 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030094 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010095 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020096 {
97 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030098 .types = BIT(NL80211_IFTYPE_AP) |
99 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200100 BIT(NL80211_IFTYPE_P2P_GO),
101 },
102 {
103 .max = 1,
104 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
105 },
Johannes Berg8ca151b2013-01-24 14:25:36 +0100106};
107
108static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
109 {
Emmanuel Grumbach2624a5c2014-12-16 13:02:03 +0200110 .num_different_channels = 2,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100111 .max_interfaces = 3,
112 .limits = iwl_mvm_limits,
113 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
114 },
115};
116
Johannes Bergf0c26462013-01-22 20:41:58 +0100117#ifdef CONFIG_PM_SLEEP
118static const struct nl80211_wowlan_tcp_data_token_feature
119iwl_mvm_wowlan_tcp_token_feature = {
120 .min_len = 0,
121 .max_len = 255,
122 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
123};
124
125static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
126 .tok = &iwl_mvm_wowlan_tcp_token_feature,
127 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
128 sizeof(struct ethhdr) -
129 sizeof(struct iphdr) -
130 sizeof(struct tcphdr),
131 .data_interval_max = 65535, /* __le16 in API */
132 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
133 sizeof(struct ethhdr) -
134 sizeof(struct iphdr) -
135 sizeof(struct tcphdr),
136 .seq = true,
137};
138#endif
139
Eliad Peller77736922014-01-14 12:35:49 +0200140#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
Eliad Peller2ee8f022014-01-13 19:07:09 +0200141/*
142 * Use the reserved field to indicate magic values.
143 * these values will only be used internally by the driver,
144 * and won't make it to the fw (reserved will be 0).
145 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
146 * be the vif's ip address. in case there is not a single
147 * ip address (0, or more than 1), this attribute will
148 * be skipped.
149 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
150 * the LSB bytes of the vif's mac address
151 */
152enum {
153 BC_FILTER_MAGIC_NONE = 0,
154 BC_FILTER_MAGIC_IP,
155 BC_FILTER_MAGIC_MAC,
156};
157
Eliad Peller77736922014-01-14 12:35:49 +0200158static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
159 {
160 /* arp */
161 .discard = 0,
162 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
163 .attrs = {
164 {
165 /* frame type - arp, hw type - ethernet */
166 .offset_type =
167 BCAST_FILTER_OFFSET_PAYLOAD_START,
168 .offset = sizeof(rfc1042_header),
169 .val = cpu_to_be32(0x08060001),
170 .mask = cpu_to_be32(0xffffffff),
171 },
Eliad Peller2ee8f022014-01-13 19:07:09 +0200172 {
173 /* arp dest ip */
174 .offset_type =
175 BCAST_FILTER_OFFSET_PAYLOAD_START,
176 .offset = sizeof(rfc1042_header) + 2 +
177 sizeof(struct arphdr) +
178 ETH_ALEN + sizeof(__be32) +
179 ETH_ALEN,
180 .mask = cpu_to_be32(0xffffffff),
181 /* mark it as special field */
182 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
183 },
184 },
185 },
186 {
187 /* dhcp offer bcast */
188 .discard = 0,
189 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
190 .attrs = {
191 {
192 /* udp dest port - 68 (bootp client)*/
193 .offset_type = BCAST_FILTER_OFFSET_IP_END,
194 .offset = offsetof(struct udphdr, dest),
195 .val = cpu_to_be32(0x00440000),
196 .mask = cpu_to_be32(0xffff0000),
197 },
198 {
199 /* dhcp - lsb bytes of client hw address */
200 .offset_type = BCAST_FILTER_OFFSET_IP_END,
201 .offset = 38,
202 .mask = cpu_to_be32(0xffffffff),
203 /* mark it as special field */
204 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
205 },
Eliad Peller77736922014-01-14 12:35:49 +0200206 },
207 },
208 /* last filter must be empty */
209 {},
210};
211#endif
212
Eliad Peller7498cf42014-01-16 17:10:44 +0200213void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
214{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200215 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200216 return;
217
218 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300219 spin_lock_bh(&mvm->refs_lock);
220 mvm->refs[ref_type]++;
221 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200222 iwl_trans_ref(mvm->trans);
223}
224
225void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
226{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200227 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200228 return;
229
230 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300231 spin_lock_bh(&mvm->refs_lock);
232 WARN_ON(!mvm->refs[ref_type]--);
233 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200234 iwl_trans_unref(mvm->trans);
235}
236
Eliad Peller576eeee2014-07-01 18:38:38 +0300237static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
238 enum iwl_mvm_ref_type except_ref)
Eliad Peller7498cf42014-01-16 17:10:44 +0200239{
Eliad Peller576eeee2014-07-01 18:38:38 +0300240 int i, j;
Eliad Peller7498cf42014-01-16 17:10:44 +0200241
Eliad Peller7bb426e2014-02-24 12:54:37 +0200242 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200243 return;
244
Eliad Peller576eeee2014-07-01 18:38:38 +0300245 spin_lock_bh(&mvm->refs_lock);
246 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
247 if (except_ref == i || !mvm->refs[i])
Eliad Peller7498cf42014-01-16 17:10:44 +0200248 continue;
249
Eliad Peller576eeee2014-07-01 18:38:38 +0300250 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
251 i, mvm->refs[i]);
252 for (j = 0; j < mvm->refs[i]; j++)
253 iwl_trans_unref(mvm->trans);
254 mvm->refs[i] = 0;
Eliad Peller7498cf42014-01-16 17:10:44 +0200255 }
Eliad Peller576eeee2014-07-01 18:38:38 +0300256 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200257}
258
Eliad Pellerf4cf8682014-11-04 16:57:06 +0200259bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
260{
261 int i;
262 bool taken = false;
263
264 if (!iwl_mvm_is_d0i3_supported(mvm))
265 return true;
266
267 spin_lock_bh(&mvm->refs_lock);
268 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
269 if (mvm->refs[i]) {
270 taken = true;
271 break;
272 }
273 }
274 spin_unlock_bh(&mvm->refs_lock);
275
276 return taken;
277}
278
Eliad Peller576eeee2014-07-01 18:38:38 +0300279int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
Gregory Greenmand40fc482014-06-25 14:08:50 +0200280{
281 iwl_mvm_ref(mvm, ref_type);
282
283 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
284 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
285 HZ)) {
286 WARN_ON_ONCE(1);
287 iwl_mvm_unref(mvm, ref_type);
288 return -EIO;
289 }
290
291 return 0;
292}
293
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200294static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
295{
296 int i;
297
298 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
299 for (i = 0; i < NUM_PHY_CTX; i++) {
300 mvm->phy_ctxts[i].id = i;
301 mvm->phy_ctxts[i].ref = 0;
302 }
303}
304
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200305struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
306 const char *alpha2)
307{
308 struct ieee80211_regdomain *regd = NULL;
309 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
310 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
311 struct iwl_mcc_update_resp *resp;
312
313 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
314
315 mutex_lock(&mvm->mutex);
316
317 /* change "99" to "ZZ" for the FW */
318 if (alpha2[0] == '9' && alpha2[1] == '9')
319 alpha2 = "ZZ";
320
321 resp = iwl_mvm_update_mcc(mvm, alpha2);
322 if (IS_ERR_OR_NULL(resp)) {
323 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
324 PTR_RET(resp));
325 goto out_unlock;
326 }
327
328 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev,
329 __le32_to_cpu(resp->n_channels),
330 resp->channels,
331 __le16_to_cpu(resp->mcc));
332 kfree(resp);
333 if (IS_ERR_OR_NULL(regd)) {
334 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
335 PTR_RET(resp));
336 goto out_unlock;
337 }
338
339 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x)\n",
340 regd->alpha2, regd->alpha2[0], regd->alpha2[1]);
341 mvm->lar_regdom_set = true;
342
343out_unlock:
344 mutex_unlock(&mvm->mutex);
345 return regd;
346}
347
Johannes Berg8ca151b2013-01-24 14:25:36 +0100348int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
349{
350 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200351 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100352
353 /* Tell mac80211 our characteristics */
354 hw->flags = IEEE80211_HW_SIGNAL_DBM |
355 IEEE80211_HW_SPECTRUM_MGMT |
356 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
357 IEEE80211_HW_QUEUE_CONTROL |
358 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100359 IEEE80211_HW_SUPPORTS_PS |
360 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100361 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200362 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300363 IEEE80211_HW_CONNECTION_MONITOR |
Ido Yarivb71d9c82014-07-23 09:31:14 -0400364 IEEE80211_HW_CHANCTX_STA_CSA |
365 IEEE80211_HW_SUPPORTS_CLONED_SKBS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100366
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200367 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200368 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200369 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
370 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
Eyal Shapira339b3082014-11-18 16:43:55 +0200371 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
372 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100373 hw->rate_control_algorithm = "iwl-mvm-rs";
Johannes Berg848955c2014-11-11 12:48:42 +0100374 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
375 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100376
377 /*
378 * Enable 11w if advertised by firmware and software crypto
379 * is not enabled (as the firmware will interpret some mgmt
380 * packets, so enabling it with software crypto isn't safe)
381 */
382 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
383 !iwlwifi_mod_params.sw_crypto)
384 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
385
Luciano Coelho1f940382015-02-10 13:03:38 +0200386 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
387 hw->wiphy->features |=
388 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
389 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
David Spinadelfb98be52014-05-04 12:51:10 +0300390
Johannes Berg8ca151b2013-01-24 14:25:36 +0100391 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
392 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200393 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100394
395 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200396 BIT(NL80211_IFTYPE_P2P_CLIENT) |
397 BIT(NL80211_IFTYPE_AP) |
398 BIT(NL80211_IFTYPE_P2P_GO) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200399 BIT(NL80211_IFTYPE_P2P_DEVICE) |
400 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200401
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100402 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
403 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
404 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100405
Johannes Berg3e56ead2013-02-15 22:23:18 +0100406 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
407 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
408
Emmanuel Grumbach94bbed72014-11-24 08:53:33 +0200409 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +0200410
Johannes Berg8ca151b2013-01-24 14:25:36 +0100411 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
412 hw->wiphy->n_iface_combinations =
413 ARRAY_SIZE(iwl_mvm_iface_combinations);
414
Ilan Peerc451e6d2013-02-20 08:41:54 +0200415 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100416 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
Emmanuel Grumbachf1a68542014-12-16 12:31:13 +0200417 /* we can compensate an offset of up to 3 channels = 15 MHz */
418 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100419
420 /* Extract MAC address */
421 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
422 hw->wiphy->addresses = mvm->addresses;
423 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200424
425 /* Extract additional MAC addresses if available */
426 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
427 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
428
429 for (i = 1; i < num_mac; i++) {
430 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100431 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200432 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100433 hw->wiphy->n_addresses++;
434 }
435
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200436 iwl_mvm_reset_phy_ctxts(mvm);
437
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300438 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300439
Johannes Berg8ca151b2013-01-24 14:25:36 +0100440 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
441
442 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
443 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
444 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200445 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100446 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
447 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
448
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200449 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_BEAMFORMER)
450 hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
451 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
452 }
453
Johannes Berg8ca151b2013-01-24 14:25:36 +0100454 hw->wiphy->hw_version = mvm->trans->hw_id;
455
Alexander Bondarade50652013-04-03 16:28:47 +0300456 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100457 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
458 else
459 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
460
Emmanuel Grumbach6efaaf32014-09-01 10:03:21 +0300461 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
462 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
463 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
464 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
465 /* we create the 802.11 header and zero length SSID IE. */
466 hw->wiphy->max_sched_scan_ie_len =
467 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
468 }
David Spinadel35a000b2013-08-28 09:29:43 +0300469
Johannes Berg8ca151b2013-01-24 14:25:36 +0100470 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Johannes Bergab480032014-06-04 10:13:50 +0200471 NL80211_FEATURE_LOW_PRIORITY_SCAN |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300472 NL80211_FEATURE_P2P_GO_OPPPS |
473 NL80211_FEATURE_DYNAMIC_SMPS |
Emmanuel Grumbach9b5452f2014-10-07 10:38:53 +0300474 NL80211_FEATURE_STATIC_SMPS |
475 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100476
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300477 if (mvm->fw->ucode_capa.capa[0] &
478 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
479 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
Assaf Krauss226bcd42014-03-13 08:12:15 +0200480 if (mvm->fw->ucode_capa.capa[0] &
481 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
482 hw->wiphy->features |= NL80211_FEATURE_QUIET;
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300483
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300484 if (mvm->fw->ucode_capa.capa[0] &
485 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
486 hw->wiphy->features |=
487 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
488
489 if (mvm->fw->ucode_capa.capa[0] &
490 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
491 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
492
Johannes Berg8ca151b2013-01-24 14:25:36 +0100493 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
494
Max Stepanove36e5432013-08-27 19:56:13 +0300495 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100496 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300497 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100498 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300499 }
500
Johannes Berg8ca151b2013-01-24 14:25:36 +0100501#ifdef CONFIG_PM_SLEEP
Eliad Pellerd15a7472014-03-27 18:53:12 +0200502 if (iwl_mvm_is_d0i3_supported(mvm) &&
503 device_can_wakeup(mvm->trans->dev)) {
504 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
505 hw->wiphy->wowlan = &mvm->wowlan;
Eliad Peller91742442014-12-09 15:54:46 +0200506 }
507
508 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100509 mvm->trans->ops->d3_suspend &&
510 mvm->trans->ops->d3_resume &&
511 device_can_wakeup(mvm->trans->dev)) {
Eliad Peller91742442014-12-09 15:54:46 +0200512 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
513 WIPHY_WOWLAN_DISCONNECT |
514 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
515 WIPHY_WOWLAN_RFKILL_RELEASE |
516 WIPHY_WOWLAN_NET_DETECT;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100517 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200518 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
519 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
520 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100521
Johannes Berg964dc9e2013-06-03 17:25:34 +0200522 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
523 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
524 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
Luciano Coelhoc55385f2014-10-24 10:39:51 +0300525 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
Johannes Berg964dc9e2013-06-03 17:25:34 +0200526 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
527 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100528 }
529#endif
530
Eliad Peller77736922014-01-14 12:35:49 +0200531#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
532 /* assign default bcast filtering configuration */
533 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
534#endif
535
Johannes Berg8ca151b2013-01-24 14:25:36 +0100536 ret = iwl_mvm_leds_init(mvm);
537 if (ret)
538 return ret;
539
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300540 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) {
541 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
542 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
543 }
544
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300545 if (mvm->fw->ucode_capa.capa[0] &
546 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) {
547 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
548 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
549 }
550
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300551 ret = ieee80211_register_hw(mvm->hw);
552 if (ret)
553 iwl_mvm_leds_exit(mvm);
554
555 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100556}
557
Arik Nemtsovb2492502014-03-13 12:21:50 +0200558static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
559 struct ieee80211_sta *sta,
560 struct sk_buff *skb)
561{
562 struct iwl_mvm_sta *mvmsta;
563 bool defer = false;
564
565 /*
566 * double check the IN_D0I3 flag both before and after
567 * taking the spinlock, in order to prevent taking
568 * the spinlock when not needed.
569 */
570 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
571 return false;
572
573 spin_lock(&mvm->d0i3_tx_lock);
574 /*
575 * testing the flag again ensures the skb dequeue
576 * loop (on d0i3 exit) hasn't run yet.
577 */
578 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
579 goto out;
580
581 mvmsta = iwl_mvm_sta_from_mac80211(sta);
582 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
583 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
584 goto out;
585
586 __skb_queue_tail(&mvm->d0i3_tx, skb);
587 ieee80211_stop_queues(mvm->hw);
588
589 /* trigger wakeup */
590 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
591 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
592
593 defer = true;
594out:
595 spin_unlock(&mvm->d0i3_tx_lock);
596 return defer;
597}
598
Johannes Berg8ca151b2013-01-24 14:25:36 +0100599static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
600 struct ieee80211_tx_control *control,
601 struct sk_buff *skb)
602{
603 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100604 struct ieee80211_sta *sta = control->sta;
605 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
606 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100607
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300608 if (iwl_mvm_is_radio_killed(mvm)) {
609 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100610 goto drop;
611 }
612
Ilan Peer398e8c62013-03-13 15:20:35 +0200613 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Matti Gottlieba6cc5162014-09-29 11:46:04 +0300614 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
615 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100616 goto drop;
617
Johannes Berg3e56ead2013-02-15 22:23:18 +0100618 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
619 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
620 ieee80211_is_mgmt(hdr->frame_control) &&
621 !ieee80211_is_deauth(hdr->frame_control) &&
622 !ieee80211_is_disassoc(hdr->frame_control) &&
623 !ieee80211_is_action(hdr->frame_control)))
624 sta = NULL;
625
626 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200627 if (iwl_mvm_defer_tx(mvm, sta, skb))
628 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100629 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100630 goto drop;
631 return;
632 }
633
634 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
635 goto drop;
636 return;
637 drop:
638 ieee80211_free_txskb(hw, skb);
639}
640
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200641static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
642{
643 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
644 return false;
645 return true;
646}
647
648static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
649{
650 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
651 return false;
652 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
653 return true;
654
655 /* enabled by default */
656 return true;
657}
658
Johannes Berg8ca151b2013-01-24 14:25:36 +0100659static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
660 struct ieee80211_vif *vif,
661 enum ieee80211_ampdu_mlme_action action,
662 struct ieee80211_sta *sta, u16 tid,
663 u16 *ssn, u8 buf_size)
664{
665 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
666 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200667 bool tx_agg_ref = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100668
669 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
670 sta->addr, tid, action);
671
672 if (!(mvm->nvm_data->sku_cap_11n_enable))
673 return -EACCES;
674
Arik Nemtsovb2492502014-03-13 12:21:50 +0200675 /* return from D0i3 before starting a new Tx aggregation */
Eliad Peller9256c202014-04-22 13:33:29 +0300676 switch (action) {
677 case IEEE80211_AMPDU_TX_START:
678 case IEEE80211_AMPDU_TX_STOP_CONT:
679 case IEEE80211_AMPDU_TX_STOP_FLUSH:
680 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
681 case IEEE80211_AMPDU_TX_OPERATIONAL:
Arik Nemtsovb2492502014-03-13 12:21:50 +0200682 /*
Eliad Peller9256c202014-04-22 13:33:29 +0300683 * for tx start, wait synchronously until D0i3 exit to
684 * get the correct sequence number for the tid.
685 * additionally, some other ampdu actions use direct
686 * target access, which is not handled automatically
687 * by the trans layer (unlike commands), so wait for
688 * d0i3 exit in these cases as well.
Arik Nemtsovb2492502014-03-13 12:21:50 +0200689 */
Gregory Greenmand40fc482014-06-25 14:08:50 +0200690 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
691 if (ret)
692 return ret;
693
694 tx_agg_ref = true;
Eliad Peller9256c202014-04-22 13:33:29 +0300695 break;
696 default:
697 break;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200698 }
699
Johannes Berg8ca151b2013-01-24 14:25:36 +0100700 mutex_lock(&mvm->mutex);
701
702 switch (action) {
703 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200704 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100705 ret = -EINVAL;
706 break;
707 }
708 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
709 break;
710 case IEEE80211_AMPDU_RX_STOP:
711 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
712 break;
713 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200714 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200715 ret = -EINVAL;
716 break;
717 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100718 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
719 break;
720 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200721 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
722 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100723 case IEEE80211_AMPDU_TX_STOP_FLUSH:
724 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200725 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100726 break;
727 case IEEE80211_AMPDU_TX_OPERATIONAL:
728 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
729 break;
730 default:
731 WARN_ON_ONCE(1);
732 ret = -EINVAL;
733 break;
734 }
735 mutex_unlock(&mvm->mutex);
736
Arik Nemtsovb2492502014-03-13 12:21:50 +0200737 /*
738 * If the tid is marked as started, we won't use it for offloaded
739 * traffic on the next D0i3 entry. It's safe to unref.
740 */
741 if (tx_agg_ref)
742 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
743
Johannes Berg8ca151b2013-01-24 14:25:36 +0100744 return ret;
745}
746
747static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
748 struct ieee80211_vif *vif)
749{
750 struct iwl_mvm *mvm = data;
751 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
752
753 mvmvif->uploaded = false;
754 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
755
Johannes Berg8ca151b2013-01-24 14:25:36 +0100756 spin_lock_bh(&mvm->time_event_lock);
757 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
758 spin_unlock_bh(&mvm->time_event_lock);
759
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200760 mvmvif->phy_ctxt = NULL;
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300761 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100762}
763
Johannes Bergaadede62014-10-09 17:01:36 +0200764static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
765 const void *data, size_t datalen)
766{
767 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
768 ssize_t bytes_read;
769 ssize_t bytes_read_trans;
770
771 if (offset < dump_ptrs->op_mode_len) {
772 bytes_read = min_t(ssize_t, count,
773 dump_ptrs->op_mode_len - offset);
774 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
775 bytes_read);
776 offset += bytes_read;
777 count -= bytes_read;
778
779 if (count == 0)
780 return bytes_read;
781 } else {
782 bytes_read = 0;
783 }
784
785 if (!dump_ptrs->trans_ptr)
786 return bytes_read;
787
788 offset -= dump_ptrs->op_mode_len;
789 bytes_read_trans = min_t(ssize_t, count,
790 dump_ptrs->trans_ptr->len - offset);
791 memcpy(buffer + bytes_read,
792 (u8 *)dump_ptrs->trans_ptr->data + offset,
793 bytes_read_trans);
794
795 return bytes_read + bytes_read_trans;
796}
797
798static void iwl_mvm_free_coredump(const void *data)
799{
800 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
801
802 vfree(fw_error_dump->op_mode_ptr);
803 vfree(fw_error_dump->trans_ptr);
804 kfree(fw_error_dump);
805}
806
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200807static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
808 struct iwl_fw_error_dump_data **dump_data)
809{
810 struct iwl_fw_error_dump_fifo *fifo_hdr;
811 u32 *fifo_data;
812 u32 fifo_len;
813 unsigned long flags;
814 int i, j;
815
816 if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags))
817 return;
818
819 /* Pull RXF data from all RXFs */
820 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
821 /*
822 * Keep aside the additional offset that might be needed for
823 * next RXF
824 */
825 u32 offset_diff = RXF_DIFF_FROM_PREV * i;
826
827 fifo_hdr = (void *)(*dump_data)->data;
828 fifo_data = (void *)fifo_hdr->data;
829 fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
830
831 /* No need to try to read the data if the length is 0 */
832 if (fifo_len == 0)
833 continue;
834
835 /* Add a TLV for the RXF */
836 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
837 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
838
839 fifo_hdr->fifo_num = cpu_to_le32(i);
840 fifo_hdr->available_bytes =
841 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
842 RXF_RD_D_SPACE +
843 offset_diff));
844 fifo_hdr->wr_ptr =
845 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
846 RXF_RD_WR_PTR +
847 offset_diff));
848 fifo_hdr->rd_ptr =
849 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
850 RXF_RD_RD_PTR +
851 offset_diff));
852 fifo_hdr->fence_ptr =
853 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
854 RXF_RD_FENCE_PTR +
855 offset_diff));
856 fifo_hdr->fence_mode =
857 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
858 RXF_SET_FENCE_MODE +
859 offset_diff));
860
861 /* Lock fence */
862 iwl_trans_write_prph(mvm->trans,
863 RXF_SET_FENCE_MODE + offset_diff, 0x1);
864 /* Set fence pointer to the same place like WR pointer */
865 iwl_trans_write_prph(mvm->trans,
866 RXF_LD_WR2FENCE + offset_diff, 0x1);
867 /* Set fence offset */
868 iwl_trans_write_prph(mvm->trans,
869 RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
870 0x0);
871
872 /* Read FIFO */
873 fifo_len /= sizeof(u32); /* Size in DWORDS */
874 for (j = 0; j < fifo_len; j++)
875 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
876 RXF_FIFO_RD_FENCE_INC +
877 offset_diff);
878 *dump_data = iwl_fw_error_next_data(*dump_data);
879 }
880
881 /* Pull TXF data from all TXFs */
882 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
883 /* Mark the number of TXF we're pulling now */
884 iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
885
886 fifo_hdr = (void *)(*dump_data)->data;
887 fifo_data = (void *)fifo_hdr->data;
888 fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
889
890 /* No need to try to read the data if the length is 0 */
891 if (fifo_len == 0)
892 continue;
893
894 /* Add a TLV for the FIFO */
895 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
896 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
897
898 fifo_hdr->fifo_num = cpu_to_le32(i);
899 fifo_hdr->available_bytes =
900 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
901 TXF_FIFO_ITEM_CNT));
902 fifo_hdr->wr_ptr =
903 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
904 TXF_WR_PTR));
905 fifo_hdr->rd_ptr =
906 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
907 TXF_RD_PTR));
908 fifo_hdr->fence_ptr =
909 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
910 TXF_FENCE_PTR));
911 fifo_hdr->fence_mode =
912 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
913 TXF_LOCK_FENCE));
914
915 /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
916 iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
917 TXF_WR_PTR);
918
919 /* Dummy-read to advance the read pointer to the head */
920 iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
921
922 /* Read FIFO */
923 fifo_len /= sizeof(u32); /* Size in DWORDS */
924 for (j = 0; j < fifo_len; j++)
925 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
926 TXF_READ_MODIFY_DATA);
927 *dump_data = iwl_fw_error_next_data(*dump_data);
928 }
929
930 iwl_trans_release_nic_access(mvm->trans, &flags);
931}
932
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +0200933void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
934{
935 if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert ||
936 !mvm->fw_dump_desc)
937 return;
938
939 kfree(mvm->fw_dump_desc);
940 mvm->fw_dump_desc = NULL;
941}
942
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +0300943void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300944{
945 struct iwl_fw_error_dump_file *dump_file;
946 struct iwl_fw_error_dump_data *dump_data;
947 struct iwl_fw_error_dump_info *dump_info;
Emmanuel Grumbacha549b292014-12-09 14:47:57 +0200948 struct iwl_fw_error_dump_mem *dump_mem;
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +0200949 struct iwl_fw_error_dump_trigger_desc *dump_trig;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300950 struct iwl_mvm_dump_ptrs *fw_error_dump;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300951 u32 sram_len, sram_ofs;
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200952 u32 file_len, fifo_data_len = 0;
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200953 u32 smem_len = mvm->cfg->smem_len;
Ido Yariv86138322014-12-10 12:39:27 -0500954 u32 sram2_len = mvm->cfg->dccm2_len;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300955
956 lockdep_assert_held(&mvm->mutex);
957
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200958 /* W/A for 8000 HW family A-step */
Ido Yariv86138322014-12-10 12:39:27 -0500959 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
960 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP) {
961 if (smem_len)
962 smem_len = 0x38000;
963
964 if (sram2_len)
965 sram2_len = 0x10000;
966 }
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200967
Johannes Bergaadede62014-10-09 17:01:36 +0200968 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300969 if (!fw_error_dump)
970 return;
971
Liad Kaufmanf53bf4c2014-12-01 10:44:18 +0200972 /* SRAM - include stack CCM if driver knows the values for it */
973 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
974 const struct fw_img *img;
975
976 img = &mvm->fw->img[mvm->cur_ucode];
977 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
978 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
979 } else {
980 sram_ofs = mvm->cfg->dccm_offset;
981 sram_len = mvm->cfg->dccm_len;
982 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300983
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200984 /* reading RXF/TXF sizes */
985 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
986 struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
987 int i;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300988
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200989 fifo_data_len = 0;
990
991 /* Count RXF size */
992 for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
993 if (!mem_cfg->rxfifo_size[i])
994 continue;
995
996 /* Add header info */
997 fifo_data_len += mem_cfg->rxfifo_size[i] +
998 sizeof(*dump_data) +
999 sizeof(struct iwl_fw_error_dump_fifo);
1000 }
1001
1002 for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
1003 if (!mem_cfg->txfifo_size[i])
1004 continue;
1005
1006 /* Add header info */
1007 fifo_data_len += mem_cfg->txfifo_size[i] +
1008 sizeof(*dump_data) +
1009 sizeof(struct iwl_fw_error_dump_fifo);
1010 }
1011 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001012
1013 file_len = sizeof(*dump_file) +
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001014 sizeof(*dump_data) * 2 +
Emmanuel Grumbacha549b292014-12-09 14:47:57 +02001015 sram_len + sizeof(*dump_mem) +
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001016 fifo_data_len +
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001017 sizeof(*dump_info);
1018
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001019 if (mvm->fw_dump_desc)
1020 file_len += sizeof(*dump_data) + sizeof(*dump_trig) +
1021 mvm->fw_dump_desc->len;
1022
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001023 /* Make room for the SMEM, if it exists */
1024 if (smem_len)
Emmanuel Grumbacha549b292014-12-09 14:47:57 +02001025 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001026
Ido Yariv86138322014-12-10 12:39:27 -05001027 /* Make room for the secondary SRAM, if it exists */
1028 if (sram2_len)
1029 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
1030
Emmanuel Grumbach5bfe6f52014-06-25 16:21:43 +03001031 dump_file = vzalloc(file_len);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001032 if (!dump_file) {
1033 kfree(fw_error_dump);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001034 iwl_mvm_free_fw_dump_desc(mvm);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001035 return;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001036 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001037
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001038 fw_error_dump->op_mode_ptr = dump_file;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001039
1040 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001041 dump_data = (void *)dump_file->data;
1042
1043 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
1044 dump_data->len = cpu_to_le32(sizeof(*dump_info));
1045 dump_info = (void *) dump_data->data;
1046 dump_info->device_family =
1047 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
1048 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
1049 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
Ido Yariv435da2c2014-12-11 16:11:01 -05001050 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001051 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
1052 sizeof(dump_info->fw_human_readable));
1053 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
1054 sizeof(dump_info->dev_human_readable));
1055 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
1056 sizeof(dump_info->bus_human_readable));
1057
1058 dump_data = iwl_fw_error_next_data(dump_data);
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001059 /* We only dump the FIFOs if the FW is in error state */
1060 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status))
1061 iwl_mvm_dump_fifos(mvm, &dump_data);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001062
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001063 if (mvm->fw_dump_desc) {
1064 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO);
1065 dump_data->len = cpu_to_le32(sizeof(*dump_trig) +
1066 mvm->fw_dump_desc->len);
1067 dump_trig = (void *)dump_data->data;
1068 memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc,
1069 sizeof(*dump_trig) + mvm->fw_dump_desc->len);
1070
1071 /* now we can free this copy */
1072 iwl_mvm_free_fw_dump_desc(mvm);
1073 dump_data = iwl_fw_error_next_data(dump_data);
1074 }
1075
Emmanuel Grumbacha549b292014-12-09 14:47:57 +02001076 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1077 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
1078 dump_mem = (void *)dump_data->data;
1079 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1080 dump_mem->offset = cpu_to_le32(sram_ofs);
1081 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001082 sram_len);
1083
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001084 if (smem_len) {
1085 dump_data = iwl_fw_error_next_data(dump_data);
Emmanuel Grumbache06d8432014-12-09 14:36:41 +02001086 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1087 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
1088 dump_mem = (void *)dump_data->data;
1089 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
1090 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001091 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
Emmanuel Grumbache06d8432014-12-09 14:36:41 +02001092 dump_mem->data, smem_len);
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001093 }
1094
Ido Yariv86138322014-12-10 12:39:27 -05001095 if (sram2_len) {
1096 dump_data = iwl_fw_error_next_data(dump_data);
1097 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1098 dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
1099 dump_mem = (void *)dump_data->data;
1100 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1101 dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
1102 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
1103 dump_mem->data, sram2_len);
1104 }
1105
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001106 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
1107 fw_error_dump->op_mode_len = file_len;
1108 if (fw_error_dump->trans_ptr)
1109 file_len += fw_error_dump->trans_ptr->len;
1110 dump_file->file_len = cpu_to_le32(file_len);
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +03001111
Johannes Bergaadede62014-10-09 17:01:36 +02001112 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
1113 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001114
1115 clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001116}
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001117
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001118struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
1119 .trig_desc = {
1120 .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
1121 },
1122};
1123
Johannes Berg8ca151b2013-01-24 14:25:36 +01001124static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1125{
Johannes Berg58629d92014-11-06 09:40:50 +01001126 /* clear the D3 reconfig, we only need it to avoid dumping a
1127 * firmware coredump on reconfiguration, we shouldn't do that
1128 * on D3->D0 transition
1129 */
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001130 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1131 mvm->fw_dump_desc = &iwl_mvm_dump_desc_assert;
Johannes Berg58629d92014-11-06 09:40:50 +01001132 iwl_mvm_fw_error_dump(mvm);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001133 }
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +02001134
Eliad Peller744cb692014-12-10 18:44:13 +02001135 /* cleanup all stale references (scan, roc), but keep the
1136 * ucode_down ref until reconfig is complete
1137 */
1138 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1139
Johannes Berg8ca151b2013-01-24 14:25:36 +01001140 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001141
1142 mvm->scan_status = IWL_MVM_SCAN_NONE;
Luciano Coelhob1873302014-08-08 17:12:07 +03001143 mvm->ps_disabled = false;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +02001144 mvm->calibrating = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001145
1146 /* just in case one was running */
1147 ieee80211_remain_on_channel_expired(mvm->hw);
1148
1149 ieee80211_iterate_active_interfaces_atomic(
1150 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1151 iwl_mvm_cleanup_iterator, mvm);
1152
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001153 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +02001154 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001155
1156 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001157 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1158 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001159 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001160 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1161 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
1162 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1163 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
1164 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
1165 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001166
1167 ieee80211_wake_queues(mvm->hw);
1168
Eliad Peller228670b2014-08-10 17:00:15 +03001169 /* clear any stale d0i3 state */
1170 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1171
Johannes Berg8ca151b2013-01-24 14:25:36 +01001172 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001173 mvm->rx_ba_sessions = 0;
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001174 mvm->fw_dbg_conf = FW_DBG_INVALID;
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001175
1176 /* keep statistics ticking */
1177 iwl_mvm_accu_radio_stats(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001178}
1179
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001180int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001181{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001182 int ret;
1183
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001184 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001185
1186 /* Clean up some internal and mac80211 state on restart */
1187 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1188 iwl_mvm_restart_cleanup(mvm);
1189
1190 ret = iwl_mvm_up(mvm);
Johannes Bergc47af222014-04-30 16:34:45 +02001191
1192 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1193 /* Something went wrong - we need to finish some cleanup
1194 * that normally iwl_mvm_mac_restart_complete() below
1195 * would do.
1196 */
1197 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1198 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1199 }
1200
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001201 return ret;
1202}
1203
1204static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1205{
1206 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1207 int ret;
1208
Eliad Peller37948fc2014-12-11 10:48:18 +02001209 /* Some hw restart cleanups must not hold the mutex */
1210 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1211 /*
1212 * Make sure we are out of d0i3. This is needed
1213 * to make sure the reference accounting is correct
1214 * (and there is no stale d0i3_exit_work).
1215 */
1216 wait_event_timeout(mvm->d0i3_exit_waitq,
1217 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1218 &mvm->status),
1219 HZ);
1220 }
1221
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001222 mutex_lock(&mvm->mutex);
1223 ret = __iwl_mvm_mac_start(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001224 mutex_unlock(&mvm->mutex);
1225
1226 return ret;
1227}
1228
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001229static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001230{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001231 int ret;
1232
1233 mutex_lock(&mvm->mutex);
1234
1235 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +02001236 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berg01662302014-06-06 15:18:45 +02001237 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001238 if (ret)
1239 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1240 ret);
1241
Eliad Peller7498cf42014-01-16 17:10:44 +02001242 /* allow transport/FW low power modes */
1243 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1244
Arik Nemtsovcbd2ae22014-09-14 19:13:54 +03001245 /*
1246 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1247 * of packets the FW sent out, so we must reconnect.
1248 */
1249 iwl_mvm_teardown_tdls_peers(mvm);
1250
Johannes Berg8ca151b2013-01-24 14:25:36 +01001251 mutex_unlock(&mvm->mutex);
1252}
1253
Eliad Peller088070a2014-10-20 18:42:58 +03001254static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1255{
1256 bool exit_now;
1257
1258 if (!iwl_mvm_is_d0i3_supported(mvm))
1259 return;
1260
1261 mutex_lock(&mvm->d0i3_suspend_mutex);
1262 __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
1263 exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
1264 &mvm->d0i3_suspend_flags);
1265 mutex_unlock(&mvm->d0i3_suspend_mutex);
1266
1267 if (exit_now) {
1268 IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
1269 _iwl_mvm_exit_d0i3(mvm);
1270 }
Eliad Peller67359432014-12-09 15:23:54 +02001271
1272 if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND)
1273 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
1274 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1275 &mvm->status),
1276 HZ))
1277 WARN_ONCE(1, "D0i3 exit on resume timed out\n");
Eliad Peller088070a2014-10-20 18:42:58 +03001278}
1279
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001280static void
1281iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1282 enum ieee80211_reconfig_type reconfig_type)
1283{
1284 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1285
1286 switch (reconfig_type) {
1287 case IEEE80211_RECONFIG_TYPE_RESTART:
1288 iwl_mvm_restart_complete(mvm);
1289 break;
1290 case IEEE80211_RECONFIG_TYPE_SUSPEND:
Eliad Peller088070a2014-10-20 18:42:58 +03001291 iwl_mvm_resume_complete(mvm);
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001292 break;
1293 }
1294}
1295
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001296void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001297{
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001298 lockdep_assert_held(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +02001299
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001300 /* firmware counters are obviously reset now, but we shouldn't
1301 * partially track so also clear the fw_reset_accu counters.
1302 */
1303 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1304
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001305 /*
1306 * Disallow low power states when the FW is down by taking
1307 * the UCODE_DOWN ref. in case of ongoing hw restart the
1308 * ref is already taken, so don't take it again.
1309 */
1310 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1311 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
Eliad Peller7498cf42014-01-16 17:10:44 +02001312
Johannes Berg8ca151b2013-01-24 14:25:36 +01001313 /* async_handlers_wk is now blocked */
1314
1315 /*
1316 * The work item could be running or queued if the
1317 * ROC time event stops just as we get here.
1318 */
1319 cancel_work_sync(&mvm->roc_done_wk);
1320
1321 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001322
1323 iwl_mvm_async_handlers_purge(mvm);
1324 /* async_handlers_list is empty and will stay empty: HW is stopped */
1325
1326 /* the fw is stopped, the aux sta is dead: clean up driver state */
Johannes Berg712b24a2014-08-04 14:14:14 +02001327 iwl_mvm_del_aux_sta(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001328
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001329 /*
1330 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1331 * won't be called in this case).
1332 */
1333 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1334
Luciano Coelhobc448862014-08-20 11:49:11 +03001335 mvm->ucode_loaded = false;
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001336}
Luciano Coelhobc448862014-08-20 11:49:11 +03001337
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001338static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1339{
1340 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1341
1342 flush_work(&mvm->d0i3_exit_work);
1343 flush_work(&mvm->async_handlers_wk);
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001344 cancel_delayed_work_sync(&mvm->fw_dump_wk);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001345 iwl_mvm_free_fw_dump_desc(mvm);
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001346
1347 mutex_lock(&mvm->mutex);
1348 __iwl_mvm_mac_stop(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001349 mutex_unlock(&mvm->mutex);
1350
1351 /*
1352 * The worker might have been waiting for the mutex, let it run and
1353 * discover that its list is now empty.
1354 */
1355 cancel_work_sync(&mvm->async_handlers_wk);
1356}
1357
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001358static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1359{
1360 u16 i;
1361
1362 lockdep_assert_held(&mvm->mutex);
1363
1364 for (i = 0; i < NUM_PHY_CTX; i++)
1365 if (!mvm->phy_ctxts[i].ref)
1366 return &mvm->phy_ctxts[i];
1367
1368 IWL_ERR(mvm, "No available PHY context\n");
1369 return NULL;
1370}
1371
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001372static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1373 s8 tx_power)
1374{
1375 /* FW is in charge of regulatory enforcement */
1376 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
1377 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
1378 .pwr_restriction = cpu_to_le16(tx_power),
1379 };
1380
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001381 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001382 sizeof(reduce_txpwr_cmd),
1383 &reduce_txpwr_cmd);
1384}
1385
Johannes Berg8ca151b2013-01-24 14:25:36 +01001386static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1387 struct ieee80211_vif *vif)
1388{
1389 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1390 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1391 int ret;
1392
Emmanuel Grumbachaa5e1832015-03-07 19:35:37 +02001393 mvmvif->mvm = mvm;
1394
Johannes Berg8ca151b2013-01-24 14:25:36 +01001395 /*
Gregory Greenmand40fc482014-06-25 14:08:50 +02001396 * make sure D0i3 exit is completed, otherwise a target access
1397 * during tx queue configuration could be done when still in
1398 * D0i3 state.
1399 */
1400 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1401 if (ret)
1402 return ret;
1403
1404 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001405 * Not much to do here. The stack will not allow interface
1406 * types or combinations that we didn't advertise, so we
1407 * don't really have to check the types.
1408 */
1409
1410 mutex_lock(&mvm->mutex);
1411
Johannes Berg33cef922015-01-21 21:41:29 +01001412 /* make sure that beacon statistics don't go backwards with FW reset */
1413 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1414 mvmvif->beacon_stats.accu_num_beacons +=
1415 mvmvif->beacon_stats.num_beacons;
1416
Eliad Pellere89044d2013-07-16 17:33:26 +03001417 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001418 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1419 if (ret)
1420 goto out_unlock;
1421
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001422 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +03001423 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1424 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +03001425
1426 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001427 * The AP binding flow can be done only after the beacon
1428 * template is configured (which happens only in the mac80211
1429 * start_ap() flow), and adding the broadcast station can happen
1430 * only after the binding.
1431 * In addition, since modifying the MAC before adding a bcast
1432 * station is not allowed by the FW, delay the adding of MAC context to
1433 * the point where we can also add the bcast station.
1434 * In short: there's not much we can do at this point, other than
1435 * allocating resources :)
1436 */
Johannes Berg5023d962013-07-31 14:07:43 +02001437 if (vif->type == NL80211_IFTYPE_AP ||
1438 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg013290a2014-08-04 13:38:48 +02001439 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001440 if (ret) {
1441 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1442 goto out_release;
1443 }
1444
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +03001445 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001446 goto out_unlock;
1447 }
1448
Johannes Berg8ca151b2013-01-24 14:25:36 +01001449 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1450 if (ret)
1451 goto out_release;
1452
Arik Nemtsov999609f2014-05-15 17:31:51 +03001453 ret = iwl_mvm_power_update_mac(mvm);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001454 if (ret)
Luciano Coelhofd66fc12015-01-27 15:06:57 +02001455 goto out_remove_mac;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001456
Hila Gonen7df15b12012-12-12 11:16:19 +02001457 /* beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001458 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001459 if (ret)
1460 goto out_remove_mac;
1461
Hila Gonen7df15b12012-12-12 11:16:19 +02001462 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +03001463 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001464 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001465 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1466 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +02001467 }
1468
Johannes Berg8ca151b2013-01-24 14:25:36 +01001469 /*
1470 * P2P_DEVICE interface does not have a channel context assigned to it,
1471 * so a dedicated PHY context is allocated to it and the corresponding
1472 * MAC context is bound to it at this stage.
1473 */
1474 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001475
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001476 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1477 if (!mvmvif->phy_ctxt) {
1478 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001479 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001480 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001481
Ilan Peer53a9d612013-04-28 11:55:08 +03001482 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001483 ret = iwl_mvm_binding_add_vif(mvm, vif);
1484 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +03001485 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001486
Johannes Berg013290a2014-08-04 13:38:48 +02001487 ret = iwl_mvm_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001488 if (ret)
1489 goto out_unbind;
1490
1491 /* Save a pointer to p2p device vif, so it can later be used to
1492 * update the p2p device MAC when a GO is started/stopped */
1493 mvm->p2p_device_vif = vif;
1494 }
1495
Johannes Berg63494372013-03-26 10:47:53 +01001496 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001497 goto out_unlock;
1498
1499 out_unbind:
1500 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +03001501 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001502 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001503 out_free_bf:
1504 if (mvm->bf_allowed_vif == mvmvif) {
1505 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001506 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1507 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001508 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001509 out_remove_mac:
1510 mvmvif->phy_ctxt = NULL;
1511 iwl_mvm_mac_ctxt_remove(mvm, vif);
1512 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001513 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1514 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001515
Johannes Berg8ca151b2013-01-24 14:25:36 +01001516 iwl_mvm_mac_ctxt_release(mvm, vif);
1517 out_unlock:
1518 mutex_unlock(&mvm->mutex);
1519
Gregory Greenmand40fc482014-06-25 14:08:50 +02001520 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1521
Johannes Berg8ca151b2013-01-24 14:25:36 +01001522 return ret;
1523}
1524
Johannes Berg38a12b52013-02-22 14:07:56 +01001525static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1526 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001527{
Arik Nemtsovd92b732e2014-09-21 19:00:42 +03001528 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001529
1530 if (tfd_msk) {
1531 mutex_lock(&mvm->mutex);
1532 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1533 mutex_unlock(&mvm->mutex);
1534 }
1535
1536 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1537 /*
1538 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1539 * We assume here that all the packets sent to the OFFCHANNEL
1540 * queue are sent in ROC session.
1541 */
1542 flush_work(&mvm->roc_done_wk);
1543 } else {
1544 /*
1545 * By now, all the AC queues are empty. The AGG queues are
1546 * empty too. We already got all the Tx responses for all the
1547 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +03001548 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001549 */
1550 flush_work(&mvm->sta_drained_wk);
1551 }
Johannes Berg38a12b52013-02-22 14:07:56 +01001552}
1553
1554static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1555 struct ieee80211_vif *vif)
1556{
1557 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1558 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1559
1560 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001561
1562 mutex_lock(&mvm->mutex);
1563
Hila Gonen7df15b12012-12-12 11:16:19 +02001564 if (mvm->bf_allowed_vif == mvmvif) {
1565 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001566 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1567 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +02001568 }
1569
Johannes Berg63494372013-03-26 10:47:53 +01001570 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1571
Johannes Berg8ca151b2013-01-24 14:25:36 +01001572 /*
1573 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +01001574 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001575 */
Johannes Berg5023d962013-07-31 14:07:43 +02001576 if (vif->type == NL80211_IFTYPE_AP ||
1577 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +03001578#ifdef CONFIG_NL80211_TESTMODE
1579 if (vif == mvm->noa_vif) {
1580 mvm->noa_vif = NULL;
1581 mvm->noa_duration = 0;
1582 }
1583#endif
Johannes Berg013290a2014-08-04 13:38:48 +02001584 iwl_mvm_dealloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001585 goto out_release;
1586 }
1587
1588 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1589 mvm->p2p_device_vif = NULL;
Johannes Berg013290a2014-08-04 13:38:48 +02001590 iwl_mvm_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001591 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001592 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001593 mvmvif->phy_ctxt = NULL;
1594 }
1595
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001596 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001597 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001598
Arik Nemtsov999609f2014-05-15 17:31:51 +03001599 iwl_mvm_power_update_mac(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001600 iwl_mvm_mac_ctxt_remove(mvm, vif);
1601
1602out_release:
1603 iwl_mvm_mac_ctxt_release(mvm, vif);
1604 mutex_unlock(&mvm->mutex);
1605}
1606
1607static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1608{
1609 return 0;
1610}
1611
Eliad Pellere59647e2013-11-28 14:08:50 +02001612struct iwl_mvm_mc_iter_data {
1613 struct iwl_mvm *mvm;
1614 int port_id;
1615};
1616
1617static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1618 struct ieee80211_vif *vif)
1619{
1620 struct iwl_mvm_mc_iter_data *data = _data;
1621 struct iwl_mvm *mvm = data->mvm;
1622 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1623 int ret, len;
1624
1625 /* if we don't have free ports, mcast frames will be dropped */
1626 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1627 return;
1628
1629 if (vif->type != NL80211_IFTYPE_STATION ||
1630 !vif->bss_conf.assoc)
1631 return;
1632
1633 cmd->port_id = data->port_id++;
1634 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1635 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1636
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001637 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
Eliad Pellere59647e2013-11-28 14:08:50 +02001638 if (ret)
1639 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1640}
1641
1642static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1643{
1644 struct iwl_mvm_mc_iter_data iter_data = {
1645 .mvm = mvm,
1646 };
1647
1648 lockdep_assert_held(&mvm->mutex);
1649
1650 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1651 return;
1652
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001653 ieee80211_iterate_active_interfaces_atomic(
Eliad Pellere59647e2013-11-28 14:08:50 +02001654 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1655 iwl_mvm_mc_iface_iterator, &iter_data);
1656}
1657
1658static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1659 struct netdev_hw_addr_list *mc_list)
1660{
1661 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1662 struct iwl_mcast_filter_cmd *cmd;
1663 struct netdev_hw_addr *addr;
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001664 int addr_count;
1665 bool pass_all;
Eliad Pellere59647e2013-11-28 14:08:50 +02001666 int len;
1667
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001668 addr_count = netdev_hw_addr_list_count(mc_list);
1669 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1670 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1671 if (pass_all)
Eliad Pellere59647e2013-11-28 14:08:50 +02001672 addr_count = 0;
Eliad Pellere59647e2013-11-28 14:08:50 +02001673
1674 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1675 cmd = kzalloc(len, GFP_ATOMIC);
1676 if (!cmd)
1677 return 0;
1678
1679 if (pass_all) {
1680 cmd->pass_all = 1;
1681 return (u64)(unsigned long)cmd;
1682 }
1683
1684 netdev_hw_addr_list_for_each(addr, mc_list) {
1685 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1686 cmd->count, addr->addr);
1687 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1688 addr->addr, ETH_ALEN);
1689 cmd->count++;
1690 }
1691
1692 return (u64)(unsigned long)cmd;
1693}
1694
Johannes Berg8ca151b2013-01-24 14:25:36 +01001695static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1696 unsigned int changed_flags,
1697 unsigned int *total_flags,
1698 u64 multicast)
1699{
Eliad Pellere59647e2013-11-28 14:08:50 +02001700 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1701 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1702
1703 mutex_lock(&mvm->mutex);
1704
1705 /* replace previous configuration */
1706 kfree(mvm->mcast_filter_cmd);
1707 mvm->mcast_filter_cmd = cmd;
1708
1709 if (!cmd)
1710 goto out;
1711
1712 iwl_mvm_recalc_multicast(mvm);
1713out:
1714 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001715 *total_flags = 0;
1716}
1717
Eliad Pellerc87163b2014-01-08 10:11:11 +02001718#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1719struct iwl_bcast_iter_data {
1720 struct iwl_mvm *mvm;
1721 struct iwl_bcast_filter_cmd *cmd;
1722 u8 current_filter;
1723};
1724
1725static void
1726iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1727 const struct iwl_fw_bcast_filter *in_filter,
1728 struct iwl_fw_bcast_filter *out_filter)
1729{
1730 struct iwl_fw_bcast_filter_attr *attr;
1731 int i;
1732
1733 memcpy(out_filter, in_filter, sizeof(*out_filter));
1734
1735 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1736 attr = &out_filter->attrs[i];
1737
1738 if (!attr->mask)
1739 break;
1740
Eliad Peller2ee8f022014-01-13 19:07:09 +02001741 switch (attr->reserved1) {
1742 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1743 if (vif->bss_conf.arp_addr_cnt != 1) {
1744 attr->mask = 0;
1745 continue;
1746 }
1747
1748 attr->val = vif->bss_conf.arp_addr_list[0];
1749 break;
1750 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1751 attr->val = *(__be32 *)&vif->addr[2];
1752 break;
1753 default:
1754 break;
1755 }
1756 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001757 out_filter->num_attrs++;
1758 }
1759}
1760
1761static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1762 struct ieee80211_vif *vif)
1763{
1764 struct iwl_bcast_iter_data *data = _data;
1765 struct iwl_mvm *mvm = data->mvm;
1766 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1767 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1768 struct iwl_fw_bcast_mac *bcast_mac;
1769 int i;
1770
1771 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1772 return;
1773
1774 bcast_mac = &cmd->macs[mvmvif->id];
1775
Ilan Peere48393e2014-05-22 11:19:02 +03001776 /*
1777 * enable filtering only for associated stations, but not for P2P
1778 * Clients
1779 */
1780 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1781 !vif->bss_conf.assoc)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001782 return;
1783
1784 bcast_mac->default_discard = 1;
1785
1786 /* copy all configured filters */
1787 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1788 /*
1789 * Make sure we don't exceed our filters limit.
1790 * if there is still a valid filter to be configured,
1791 * be on the safe side and just allow bcast for this mac.
1792 */
1793 if (WARN_ON_ONCE(data->current_filter >=
1794 ARRAY_SIZE(cmd->filters))) {
1795 bcast_mac->default_discard = 0;
1796 bcast_mac->attached_filters = 0;
1797 break;
1798 }
1799
1800 iwl_mvm_set_bcast_filter(vif,
1801 &mvm->bcast_filters[i],
1802 &cmd->filters[data->current_filter]);
1803
1804 /* skip current filter if it contains no attributes */
1805 if (!cmd->filters[data->current_filter].num_attrs)
1806 continue;
1807
1808 /* attach the filter to current mac */
1809 bcast_mac->attached_filters |=
1810 cpu_to_le16(BIT(data->current_filter));
1811
1812 data->current_filter++;
1813 }
1814}
1815
Eliad Pellerde06a592014-01-08 10:11:12 +02001816bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1817 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001818{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001819 struct iwl_bcast_iter_data iter_data = {
1820 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001821 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001822 };
1823
Max Stepanov3b8983b2014-10-15 11:27:16 +03001824 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1825 return false;
1826
Eliad Pellerde06a592014-01-08 10:11:12 +02001827 memset(cmd, 0, sizeof(*cmd));
1828 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1829 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1830
1831#ifdef CONFIG_IWLWIFI_DEBUGFS
1832 /* use debugfs filters/macs if override is configured */
1833 if (mvm->dbgfs_bcast_filtering.override) {
1834 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1835 sizeof(cmd->filters));
1836 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1837 sizeof(cmd->macs));
1838 return true;
1839 }
1840#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001841
1842 /* if no filters are configured, do nothing */
1843 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001844 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001845
1846 /* configure and attach these filters for each associated sta vif */
1847 ieee80211_iterate_active_interfaces(
1848 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1849 iwl_mvm_bcast_filter_iterator, &iter_data);
1850
Eliad Pellerde06a592014-01-08 10:11:12 +02001851 return true;
1852}
1853static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1854 struct ieee80211_vif *vif)
1855{
1856 struct iwl_bcast_filter_cmd cmd;
1857
1858 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1859 return 0;
1860
1861 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1862 return 0;
1863
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001864 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001865 sizeof(cmd), &cmd);
1866}
1867#else
1868static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1869 struct ieee80211_vif *vif)
1870{
1871 return 0;
1872}
1873#endif
1874
Johannes Berg8ca151b2013-01-24 14:25:36 +01001875static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1876 struct ieee80211_vif *vif,
1877 struct ieee80211_bss_conf *bss_conf,
1878 u32 changes)
1879{
1880 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1881 int ret;
1882
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001883 /*
1884 * Re-calculate the tsf id, as the master-slave relations depend on the
1885 * beacon interval, which was not known when the station interface was
1886 * added.
1887 */
1888 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1889 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1890
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001891 /*
1892 * If we're not associated yet, take the (new) BSSID before associating
1893 * so the firmware knows. If we're already associated, then use the old
1894 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1895 * branch for disassociation below.
1896 */
1897 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1898 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1899
1900 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001901 if (ret)
1902 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1903
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001904 /* after sending it once, adopt mac80211 data */
1905 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1906 mvmvif->associated = bss_conf->assoc;
1907
Johannes Berg8ca151b2013-01-24 14:25:36 +01001908 if (changes & BSS_CHANGED_ASSOC) {
1909 if (bss_conf->assoc) {
Johannes Berg33cef922015-01-21 21:41:29 +01001910 /* clear statistics to get clean beacon counter */
1911 iwl_mvm_request_statistics(mvm, true);
1912 memset(&mvmvif->beacon_stats, 0,
1913 sizeof(mvmvif->beacon_stats));
1914
Johannes Berg8ca151b2013-01-24 14:25:36 +01001915 /* add quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001916 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001917 if (ret) {
1918 IWL_ERR(mvm, "failed to update quotas\n");
1919 return;
1920 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001921
1922 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1923 &mvm->status)) {
1924 /*
1925 * If we're restarting then the firmware will
1926 * obviously have lost synchronisation with
1927 * the AP. It will attempt to synchronise by
1928 * itself, but we can make it more reliable by
1929 * scheduling a session protection time event.
1930 *
1931 * The firmware needs to receive a beacon to
1932 * catch up with synchronisation, use 110% of
1933 * the beacon interval.
1934 *
1935 * Set a large maximum delay to allow for more
1936 * than a single interface.
1937 */
1938 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1939 iwl_mvm_protect_session(mvm, vif, dur, dur,
Liad Kaufmand20d37b2014-07-06 17:14:39 +03001940 5 * dur, false);
Johannes Berg016d27e2013-05-03 11:16:15 +02001941 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001942
1943 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001944 iwl_mvm_power_vif_assoc(mvm, vif);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001945 if (vif->p2p) {
Eliad Peller29a90a42013-11-05 14:06:29 +02001946 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001947 iwl_mvm_update_smps(mvm, vif,
1948 IWL_MVM_SMPS_REQ_PROT,
1949 IEEE80211_SMPS_DYNAMIC);
1950 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001951 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001952 /*
1953 * If update fails - SF might be running in associated
1954 * mode while disassociated - which is forbidden.
1955 */
1956 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1957 "Failed to update SF upon disassociation\n");
1958
Johannes Berg8ca151b2013-01-24 14:25:36 +01001959 /* remove AP station now that the MAC is unassoc */
1960 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1961 if (ret)
1962 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001963
1964 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1965 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001966 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1967 /* remove quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001968 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001969 if (ret)
1970 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001971
1972 if (vif->p2p)
1973 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001974
1975 /* this will take the cleared BSSID from bss_conf */
1976 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1977 if (ret)
1978 IWL_ERR(mvm,
1979 "failed to update MAC %pM (clear after unassoc)\n",
1980 vif->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001981 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001982
Eliad Pellere59647e2013-11-28 14:08:50 +02001983 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02001984 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02001985
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001986 /* reset rssi values */
1987 mvmvif->bf_data.ave_beacon_signal = 0;
1988
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001989 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001990 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1991 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03001992 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001993 /*
1994 * We received a beacon _after_ association so
1995 * remove the session protection.
1996 */
1997 iwl_mvm_remove_time_event(mvm, mvmvif,
1998 &mvmvif->time_event_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001999 }
Eran Hararycc87d322014-07-15 14:04:23 +03002000
2001 if (changes & BSS_CHANGED_BEACON_INFO) {
2002 iwl_mvm_sf_update(mvm, vif, false);
2003 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2004 }
2005
Johannes Berg1bc10d32014-08-26 14:25:46 +02002006 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
2007 ret = iwl_mvm_power_update_mac(mvm);
2008 if (ret)
2009 IWL_ERR(mvm, "failed to update power mode\n");
2010 }
2011
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03002012 if (changes & BSS_CHANGED_TXPOWER) {
2013 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2014 bss_conf->txpower);
2015 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2016 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002017
2018 if (changes & BSS_CHANGED_CQM) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002019 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002020 /* reset cqm events tracking */
2021 mvmvif->bf_data.last_cqm_event = 0;
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002022 if (mvmvif->bf_data.bf_enabled) {
2023 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2024 if (ret)
2025 IWL_ERR(mvm,
2026 "failed to update CQM thresholds\n");
2027 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002028 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02002029
2030 if (changes & BSS_CHANGED_ARP_FILTER) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002031 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
Eliad Peller2ee8f022014-01-13 19:07:09 +02002032 iwl_mvm_configure_bcast_filter(mvm, vif);
2033 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002034}
2035
Johannes Berg5023d962013-07-31 14:07:43 +02002036static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2037 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002038{
2039 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2040 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2041 int ret;
2042
Eliad Peller576eeee2014-07-01 18:38:38 +03002043 /*
2044 * iwl_mvm_mac_ctxt_add() might read directly from the device
2045 * (the system time), so make sure it is available.
2046 */
2047 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2048 if (ret)
2049 return ret;
2050
Johannes Berg8ca151b2013-01-24 14:25:36 +01002051 mutex_lock(&mvm->mutex);
2052
2053 /* Send the beacon template */
2054 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2055 if (ret)
2056 goto out_unlock;
2057
Ilan Peer6e97b0d2013-12-23 22:18:02 +02002058 /*
2059 * Re-calculate the tsf id, as the master-slave relations depend on the
2060 * beacon interval, which was not known when the AP interface was added.
2061 */
2062 if (vif->type == NL80211_IFTYPE_AP)
2063 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2064
Johannes Berg8ca151b2013-01-24 14:25:36 +01002065 /* Add the mac context */
2066 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2067 if (ret)
2068 goto out_unlock;
2069
2070 /* Perform the binding */
2071 ret = iwl_mvm_binding_add_vif(mvm, vif);
2072 if (ret)
2073 goto out_remove;
2074
Johannes Berg8ca151b2013-01-24 14:25:36 +01002075 /* Send the bcast station. At this stage the TBTT and DTIM time events
2076 * are added and applied to the scheduler */
Johannes Berg013290a2014-08-04 13:38:48 +02002077 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002078 if (ret)
2079 goto out_unbind;
2080
Ilan Peer5691e212013-12-31 21:05:50 +02002081 /* must be set before quota calculations */
2082 mvmvif->ap_ibss_active = true;
2083
Ilan Peera11e1442013-12-31 21:19:55 +02002084 /* power updated needs to be done before quotas */
Arik Nemtsov999609f2014-05-15 17:31:51 +03002085 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002086
Johannes Berg01662302014-06-06 15:18:45 +02002087 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002088 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02002089 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002090
Johannes Berg5023d962013-07-31 14:07:43 +02002091 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002092 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002093 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002094
Eliad Peller29a90a42013-11-05 14:06:29 +02002095 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2096
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002097 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002098
Arik Nemtsovf6972672014-06-15 16:03:55 +03002099 /* we don't support TDLS during DCM */
2100 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2101 iwl_mvm_teardown_tdls_peers(mvm);
2102
Johannes Berg8ca151b2013-01-24 14:25:36 +01002103 mutex_unlock(&mvm->mutex);
2104 return 0;
2105
Ilan Peera11e1442013-12-31 21:19:55 +02002106out_quota_failed:
Arik Nemtsov999609f2014-05-15 17:31:51 +03002107 iwl_mvm_power_update_mac(mvm);
Ilan Peer5691e212013-12-31 21:05:50 +02002108 mvmvif->ap_ibss_active = false;
Johannes Berg013290a2014-08-04 13:38:48 +02002109 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002110out_unbind:
2111 iwl_mvm_binding_remove_vif(mvm, vif);
2112out_remove:
2113 iwl_mvm_mac_ctxt_remove(mvm, vif);
2114out_unlock:
2115 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002116 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002117 return ret;
2118}
2119
Johannes Berg5023d962013-07-31 14:07:43 +02002120static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2121 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002122{
2123 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2124 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2125
Johannes Berg38a12b52013-02-22 14:07:56 +01002126 iwl_mvm_prepare_mac_removal(mvm, vif);
2127
Johannes Berg8ca151b2013-01-24 14:25:36 +01002128 mutex_lock(&mvm->mutex);
2129
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002130 /* Handle AP stop while in CSA */
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002131 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2132 iwl_mvm_remove_time_event(mvm, mvmvif,
2133 &mvmvif->time_event_data);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002134 RCU_INIT_POINTER(mvm->csa_vif, NULL);
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002135 }
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002136
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002137 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2138 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2139 mvm->csa_tx_block_bcn_timeout = 0;
2140 }
2141
Johannes Berg5023d962013-07-31 14:07:43 +02002142 mvmvif->ap_ibss_active = false;
David Spinadel1c87bba2014-02-27 16:41:52 +02002143 mvm->ap_last_beacon_gp2 = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002144
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002145 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002146
Eliad Peller29a90a42013-11-05 14:06:29 +02002147 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2148
Johannes Berg5023d962013-07-31 14:07:43 +02002149 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002150 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002151 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002152
Johannes Berg01662302014-06-06 15:18:45 +02002153 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg013290a2014-08-04 13:38:48 +02002154 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002155 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02002156
Arik Nemtsov999609f2014-05-15 17:31:51 +03002157 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002158
Johannes Berg8ca151b2013-01-24 14:25:36 +01002159 iwl_mvm_mac_ctxt_remove(mvm, vif);
2160
2161 mutex_unlock(&mvm->mutex);
2162}
2163
Johannes Berg5023d962013-07-31 14:07:43 +02002164static void
2165iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2166 struct ieee80211_vif *vif,
2167 struct ieee80211_bss_conf *bss_conf,
2168 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002169{
Ilan Peerbe2056f2013-12-04 16:47:14 +02002170 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02002171
Ilan Peerbe2056f2013-12-04 16:47:14 +02002172 /* Changes will be applied when the AP/IBSS is started */
2173 if (!mvmvif->ap_ibss_active)
2174 return;
2175
Johannes Berg863230da2013-12-04 17:08:40 +01002176 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
Johannes Bergf7d8b702014-09-09 15:49:19 +02002177 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002178 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
Johannes Berg863230da2013-12-04 17:08:40 +01002179 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02002180
Johannes Berg8ca151b2013-01-24 14:25:36 +01002181 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01002182 if (changes & BSS_CHANGED_BEACON &&
2183 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2184 IWL_WARN(mvm, "Failed updating beacon data\n");
Haim Dreyfuss79b7a692014-09-14 12:40:00 +03002185
2186 if (changes & BSS_CHANGED_TXPOWER) {
2187 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2188 bss_conf->txpower);
2189 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2190 }
2191
Johannes Berg8ca151b2013-01-24 14:25:36 +01002192}
2193
2194static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2195 struct ieee80211_vif *vif,
2196 struct ieee80211_bss_conf *bss_conf,
2197 u32 changes)
2198{
2199 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2200
Eliad Peller576eeee2014-07-01 18:38:38 +03002201 /*
2202 * iwl_mvm_bss_info_changed_station() might call
2203 * iwl_mvm_protect_session(), which reads directly from
2204 * the device (the system time), so make sure it is available.
2205 */
2206 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2207 return;
2208
Johannes Berg8ca151b2013-01-24 14:25:36 +01002209 mutex_lock(&mvm->mutex);
2210
David Spinadel723f02e2014-04-27 09:54:54 +03002211 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
David Spinadelfb98be52014-05-04 12:51:10 +03002212 iwl_mvm_scan_offload_stop(mvm, true);
David Spinadel723f02e2014-04-27 09:54:54 +03002213
Johannes Berg8ca151b2013-01-24 14:25:36 +01002214 switch (vif->type) {
2215 case NL80211_IFTYPE_STATION:
2216 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2217 break;
2218 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002219 case NL80211_IFTYPE_ADHOC:
2220 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002221 break;
2222 default:
2223 /* shouldn't happen */
2224 WARN_ON_ONCE(1);
2225 }
2226
2227 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002228 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002229}
2230
Eliad Peller4660dfb2014-06-22 18:15:59 +03002231static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
2232 enum iwl_scan_status scan_type)
2233{
2234 int ret;
2235 bool wait_for_handlers = false;
2236
2237 mutex_lock(&mvm->mutex);
2238
2239 if (mvm->scan_status != scan_type) {
2240 ret = 0;
2241 /* make sure there are no pending notifications */
2242 wait_for_handlers = true;
2243 goto out;
2244 }
2245
2246 switch (scan_type) {
2247 case IWL_MVM_SCAN_SCHED:
2248 ret = iwl_mvm_scan_offload_stop(mvm, true);
2249 break;
2250 case IWL_MVM_SCAN_OS:
2251 ret = iwl_mvm_cancel_scan(mvm);
2252 break;
2253 case IWL_MVM_SCAN_NONE:
2254 default:
2255 WARN_ON_ONCE(1);
2256 ret = -EINVAL;
2257 break;
2258 }
2259 if (ret)
2260 goto out;
2261
2262 wait_for_handlers = true;
2263out:
2264 mutex_unlock(&mvm->mutex);
2265
2266 /* make sure we consume the completion notification */
2267 if (wait_for_handlers)
2268 iwl_mvm_wait_for_async_handlers(mvm);
2269
2270 return ret;
2271}
Johannes Berg8ca151b2013-01-24 14:25:36 +01002272static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2273 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02002274 struct ieee80211_scan_request *hw_req)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002275{
2276 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
David Spinadelc56ef672014-02-05 15:21:13 +02002277 struct cfg80211_scan_request *req = &hw_req->req;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002278 int ret;
2279
David Spinadel762533b2014-06-05 11:20:43 +03002280 if (req->n_channels == 0 ||
2281 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002282 return -EINVAL;
2283
David Spinadeld2496222014-05-20 12:46:37 +03002284 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2285 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
2286 if (ret)
2287 return ret;
2288 }
Eliad Peller4660dfb2014-06-22 18:15:59 +03002289
Johannes Berg8ca151b2013-01-24 14:25:36 +01002290 mutex_lock(&mvm->mutex);
2291
Arik Nemtsov88931cc2014-03-05 12:26:15 +02002292 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
2293 IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
2294 ret = -EBUSY;
2295 goto out;
2296 }
2297
Eliad Peller4660dfb2014-06-22 18:15:59 +03002298 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002299 ret = -EBUSY;
Arik Nemtsov519e2022013-10-17 17:51:35 +03002300 goto out;
2301 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002302
Arik Nemtsov519e2022013-10-17 17:51:35 +03002303 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
2304
David Spinadelb975e552014-11-17 12:30:05 +02002305 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
David Spinadeld2496222014-05-20 12:46:37 +03002306 ret = iwl_mvm_scan_umac(mvm, vif, hw_req);
David Spinadelfb98be52014-05-04 12:51:10 +03002307 else
Luciano Coelho1f940382015-02-10 13:03:38 +02002308 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
David Spinadelfb98be52014-05-04 12:51:10 +03002309
Arik Nemtsov519e2022013-10-17 17:51:35 +03002310 if (ret)
2311 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2312out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002313 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002314 return ret;
2315}
2316
2317static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2318 struct ieee80211_vif *vif)
2319{
2320 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2321
2322 mutex_lock(&mvm->mutex);
2323
2324 iwl_mvm_cancel_scan(mvm);
2325
2326 mutex_unlock(&mvm->mutex);
2327}
2328
2329static void
2330iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002331 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002332 int num_frames,
2333 enum ieee80211_frame_release_type reason,
2334 bool more_data)
2335{
2336 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002337
Johannes Berg3e56ead2013-02-15 22:23:18 +01002338 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002339
Johannes Berg3e56ead2013-02-15 22:23:18 +01002340 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2341 tids, more_data, false);
2342}
2343
2344static void
2345iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2346 struct ieee80211_sta *sta, u16 tids,
2347 int num_frames,
2348 enum ieee80211_frame_release_type reason,
2349 bool more_data)
2350{
2351 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2352
2353 /* Called when we need to transmit (a) frame(s) from agg queue */
2354
2355 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2356 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002357}
2358
2359static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2360 struct ieee80211_vif *vif,
2361 enum sta_notify_cmd cmd,
2362 struct ieee80211_sta *sta)
2363{
2364 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01002365 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg3e56ead2013-02-15 22:23:18 +01002366 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002367
2368 switch (cmd) {
2369 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03002370 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002371 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01002372 spin_lock_bh(&mvmsta->lock);
2373 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2374 struct iwl_mvm_tid_data *tid_data;
2375
2376 tid_data = &mvmsta->tid_data[tid];
2377 if (tid_data->state != IWL_AGG_ON &&
2378 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2379 continue;
2380 if (iwl_mvm_tid_queued(tid_data) == 0)
2381 continue;
2382 ieee80211_sta_set_buffered(sta, tid, true);
2383 }
2384 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002385 /*
2386 * The fw updates the STA to be asleep. Tx packets on the Tx
2387 * queues to this station will not be transmitted. The fw will
2388 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2389 */
2390 break;
2391 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02002392 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01002393 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01002394 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002395 break;
2396 default:
2397 break;
2398 }
2399}
2400
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002401static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2402 struct ieee80211_vif *vif,
2403 struct ieee80211_sta *sta)
2404{
2405 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01002406 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002407
2408 /*
2409 * This is called before mac80211 does RCU synchronisation,
2410 * so here we already invalidate our internal RCU-protected
2411 * station pointer. The rest of the code will thus no longer
2412 * be able to find the station this way, and we don't rely
2413 * on further RCU synchronisation after the sta_state()
2414 * callback deleted the station.
2415 */
2416 mutex_lock(&mvm->mutex);
2417 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2418 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2419 ERR_PTR(-ENOENT));
2420 mutex_unlock(&mvm->mutex);
2421}
2422
Johannes Bergbd1ba662014-11-13 20:53:45 +01002423static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2424 const u8 *bssid)
2425{
2426 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2427 return;
2428
2429 if (iwlwifi_mod_params.uapsd_disable) {
2430 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2431 return;
2432 }
2433
2434 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2435}
2436
Johannes Berg8ca151b2013-01-24 14:25:36 +01002437static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2438 struct ieee80211_vif *vif,
2439 struct ieee80211_sta *sta,
2440 enum ieee80211_sta_state old_state,
2441 enum ieee80211_sta_state new_state)
2442{
2443 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2444 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2445 int ret;
2446
2447 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2448 sta->addr, old_state, new_state);
2449
2450 /* this would be a mac80211 bug ... but don't crash */
2451 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2452 return -EINVAL;
2453
2454 /* if a STA is being removed, reuse its ID */
2455 flush_work(&mvm->sta_drained_wk);
2456
2457 mutex_lock(&mvm->mutex);
2458 if (old_state == IEEE80211_STA_NOTEXIST &&
2459 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02002460 /*
2461 * Firmware bug - it'll crash if the beacon interval is less
2462 * than 16. We can't avoid connecting at all, so refuse the
2463 * station state change, this will cause mac80211 to abandon
2464 * attempts to connect to this AP, and eventually wpa_s will
2465 * blacklist the AP...
2466 */
2467 if (vif->type == NL80211_IFTYPE_STATION &&
2468 vif->bss_conf.beacon_int < 16) {
2469 IWL_ERR(mvm,
2470 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2471 sta->addr, vif->bss_conf.beacon_int);
2472 ret = -EINVAL;
2473 goto out_unlock;
2474 }
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002475
2476 if (sta->tdls &&
2477 (vif->p2p ||
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002478 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2479 IWL_MVM_TDLS_STA_COUNT ||
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002480 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2481 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2482 ret = -EBUSY;
2483 goto out_unlock;
2484 }
2485
Johannes Berg8ca151b2013-01-24 14:25:36 +01002486 ret = iwl_mvm_add_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002487 if (sta->tdls && ret == 0)
2488 iwl_mvm_recalc_tdls_state(mvm, vif, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002489 } else if (old_state == IEEE80211_STA_NONE &&
2490 new_state == IEEE80211_STA_AUTH) {
Haim Dreyfusse820c2d2014-04-06 11:19:09 +03002491 /*
2492 * EBS may be disabled due to previous failures reported by FW.
2493 * Reset EBS status here assuming environment has been changed.
2494 */
2495 mvm->last_ebs_successful = true;
Johannes Bergbd1ba662014-11-13 20:53:45 +01002496 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002497 ret = 0;
2498 } else if (old_state == IEEE80211_STA_AUTH &&
2499 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01002500 ret = iwl_mvm_update_sta(mvm, vif, sta);
2501 if (ret == 0)
2502 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02002503 mvmvif->phy_ctxt->channel->band,
2504 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002505 } else if (old_state == IEEE80211_STA_ASSOC &&
2506 new_state == IEEE80211_STA_AUTHORIZED) {
Arik Nemtsovf59e0e3c2014-06-10 19:56:27 +03002507
2508 /* we don't support TDLS during DCM */
2509 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2510 iwl_mvm_teardown_tdls_peers(mvm);
2511
Hila Gonen7df15b12012-12-12 11:16:19 +02002512 /* enable beacon filtering */
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002513 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002514 ret = 0;
2515 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2516 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02002517 /* disable beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002518 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002519 ret = 0;
2520 } else if (old_state == IEEE80211_STA_ASSOC &&
2521 new_state == IEEE80211_STA_AUTH) {
2522 ret = 0;
2523 } else if (old_state == IEEE80211_STA_AUTH &&
2524 new_state == IEEE80211_STA_NONE) {
2525 ret = 0;
2526 } else if (old_state == IEEE80211_STA_NONE &&
2527 new_state == IEEE80211_STA_NOTEXIST) {
2528 ret = iwl_mvm_rm_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002529 if (sta->tdls)
2530 iwl_mvm_recalc_tdls_state(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002531 } else {
2532 ret = -EIO;
2533 }
Johannes Berg48bc1302013-07-04 15:55:29 +02002534 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002535 mutex_unlock(&mvm->mutex);
2536
Liad Kaufman9c126cd2014-10-06 19:08:56 +02002537 if (sta->tdls && ret == 0) {
2538 if (old_state == IEEE80211_STA_NOTEXIST &&
2539 new_state == IEEE80211_STA_NONE)
2540 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2541 else if (old_state == IEEE80211_STA_NONE &&
2542 new_state == IEEE80211_STA_NOTEXIST)
2543 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2544 }
2545
Johannes Berg8ca151b2013-01-24 14:25:36 +01002546 return ret;
2547}
2548
2549static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2550{
2551 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2552
2553 mvm->rts_threshold = value;
2554
2555 return 0;
2556}
2557
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002558static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2559 struct ieee80211_vif *vif,
2560 struct ieee80211_sta *sta, u32 changed)
2561{
2562 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2563
2564 if (vif->type == NL80211_IFTYPE_STATION &&
2565 changed & IEEE80211_RC_NSS_CHANGED)
2566 iwl_mvm_sf_update(mvm, vif, false);
2567}
2568
Johannes Berg8ca151b2013-01-24 14:25:36 +01002569static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2570 struct ieee80211_vif *vif, u16 ac,
2571 const struct ieee80211_tx_queue_params *params)
2572{
2573 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2574 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2575
2576 mvmvif->queue_params[ac] = *params;
2577
2578 /*
2579 * No need to update right away, we'll get BSS_CHANGED_QOS
2580 * The exception is P2P_DEVICE interface which needs immediate update.
2581 */
2582 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2583 int ret;
2584
2585 mutex_lock(&mvm->mutex);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002586 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002587 mutex_unlock(&mvm->mutex);
2588 return ret;
2589 }
2590 return 0;
2591}
2592
2593static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2594 struct ieee80211_vif *vif)
2595{
2596 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2597 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2598 200 + vif->bss_conf.beacon_int);
2599 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2600 100 + vif->bss_conf.beacon_int);
2601
2602 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2603 return;
2604
Eliad Peller576eeee2014-07-01 18:38:38 +03002605 /*
2606 * iwl_mvm_protect_session() reads directly from the device
2607 * (the system time), so make sure it is available.
2608 */
2609 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2610 return;
2611
Johannes Berg8ca151b2013-01-24 14:25:36 +01002612 mutex_lock(&mvm->mutex);
2613 /* Try really hard to protect the session and hear a beacon */
Liad Kaufmand20d37b2014-07-06 17:14:39 +03002614 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002615 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002616
2617 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002618}
2619
David Spinadel35a000b2013-08-28 09:29:43 +03002620static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2621 struct ieee80211_vif *vif,
2622 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +02002623 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +03002624{
2625 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2626 int ret;
2627
David Spinadeld2496222014-05-20 12:46:37 +03002628 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2629 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2630 if (ret)
2631 return ret;
2632 }
Eliad Peller4660dfb2014-06-22 18:15:59 +03002633
David Spinadel35a000b2013-08-28 09:29:43 +03002634 mutex_lock(&mvm->mutex);
2635
Arik Nemtsov88931cc2014-03-05 12:26:15 +02002636 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
2637 IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
2638 ret = -EBUSY;
2639 goto out;
2640 }
2641
Luciano Coelho1f940382015-02-10 13:03:38 +02002642 if (!vif->bss_conf.idle) {
David Spinadelbd5e4742014-04-24 13:15:29 +03002643 ret = -EBUSY;
2644 goto out;
2645 }
2646
Eliad Peller4660dfb2014-06-22 18:15:59 +03002647 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
David Spinadel35a000b2013-08-28 09:29:43 +03002648 ret = -EBUSY;
2649 goto out;
2650 }
2651
Luciano Coelhob141c232014-10-01 13:22:40 +03002652 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
David Spinadel35a000b2013-08-28 09:29:43 +03002653 if (ret)
Luciano Coelhob141c232014-10-01 13:22:40 +03002654 mvm->scan_status = IWL_MVM_SCAN_NONE;
David Spinadeld2496222014-05-20 12:46:37 +03002655
David Spinadel35a000b2013-08-28 09:29:43 +03002656out:
2657 mutex_unlock(&mvm->mutex);
2658 return ret;
2659}
2660
Johannes Berg37e33082014-02-17 10:48:17 +01002661static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2662 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03002663{
2664 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002665 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002666
2667 mutex_lock(&mvm->mutex);
David Spinadelfb98be52014-05-04 12:51:10 +03002668 ret = iwl_mvm_scan_offload_stop(mvm, false);
David Spinadel35a000b2013-08-28 09:29:43 +03002669 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002670 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01002671
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002672 return ret;
David Spinadeld2496222014-05-20 12:46:37 +03002673
David Spinadel35a000b2013-08-28 09:29:43 +03002674}
2675
Johannes Berg8ca151b2013-01-24 14:25:36 +01002676static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2677 enum set_key_cmd cmd,
2678 struct ieee80211_vif *vif,
2679 struct ieee80211_sta *sta,
2680 struct ieee80211_key_conf *key)
2681{
2682 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2683 int ret;
2684
2685 if (iwlwifi_mod_params.sw_crypto) {
2686 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2687 return -EOPNOTSUPP;
2688 }
2689
2690 switch (key->cipher) {
2691 case WLAN_CIPHER_SUITE_TKIP:
2692 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2693 /* fall-through */
2694 case WLAN_CIPHER_SUITE_CCMP:
2695 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2696 break;
2697 case WLAN_CIPHER_SUITE_AES_CMAC:
2698 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2699 break;
2700 case WLAN_CIPHER_SUITE_WEP40:
2701 case WLAN_CIPHER_SUITE_WEP104:
Johannes Bergba3943b2014-11-12 23:54:48 +01002702 /* For non-client mode, only use WEP keys for TX as we probably
2703 * don't have a station yet anyway and would then have to keep
2704 * track of the keys, linking them to each of the clients/peers
2705 * as they appear. For now, don't do that, for performance WEP
2706 * offload doesn't really matter much, but we need it for some
2707 * other offload features in client mode.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002708 */
Johannes Bergba3943b2014-11-12 23:54:48 +01002709 if (vif->type != NL80211_IFTYPE_STATION)
2710 return 0;
2711 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002712 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002713 /* currently FW supports only one optional cipher scheme */
2714 if (hw->n_cipher_schemes &&
2715 hw->cipher_schemes->cipher == key->cipher)
2716 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2717 else
2718 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002719 }
2720
2721 mutex_lock(&mvm->mutex);
2722
2723 switch (cmd) {
2724 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02002725 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2726 vif->type == NL80211_IFTYPE_AP) && !sta) {
2727 /*
2728 * GTK on AP interface is a TX-only key, return 0;
2729 * on IBSS they're per-station and because we're lazy
2730 * we don't support them for RX, so do the same.
2731 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002732 ret = 0;
2733 key->hw_key_idx = STA_KEY_IDX_INVALID;
2734 break;
2735 }
2736
Johannes Berg8ca151b2013-01-24 14:25:36 +01002737 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2738 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2739 if (ret) {
2740 IWL_WARN(mvm, "set key failed\n");
2741 /*
2742 * can't add key for RX, but we don't need it
2743 * in the device for TX so still return 0
2744 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002745 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002746 ret = 0;
2747 }
2748
2749 break;
2750 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01002751 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2752 ret = 0;
2753 break;
2754 }
2755
Johannes Berg8ca151b2013-01-24 14:25:36 +01002756 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2757 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2758 break;
2759 default:
2760 ret = -EINVAL;
2761 }
2762
2763 mutex_unlock(&mvm->mutex);
2764 return ret;
2765}
2766
2767static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2768 struct ieee80211_vif *vif,
2769 struct ieee80211_key_conf *keyconf,
2770 struct ieee80211_sta *sta,
2771 u32 iv32, u16 *phase1key)
2772{
2773 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2774
Johannes Berg5023d962013-07-31 14:07:43 +02002775 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2776 return;
2777
Johannes Berg8ca151b2013-01-24 14:25:36 +01002778 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2779}
2780
2781
Ariej Marjiehb1128892014-07-16 21:11:12 +03002782static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2783 struct iwl_rx_packet *pkt, void *data)
2784{
2785 struct iwl_mvm *mvm =
2786 container_of(notif_wait, struct iwl_mvm, notif_wait);
2787 struct iwl_hs20_roc_res *resp;
2788 int resp_len = iwl_rx_packet_payload_len(pkt);
2789 struct iwl_mvm_time_event_data *te_data = data;
2790
2791 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2792 return true;
2793
2794 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2795 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2796 return true;
2797 }
2798
2799 resp = (void *)pkt->data;
2800
2801 IWL_DEBUG_TE(mvm,
2802 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2803 resp->status, resp->event_unique_id);
2804
2805 te_data->uid = le32_to_cpu(resp->event_unique_id);
2806 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2807 te_data->uid);
2808
2809 spin_lock_bh(&mvm->time_event_lock);
2810 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2811 spin_unlock_bh(&mvm->time_event_lock);
2812
2813 return true;
2814}
2815
2816#define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2817static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2818 struct ieee80211_channel *channel,
2819 struct ieee80211_vif *vif,
2820 int duration)
2821{
2822 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2823 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2824 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2825 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2826 struct iwl_notification_wait wait_time_event;
2827 struct iwl_hs20_roc_req aux_roc_req = {
2828 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2829 .id_and_color =
2830 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2831 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2832 /* Set the channel info data */
2833 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2834 PHY_BAND_24 : PHY_BAND_5,
2835 .channel_info.channel = channel->hw_value,
2836 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2837 /* Set the time and duration */
2838 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2839 .apply_time_max_delay =
2840 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2841 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2842 };
2843
2844 /* Set the node address */
2845 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2846
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002847 lockdep_assert_held(&mvm->mutex);
2848
2849 spin_lock_bh(&mvm->time_event_lock);
2850
2851 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2852 spin_unlock_bh(&mvm->time_event_lock);
2853 return -EIO;
2854 }
2855
Ariej Marjiehb1128892014-07-16 21:11:12 +03002856 te_data->vif = vif;
2857 te_data->duration = duration;
2858 te_data->id = HOT_SPOT_CMD;
2859
Ariej Marjiehb1128892014-07-16 21:11:12 +03002860 spin_unlock_bh(&mvm->time_event_lock);
2861
2862 /*
2863 * Use a notification wait, which really just processes the
2864 * command response and doesn't wait for anything, in order
2865 * to be able to process the response and get the UID inside
2866 * the RX path. Using CMD_WANT_SKB doesn't work because it
2867 * stores the buffer and then wakes up this thread, by which
2868 * time another notification (that the time event started)
2869 * might already be processed unsuccessfully.
2870 */
2871 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2872 time_event_response,
2873 ARRAY_SIZE(time_event_response),
2874 iwl_mvm_rx_aux_roc, te_data);
2875
2876 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2877 &aux_roc_req);
2878
2879 if (res) {
2880 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2881 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2882 goto out_clear_te;
2883 }
2884
2885 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2886 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2887 /* should never fail */
2888 WARN_ON_ONCE(res);
2889
2890 if (res) {
2891 out_clear_te:
2892 spin_lock_bh(&mvm->time_event_lock);
2893 iwl_mvm_te_clear_data(mvm, te_data);
2894 spin_unlock_bh(&mvm->time_event_lock);
2895 }
2896
2897 return res;
2898}
2899
Johannes Berg8ca151b2013-01-24 14:25:36 +01002900static int iwl_mvm_roc(struct ieee80211_hw *hw,
2901 struct ieee80211_vif *vif,
2902 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002903 int duration,
2904 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002905{
2906 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002907 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002908 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03002909 struct iwl_mvm_phy_ctxt *phy_ctxt;
2910 int ret, i;
2911
2912 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2913 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002914
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002915 mutex_lock(&mvm->mutex);
2916
Ariej Marjiehb1128892014-07-16 21:11:12 +03002917 switch (vif->type) {
2918 case NL80211_IFTYPE_STATION:
Luciano Coelho5ac6c722014-10-21 16:12:18 +03002919 if (mvm->fw->ucode_capa.capa[0] &
2920 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
2921 /* Use aux roc framework (HS20) */
2922 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2923 vif, duration);
2924 goto out_unlock;
2925 }
2926 IWL_ERR(mvm, "hotspot not supported\n");
2927 ret = -EINVAL;
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002928 goto out_unlock;
Ariej Marjiehb1128892014-07-16 21:11:12 +03002929 case NL80211_IFTYPE_P2P_DEVICE:
2930 /* handle below */
2931 break;
2932 default:
2933 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002934 ret = -EINVAL;
2935 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002936 }
2937
Ilan Peer31d385a2013-04-02 10:25:46 +03002938 for (i = 0; i < NUM_PHY_CTX; i++) {
2939 phy_ctxt = &mvm->phy_ctxts[i];
2940 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2941 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002942
Ilan Peer31d385a2013-04-02 10:25:46 +03002943 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2944 /*
2945 * Unbind the P2P_DEVICE from the current PHY context,
2946 * and if the PHY context is not used remove it.
2947 */
2948 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2949 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2950 goto out_unlock;
2951
2952 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2953
2954 /* Bind the P2P_DEVICE to the current PHY Context */
2955 mvmvif->phy_ctxt = phy_ctxt;
2956
2957 ret = iwl_mvm_binding_add_vif(mvm, vif);
2958 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2959 goto out_unlock;
2960
2961 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2962 goto schedule_time_event;
2963 }
2964 }
2965
2966 /* Need to update the PHY context only if the ROC channel changed */
2967 if (channel == mvmvif->phy_ctxt->channel)
2968 goto schedule_time_event;
2969
2970 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2971
2972 /*
2973 * Change the PHY context configuration as it is currently referenced
2974 * only by the P2P Device MAC
2975 */
2976 if (mvmvif->phy_ctxt->ref == 1) {
2977 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2978 &chandef, 1, 1);
2979 if (ret)
2980 goto out_unlock;
2981 } else {
2982 /*
2983 * The PHY context is shared with other MACs. Need to remove the
2984 * P2P Device from the binding, allocate an new PHY context and
2985 * create a new binding
2986 */
2987 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2988 if (!phy_ctxt) {
2989 ret = -ENOSPC;
2990 goto out_unlock;
2991 }
2992
2993 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2994 1, 1);
2995 if (ret) {
2996 IWL_ERR(mvm, "Failed to change PHY context\n");
2997 goto out_unlock;
2998 }
2999
3000 /* Unbind the P2P_DEVICE from the current PHY context */
3001 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3002 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3003 goto out_unlock;
3004
3005 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3006
3007 /* Bind the P2P_DEVICE to the new allocated PHY context */
3008 mvmvif->phy_ctxt = phy_ctxt;
3009
3010 ret = iwl_mvm_binding_add_vif(mvm, vif);
3011 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3012 goto out_unlock;
3013
3014 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3015 }
3016
3017schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003018 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02003019 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003020
Ilan Peer31d385a2013-04-02 10:25:46 +03003021out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003022 mutex_unlock(&mvm->mutex);
3023 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01003024 return ret;
3025}
3026
3027static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3028{
3029 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3030
3031 IWL_DEBUG_MAC80211(mvm, "enter\n");
3032
3033 mutex_lock(&mvm->mutex);
Matti Gottliebbf5da872014-11-16 10:25:12 +02003034 iwl_mvm_stop_roc(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003035 mutex_unlock(&mvm->mutex);
3036
3037 IWL_DEBUG_MAC80211(mvm, "leave\n");
3038 return 0;
3039}
3040
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003041static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3042 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003043{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003044 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3045 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003046 int ret;
3047
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003048 lockdep_assert_held(&mvm->mutex);
3049
Ilan Peer53a9d612013-04-28 11:55:08 +03003050 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003051
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003052 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3053 if (!phy_ctxt) {
3054 ret = -ENOSPC;
3055 goto out;
3056 }
3057
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003058 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03003059 ctx->rx_chains_static,
3060 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003061 if (ret) {
3062 IWL_ERR(mvm, "Failed to add PHY context\n");
3063 goto out;
3064 }
3065
Ilan Peer53a9d612013-04-28 11:55:08 +03003066 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003067 *phy_ctxt_id = phy_ctxt->id;
3068out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003069 return ret;
3070}
3071
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003072static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3073 struct ieee80211_chanctx_conf *ctx)
3074{
3075 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3076 int ret;
3077
3078 mutex_lock(&mvm->mutex);
3079 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3080 mutex_unlock(&mvm->mutex);
3081
3082 return ret;
3083}
3084
3085static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3086 struct ieee80211_chanctx_conf *ctx)
3087{
3088 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3089 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3090
3091 lockdep_assert_held(&mvm->mutex);
3092
3093 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3094}
3095
Johannes Berg8ca151b2013-01-24 14:25:36 +01003096static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3097 struct ieee80211_chanctx_conf *ctx)
3098{
3099 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003100
3101 mutex_lock(&mvm->mutex);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003102 __iwl_mvm_remove_chanctx(mvm, ctx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003103 mutex_unlock(&mvm->mutex);
3104}
3105
3106static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3107 struct ieee80211_chanctx_conf *ctx,
3108 u32 changed)
3109{
3110 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003111 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3112 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003113
Ilan Peer31d385a2013-04-02 10:25:46 +03003114 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3115 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3116 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02003117 IEEE80211_CHANCTX_CHANGE_RADAR |
3118 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03003119 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3120 phy_ctxt->ref, changed))
3121 return;
3122
Johannes Berg8ca151b2013-01-24 14:25:36 +01003123 mutex_lock(&mvm->mutex);
Emmanuel Grumbach4d664492014-04-30 18:09:59 +03003124 iwl_mvm_bt_coex_vif_change(mvm);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003125 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003126 ctx->rx_chains_static,
3127 ctx->rx_chains_dynamic);
3128 mutex_unlock(&mvm->mutex);
3129}
3130
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003131static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3132 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003133 struct ieee80211_chanctx_conf *ctx,
3134 bool switching_chanctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003135{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003136 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3137 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003138 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3139 int ret;
3140
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003141 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003142
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003143 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003144
3145 switch (vif->type) {
3146 case NL80211_IFTYPE_AP:
Luciano Coelho4741dd02014-11-10 11:10:13 +02003147 /* only needed if we're switching chanctx (i.e. during CSA) */
3148 if (switching_chanctx) {
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003149 mvmvif->ap_ibss_active = true;
3150 break;
3151 }
Johannes Berg5023d962013-07-31 14:07:43 +02003152 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003153 /*
3154 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02003155 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01003156 */
3157 ret = 0;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003158 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003159 case NL80211_IFTYPE_STATION:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003160 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003161 case NL80211_IFTYPE_MONITOR:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003162 /* always disable PS when a monitor interface is active */
3163 mvmvif->ps_disabled = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003164 break;
3165 default:
3166 ret = -EINVAL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003167 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003168 }
3169
3170 ret = iwl_mvm_binding_add_vif(mvm, vif);
3171 if (ret)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003172 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003173
3174 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02003175 * Power state must be updated before quotas,
3176 * otherwise fw will complain.
3177 */
Arik Nemtsov999609f2014-05-15 17:31:51 +03003178 iwl_mvm_power_update_mac(mvm);
Alexander Bondar92d85562013-10-23 11:50:34 +02003179
3180 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01003181 * interfaces. For the other types, the bss_info changed flow
3182 * will handle quota settings.
3183 */
3184 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02003185 mvmvif->monitor_active = true;
Johannes Berg01662302014-06-06 15:18:45 +02003186 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003187 if (ret)
3188 goto out_remove_binding;
3189 }
3190
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003191 /* Handle binding during CSA */
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003192 if (vif->type == NL80211_IFTYPE_AP) {
Johannes Berg01662302014-06-06 15:18:45 +02003193 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003194 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003195 }
3196
Luciano Coelho4741dd02014-11-10 11:10:13 +02003197 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003198 u32 duration = 2 * vif->bss_conf.beacon_int;
3199
3200 /* iwl_mvm_protect_session() reads directly from the
3201 * device (the system time), so make sure it is
3202 * available.
3203 */
3204 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3205 if (ret)
3206 goto out_remove_binding;
3207
3208 /* Protect the session to make sure we hear the first
3209 * beacon on the new channel.
3210 */
3211 iwl_mvm_protect_session(mvm, vif, duration, duration,
3212 vif->bss_conf.beacon_int / 2,
3213 true);
3214
3215 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3216
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003217 iwl_mvm_update_quotas(mvm, NULL);
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03003218 }
3219
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003220 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003221
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003222out_remove_binding:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003223 iwl_mvm_binding_remove_vif(mvm, vif);
Arik Nemtsov999609f2014-05-15 17:31:51 +03003224 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003225out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003226 if (ret)
3227 mvmvif->phy_ctxt = NULL;
3228 return ret;
3229}
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003230static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3231 struct ieee80211_vif *vif,
3232 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003233{
3234 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003235 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003236
3237 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003238 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003239 mutex_unlock(&mvm->mutex);
3240
3241 return ret;
3242}
3243
3244static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3245 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003246 struct ieee80211_chanctx_conf *ctx,
3247 bool switching_chanctx)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003248{
3249 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003250 struct ieee80211_vif *disabled_vif = NULL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003251
3252 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003253
3254 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3255
Johannes Berg8ca151b2013-01-24 14:25:36 +01003256 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02003257 case NL80211_IFTYPE_ADHOC:
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003258 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003259 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02003260 mvmvif->monitor_active = false;
Luciano Coelho2533edc2014-08-08 19:50:46 +03003261 mvmvif->ps_disabled = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003262 break;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003263 case NL80211_IFTYPE_AP:
3264 /* This part is triggered only during CSA */
Luciano Coelho4741dd02014-11-10 11:10:13 +02003265 if (!switching_chanctx || !mvmvif->ap_ibss_active)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003266 goto out;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003267
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003268 mvmvif->csa_countdown = false;
3269
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003270 /* Set CS bit on all the stations */
3271 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3272
3273 /* Save blocked iface, the timeout is set on the next beacon */
3274 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3275
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003276 mvmvif->ap_ibss_active = false;
Luciano Coelhof0c97782014-03-05 15:41:48 +02003277 break;
3278 case NL80211_IFTYPE_STATION:
3279 if (!switching_chanctx)
3280 break;
3281
3282 disabled_vif = vif;
3283
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003284 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003285 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003286 default:
3287 break;
3288 }
3289
Luciano Coelhof0c97782014-03-05 15:41:48 +02003290 iwl_mvm_update_quotas(mvm, disabled_vif);
Ilan Peer1e1391c2013-03-13 14:52:04 +02003291 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03003292
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003293out:
Ilan Peera11e1442013-12-31 21:19:55 +02003294 mvmvif->phy_ctxt = NULL;
Arik Nemtsov999609f2014-05-15 17:31:51 +03003295 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003296}
3297
3298static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3299 struct ieee80211_vif *vif,
3300 struct ieee80211_chanctx_conf *ctx)
3301{
3302 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3303
3304 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003305 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003306 mutex_unlock(&mvm->mutex);
3307}
3308
Luciano Coelho50cc9572014-11-10 11:10:08 +02003309static int
3310iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3311 struct ieee80211_vif_chanctx_switch *vifs)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003312{
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003313 int ret;
3314
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003315 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003316 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003317 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3318
3319 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3320 if (ret) {
3321 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3322 goto out_reassign;
3323 }
3324
Luciano Coelhof0c97782014-03-05 15:41:48 +02003325 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3326 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003327 if (ret) {
3328 IWL_ERR(mvm,
3329 "failed to assign new_ctx during channel switch\n");
3330 goto out_remove;
3331 }
3332
Arik Nemtsovf6972672014-06-15 16:03:55 +03003333 /* we don't support TDLS during DCM - can be caused by channel switch */
3334 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3335 iwl_mvm_teardown_tdls_peers(mvm);
3336
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003337 goto out;
3338
3339out_remove:
3340 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3341
3342out_reassign:
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003343 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003344 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3345 goto out_restart;
3346 }
3347
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003348 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3349 true)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003350 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3351 goto out_restart;
3352 }
3353
3354 goto out;
3355
3356out_restart:
3357 /* things keep failing, better restart the hw */
3358 iwl_mvm_nic_restart(mvm, false);
3359
3360out:
3361 mutex_unlock(&mvm->mutex);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003362
3363 return ret;
3364}
3365
Luciano Coelho48a256e2014-11-10 11:10:09 +02003366static int
3367iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3368 struct ieee80211_vif_chanctx_switch *vifs)
3369{
3370 int ret;
3371
3372 mutex_lock(&mvm->mutex);
3373 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3374
3375 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3376 true);
3377 if (ret) {
3378 IWL_ERR(mvm,
3379 "failed to assign new_ctx during channel switch\n");
3380 goto out_reassign;
3381 }
3382
3383 goto out;
3384
3385out_reassign:
3386 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3387 true)) {
3388 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3389 goto out_restart;
3390 }
3391
3392 goto out;
3393
3394out_restart:
3395 /* things keep failing, better restart the hw */
3396 iwl_mvm_nic_restart(mvm, false);
3397
3398out:
3399 mutex_unlock(&mvm->mutex);
3400
3401 return ret;
3402}
3403
Luciano Coelho50cc9572014-11-10 11:10:08 +02003404static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3405 struct ieee80211_vif_chanctx_switch *vifs,
3406 int n_vifs,
3407 enum ieee80211_chanctx_switch_mode mode)
3408{
3409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3410 int ret;
3411
3412 /* we only support a single-vif right now */
3413 if (n_vifs > 1)
3414 return -EOPNOTSUPP;
3415
3416 switch (mode) {
3417 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3418 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3419 break;
3420 case CHANCTX_SWMODE_REASSIGN_VIF:
Luciano Coelho48a256e2014-11-10 11:10:09 +02003421 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003422 break;
3423 default:
3424 ret = -EOPNOTSUPP;
3425 break;
3426 }
3427
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003428 return ret;
3429}
3430
Johannes Berg8ca151b2013-01-24 14:25:36 +01003431static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3432 struct ieee80211_sta *sta,
3433 bool set)
3434{
3435 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01003436 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003437
3438 if (!mvm_sta || !mvm_sta->vif) {
3439 IWL_ERR(mvm, "Station is not associated to a vif\n");
3440 return -EINVAL;
3441 }
3442
3443 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3444}
3445
David Spinadel507cadf2013-07-31 18:07:21 +03003446#ifdef CONFIG_NL80211_TESTMODE
3447static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3448 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3449 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003450 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03003451};
3452
3453static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3454 struct ieee80211_vif *vif,
3455 void *data, int len)
3456{
3457 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3458 int err;
3459 u32 noa_duration;
3460
3461 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3462 if (err)
3463 return err;
3464
3465 if (!tb[IWL_MVM_TM_ATTR_CMD])
3466 return -EINVAL;
3467
3468 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3469 case IWL_MVM_TM_CMD_SET_NOA:
3470 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3471 !vif->bss_conf.enable_beacon ||
3472 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3473 return -EINVAL;
3474
3475 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3476 if (noa_duration >= vif->bss_conf.beacon_int)
3477 return -EINVAL;
3478
3479 mvm->noa_duration = noa_duration;
3480 mvm->noa_vif = vif;
3481
Johannes Berg01662302014-06-06 15:18:45 +02003482 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003483 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3484 /* must be associated client vif - ignore authorized */
3485 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3486 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3487 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3488 return -EINVAL;
3489
3490 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03003491 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3492 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
David Spinadel507cadf2013-07-31 18:07:21 +03003493 }
3494
3495 return -EOPNOTSUPP;
3496}
3497
3498static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3499 struct ieee80211_vif *vif,
3500 void *data, int len)
3501{
3502 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3503 int err;
3504
3505 mutex_lock(&mvm->mutex);
3506 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3507 mutex_unlock(&mvm->mutex);
3508
3509 return err;
3510}
3511#endif
3512
Luciano Coelho622e3f92014-11-10 11:10:17 +02003513static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3514 struct ieee80211_vif *vif,
3515 struct ieee80211_channel_switch *chsw)
3516{
3517 /* By implementing this operation, we prevent mac80211 from
3518 * starting its own channel switch timer, so that we can call
3519 * ieee80211_chswitch_done() ourselves at the right time
3520 * (which is when the absence time event starts).
3521 */
3522
3523 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3524 "dummy channel switch op\n");
3525}
3526
Luciano Coelhof0289052014-11-10 11:10:06 +02003527static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3528 struct ieee80211_vif *vif,
3529 struct ieee80211_channel_switch *chsw)
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003530{
3531 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003532 struct ieee80211_vif *csa_vif;
Luciano Coelhof6c34822014-11-10 11:10:12 +02003533 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003534 u32 apply_time;
Luciano Coelhof0289052014-11-10 11:10:06 +02003535 int ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003536
3537 mutex_lock(&mvm->mutex);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003538
Luciano Coelho6b20d772014-11-10 11:10:07 +02003539 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
Luciano Coelhof0289052014-11-10 11:10:06 +02003540 chsw->chandef.center_freq1);
Luciano Coelho6b20d772014-11-10 11:10:07 +02003541
Emmanuel Grumbachf35d9c52015-02-10 10:49:51 +02003542 iwl_fw_dbg_trigger_simple_stop(mvm, vif, FW_DBG_TRIGGER_CHANNEL_SWITCH,
3543 NULL, 0);
3544
Luciano Coelho6b20d772014-11-10 11:10:07 +02003545 switch (vif->type) {
3546 case NL80211_IFTYPE_AP:
3547 csa_vif =
3548 rcu_dereference_protected(mvm->csa_vif,
3549 lockdep_is_held(&mvm->mutex));
3550 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3551 "Another CSA is already in progress")) {
3552 ret = -EBUSY;
3553 goto out_unlock;
3554 }
3555
3556 rcu_assign_pointer(mvm->csa_vif, vif);
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003557
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003558 if (WARN_ONCE(mvmvif->csa_countdown,
3559 "Previous CSA countdown didn't complete")) {
3560 ret = -EBUSY;
3561 goto out_unlock;
3562 }
3563
Luciano Coelho6b20d772014-11-10 11:10:07 +02003564 break;
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003565 case NL80211_IFTYPE_STATION:
Luciano Coelho4500e132014-11-10 11:10:15 +02003566 /* Schedule the time event to a bit before beacon 1,
3567 * to make sure we're in the new channel when the
3568 * GO/AP arrives.
3569 */
3570 apply_time = chsw->device_timestamp +
3571 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3572 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003573
3574 if (chsw->block_tx)
3575 iwl_mvm_csa_client_absent(mvm, vif);
3576
Luciano Coelho4500e132014-11-10 11:10:15 +02003577 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003578 apply_time);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003579 if (mvmvif->bf_data.bf_enabled) {
3580 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3581 if (ret)
3582 goto out_unlock;
3583 }
3584
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003585 break;
Luciano Coelho6b20d772014-11-10 11:10:07 +02003586 default:
3587 break;
3588 }
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003589
Luciano Coelhof6c34822014-11-10 11:10:12 +02003590 mvmvif->ps_disabled = true;
3591
3592 ret = iwl_mvm_power_update_ps(mvm);
3593 if (ret)
3594 goto out_unlock;
Luciano Coelhof0289052014-11-10 11:10:06 +02003595
Arik Nemtsove198f5e2014-09-14 19:13:54 +03003596 /* we won't be on this channel any longer */
3597 iwl_mvm_teardown_tdls_peers(mvm);
3598
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003599out_unlock:
3600 mutex_unlock(&mvm->mutex);
Luciano Coelhof0289052014-11-10 11:10:06 +02003601
3602 return ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003603}
3604
Luciano Coelhof6c34822014-11-10 11:10:12 +02003605static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3606 struct ieee80211_vif *vif)
3607{
3608 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3609 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3610 int ret;
3611
3612 mutex_lock(&mvm->mutex);
3613
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003614 if (vif->type == NL80211_IFTYPE_STATION) {
3615 struct iwl_mvm_sta *mvmsta;
3616
3617 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3618 mvmvif->ap_sta_id);
3619
3620 if (WARN_ON(!mvmsta)) {
3621 ret = -EIO;
3622 goto out_unlock;
3623 }
3624
3625 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3626
3627 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003628
3629 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3630 if (ret)
3631 goto out_unlock;
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003632
3633 iwl_mvm_stop_session_protection(mvm, vif);
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003634 }
3635
Luciano Coelhof6c34822014-11-10 11:10:12 +02003636 mvmvif->ps_disabled = false;
3637
3638 ret = iwl_mvm_power_update_ps(mvm);
3639
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003640out_unlock:
Luciano Coelhof6c34822014-11-10 11:10:12 +02003641 mutex_unlock(&mvm->mutex);
3642
3643 return ret;
3644}
3645
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003646static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3647 struct ieee80211_vif *vif, u32 queues, bool drop)
3648{
3649 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3650 struct iwl_mvm_vif *mvmvif;
3651 struct iwl_mvm_sta *mvmsta;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003652 struct ieee80211_sta *sta;
3653 int i;
3654 u32 msk = 0;
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003655
3656 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3657 return;
3658
3659 mutex_lock(&mvm->mutex);
3660 mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003661
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003662 /* flush the AP-station and all TDLS peers */
3663 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3664 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3665 lockdep_is_held(&mvm->mutex));
3666 if (IS_ERR_OR_NULL(sta))
3667 continue;
3668
3669 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3670 if (mvmsta->vif != vif)
3671 continue;
3672
3673 /* make sure only TDLS peers or the AP are flushed */
3674 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3675
3676 msk |= mvmsta->tfd_queue_msk;
Johannes Berg480acbc2014-10-10 08:59:27 +02003677 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003678
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003679 if (drop) {
3680 if (iwl_mvm_flush_tx_path(mvm, msk, true))
3681 IWL_ERR(mvm, "flush request fail\n");
3682 mutex_unlock(&mvm->mutex);
3683 } else {
3684 mutex_unlock(&mvm->mutex);
Johannes Berg480acbc2014-10-10 08:59:27 +02003685
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003686 /* this can take a while, and we may need/want other operations
3687 * to succeed while doing this, so do it without the mutex held
3688 */
3689 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3690 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003691}
3692
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003693static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
3694 struct survey_info *survey)
3695{
3696 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3697 int ret;
3698
3699 memset(survey, 0, sizeof(*survey));
3700
3701 /* only support global statistics right now */
3702 if (idx != 0)
3703 return -ENOENT;
3704
3705 if (!(mvm->fw->ucode_capa.capa[0] &
3706 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3707 return -ENOENT;
3708
3709 mutex_lock(&mvm->mutex);
3710
3711 if (mvm->ucode_loaded) {
Johannes Berg33cef922015-01-21 21:41:29 +01003712 ret = iwl_mvm_request_statistics(mvm, false);
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003713 if (ret)
3714 goto out;
3715 }
3716
3717 survey->filled = SURVEY_INFO_TIME |
3718 SURVEY_INFO_TIME_RX |
3719 SURVEY_INFO_TIME_TX |
3720 SURVEY_INFO_TIME_SCAN;
3721 survey->time = mvm->accu_radio_stats.on_time_rf +
3722 mvm->radio_stats.on_time_rf;
3723 do_div(survey->time, USEC_PER_MSEC);
3724
3725 survey->time_rx = mvm->accu_radio_stats.rx_time +
3726 mvm->radio_stats.rx_time;
3727 do_div(survey->time_rx, USEC_PER_MSEC);
3728
3729 survey->time_tx = mvm->accu_radio_stats.tx_time +
3730 mvm->radio_stats.tx_time;
3731 do_div(survey->time_tx, USEC_PER_MSEC);
3732
3733 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
3734 mvm->radio_stats.on_time_scan;
3735 do_div(survey->time_scan, USEC_PER_MSEC);
3736
3737 out:
3738 mutex_unlock(&mvm->mutex);
3739 return ret;
3740}
3741
Johannes Berg33cef922015-01-21 21:41:29 +01003742static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
3743 struct ieee80211_vif *vif,
3744 struct ieee80211_sta *sta,
3745 struct station_info *sinfo)
3746{
3747 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3748 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3749 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3750
3751 if (!(mvm->fw->ucode_capa.capa[0] &
3752 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3753 return;
3754
3755 /* if beacon filtering isn't on mac80211 does it anyway */
3756 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
3757 return;
3758
3759 if (!vif->bss_conf.assoc)
3760 return;
3761
3762 mutex_lock(&mvm->mutex);
3763
3764 if (mvmvif->ap_sta_id != mvmsta->sta_id)
3765 goto unlock;
3766
3767 if (iwl_mvm_request_statistics(mvm, false))
3768 goto unlock;
3769
3770 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
3771 mvmvif->beacon_stats.accu_num_beacons;
3772 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
3773 if (mvmvif->beacon_stats.avg_signal) {
3774 /* firmware only reports a value after RXing a few beacons */
3775 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
3776 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
3777 }
3778 unlock:
3779 mutex_unlock(&mvm->mutex);
3780}
3781
Johannes Berge5209262014-01-20 23:38:59 +01003782const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003783 .tx = iwl_mvm_mac_tx,
3784 .ampdu_action = iwl_mvm_mac_ampdu_action,
3785 .start = iwl_mvm_mac_start,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02003786 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003787 .stop = iwl_mvm_mac_stop,
3788 .add_interface = iwl_mvm_mac_add_interface,
3789 .remove_interface = iwl_mvm_mac_remove_interface,
3790 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02003791 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003792 .configure_filter = iwl_mvm_configure_filter,
3793 .bss_info_changed = iwl_mvm_bss_info_changed,
3794 .hw_scan = iwl_mvm_mac_hw_scan,
3795 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01003796 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003797 .sta_state = iwl_mvm_mac_sta_state,
3798 .sta_notify = iwl_mvm_mac_sta_notify,
3799 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01003800 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003801 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02003802 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003803 .conf_tx = iwl_mvm_mac_conf_tx,
3804 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
Arik Nemtsov07ecd892014-05-20 18:16:42 +03003805 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003806 .flush = iwl_mvm_mac_flush,
David Spinadel35a000b2013-08-28 09:29:43 +03003807 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3808 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003809 .set_key = iwl_mvm_mac_set_key,
3810 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3811 .remain_on_channel = iwl_mvm_roc,
3812 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003813 .add_chanctx = iwl_mvm_add_chanctx,
3814 .remove_chanctx = iwl_mvm_remove_chanctx,
3815 .change_chanctx = iwl_mvm_change_chanctx,
3816 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3817 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003818 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003819
Johannes Berg5023d962013-07-31 14:07:43 +02003820 .start_ap = iwl_mvm_start_ap_ibss,
3821 .stop_ap = iwl_mvm_stop_ap_ibss,
3822 .join_ibss = iwl_mvm_start_ap_ibss,
3823 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003824
3825 .set_tim = iwl_mvm_set_tim,
3826
Luciano Coelho622e3f92014-11-10 11:10:17 +02003827 .channel_switch = iwl_mvm_channel_switch,
Luciano Coelhof0289052014-11-10 11:10:06 +02003828 .pre_channel_switch = iwl_mvm_pre_channel_switch,
Luciano Coelhof6c34822014-11-10 11:10:12 +02003829 .post_channel_switch = iwl_mvm_post_channel_switch,
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003830
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03003831 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
3832 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
3833 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
3834
David Spinadel507cadf2013-07-31 18:07:21 +03003835 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3836
Johannes Berg8ca151b2013-01-24 14:25:36 +01003837#ifdef CONFIG_PM_SLEEP
3838 /* look at d3.c */
3839 .suspend = iwl_mvm_suspend,
3840 .resume = iwl_mvm_resume,
3841 .set_wakeup = iwl_mvm_set_wakeup,
3842 .set_rekey_data = iwl_mvm_set_rekey_data,
3843#if IS_ENABLED(CONFIG_IPV6)
3844 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3845#endif
3846 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3847#endif
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003848 .get_survey = iwl_mvm_mac_get_survey,
Johannes Berg33cef922015-01-21 21:41:29 +01003849 .sta_statistics = iwl_mvm_mac_sta_statistics,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003850};