blob: 67c0dfcc7285ffc8854ab5cf7e318db8c21be527 [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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +01009 *
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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +010034 * 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>
Eliad Peller2ee8f022014-01-13 19:07:09 +020069#include <linux/if_arp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010070#include <net/mac80211.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010071#include <net/tcp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010072
73#include "iwl-op-mode.h"
74#include "iwl-io.h"
75#include "mvm.h"
76#include "sta.h"
77#include "time-event.h"
78#include "iwl-eeprom-parse.h"
79#include "fw-api-scan.h"
80#include "iwl-phy-db.h"
David Spinadel507cadf2013-07-31 18:07:21 +030081#include "testmode.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010082
83static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
84 {
85 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030086 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010087 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020088 {
89 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030090 .types = BIT(NL80211_IFTYPE_AP) |
91 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +020092 BIT(NL80211_IFTYPE_P2P_GO),
93 },
94 {
95 .max = 1,
96 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
97 },
Johannes Berg8ca151b2013-01-24 14:25:36 +010098};
99
100static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
101 {
102 .num_different_channels = 1,
103 .max_interfaces = 3,
104 .limits = iwl_mvm_limits,
105 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
106 },
107};
108
Johannes Bergf0c26462013-01-22 20:41:58 +0100109#ifdef CONFIG_PM_SLEEP
110static const struct nl80211_wowlan_tcp_data_token_feature
111iwl_mvm_wowlan_tcp_token_feature = {
112 .min_len = 0,
113 .max_len = 255,
114 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
115};
116
117static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
118 .tok = &iwl_mvm_wowlan_tcp_token_feature,
119 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
120 sizeof(struct ethhdr) -
121 sizeof(struct iphdr) -
122 sizeof(struct tcphdr),
123 .data_interval_max = 65535, /* __le16 in API */
124 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
125 sizeof(struct ethhdr) -
126 sizeof(struct iphdr) -
127 sizeof(struct tcphdr),
128 .seq = true,
129};
130#endif
131
Eliad Peller77736922014-01-14 12:35:49 +0200132#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
Eliad Peller2ee8f022014-01-13 19:07:09 +0200133/*
134 * Use the reserved field to indicate magic values.
135 * these values will only be used internally by the driver,
136 * and won't make it to the fw (reserved will be 0).
137 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
138 * be the vif's ip address. in case there is not a single
139 * ip address (0, or more than 1), this attribute will
140 * be skipped.
141 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
142 * the LSB bytes of the vif's mac address
143 */
144enum {
145 BC_FILTER_MAGIC_NONE = 0,
146 BC_FILTER_MAGIC_IP,
147 BC_FILTER_MAGIC_MAC,
148};
149
Eliad Peller77736922014-01-14 12:35:49 +0200150static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
151 {
152 /* arp */
153 .discard = 0,
154 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
155 .attrs = {
156 {
157 /* frame type - arp, hw type - ethernet */
158 .offset_type =
159 BCAST_FILTER_OFFSET_PAYLOAD_START,
160 .offset = sizeof(rfc1042_header),
161 .val = cpu_to_be32(0x08060001),
162 .mask = cpu_to_be32(0xffffffff),
163 },
Eliad Peller2ee8f022014-01-13 19:07:09 +0200164 {
165 /* arp dest ip */
166 .offset_type =
167 BCAST_FILTER_OFFSET_PAYLOAD_START,
168 .offset = sizeof(rfc1042_header) + 2 +
169 sizeof(struct arphdr) +
170 ETH_ALEN + sizeof(__be32) +
171 ETH_ALEN,
172 .mask = cpu_to_be32(0xffffffff),
173 /* mark it as special field */
174 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
175 },
176 },
177 },
178 {
179 /* dhcp offer bcast */
180 .discard = 0,
181 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
182 .attrs = {
183 {
184 /* udp dest port - 68 (bootp client)*/
185 .offset_type = BCAST_FILTER_OFFSET_IP_END,
186 .offset = offsetof(struct udphdr, dest),
187 .val = cpu_to_be32(0x00440000),
188 .mask = cpu_to_be32(0xffff0000),
189 },
190 {
191 /* dhcp - lsb bytes of client hw address */
192 .offset_type = BCAST_FILTER_OFFSET_IP_END,
193 .offset = 38,
194 .mask = cpu_to_be32(0xffffffff),
195 /* mark it as special field */
196 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
197 },
Eliad Peller77736922014-01-14 12:35:49 +0200198 },
199 },
200 /* last filter must be empty */
201 {},
202};
203#endif
204
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200205static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
206{
207 int i;
208
209 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
210 for (i = 0; i < NUM_PHY_CTX; i++) {
211 mvm->phy_ctxts[i].id = i;
212 mvm->phy_ctxts[i].ref = 0;
213 }
214}
215
David Spinadel20f1a5d2013-08-21 09:14:27 +0300216static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
217{
218 /* we create the 802.11 header and SSID element */
219 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
220 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
221 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
222}
223
Johannes Berg8ca151b2013-01-24 14:25:36 +0100224int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
225{
226 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200227 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100228
229 /* Tell mac80211 our characteristics */
230 hw->flags = IEEE80211_HW_SIGNAL_DBM |
231 IEEE80211_HW_SPECTRUM_MGMT |
232 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
233 IEEE80211_HW_QUEUE_CONTROL |
234 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100235 IEEE80211_HW_SUPPORTS_PS |
236 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100237 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200238 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300239 IEEE80211_HW_CONNECTION_MONITOR |
240 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
Alexander Bondare8e626a2013-10-16 00:21:34 +0200241 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100242
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200243 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200244 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100245 hw->rate_control_algorithm = "iwl-mvm-rs";
246
247 /*
248 * Enable 11w if advertised by firmware and software crypto
249 * is not enabled (as the firmware will interpret some mgmt
250 * packets, so enabling it with software crypto isn't safe)
251 */
252 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
253 !iwlwifi_mod_params.sw_crypto)
254 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
255
Alexander Bondare8e626a2013-10-16 00:21:34 +0200256 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) {
257 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
258 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
259 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
260 }
261
Johannes Berg8ca151b2013-01-24 14:25:36 +0100262 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
263 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200264 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100265
266 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200267 BIT(NL80211_IFTYPE_P2P_CLIENT) |
268 BIT(NL80211_IFTYPE_AP) |
269 BIT(NL80211_IFTYPE_P2P_GO) |
270 BIT(NL80211_IFTYPE_P2P_DEVICE);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100271
Johannes Berg5023d962013-07-31 14:07:43 +0200272 /* IBSS has bugs in older versions */
273 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 8)
274 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
275
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100276 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
277 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
278 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100279
Johannes Berg3e56ead2013-02-15 22:23:18 +0100280 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
281 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
282
Johannes Berg8ca151b2013-01-24 14:25:36 +0100283 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
284 hw->wiphy->n_iface_combinations =
285 ARRAY_SIZE(iwl_mvm_iface_combinations);
286
Ilan Peerc451e6d2013-02-20 08:41:54 +0200287 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100288 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
289
290 /* Extract MAC address */
291 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
292 hw->wiphy->addresses = mvm->addresses;
293 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200294
295 /* Extract additional MAC addresses if available */
296 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
297 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
298
299 for (i = 1; i < num_mac; i++) {
300 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100301 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200302 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100303 hw->wiphy->n_addresses++;
304 }
305
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200306 iwl_mvm_reset_phy_ctxts(mvm);
307
David Spinadel20f1a5d2013-08-21 09:14:27 +0300308 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
309
Johannes Berg8ca151b2013-01-24 14:25:36 +0100310 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
311
312 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
313 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
314 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
315 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
316 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
317 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
318
319 hw->wiphy->hw_version = mvm->trans->hw_id;
320
Alexander Bondarade50652013-04-03 16:28:47 +0300321 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100322 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
323 else
324 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
325
David Spinadel35a000b2013-08-28 09:29:43 +0300326 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
327 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
328 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
329 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
330 /* we create the 802.11 header and zero length SSID IE. */
331 hw->wiphy->max_sched_scan_ie_len =
332 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
333 }
334
Johannes Berg8ca151b2013-01-24 14:25:36 +0100335 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200336 NL80211_FEATURE_P2P_GO_OPPPS |
337 NL80211_FEATURE_LOW_PRIORITY_SCAN;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100338
339 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
340
Max Stepanove36e5432013-08-27 19:56:13 +0300341 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100342 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300343 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100344 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300345 }
346
Johannes Berg8ca151b2013-01-24 14:25:36 +0100347#ifdef CONFIG_PM_SLEEP
348 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
349 mvm->trans->ops->d3_suspend &&
350 mvm->trans->ops->d3_resume &&
351 device_can_wakeup(mvm->trans->dev)) {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200352 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
353 WIPHY_WOWLAN_DISCONNECT |
354 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
355 WIPHY_WOWLAN_RFKILL_RELEASE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100356 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200357 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
358 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
359 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100360
Johannes Berg964dc9e2013-06-03 17:25:34 +0200361 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
362 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
363 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
364 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
365 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100366 }
367#endif
368
Eliad Peller77736922014-01-14 12:35:49 +0200369#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
370 /* assign default bcast filtering configuration */
371 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
372#endif
373
Johannes Berg8ca151b2013-01-24 14:25:36 +0100374 ret = iwl_mvm_leds_init(mvm);
375 if (ret)
376 return ret;
377
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300378 ret = ieee80211_register_hw(mvm->hw);
379 if (ret)
380 iwl_mvm_leds_exit(mvm);
381
382 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100383}
384
385static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
386 struct ieee80211_tx_control *control,
387 struct sk_buff *skb)
388{
389 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100390 struct ieee80211_sta *sta = control->sta;
391 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
392 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100393
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300394 if (iwl_mvm_is_radio_killed(mvm)) {
395 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100396 goto drop;
397 }
398
Ilan Peer398e8c62013-03-13 15:20:35 +0200399 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100400 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
401 goto drop;
402
Johannes Berg3e56ead2013-02-15 22:23:18 +0100403 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
404 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
405 ieee80211_is_mgmt(hdr->frame_control) &&
406 !ieee80211_is_deauth(hdr->frame_control) &&
407 !ieee80211_is_disassoc(hdr->frame_control) &&
408 !ieee80211_is_action(hdr->frame_control)))
409 sta = NULL;
410
411 if (sta) {
412 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100413 goto drop;
414 return;
415 }
416
417 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
418 goto drop;
419 return;
420 drop:
421 ieee80211_free_txskb(hw, skb);
422}
423
424static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
425 struct ieee80211_vif *vif,
426 enum ieee80211_ampdu_mlme_action action,
427 struct ieee80211_sta *sta, u16 tid,
428 u16 *ssn, u8 buf_size)
429{
430 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
431 int ret;
432
433 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
434 sta->addr, tid, action);
435
436 if (!(mvm->nvm_data->sku_cap_11n_enable))
437 return -EACCES;
438
439 mutex_lock(&mvm->mutex);
440
441 switch (action) {
442 case IEEE80211_AMPDU_RX_START:
443 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
444 ret = -EINVAL;
445 break;
446 }
447 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
448 break;
449 case IEEE80211_AMPDU_RX_STOP:
450 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
451 break;
452 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200453 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
454 ret = -EINVAL;
455 break;
456 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100457 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
458 break;
459 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200460 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
461 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100462 case IEEE80211_AMPDU_TX_STOP_FLUSH:
463 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200464 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100465 break;
466 case IEEE80211_AMPDU_TX_OPERATIONAL:
467 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
468 break;
469 default:
470 WARN_ON_ONCE(1);
471 ret = -EINVAL;
472 break;
473 }
474 mutex_unlock(&mvm->mutex);
475
476 return ret;
477}
478
479static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
480 struct ieee80211_vif *vif)
481{
482 struct iwl_mvm *mvm = data;
483 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
484
485 mvmvif->uploaded = false;
486 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
487
488 /* does this make sense at all? */
489 mvmvif->color++;
490
491 spin_lock_bh(&mvm->time_event_lock);
492 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
493 spin_unlock_bh(&mvm->time_event_lock);
494
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200495 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100496}
497
498static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
499{
500 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100501
502 mvm->scan_status = IWL_MVM_SCAN_NONE;
503
504 /* just in case one was running */
505 ieee80211_remain_on_channel_expired(mvm->hw);
506
507 ieee80211_iterate_active_interfaces_atomic(
508 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
509 iwl_mvm_cleanup_iterator, mvm);
510
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200511 mvm->p2p_device_vif = NULL;
512
513 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100514 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
515 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
516
517 ieee80211_wake_queues(mvm->hw);
518
519 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300520 mvm->rx_ba_sessions = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100521}
522
523static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
524{
525 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
526 int ret;
527
528 mutex_lock(&mvm->mutex);
529
530 /* Clean up some internal and mac80211 state on restart */
531 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
532 iwl_mvm_restart_cleanup(mvm);
533
534 ret = iwl_mvm_up(mvm);
535 mutex_unlock(&mvm->mutex);
536
537 return ret;
538}
539
540static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
541{
542 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
543 int ret;
544
545 mutex_lock(&mvm->mutex);
546
547 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
548 ret = iwl_mvm_update_quotas(mvm, NULL);
549 if (ret)
550 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
551 ret);
552
553 mutex_unlock(&mvm->mutex);
554}
555
556static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
557{
558 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
559
560 flush_work(&mvm->async_handlers_wk);
561
562 mutex_lock(&mvm->mutex);
563 /* async_handlers_wk is now blocked */
564
565 /*
566 * The work item could be running or queued if the
567 * ROC time event stops just as we get here.
568 */
569 cancel_work_sync(&mvm->roc_done_wk);
570
571 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100572
573 iwl_mvm_async_handlers_purge(mvm);
574 /* async_handlers_list is empty and will stay empty: HW is stopped */
575
576 /* the fw is stopped, the aux sta is dead: clean up driver state */
577 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
578
579 mutex_unlock(&mvm->mutex);
580
581 /*
582 * The worker might have been waiting for the mutex, let it run and
583 * discover that its list is now empty.
584 */
585 cancel_work_sync(&mvm->async_handlers_wk);
586}
587
Johannes Berg8ca151b2013-01-24 14:25:36 +0100588static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
589 struct ieee80211_vif *vif)
590{
591 struct iwl_mvm *mvm = data;
592
593 iwl_mvm_power_update_mode(mvm, vif);
594}
595
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200596static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
597{
598 u16 i;
599
600 lockdep_assert_held(&mvm->mutex);
601
602 for (i = 0; i < NUM_PHY_CTX; i++)
603 if (!mvm->phy_ctxts[i].ref)
604 return &mvm->phy_ctxts[i];
605
606 IWL_ERR(mvm, "No available PHY context\n");
607 return NULL;
608}
609
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +0200610static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
611 s8 tx_power)
612{
613 /* FW is in charge of regulatory enforcement */
614 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
615 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
616 .pwr_restriction = cpu_to_le16(tx_power),
617 };
618
619 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
620 sizeof(reduce_txpwr_cmd),
621 &reduce_txpwr_cmd);
622}
623
Johannes Berg8ca151b2013-01-24 14:25:36 +0100624static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
625 struct ieee80211_vif *vif)
626{
627 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
628 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
629 int ret;
630
631 /*
632 * Not much to do here. The stack will not allow interface
633 * types or combinations that we didn't advertise, so we
634 * don't really have to check the types.
635 */
636
637 mutex_lock(&mvm->mutex);
638
Eliad Pellere89044d2013-07-16 17:33:26 +0300639 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100640 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
641 if (ret)
642 goto out_unlock;
643
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300644 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +0300645 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
646 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +0300647
648 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100649 * The AP binding flow can be done only after the beacon
650 * template is configured (which happens only in the mac80211
651 * start_ap() flow), and adding the broadcast station can happen
652 * only after the binding.
653 * In addition, since modifying the MAC before adding a bcast
654 * station is not allowed by the FW, delay the adding of MAC context to
655 * the point where we can also add the bcast station.
656 * In short: there's not much we can do at this point, other than
657 * allocating resources :)
658 */
Johannes Berg5023d962013-07-31 14:07:43 +0200659 if (vif->type == NL80211_IFTYPE_AP ||
660 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100661 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
662 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
663 qmask);
664 if (ret) {
665 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
666 goto out_release;
667 }
668
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +0300669 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100670 goto out_unlock;
671 }
672
Johannes Berg8ca151b2013-01-24 14:25:36 +0100673 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
674 if (ret)
675 goto out_release;
676
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300677 iwl_mvm_power_disable(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100678
Hila Gonen7df15b12012-12-12 11:16:19 +0200679 /* beacon filtering */
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300680 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
681 if (ret)
682 goto out_remove_mac;
683
Hila Gonen7df15b12012-12-12 11:16:19 +0200684 if (!mvm->bf_allowed_vif &&
Hila Gonen5dca7c22013-07-16 11:15:35 +0300685 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
686 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
Hila Gonen7df15b12012-12-12 11:16:19 +0200687 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300688 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
689 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +0200690 }
691
Johannes Berg8ca151b2013-01-24 14:25:36 +0100692 /*
693 * P2P_DEVICE interface does not have a channel context assigned to it,
694 * so a dedicated PHY context is allocated to it and the corresponding
695 * MAC context is bound to it at this stage.
696 */
697 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100698
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200699 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
700 if (!mvmvif->phy_ctxt) {
701 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300702 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200703 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100704
Ilan Peer53a9d612013-04-28 11:55:08 +0300705 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100706 ret = iwl_mvm_binding_add_vif(mvm, vif);
707 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +0300708 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100709
710 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
711 if (ret)
712 goto out_unbind;
713
714 /* Save a pointer to p2p device vif, so it can later be used to
715 * update the p2p device MAC when a GO is started/stopped */
716 mvm->p2p_device_vif = vif;
717 }
718
Johannes Berg63494372013-03-26 10:47:53 +0100719 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100720 goto out_unlock;
721
722 out_unbind:
723 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +0300724 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200725 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300726 out_free_bf:
727 if (mvm->bf_allowed_vif == mvmvif) {
728 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300729 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
730 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300731 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100732 out_remove_mac:
733 mvmvif->phy_ctxt = NULL;
734 iwl_mvm_mac_ctxt_remove(mvm, vif);
735 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200736 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
737 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300738
739 /* TODO: remove this when legacy PM will be discarded */
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300740 ieee80211_iterate_active_interfaces(
741 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
742 iwl_mvm_power_update_iterator, mvm);
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300743
Johannes Berg8ca151b2013-01-24 14:25:36 +0100744 iwl_mvm_mac_ctxt_release(mvm, vif);
745 out_unlock:
746 mutex_unlock(&mvm->mutex);
747
748 return ret;
749}
750
Johannes Berg38a12b52013-02-22 14:07:56 +0100751static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
752 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100753{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100754 u32 tfd_msk = 0, ac;
755
756 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
757 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
758 tfd_msk |= BIT(vif->hw_queue[ac]);
759
760 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
761 tfd_msk |= BIT(vif->cab_queue);
762
763 if (tfd_msk) {
764 mutex_lock(&mvm->mutex);
765 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
766 mutex_unlock(&mvm->mutex);
767 }
768
769 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
770 /*
771 * Flush the ROC worker which will flush the OFFCHANNEL queue.
772 * We assume here that all the packets sent to the OFFCHANNEL
773 * queue are sent in ROC session.
774 */
775 flush_work(&mvm->roc_done_wk);
776 } else {
777 /*
778 * By now, all the AC queues are empty. The AGG queues are
779 * empty too. We already got all the Tx responses for all the
780 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +0300781 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100782 */
783 flush_work(&mvm->sta_drained_wk);
784 }
Johannes Berg38a12b52013-02-22 14:07:56 +0100785}
786
787static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
788 struct ieee80211_vif *vif)
789{
790 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
791 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
792
793 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100794
795 mutex_lock(&mvm->mutex);
796
Hila Gonen7df15b12012-12-12 11:16:19 +0200797 if (mvm->bf_allowed_vif == mvmvif) {
798 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300799 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
800 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +0200801 }
802
Johannes Berg63494372013-03-26 10:47:53 +0100803 iwl_mvm_vif_dbgfs_clean(mvm, vif);
804
Johannes Berg8ca151b2013-01-24 14:25:36 +0100805 /*
806 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +0100807 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100808 */
Johannes Berg5023d962013-07-31 14:07:43 +0200809 if (vif->type == NL80211_IFTYPE_AP ||
810 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +0300811#ifdef CONFIG_NL80211_TESTMODE
812 if (vif == mvm->noa_vif) {
813 mvm->noa_vif = NULL;
814 mvm->noa_duration = 0;
815 }
816#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100817 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
818 goto out_release;
819 }
820
821 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
822 mvm->p2p_device_vif = NULL;
823 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
824 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200825 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100826 mvmvif->phy_ctxt = NULL;
827 }
828
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200829 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100830 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300831
832 /* TODO: remove this when legacy PM will be discarded */
833 ieee80211_iterate_active_interfaces(
834 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
835 iwl_mvm_power_update_iterator, mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100836
837 iwl_mvm_mac_ctxt_remove(mvm, vif);
838
839out_release:
840 iwl_mvm_mac_ctxt_release(mvm, vif);
841 mutex_unlock(&mvm->mutex);
842}
843
844static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
845{
846 return 0;
847}
848
Eliad Pellere59647e2013-11-28 14:08:50 +0200849struct iwl_mvm_mc_iter_data {
850 struct iwl_mvm *mvm;
851 int port_id;
852};
853
854static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
855 struct ieee80211_vif *vif)
856{
857 struct iwl_mvm_mc_iter_data *data = _data;
858 struct iwl_mvm *mvm = data->mvm;
859 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
860 int ret, len;
861
862 /* if we don't have free ports, mcast frames will be dropped */
863 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
864 return;
865
866 if (vif->type != NL80211_IFTYPE_STATION ||
867 !vif->bss_conf.assoc)
868 return;
869
870 cmd->port_id = data->port_id++;
871 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
872 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
873
874 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd);
875 if (ret)
876 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
877}
878
879static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
880{
881 struct iwl_mvm_mc_iter_data iter_data = {
882 .mvm = mvm,
883 };
884
885 lockdep_assert_held(&mvm->mutex);
886
887 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
888 return;
889
890 ieee80211_iterate_active_interfaces(
891 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
892 iwl_mvm_mc_iface_iterator, &iter_data);
893}
894
895static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
896 struct netdev_hw_addr_list *mc_list)
897{
898 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
899 struct iwl_mcast_filter_cmd *cmd;
900 struct netdev_hw_addr *addr;
901 int addr_count = netdev_hw_addr_list_count(mc_list);
902 bool pass_all = false;
903 int len;
904
905 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
906 pass_all = true;
907 addr_count = 0;
908 }
909
910 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
911 cmd = kzalloc(len, GFP_ATOMIC);
912 if (!cmd)
913 return 0;
914
915 if (pass_all) {
916 cmd->pass_all = 1;
917 return (u64)(unsigned long)cmd;
918 }
919
920 netdev_hw_addr_list_for_each(addr, mc_list) {
921 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
922 cmd->count, addr->addr);
923 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
924 addr->addr, ETH_ALEN);
925 cmd->count++;
926 }
927
928 return (u64)(unsigned long)cmd;
929}
930
Johannes Berg8ca151b2013-01-24 14:25:36 +0100931static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
932 unsigned int changed_flags,
933 unsigned int *total_flags,
934 u64 multicast)
935{
Eliad Pellere59647e2013-11-28 14:08:50 +0200936 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
937 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
938
939 mutex_lock(&mvm->mutex);
940
941 /* replace previous configuration */
942 kfree(mvm->mcast_filter_cmd);
943 mvm->mcast_filter_cmd = cmd;
944
945 if (!cmd)
946 goto out;
947
948 iwl_mvm_recalc_multicast(mvm);
949out:
950 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100951 *total_flags = 0;
952}
953
Eliad Pellerc87163b2014-01-08 10:11:11 +0200954#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
955struct iwl_bcast_iter_data {
956 struct iwl_mvm *mvm;
957 struct iwl_bcast_filter_cmd *cmd;
958 u8 current_filter;
959};
960
961static void
962iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
963 const struct iwl_fw_bcast_filter *in_filter,
964 struct iwl_fw_bcast_filter *out_filter)
965{
966 struct iwl_fw_bcast_filter_attr *attr;
967 int i;
968
969 memcpy(out_filter, in_filter, sizeof(*out_filter));
970
971 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
972 attr = &out_filter->attrs[i];
973
974 if (!attr->mask)
975 break;
976
Eliad Peller2ee8f022014-01-13 19:07:09 +0200977 switch (attr->reserved1) {
978 case cpu_to_le16(BC_FILTER_MAGIC_IP):
979 if (vif->bss_conf.arp_addr_cnt != 1) {
980 attr->mask = 0;
981 continue;
982 }
983
984 attr->val = vif->bss_conf.arp_addr_list[0];
985 break;
986 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
987 attr->val = *(__be32 *)&vif->addr[2];
988 break;
989 default:
990 break;
991 }
992 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +0200993 out_filter->num_attrs++;
994 }
995}
996
997static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
998 struct ieee80211_vif *vif)
999{
1000 struct iwl_bcast_iter_data *data = _data;
1001 struct iwl_mvm *mvm = data->mvm;
1002 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1003 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1004 struct iwl_fw_bcast_mac *bcast_mac;
1005 int i;
1006
1007 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1008 return;
1009
1010 bcast_mac = &cmd->macs[mvmvif->id];
1011
1012 /* enable filtering only for associated stations */
1013 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1014 return;
1015
1016 bcast_mac->default_discard = 1;
1017
1018 /* copy all configured filters */
1019 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1020 /*
1021 * Make sure we don't exceed our filters limit.
1022 * if there is still a valid filter to be configured,
1023 * be on the safe side and just allow bcast for this mac.
1024 */
1025 if (WARN_ON_ONCE(data->current_filter >=
1026 ARRAY_SIZE(cmd->filters))) {
1027 bcast_mac->default_discard = 0;
1028 bcast_mac->attached_filters = 0;
1029 break;
1030 }
1031
1032 iwl_mvm_set_bcast_filter(vif,
1033 &mvm->bcast_filters[i],
1034 &cmd->filters[data->current_filter]);
1035
1036 /* skip current filter if it contains no attributes */
1037 if (!cmd->filters[data->current_filter].num_attrs)
1038 continue;
1039
1040 /* attach the filter to current mac */
1041 bcast_mac->attached_filters |=
1042 cpu_to_le16(BIT(data->current_filter));
1043
1044 data->current_filter++;
1045 }
1046}
1047
Eliad Pellerde06a592014-01-08 10:11:12 +02001048bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1049 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001050{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001051 struct iwl_bcast_iter_data iter_data = {
1052 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001053 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001054 };
1055
Eliad Pellerde06a592014-01-08 10:11:12 +02001056 memset(cmd, 0, sizeof(*cmd));
1057 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1058 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1059
1060#ifdef CONFIG_IWLWIFI_DEBUGFS
1061 /* use debugfs filters/macs if override is configured */
1062 if (mvm->dbgfs_bcast_filtering.override) {
1063 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1064 sizeof(cmd->filters));
1065 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1066 sizeof(cmd->macs));
1067 return true;
1068 }
1069#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001070
1071 /* if no filters are configured, do nothing */
1072 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001073 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001074
1075 /* configure and attach these filters for each associated sta vif */
1076 ieee80211_iterate_active_interfaces(
1077 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1078 iwl_mvm_bcast_filter_iterator, &iter_data);
1079
Eliad Pellerde06a592014-01-08 10:11:12 +02001080 return true;
1081}
1082static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1083 struct ieee80211_vif *vif)
1084{
1085 struct iwl_bcast_filter_cmd cmd;
1086
1087 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1088 return 0;
1089
1090 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1091 return 0;
1092
Eliad Pellerc87163b2014-01-08 10:11:11 +02001093 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC,
1094 sizeof(cmd), &cmd);
1095}
1096#else
1097static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1098 struct ieee80211_vif *vif)
1099{
1100 return 0;
1101}
1102#endif
1103
Johannes Berg8ca151b2013-01-24 14:25:36 +01001104static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1105 struct ieee80211_vif *vif,
1106 struct ieee80211_bss_conf *bss_conf,
1107 u32 changes)
1108{
1109 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1110 int ret;
1111
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001112 /*
1113 * Re-calculate the tsf id, as the master-slave relations depend on the
1114 * beacon interval, which was not known when the station interface was
1115 * added.
1116 */
1117 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1118 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1119
Johannes Berg8ca151b2013-01-24 14:25:36 +01001120 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1121 if (ret)
1122 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1123
1124 if (changes & BSS_CHANGED_ASSOC) {
1125 if (bss_conf->assoc) {
1126 /* add quota for this interface */
1127 ret = iwl_mvm_update_quotas(mvm, vif);
1128 if (ret) {
1129 IWL_ERR(mvm, "failed to update quotas\n");
1130 return;
1131 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001132
1133 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1134 &mvm->status)) {
1135 /*
1136 * If we're restarting then the firmware will
1137 * obviously have lost synchronisation with
1138 * the AP. It will attempt to synchronise by
1139 * itself, but we can make it more reliable by
1140 * scheduling a session protection time event.
1141 *
1142 * The firmware needs to receive a beacon to
1143 * catch up with synchronisation, use 110% of
1144 * the beacon interval.
1145 *
1146 * Set a large maximum delay to allow for more
1147 * than a single interface.
1148 */
1149 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1150 iwl_mvm_protect_session(mvm, vif, dur, dur,
1151 5 * dur);
1152 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001153
1154 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001155 iwl_mvm_power_vif_assoc(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001156 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001157 /*
1158 * If update fails - SF might be running in associated
1159 * mode while disassociated - which is forbidden.
1160 */
1161 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1162 "Failed to update SF upon disassociation\n");
1163
Johannes Berg8ca151b2013-01-24 14:25:36 +01001164 /* remove AP station now that the MAC is unassoc */
1165 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1166 if (ret)
1167 IWL_ERR(mvm, "failed to remove AP station\n");
1168 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1169 /* remove quota for this interface */
1170 ret = iwl_mvm_update_quotas(mvm, NULL);
1171 if (ret)
1172 IWL_ERR(mvm, "failed to update quotas\n");
1173 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001174
Eliad Pellere59647e2013-11-28 14:08:50 +02001175 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02001176 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02001177
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001178 /* reset rssi values */
1179 mvmvif->bf_data.ave_beacon_signal = 0;
1180
Alexander Bondare8e626a2013-10-16 00:21:34 +02001181 if (!(mvm->fw->ucode_capa.flags &
1182 IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) {
Alexander Bondare811ada2013-03-10 15:29:44 +02001183 /* Workaround for FW bug, otherwise FW disables device
1184 * power save upon disassociation
1185 */
1186 ret = iwl_mvm_power_update_mode(mvm, vif);
1187 if (ret)
1188 IWL_ERR(mvm, "failed to update power mode\n");
1189 }
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001190 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001191 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1192 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03001193 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001194 /*
1195 * We received a beacon _after_ association so
1196 * remove the session protection.
1197 */
1198 iwl_mvm_remove_time_event(mvm, mvmvif,
1199 &mvmvif->time_event_data);
Alexander Bondar51498cf62013-09-02 17:10:14 +03001200 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1201 BSS_CHANGED_QOS)) {
Alexander Bondar4bf881f2013-05-29 10:19:50 +03001202 ret = iwl_mvm_power_update_mode(mvm, vif);
1203 if (ret)
1204 IWL_ERR(mvm, "failed to update power mode\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001205 }
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03001206 if (changes & BSS_CHANGED_TXPOWER) {
1207 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1208 bss_conf->txpower);
1209 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1210 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001211
1212 if (changes & BSS_CHANGED_CQM) {
1213 IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
1214 /* reset cqm events tracking */
1215 mvmvif->bf_data.last_cqm_event = 0;
1216 ret = iwl_mvm_update_beacon_filter(mvm, vif);
1217 if (ret)
1218 IWL_ERR(mvm, "failed to update CQM thresholds\n");
1219 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02001220
1221 if (changes & BSS_CHANGED_ARP_FILTER) {
1222 IWL_DEBUG_MAC80211(mvm, "arp filter changed");
1223 iwl_mvm_configure_bcast_filter(mvm, vif);
1224 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001225}
1226
Johannes Berg5023d962013-07-31 14:07:43 +02001227static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1228 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001229{
1230 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1231 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1232 int ret;
1233
1234 mutex_lock(&mvm->mutex);
1235
1236 /* Send the beacon template */
1237 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1238 if (ret)
1239 goto out_unlock;
1240
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001241 /*
1242 * Re-calculate the tsf id, as the master-slave relations depend on the
1243 * beacon interval, which was not known when the AP interface was added.
1244 */
1245 if (vif->type == NL80211_IFTYPE_AP)
1246 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1247
Johannes Berg8ca151b2013-01-24 14:25:36 +01001248 /* Add the mac context */
1249 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1250 if (ret)
1251 goto out_unlock;
1252
1253 /* Perform the binding */
1254 ret = iwl_mvm_binding_add_vif(mvm, vif);
1255 if (ret)
1256 goto out_remove;
1257
Johannes Berg5023d962013-07-31 14:07:43 +02001258 mvmvif->ap_ibss_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001259
1260 /* Send the bcast station. At this stage the TBTT and DTIM time events
1261 * are added and applied to the scheduler */
1262 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1263 if (ret)
1264 goto out_unbind;
1265
Ilan Peer5691e212013-12-31 21:05:50 +02001266 /* must be set before quota calculations */
1267 mvmvif->ap_ibss_active = true;
1268
Ilan Peera11e1442013-12-31 21:19:55 +02001269 /* power updated needs to be done before quotas */
1270 mvm->bound_vif_cnt++;
1271 iwl_mvm_power_update_binding(mvm, vif, true);
1272
Johannes Berg8ca151b2013-01-24 14:25:36 +01001273 ret = iwl_mvm_update_quotas(mvm, vif);
1274 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02001275 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001276
Johannes Berg5023d962013-07-31 14:07:43 +02001277 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001278 if (vif->p2p && mvm->p2p_device_vif)
1279 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1280
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001281 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001282
Johannes Berg8ca151b2013-01-24 14:25:36 +01001283 mutex_unlock(&mvm->mutex);
1284 return 0;
1285
Ilan Peera11e1442013-12-31 21:19:55 +02001286out_quota_failed:
1287 mvm->bound_vif_cnt--;
1288 iwl_mvm_power_update_binding(mvm, vif, false);
Ilan Peer5691e212013-12-31 21:05:50 +02001289 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001290 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1291out_unbind:
1292 iwl_mvm_binding_remove_vif(mvm, vif);
1293out_remove:
1294 iwl_mvm_mac_ctxt_remove(mvm, vif);
1295out_unlock:
1296 mutex_unlock(&mvm->mutex);
1297 return ret;
1298}
1299
Johannes Berg5023d962013-07-31 14:07:43 +02001300static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1301 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001302{
1303 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1304 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1305
Johannes Berg38a12b52013-02-22 14:07:56 +01001306 iwl_mvm_prepare_mac_removal(mvm, vif);
1307
Johannes Berg8ca151b2013-01-24 14:25:36 +01001308 mutex_lock(&mvm->mutex);
1309
Johannes Berg5023d962013-07-31 14:07:43 +02001310 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001311
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001312 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001313
Johannes Berg5023d962013-07-31 14:07:43 +02001314 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001315 if (vif->p2p && mvm->p2p_device_vif)
1316 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1317
1318 iwl_mvm_update_quotas(mvm, NULL);
1319 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1320 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001321
1322 mvm->bound_vif_cnt--;
1323 iwl_mvm_power_update_binding(mvm, vif, false);
1324
Johannes Berg8ca151b2013-01-24 14:25:36 +01001325 iwl_mvm_mac_ctxt_remove(mvm, vif);
1326
1327 mutex_unlock(&mvm->mutex);
1328}
1329
Johannes Berg5023d962013-07-31 14:07:43 +02001330static void
1331iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1332 struct ieee80211_vif *vif,
1333 struct ieee80211_bss_conf *bss_conf,
1334 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001335{
Ilan Peerbe2056f2013-12-04 16:47:14 +02001336 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02001337 enum ieee80211_bss_change ht_change = BSS_CHANGED_ERP_CTS_PROT |
1338 BSS_CHANGED_HT |
1339 BSS_CHANGED_BANDWIDTH;
1340 int ret;
1341
Ilan Peerbe2056f2013-12-04 16:47:14 +02001342 /* Changes will be applied when the AP/IBSS is started */
1343 if (!mvmvif->ap_ibss_active)
1344 return;
1345
Avri Altman8a5e3662013-11-12 19:16:03 +02001346 if (changes & ht_change) {
1347 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1348 if (ret)
1349 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1350 }
1351
Johannes Berg8ca151b2013-01-24 14:25:36 +01001352 /* Need to send a new beacon template to the FW */
1353 if (changes & BSS_CHANGED_BEACON) {
1354 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1355 IWL_WARN(mvm, "Failed updating beacon data\n");
1356 }
1357}
1358
1359static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1360 struct ieee80211_vif *vif,
1361 struct ieee80211_bss_conf *bss_conf,
1362 u32 changes)
1363{
1364 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1365
1366 mutex_lock(&mvm->mutex);
1367
1368 switch (vif->type) {
1369 case NL80211_IFTYPE_STATION:
1370 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1371 break;
1372 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001373 case NL80211_IFTYPE_ADHOC:
1374 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001375 break;
1376 default:
1377 /* shouldn't happen */
1378 WARN_ON_ONCE(1);
1379 }
1380
1381 mutex_unlock(&mvm->mutex);
1382}
1383
1384static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1385 struct ieee80211_vif *vif,
1386 struct cfg80211_scan_request *req)
1387{
1388 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1389 int ret;
1390
1391 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
1392 return -EINVAL;
1393
1394 mutex_lock(&mvm->mutex);
1395
1396 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
1397 ret = iwl_mvm_scan_request(mvm, vif, req);
1398 else
1399 ret = -EBUSY;
1400
1401 mutex_unlock(&mvm->mutex);
1402
1403 return ret;
1404}
1405
1406static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1407 struct ieee80211_vif *vif)
1408{
1409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1410
1411 mutex_lock(&mvm->mutex);
1412
1413 iwl_mvm_cancel_scan(mvm);
1414
1415 mutex_unlock(&mvm->mutex);
1416}
1417
1418static void
1419iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01001420 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001421 int num_frames,
1422 enum ieee80211_frame_release_type reason,
1423 bool more_data)
1424{
1425 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001426
Johannes Berg3e56ead2013-02-15 22:23:18 +01001427 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001428
Johannes Berg3e56ead2013-02-15 22:23:18 +01001429 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1430 tids, more_data, false);
1431}
1432
1433static void
1434iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1435 struct ieee80211_sta *sta, u16 tids,
1436 int num_frames,
1437 enum ieee80211_frame_release_type reason,
1438 bool more_data)
1439{
1440 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1441
1442 /* Called when we need to transmit (a) frame(s) from agg queue */
1443
1444 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1445 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001446}
1447
1448static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1449 struct ieee80211_vif *vif,
1450 enum sta_notify_cmd cmd,
1451 struct ieee80211_sta *sta)
1452{
1453 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01001454 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001455 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001456
1457 switch (cmd) {
1458 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001459 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001460 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001461 spin_lock_bh(&mvmsta->lock);
1462 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1463 struct iwl_mvm_tid_data *tid_data;
1464
1465 tid_data = &mvmsta->tid_data[tid];
1466 if (tid_data->state != IWL_AGG_ON &&
1467 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1468 continue;
1469 if (iwl_mvm_tid_queued(tid_data) == 0)
1470 continue;
1471 ieee80211_sta_set_buffered(sta, tid, true);
1472 }
1473 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001474 /*
1475 * The fw updates the STA to be asleep. Tx packets on the Tx
1476 * queues to this station will not be transmitted. The fw will
1477 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1478 */
1479 break;
1480 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001481 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001482 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01001483 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001484 break;
1485 default:
1486 break;
1487 }
1488}
1489
Johannes Berg1ddbbb02013-12-04 22:39:17 +01001490static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1491 struct ieee80211_vif *vif,
1492 struct ieee80211_sta *sta)
1493{
1494 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1495 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1496
1497 /*
1498 * This is called before mac80211 does RCU synchronisation,
1499 * so here we already invalidate our internal RCU-protected
1500 * station pointer. The rest of the code will thus no longer
1501 * be able to find the station this way, and we don't rely
1502 * on further RCU synchronisation after the sta_state()
1503 * callback deleted the station.
1504 */
1505 mutex_lock(&mvm->mutex);
1506 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1507 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1508 ERR_PTR(-ENOENT));
1509 mutex_unlock(&mvm->mutex);
1510}
1511
Johannes Berg8ca151b2013-01-24 14:25:36 +01001512static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1513 struct ieee80211_vif *vif,
1514 struct ieee80211_sta *sta,
1515 enum ieee80211_sta_state old_state,
1516 enum ieee80211_sta_state new_state)
1517{
1518 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1519 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1520 int ret;
1521
1522 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1523 sta->addr, old_state, new_state);
1524
1525 /* this would be a mac80211 bug ... but don't crash */
1526 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1527 return -EINVAL;
1528
1529 /* if a STA is being removed, reuse its ID */
1530 flush_work(&mvm->sta_drained_wk);
1531
1532 mutex_lock(&mvm->mutex);
1533 if (old_state == IEEE80211_STA_NOTEXIST &&
1534 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02001535 /*
1536 * Firmware bug - it'll crash if the beacon interval is less
1537 * than 16. We can't avoid connecting at all, so refuse the
1538 * station state change, this will cause mac80211 to abandon
1539 * attempts to connect to this AP, and eventually wpa_s will
1540 * blacklist the AP...
1541 */
1542 if (vif->type == NL80211_IFTYPE_STATION &&
1543 vif->bss_conf.beacon_int < 16) {
1544 IWL_ERR(mvm,
1545 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1546 sta->addr, vif->bss_conf.beacon_int);
1547 ret = -EINVAL;
1548 goto out_unlock;
1549 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001550 ret = iwl_mvm_add_sta(mvm, vif, sta);
1551 } else if (old_state == IEEE80211_STA_NONE &&
1552 new_state == IEEE80211_STA_AUTH) {
1553 ret = 0;
1554 } else if (old_state == IEEE80211_STA_AUTH &&
1555 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01001556 ret = iwl_mvm_update_sta(mvm, vif, sta);
1557 if (ret == 0)
1558 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02001559 mvmvif->phy_ctxt->channel->band,
1560 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001561 } else if (old_state == IEEE80211_STA_ASSOC &&
1562 new_state == IEEE80211_STA_AUTHORIZED) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001563 /* enable beacon filtering */
1564 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001565 ret = 0;
1566 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1567 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001568 /* disable beacon filtering */
1569 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001570 ret = 0;
1571 } else if (old_state == IEEE80211_STA_ASSOC &&
1572 new_state == IEEE80211_STA_AUTH) {
1573 ret = 0;
1574 } else if (old_state == IEEE80211_STA_AUTH &&
1575 new_state == IEEE80211_STA_NONE) {
1576 ret = 0;
1577 } else if (old_state == IEEE80211_STA_NONE &&
1578 new_state == IEEE80211_STA_NOTEXIST) {
1579 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1580 } else {
1581 ret = -EIO;
1582 }
Johannes Berg48bc1302013-07-04 15:55:29 +02001583 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001584 mutex_unlock(&mvm->mutex);
1585
1586 return ret;
1587}
1588
1589static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1590{
1591 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1592
1593 mvm->rts_threshold = value;
1594
1595 return 0;
1596}
1597
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001598static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1599 struct ieee80211_vif *vif,
1600 struct ieee80211_sta *sta, u32 changed)
1601{
1602 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1603
1604 if (vif->type == NL80211_IFTYPE_STATION &&
1605 changed & IEEE80211_RC_NSS_CHANGED)
1606 iwl_mvm_sf_update(mvm, vif, false);
1607}
1608
Johannes Berg8ca151b2013-01-24 14:25:36 +01001609static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1610 struct ieee80211_vif *vif, u16 ac,
1611 const struct ieee80211_tx_queue_params *params)
1612{
1613 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1614 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1615
1616 mvmvif->queue_params[ac] = *params;
1617
1618 /*
1619 * No need to update right away, we'll get BSS_CHANGED_QOS
1620 * The exception is P2P_DEVICE interface which needs immediate update.
1621 */
1622 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1623 int ret;
1624
1625 mutex_lock(&mvm->mutex);
1626 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1627 mutex_unlock(&mvm->mutex);
1628 return ret;
1629 }
1630 return 0;
1631}
1632
1633static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1634 struct ieee80211_vif *vif)
1635{
1636 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1637 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1638 200 + vif->bss_conf.beacon_int);
1639 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1640 100 + vif->bss_conf.beacon_int);
1641
1642 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1643 return;
1644
1645 mutex_lock(&mvm->mutex);
1646 /* Try really hard to protect the session and hear a beacon */
Johannes Berg016d27e2013-05-03 11:16:15 +02001647 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001648 mutex_unlock(&mvm->mutex);
1649}
1650
David Spinadel35a000b2013-08-28 09:29:43 +03001651static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1652 struct ieee80211_vif *vif,
1653 struct cfg80211_sched_scan_request *req,
1654 struct ieee80211_sched_scan_ies *ies)
1655{
1656 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1657 int ret;
1658
1659 mutex_lock(&mvm->mutex);
1660
1661 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
1662 IWL_DEBUG_SCAN(mvm,
1663 "SCHED SCAN request during internal scan - abort\n");
1664 ret = -EBUSY;
1665 goto out;
1666 }
1667
1668 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1669
1670 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1671 if (ret)
1672 goto err;
1673
1674 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1675 if (ret)
1676 goto err;
1677
1678 ret = iwl_mvm_sched_scan_start(mvm, req);
1679 if (!ret)
1680 goto out;
1681err:
1682 mvm->scan_status = IWL_MVM_SCAN_NONE;
1683out:
1684 mutex_unlock(&mvm->mutex);
1685 return ret;
1686}
1687
1688static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1689 struct ieee80211_vif *vif)
1690{
1691 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1692
1693 mutex_lock(&mvm->mutex);
1694 iwl_mvm_sched_scan_stop(mvm);
1695 mutex_unlock(&mvm->mutex);
1696}
1697
Johannes Berg8ca151b2013-01-24 14:25:36 +01001698static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1699 enum set_key_cmd cmd,
1700 struct ieee80211_vif *vif,
1701 struct ieee80211_sta *sta,
1702 struct ieee80211_key_conf *key)
1703{
1704 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1705 int ret;
1706
1707 if (iwlwifi_mod_params.sw_crypto) {
1708 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1709 return -EOPNOTSUPP;
1710 }
1711
1712 switch (key->cipher) {
1713 case WLAN_CIPHER_SUITE_TKIP:
1714 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1715 /* fall-through */
1716 case WLAN_CIPHER_SUITE_CCMP:
1717 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1718 break;
1719 case WLAN_CIPHER_SUITE_AES_CMAC:
1720 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1721 break;
1722 case WLAN_CIPHER_SUITE_WEP40:
1723 case WLAN_CIPHER_SUITE_WEP104:
1724 /*
1725 * Support for TX only, at least for now, so accept
1726 * the key and do nothing else. Then mac80211 will
1727 * pass it for TX but we don't have to use it for RX.
1728 */
1729 return 0;
1730 default:
Max Stepanove36e5432013-08-27 19:56:13 +03001731 /* currently FW supports only one optional cipher scheme */
1732 if (hw->n_cipher_schemes &&
1733 hw->cipher_schemes->cipher == key->cipher)
1734 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
1735 else
1736 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001737 }
1738
1739 mutex_lock(&mvm->mutex);
1740
1741 switch (cmd) {
1742 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02001743 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1744 vif->type == NL80211_IFTYPE_AP) && !sta) {
1745 /*
1746 * GTK on AP interface is a TX-only key, return 0;
1747 * on IBSS they're per-station and because we're lazy
1748 * we don't support them for RX, so do the same.
1749 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001750 ret = 0;
1751 key->hw_key_idx = STA_KEY_IDX_INVALID;
1752 break;
1753 }
1754
Johannes Berg8ca151b2013-01-24 14:25:36 +01001755 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1756 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1757 if (ret) {
1758 IWL_WARN(mvm, "set key failed\n");
1759 /*
1760 * can't add key for RX, but we don't need it
1761 * in the device for TX so still return 0
1762 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001763 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001764 ret = 0;
1765 }
1766
1767 break;
1768 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001769 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1770 ret = 0;
1771 break;
1772 }
1773
Johannes Berg8ca151b2013-01-24 14:25:36 +01001774 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1775 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1776 break;
1777 default:
1778 ret = -EINVAL;
1779 }
1780
1781 mutex_unlock(&mvm->mutex);
1782 return ret;
1783}
1784
1785static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1786 struct ieee80211_vif *vif,
1787 struct ieee80211_key_conf *keyconf,
1788 struct ieee80211_sta *sta,
1789 u32 iv32, u16 *phase1key)
1790{
1791 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1792
Johannes Berg5023d962013-07-31 14:07:43 +02001793 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1794 return;
1795
Johannes Berg8ca151b2013-01-24 14:25:36 +01001796 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1797}
1798
1799
1800static int iwl_mvm_roc(struct ieee80211_hw *hw,
1801 struct ieee80211_vif *vif,
1802 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001803 int duration,
1804 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001805{
1806 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001807 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001808 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03001809 struct iwl_mvm_phy_ctxt *phy_ctxt;
1810 int ret, i;
1811
1812 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1813 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001814
1815 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1816 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1817 return -EINVAL;
1818 }
1819
Johannes Berg8ca151b2013-01-24 14:25:36 +01001820 mutex_lock(&mvm->mutex);
1821
Ilan Peer31d385a2013-04-02 10:25:46 +03001822 for (i = 0; i < NUM_PHY_CTX; i++) {
1823 phy_ctxt = &mvm->phy_ctxts[i];
1824 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1825 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001826
Ilan Peer31d385a2013-04-02 10:25:46 +03001827 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1828 /*
1829 * Unbind the P2P_DEVICE from the current PHY context,
1830 * and if the PHY context is not used remove it.
1831 */
1832 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1833 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1834 goto out_unlock;
1835
1836 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1837
1838 /* Bind the P2P_DEVICE to the current PHY Context */
1839 mvmvif->phy_ctxt = phy_ctxt;
1840
1841 ret = iwl_mvm_binding_add_vif(mvm, vif);
1842 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1843 goto out_unlock;
1844
1845 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1846 goto schedule_time_event;
1847 }
1848 }
1849
1850 /* Need to update the PHY context only if the ROC channel changed */
1851 if (channel == mvmvif->phy_ctxt->channel)
1852 goto schedule_time_event;
1853
1854 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1855
1856 /*
1857 * Change the PHY context configuration as it is currently referenced
1858 * only by the P2P Device MAC
1859 */
1860 if (mvmvif->phy_ctxt->ref == 1) {
1861 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1862 &chandef, 1, 1);
1863 if (ret)
1864 goto out_unlock;
1865 } else {
1866 /*
1867 * The PHY context is shared with other MACs. Need to remove the
1868 * P2P Device from the binding, allocate an new PHY context and
1869 * create a new binding
1870 */
1871 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1872 if (!phy_ctxt) {
1873 ret = -ENOSPC;
1874 goto out_unlock;
1875 }
1876
1877 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1878 1, 1);
1879 if (ret) {
1880 IWL_ERR(mvm, "Failed to change PHY context\n");
1881 goto out_unlock;
1882 }
1883
1884 /* Unbind the P2P_DEVICE from the current PHY context */
1885 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1886 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1887 goto out_unlock;
1888
1889 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1890
1891 /* Bind the P2P_DEVICE to the new allocated PHY context */
1892 mvmvif->phy_ctxt = phy_ctxt;
1893
1894 ret = iwl_mvm_binding_add_vif(mvm, vif);
1895 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1896 goto out_unlock;
1897
1898 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1899 }
1900
1901schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001902 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02001903 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001904
Ilan Peer31d385a2013-04-02 10:25:46 +03001905out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001906 mutex_unlock(&mvm->mutex);
1907 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001908 return ret;
1909}
1910
1911static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1912{
1913 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1914
1915 IWL_DEBUG_MAC80211(mvm, "enter\n");
1916
1917 mutex_lock(&mvm->mutex);
1918 iwl_mvm_stop_p2p_roc(mvm);
1919 mutex_unlock(&mvm->mutex);
1920
1921 IWL_DEBUG_MAC80211(mvm, "leave\n");
1922 return 0;
1923}
1924
1925static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1926 struct ieee80211_chanctx_conf *ctx)
1927{
1928 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001929 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1930 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001931 int ret;
1932
Ilan Peer53a9d612013-04-28 11:55:08 +03001933 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001934
1935 mutex_lock(&mvm->mutex);
1936 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1937 if (!phy_ctxt) {
1938 ret = -ENOSPC;
1939 goto out;
1940 }
1941
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02001942 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03001943 ctx->rx_chains_static,
1944 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001945 if (ret) {
1946 IWL_ERR(mvm, "Failed to add PHY context\n");
1947 goto out;
1948 }
1949
Ilan Peer53a9d612013-04-28 11:55:08 +03001950 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001951 *phy_ctxt_id = phy_ctxt->id;
1952out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001953 mutex_unlock(&mvm->mutex);
1954 return ret;
1955}
1956
1957static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1958 struct ieee80211_chanctx_conf *ctx)
1959{
1960 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001961 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1962 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001963
1964 mutex_lock(&mvm->mutex);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001965 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001966 mutex_unlock(&mvm->mutex);
1967}
1968
1969static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1970 struct ieee80211_chanctx_conf *ctx,
1971 u32 changed)
1972{
1973 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001974 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1975 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001976
Ilan Peer31d385a2013-04-02 10:25:46 +03001977 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1978 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1979 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02001980 IEEE80211_CHANCTX_CHANGE_RADAR |
1981 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03001982 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1983 phy_ctxt->ref, changed))
1984 return;
1985
Johannes Berg8ca151b2013-01-24 14:25:36 +01001986 mutex_lock(&mvm->mutex);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02001987 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001988 ctx->rx_chains_static,
1989 ctx->rx_chains_dynamic);
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001990 iwl_mvm_bt_coex_vif_change(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001991 mutex_unlock(&mvm->mutex);
1992}
1993
1994static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1995 struct ieee80211_vif *vif,
1996 struct ieee80211_chanctx_conf *ctx)
1997{
1998 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001999 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2000 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002001 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2002 int ret;
2003
2004 mutex_lock(&mvm->mutex);
2005
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002006 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002007
2008 switch (vif->type) {
2009 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002010 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002011 /*
2012 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02002013 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002014 */
2015 ret = 0;
2016 goto out_unlock;
2017 case NL80211_IFTYPE_STATION:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002018 case NL80211_IFTYPE_MONITOR:
2019 break;
2020 default:
2021 ret = -EINVAL;
2022 goto out_unlock;
2023 }
2024
2025 ret = iwl_mvm_binding_add_vif(mvm, vif);
2026 if (ret)
2027 goto out_unlock;
2028
2029 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02002030 * Power state must be updated before quotas,
2031 * otherwise fw will complain.
2032 */
2033 mvm->bound_vif_cnt++;
2034 iwl_mvm_power_update_binding(mvm, vif, true);
2035
2036 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01002037 * interfaces. For the other types, the bss_info changed flow
2038 * will handle quota settings.
2039 */
2040 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02002041 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002042 ret = iwl_mvm_update_quotas(mvm, vif);
2043 if (ret)
2044 goto out_remove_binding;
2045 }
2046
2047 goto out_unlock;
2048
2049 out_remove_binding:
2050 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar92d85562013-10-23 11:50:34 +02002051 mvm->bound_vif_cnt--;
2052 iwl_mvm_power_update_binding(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002053 out_unlock:
2054 mutex_unlock(&mvm->mutex);
2055 if (ret)
2056 mvmvif->phy_ctxt = NULL;
2057 return ret;
2058}
2059
2060static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2061 struct ieee80211_vif *vif,
2062 struct ieee80211_chanctx_conf *ctx)
2063{
2064 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2065 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2066
2067 mutex_lock(&mvm->mutex);
2068
2069 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2070
Johannes Berg8ca151b2013-01-24 14:25:36 +01002071 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02002072 case NL80211_IFTYPE_AP:
2073 case NL80211_IFTYPE_ADHOC:
2074 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002075 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02002076 mvmvif->monitor_active = false;
2077 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002078 break;
2079 default:
2080 break;
2081 }
2082
Ilan Peer1e1391c2013-03-13 14:52:04 +02002083 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03002084 mvm->bound_vif_cnt--;
Alexander Bondar92d85562013-10-23 11:50:34 +02002085 iwl_mvm_power_update_binding(mvm, vif, false);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03002086
Ilan Peera11e1442013-12-31 21:19:55 +02002087out_unlock:
2088 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002089 mutex_unlock(&mvm->mutex);
2090}
2091
2092static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2093 struct ieee80211_sta *sta,
2094 bool set)
2095{
2096 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2097 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2098
2099 if (!mvm_sta || !mvm_sta->vif) {
2100 IWL_ERR(mvm, "Station is not associated to a vif\n");
2101 return -EINVAL;
2102 }
2103
2104 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2105}
2106
David Spinadel507cadf2013-07-31 18:07:21 +03002107#ifdef CONFIG_NL80211_TESTMODE
2108static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2109 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2110 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02002111 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03002112};
2113
2114static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2115 struct ieee80211_vif *vif,
2116 void *data, int len)
2117{
2118 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2119 int err;
2120 u32 noa_duration;
2121
2122 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2123 if (err)
2124 return err;
2125
2126 if (!tb[IWL_MVM_TM_ATTR_CMD])
2127 return -EINVAL;
2128
2129 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2130 case IWL_MVM_TM_CMD_SET_NOA:
2131 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2132 !vif->bss_conf.enable_beacon ||
2133 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2134 return -EINVAL;
2135
2136 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2137 if (noa_duration >= vif->bss_conf.beacon_int)
2138 return -EINVAL;
2139
2140 mvm->noa_duration = noa_duration;
2141 mvm->noa_vif = vif;
2142
2143 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02002144 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2145 /* must be associated client vif - ignore authorized */
2146 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2147 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2148 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2149 return -EINVAL;
2150
2151 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
2152 return iwl_mvm_enable_beacon_filter(mvm, vif);
2153 return iwl_mvm_disable_beacon_filter(mvm, vif);
David Spinadel507cadf2013-07-31 18:07:21 +03002154 }
2155
2156 return -EOPNOTSUPP;
2157}
2158
2159static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2160 struct ieee80211_vif *vif,
2161 void *data, int len)
2162{
2163 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2164 int err;
2165
2166 mutex_lock(&mvm->mutex);
2167 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2168 mutex_unlock(&mvm->mutex);
2169
2170 return err;
2171}
2172#endif
2173
Johannes Berg8ca151b2013-01-24 14:25:36 +01002174struct ieee80211_ops iwl_mvm_hw_ops = {
2175 .tx = iwl_mvm_mac_tx,
2176 .ampdu_action = iwl_mvm_mac_ampdu_action,
2177 .start = iwl_mvm_mac_start,
2178 .restart_complete = iwl_mvm_mac_restart_complete,
2179 .stop = iwl_mvm_mac_stop,
2180 .add_interface = iwl_mvm_mac_add_interface,
2181 .remove_interface = iwl_mvm_mac_remove_interface,
2182 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02002183 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002184 .configure_filter = iwl_mvm_configure_filter,
2185 .bss_info_changed = iwl_mvm_bss_info_changed,
2186 .hw_scan = iwl_mvm_mac_hw_scan,
2187 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002188 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002189 .sta_state = iwl_mvm_mac_sta_state,
2190 .sta_notify = iwl_mvm_mac_sta_notify,
2191 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002192 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002193 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002194 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002195 .conf_tx = iwl_mvm_mac_conf_tx,
2196 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
David Spinadel35a000b2013-08-28 09:29:43 +03002197 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
2198 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002199 .set_key = iwl_mvm_mac_set_key,
2200 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
2201 .remain_on_channel = iwl_mvm_roc,
2202 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002203 .add_chanctx = iwl_mvm_add_chanctx,
2204 .remove_chanctx = iwl_mvm_remove_chanctx,
2205 .change_chanctx = iwl_mvm_change_chanctx,
2206 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
2207 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
2208
Johannes Berg5023d962013-07-31 14:07:43 +02002209 .start_ap = iwl_mvm_start_ap_ibss,
2210 .stop_ap = iwl_mvm_stop_ap_ibss,
2211 .join_ibss = iwl_mvm_start_ap_ibss,
2212 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002213
2214 .set_tim = iwl_mvm_set_tim,
2215
David Spinadel507cadf2013-07-31 18:07:21 +03002216 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
2217
Johannes Berg8ca151b2013-01-24 14:25:36 +01002218#ifdef CONFIG_PM_SLEEP
2219 /* look at d3.c */
2220 .suspend = iwl_mvm_suspend,
2221 .resume = iwl_mvm_resume,
2222 .set_wakeup = iwl_mvm_set_wakeup,
2223 .set_rekey_data = iwl_mvm_set_rekey_data,
2224#if IS_ENABLED(CONFIG_IPV6)
2225 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
2226#endif
2227 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
2228#endif
2229};