blob: 5f26557e4197cb6c78e9799fb6a27482cd8491c0 [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,
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200306 const char *alpha2,
Jonathan Doron47c8b152014-11-27 16:55:25 +0200307 enum iwl_mcc_source src_id,
308 bool *changed)
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200309{
310 struct ieee80211_regdomain *regd = NULL;
311 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
312 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
313 struct iwl_mcc_update_resp *resp;
314
315 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
316
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200317 lockdep_assert_held(&mvm->mutex);
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200318
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200319 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200320 if (IS_ERR_OR_NULL(resp)) {
321 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
322 PTR_RET(resp));
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200323 goto out;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200324 }
325
Jonathan Doron47c8b152014-11-27 16:55:25 +0200326 if (changed)
327 *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
328
Arik Nemtsov162ee3c2014-06-10 11:25:35 +0300329 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200330 __le32_to_cpu(resp->n_channels),
331 resp->channels,
332 __le16_to_cpu(resp->mcc));
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200333 /* Store the return source id */
334 src_id = resp->source_id;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200335 kfree(resp);
336 if (IS_ERR_OR_NULL(regd)) {
337 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200338 PTR_RET(regd));
339 goto out;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200340 }
341
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200342 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
343 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200344 mvm->lar_regdom_set = true;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200345 mvm->mcc_src = src_id;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200346
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200347out:
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200348 return regd;
349}
350
Jonathan Doron47c8b152014-11-27 16:55:25 +0200351void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
352{
353 bool changed;
354 struct ieee80211_regdomain *regd;
355
356 if (!iwl_mvm_is_lar_supported(mvm))
357 return;
358
359 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
360 if (!IS_ERR_OR_NULL(regd)) {
361 /* only update the regulatory core if changed */
362 if (changed)
363 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
364
365 kfree(regd);
366 }
367}
368
369struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
370 bool *changed)
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200371{
372 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
373 iwl_mvm_is_wifi_mcc_supported(mvm) ?
374 MCC_SOURCE_GET_CURRENT :
Jonathan Doron47c8b152014-11-27 16:55:25 +0200375 MCC_SOURCE_OLD_FW, changed);
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200376}
377
378int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
379{
380 enum iwl_mcc_source used_src;
381 struct ieee80211_regdomain *regd;
382 const struct ieee80211_regdomain *r =
383 rtnl_dereference(mvm->hw->wiphy->regd);
384
385 if (!r)
386 return 0;
387
388 /* save the last source in case we overwrite it below */
389 used_src = mvm->mcc_src;
390 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
391 /* Notify the firmware we support wifi location updates */
Jonathan Doron47c8b152014-11-27 16:55:25 +0200392 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200393 if (!IS_ERR_OR_NULL(regd))
394 kfree(regd);
395 }
396
397 /* Now set our last stored MCC and source */
Jonathan Doron47c8b152014-11-27 16:55:25 +0200398 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, NULL);
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200399 if (IS_ERR_OR_NULL(regd))
400 return -EIO;
401
402 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
403 kfree(regd);
404
405 return 0;
406}
407
Johannes Berg8ca151b2013-01-24 14:25:36 +0100408int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
409{
410 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200411 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100412
413 /* Tell mac80211 our characteristics */
414 hw->flags = IEEE80211_HW_SIGNAL_DBM |
415 IEEE80211_HW_SPECTRUM_MGMT |
416 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
417 IEEE80211_HW_QUEUE_CONTROL |
418 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100419 IEEE80211_HW_SUPPORTS_PS |
420 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100421 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200422 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300423 IEEE80211_HW_CONNECTION_MONITOR |
Ido Yarivb71d9c82014-07-23 09:31:14 -0400424 IEEE80211_HW_CHANCTX_STA_CSA |
425 IEEE80211_HW_SUPPORTS_CLONED_SKBS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100426
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200427 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200428 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200429 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
430 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
Eyal Shapira339b3082014-11-18 16:43:55 +0200431 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
432 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100433 hw->rate_control_algorithm = "iwl-mvm-rs";
Johannes Berg848955c2014-11-11 12:48:42 +0100434 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
435 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100436
437 /*
438 * Enable 11w if advertised by firmware and software crypto
439 * is not enabled (as the firmware will interpret some mgmt
440 * packets, so enabling it with software crypto isn't safe)
441 */
442 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
443 !iwlwifi_mod_params.sw_crypto)
444 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
445
Luciano Coelho1f940382015-02-10 13:03:38 +0200446 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
447 hw->wiphy->features |=
448 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
449 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
David Spinadelfb98be52014-05-04 12:51:10 +0300450
Johannes Berg8ca151b2013-01-24 14:25:36 +0100451 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
452 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200453 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100454
455 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200456 BIT(NL80211_IFTYPE_P2P_CLIENT) |
457 BIT(NL80211_IFTYPE_AP) |
458 BIT(NL80211_IFTYPE_P2P_GO) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200459 BIT(NL80211_IFTYPE_P2P_DEVICE) |
460 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200461
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100462 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200463 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
464 if (iwl_mvm_is_lar_supported(mvm))
465 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
466 else
467 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
468 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100469
Johannes Berg3e56ead2013-02-15 22:23:18 +0100470 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
471 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
472
Emmanuel Grumbach94bbed72014-11-24 08:53:33 +0200473 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +0200474
Johannes Berg8ca151b2013-01-24 14:25:36 +0100475 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
476 hw->wiphy->n_iface_combinations =
477 ARRAY_SIZE(iwl_mvm_iface_combinations);
478
Ilan Peerc451e6d2013-02-20 08:41:54 +0200479 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100480 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
Emmanuel Grumbachf1a68542014-12-16 12:31:13 +0200481 /* we can compensate an offset of up to 3 channels = 15 MHz */
482 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100483
484 /* Extract MAC address */
485 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
486 hw->wiphy->addresses = mvm->addresses;
487 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200488
489 /* Extract additional MAC addresses if available */
490 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
491 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
492
493 for (i = 1; i < num_mac; i++) {
494 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100495 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200496 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100497 hw->wiphy->n_addresses++;
498 }
499
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200500 iwl_mvm_reset_phy_ctxts(mvm);
501
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300502 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300503
Johannes Berg8ca151b2013-01-24 14:25:36 +0100504 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
505
506 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
507 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
508 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200509 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100510 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
511 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
512
Eyal Shapirac9faccc2015-02-23 10:02:23 +0200513 if ((mvm->fw->ucode_capa.capa[0] &
514 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
515 (mvm->fw->ucode_capa.api[0] &
516 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200517 hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
518 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
519 }
520
Johannes Berg8ca151b2013-01-24 14:25:36 +0100521 hw->wiphy->hw_version = mvm->trans->hw_id;
522
Alexander Bondarade50652013-04-03 16:28:47 +0300523 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100524 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
525 else
526 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
527
Emmanuel Grumbach6efaaf32014-09-01 10:03:21 +0300528 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
529 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
530 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
531 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
532 /* we create the 802.11 header and zero length SSID IE. */
533 hw->wiphy->max_sched_scan_ie_len =
534 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
535 }
David Spinadel35a000b2013-08-28 09:29:43 +0300536
Johannes Berg8ca151b2013-01-24 14:25:36 +0100537 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Johannes Bergab480032014-06-04 10:13:50 +0200538 NL80211_FEATURE_LOW_PRIORITY_SCAN |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300539 NL80211_FEATURE_P2P_GO_OPPPS |
540 NL80211_FEATURE_DYNAMIC_SMPS |
Emmanuel Grumbach9b5452f2014-10-07 10:38:53 +0300541 NL80211_FEATURE_STATIC_SMPS |
542 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100543
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300544 if (mvm->fw->ucode_capa.capa[0] &
545 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
546 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
Assaf Krauss226bcd42014-03-13 08:12:15 +0200547 if (mvm->fw->ucode_capa.capa[0] &
548 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
549 hw->wiphy->features |= NL80211_FEATURE_QUIET;
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300550
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300551 if (mvm->fw->ucode_capa.capa[0] &
552 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
553 hw->wiphy->features |=
554 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
555
556 if (mvm->fw->ucode_capa.capa[0] &
557 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
558 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
559
Johannes Berg8ca151b2013-01-24 14:25:36 +0100560 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
561
Max Stepanove36e5432013-08-27 19:56:13 +0300562 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100563 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300564 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100565 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300566 }
567
Johannes Berg8ca151b2013-01-24 14:25:36 +0100568#ifdef CONFIG_PM_SLEEP
Eliad Pellerd15a7472014-03-27 18:53:12 +0200569 if (iwl_mvm_is_d0i3_supported(mvm) &&
570 device_can_wakeup(mvm->trans->dev)) {
571 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
572 hw->wiphy->wowlan = &mvm->wowlan;
Eliad Peller91742442014-12-09 15:54:46 +0200573 }
574
575 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100576 mvm->trans->ops->d3_suspend &&
577 mvm->trans->ops->d3_resume &&
578 device_can_wakeup(mvm->trans->dev)) {
Eliad Peller91742442014-12-09 15:54:46 +0200579 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
580 WIPHY_WOWLAN_DISCONNECT |
581 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
582 WIPHY_WOWLAN_RFKILL_RELEASE |
583 WIPHY_WOWLAN_NET_DETECT;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100584 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200585 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
586 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
587 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100588
Johannes Berg964dc9e2013-06-03 17:25:34 +0200589 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
590 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
591 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
Luciano Coelhoc55385f2014-10-24 10:39:51 +0300592 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
Johannes Berg964dc9e2013-06-03 17:25:34 +0200593 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
594 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100595 }
596#endif
597
Eliad Peller77736922014-01-14 12:35:49 +0200598#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
599 /* assign default bcast filtering configuration */
600 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
601#endif
602
Johannes Berg8ca151b2013-01-24 14:25:36 +0100603 ret = iwl_mvm_leds_init(mvm);
604 if (ret)
605 return ret;
606
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300607 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) {
608 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
609 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
610 }
611
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300612 if (mvm->fw->ucode_capa.capa[0] &
613 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) {
614 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
615 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
616 }
617
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300618 ret = ieee80211_register_hw(mvm->hw);
619 if (ret)
620 iwl_mvm_leds_exit(mvm);
621
622 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100623}
624
Arik Nemtsovb2492502014-03-13 12:21:50 +0200625static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
626 struct ieee80211_sta *sta,
627 struct sk_buff *skb)
628{
629 struct iwl_mvm_sta *mvmsta;
630 bool defer = false;
631
632 /*
633 * double check the IN_D0I3 flag both before and after
634 * taking the spinlock, in order to prevent taking
635 * the spinlock when not needed.
636 */
637 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
638 return false;
639
640 spin_lock(&mvm->d0i3_tx_lock);
641 /*
642 * testing the flag again ensures the skb dequeue
643 * loop (on d0i3 exit) hasn't run yet.
644 */
645 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
646 goto out;
647
648 mvmsta = iwl_mvm_sta_from_mac80211(sta);
649 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
650 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
651 goto out;
652
653 __skb_queue_tail(&mvm->d0i3_tx, skb);
654 ieee80211_stop_queues(mvm->hw);
655
656 /* trigger wakeup */
657 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
658 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
659
660 defer = true;
661out:
662 spin_unlock(&mvm->d0i3_tx_lock);
663 return defer;
664}
665
Johannes Berg8ca151b2013-01-24 14:25:36 +0100666static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
667 struct ieee80211_tx_control *control,
668 struct sk_buff *skb)
669{
670 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100671 struct ieee80211_sta *sta = control->sta;
672 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
673 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100674
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300675 if (iwl_mvm_is_radio_killed(mvm)) {
676 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100677 goto drop;
678 }
679
Ilan Peer398e8c62013-03-13 15:20:35 +0200680 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Matti Gottlieba6cc5162014-09-29 11:46:04 +0300681 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
682 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100683 goto drop;
684
Johannes Berg3e56ead2013-02-15 22:23:18 +0100685 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
686 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
687 ieee80211_is_mgmt(hdr->frame_control) &&
688 !ieee80211_is_deauth(hdr->frame_control) &&
689 !ieee80211_is_disassoc(hdr->frame_control) &&
690 !ieee80211_is_action(hdr->frame_control)))
691 sta = NULL;
692
693 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200694 if (iwl_mvm_defer_tx(mvm, sta, skb))
695 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100696 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100697 goto drop;
698 return;
699 }
700
701 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
702 goto drop;
703 return;
704 drop:
705 ieee80211_free_txskb(hw, skb);
706}
707
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200708static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
709{
710 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
711 return false;
712 return true;
713}
714
715static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
716{
717 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
718 return false;
719 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
720 return true;
721
722 /* enabled by default */
723 return true;
724}
725
Johannes Berg8ca151b2013-01-24 14:25:36 +0100726static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
727 struct ieee80211_vif *vif,
728 enum ieee80211_ampdu_mlme_action action,
729 struct ieee80211_sta *sta, u16 tid,
730 u16 *ssn, u8 buf_size)
731{
732 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
733 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200734 bool tx_agg_ref = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100735
736 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
737 sta->addr, tid, action);
738
739 if (!(mvm->nvm_data->sku_cap_11n_enable))
740 return -EACCES;
741
Arik Nemtsovb2492502014-03-13 12:21:50 +0200742 /* return from D0i3 before starting a new Tx aggregation */
Eliad Peller9256c202014-04-22 13:33:29 +0300743 switch (action) {
744 case IEEE80211_AMPDU_TX_START:
745 case IEEE80211_AMPDU_TX_STOP_CONT:
746 case IEEE80211_AMPDU_TX_STOP_FLUSH:
747 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
748 case IEEE80211_AMPDU_TX_OPERATIONAL:
Arik Nemtsovb2492502014-03-13 12:21:50 +0200749 /*
Eliad Peller9256c202014-04-22 13:33:29 +0300750 * for tx start, wait synchronously until D0i3 exit to
751 * get the correct sequence number for the tid.
752 * additionally, some other ampdu actions use direct
753 * target access, which is not handled automatically
754 * by the trans layer (unlike commands), so wait for
755 * d0i3 exit in these cases as well.
Arik Nemtsovb2492502014-03-13 12:21:50 +0200756 */
Gregory Greenmand40fc482014-06-25 14:08:50 +0200757 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
758 if (ret)
759 return ret;
760
761 tx_agg_ref = true;
Eliad Peller9256c202014-04-22 13:33:29 +0300762 break;
763 default:
764 break;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200765 }
766
Johannes Berg8ca151b2013-01-24 14:25:36 +0100767 mutex_lock(&mvm->mutex);
768
769 switch (action) {
770 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200771 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100772 ret = -EINVAL;
773 break;
774 }
775 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
776 break;
777 case IEEE80211_AMPDU_RX_STOP:
778 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
779 break;
780 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200781 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200782 ret = -EINVAL;
783 break;
784 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100785 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
786 break;
787 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200788 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
789 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100790 case IEEE80211_AMPDU_TX_STOP_FLUSH:
791 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200792 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100793 break;
794 case IEEE80211_AMPDU_TX_OPERATIONAL:
795 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
796 break;
797 default:
798 WARN_ON_ONCE(1);
799 ret = -EINVAL;
800 break;
801 }
802 mutex_unlock(&mvm->mutex);
803
Arik Nemtsovb2492502014-03-13 12:21:50 +0200804 /*
805 * If the tid is marked as started, we won't use it for offloaded
806 * traffic on the next D0i3 entry. It's safe to unref.
807 */
808 if (tx_agg_ref)
809 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
810
Johannes Berg8ca151b2013-01-24 14:25:36 +0100811 return ret;
812}
813
814static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
815 struct ieee80211_vif *vif)
816{
817 struct iwl_mvm *mvm = data;
818 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
819
820 mvmvif->uploaded = false;
821 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
822
Johannes Berg8ca151b2013-01-24 14:25:36 +0100823 spin_lock_bh(&mvm->time_event_lock);
824 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
825 spin_unlock_bh(&mvm->time_event_lock);
826
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200827 mvmvif->phy_ctxt = NULL;
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300828 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100829}
830
Johannes Bergaadede62014-10-09 17:01:36 +0200831static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
832 const void *data, size_t datalen)
833{
834 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
835 ssize_t bytes_read;
836 ssize_t bytes_read_trans;
837
838 if (offset < dump_ptrs->op_mode_len) {
839 bytes_read = min_t(ssize_t, count,
840 dump_ptrs->op_mode_len - offset);
841 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
842 bytes_read);
843 offset += bytes_read;
844 count -= bytes_read;
845
846 if (count == 0)
847 return bytes_read;
848 } else {
849 bytes_read = 0;
850 }
851
852 if (!dump_ptrs->trans_ptr)
853 return bytes_read;
854
855 offset -= dump_ptrs->op_mode_len;
856 bytes_read_trans = min_t(ssize_t, count,
857 dump_ptrs->trans_ptr->len - offset);
858 memcpy(buffer + bytes_read,
859 (u8 *)dump_ptrs->trans_ptr->data + offset,
860 bytes_read_trans);
861
862 return bytes_read + bytes_read_trans;
863}
864
865static void iwl_mvm_free_coredump(const void *data)
866{
867 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
868
869 vfree(fw_error_dump->op_mode_ptr);
870 vfree(fw_error_dump->trans_ptr);
871 kfree(fw_error_dump);
872}
873
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200874static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
875 struct iwl_fw_error_dump_data **dump_data)
876{
877 struct iwl_fw_error_dump_fifo *fifo_hdr;
878 u32 *fifo_data;
879 u32 fifo_len;
880 unsigned long flags;
881 int i, j;
882
883 if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags))
884 return;
885
886 /* Pull RXF data from all RXFs */
887 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
888 /*
889 * Keep aside the additional offset that might be needed for
890 * next RXF
891 */
892 u32 offset_diff = RXF_DIFF_FROM_PREV * i;
893
894 fifo_hdr = (void *)(*dump_data)->data;
895 fifo_data = (void *)fifo_hdr->data;
896 fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
897
898 /* No need to try to read the data if the length is 0 */
899 if (fifo_len == 0)
900 continue;
901
902 /* Add a TLV for the RXF */
903 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
904 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
905
906 fifo_hdr->fifo_num = cpu_to_le32(i);
907 fifo_hdr->available_bytes =
908 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
909 RXF_RD_D_SPACE +
910 offset_diff));
911 fifo_hdr->wr_ptr =
912 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
913 RXF_RD_WR_PTR +
914 offset_diff));
915 fifo_hdr->rd_ptr =
916 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
917 RXF_RD_RD_PTR +
918 offset_diff));
919 fifo_hdr->fence_ptr =
920 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
921 RXF_RD_FENCE_PTR +
922 offset_diff));
923 fifo_hdr->fence_mode =
924 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
925 RXF_SET_FENCE_MODE +
926 offset_diff));
927
928 /* Lock fence */
929 iwl_trans_write_prph(mvm->trans,
930 RXF_SET_FENCE_MODE + offset_diff, 0x1);
931 /* Set fence pointer to the same place like WR pointer */
932 iwl_trans_write_prph(mvm->trans,
933 RXF_LD_WR2FENCE + offset_diff, 0x1);
934 /* Set fence offset */
935 iwl_trans_write_prph(mvm->trans,
936 RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
937 0x0);
938
939 /* Read FIFO */
940 fifo_len /= sizeof(u32); /* Size in DWORDS */
941 for (j = 0; j < fifo_len; j++)
942 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
943 RXF_FIFO_RD_FENCE_INC +
944 offset_diff);
945 *dump_data = iwl_fw_error_next_data(*dump_data);
946 }
947
948 /* Pull TXF data from all TXFs */
949 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
950 /* Mark the number of TXF we're pulling now */
951 iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
952
953 fifo_hdr = (void *)(*dump_data)->data;
954 fifo_data = (void *)fifo_hdr->data;
955 fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
956
957 /* No need to try to read the data if the length is 0 */
958 if (fifo_len == 0)
959 continue;
960
961 /* Add a TLV for the FIFO */
962 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
963 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
964
965 fifo_hdr->fifo_num = cpu_to_le32(i);
966 fifo_hdr->available_bytes =
967 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
968 TXF_FIFO_ITEM_CNT));
969 fifo_hdr->wr_ptr =
970 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
971 TXF_WR_PTR));
972 fifo_hdr->rd_ptr =
973 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
974 TXF_RD_PTR));
975 fifo_hdr->fence_ptr =
976 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
977 TXF_FENCE_PTR));
978 fifo_hdr->fence_mode =
979 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
980 TXF_LOCK_FENCE));
981
982 /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
983 iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
984 TXF_WR_PTR);
985
986 /* Dummy-read to advance the read pointer to the head */
987 iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
988
989 /* Read FIFO */
990 fifo_len /= sizeof(u32); /* Size in DWORDS */
991 for (j = 0; j < fifo_len; j++)
992 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
993 TXF_READ_MODIFY_DATA);
994 *dump_data = iwl_fw_error_next_data(*dump_data);
995 }
996
997 iwl_trans_release_nic_access(mvm->trans, &flags);
998}
999
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001000void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
1001{
1002 if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert ||
1003 !mvm->fw_dump_desc)
1004 return;
1005
1006 kfree(mvm->fw_dump_desc);
1007 mvm->fw_dump_desc = NULL;
1008}
1009
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +03001010void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001011{
1012 struct iwl_fw_error_dump_file *dump_file;
1013 struct iwl_fw_error_dump_data *dump_data;
1014 struct iwl_fw_error_dump_info *dump_info;
Emmanuel Grumbacha549b292014-12-09 14:47:57 +02001015 struct iwl_fw_error_dump_mem *dump_mem;
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001016 struct iwl_fw_error_dump_trigger_desc *dump_trig;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001017 struct iwl_mvm_dump_ptrs *fw_error_dump;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001018 u32 sram_len, sram_ofs;
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001019 u32 file_len, fifo_data_len = 0;
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001020 u32 smem_len = mvm->cfg->smem_len;
Ido Yariv86138322014-12-10 12:39:27 -05001021 u32 sram2_len = mvm->cfg->dccm2_len;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001022
1023 lockdep_assert_held(&mvm->mutex);
1024
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001025 /* W/A for 8000 HW family A-step */
Ido Yariv86138322014-12-10 12:39:27 -05001026 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
1027 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP) {
1028 if (smem_len)
1029 smem_len = 0x38000;
1030
1031 if (sram2_len)
1032 sram2_len = 0x10000;
1033 }
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001034
Johannes Bergaadede62014-10-09 17:01:36 +02001035 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001036 if (!fw_error_dump)
1037 return;
1038
Liad Kaufmanf53bf4c2014-12-01 10:44:18 +02001039 /* SRAM - include stack CCM if driver knows the values for it */
1040 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
1041 const struct fw_img *img;
1042
1043 img = &mvm->fw->img[mvm->cur_ucode];
1044 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
1045 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
1046 } else {
1047 sram_ofs = mvm->cfg->dccm_offset;
1048 sram_len = mvm->cfg->dccm_len;
1049 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001050
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001051 /* reading RXF/TXF sizes */
1052 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
1053 struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
1054 int i;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001055
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001056 fifo_data_len = 0;
1057
1058 /* Count RXF size */
1059 for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
1060 if (!mem_cfg->rxfifo_size[i])
1061 continue;
1062
1063 /* Add header info */
1064 fifo_data_len += mem_cfg->rxfifo_size[i] +
1065 sizeof(*dump_data) +
1066 sizeof(struct iwl_fw_error_dump_fifo);
1067 }
1068
1069 for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
1070 if (!mem_cfg->txfifo_size[i])
1071 continue;
1072
1073 /* Add header info */
1074 fifo_data_len += mem_cfg->txfifo_size[i] +
1075 sizeof(*dump_data) +
1076 sizeof(struct iwl_fw_error_dump_fifo);
1077 }
1078 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001079
1080 file_len = sizeof(*dump_file) +
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001081 sizeof(*dump_data) * 2 +
Emmanuel Grumbacha549b292014-12-09 14:47:57 +02001082 sram_len + sizeof(*dump_mem) +
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001083 fifo_data_len +
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001084 sizeof(*dump_info);
1085
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001086 if (mvm->fw_dump_desc)
1087 file_len += sizeof(*dump_data) + sizeof(*dump_trig) +
1088 mvm->fw_dump_desc->len;
1089
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001090 /* Make room for the SMEM, if it exists */
1091 if (smem_len)
Emmanuel Grumbacha549b292014-12-09 14:47:57 +02001092 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001093
Ido Yariv86138322014-12-10 12:39:27 -05001094 /* Make room for the secondary SRAM, if it exists */
1095 if (sram2_len)
1096 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
1097
Emmanuel Grumbach5bfe6f52014-06-25 16:21:43 +03001098 dump_file = vzalloc(file_len);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001099 if (!dump_file) {
1100 kfree(fw_error_dump);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001101 iwl_mvm_free_fw_dump_desc(mvm);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001102 return;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001103 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001104
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001105 fw_error_dump->op_mode_ptr = dump_file;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001106
1107 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001108 dump_data = (void *)dump_file->data;
1109
1110 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
1111 dump_data->len = cpu_to_le32(sizeof(*dump_info));
1112 dump_info = (void *) dump_data->data;
1113 dump_info->device_family =
1114 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
1115 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
1116 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
Ido Yariv435da2c2014-12-11 16:11:01 -05001117 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001118 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
1119 sizeof(dump_info->fw_human_readable));
1120 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
1121 sizeof(dump_info->dev_human_readable));
1122 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
1123 sizeof(dump_info->bus_human_readable));
1124
1125 dump_data = iwl_fw_error_next_data(dump_data);
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001126 /* We only dump the FIFOs if the FW is in error state */
1127 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status))
1128 iwl_mvm_dump_fifos(mvm, &dump_data);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001129
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001130 if (mvm->fw_dump_desc) {
1131 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO);
1132 dump_data->len = cpu_to_le32(sizeof(*dump_trig) +
1133 mvm->fw_dump_desc->len);
1134 dump_trig = (void *)dump_data->data;
1135 memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc,
1136 sizeof(*dump_trig) + mvm->fw_dump_desc->len);
1137
1138 /* now we can free this copy */
1139 iwl_mvm_free_fw_dump_desc(mvm);
1140 dump_data = iwl_fw_error_next_data(dump_data);
1141 }
1142
Emmanuel Grumbacha549b292014-12-09 14:47:57 +02001143 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1144 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
1145 dump_mem = (void *)dump_data->data;
1146 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1147 dump_mem->offset = cpu_to_le32(sram_ofs);
1148 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001149 sram_len);
1150
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001151 if (smem_len) {
1152 dump_data = iwl_fw_error_next_data(dump_data);
Emmanuel Grumbache06d8432014-12-09 14:36:41 +02001153 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1154 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
1155 dump_mem = (void *)dump_data->data;
1156 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
1157 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001158 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
Emmanuel Grumbache06d8432014-12-09 14:36:41 +02001159 dump_mem->data, smem_len);
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001160 }
1161
Ido Yariv86138322014-12-10 12:39:27 -05001162 if (sram2_len) {
1163 dump_data = iwl_fw_error_next_data(dump_data);
1164 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1165 dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
1166 dump_mem = (void *)dump_data->data;
1167 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1168 dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
1169 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
1170 dump_mem->data, sram2_len);
1171 }
1172
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001173 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
1174 fw_error_dump->op_mode_len = file_len;
1175 if (fw_error_dump->trans_ptr)
1176 file_len += fw_error_dump->trans_ptr->len;
1177 dump_file->file_len = cpu_to_le32(file_len);
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +03001178
Johannes Bergaadede62014-10-09 17:01:36 +02001179 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
1180 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001181
1182 clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001183}
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001184
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001185struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
1186 .trig_desc = {
1187 .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
1188 },
1189};
1190
Johannes Berg8ca151b2013-01-24 14:25:36 +01001191static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1192{
Johannes Berg58629d92014-11-06 09:40:50 +01001193 /* clear the D3 reconfig, we only need it to avoid dumping a
1194 * firmware coredump on reconfiguration, we shouldn't do that
1195 * on D3->D0 transition
1196 */
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001197 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1198 mvm->fw_dump_desc = &iwl_mvm_dump_desc_assert;
Johannes Berg58629d92014-11-06 09:40:50 +01001199 iwl_mvm_fw_error_dump(mvm);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001200 }
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +02001201
Eliad Peller744cb692014-12-10 18:44:13 +02001202 /* cleanup all stale references (scan, roc), but keep the
1203 * ucode_down ref until reconfig is complete
1204 */
1205 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1206
Johannes Berg8ca151b2013-01-24 14:25:36 +01001207 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001208
1209 mvm->scan_status = IWL_MVM_SCAN_NONE;
Luciano Coelhob1873302014-08-08 17:12:07 +03001210 mvm->ps_disabled = false;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +02001211 mvm->calibrating = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001212
1213 /* just in case one was running */
1214 ieee80211_remain_on_channel_expired(mvm->hw);
1215
1216 ieee80211_iterate_active_interfaces_atomic(
1217 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1218 iwl_mvm_cleanup_iterator, mvm);
1219
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001220 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +02001221 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001222
1223 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001224 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1225 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001226 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001227 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1228 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
1229 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1230 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
1231 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
1232 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001233
1234 ieee80211_wake_queues(mvm->hw);
1235
Eliad Peller228670b2014-08-10 17:00:15 +03001236 /* clear any stale d0i3 state */
1237 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1238
Johannes Berg8ca151b2013-01-24 14:25:36 +01001239 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001240 mvm->rx_ba_sessions = 0;
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001241 mvm->fw_dbg_conf = FW_DBG_INVALID;
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001242
1243 /* keep statistics ticking */
1244 iwl_mvm_accu_radio_stats(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001245}
1246
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001247int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001248{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001249 int ret;
1250
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001251 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001252
1253 /* Clean up some internal and mac80211 state on restart */
1254 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1255 iwl_mvm_restart_cleanup(mvm);
1256
1257 ret = iwl_mvm_up(mvm);
Johannes Bergc47af222014-04-30 16:34:45 +02001258
1259 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1260 /* Something went wrong - we need to finish some cleanup
1261 * that normally iwl_mvm_mac_restart_complete() below
1262 * would do.
1263 */
1264 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1265 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1266 }
1267
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001268 return ret;
1269}
1270
1271static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1272{
1273 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1274 int ret;
1275
Eliad Peller37948fc2014-12-11 10:48:18 +02001276 /* Some hw restart cleanups must not hold the mutex */
1277 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1278 /*
1279 * Make sure we are out of d0i3. This is needed
1280 * to make sure the reference accounting is correct
1281 * (and there is no stale d0i3_exit_work).
1282 */
1283 wait_event_timeout(mvm->d0i3_exit_waitq,
1284 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1285 &mvm->status),
1286 HZ);
1287 }
1288
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001289 mutex_lock(&mvm->mutex);
1290 ret = __iwl_mvm_mac_start(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001291 mutex_unlock(&mvm->mutex);
1292
1293 return ret;
1294}
1295
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001296static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001297{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001298 int ret;
1299
1300 mutex_lock(&mvm->mutex);
1301
1302 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +02001303 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001304 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001305 if (ret)
1306 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1307 ret);
1308
Eliad Peller7498cf42014-01-16 17:10:44 +02001309 /* allow transport/FW low power modes */
1310 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1311
Arik Nemtsovcbd2ae22014-09-14 19:13:54 +03001312 /*
1313 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1314 * of packets the FW sent out, so we must reconnect.
1315 */
1316 iwl_mvm_teardown_tdls_peers(mvm);
1317
Johannes Berg8ca151b2013-01-24 14:25:36 +01001318 mutex_unlock(&mvm->mutex);
1319}
1320
Eliad Peller088070a2014-10-20 18:42:58 +03001321static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1322{
1323 bool exit_now;
1324
1325 if (!iwl_mvm_is_d0i3_supported(mvm))
1326 return;
1327
1328 mutex_lock(&mvm->d0i3_suspend_mutex);
1329 __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
1330 exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
1331 &mvm->d0i3_suspend_flags);
1332 mutex_unlock(&mvm->d0i3_suspend_mutex);
1333
1334 if (exit_now) {
1335 IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
1336 _iwl_mvm_exit_d0i3(mvm);
1337 }
Eliad Peller67359432014-12-09 15:23:54 +02001338
1339 if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND)
1340 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
1341 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1342 &mvm->status),
1343 HZ))
1344 WARN_ONCE(1, "D0i3 exit on resume timed out\n");
Eliad Peller088070a2014-10-20 18:42:58 +03001345}
1346
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001347static void
1348iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1349 enum ieee80211_reconfig_type reconfig_type)
1350{
1351 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1352
1353 switch (reconfig_type) {
1354 case IEEE80211_RECONFIG_TYPE_RESTART:
1355 iwl_mvm_restart_complete(mvm);
1356 break;
1357 case IEEE80211_RECONFIG_TYPE_SUSPEND:
Eliad Peller088070a2014-10-20 18:42:58 +03001358 iwl_mvm_resume_complete(mvm);
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001359 break;
1360 }
1361}
1362
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001363void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001364{
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001365 lockdep_assert_held(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +02001366
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001367 /* firmware counters are obviously reset now, but we shouldn't
1368 * partially track so also clear the fw_reset_accu counters.
1369 */
1370 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1371
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001372 /*
1373 * Disallow low power states when the FW is down by taking
1374 * the UCODE_DOWN ref. in case of ongoing hw restart the
1375 * ref is already taken, so don't take it again.
1376 */
1377 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1378 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
Eliad Peller7498cf42014-01-16 17:10:44 +02001379
Johannes Berg8ca151b2013-01-24 14:25:36 +01001380 /* async_handlers_wk is now blocked */
1381
1382 /*
1383 * The work item could be running or queued if the
1384 * ROC time event stops just as we get here.
1385 */
1386 cancel_work_sync(&mvm->roc_done_wk);
1387
1388 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001389
1390 iwl_mvm_async_handlers_purge(mvm);
1391 /* async_handlers_list is empty and will stay empty: HW is stopped */
1392
1393 /* the fw is stopped, the aux sta is dead: clean up driver state */
Johannes Berg712b24a2014-08-04 14:14:14 +02001394 iwl_mvm_del_aux_sta(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001395
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001396 /*
1397 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1398 * won't be called in this case).
1399 */
1400 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1401
Luciano Coelhobc448862014-08-20 11:49:11 +03001402 mvm->ucode_loaded = false;
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001403}
Luciano Coelhobc448862014-08-20 11:49:11 +03001404
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001405static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1406{
1407 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1408
1409 flush_work(&mvm->d0i3_exit_work);
1410 flush_work(&mvm->async_handlers_wk);
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001411 cancel_delayed_work_sync(&mvm->fw_dump_wk);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001412 iwl_mvm_free_fw_dump_desc(mvm);
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001413
1414 mutex_lock(&mvm->mutex);
1415 __iwl_mvm_mac_stop(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001416 mutex_unlock(&mvm->mutex);
1417
1418 /*
1419 * The worker might have been waiting for the mutex, let it run and
1420 * discover that its list is now empty.
1421 */
1422 cancel_work_sync(&mvm->async_handlers_wk);
1423}
1424
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001425static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1426{
1427 u16 i;
1428
1429 lockdep_assert_held(&mvm->mutex);
1430
1431 for (i = 0; i < NUM_PHY_CTX; i++)
1432 if (!mvm->phy_ctxts[i].ref)
1433 return &mvm->phy_ctxts[i];
1434
1435 IWL_ERR(mvm, "No available PHY context\n");
1436 return NULL;
1437}
1438
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001439static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1440 s8 tx_power)
1441{
1442 /* FW is in charge of regulatory enforcement */
1443 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
1444 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
1445 .pwr_restriction = cpu_to_le16(tx_power),
1446 };
1447
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001448 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001449 sizeof(reduce_txpwr_cmd),
1450 &reduce_txpwr_cmd);
1451}
1452
Johannes Berg8ca151b2013-01-24 14:25:36 +01001453static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1454 struct ieee80211_vif *vif)
1455{
1456 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1457 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1458 int ret;
1459
Emmanuel Grumbachaa5e1832015-03-07 19:35:37 +02001460 mvmvif->mvm = mvm;
1461
Johannes Berg8ca151b2013-01-24 14:25:36 +01001462 /*
Gregory Greenmand40fc482014-06-25 14:08:50 +02001463 * make sure D0i3 exit is completed, otherwise a target access
1464 * during tx queue configuration could be done when still in
1465 * D0i3 state.
1466 */
1467 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1468 if (ret)
1469 return ret;
1470
1471 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001472 * Not much to do here. The stack will not allow interface
1473 * types or combinations that we didn't advertise, so we
1474 * don't really have to check the types.
1475 */
1476
1477 mutex_lock(&mvm->mutex);
1478
Johannes Berg33cef922015-01-21 21:41:29 +01001479 /* make sure that beacon statistics don't go backwards with FW reset */
1480 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1481 mvmvif->beacon_stats.accu_num_beacons +=
1482 mvmvif->beacon_stats.num_beacons;
1483
Eliad Pellere89044d2013-07-16 17:33:26 +03001484 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001485 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1486 if (ret)
1487 goto out_unlock;
1488
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001489 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +03001490 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1491 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +03001492
1493 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001494 * The AP binding flow can be done only after the beacon
1495 * template is configured (which happens only in the mac80211
1496 * start_ap() flow), and adding the broadcast station can happen
1497 * only after the binding.
1498 * In addition, since modifying the MAC before adding a bcast
1499 * station is not allowed by the FW, delay the adding of MAC context to
1500 * the point where we can also add the bcast station.
1501 * In short: there's not much we can do at this point, other than
1502 * allocating resources :)
1503 */
Johannes Berg5023d962013-07-31 14:07:43 +02001504 if (vif->type == NL80211_IFTYPE_AP ||
1505 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg013290a2014-08-04 13:38:48 +02001506 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001507 if (ret) {
1508 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1509 goto out_release;
1510 }
1511
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +03001512 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001513 goto out_unlock;
1514 }
1515
Johannes Berg8ca151b2013-01-24 14:25:36 +01001516 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1517 if (ret)
1518 goto out_release;
1519
Arik Nemtsov999609f2014-05-15 17:31:51 +03001520 ret = iwl_mvm_power_update_mac(mvm);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001521 if (ret)
Luciano Coelhofd66fc12015-01-27 15:06:57 +02001522 goto out_remove_mac;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001523
Hila Gonen7df15b12012-12-12 11:16:19 +02001524 /* beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001525 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001526 if (ret)
1527 goto out_remove_mac;
1528
Hila Gonen7df15b12012-12-12 11:16:19 +02001529 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +03001530 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001531 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001532 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1533 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +02001534 }
1535
Johannes Berg8ca151b2013-01-24 14:25:36 +01001536 /*
1537 * P2P_DEVICE interface does not have a channel context assigned to it,
1538 * so a dedicated PHY context is allocated to it and the corresponding
1539 * MAC context is bound to it at this stage.
1540 */
1541 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001542
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001543 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1544 if (!mvmvif->phy_ctxt) {
1545 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001546 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001547 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001548
Ilan Peer53a9d612013-04-28 11:55:08 +03001549 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001550 ret = iwl_mvm_binding_add_vif(mvm, vif);
1551 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +03001552 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001553
Johannes Berg013290a2014-08-04 13:38:48 +02001554 ret = iwl_mvm_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001555 if (ret)
1556 goto out_unbind;
1557
1558 /* Save a pointer to p2p device vif, so it can later be used to
1559 * update the p2p device MAC when a GO is started/stopped */
1560 mvm->p2p_device_vif = vif;
1561 }
1562
Johannes Berg63494372013-03-26 10:47:53 +01001563 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001564 goto out_unlock;
1565
1566 out_unbind:
1567 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +03001568 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001569 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001570 out_free_bf:
1571 if (mvm->bf_allowed_vif == mvmvif) {
1572 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001573 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1574 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001575 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001576 out_remove_mac:
1577 mvmvif->phy_ctxt = NULL;
1578 iwl_mvm_mac_ctxt_remove(mvm, vif);
1579 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001580 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1581 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001582
Johannes Berg8ca151b2013-01-24 14:25:36 +01001583 iwl_mvm_mac_ctxt_release(mvm, vif);
1584 out_unlock:
1585 mutex_unlock(&mvm->mutex);
1586
Gregory Greenmand40fc482014-06-25 14:08:50 +02001587 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1588
Johannes Berg8ca151b2013-01-24 14:25:36 +01001589 return ret;
1590}
1591
Johannes Berg38a12b52013-02-22 14:07:56 +01001592static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1593 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001594{
Arik Nemtsovd92b732e2014-09-21 19:00:42 +03001595 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001596
1597 if (tfd_msk) {
1598 mutex_lock(&mvm->mutex);
1599 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1600 mutex_unlock(&mvm->mutex);
1601 }
1602
1603 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1604 /*
1605 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1606 * We assume here that all the packets sent to the OFFCHANNEL
1607 * queue are sent in ROC session.
1608 */
1609 flush_work(&mvm->roc_done_wk);
1610 } else {
1611 /*
1612 * By now, all the AC queues are empty. The AGG queues are
1613 * empty too. We already got all the Tx responses for all the
1614 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +03001615 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001616 */
1617 flush_work(&mvm->sta_drained_wk);
1618 }
Johannes Berg38a12b52013-02-22 14:07:56 +01001619}
1620
1621static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1622 struct ieee80211_vif *vif)
1623{
1624 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1625 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1626
1627 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001628
1629 mutex_lock(&mvm->mutex);
1630
Hila Gonen7df15b12012-12-12 11:16:19 +02001631 if (mvm->bf_allowed_vif == mvmvif) {
1632 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001633 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1634 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +02001635 }
1636
Johannes Berg63494372013-03-26 10:47:53 +01001637 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1638
Johannes Berg8ca151b2013-01-24 14:25:36 +01001639 /*
1640 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +01001641 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001642 */
Johannes Berg5023d962013-07-31 14:07:43 +02001643 if (vif->type == NL80211_IFTYPE_AP ||
1644 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +03001645#ifdef CONFIG_NL80211_TESTMODE
1646 if (vif == mvm->noa_vif) {
1647 mvm->noa_vif = NULL;
1648 mvm->noa_duration = 0;
1649 }
1650#endif
Johannes Berg013290a2014-08-04 13:38:48 +02001651 iwl_mvm_dealloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001652 goto out_release;
1653 }
1654
1655 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1656 mvm->p2p_device_vif = NULL;
Johannes Berg013290a2014-08-04 13:38:48 +02001657 iwl_mvm_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001658 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001659 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001660 mvmvif->phy_ctxt = NULL;
1661 }
1662
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001663 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001664 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001665
Arik Nemtsov999609f2014-05-15 17:31:51 +03001666 iwl_mvm_power_update_mac(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001667 iwl_mvm_mac_ctxt_remove(mvm, vif);
1668
1669out_release:
1670 iwl_mvm_mac_ctxt_release(mvm, vif);
1671 mutex_unlock(&mvm->mutex);
1672}
1673
1674static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1675{
1676 return 0;
1677}
1678
Eliad Pellere59647e2013-11-28 14:08:50 +02001679struct iwl_mvm_mc_iter_data {
1680 struct iwl_mvm *mvm;
1681 int port_id;
1682};
1683
1684static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1685 struct ieee80211_vif *vif)
1686{
1687 struct iwl_mvm_mc_iter_data *data = _data;
1688 struct iwl_mvm *mvm = data->mvm;
1689 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1690 int ret, len;
1691
1692 /* if we don't have free ports, mcast frames will be dropped */
1693 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1694 return;
1695
1696 if (vif->type != NL80211_IFTYPE_STATION ||
1697 !vif->bss_conf.assoc)
1698 return;
1699
1700 cmd->port_id = data->port_id++;
1701 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1702 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1703
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001704 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
Eliad Pellere59647e2013-11-28 14:08:50 +02001705 if (ret)
1706 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1707}
1708
1709static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1710{
1711 struct iwl_mvm_mc_iter_data iter_data = {
1712 .mvm = mvm,
1713 };
1714
1715 lockdep_assert_held(&mvm->mutex);
1716
1717 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1718 return;
1719
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001720 ieee80211_iterate_active_interfaces_atomic(
Eliad Pellere59647e2013-11-28 14:08:50 +02001721 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1722 iwl_mvm_mc_iface_iterator, &iter_data);
1723}
1724
1725static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1726 struct netdev_hw_addr_list *mc_list)
1727{
1728 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1729 struct iwl_mcast_filter_cmd *cmd;
1730 struct netdev_hw_addr *addr;
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001731 int addr_count;
1732 bool pass_all;
Eliad Pellere59647e2013-11-28 14:08:50 +02001733 int len;
1734
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001735 addr_count = netdev_hw_addr_list_count(mc_list);
1736 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1737 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1738 if (pass_all)
Eliad Pellere59647e2013-11-28 14:08:50 +02001739 addr_count = 0;
Eliad Pellere59647e2013-11-28 14:08:50 +02001740
1741 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1742 cmd = kzalloc(len, GFP_ATOMIC);
1743 if (!cmd)
1744 return 0;
1745
1746 if (pass_all) {
1747 cmd->pass_all = 1;
1748 return (u64)(unsigned long)cmd;
1749 }
1750
1751 netdev_hw_addr_list_for_each(addr, mc_list) {
1752 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1753 cmd->count, addr->addr);
1754 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1755 addr->addr, ETH_ALEN);
1756 cmd->count++;
1757 }
1758
1759 return (u64)(unsigned long)cmd;
1760}
1761
Johannes Berg8ca151b2013-01-24 14:25:36 +01001762static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1763 unsigned int changed_flags,
1764 unsigned int *total_flags,
1765 u64 multicast)
1766{
Eliad Pellere59647e2013-11-28 14:08:50 +02001767 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1768 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1769
1770 mutex_lock(&mvm->mutex);
1771
1772 /* replace previous configuration */
1773 kfree(mvm->mcast_filter_cmd);
1774 mvm->mcast_filter_cmd = cmd;
1775
1776 if (!cmd)
1777 goto out;
1778
1779 iwl_mvm_recalc_multicast(mvm);
1780out:
1781 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001782 *total_flags = 0;
1783}
1784
Eliad Pellerc87163b2014-01-08 10:11:11 +02001785#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1786struct iwl_bcast_iter_data {
1787 struct iwl_mvm *mvm;
1788 struct iwl_bcast_filter_cmd *cmd;
1789 u8 current_filter;
1790};
1791
1792static void
1793iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1794 const struct iwl_fw_bcast_filter *in_filter,
1795 struct iwl_fw_bcast_filter *out_filter)
1796{
1797 struct iwl_fw_bcast_filter_attr *attr;
1798 int i;
1799
1800 memcpy(out_filter, in_filter, sizeof(*out_filter));
1801
1802 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1803 attr = &out_filter->attrs[i];
1804
1805 if (!attr->mask)
1806 break;
1807
Eliad Peller2ee8f022014-01-13 19:07:09 +02001808 switch (attr->reserved1) {
1809 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1810 if (vif->bss_conf.arp_addr_cnt != 1) {
1811 attr->mask = 0;
1812 continue;
1813 }
1814
1815 attr->val = vif->bss_conf.arp_addr_list[0];
1816 break;
1817 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1818 attr->val = *(__be32 *)&vif->addr[2];
1819 break;
1820 default:
1821 break;
1822 }
1823 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001824 out_filter->num_attrs++;
1825 }
1826}
1827
1828static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1829 struct ieee80211_vif *vif)
1830{
1831 struct iwl_bcast_iter_data *data = _data;
1832 struct iwl_mvm *mvm = data->mvm;
1833 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1834 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1835 struct iwl_fw_bcast_mac *bcast_mac;
1836 int i;
1837
1838 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1839 return;
1840
1841 bcast_mac = &cmd->macs[mvmvif->id];
1842
Ilan Peere48393e2014-05-22 11:19:02 +03001843 /*
1844 * enable filtering only for associated stations, but not for P2P
1845 * Clients
1846 */
1847 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1848 !vif->bss_conf.assoc)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001849 return;
1850
1851 bcast_mac->default_discard = 1;
1852
1853 /* copy all configured filters */
1854 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1855 /*
1856 * Make sure we don't exceed our filters limit.
1857 * if there is still a valid filter to be configured,
1858 * be on the safe side and just allow bcast for this mac.
1859 */
1860 if (WARN_ON_ONCE(data->current_filter >=
1861 ARRAY_SIZE(cmd->filters))) {
1862 bcast_mac->default_discard = 0;
1863 bcast_mac->attached_filters = 0;
1864 break;
1865 }
1866
1867 iwl_mvm_set_bcast_filter(vif,
1868 &mvm->bcast_filters[i],
1869 &cmd->filters[data->current_filter]);
1870
1871 /* skip current filter if it contains no attributes */
1872 if (!cmd->filters[data->current_filter].num_attrs)
1873 continue;
1874
1875 /* attach the filter to current mac */
1876 bcast_mac->attached_filters |=
1877 cpu_to_le16(BIT(data->current_filter));
1878
1879 data->current_filter++;
1880 }
1881}
1882
Eliad Pellerde06a592014-01-08 10:11:12 +02001883bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1884 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001885{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001886 struct iwl_bcast_iter_data iter_data = {
1887 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001888 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001889 };
1890
Max Stepanov3b8983b2014-10-15 11:27:16 +03001891 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1892 return false;
1893
Eliad Pellerde06a592014-01-08 10:11:12 +02001894 memset(cmd, 0, sizeof(*cmd));
1895 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1896 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1897
1898#ifdef CONFIG_IWLWIFI_DEBUGFS
1899 /* use debugfs filters/macs if override is configured */
1900 if (mvm->dbgfs_bcast_filtering.override) {
1901 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1902 sizeof(cmd->filters));
1903 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1904 sizeof(cmd->macs));
1905 return true;
1906 }
1907#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001908
1909 /* if no filters are configured, do nothing */
1910 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001911 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001912
1913 /* configure and attach these filters for each associated sta vif */
1914 ieee80211_iterate_active_interfaces(
1915 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1916 iwl_mvm_bcast_filter_iterator, &iter_data);
1917
Eliad Pellerde06a592014-01-08 10:11:12 +02001918 return true;
1919}
1920static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1921 struct ieee80211_vif *vif)
1922{
1923 struct iwl_bcast_filter_cmd cmd;
1924
1925 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1926 return 0;
1927
1928 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1929 return 0;
1930
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001931 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001932 sizeof(cmd), &cmd);
1933}
1934#else
1935static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1936 struct ieee80211_vif *vif)
1937{
1938 return 0;
1939}
1940#endif
1941
Johannes Berg8ca151b2013-01-24 14:25:36 +01001942static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1943 struct ieee80211_vif *vif,
1944 struct ieee80211_bss_conf *bss_conf,
1945 u32 changes)
1946{
1947 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1948 int ret;
1949
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001950 /*
1951 * Re-calculate the tsf id, as the master-slave relations depend on the
1952 * beacon interval, which was not known when the station interface was
1953 * added.
1954 */
1955 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1956 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1957
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001958 /*
1959 * If we're not associated yet, take the (new) BSSID before associating
1960 * so the firmware knows. If we're already associated, then use the old
1961 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1962 * branch for disassociation below.
1963 */
1964 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1965 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1966
1967 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001968 if (ret)
1969 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1970
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001971 /* after sending it once, adopt mac80211 data */
1972 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1973 mvmvif->associated = bss_conf->assoc;
1974
Johannes Berg8ca151b2013-01-24 14:25:36 +01001975 if (changes & BSS_CHANGED_ASSOC) {
1976 if (bss_conf->assoc) {
Johannes Berg33cef922015-01-21 21:41:29 +01001977 /* clear statistics to get clean beacon counter */
1978 iwl_mvm_request_statistics(mvm, true);
1979 memset(&mvmvif->beacon_stats, 0,
1980 sizeof(mvmvif->beacon_stats));
1981
Johannes Berg8ca151b2013-01-24 14:25:36 +01001982 /* add quota for this interface */
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001983 ret = iwl_mvm_update_quotas(mvm, true, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001984 if (ret) {
1985 IWL_ERR(mvm, "failed to update quotas\n");
1986 return;
1987 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001988
1989 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1990 &mvm->status)) {
1991 /*
1992 * If we're restarting then the firmware will
1993 * obviously have lost synchronisation with
1994 * the AP. It will attempt to synchronise by
1995 * itself, but we can make it more reliable by
1996 * scheduling a session protection time event.
1997 *
1998 * The firmware needs to receive a beacon to
1999 * catch up with synchronisation, use 110% of
2000 * the beacon interval.
2001 *
2002 * Set a large maximum delay to allow for more
2003 * than a single interface.
2004 */
2005 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2006 iwl_mvm_protect_session(mvm, vif, dur, dur,
Liad Kaufmand20d37b2014-07-06 17:14:39 +03002007 5 * dur, false);
Johannes Berg016d27e2013-05-03 11:16:15 +02002008 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002009
2010 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03002011 iwl_mvm_power_vif_assoc(mvm, vif);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03002012 if (vif->p2p) {
Eliad Peller29a90a42013-11-05 14:06:29 +02002013 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03002014 iwl_mvm_update_smps(mvm, vif,
2015 IWL_MVM_SMPS_REQ_PROT,
2016 IEEE80211_SMPS_DYNAMIC);
2017 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002018 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002019 /*
2020 * If update fails - SF might be running in associated
2021 * mode while disassociated - which is forbidden.
2022 */
2023 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2024 "Failed to update SF upon disassociation\n");
2025
Johannes Berg8ca151b2013-01-24 14:25:36 +01002026 /* remove AP station now that the MAC is unassoc */
2027 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
2028 if (ret)
2029 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02002030
2031 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2032 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002033 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
2034 /* remove quota for this interface */
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02002035 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002036 if (ret)
2037 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02002038
2039 if (vif->p2p)
2040 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002041
2042 /* this will take the cleared BSSID from bss_conf */
2043 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2044 if (ret)
2045 IWL_ERR(mvm,
2046 "failed to update MAC %pM (clear after unassoc)\n",
2047 vif->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002048 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002049
Eliad Pellere59647e2013-11-28 14:08:50 +02002050 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02002051 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02002052
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002053 /* reset rssi values */
2054 mvmvif->bf_data.ave_beacon_signal = 0;
2055
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002056 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02002057 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2058 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03002059 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01002060 /*
2061 * We received a beacon _after_ association so
2062 * remove the session protection.
2063 */
2064 iwl_mvm_remove_time_event(mvm, mvmvif,
2065 &mvmvif->time_event_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002066 }
Eran Hararycc87d322014-07-15 14:04:23 +03002067
2068 if (changes & BSS_CHANGED_BEACON_INFO) {
2069 iwl_mvm_sf_update(mvm, vif, false);
2070 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2071 }
2072
Johannes Berg1bc10d32014-08-26 14:25:46 +02002073 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
2074 ret = iwl_mvm_power_update_mac(mvm);
2075 if (ret)
2076 IWL_ERR(mvm, "failed to update power mode\n");
2077 }
2078
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03002079 if (changes & BSS_CHANGED_TXPOWER) {
2080 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2081 bss_conf->txpower);
2082 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2083 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002084
2085 if (changes & BSS_CHANGED_CQM) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002086 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002087 /* reset cqm events tracking */
2088 mvmvif->bf_data.last_cqm_event = 0;
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002089 if (mvmvif->bf_data.bf_enabled) {
2090 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2091 if (ret)
2092 IWL_ERR(mvm,
2093 "failed to update CQM thresholds\n");
2094 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002095 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02002096
2097 if (changes & BSS_CHANGED_ARP_FILTER) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002098 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
Eliad Peller2ee8f022014-01-13 19:07:09 +02002099 iwl_mvm_configure_bcast_filter(mvm, vif);
2100 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002101}
2102
Johannes Berg5023d962013-07-31 14:07:43 +02002103static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2104 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002105{
2106 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2107 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2108 int ret;
2109
Eliad Peller576eeee2014-07-01 18:38:38 +03002110 /*
2111 * iwl_mvm_mac_ctxt_add() might read directly from the device
2112 * (the system time), so make sure it is available.
2113 */
2114 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2115 if (ret)
2116 return ret;
2117
Johannes Berg8ca151b2013-01-24 14:25:36 +01002118 mutex_lock(&mvm->mutex);
2119
2120 /* Send the beacon template */
2121 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2122 if (ret)
2123 goto out_unlock;
2124
Ilan Peer6e97b0d2013-12-23 22:18:02 +02002125 /*
2126 * Re-calculate the tsf id, as the master-slave relations depend on the
2127 * beacon interval, which was not known when the AP interface was added.
2128 */
2129 if (vif->type == NL80211_IFTYPE_AP)
2130 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2131
Johannes Berg8ca151b2013-01-24 14:25:36 +01002132 /* Add the mac context */
2133 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2134 if (ret)
2135 goto out_unlock;
2136
2137 /* Perform the binding */
2138 ret = iwl_mvm_binding_add_vif(mvm, vif);
2139 if (ret)
2140 goto out_remove;
2141
Johannes Berg8ca151b2013-01-24 14:25:36 +01002142 /* Send the bcast station. At this stage the TBTT and DTIM time events
2143 * are added and applied to the scheduler */
Johannes Berg013290a2014-08-04 13:38:48 +02002144 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002145 if (ret)
2146 goto out_unbind;
2147
Ilan Peer5691e212013-12-31 21:05:50 +02002148 /* must be set before quota calculations */
2149 mvmvif->ap_ibss_active = true;
2150
Ilan Peera11e1442013-12-31 21:19:55 +02002151 /* power updated needs to be done before quotas */
Arik Nemtsov999609f2014-05-15 17:31:51 +03002152 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002153
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02002154 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002155 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02002156 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002157
Johannes Berg5023d962013-07-31 14:07:43 +02002158 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002159 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002160 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002161
Eliad Peller29a90a42013-11-05 14:06:29 +02002162 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2163
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002164 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002165
Arik Nemtsovf6972672014-06-15 16:03:55 +03002166 /* we don't support TDLS during DCM */
2167 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2168 iwl_mvm_teardown_tdls_peers(mvm);
2169
Johannes Berg8ca151b2013-01-24 14:25:36 +01002170 mutex_unlock(&mvm->mutex);
2171 return 0;
2172
Ilan Peera11e1442013-12-31 21:19:55 +02002173out_quota_failed:
Arik Nemtsov999609f2014-05-15 17:31:51 +03002174 iwl_mvm_power_update_mac(mvm);
Ilan Peer5691e212013-12-31 21:05:50 +02002175 mvmvif->ap_ibss_active = false;
Johannes Berg013290a2014-08-04 13:38:48 +02002176 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002177out_unbind:
2178 iwl_mvm_binding_remove_vif(mvm, vif);
2179out_remove:
2180 iwl_mvm_mac_ctxt_remove(mvm, vif);
2181out_unlock:
2182 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002183 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002184 return ret;
2185}
2186
Johannes Berg5023d962013-07-31 14:07:43 +02002187static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2188 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002189{
2190 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2191 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2192
Johannes Berg38a12b52013-02-22 14:07:56 +01002193 iwl_mvm_prepare_mac_removal(mvm, vif);
2194
Johannes Berg8ca151b2013-01-24 14:25:36 +01002195 mutex_lock(&mvm->mutex);
2196
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002197 /* Handle AP stop while in CSA */
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002198 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2199 iwl_mvm_remove_time_event(mvm, mvmvif,
2200 &mvmvif->time_event_data);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002201 RCU_INIT_POINTER(mvm->csa_vif, NULL);
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002202 }
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002203
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002204 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2205 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2206 mvm->csa_tx_block_bcn_timeout = 0;
2207 }
2208
Johannes Berg5023d962013-07-31 14:07:43 +02002209 mvmvif->ap_ibss_active = false;
David Spinadel1c87bba2014-02-27 16:41:52 +02002210 mvm->ap_last_beacon_gp2 = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002211
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002212 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002213
Eliad Peller29a90a42013-11-05 14:06:29 +02002214 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2215
Johannes Berg5023d962013-07-31 14:07:43 +02002216 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002217 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002218 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002219
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02002220 iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg013290a2014-08-04 13:38:48 +02002221 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002222 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02002223
Arik Nemtsov999609f2014-05-15 17:31:51 +03002224 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002225
Johannes Berg8ca151b2013-01-24 14:25:36 +01002226 iwl_mvm_mac_ctxt_remove(mvm, vif);
2227
2228 mutex_unlock(&mvm->mutex);
2229}
2230
Johannes Berg5023d962013-07-31 14:07:43 +02002231static void
2232iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2233 struct ieee80211_vif *vif,
2234 struct ieee80211_bss_conf *bss_conf,
2235 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002236{
Ilan Peerbe2056f2013-12-04 16:47:14 +02002237 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02002238
Ilan Peerbe2056f2013-12-04 16:47:14 +02002239 /* Changes will be applied when the AP/IBSS is started */
2240 if (!mvmvif->ap_ibss_active)
2241 return;
2242
Johannes Berg863230da2013-12-04 17:08:40 +01002243 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
Johannes Bergf7d8b702014-09-09 15:49:19 +02002244 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002245 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
Johannes Berg863230da2013-12-04 17:08:40 +01002246 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02002247
Johannes Berg8ca151b2013-01-24 14:25:36 +01002248 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01002249 if (changes & BSS_CHANGED_BEACON &&
2250 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2251 IWL_WARN(mvm, "Failed updating beacon data\n");
Haim Dreyfuss79b7a692014-09-14 12:40:00 +03002252
2253 if (changes & BSS_CHANGED_TXPOWER) {
2254 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2255 bss_conf->txpower);
2256 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2257 }
2258
Johannes Berg8ca151b2013-01-24 14:25:36 +01002259}
2260
2261static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2262 struct ieee80211_vif *vif,
2263 struct ieee80211_bss_conf *bss_conf,
2264 u32 changes)
2265{
2266 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2267
Eliad Peller576eeee2014-07-01 18:38:38 +03002268 /*
2269 * iwl_mvm_bss_info_changed_station() might call
2270 * iwl_mvm_protect_session(), which reads directly from
2271 * the device (the system time), so make sure it is available.
2272 */
2273 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2274 return;
2275
Johannes Berg8ca151b2013-01-24 14:25:36 +01002276 mutex_lock(&mvm->mutex);
2277
David Spinadel723f02e2014-04-27 09:54:54 +03002278 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
David Spinadelfb98be52014-05-04 12:51:10 +03002279 iwl_mvm_scan_offload_stop(mvm, true);
David Spinadel723f02e2014-04-27 09:54:54 +03002280
Johannes Berg8ca151b2013-01-24 14:25:36 +01002281 switch (vif->type) {
2282 case NL80211_IFTYPE_STATION:
2283 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2284 break;
2285 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002286 case NL80211_IFTYPE_ADHOC:
2287 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002288 break;
2289 default:
2290 /* shouldn't happen */
2291 WARN_ON_ONCE(1);
2292 }
2293
2294 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002295 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002296}
2297
Eliad Peller4660dfb2014-06-22 18:15:59 +03002298static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
2299 enum iwl_scan_status scan_type)
2300{
2301 int ret;
2302 bool wait_for_handlers = false;
2303
2304 mutex_lock(&mvm->mutex);
2305
2306 if (mvm->scan_status != scan_type) {
2307 ret = 0;
2308 /* make sure there are no pending notifications */
2309 wait_for_handlers = true;
2310 goto out;
2311 }
2312
2313 switch (scan_type) {
2314 case IWL_MVM_SCAN_SCHED:
2315 ret = iwl_mvm_scan_offload_stop(mvm, true);
2316 break;
2317 case IWL_MVM_SCAN_OS:
2318 ret = iwl_mvm_cancel_scan(mvm);
2319 break;
2320 case IWL_MVM_SCAN_NONE:
2321 default:
2322 WARN_ON_ONCE(1);
2323 ret = -EINVAL;
2324 break;
2325 }
2326 if (ret)
2327 goto out;
2328
2329 wait_for_handlers = true;
2330out:
2331 mutex_unlock(&mvm->mutex);
2332
2333 /* make sure we consume the completion notification */
2334 if (wait_for_handlers)
2335 iwl_mvm_wait_for_async_handlers(mvm);
2336
2337 return ret;
2338}
Johannes Berg8ca151b2013-01-24 14:25:36 +01002339static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2340 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02002341 struct ieee80211_scan_request *hw_req)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002342{
2343 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
David Spinadelc56ef672014-02-05 15:21:13 +02002344 struct cfg80211_scan_request *req = &hw_req->req;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002345 int ret;
2346
David Spinadel762533b2014-06-05 11:20:43 +03002347 if (req->n_channels == 0 ||
2348 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002349 return -EINVAL;
2350
David Spinadeld2496222014-05-20 12:46:37 +03002351 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2352 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
2353 if (ret)
2354 return ret;
2355 }
Eliad Peller4660dfb2014-06-22 18:15:59 +03002356
Johannes Berg8ca151b2013-01-24 14:25:36 +01002357 mutex_lock(&mvm->mutex);
2358
Arik Nemtsov88931cc2014-03-05 12:26:15 +02002359 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
2360 IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
2361 ret = -EBUSY;
2362 goto out;
2363 }
2364
Eliad Peller4660dfb2014-06-22 18:15:59 +03002365 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002366 ret = -EBUSY;
Arik Nemtsov519e2022013-10-17 17:51:35 +03002367 goto out;
2368 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002369
Arik Nemtsov519e2022013-10-17 17:51:35 +03002370 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
2371
David Spinadelb975e552014-11-17 12:30:05 +02002372 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
David Spinadeld2496222014-05-20 12:46:37 +03002373 ret = iwl_mvm_scan_umac(mvm, vif, hw_req);
David Spinadelfb98be52014-05-04 12:51:10 +03002374 else
Luciano Coelho1f940382015-02-10 13:03:38 +02002375 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
David Spinadelfb98be52014-05-04 12:51:10 +03002376
Arik Nemtsov519e2022013-10-17 17:51:35 +03002377 if (ret)
2378 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2379out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002380 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002381 return ret;
2382}
2383
2384static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2385 struct ieee80211_vif *vif)
2386{
2387 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2388
2389 mutex_lock(&mvm->mutex);
2390
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002391 /* Due to a race condition, it's possible that mac80211 asks
2392 * us to stop a hw_scan when it's already stopped. This can
2393 * happen, for instance, if we stopped the scan ourselves,
2394 * called ieee80211_scan_completed() and the userspace called
2395 * cancel scan scan before ieee80211_scan_work() could run.
2396 * To handle that, simply return if the scan is not running.
2397 */
2398 /* FIXME: for now, we ignore this race for UMAC scans, since
2399 * they don't set the scan_status.
2400 */
2401 if ((mvm->scan_status == IWL_MVM_SCAN_OS) ||
2402 (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2403 iwl_mvm_cancel_scan(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002404
2405 mutex_unlock(&mvm->mutex);
2406}
2407
2408static void
2409iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002410 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002411 int num_frames,
2412 enum ieee80211_frame_release_type reason,
2413 bool more_data)
2414{
2415 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002416
Johannes Berg3e56ead2013-02-15 22:23:18 +01002417 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002418
Johannes Berg3e56ead2013-02-15 22:23:18 +01002419 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2420 tids, more_data, false);
2421}
2422
2423static void
2424iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2425 struct ieee80211_sta *sta, u16 tids,
2426 int num_frames,
2427 enum ieee80211_frame_release_type reason,
2428 bool more_data)
2429{
2430 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2431
2432 /* Called when we need to transmit (a) frame(s) from agg queue */
2433
2434 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2435 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002436}
2437
2438static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2439 struct ieee80211_vif *vif,
2440 enum sta_notify_cmd cmd,
2441 struct ieee80211_sta *sta)
2442{
2443 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01002444 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002445 unsigned long txqs = 0, tids = 0;
Johannes Berg3e56ead2013-02-15 22:23:18 +01002446 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002447
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002448 spin_lock_bh(&mvmsta->lock);
2449 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2450 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2451
2452 if (tid_data->state != IWL_AGG_ON &&
2453 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2454 continue;
2455
2456 __set_bit(tid_data->txq_id, &txqs);
2457
2458 if (iwl_mvm_tid_queued(tid_data) == 0)
2459 continue;
2460
2461 __set_bit(tid, &tids);
2462 }
2463
Johannes Berg8ca151b2013-01-24 14:25:36 +01002464 switch (cmd) {
2465 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03002466 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002467 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01002468
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002469 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
Johannes Berg3e56ead2013-02-15 22:23:18 +01002470 ieee80211_sta_set_buffered(sta, tid, true);
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002471
2472 if (txqs)
2473 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002474 /*
2475 * The fw updates the STA to be asleep. Tx packets on the Tx
2476 * queues to this station will not be transmitted. The fw will
2477 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2478 */
2479 break;
2480 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02002481 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01002482 break;
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002483
2484 if (txqs)
2485 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
Johannes Berg9cc40712013-02-15 22:47:48 +01002486 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002487 break;
2488 default:
2489 break;
2490 }
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002491 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002492}
2493
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002494static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2495 struct ieee80211_vif *vif,
2496 struct ieee80211_sta *sta)
2497{
2498 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01002499 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002500
2501 /*
2502 * This is called before mac80211 does RCU synchronisation,
2503 * so here we already invalidate our internal RCU-protected
2504 * station pointer. The rest of the code will thus no longer
2505 * be able to find the station this way, and we don't rely
2506 * on further RCU synchronisation after the sta_state()
2507 * callback deleted the station.
2508 */
2509 mutex_lock(&mvm->mutex);
2510 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2511 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2512 ERR_PTR(-ENOENT));
2513 mutex_unlock(&mvm->mutex);
2514}
2515
Johannes Bergbd1ba662014-11-13 20:53:45 +01002516static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2517 const u8 *bssid)
2518{
2519 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2520 return;
2521
2522 if (iwlwifi_mod_params.uapsd_disable) {
2523 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2524 return;
2525 }
2526
2527 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2528}
2529
Johannes Berg8ca151b2013-01-24 14:25:36 +01002530static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2531 struct ieee80211_vif *vif,
2532 struct ieee80211_sta *sta,
2533 enum ieee80211_sta_state old_state,
2534 enum ieee80211_sta_state new_state)
2535{
2536 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2537 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2538 int ret;
2539
2540 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2541 sta->addr, old_state, new_state);
2542
2543 /* this would be a mac80211 bug ... but don't crash */
2544 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2545 return -EINVAL;
2546
2547 /* if a STA is being removed, reuse its ID */
2548 flush_work(&mvm->sta_drained_wk);
2549
2550 mutex_lock(&mvm->mutex);
2551 if (old_state == IEEE80211_STA_NOTEXIST &&
2552 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02002553 /*
2554 * Firmware bug - it'll crash if the beacon interval is less
2555 * than 16. We can't avoid connecting at all, so refuse the
2556 * station state change, this will cause mac80211 to abandon
2557 * attempts to connect to this AP, and eventually wpa_s will
2558 * blacklist the AP...
2559 */
2560 if (vif->type == NL80211_IFTYPE_STATION &&
2561 vif->bss_conf.beacon_int < 16) {
2562 IWL_ERR(mvm,
2563 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2564 sta->addr, vif->bss_conf.beacon_int);
2565 ret = -EINVAL;
2566 goto out_unlock;
2567 }
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002568
2569 if (sta->tdls &&
2570 (vif->p2p ||
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002571 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2572 IWL_MVM_TDLS_STA_COUNT ||
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002573 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2574 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2575 ret = -EBUSY;
2576 goto out_unlock;
2577 }
2578
Johannes Berg8ca151b2013-01-24 14:25:36 +01002579 ret = iwl_mvm_add_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002580 if (sta->tdls && ret == 0)
2581 iwl_mvm_recalc_tdls_state(mvm, vif, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002582 } else if (old_state == IEEE80211_STA_NONE &&
2583 new_state == IEEE80211_STA_AUTH) {
Haim Dreyfusse820c2d2014-04-06 11:19:09 +03002584 /*
2585 * EBS may be disabled due to previous failures reported by FW.
2586 * Reset EBS status here assuming environment has been changed.
2587 */
2588 mvm->last_ebs_successful = true;
Johannes Bergbd1ba662014-11-13 20:53:45 +01002589 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002590 ret = 0;
2591 } else if (old_state == IEEE80211_STA_AUTH &&
2592 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01002593 ret = iwl_mvm_update_sta(mvm, vif, sta);
2594 if (ret == 0)
2595 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02002596 mvmvif->phy_ctxt->channel->band,
2597 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002598 } else if (old_state == IEEE80211_STA_ASSOC &&
2599 new_state == IEEE80211_STA_AUTHORIZED) {
Arik Nemtsovf59e0e3c2014-06-10 19:56:27 +03002600
2601 /* we don't support TDLS during DCM */
2602 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2603 iwl_mvm_teardown_tdls_peers(mvm);
2604
Hila Gonen7df15b12012-12-12 11:16:19 +02002605 /* enable beacon filtering */
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002606 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002607 ret = 0;
2608 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2609 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02002610 /* disable beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002611 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002612 ret = 0;
2613 } else if (old_state == IEEE80211_STA_ASSOC &&
2614 new_state == IEEE80211_STA_AUTH) {
2615 ret = 0;
2616 } else if (old_state == IEEE80211_STA_AUTH &&
2617 new_state == IEEE80211_STA_NONE) {
2618 ret = 0;
2619 } else if (old_state == IEEE80211_STA_NONE &&
2620 new_state == IEEE80211_STA_NOTEXIST) {
2621 ret = iwl_mvm_rm_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002622 if (sta->tdls)
2623 iwl_mvm_recalc_tdls_state(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002624 } else {
2625 ret = -EIO;
2626 }
Johannes Berg48bc1302013-07-04 15:55:29 +02002627 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002628 mutex_unlock(&mvm->mutex);
2629
Liad Kaufman9c126cd2014-10-06 19:08:56 +02002630 if (sta->tdls && ret == 0) {
2631 if (old_state == IEEE80211_STA_NOTEXIST &&
2632 new_state == IEEE80211_STA_NONE)
2633 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2634 else if (old_state == IEEE80211_STA_NONE &&
2635 new_state == IEEE80211_STA_NOTEXIST)
2636 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2637 }
2638
Johannes Berg8ca151b2013-01-24 14:25:36 +01002639 return ret;
2640}
2641
2642static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2643{
2644 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2645
2646 mvm->rts_threshold = value;
2647
2648 return 0;
2649}
2650
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002651static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2652 struct ieee80211_vif *vif,
2653 struct ieee80211_sta *sta, u32 changed)
2654{
2655 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2656
2657 if (vif->type == NL80211_IFTYPE_STATION &&
2658 changed & IEEE80211_RC_NSS_CHANGED)
2659 iwl_mvm_sf_update(mvm, vif, false);
2660}
2661
Johannes Berg8ca151b2013-01-24 14:25:36 +01002662static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2663 struct ieee80211_vif *vif, u16 ac,
2664 const struct ieee80211_tx_queue_params *params)
2665{
2666 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2667 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2668
2669 mvmvif->queue_params[ac] = *params;
2670
2671 /*
2672 * No need to update right away, we'll get BSS_CHANGED_QOS
2673 * The exception is P2P_DEVICE interface which needs immediate update.
2674 */
2675 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2676 int ret;
2677
2678 mutex_lock(&mvm->mutex);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002679 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002680 mutex_unlock(&mvm->mutex);
2681 return ret;
2682 }
2683 return 0;
2684}
2685
2686static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2687 struct ieee80211_vif *vif)
2688{
2689 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2690 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2691 200 + vif->bss_conf.beacon_int);
2692 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2693 100 + vif->bss_conf.beacon_int);
2694
2695 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2696 return;
2697
Eliad Peller576eeee2014-07-01 18:38:38 +03002698 /*
2699 * iwl_mvm_protect_session() reads directly from the device
2700 * (the system time), so make sure it is available.
2701 */
2702 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2703 return;
2704
Johannes Berg8ca151b2013-01-24 14:25:36 +01002705 mutex_lock(&mvm->mutex);
2706 /* Try really hard to protect the session and hear a beacon */
Liad Kaufmand20d37b2014-07-06 17:14:39 +03002707 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002708 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002709
2710 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002711}
2712
David Spinadel35a000b2013-08-28 09:29:43 +03002713static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2714 struct ieee80211_vif *vif,
2715 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +02002716 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +03002717{
2718 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2719 int ret;
2720
David Spinadeld2496222014-05-20 12:46:37 +03002721 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2722 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2723 if (ret)
2724 return ret;
2725 }
Eliad Peller4660dfb2014-06-22 18:15:59 +03002726
David Spinadel35a000b2013-08-28 09:29:43 +03002727 mutex_lock(&mvm->mutex);
2728
Arik Nemtsov88931cc2014-03-05 12:26:15 +02002729 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
2730 IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
2731 ret = -EBUSY;
2732 goto out;
2733 }
2734
Luciano Coelho1f940382015-02-10 13:03:38 +02002735 if (!vif->bss_conf.idle) {
David Spinadelbd5e4742014-04-24 13:15:29 +03002736 ret = -EBUSY;
2737 goto out;
2738 }
2739
Eliad Peller4660dfb2014-06-22 18:15:59 +03002740 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
David Spinadel35a000b2013-08-28 09:29:43 +03002741 ret = -EBUSY;
2742 goto out;
2743 }
2744
Luciano Coelhob141c232014-10-01 13:22:40 +03002745 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
David Spinadel35a000b2013-08-28 09:29:43 +03002746 if (ret)
Luciano Coelhob141c232014-10-01 13:22:40 +03002747 mvm->scan_status = IWL_MVM_SCAN_NONE;
David Spinadeld2496222014-05-20 12:46:37 +03002748
David Spinadel35a000b2013-08-28 09:29:43 +03002749out:
2750 mutex_unlock(&mvm->mutex);
2751 return ret;
2752}
2753
Johannes Berg37e33082014-02-17 10:48:17 +01002754static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2755 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03002756{
2757 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002758 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002759
2760 mutex_lock(&mvm->mutex);
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002761
2762 /* Due to a race condition, it's possible that mac80211 asks
2763 * us to stop a sched_scan when it's already stopped. This
2764 * can happen, for instance, if we stopped the scan ourselves,
2765 * called ieee80211_sched_scan_stopped() and the userspace called
2766 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2767 * could run. To handle this, simply return if the scan is
2768 * not running.
2769 */
2770 /* FIXME: for now, we ignore this race for UMAC scans, since
2771 * they don't set the scan_status.
2772 */
2773 if (mvm->scan_status != IWL_MVM_SCAN_SCHED &&
2774 !(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2775 mutex_unlock(&mvm->mutex);
2776 return 0;
2777 }
2778
David Spinadelfb98be52014-05-04 12:51:10 +03002779 ret = iwl_mvm_scan_offload_stop(mvm, false);
David Spinadel35a000b2013-08-28 09:29:43 +03002780 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002781 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01002782
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002783 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002784}
2785
Johannes Berg8ca151b2013-01-24 14:25:36 +01002786static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2787 enum set_key_cmd cmd,
2788 struct ieee80211_vif *vif,
2789 struct ieee80211_sta *sta,
2790 struct ieee80211_key_conf *key)
2791{
2792 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2793 int ret;
2794
2795 if (iwlwifi_mod_params.sw_crypto) {
2796 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2797 return -EOPNOTSUPP;
2798 }
2799
2800 switch (key->cipher) {
2801 case WLAN_CIPHER_SUITE_TKIP:
2802 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2803 /* fall-through */
2804 case WLAN_CIPHER_SUITE_CCMP:
2805 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2806 break;
2807 case WLAN_CIPHER_SUITE_AES_CMAC:
2808 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2809 break;
2810 case WLAN_CIPHER_SUITE_WEP40:
2811 case WLAN_CIPHER_SUITE_WEP104:
Johannes Bergba3943b2014-11-12 23:54:48 +01002812 /* For non-client mode, only use WEP keys for TX as we probably
2813 * don't have a station yet anyway and would then have to keep
2814 * track of the keys, linking them to each of the clients/peers
2815 * as they appear. For now, don't do that, for performance WEP
2816 * offload doesn't really matter much, but we need it for some
2817 * other offload features in client mode.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002818 */
Johannes Bergba3943b2014-11-12 23:54:48 +01002819 if (vif->type != NL80211_IFTYPE_STATION)
2820 return 0;
2821 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002822 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002823 /* currently FW supports only one optional cipher scheme */
2824 if (hw->n_cipher_schemes &&
2825 hw->cipher_schemes->cipher == key->cipher)
2826 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2827 else
2828 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002829 }
2830
2831 mutex_lock(&mvm->mutex);
2832
2833 switch (cmd) {
2834 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02002835 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2836 vif->type == NL80211_IFTYPE_AP) && !sta) {
2837 /*
2838 * GTK on AP interface is a TX-only key, return 0;
2839 * on IBSS they're per-station and because we're lazy
2840 * we don't support them for RX, so do the same.
2841 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002842 ret = 0;
2843 key->hw_key_idx = STA_KEY_IDX_INVALID;
2844 break;
2845 }
2846
Johannes Berg8ca151b2013-01-24 14:25:36 +01002847 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2848 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2849 if (ret) {
2850 IWL_WARN(mvm, "set key failed\n");
2851 /*
2852 * can't add key for RX, but we don't need it
2853 * in the device for TX so still return 0
2854 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002855 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002856 ret = 0;
2857 }
2858
2859 break;
2860 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01002861 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2862 ret = 0;
2863 break;
2864 }
2865
Johannes Berg8ca151b2013-01-24 14:25:36 +01002866 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2867 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2868 break;
2869 default:
2870 ret = -EINVAL;
2871 }
2872
2873 mutex_unlock(&mvm->mutex);
2874 return ret;
2875}
2876
2877static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2878 struct ieee80211_vif *vif,
2879 struct ieee80211_key_conf *keyconf,
2880 struct ieee80211_sta *sta,
2881 u32 iv32, u16 *phase1key)
2882{
2883 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2884
Johannes Berg5023d962013-07-31 14:07:43 +02002885 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2886 return;
2887
Johannes Berg8ca151b2013-01-24 14:25:36 +01002888 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2889}
2890
2891
Ariej Marjiehb1128892014-07-16 21:11:12 +03002892static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2893 struct iwl_rx_packet *pkt, void *data)
2894{
2895 struct iwl_mvm *mvm =
2896 container_of(notif_wait, struct iwl_mvm, notif_wait);
2897 struct iwl_hs20_roc_res *resp;
2898 int resp_len = iwl_rx_packet_payload_len(pkt);
2899 struct iwl_mvm_time_event_data *te_data = data;
2900
2901 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2902 return true;
2903
2904 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2905 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2906 return true;
2907 }
2908
2909 resp = (void *)pkt->data;
2910
2911 IWL_DEBUG_TE(mvm,
2912 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2913 resp->status, resp->event_unique_id);
2914
2915 te_data->uid = le32_to_cpu(resp->event_unique_id);
2916 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2917 te_data->uid);
2918
2919 spin_lock_bh(&mvm->time_event_lock);
2920 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2921 spin_unlock_bh(&mvm->time_event_lock);
2922
2923 return true;
2924}
2925
2926#define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2927static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2928 struct ieee80211_channel *channel,
2929 struct ieee80211_vif *vif,
2930 int duration)
2931{
2932 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2933 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2934 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2935 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2936 struct iwl_notification_wait wait_time_event;
2937 struct iwl_hs20_roc_req aux_roc_req = {
2938 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2939 .id_and_color =
2940 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2941 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2942 /* Set the channel info data */
2943 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2944 PHY_BAND_24 : PHY_BAND_5,
2945 .channel_info.channel = channel->hw_value,
2946 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2947 /* Set the time and duration */
2948 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2949 .apply_time_max_delay =
2950 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2951 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2952 };
2953
2954 /* Set the node address */
2955 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2956
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002957 lockdep_assert_held(&mvm->mutex);
2958
2959 spin_lock_bh(&mvm->time_event_lock);
2960
2961 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2962 spin_unlock_bh(&mvm->time_event_lock);
2963 return -EIO;
2964 }
2965
Ariej Marjiehb1128892014-07-16 21:11:12 +03002966 te_data->vif = vif;
2967 te_data->duration = duration;
2968 te_data->id = HOT_SPOT_CMD;
2969
Ariej Marjiehb1128892014-07-16 21:11:12 +03002970 spin_unlock_bh(&mvm->time_event_lock);
2971
2972 /*
2973 * Use a notification wait, which really just processes the
2974 * command response and doesn't wait for anything, in order
2975 * to be able to process the response and get the UID inside
2976 * the RX path. Using CMD_WANT_SKB doesn't work because it
2977 * stores the buffer and then wakes up this thread, by which
2978 * time another notification (that the time event started)
2979 * might already be processed unsuccessfully.
2980 */
2981 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2982 time_event_response,
2983 ARRAY_SIZE(time_event_response),
2984 iwl_mvm_rx_aux_roc, te_data);
2985
2986 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2987 &aux_roc_req);
2988
2989 if (res) {
2990 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2991 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2992 goto out_clear_te;
2993 }
2994
2995 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2996 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2997 /* should never fail */
2998 WARN_ON_ONCE(res);
2999
3000 if (res) {
3001 out_clear_te:
3002 spin_lock_bh(&mvm->time_event_lock);
3003 iwl_mvm_te_clear_data(mvm, te_data);
3004 spin_unlock_bh(&mvm->time_event_lock);
3005 }
3006
3007 return res;
3008}
3009
Johannes Berg8ca151b2013-01-24 14:25:36 +01003010static int iwl_mvm_roc(struct ieee80211_hw *hw,
3011 struct ieee80211_vif *vif,
3012 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003013 int duration,
3014 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003015{
3016 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003017 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003018 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03003019 struct iwl_mvm_phy_ctxt *phy_ctxt;
3020 int ret, i;
3021
3022 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3023 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003024
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003025 mutex_lock(&mvm->mutex);
3026
Ariej Marjiehb1128892014-07-16 21:11:12 +03003027 switch (vif->type) {
3028 case NL80211_IFTYPE_STATION:
Luciano Coelho5ac6c722014-10-21 16:12:18 +03003029 if (mvm->fw->ucode_capa.capa[0] &
3030 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
3031 /* Use aux roc framework (HS20) */
3032 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3033 vif, duration);
3034 goto out_unlock;
3035 }
3036 IWL_ERR(mvm, "hotspot not supported\n");
3037 ret = -EINVAL;
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003038 goto out_unlock;
Ariej Marjiehb1128892014-07-16 21:11:12 +03003039 case NL80211_IFTYPE_P2P_DEVICE:
3040 /* handle below */
3041 break;
3042 default:
3043 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003044 ret = -EINVAL;
3045 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003046 }
3047
Ilan Peer31d385a2013-04-02 10:25:46 +03003048 for (i = 0; i < NUM_PHY_CTX; i++) {
3049 phy_ctxt = &mvm->phy_ctxts[i];
3050 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3051 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003052
Ilan Peer31d385a2013-04-02 10:25:46 +03003053 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3054 /*
3055 * Unbind the P2P_DEVICE from the current PHY context,
3056 * and if the PHY context is not used remove it.
3057 */
3058 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3059 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3060 goto out_unlock;
3061
3062 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3063
3064 /* Bind the P2P_DEVICE to the current PHY Context */
3065 mvmvif->phy_ctxt = phy_ctxt;
3066
3067 ret = iwl_mvm_binding_add_vif(mvm, vif);
3068 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3069 goto out_unlock;
3070
3071 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3072 goto schedule_time_event;
3073 }
3074 }
3075
3076 /* Need to update the PHY context only if the ROC channel changed */
3077 if (channel == mvmvif->phy_ctxt->channel)
3078 goto schedule_time_event;
3079
3080 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3081
3082 /*
3083 * Change the PHY context configuration as it is currently referenced
3084 * only by the P2P Device MAC
3085 */
3086 if (mvmvif->phy_ctxt->ref == 1) {
3087 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3088 &chandef, 1, 1);
3089 if (ret)
3090 goto out_unlock;
3091 } else {
3092 /*
3093 * The PHY context is shared with other MACs. Need to remove the
3094 * P2P Device from the binding, allocate an new PHY context and
3095 * create a new binding
3096 */
3097 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3098 if (!phy_ctxt) {
3099 ret = -ENOSPC;
3100 goto out_unlock;
3101 }
3102
3103 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3104 1, 1);
3105 if (ret) {
3106 IWL_ERR(mvm, "Failed to change PHY context\n");
3107 goto out_unlock;
3108 }
3109
3110 /* Unbind the P2P_DEVICE from the current PHY context */
3111 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3112 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3113 goto out_unlock;
3114
3115 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3116
3117 /* Bind the P2P_DEVICE to the new allocated PHY context */
3118 mvmvif->phy_ctxt = phy_ctxt;
3119
3120 ret = iwl_mvm_binding_add_vif(mvm, vif);
3121 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3122 goto out_unlock;
3123
3124 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3125 }
3126
3127schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003128 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02003129 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003130
Ilan Peer31d385a2013-04-02 10:25:46 +03003131out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003132 mutex_unlock(&mvm->mutex);
3133 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01003134 return ret;
3135}
3136
3137static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3138{
3139 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3140
3141 IWL_DEBUG_MAC80211(mvm, "enter\n");
3142
3143 mutex_lock(&mvm->mutex);
Matti Gottliebbf5da872014-11-16 10:25:12 +02003144 iwl_mvm_stop_roc(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003145 mutex_unlock(&mvm->mutex);
3146
3147 IWL_DEBUG_MAC80211(mvm, "leave\n");
3148 return 0;
3149}
3150
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003151static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3152 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003153{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003154 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3155 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003156 int ret;
3157
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003158 lockdep_assert_held(&mvm->mutex);
3159
Ilan Peer53a9d612013-04-28 11:55:08 +03003160 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003161
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003162 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3163 if (!phy_ctxt) {
3164 ret = -ENOSPC;
3165 goto out;
3166 }
3167
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003168 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03003169 ctx->rx_chains_static,
3170 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003171 if (ret) {
3172 IWL_ERR(mvm, "Failed to add PHY context\n");
3173 goto out;
3174 }
3175
Ilan Peer53a9d612013-04-28 11:55:08 +03003176 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003177 *phy_ctxt_id = phy_ctxt->id;
3178out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003179 return ret;
3180}
3181
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003182static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3183 struct ieee80211_chanctx_conf *ctx)
3184{
3185 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3186 int ret;
3187
3188 mutex_lock(&mvm->mutex);
3189 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3190 mutex_unlock(&mvm->mutex);
3191
3192 return ret;
3193}
3194
3195static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3196 struct ieee80211_chanctx_conf *ctx)
3197{
3198 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3199 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3200
3201 lockdep_assert_held(&mvm->mutex);
3202
3203 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3204}
3205
Johannes Berg8ca151b2013-01-24 14:25:36 +01003206static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3207 struct ieee80211_chanctx_conf *ctx)
3208{
3209 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003210
3211 mutex_lock(&mvm->mutex);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003212 __iwl_mvm_remove_chanctx(mvm, ctx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003213 mutex_unlock(&mvm->mutex);
3214}
3215
3216static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3217 struct ieee80211_chanctx_conf *ctx,
3218 u32 changed)
3219{
3220 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003221 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3222 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003223
Ilan Peer31d385a2013-04-02 10:25:46 +03003224 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3225 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3226 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02003227 IEEE80211_CHANCTX_CHANGE_RADAR |
3228 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03003229 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3230 phy_ctxt->ref, changed))
3231 return;
3232
Johannes Berg8ca151b2013-01-24 14:25:36 +01003233 mutex_lock(&mvm->mutex);
Emmanuel Grumbach4d664492014-04-30 18:09:59 +03003234 iwl_mvm_bt_coex_vif_change(mvm);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003235 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003236 ctx->rx_chains_static,
3237 ctx->rx_chains_dynamic);
3238 mutex_unlock(&mvm->mutex);
3239}
3240
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003241static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3242 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003243 struct ieee80211_chanctx_conf *ctx,
3244 bool switching_chanctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003245{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003246 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3247 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003248 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3249 int ret;
3250
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003251 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003252
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003253 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003254
3255 switch (vif->type) {
3256 case NL80211_IFTYPE_AP:
Luciano Coelho4741dd02014-11-10 11:10:13 +02003257 /* only needed if we're switching chanctx (i.e. during CSA) */
3258 if (switching_chanctx) {
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003259 mvmvif->ap_ibss_active = true;
3260 break;
3261 }
Johannes Berg5023d962013-07-31 14:07:43 +02003262 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003263 /*
3264 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02003265 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01003266 */
3267 ret = 0;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003268 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003269 case NL80211_IFTYPE_STATION:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003270 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003271 case NL80211_IFTYPE_MONITOR:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003272 /* always disable PS when a monitor interface is active */
3273 mvmvif->ps_disabled = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003274 break;
3275 default:
3276 ret = -EINVAL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003277 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003278 }
3279
3280 ret = iwl_mvm_binding_add_vif(mvm, vif);
3281 if (ret)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003282 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003283
3284 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02003285 * Power state must be updated before quotas,
3286 * otherwise fw will complain.
3287 */
Arik Nemtsov999609f2014-05-15 17:31:51 +03003288 iwl_mvm_power_update_mac(mvm);
Alexander Bondar92d85562013-10-23 11:50:34 +02003289
3290 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01003291 * interfaces. For the other types, the bss_info changed flow
3292 * will handle quota settings.
3293 */
3294 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02003295 mvmvif->monitor_active = true;
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003296 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003297 if (ret)
3298 goto out_remove_binding;
3299 }
3300
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003301 /* Handle binding during CSA */
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003302 if (vif->type == NL80211_IFTYPE_AP) {
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003303 iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003304 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003305 }
3306
Luciano Coelho4741dd02014-11-10 11:10:13 +02003307 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003308 u32 duration = 2 * vif->bss_conf.beacon_int;
3309
3310 /* iwl_mvm_protect_session() reads directly from the
3311 * device (the system time), so make sure it is
3312 * available.
3313 */
3314 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3315 if (ret)
3316 goto out_remove_binding;
3317
3318 /* Protect the session to make sure we hear the first
3319 * beacon on the new channel.
3320 */
3321 iwl_mvm_protect_session(mvm, vif, duration, duration,
3322 vif->bss_conf.beacon_int / 2,
3323 true);
3324
3325 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3326
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003327 iwl_mvm_update_quotas(mvm, false, NULL);
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03003328 }
3329
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003330 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003331
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003332out_remove_binding:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003333 iwl_mvm_binding_remove_vif(mvm, vif);
Arik Nemtsov999609f2014-05-15 17:31:51 +03003334 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003335out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003336 if (ret)
3337 mvmvif->phy_ctxt = NULL;
3338 return ret;
3339}
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003340static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3341 struct ieee80211_vif *vif,
3342 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003343{
3344 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003345 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003346
3347 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003348 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003349 mutex_unlock(&mvm->mutex);
3350
3351 return ret;
3352}
3353
3354static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3355 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003356 struct ieee80211_chanctx_conf *ctx,
3357 bool switching_chanctx)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003358{
3359 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003360 struct ieee80211_vif *disabled_vif = NULL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003361
3362 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003363
3364 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3365
Johannes Berg8ca151b2013-01-24 14:25:36 +01003366 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02003367 case NL80211_IFTYPE_ADHOC:
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003368 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003369 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02003370 mvmvif->monitor_active = false;
Luciano Coelho2533edc2014-08-08 19:50:46 +03003371 mvmvif->ps_disabled = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003372 break;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003373 case NL80211_IFTYPE_AP:
3374 /* This part is triggered only during CSA */
Luciano Coelho4741dd02014-11-10 11:10:13 +02003375 if (!switching_chanctx || !mvmvif->ap_ibss_active)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003376 goto out;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003377
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003378 mvmvif->csa_countdown = false;
3379
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003380 /* Set CS bit on all the stations */
3381 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3382
3383 /* Save blocked iface, the timeout is set on the next beacon */
3384 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3385
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003386 mvmvif->ap_ibss_active = false;
Luciano Coelhof0c97782014-03-05 15:41:48 +02003387 break;
3388 case NL80211_IFTYPE_STATION:
3389 if (!switching_chanctx)
3390 break;
3391
3392 disabled_vif = vif;
3393
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003394 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003395 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003396 default:
3397 break;
3398 }
3399
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003400 iwl_mvm_update_quotas(mvm, false, disabled_vif);
Ilan Peer1e1391c2013-03-13 14:52:04 +02003401 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03003402
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003403out:
Ilan Peera11e1442013-12-31 21:19:55 +02003404 mvmvif->phy_ctxt = NULL;
Arik Nemtsov999609f2014-05-15 17:31:51 +03003405 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003406}
3407
3408static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3409 struct ieee80211_vif *vif,
3410 struct ieee80211_chanctx_conf *ctx)
3411{
3412 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3413
3414 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003415 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003416 mutex_unlock(&mvm->mutex);
3417}
3418
Luciano Coelho50cc9572014-11-10 11:10:08 +02003419static int
3420iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3421 struct ieee80211_vif_chanctx_switch *vifs)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003422{
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003423 int ret;
3424
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003425 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003426 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003427 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3428
3429 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3430 if (ret) {
3431 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3432 goto out_reassign;
3433 }
3434
Luciano Coelhof0c97782014-03-05 15:41:48 +02003435 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3436 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003437 if (ret) {
3438 IWL_ERR(mvm,
3439 "failed to assign new_ctx during channel switch\n");
3440 goto out_remove;
3441 }
3442
Arik Nemtsovf6972672014-06-15 16:03:55 +03003443 /* we don't support TDLS during DCM - can be caused by channel switch */
3444 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3445 iwl_mvm_teardown_tdls_peers(mvm);
3446
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003447 goto out;
3448
3449out_remove:
3450 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3451
3452out_reassign:
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003453 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003454 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3455 goto out_restart;
3456 }
3457
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003458 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3459 true)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003460 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3461 goto out_restart;
3462 }
3463
3464 goto out;
3465
3466out_restart:
3467 /* things keep failing, better restart the hw */
3468 iwl_mvm_nic_restart(mvm, false);
3469
3470out:
3471 mutex_unlock(&mvm->mutex);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003472
3473 return ret;
3474}
3475
Luciano Coelho48a256e2014-11-10 11:10:09 +02003476static int
3477iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3478 struct ieee80211_vif_chanctx_switch *vifs)
3479{
3480 int ret;
3481
3482 mutex_lock(&mvm->mutex);
3483 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3484
3485 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3486 true);
3487 if (ret) {
3488 IWL_ERR(mvm,
3489 "failed to assign new_ctx during channel switch\n");
3490 goto out_reassign;
3491 }
3492
3493 goto out;
3494
3495out_reassign:
3496 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3497 true)) {
3498 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3499 goto out_restart;
3500 }
3501
3502 goto out;
3503
3504out_restart:
3505 /* things keep failing, better restart the hw */
3506 iwl_mvm_nic_restart(mvm, false);
3507
3508out:
3509 mutex_unlock(&mvm->mutex);
3510
3511 return ret;
3512}
3513
Luciano Coelho50cc9572014-11-10 11:10:08 +02003514static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3515 struct ieee80211_vif_chanctx_switch *vifs,
3516 int n_vifs,
3517 enum ieee80211_chanctx_switch_mode mode)
3518{
3519 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3520 int ret;
3521
3522 /* we only support a single-vif right now */
3523 if (n_vifs > 1)
3524 return -EOPNOTSUPP;
3525
3526 switch (mode) {
3527 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3528 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3529 break;
3530 case CHANCTX_SWMODE_REASSIGN_VIF:
Luciano Coelho48a256e2014-11-10 11:10:09 +02003531 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003532 break;
3533 default:
3534 ret = -EOPNOTSUPP;
3535 break;
3536 }
3537
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003538 return ret;
3539}
3540
Johannes Berg8ca151b2013-01-24 14:25:36 +01003541static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3542 struct ieee80211_sta *sta,
3543 bool set)
3544{
3545 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01003546 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003547
3548 if (!mvm_sta || !mvm_sta->vif) {
3549 IWL_ERR(mvm, "Station is not associated to a vif\n");
3550 return -EINVAL;
3551 }
3552
3553 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3554}
3555
David Spinadel507cadf2013-07-31 18:07:21 +03003556#ifdef CONFIG_NL80211_TESTMODE
3557static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3558 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3559 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003560 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03003561};
3562
3563static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3564 struct ieee80211_vif *vif,
3565 void *data, int len)
3566{
3567 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3568 int err;
3569 u32 noa_duration;
3570
3571 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3572 if (err)
3573 return err;
3574
3575 if (!tb[IWL_MVM_TM_ATTR_CMD])
3576 return -EINVAL;
3577
3578 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3579 case IWL_MVM_TM_CMD_SET_NOA:
3580 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3581 !vif->bss_conf.enable_beacon ||
3582 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3583 return -EINVAL;
3584
3585 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3586 if (noa_duration >= vif->bss_conf.beacon_int)
3587 return -EINVAL;
3588
3589 mvm->noa_duration = noa_duration;
3590 mvm->noa_vif = vif;
3591
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003592 return iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003593 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3594 /* must be associated client vif - ignore authorized */
3595 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3596 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3597 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3598 return -EINVAL;
3599
3600 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03003601 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3602 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
David Spinadel507cadf2013-07-31 18:07:21 +03003603 }
3604
3605 return -EOPNOTSUPP;
3606}
3607
3608static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3609 struct ieee80211_vif *vif,
3610 void *data, int len)
3611{
3612 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3613 int err;
3614
3615 mutex_lock(&mvm->mutex);
3616 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3617 mutex_unlock(&mvm->mutex);
3618
3619 return err;
3620}
3621#endif
3622
Luciano Coelho622e3f92014-11-10 11:10:17 +02003623static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3624 struct ieee80211_vif *vif,
3625 struct ieee80211_channel_switch *chsw)
3626{
3627 /* By implementing this operation, we prevent mac80211 from
3628 * starting its own channel switch timer, so that we can call
3629 * ieee80211_chswitch_done() ourselves at the right time
3630 * (which is when the absence time event starts).
3631 */
3632
3633 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3634 "dummy channel switch op\n");
3635}
3636
Luciano Coelhof0289052014-11-10 11:10:06 +02003637static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3638 struct ieee80211_vif *vif,
3639 struct ieee80211_channel_switch *chsw)
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003640{
3641 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003642 struct ieee80211_vif *csa_vif;
Luciano Coelhof6c34822014-11-10 11:10:12 +02003643 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003644 u32 apply_time;
Luciano Coelhof0289052014-11-10 11:10:06 +02003645 int ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003646
3647 mutex_lock(&mvm->mutex);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003648
Johannes Berg81d62d52015-03-10 14:44:00 +01003649 mvmvif->csa_failed = false;
3650
Luciano Coelho6b20d772014-11-10 11:10:07 +02003651 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
Luciano Coelhof0289052014-11-10 11:10:06 +02003652 chsw->chandef.center_freq1);
Luciano Coelho6b20d772014-11-10 11:10:07 +02003653
Emmanuel Grumbachf35d9c52015-02-10 10:49:51 +02003654 iwl_fw_dbg_trigger_simple_stop(mvm, vif, FW_DBG_TRIGGER_CHANNEL_SWITCH,
3655 NULL, 0);
3656
Luciano Coelho6b20d772014-11-10 11:10:07 +02003657 switch (vif->type) {
3658 case NL80211_IFTYPE_AP:
3659 csa_vif =
3660 rcu_dereference_protected(mvm->csa_vif,
3661 lockdep_is_held(&mvm->mutex));
3662 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3663 "Another CSA is already in progress")) {
3664 ret = -EBUSY;
3665 goto out_unlock;
3666 }
3667
3668 rcu_assign_pointer(mvm->csa_vif, vif);
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003669
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003670 if (WARN_ONCE(mvmvif->csa_countdown,
3671 "Previous CSA countdown didn't complete")) {
3672 ret = -EBUSY;
3673 goto out_unlock;
3674 }
3675
Luciano Coelho6b20d772014-11-10 11:10:07 +02003676 break;
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003677 case NL80211_IFTYPE_STATION:
Luciano Coelho4500e132014-11-10 11:10:15 +02003678 /* Schedule the time event to a bit before beacon 1,
3679 * to make sure we're in the new channel when the
3680 * GO/AP arrives.
3681 */
3682 apply_time = chsw->device_timestamp +
3683 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3684 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003685
3686 if (chsw->block_tx)
3687 iwl_mvm_csa_client_absent(mvm, vif);
3688
Luciano Coelho4500e132014-11-10 11:10:15 +02003689 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003690 apply_time);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003691 if (mvmvif->bf_data.bf_enabled) {
3692 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3693 if (ret)
3694 goto out_unlock;
3695 }
3696
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003697 break;
Luciano Coelho6b20d772014-11-10 11:10:07 +02003698 default:
3699 break;
3700 }
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003701
Luciano Coelhof6c34822014-11-10 11:10:12 +02003702 mvmvif->ps_disabled = true;
3703
3704 ret = iwl_mvm_power_update_ps(mvm);
3705 if (ret)
3706 goto out_unlock;
Luciano Coelhof0289052014-11-10 11:10:06 +02003707
Arik Nemtsove198f5e2014-09-14 19:13:54 +03003708 /* we won't be on this channel any longer */
3709 iwl_mvm_teardown_tdls_peers(mvm);
3710
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003711out_unlock:
3712 mutex_unlock(&mvm->mutex);
Luciano Coelhof0289052014-11-10 11:10:06 +02003713
3714 return ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003715}
3716
Luciano Coelhof6c34822014-11-10 11:10:12 +02003717static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3718 struct ieee80211_vif *vif)
3719{
3720 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3721 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3722 int ret;
3723
3724 mutex_lock(&mvm->mutex);
3725
Johannes Berg81d62d52015-03-10 14:44:00 +01003726 if (mvmvif->csa_failed) {
3727 mvmvif->csa_failed = false;
3728 ret = -EIO;
3729 goto out_unlock;
3730 }
3731
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003732 if (vif->type == NL80211_IFTYPE_STATION) {
3733 struct iwl_mvm_sta *mvmsta;
3734
3735 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3736 mvmvif->ap_sta_id);
3737
3738 if (WARN_ON(!mvmsta)) {
3739 ret = -EIO;
3740 goto out_unlock;
3741 }
3742
3743 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3744
3745 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003746
3747 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3748 if (ret)
3749 goto out_unlock;
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003750
3751 iwl_mvm_stop_session_protection(mvm, vif);
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003752 }
3753
Luciano Coelhof6c34822014-11-10 11:10:12 +02003754 mvmvif->ps_disabled = false;
3755
3756 ret = iwl_mvm_power_update_ps(mvm);
3757
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003758out_unlock:
Luciano Coelhof6c34822014-11-10 11:10:12 +02003759 mutex_unlock(&mvm->mutex);
3760
3761 return ret;
3762}
3763
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003764static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3765 struct ieee80211_vif *vif, u32 queues, bool drop)
3766{
3767 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3768 struct iwl_mvm_vif *mvmvif;
3769 struct iwl_mvm_sta *mvmsta;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003770 struct ieee80211_sta *sta;
3771 int i;
3772 u32 msk = 0;
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003773
3774 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3775 return;
3776
3777 mutex_lock(&mvm->mutex);
3778 mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003779
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003780 /* flush the AP-station and all TDLS peers */
3781 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3782 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3783 lockdep_is_held(&mvm->mutex));
3784 if (IS_ERR_OR_NULL(sta))
3785 continue;
3786
3787 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3788 if (mvmsta->vif != vif)
3789 continue;
3790
3791 /* make sure only TDLS peers or the AP are flushed */
3792 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3793
3794 msk |= mvmsta->tfd_queue_msk;
Johannes Berg480acbc2014-10-10 08:59:27 +02003795 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003796
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003797 if (drop) {
3798 if (iwl_mvm_flush_tx_path(mvm, msk, true))
3799 IWL_ERR(mvm, "flush request fail\n");
3800 mutex_unlock(&mvm->mutex);
3801 } else {
3802 mutex_unlock(&mvm->mutex);
Johannes Berg480acbc2014-10-10 08:59:27 +02003803
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003804 /* this can take a while, and we may need/want other operations
3805 * to succeed while doing this, so do it without the mutex held
3806 */
3807 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3808 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003809}
3810
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003811static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
3812 struct survey_info *survey)
3813{
3814 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3815 int ret;
3816
3817 memset(survey, 0, sizeof(*survey));
3818
3819 /* only support global statistics right now */
3820 if (idx != 0)
3821 return -ENOENT;
3822
3823 if (!(mvm->fw->ucode_capa.capa[0] &
3824 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3825 return -ENOENT;
3826
3827 mutex_lock(&mvm->mutex);
3828
3829 if (mvm->ucode_loaded) {
Johannes Berg33cef922015-01-21 21:41:29 +01003830 ret = iwl_mvm_request_statistics(mvm, false);
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003831 if (ret)
3832 goto out;
3833 }
3834
3835 survey->filled = SURVEY_INFO_TIME |
3836 SURVEY_INFO_TIME_RX |
3837 SURVEY_INFO_TIME_TX |
3838 SURVEY_INFO_TIME_SCAN;
3839 survey->time = mvm->accu_radio_stats.on_time_rf +
3840 mvm->radio_stats.on_time_rf;
3841 do_div(survey->time, USEC_PER_MSEC);
3842
3843 survey->time_rx = mvm->accu_radio_stats.rx_time +
3844 mvm->radio_stats.rx_time;
3845 do_div(survey->time_rx, USEC_PER_MSEC);
3846
3847 survey->time_tx = mvm->accu_radio_stats.tx_time +
3848 mvm->radio_stats.tx_time;
3849 do_div(survey->time_tx, USEC_PER_MSEC);
3850
3851 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
3852 mvm->radio_stats.on_time_scan;
3853 do_div(survey->time_scan, USEC_PER_MSEC);
3854
3855 out:
3856 mutex_unlock(&mvm->mutex);
3857 return ret;
3858}
3859
Johannes Berg33cef922015-01-21 21:41:29 +01003860static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
3861 struct ieee80211_vif *vif,
3862 struct ieee80211_sta *sta,
3863 struct station_info *sinfo)
3864{
3865 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3866 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3867 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3868
3869 if (!(mvm->fw->ucode_capa.capa[0] &
3870 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3871 return;
3872
3873 /* if beacon filtering isn't on mac80211 does it anyway */
3874 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
3875 return;
3876
3877 if (!vif->bss_conf.assoc)
3878 return;
3879
3880 mutex_lock(&mvm->mutex);
3881
3882 if (mvmvif->ap_sta_id != mvmsta->sta_id)
3883 goto unlock;
3884
3885 if (iwl_mvm_request_statistics(mvm, false))
3886 goto unlock;
3887
3888 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
3889 mvmvif->beacon_stats.accu_num_beacons;
3890 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
3891 if (mvmvif->beacon_stats.avg_signal) {
3892 /* firmware only reports a value after RXing a few beacons */
3893 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
3894 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
3895 }
3896 unlock:
3897 mutex_unlock(&mvm->mutex);
3898}
3899
Johannes Berge5209262014-01-20 23:38:59 +01003900const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003901 .tx = iwl_mvm_mac_tx,
3902 .ampdu_action = iwl_mvm_mac_ampdu_action,
3903 .start = iwl_mvm_mac_start,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02003904 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003905 .stop = iwl_mvm_mac_stop,
3906 .add_interface = iwl_mvm_mac_add_interface,
3907 .remove_interface = iwl_mvm_mac_remove_interface,
3908 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02003909 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003910 .configure_filter = iwl_mvm_configure_filter,
3911 .bss_info_changed = iwl_mvm_bss_info_changed,
3912 .hw_scan = iwl_mvm_mac_hw_scan,
3913 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01003914 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003915 .sta_state = iwl_mvm_mac_sta_state,
3916 .sta_notify = iwl_mvm_mac_sta_notify,
3917 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01003918 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003919 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02003920 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003921 .conf_tx = iwl_mvm_mac_conf_tx,
3922 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
Arik Nemtsov07ecd892014-05-20 18:16:42 +03003923 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003924 .flush = iwl_mvm_mac_flush,
David Spinadel35a000b2013-08-28 09:29:43 +03003925 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3926 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003927 .set_key = iwl_mvm_mac_set_key,
3928 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3929 .remain_on_channel = iwl_mvm_roc,
3930 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003931 .add_chanctx = iwl_mvm_add_chanctx,
3932 .remove_chanctx = iwl_mvm_remove_chanctx,
3933 .change_chanctx = iwl_mvm_change_chanctx,
3934 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3935 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003936 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003937
Johannes Berg5023d962013-07-31 14:07:43 +02003938 .start_ap = iwl_mvm_start_ap_ibss,
3939 .stop_ap = iwl_mvm_stop_ap_ibss,
3940 .join_ibss = iwl_mvm_start_ap_ibss,
3941 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003942
3943 .set_tim = iwl_mvm_set_tim,
3944
Luciano Coelho622e3f92014-11-10 11:10:17 +02003945 .channel_switch = iwl_mvm_channel_switch,
Luciano Coelhof0289052014-11-10 11:10:06 +02003946 .pre_channel_switch = iwl_mvm_pre_channel_switch,
Luciano Coelhof6c34822014-11-10 11:10:12 +02003947 .post_channel_switch = iwl_mvm_post_channel_switch,
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003948
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03003949 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
3950 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
3951 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
3952
David Spinadel507cadf2013-07-31 18:07:21 +03003953 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3954
Johannes Berg8ca151b2013-01-24 14:25:36 +01003955#ifdef CONFIG_PM_SLEEP
3956 /* look at d3.c */
3957 .suspend = iwl_mvm_suspend,
3958 .resume = iwl_mvm_resume,
3959 .set_wakeup = iwl_mvm_set_wakeup,
3960 .set_rekey_data = iwl_mvm_set_rekey_data,
3961#if IS_ENABLED(CONFIG_IPV6)
3962 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3963#endif
3964 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3965#endif
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003966 .get_survey = iwl_mvm_mac_get_survey,
Johannes Berg33cef922015-01-21 21:41:29 +01003967 .sta_statistics = iwl_mvm_mac_sta_statistics,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003968};