blob: 9baa3d53ffee40f80c8418146adeb98be894147f [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,
84 .types = BIT(NL80211_IFTYPE_STATION) |
85 BIT(NL80211_IFTYPE_AP),
86 },
87 {
88 .max = 1,
89 .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
90 BIT(NL80211_IFTYPE_P2P_GO),
91 },
92 {
93 .max = 1,
94 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
95 },
96};
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
Johannes Berg8ca151b2013-01-24 14:25:36 +0100130int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
131{
132 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200133 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100134
135 /* Tell mac80211 our characteristics */
136 hw->flags = IEEE80211_HW_SIGNAL_DBM |
137 IEEE80211_HW_SPECTRUM_MGMT |
138 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
139 IEEE80211_HW_QUEUE_CONTROL |
140 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100141 IEEE80211_HW_SUPPORTS_PS |
142 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100143 IEEE80211_HW_AMPDU_AGGREGATION |
144 IEEE80211_HW_TIMING_BEACON_ONLY;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100145
Ilan Peer398e8c62013-03-13 15:20:35 +0200146 hw->queues = IWL_MVM_FIRST_AGG_QUEUE;
147 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100148 hw->rate_control_algorithm = "iwl-mvm-rs";
149
150 /*
151 * Enable 11w if advertised by firmware and software crypto
152 * is not enabled (as the firmware will interpret some mgmt
153 * packets, so enabling it with software crypto isn't safe)
154 */
155 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
156 !iwlwifi_mod_params.sw_crypto)
157 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
158
159 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
160 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
161 hw->chanctx_data_size = sizeof(struct iwl_mvm_phy_ctxt);
162
163 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
164 BIT(NL80211_IFTYPE_P2P_CLIENT) |
165 BIT(NL80211_IFTYPE_AP) |
166 BIT(NL80211_IFTYPE_P2P_GO) |
167 BIT(NL80211_IFTYPE_P2P_DEVICE);
168
169 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
170 WIPHY_FLAG_DISABLE_BEACON_HINTS |
171 WIPHY_FLAG_IBSS_RSN;
172
173 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
174 hw->wiphy->n_iface_combinations =
175 ARRAY_SIZE(iwl_mvm_iface_combinations);
176
Ilan Peerc451e6d2013-02-20 08:41:54 +0200177 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100178 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
179
180 /* Extract MAC address */
181 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
182 hw->wiphy->addresses = mvm->addresses;
183 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200184
185 /* Extract additional MAC addresses if available */
186 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
187 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
188
189 for (i = 1; i < num_mac; i++) {
190 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100191 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200192 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100193 hw->wiphy->n_addresses++;
194 }
195
196 /* we create the 802.11 header and a max-length SSID element */
197 hw->wiphy->max_scan_ie_len =
198 mvm->fw->ucode_capa.max_probe_length - 24 - 34;
199 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
200
201 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
202 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
203 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
204 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
205 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
206 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
207
208 hw->wiphy->hw_version = mvm->trans->hw_id;
209
210 if (iwlwifi_mod_params.power_save)
211 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
212 else
213 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
214
215 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
216 NL80211_FEATURE_P2P_GO_OPPPS;
217
218 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
219
220#ifdef CONFIG_PM_SLEEP
221 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
222 mvm->trans->ops->d3_suspend &&
223 mvm->trans->ops->d3_resume &&
224 device_can_wakeup(mvm->trans->dev)) {
225 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
226 WIPHY_WOWLAN_DISCONNECT |
227 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
228 WIPHY_WOWLAN_RFKILL_RELEASE;
229 if (!iwlwifi_mod_params.sw_crypto)
230 hw->wiphy->wowlan.flags |=
231 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
232 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
233 WIPHY_WOWLAN_4WAY_HANDSHAKE;
234
235 hw->wiphy->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
236 hw->wiphy->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
237 hw->wiphy->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
Johannes Bergf0c26462013-01-22 20:41:58 +0100238 hw->wiphy->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100239 }
240#endif
241
242 ret = iwl_mvm_leds_init(mvm);
243 if (ret)
244 return ret;
245
246 return ieee80211_register_hw(mvm->hw);
247}
248
249static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
250 struct ieee80211_tx_control *control,
251 struct sk_buff *skb)
252{
253 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
254
255 if (test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status)) {
256 IWL_DEBUG_DROP(mvm, "Dropping - RF KILL\n");
257 goto drop;
258 }
259
Ilan Peer398e8c62013-03-13 15:20:35 +0200260 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100261 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
262 goto drop;
263
264 if (control->sta) {
265 if (iwl_mvm_tx_skb(mvm, skb, control->sta))
266 goto drop;
267 return;
268 }
269
270 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
271 goto drop;
272 return;
273 drop:
274 ieee80211_free_txskb(hw, skb);
275}
276
277static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
278 struct ieee80211_vif *vif,
279 enum ieee80211_ampdu_mlme_action action,
280 struct ieee80211_sta *sta, u16 tid,
281 u16 *ssn, u8 buf_size)
282{
283 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
284 int ret;
285
286 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
287 sta->addr, tid, action);
288
289 if (!(mvm->nvm_data->sku_cap_11n_enable))
290 return -EACCES;
291
292 mutex_lock(&mvm->mutex);
293
294 switch (action) {
295 case IEEE80211_AMPDU_RX_START:
296 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
297 ret = -EINVAL;
298 break;
299 }
300 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
301 break;
302 case IEEE80211_AMPDU_RX_STOP:
303 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
304 break;
305 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200306 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
307 ret = -EINVAL;
308 break;
309 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100310 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
311 break;
312 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200313 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
314 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100315 case IEEE80211_AMPDU_TX_STOP_FLUSH:
316 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200317 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100318 break;
319 case IEEE80211_AMPDU_TX_OPERATIONAL:
320 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
321 break;
322 default:
323 WARN_ON_ONCE(1);
324 ret = -EINVAL;
325 break;
326 }
327 mutex_unlock(&mvm->mutex);
328
329 return ret;
330}
331
332static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
333 struct ieee80211_vif *vif)
334{
335 struct iwl_mvm *mvm = data;
336 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
337
338 mvmvif->uploaded = false;
339 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
340
341 /* does this make sense at all? */
342 mvmvif->color++;
343
344 spin_lock_bh(&mvm->time_event_lock);
345 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
346 spin_unlock_bh(&mvm->time_event_lock);
347
348 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
349 mvmvif->phy_ctxt = NULL;
350}
351
352static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
353{
354 iwl_trans_stop_device(mvm->trans);
355 iwl_trans_stop_hw(mvm->trans, false);
356
357 mvm->scan_status = IWL_MVM_SCAN_NONE;
358
359 /* just in case one was running */
360 ieee80211_remain_on_channel_expired(mvm->hw);
361
362 ieee80211_iterate_active_interfaces_atomic(
363 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
364 iwl_mvm_cleanup_iterator, mvm);
365
366 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
367 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
368
369 ieee80211_wake_queues(mvm->hw);
370
371 mvm->vif_count = 0;
372}
373
374static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
375{
376 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
377 int ret;
378
379 mutex_lock(&mvm->mutex);
380
381 /* Clean up some internal and mac80211 state on restart */
382 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
383 iwl_mvm_restart_cleanup(mvm);
384
385 ret = iwl_mvm_up(mvm);
386 mutex_unlock(&mvm->mutex);
387
388 return ret;
389}
390
391static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
392{
393 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
394 int ret;
395
396 mutex_lock(&mvm->mutex);
397
398 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
399 ret = iwl_mvm_update_quotas(mvm, NULL);
400 if (ret)
401 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
402 ret);
403
404 mutex_unlock(&mvm->mutex);
405}
406
407static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
408{
409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
410
411 flush_work(&mvm->async_handlers_wk);
412
413 mutex_lock(&mvm->mutex);
414 /* async_handlers_wk is now blocked */
415
416 /*
417 * The work item could be running or queued if the
418 * ROC time event stops just as we get here.
419 */
420 cancel_work_sync(&mvm->roc_done_wk);
421
422 iwl_trans_stop_device(mvm->trans);
423 iwl_trans_stop_hw(mvm->trans, false);
424
425 iwl_mvm_async_handlers_purge(mvm);
426 /* async_handlers_list is empty and will stay empty: HW is stopped */
427
428 /* the fw is stopped, the aux sta is dead: clean up driver state */
429 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
430
431 mutex_unlock(&mvm->mutex);
432
433 /*
434 * The worker might have been waiting for the mutex, let it run and
435 * discover that its list is now empty.
436 */
437 cancel_work_sync(&mvm->async_handlers_wk);
438}
439
440static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
441 struct ieee80211_vif *vif)
442{
443 struct iwl_mvm *mvm = data;
444 int ret;
445
446 ret = iwl_mvm_power_disable(mvm, vif);
447 if (ret)
448 IWL_ERR(mvm, "failed to disable power management\n");
449}
450
451static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
452 struct ieee80211_vif *vif)
453{
454 struct iwl_mvm *mvm = data;
455
456 iwl_mvm_power_update_mode(mvm, vif);
457}
458
459static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
460 struct ieee80211_vif *vif)
461{
462 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
463 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
464 int ret;
465
466 /*
467 * Not much to do here. The stack will not allow interface
468 * types or combinations that we didn't advertise, so we
469 * don't really have to check the types.
470 */
471
472 mutex_lock(&mvm->mutex);
473
474 /* Allocate resources for the MAC context, and add it the the fw */
475 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
476 if (ret)
477 goto out_unlock;
478
479 /*
480 * The AP binding flow can be done only after the beacon
481 * template is configured (which happens only in the mac80211
482 * start_ap() flow), and adding the broadcast station can happen
483 * only after the binding.
484 * In addition, since modifying the MAC before adding a bcast
485 * station is not allowed by the FW, delay the adding of MAC context to
486 * the point where we can also add the bcast station.
487 * In short: there's not much we can do at this point, other than
488 * allocating resources :)
489 */
490 if (vif->type == NL80211_IFTYPE_AP) {
491 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
492 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
493 qmask);
494 if (ret) {
495 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
496 goto out_release;
497 }
498
499 goto out_unlock;
500 }
501
502 /*
503 * TODO: remove this temporary code.
504 * Currently MVM FW supports power management only on single MAC.
505 * Iterate and disable PM on all active interfaces.
506 * Note: the method below does not count the new interface being added
507 * at this moment.
508 */
509 mvm->vif_count++;
510 if (mvm->vif_count > 1) {
511 IWL_DEBUG_MAC80211(mvm,
512 "Disable power on existing interfaces\n");
Emmanuel Grumbach5360cfb2013-02-11 15:56:01 +0200513 ieee80211_iterate_active_interfaces_atomic(
Johannes Berg8ca151b2013-01-24 14:25:36 +0100514 mvm->hw,
515 IEEE80211_IFACE_ITER_NORMAL,
516 iwl_mvm_pm_disable_iterator, mvm);
517 }
518
519 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
520 if (ret)
521 goto out_release;
522
523 /*
524 * Update power state on the new interface. Admittedly, based on
525 * mac80211 logics this power update will disable power management
526 */
527 iwl_mvm_power_update_mode(mvm, vif);
528
529 /*
530 * P2P_DEVICE interface does not have a channel context assigned to it,
531 * so a dedicated PHY context is allocated to it and the corresponding
532 * MAC context is bound to it at this stage.
533 */
534 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
535 struct ieee80211_channel *chan;
536 struct cfg80211_chan_def chandef;
537
538 mvmvif->phy_ctxt = &mvm->phy_ctxt_roc;
539
540 /*
541 * The channel used here isn't relevant as it's
542 * going to be overwritten as part of the ROC flow.
543 * For now use the first channel we have.
544 */
545 chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0];
546 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
547 ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt,
548 &chandef, 1, 1);
549 if (ret)
550 goto out_remove_mac;
551
552 ret = iwl_mvm_binding_add_vif(mvm, vif);
553 if (ret)
554 goto out_remove_phy;
555
556 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
557 if (ret)
558 goto out_unbind;
559
560 /* Save a pointer to p2p device vif, so it can later be used to
561 * update the p2p device MAC when a GO is started/stopped */
562 mvm->p2p_device_vif = vif;
563 }
564
Johannes Berg63494372013-03-26 10:47:53 +0100565 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100566 goto out_unlock;
567
568 out_unbind:
569 iwl_mvm_binding_remove_vif(mvm, vif);
570 out_remove_phy:
571 iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt);
572 out_remove_mac:
573 mvmvif->phy_ctxt = NULL;
574 iwl_mvm_mac_ctxt_remove(mvm, vif);
575 out_release:
576 /*
577 * TODO: remove this temporary code.
578 * Currently MVM FW supports power management only on single MAC.
579 * Check if only one additional interface remains after rereasing
580 * current one. Update power mode on the remaining interface.
581 */
582 mvm->vif_count--;
583 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
584 mvm->vif_count);
585 if (mvm->vif_count == 1) {
586 ieee80211_iterate_active_interfaces(
587 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
588 iwl_mvm_power_update_iterator, mvm);
589 }
590 iwl_mvm_mac_ctxt_release(mvm, vif);
591 out_unlock:
592 mutex_unlock(&mvm->mutex);
593
594 return ret;
595}
596
Johannes Berg38a12b52013-02-22 14:07:56 +0100597static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
598 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100599{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100600 u32 tfd_msk = 0, ac;
601
602 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
603 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
604 tfd_msk |= BIT(vif->hw_queue[ac]);
605
606 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
607 tfd_msk |= BIT(vif->cab_queue);
608
609 if (tfd_msk) {
610 mutex_lock(&mvm->mutex);
611 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
612 mutex_unlock(&mvm->mutex);
613 }
614
615 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
616 /*
617 * Flush the ROC worker which will flush the OFFCHANNEL queue.
618 * We assume here that all the packets sent to the OFFCHANNEL
619 * queue are sent in ROC session.
620 */
621 flush_work(&mvm->roc_done_wk);
622 } else {
623 /*
624 * By now, all the AC queues are empty. The AGG queues are
625 * empty too. We already got all the Tx responses for all the
626 * packets in the queues. The drain work can have been
627 * triggered. Flush it. This work item takes the mutex, so kill
628 * it before we take it.
629 */
630 flush_work(&mvm->sta_drained_wk);
631 }
Johannes Berg38a12b52013-02-22 14:07:56 +0100632}
633
634static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
635 struct ieee80211_vif *vif)
636{
637 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
638 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
639
640 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100641
642 mutex_lock(&mvm->mutex);
643
Johannes Berg63494372013-03-26 10:47:53 +0100644 iwl_mvm_vif_dbgfs_clean(mvm, vif);
645
Johannes Berg8ca151b2013-01-24 14:25:36 +0100646 /*
647 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +0100648 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100649 */
650 if (vif->type == NL80211_IFTYPE_AP) {
651 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
652 goto out_release;
653 }
654
655 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
656 mvm->p2p_device_vif = NULL;
657 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
658 iwl_mvm_binding_remove_vif(mvm, vif);
659 iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt);
660 mvmvif->phy_ctxt = NULL;
661 }
662
663 /*
664 * TODO: remove this temporary code.
665 * Currently MVM FW supports power management only on single MAC.
666 * Check if only one additional interface remains after removing
667 * current one. Update power mode on the remaining interface.
668 */
669 if (mvm->vif_count)
670 mvm->vif_count--;
671 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
672 mvm->vif_count);
673 if (mvm->vif_count == 1) {
674 ieee80211_iterate_active_interfaces(
675 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
676 iwl_mvm_power_update_iterator, mvm);
677 }
678
679 iwl_mvm_mac_ctxt_remove(mvm, vif);
680
681out_release:
682 iwl_mvm_mac_ctxt_release(mvm, vif);
683 mutex_unlock(&mvm->mutex);
684}
685
686static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
687{
688 return 0;
689}
690
691static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
692 unsigned int changed_flags,
693 unsigned int *total_flags,
694 u64 multicast)
695{
696 *total_flags = 0;
697}
698
699static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
700 struct ieee80211_vif *vif,
701 struct ieee80211_bss_conf *bss_conf,
702 u32 changes)
703{
704 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
705 int ret;
706
707 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
708 if (ret)
709 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
710
711 if (changes & BSS_CHANGED_ASSOC) {
712 if (bss_conf->assoc) {
713 /* add quota for this interface */
714 ret = iwl_mvm_update_quotas(mvm, vif);
715 if (ret) {
716 IWL_ERR(mvm, "failed to update quotas\n");
717 return;
718 }
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200719 iwl_mvm_bt_coex_vif_assoc(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100720 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
721 /* remove AP station now that the MAC is unassoc */
722 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
723 if (ret)
724 IWL_ERR(mvm, "failed to remove AP station\n");
725 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
726 /* remove quota for this interface */
727 ret = iwl_mvm_update_quotas(mvm, NULL);
728 if (ret)
729 IWL_ERR(mvm, "failed to update quotas\n");
730 }
Johannes Berg210a5442013-01-24 23:48:23 +0100731 } else if (changes & BSS_CHANGED_DTIM_PERIOD) {
732 /*
733 * We received a beacon _after_ association so
734 * remove the session protection.
735 */
736 iwl_mvm_remove_time_event(mvm, mvmvif,
737 &mvmvif->time_event_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100738 } else if (changes & BSS_CHANGED_PS) {
739 /*
740 * TODO: remove this temporary code.
741 * Currently MVM FW supports power management only on single
742 * MAC. Avoid power mode update if more than one interface
743 * is active.
744 */
745 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
746 mvm->vif_count);
747 if (mvm->vif_count == 1) {
748 ret = iwl_mvm_power_update_mode(mvm, vif);
749 if (ret)
750 IWL_ERR(mvm, "failed to update power mode\n");
751 }
752 }
753}
754
755static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
756{
757 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
758 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
759 int ret;
760
761 mutex_lock(&mvm->mutex);
762
763 /* Send the beacon template */
764 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
765 if (ret)
766 goto out_unlock;
767
768 /* Add the mac context */
769 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
770 if (ret)
771 goto out_unlock;
772
773 /* Perform the binding */
774 ret = iwl_mvm_binding_add_vif(mvm, vif);
775 if (ret)
776 goto out_remove;
777
778 mvmvif->ap_active = true;
779
780 /* Send the bcast station. At this stage the TBTT and DTIM time events
781 * are added and applied to the scheduler */
782 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
783 if (ret)
784 goto out_unbind;
785
786 ret = iwl_mvm_update_quotas(mvm, vif);
787 if (ret)
788 goto out_rm_bcast;
789
790 /* Need to update the P2P Device MAC */
791 if (vif->p2p && mvm->p2p_device_vif)
792 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
793
794 mutex_unlock(&mvm->mutex);
795 return 0;
796
797out_rm_bcast:
798 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
799out_unbind:
800 iwl_mvm_binding_remove_vif(mvm, vif);
801out_remove:
802 iwl_mvm_mac_ctxt_remove(mvm, vif);
803out_unlock:
804 mutex_unlock(&mvm->mutex);
805 return ret;
806}
807
808static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
809{
810 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
811 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
812
Johannes Berg38a12b52013-02-22 14:07:56 +0100813 iwl_mvm_prepare_mac_removal(mvm, vif);
814
Johannes Berg8ca151b2013-01-24 14:25:36 +0100815 mutex_lock(&mvm->mutex);
816
817 mvmvif->ap_active = false;
818
819 /* Need to update the P2P Device MAC */
820 if (vif->p2p && mvm->p2p_device_vif)
821 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
822
823 iwl_mvm_update_quotas(mvm, NULL);
824 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
825 iwl_mvm_binding_remove_vif(mvm, vif);
826 iwl_mvm_mac_ctxt_remove(mvm, vif);
827
828 mutex_unlock(&mvm->mutex);
829}
830
831static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
832 struct ieee80211_vif *vif,
833 struct ieee80211_bss_conf *bss_conf,
834 u32 changes)
835{
836 /* Need to send a new beacon template to the FW */
837 if (changes & BSS_CHANGED_BEACON) {
838 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
839 IWL_WARN(mvm, "Failed updating beacon data\n");
840 }
841}
842
843static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
844 struct ieee80211_vif *vif,
845 struct ieee80211_bss_conf *bss_conf,
846 u32 changes)
847{
848 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
849
850 mutex_lock(&mvm->mutex);
851
852 switch (vif->type) {
853 case NL80211_IFTYPE_STATION:
854 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
855 break;
856 case NL80211_IFTYPE_AP:
857 iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
858 break;
859 default:
860 /* shouldn't happen */
861 WARN_ON_ONCE(1);
862 }
863
864 mutex_unlock(&mvm->mutex);
865}
866
867static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
868 struct ieee80211_vif *vif,
869 struct cfg80211_scan_request *req)
870{
871 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
872 int ret;
873
874 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
875 return -EINVAL;
876
877 mutex_lock(&mvm->mutex);
878
879 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
880 ret = iwl_mvm_scan_request(mvm, vif, req);
881 else
882 ret = -EBUSY;
883
884 mutex_unlock(&mvm->mutex);
885
886 return ret;
887}
888
889static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
890 struct ieee80211_vif *vif)
891{
892 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
893
894 mutex_lock(&mvm->mutex);
895
896 iwl_mvm_cancel_scan(mvm);
897
898 mutex_unlock(&mvm->mutex);
899}
900
901static void
902iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
903 struct ieee80211_sta *sta, u16 tid,
904 int num_frames,
905 enum ieee80211_frame_release_type reason,
906 bool more_data)
907{
908 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100909
910 /* TODO: how do we tell the fw to send frames for a specific TID */
911
912 /*
913 * The fw will send EOSP notification when the last frame will be
914 * transmitted.
915 */
Johannes Berg9cc40712013-02-15 22:47:48 +0100916 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100917}
918
919static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
920 struct ieee80211_vif *vif,
921 enum sta_notify_cmd cmd,
922 struct ieee80211_sta *sta)
923{
924 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
925 struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
926
927 switch (cmd) {
928 case STA_NOTIFY_SLEEP:
929 if (atomic_read(&mvmsta->pending_frames) > 0)
930 ieee80211_sta_block_awake(hw, sta, true);
931 /*
932 * The fw updates the STA to be asleep. Tx packets on the Tx
933 * queues to this station will not be transmitted. The fw will
934 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
935 */
936 break;
937 case STA_NOTIFY_AWAKE:
938 if (WARN_ON(mvmsta->sta_id == IWL_INVALID_STATION))
939 break;
Johannes Berg9cc40712013-02-15 22:47:48 +0100940 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100941 break;
942 default:
943 break;
944 }
945}
946
947static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
948 struct ieee80211_vif *vif,
949 struct ieee80211_sta *sta,
950 enum ieee80211_sta_state old_state,
951 enum ieee80211_sta_state new_state)
952{
953 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
954 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
955 int ret;
956
957 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
958 sta->addr, old_state, new_state);
959
960 /* this would be a mac80211 bug ... but don't crash */
961 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
962 return -EINVAL;
963
964 /* if a STA is being removed, reuse its ID */
965 flush_work(&mvm->sta_drained_wk);
966
967 mutex_lock(&mvm->mutex);
968 if (old_state == IEEE80211_STA_NOTEXIST &&
969 new_state == IEEE80211_STA_NONE) {
970 ret = iwl_mvm_add_sta(mvm, vif, sta);
971 } else if (old_state == IEEE80211_STA_NONE &&
972 new_state == IEEE80211_STA_AUTH) {
973 ret = 0;
974 } else if (old_state == IEEE80211_STA_AUTH &&
975 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +0100976 ret = iwl_mvm_update_sta(mvm, vif, sta);
977 if (ret == 0)
978 iwl_mvm_rs_rate_init(mvm, sta,
979 mvmvif->phy_ctxt->channel->band);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100980 } else if (old_state == IEEE80211_STA_ASSOC &&
981 new_state == IEEE80211_STA_AUTHORIZED) {
982 ret = 0;
983 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
984 new_state == IEEE80211_STA_ASSOC) {
985 ret = 0;
986 } else if (old_state == IEEE80211_STA_ASSOC &&
987 new_state == IEEE80211_STA_AUTH) {
988 ret = 0;
989 } else if (old_state == IEEE80211_STA_AUTH &&
990 new_state == IEEE80211_STA_NONE) {
991 ret = 0;
992 } else if (old_state == IEEE80211_STA_NONE &&
993 new_state == IEEE80211_STA_NOTEXIST) {
994 ret = iwl_mvm_rm_sta(mvm, vif, sta);
995 } else {
996 ret = -EIO;
997 }
998 mutex_unlock(&mvm->mutex);
999
1000 return ret;
1001}
1002
1003static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1004{
1005 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1006
1007 mvm->rts_threshold = value;
1008
1009 return 0;
1010}
1011
1012static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1013 struct ieee80211_vif *vif, u16 ac,
1014 const struct ieee80211_tx_queue_params *params)
1015{
1016 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1017 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1018
1019 mvmvif->queue_params[ac] = *params;
1020
1021 /*
1022 * No need to update right away, we'll get BSS_CHANGED_QOS
1023 * The exception is P2P_DEVICE interface which needs immediate update.
1024 */
1025 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1026 int ret;
1027
1028 mutex_lock(&mvm->mutex);
1029 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1030 mutex_unlock(&mvm->mutex);
1031 return ret;
1032 }
1033 return 0;
1034}
1035
1036static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1037 struct ieee80211_vif *vif)
1038{
1039 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1040 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1041 200 + vif->bss_conf.beacon_int);
1042 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1043 100 + vif->bss_conf.beacon_int);
1044
1045 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1046 return;
1047
1048 mutex_lock(&mvm->mutex);
1049 /* Try really hard to protect the session and hear a beacon */
1050 iwl_mvm_protect_session(mvm, vif, duration, min_duration);
1051 mutex_unlock(&mvm->mutex);
1052}
1053
1054static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1055 enum set_key_cmd cmd,
1056 struct ieee80211_vif *vif,
1057 struct ieee80211_sta *sta,
1058 struct ieee80211_key_conf *key)
1059{
1060 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1061 int ret;
1062
1063 if (iwlwifi_mod_params.sw_crypto) {
1064 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1065 return -EOPNOTSUPP;
1066 }
1067
1068 switch (key->cipher) {
1069 case WLAN_CIPHER_SUITE_TKIP:
1070 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1071 /* fall-through */
1072 case WLAN_CIPHER_SUITE_CCMP:
1073 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1074 break;
1075 case WLAN_CIPHER_SUITE_AES_CMAC:
1076 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1077 break;
1078 case WLAN_CIPHER_SUITE_WEP40:
1079 case WLAN_CIPHER_SUITE_WEP104:
1080 /*
1081 * Support for TX only, at least for now, so accept
1082 * the key and do nothing else. Then mac80211 will
1083 * pass it for TX but we don't have to use it for RX.
1084 */
1085 return 0;
1086 default:
1087 return -EOPNOTSUPP;
1088 }
1089
1090 mutex_lock(&mvm->mutex);
1091
1092 switch (cmd) {
1093 case SET_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001094 if (vif->type == NL80211_IFTYPE_AP && !sta) {
1095 /* GTK on AP interface is a TX-only key, return 0 */
1096 ret = 0;
1097 key->hw_key_idx = STA_KEY_IDX_INVALID;
1098 break;
1099 }
1100
Johannes Berg8ca151b2013-01-24 14:25:36 +01001101 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1102 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1103 if (ret) {
1104 IWL_WARN(mvm, "set key failed\n");
1105 /*
1106 * can't add key for RX, but we don't need it
1107 * in the device for TX so still return 0
1108 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001109 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001110 ret = 0;
1111 }
1112
1113 break;
1114 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001115 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1116 ret = 0;
1117 break;
1118 }
1119
Johannes Berg8ca151b2013-01-24 14:25:36 +01001120 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1121 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1122 break;
1123 default:
1124 ret = -EINVAL;
1125 }
1126
1127 mutex_unlock(&mvm->mutex);
1128 return ret;
1129}
1130
1131static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1132 struct ieee80211_vif *vif,
1133 struct ieee80211_key_conf *keyconf,
1134 struct ieee80211_sta *sta,
1135 u32 iv32, u16 *phase1key)
1136{
1137 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1138
1139 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1140}
1141
1142
1143static int iwl_mvm_roc(struct ieee80211_hw *hw,
1144 struct ieee80211_vif *vif,
1145 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001146 int duration,
1147 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001148{
1149 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1150 struct cfg80211_chan_def chandef;
1151 int ret;
1152
1153 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1154 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1155 return -EINVAL;
1156 }
1157
Ilan Peerd339d5c2013-02-12 09:34:13 +02001158 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1159 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001160
1161 mutex_lock(&mvm->mutex);
1162
1163 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1164 ret = iwl_mvm_phy_ctxt_changed(mvm, &mvm->phy_ctxt_roc,
1165 &chandef, 1, 1);
1166
1167 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02001168 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001169
1170 mutex_unlock(&mvm->mutex);
1171 IWL_DEBUG_MAC80211(mvm, "leave\n");
1172
1173 return ret;
1174}
1175
1176static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1177{
1178 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1179
1180 IWL_DEBUG_MAC80211(mvm, "enter\n");
1181
1182 mutex_lock(&mvm->mutex);
1183 iwl_mvm_stop_p2p_roc(mvm);
1184 mutex_unlock(&mvm->mutex);
1185
1186 IWL_DEBUG_MAC80211(mvm, "leave\n");
1187 return 0;
1188}
1189
1190static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1191 struct ieee80211_chanctx_conf *ctx)
1192{
1193 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1194 struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
1195 int ret;
1196
1197 mutex_lock(&mvm->mutex);
1198
1199 IWL_DEBUG_MAC80211(mvm, "Add PHY context\n");
1200 ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, &ctx->def,
1201 ctx->rx_chains_static,
1202 ctx->rx_chains_dynamic);
1203 mutex_unlock(&mvm->mutex);
1204 return ret;
1205}
1206
1207static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1208 struct ieee80211_chanctx_conf *ctx)
1209{
1210 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1211 struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
1212
1213 mutex_lock(&mvm->mutex);
1214 iwl_mvm_phy_ctxt_remove(mvm, phy_ctxt);
1215 mutex_unlock(&mvm->mutex);
1216}
1217
1218static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1219 struct ieee80211_chanctx_conf *ctx,
1220 u32 changed)
1221{
1222 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1223 struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
1224
1225 mutex_lock(&mvm->mutex);
1226 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1227 ctx->rx_chains_static,
1228 ctx->rx_chains_dynamic);
1229 mutex_unlock(&mvm->mutex);
1230}
1231
1232static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1233 struct ieee80211_vif *vif,
1234 struct ieee80211_chanctx_conf *ctx)
1235{
1236 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1237 struct iwl_mvm_phy_ctxt *phyctx = (void *)ctx->drv_priv;
1238 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1239 int ret;
1240
1241 mutex_lock(&mvm->mutex);
1242
1243 mvmvif->phy_ctxt = phyctx;
1244
1245 switch (vif->type) {
1246 case NL80211_IFTYPE_AP:
1247 /*
1248 * The AP binding flow is handled as part of the start_ap flow
1249 * (in bss_info_changed).
1250 */
1251 ret = 0;
1252 goto out_unlock;
1253 case NL80211_IFTYPE_STATION:
1254 case NL80211_IFTYPE_ADHOC:
1255 case NL80211_IFTYPE_MONITOR:
1256 break;
1257 default:
1258 ret = -EINVAL;
1259 goto out_unlock;
1260 }
1261
1262 ret = iwl_mvm_binding_add_vif(mvm, vif);
1263 if (ret)
1264 goto out_unlock;
1265
1266 /*
1267 * Setting the quota at this stage is only required for monitor
1268 * interfaces. For the other types, the bss_info changed flow
1269 * will handle quota settings.
1270 */
1271 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02001272 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001273 ret = iwl_mvm_update_quotas(mvm, vif);
1274 if (ret)
1275 goto out_remove_binding;
1276 }
1277
1278 goto out_unlock;
1279
1280 out_remove_binding:
1281 iwl_mvm_binding_remove_vif(mvm, vif);
1282 out_unlock:
1283 mutex_unlock(&mvm->mutex);
1284 if (ret)
1285 mvmvif->phy_ctxt = NULL;
1286 return ret;
1287}
1288
1289static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1290 struct ieee80211_vif *vif,
1291 struct ieee80211_chanctx_conf *ctx)
1292{
1293 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1294 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1295
1296 mutex_lock(&mvm->mutex);
1297
1298 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1299
1300 if (vif->type == NL80211_IFTYPE_AP)
1301 goto out_unlock;
1302
Johannes Berg8ca151b2013-01-24 14:25:36 +01001303 switch (vif->type) {
1304 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02001305 mvmvif->monitor_active = false;
1306 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001307 break;
1308 default:
1309 break;
1310 }
1311
Ilan Peer1e1391c2013-03-13 14:52:04 +02001312 iwl_mvm_binding_remove_vif(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001313out_unlock:
1314 mvmvif->phy_ctxt = NULL;
1315 mutex_unlock(&mvm->mutex);
1316}
1317
1318static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1319 struct ieee80211_sta *sta,
1320 bool set)
1321{
1322 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1323 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1324
1325 if (!mvm_sta || !mvm_sta->vif) {
1326 IWL_ERR(mvm, "Station is not associated to a vif\n");
1327 return -EINVAL;
1328 }
1329
1330 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1331}
1332
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +02001333static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw *hw,
1334 struct ieee80211_vif *vif,
1335 enum ieee80211_rssi_event rssi_event)
1336{
1337 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1338
1339 iwl_mvm_bt_rssi_event(mvm, vif, rssi_event);
1340}
1341
Johannes Berg8ca151b2013-01-24 14:25:36 +01001342struct ieee80211_ops iwl_mvm_hw_ops = {
1343 .tx = iwl_mvm_mac_tx,
1344 .ampdu_action = iwl_mvm_mac_ampdu_action,
1345 .start = iwl_mvm_mac_start,
1346 .restart_complete = iwl_mvm_mac_restart_complete,
1347 .stop = iwl_mvm_mac_stop,
1348 .add_interface = iwl_mvm_mac_add_interface,
1349 .remove_interface = iwl_mvm_mac_remove_interface,
1350 .config = iwl_mvm_mac_config,
1351 .configure_filter = iwl_mvm_configure_filter,
1352 .bss_info_changed = iwl_mvm_bss_info_changed,
1353 .hw_scan = iwl_mvm_mac_hw_scan,
1354 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1355 .sta_state = iwl_mvm_mac_sta_state,
1356 .sta_notify = iwl_mvm_mac_sta_notify,
1357 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1358 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1359 .conf_tx = iwl_mvm_mac_conf_tx,
1360 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
1361 .set_key = iwl_mvm_mac_set_key,
1362 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1363 .remain_on_channel = iwl_mvm_roc,
1364 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +02001365 .rssi_callback = iwl_mvm_mac_rssi_callback,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001366
1367 .add_chanctx = iwl_mvm_add_chanctx,
1368 .remove_chanctx = iwl_mvm_remove_chanctx,
1369 .change_chanctx = iwl_mvm_change_chanctx,
1370 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1371 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1372
1373 .start_ap = iwl_mvm_start_ap,
1374 .stop_ap = iwl_mvm_stop_ap,
1375
1376 .set_tim = iwl_mvm_set_tim,
1377
1378#ifdef CONFIG_PM_SLEEP
1379 /* look at d3.c */
1380 .suspend = iwl_mvm_suspend,
1381 .resume = iwl_mvm_resume,
1382 .set_wakeup = iwl_mvm_set_wakeup,
1383 .set_rekey_data = iwl_mvm_set_rekey_data,
1384#if IS_ENABLED(CONFIG_IPV6)
1385 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1386#endif
1387 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1388#endif
1389};