blob: 4f4515696e550c1091c5dae42219ee33257f7dd5 [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"
Wey-Yi Guy73356132011-11-10 06:55:11 -080047#include "iwl-io.h"
48#include "iwl-agn-calib.h"
49#include "iwl-agn.h"
Wey-Yi Guy73356132011-11-10 06:55:11 -080050#include "iwl-trans.h"
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +020051#include "iwl-op-mode.h"
Wey-Yi Guy73356132011-11-10 06:55:11 -080052
53/*****************************************************************************
54 *
55 * mac80211 entry point functions
56 *
57 *****************************************************************************/
58
59static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
60 {
61 .max = 1,
62 .types = BIT(NL80211_IFTYPE_STATION),
63 },
64 {
65 .max = 1,
66 .types = BIT(NL80211_IFTYPE_AP),
67 },
68};
69
70static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
71 {
72 .max = 2,
73 .types = BIT(NL80211_IFTYPE_STATION),
74 },
75};
76
77static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
78 {
79 .max = 1,
80 .types = BIT(NL80211_IFTYPE_STATION),
81 },
82 {
83 .max = 1,
84 .types = BIT(NL80211_IFTYPE_P2P_GO) |
85 BIT(NL80211_IFTYPE_AP),
86 },
87};
88
89static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
90 {
91 .max = 2,
92 .types = BIT(NL80211_IFTYPE_STATION),
93 },
94 {
95 .max = 1,
96 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
97 },
98};
99
100static const struct ieee80211_iface_combination
101iwlagn_iface_combinations_dualmode[] = {
102 { .num_different_channels = 1,
103 .max_interfaces = 2,
104 .beacon_int_infra_match = true,
105 .limits = iwlagn_sta_ap_limits,
106 .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
107 },
108 { .num_different_channels = 1,
109 .max_interfaces = 2,
110 .limits = iwlagn_2sta_limits,
111 .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
112 },
113};
114
115static const struct ieee80211_iface_combination
116iwlagn_iface_combinations_p2p[] = {
117 { .num_different_channels = 1,
118 .max_interfaces = 2,
119 .beacon_int_infra_match = true,
120 .limits = iwlagn_p2p_sta_go_limits,
121 .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
122 },
123 { .num_different_channels = 1,
124 .max_interfaces = 2,
125 .limits = iwlagn_p2p_2sta_limits,
126 .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
127 },
128};
129
130/*
131 * Not a mac80211 entry point function, but it fits in with all the
132 * other mac80211 functions grouped here.
133 */
134int iwlagn_mac_setup_register(struct iwl_priv *priv,
Johannes Berg0692fe42012-03-06 13:30:37 -0800135 const struct iwl_ucode_capabilities *capa)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800136{
137 int ret;
138 struct ieee80211_hw *hw = priv->hw;
139 struct iwl_rxon_context *ctx;
140
141 hw->rate_control_algorithm = "iwl-agn-rs";
142
143 /* Tell mac80211 our characteristics */
144 hw->flags = IEEE80211_HW_SIGNAL_DBM |
145 IEEE80211_HW_AMPDU_AGGREGATION |
146 IEEE80211_HW_NEED_DTIM_PERIOD |
147 IEEE80211_HW_SPECTRUM_MGMT |
148 IEEE80211_HW_REPORTS_TX_ACK_STATUS;
149
150 /*
151 * Including the following line will crash some AP's. This
152 * workaround removes the stimulus which causes the crash until
153 * the AP software can be fixed.
154 hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
155 */
156
157 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
Johannes Berge5610382012-03-15 13:26:51 -0700158 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
159 IEEE80211_HW_SCAN_WHILE_IDLE;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800160
Johannes Berg9e295112012-04-09 17:46:55 -0700161 if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800162 hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
163 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
164
David Spinadel18c57d32012-03-07 09:52:31 -0800165#ifndef CONFIG_IWLWIFI_EXPERIMENTAL_MFP
166 /* enable 11w if the uCode advertise */
Wey-Yi Guy73356132011-11-10 06:55:11 -0800167 if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
David Spinadel18c57d32012-03-07 09:52:31 -0800168#endif /* !CONFIG_IWLWIFI_EXPERIMENTAL_MFP */
Wey-Yi Guy73356132011-11-10 06:55:11 -0800169 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
170
171 hw->sta_data_size = sizeof(struct iwl_station_priv);
172 hw->vif_data_size = sizeof(struct iwl_vif_priv);
173
174 for_each_context(priv, ctx) {
175 hw->wiphy->interface_modes |= ctx->interface_modes;
176 hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
177 }
178
179 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
180
181 if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
182 hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
183 hw->wiphy->n_iface_combinations =
184 ARRAY_SIZE(iwlagn_iface_combinations_p2p);
185 } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
186 hw->wiphy->iface_combinations =
187 iwlagn_iface_combinations_dualmode;
188 hw->wiphy->n_iface_combinations =
189 ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
190 }
191
192 hw->wiphy->max_remain_on_channel_duration = 1000;
193
194 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
195 WIPHY_FLAG_DISABLE_BEACON_HINTS |
196 WIPHY_FLAG_IBSS_RSN;
197
David Spinadel6dfa8d02012-03-10 13:00:14 -0800198 if (priv->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700199 priv->trans->ops->wowlan_suspend &&
200 device_can_wakeup(priv->trans->dev)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800201 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
202 WIPHY_WOWLAN_DISCONNECT |
203 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
204 WIPHY_WOWLAN_RFKILL_RELEASE;
205 if (!iwlagn_mod_params.sw_crypto)
206 hw->wiphy->wowlan.flags |=
207 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
208 WIPHY_WOWLAN_GTK_REKEY_FAILURE;
209
210 hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
211 hw->wiphy->wowlan.pattern_min_len =
212 IWLAGN_WOWLAN_MIN_PATTERN_LEN;
213 hw->wiphy->wowlan.pattern_max_len =
214 IWLAGN_WOWLAN_MAX_PATTERN_LEN;
215 }
216
217 if (iwlagn_mod_params.power_save)
218 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
219 else
220 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
221
222 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
223 /* we create the 802.11 header and a zero-length SSID element */
224 hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
225
226 /* Default value; 4 EDCA QOS priorities */
227 hw->queues = 4;
228
229 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
230
231 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
232 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
233 &priv->bands[IEEE80211_BAND_2GHZ];
234 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
235 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
236 &priv->bands[IEEE80211_BAND_5GHZ];
237
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700238 hw->wiphy->hw_version = priv->trans->hw_id;
Wey-Yi Guy0ba958e2011-12-10 11:33:52 -0800239
Wey-Yi Guy73356132011-11-10 06:55:11 -0800240 iwl_leds_init(priv);
241
242 ret = ieee80211_register_hw(priv->hw);
243 if (ret) {
244 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
245 return ret;
246 }
247 priv->mac80211_registered = 1;
248
249 return 0;
250}
251
Don Fry09af1402011-12-09 10:07:38 -0800252void iwlagn_mac_unregister(struct iwl_priv *priv)
253{
254 if (!priv->mac80211_registered)
255 return;
256 iwl_leds_exit(priv);
257 ieee80211_unregister_hw(priv->hw);
258 priv->mac80211_registered = 0;
259}
260
Wey-Yi Guy73356132011-11-10 06:55:11 -0800261static int __iwl_up(struct iwl_priv *priv)
262{
263 struct iwl_rxon_context *ctx;
264 int ret;
265
Johannes Bergb1eea292012-03-06 13:30:42 -0800266 lockdep_assert_held(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800267
Don Fry83626402012-03-07 09:52:37 -0800268 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800269 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
270 return -EIO;
271 }
272
273 for_each_context(priv, ctx) {
274 ret = iwlagn_alloc_bcast_station(priv, ctx);
275 if (ret) {
276 iwl_dealloc_bcast_stations(priv);
277 return ret;
278 }
279 }
280
Johannes Berge1991882012-03-06 13:30:36 -0800281 ret = iwl_run_init_ucode(priv);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800282 if (ret) {
283 IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
284 goto error;
285 }
286
Johannes Berge1991882012-03-06 13:30:36 -0800287 ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800288 if (ret) {
289 IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
290 goto error;
291 }
292
293 ret = iwl_alive_start(priv);
294 if (ret)
295 goto error;
296 return 0;
297
298 error:
Don Fry83626402012-03-07 09:52:37 -0800299 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach78e5a462012-02-17 10:34:53 -0800300 iwl_down(priv);
Don Fry83626402012-03-07 09:52:37 -0800301 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800302
303 IWL_ERR(priv, "Unable to initialize device.\n");
304 return ret;
305}
306
307static int iwlagn_mac_start(struct ieee80211_hw *hw)
308{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200309 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800310 int ret;
311
312 IWL_DEBUG_MAC80211(priv, "enter\n");
313
314 /* we should be verifying the device is ready to be opened */
Johannes Bergb1eea292012-03-06 13:30:42 -0800315 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800316 ret = __iwl_up(priv);
Johannes Bergb1eea292012-03-06 13:30:42 -0800317 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800318 if (ret)
319 return ret;
320
321 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
322
323 /* Now we should be done, and the READY bit should be set. */
Don Fry83626402012-03-07 09:52:37 -0800324 if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
Wey-Yi Guy73356132011-11-10 06:55:11 -0800325 ret = -EIO;
326
327 iwlagn_led_enable(priv);
328
329 priv->is_open = 1;
330 IWL_DEBUG_MAC80211(priv, "leave\n");
331 return 0;
332}
333
David Spinadel50c1e9a2012-04-16 14:43:30 -0700334void iwlagn_mac_stop(struct ieee80211_hw *hw)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800335{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200336 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800337
338 IWL_DEBUG_MAC80211(priv, "enter\n");
339
340 if (!priv->is_open)
341 return;
342
343 priv->is_open = 0;
344
Johannes Bergb1eea292012-03-06 13:30:42 -0800345 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800346 iwl_down(priv);
Johannes Bergb1eea292012-03-06 13:30:42 -0800347 mutex_unlock(&priv->mutex);
Emmanuel Grumbach78e5a462012-02-17 10:34:53 -0800348
349 iwl_cancel_deferred_work(priv);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800350
Johannes Berg1ee158d2012-02-17 10:07:44 -0800351 flush_workqueue(priv->workqueue);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800352
353 /* User space software may expect getting rfkill changes
Emmanuel Grumbach1df06bd2012-01-09 16:35:08 +0200354 * even if interface is down, trans->down will leave the RF
355 * kill interrupt enabled
356 */
Emmanuel Grumbach218733c2012-03-31 08:28:38 -0700357 iwl_trans_stop_hw(priv->trans, false);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800358
359 IWL_DEBUG_MAC80211(priv, "leave\n");
360}
361
David Spinadel50c1e9a2012-04-16 14:43:30 -0700362void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
363 struct ieee80211_vif *vif,
364 struct cfg80211_gtk_rekey_data *data)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800365{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200366 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800367
368 if (iwlagn_mod_params.sw_crypto)
369 return;
370
371 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -0800372 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800373
374 if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
375 goto out;
376
377 memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
378 memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
379 priv->replay_ctr =
380 cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
381 priv->have_rekey_data = true;
382
383 out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800384 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800385 IWL_DEBUG_MAC80211(priv, "leave\n");
386}
387
388#ifdef CONFIG_PM_SLEEP
Wey-Yi Guy73356132011-11-10 06:55:11 -0800389
David Spinadel50c1e9a2012-04-16 14:43:30 -0700390int iwlagn_mac_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800391{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200392 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800393 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Wey-Yi Guy023ca582011-11-10 06:55:17 -0800394 int ret;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800395
396 if (WARN_ON(!wowlan))
397 return -EINVAL;
398
399 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -0800400 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800401
402 /* Don't attempt WoWLAN when not associated, tear down instead. */
403 if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
404 !iwl_is_associated_ctx(ctx)) {
405 ret = 1;
406 goto out;
407 }
408
Johannes Bergea886a62012-03-07 09:52:15 -0800409 ret = iwlagn_suspend(priv, wowlan);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800410 if (ret)
411 goto error;
412
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700413 device_set_wakeup_enable(priv->trans->dev, true);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800414
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700415 iwl_trans_wowlan_suspend(priv->trans);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800416
417 goto out;
418
419 error:
Johannes Berg15b86bf2012-03-05 11:24:36 -0800420 priv->wowlan = false;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800421 iwlagn_prepare_restart(priv);
422 ieee80211_restart_hw(priv->hw);
423 out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800424 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800425 IWL_DEBUG_MAC80211(priv, "leave\n");
426
427 return ret;
428}
429
430static int iwlagn_mac_resume(struct ieee80211_hw *hw)
431{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200432 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800433 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
434 struct ieee80211_vif *vif;
435 unsigned long flags;
436 u32 base, status = 0xffffffff;
437 int ret = -EIO;
438
439 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -0800440 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800441
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700442 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
Wey-Yi Guy73356132011-11-10 06:55:11 -0800443 CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
444
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -0700445 base = priv->device_pointers.error_event_table;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800446 if (iwlagn_hw_valid_rtc_data_addr(base)) {
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700447 spin_lock_irqsave(&priv->trans->reg_lock, flags);
448 ret = iwl_grab_nic_access_silent(priv->trans);
Stanislaw Gruszkabfe4b802012-03-07 09:52:24 -0800449 if (likely(ret == 0)) {
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700450 iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, base);
451 status = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
452 iwl_release_nic_access(priv->trans);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800453 }
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700454 spin_unlock_irqrestore(&priv->trans->reg_lock, flags);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800455
456#ifdef CONFIG_IWLWIFI_DEBUGFS
457 if (ret == 0) {
Oliver Hartkoppa855f7e2012-03-25 08:43:24 +0200458 const struct fw_img *img;
459
David Spinadel6dfa8d02012-03-10 13:00:14 -0800460 img = &(priv->fw->img[IWL_UCODE_WOWLAN]);
461 if (!priv->wowlan_sram) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800462 priv->wowlan_sram =
David Spinadel6dfa8d02012-03-10 13:00:14 -0800463 kzalloc(img->sec[IWL_UCODE_SECTION_DATA].len,
Wey-Yi Guy73356132011-11-10 06:55:11 -0800464 GFP_KERNEL);
David Spinadel6dfa8d02012-03-10 13:00:14 -0800465 }
Wey-Yi Guy73356132011-11-10 06:55:11 -0800466
467 if (priv->wowlan_sram)
468 _iwl_read_targ_mem_words(
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700469 priv->trans, 0x800000,
David Spinadel6dfa8d02012-03-10 13:00:14 -0800470 priv->wowlan_sram,
471 img->sec[IWL_UCODE_SECTION_DATA].len / 4);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800472 }
473#endif
474 }
475
476 /* we'll clear ctx->vif during iwlagn_prepare_restart() */
477 vif = ctx->vif;
478
Johannes Berg15b86bf2012-03-05 11:24:36 -0800479 priv->wowlan = false;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800480
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700481 device_set_wakeup_enable(priv->trans->dev, false);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800482
483 iwlagn_prepare_restart(priv);
484
485 memset((void *)&ctx->active, 0, sizeof(ctx->active));
486 iwl_connection_init_rx_config(priv, ctx);
487 iwlagn_set_rxon_chain(priv, ctx);
488
Johannes Bergb1eea292012-03-06 13:30:42 -0800489 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800490 IWL_DEBUG_MAC80211(priv, "leave\n");
491
492 ieee80211_resume_disconnect(vif);
493
494 return 1;
495}
496
497#endif
498
David Spinadel50c1e9a2012-04-16 14:43:30 -0700499void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800500{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200501 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800502
Wey-Yi Guy73356132011-11-10 06:55:11 -0800503 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
504 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
505
506 if (iwlagn_tx_skb(priv, skb))
507 dev_kfree_skb_any(skb);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800508}
509
David Spinadel50c1e9a2012-04-16 14:43:30 -0700510void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
511 struct ieee80211_vif *vif,
512 struct ieee80211_key_conf *keyconf,
513 struct ieee80211_sta *sta,
514 u32 iv32, u16 *phase1key)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800515{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200516 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800517
518 iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
519}
520
David Spinadel50c1e9a2012-04-16 14:43:30 -0700521int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
522 struct ieee80211_vif *vif,
523 struct ieee80211_sta *sta,
524 struct ieee80211_key_conf *key)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800525{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200526 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800527 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
528 struct iwl_rxon_context *ctx = vif_priv->ctx;
529 int ret;
530 bool is_default_wep_key = false;
531
532 IWL_DEBUG_MAC80211(priv, "enter\n");
533
534 if (iwlagn_mod_params.sw_crypto) {
535 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
536 return -EOPNOTSUPP;
537 }
538
Johannes Berga7e12c82011-11-25 03:20:09 -0800539 switch (key->cipher) {
540 case WLAN_CIPHER_SUITE_TKIP:
541 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
542 /* fall through */
543 case WLAN_CIPHER_SUITE_CCMP:
544 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
545 break;
546 default:
547 break;
548 }
549
Wey-Yi Guy73356132011-11-10 06:55:11 -0800550 /*
551 * We could program these keys into the hardware as well, but we
552 * don't expect much multicast traffic in IBSS and having keys
553 * for more stations is probably more useful.
554 *
555 * Mark key TX-only and return 0.
556 */
557 if (vif->type == NL80211_IFTYPE_ADHOC &&
558 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
559 key->hw_key_idx = WEP_INVALID_OFFSET;
560 return 0;
561 }
562
563 /* If they key was TX-only, accept deletion */
564 if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
565 return 0;
566
Johannes Bergb1eea292012-03-06 13:30:42 -0800567 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800568 iwl_scan_cancel_timeout(priv, 100);
569
570 BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
571
572 /*
573 * If we are getting WEP group key and we didn't receive any key mapping
574 * so far, we are in legacy wep mode (group key only), otherwise we are
575 * in 1X mode.
576 * In legacy wep mode, we use another host command to the uCode.
577 */
578 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
579 key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
580 if (cmd == SET_KEY)
581 is_default_wep_key = !ctx->key_mapping_keys;
582 else
583 is_default_wep_key =
584 key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
585 }
586
587
588 switch (cmd) {
589 case SET_KEY:
590 if (is_default_wep_key) {
591 ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
592 break;
593 }
594 ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
595 if (ret) {
596 /*
597 * can't add key for RX, but we don't need it
598 * in the device for TX so still return 0
599 */
600 ret = 0;
601 key->hw_key_idx = WEP_INVALID_OFFSET;
602 }
603
604 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
605 break;
606 case DISABLE_KEY:
607 if (is_default_wep_key)
608 ret = iwl_remove_default_wep_key(priv, ctx, key);
609 else
610 ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
611
612 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
613 break;
614 default:
615 ret = -EINVAL;
616 }
617
Johannes Bergb1eea292012-03-06 13:30:42 -0800618 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800619 IWL_DEBUG_MAC80211(priv, "leave\n");
620
621 return ret;
622}
623
David Spinadel50c1e9a2012-04-16 14:43:30 -0700624int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
625 struct ieee80211_vif *vif,
626 enum ieee80211_ampdu_mlme_action action,
627 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
628 u8 buf_size)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800629{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200630 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800631 int ret = -EINVAL;
632 struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800633
634 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
635 sta->addr, tid);
636
Johannes Berg9e295112012-04-09 17:46:55 -0700637 if (!(priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE))
Wey-Yi Guy73356132011-11-10 06:55:11 -0800638 return -EACCES;
639
640 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -0800641 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800642
643 switch (action) {
644 case IEEE80211_AMPDU_RX_START:
Johannes Berg74289942011-12-13 00:07:40 -0800645 if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
646 break;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800647 IWL_DEBUG_HT(priv, "start Rx\n");
648 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
649 break;
650 case IEEE80211_AMPDU_RX_STOP:
651 IWL_DEBUG_HT(priv, "stop Rx\n");
652 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800653 break;
654 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700655 if (!priv->trans->ops->tx_agg_setup)
Johannes Berg9eae88f2012-03-15 13:26:52 -0700656 break;
Johannes Berg74289942011-12-13 00:07:40 -0800657 if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
658 break;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800659 IWL_DEBUG_HT(priv, "start Tx\n");
660 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
661 break;
662 case IEEE80211_AMPDU_TX_STOP:
663 IWL_DEBUG_HT(priv, "stop Tx\n");
664 ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
665 if ((ret == 0) && (priv->agg_tids_count > 0)) {
666 priv->agg_tids_count--;
667 IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
668 priv->agg_tids_count);
669 }
Johannes Bergb9ad70d2012-03-06 13:30:55 -0800670 if (!priv->agg_tids_count &&
Johannes Berg9e295112012-04-09 17:46:55 -0700671 priv->hw_params.use_rts_for_aggregation) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800672 /*
673 * switch off RTS/CTS if it was previously enabled
674 */
675 sta_priv->lq_sta.lq.general_params.flags &=
676 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
677 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
678 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
679 }
680 break;
681 case IEEE80211_AMPDU_TX_OPERATIONAL:
Emmanuel Grumbach822e8b22011-11-21 13:25:31 +0200682 ret = iwlagn_tx_agg_oper(priv, vif, sta, tid, buf_size);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800683 break;
684 }
Johannes Bergb1eea292012-03-06 13:30:42 -0800685 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800686 IWL_DEBUG_MAC80211(priv, "leave\n");
687 return ret;
688}
689
690static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
691 struct ieee80211_vif *vif,
692 struct ieee80211_sta *sta)
693{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200694 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800695 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
696 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
697 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800698 int ret;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800699 u8 sta_id;
700
Wey-Yi Guy73356132011-11-10 06:55:11 -0800701 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
702 sta->addr);
703 sta_priv->sta_id = IWL_INVALID_STATION;
704
705 atomic_set(&sta_priv->pending_frames, 0);
706 if (vif->type == NL80211_IFTYPE_AP)
707 sta_priv->client = true;
708
709 ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
710 is_ap, sta, &sta_id);
711 if (ret) {
712 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
713 sta->addr, ret);
714 /* Should we return success if return code is EEXIST ? */
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800715 return ret;
Wey-Yi Guy73356132011-11-10 06:55:11 -0800716 }
717
718 sta_priv->sta_id = sta_id;
719
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800720 return 0;
721}
722
723static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
724 struct ieee80211_vif *vif,
725 struct ieee80211_sta *sta)
726{
727 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
728 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
729 int ret;
730
Johannes Berg97420512012-03-07 09:52:42 -0800731 IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", sta->addr);
732
733 if (vif->type == NL80211_IFTYPE_STATION) {
734 /*
735 * Station will be removed from device when the RXON
736 * is set to unassociated -- just deactivate it here
737 * to avoid re-programming it.
738 */
739 ret = 0;
740 iwl_deactivate_station(priv, sta_priv->sta_id, sta->addr);
741 } else {
742 ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
743 if (ret)
744 IWL_DEBUG_QUIET_RFKILL(priv,
745 "Error removing station %pM\n", sta->addr);
746 }
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800747 return ret;
748}
749
David Spinadel50c1e9a2012-04-16 14:43:30 -0700750int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
751 struct ieee80211_vif *vif,
752 struct ieee80211_sta *sta,
753 enum ieee80211_sta_state old_state,
754 enum ieee80211_sta_state new_state)
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800755{
756 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Bergab0bd5b2012-03-05 11:24:47 -0800757 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800758 enum {
Johannes Bergab0bd5b2012-03-05 11:24:47 -0800759 NONE, ADD, REMOVE, HT_RATE_INIT, ADD_RATE_INIT,
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800760 } op = NONE;
761 int ret;
762
763 IWL_DEBUG_MAC80211(priv, "station %pM state change %d->%d\n",
764 sta->addr, old_state, new_state);
765
Johannes Bergb1eea292012-03-06 13:30:42 -0800766 mutex_lock(&priv->mutex);
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800767 if (vif->type == NL80211_IFTYPE_STATION) {
768 if (old_state == IEEE80211_STA_NOTEXIST &&
769 new_state == IEEE80211_STA_NONE)
770 op = ADD;
771 else if (old_state == IEEE80211_STA_NONE &&
772 new_state == IEEE80211_STA_NOTEXIST)
773 op = REMOVE;
774 else if (old_state == IEEE80211_STA_AUTH &&
775 new_state == IEEE80211_STA_ASSOC)
Johannes Bergab0bd5b2012-03-05 11:24:47 -0800776 op = HT_RATE_INIT;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800777 } else {
778 if (old_state == IEEE80211_STA_AUTH &&
779 new_state == IEEE80211_STA_ASSOC)
780 op = ADD_RATE_INIT;
781 else if (old_state == IEEE80211_STA_ASSOC &&
782 new_state == IEEE80211_STA_AUTH)
783 op = REMOVE;
784 }
785
786 switch (op) {
787 case ADD:
788 ret = iwlagn_mac_sta_add(hw, vif, sta);
789 break;
790 case REMOVE:
791 ret = iwlagn_mac_sta_remove(hw, vif, sta);
792 break;
793 case ADD_RATE_INIT:
794 ret = iwlagn_mac_sta_add(hw, vif, sta);
795 if (ret)
796 break;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800797 /* Initialize rate scaling */
798 IWL_DEBUG_INFO(priv,
799 "Initializing rate scaling for station %pM\n",
800 sta->addr);
801 iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
802 ret = 0;
803 break;
Johannes Bergab0bd5b2012-03-05 11:24:47 -0800804 case HT_RATE_INIT:
805 /* Initialize rate scaling */
806 ret = iwl_sta_update_ht(priv, vif_priv->ctx, sta);
807 if (ret)
808 break;
809 IWL_DEBUG_INFO(priv,
810 "Initializing rate scaling for station %pM\n",
811 sta->addr);
812 iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
813 ret = 0;
814 break;
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800815 default:
816 ret = 0;
817 break;
818 }
819
820 /*
821 * mac80211 might WARN if we fail, but due the way we
822 * (badly) handle hard rfkill, we might fail here
823 */
Don Fry83626402012-03-07 09:52:37 -0800824 if (iwl_is_rfkill(priv))
Johannes Bergfb5fe5b2012-03-05 11:24:29 -0800825 ret = 0;
826
Johannes Bergb1eea292012-03-06 13:30:42 -0800827 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800828 IWL_DEBUG_MAC80211(priv, "leave\n");
829
830 return ret;
831}
832
David Spinadel50c1e9a2012-04-16 14:43:30 -0700833void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
834 struct ieee80211_channel_switch *ch_switch)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800835{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200836 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800837 const struct iwl_channel_info *ch_info;
838 struct ieee80211_conf *conf = &hw->conf;
839 struct ieee80211_channel *channel = ch_switch->channel;
840 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
841 /*
842 * MULTI-FIXME
843 * When we add support for multiple interfaces, we need to
844 * revisit this. The channel switch command in the device
845 * only affects the BSS context, but what does that really
846 * mean? And what if we get a CSA on the second interface?
847 * This needs a lot of work.
848 */
849 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
850 u16 ch;
851
852 IWL_DEBUG_MAC80211(priv, "enter\n");
853
Johannes Bergb1eea292012-03-06 13:30:42 -0800854 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800855
Don Fry83626402012-03-07 09:52:37 -0800856 if (iwl_is_rfkill(priv))
Wey-Yi Guy73356132011-11-10 06:55:11 -0800857 goto out;
858
Don Fry83626402012-03-07 09:52:37 -0800859 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
860 test_bit(STATUS_SCANNING, &priv->status) ||
861 test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
Wey-Yi Guy73356132011-11-10 06:55:11 -0800862 goto out;
863
864 if (!iwl_is_associated_ctx(ctx))
865 goto out;
866
Johannes Berge9676692012-04-10 14:10:28 -0700867 if (!priv->lib->set_channel_switch)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800868 goto out;
869
870 ch = channel->hw_value;
871 if (le16_to_cpu(ctx->active.channel) == ch)
872 goto out;
873
874 ch_info = iwl_get_channel_info(priv, channel->band, ch);
875 if (!is_channel_valid(ch_info)) {
876 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
877 goto out;
878 }
879
Wey-Yi Guy73356132011-11-10 06:55:11 -0800880 priv->current_ht_config.smps = conf->smps_mode;
881
882 /* Configure HT40 channels */
883 ctx->ht.enabled = conf_is_ht(conf);
Wey-Yi Guy137ce792011-11-22 16:23:35 -0800884 if (ctx->ht.enabled)
885 iwlagn_config_ht40(conf, ctx);
886 else
Wey-Yi Guy73356132011-11-10 06:55:11 -0800887 ctx->ht.is_40mhz = false;
888
889 if ((le16_to_cpu(ctx->staging.channel) != ch))
890 ctx->staging.flags = 0;
891
892 iwl_set_rxon_channel(priv, channel, ctx);
893 iwl_set_rxon_ht(priv, ht_conf);
894 iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
895
Wey-Yi Guy73356132011-11-10 06:55:11 -0800896 /*
897 * at this point, staging_rxon has the
898 * configuration for channel switch
899 */
Don Fry83626402012-03-07 09:52:37 -0800900 set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800901 priv->switch_channel = cpu_to_le16(ch);
Johannes Berge9676692012-04-10 14:10:28 -0700902 if (priv->lib->set_channel_switch(priv, ch_switch)) {
Don Fry83626402012-03-07 09:52:37 -0800903 clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800904 priv->switch_channel = 0;
905 ieee80211_chswitch_done(ctx->vif, false);
906 }
907
908out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800909 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800910 IWL_DEBUG_MAC80211(priv, "leave\n");
911}
912
Meenakshi Venkataramanbedec3a2012-03-13 17:47:23 -0700913void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
914{
915 /*
916 * MULTI-FIXME
917 * See iwlagn_mac_channel_switch.
918 */
919 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
920
921 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
922 return;
923
924 if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
925 ieee80211_chswitch_done(ctx->vif, is_success);
926}
927
David Spinadel50c1e9a2012-04-16 14:43:30 -0700928void iwlagn_configure_filter(struct ieee80211_hw *hw,
929 unsigned int changed_flags,
930 unsigned int *total_flags,
931 u64 multicast)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800932{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200933 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800934 __le32 filter_or = 0, filter_nand = 0;
935 struct iwl_rxon_context *ctx;
936
937#define CHK(test, flag) do { \
938 if (*total_flags & (test)) \
939 filter_or |= (flag); \
940 else \
941 filter_nand |= (flag); \
942 } while (0)
943
944 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
945 changed_flags, *total_flags);
946
947 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
948 /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
949 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
950 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
951
952#undef CHK
953
Johannes Bergb1eea292012-03-06 13:30:42 -0800954 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800955
956 for_each_context(priv, ctx) {
957 ctx->staging.filter_flags &= ~filter_nand;
958 ctx->staging.filter_flags |= filter_or;
959
960 /*
961 * Not committing directly because hardware can perform a scan,
962 * but we'll eventually commit the filter flags change anyway.
963 */
964 }
965
Johannes Bergb1eea292012-03-06 13:30:42 -0800966 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800967
968 /*
969 * Receiving all multicast frames is always enabled by the
970 * default flags setup in iwl_connection_init_rx_config()
971 * since we currently do not support programming multicast
972 * filters into the device.
973 */
974 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
975 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
976}
977
David Spinadel50c1e9a2012-04-16 14:43:30 -0700978void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
Wey-Yi Guy73356132011-11-10 06:55:11 -0800979{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200980 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800981
Johannes Bergb1eea292012-03-06 13:30:42 -0800982 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -0800983 IWL_DEBUG_MAC80211(priv, "enter\n");
984
Don Fry83626402012-03-07 09:52:37 -0800985 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800986 IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
987 goto done;
988 }
Don Fry83626402012-03-07 09:52:37 -0800989 if (iwl_is_rfkill(priv)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -0800990 IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
991 goto done;
992 }
993
994 /*
995 * mac80211 will not push any more frames for transmit
996 * until the flush is completed
997 */
998 if (drop) {
999 IWL_DEBUG_MAC80211(priv, "send flush command\n");
1000 if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
1001 IWL_ERR(priv, "flush request fail\n");
1002 goto done;
1003 }
1004 }
1005 IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001006 iwl_trans_wait_tx_queue_empty(priv->trans);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001007done:
Johannes Bergb1eea292012-03-06 13:30:42 -08001008 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001009 IWL_DEBUG_MAC80211(priv, "leave\n");
1010}
1011
1012static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
1013 struct ieee80211_channel *channel,
1014 enum nl80211_channel_type channel_type,
1015 int duration)
1016{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001017 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001018 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
1019 int err = 0;
1020
Johannes Berga18f61b2012-03-15 13:26:53 -07001021 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
Wey-Yi Guy73356132011-11-10 06:55:11 -08001022 return -EOPNOTSUPP;
1023
1024 if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
1025 return -EOPNOTSUPP;
1026
1027 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001028 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001029
Don Fry83626402012-03-07 09:52:37 -08001030 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Wey-Yi Guy73356132011-11-10 06:55:11 -08001031 err = -EBUSY;
1032 goto out;
1033 }
1034
1035 priv->hw_roc_channel = channel;
1036 priv->hw_roc_chantype = channel_type;
Johannes Berg3ddf6be2011-11-10 06:55:21 -08001037 /* convert from ms to TU */
1038 priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001039 priv->hw_roc_start_notified = false;
1040 cancel_delayed_work(&priv->hw_roc_disable_work);
1041
1042 if (!ctx->is_active) {
Johannes Berga69cd042011-11-10 06:55:13 -08001043 static const struct iwl_qos_info default_qos_data = {
1044 .def_qos_parm = {
1045 .ac[0] = {
1046 .cw_min = cpu_to_le16(3),
1047 .cw_max = cpu_to_le16(7),
1048 .aifsn = 2,
1049 .edca_txop = cpu_to_le16(1504),
1050 },
1051 .ac[1] = {
1052 .cw_min = cpu_to_le16(7),
1053 .cw_max = cpu_to_le16(15),
1054 .aifsn = 2,
1055 .edca_txop = cpu_to_le16(3008),
1056 },
1057 .ac[2] = {
1058 .cw_min = cpu_to_le16(15),
1059 .cw_max = cpu_to_le16(1023),
1060 .aifsn = 3,
1061 },
1062 .ac[3] = {
1063 .cw_min = cpu_to_le16(15),
1064 .cw_max = cpu_to_le16(1023),
1065 .aifsn = 7,
1066 },
1067 },
1068 };
1069
Wey-Yi Guy73356132011-11-10 06:55:11 -08001070 ctx->is_active = true;
Johannes Berga69cd042011-11-10 06:55:13 -08001071 ctx->qos_data = default_qos_data;
Wey-Yi Guy73356132011-11-10 06:55:11 -08001072 ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
1073 memcpy(ctx->staging.node_addr,
1074 priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
1075 ETH_ALEN);
1076 memcpy(ctx->staging.bssid_addr,
1077 priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
1078 ETH_ALEN);
1079 err = iwlagn_commit_rxon(priv, ctx);
1080 if (err)
1081 goto out;
1082 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
1083 RXON_FILTER_PROMISC_MSK |
1084 RXON_FILTER_CTL2HOST_MSK;
1085
1086 err = iwlagn_commit_rxon(priv, ctx);
1087 if (err) {
1088 iwlagn_disable_roc(priv);
1089 goto out;
1090 }
1091 priv->hw_roc_setup = true;
1092 }
1093
1094 err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
1095 if (err)
1096 iwlagn_disable_roc(priv);
1097
1098 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001099 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001100 IWL_DEBUG_MAC80211(priv, "leave\n");
1101
1102 return err;
1103}
1104
David Spinadel50c1e9a2012-04-16 14:43:30 -07001105int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
Wey-Yi Guy73356132011-11-10 06:55:11 -08001106{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001107 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001108
Johannes Berga18f61b2012-03-15 13:26:53 -07001109 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
Wey-Yi Guy73356132011-11-10 06:55:11 -08001110 return -EOPNOTSUPP;
1111
1112 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001113 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001114 iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
1115 iwlagn_disable_roc(priv);
Johannes Bergb1eea292012-03-06 13:30:42 -08001116 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001117 IWL_DEBUG_MAC80211(priv, "leave\n");
1118
1119 return 0;
1120}
1121
David Spinadel50c1e9a2012-04-16 14:43:30 -07001122void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
1123 enum ieee80211_rssi_event rssi_event)
Wey-Yi Guy73356132011-11-10 06:55:11 -08001124{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001125 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001126
1127 IWL_DEBUG_MAC80211(priv, "enter\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001128 mutex_lock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001129
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001130 if (priv->cfg->bt_params &&
1131 priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guy73356132011-11-10 06:55:11 -08001132 if (rssi_event == RSSI_EVENT_LOW)
1133 priv->bt_enable_pspoll = true;
1134 else if (rssi_event == RSSI_EVENT_HIGH)
1135 priv->bt_enable_pspoll = false;
1136
1137 iwlagn_send_advance_bt_config(priv);
1138 } else {
1139 IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
1140 "ignoring RSSI callback\n");
1141 }
1142
Johannes Bergb1eea292012-03-06 13:30:42 -08001143 mutex_unlock(&priv->mutex);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001144 IWL_DEBUG_MAC80211(priv, "leave\n");
1145}
1146
David Spinadel50c1e9a2012-04-16 14:43:30 -07001147int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
1148 struct ieee80211_sta *sta, bool set)
Wey-Yi Guy73356132011-11-10 06:55:11 -08001149{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001150 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001151
Johannes Berg1ee158d2012-02-17 10:07:44 -08001152 queue_work(priv->workqueue, &priv->beacon_update);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001153
1154 return 0;
1155}
1156
David Spinadel50c1e9a2012-04-16 14:43:30 -07001157int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
1158 struct ieee80211_vif *vif, u16 queue,
1159 const struct ieee80211_tx_queue_params *params)
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001160{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001161 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001162 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1163 struct iwl_rxon_context *ctx = vif_priv->ctx;
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001164 int q;
1165
1166 if (WARN_ON(!ctx))
1167 return -EINVAL;
1168
1169 IWL_DEBUG_MAC80211(priv, "enter\n");
1170
Don Fry83626402012-03-07 09:52:37 -08001171 if (!iwl_is_ready_rf(priv)) {
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001172 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
1173 return -EIO;
1174 }
1175
1176 if (queue >= AC_NUM) {
1177 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
1178 return 0;
1179 }
1180
1181 q = AC_NUM - 1 - queue;
1182
Johannes Bergb1eea292012-03-06 13:30:42 -08001183 mutex_lock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001184
1185 ctx->qos_data.def_qos_parm.ac[q].cw_min =
1186 cpu_to_le16(params->cw_min);
1187 ctx->qos_data.def_qos_parm.ac[q].cw_max =
1188 cpu_to_le16(params->cw_max);
1189 ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
1190 ctx->qos_data.def_qos_parm.ac[q].edca_txop =
1191 cpu_to_le16((params->txop * 32));
1192
1193 ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
1194
Johannes Bergb1eea292012-03-06 13:30:42 -08001195 mutex_unlock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001196
1197 IWL_DEBUG_MAC80211(priv, "leave\n");
1198 return 0;
1199}
1200
David Spinadel50c1e9a2012-04-16 14:43:30 -07001201int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001202{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001203 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001204
1205 return priv->ibss_manager == IWL_IBSS_MANAGER;
1206}
1207
1208static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1209{
1210 iwl_connection_init_rx_config(priv, ctx);
1211
1212 iwlagn_set_rxon_chain(priv, ctx);
1213
1214 return iwlagn_commit_rxon(priv, ctx);
1215}
1216
David Spinadel50c1e9a2012-04-16 14:43:30 -07001217int iwl_setup_interface(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001218{
1219 struct ieee80211_vif *vif = ctx->vif;
1220 int err;
1221
Johannes Bergb1eea292012-03-06 13:30:42 -08001222 lockdep_assert_held(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001223
1224 /*
1225 * This variable will be correct only when there's just
1226 * a single context, but all code using it is for hardware
1227 * that supports only one context.
1228 */
1229 priv->iw_mode = vif->type;
1230
1231 ctx->is_active = true;
1232
1233 err = iwl_set_mode(priv, ctx);
1234 if (err) {
1235 if (!ctx->always_active)
1236 ctx->is_active = false;
1237 return err;
1238 }
1239
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001240 if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist &&
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001241 vif->type == NL80211_IFTYPE_ADHOC) {
1242 /*
1243 * pretend to have high BT traffic as long as we
1244 * are operating in IBSS mode, as this will cause
1245 * the rate scaling etc. to behave as intended.
1246 */
1247 priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
1248 }
1249
1250 return 0;
1251}
1252
1253static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
1254 struct ieee80211_vif *vif)
1255{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001256 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001257 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1258 struct iwl_rxon_context *tmp, *ctx = NULL;
1259 int err;
1260 enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
1261
1262 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
1263 viftype, vif->addr);
1264
1265 cancel_delayed_work_sync(&priv->hw_roc_disable_work);
1266
Johannes Bergb1eea292012-03-06 13:30:42 -08001267 mutex_lock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001268
1269 iwlagn_disable_roc(priv);
1270
Don Fry83626402012-03-07 09:52:37 -08001271 if (!iwl_is_ready_rf(priv)) {
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001272 IWL_WARN(priv, "Try to add interface when device not ready\n");
1273 err = -EINVAL;
1274 goto out;
1275 }
1276
1277 for_each_context(priv, tmp) {
1278 u32 possible_modes =
1279 tmp->interface_modes | tmp->exclusive_interface_modes;
1280
1281 if (tmp->vif) {
1282 /* check if this busy context is exclusive */
1283 if (tmp->exclusive_interface_modes &
1284 BIT(tmp->vif->type)) {
1285 err = -EINVAL;
1286 goto out;
1287 }
1288 continue;
1289 }
1290
1291 if (!(possible_modes & BIT(viftype)))
1292 continue;
1293
1294 /* have maybe usable context w/o interface */
1295 ctx = tmp;
1296 break;
1297 }
1298
1299 if (!ctx) {
1300 err = -EOPNOTSUPP;
1301 goto out;
1302 }
1303
1304 vif_priv->ctx = ctx;
1305 ctx->vif = vif;
1306
1307 err = iwl_setup_interface(priv, ctx);
1308 if (!err)
1309 goto out;
1310
1311 ctx->vif = NULL;
1312 priv->iw_mode = NL80211_IFTYPE_STATION;
1313 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001314 mutex_unlock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001315
1316 IWL_DEBUG_MAC80211(priv, "leave\n");
1317 return err;
1318}
1319
David Spinadel50c1e9a2012-04-16 14:43:30 -07001320void iwl_teardown_interface(struct iwl_priv *priv,
1321 struct ieee80211_vif *vif,
1322 bool mode_change)
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001323{
1324 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1325
Johannes Bergb1eea292012-03-06 13:30:42 -08001326 lockdep_assert_held(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001327
1328 if (priv->scan_vif == vif) {
1329 iwl_scan_cancel_timeout(priv, 200);
1330 iwl_force_scan_end(priv);
1331 }
1332
1333 if (!mode_change) {
1334 iwl_set_mode(priv, ctx);
1335 if (!ctx->always_active)
1336 ctx->is_active = false;
1337 }
1338
1339 /*
1340 * When removing the IBSS interface, overwrite the
1341 * BT traffic load with the stored one from the last
1342 * notification, if any. If this is a device that
1343 * doesn't implement this, this has no effect since
1344 * both values are the same and zero.
1345 */
1346 if (vif->type == NL80211_IFTYPE_ADHOC)
1347 priv->bt_traffic_load = priv->last_bt_traffic_load;
1348}
1349
1350static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw,
1351 struct ieee80211_vif *vif)
1352{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001353 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001354 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1355
1356 IWL_DEBUG_MAC80211(priv, "enter\n");
1357
Johannes Bergb1eea292012-03-06 13:30:42 -08001358 mutex_lock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001359
1360 if (WARN_ON(ctx->vif != vif)) {
1361 struct iwl_rxon_context *tmp;
1362 IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif);
1363 for_each_context(priv, tmp)
1364 IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n",
1365 tmp->ctxid, tmp, tmp->vif);
1366 }
1367 ctx->vif = NULL;
1368
1369 iwl_teardown_interface(priv, vif, false);
1370
Johannes Bergb1eea292012-03-06 13:30:42 -08001371 mutex_unlock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001372
1373 IWL_DEBUG_MAC80211(priv, "leave\n");
1374
1375}
1376
1377static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
1378 struct ieee80211_vif *vif,
1379 enum nl80211_iftype newtype, bool newp2p)
1380{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001381 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001382 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1383 struct iwl_rxon_context *bss_ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1384 struct iwl_rxon_context *tmp;
1385 enum nl80211_iftype newviftype = newtype;
1386 u32 interface_modes;
1387 int err;
1388
1389 IWL_DEBUG_MAC80211(priv, "enter\n");
1390
1391 newtype = ieee80211_iftype_p2p(newtype, newp2p);
1392
Johannes Bergb1eea292012-03-06 13:30:42 -08001393 mutex_lock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001394
Don Fry83626402012-03-07 09:52:37 -08001395 if (!ctx->vif || !iwl_is_ready_rf(priv)) {
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001396 /*
1397 * Huh? But wait ... this can maybe happen when
1398 * we're in the middle of a firmware restart!
1399 */
1400 err = -EBUSY;
1401 goto out;
1402 }
1403
1404 interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
1405
1406 if (!(interface_modes & BIT(newtype))) {
1407 err = -EBUSY;
1408 goto out;
1409 }
1410
1411 /*
1412 * Refuse a change that should be done by moving from the PAN
1413 * context to the BSS context instead, if the BSS context is
1414 * available and can support the new interface type.
1415 */
1416 if (ctx->ctxid == IWL_RXON_CTX_PAN && !bss_ctx->vif &&
1417 (bss_ctx->interface_modes & BIT(newtype) ||
1418 bss_ctx->exclusive_interface_modes & BIT(newtype))) {
1419 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
1420 err = -EBUSY;
1421 goto out;
1422 }
1423
1424 if (ctx->exclusive_interface_modes & BIT(newtype)) {
1425 for_each_context(priv, tmp) {
1426 if (ctx == tmp)
1427 continue;
1428
1429 if (!tmp->vif)
1430 continue;
1431
1432 /*
1433 * The current mode switch would be exclusive, but
1434 * another context is active ... refuse the switch.
1435 */
1436 err = -EBUSY;
1437 goto out;
1438 }
1439 }
1440
1441 /* success */
1442 iwl_teardown_interface(priv, vif, true);
1443 vif->type = newviftype;
1444 vif->p2p = newp2p;
1445 err = iwl_setup_interface(priv, ctx);
1446 WARN_ON(err);
1447 /*
1448 * We've switched internally, but submitting to the
1449 * device may have failed for some reason. Mask this
1450 * error, because otherwise mac80211 will not switch
1451 * (and set the interface type back) and we'll be
1452 * out of sync with it.
1453 */
1454 err = 0;
1455
1456 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001457 mutex_unlock(&priv->mutex);
Wey-Yi Guy0b7a4c72011-11-10 06:55:14 -08001458 IWL_DEBUG_MAC80211(priv, "leave\n");
1459
1460 return err;
1461}
1462
David Spinadel50c1e9a2012-04-16 14:43:30 -07001463int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
1464 struct ieee80211_vif *vif,
1465 struct cfg80211_scan_request *req)
Wey-Yi Guyba4c5312011-11-10 06:55:15 -08001466{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001467 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guyba4c5312011-11-10 06:55:15 -08001468 int ret;
1469
1470 IWL_DEBUG_MAC80211(priv, "enter\n");
1471
1472 if (req->n_channels == 0)
1473 return -EINVAL;
1474
Johannes Bergb1eea292012-03-06 13:30:42 -08001475 mutex_lock(&priv->mutex);
Wey-Yi Guyba4c5312011-11-10 06:55:15 -08001476
1477 /*
1478 * If an internal scan is in progress, just set
1479 * up the scan_request as per above.
1480 */
1481 if (priv->scan_type != IWL_SCAN_NORMAL) {
1482 IWL_DEBUG_SCAN(priv,
1483 "SCAN request during internal scan - defer\n");
1484 priv->scan_request = req;
1485 priv->scan_vif = vif;
1486 ret = 0;
1487 } else {
1488 priv->scan_request = req;
1489 priv->scan_vif = vif;
1490 /*
1491 * mac80211 will only ask for one band at a time
1492 * so using channels[0] here is ok
1493 */
1494 ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
1495 req->channels[0]->band);
1496 if (ret) {
1497 priv->scan_request = NULL;
1498 priv->scan_vif = NULL;
1499 }
1500 }
1501
1502 IWL_DEBUG_MAC80211(priv, "leave\n");
1503
Johannes Bergb1eea292012-03-06 13:30:42 -08001504 mutex_unlock(&priv->mutex);
Wey-Yi Guyba4c5312011-11-10 06:55:15 -08001505
1506 return ret;
1507}
1508
Wey-Yi Guy76b29332011-11-10 06:55:16 -08001509static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1510{
Johannes Berg9451ca12012-03-05 11:24:23 -08001511 struct iwl_addsta_cmd cmd = {
1512 .mode = STA_CONTROL_MODIFY_MSK,
1513 .station_flags_msk = STA_FLG_PWR_SAVE_MSK,
1514 .sta.sta_id = sta_id,
1515 };
Wey-Yi Guy76b29332011-11-10 06:55:16 -08001516
Johannes Berg9451ca12012-03-05 11:24:23 -08001517 iwl_send_add_sta(priv, &cmd, CMD_ASYNC);
Wey-Yi Guy76b29332011-11-10 06:55:16 -08001518}
1519
David Spinadel50c1e9a2012-04-16 14:43:30 -07001520void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
Wey-Yi Guy76b29332011-11-10 06:55:16 -08001521 struct ieee80211_vif *vif,
1522 enum sta_notify_cmd cmd,
1523 struct ieee80211_sta *sta)
1524{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001525 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy76b29332011-11-10 06:55:16 -08001526 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
1527 int sta_id;
1528
1529 IWL_DEBUG_MAC80211(priv, "enter\n");
1530
1531 switch (cmd) {
1532 case STA_NOTIFY_SLEEP:
1533 WARN_ON(!sta_priv->client);
1534 sta_priv->asleep = true;
1535 if (atomic_read(&sta_priv->pending_frames) > 0)
1536 ieee80211_sta_block_awake(hw, sta, true);
1537 break;
1538 case STA_NOTIFY_AWAKE:
1539 WARN_ON(!sta_priv->client);
1540 if (!sta_priv->asleep)
1541 break;
1542 sta_priv->asleep = false;
1543 sta_id = iwl_sta_id(sta);
1544 if (sta_id != IWL_INVALID_STATION)
1545 iwl_sta_modify_ps_wake(priv, sta_id);
1546 break;
1547 default:
1548 break;
1549 }
1550 IWL_DEBUG_MAC80211(priv, "leave\n");
1551}
1552
Wey-Yi Guy73356132011-11-10 06:55:11 -08001553struct ieee80211_ops iwlagn_hw_ops = {
1554 .tx = iwlagn_mac_tx,
1555 .start = iwlagn_mac_start,
1556 .stop = iwlagn_mac_stop,
1557#ifdef CONFIG_PM_SLEEP
1558 .suspend = iwlagn_mac_suspend,
1559 .resume = iwlagn_mac_resume,
1560#endif
1561 .add_interface = iwlagn_mac_add_interface,
1562 .remove_interface = iwlagn_mac_remove_interface,
1563 .change_interface = iwlagn_mac_change_interface,
1564 .config = iwlagn_mac_config,
1565 .configure_filter = iwlagn_configure_filter,
1566 .set_key = iwlagn_mac_set_key,
1567 .update_tkip_key = iwlagn_mac_update_tkip_key,
1568 .set_rekey_data = iwlagn_mac_set_rekey_data,
1569 .conf_tx = iwlagn_mac_conf_tx,
1570 .bss_info_changed = iwlagn_bss_info_changed,
1571 .ampdu_action = iwlagn_mac_ampdu_action,
1572 .hw_scan = iwlagn_mac_hw_scan,
1573 .sta_notify = iwlagn_mac_sta_notify,
Johannes Bergfb5fe5b2012-03-05 11:24:29 -08001574 .sta_state = iwlagn_mac_sta_state,
Wey-Yi Guy73356132011-11-10 06:55:11 -08001575 .channel_switch = iwlagn_mac_channel_switch,
1576 .flush = iwlagn_mac_flush,
1577 .tx_last_beacon = iwlagn_mac_tx_last_beacon,
1578 .remain_on_channel = iwlagn_mac_remain_on_channel,
1579 .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
1580 .rssi_callback = iwlagn_mac_rssi_callback,
1581 CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd)
1582 CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump)
Wey-Yi Guy73356132011-11-10 06:55:11 -08001583 .set_tim = iwlagn_mac_set_tim,
1584};
1585
1586/* This function both allocates and initializes hw and priv. */
1587struct ieee80211_hw *iwl_alloc_all(void)
1588{
1589 struct iwl_priv *priv;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001590 struct iwl_op_mode *op_mode;
Wey-Yi Guy73356132011-11-10 06:55:11 -08001591 /* mac80211 allocates memory for this device instance, including
1592 * space for this driver's private structure */
1593 struct ieee80211_hw *hw;
1594
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001595 hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) +
1596 sizeof(struct iwl_op_mode), &iwlagn_hw_ops);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001597 if (!hw)
1598 goto out;
1599
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001600 op_mode = hw->priv;
1601 priv = IWL_OP_MODE_GET_DVM(op_mode);
Wey-Yi Guy73356132011-11-10 06:55:11 -08001602 priv->hw = hw;
1603
1604out:
1605 return hw;
1606}