blob: 8e4e79a83d1405b7af1bbcbffbc6a7a5c9a7520b [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"
80
81static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
82 {
83 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030084 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010085 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020086 {
87 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030088 .types = BIT(NL80211_IFTYPE_AP) |
89 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +020090 BIT(NL80211_IFTYPE_P2P_GO),
91 },
92 {
93 .max = 1,
94 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
95 },
Johannes Berg8ca151b2013-01-24 14:25:36 +010096};
97
98static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
99 {
100 .num_different_channels = 1,
101 .max_interfaces = 3,
102 .limits = iwl_mvm_limits,
103 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
104 },
105};
106
Johannes Bergf0c26462013-01-22 20:41:58 +0100107#ifdef CONFIG_PM_SLEEP
108static const struct nl80211_wowlan_tcp_data_token_feature
109iwl_mvm_wowlan_tcp_token_feature = {
110 .min_len = 0,
111 .max_len = 255,
112 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
113};
114
115static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
116 .tok = &iwl_mvm_wowlan_tcp_token_feature,
117 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
118 sizeof(struct ethhdr) -
119 sizeof(struct iphdr) -
120 sizeof(struct tcphdr),
121 .data_interval_max = 65535, /* __le16 in API */
122 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
123 sizeof(struct ethhdr) -
124 sizeof(struct iphdr) -
125 sizeof(struct tcphdr),
126 .seq = true,
127};
128#endif
129
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200130static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
131{
132 int i;
133
134 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
135 for (i = 0; i < NUM_PHY_CTX; i++) {
136 mvm->phy_ctxts[i].id = i;
137 mvm->phy_ctxts[i].ref = 0;
138 }
139}
140
Johannes Berg8ca151b2013-01-24 14:25:36 +0100141int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
142{
143 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200144 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100145
146 /* Tell mac80211 our characteristics */
147 hw->flags = IEEE80211_HW_SIGNAL_DBM |
148 IEEE80211_HW_SPECTRUM_MGMT |
149 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
150 IEEE80211_HW_QUEUE_CONTROL |
151 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100152 IEEE80211_HW_SUPPORTS_PS |
153 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100154 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200155 IEEE80211_HW_TIMING_BEACON_ONLY |
156 IEEE80211_HW_CONNECTION_MONITOR;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100157
Ilan Peer398e8c62013-03-13 15:20:35 +0200158 hw->queues = IWL_MVM_FIRST_AGG_QUEUE;
159 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100160 hw->rate_control_algorithm = "iwl-mvm-rs";
161
162 /*
163 * Enable 11w if advertised by firmware and software crypto
164 * is not enabled (as the firmware will interpret some mgmt
165 * packets, so enabling it with software crypto isn't safe)
166 */
167 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
168 !iwlwifi_mod_params.sw_crypto)
169 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
170
171 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
172 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200173 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100174
175 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200176 BIT(NL80211_IFTYPE_P2P_CLIENT) |
177 BIT(NL80211_IFTYPE_AP) |
178 BIT(NL80211_IFTYPE_P2P_GO) |
179 BIT(NL80211_IFTYPE_P2P_DEVICE);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100180
181 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
182 WIPHY_FLAG_DISABLE_BEACON_HINTS |
183 WIPHY_FLAG_IBSS_RSN;
184
185 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
186 hw->wiphy->n_iface_combinations =
187 ARRAY_SIZE(iwl_mvm_iface_combinations);
188
Ilan Peerc451e6d2013-02-20 08:41:54 +0200189 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100190 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
191
192 /* Extract MAC address */
193 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
194 hw->wiphy->addresses = mvm->addresses;
195 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200196
197 /* Extract additional MAC addresses if available */
198 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
199 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
200
201 for (i = 1; i < num_mac; i++) {
202 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100203 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200204 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100205 hw->wiphy->n_addresses++;
206 }
207
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200208 iwl_mvm_reset_phy_ctxts(mvm);
209
Johannes Berg8ca151b2013-01-24 14:25:36 +0100210 /* we create the 802.11 header and a max-length SSID element */
211 hw->wiphy->max_scan_ie_len =
212 mvm->fw->ucode_capa.max_probe_length - 24 - 34;
213 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
214
215 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
216 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
217 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
218 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
219 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
220 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
221
222 hw->wiphy->hw_version = mvm->trans->hw_id;
223
Alexander Bondarade50652013-04-03 16:28:47 +0300224 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100225 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
226 else
227 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
228
229 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
230 NL80211_FEATURE_P2P_GO_OPPPS;
231
232 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
233
234#ifdef CONFIG_PM_SLEEP
235 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
236 mvm->trans->ops->d3_suspend &&
237 mvm->trans->ops->d3_resume &&
238 device_can_wakeup(mvm->trans->dev)) {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200239 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
240 WIPHY_WOWLAN_DISCONNECT |
241 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
242 WIPHY_WOWLAN_RFKILL_RELEASE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100243 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200244 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
245 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
246 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100247
Johannes Berg964dc9e2013-06-03 17:25:34 +0200248 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
249 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
250 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
251 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
252 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100253 }
254#endif
255
256 ret = iwl_mvm_leds_init(mvm);
257 if (ret)
258 return ret;
259
260 return ieee80211_register_hw(mvm->hw);
261}
262
263static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
264 struct ieee80211_tx_control *control,
265 struct sk_buff *skb)
266{
267 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
268
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300269 if (iwl_mvm_is_radio_killed(mvm)) {
270 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100271 goto drop;
272 }
273
Ilan Peer398e8c62013-03-13 15:20:35 +0200274 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100275 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
276 goto drop;
277
278 if (control->sta) {
279 if (iwl_mvm_tx_skb(mvm, skb, control->sta))
280 goto drop;
281 return;
282 }
283
284 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
285 goto drop;
286 return;
287 drop:
288 ieee80211_free_txskb(hw, skb);
289}
290
291static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
292 struct ieee80211_vif *vif,
293 enum ieee80211_ampdu_mlme_action action,
294 struct ieee80211_sta *sta, u16 tid,
295 u16 *ssn, u8 buf_size)
296{
297 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
298 int ret;
299
300 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
301 sta->addr, tid, action);
302
303 if (!(mvm->nvm_data->sku_cap_11n_enable))
304 return -EACCES;
305
306 mutex_lock(&mvm->mutex);
307
308 switch (action) {
309 case IEEE80211_AMPDU_RX_START:
310 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
311 ret = -EINVAL;
312 break;
313 }
314 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
315 break;
316 case IEEE80211_AMPDU_RX_STOP:
317 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
318 break;
319 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200320 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
321 ret = -EINVAL;
322 break;
323 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100324 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
325 break;
326 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200327 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
328 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100329 case IEEE80211_AMPDU_TX_STOP_FLUSH:
330 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200331 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100332 break;
333 case IEEE80211_AMPDU_TX_OPERATIONAL:
334 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
335 break;
336 default:
337 WARN_ON_ONCE(1);
338 ret = -EINVAL;
339 break;
340 }
341 mutex_unlock(&mvm->mutex);
342
343 return ret;
344}
345
346static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
347 struct ieee80211_vif *vif)
348{
349 struct iwl_mvm *mvm = data;
350 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
351
352 mvmvif->uploaded = false;
353 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
354
355 /* does this make sense at all? */
356 mvmvif->color++;
357
358 spin_lock_bh(&mvm->time_event_lock);
359 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
360 spin_unlock_bh(&mvm->time_event_lock);
361
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200362 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100363}
364
365static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
366{
367 iwl_trans_stop_device(mvm->trans);
368 iwl_trans_stop_hw(mvm->trans, false);
369
370 mvm->scan_status = IWL_MVM_SCAN_NONE;
371
372 /* just in case one was running */
373 ieee80211_remain_on_channel_expired(mvm->hw);
374
375 ieee80211_iterate_active_interfaces_atomic(
376 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
377 iwl_mvm_cleanup_iterator, mvm);
378
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200379 mvm->p2p_device_vif = NULL;
380
381 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100382 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
383 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
384
385 ieee80211_wake_queues(mvm->hw);
386
387 mvm->vif_count = 0;
388}
389
390static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
391{
392 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
393 int ret;
394
395 mutex_lock(&mvm->mutex);
396
397 /* Clean up some internal and mac80211 state on restart */
398 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
399 iwl_mvm_restart_cleanup(mvm);
400
401 ret = iwl_mvm_up(mvm);
402 mutex_unlock(&mvm->mutex);
403
404 return ret;
405}
406
407static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
408{
409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
410 int ret;
411
412 mutex_lock(&mvm->mutex);
413
414 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
415 ret = iwl_mvm_update_quotas(mvm, NULL);
416 if (ret)
417 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
418 ret);
419
420 mutex_unlock(&mvm->mutex);
421}
422
423static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
424{
425 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
426
427 flush_work(&mvm->async_handlers_wk);
428
429 mutex_lock(&mvm->mutex);
430 /* async_handlers_wk is now blocked */
431
432 /*
433 * The work item could be running or queued if the
434 * ROC time event stops just as we get here.
435 */
436 cancel_work_sync(&mvm->roc_done_wk);
437
438 iwl_trans_stop_device(mvm->trans);
439 iwl_trans_stop_hw(mvm->trans, false);
440
441 iwl_mvm_async_handlers_purge(mvm);
442 /* async_handlers_list is empty and will stay empty: HW is stopped */
443
444 /* the fw is stopped, the aux sta is dead: clean up driver state */
445 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
446
447 mutex_unlock(&mvm->mutex);
448
449 /*
450 * The worker might have been waiting for the mutex, let it run and
451 * discover that its list is now empty.
452 */
453 cancel_work_sync(&mvm->async_handlers_wk);
454}
455
456static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
457 struct ieee80211_vif *vif)
458{
459 struct iwl_mvm *mvm = data;
460 int ret;
461
462 ret = iwl_mvm_power_disable(mvm, vif);
463 if (ret)
464 IWL_ERR(mvm, "failed to disable power management\n");
465}
466
467static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
468 struct ieee80211_vif *vif)
469{
470 struct iwl_mvm *mvm = data;
471
472 iwl_mvm_power_update_mode(mvm, vif);
473}
474
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200475static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
476{
477 u16 i;
478
479 lockdep_assert_held(&mvm->mutex);
480
481 for (i = 0; i < NUM_PHY_CTX; i++)
482 if (!mvm->phy_ctxts[i].ref)
483 return &mvm->phy_ctxts[i];
484
485 IWL_ERR(mvm, "No available PHY context\n");
486 return NULL;
487}
488
Johannes Berg8ca151b2013-01-24 14:25:36 +0100489static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
490 struct ieee80211_vif *vif)
491{
492 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
493 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
494 int ret;
495
496 /*
497 * Not much to do here. The stack will not allow interface
498 * types or combinations that we didn't advertise, so we
499 * don't really have to check the types.
500 */
501
502 mutex_lock(&mvm->mutex);
503
504 /* Allocate resources for the MAC context, and add it the the fw */
505 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
506 if (ret)
507 goto out_unlock;
508
509 /*
510 * The AP binding flow can be done only after the beacon
511 * template is configured (which happens only in the mac80211
512 * start_ap() flow), and adding the broadcast station can happen
513 * only after the binding.
514 * In addition, since modifying the MAC before adding a bcast
515 * station is not allowed by the FW, delay the adding of MAC context to
516 * the point where we can also add the bcast station.
517 * In short: there's not much we can do at this point, other than
518 * allocating resources :)
519 */
520 if (vif->type == NL80211_IFTYPE_AP) {
521 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
522 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
523 qmask);
524 if (ret) {
525 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
526 goto out_release;
527 }
528
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +0300529 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100530 goto out_unlock;
531 }
532
533 /*
534 * TODO: remove this temporary code.
535 * Currently MVM FW supports power management only on single MAC.
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200536 * If new interface added, disable PM on existing interface.
537 * P2P device is a special case, since it is handled by FW similary to
538 * scan. If P2P deviced is added, PM remains enabled on existing
539 * interface.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100540 * Note: the method below does not count the new interface being added
541 * at this moment.
542 */
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200543 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
544 mvm->vif_count++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100545 if (mvm->vif_count > 1) {
546 IWL_DEBUG_MAC80211(mvm,
547 "Disable power on existing interfaces\n");
Emmanuel Grumbach5360cfb2013-02-11 15:56:01 +0200548 ieee80211_iterate_active_interfaces_atomic(
Johannes Berg8ca151b2013-01-24 14:25:36 +0100549 mvm->hw,
550 IEEE80211_IFACE_ITER_NORMAL,
551 iwl_mvm_pm_disable_iterator, mvm);
552 }
553
554 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
555 if (ret)
556 goto out_release;
557
558 /*
559 * Update power state on the new interface. Admittedly, based on
560 * mac80211 logics this power update will disable power management
561 */
562 iwl_mvm_power_update_mode(mvm, vif);
563
Hila Gonen7df15b12012-12-12 11:16:19 +0200564 /* beacon filtering */
565 if (!mvm->bf_allowed_vif &&
Hila Gonen5dca7c22013-07-16 11:15:35 +0300566 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
567 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
Hila Gonen7df15b12012-12-12 11:16:19 +0200568 mvm->bf_allowed_vif = mvmvif;
569 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
570 }
571
572 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
573 if (ret)
574 goto out_release;
575
Johannes Berg8ca151b2013-01-24 14:25:36 +0100576 /*
577 * P2P_DEVICE interface does not have a channel context assigned to it,
578 * so a dedicated PHY context is allocated to it and the corresponding
579 * MAC context is bound to it at this stage.
580 */
581 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100582
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200583 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
584 if (!mvmvif->phy_ctxt) {
585 ret = -ENOSPC;
586 goto out_remove_mac;
587 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100588
Ilan Peer53a9d612013-04-28 11:55:08 +0300589 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100590 ret = iwl_mvm_binding_add_vif(mvm, vif);
591 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +0300592 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100593
594 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
595 if (ret)
596 goto out_unbind;
597
598 /* Save a pointer to p2p device vif, so it can later be used to
599 * update the p2p device MAC when a GO is started/stopped */
600 mvm->p2p_device_vif = vif;
601 }
602
Johannes Berg63494372013-03-26 10:47:53 +0100603 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100604 goto out_unlock;
605
606 out_unbind:
607 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +0300608 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200609 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100610 out_remove_mac:
611 mvmvif->phy_ctxt = NULL;
612 iwl_mvm_mac_ctxt_remove(mvm, vif);
613 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200614 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
615 mvm->vif_count--;
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300616 ieee80211_iterate_active_interfaces(
617 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
618 iwl_mvm_power_update_iterator, mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100619 iwl_mvm_mac_ctxt_release(mvm, vif);
620 out_unlock:
621 mutex_unlock(&mvm->mutex);
622
623 return ret;
624}
625
Johannes Berg38a12b52013-02-22 14:07:56 +0100626static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
627 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100628{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100629 u32 tfd_msk = 0, ac;
630
631 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
632 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
633 tfd_msk |= BIT(vif->hw_queue[ac]);
634
635 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
636 tfd_msk |= BIT(vif->cab_queue);
637
638 if (tfd_msk) {
639 mutex_lock(&mvm->mutex);
640 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
641 mutex_unlock(&mvm->mutex);
642 }
643
644 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
645 /*
646 * Flush the ROC worker which will flush the OFFCHANNEL queue.
647 * We assume here that all the packets sent to the OFFCHANNEL
648 * queue are sent in ROC session.
649 */
650 flush_work(&mvm->roc_done_wk);
651 } else {
652 /*
653 * By now, all the AC queues are empty. The AGG queues are
654 * empty too. We already got all the Tx responses for all the
655 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +0300656 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100657 */
658 flush_work(&mvm->sta_drained_wk);
659 }
Johannes Berg38a12b52013-02-22 14:07:56 +0100660}
661
662static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
663 struct ieee80211_vif *vif)
664{
665 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
666 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
667
668 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100669
670 mutex_lock(&mvm->mutex);
671
Hila Gonen7df15b12012-12-12 11:16:19 +0200672 if (mvm->bf_allowed_vif == mvmvif) {
673 mvm->bf_allowed_vif = NULL;
674 vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
675 }
676
Johannes Berg63494372013-03-26 10:47:53 +0100677 iwl_mvm_vif_dbgfs_clean(mvm, vif);
678
Johannes Berg8ca151b2013-01-24 14:25:36 +0100679 /*
680 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +0100681 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100682 */
683 if (vif->type == NL80211_IFTYPE_AP) {
684 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
685 goto out_release;
686 }
687
688 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
689 mvm->p2p_device_vif = NULL;
690 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
691 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200692 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100693 mvmvif->phy_ctxt = NULL;
694 }
695
696 /*
697 * TODO: remove this temporary code.
698 * Currently MVM FW supports power management only on single MAC.
699 * Check if only one additional interface remains after removing
700 * current one. Update power mode on the remaining interface.
701 */
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200702 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100703 mvm->vif_count--;
704 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
705 mvm->vif_count);
706 if (mvm->vif_count == 1) {
707 ieee80211_iterate_active_interfaces(
708 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
709 iwl_mvm_power_update_iterator, mvm);
710 }
711
712 iwl_mvm_mac_ctxt_remove(mvm, vif);
713
714out_release:
715 iwl_mvm_mac_ctxt_release(mvm, vif);
716 mutex_unlock(&mvm->mutex);
717}
718
Matti Gottlieb88f2fd72013-07-09 15:25:46 +0300719static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
720 s8 tx_power)
721{
722 /* FW is in charge of regulatory enforcement */
723 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
724 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
725 .pwr_restriction = cpu_to_le16(tx_power),
726 };
727
728 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
729 sizeof(reduce_txpwr_cmd),
730 &reduce_txpwr_cmd);
731}
732
Johannes Berg8ca151b2013-01-24 14:25:36 +0100733static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
734{
735 return 0;
736}
737
738static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
739 unsigned int changed_flags,
740 unsigned int *total_flags,
741 u64 multicast)
742{
743 *total_flags = 0;
744}
745
Emmanuel Grumbach51b6b9e2013-05-02 15:01:24 +0300746static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
747 struct ieee80211_vif *vif)
748{
749 struct iwl_mcast_filter_cmd mcast_filter_cmd = {
750 .pass_all = 1,
751 };
752
753 memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
754
755 return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
756 sizeof(mcast_filter_cmd),
757 &mcast_filter_cmd);
758}
759
Johannes Berg8ca151b2013-01-24 14:25:36 +0100760static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
761 struct ieee80211_vif *vif,
762 struct ieee80211_bss_conf *bss_conf,
763 u32 changes)
764{
765 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
766 int ret;
767
768 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
769 if (ret)
770 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
771
772 if (changes & BSS_CHANGED_ASSOC) {
773 if (bss_conf->assoc) {
774 /* add quota for this interface */
775 ret = iwl_mvm_update_quotas(mvm, vif);
776 if (ret) {
777 IWL_ERR(mvm, "failed to update quotas\n");
778 return;
779 }
Emmanuel Grumbach51b6b9e2013-05-02 15:01:24 +0300780 iwl_mvm_configure_mcast_filter(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100781 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
782 /* remove AP station now that the MAC is unassoc */
783 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
784 if (ret)
785 IWL_ERR(mvm, "failed to remove AP station\n");
786 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
787 /* remove quota for this interface */
788 ret = iwl_mvm_update_quotas(mvm, NULL);
789 if (ret)
790 IWL_ERR(mvm, "failed to update quotas\n");
791 }
Alexander Bondare811ada2013-03-10 15:29:44 +0200792 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD)) {
793 /* Workaround for FW bug, otherwise FW disables device
794 * power save upon disassociation
795 */
796 ret = iwl_mvm_power_update_mode(mvm, vif);
797 if (ret)
798 IWL_ERR(mvm, "failed to update power mode\n");
799 }
Emmanuel Grumbach41069b42013-06-25 21:49:19 +0300800 iwl_mvm_bt_coex_vif_assoc(mvm, vif);
Alexander Bondar989c6502013-05-16 17:34:17 +0300801 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +0100802 /*
803 * We received a beacon _after_ association so
804 * remove the session protection.
805 */
806 iwl_mvm_remove_time_event(mvm, mvmvif,
807 &mvmvif->time_event_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100808 } else if (changes & BSS_CHANGED_PS) {
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300809 ret = iwl_mvm_power_update_mode(mvm, vif);
810 if (ret)
811 IWL_ERR(mvm, "failed to update power mode\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100812 }
Matti Gottlieb88f2fd72013-07-09 15:25:46 +0300813 if (changes & BSS_CHANGED_TXPOWER) {
814 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
815 bss_conf->txpower);
816 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
817 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100818}
819
820static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
821{
822 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
823 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
824 int ret;
825
826 mutex_lock(&mvm->mutex);
827
828 /* Send the beacon template */
829 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
830 if (ret)
831 goto out_unlock;
832
833 /* Add the mac context */
834 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
835 if (ret)
836 goto out_unlock;
837
838 /* Perform the binding */
839 ret = iwl_mvm_binding_add_vif(mvm, vif);
840 if (ret)
841 goto out_remove;
842
843 mvmvif->ap_active = true;
844
845 /* Send the bcast station. At this stage the TBTT and DTIM time events
846 * are added and applied to the scheduler */
847 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
848 if (ret)
849 goto out_unbind;
850
851 ret = iwl_mvm_update_quotas(mvm, vif);
852 if (ret)
853 goto out_rm_bcast;
854
855 /* Need to update the P2P Device MAC */
856 if (vif->p2p && mvm->p2p_device_vif)
857 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
858
859 mutex_unlock(&mvm->mutex);
860 return 0;
861
862out_rm_bcast:
863 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
864out_unbind:
865 iwl_mvm_binding_remove_vif(mvm, vif);
866out_remove:
867 iwl_mvm_mac_ctxt_remove(mvm, vif);
868out_unlock:
869 mutex_unlock(&mvm->mutex);
870 return ret;
871}
872
873static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
874{
875 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
876 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
877
Johannes Berg38a12b52013-02-22 14:07:56 +0100878 iwl_mvm_prepare_mac_removal(mvm, vif);
879
Johannes Berg8ca151b2013-01-24 14:25:36 +0100880 mutex_lock(&mvm->mutex);
881
882 mvmvif->ap_active = false;
883
884 /* Need to update the P2P Device MAC */
885 if (vif->p2p && mvm->p2p_device_vif)
886 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
887
888 iwl_mvm_update_quotas(mvm, NULL);
889 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
890 iwl_mvm_binding_remove_vif(mvm, vif);
891 iwl_mvm_mac_ctxt_remove(mvm, vif);
892
893 mutex_unlock(&mvm->mutex);
894}
895
896static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
897 struct ieee80211_vif *vif,
898 struct ieee80211_bss_conf *bss_conf,
899 u32 changes)
900{
901 /* Need to send a new beacon template to the FW */
902 if (changes & BSS_CHANGED_BEACON) {
903 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
904 IWL_WARN(mvm, "Failed updating beacon data\n");
905 }
906}
907
908static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
909 struct ieee80211_vif *vif,
910 struct ieee80211_bss_conf *bss_conf,
911 u32 changes)
912{
913 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
914
915 mutex_lock(&mvm->mutex);
916
917 switch (vif->type) {
918 case NL80211_IFTYPE_STATION:
919 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
920 break;
921 case NL80211_IFTYPE_AP:
922 iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
923 break;
924 default:
925 /* shouldn't happen */
926 WARN_ON_ONCE(1);
927 }
928
929 mutex_unlock(&mvm->mutex);
930}
931
932static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
933 struct ieee80211_vif *vif,
934 struct cfg80211_scan_request *req)
935{
936 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
937 int ret;
938
939 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
940 return -EINVAL;
941
942 mutex_lock(&mvm->mutex);
943
944 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
945 ret = iwl_mvm_scan_request(mvm, vif, req);
946 else
947 ret = -EBUSY;
948
949 mutex_unlock(&mvm->mutex);
950
951 return ret;
952}
953
954static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
955 struct ieee80211_vif *vif)
956{
957 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
958
959 mutex_lock(&mvm->mutex);
960
961 iwl_mvm_cancel_scan(mvm);
962
963 mutex_unlock(&mvm->mutex);
964}
965
966static void
967iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
968 struct ieee80211_sta *sta, u16 tid,
969 int num_frames,
970 enum ieee80211_frame_release_type reason,
971 bool more_data)
972{
973 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100974
975 /* TODO: how do we tell the fw to send frames for a specific TID */
976
977 /*
978 * The fw will send EOSP notification when the last frame will be
979 * transmitted.
980 */
Johannes Berg9cc40712013-02-15 22:47:48 +0100981 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100982}
983
984static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
985 struct ieee80211_vif *vif,
986 enum sta_notify_cmd cmd,
987 struct ieee80211_sta *sta)
988{
989 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
990 struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
991
992 switch (cmd) {
993 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300994 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100995 ieee80211_sta_block_awake(hw, sta, true);
996 /*
997 * The fw updates the STA to be asleep. Tx packets on the Tx
998 * queues to this station will not be transmitted. The fw will
999 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1000 */
1001 break;
1002 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001003 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001004 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01001005 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001006 break;
1007 default:
1008 break;
1009 }
1010}
1011
1012static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1013 struct ieee80211_vif *vif,
1014 struct ieee80211_sta *sta,
1015 enum ieee80211_sta_state old_state,
1016 enum ieee80211_sta_state new_state)
1017{
1018 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1019 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1020 int ret;
1021
1022 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1023 sta->addr, old_state, new_state);
1024
1025 /* this would be a mac80211 bug ... but don't crash */
1026 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1027 return -EINVAL;
1028
1029 /* if a STA is being removed, reuse its ID */
1030 flush_work(&mvm->sta_drained_wk);
1031
1032 mutex_lock(&mvm->mutex);
1033 if (old_state == IEEE80211_STA_NOTEXIST &&
1034 new_state == IEEE80211_STA_NONE) {
1035 ret = iwl_mvm_add_sta(mvm, vif, sta);
1036 } else if (old_state == IEEE80211_STA_NONE &&
1037 new_state == IEEE80211_STA_AUTH) {
1038 ret = 0;
1039 } else if (old_state == IEEE80211_STA_AUTH &&
1040 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01001041 ret = iwl_mvm_update_sta(mvm, vif, sta);
1042 if (ret == 0)
1043 iwl_mvm_rs_rate_init(mvm, sta,
1044 mvmvif->phy_ctxt->channel->band);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001045 } else if (old_state == IEEE80211_STA_ASSOC &&
1046 new_state == IEEE80211_STA_AUTHORIZED) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001047 /* enable beacon filtering */
1048 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001049 ret = 0;
1050 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1051 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001052 /* disable beacon filtering */
1053 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001054 ret = 0;
1055 } else if (old_state == IEEE80211_STA_ASSOC &&
1056 new_state == IEEE80211_STA_AUTH) {
1057 ret = 0;
1058 } else if (old_state == IEEE80211_STA_AUTH &&
1059 new_state == IEEE80211_STA_NONE) {
1060 ret = 0;
1061 } else if (old_state == IEEE80211_STA_NONE &&
1062 new_state == IEEE80211_STA_NOTEXIST) {
1063 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1064 } else {
1065 ret = -EIO;
1066 }
1067 mutex_unlock(&mvm->mutex);
1068
1069 return ret;
1070}
1071
1072static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1073{
1074 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1075
1076 mvm->rts_threshold = value;
1077
1078 return 0;
1079}
1080
1081static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1082 struct ieee80211_vif *vif, u16 ac,
1083 const struct ieee80211_tx_queue_params *params)
1084{
1085 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1086 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1087
1088 mvmvif->queue_params[ac] = *params;
1089
1090 /*
1091 * No need to update right away, we'll get BSS_CHANGED_QOS
1092 * The exception is P2P_DEVICE interface which needs immediate update.
1093 */
1094 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1095 int ret;
1096
1097 mutex_lock(&mvm->mutex);
1098 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1099 mutex_unlock(&mvm->mutex);
1100 return ret;
1101 }
1102 return 0;
1103}
1104
1105static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1106 struct ieee80211_vif *vif)
1107{
1108 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1109 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1110 200 + vif->bss_conf.beacon_int);
1111 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1112 100 + vif->bss_conf.beacon_int);
1113
1114 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1115 return;
1116
1117 mutex_lock(&mvm->mutex);
1118 /* Try really hard to protect the session and hear a beacon */
1119 iwl_mvm_protect_session(mvm, vif, duration, min_duration);
1120 mutex_unlock(&mvm->mutex);
1121}
1122
1123static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1124 enum set_key_cmd cmd,
1125 struct ieee80211_vif *vif,
1126 struct ieee80211_sta *sta,
1127 struct ieee80211_key_conf *key)
1128{
1129 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1130 int ret;
1131
1132 if (iwlwifi_mod_params.sw_crypto) {
1133 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1134 return -EOPNOTSUPP;
1135 }
1136
1137 switch (key->cipher) {
1138 case WLAN_CIPHER_SUITE_TKIP:
1139 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1140 /* fall-through */
1141 case WLAN_CIPHER_SUITE_CCMP:
1142 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1143 break;
1144 case WLAN_CIPHER_SUITE_AES_CMAC:
1145 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1146 break;
1147 case WLAN_CIPHER_SUITE_WEP40:
1148 case WLAN_CIPHER_SUITE_WEP104:
1149 /*
1150 * Support for TX only, at least for now, so accept
1151 * the key and do nothing else. Then mac80211 will
1152 * pass it for TX but we don't have to use it for RX.
1153 */
1154 return 0;
1155 default:
1156 return -EOPNOTSUPP;
1157 }
1158
1159 mutex_lock(&mvm->mutex);
1160
1161 switch (cmd) {
1162 case SET_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001163 if (vif->type == NL80211_IFTYPE_AP && !sta) {
1164 /* GTK on AP interface is a TX-only key, return 0 */
1165 ret = 0;
1166 key->hw_key_idx = STA_KEY_IDX_INVALID;
1167 break;
1168 }
1169
Johannes Berg8ca151b2013-01-24 14:25:36 +01001170 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1171 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1172 if (ret) {
1173 IWL_WARN(mvm, "set key failed\n");
1174 /*
1175 * can't add key for RX, but we don't need it
1176 * in the device for TX so still return 0
1177 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001178 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001179 ret = 0;
1180 }
1181
1182 break;
1183 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001184 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1185 ret = 0;
1186 break;
1187 }
1188
Johannes Berg8ca151b2013-01-24 14:25:36 +01001189 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1190 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1191 break;
1192 default:
1193 ret = -EINVAL;
1194 }
1195
1196 mutex_unlock(&mvm->mutex);
1197 return ret;
1198}
1199
1200static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1201 struct ieee80211_vif *vif,
1202 struct ieee80211_key_conf *keyconf,
1203 struct ieee80211_sta *sta,
1204 u32 iv32, u16 *phase1key)
1205{
1206 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1207
1208 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1209}
1210
1211
1212static int iwl_mvm_roc(struct ieee80211_hw *hw,
1213 struct ieee80211_vif *vif,
1214 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001215 int duration,
1216 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001217{
1218 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001219 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001220 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03001221 struct iwl_mvm_phy_ctxt *phy_ctxt;
1222 int ret, i;
1223
1224 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1225 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001226
1227 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1228 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1229 return -EINVAL;
1230 }
1231
Johannes Berg8ca151b2013-01-24 14:25:36 +01001232 mutex_lock(&mvm->mutex);
1233
Ilan Peer31d385a2013-04-02 10:25:46 +03001234 for (i = 0; i < NUM_PHY_CTX; i++) {
1235 phy_ctxt = &mvm->phy_ctxts[i];
1236 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1237 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001238
Ilan Peer31d385a2013-04-02 10:25:46 +03001239 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1240 /*
1241 * Unbind the P2P_DEVICE from the current PHY context,
1242 * and if the PHY context is not used remove it.
1243 */
1244 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1245 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1246 goto out_unlock;
1247
1248 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1249
1250 /* Bind the P2P_DEVICE to the current PHY Context */
1251 mvmvif->phy_ctxt = phy_ctxt;
1252
1253 ret = iwl_mvm_binding_add_vif(mvm, vif);
1254 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1255 goto out_unlock;
1256
1257 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1258 goto schedule_time_event;
1259 }
1260 }
1261
1262 /* Need to update the PHY context only if the ROC channel changed */
1263 if (channel == mvmvif->phy_ctxt->channel)
1264 goto schedule_time_event;
1265
1266 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1267
1268 /*
1269 * Change the PHY context configuration as it is currently referenced
1270 * only by the P2P Device MAC
1271 */
1272 if (mvmvif->phy_ctxt->ref == 1) {
1273 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1274 &chandef, 1, 1);
1275 if (ret)
1276 goto out_unlock;
1277 } else {
1278 /*
1279 * The PHY context is shared with other MACs. Need to remove the
1280 * P2P Device from the binding, allocate an new PHY context and
1281 * create a new binding
1282 */
1283 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1284 if (!phy_ctxt) {
1285 ret = -ENOSPC;
1286 goto out_unlock;
1287 }
1288
1289 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1290 1, 1);
1291 if (ret) {
1292 IWL_ERR(mvm, "Failed to change PHY context\n");
1293 goto out_unlock;
1294 }
1295
1296 /* Unbind the P2P_DEVICE from the current PHY context */
1297 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1298 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1299 goto out_unlock;
1300
1301 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1302
1303 /* Bind the P2P_DEVICE to the new allocated PHY context */
1304 mvmvif->phy_ctxt = phy_ctxt;
1305
1306 ret = iwl_mvm_binding_add_vif(mvm, vif);
1307 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1308 goto out_unlock;
1309
1310 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1311 }
1312
1313schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001314 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02001315 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001316
Ilan Peer31d385a2013-04-02 10:25:46 +03001317out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001318 mutex_unlock(&mvm->mutex);
1319 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001320 return ret;
1321}
1322
1323static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1324{
1325 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1326
1327 IWL_DEBUG_MAC80211(mvm, "enter\n");
1328
1329 mutex_lock(&mvm->mutex);
1330 iwl_mvm_stop_p2p_roc(mvm);
1331 mutex_unlock(&mvm->mutex);
1332
1333 IWL_DEBUG_MAC80211(mvm, "leave\n");
1334 return 0;
1335}
1336
1337static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1338 struct ieee80211_chanctx_conf *ctx)
1339{
1340 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001341 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1342 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001343 int ret;
1344
Ilan Peer53a9d612013-04-28 11:55:08 +03001345 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001346
1347 mutex_lock(&mvm->mutex);
1348 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1349 if (!phy_ctxt) {
1350 ret = -ENOSPC;
1351 goto out;
1352 }
1353
Ilan Peer53a9d612013-04-28 11:55:08 +03001354 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1355 ctx->rx_chains_static,
1356 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001357 if (ret) {
1358 IWL_ERR(mvm, "Failed to add PHY context\n");
1359 goto out;
1360 }
1361
Ilan Peer53a9d612013-04-28 11:55:08 +03001362 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001363 *phy_ctxt_id = phy_ctxt->id;
1364out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001365 mutex_unlock(&mvm->mutex);
1366 return ret;
1367}
1368
1369static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1370 struct ieee80211_chanctx_conf *ctx)
1371{
1372 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001373 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1374 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001375
1376 mutex_lock(&mvm->mutex);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001377 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001378 mutex_unlock(&mvm->mutex);
1379}
1380
1381static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1382 struct ieee80211_chanctx_conf *ctx,
1383 u32 changed)
1384{
1385 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001386 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1387 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001388
Ilan Peer31d385a2013-04-02 10:25:46 +03001389 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1390 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1391 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
1392 IEEE80211_CHANCTX_CHANGE_RADAR)),
1393 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1394 phy_ctxt->ref, changed))
1395 return;
1396
Johannes Berg8ca151b2013-01-24 14:25:36 +01001397 mutex_lock(&mvm->mutex);
1398 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1399 ctx->rx_chains_static,
1400 ctx->rx_chains_dynamic);
1401 mutex_unlock(&mvm->mutex);
1402}
1403
1404static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1405 struct ieee80211_vif *vif,
1406 struct ieee80211_chanctx_conf *ctx)
1407{
1408 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001409 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1410 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001411 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1412 int ret;
1413
1414 mutex_lock(&mvm->mutex);
1415
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001416 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001417
1418 switch (vif->type) {
1419 case NL80211_IFTYPE_AP:
1420 /*
1421 * The AP binding flow is handled as part of the start_ap flow
1422 * (in bss_info_changed).
1423 */
1424 ret = 0;
1425 goto out_unlock;
1426 case NL80211_IFTYPE_STATION:
1427 case NL80211_IFTYPE_ADHOC:
1428 case NL80211_IFTYPE_MONITOR:
1429 break;
1430 default:
1431 ret = -EINVAL;
1432 goto out_unlock;
1433 }
1434
1435 ret = iwl_mvm_binding_add_vif(mvm, vif);
1436 if (ret)
1437 goto out_unlock;
1438
1439 /*
1440 * Setting the quota at this stage is only required for monitor
1441 * interfaces. For the other types, the bss_info changed flow
1442 * will handle quota settings.
1443 */
1444 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02001445 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001446 ret = iwl_mvm_update_quotas(mvm, vif);
1447 if (ret)
1448 goto out_remove_binding;
1449 }
1450
1451 goto out_unlock;
1452
1453 out_remove_binding:
1454 iwl_mvm_binding_remove_vif(mvm, vif);
1455 out_unlock:
1456 mutex_unlock(&mvm->mutex);
1457 if (ret)
1458 mvmvif->phy_ctxt = NULL;
1459 return ret;
1460}
1461
1462static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1463 struct ieee80211_vif *vif,
1464 struct ieee80211_chanctx_conf *ctx)
1465{
1466 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1467 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1468
1469 mutex_lock(&mvm->mutex);
1470
1471 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1472
1473 if (vif->type == NL80211_IFTYPE_AP)
1474 goto out_unlock;
1475
Johannes Berg8ca151b2013-01-24 14:25:36 +01001476 switch (vif->type) {
1477 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02001478 mvmvif->monitor_active = false;
1479 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001480 break;
1481 default:
1482 break;
1483 }
1484
Ilan Peer1e1391c2013-03-13 14:52:04 +02001485 iwl_mvm_binding_remove_vif(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001486out_unlock:
1487 mvmvif->phy_ctxt = NULL;
1488 mutex_unlock(&mvm->mutex);
1489}
1490
1491static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1492 struct ieee80211_sta *sta,
1493 bool set)
1494{
1495 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1496 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1497
1498 if (!mvm_sta || !mvm_sta->vif) {
1499 IWL_ERR(mvm, "Station is not associated to a vif\n");
1500 return -EINVAL;
1501 }
1502
1503 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1504}
1505
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +02001506static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw *hw,
1507 struct ieee80211_vif *vif,
1508 enum ieee80211_rssi_event rssi_event)
1509{
1510 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1511
1512 iwl_mvm_bt_rssi_event(mvm, vif, rssi_event);
1513}
1514
Johannes Berg8ca151b2013-01-24 14:25:36 +01001515struct ieee80211_ops iwl_mvm_hw_ops = {
1516 .tx = iwl_mvm_mac_tx,
1517 .ampdu_action = iwl_mvm_mac_ampdu_action,
1518 .start = iwl_mvm_mac_start,
1519 .restart_complete = iwl_mvm_mac_restart_complete,
1520 .stop = iwl_mvm_mac_stop,
1521 .add_interface = iwl_mvm_mac_add_interface,
1522 .remove_interface = iwl_mvm_mac_remove_interface,
1523 .config = iwl_mvm_mac_config,
1524 .configure_filter = iwl_mvm_configure_filter,
1525 .bss_info_changed = iwl_mvm_bss_info_changed,
1526 .hw_scan = iwl_mvm_mac_hw_scan,
1527 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1528 .sta_state = iwl_mvm_mac_sta_state,
1529 .sta_notify = iwl_mvm_mac_sta_notify,
1530 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1531 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1532 .conf_tx = iwl_mvm_mac_conf_tx,
1533 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
1534 .set_key = iwl_mvm_mac_set_key,
1535 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1536 .remain_on_channel = iwl_mvm_roc,
1537 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +02001538 .rssi_callback = iwl_mvm_mac_rssi_callback,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001539
1540 .add_chanctx = iwl_mvm_add_chanctx,
1541 .remove_chanctx = iwl_mvm_remove_chanctx,
1542 .change_chanctx = iwl_mvm_change_chanctx,
1543 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1544 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1545
1546 .start_ap = iwl_mvm_start_ap,
1547 .stop_ap = iwl_mvm_stop_ap,
1548
1549 .set_tim = iwl_mvm_set_tim,
1550
1551#ifdef CONFIG_PM_SLEEP
1552 /* look at d3.c */
1553 .suspend = iwl_mvm_suspend,
1554 .resume = iwl_mvm_resume,
1555 .set_wakeup = iwl_mvm_set_wakeup,
1556 .set_rekey_data = iwl_mvm_set_rekey_data,
1557#if IS_ENABLED(CONFIG_IPV6)
1558 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1559#endif
1560 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1561#endif
1562};