blob: afc4419be46dd1eaff2f1b419dae01e4b231b1cb [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
1117static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1118 struct ieee80211_vif *vif,
1119 struct ieee80211_sta *sta,
1120 enum ieee80211_sta_state old_state,
1121 enum ieee80211_sta_state new_state)
1122{
1123 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1124 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1125 int ret;
1126
1127 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1128 sta->addr, old_state, new_state);
1129
1130 /* this would be a mac80211 bug ... but don't crash */
1131 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1132 return -EINVAL;
1133
1134 /* if a STA is being removed, reuse its ID */
1135 flush_work(&mvm->sta_drained_wk);
1136
1137 mutex_lock(&mvm->mutex);
1138 if (old_state == IEEE80211_STA_NOTEXIST &&
1139 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02001140 /*
1141 * Firmware bug - it'll crash if the beacon interval is less
1142 * than 16. We can't avoid connecting at all, so refuse the
1143 * station state change, this will cause mac80211 to abandon
1144 * attempts to connect to this AP, and eventually wpa_s will
1145 * blacklist the AP...
1146 */
1147 if (vif->type == NL80211_IFTYPE_STATION &&
1148 vif->bss_conf.beacon_int < 16) {
1149 IWL_ERR(mvm,
1150 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1151 sta->addr, vif->bss_conf.beacon_int);
1152 ret = -EINVAL;
1153 goto out_unlock;
1154 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001155 ret = iwl_mvm_add_sta(mvm, vif, sta);
1156 } else if (old_state == IEEE80211_STA_NONE &&
1157 new_state == IEEE80211_STA_AUTH) {
1158 ret = 0;
1159 } else if (old_state == IEEE80211_STA_AUTH &&
1160 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01001161 ret = iwl_mvm_update_sta(mvm, vif, sta);
1162 if (ret == 0)
1163 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02001164 mvmvif->phy_ctxt->channel->band,
1165 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001166 } else if (old_state == IEEE80211_STA_ASSOC &&
1167 new_state == IEEE80211_STA_AUTHORIZED) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001168 /* enable beacon filtering */
1169 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001170 ret = 0;
1171 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1172 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001173 /* disable beacon filtering */
1174 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001175 ret = 0;
1176 } else if (old_state == IEEE80211_STA_ASSOC &&
1177 new_state == IEEE80211_STA_AUTH) {
1178 ret = 0;
1179 } else if (old_state == IEEE80211_STA_AUTH &&
1180 new_state == IEEE80211_STA_NONE) {
1181 ret = 0;
1182 } else if (old_state == IEEE80211_STA_NONE &&
1183 new_state == IEEE80211_STA_NOTEXIST) {
1184 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1185 } else {
1186 ret = -EIO;
1187 }
Johannes Berg48bc1302013-07-04 15:55:29 +02001188 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001189 mutex_unlock(&mvm->mutex);
1190
1191 return ret;
1192}
1193
1194static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1195{
1196 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1197
1198 mvm->rts_threshold = value;
1199
1200 return 0;
1201}
1202
1203static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1204 struct ieee80211_vif *vif, u16 ac,
1205 const struct ieee80211_tx_queue_params *params)
1206{
1207 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1208 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1209
1210 mvmvif->queue_params[ac] = *params;
1211
1212 /*
1213 * No need to update right away, we'll get BSS_CHANGED_QOS
1214 * The exception is P2P_DEVICE interface which needs immediate update.
1215 */
1216 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1217 int ret;
1218
1219 mutex_lock(&mvm->mutex);
1220 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1221 mutex_unlock(&mvm->mutex);
1222 return ret;
1223 }
1224 return 0;
1225}
1226
1227static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1228 struct ieee80211_vif *vif)
1229{
1230 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1231 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1232 200 + vif->bss_conf.beacon_int);
1233 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1234 100 + vif->bss_conf.beacon_int);
1235
1236 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1237 return;
1238
1239 mutex_lock(&mvm->mutex);
1240 /* Try really hard to protect the session and hear a beacon */
Johannes Berg016d27e2013-05-03 11:16:15 +02001241 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001242 mutex_unlock(&mvm->mutex);
1243}
1244
David Spinadel35a000b2013-08-28 09:29:43 +03001245static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1246 struct ieee80211_vif *vif,
1247 struct cfg80211_sched_scan_request *req,
1248 struct ieee80211_sched_scan_ies *ies)
1249{
1250 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1251 int ret;
1252
1253 mutex_lock(&mvm->mutex);
1254
1255 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
1256 IWL_DEBUG_SCAN(mvm,
1257 "SCHED SCAN request during internal scan - abort\n");
1258 ret = -EBUSY;
1259 goto out;
1260 }
1261
1262 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1263
1264 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1265 if (ret)
1266 goto err;
1267
1268 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1269 if (ret)
1270 goto err;
1271
1272 ret = iwl_mvm_sched_scan_start(mvm, req);
1273 if (!ret)
1274 goto out;
1275err:
1276 mvm->scan_status = IWL_MVM_SCAN_NONE;
1277out:
1278 mutex_unlock(&mvm->mutex);
1279 return ret;
1280}
1281
1282static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1283 struct ieee80211_vif *vif)
1284{
1285 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1286
1287 mutex_lock(&mvm->mutex);
1288 iwl_mvm_sched_scan_stop(mvm);
1289 mutex_unlock(&mvm->mutex);
1290}
1291
Johannes Berg8ca151b2013-01-24 14:25:36 +01001292static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1293 enum set_key_cmd cmd,
1294 struct ieee80211_vif *vif,
1295 struct ieee80211_sta *sta,
1296 struct ieee80211_key_conf *key)
1297{
1298 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1299 int ret;
1300
1301 if (iwlwifi_mod_params.sw_crypto) {
1302 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1303 return -EOPNOTSUPP;
1304 }
1305
1306 switch (key->cipher) {
1307 case WLAN_CIPHER_SUITE_TKIP:
1308 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1309 /* fall-through */
1310 case WLAN_CIPHER_SUITE_CCMP:
1311 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1312 break;
1313 case WLAN_CIPHER_SUITE_AES_CMAC:
1314 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1315 break;
1316 case WLAN_CIPHER_SUITE_WEP40:
1317 case WLAN_CIPHER_SUITE_WEP104:
1318 /*
1319 * Support for TX only, at least for now, so accept
1320 * the key and do nothing else. Then mac80211 will
1321 * pass it for TX but we don't have to use it for RX.
1322 */
1323 return 0;
1324 default:
1325 return -EOPNOTSUPP;
1326 }
1327
1328 mutex_lock(&mvm->mutex);
1329
1330 switch (cmd) {
1331 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02001332 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1333 vif->type == NL80211_IFTYPE_AP) && !sta) {
1334 /*
1335 * GTK on AP interface is a TX-only key, return 0;
1336 * on IBSS they're per-station and because we're lazy
1337 * we don't support them for RX, so do the same.
1338 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001339 ret = 0;
1340 key->hw_key_idx = STA_KEY_IDX_INVALID;
1341 break;
1342 }
1343
Johannes Berg8ca151b2013-01-24 14:25:36 +01001344 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1345 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1346 if (ret) {
1347 IWL_WARN(mvm, "set key failed\n");
1348 /*
1349 * can't add key for RX, but we don't need it
1350 * in the device for TX so still return 0
1351 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001352 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001353 ret = 0;
1354 }
1355
1356 break;
1357 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001358 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1359 ret = 0;
1360 break;
1361 }
1362
Johannes Berg8ca151b2013-01-24 14:25:36 +01001363 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1364 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1365 break;
1366 default:
1367 ret = -EINVAL;
1368 }
1369
1370 mutex_unlock(&mvm->mutex);
1371 return ret;
1372}
1373
1374static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1375 struct ieee80211_vif *vif,
1376 struct ieee80211_key_conf *keyconf,
1377 struct ieee80211_sta *sta,
1378 u32 iv32, u16 *phase1key)
1379{
1380 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1381
Johannes Berg5023d962013-07-31 14:07:43 +02001382 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1383 return;
1384
Johannes Berg8ca151b2013-01-24 14:25:36 +01001385 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1386}
1387
1388
1389static int iwl_mvm_roc(struct ieee80211_hw *hw,
1390 struct ieee80211_vif *vif,
1391 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001392 int duration,
1393 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001394{
1395 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001396 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001397 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03001398 struct iwl_mvm_phy_ctxt *phy_ctxt;
1399 int ret, i;
1400
1401 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1402 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001403
1404 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1405 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1406 return -EINVAL;
1407 }
1408
Johannes Berg8ca151b2013-01-24 14:25:36 +01001409 mutex_lock(&mvm->mutex);
1410
Ilan Peer31d385a2013-04-02 10:25:46 +03001411 for (i = 0; i < NUM_PHY_CTX; i++) {
1412 phy_ctxt = &mvm->phy_ctxts[i];
1413 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1414 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001415
Ilan Peer31d385a2013-04-02 10:25:46 +03001416 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1417 /*
1418 * Unbind the P2P_DEVICE from the current PHY context,
1419 * and if the PHY context is not used remove it.
1420 */
1421 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1422 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1423 goto out_unlock;
1424
1425 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1426
1427 /* Bind the P2P_DEVICE to the current PHY Context */
1428 mvmvif->phy_ctxt = phy_ctxt;
1429
1430 ret = iwl_mvm_binding_add_vif(mvm, vif);
1431 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1432 goto out_unlock;
1433
1434 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1435 goto schedule_time_event;
1436 }
1437 }
1438
1439 /* Need to update the PHY context only if the ROC channel changed */
1440 if (channel == mvmvif->phy_ctxt->channel)
1441 goto schedule_time_event;
1442
1443 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1444
1445 /*
1446 * Change the PHY context configuration as it is currently referenced
1447 * only by the P2P Device MAC
1448 */
1449 if (mvmvif->phy_ctxt->ref == 1) {
1450 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1451 &chandef, 1, 1);
1452 if (ret)
1453 goto out_unlock;
1454 } else {
1455 /*
1456 * The PHY context is shared with other MACs. Need to remove the
1457 * P2P Device from the binding, allocate an new PHY context and
1458 * create a new binding
1459 */
1460 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1461 if (!phy_ctxt) {
1462 ret = -ENOSPC;
1463 goto out_unlock;
1464 }
1465
1466 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1467 1, 1);
1468 if (ret) {
1469 IWL_ERR(mvm, "Failed to change PHY context\n");
1470 goto out_unlock;
1471 }
1472
1473 /* Unbind the P2P_DEVICE from the current PHY context */
1474 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1475 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1476 goto out_unlock;
1477
1478 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1479
1480 /* Bind the P2P_DEVICE to the new allocated PHY context */
1481 mvmvif->phy_ctxt = phy_ctxt;
1482
1483 ret = iwl_mvm_binding_add_vif(mvm, vif);
1484 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1485 goto out_unlock;
1486
1487 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1488 }
1489
1490schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001491 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02001492 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001493
Ilan Peer31d385a2013-04-02 10:25:46 +03001494out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001495 mutex_unlock(&mvm->mutex);
1496 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001497 return ret;
1498}
1499
1500static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1501{
1502 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1503
1504 IWL_DEBUG_MAC80211(mvm, "enter\n");
1505
1506 mutex_lock(&mvm->mutex);
1507 iwl_mvm_stop_p2p_roc(mvm);
1508 mutex_unlock(&mvm->mutex);
1509
1510 IWL_DEBUG_MAC80211(mvm, "leave\n");
1511 return 0;
1512}
1513
1514static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1515 struct ieee80211_chanctx_conf *ctx)
1516{
1517 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001518 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1519 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001520 int ret;
1521
Ilan Peer53a9d612013-04-28 11:55:08 +03001522 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001523
1524 mutex_lock(&mvm->mutex);
1525 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1526 if (!phy_ctxt) {
1527 ret = -ENOSPC;
1528 goto out;
1529 }
1530
Ilan Peer53a9d612013-04-28 11:55:08 +03001531 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1532 ctx->rx_chains_static,
1533 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001534 if (ret) {
1535 IWL_ERR(mvm, "Failed to add PHY context\n");
1536 goto out;
1537 }
1538
Ilan Peer53a9d612013-04-28 11:55:08 +03001539 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001540 *phy_ctxt_id = phy_ctxt->id;
1541out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001542 mutex_unlock(&mvm->mutex);
1543 return ret;
1544}
1545
1546static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1547 struct ieee80211_chanctx_conf *ctx)
1548{
1549 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001550 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1551 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001552
1553 mutex_lock(&mvm->mutex);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001554 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001555 mutex_unlock(&mvm->mutex);
1556}
1557
1558static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1559 struct ieee80211_chanctx_conf *ctx,
1560 u32 changed)
1561{
1562 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001563 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1564 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001565
Ilan Peer31d385a2013-04-02 10:25:46 +03001566 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1567 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1568 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
1569 IEEE80211_CHANCTX_CHANGE_RADAR)),
1570 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1571 phy_ctxt->ref, changed))
1572 return;
1573
Johannes Berg8ca151b2013-01-24 14:25:36 +01001574 mutex_lock(&mvm->mutex);
1575 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1576 ctx->rx_chains_static,
1577 ctx->rx_chains_dynamic);
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001578 iwl_mvm_bt_coex_vif_change(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001579 mutex_unlock(&mvm->mutex);
1580}
1581
1582static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1583 struct ieee80211_vif *vif,
1584 struct ieee80211_chanctx_conf *ctx)
1585{
1586 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001587 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1588 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001589 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1590 int ret;
1591
1592 mutex_lock(&mvm->mutex);
1593
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001594 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001595
1596 switch (vif->type) {
1597 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001598 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001599 /*
1600 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02001601 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001602 */
1603 ret = 0;
1604 goto out_unlock;
1605 case NL80211_IFTYPE_STATION:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001606 case NL80211_IFTYPE_MONITOR:
1607 break;
1608 default:
1609 ret = -EINVAL;
1610 goto out_unlock;
1611 }
1612
1613 ret = iwl_mvm_binding_add_vif(mvm, vif);
1614 if (ret)
1615 goto out_unlock;
1616
1617 /*
1618 * Setting the quota at this stage is only required for monitor
1619 * interfaces. For the other types, the bss_info changed flow
1620 * will handle quota settings.
1621 */
1622 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02001623 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001624 ret = iwl_mvm_update_quotas(mvm, vif);
1625 if (ret)
1626 goto out_remove_binding;
1627 }
1628
1629 goto out_unlock;
1630
1631 out_remove_binding:
1632 iwl_mvm_binding_remove_vif(mvm, vif);
1633 out_unlock:
1634 mutex_unlock(&mvm->mutex);
1635 if (ret)
1636 mvmvif->phy_ctxt = NULL;
1637 return ret;
1638}
1639
1640static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1641 struct ieee80211_vif *vif,
1642 struct ieee80211_chanctx_conf *ctx)
1643{
1644 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1645 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1646
1647 mutex_lock(&mvm->mutex);
1648
1649 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1650
Johannes Berg8ca151b2013-01-24 14:25:36 +01001651 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02001652 case NL80211_IFTYPE_AP:
1653 case NL80211_IFTYPE_ADHOC:
1654 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001655 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02001656 mvmvif->monitor_active = false;
1657 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001658 break;
1659 default:
1660 break;
1661 }
1662
Ilan Peer1e1391c2013-03-13 14:52:04 +02001663 iwl_mvm_binding_remove_vif(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001664out_unlock:
1665 mvmvif->phy_ctxt = NULL;
1666 mutex_unlock(&mvm->mutex);
1667}
1668
1669static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1670 struct ieee80211_sta *sta,
1671 bool set)
1672{
1673 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1674 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1675
1676 if (!mvm_sta || !mvm_sta->vif) {
1677 IWL_ERR(mvm, "Station is not associated to a vif\n");
1678 return -EINVAL;
1679 }
1680
1681 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1682}
1683
David Spinadel507cadf2013-07-31 18:07:21 +03001684#ifdef CONFIG_NL80211_TESTMODE
1685static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
1686 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
1687 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad42013-08-01 14:17:15 +02001688 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03001689};
1690
1691static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
1692 struct ieee80211_vif *vif,
1693 void *data, int len)
1694{
1695 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
1696 int err;
1697 u32 noa_duration;
1698
1699 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
1700 if (err)
1701 return err;
1702
1703 if (!tb[IWL_MVM_TM_ATTR_CMD])
1704 return -EINVAL;
1705
1706 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
1707 case IWL_MVM_TM_CMD_SET_NOA:
1708 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
1709 !vif->bss_conf.enable_beacon ||
1710 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
1711 return -EINVAL;
1712
1713 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
1714 if (noa_duration >= vif->bss_conf.beacon_int)
1715 return -EINVAL;
1716
1717 mvm->noa_duration = noa_duration;
1718 mvm->noa_vif = vif;
1719
1720 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad42013-08-01 14:17:15 +02001721 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
1722 /* must be associated client vif - ignore authorized */
1723 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
1724 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
1725 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
1726 return -EINVAL;
1727
1728 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
1729 return iwl_mvm_enable_beacon_filter(mvm, vif);
1730 return iwl_mvm_disable_beacon_filter(mvm, vif);
David Spinadel507cadf2013-07-31 18:07:21 +03001731 }
1732
1733 return -EOPNOTSUPP;
1734}
1735
1736static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
1737 struct ieee80211_vif *vif,
1738 void *data, int len)
1739{
1740 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1741 int err;
1742
1743 mutex_lock(&mvm->mutex);
1744 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
1745 mutex_unlock(&mvm->mutex);
1746
1747 return err;
1748}
1749#endif
1750
Johannes Berg8ca151b2013-01-24 14:25:36 +01001751struct ieee80211_ops iwl_mvm_hw_ops = {
1752 .tx = iwl_mvm_mac_tx,
1753 .ampdu_action = iwl_mvm_mac_ampdu_action,
1754 .start = iwl_mvm_mac_start,
1755 .restart_complete = iwl_mvm_mac_restart_complete,
1756 .stop = iwl_mvm_mac_stop,
1757 .add_interface = iwl_mvm_mac_add_interface,
1758 .remove_interface = iwl_mvm_mac_remove_interface,
1759 .config = iwl_mvm_mac_config,
1760 .configure_filter = iwl_mvm_configure_filter,
1761 .bss_info_changed = iwl_mvm_bss_info_changed,
1762 .hw_scan = iwl_mvm_mac_hw_scan,
1763 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1764 .sta_state = iwl_mvm_mac_sta_state,
1765 .sta_notify = iwl_mvm_mac_sta_notify,
1766 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1767 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1768 .conf_tx = iwl_mvm_mac_conf_tx,
1769 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
David Spinadel35a000b2013-08-28 09:29:43 +03001770 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
1771 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001772 .set_key = iwl_mvm_mac_set_key,
1773 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1774 .remain_on_channel = iwl_mvm_roc,
1775 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001776 .add_chanctx = iwl_mvm_add_chanctx,
1777 .remove_chanctx = iwl_mvm_remove_chanctx,
1778 .change_chanctx = iwl_mvm_change_chanctx,
1779 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1780 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1781
Johannes Berg5023d962013-07-31 14:07:43 +02001782 .start_ap = iwl_mvm_start_ap_ibss,
1783 .stop_ap = iwl_mvm_stop_ap_ibss,
1784 .join_ibss = iwl_mvm_start_ap_ibss,
1785 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001786
1787 .set_tim = iwl_mvm_set_tim,
1788
David Spinadel507cadf2013-07-31 18:07:21 +03001789 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
1790
Johannes Berg8ca151b2013-01-24 14:25:36 +01001791#ifdef CONFIG_PM_SLEEP
1792 /* look at d3.c */
1793 .suspend = iwl_mvm_suspend,
1794 .resume = iwl_mvm_resume,
1795 .set_wakeup = iwl_mvm_set_wakeup,
1796 .set_rekey_data = iwl_mvm_set_rekey_data,
1797#if IS_ENABLED(CONFIG_IPV6)
1798 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1799#endif
1800 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1801#endif
1802};