blob: e2cf6d92217b43ad73ecd3cb83f8d2459a559306 [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
Alexander Bondarade50652013-04-03 16:28:47 +0300210 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100211 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.
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200505 * If new interface added, disable PM on existing interface.
506 * P2P device is a special case, since it is handled by FW similary to
507 * scan. If P2P deviced is added, PM remains enabled on existing
508 * interface.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100509 * Note: the method below does not count the new interface being added
510 * at this moment.
511 */
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200512 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
513 mvm->vif_count++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100514 if (mvm->vif_count > 1) {
515 IWL_DEBUG_MAC80211(mvm,
516 "Disable power on existing interfaces\n");
Emmanuel Grumbach5360cfb2013-02-11 15:56:01 +0200517 ieee80211_iterate_active_interfaces_atomic(
Johannes Berg8ca151b2013-01-24 14:25:36 +0100518 mvm->hw,
519 IEEE80211_IFACE_ITER_NORMAL,
520 iwl_mvm_pm_disable_iterator, mvm);
521 }
522
523 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
524 if (ret)
525 goto out_release;
526
527 /*
528 * Update power state on the new interface. Admittedly, based on
529 * mac80211 logics this power update will disable power management
530 */
531 iwl_mvm_power_update_mode(mvm, vif);
532
Hila Gonen7df15b12012-12-12 11:16:19 +0200533 /* beacon filtering */
534 if (!mvm->bf_allowed_vif &&
535 vif->type == NL80211_IFTYPE_STATION && !vif->p2p){
536 mvm->bf_allowed_vif = mvmvif;
537 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
538 }
539
540 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
541 if (ret)
542 goto out_release;
543
Johannes Berg8ca151b2013-01-24 14:25:36 +0100544 /*
545 * P2P_DEVICE interface does not have a channel context assigned to it,
546 * so a dedicated PHY context is allocated to it and the corresponding
547 * MAC context is bound to it at this stage.
548 */
549 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
550 struct ieee80211_channel *chan;
551 struct cfg80211_chan_def chandef;
552
553 mvmvif->phy_ctxt = &mvm->phy_ctxt_roc;
554
555 /*
556 * The channel used here isn't relevant as it's
557 * going to be overwritten as part of the ROC flow.
558 * For now use the first channel we have.
559 */
560 chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0];
561 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
562 ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt,
563 &chandef, 1, 1);
564 if (ret)
565 goto out_remove_mac;
566
567 ret = iwl_mvm_binding_add_vif(mvm, vif);
568 if (ret)
569 goto out_remove_phy;
570
571 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
572 if (ret)
573 goto out_unbind;
574
575 /* Save a pointer to p2p device vif, so it can later be used to
576 * update the p2p device MAC when a GO is started/stopped */
577 mvm->p2p_device_vif = vif;
578 }
579
Johannes Berg63494372013-03-26 10:47:53 +0100580 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100581 goto out_unlock;
582
583 out_unbind:
584 iwl_mvm_binding_remove_vif(mvm, vif);
585 out_remove_phy:
586 iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt);
587 out_remove_mac:
588 mvmvif->phy_ctxt = NULL;
589 iwl_mvm_mac_ctxt_remove(mvm, vif);
590 out_release:
591 /*
592 * TODO: remove this temporary code.
593 * Currently MVM FW supports power management only on single MAC.
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200594 * Check if only one additional interface remains after releasing
Johannes Berg8ca151b2013-01-24 14:25:36 +0100595 * current one. Update power mode on the remaining interface.
596 */
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200597 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
598 mvm->vif_count--;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100599 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
600 mvm->vif_count);
601 if (mvm->vif_count == 1) {
602 ieee80211_iterate_active_interfaces(
603 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
604 iwl_mvm_power_update_iterator, mvm);
605 }
606 iwl_mvm_mac_ctxt_release(mvm, vif);
607 out_unlock:
608 mutex_unlock(&mvm->mutex);
609
610 return ret;
611}
612
Johannes Berg38a12b52013-02-22 14:07:56 +0100613static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
614 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100615{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100616 u32 tfd_msk = 0, ac;
617
618 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
619 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
620 tfd_msk |= BIT(vif->hw_queue[ac]);
621
622 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
623 tfd_msk |= BIT(vif->cab_queue);
624
625 if (tfd_msk) {
626 mutex_lock(&mvm->mutex);
627 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
628 mutex_unlock(&mvm->mutex);
629 }
630
631 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
632 /*
633 * Flush the ROC worker which will flush the OFFCHANNEL queue.
634 * We assume here that all the packets sent to the OFFCHANNEL
635 * queue are sent in ROC session.
636 */
637 flush_work(&mvm->roc_done_wk);
638 } else {
639 /*
640 * By now, all the AC queues are empty. The AGG queues are
641 * empty too. We already got all the Tx responses for all the
642 * packets in the queues. The drain work can have been
643 * triggered. Flush it. This work item takes the mutex, so kill
644 * it before we take it.
645 */
646 flush_work(&mvm->sta_drained_wk);
647 }
Johannes Berg38a12b52013-02-22 14:07:56 +0100648}
649
650static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
651 struct ieee80211_vif *vif)
652{
653 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
654 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
655
656 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100657
658 mutex_lock(&mvm->mutex);
659
Hila Gonen7df15b12012-12-12 11:16:19 +0200660 if (mvm->bf_allowed_vif == mvmvif) {
661 mvm->bf_allowed_vif = NULL;
662 vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
663 }
664
Johannes Berg63494372013-03-26 10:47:53 +0100665 iwl_mvm_vif_dbgfs_clean(mvm, vif);
666
Johannes Berg8ca151b2013-01-24 14:25:36 +0100667 /*
668 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +0100669 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100670 */
671 if (vif->type == NL80211_IFTYPE_AP) {
672 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
673 goto out_release;
674 }
675
676 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
677 mvm->p2p_device_vif = NULL;
678 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
679 iwl_mvm_binding_remove_vif(mvm, vif);
680 iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt);
681 mvmvif->phy_ctxt = NULL;
682 }
683
684 /*
685 * TODO: remove this temporary code.
686 * Currently MVM FW supports power management only on single MAC.
687 * Check if only one additional interface remains after removing
688 * current one. Update power mode on the remaining interface.
689 */
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200690 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100691 mvm->vif_count--;
692 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
693 mvm->vif_count);
694 if (mvm->vif_count == 1) {
695 ieee80211_iterate_active_interfaces(
696 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
697 iwl_mvm_power_update_iterator, mvm);
698 }
699
700 iwl_mvm_mac_ctxt_remove(mvm, vif);
701
702out_release:
703 iwl_mvm_mac_ctxt_release(mvm, vif);
704 mutex_unlock(&mvm->mutex);
705}
706
707static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
708{
709 return 0;
710}
711
712static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
713 unsigned int changed_flags,
714 unsigned int *total_flags,
715 u64 multicast)
716{
717 *total_flags = 0;
718}
719
720static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
721 struct ieee80211_vif *vif,
722 struct ieee80211_bss_conf *bss_conf,
723 u32 changes)
724{
725 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
726 int ret;
727
728 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
729 if (ret)
730 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
731
732 if (changes & BSS_CHANGED_ASSOC) {
733 if (bss_conf->assoc) {
734 /* add quota for this interface */
735 ret = iwl_mvm_update_quotas(mvm, vif);
736 if (ret) {
737 IWL_ERR(mvm, "failed to update quotas\n");
738 return;
739 }
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200740 iwl_mvm_bt_coex_vif_assoc(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100741 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
742 /* remove AP station now that the MAC is unassoc */
743 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
744 if (ret)
745 IWL_ERR(mvm, "failed to remove AP station\n");
746 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
747 /* remove quota for this interface */
748 ret = iwl_mvm_update_quotas(mvm, NULL);
749 if (ret)
750 IWL_ERR(mvm, "failed to update quotas\n");
751 }
Johannes Berg210a5442013-01-24 23:48:23 +0100752 } else if (changes & BSS_CHANGED_DTIM_PERIOD) {
753 /*
754 * We received a beacon _after_ association so
755 * remove the session protection.
756 */
757 iwl_mvm_remove_time_event(mvm, mvmvif,
758 &mvmvif->time_event_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100759 } else if (changes & BSS_CHANGED_PS) {
760 /*
761 * TODO: remove this temporary code.
762 * Currently MVM FW supports power management only on single
763 * MAC. Avoid power mode update if more than one interface
764 * is active.
765 */
766 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
767 mvm->vif_count);
768 if (mvm->vif_count == 1) {
769 ret = iwl_mvm_power_update_mode(mvm, vif);
770 if (ret)
771 IWL_ERR(mvm, "failed to update power mode\n");
772 }
773 }
774}
775
776static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
777{
778 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
779 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
780 int ret;
781
782 mutex_lock(&mvm->mutex);
783
784 /* Send the beacon template */
785 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
786 if (ret)
787 goto out_unlock;
788
789 /* Add the mac context */
790 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
791 if (ret)
792 goto out_unlock;
793
794 /* Perform the binding */
795 ret = iwl_mvm_binding_add_vif(mvm, vif);
796 if (ret)
797 goto out_remove;
798
799 mvmvif->ap_active = true;
800
801 /* Send the bcast station. At this stage the TBTT and DTIM time events
802 * are added and applied to the scheduler */
803 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
804 if (ret)
805 goto out_unbind;
806
807 ret = iwl_mvm_update_quotas(mvm, vif);
808 if (ret)
809 goto out_rm_bcast;
810
811 /* Need to update the P2P Device MAC */
812 if (vif->p2p && mvm->p2p_device_vif)
813 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
814
815 mutex_unlock(&mvm->mutex);
816 return 0;
817
818out_rm_bcast:
819 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
820out_unbind:
821 iwl_mvm_binding_remove_vif(mvm, vif);
822out_remove:
823 iwl_mvm_mac_ctxt_remove(mvm, vif);
824out_unlock:
825 mutex_unlock(&mvm->mutex);
826 return ret;
827}
828
829static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
830{
831 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
832 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
833
Johannes Berg38a12b52013-02-22 14:07:56 +0100834 iwl_mvm_prepare_mac_removal(mvm, vif);
835
Johannes Berg8ca151b2013-01-24 14:25:36 +0100836 mutex_lock(&mvm->mutex);
837
838 mvmvif->ap_active = false;
839
840 /* Need to update the P2P Device MAC */
841 if (vif->p2p && mvm->p2p_device_vif)
842 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
843
844 iwl_mvm_update_quotas(mvm, NULL);
845 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
846 iwl_mvm_binding_remove_vif(mvm, vif);
847 iwl_mvm_mac_ctxt_remove(mvm, vif);
848
849 mutex_unlock(&mvm->mutex);
850}
851
852static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
853 struct ieee80211_vif *vif,
854 struct ieee80211_bss_conf *bss_conf,
855 u32 changes)
856{
857 /* Need to send a new beacon template to the FW */
858 if (changes & BSS_CHANGED_BEACON) {
859 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
860 IWL_WARN(mvm, "Failed updating beacon data\n");
861 }
862}
863
864static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
865 struct ieee80211_vif *vif,
866 struct ieee80211_bss_conf *bss_conf,
867 u32 changes)
868{
869 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
870
871 mutex_lock(&mvm->mutex);
872
873 switch (vif->type) {
874 case NL80211_IFTYPE_STATION:
875 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
876 break;
877 case NL80211_IFTYPE_AP:
878 iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
879 break;
880 default:
881 /* shouldn't happen */
882 WARN_ON_ONCE(1);
883 }
884
885 mutex_unlock(&mvm->mutex);
886}
887
888static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
889 struct ieee80211_vif *vif,
890 struct cfg80211_scan_request *req)
891{
892 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
893 int ret;
894
895 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
896 return -EINVAL;
897
898 mutex_lock(&mvm->mutex);
899
900 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
901 ret = iwl_mvm_scan_request(mvm, vif, req);
902 else
903 ret = -EBUSY;
904
905 mutex_unlock(&mvm->mutex);
906
907 return ret;
908}
909
910static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
911 struct ieee80211_vif *vif)
912{
913 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
914
915 mutex_lock(&mvm->mutex);
916
917 iwl_mvm_cancel_scan(mvm);
918
919 mutex_unlock(&mvm->mutex);
920}
921
922static void
923iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
924 struct ieee80211_sta *sta, u16 tid,
925 int num_frames,
926 enum ieee80211_frame_release_type reason,
927 bool more_data)
928{
929 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100930
931 /* TODO: how do we tell the fw to send frames for a specific TID */
932
933 /*
934 * The fw will send EOSP notification when the last frame will be
935 * transmitted.
936 */
Johannes Berg9cc40712013-02-15 22:47:48 +0100937 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100938}
939
940static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
941 struct ieee80211_vif *vif,
942 enum sta_notify_cmd cmd,
943 struct ieee80211_sta *sta)
944{
945 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
946 struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
947
948 switch (cmd) {
949 case STA_NOTIFY_SLEEP:
950 if (atomic_read(&mvmsta->pending_frames) > 0)
951 ieee80211_sta_block_awake(hw, sta, true);
952 /*
953 * The fw updates the STA to be asleep. Tx packets on the Tx
954 * queues to this station will not be transmitted. The fw will
955 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
956 */
957 break;
958 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +0200959 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100960 break;
Johannes Berg9cc40712013-02-15 22:47:48 +0100961 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100962 break;
963 default:
964 break;
965 }
966}
967
968static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
969 struct ieee80211_vif *vif,
970 struct ieee80211_sta *sta,
971 enum ieee80211_sta_state old_state,
972 enum ieee80211_sta_state new_state)
973{
974 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
975 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
976 int ret;
977
978 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
979 sta->addr, old_state, new_state);
980
981 /* this would be a mac80211 bug ... but don't crash */
982 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
983 return -EINVAL;
984
985 /* if a STA is being removed, reuse its ID */
986 flush_work(&mvm->sta_drained_wk);
987
988 mutex_lock(&mvm->mutex);
989 if (old_state == IEEE80211_STA_NOTEXIST &&
990 new_state == IEEE80211_STA_NONE) {
991 ret = iwl_mvm_add_sta(mvm, vif, sta);
992 } else if (old_state == IEEE80211_STA_NONE &&
993 new_state == IEEE80211_STA_AUTH) {
994 ret = 0;
995 } else if (old_state == IEEE80211_STA_AUTH &&
996 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +0100997 ret = iwl_mvm_update_sta(mvm, vif, sta);
998 if (ret == 0)
999 iwl_mvm_rs_rate_init(mvm, sta,
1000 mvmvif->phy_ctxt->channel->band);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001001 } else if (old_state == IEEE80211_STA_ASSOC &&
1002 new_state == IEEE80211_STA_AUTHORIZED) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001003 /* enable beacon filtering */
1004 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001005 ret = 0;
1006 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1007 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001008 /* disable beacon filtering */
1009 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001010 ret = 0;
1011 } else if (old_state == IEEE80211_STA_ASSOC &&
1012 new_state == IEEE80211_STA_AUTH) {
1013 ret = 0;
1014 } else if (old_state == IEEE80211_STA_AUTH &&
1015 new_state == IEEE80211_STA_NONE) {
1016 ret = 0;
1017 } else if (old_state == IEEE80211_STA_NONE &&
1018 new_state == IEEE80211_STA_NOTEXIST) {
1019 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1020 } else {
1021 ret = -EIO;
1022 }
1023 mutex_unlock(&mvm->mutex);
1024
1025 return ret;
1026}
1027
1028static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1029{
1030 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1031
1032 mvm->rts_threshold = value;
1033
1034 return 0;
1035}
1036
1037static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1038 struct ieee80211_vif *vif, u16 ac,
1039 const struct ieee80211_tx_queue_params *params)
1040{
1041 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1042 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1043
1044 mvmvif->queue_params[ac] = *params;
1045
1046 /*
1047 * No need to update right away, we'll get BSS_CHANGED_QOS
1048 * The exception is P2P_DEVICE interface which needs immediate update.
1049 */
1050 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1051 int ret;
1052
1053 mutex_lock(&mvm->mutex);
1054 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1055 mutex_unlock(&mvm->mutex);
1056 return ret;
1057 }
1058 return 0;
1059}
1060
1061static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1062 struct ieee80211_vif *vif)
1063{
1064 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1065 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1066 200 + vif->bss_conf.beacon_int);
1067 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1068 100 + vif->bss_conf.beacon_int);
1069
1070 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1071 return;
1072
1073 mutex_lock(&mvm->mutex);
1074 /* Try really hard to protect the session and hear a beacon */
1075 iwl_mvm_protect_session(mvm, vif, duration, min_duration);
1076 mutex_unlock(&mvm->mutex);
1077}
1078
1079static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1080 enum set_key_cmd cmd,
1081 struct ieee80211_vif *vif,
1082 struct ieee80211_sta *sta,
1083 struct ieee80211_key_conf *key)
1084{
1085 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1086 int ret;
1087
1088 if (iwlwifi_mod_params.sw_crypto) {
1089 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1090 return -EOPNOTSUPP;
1091 }
1092
1093 switch (key->cipher) {
1094 case WLAN_CIPHER_SUITE_TKIP:
1095 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1096 /* fall-through */
1097 case WLAN_CIPHER_SUITE_CCMP:
1098 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1099 break;
1100 case WLAN_CIPHER_SUITE_AES_CMAC:
1101 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1102 break;
1103 case WLAN_CIPHER_SUITE_WEP40:
1104 case WLAN_CIPHER_SUITE_WEP104:
1105 /*
1106 * Support for TX only, at least for now, so accept
1107 * the key and do nothing else. Then mac80211 will
1108 * pass it for TX but we don't have to use it for RX.
1109 */
1110 return 0;
1111 default:
1112 return -EOPNOTSUPP;
1113 }
1114
1115 mutex_lock(&mvm->mutex);
1116
1117 switch (cmd) {
1118 case SET_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001119 if (vif->type == NL80211_IFTYPE_AP && !sta) {
1120 /* GTK on AP interface is a TX-only key, return 0 */
1121 ret = 0;
1122 key->hw_key_idx = STA_KEY_IDX_INVALID;
1123 break;
1124 }
1125
Johannes Berg8ca151b2013-01-24 14:25:36 +01001126 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1127 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1128 if (ret) {
1129 IWL_WARN(mvm, "set key failed\n");
1130 /*
1131 * can't add key for RX, but we don't need it
1132 * in the device for TX so still return 0
1133 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001134 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001135 ret = 0;
1136 }
1137
1138 break;
1139 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001140 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1141 ret = 0;
1142 break;
1143 }
1144
Johannes Berg8ca151b2013-01-24 14:25:36 +01001145 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1146 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1147 break;
1148 default:
1149 ret = -EINVAL;
1150 }
1151
1152 mutex_unlock(&mvm->mutex);
1153 return ret;
1154}
1155
1156static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1157 struct ieee80211_vif *vif,
1158 struct ieee80211_key_conf *keyconf,
1159 struct ieee80211_sta *sta,
1160 u32 iv32, u16 *phase1key)
1161{
1162 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1163
1164 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1165}
1166
1167
1168static int iwl_mvm_roc(struct ieee80211_hw *hw,
1169 struct ieee80211_vif *vif,
1170 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001171 int duration,
1172 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001173{
1174 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1175 struct cfg80211_chan_def chandef;
1176 int ret;
1177
1178 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1179 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1180 return -EINVAL;
1181 }
1182
Ilan Peerd339d5c2013-02-12 09:34:13 +02001183 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1184 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001185
1186 mutex_lock(&mvm->mutex);
1187
1188 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1189 ret = iwl_mvm_phy_ctxt_changed(mvm, &mvm->phy_ctxt_roc,
1190 &chandef, 1, 1);
1191
1192 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02001193 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001194
1195 mutex_unlock(&mvm->mutex);
1196 IWL_DEBUG_MAC80211(mvm, "leave\n");
1197
1198 return ret;
1199}
1200
1201static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1202{
1203 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1204
1205 IWL_DEBUG_MAC80211(mvm, "enter\n");
1206
1207 mutex_lock(&mvm->mutex);
1208 iwl_mvm_stop_p2p_roc(mvm);
1209 mutex_unlock(&mvm->mutex);
1210
1211 IWL_DEBUG_MAC80211(mvm, "leave\n");
1212 return 0;
1213}
1214
1215static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1216 struct ieee80211_chanctx_conf *ctx)
1217{
1218 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1219 struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
1220 int ret;
1221
1222 mutex_lock(&mvm->mutex);
1223
1224 IWL_DEBUG_MAC80211(mvm, "Add PHY context\n");
1225 ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, &ctx->def,
1226 ctx->rx_chains_static,
1227 ctx->rx_chains_dynamic);
1228 mutex_unlock(&mvm->mutex);
1229 return ret;
1230}
1231
1232static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1233 struct ieee80211_chanctx_conf *ctx)
1234{
1235 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1236 struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
1237
1238 mutex_lock(&mvm->mutex);
1239 iwl_mvm_phy_ctxt_remove(mvm, phy_ctxt);
1240 mutex_unlock(&mvm->mutex);
1241}
1242
1243static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1244 struct ieee80211_chanctx_conf *ctx,
1245 u32 changed)
1246{
1247 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1248 struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
1249
1250 mutex_lock(&mvm->mutex);
1251 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1252 ctx->rx_chains_static,
1253 ctx->rx_chains_dynamic);
1254 mutex_unlock(&mvm->mutex);
1255}
1256
1257static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1258 struct ieee80211_vif *vif,
1259 struct ieee80211_chanctx_conf *ctx)
1260{
1261 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1262 struct iwl_mvm_phy_ctxt *phyctx = (void *)ctx->drv_priv;
1263 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1264 int ret;
1265
1266 mutex_lock(&mvm->mutex);
1267
1268 mvmvif->phy_ctxt = phyctx;
1269
1270 switch (vif->type) {
1271 case NL80211_IFTYPE_AP:
1272 /*
1273 * The AP binding flow is handled as part of the start_ap flow
1274 * (in bss_info_changed).
1275 */
1276 ret = 0;
1277 goto out_unlock;
1278 case NL80211_IFTYPE_STATION:
1279 case NL80211_IFTYPE_ADHOC:
1280 case NL80211_IFTYPE_MONITOR:
1281 break;
1282 default:
1283 ret = -EINVAL;
1284 goto out_unlock;
1285 }
1286
1287 ret = iwl_mvm_binding_add_vif(mvm, vif);
1288 if (ret)
1289 goto out_unlock;
1290
1291 /*
1292 * Setting the quota at this stage is only required for monitor
1293 * interfaces. For the other types, the bss_info changed flow
1294 * will handle quota settings.
1295 */
1296 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02001297 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001298 ret = iwl_mvm_update_quotas(mvm, vif);
1299 if (ret)
1300 goto out_remove_binding;
1301 }
1302
1303 goto out_unlock;
1304
1305 out_remove_binding:
1306 iwl_mvm_binding_remove_vif(mvm, vif);
1307 out_unlock:
1308 mutex_unlock(&mvm->mutex);
1309 if (ret)
1310 mvmvif->phy_ctxt = NULL;
1311 return ret;
1312}
1313
1314static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1315 struct ieee80211_vif *vif,
1316 struct ieee80211_chanctx_conf *ctx)
1317{
1318 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1319 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1320
1321 mutex_lock(&mvm->mutex);
1322
1323 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1324
1325 if (vif->type == NL80211_IFTYPE_AP)
1326 goto out_unlock;
1327
Johannes Berg8ca151b2013-01-24 14:25:36 +01001328 switch (vif->type) {
1329 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02001330 mvmvif->monitor_active = false;
1331 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001332 break;
1333 default:
1334 break;
1335 }
1336
Ilan Peer1e1391c2013-03-13 14:52:04 +02001337 iwl_mvm_binding_remove_vif(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001338out_unlock:
1339 mvmvif->phy_ctxt = NULL;
1340 mutex_unlock(&mvm->mutex);
1341}
1342
1343static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1344 struct ieee80211_sta *sta,
1345 bool set)
1346{
1347 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1348 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1349
1350 if (!mvm_sta || !mvm_sta->vif) {
1351 IWL_ERR(mvm, "Station is not associated to a vif\n");
1352 return -EINVAL;
1353 }
1354
1355 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1356}
1357
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +02001358static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw *hw,
1359 struct ieee80211_vif *vif,
1360 enum ieee80211_rssi_event rssi_event)
1361{
1362 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1363
1364 iwl_mvm_bt_rssi_event(mvm, vif, rssi_event);
1365}
1366
Johannes Berg8ca151b2013-01-24 14:25:36 +01001367struct ieee80211_ops iwl_mvm_hw_ops = {
1368 .tx = iwl_mvm_mac_tx,
1369 .ampdu_action = iwl_mvm_mac_ampdu_action,
1370 .start = iwl_mvm_mac_start,
1371 .restart_complete = iwl_mvm_mac_restart_complete,
1372 .stop = iwl_mvm_mac_stop,
1373 .add_interface = iwl_mvm_mac_add_interface,
1374 .remove_interface = iwl_mvm_mac_remove_interface,
1375 .config = iwl_mvm_mac_config,
1376 .configure_filter = iwl_mvm_configure_filter,
1377 .bss_info_changed = iwl_mvm_bss_info_changed,
1378 .hw_scan = iwl_mvm_mac_hw_scan,
1379 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1380 .sta_state = iwl_mvm_mac_sta_state,
1381 .sta_notify = iwl_mvm_mac_sta_notify,
1382 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1383 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1384 .conf_tx = iwl_mvm_mac_conf_tx,
1385 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
1386 .set_key = iwl_mvm_mac_set_key,
1387 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1388 .remain_on_channel = iwl_mvm_roc,
1389 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +02001390 .rssi_callback = iwl_mvm_mac_rssi_callback,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001391
1392 .add_chanctx = iwl_mvm_add_chanctx,
1393 .remove_chanctx = iwl_mvm_remove_chanctx,
1394 .change_chanctx = iwl_mvm_change_chanctx,
1395 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1396 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1397
1398 .start_ap = iwl_mvm_start_ap,
1399 .stop_ap = iwl_mvm_stop_ap,
1400
1401 .set_tim = iwl_mvm_set_tim,
1402
1403#ifdef CONFIG_PM_SLEEP
1404 /* look at d3.c */
1405 .suspend = iwl_mvm_suspend,
1406 .resume = iwl_mvm_resume,
1407 .set_wakeup = iwl_mvm_set_wakeup,
1408 .set_rekey_data = iwl_mvm_set_rekey_data,
1409#if IS_ENABLED(CONFIG_IPV6)
1410 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1411#endif
1412 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1413#endif
1414};