blob: dcb13c8967701fcc950fa59f7867f52ddbc9aaac [file] [log] [blame]
Wey-Yi Guy73356132011-11-10 06:55:11 -08001/******************************************************************************
2 *
Wey-Yi Guy4e318262011-12-27 11:21:32 -08003 * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
Wey-Yi Guy73356132011-11-10 06:55:11 -08004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33#include <linux/dma-mapping.h>
34#include <linux/delay.h>
35#include <linux/sched.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
Wey-Yi Guy73356132011-11-10 06:55:11 -080038#include <linux/etherdevice.h>
39#include <linux/if_arp.h>
40
41#include <net/mac80211.h>
42
43#include <asm/div64.h>
44
45#include "iwl-eeprom.h"
46#include "iwl-dev.h"
47#include "iwl-core.h"
48#include "iwl-io.h"
49#include "iwl-agn-calib.h"
50#include "iwl-agn.h"
51#include "iwl-shared.h"
Wey-Yi Guy73356132011-11-10 06:55:11 -080052#include "iwl-trans.h"
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +020053#include "iwl-op-mode.h"
Wey-Yi Guy73356132011-11-10 06:55:11 -080054
55/*****************************************************************************
56 *
57 * mac80211 entry point functions
58 *
59 *****************************************************************************/
60
61static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
62 {
63 .max = 1,
64 .types = BIT(NL80211_IFTYPE_STATION),
65 },
66 {
67 .max = 1,
68 .types = BIT(NL80211_IFTYPE_AP),
69 },
70};
71
72static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
73 {
74 .max = 2,
75 .types = BIT(NL80211_IFTYPE_STATION),
76 },
77};
78
79static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
80 {
81 .max = 1,
82 .types = BIT(NL80211_IFTYPE_STATION),
83 },
84 {
85 .max = 1,
86 .types = BIT(NL80211_IFTYPE_P2P_GO) |
87 BIT(NL80211_IFTYPE_AP),
88 },
89};
90
91static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
92 {
93 .max = 2,
94 .types = BIT(NL80211_IFTYPE_STATION),
95 },
96 {
97 .max = 1,
98 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
99 },
100};
101
102static const struct ieee80211_iface_combination
103iwlagn_iface_combinations_dualmode[] = {
104 { .num_different_channels = 1,
105 .max_interfaces = 2,
106 .beacon_int_infra_match = true,
107 .limits = iwlagn_sta_ap_limits,
108 .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
109 },
110 { .num_different_channels = 1,
111 .max_interfaces = 2,
112 .limits = iwlagn_2sta_limits,
113 .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
114 },
115};
116
117static const struct ieee80211_iface_combination
118iwlagn_iface_combinations_p2p[] = {
119 { .num_different_channels = 1,
120 .max_interfaces = 2,
121 .beacon_int_infra_match = true,
122 .limits = iwlagn_p2p_sta_go_limits,
123 .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
124 },
125 { .num_different_channels = 1,
126 .max_interfaces = 2,
127 .limits = iwlagn_p2p_2sta_limits,
128 .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
129 },
130};
131
132/*
133 * Not a mac80211 entry point function, but it fits in with all the
134 * other mac80211 functions grouped here.
135 */
136int iwlagn_mac_setup_register(struct iwl_priv *priv,
Johannes Berg0692fe42012-03-06 13:30:37 -0800137 const struct iwl_ucode_capabilities *capa)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800138{
139 int ret;
140 struct ieee80211_hw *hw = priv->hw;
141 struct iwl_rxon_context *ctx;
142
143 hw->rate_control_algorithm = "iwl-agn-rs";
144
145 /* Tell mac80211 our characteristics */
146 hw->flags = IEEE80211_HW_SIGNAL_DBM |
147 IEEE80211_HW_AMPDU_AGGREGATION |
148 IEEE80211_HW_NEED_DTIM_PERIOD |
149 IEEE80211_HW_SPECTRUM_MGMT |
150 IEEE80211_HW_REPORTS_TX_ACK_STATUS;
151
152 /*
153 * Including the following line will crash some AP's. This
154 * workaround removes the stimulus which causes the crash until
155 * the AP software can be fixed.
156 hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
157 */
158
159 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
160 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
161
Johannes Berg54708d82012-03-05 11:24:31 -0800162 if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800163 hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
164 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
165
David Spinadel18c57d32012-03-07 09:52:31 -0800166#ifndef CONFIG_IWLWIFI_EXPERIMENTAL_MFP
167 /* enable 11w if the uCode advertise */
Wey-Yi Guy73356132011-11-10 06:55:11 -0800168 if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
David Spinadel18c57d32012-03-07 09:52:31 -0800169#endif /* !CONFIG_IWLWIFI_EXPERIMENTAL_MFP */
Wey-Yi Guy73356132011-11-10 06:55:11 -0800170 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
171
172 hw->sta_data_size = sizeof(struct iwl_station_priv);
173 hw->vif_data_size = sizeof(struct iwl_vif_priv);
174
175 for_each_context(priv, ctx) {
176 hw->wiphy->interface_modes |= ctx->interface_modes;
177 hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
178 }
179
180 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
181
182 if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
183 hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
184 hw->wiphy->n_iface_combinations =
185 ARRAY_SIZE(iwlagn_iface_combinations_p2p);
186 } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
187 hw->wiphy->iface_combinations =
188 iwlagn_iface_combinations_dualmode;
189 hw->wiphy->n_iface_combinations =
190 ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
191 }
192
193 hw->wiphy->max_remain_on_channel_duration = 1000;
194
195 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
196 WIPHY_FLAG_DISABLE_BEACON_HINTS |
197 WIPHY_FLAG_IBSS_RSN;
198
Johannes Berg20528f72012-06-04 13:43:11 +0200199#ifdef CONFIG_PM_SLEEP
David Spinadel6dfa8d02012-03-10 13:00:14 -0800200 if (priv->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
Johannes Berg2dd4f9f2012-03-05 11:24:35 -0800201 trans(priv)->ops->wowlan_suspend &&
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200202 device_can_wakeup(trans(priv)->dev)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800203 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
204 WIPHY_WOWLAN_DISCONNECT |
205 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
206 WIPHY_WOWLAN_RFKILL_RELEASE;
207 if (!iwlagn_mod_params.sw_crypto)
208 hw->wiphy->wowlan.flags |=
209 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
210 WIPHY_WOWLAN_GTK_REKEY_FAILURE;
211
212 hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
213 hw->wiphy->wowlan.pattern_min_len =
214 IWLAGN_WOWLAN_MIN_PATTERN_LEN;
215 hw->wiphy->wowlan.pattern_max_len =
216 IWLAGN_WOWLAN_MAX_PATTERN_LEN;
217 }
Johannes Berg20528f72012-06-04 13:43:11 +0200218#endif
Wey-Yi Guy73356132011-11-10 06:55:11 -0800219
220 if (iwlagn_mod_params.power_save)
221 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
222 else
223 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
224
225 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
226 /* we create the 802.11 header and a zero-length SSID element */
227 hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
228
229 /* Default value; 4 EDCA QOS priorities */
230 hw->queues = 4;
231
232 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
233
234 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
235 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
236 &priv->bands[IEEE80211_BAND_2GHZ];
237 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
238 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
239 &priv->bands[IEEE80211_BAND_5GHZ];
240
Emmanuel Grumbach99673ee2012-01-08 21:19:45 +0200241 hw->wiphy->hw_version = trans(priv)->hw_id;
Wey-Yi Guy0ba958e2011-12-10 11:33:52 -0800242
Wey-Yi Guy73356132011-11-10 06:55:11 -0800243 iwl_leds_init(priv);
244
245 ret = ieee80211_register_hw(priv->hw);
246 if (ret) {
247 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
248 return ret;
249 }
250 priv->mac80211_registered = 1;
251
252 return 0;
253}
254
Don Fry09af1402011-12-09 10:07:38 -0800255void iwlagn_mac_unregister(struct iwl_priv *priv)
256{
257 if (!priv->mac80211_registered)
258 return;
259 iwl_leds_exit(priv);
260 ieee80211_unregister_hw(priv->hw);
261 priv->mac80211_registered = 0;
262}
263
Wey-Yi Guy73356132011-11-10 06:55:11 -0800264static int __iwl_up(struct iwl_priv *priv)
265{
266 struct iwl_rxon_context *ctx;
267 int ret;
268
Johannes Bergb1eea292012-03-06 13:30:42 -0800269 lockdep_assert_held(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800270
Don Fry83626402012-03-07 09:52:37 -0800271 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800272 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
273 return -EIO;
274 }
275
276 for_each_context(priv, ctx) {
277 ret = iwlagn_alloc_bcast_station(priv, ctx);
278 if (ret) {
279 iwl_dealloc_bcast_stations(priv);
280 return ret;
281 }
282 }
283
Johannes Berge1991882012-03-06 13:30:36 -0800284 ret = iwl_run_init_ucode(priv);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800285 if (ret) {
286 IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
287 goto error;
288 }
289
Johannes Berge1991882012-03-06 13:30:36 -0800290 ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800291 if (ret) {
292 IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
293 goto error;
294 }
295
296 ret = iwl_alive_start(priv);
297 if (ret)
298 goto error;
299 return 0;
300
301 error:
Don Fry83626402012-03-07 09:52:37 -0800302 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach78e5a462012-02-17 10:34:53 -0800303 iwl_down(priv);
Don Fry83626402012-03-07 09:52:37 -0800304 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800305
306 IWL_ERR(priv, "Unable to initialize device.\n");
307 return ret;
308}
309
310static int iwlagn_mac_start(struct ieee80211_hw *hw)
311{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200312 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800313 int ret;
314
315 IWL_DEBUG_MAC80211(priv, "enter\n");
316
317 /* we should be verifying the device is ready to be opened */
Johannes Bergb1eea292012-03-06 13:30:42 -0800318 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800319 ret = __iwl_up(priv);
Johannes Bergb1eea292012-03-06 13:30:42 -0800320 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800321 if (ret)
322 return ret;
323
324 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
325
326 /* Now we should be done, and the READY bit should be set. */
Don Fry83626402012-03-07 09:52:37 -0800327 if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
Wey-Yi Guy73356132011-11-10 06:55:11 -0800328 ret = -EIO;
329
330 iwlagn_led_enable(priv);
331
332 priv->is_open = 1;
333 IWL_DEBUG_MAC80211(priv, "leave\n");
334 return 0;
335}
336
337static void iwlagn_mac_stop(struct ieee80211_hw *hw)
338{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200339 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800340
341 IWL_DEBUG_MAC80211(priv, "enter\n");
342
343 if (!priv->is_open)
344 return;
345
346 priv->is_open = 0;
347
Johannes Bergb1eea292012-03-06 13:30:42 -0800348 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800349 iwl_down(priv);
Johannes Bergb1eea292012-03-06 13:30:42 -0800350 mutex_unlock(&priv->mutex);
Emmanuel Grumbach78e5a462012-02-17 10:34:53 -0800351
352 iwl_cancel_deferred_work(priv);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800353
Johannes Berg1ee158d2012-02-17 10:07:44 -0800354 flush_workqueue(priv->workqueue);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800355
356 /* User space software may expect getting rfkill changes
Emmanuel Grumbach1df06bd2012-01-09 16:35:08 +0200357 * even if interface is down, trans->down will leave the RF
358 * kill interrupt enabled
359 */
360 iwl_trans_stop_hw(trans(priv));
Wey-Yi Guy73356132011-11-10 06:55:11 -0800361
362 IWL_DEBUG_MAC80211(priv, "leave\n");
363}
364
365static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
366 struct ieee80211_vif *vif,
367 struct cfg80211_gtk_rekey_data *data)
368{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200369 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800370
371 if (iwlagn_mod_params.sw_crypto)
372 return;
373
374 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -0800375 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800376
377 if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
378 goto out;
379
380 memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
381 memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
382 priv->replay_ctr =
383 cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
384 priv->have_rekey_data = true;
385
386 out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800387 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800388 IWL_DEBUG_MAC80211(priv, "leave\n");
389}
390
391#ifdef CONFIG_PM_SLEEP
Wey-Yi Guy73356132011-11-10 06:55:11 -0800392
393static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
394 struct cfg80211_wowlan *wowlan)
395{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200396 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800397 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Wey-Yi Guy023ca582011-11-10 06:55:17 -0800398 int ret;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800399
400 if (WARN_ON(!wowlan))
401 return -EINVAL;
402
403 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -0800404 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800405
406 /* Don't attempt WoWLAN when not associated, tear down instead. */
407 if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
408 !iwl_is_associated_ctx(ctx)) {
409 ret = 1;
410 goto out;
411 }
412
Johannes Bergea886a62012-03-07 09:52:15 -0800413 ret = iwlagn_suspend(priv, wowlan);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800414 if (ret)
415 goto error;
416
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200417 device_set_wakeup_enable(trans(priv)->dev, true);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800418
Johannes Berg2dd4f9f2012-03-05 11:24:35 -0800419 iwl_trans_wowlan_suspend(trans(priv));
Wey-Yi Guy73356132011-11-10 06:55:11 -0800420
421 goto out;
422
423 error:
Johannes Berg15b86bf2012-03-05 11:24:36 -0800424 priv->wowlan = false;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800425 iwlagn_prepare_restart(priv);
426 ieee80211_restart_hw(priv->hw);
427 out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800428 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800429 IWL_DEBUG_MAC80211(priv, "leave\n");
430
431 return ret;
432}
433
434static int iwlagn_mac_resume(struct ieee80211_hw *hw)
435{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200436 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800437 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
438 struct ieee80211_vif *vif;
439 unsigned long flags;
440 u32 base, status = 0xffffffff;
441 int ret = -EIO;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800442 const struct fw_img *img;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800443
444 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -0800445 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800446
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200447 iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR,
Wey-Yi Guy73356132011-11-10 06:55:11 -0800448 CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
449
Don Fryae6130f2011-11-30 16:12:59 -0800450 base = priv->shrd->device_pointers.error_event_table;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800451 if (iwlagn_hw_valid_rtc_data_addr(base)) {
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200452 spin_lock_irqsave(&trans(priv)->reg_lock, flags);
453 ret = iwl_grab_nic_access_silent(trans(priv));
Stanislaw Gruszkabfe4b802012-03-07 09:52:24 -0800454 if (likely(ret == 0)) {
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200455 iwl_write32(trans(priv), HBUS_TARG_MEM_RADDR, base);
456 status = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
457 iwl_release_nic_access(trans(priv));
Wey-Yi Guy73356132011-11-10 06:55:11 -0800458 }
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200459 spin_unlock_irqrestore(&trans(priv)->reg_lock, flags);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800460
461#ifdef CONFIG_IWLWIFI_DEBUGFS
462 if (ret == 0) {
David Spinadel6dfa8d02012-03-10 13:00:14 -0800463 img = &(priv->fw->img[IWL_UCODE_WOWLAN]);
464 if (!priv->wowlan_sram) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800465 priv->wowlan_sram =
David Spinadel6dfa8d02012-03-10 13:00:14 -0800466 kzalloc(img->sec[IWL_UCODE_SECTION_DATA].len,
Wey-Yi Guy73356132011-11-10 06:55:11 -0800467 GFP_KERNEL);
David Spinadel6dfa8d02012-03-10 13:00:14 -0800468 }
Wey-Yi Guy73356132011-11-10 06:55:11 -0800469
470 if (priv->wowlan_sram)
471 _iwl_read_targ_mem_words(
David Spinadel6dfa8d02012-03-10 13:00:14 -0800472 trans(priv), 0x800000,
473 priv->wowlan_sram,
474 img->sec[IWL_UCODE_SECTION_DATA].len / 4);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800475 }
476#endif
477 }
478
479 /* we'll clear ctx->vif during iwlagn_prepare_restart() */
480 vif = ctx->vif;
481
Johannes Berg15b86bf2012-03-05 11:24:36 -0800482 priv->wowlan = false;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800483
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200484 device_set_wakeup_enable(trans(priv)->dev, false);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800485
486 iwlagn_prepare_restart(priv);
487
488 memset((void *)&ctx->active, 0, sizeof(ctx->active));
489 iwl_connection_init_rx_config(priv, ctx);
490 iwlagn_set_rxon_chain(priv, ctx);
491
Johannes Bergb1eea292012-03-06 13:30:42 -0800492 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800493 IWL_DEBUG_MAC80211(priv, "leave\n");
494
495 ieee80211_resume_disconnect(vif);
496
497 return 1;
498}
499
500#endif
501
502static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
503{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200504 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800505
Wey-Yi Guy73356132011-11-10 06:55:11 -0800506 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
507 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
508
509 if (iwlagn_tx_skb(priv, skb))
510 dev_kfree_skb_any(skb);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800511}
512
513static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
514 struct ieee80211_vif *vif,
515 struct ieee80211_key_conf *keyconf,
516 struct ieee80211_sta *sta,
517 u32 iv32, u16 *phase1key)
518{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200519 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800520
521 iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
522}
523
524static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
525 struct ieee80211_vif *vif,
526 struct ieee80211_sta *sta,
527 struct ieee80211_key_conf *key)
528{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200529 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800530 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
531 struct iwl_rxon_context *ctx = vif_priv->ctx;
532 int ret;
533 bool is_default_wep_key = false;
534
535 IWL_DEBUG_MAC80211(priv, "enter\n");
536
537 if (iwlagn_mod_params.sw_crypto) {
538 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
539 return -EOPNOTSUPP;
540 }
541
Johannes Berga7e12c82011-11-25 03:20:09 -0800542 switch (key->cipher) {
543 case WLAN_CIPHER_SUITE_TKIP:
544 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
545 /* fall through */
546 case WLAN_CIPHER_SUITE_CCMP:
547 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
548 break;
549 default:
550 break;
551 }
552
Wey-Yi Guy73356132011-11-10 06:55:11 -0800553 /*
554 * We could program these keys into the hardware as well, but we
555 * don't expect much multicast traffic in IBSS and having keys
556 * for more stations is probably more useful.
557 *
558 * Mark key TX-only and return 0.
559 */
560 if (vif->type == NL80211_IFTYPE_ADHOC &&
561 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
562 key->hw_key_idx = WEP_INVALID_OFFSET;
563 return 0;
564 }
565
566 /* If they key was TX-only, accept deletion */
567 if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
568 return 0;
569
Johannes Bergb1eea292012-03-06 13:30:42 -0800570 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800571 iwl_scan_cancel_timeout(priv, 100);
572
573 BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
574
575 /*
576 * If we are getting WEP group key and we didn't receive any key mapping
577 * so far, we are in legacy wep mode (group key only), otherwise we are
578 * in 1X mode.
579 * In legacy wep mode, we use another host command to the uCode.
580 */
581 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
582 key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
583 if (cmd == SET_KEY)
584 is_default_wep_key = !ctx->key_mapping_keys;
585 else
586 is_default_wep_key =
587 key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
588 }
589
590
591 switch (cmd) {
592 case SET_KEY:
593 if (is_default_wep_key) {
594 ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
595 break;
596 }
597 ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
598 if (ret) {
599 /*
600 * can't add key for RX, but we don't need it
601 * in the device for TX so still return 0
602 */
603 ret = 0;
604 key->hw_key_idx = WEP_INVALID_OFFSET;
605 }
606
607 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
608 break;
609 case DISABLE_KEY:
610 if (is_default_wep_key)
611 ret = iwl_remove_default_wep_key(priv, ctx, key);
612 else
613 ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
614
615 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
616 break;
617 default:
618 ret = -EINVAL;
619 }
620
Johannes Bergb1eea292012-03-06 13:30:42 -0800621 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800622 IWL_DEBUG_MAC80211(priv, "leave\n");
623
624 return ret;
625}
626
627static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
628 struct ieee80211_vif *vif,
629 enum ieee80211_ampdu_mlme_action action,
630 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
631 u8 buf_size)
632{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200633 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800634 int ret = -EINVAL;
635 struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800636
637 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
638 sta->addr, tid);
639
Johannes Berg54708d82012-03-05 11:24:31 -0800640 if (!(hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE))
Wey-Yi Guy73356132011-11-10 06:55:11 -0800641 return -EACCES;
642
643 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -0800644 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800645
646 switch (action) {
647 case IEEE80211_AMPDU_RX_START:
Johannes Berg74289942011-12-13 00:07:40 -0800648 if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
649 break;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800650 IWL_DEBUG_HT(priv, "start Rx\n");
651 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
652 break;
653 case IEEE80211_AMPDU_RX_STOP:
654 IWL_DEBUG_HT(priv, "stop Rx\n");
655 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800656 break;
657 case IEEE80211_AMPDU_TX_START:
Johannes Berg74289942011-12-13 00:07:40 -0800658 if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
659 break;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800660 IWL_DEBUG_HT(priv, "start Tx\n");
661 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
662 break;
663 case IEEE80211_AMPDU_TX_STOP:
664 IWL_DEBUG_HT(priv, "stop Tx\n");
665 ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
666 if ((ret == 0) && (priv->agg_tids_count > 0)) {
667 priv->agg_tids_count--;
668 IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
669 priv->agg_tids_count);
670 }
Johannes Bergb9ad70d2012-03-06 13:30:55 -0800671 if (!priv->agg_tids_count &&
672 hw_params(priv).use_rts_for_aggregation) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800673 /*
674 * switch off RTS/CTS if it was previously enabled
675 */
676 sta_priv->lq_sta.lq.general_params.flags &=
677 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
678 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
679 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
680 }
681 break;
682 case IEEE80211_AMPDU_TX_OPERATIONAL:
Emmanuel Grumbach822e8b22011-11-21 13:25:31 +0200683 ret = iwlagn_tx_agg_oper(priv, vif, sta, tid, buf_size);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800684 break;
685 }
Johannes Bergb1eea292012-03-06 13:30:42 -0800686 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800687 IWL_DEBUG_MAC80211(priv, "leave\n");
688 return ret;
689}
690
691static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
692 struct ieee80211_vif *vif,
693 struct ieee80211_sta *sta)
694{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200695 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800696 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
697 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
698 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800699 int ret;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800700 u8 sta_id;
701
Wey-Yi Guy73356132011-11-10 06:55:11 -0800702 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
703 sta->addr);
704 sta_priv->sta_id = IWL_INVALID_STATION;
705
706 atomic_set(&sta_priv->pending_frames, 0);
707 if (vif->type == NL80211_IFTYPE_AP)
708 sta_priv->client = true;
709
710 ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
711 is_ap, sta, &sta_id);
712 if (ret) {
713 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
714 sta->addr, ret);
715 /* Should we return success if return code is EEXIST ? */
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800716 return ret;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800717 }
718
719 sta_priv->sta_id = sta_id;
720
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800721 return 0;
722}
723
724static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
725 struct ieee80211_vif *vif,
726 struct ieee80211_sta *sta)
727{
728 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
729 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
730 int ret;
731
Johannes Berg97420512012-03-07 09:52:42 -0800732 IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", sta->addr);
733
734 if (vif->type == NL80211_IFTYPE_STATION) {
735 /*
736 * Station will be removed from device when the RXON
737 * is set to unassociated -- just deactivate it here
738 * to avoid re-programming it.
739 */
740 ret = 0;
741 iwl_deactivate_station(priv, sta_priv->sta_id, sta->addr);
742 } else {
743 ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
744 if (ret)
745 IWL_DEBUG_QUIET_RFKILL(priv,
746 "Error removing station %pM\n", sta->addr);
747 }
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800748 return ret;
749}
750
751static int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
752 struct ieee80211_vif *vif,
753 struct ieee80211_sta *sta,
754 enum ieee80211_sta_state old_state,
755 enum ieee80211_sta_state new_state)
756{
757 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Bergab0bd5b2012-03-05 11:24:47 -0800758 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800759 enum {
Johannes Bergab0bd5b2012-03-05 11:24:47 -0800760 NONE, ADD, REMOVE, HT_RATE_INIT, ADD_RATE_INIT,
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800761 } op = NONE;
762 int ret;
763
764 IWL_DEBUG_MAC80211(priv, "station %pM state change %d->%d\n",
765 sta->addr, old_state, new_state);
766
Johannes Bergb1eea292012-03-06 13:30:42 -0800767 mutex_lock(&priv->mutex);
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800768 if (vif->type == NL80211_IFTYPE_STATION) {
769 if (old_state == IEEE80211_STA_NOTEXIST &&
770 new_state == IEEE80211_STA_NONE)
771 op = ADD;
772 else if (old_state == IEEE80211_STA_NONE &&
773 new_state == IEEE80211_STA_NOTEXIST)
774 op = REMOVE;
775 else if (old_state == IEEE80211_STA_AUTH &&
776 new_state == IEEE80211_STA_ASSOC)
Johannes Bergab0bd5b2012-03-05 11:24:47 -0800777 op = HT_RATE_INIT;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800778 } else {
779 if (old_state == IEEE80211_STA_AUTH &&
780 new_state == IEEE80211_STA_ASSOC)
781 op = ADD_RATE_INIT;
782 else if (old_state == IEEE80211_STA_ASSOC &&
783 new_state == IEEE80211_STA_AUTH)
784 op = REMOVE;
785 }
786
787 switch (op) {
788 case ADD:
789 ret = iwlagn_mac_sta_add(hw, vif, sta);
790 break;
791 case REMOVE:
792 ret = iwlagn_mac_sta_remove(hw, vif, sta);
793 break;
794 case ADD_RATE_INIT:
795 ret = iwlagn_mac_sta_add(hw, vif, sta);
796 if (ret)
797 break;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800798 /* Initialize rate scaling */
799 IWL_DEBUG_INFO(priv,
800 "Initializing rate scaling for station %pM\n",
801 sta->addr);
802 iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
803 ret = 0;
804 break;
Johannes Bergab0bd5b2012-03-05 11:24:47 -0800805 case HT_RATE_INIT:
806 /* Initialize rate scaling */
807 ret = iwl_sta_update_ht(priv, vif_priv->ctx, sta);
808 if (ret)
809 break;
810 IWL_DEBUG_INFO(priv,
811 "Initializing rate scaling for station %pM\n",
812 sta->addr);
813 iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
814 ret = 0;
815 break;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800816 default:
817 ret = 0;
818 break;
819 }
820
821 /*
822 * mac80211 might WARN if we fail, but due the way we
823 * (badly) handle hard rfkill, we might fail here
824 */
Don Fry83626402012-03-07 09:52:37 -0800825 if (iwl_is_rfkill(priv))
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800826 ret = 0;
827
Johannes Bergb1eea292012-03-06 13:30:42 -0800828 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800829 IWL_DEBUG_MAC80211(priv, "leave\n");
830
831 return ret;
832}
833
834static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
835 struct ieee80211_channel_switch *ch_switch)
836{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200837 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800838 const struct iwl_channel_info *ch_info;
839 struct ieee80211_conf *conf = &hw->conf;
840 struct ieee80211_channel *channel = ch_switch->channel;
841 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
842 /*
843 * MULTI-FIXME
844 * When we add support for multiple interfaces, we need to
845 * revisit this. The channel switch command in the device
846 * only affects the BSS context, but what does that really
847 * mean? And what if we get a CSA on the second interface?
848 * This needs a lot of work.
849 */
850 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
851 u16 ch;
852
853 IWL_DEBUG_MAC80211(priv, "enter\n");
854
Johannes Bergb1eea292012-03-06 13:30:42 -0800855 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800856
Don Fry83626402012-03-07 09:52:37 -0800857 if (iwl_is_rfkill(priv))
Wey-Yi Guy73356132011-11-10 06:55:11 -0800858 goto out;
859
Don Fry83626402012-03-07 09:52:37 -0800860 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
861 test_bit(STATUS_SCANNING, &priv->status) ||
862 test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
Wey-Yi Guy73356132011-11-10 06:55:11 -0800863 goto out;
864
865 if (!iwl_is_associated_ctx(ctx))
866 goto out;
867
Don Fry38622412011-12-16 07:07:36 -0800868 if (!cfg(priv)->lib->set_channel_switch)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800869 goto out;
870
871 ch = channel->hw_value;
872 if (le16_to_cpu(ctx->active.channel) == ch)
873 goto out;
874
875 ch_info = iwl_get_channel_info(priv, channel->band, ch);
876 if (!is_channel_valid(ch_info)) {
877 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
878 goto out;
879 }
880
Wey-Yi Guy73356132011-11-10 06:55:11 -0800881 priv->current_ht_config.smps = conf->smps_mode;
882
883 /* Configure HT40 channels */
884 ctx->ht.enabled = conf_is_ht(conf);
Wey-Yi Guy137ce792011-11-22 16:23:35 -0800885 if (ctx->ht.enabled)
886 iwlagn_config_ht40(conf, ctx);
887 else
Wey-Yi Guy73356132011-11-10 06:55:11 -0800888 ctx->ht.is_40mhz = false;
889
890 if ((le16_to_cpu(ctx->staging.channel) != ch))
891 ctx->staging.flags = 0;
892
893 iwl_set_rxon_channel(priv, channel, ctx);
894 iwl_set_rxon_ht(priv, ht_conf);
895 iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
896
Wey-Yi Guy73356132011-11-10 06:55:11 -0800897 iwl_set_rate(priv);
898 /*
899 * at this point, staging_rxon has the
900 * configuration for channel switch
901 */
Don Fry83626402012-03-07 09:52:37 -0800902 set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800903 priv->switch_channel = cpu_to_le16(ch);
Don Fry38622412011-12-16 07:07:36 -0800904 if (cfg(priv)->lib->set_channel_switch(priv, ch_switch)) {
Don Fry83626402012-03-07 09:52:37 -0800905 clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800906 priv->switch_channel = 0;
907 ieee80211_chswitch_done(ctx->vif, false);
908 }
909
910out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800911 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800912 IWL_DEBUG_MAC80211(priv, "leave\n");
913}
914
915static void iwlagn_configure_filter(struct ieee80211_hw *hw,
916 unsigned int changed_flags,
917 unsigned int *total_flags,
918 u64 multicast)
919{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200920 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800921 __le32 filter_or = 0, filter_nand = 0;
922 struct iwl_rxon_context *ctx;
923
924#define CHK(test, flag) do { \
925 if (*total_flags & (test)) \
926 filter_or |= (flag); \
927 else \
928 filter_nand |= (flag); \
929 } while (0)
930
931 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
932 changed_flags, *total_flags);
933
934 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
935 /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
936 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
937 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
938
939#undef CHK
940
Johannes Bergb1eea292012-03-06 13:30:42 -0800941 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800942
943 for_each_context(priv, ctx) {
944 ctx->staging.filter_flags &= ~filter_nand;
945 ctx->staging.filter_flags |= filter_or;
946
947 /*
948 * Not committing directly because hardware can perform a scan,
949 * but we'll eventually commit the filter flags change anyway.
950 */
951 }
952
Johannes Bergb1eea292012-03-06 13:30:42 -0800953 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800954
955 /*
956 * Receiving all multicast frames is always enabled by the
957 * default flags setup in iwl_connection_init_rx_config()
958 * since we currently do not support programming multicast
959 * filters into the device.
960 */
961 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
962 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
963}
964
965static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
966{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200967 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800968
Johannes Bergb1eea292012-03-06 13:30:42 -0800969 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800970 IWL_DEBUG_MAC80211(priv, "enter\n");
971
Don Fry83626402012-03-07 09:52:37 -0800972 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800973 IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
974 goto done;
975 }
Don Fry83626402012-03-07 09:52:37 -0800976 if (iwl_is_rfkill(priv)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800977 IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
978 goto done;
979 }
980
981 /*
982 * mac80211 will not push any more frames for transmit
983 * until the flush is completed
984 */
985 if (drop) {
986 IWL_DEBUG_MAC80211(priv, "send flush command\n");
987 if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
988 IWL_ERR(priv, "flush request fail\n");
989 goto done;
990 }
991 }
992 IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
993 iwl_trans_wait_tx_queue_empty(trans(priv));
994done:
Johannes Bergb1eea292012-03-06 13:30:42 -0800995 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800996 IWL_DEBUG_MAC80211(priv, "leave\n");
997}
998
999static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
1000 struct ieee80211_channel *channel,
1001 enum nl80211_channel_type channel_type,
1002 int duration)
1003{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001004 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001005 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
1006 int err = 0;
1007
1008 if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
1009 return -EOPNOTSUPP;
1010
1011 if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
1012 return -EOPNOTSUPP;
1013
1014 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001015 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001016
Don Fry83626402012-03-07 09:52:37 -08001017 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -08001018 err = -EBUSY;
1019 goto out;
1020 }
1021
1022 priv->hw_roc_channel = channel;
1023 priv->hw_roc_chantype = channel_type;
Johannes Berg3ddf6be2011-11-10 06:55:21 -08001024 /* convert from ms to TU */
1025 priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001026 priv->hw_roc_start_notified = false;
1027 cancel_delayed_work(&priv->hw_roc_disable_work);
1028
1029 if (!ctx->is_active) {
Johannes Berga69cd042011-11-10 06:55:13 -08001030 static const struct iwl_qos_info default_qos_data = {
1031 .def_qos_parm = {
1032 .ac[0] = {
1033 .cw_min = cpu_to_le16(3),
1034 .cw_max = cpu_to_le16(7),
1035 .aifsn = 2,
1036 .edca_txop = cpu_to_le16(1504),
1037 },
1038 .ac[1] = {
1039 .cw_min = cpu_to_le16(7),
1040 .cw_max = cpu_to_le16(15),
1041 .aifsn = 2,
1042 .edca_txop = cpu_to_le16(3008),
1043 },
1044 .ac[2] = {
1045 .cw_min = cpu_to_le16(15),
1046 .cw_max = cpu_to_le16(1023),
1047 .aifsn = 3,
1048 },
1049 .ac[3] = {
1050 .cw_min = cpu_to_le16(15),
1051 .cw_max = cpu_to_le16(1023),
1052 .aifsn = 7,
1053 },
1054 },
1055 };
1056
Wey-Yi Guy73356132011-11-10 06:55:11 -08001057 ctx->is_active = true;
Johannes Berga69cd042011-11-10 06:55:13 -08001058 ctx->qos_data = default_qos_data;
Wey-Yi Guy73356132011-11-10 06:55:11 -08001059 ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
1060 memcpy(ctx->staging.node_addr,
1061 priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
1062 ETH_ALEN);
1063 memcpy(ctx->staging.bssid_addr,
1064 priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
1065 ETH_ALEN);
1066 err = iwlagn_commit_rxon(priv, ctx);
1067 if (err)
1068 goto out;
1069 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
1070 RXON_FILTER_PROMISC_MSK |
1071 RXON_FILTER_CTL2HOST_MSK;
1072
1073 err = iwlagn_commit_rxon(priv, ctx);
1074 if (err) {
1075 iwlagn_disable_roc(priv);
1076 goto out;
1077 }
1078 priv->hw_roc_setup = true;
1079 }
1080
1081 err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
1082 if (err)
1083 iwlagn_disable_roc(priv);
1084
1085 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001086 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001087 IWL_DEBUG_MAC80211(priv, "leave\n");
1088
1089 return err;
1090}
1091
1092static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
1093{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001094 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001095
1096 if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
1097 return -EOPNOTSUPP;
1098
1099 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001100 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001101 iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
1102 iwlagn_disable_roc(priv);
Johannes Bergb1eea292012-03-06 13:30:42 -08001103 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001104 IWL_DEBUG_MAC80211(priv, "leave\n");
1105
1106 return 0;
1107}
1108
Wey-Yi Guy73356132011-11-10 06:55:11 -08001109static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
1110 enum ieee80211_rssi_event rssi_event)
1111{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001112 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001113
1114 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001115 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001116
Don Fry38622412011-12-16 07:07:36 -08001117 if (cfg(priv)->bt_params &&
1118 cfg(priv)->bt_params->advanced_bt_coexist) {
Wey-Yi Guy73356132011-11-10 06:55:11 -08001119 if (rssi_event == RSSI_EVENT_LOW)
1120 priv->bt_enable_pspoll = true;
1121 else if (rssi_event == RSSI_EVENT_HIGH)
1122 priv->bt_enable_pspoll = false;
1123
1124 iwlagn_send_advance_bt_config(priv);
1125 } else {
1126 IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
1127 "ignoring RSSI callback\n");
1128 }
1129
Johannes Bergb1eea292012-03-06 13:30:42 -08001130 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001131 IWL_DEBUG_MAC80211(priv, "leave\n");
1132}
1133
1134static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
1135 struct ieee80211_sta *sta, bool set)
1136{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001137 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001138
Johannes Berg1ee158d2012-02-17 10:07:44 -08001139 queue_work(priv->workqueue, &priv->beacon_update);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001140
1141 return 0;
1142}
1143
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001144static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
1145 struct ieee80211_vif *vif, u16 queue,
1146 const struct ieee80211_tx_queue_params *params)
1147{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001148 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001149 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1150 struct iwl_rxon_context *ctx = vif_priv->ctx;
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001151 int q;
1152
1153 if (WARN_ON(!ctx))
1154 return -EINVAL;
1155
1156 IWL_DEBUG_MAC80211(priv, "enter\n");
1157
Don Fry83626402012-03-07 09:52:37 -08001158 if (!iwl_is_ready_rf(priv)) {
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001159 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
1160 return -EIO;
1161 }
1162
1163 if (queue >= AC_NUM) {
1164 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
1165 return 0;
1166 }
1167
1168 q = AC_NUM - 1 - queue;
1169
Johannes Bergb1eea292012-03-06 13:30:42 -08001170 mutex_lock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001171
1172 ctx->qos_data.def_qos_parm.ac[q].cw_min =
1173 cpu_to_le16(params->cw_min);
1174 ctx->qos_data.def_qos_parm.ac[q].cw_max =
1175 cpu_to_le16(params->cw_max);
1176 ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
1177 ctx->qos_data.def_qos_parm.ac[q].edca_txop =
1178 cpu_to_le16((params->txop * 32));
1179
1180 ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
1181
Johannes Bergb1eea292012-03-06 13:30:42 -08001182 mutex_unlock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001183
1184 IWL_DEBUG_MAC80211(priv, "leave\n");
1185 return 0;
1186}
1187
1188static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
1189{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001190 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001191
1192 return priv->ibss_manager == IWL_IBSS_MANAGER;
1193}
1194
1195static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1196{
1197 iwl_connection_init_rx_config(priv, ctx);
1198
1199 iwlagn_set_rxon_chain(priv, ctx);
1200
1201 return iwlagn_commit_rxon(priv, ctx);
1202}
1203
1204static int iwl_setup_interface(struct iwl_priv *priv,
1205 struct iwl_rxon_context *ctx)
1206{
1207 struct ieee80211_vif *vif = ctx->vif;
1208 int err;
1209
Johannes Bergb1eea292012-03-06 13:30:42 -08001210 lockdep_assert_held(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001211
1212 /*
1213 * This variable will be correct only when there's just
1214 * a single context, but all code using it is for hardware
1215 * that supports only one context.
1216 */
1217 priv->iw_mode = vif->type;
1218
1219 ctx->is_active = true;
1220
1221 err = iwl_set_mode(priv, ctx);
1222 if (err) {
1223 if (!ctx->always_active)
1224 ctx->is_active = false;
1225 return err;
1226 }
1227
Don Fry38622412011-12-16 07:07:36 -08001228 if (cfg(priv)->bt_params && cfg(priv)->bt_params->advanced_bt_coexist &&
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001229 vif->type == NL80211_IFTYPE_ADHOC) {
1230 /*
1231 * pretend to have high BT traffic as long as we
1232 * are operating in IBSS mode, as this will cause
1233 * the rate scaling etc. to behave as intended.
1234 */
1235 priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
1236 }
1237
1238 return 0;
1239}
1240
1241static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
1242 struct ieee80211_vif *vif)
1243{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001244 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001245 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1246 struct iwl_rxon_context *tmp, *ctx = NULL;
1247 int err;
1248 enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
Stanislaw Gruszka8db4c7e2012-04-18 08:01:15 -07001249 bool reset = false;
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001250
1251 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
1252 viftype, vif->addr);
1253
1254 cancel_delayed_work_sync(&priv->hw_roc_disable_work);
1255
Johannes Bergb1eea292012-03-06 13:30:42 -08001256 mutex_lock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001257
1258 iwlagn_disable_roc(priv);
1259
Don Fry83626402012-03-07 09:52:37 -08001260 if (!iwl_is_ready_rf(priv)) {
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001261 IWL_WARN(priv, "Try to add interface when device not ready\n");
1262 err = -EINVAL;
1263 goto out;
1264 }
1265
1266 for_each_context(priv, tmp) {
1267 u32 possible_modes =
1268 tmp->interface_modes | tmp->exclusive_interface_modes;
1269
1270 if (tmp->vif) {
Stanislaw Gruszka8db4c7e2012-04-18 08:01:15 -07001271 /* On reset we need to add the same interface again */
1272 if (tmp->vif == vif) {
1273 reset = true;
1274 ctx = tmp;
1275 break;
1276 }
1277
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001278 /* check if this busy context is exclusive */
1279 if (tmp->exclusive_interface_modes &
1280 BIT(tmp->vif->type)) {
1281 err = -EINVAL;
1282 goto out;
1283 }
1284 continue;
1285 }
1286
1287 if (!(possible_modes & BIT(viftype)))
1288 continue;
1289
1290 /* have maybe usable context w/o interface */
1291 ctx = tmp;
1292 break;
1293 }
1294
1295 if (!ctx) {
1296 err = -EOPNOTSUPP;
1297 goto out;
1298 }
1299
1300 vif_priv->ctx = ctx;
1301 ctx->vif = vif;
1302
1303 err = iwl_setup_interface(priv, ctx);
Stanislaw Gruszka8db4c7e2012-04-18 08:01:15 -07001304 if (!err || reset)
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001305 goto out;
1306
1307 ctx->vif = NULL;
1308 priv->iw_mode = NL80211_IFTYPE_STATION;
1309 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001310 mutex_unlock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001311
1312 IWL_DEBUG_MAC80211(priv, "leave\n");
1313 return err;
1314}
1315
1316static void iwl_teardown_interface(struct iwl_priv *priv,
1317 struct ieee80211_vif *vif,
1318 bool mode_change)
1319{
1320 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1321
Johannes Bergb1eea292012-03-06 13:30:42 -08001322 lockdep_assert_held(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001323
1324 if (priv->scan_vif == vif) {
1325 iwl_scan_cancel_timeout(priv, 200);
1326 iwl_force_scan_end(priv);
1327 }
1328
1329 if (!mode_change) {
1330 iwl_set_mode(priv, ctx);
1331 if (!ctx->always_active)
1332 ctx->is_active = false;
1333 }
1334
1335 /*
1336 * When removing the IBSS interface, overwrite the
1337 * BT traffic load with the stored one from the last
1338 * notification, if any. If this is a device that
1339 * doesn't implement this, this has no effect since
1340 * both values are the same and zero.
1341 */
1342 if (vif->type == NL80211_IFTYPE_ADHOC)
1343 priv->bt_traffic_load = priv->last_bt_traffic_load;
1344}
1345
1346static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw,
1347 struct ieee80211_vif *vif)
1348{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001349 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001350 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1351
1352 IWL_DEBUG_MAC80211(priv, "enter\n");
1353
Johannes Bergb1eea292012-03-06 13:30:42 -08001354 mutex_lock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001355
1356 if (WARN_ON(ctx->vif != vif)) {
1357 struct iwl_rxon_context *tmp;
1358 IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif);
1359 for_each_context(priv, tmp)
1360 IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n",
1361 tmp->ctxid, tmp, tmp->vif);
1362 }
1363 ctx->vif = NULL;
1364
1365 iwl_teardown_interface(priv, vif, false);
1366
Johannes Bergb1eea292012-03-06 13:30:42 -08001367 mutex_unlock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001368
1369 IWL_DEBUG_MAC80211(priv, "leave\n");
1370
1371}
1372
1373static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
1374 struct ieee80211_vif *vif,
1375 enum nl80211_iftype newtype, bool newp2p)
1376{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001377 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001378 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1379 struct iwl_rxon_context *bss_ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1380 struct iwl_rxon_context *tmp;
1381 enum nl80211_iftype newviftype = newtype;
1382 u32 interface_modes;
1383 int err;
1384
1385 IWL_DEBUG_MAC80211(priv, "enter\n");
1386
1387 newtype = ieee80211_iftype_p2p(newtype, newp2p);
1388
Johannes Bergb1eea292012-03-06 13:30:42 -08001389 mutex_lock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001390
Don Fry83626402012-03-07 09:52:37 -08001391 if (!ctx->vif || !iwl_is_ready_rf(priv)) {
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001392 /*
1393 * Huh? But wait ... this can maybe happen when
1394 * we're in the middle of a firmware restart!
1395 */
1396 err = -EBUSY;
1397 goto out;
1398 }
1399
1400 interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
1401
1402 if (!(interface_modes & BIT(newtype))) {
1403 err = -EBUSY;
1404 goto out;
1405 }
1406
1407 /*
1408 * Refuse a change that should be done by moving from the PAN
1409 * context to the BSS context instead, if the BSS context is
1410 * available and can support the new interface type.
1411 */
1412 if (ctx->ctxid == IWL_RXON_CTX_PAN && !bss_ctx->vif &&
1413 (bss_ctx->interface_modes & BIT(newtype) ||
1414 bss_ctx->exclusive_interface_modes & BIT(newtype))) {
1415 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
1416 err = -EBUSY;
1417 goto out;
1418 }
1419
1420 if (ctx->exclusive_interface_modes & BIT(newtype)) {
1421 for_each_context(priv, tmp) {
1422 if (ctx == tmp)
1423 continue;
1424
1425 if (!tmp->vif)
1426 continue;
1427
1428 /*
1429 * The current mode switch would be exclusive, but
1430 * another context is active ... refuse the switch.
1431 */
1432 err = -EBUSY;
1433 goto out;
1434 }
1435 }
1436
1437 /* success */
1438 iwl_teardown_interface(priv, vif, true);
1439 vif->type = newviftype;
1440 vif->p2p = newp2p;
1441 err = iwl_setup_interface(priv, ctx);
1442 WARN_ON(err);
1443 /*
1444 * We've switched internally, but submitting to the
1445 * device may have failed for some reason. Mask this
1446 * error, because otherwise mac80211 will not switch
1447 * (and set the interface type back) and we'll be
1448 * out of sync with it.
1449 */
1450 err = 0;
1451
1452 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001453 mutex_unlock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001454 IWL_DEBUG_MAC80211(priv, "leave\n");
1455
1456 return err;
1457}
1458
Wey-Yi Guyba4c5312011-11-10 06:55:15 -08001459static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
1460 struct ieee80211_vif *vif,
1461 struct cfg80211_scan_request *req)
1462{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001463 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guyba4c5312011-11-10 06:55:15 -08001464 int ret;
1465
1466 IWL_DEBUG_MAC80211(priv, "enter\n");
1467
1468 if (req->n_channels == 0)
1469 return -EINVAL;
1470
Johannes Bergb1eea292012-03-06 13:30:42 -08001471 mutex_lock(&priv->mutex);
Wey-Yi Guyba4c5312011-11-10 06:55:15 -08001472
1473 /*
1474 * If an internal scan is in progress, just set
1475 * up the scan_request as per above.
1476 */
1477 if (priv->scan_type != IWL_SCAN_NORMAL) {
1478 IWL_DEBUG_SCAN(priv,
1479 "SCAN request during internal scan - defer\n");
1480 priv->scan_request = req;
1481 priv->scan_vif = vif;
1482 ret = 0;
1483 } else {
1484 priv->scan_request = req;
1485 priv->scan_vif = vif;
1486 /*
1487 * mac80211 will only ask for one band at a time
1488 * so using channels[0] here is ok
1489 */
1490 ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
1491 req->channels[0]->band);
1492 if (ret) {
1493 priv->scan_request = NULL;
1494 priv->scan_vif = NULL;
1495 }
1496 }
1497
1498 IWL_DEBUG_MAC80211(priv, "leave\n");
1499
Johannes Bergb1eea292012-03-06 13:30:42 -08001500 mutex_unlock(&priv->mutex);
Wey-Yi Guyba4c5312011-11-10 06:55:15 -08001501
1502 return ret;
1503}
1504
Wey-Yi Guy76b29332011-11-10 06:55:16 -08001505static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1506{
Johannes Berg9451ca12012-03-05 11:24:23 -08001507 struct iwl_addsta_cmd cmd = {
1508 .mode = STA_CONTROL_MODIFY_MSK,
1509 .station_flags_msk = STA_FLG_PWR_SAVE_MSK,
1510 .sta.sta_id = sta_id,
1511 };
Wey-Yi Guy76b29332011-11-10 06:55:16 -08001512
Johannes Berg9451ca12012-03-05 11:24:23 -08001513 iwl_send_add_sta(priv, &cmd, CMD_ASYNC);
Wey-Yi Guy76b29332011-11-10 06:55:16 -08001514}
1515
1516static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
1517 struct ieee80211_vif *vif,
1518 enum sta_notify_cmd cmd,
1519 struct ieee80211_sta *sta)
1520{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001521 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy76b29332011-11-10 06:55:16 -08001522 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
1523 int sta_id;
1524
1525 IWL_DEBUG_MAC80211(priv, "enter\n");
1526
1527 switch (cmd) {
1528 case STA_NOTIFY_SLEEP:
1529 WARN_ON(!sta_priv->client);
1530 sta_priv->asleep = true;
1531 if (atomic_read(&sta_priv->pending_frames) > 0)
1532 ieee80211_sta_block_awake(hw, sta, true);
1533 break;
1534 case STA_NOTIFY_AWAKE:
1535 WARN_ON(!sta_priv->client);
1536 if (!sta_priv->asleep)
1537 break;
1538 sta_priv->asleep = false;
1539 sta_id = iwl_sta_id(sta);
1540 if (sta_id != IWL_INVALID_STATION)
1541 iwl_sta_modify_ps_wake(priv, sta_id);
1542 break;
1543 default:
1544 break;
1545 }
1546 IWL_DEBUG_MAC80211(priv, "leave\n");
1547}
1548
Wey-Yi Guy73356132011-11-10 06:55:11 -08001549struct ieee80211_ops iwlagn_hw_ops = {
1550 .tx = iwlagn_mac_tx,
1551 .start = iwlagn_mac_start,
1552 .stop = iwlagn_mac_stop,
1553#ifdef CONFIG_PM_SLEEP
1554 .suspend = iwlagn_mac_suspend,
1555 .resume = iwlagn_mac_resume,
1556#endif
1557 .add_interface = iwlagn_mac_add_interface,
1558 .remove_interface = iwlagn_mac_remove_interface,
1559 .change_interface = iwlagn_mac_change_interface,
1560 .config = iwlagn_mac_config,
1561 .configure_filter = iwlagn_configure_filter,
1562 .set_key = iwlagn_mac_set_key,
1563 .update_tkip_key = iwlagn_mac_update_tkip_key,
1564 .set_rekey_data = iwlagn_mac_set_rekey_data,
1565 .conf_tx = iwlagn_mac_conf_tx,
1566 .bss_info_changed = iwlagn_bss_info_changed,
1567 .ampdu_action = iwlagn_mac_ampdu_action,
1568 .hw_scan = iwlagn_mac_hw_scan,
1569 .sta_notify = iwlagn_mac_sta_notify,
Johannes Bergfb5fe5b2012-03-05 11:24:29 -08001570 .sta_state = iwlagn_mac_sta_state,
Wey-Yi Guy73356132011-11-10 06:55:11 -08001571 .channel_switch = iwlagn_mac_channel_switch,
1572 .flush = iwlagn_mac_flush,
1573 .tx_last_beacon = iwlagn_mac_tx_last_beacon,
1574 .remain_on_channel = iwlagn_mac_remain_on_channel,
1575 .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
1576 .rssi_callback = iwlagn_mac_rssi_callback,
1577 CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd)
1578 CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump)
Wey-Yi Guy73356132011-11-10 06:55:11 -08001579 .set_tim = iwlagn_mac_set_tim,
1580};
1581
1582/* This function both allocates and initializes hw and priv. */
1583struct ieee80211_hw *iwl_alloc_all(void)
1584{
1585 struct iwl_priv *priv;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001586 struct iwl_op_mode *op_mode;
Wey-Yi Guy73356132011-11-10 06:55:11 -08001587 /* mac80211 allocates memory for this device instance, including
1588 * space for this driver's private structure */
1589 struct ieee80211_hw *hw;
1590
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001591 hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) +
1592 sizeof(struct iwl_op_mode), &iwlagn_hw_ops);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001593 if (!hw)
1594 goto out;
1595
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001596 op_mode = hw->priv;
1597 priv = IWL_OP_MODE_GET_DVM(op_mode);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001598 priv->hw = hw;
1599
1600out:
1601 return hw;
1602}