blob: a77007cfd7653af11c00b73dd9866dac4c6284b1 [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 *
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel 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 *
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63#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
264#ifdef CONFIG_PM_SLEEP
265 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
266 mvm->trans->ops->d3_suspend &&
267 mvm->trans->ops->d3_resume &&
268 device_can_wakeup(mvm->trans->dev)) {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200269 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
270 WIPHY_WOWLAN_DISCONNECT |
271 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
272 WIPHY_WOWLAN_RFKILL_RELEASE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100273 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200274 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
275 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
276 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100277
Johannes Berg964dc9e2013-06-03 17:25:34 +0200278 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
279 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
280 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
281 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
282 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100283 }
284#endif
285
286 ret = iwl_mvm_leds_init(mvm);
287 if (ret)
288 return ret;
289
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300290 ret = ieee80211_register_hw(mvm->hw);
291 if (ret)
292 iwl_mvm_leds_exit(mvm);
293
294 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100295}
296
297static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
298 struct ieee80211_tx_control *control,
299 struct sk_buff *skb)
300{
301 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
302
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300303 if (iwl_mvm_is_radio_killed(mvm)) {
304 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100305 goto drop;
306 }
307
Ilan Peer398e8c62013-03-13 15:20:35 +0200308 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100309 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
310 goto drop;
311
312 if (control->sta) {
313 if (iwl_mvm_tx_skb(mvm, skb, control->sta))
314 goto drop;
315 return;
316 }
317
318 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
319 goto drop;
320 return;
321 drop:
322 ieee80211_free_txskb(hw, skb);
323}
324
325static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
326 struct ieee80211_vif *vif,
327 enum ieee80211_ampdu_mlme_action action,
328 struct ieee80211_sta *sta, u16 tid,
329 u16 *ssn, u8 buf_size)
330{
331 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
332 int ret;
333
334 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
335 sta->addr, tid, action);
336
337 if (!(mvm->nvm_data->sku_cap_11n_enable))
338 return -EACCES;
339
340 mutex_lock(&mvm->mutex);
341
342 switch (action) {
343 case IEEE80211_AMPDU_RX_START:
344 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
345 ret = -EINVAL;
346 break;
347 }
348 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
349 break;
350 case IEEE80211_AMPDU_RX_STOP:
351 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
352 break;
353 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200354 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
355 ret = -EINVAL;
356 break;
357 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100358 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
359 break;
360 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200361 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
362 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100363 case IEEE80211_AMPDU_TX_STOP_FLUSH:
364 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200365 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100366 break;
367 case IEEE80211_AMPDU_TX_OPERATIONAL:
368 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
369 break;
370 default:
371 WARN_ON_ONCE(1);
372 ret = -EINVAL;
373 break;
374 }
375 mutex_unlock(&mvm->mutex);
376
377 return ret;
378}
379
380static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
381 struct ieee80211_vif *vif)
382{
383 struct iwl_mvm *mvm = data;
384 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
385
386 mvmvif->uploaded = false;
387 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
388
389 /* does this make sense at all? */
390 mvmvif->color++;
391
392 spin_lock_bh(&mvm->time_event_lock);
393 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
394 spin_unlock_bh(&mvm->time_event_lock);
395
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200396 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100397}
398
399static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
400{
401 iwl_trans_stop_device(mvm->trans);
402 iwl_trans_stop_hw(mvm->trans, false);
403
404 mvm->scan_status = IWL_MVM_SCAN_NONE;
405
406 /* just in case one was running */
407 ieee80211_remain_on_channel_expired(mvm->hw);
408
409 ieee80211_iterate_active_interfaces_atomic(
410 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
411 iwl_mvm_cleanup_iterator, mvm);
412
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200413 mvm->p2p_device_vif = NULL;
414
415 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100416 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
417 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
418
419 ieee80211_wake_queues(mvm->hw);
420
421 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300422 mvm->rx_ba_sessions = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100423}
424
425static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
426{
427 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
428 int ret;
429
430 mutex_lock(&mvm->mutex);
431
432 /* Clean up some internal and mac80211 state on restart */
433 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
434 iwl_mvm_restart_cleanup(mvm);
435
436 ret = iwl_mvm_up(mvm);
437 mutex_unlock(&mvm->mutex);
438
439 return ret;
440}
441
442static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
443{
444 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
445 int ret;
446
447 mutex_lock(&mvm->mutex);
448
449 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
450 ret = iwl_mvm_update_quotas(mvm, NULL);
451 if (ret)
452 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
453 ret);
454
455 mutex_unlock(&mvm->mutex);
456}
457
458static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
459{
460 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
461
462 flush_work(&mvm->async_handlers_wk);
463
464 mutex_lock(&mvm->mutex);
465 /* async_handlers_wk is now blocked */
466
467 /*
468 * The work item could be running or queued if the
469 * ROC time event stops just as we get here.
470 */
471 cancel_work_sync(&mvm->roc_done_wk);
472
473 iwl_trans_stop_device(mvm->trans);
474 iwl_trans_stop_hw(mvm->trans, false);
475
476 iwl_mvm_async_handlers_purge(mvm);
477 /* async_handlers_list is empty and will stay empty: HW is stopped */
478
479 /* the fw is stopped, the aux sta is dead: clean up driver state */
480 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
481
482 mutex_unlock(&mvm->mutex);
483
484 /*
485 * The worker might have been waiting for the mutex, let it run and
486 * discover that its list is now empty.
487 */
488 cancel_work_sync(&mvm->async_handlers_wk);
489}
490
491static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
492 struct ieee80211_vif *vif)
493{
494 struct iwl_mvm *mvm = data;
495 int ret;
496
497 ret = iwl_mvm_power_disable(mvm, vif);
498 if (ret)
499 IWL_ERR(mvm, "failed to disable power management\n");
500}
501
502static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
503 struct ieee80211_vif *vif)
504{
505 struct iwl_mvm *mvm = data;
506
507 iwl_mvm_power_update_mode(mvm, vif);
508}
509
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200510static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
511{
512 u16 i;
513
514 lockdep_assert_held(&mvm->mutex);
515
516 for (i = 0; i < NUM_PHY_CTX; i++)
517 if (!mvm->phy_ctxts[i].ref)
518 return &mvm->phy_ctxts[i];
519
520 IWL_ERR(mvm, "No available PHY context\n");
521 return NULL;
522}
523
Johannes Berg8ca151b2013-01-24 14:25:36 +0100524static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
525 struct ieee80211_vif *vif)
526{
527 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
528 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
529 int ret;
530
531 /*
532 * Not much to do here. The stack will not allow interface
533 * types or combinations that we didn't advertise, so we
534 * don't really have to check the types.
535 */
536
537 mutex_lock(&mvm->mutex);
538
Eliad Pellere89044d2013-07-16 17:33:26 +0300539 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100540 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
541 if (ret)
542 goto out_unlock;
543
544 /*
Ilan Peerea183d02013-07-23 14:41:53 +0300545 * TODO: remove this temporary code.
546 * Currently MVM FW supports power management only on single MAC.
547 * If new interface added, disable PM on existing interface.
548 * P2P device is a special case, since it is handled by FW similary to
549 * scan. If P2P deviced is added, PM remains enabled on existing
550 * interface.
551 * Note: the method below does not count the new interface being added
552 * at this moment.
553 */
554 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
555 mvm->vif_count++;
556 if (mvm->vif_count > 1) {
557 IWL_DEBUG_MAC80211(mvm,
558 "Disable power on existing interfaces\n");
559 ieee80211_iterate_active_interfaces_atomic(
560 mvm->hw,
561 IEEE80211_IFACE_ITER_NORMAL,
562 iwl_mvm_pm_disable_iterator, mvm);
563 }
564
565 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100566 * The AP binding flow can be done only after the beacon
567 * template is configured (which happens only in the mac80211
568 * start_ap() flow), and adding the broadcast station can happen
569 * only after the binding.
570 * In addition, since modifying the MAC before adding a bcast
571 * station is not allowed by the FW, delay the adding of MAC context to
572 * the point where we can also add the bcast station.
573 * In short: there's not much we can do at this point, other than
574 * allocating resources :)
575 */
Johannes Berg5023d962013-07-31 14:07:43 +0200576 if (vif->type == NL80211_IFTYPE_AP ||
577 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100578 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
579 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
580 qmask);
581 if (ret) {
582 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
583 goto out_release;
584 }
585
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +0300586 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100587 goto out_unlock;
588 }
589
Johannes Berg8ca151b2013-01-24 14:25:36 +0100590 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
591 if (ret)
592 goto out_release;
593
594 /*
595 * Update power state on the new interface. Admittedly, based on
596 * mac80211 logics this power update will disable power management
597 */
598 iwl_mvm_power_update_mode(mvm, vif);
599
Hila Gonen7df15b12012-12-12 11:16:19 +0200600 /* beacon filtering */
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300601 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
602 if (ret)
603 goto out_remove_mac;
604
Hila Gonen7df15b12012-12-12 11:16:19 +0200605 if (!mvm->bf_allowed_vif &&
Hila Gonen5dca7c22013-07-16 11:15:35 +0300606 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
607 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
Hila Gonen7df15b12012-12-12 11:16:19 +0200608 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300609 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
610 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +0200611 }
612
Johannes Berg8ca151b2013-01-24 14:25:36 +0100613 /*
614 * P2P_DEVICE interface does not have a channel context assigned to it,
615 * so a dedicated PHY context is allocated to it and the corresponding
616 * MAC context is bound to it at this stage.
617 */
618 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100619
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200620 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
621 if (!mvmvif->phy_ctxt) {
622 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300623 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200624 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100625
Ilan Peer53a9d612013-04-28 11:55:08 +0300626 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100627 ret = iwl_mvm_binding_add_vif(mvm, vif);
628 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +0300629 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100630
631 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
632 if (ret)
633 goto out_unbind;
634
635 /* Save a pointer to p2p device vif, so it can later be used to
636 * update the p2p device MAC when a GO is started/stopped */
637 mvm->p2p_device_vif = vif;
638 }
639
Johannes Berg63494372013-03-26 10:47:53 +0100640 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100641 goto out_unlock;
642
643 out_unbind:
644 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +0300645 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200646 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300647 out_free_bf:
648 if (mvm->bf_allowed_vif == mvmvif) {
649 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300650 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
651 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300652 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100653 out_remove_mac:
654 mvmvif->phy_ctxt = NULL;
655 iwl_mvm_mac_ctxt_remove(mvm, vif);
656 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200657 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
658 mvm->vif_count--;
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300659 ieee80211_iterate_active_interfaces(
660 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
661 iwl_mvm_power_update_iterator, mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100662 iwl_mvm_mac_ctxt_release(mvm, vif);
663 out_unlock:
664 mutex_unlock(&mvm->mutex);
665
666 return ret;
667}
668
Johannes Berg38a12b52013-02-22 14:07:56 +0100669static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
670 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100671{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100672 u32 tfd_msk = 0, ac;
673
674 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
675 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
676 tfd_msk |= BIT(vif->hw_queue[ac]);
677
678 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
679 tfd_msk |= BIT(vif->cab_queue);
680
681 if (tfd_msk) {
682 mutex_lock(&mvm->mutex);
683 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
684 mutex_unlock(&mvm->mutex);
685 }
686
687 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
688 /*
689 * Flush the ROC worker which will flush the OFFCHANNEL queue.
690 * We assume here that all the packets sent to the OFFCHANNEL
691 * queue are sent in ROC session.
692 */
693 flush_work(&mvm->roc_done_wk);
694 } else {
695 /*
696 * By now, all the AC queues are empty. The AGG queues are
697 * empty too. We already got all the Tx responses for all the
698 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +0300699 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100700 */
701 flush_work(&mvm->sta_drained_wk);
702 }
Johannes Berg38a12b52013-02-22 14:07:56 +0100703}
704
705static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
706 struct ieee80211_vif *vif)
707{
708 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
709 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
710
711 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100712
713 mutex_lock(&mvm->mutex);
714
Hila Gonen7df15b12012-12-12 11:16:19 +0200715 if (mvm->bf_allowed_vif == mvmvif) {
716 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300717 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
718 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +0200719 }
720
Johannes Berg63494372013-03-26 10:47:53 +0100721 iwl_mvm_vif_dbgfs_clean(mvm, vif);
722
Johannes Berg8ca151b2013-01-24 14:25:36 +0100723 /*
724 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +0100725 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100726 */
Johannes Berg5023d962013-07-31 14:07:43 +0200727 if (vif->type == NL80211_IFTYPE_AP ||
728 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +0300729#ifdef CONFIG_NL80211_TESTMODE
730 if (vif == mvm->noa_vif) {
731 mvm->noa_vif = NULL;
732 mvm->noa_duration = 0;
733 }
734#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100735 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
736 goto out_release;
737 }
738
739 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
740 mvm->p2p_device_vif = NULL;
741 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
742 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200743 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100744 mvmvif->phy_ctxt = NULL;
745 }
746
747 /*
748 * TODO: remove this temporary code.
749 * Currently MVM FW supports power management only on single MAC.
750 * Check if only one additional interface remains after removing
751 * current one. Update power mode on the remaining interface.
752 */
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200753 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100754 mvm->vif_count--;
755 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
756 mvm->vif_count);
757 if (mvm->vif_count == 1) {
758 ieee80211_iterate_active_interfaces(
759 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
760 iwl_mvm_power_update_iterator, mvm);
761 }
762
763 iwl_mvm_mac_ctxt_remove(mvm, vif);
764
765out_release:
766 iwl_mvm_mac_ctxt_release(mvm, vif);
767 mutex_unlock(&mvm->mutex);
768}
769
Matti Gottlieb88f2fd72013-07-09 15:25:46 +0300770static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
771 s8 tx_power)
772{
773 /* FW is in charge of regulatory enforcement */
774 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
775 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
776 .pwr_restriction = cpu_to_le16(tx_power),
777 };
778
779 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
780 sizeof(reduce_txpwr_cmd),
781 &reduce_txpwr_cmd);
782}
783
Johannes Berg8ca151b2013-01-24 14:25:36 +0100784static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
785{
786 return 0;
787}
788
789static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
790 unsigned int changed_flags,
791 unsigned int *total_flags,
792 u64 multicast)
793{
794 *total_flags = 0;
795}
796
Emmanuel Grumbach51b6b9e2013-05-02 15:01:24 +0300797static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
798 struct ieee80211_vif *vif)
799{
800 struct iwl_mcast_filter_cmd mcast_filter_cmd = {
801 .pass_all = 1,
802 };
803
804 memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
805
806 return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
807 sizeof(mcast_filter_cmd),
808 &mcast_filter_cmd);
809}
810
Johannes Berg8ca151b2013-01-24 14:25:36 +0100811static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
812 struct ieee80211_vif *vif,
813 struct ieee80211_bss_conf *bss_conf,
814 u32 changes)
815{
816 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
817 int ret;
818
819 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
820 if (ret)
821 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
822
823 if (changes & BSS_CHANGED_ASSOC) {
824 if (bss_conf->assoc) {
825 /* add quota for this interface */
826 ret = iwl_mvm_update_quotas(mvm, vif);
827 if (ret) {
828 IWL_ERR(mvm, "failed to update quotas\n");
829 return;
830 }
Emmanuel Grumbach51b6b9e2013-05-02 15:01:24 +0300831 iwl_mvm_configure_mcast_filter(mvm, vif);
Johannes Berg016d27e2013-05-03 11:16:15 +0200832
833 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
834 &mvm->status)) {
835 /*
836 * If we're restarting then the firmware will
837 * obviously have lost synchronisation with
838 * the AP. It will attempt to synchronise by
839 * itself, but we can make it more reliable by
840 * scheduling a session protection time event.
841 *
842 * The firmware needs to receive a beacon to
843 * catch up with synchronisation, use 110% of
844 * the beacon interval.
845 *
846 * Set a large maximum delay to allow for more
847 * than a single interface.
848 */
849 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
850 iwl_mvm_protect_session(mvm, vif, dur, dur,
851 5 * dur);
852 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100853 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
854 /* remove AP station now that the MAC is unassoc */
855 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
856 if (ret)
857 IWL_ERR(mvm, "failed to remove AP station\n");
858 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
859 /* remove quota for this interface */
860 ret = iwl_mvm_update_quotas(mvm, NULL);
861 if (ret)
862 IWL_ERR(mvm, "failed to update quotas\n");
863 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300864
865 /* reset rssi values */
866 mvmvif->bf_data.ave_beacon_signal = 0;
867
Alexander Bondare8e626a2013-10-16 00:21:34 +0200868 if (!(mvm->fw->ucode_capa.flags &
869 IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) {
Alexander Bondare811ada2013-03-10 15:29:44 +0200870 /* Workaround for FW bug, otherwise FW disables device
871 * power save upon disassociation
872 */
873 ret = iwl_mvm_power_update_mode(mvm, vif);
874 if (ret)
875 IWL_ERR(mvm, "failed to update power mode\n");
876 }
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +0300877 iwl_mvm_bt_coex_vif_change(mvm);
Alexander Bondar989c6502013-05-16 17:34:17 +0300878 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +0100879 /*
880 * We received a beacon _after_ association so
881 * remove the session protection.
882 */
883 iwl_mvm_remove_time_event(mvm, mvmvif,
884 &mvmvif->time_event_data);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300885 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_QOS)) {
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300886 ret = iwl_mvm_power_update_mode(mvm, vif);
887 if (ret)
888 IWL_ERR(mvm, "failed to update power mode\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100889 }
Matti Gottlieb88f2fd72013-07-09 15:25:46 +0300890 if (changes & BSS_CHANGED_TXPOWER) {
891 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
892 bss_conf->txpower);
893 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
894 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300895
896 if (changes & BSS_CHANGED_CQM) {
897 IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
898 /* reset cqm events tracking */
899 mvmvif->bf_data.last_cqm_event = 0;
900 ret = iwl_mvm_update_beacon_filter(mvm, vif);
901 if (ret)
902 IWL_ERR(mvm, "failed to update CQM thresholds\n");
903 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100904}
905
Johannes Berg5023d962013-07-31 14:07:43 +0200906static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
907 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100908{
909 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
910 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
911 int ret;
912
913 mutex_lock(&mvm->mutex);
914
915 /* Send the beacon template */
916 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
917 if (ret)
918 goto out_unlock;
919
920 /* Add the mac context */
921 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
922 if (ret)
923 goto out_unlock;
924
925 /* Perform the binding */
926 ret = iwl_mvm_binding_add_vif(mvm, vif);
927 if (ret)
928 goto out_remove;
929
Johannes Berg5023d962013-07-31 14:07:43 +0200930 mvmvif->ap_ibss_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100931
932 /* Send the bcast station. At this stage the TBTT and DTIM time events
933 * are added and applied to the scheduler */
934 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
935 if (ret)
936 goto out_unbind;
937
938 ret = iwl_mvm_update_quotas(mvm, vif);
939 if (ret)
940 goto out_rm_bcast;
941
Johannes Berg5023d962013-07-31 14:07:43 +0200942 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100943 if (vif->p2p && mvm->p2p_device_vif)
944 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
945
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +0300946 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300947
Johannes Berg8ca151b2013-01-24 14:25:36 +0100948 mutex_unlock(&mvm->mutex);
949 return 0;
950
951out_rm_bcast:
952 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
953out_unbind:
954 iwl_mvm_binding_remove_vif(mvm, vif);
955out_remove:
956 iwl_mvm_mac_ctxt_remove(mvm, vif);
957out_unlock:
958 mutex_unlock(&mvm->mutex);
959 return ret;
960}
961
Johannes Berg5023d962013-07-31 14:07:43 +0200962static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
963 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100964{
965 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
966 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
967
Johannes Berg38a12b52013-02-22 14:07:56 +0100968 iwl_mvm_prepare_mac_removal(mvm, vif);
969
Johannes Berg8ca151b2013-01-24 14:25:36 +0100970 mutex_lock(&mvm->mutex);
971
Johannes Berg5023d962013-07-31 14:07:43 +0200972 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100973
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +0300974 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300975
Johannes Berg5023d962013-07-31 14:07:43 +0200976 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100977 if (vif->p2p && mvm->p2p_device_vif)
978 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
979
980 iwl_mvm_update_quotas(mvm, NULL);
981 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
982 iwl_mvm_binding_remove_vif(mvm, vif);
983 iwl_mvm_mac_ctxt_remove(mvm, vif);
984
985 mutex_unlock(&mvm->mutex);
986}
987
Johannes Berg5023d962013-07-31 14:07:43 +0200988static void
989iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
990 struct ieee80211_vif *vif,
991 struct ieee80211_bss_conf *bss_conf,
992 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100993{
Avri Altman8a5e3662013-11-12 19:16:03 +0200994 enum ieee80211_bss_change ht_change = BSS_CHANGED_ERP_CTS_PROT |
995 BSS_CHANGED_HT |
996 BSS_CHANGED_BANDWIDTH;
997 int ret;
998
999 if (changes & ht_change) {
1000 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1001 if (ret)
1002 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1003 }
1004
Johannes Berg8ca151b2013-01-24 14:25:36 +01001005 /* Need to send a new beacon template to the FW */
1006 if (changes & BSS_CHANGED_BEACON) {
1007 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1008 IWL_WARN(mvm, "Failed updating beacon data\n");
1009 }
1010}
1011
1012static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1013 struct ieee80211_vif *vif,
1014 struct ieee80211_bss_conf *bss_conf,
1015 u32 changes)
1016{
1017 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1018
1019 mutex_lock(&mvm->mutex);
1020
1021 switch (vif->type) {
1022 case NL80211_IFTYPE_STATION:
1023 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1024 break;
1025 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001026 case NL80211_IFTYPE_ADHOC:
1027 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001028 break;
1029 default:
1030 /* shouldn't happen */
1031 WARN_ON_ONCE(1);
1032 }
1033
1034 mutex_unlock(&mvm->mutex);
1035}
1036
1037static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1038 struct ieee80211_vif *vif,
1039 struct cfg80211_scan_request *req)
1040{
1041 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1042 int ret;
1043
1044 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
1045 return -EINVAL;
1046
1047 mutex_lock(&mvm->mutex);
1048
1049 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
1050 ret = iwl_mvm_scan_request(mvm, vif, req);
1051 else
1052 ret = -EBUSY;
1053
1054 mutex_unlock(&mvm->mutex);
1055
1056 return ret;
1057}
1058
1059static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1060 struct ieee80211_vif *vif)
1061{
1062 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1063
1064 mutex_lock(&mvm->mutex);
1065
1066 iwl_mvm_cancel_scan(mvm);
1067
1068 mutex_unlock(&mvm->mutex);
1069}
1070
1071static void
1072iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
1073 struct ieee80211_sta *sta, u16 tid,
1074 int num_frames,
1075 enum ieee80211_frame_release_type reason,
1076 bool more_data)
1077{
1078 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001079
1080 /* TODO: how do we tell the fw to send frames for a specific TID */
1081
1082 /*
1083 * The fw will send EOSP notification when the last frame will be
1084 * transmitted.
1085 */
Johannes Berg9cc40712013-02-15 22:47:48 +01001086 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001087}
1088
1089static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1090 struct ieee80211_vif *vif,
1091 enum sta_notify_cmd cmd,
1092 struct ieee80211_sta *sta)
1093{
1094 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01001095 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001096
1097 switch (cmd) {
1098 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001099 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001100 ieee80211_sta_block_awake(hw, sta, true);
1101 /*
1102 * The fw updates the STA to be asleep. Tx packets on the Tx
1103 * queues to this station will not be transmitted. The fw will
1104 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1105 */
1106 break;
1107 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001108 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001109 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01001110 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001111 break;
1112 default:
1113 break;
1114 }
1115}
1116
Johannes Berg1ddbbb02013-12-04 22:39:17 +01001117static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1118 struct ieee80211_vif *vif,
1119 struct ieee80211_sta *sta)
1120{
1121 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1122 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1123
1124 /*
1125 * This is called before mac80211 does RCU synchronisation,
1126 * so here we already invalidate our internal RCU-protected
1127 * station pointer. The rest of the code will thus no longer
1128 * be able to find the station this way, and we don't rely
1129 * on further RCU synchronisation after the sta_state()
1130 * callback deleted the station.
1131 */
1132 mutex_lock(&mvm->mutex);
1133 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1134 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1135 ERR_PTR(-ENOENT));
1136 mutex_unlock(&mvm->mutex);
1137}
1138
Johannes Berg8ca151b2013-01-24 14:25:36 +01001139static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1140 struct ieee80211_vif *vif,
1141 struct ieee80211_sta *sta,
1142 enum ieee80211_sta_state old_state,
1143 enum ieee80211_sta_state new_state)
1144{
1145 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1146 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1147 int ret;
1148
1149 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1150 sta->addr, old_state, new_state);
1151
1152 /* this would be a mac80211 bug ... but don't crash */
1153 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1154 return -EINVAL;
1155
1156 /* if a STA is being removed, reuse its ID */
1157 flush_work(&mvm->sta_drained_wk);
1158
1159 mutex_lock(&mvm->mutex);
1160 if (old_state == IEEE80211_STA_NOTEXIST &&
1161 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02001162 /*
1163 * Firmware bug - it'll crash if the beacon interval is less
1164 * than 16. We can't avoid connecting at all, so refuse the
1165 * station state change, this will cause mac80211 to abandon
1166 * attempts to connect to this AP, and eventually wpa_s will
1167 * blacklist the AP...
1168 */
1169 if (vif->type == NL80211_IFTYPE_STATION &&
1170 vif->bss_conf.beacon_int < 16) {
1171 IWL_ERR(mvm,
1172 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1173 sta->addr, vif->bss_conf.beacon_int);
1174 ret = -EINVAL;
1175 goto out_unlock;
1176 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001177 ret = iwl_mvm_add_sta(mvm, vif, sta);
1178 } else if (old_state == IEEE80211_STA_NONE &&
1179 new_state == IEEE80211_STA_AUTH) {
1180 ret = 0;
1181 } else if (old_state == IEEE80211_STA_AUTH &&
1182 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01001183 ret = iwl_mvm_update_sta(mvm, vif, sta);
1184 if (ret == 0)
1185 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02001186 mvmvif->phy_ctxt->channel->band,
1187 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001188 } else if (old_state == IEEE80211_STA_ASSOC &&
1189 new_state == IEEE80211_STA_AUTHORIZED) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001190 /* enable beacon filtering */
1191 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001192 ret = 0;
1193 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1194 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001195 /* disable beacon filtering */
1196 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001197 ret = 0;
1198 } else if (old_state == IEEE80211_STA_ASSOC &&
1199 new_state == IEEE80211_STA_AUTH) {
1200 ret = 0;
1201 } else if (old_state == IEEE80211_STA_AUTH &&
1202 new_state == IEEE80211_STA_NONE) {
1203 ret = 0;
1204 } else if (old_state == IEEE80211_STA_NONE &&
1205 new_state == IEEE80211_STA_NOTEXIST) {
1206 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1207 } else {
1208 ret = -EIO;
1209 }
Johannes Berg48bc1302013-07-04 15:55:29 +02001210 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001211 mutex_unlock(&mvm->mutex);
1212
1213 return ret;
1214}
1215
1216static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1217{
1218 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1219
1220 mvm->rts_threshold = value;
1221
1222 return 0;
1223}
1224
1225static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1226 struct ieee80211_vif *vif, u16 ac,
1227 const struct ieee80211_tx_queue_params *params)
1228{
1229 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1230 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1231
1232 mvmvif->queue_params[ac] = *params;
1233
1234 /*
1235 * No need to update right away, we'll get BSS_CHANGED_QOS
1236 * The exception is P2P_DEVICE interface which needs immediate update.
1237 */
1238 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1239 int ret;
1240
1241 mutex_lock(&mvm->mutex);
1242 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1243 mutex_unlock(&mvm->mutex);
1244 return ret;
1245 }
1246 return 0;
1247}
1248
1249static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1250 struct ieee80211_vif *vif)
1251{
1252 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1253 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1254 200 + vif->bss_conf.beacon_int);
1255 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1256 100 + vif->bss_conf.beacon_int);
1257
1258 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1259 return;
1260
1261 mutex_lock(&mvm->mutex);
1262 /* Try really hard to protect the session and hear a beacon */
Johannes Berg016d27e2013-05-03 11:16:15 +02001263 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001264 mutex_unlock(&mvm->mutex);
1265}
1266
David Spinadel35a000b2013-08-28 09:29:43 +03001267static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1268 struct ieee80211_vif *vif,
1269 struct cfg80211_sched_scan_request *req,
1270 struct ieee80211_sched_scan_ies *ies)
1271{
1272 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1273 int ret;
1274
1275 mutex_lock(&mvm->mutex);
1276
1277 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
1278 IWL_DEBUG_SCAN(mvm,
1279 "SCHED SCAN request during internal scan - abort\n");
1280 ret = -EBUSY;
1281 goto out;
1282 }
1283
1284 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1285
1286 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1287 if (ret)
1288 goto err;
1289
1290 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1291 if (ret)
1292 goto err;
1293
1294 ret = iwl_mvm_sched_scan_start(mvm, req);
1295 if (!ret)
1296 goto out;
1297err:
1298 mvm->scan_status = IWL_MVM_SCAN_NONE;
1299out:
1300 mutex_unlock(&mvm->mutex);
1301 return ret;
1302}
1303
1304static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1305 struct ieee80211_vif *vif)
1306{
1307 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1308
1309 mutex_lock(&mvm->mutex);
1310 iwl_mvm_sched_scan_stop(mvm);
1311 mutex_unlock(&mvm->mutex);
1312}
1313
Johannes Berg8ca151b2013-01-24 14:25:36 +01001314static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1315 enum set_key_cmd cmd,
1316 struct ieee80211_vif *vif,
1317 struct ieee80211_sta *sta,
1318 struct ieee80211_key_conf *key)
1319{
1320 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1321 int ret;
1322
1323 if (iwlwifi_mod_params.sw_crypto) {
1324 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1325 return -EOPNOTSUPP;
1326 }
1327
1328 switch (key->cipher) {
1329 case WLAN_CIPHER_SUITE_TKIP:
1330 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1331 /* fall-through */
1332 case WLAN_CIPHER_SUITE_CCMP:
1333 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1334 break;
1335 case WLAN_CIPHER_SUITE_AES_CMAC:
1336 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1337 break;
1338 case WLAN_CIPHER_SUITE_WEP40:
1339 case WLAN_CIPHER_SUITE_WEP104:
1340 /*
1341 * Support for TX only, at least for now, so accept
1342 * the key and do nothing else. Then mac80211 will
1343 * pass it for TX but we don't have to use it for RX.
1344 */
1345 return 0;
1346 default:
1347 return -EOPNOTSUPP;
1348 }
1349
1350 mutex_lock(&mvm->mutex);
1351
1352 switch (cmd) {
1353 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02001354 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1355 vif->type == NL80211_IFTYPE_AP) && !sta) {
1356 /*
1357 * GTK on AP interface is a TX-only key, return 0;
1358 * on IBSS they're per-station and because we're lazy
1359 * we don't support them for RX, so do the same.
1360 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001361 ret = 0;
1362 key->hw_key_idx = STA_KEY_IDX_INVALID;
1363 break;
1364 }
1365
Johannes Berg8ca151b2013-01-24 14:25:36 +01001366 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1367 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1368 if (ret) {
1369 IWL_WARN(mvm, "set key failed\n");
1370 /*
1371 * can't add key for RX, but we don't need it
1372 * in the device for TX so still return 0
1373 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001374 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001375 ret = 0;
1376 }
1377
1378 break;
1379 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001380 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1381 ret = 0;
1382 break;
1383 }
1384
Johannes Berg8ca151b2013-01-24 14:25:36 +01001385 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1386 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1387 break;
1388 default:
1389 ret = -EINVAL;
1390 }
1391
1392 mutex_unlock(&mvm->mutex);
1393 return ret;
1394}
1395
1396static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1397 struct ieee80211_vif *vif,
1398 struct ieee80211_key_conf *keyconf,
1399 struct ieee80211_sta *sta,
1400 u32 iv32, u16 *phase1key)
1401{
1402 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1403
Johannes Berg5023d962013-07-31 14:07:43 +02001404 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1405 return;
1406
Johannes Berg8ca151b2013-01-24 14:25:36 +01001407 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1408}
1409
1410
1411static int iwl_mvm_roc(struct ieee80211_hw *hw,
1412 struct ieee80211_vif *vif,
1413 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001414 int duration,
1415 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001416{
1417 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001418 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001419 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03001420 struct iwl_mvm_phy_ctxt *phy_ctxt;
1421 int ret, i;
1422
1423 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1424 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001425
1426 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1427 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1428 return -EINVAL;
1429 }
1430
Johannes Berg8ca151b2013-01-24 14:25:36 +01001431 mutex_lock(&mvm->mutex);
1432
Ilan Peer31d385a2013-04-02 10:25:46 +03001433 for (i = 0; i < NUM_PHY_CTX; i++) {
1434 phy_ctxt = &mvm->phy_ctxts[i];
1435 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1436 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001437
Ilan Peer31d385a2013-04-02 10:25:46 +03001438 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1439 /*
1440 * Unbind the P2P_DEVICE from the current PHY context,
1441 * and if the PHY context is not used remove it.
1442 */
1443 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1444 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1445 goto out_unlock;
1446
1447 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1448
1449 /* Bind the P2P_DEVICE to the current PHY Context */
1450 mvmvif->phy_ctxt = phy_ctxt;
1451
1452 ret = iwl_mvm_binding_add_vif(mvm, vif);
1453 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1454 goto out_unlock;
1455
1456 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1457 goto schedule_time_event;
1458 }
1459 }
1460
1461 /* Need to update the PHY context only if the ROC channel changed */
1462 if (channel == mvmvif->phy_ctxt->channel)
1463 goto schedule_time_event;
1464
1465 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1466
1467 /*
1468 * Change the PHY context configuration as it is currently referenced
1469 * only by the P2P Device MAC
1470 */
1471 if (mvmvif->phy_ctxt->ref == 1) {
1472 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1473 &chandef, 1, 1);
1474 if (ret)
1475 goto out_unlock;
1476 } else {
1477 /*
1478 * The PHY context is shared with other MACs. Need to remove the
1479 * P2P Device from the binding, allocate an new PHY context and
1480 * create a new binding
1481 */
1482 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1483 if (!phy_ctxt) {
1484 ret = -ENOSPC;
1485 goto out_unlock;
1486 }
1487
1488 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1489 1, 1);
1490 if (ret) {
1491 IWL_ERR(mvm, "Failed to change PHY context\n");
1492 goto out_unlock;
1493 }
1494
1495 /* Unbind the P2P_DEVICE from the current PHY context */
1496 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1497 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1498 goto out_unlock;
1499
1500 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1501
1502 /* Bind the P2P_DEVICE to the new allocated PHY context */
1503 mvmvif->phy_ctxt = phy_ctxt;
1504
1505 ret = iwl_mvm_binding_add_vif(mvm, vif);
1506 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1507 goto out_unlock;
1508
1509 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1510 }
1511
1512schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001513 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02001514 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001515
Ilan Peer31d385a2013-04-02 10:25:46 +03001516out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001517 mutex_unlock(&mvm->mutex);
1518 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001519 return ret;
1520}
1521
1522static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1523{
1524 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1525
1526 IWL_DEBUG_MAC80211(mvm, "enter\n");
1527
1528 mutex_lock(&mvm->mutex);
1529 iwl_mvm_stop_p2p_roc(mvm);
1530 mutex_unlock(&mvm->mutex);
1531
1532 IWL_DEBUG_MAC80211(mvm, "leave\n");
1533 return 0;
1534}
1535
1536static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1537 struct ieee80211_chanctx_conf *ctx)
1538{
1539 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001540 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1541 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001542 int ret;
1543
Ilan Peer53a9d612013-04-28 11:55:08 +03001544 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001545
1546 mutex_lock(&mvm->mutex);
1547 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1548 if (!phy_ctxt) {
1549 ret = -ENOSPC;
1550 goto out;
1551 }
1552
Ilan Peer53a9d612013-04-28 11:55:08 +03001553 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1554 ctx->rx_chains_static,
1555 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001556 if (ret) {
1557 IWL_ERR(mvm, "Failed to add PHY context\n");
1558 goto out;
1559 }
1560
Ilan Peer53a9d612013-04-28 11:55:08 +03001561 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001562 *phy_ctxt_id = phy_ctxt->id;
1563out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001564 mutex_unlock(&mvm->mutex);
1565 return ret;
1566}
1567
1568static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1569 struct ieee80211_chanctx_conf *ctx)
1570{
1571 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001572 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1573 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001574
1575 mutex_lock(&mvm->mutex);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001576 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001577 mutex_unlock(&mvm->mutex);
1578}
1579
1580static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1581 struct ieee80211_chanctx_conf *ctx,
1582 u32 changed)
1583{
1584 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001585 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1586 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001587
Ilan Peer31d385a2013-04-02 10:25:46 +03001588 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1589 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1590 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
1591 IEEE80211_CHANCTX_CHANGE_RADAR)),
1592 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1593 phy_ctxt->ref, changed))
1594 return;
1595
Johannes Berg8ca151b2013-01-24 14:25:36 +01001596 mutex_lock(&mvm->mutex);
1597 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1598 ctx->rx_chains_static,
1599 ctx->rx_chains_dynamic);
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001600 iwl_mvm_bt_coex_vif_change(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001601 mutex_unlock(&mvm->mutex);
1602}
1603
1604static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1605 struct ieee80211_vif *vif,
1606 struct ieee80211_chanctx_conf *ctx)
1607{
1608 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001609 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1610 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001611 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1612 int ret;
1613
1614 mutex_lock(&mvm->mutex);
1615
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001616 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001617
1618 switch (vif->type) {
1619 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001620 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001621 /*
1622 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02001623 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001624 */
1625 ret = 0;
1626 goto out_unlock;
1627 case NL80211_IFTYPE_STATION:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001628 case NL80211_IFTYPE_MONITOR:
1629 break;
1630 default:
1631 ret = -EINVAL;
1632 goto out_unlock;
1633 }
1634
1635 ret = iwl_mvm_binding_add_vif(mvm, vif);
1636 if (ret)
1637 goto out_unlock;
1638
1639 /*
1640 * Setting the quota at this stage is only required for monitor
1641 * interfaces. For the other types, the bss_info changed flow
1642 * will handle quota settings.
1643 */
1644 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02001645 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001646 ret = iwl_mvm_update_quotas(mvm, vif);
1647 if (ret)
1648 goto out_remove_binding;
1649 }
1650
1651 goto out_unlock;
1652
1653 out_remove_binding:
1654 iwl_mvm_binding_remove_vif(mvm, vif);
1655 out_unlock:
1656 mutex_unlock(&mvm->mutex);
1657 if (ret)
1658 mvmvif->phy_ctxt = NULL;
1659 return ret;
1660}
1661
1662static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1663 struct ieee80211_vif *vif,
1664 struct ieee80211_chanctx_conf *ctx)
1665{
1666 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1667 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1668
1669 mutex_lock(&mvm->mutex);
1670
1671 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1672
Johannes Berg8ca151b2013-01-24 14:25:36 +01001673 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02001674 case NL80211_IFTYPE_AP:
1675 case NL80211_IFTYPE_ADHOC:
1676 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001677 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02001678 mvmvif->monitor_active = false;
1679 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001680 break;
1681 default:
1682 break;
1683 }
1684
Ilan Peer1e1391c2013-03-13 14:52:04 +02001685 iwl_mvm_binding_remove_vif(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001686out_unlock:
1687 mvmvif->phy_ctxt = NULL;
1688 mutex_unlock(&mvm->mutex);
1689}
1690
1691static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1692 struct ieee80211_sta *sta,
1693 bool set)
1694{
1695 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1696 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1697
1698 if (!mvm_sta || !mvm_sta->vif) {
1699 IWL_ERR(mvm, "Station is not associated to a vif\n");
1700 return -EINVAL;
1701 }
1702
1703 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1704}
1705
David Spinadel507cadf2013-07-31 18:07:21 +03001706#ifdef CONFIG_NL80211_TESTMODE
1707static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
1708 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
1709 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad42013-08-01 14:17:15 +02001710 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03001711};
1712
1713static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
1714 struct ieee80211_vif *vif,
1715 void *data, int len)
1716{
1717 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
1718 int err;
1719 u32 noa_duration;
1720
1721 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
1722 if (err)
1723 return err;
1724
1725 if (!tb[IWL_MVM_TM_ATTR_CMD])
1726 return -EINVAL;
1727
1728 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
1729 case IWL_MVM_TM_CMD_SET_NOA:
1730 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
1731 !vif->bss_conf.enable_beacon ||
1732 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
1733 return -EINVAL;
1734
1735 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
1736 if (noa_duration >= vif->bss_conf.beacon_int)
1737 return -EINVAL;
1738
1739 mvm->noa_duration = noa_duration;
1740 mvm->noa_vif = vif;
1741
1742 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad42013-08-01 14:17:15 +02001743 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
1744 /* must be associated client vif - ignore authorized */
1745 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
1746 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
1747 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
1748 return -EINVAL;
1749
1750 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
1751 return iwl_mvm_enable_beacon_filter(mvm, vif);
1752 return iwl_mvm_disable_beacon_filter(mvm, vif);
David Spinadel507cadf2013-07-31 18:07:21 +03001753 }
1754
1755 return -EOPNOTSUPP;
1756}
1757
1758static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
1759 struct ieee80211_vif *vif,
1760 void *data, int len)
1761{
1762 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1763 int err;
1764
1765 mutex_lock(&mvm->mutex);
1766 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
1767 mutex_unlock(&mvm->mutex);
1768
1769 return err;
1770}
1771#endif
1772
Johannes Berg8ca151b2013-01-24 14:25:36 +01001773struct ieee80211_ops iwl_mvm_hw_ops = {
1774 .tx = iwl_mvm_mac_tx,
1775 .ampdu_action = iwl_mvm_mac_ampdu_action,
1776 .start = iwl_mvm_mac_start,
1777 .restart_complete = iwl_mvm_mac_restart_complete,
1778 .stop = iwl_mvm_mac_stop,
1779 .add_interface = iwl_mvm_mac_add_interface,
1780 .remove_interface = iwl_mvm_mac_remove_interface,
1781 .config = iwl_mvm_mac_config,
1782 .configure_filter = iwl_mvm_configure_filter,
1783 .bss_info_changed = iwl_mvm_bss_info_changed,
1784 .hw_scan = iwl_mvm_mac_hw_scan,
1785 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01001786 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001787 .sta_state = iwl_mvm_mac_sta_state,
1788 .sta_notify = iwl_mvm_mac_sta_notify,
1789 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1790 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1791 .conf_tx = iwl_mvm_mac_conf_tx,
1792 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
David Spinadel35a000b2013-08-28 09:29:43 +03001793 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
1794 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001795 .set_key = iwl_mvm_mac_set_key,
1796 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1797 .remain_on_channel = iwl_mvm_roc,
1798 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001799 .add_chanctx = iwl_mvm_add_chanctx,
1800 .remove_chanctx = iwl_mvm_remove_chanctx,
1801 .change_chanctx = iwl_mvm_change_chanctx,
1802 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1803 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1804
Johannes Berg5023d962013-07-31 14:07:43 +02001805 .start_ap = iwl_mvm_start_ap_ibss,
1806 .stop_ap = iwl_mvm_stop_ap_ibss,
1807 .join_ibss = iwl_mvm_start_ap_ibss,
1808 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001809
1810 .set_tim = iwl_mvm_set_tim,
1811
David Spinadel507cadf2013-07-31 18:07:21 +03001812 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
1813
Johannes Berg8ca151b2013-01-24 14:25:36 +01001814#ifdef CONFIG_PM_SLEEP
1815 /* look at d3.c */
1816 .suspend = iwl_mvm_suspend,
1817 .resume = iwl_mvm_resume,
1818 .set_wakeup = iwl_mvm_set_wakeup,
1819 .set_rekey_data = iwl_mvm_set_rekey_data,
1820#if IS_ENABLED(CONFIG_IPV6)
1821 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1822#endif
1823 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1824#endif
1825};