blob: e843080b5c0b99aee11d7807fb0f7f9576228208 [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 Berg8ca151b2013-01-24 14:25:36 +01009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +010034 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63#include <linux/kernel.h>
64#include <linux/slab.h>
65#include <linux/skbuff.h>
66#include <linux/netdevice.h>
67#include <linux/etherdevice.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010068#include <linux/ip.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010069#include <net/mac80211.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010070#include <net/tcp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010071
72#include "iwl-op-mode.h"
73#include "iwl-io.h"
74#include "mvm.h"
75#include "sta.h"
76#include "time-event.h"
77#include "iwl-eeprom-parse.h"
78#include "fw-api-scan.h"
79#include "iwl-phy-db.h"
David Spinadel507cadf2013-07-31 18:07:21 +030080#include "testmode.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010081
82static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
83 {
84 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030085 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010086 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020087 {
88 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030089 .types = BIT(NL80211_IFTYPE_AP) |
90 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +020091 BIT(NL80211_IFTYPE_P2P_GO),
92 },
93 {
94 .max = 1,
95 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
96 },
Johannes Berg8ca151b2013-01-24 14:25:36 +010097};
98
99static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
100 {
101 .num_different_channels = 1,
102 .max_interfaces = 3,
103 .limits = iwl_mvm_limits,
104 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
105 },
106};
107
Johannes Bergf0c26462013-01-22 20:41:58 +0100108#ifdef CONFIG_PM_SLEEP
109static const struct nl80211_wowlan_tcp_data_token_feature
110iwl_mvm_wowlan_tcp_token_feature = {
111 .min_len = 0,
112 .max_len = 255,
113 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
114};
115
116static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
117 .tok = &iwl_mvm_wowlan_tcp_token_feature,
118 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
119 sizeof(struct ethhdr) -
120 sizeof(struct iphdr) -
121 sizeof(struct tcphdr),
122 .data_interval_max = 65535, /* __le16 in API */
123 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
124 sizeof(struct ethhdr) -
125 sizeof(struct iphdr) -
126 sizeof(struct tcphdr),
127 .seq = true,
128};
129#endif
130
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200131static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
132{
133 int i;
134
135 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
136 for (i = 0; i < NUM_PHY_CTX; i++) {
137 mvm->phy_ctxts[i].id = i;
138 mvm->phy_ctxts[i].ref = 0;
139 }
140}
141
David Spinadel20f1a5d2013-08-21 09:14:27 +0300142static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
143{
144 /* we create the 802.11 header and SSID element */
145 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
146 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
147 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
148}
149
Johannes Berg8ca151b2013-01-24 14:25:36 +0100150int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
151{
152 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200153 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100154
155 /* Tell mac80211 our characteristics */
156 hw->flags = IEEE80211_HW_SIGNAL_DBM |
157 IEEE80211_HW_SPECTRUM_MGMT |
158 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
159 IEEE80211_HW_QUEUE_CONTROL |
160 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100161 IEEE80211_HW_SUPPORTS_PS |
162 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100163 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200164 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300165 IEEE80211_HW_CONNECTION_MONITOR |
166 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
Alexander Bondare8e626a2013-10-16 00:21:34 +0200167 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100168
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200169 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200170 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100171 hw->rate_control_algorithm = "iwl-mvm-rs";
172
173 /*
174 * Enable 11w if advertised by firmware and software crypto
175 * is not enabled (as the firmware will interpret some mgmt
176 * packets, so enabling it with software crypto isn't safe)
177 */
178 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
179 !iwlwifi_mod_params.sw_crypto)
180 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
181
Alexander Bondare8e626a2013-10-16 00:21:34 +0200182 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) {
183 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
184 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
185 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
186 }
187
Johannes Berg8ca151b2013-01-24 14:25:36 +0100188 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
189 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200190 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100191
192 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200193 BIT(NL80211_IFTYPE_P2P_CLIENT) |
194 BIT(NL80211_IFTYPE_AP) |
195 BIT(NL80211_IFTYPE_P2P_GO) |
196 BIT(NL80211_IFTYPE_P2P_DEVICE);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100197
Johannes Berg5023d962013-07-31 14:07:43 +0200198 /* IBSS has bugs in older versions */
199 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 8)
200 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
201
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100202 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
203 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
204 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100205
206 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
207 hw->wiphy->n_iface_combinations =
208 ARRAY_SIZE(iwl_mvm_iface_combinations);
209
Ilan Peerc451e6d2013-02-20 08:41:54 +0200210 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100211 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
212
213 /* Extract MAC address */
214 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
215 hw->wiphy->addresses = mvm->addresses;
216 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200217
218 /* Extract additional MAC addresses if available */
219 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
220 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
221
222 for (i = 1; i < num_mac; i++) {
223 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100224 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200225 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100226 hw->wiphy->n_addresses++;
227 }
228
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200229 iwl_mvm_reset_phy_ctxts(mvm);
230
David Spinadel20f1a5d2013-08-21 09:14:27 +0300231 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
232
Johannes Berg8ca151b2013-01-24 14:25:36 +0100233 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
234
235 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
236 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
237 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
238 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
239 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
240 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
241
242 hw->wiphy->hw_version = mvm->trans->hw_id;
243
Alexander Bondarade50652013-04-03 16:28:47 +0300244 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100245 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
246 else
247 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
248
David Spinadel35a000b2013-08-28 09:29:43 +0300249 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
250 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
251 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
252 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
253 /* we create the 802.11 header and zero length SSID IE. */
254 hw->wiphy->max_sched_scan_ie_len =
255 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
256 }
257
Johannes Berg8ca151b2013-01-24 14:25:36 +0100258 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200259 NL80211_FEATURE_P2P_GO_OPPPS |
260 NL80211_FEATURE_LOW_PRIORITY_SCAN;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100261
262 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
263
Max Stepanove36e5432013-08-27 19:56:13 +0300264 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100265 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300266 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100267 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300268 }
269
Johannes Berg8ca151b2013-01-24 14:25:36 +0100270#ifdef CONFIG_PM_SLEEP
271 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
272 mvm->trans->ops->d3_suspend &&
273 mvm->trans->ops->d3_resume &&
274 device_can_wakeup(mvm->trans->dev)) {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200275 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
276 WIPHY_WOWLAN_DISCONNECT |
277 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
278 WIPHY_WOWLAN_RFKILL_RELEASE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100279 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200280 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
281 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
282 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100283
Johannes Berg964dc9e2013-06-03 17:25:34 +0200284 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
285 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
286 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
287 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
288 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100289 }
290#endif
291
292 ret = iwl_mvm_leds_init(mvm);
293 if (ret)
294 return ret;
295
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300296 ret = ieee80211_register_hw(mvm->hw);
297 if (ret)
298 iwl_mvm_leds_exit(mvm);
299
300 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100301}
302
303static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
304 struct ieee80211_tx_control *control,
305 struct sk_buff *skb)
306{
307 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
308
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300309 if (iwl_mvm_is_radio_killed(mvm)) {
310 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100311 goto drop;
312 }
313
Ilan Peer398e8c62013-03-13 15:20:35 +0200314 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100315 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
316 goto drop;
317
318 if (control->sta) {
319 if (iwl_mvm_tx_skb(mvm, skb, control->sta))
320 goto drop;
321 return;
322 }
323
324 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
325 goto drop;
326 return;
327 drop:
328 ieee80211_free_txskb(hw, skb);
329}
330
331static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
332 struct ieee80211_vif *vif,
333 enum ieee80211_ampdu_mlme_action action,
334 struct ieee80211_sta *sta, u16 tid,
335 u16 *ssn, u8 buf_size)
336{
337 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
338 int ret;
339
340 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
341 sta->addr, tid, action);
342
343 if (!(mvm->nvm_data->sku_cap_11n_enable))
344 return -EACCES;
345
346 mutex_lock(&mvm->mutex);
347
348 switch (action) {
349 case IEEE80211_AMPDU_RX_START:
350 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
351 ret = -EINVAL;
352 break;
353 }
354 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
355 break;
356 case IEEE80211_AMPDU_RX_STOP:
357 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
358 break;
359 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200360 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
361 ret = -EINVAL;
362 break;
363 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100364 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
365 break;
366 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200367 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
368 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100369 case IEEE80211_AMPDU_TX_STOP_FLUSH:
370 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200371 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100372 break;
373 case IEEE80211_AMPDU_TX_OPERATIONAL:
374 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
375 break;
376 default:
377 WARN_ON_ONCE(1);
378 ret = -EINVAL;
379 break;
380 }
381 mutex_unlock(&mvm->mutex);
382
383 return ret;
384}
385
386static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
387 struct ieee80211_vif *vif)
388{
389 struct iwl_mvm *mvm = data;
390 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
391
392 mvmvif->uploaded = false;
393 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
394
395 /* does this make sense at all? */
396 mvmvif->color++;
397
398 spin_lock_bh(&mvm->time_event_lock);
399 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
400 spin_unlock_bh(&mvm->time_event_lock);
401
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200402 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100403}
404
405static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
406{
407 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100408
409 mvm->scan_status = IWL_MVM_SCAN_NONE;
410
411 /* just in case one was running */
412 ieee80211_remain_on_channel_expired(mvm->hw);
413
414 ieee80211_iterate_active_interfaces_atomic(
415 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
416 iwl_mvm_cleanup_iterator, mvm);
417
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200418 mvm->p2p_device_vif = NULL;
419
420 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100421 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
422 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
423
424 ieee80211_wake_queues(mvm->hw);
425
426 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300427 mvm->rx_ba_sessions = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100428}
429
430static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
431{
432 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
433 int ret;
434
435 mutex_lock(&mvm->mutex);
436
437 /* Clean up some internal and mac80211 state on restart */
438 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
439 iwl_mvm_restart_cleanup(mvm);
440
441 ret = iwl_mvm_up(mvm);
442 mutex_unlock(&mvm->mutex);
443
444 return ret;
445}
446
447static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
448{
449 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
450 int ret;
451
452 mutex_lock(&mvm->mutex);
453
454 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
455 ret = iwl_mvm_update_quotas(mvm, NULL);
456 if (ret)
457 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
458 ret);
459
460 mutex_unlock(&mvm->mutex);
461}
462
463static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
464{
465 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
466
467 flush_work(&mvm->async_handlers_wk);
468
469 mutex_lock(&mvm->mutex);
470 /* async_handlers_wk is now blocked */
471
472 /*
473 * The work item could be running or queued if the
474 * ROC time event stops just as we get here.
475 */
476 cancel_work_sync(&mvm->roc_done_wk);
477
478 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100479
480 iwl_mvm_async_handlers_purge(mvm);
481 /* async_handlers_list is empty and will stay empty: HW is stopped */
482
483 /* the fw is stopped, the aux sta is dead: clean up driver state */
484 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
485
486 mutex_unlock(&mvm->mutex);
487
488 /*
489 * The worker might have been waiting for the mutex, let it run and
490 * discover that its list is now empty.
491 */
492 cancel_work_sync(&mvm->async_handlers_wk);
493}
494
Johannes Berg8ca151b2013-01-24 14:25:36 +0100495static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
496 struct ieee80211_vif *vif)
497{
498 struct iwl_mvm *mvm = data;
499
500 iwl_mvm_power_update_mode(mvm, vif);
501}
502
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200503static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
504{
505 u16 i;
506
507 lockdep_assert_held(&mvm->mutex);
508
509 for (i = 0; i < NUM_PHY_CTX; i++)
510 if (!mvm->phy_ctxts[i].ref)
511 return &mvm->phy_ctxts[i];
512
513 IWL_ERR(mvm, "No available PHY context\n");
514 return NULL;
515}
516
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +0200517static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
518 s8 tx_power)
519{
520 /* FW is in charge of regulatory enforcement */
521 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
522 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
523 .pwr_restriction = cpu_to_le16(tx_power),
524 };
525
526 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
527 sizeof(reduce_txpwr_cmd),
528 &reduce_txpwr_cmd);
529}
530
Johannes Berg8ca151b2013-01-24 14:25:36 +0100531static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
532 struct ieee80211_vif *vif)
533{
534 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
535 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
536 int ret;
537
538 /*
539 * Not much to do here. The stack will not allow interface
540 * types or combinations that we didn't advertise, so we
541 * don't really have to check the types.
542 */
543
544 mutex_lock(&mvm->mutex);
545
Eliad Pellere89044d2013-07-16 17:33:26 +0300546 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100547 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
548 if (ret)
549 goto out_unlock;
550
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300551 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +0300552 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
553 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +0300554
555 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100556 * The AP binding flow can be done only after the beacon
557 * template is configured (which happens only in the mac80211
558 * start_ap() flow), and adding the broadcast station can happen
559 * only after the binding.
560 * In addition, since modifying the MAC before adding a bcast
561 * station is not allowed by the FW, delay the adding of MAC context to
562 * the point where we can also add the bcast station.
563 * In short: there's not much we can do at this point, other than
564 * allocating resources :)
565 */
Johannes Berg5023d962013-07-31 14:07:43 +0200566 if (vif->type == NL80211_IFTYPE_AP ||
567 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100568 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
569 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
570 qmask);
571 if (ret) {
572 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
573 goto out_release;
574 }
575
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +0300576 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100577 goto out_unlock;
578 }
579
Johannes Berg8ca151b2013-01-24 14:25:36 +0100580 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
581 if (ret)
582 goto out_release;
583
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300584 iwl_mvm_power_disable(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100585
Hila Gonen7df15b12012-12-12 11:16:19 +0200586 /* beacon filtering */
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300587 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
588 if (ret)
589 goto out_remove_mac;
590
Hila Gonen7df15b12012-12-12 11:16:19 +0200591 if (!mvm->bf_allowed_vif &&
Hila Gonen5dca7c22013-07-16 11:15:35 +0300592 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
593 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
Hila Gonen7df15b12012-12-12 11:16:19 +0200594 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300595 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
596 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +0200597 }
598
Johannes Berg8ca151b2013-01-24 14:25:36 +0100599 /*
600 * P2P_DEVICE interface does not have a channel context assigned to it,
601 * so a dedicated PHY context is allocated to it and the corresponding
602 * MAC context is bound to it at this stage.
603 */
604 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100605
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200606 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
607 if (!mvmvif->phy_ctxt) {
608 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300609 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200610 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100611
Ilan Peer53a9d612013-04-28 11:55:08 +0300612 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100613 ret = iwl_mvm_binding_add_vif(mvm, vif);
614 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +0300615 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100616
617 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
618 if (ret)
619 goto out_unbind;
620
621 /* Save a pointer to p2p device vif, so it can later be used to
622 * update the p2p device MAC when a GO is started/stopped */
623 mvm->p2p_device_vif = vif;
624 }
625
Johannes Berg63494372013-03-26 10:47:53 +0100626 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100627 goto out_unlock;
628
629 out_unbind:
630 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +0300631 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200632 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300633 out_free_bf:
634 if (mvm->bf_allowed_vif == mvmvif) {
635 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300636 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
637 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300638 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100639 out_remove_mac:
640 mvmvif->phy_ctxt = NULL;
641 iwl_mvm_mac_ctxt_remove(mvm, vif);
642 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200643 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
644 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300645
646 /* TODO: remove this when legacy PM will be discarded */
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300647 ieee80211_iterate_active_interfaces(
648 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
649 iwl_mvm_power_update_iterator, mvm);
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300650
Johannes Berg8ca151b2013-01-24 14:25:36 +0100651 iwl_mvm_mac_ctxt_release(mvm, vif);
652 out_unlock:
653 mutex_unlock(&mvm->mutex);
654
655 return ret;
656}
657
Johannes Berg38a12b52013-02-22 14:07:56 +0100658static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
659 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100660{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100661 u32 tfd_msk = 0, ac;
662
663 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
664 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
665 tfd_msk |= BIT(vif->hw_queue[ac]);
666
667 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
668 tfd_msk |= BIT(vif->cab_queue);
669
670 if (tfd_msk) {
671 mutex_lock(&mvm->mutex);
672 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
673 mutex_unlock(&mvm->mutex);
674 }
675
676 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
677 /*
678 * Flush the ROC worker which will flush the OFFCHANNEL queue.
679 * We assume here that all the packets sent to the OFFCHANNEL
680 * queue are sent in ROC session.
681 */
682 flush_work(&mvm->roc_done_wk);
683 } else {
684 /*
685 * By now, all the AC queues are empty. The AGG queues are
686 * empty too. We already got all the Tx responses for all the
687 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +0300688 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100689 */
690 flush_work(&mvm->sta_drained_wk);
691 }
Johannes Berg38a12b52013-02-22 14:07:56 +0100692}
693
694static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
695 struct ieee80211_vif *vif)
696{
697 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
698 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
699
700 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100701
702 mutex_lock(&mvm->mutex);
703
Hila Gonen7df15b12012-12-12 11:16:19 +0200704 if (mvm->bf_allowed_vif == mvmvif) {
705 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300706 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
707 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +0200708 }
709
Johannes Berg63494372013-03-26 10:47:53 +0100710 iwl_mvm_vif_dbgfs_clean(mvm, vif);
711
Johannes Berg8ca151b2013-01-24 14:25:36 +0100712 /*
713 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +0100714 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100715 */
Johannes Berg5023d962013-07-31 14:07:43 +0200716 if (vif->type == NL80211_IFTYPE_AP ||
717 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +0300718#ifdef CONFIG_NL80211_TESTMODE
719 if (vif == mvm->noa_vif) {
720 mvm->noa_vif = NULL;
721 mvm->noa_duration = 0;
722 }
723#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100724 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
725 goto out_release;
726 }
727
728 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
729 mvm->p2p_device_vif = NULL;
730 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
731 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200732 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100733 mvmvif->phy_ctxt = NULL;
734 }
735
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200736 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100737 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300738
739 /* TODO: remove this when legacy PM will be discarded */
740 ieee80211_iterate_active_interfaces(
741 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
742 iwl_mvm_power_update_iterator, mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100743
744 iwl_mvm_mac_ctxt_remove(mvm, vif);
745
746out_release:
747 iwl_mvm_mac_ctxt_release(mvm, vif);
748 mutex_unlock(&mvm->mutex);
749}
750
751static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
752{
753 return 0;
754}
755
Eliad Pellere59647e2013-11-28 14:08:50 +0200756struct iwl_mvm_mc_iter_data {
757 struct iwl_mvm *mvm;
758 int port_id;
759};
760
761static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
762 struct ieee80211_vif *vif)
763{
764 struct iwl_mvm_mc_iter_data *data = _data;
765 struct iwl_mvm *mvm = data->mvm;
766 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
767 int ret, len;
768
769 /* if we don't have free ports, mcast frames will be dropped */
770 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
771 return;
772
773 if (vif->type != NL80211_IFTYPE_STATION ||
774 !vif->bss_conf.assoc)
775 return;
776
777 cmd->port_id = data->port_id++;
778 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
779 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
780
781 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd);
782 if (ret)
783 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
784}
785
786static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
787{
788 struct iwl_mvm_mc_iter_data iter_data = {
789 .mvm = mvm,
790 };
791
792 lockdep_assert_held(&mvm->mutex);
793
794 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
795 return;
796
797 ieee80211_iterate_active_interfaces(
798 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
799 iwl_mvm_mc_iface_iterator, &iter_data);
800}
801
802static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
803 struct netdev_hw_addr_list *mc_list)
804{
805 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
806 struct iwl_mcast_filter_cmd *cmd;
807 struct netdev_hw_addr *addr;
808 int addr_count = netdev_hw_addr_list_count(mc_list);
809 bool pass_all = false;
810 int len;
811
812 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
813 pass_all = true;
814 addr_count = 0;
815 }
816
817 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
818 cmd = kzalloc(len, GFP_ATOMIC);
819 if (!cmd)
820 return 0;
821
822 if (pass_all) {
823 cmd->pass_all = 1;
824 return (u64)(unsigned long)cmd;
825 }
826
827 netdev_hw_addr_list_for_each(addr, mc_list) {
828 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
829 cmd->count, addr->addr);
830 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
831 addr->addr, ETH_ALEN);
832 cmd->count++;
833 }
834
835 return (u64)(unsigned long)cmd;
836}
837
Johannes Berg8ca151b2013-01-24 14:25:36 +0100838static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
839 unsigned int changed_flags,
840 unsigned int *total_flags,
841 u64 multicast)
842{
Eliad Pellere59647e2013-11-28 14:08:50 +0200843 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
844 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
845
846 mutex_lock(&mvm->mutex);
847
848 /* replace previous configuration */
849 kfree(mvm->mcast_filter_cmd);
850 mvm->mcast_filter_cmd = cmd;
851
852 if (!cmd)
853 goto out;
854
855 iwl_mvm_recalc_multicast(mvm);
856out:
857 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100858 *total_flags = 0;
859}
860
861static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
862 struct ieee80211_vif *vif,
863 struct ieee80211_bss_conf *bss_conf,
864 u32 changes)
865{
866 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
867 int ret;
868
Ilan Peer6e97b0d2013-12-23 22:18:02 +0200869 /*
870 * Re-calculate the tsf id, as the master-slave relations depend on the
871 * beacon interval, which was not known when the station interface was
872 * added.
873 */
874 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
875 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
876
Johannes Berg8ca151b2013-01-24 14:25:36 +0100877 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
878 if (ret)
879 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
880
881 if (changes & BSS_CHANGED_ASSOC) {
882 if (bss_conf->assoc) {
883 /* add quota for this interface */
884 ret = iwl_mvm_update_quotas(mvm, vif);
885 if (ret) {
886 IWL_ERR(mvm, "failed to update quotas\n");
887 return;
888 }
Johannes Berg016d27e2013-05-03 11:16:15 +0200889
890 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
891 &mvm->status)) {
892 /*
893 * If we're restarting then the firmware will
894 * obviously have lost synchronisation with
895 * the AP. It will attempt to synchronise by
896 * itself, but we can make it more reliable by
897 * scheduling a session protection time event.
898 *
899 * The firmware needs to receive a beacon to
900 * catch up with synchronisation, use 110% of
901 * the beacon interval.
902 *
903 * Set a large maximum delay to allow for more
904 * than a single interface.
905 */
906 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
907 iwl_mvm_protect_session(mvm, vif, dur, dur,
908 5 * dur);
909 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +0200910
911 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +0300912 iwl_mvm_power_vif_assoc(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100913 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +0200914 /*
915 * If update fails - SF might be running in associated
916 * mode while disassociated - which is forbidden.
917 */
918 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
919 "Failed to update SF upon disassociation\n");
920
Johannes Berg8ca151b2013-01-24 14:25:36 +0100921 /* remove AP station now that the MAC is unassoc */
922 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
923 if (ret)
924 IWL_ERR(mvm, "failed to remove AP station\n");
925 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
926 /* remove quota for this interface */
927 ret = iwl_mvm_update_quotas(mvm, NULL);
928 if (ret)
929 IWL_ERR(mvm, "failed to update quotas\n");
930 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300931
Eliad Pellere59647e2013-11-28 14:08:50 +0200932 iwl_mvm_recalc_multicast(mvm);
933
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300934 /* reset rssi values */
935 mvmvif->bf_data.ave_beacon_signal = 0;
936
Alexander Bondare8e626a2013-10-16 00:21:34 +0200937 if (!(mvm->fw->ucode_capa.flags &
938 IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) {
Alexander Bondare811ada2013-03-10 15:29:44 +0200939 /* Workaround for FW bug, otherwise FW disables device
940 * power save upon disassociation
941 */
942 ret = iwl_mvm_power_update_mode(mvm, vif);
943 if (ret)
944 IWL_ERR(mvm, "failed to update power mode\n");
945 }
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +0300946 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +0200947 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
948 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +0300949 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +0100950 /*
951 * We received a beacon _after_ association so
952 * remove the session protection.
953 */
954 iwl_mvm_remove_time_event(mvm, mvmvif,
955 &mvmvif->time_event_data);
Alexander Bondar51498cf62013-09-02 17:10:14 +0300956 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
957 BSS_CHANGED_QOS)) {
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300958 ret = iwl_mvm_power_update_mode(mvm, vif);
959 if (ret)
960 IWL_ERR(mvm, "failed to update power mode\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100961 }
Matti Gottlieb88f2fd72013-07-09 15:25:46 +0300962 if (changes & BSS_CHANGED_TXPOWER) {
963 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
964 bss_conf->txpower);
965 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
966 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300967
968 if (changes & BSS_CHANGED_CQM) {
969 IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
970 /* reset cqm events tracking */
971 mvmvif->bf_data.last_cqm_event = 0;
972 ret = iwl_mvm_update_beacon_filter(mvm, vif);
973 if (ret)
974 IWL_ERR(mvm, "failed to update CQM thresholds\n");
975 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100976}
977
Johannes Berg5023d962013-07-31 14:07:43 +0200978static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
979 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100980{
981 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
982 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
983 int ret;
984
985 mutex_lock(&mvm->mutex);
986
987 /* Send the beacon template */
988 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
989 if (ret)
990 goto out_unlock;
991
Ilan Peer6e97b0d2013-12-23 22:18:02 +0200992 /*
993 * Re-calculate the tsf id, as the master-slave relations depend on the
994 * beacon interval, which was not known when the AP interface was added.
995 */
996 if (vif->type == NL80211_IFTYPE_AP)
997 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
998
Johannes Berg8ca151b2013-01-24 14:25:36 +0100999 /* Add the mac context */
1000 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1001 if (ret)
1002 goto out_unlock;
1003
1004 /* Perform the binding */
1005 ret = iwl_mvm_binding_add_vif(mvm, vif);
1006 if (ret)
1007 goto out_remove;
1008
Johannes Berg5023d962013-07-31 14:07:43 +02001009 mvmvif->ap_ibss_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001010
1011 /* Send the bcast station. At this stage the TBTT and DTIM time events
1012 * are added and applied to the scheduler */
1013 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1014 if (ret)
1015 goto out_unbind;
1016
Ilan Peer5691e212013-12-31 21:05:50 +02001017 /* must be set before quota calculations */
1018 mvmvif->ap_ibss_active = true;
1019
Ilan Peera11e1442013-12-31 21:19:55 +02001020 /* power updated needs to be done before quotas */
1021 mvm->bound_vif_cnt++;
1022 iwl_mvm_power_update_binding(mvm, vif, true);
1023
Johannes Berg8ca151b2013-01-24 14:25:36 +01001024 ret = iwl_mvm_update_quotas(mvm, vif);
1025 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02001026 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001027
Johannes Berg5023d962013-07-31 14:07:43 +02001028 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001029 if (vif->p2p && mvm->p2p_device_vif)
1030 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1031
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001032 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001033
Johannes Berg8ca151b2013-01-24 14:25:36 +01001034 mutex_unlock(&mvm->mutex);
1035 return 0;
1036
Ilan Peera11e1442013-12-31 21:19:55 +02001037out_quota_failed:
1038 mvm->bound_vif_cnt--;
1039 iwl_mvm_power_update_binding(mvm, vif, false);
Ilan Peer5691e212013-12-31 21:05:50 +02001040 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001041 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1042out_unbind:
1043 iwl_mvm_binding_remove_vif(mvm, vif);
1044out_remove:
1045 iwl_mvm_mac_ctxt_remove(mvm, vif);
1046out_unlock:
1047 mutex_unlock(&mvm->mutex);
1048 return ret;
1049}
1050
Johannes Berg5023d962013-07-31 14:07:43 +02001051static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1052 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001053{
1054 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1055 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1056
Johannes Berg38a12b52013-02-22 14:07:56 +01001057 iwl_mvm_prepare_mac_removal(mvm, vif);
1058
Johannes Berg8ca151b2013-01-24 14:25:36 +01001059 mutex_lock(&mvm->mutex);
1060
Johannes Berg5023d962013-07-31 14:07:43 +02001061 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001062
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001063 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001064
Johannes Berg5023d962013-07-31 14:07:43 +02001065 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001066 if (vif->p2p && mvm->p2p_device_vif)
1067 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1068
1069 iwl_mvm_update_quotas(mvm, NULL);
1070 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1071 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001072
1073 mvm->bound_vif_cnt--;
1074 iwl_mvm_power_update_binding(mvm, vif, false);
1075
Johannes Berg8ca151b2013-01-24 14:25:36 +01001076 iwl_mvm_mac_ctxt_remove(mvm, vif);
1077
1078 mutex_unlock(&mvm->mutex);
1079}
1080
Johannes Berg5023d962013-07-31 14:07:43 +02001081static void
1082iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1083 struct ieee80211_vif *vif,
1084 struct ieee80211_bss_conf *bss_conf,
1085 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001086{
Ilan Peerbe2056f2013-12-04 16:47:14 +02001087 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02001088 enum ieee80211_bss_change ht_change = BSS_CHANGED_ERP_CTS_PROT |
1089 BSS_CHANGED_HT |
1090 BSS_CHANGED_BANDWIDTH;
1091 int ret;
1092
Ilan Peerbe2056f2013-12-04 16:47:14 +02001093 /* Changes will be applied when the AP/IBSS is started */
1094 if (!mvmvif->ap_ibss_active)
1095 return;
1096
Avri Altman8a5e3662013-11-12 19:16:03 +02001097 if (changes & ht_change) {
1098 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1099 if (ret)
1100 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1101 }
1102
Johannes Berg8ca151b2013-01-24 14:25:36 +01001103 /* Need to send a new beacon template to the FW */
1104 if (changes & BSS_CHANGED_BEACON) {
1105 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1106 IWL_WARN(mvm, "Failed updating beacon data\n");
1107 }
1108}
1109
1110static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1111 struct ieee80211_vif *vif,
1112 struct ieee80211_bss_conf *bss_conf,
1113 u32 changes)
1114{
1115 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1116
1117 mutex_lock(&mvm->mutex);
1118
1119 switch (vif->type) {
1120 case NL80211_IFTYPE_STATION:
1121 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1122 break;
1123 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001124 case NL80211_IFTYPE_ADHOC:
1125 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001126 break;
1127 default:
1128 /* shouldn't happen */
1129 WARN_ON_ONCE(1);
1130 }
1131
1132 mutex_unlock(&mvm->mutex);
1133}
1134
1135static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1136 struct ieee80211_vif *vif,
1137 struct cfg80211_scan_request *req)
1138{
1139 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1140 int ret;
1141
1142 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
1143 return -EINVAL;
1144
1145 mutex_lock(&mvm->mutex);
1146
1147 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
1148 ret = iwl_mvm_scan_request(mvm, vif, req);
1149 else
1150 ret = -EBUSY;
1151
1152 mutex_unlock(&mvm->mutex);
1153
1154 return ret;
1155}
1156
1157static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1158 struct ieee80211_vif *vif)
1159{
1160 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1161
1162 mutex_lock(&mvm->mutex);
1163
1164 iwl_mvm_cancel_scan(mvm);
1165
1166 mutex_unlock(&mvm->mutex);
1167}
1168
1169static void
1170iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
1171 struct ieee80211_sta *sta, u16 tid,
1172 int num_frames,
1173 enum ieee80211_frame_release_type reason,
1174 bool more_data)
1175{
1176 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001177
1178 /* TODO: how do we tell the fw to send frames for a specific TID */
1179
1180 /*
1181 * The fw will send EOSP notification when the last frame will be
1182 * transmitted.
1183 */
Johannes Berg9cc40712013-02-15 22:47:48 +01001184 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001185}
1186
1187static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1188 struct ieee80211_vif *vif,
1189 enum sta_notify_cmd cmd,
1190 struct ieee80211_sta *sta)
1191{
1192 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01001193 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001194
1195 switch (cmd) {
1196 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001197 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001198 ieee80211_sta_block_awake(hw, sta, true);
1199 /*
1200 * The fw updates the STA to be asleep. Tx packets on the Tx
1201 * queues to this station will not be transmitted. The fw will
1202 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1203 */
1204 break;
1205 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001206 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001207 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01001208 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001209 break;
1210 default:
1211 break;
1212 }
1213}
1214
1215static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1216 struct ieee80211_vif *vif,
1217 struct ieee80211_sta *sta,
1218 enum ieee80211_sta_state old_state,
1219 enum ieee80211_sta_state new_state)
1220{
1221 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1222 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1223 int ret;
1224
1225 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1226 sta->addr, old_state, new_state);
1227
1228 /* this would be a mac80211 bug ... but don't crash */
1229 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1230 return -EINVAL;
1231
1232 /* if a STA is being removed, reuse its ID */
1233 flush_work(&mvm->sta_drained_wk);
1234
1235 mutex_lock(&mvm->mutex);
1236 if (old_state == IEEE80211_STA_NOTEXIST &&
1237 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02001238 /*
1239 * Firmware bug - it'll crash if the beacon interval is less
1240 * than 16. We can't avoid connecting at all, so refuse the
1241 * station state change, this will cause mac80211 to abandon
1242 * attempts to connect to this AP, and eventually wpa_s will
1243 * blacklist the AP...
1244 */
1245 if (vif->type == NL80211_IFTYPE_STATION &&
1246 vif->bss_conf.beacon_int < 16) {
1247 IWL_ERR(mvm,
1248 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1249 sta->addr, vif->bss_conf.beacon_int);
1250 ret = -EINVAL;
1251 goto out_unlock;
1252 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001253 ret = iwl_mvm_add_sta(mvm, vif, sta);
1254 } else if (old_state == IEEE80211_STA_NONE &&
1255 new_state == IEEE80211_STA_AUTH) {
1256 ret = 0;
1257 } else if (old_state == IEEE80211_STA_AUTH &&
1258 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01001259 ret = iwl_mvm_update_sta(mvm, vif, sta);
1260 if (ret == 0)
1261 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02001262 mvmvif->phy_ctxt->channel->band,
1263 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001264 } else if (old_state == IEEE80211_STA_ASSOC &&
1265 new_state == IEEE80211_STA_AUTHORIZED) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001266 /* enable beacon filtering */
1267 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001268 ret = 0;
1269 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1270 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001271 /* disable beacon filtering */
1272 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001273 ret = 0;
1274 } else if (old_state == IEEE80211_STA_ASSOC &&
1275 new_state == IEEE80211_STA_AUTH) {
1276 ret = 0;
1277 } else if (old_state == IEEE80211_STA_AUTH &&
1278 new_state == IEEE80211_STA_NONE) {
1279 ret = 0;
1280 } else if (old_state == IEEE80211_STA_NONE &&
1281 new_state == IEEE80211_STA_NOTEXIST) {
1282 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1283 } else {
1284 ret = -EIO;
1285 }
Johannes Berg48bc1302013-07-04 15:55:29 +02001286 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001287 mutex_unlock(&mvm->mutex);
1288
1289 return ret;
1290}
1291
1292static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1293{
1294 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1295
1296 mvm->rts_threshold = value;
1297
1298 return 0;
1299}
1300
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001301static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1302 struct ieee80211_vif *vif,
1303 struct ieee80211_sta *sta, u32 changed)
1304{
1305 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1306
1307 if (vif->type == NL80211_IFTYPE_STATION &&
1308 changed & IEEE80211_RC_NSS_CHANGED)
1309 iwl_mvm_sf_update(mvm, vif, false);
1310}
1311
Johannes Berg8ca151b2013-01-24 14:25:36 +01001312static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1313 struct ieee80211_vif *vif, u16 ac,
1314 const struct ieee80211_tx_queue_params *params)
1315{
1316 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1317 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1318
1319 mvmvif->queue_params[ac] = *params;
1320
1321 /*
1322 * No need to update right away, we'll get BSS_CHANGED_QOS
1323 * The exception is P2P_DEVICE interface which needs immediate update.
1324 */
1325 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1326 int ret;
1327
1328 mutex_lock(&mvm->mutex);
1329 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1330 mutex_unlock(&mvm->mutex);
1331 return ret;
1332 }
1333 return 0;
1334}
1335
1336static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1337 struct ieee80211_vif *vif)
1338{
1339 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1340 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1341 200 + vif->bss_conf.beacon_int);
1342 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1343 100 + vif->bss_conf.beacon_int);
1344
1345 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1346 return;
1347
1348 mutex_lock(&mvm->mutex);
1349 /* Try really hard to protect the session and hear a beacon */
Johannes Berg016d27e2013-05-03 11:16:15 +02001350 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001351 mutex_unlock(&mvm->mutex);
1352}
1353
David Spinadel35a000b2013-08-28 09:29:43 +03001354static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1355 struct ieee80211_vif *vif,
1356 struct cfg80211_sched_scan_request *req,
1357 struct ieee80211_sched_scan_ies *ies)
1358{
1359 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1360 int ret;
1361
1362 mutex_lock(&mvm->mutex);
1363
1364 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
1365 IWL_DEBUG_SCAN(mvm,
1366 "SCHED SCAN request during internal scan - abort\n");
1367 ret = -EBUSY;
1368 goto out;
1369 }
1370
1371 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1372
1373 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1374 if (ret)
1375 goto err;
1376
1377 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1378 if (ret)
1379 goto err;
1380
1381 ret = iwl_mvm_sched_scan_start(mvm, req);
1382 if (!ret)
1383 goto out;
1384err:
1385 mvm->scan_status = IWL_MVM_SCAN_NONE;
1386out:
1387 mutex_unlock(&mvm->mutex);
1388 return ret;
1389}
1390
1391static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1392 struct ieee80211_vif *vif)
1393{
1394 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1395
1396 mutex_lock(&mvm->mutex);
1397 iwl_mvm_sched_scan_stop(mvm);
1398 mutex_unlock(&mvm->mutex);
1399}
1400
Johannes Berg8ca151b2013-01-24 14:25:36 +01001401static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1402 enum set_key_cmd cmd,
1403 struct ieee80211_vif *vif,
1404 struct ieee80211_sta *sta,
1405 struct ieee80211_key_conf *key)
1406{
1407 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1408 int ret;
1409
1410 if (iwlwifi_mod_params.sw_crypto) {
1411 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1412 return -EOPNOTSUPP;
1413 }
1414
1415 switch (key->cipher) {
1416 case WLAN_CIPHER_SUITE_TKIP:
1417 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1418 /* fall-through */
1419 case WLAN_CIPHER_SUITE_CCMP:
1420 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1421 break;
1422 case WLAN_CIPHER_SUITE_AES_CMAC:
1423 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1424 break;
1425 case WLAN_CIPHER_SUITE_WEP40:
1426 case WLAN_CIPHER_SUITE_WEP104:
1427 /*
1428 * Support for TX only, at least for now, so accept
1429 * the key and do nothing else. Then mac80211 will
1430 * pass it for TX but we don't have to use it for RX.
1431 */
1432 return 0;
1433 default:
Max Stepanove36e5432013-08-27 19:56:13 +03001434 /* currently FW supports only one optional cipher scheme */
1435 if (hw->n_cipher_schemes &&
1436 hw->cipher_schemes->cipher == key->cipher)
1437 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
1438 else
1439 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001440 }
1441
1442 mutex_lock(&mvm->mutex);
1443
1444 switch (cmd) {
1445 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02001446 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1447 vif->type == NL80211_IFTYPE_AP) && !sta) {
1448 /*
1449 * GTK on AP interface is a TX-only key, return 0;
1450 * on IBSS they're per-station and because we're lazy
1451 * we don't support them for RX, so do the same.
1452 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001453 ret = 0;
1454 key->hw_key_idx = STA_KEY_IDX_INVALID;
1455 break;
1456 }
1457
Johannes Berg8ca151b2013-01-24 14:25:36 +01001458 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1459 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1460 if (ret) {
1461 IWL_WARN(mvm, "set key failed\n");
1462 /*
1463 * can't add key for RX, but we don't need it
1464 * in the device for TX so still return 0
1465 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001466 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001467 ret = 0;
1468 }
1469
1470 break;
1471 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001472 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1473 ret = 0;
1474 break;
1475 }
1476
Johannes Berg8ca151b2013-01-24 14:25:36 +01001477 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1478 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1479 break;
1480 default:
1481 ret = -EINVAL;
1482 }
1483
1484 mutex_unlock(&mvm->mutex);
1485 return ret;
1486}
1487
1488static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1489 struct ieee80211_vif *vif,
1490 struct ieee80211_key_conf *keyconf,
1491 struct ieee80211_sta *sta,
1492 u32 iv32, u16 *phase1key)
1493{
1494 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1495
Johannes Berg5023d962013-07-31 14:07:43 +02001496 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1497 return;
1498
Johannes Berg8ca151b2013-01-24 14:25:36 +01001499 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1500}
1501
1502
1503static int iwl_mvm_roc(struct ieee80211_hw *hw,
1504 struct ieee80211_vif *vif,
1505 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001506 int duration,
1507 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001508{
1509 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001510 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001511 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03001512 struct iwl_mvm_phy_ctxt *phy_ctxt;
1513 int ret, i;
1514
1515 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1516 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001517
1518 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1519 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1520 return -EINVAL;
1521 }
1522
Johannes Berg8ca151b2013-01-24 14:25:36 +01001523 mutex_lock(&mvm->mutex);
1524
Ilan Peer31d385a2013-04-02 10:25:46 +03001525 for (i = 0; i < NUM_PHY_CTX; i++) {
1526 phy_ctxt = &mvm->phy_ctxts[i];
1527 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1528 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001529
Ilan Peer31d385a2013-04-02 10:25:46 +03001530 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1531 /*
1532 * Unbind the P2P_DEVICE from the current PHY context,
1533 * and if the PHY context is not used remove it.
1534 */
1535 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1536 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1537 goto out_unlock;
1538
1539 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1540
1541 /* Bind the P2P_DEVICE to the current PHY Context */
1542 mvmvif->phy_ctxt = phy_ctxt;
1543
1544 ret = iwl_mvm_binding_add_vif(mvm, vif);
1545 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1546 goto out_unlock;
1547
1548 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1549 goto schedule_time_event;
1550 }
1551 }
1552
1553 /* Need to update the PHY context only if the ROC channel changed */
1554 if (channel == mvmvif->phy_ctxt->channel)
1555 goto schedule_time_event;
1556
1557 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1558
1559 /*
1560 * Change the PHY context configuration as it is currently referenced
1561 * only by the P2P Device MAC
1562 */
1563 if (mvmvif->phy_ctxt->ref == 1) {
1564 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1565 &chandef, 1, 1);
1566 if (ret)
1567 goto out_unlock;
1568 } else {
1569 /*
1570 * The PHY context is shared with other MACs. Need to remove the
1571 * P2P Device from the binding, allocate an new PHY context and
1572 * create a new binding
1573 */
1574 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1575 if (!phy_ctxt) {
1576 ret = -ENOSPC;
1577 goto out_unlock;
1578 }
1579
1580 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1581 1, 1);
1582 if (ret) {
1583 IWL_ERR(mvm, "Failed to change PHY context\n");
1584 goto out_unlock;
1585 }
1586
1587 /* Unbind the P2P_DEVICE from the current PHY context */
1588 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1589 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1590 goto out_unlock;
1591
1592 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1593
1594 /* Bind the P2P_DEVICE to the new allocated PHY context */
1595 mvmvif->phy_ctxt = phy_ctxt;
1596
1597 ret = iwl_mvm_binding_add_vif(mvm, vif);
1598 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1599 goto out_unlock;
1600
1601 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1602 }
1603
1604schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001605 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02001606 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001607
Ilan Peer31d385a2013-04-02 10:25:46 +03001608out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001609 mutex_unlock(&mvm->mutex);
1610 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001611 return ret;
1612}
1613
1614static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1615{
1616 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1617
1618 IWL_DEBUG_MAC80211(mvm, "enter\n");
1619
1620 mutex_lock(&mvm->mutex);
1621 iwl_mvm_stop_p2p_roc(mvm);
1622 mutex_unlock(&mvm->mutex);
1623
1624 IWL_DEBUG_MAC80211(mvm, "leave\n");
1625 return 0;
1626}
1627
1628static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1629 struct ieee80211_chanctx_conf *ctx)
1630{
1631 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001632 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1633 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001634 int ret;
1635
Ilan Peer53a9d612013-04-28 11:55:08 +03001636 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001637
1638 mutex_lock(&mvm->mutex);
1639 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1640 if (!phy_ctxt) {
1641 ret = -ENOSPC;
1642 goto out;
1643 }
1644
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02001645 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03001646 ctx->rx_chains_static,
1647 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001648 if (ret) {
1649 IWL_ERR(mvm, "Failed to add PHY context\n");
1650 goto out;
1651 }
1652
Ilan Peer53a9d612013-04-28 11:55:08 +03001653 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001654 *phy_ctxt_id = phy_ctxt->id;
1655out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001656 mutex_unlock(&mvm->mutex);
1657 return ret;
1658}
1659
1660static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1661 struct ieee80211_chanctx_conf *ctx)
1662{
1663 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001664 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1665 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001666
1667 mutex_lock(&mvm->mutex);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001668 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001669 mutex_unlock(&mvm->mutex);
1670}
1671
1672static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1673 struct ieee80211_chanctx_conf *ctx,
1674 u32 changed)
1675{
1676 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001677 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1678 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001679
Ilan Peer31d385a2013-04-02 10:25:46 +03001680 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1681 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1682 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02001683 IEEE80211_CHANCTX_CHANGE_RADAR |
1684 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03001685 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1686 phy_ctxt->ref, changed))
1687 return;
1688
Johannes Berg8ca151b2013-01-24 14:25:36 +01001689 mutex_lock(&mvm->mutex);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02001690 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001691 ctx->rx_chains_static,
1692 ctx->rx_chains_dynamic);
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001693 iwl_mvm_bt_coex_vif_change(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001694 mutex_unlock(&mvm->mutex);
1695}
1696
1697static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1698 struct ieee80211_vif *vif,
1699 struct ieee80211_chanctx_conf *ctx)
1700{
1701 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001702 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1703 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001704 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1705 int ret;
1706
1707 mutex_lock(&mvm->mutex);
1708
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001709 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001710
1711 switch (vif->type) {
1712 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001713 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001714 /*
1715 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02001716 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001717 */
1718 ret = 0;
1719 goto out_unlock;
1720 case NL80211_IFTYPE_STATION:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001721 case NL80211_IFTYPE_MONITOR:
1722 break;
1723 default:
1724 ret = -EINVAL;
1725 goto out_unlock;
1726 }
1727
1728 ret = iwl_mvm_binding_add_vif(mvm, vif);
1729 if (ret)
1730 goto out_unlock;
1731
1732 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02001733 * Power state must be updated before quotas,
1734 * otherwise fw will complain.
1735 */
1736 mvm->bound_vif_cnt++;
1737 iwl_mvm_power_update_binding(mvm, vif, true);
1738
1739 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01001740 * interfaces. For the other types, the bss_info changed flow
1741 * will handle quota settings.
1742 */
1743 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02001744 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001745 ret = iwl_mvm_update_quotas(mvm, vif);
1746 if (ret)
1747 goto out_remove_binding;
1748 }
1749
1750 goto out_unlock;
1751
1752 out_remove_binding:
1753 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar92d85562013-10-23 11:50:34 +02001754 mvm->bound_vif_cnt--;
1755 iwl_mvm_power_update_binding(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001756 out_unlock:
1757 mutex_unlock(&mvm->mutex);
1758 if (ret)
1759 mvmvif->phy_ctxt = NULL;
1760 return ret;
1761}
1762
1763static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1764 struct ieee80211_vif *vif,
1765 struct ieee80211_chanctx_conf *ctx)
1766{
1767 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1768 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1769
1770 mutex_lock(&mvm->mutex);
1771
1772 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1773
Johannes Berg8ca151b2013-01-24 14:25:36 +01001774 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02001775 case NL80211_IFTYPE_AP:
1776 case NL80211_IFTYPE_ADHOC:
1777 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001778 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02001779 mvmvif->monitor_active = false;
1780 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001781 break;
1782 default:
1783 break;
1784 }
1785
Ilan Peer1e1391c2013-03-13 14:52:04 +02001786 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001787 mvm->bound_vif_cnt--;
Alexander Bondar92d85562013-10-23 11:50:34 +02001788 iwl_mvm_power_update_binding(mvm, vif, false);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001789
Ilan Peera11e1442013-12-31 21:19:55 +02001790out_unlock:
1791 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001792 mutex_unlock(&mvm->mutex);
1793}
1794
1795static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1796 struct ieee80211_sta *sta,
1797 bool set)
1798{
1799 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1800 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1801
1802 if (!mvm_sta || !mvm_sta->vif) {
1803 IWL_ERR(mvm, "Station is not associated to a vif\n");
1804 return -EINVAL;
1805 }
1806
1807 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1808}
1809
David Spinadel507cadf2013-07-31 18:07:21 +03001810#ifdef CONFIG_NL80211_TESTMODE
1811static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
1812 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
1813 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02001814 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03001815};
1816
1817static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
1818 struct ieee80211_vif *vif,
1819 void *data, int len)
1820{
1821 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
1822 int err;
1823 u32 noa_duration;
1824
1825 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
1826 if (err)
1827 return err;
1828
1829 if (!tb[IWL_MVM_TM_ATTR_CMD])
1830 return -EINVAL;
1831
1832 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
1833 case IWL_MVM_TM_CMD_SET_NOA:
1834 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
1835 !vif->bss_conf.enable_beacon ||
1836 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
1837 return -EINVAL;
1838
1839 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
1840 if (noa_duration >= vif->bss_conf.beacon_int)
1841 return -EINVAL;
1842
1843 mvm->noa_duration = noa_duration;
1844 mvm->noa_vif = vif;
1845
1846 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02001847 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
1848 /* must be associated client vif - ignore authorized */
1849 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
1850 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
1851 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
1852 return -EINVAL;
1853
1854 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
1855 return iwl_mvm_enable_beacon_filter(mvm, vif);
1856 return iwl_mvm_disable_beacon_filter(mvm, vif);
David Spinadel507cadf2013-07-31 18:07:21 +03001857 }
1858
1859 return -EOPNOTSUPP;
1860}
1861
1862static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
1863 struct ieee80211_vif *vif,
1864 void *data, int len)
1865{
1866 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1867 int err;
1868
1869 mutex_lock(&mvm->mutex);
1870 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
1871 mutex_unlock(&mvm->mutex);
1872
1873 return err;
1874}
1875#endif
1876
Johannes Berg8ca151b2013-01-24 14:25:36 +01001877struct ieee80211_ops iwl_mvm_hw_ops = {
1878 .tx = iwl_mvm_mac_tx,
1879 .ampdu_action = iwl_mvm_mac_ampdu_action,
1880 .start = iwl_mvm_mac_start,
1881 .restart_complete = iwl_mvm_mac_restart_complete,
1882 .stop = iwl_mvm_mac_stop,
1883 .add_interface = iwl_mvm_mac_add_interface,
1884 .remove_interface = iwl_mvm_mac_remove_interface,
1885 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02001886 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001887 .configure_filter = iwl_mvm_configure_filter,
1888 .bss_info_changed = iwl_mvm_bss_info_changed,
1889 .hw_scan = iwl_mvm_mac_hw_scan,
1890 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1891 .sta_state = iwl_mvm_mac_sta_state,
1892 .sta_notify = iwl_mvm_mac_sta_notify,
1893 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1894 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001895 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001896 .conf_tx = iwl_mvm_mac_conf_tx,
1897 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
David Spinadel35a000b2013-08-28 09:29:43 +03001898 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
1899 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001900 .set_key = iwl_mvm_mac_set_key,
1901 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1902 .remain_on_channel = iwl_mvm_roc,
1903 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001904 .add_chanctx = iwl_mvm_add_chanctx,
1905 .remove_chanctx = iwl_mvm_remove_chanctx,
1906 .change_chanctx = iwl_mvm_change_chanctx,
1907 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1908 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1909
Johannes Berg5023d962013-07-31 14:07:43 +02001910 .start_ap = iwl_mvm_start_ap_ibss,
1911 .stop_ap = iwl_mvm_stop_ap_ibss,
1912 .join_ibss = iwl_mvm_start_ap_ibss,
1913 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001914
1915 .set_tim = iwl_mvm_set_tim,
1916
David Spinadel507cadf2013-07-31 18:07:21 +03001917 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
1918
Johannes Berg8ca151b2013-01-24 14:25:36 +01001919#ifdef CONFIG_PM_SLEEP
1920 /* look at d3.c */
1921 .suspend = iwl_mvm_suspend,
1922 .resume = iwl_mvm_resume,
1923 .set_wakeup = iwl_mvm_set_wakeup,
1924 .set_rekey_data = iwl_mvm_set_rekey_data,
1925#if IS_ENABLED(CONFIG_IPV6)
1926 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1927#endif
1928 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1929#endif
1930};