]>
Commit | Line | Data |
---|---|---|
7335613a WYG |
1 | /****************************************************************************** |
2 | * | |
128e63ef | 3 | * Copyright(c) 2003 - 2013 Intel Corporation. All rights reserved. |
7335613a WYG |
4 | * |
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> | |
7335613a WYG |
38 | #include <linux/etherdevice.h> |
39 | #include <linux/if_arp.h> | |
40 | ||
53e1116e | 41 | #include <net/ieee80211_radiotap.h> |
7335613a WYG |
42 | #include <net/mac80211.h> |
43 | ||
44 | #include <asm/div64.h> | |
45 | ||
7335613a | 46 | #include "iwl-io.h" |
7335613a | 47 | #include "iwl-trans.h" |
d0f76d68 | 48 | #include "iwl-op-mode.h" |
65de7e84 | 49 | #include "iwl-modparams.h" |
7335613a | 50 | |
1023fdc4 JB |
51 | #include "dev.h" |
52 | #include "calib.h" | |
53 | #include "agn.h" | |
54 | ||
7335613a WYG |
55 | /***************************************************************************** |
56 | * | |
57 | * mac80211 entry point functions | |
58 | * | |
59 | *****************************************************************************/ | |
60 | ||
61 | static 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 | ||
72 | static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = { | |
73 | { | |
74 | .max = 2, | |
75 | .types = BIT(NL80211_IFTYPE_STATION), | |
76 | }, | |
77 | }; | |
78 | ||
79 | static 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 | ||
91 | static 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 | ||
102 | static const struct ieee80211_iface_combination | |
103 | iwlagn_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 | ||
117 | static const struct ieee80211_iface_combination | |
118 | iwlagn_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 | */ | |
136 | int iwlagn_mac_setup_register(struct iwl_priv *priv, | |
0692fe41 | 137 | const struct iwl_ucode_capabilities *capa) |
7335613a WYG |
138 | { |
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 | | |
c65dd147 | 148 | IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC | |
7335613a | 149 | IEEE80211_HW_SPECTRUM_MGMT | |
1479177b JB |
150 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
151 | IEEE80211_HW_QUEUE_CONTROL | | |
152 | IEEE80211_HW_SUPPORTS_PS | | |
153 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | | |
f1e3e051 | 154 | IEEE80211_HW_WANT_MONITOR_VIF; |
1479177b JB |
155 | |
156 | hw->offchannel_tx_hw_queue = IWL_AUX_QUEUE; | |
53e1116e | 157 | hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FMT; |
7335613a WYG |
158 | |
159 | /* | |
160 | * Including the following line will crash some AP's. This | |
161 | * workaround removes the stimulus which causes the crash until | |
162 | * the AP software can be fixed. | |
163 | hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF; | |
164 | */ | |
165 | ||
b7998c8b | 166 | if (priv->nvm_data->sku_cap_11n_enable) |
7335613a WYG |
167 | hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | |
168 | IEEE80211_HW_SUPPORTS_STATIC_SMPS; | |
169 | ||
686681b0 JB |
170 | /* |
171 | * Enable 11w if advertised by firmware and software crypto | |
172 | * is not enabled (as the firmware will interpret some mgmt | |
173 | * packets, so enabling it with software crypto isn't safe) | |
174 | */ | |
175 | if (priv->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP && | |
176 | !iwlwifi_mod_params.sw_crypto) | |
7335613a WYG |
177 | hw->flags |= IEEE80211_HW_MFP_CAPABLE; |
178 | ||
179 | hw->sta_data_size = sizeof(struct iwl_station_priv); | |
180 | hw->vif_data_size = sizeof(struct iwl_vif_priv); | |
181 | ||
182 | for_each_context(priv, ctx) { | |
183 | hw->wiphy->interface_modes |= ctx->interface_modes; | |
184 | hw->wiphy->interface_modes |= ctx->exclusive_interface_modes; | |
185 | } | |
186 | ||
187 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); | |
188 | ||
189 | if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) { | |
190 | hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p; | |
191 | hw->wiphy->n_iface_combinations = | |
192 | ARRAY_SIZE(iwlagn_iface_combinations_p2p); | |
193 | } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) { | |
194 | hw->wiphy->iface_combinations = | |
195 | iwlagn_iface_combinations_dualmode; | |
196 | hw->wiphy->n_iface_combinations = | |
197 | ARRAY_SIZE(iwlagn_iface_combinations_dualmode); | |
198 | } | |
199 | ||
da0cabb8 | 200 | hw->wiphy->max_remain_on_channel_duration = 500; |
7335613a WYG |
201 | |
202 | hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY | | |
203 | WIPHY_FLAG_DISABLE_BEACON_HINTS | | |
204 | WIPHY_FLAG_IBSS_RSN; | |
205 | ||
fcb6ff5e | 206 | #ifdef CONFIG_PM_SLEEP |
6dfa8d01 | 207 | if (priv->fw->img[IWL_UCODE_WOWLAN].sec[0].len && |
ddaf5a5b JB |
208 | priv->trans->ops->d3_suspend && |
209 | priv->trans->ops->d3_resume && | |
68e8dfda | 210 | device_can_wakeup(priv->trans->dev)) { |
964dc9e2 JB |
211 | priv->wowlan_support.flags = WIPHY_WOWLAN_MAGIC_PKT | |
212 | WIPHY_WOWLAN_DISCONNECT | | |
213 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | | |
214 | WIPHY_WOWLAN_RFKILL_RELEASE; | |
65de7e84 | 215 | if (!iwlwifi_mod_params.sw_crypto) |
964dc9e2 | 216 | priv->wowlan_support.flags |= |
7335613a WYG |
217 | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
218 | WIPHY_WOWLAN_GTK_REKEY_FAILURE; | |
219 | ||
964dc9e2 JB |
220 | priv->wowlan_support.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS; |
221 | priv->wowlan_support.pattern_min_len = | |
7335613a | 222 | IWLAGN_WOWLAN_MIN_PATTERN_LEN; |
964dc9e2 | 223 | priv->wowlan_support.pattern_max_len = |
7335613a | 224 | IWLAGN_WOWLAN_MAX_PATTERN_LEN; |
964dc9e2 | 225 | hw->wiphy->wowlan = &priv->wowlan_support; |
7335613a | 226 | } |
fcb6ff5e | 227 | #endif |
7335613a | 228 | |
65de7e84 | 229 | if (iwlwifi_mod_params.power_save) |
7335613a WYG |
230 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
231 | else | |
232 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; | |
233 | ||
234 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; | |
4f9bfbb1 DS |
235 | /* we create the 802.11 header and a max-length SSID element */ |
236 | hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 34; | |
7335613a | 237 | |
1479177b JB |
238 | /* |
239 | * We don't use all queues: 4 and 9 are unused and any | |
240 | * aggregation queue gets mapped down to the AC queue. | |
241 | */ | |
242 | hw->queues = IWLAGN_FIRST_AMPDU_QUEUE; | |
7335613a WYG |
243 | |
244 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; | |
245 | ||
b7998c8b | 246 | if (priv->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels) |
7335613a | 247 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
b7998c8b EL |
248 | &priv->nvm_data->bands[IEEE80211_BAND_2GHZ]; |
249 | if (priv->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) | |
7335613a | 250 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
b7998c8b | 251 | &priv->nvm_data->bands[IEEE80211_BAND_5GHZ]; |
7335613a | 252 | |
68e8dfda | 253 | hw->wiphy->hw_version = priv->trans->hw_id; |
0ba958eb | 254 | |
7335613a WYG |
255 | iwl_leds_init(priv); |
256 | ||
257 | ret = ieee80211_register_hw(priv->hw); | |
258 | if (ret) { | |
259 | IWL_ERR(priv, "Failed to register hw (error %d)\n", ret); | |
0e1fa7ef | 260 | iwl_leds_exit(priv); |
7335613a WYG |
261 | return ret; |
262 | } | |
263 | priv->mac80211_registered = 1; | |
264 | ||
265 | return 0; | |
266 | } | |
267 | ||
09af1403 DF |
268 | void iwlagn_mac_unregister(struct iwl_priv *priv) |
269 | { | |
270 | if (!priv->mac80211_registered) | |
271 | return; | |
272 | iwl_leds_exit(priv); | |
273 | ieee80211_unregister_hw(priv->hw); | |
274 | priv->mac80211_registered = 0; | |
275 | } | |
276 | ||
7335613a WYG |
277 | static int __iwl_up(struct iwl_priv *priv) |
278 | { | |
279 | struct iwl_rxon_context *ctx; | |
280 | int ret; | |
281 | ||
b1eea297 | 282 | lockdep_assert_held(&priv->mutex); |
7335613a | 283 | |
83626404 | 284 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
7335613a WYG |
285 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
286 | return -EIO; | |
287 | } | |
288 | ||
289 | for_each_context(priv, ctx) { | |
290 | ret = iwlagn_alloc_bcast_station(priv, ctx); | |
291 | if (ret) { | |
292 | iwl_dealloc_bcast_stations(priv); | |
293 | return ret; | |
294 | } | |
295 | } | |
296 | ||
e1991885 | 297 | ret = iwl_run_init_ucode(priv); |
7335613a WYG |
298 | if (ret) { |
299 | IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret); | |
300 | goto error; | |
301 | } | |
302 | ||
e1991885 | 303 | ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR); |
7335613a WYG |
304 | if (ret) { |
305 | IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret); | |
306 | goto error; | |
307 | } | |
308 | ||
309 | ret = iwl_alive_start(priv); | |
310 | if (ret) | |
311 | goto error; | |
312 | return 0; | |
313 | ||
314 | error: | |
83626404 | 315 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
78e5a464 | 316 | iwl_down(priv); |
83626404 | 317 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
7335613a WYG |
318 | |
319 | IWL_ERR(priv, "Unable to initialize device.\n"); | |
320 | return ret; | |
321 | } | |
322 | ||
323 | static int iwlagn_mac_start(struct ieee80211_hw *hw) | |
324 | { | |
d0f76d68 | 325 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
326 | int ret; |
327 | ||
328 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
329 | ||
330 | /* we should be verifying the device is ready to be opened */ | |
b1eea297 | 331 | mutex_lock(&priv->mutex); |
7335613a | 332 | ret = __iwl_up(priv); |
b1eea297 | 333 | mutex_unlock(&priv->mutex); |
7335613a WYG |
334 | if (ret) |
335 | return ret; | |
336 | ||
337 | IWL_DEBUG_INFO(priv, "Start UP work done.\n"); | |
338 | ||
339 | /* Now we should be done, and the READY bit should be set. */ | |
83626404 | 340 | if (WARN_ON(!test_bit(STATUS_READY, &priv->status))) |
7335613a WYG |
341 | ret = -EIO; |
342 | ||
343 | iwlagn_led_enable(priv); | |
344 | ||
345 | priv->is_open = 1; | |
346 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
347 | return 0; | |
348 | } | |
349 | ||
aca86268 | 350 | static void iwlagn_mac_stop(struct ieee80211_hw *hw) |
7335613a | 351 | { |
d0f76d68 | 352 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
353 | |
354 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
355 | ||
356 | if (!priv->is_open) | |
357 | return; | |
358 | ||
359 | priv->is_open = 0; | |
360 | ||
b1eea297 | 361 | mutex_lock(&priv->mutex); |
7335613a | 362 | iwl_down(priv); |
b1eea297 | 363 | mutex_unlock(&priv->mutex); |
78e5a464 EG |
364 | |
365 | iwl_cancel_deferred_work(priv); | |
7335613a | 366 | |
1ee158d8 | 367 | flush_workqueue(priv->workqueue); |
7335613a WYG |
368 | |
369 | /* User space software may expect getting rfkill changes | |
1df06bdc EG |
370 | * even if interface is down, trans->down will leave the RF |
371 | * kill interrupt enabled | |
372 | */ | |
218733cf | 373 | iwl_trans_stop_hw(priv->trans, false); |
7335613a WYG |
374 | |
375 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
376 | } | |
377 | ||
aca86268 JB |
378 | static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw, |
379 | struct ieee80211_vif *vif, | |
380 | struct cfg80211_gtk_rekey_data *data) | |
7335613a | 381 | { |
d0f76d68 | 382 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a | 383 | |
65de7e84 | 384 | if (iwlwifi_mod_params.sw_crypto) |
7335613a WYG |
385 | return; |
386 | ||
387 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
b1eea297 | 388 | mutex_lock(&priv->mutex); |
7335613a WYG |
389 | |
390 | if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif) | |
391 | goto out; | |
392 | ||
393 | memcpy(priv->kek, data->kek, NL80211_KEK_LEN); | |
394 | memcpy(priv->kck, data->kck, NL80211_KCK_LEN); | |
395 | priv->replay_ctr = | |
396 | cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr)); | |
397 | priv->have_rekey_data = true; | |
398 | ||
399 | out: | |
b1eea297 | 400 | mutex_unlock(&priv->mutex); |
7335613a WYG |
401 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
402 | } | |
403 | ||
404 | #ifdef CONFIG_PM_SLEEP | |
7335613a | 405 | |
aca86268 JB |
406 | static int iwlagn_mac_suspend(struct ieee80211_hw *hw, |
407 | struct cfg80211_wowlan *wowlan) | |
7335613a | 408 | { |
d0f76d68 | 409 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a | 410 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
023ca58f | 411 | int ret; |
7335613a WYG |
412 | |
413 | if (WARN_ON(!wowlan)) | |
414 | return -EINVAL; | |
415 | ||
416 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
b1eea297 | 417 | mutex_lock(&priv->mutex); |
7335613a WYG |
418 | |
419 | /* Don't attempt WoWLAN when not associated, tear down instead. */ | |
420 | if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION || | |
421 | !iwl_is_associated_ctx(ctx)) { | |
422 | ret = 1; | |
423 | goto out; | |
424 | } | |
425 | ||
ea886a60 | 426 | ret = iwlagn_suspend(priv, wowlan); |
7335613a WYG |
427 | if (ret) |
428 | goto error; | |
429 | ||
ddaf5a5b | 430 | iwl_trans_d3_suspend(priv->trans); |
7335613a WYG |
431 | |
432 | goto out; | |
433 | ||
434 | error: | |
15b86bff | 435 | priv->wowlan = false; |
7335613a WYG |
436 | iwlagn_prepare_restart(priv); |
437 | ieee80211_restart_hw(priv->hw); | |
438 | out: | |
b1eea297 | 439 | mutex_unlock(&priv->mutex); |
7335613a WYG |
440 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
441 | ||
442 | return ret; | |
443 | } | |
444 | ||
5718d27f JB |
445 | struct iwl_resume_data { |
446 | struct iwl_priv *priv; | |
447 | struct iwlagn_wowlan_status *cmd; | |
448 | bool valid; | |
449 | }; | |
450 | ||
451 | static bool iwl_resume_status_fn(struct iwl_notif_wait_data *notif_wait, | |
452 | struct iwl_rx_packet *pkt, void *data) | |
453 | { | |
454 | struct iwl_resume_data *resume_data = data; | |
455 | struct iwl_priv *priv = resume_data->priv; | |
456 | u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | |
457 | ||
458 | if (len - 4 != sizeof(*resume_data->cmd)) { | |
459 | IWL_ERR(priv, "rx wrong size data\n"); | |
460 | return true; | |
461 | } | |
462 | memcpy(resume_data->cmd, pkt->data, sizeof(*resume_data->cmd)); | |
463 | resume_data->valid = true; | |
464 | ||
465 | return true; | |
466 | } | |
467 | ||
7335613a WYG |
468 | static int iwlagn_mac_resume(struct ieee80211_hw *hw) |
469 | { | |
d0f76d68 | 470 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
471 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
472 | struct ieee80211_vif *vif; | |
5718d27f JB |
473 | u32 base; |
474 | int ret; | |
475 | enum iwl_d3_status d3_status; | |
476 | struct error_table_start { | |
477 | /* cf. struct iwl_error_event_table */ | |
478 | u32 valid; | |
479 | u32 error_id; | |
480 | } err_info; | |
481 | struct iwl_notification_wait status_wait; | |
482 | static const u8 status_cmd[] = { | |
483 | REPLY_WOWLAN_GET_STATUS, | |
484 | }; | |
485 | struct iwlagn_wowlan_status status_data = {}; | |
486 | struct iwl_resume_data resume_data = { | |
487 | .priv = priv, | |
488 | .cmd = &status_data, | |
489 | .valid = false, | |
490 | }; | |
491 | struct cfg80211_wowlan_wakeup wakeup = { | |
492 | .pattern_idx = -1, | |
493 | }; | |
494 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
495 | const struct fw_img *img; | |
496 | #endif | |
7335613a WYG |
497 | |
498 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
b1eea297 | 499 | mutex_lock(&priv->mutex); |
7335613a | 500 | |
5718d27f JB |
501 | /* we'll clear ctx->vif during iwlagn_prepare_restart() */ |
502 | vif = ctx->vif; | |
503 | ||
504 | ret = iwl_trans_d3_resume(priv->trans, &d3_status); | |
505 | if (ret) | |
506 | goto out_unlock; | |
507 | ||
508 | if (d3_status != IWL_D3_STATUS_ALIVE) { | |
509 | IWL_INFO(priv, "Device was reset during suspend\n"); | |
510 | goto out_unlock; | |
511 | } | |
7335613a | 512 | |
2fdfc476 | 513 | base = priv->device_pointers.error_event_table; |
5718d27f JB |
514 | if (!iwlagn_hw_valid_rtc_data_addr(base)) { |
515 | IWL_WARN(priv, "Invalid error table during resume!\n"); | |
516 | goto out_unlock; | |
517 | } | |
518 | ||
519 | iwl_trans_read_mem_bytes(priv->trans, base, | |
520 | &err_info, sizeof(err_info)); | |
521 | ||
522 | if (err_info.valid) { | |
523 | IWL_INFO(priv, "error table is valid (%d, 0x%x)\n", | |
524 | err_info.valid, err_info.error_id); | |
525 | if (err_info.error_id == RF_KILL_INDICATOR_FOR_WOWLAN) { | |
526 | wakeup.rfkill_release = true; | |
527 | ieee80211_report_wowlan_wakeup(vif, &wakeup, | |
528 | GFP_KERNEL); | |
7335613a | 529 | } |
5718d27f JB |
530 | goto out_unlock; |
531 | } | |
7335613a WYG |
532 | |
533 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
5718d27f JB |
534 | img = &priv->fw->img[IWL_UCODE_WOWLAN]; |
535 | if (!priv->wowlan_sram) | |
536 | priv->wowlan_sram = | |
537 | kzalloc(img->sec[IWL_UCODE_SECTION_DATA].len, | |
538 | GFP_KERNEL); | |
539 | ||
540 | if (priv->wowlan_sram) | |
541 | iwl_trans_read_mem(priv->trans, 0x800000, | |
542 | priv->wowlan_sram, | |
543 | img->sec[IWL_UCODE_SECTION_DATA].len / 4); | |
7335613a | 544 | #endif |
7335613a | 545 | |
5718d27f JB |
546 | /* |
547 | * This is very strange. The GET_STATUS command is sent but the device | |
548 | * doesn't reply properly, it seems it doesn't close the RBD so one is | |
549 | * always left open ... As a result, we need to send another command | |
550 | * and have to reset the driver afterwards. As we need to switch to | |
551 | * runtime firmware again that'll happen. | |
552 | */ | |
553 | ||
554 | iwl_init_notification_wait(&priv->notif_wait, &status_wait, status_cmd, | |
555 | ARRAY_SIZE(status_cmd), iwl_resume_status_fn, | |
556 | &resume_data); | |
557 | ||
558 | iwl_dvm_send_cmd_pdu(priv, REPLY_WOWLAN_GET_STATUS, CMD_ASYNC, 0, NULL); | |
559 | iwl_dvm_send_cmd_pdu(priv, REPLY_ECHO, CMD_ASYNC, 0, NULL); | |
560 | /* an RBD is left open in the firmware now! */ | |
561 | ||
562 | ret = iwl_wait_notification(&priv->notif_wait, &status_wait, HZ/5); | |
563 | if (ret) | |
564 | goto out_unlock; | |
565 | ||
566 | if (resume_data.valid && priv->contexts[IWL_RXON_CTX_BSS].vif) { | |
567 | u32 reasons = le32_to_cpu(status_data.wakeup_reason); | |
568 | struct cfg80211_wowlan_wakeup *wakeup_report; | |
569 | ||
570 | IWL_INFO(priv, "WoWLAN wakeup reason(s): 0x%.8x\n", reasons); | |
571 | ||
572 | if (reasons) { | |
573 | if (reasons & IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET) | |
574 | wakeup.magic_pkt = true; | |
575 | if (reasons & IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH) | |
576 | wakeup.pattern_idx = status_data.pattern_number; | |
577 | if (reasons & (IWLAGN_WOWLAN_WAKEUP_BEACON_MISS | | |
578 | IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE)) | |
579 | wakeup.disconnect = true; | |
580 | if (reasons & IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL) | |
581 | wakeup.gtk_rekey_failure = true; | |
582 | if (reasons & IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ) | |
583 | wakeup.eap_identity_req = true; | |
584 | if (reasons & IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE) | |
585 | wakeup.four_way_handshake = true; | |
586 | wakeup_report = &wakeup; | |
587 | } else { | |
588 | wakeup_report = NULL; | |
589 | } | |
590 | ||
591 | ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL); | |
592 | } | |
7335613a | 593 | |
15b86bff | 594 | priv->wowlan = false; |
7335613a | 595 | |
7335613a WYG |
596 | iwlagn_prepare_restart(priv); |
597 | ||
598 | memset((void *)&ctx->active, 0, sizeof(ctx->active)); | |
599 | iwl_connection_init_rx_config(priv, ctx); | |
600 | iwlagn_set_rxon_chain(priv, ctx); | |
601 | ||
5718d27f | 602 | out_unlock: |
b1eea297 | 603 | mutex_unlock(&priv->mutex); |
7335613a WYG |
604 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
605 | ||
606 | ieee80211_resume_disconnect(vif); | |
607 | ||
608 | return 1; | |
609 | } | |
610 | ||
76ed2edd JB |
611 | static void iwlagn_mac_set_wakeup(struct ieee80211_hw *hw, bool enabled) |
612 | { | |
613 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | |
614 | ||
615 | device_set_wakeup_enable(priv->trans->dev, enabled); | |
616 | } | |
7335613a WYG |
617 | #endif |
618 | ||
36323f81 TH |
619 | static void iwlagn_mac_tx(struct ieee80211_hw *hw, |
620 | struct ieee80211_tx_control *control, | |
621 | struct sk_buff *skb) | |
7335613a | 622 | { |
d0f76d68 | 623 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a | 624 | |
36323f81 | 625 | if (iwlagn_tx_skb(priv, control->sta, skb)) |
31df3bb7 | 626 | ieee80211_free_txskb(hw, skb); |
7335613a WYG |
627 | } |
628 | ||
aca86268 JB |
629 | static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw, |
630 | struct ieee80211_vif *vif, | |
631 | struct ieee80211_key_conf *keyconf, | |
632 | struct ieee80211_sta *sta, | |
633 | u32 iv32, u16 *phase1key) | |
7335613a | 634 | { |
d0f76d68 | 635 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
636 | |
637 | iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key); | |
638 | } | |
639 | ||
aca86268 JB |
640 | static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
641 | struct ieee80211_vif *vif, | |
642 | struct ieee80211_sta *sta, | |
643 | struct ieee80211_key_conf *key) | |
7335613a | 644 | { |
d0f76d68 | 645 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
646 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
647 | struct iwl_rxon_context *ctx = vif_priv->ctx; | |
648 | int ret; | |
649 | bool is_default_wep_key = false; | |
650 | ||
651 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
652 | ||
65de7e84 | 653 | if (iwlwifi_mod_params.sw_crypto) { |
7335613a WYG |
654 | IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n"); |
655 | return -EOPNOTSUPP; | |
656 | } | |
657 | ||
a7e12c8e JB |
658 | switch (key->cipher) { |
659 | case WLAN_CIPHER_SUITE_TKIP: | |
660 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | |
661 | /* fall through */ | |
662 | case WLAN_CIPHER_SUITE_CCMP: | |
663 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
664 | break; | |
665 | default: | |
666 | break; | |
667 | } | |
668 | ||
7335613a WYG |
669 | /* |
670 | * We could program these keys into the hardware as well, but we | |
671 | * don't expect much multicast traffic in IBSS and having keys | |
672 | * for more stations is probably more useful. | |
673 | * | |
674 | * Mark key TX-only and return 0. | |
675 | */ | |
676 | if (vif->type == NL80211_IFTYPE_ADHOC && | |
677 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { | |
678 | key->hw_key_idx = WEP_INVALID_OFFSET; | |
679 | return 0; | |
680 | } | |
681 | ||
682 | /* If they key was TX-only, accept deletion */ | |
683 | if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET) | |
684 | return 0; | |
685 | ||
b1eea297 | 686 | mutex_lock(&priv->mutex); |
7335613a WYG |
687 | iwl_scan_cancel_timeout(priv, 100); |
688 | ||
689 | BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT); | |
690 | ||
691 | /* | |
692 | * If we are getting WEP group key and we didn't receive any key mapping | |
693 | * so far, we are in legacy wep mode (group key only), otherwise we are | |
694 | * in 1X mode. | |
695 | * In legacy wep mode, we use another host command to the uCode. | |
696 | */ | |
697 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 || | |
698 | key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) { | |
699 | if (cmd == SET_KEY) | |
700 | is_default_wep_key = !ctx->key_mapping_keys; | |
701 | else | |
702 | is_default_wep_key = | |
703 | key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT; | |
704 | } | |
705 | ||
706 | ||
707 | switch (cmd) { | |
708 | case SET_KEY: | |
709 | if (is_default_wep_key) { | |
710 | ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key); | |
711 | break; | |
712 | } | |
713 | ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta); | |
714 | if (ret) { | |
715 | /* | |
716 | * can't add key for RX, but we don't need it | |
717 | * in the device for TX so still return 0 | |
718 | */ | |
719 | ret = 0; | |
720 | key->hw_key_idx = WEP_INVALID_OFFSET; | |
721 | } | |
722 | ||
723 | IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n"); | |
724 | break; | |
725 | case DISABLE_KEY: | |
726 | if (is_default_wep_key) | |
727 | ret = iwl_remove_default_wep_key(priv, ctx, key); | |
728 | else | |
729 | ret = iwl_remove_dynamic_key(priv, ctx, key, sta); | |
730 | ||
731 | IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n"); | |
732 | break; | |
733 | default: | |
734 | ret = -EINVAL; | |
735 | } | |
736 | ||
b1eea297 | 737 | mutex_unlock(&priv->mutex); |
7335613a WYG |
738 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
739 | ||
740 | return ret; | |
741 | } | |
742 | ||
aca86268 JB |
743 | static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw, |
744 | struct ieee80211_vif *vif, | |
745 | enum ieee80211_ampdu_mlme_action action, | |
746 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, | |
747 | u8 buf_size) | |
7335613a | 748 | { |
d0f76d68 | 749 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
750 | int ret = -EINVAL; |
751 | struct iwl_station_priv *sta_priv = (void *) sta->drv_priv; | |
7335613a WYG |
752 | |
753 | IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n", | |
754 | sta->addr, tid); | |
755 | ||
b7998c8b | 756 | if (!(priv->nvm_data->sku_cap_11n_enable)) |
7335613a WYG |
757 | return -EACCES; |
758 | ||
759 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
b1eea297 | 760 | mutex_lock(&priv->mutex); |
7335613a WYG |
761 | |
762 | switch (action) { | |
763 | case IEEE80211_AMPDU_RX_START: | |
65de7e84 | 764 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) |
7428994d | 765 | break; |
7335613a WYG |
766 | IWL_DEBUG_HT(priv, "start Rx\n"); |
767 | ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn); | |
768 | break; | |
769 | case IEEE80211_AMPDU_RX_STOP: | |
770 | IWL_DEBUG_HT(priv, "stop Rx\n"); | |
771 | ret = iwl_sta_rx_agg_stop(priv, sta, tid); | |
7335613a WYG |
772 | break; |
773 | case IEEE80211_AMPDU_TX_START: | |
4beaf6c2 | 774 | if (!priv->trans->ops->txq_enable) |
9eae88fa | 775 | break; |
65de7e84 | 776 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) |
7428994d | 777 | break; |
7335613a WYG |
778 | IWL_DEBUG_HT(priv, "start Tx\n"); |
779 | ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn); | |
780 | break; | |
18b559d5 JB |
781 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
782 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
2d055afd EG |
783 | IWL_DEBUG_HT(priv, "Flush Tx\n"); |
784 | ret = iwlagn_tx_agg_flush(priv, vif, sta, tid); | |
785 | break; | |
786 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
7335613a WYG |
787 | IWL_DEBUG_HT(priv, "stop Tx\n"); |
788 | ret = iwlagn_tx_agg_stop(priv, vif, sta, tid); | |
789 | if ((ret == 0) && (priv->agg_tids_count > 0)) { | |
790 | priv->agg_tids_count--; | |
791 | IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n", | |
792 | priv->agg_tids_count); | |
793 | } | |
b9ad70da | 794 | if (!priv->agg_tids_count && |
9e295116 | 795 | priv->hw_params.use_rts_for_aggregation) { |
7335613a WYG |
796 | /* |
797 | * switch off RTS/CTS if it was previously enabled | |
798 | */ | |
799 | sta_priv->lq_sta.lq.general_params.flags &= | |
800 | ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK; | |
801 | iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif), | |
802 | &sta_priv->lq_sta.lq, CMD_ASYNC, false); | |
803 | } | |
804 | break; | |
805 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
822e8b2a | 806 | ret = iwlagn_tx_agg_oper(priv, vif, sta, tid, buf_size); |
7335613a WYG |
807 | break; |
808 | } | |
b1eea297 | 809 | mutex_unlock(&priv->mutex); |
7335613a WYG |
810 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
811 | return ret; | |
812 | } | |
813 | ||
814 | static int iwlagn_mac_sta_add(struct ieee80211_hw *hw, | |
815 | struct ieee80211_vif *vif, | |
816 | struct ieee80211_sta *sta) | |
817 | { | |
d0f76d68 | 818 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
819 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
820 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; | |
821 | bool is_ap = vif->type == NL80211_IFTYPE_STATION; | |
fb5fe5b9 | 822 | int ret; |
7335613a WYG |
823 | u8 sta_id; |
824 | ||
7335613a WYG |
825 | IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n", |
826 | sta->addr); | |
827 | sta_priv->sta_id = IWL_INVALID_STATION; | |
828 | ||
829 | atomic_set(&sta_priv->pending_frames, 0); | |
830 | if (vif->type == NL80211_IFTYPE_AP) | |
831 | sta_priv->client = true; | |
832 | ||
833 | ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr, | |
834 | is_ap, sta, &sta_id); | |
835 | if (ret) { | |
836 | IWL_ERR(priv, "Unable to add station %pM (%d)\n", | |
837 | sta->addr, ret); | |
838 | /* Should we return success if return code is EEXIST ? */ | |
fb5fe5b9 | 839 | return ret; |
7335613a WYG |
840 | } |
841 | ||
842 | sta_priv->sta_id = sta_id; | |
843 | ||
fb5fe5b9 JB |
844 | return 0; |
845 | } | |
846 | ||
847 | static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw, | |
848 | struct ieee80211_vif *vif, | |
849 | struct ieee80211_sta *sta) | |
850 | { | |
851 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | |
852 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | |
853 | int ret; | |
854 | ||
97420515 JB |
855 | IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", sta->addr); |
856 | ||
857 | if (vif->type == NL80211_IFTYPE_STATION) { | |
858 | /* | |
859 | * Station will be removed from device when the RXON | |
860 | * is set to unassociated -- just deactivate it here | |
861 | * to avoid re-programming it. | |
862 | */ | |
863 | ret = 0; | |
864 | iwl_deactivate_station(priv, sta_priv->sta_id, sta->addr); | |
865 | } else { | |
866 | ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr); | |
867 | if (ret) | |
868 | IWL_DEBUG_QUIET_RFKILL(priv, | |
869 | "Error removing station %pM\n", sta->addr); | |
870 | } | |
fb5fe5b9 JB |
871 | return ret; |
872 | } | |
873 | ||
aca86268 JB |
874 | static int iwlagn_mac_sta_state(struct ieee80211_hw *hw, |
875 | struct ieee80211_vif *vif, | |
876 | struct ieee80211_sta *sta, | |
877 | enum ieee80211_sta_state old_state, | |
878 | enum ieee80211_sta_state new_state) | |
fb5fe5b9 JB |
879 | { |
880 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | |
ab0bd5b3 | 881 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
fb5fe5b9 | 882 | enum { |
ab0bd5b3 | 883 | NONE, ADD, REMOVE, HT_RATE_INIT, ADD_RATE_INIT, |
fb5fe5b9 JB |
884 | } op = NONE; |
885 | int ret; | |
886 | ||
887 | IWL_DEBUG_MAC80211(priv, "station %pM state change %d->%d\n", | |
888 | sta->addr, old_state, new_state); | |
889 | ||
b1eea297 | 890 | mutex_lock(&priv->mutex); |
fb5fe5b9 JB |
891 | if (vif->type == NL80211_IFTYPE_STATION) { |
892 | if (old_state == IEEE80211_STA_NOTEXIST && | |
893 | new_state == IEEE80211_STA_NONE) | |
894 | op = ADD; | |
895 | else if (old_state == IEEE80211_STA_NONE && | |
896 | new_state == IEEE80211_STA_NOTEXIST) | |
897 | op = REMOVE; | |
898 | else if (old_state == IEEE80211_STA_AUTH && | |
899 | new_state == IEEE80211_STA_ASSOC) | |
ab0bd5b3 | 900 | op = HT_RATE_INIT; |
fb5fe5b9 JB |
901 | } else { |
902 | if (old_state == IEEE80211_STA_AUTH && | |
903 | new_state == IEEE80211_STA_ASSOC) | |
904 | op = ADD_RATE_INIT; | |
905 | else if (old_state == IEEE80211_STA_ASSOC && | |
906 | new_state == IEEE80211_STA_AUTH) | |
907 | op = REMOVE; | |
908 | } | |
909 | ||
910 | switch (op) { | |
911 | case ADD: | |
912 | ret = iwlagn_mac_sta_add(hw, vif, sta); | |
eac9ac6d JB |
913 | if (ret) |
914 | break; | |
915 | /* | |
916 | * Clear the in-progress flag, the AP station entry was added | |
917 | * but we'll initialize LQ only when we've associated (which | |
918 | * would also clear the in-progress flag). This is necessary | |
919 | * in case we never initialize LQ because association fails. | |
920 | */ | |
921 | spin_lock_bh(&priv->sta_lock); | |
922 | priv->stations[iwl_sta_id(sta)].used &= | |
923 | ~IWL_STA_UCODE_INPROGRESS; | |
924 | spin_unlock_bh(&priv->sta_lock); | |
fb5fe5b9 JB |
925 | break; |
926 | case REMOVE: | |
927 | ret = iwlagn_mac_sta_remove(hw, vif, sta); | |
928 | break; | |
929 | case ADD_RATE_INIT: | |
930 | ret = iwlagn_mac_sta_add(hw, vif, sta); | |
931 | if (ret) | |
932 | break; | |
fb5fe5b9 JB |
933 | /* Initialize rate scaling */ |
934 | IWL_DEBUG_INFO(priv, | |
935 | "Initializing rate scaling for station %pM\n", | |
936 | sta->addr); | |
937 | iwl_rs_rate_init(priv, sta, iwl_sta_id(sta)); | |
938 | ret = 0; | |
939 | break; | |
ab0bd5b3 JB |
940 | case HT_RATE_INIT: |
941 | /* Initialize rate scaling */ | |
942 | ret = iwl_sta_update_ht(priv, vif_priv->ctx, sta); | |
943 | if (ret) | |
944 | break; | |
945 | IWL_DEBUG_INFO(priv, | |
946 | "Initializing rate scaling for station %pM\n", | |
947 | sta->addr); | |
948 | iwl_rs_rate_init(priv, sta, iwl_sta_id(sta)); | |
949 | ret = 0; | |
950 | break; | |
fb5fe5b9 JB |
951 | default: |
952 | ret = 0; | |
953 | break; | |
954 | } | |
955 | ||
956 | /* | |
957 | * mac80211 might WARN if we fail, but due the way we | |
958 | * (badly) handle hard rfkill, we might fail here | |
959 | */ | |
83626404 | 960 | if (iwl_is_rfkill(priv)) |
fb5fe5b9 JB |
961 | ret = 0; |
962 | ||
b1eea297 | 963 | mutex_unlock(&priv->mutex); |
7335613a WYG |
964 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
965 | ||
966 | return ret; | |
967 | } | |
968 | ||
aca86268 JB |
969 | static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw, |
970 | struct ieee80211_channel_switch *ch_switch) | |
7335613a | 971 | { |
d0f76d68 | 972 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a | 973 | struct ieee80211_conf *conf = &hw->conf; |
85220d71 | 974 | struct ieee80211_channel *channel = ch_switch->chandef.chan; |
7335613a WYG |
975 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; |
976 | /* | |
977 | * MULTI-FIXME | |
978 | * When we add support for multiple interfaces, we need to | |
979 | * revisit this. The channel switch command in the device | |
980 | * only affects the BSS context, but what does that really | |
981 | * mean? And what if we get a CSA on the second interface? | |
982 | * This needs a lot of work. | |
983 | */ | |
984 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | |
985 | u16 ch; | |
986 | ||
987 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
988 | ||
b1eea297 | 989 | mutex_lock(&priv->mutex); |
7335613a | 990 | |
83626404 | 991 | if (iwl_is_rfkill(priv)) |
7335613a WYG |
992 | goto out; |
993 | ||
83626404 DF |
994 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
995 | test_bit(STATUS_SCANNING, &priv->status) || | |
996 | test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) | |
7335613a WYG |
997 | goto out; |
998 | ||
999 | if (!iwl_is_associated_ctx(ctx)) | |
1000 | goto out; | |
1001 | ||
e9676695 | 1002 | if (!priv->lib->set_channel_switch) |
7335613a WYG |
1003 | goto out; |
1004 | ||
1005 | ch = channel->hw_value; | |
1006 | if (le16_to_cpu(ctx->active.channel) == ch) | |
1007 | goto out; | |
1008 | ||
7335613a WYG |
1009 | priv->current_ht_config.smps = conf->smps_mode; |
1010 | ||
1011 | /* Configure HT40 channels */ | |
85220d71 JB |
1012 | switch (cfg80211_get_chandef_type(&ch_switch->chandef)) { |
1013 | case NL80211_CHAN_NO_HT: | |
1014 | case NL80211_CHAN_HT20: | |
7335613a | 1015 | ctx->ht.is_40mhz = false; |
85220d71 JB |
1016 | ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE; |
1017 | break; | |
1018 | case NL80211_CHAN_HT40MINUS: | |
1019 | ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW; | |
1020 | ctx->ht.is_40mhz = true; | |
1021 | break; | |
1022 | case NL80211_CHAN_HT40PLUS: | |
1023 | ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; | |
1024 | ctx->ht.is_40mhz = true; | |
1025 | break; | |
1026 | } | |
7335613a WYG |
1027 | |
1028 | if ((le16_to_cpu(ctx->staging.channel) != ch)) | |
1029 | ctx->staging.flags = 0; | |
1030 | ||
1031 | iwl_set_rxon_channel(priv, channel, ctx); | |
1032 | iwl_set_rxon_ht(priv, ht_conf); | |
1033 | iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif); | |
1034 | ||
7335613a WYG |
1035 | /* |
1036 | * at this point, staging_rxon has the | |
1037 | * configuration for channel switch | |
1038 | */ | |
83626404 | 1039 | set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status); |
7335613a | 1040 | priv->switch_channel = cpu_to_le16(ch); |
e9676695 | 1041 | if (priv->lib->set_channel_switch(priv, ch_switch)) { |
83626404 | 1042 | clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status); |
7335613a WYG |
1043 | priv->switch_channel = 0; |
1044 | ieee80211_chswitch_done(ctx->vif, false); | |
1045 | } | |
1046 | ||
1047 | out: | |
b1eea297 | 1048 | mutex_unlock(&priv->mutex); |
7335613a WYG |
1049 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
1050 | } | |
1051 | ||
bedec3a6 MV |
1052 | void iwl_chswitch_done(struct iwl_priv *priv, bool is_success) |
1053 | { | |
1054 | /* | |
1055 | * MULTI-FIXME | |
1056 | * See iwlagn_mac_channel_switch. | |
1057 | */ | |
1058 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | |
1059 | ||
1060 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
1061 | return; | |
1062 | ||
1063 | if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) | |
1064 | ieee80211_chswitch_done(ctx->vif, is_success); | |
1065 | } | |
1066 | ||
aca86268 JB |
1067 | static void iwlagn_configure_filter(struct ieee80211_hw *hw, |
1068 | unsigned int changed_flags, | |
1069 | unsigned int *total_flags, | |
1070 | u64 multicast) | |
7335613a | 1071 | { |
d0f76d68 | 1072 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
1073 | __le32 filter_or = 0, filter_nand = 0; |
1074 | struct iwl_rxon_context *ctx; | |
1075 | ||
1076 | #define CHK(test, flag) do { \ | |
1077 | if (*total_flags & (test)) \ | |
1078 | filter_or |= (flag); \ | |
1079 | else \ | |
1080 | filter_nand |= (flag); \ | |
1081 | } while (0) | |
1082 | ||
1083 | IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n", | |
1084 | changed_flags, *total_flags); | |
1085 | ||
1086 | CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK); | |
1087 | /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */ | |
1088 | CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK); | |
1089 | CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK); | |
1090 | ||
1091 | #undef CHK | |
1092 | ||
b1eea297 | 1093 | mutex_lock(&priv->mutex); |
7335613a WYG |
1094 | |
1095 | for_each_context(priv, ctx) { | |
1096 | ctx->staging.filter_flags &= ~filter_nand; | |
1097 | ctx->staging.filter_flags |= filter_or; | |
1098 | ||
1099 | /* | |
1100 | * Not committing directly because hardware can perform a scan, | |
1101 | * but we'll eventually commit the filter flags change anyway. | |
1102 | */ | |
1103 | } | |
1104 | ||
b1eea297 | 1105 | mutex_unlock(&priv->mutex); |
7335613a WYG |
1106 | |
1107 | /* | |
1108 | * Receiving all multicast frames is always enabled by the | |
1109 | * default flags setup in iwl_connection_init_rx_config() | |
1110 | * since we currently do not support programming multicast | |
1111 | * filters into the device. | |
1112 | */ | |
1113 | *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | | |
1114 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; | |
1115 | } | |
1116 | ||
39ecc01d | 1117 | static void iwlagn_mac_flush(struct ieee80211_hw *hw, u32 queues, bool drop) |
7335613a | 1118 | { |
d0f76d68 | 1119 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a | 1120 | |
b1eea297 | 1121 | mutex_lock(&priv->mutex); |
7335613a WYG |
1122 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
1123 | ||
83626404 | 1124 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
7335613a WYG |
1125 | IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n"); |
1126 | goto done; | |
1127 | } | |
83626404 | 1128 | if (iwl_is_rfkill(priv)) { |
7335613a WYG |
1129 | IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n"); |
1130 | goto done; | |
1131 | } | |
1132 | ||
1133 | /* | |
1134 | * mac80211 will not push any more frames for transmit | |
1135 | * until the flush is completed | |
1136 | */ | |
1137 | if (drop) { | |
1138 | IWL_DEBUG_MAC80211(priv, "send flush command\n"); | |
2d055afd | 1139 | if (iwlagn_txfifo_flush(priv, 0)) { |
7335613a WYG |
1140 | IWL_ERR(priv, "flush request fail\n"); |
1141 | goto done; | |
1142 | } | |
1143 | } | |
1144 | IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n"); | |
68e8dfda | 1145 | iwl_trans_wait_tx_queue_empty(priv->trans); |
7335613a | 1146 | done: |
b1eea297 | 1147 | mutex_unlock(&priv->mutex); |
7335613a WYG |
1148 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
1149 | } | |
1150 | ||
1151 | static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw, | |
49884568 | 1152 | struct ieee80211_vif *vif, |
7335613a | 1153 | struct ieee80211_channel *channel, |
d339d5ca IP |
1154 | int duration, |
1155 | enum ieee80211_roc_type type) | |
7335613a | 1156 | { |
d0f76d68 | 1157 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
1158 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN]; |
1159 | int err = 0; | |
1160 | ||
a18f61bc | 1161 | if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) |
7335613a WYG |
1162 | return -EOPNOTSUPP; |
1163 | ||
1164 | if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT))) | |
1165 | return -EOPNOTSUPP; | |
1166 | ||
1167 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
b1eea297 | 1168 | mutex_lock(&priv->mutex); |
7335613a | 1169 | |
83626404 | 1170 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
601968b3 JB |
1171 | /* mac80211 should not scan while ROC or ROC while scanning */ |
1172 | if (WARN_ON_ONCE(priv->scan_type != IWL_SCAN_RADIO_RESET)) { | |
1173 | err = -EBUSY; | |
1174 | goto out; | |
1175 | } | |
1176 | ||
1177 | iwl_scan_cancel_timeout(priv, 100); | |
1178 | ||
1179 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { | |
1180 | err = -EBUSY; | |
1181 | goto out; | |
1182 | } | |
7335613a WYG |
1183 | } |
1184 | ||
1185 | priv->hw_roc_channel = channel; | |
3ddf6bef JB |
1186 | /* convert from ms to TU */ |
1187 | priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024); | |
7335613a WYG |
1188 | priv->hw_roc_start_notified = false; |
1189 | cancel_delayed_work(&priv->hw_roc_disable_work); | |
1190 | ||
1191 | if (!ctx->is_active) { | |
a69cd040 JB |
1192 | static const struct iwl_qos_info default_qos_data = { |
1193 | .def_qos_parm = { | |
1194 | .ac[0] = { | |
1195 | .cw_min = cpu_to_le16(3), | |
1196 | .cw_max = cpu_to_le16(7), | |
1197 | .aifsn = 2, | |
1198 | .edca_txop = cpu_to_le16(1504), | |
1199 | }, | |
1200 | .ac[1] = { | |
1201 | .cw_min = cpu_to_le16(7), | |
1202 | .cw_max = cpu_to_le16(15), | |
1203 | .aifsn = 2, | |
1204 | .edca_txop = cpu_to_le16(3008), | |
1205 | }, | |
1206 | .ac[2] = { | |
1207 | .cw_min = cpu_to_le16(15), | |
1208 | .cw_max = cpu_to_le16(1023), | |
1209 | .aifsn = 3, | |
1210 | }, | |
1211 | .ac[3] = { | |
1212 | .cw_min = cpu_to_le16(15), | |
1213 | .cw_max = cpu_to_le16(1023), | |
1214 | .aifsn = 7, | |
1215 | }, | |
1216 | }, | |
1217 | }; | |
1218 | ||
7335613a | 1219 | ctx->is_active = true; |
a69cd040 | 1220 | ctx->qos_data = default_qos_data; |
7335613a WYG |
1221 | ctx->staging.dev_type = RXON_DEV_TYPE_P2P; |
1222 | memcpy(ctx->staging.node_addr, | |
1223 | priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr, | |
1224 | ETH_ALEN); | |
1225 | memcpy(ctx->staging.bssid_addr, | |
1226 | priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr, | |
1227 | ETH_ALEN); | |
1228 | err = iwlagn_commit_rxon(priv, ctx); | |
1229 | if (err) | |
1230 | goto out; | |
1231 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK | | |
1232 | RXON_FILTER_PROMISC_MSK | | |
1233 | RXON_FILTER_CTL2HOST_MSK; | |
1234 | ||
1235 | err = iwlagn_commit_rxon(priv, ctx); | |
1236 | if (err) { | |
1237 | iwlagn_disable_roc(priv); | |
1238 | goto out; | |
1239 | } | |
1240 | priv->hw_roc_setup = true; | |
1241 | } | |
1242 | ||
1243 | err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band); | |
1244 | if (err) | |
1245 | iwlagn_disable_roc(priv); | |
1246 | ||
1247 | out: | |
b1eea297 | 1248 | mutex_unlock(&priv->mutex); |
7335613a WYG |
1249 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
1250 | ||
1251 | return err; | |
1252 | } | |
1253 | ||
aca86268 | 1254 | static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw) |
7335613a | 1255 | { |
d0f76d68 | 1256 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a | 1257 | |
a18f61bc | 1258 | if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) |
7335613a WYG |
1259 | return -EOPNOTSUPP; |
1260 | ||
1261 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
b1eea297 | 1262 | mutex_lock(&priv->mutex); |
7335613a WYG |
1263 | iwl_scan_cancel_timeout(priv, priv->hw_roc_duration); |
1264 | iwlagn_disable_roc(priv); | |
b1eea297 | 1265 | mutex_unlock(&priv->mutex); |
7335613a WYG |
1266 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
1267 | ||
1268 | return 0; | |
1269 | } | |
1270 | ||
aca86268 | 1271 | static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw, |
887da917 | 1272 | struct ieee80211_vif *vif, |
aca86268 | 1273 | enum ieee80211_rssi_event rssi_event) |
7335613a | 1274 | { |
d0f76d68 | 1275 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a WYG |
1276 | |
1277 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
b1eea297 | 1278 | mutex_lock(&priv->mutex); |
7335613a | 1279 | |
2152268f EG |
1280 | if (priv->cfg->bt_params && |
1281 | priv->cfg->bt_params->advanced_bt_coexist) { | |
7335613a WYG |
1282 | if (rssi_event == RSSI_EVENT_LOW) |
1283 | priv->bt_enable_pspoll = true; | |
1284 | else if (rssi_event == RSSI_EVENT_HIGH) | |
1285 | priv->bt_enable_pspoll = false; | |
1286 | ||
1287 | iwlagn_send_advance_bt_config(priv); | |
1288 | } else { | |
1289 | IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled," | |
1290 | "ignoring RSSI callback\n"); | |
1291 | } | |
1292 | ||
b1eea297 | 1293 | mutex_unlock(&priv->mutex); |
7335613a WYG |
1294 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
1295 | } | |
1296 | ||
aca86268 JB |
1297 | static int iwlagn_mac_set_tim(struct ieee80211_hw *hw, |
1298 | struct ieee80211_sta *sta, bool set) | |
7335613a | 1299 | { |
d0f76d68 | 1300 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
7335613a | 1301 | |
1ee158d8 | 1302 | queue_work(priv->workqueue, &priv->beacon_update); |
7335613a WYG |
1303 | |
1304 | return 0; | |
1305 | } | |
1306 | ||
aca86268 JB |
1307 | static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw, |
1308 | struct ieee80211_vif *vif, u16 queue, | |
1309 | const struct ieee80211_tx_queue_params *params) | |
0b7a4c78 | 1310 | { |
d0f76d68 | 1311 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
0b7a4c78 WYG |
1312 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
1313 | struct iwl_rxon_context *ctx = vif_priv->ctx; | |
0b7a4c78 WYG |
1314 | int q; |
1315 | ||
1316 | if (WARN_ON(!ctx)) | |
1317 | return -EINVAL; | |
1318 | ||
1319 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
1320 | ||
83626404 | 1321 | if (!iwl_is_ready_rf(priv)) { |
0b7a4c78 WYG |
1322 | IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n"); |
1323 | return -EIO; | |
1324 | } | |
1325 | ||
1326 | if (queue >= AC_NUM) { | |
1327 | IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue); | |
1328 | return 0; | |
1329 | } | |
1330 | ||
1331 | q = AC_NUM - 1 - queue; | |
1332 | ||
b1eea297 | 1333 | mutex_lock(&priv->mutex); |
0b7a4c78 WYG |
1334 | |
1335 | ctx->qos_data.def_qos_parm.ac[q].cw_min = | |
1336 | cpu_to_le16(params->cw_min); | |
1337 | ctx->qos_data.def_qos_parm.ac[q].cw_max = | |
1338 | cpu_to_le16(params->cw_max); | |
1339 | ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; | |
1340 | ctx->qos_data.def_qos_parm.ac[q].edca_txop = | |
1341 | cpu_to_le16((params->txop * 32)); | |
1342 | ||
1343 | ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0; | |
1344 | ||
b1eea297 | 1345 | mutex_unlock(&priv->mutex); |
0b7a4c78 WYG |
1346 | |
1347 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
1348 | return 0; | |
1349 | } | |
1350 | ||
aca86268 | 1351 | static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw) |
0b7a4c78 | 1352 | { |
d0f76d68 | 1353 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
0b7a4c78 WYG |
1354 | |
1355 | return priv->ibss_manager == IWL_IBSS_MANAGER; | |
1356 | } | |
1357 | ||
1358 | static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | |
1359 | { | |
1360 | iwl_connection_init_rx_config(priv, ctx); | |
1361 | ||
1362 | iwlagn_set_rxon_chain(priv, ctx); | |
1363 | ||
1364 | return iwlagn_commit_rxon(priv, ctx); | |
1365 | } | |
1366 | ||
aca86268 JB |
1367 | static int iwl_setup_interface(struct iwl_priv *priv, |
1368 | struct iwl_rxon_context *ctx) | |
0b7a4c78 WYG |
1369 | { |
1370 | struct ieee80211_vif *vif = ctx->vif; | |
1479177b | 1371 | int err, ac; |
0b7a4c78 | 1372 | |
b1eea297 | 1373 | lockdep_assert_held(&priv->mutex); |
0b7a4c78 WYG |
1374 | |
1375 | /* | |
1376 | * This variable will be correct only when there's just | |
1377 | * a single context, but all code using it is for hardware | |
1378 | * that supports only one context. | |
1379 | */ | |
1380 | priv->iw_mode = vif->type; | |
1381 | ||
1382 | ctx->is_active = true; | |
1383 | ||
1384 | err = iwl_set_mode(priv, ctx); | |
1385 | if (err) { | |
1386 | if (!ctx->always_active) | |
1387 | ctx->is_active = false; | |
1388 | return err; | |
1389 | } | |
1390 | ||
2152268f | 1391 | if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist && |
0b7a4c78 WYG |
1392 | vif->type == NL80211_IFTYPE_ADHOC) { |
1393 | /* | |
1394 | * pretend to have high BT traffic as long as we | |
1395 | * are operating in IBSS mode, as this will cause | |
1396 | * the rate scaling etc. to behave as intended. | |
1397 | */ | |
1398 | priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH; | |
1399 | } | |
1400 | ||
1479177b JB |
1401 | /* set up queue mappings */ |
1402 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) | |
1403 | vif->hw_queue[ac] = ctx->ac_to_queue[ac]; | |
1404 | ||
1405 | if (vif->type == NL80211_IFTYPE_AP) | |
1406 | vif->cab_queue = ctx->mcast_queue; | |
1407 | else | |
1408 | vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; | |
1409 | ||
0b7a4c78 WYG |
1410 | return 0; |
1411 | } | |
1412 | ||
1413 | static int iwlagn_mac_add_interface(struct ieee80211_hw *hw, | |
1479177b | 1414 | struct ieee80211_vif *vif) |
0b7a4c78 | 1415 | { |
d0f76d68 | 1416 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
0b7a4c78 WYG |
1417 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
1418 | struct iwl_rxon_context *tmp, *ctx = NULL; | |
1419 | int err; | |
1420 | enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif); | |
8db4c7e2 | 1421 | bool reset = false; |
0b7a4c78 WYG |
1422 | |
1423 | IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n", | |
1424 | viftype, vif->addr); | |
1425 | ||
1426 | cancel_delayed_work_sync(&priv->hw_roc_disable_work); | |
1427 | ||
b1eea297 | 1428 | mutex_lock(&priv->mutex); |
0b7a4c78 WYG |
1429 | |
1430 | iwlagn_disable_roc(priv); | |
1431 | ||
83626404 | 1432 | if (!iwl_is_ready_rf(priv)) { |
0b7a4c78 WYG |
1433 | IWL_WARN(priv, "Try to add interface when device not ready\n"); |
1434 | err = -EINVAL; | |
1435 | goto out; | |
1436 | } | |
1437 | ||
1438 | for_each_context(priv, tmp) { | |
1439 | u32 possible_modes = | |
1440 | tmp->interface_modes | tmp->exclusive_interface_modes; | |
1441 | ||
1442 | if (tmp->vif) { | |
8db4c7e2 SG |
1443 | /* On reset we need to add the same interface again */ |
1444 | if (tmp->vif == vif) { | |
1445 | reset = true; | |
1446 | ctx = tmp; | |
1447 | break; | |
1448 | } | |
1449 | ||
0b7a4c78 WYG |
1450 | /* check if this busy context is exclusive */ |
1451 | if (tmp->exclusive_interface_modes & | |
1452 | BIT(tmp->vif->type)) { | |
1453 | err = -EINVAL; | |
1454 | goto out; | |
1455 | } | |
1456 | continue; | |
1457 | } | |
1458 | ||
1459 | if (!(possible_modes & BIT(viftype))) | |
1460 | continue; | |
1461 | ||
1462 | /* have maybe usable context w/o interface */ | |
1463 | ctx = tmp; | |
1464 | break; | |
1465 | } | |
1466 | ||
1467 | if (!ctx) { | |
1468 | err = -EOPNOTSUPP; | |
1469 | goto out; | |
1470 | } | |
1471 | ||
1472 | vif_priv->ctx = ctx; | |
1473 | ctx->vif = vif; | |
1474 | ||
04baaa27 JB |
1475 | /* |
1476 | * In SNIFFER device type, the firmware reports the FCS to | |
1477 | * the host, rather than snipping it off. Unfortunately, | |
1478 | * mac80211 doesn't (yet) provide a per-packet flag for | |
1479 | * this, so that we have to set the hardware flag based | |
1480 | * on the interfaces added. As the monitor interface can | |
1481 | * only be present by itself, and will be removed before | |
1482 | * other interfaces are added, this is safe. | |
1483 | */ | |
1484 | if (vif->type == NL80211_IFTYPE_MONITOR) | |
1485 | priv->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS; | |
1486 | else | |
1487 | priv->hw->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS; | |
1488 | ||
0b7a4c78 | 1489 | err = iwl_setup_interface(priv, ctx); |
8db4c7e2 | 1490 | if (!err || reset) |
0b7a4c78 WYG |
1491 | goto out; |
1492 | ||
1493 | ctx->vif = NULL; | |
1494 | priv->iw_mode = NL80211_IFTYPE_STATION; | |
1495 | out: | |
b1eea297 | 1496 | mutex_unlock(&priv->mutex); |
0b7a4c78 WYG |
1497 | |
1498 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
1499 | return err; | |
1500 | } | |
1501 | ||
aca86268 JB |
1502 | static void iwl_teardown_interface(struct iwl_priv *priv, |
1503 | struct ieee80211_vif *vif, | |
1504 | bool mode_change) | |
0b7a4c78 WYG |
1505 | { |
1506 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); | |
1507 | ||
b1eea297 | 1508 | lockdep_assert_held(&priv->mutex); |
0b7a4c78 WYG |
1509 | |
1510 | if (priv->scan_vif == vif) { | |
1511 | iwl_scan_cancel_timeout(priv, 200); | |
1512 | iwl_force_scan_end(priv); | |
1513 | } | |
1514 | ||
1515 | if (!mode_change) { | |
1516 | iwl_set_mode(priv, ctx); | |
1517 | if (!ctx->always_active) | |
1518 | ctx->is_active = false; | |
1519 | } | |
1520 | ||
1521 | /* | |
1522 | * When removing the IBSS interface, overwrite the | |
1523 | * BT traffic load with the stored one from the last | |
1524 | * notification, if any. If this is a device that | |
1525 | * doesn't implement this, this has no effect since | |
1526 | * both values are the same and zero. | |
1527 | */ | |
1528 | if (vif->type == NL80211_IFTYPE_ADHOC) | |
1529 | priv->bt_traffic_load = priv->last_bt_traffic_load; | |
1530 | } | |
1531 | ||
1532 | static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw, | |
1533 | struct ieee80211_vif *vif) | |
1534 | { | |
d0f76d68 | 1535 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
0b7a4c78 WYG |
1536 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
1537 | ||
1538 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
1539 | ||
b1eea297 | 1540 | mutex_lock(&priv->mutex); |
0b7a4c78 WYG |
1541 | |
1542 | if (WARN_ON(ctx->vif != vif)) { | |
1543 | struct iwl_rxon_context *tmp; | |
1544 | IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif); | |
1545 | for_each_context(priv, tmp) | |
1546 | IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n", | |
1547 | tmp->ctxid, tmp, tmp->vif); | |
1548 | } | |
1549 | ctx->vif = NULL; | |
1550 | ||
1551 | iwl_teardown_interface(priv, vif, false); | |
1552 | ||
b1eea297 | 1553 | mutex_unlock(&priv->mutex); |
0b7a4c78 WYG |
1554 | |
1555 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
1556 | ||
1557 | } | |
1558 | ||
1559 | static int iwlagn_mac_change_interface(struct ieee80211_hw *hw, | |
e75dac92 JB |
1560 | struct ieee80211_vif *vif, |
1561 | enum nl80211_iftype newtype, bool newp2p) | |
0b7a4c78 | 1562 | { |
d0f76d68 | 1563 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
e75dac92 | 1564 | struct iwl_rxon_context *ctx, *tmp; |
0b7a4c78 WYG |
1565 | enum nl80211_iftype newviftype = newtype; |
1566 | u32 interface_modes; | |
1567 | int err; | |
1568 | ||
1569 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
1570 | ||
1571 | newtype = ieee80211_iftype_p2p(newtype, newp2p); | |
1572 | ||
b1eea297 | 1573 | mutex_lock(&priv->mutex); |
0b7a4c78 | 1574 | |
e75dac92 JB |
1575 | ctx = iwl_rxon_ctx_from_vif(vif); |
1576 | ||
1577 | /* | |
1578 | * To simplify this code, only support changes on the | |
1579 | * BSS context. The PAN context is usually reassigned | |
1580 | * by creating/removing P2P interfaces anyway. | |
1581 | */ | |
1582 | if (ctx->ctxid != IWL_RXON_CTX_BSS) { | |
1583 | err = -EBUSY; | |
1584 | goto out; | |
1585 | } | |
1586 | ||
83626404 | 1587 | if (!ctx->vif || !iwl_is_ready_rf(priv)) { |
0b7a4c78 WYG |
1588 | /* |
1589 | * Huh? But wait ... this can maybe happen when | |
1590 | * we're in the middle of a firmware restart! | |
1591 | */ | |
1592 | err = -EBUSY; | |
1593 | goto out; | |
1594 | } | |
1595 | ||
e75dac92 | 1596 | /* Check if the switch is supported in the same context */ |
0b7a4c78 | 1597 | interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes; |
0b7a4c78 WYG |
1598 | if (!(interface_modes & BIT(newtype))) { |
1599 | err = -EBUSY; | |
1600 | goto out; | |
1601 | } | |
1602 | ||
0b7a4c78 WYG |
1603 | if (ctx->exclusive_interface_modes & BIT(newtype)) { |
1604 | for_each_context(priv, tmp) { | |
1605 | if (ctx == tmp) | |
1606 | continue; | |
1607 | ||
e75dac92 | 1608 | if (!tmp->is_active) |
0b7a4c78 WYG |
1609 | continue; |
1610 | ||
1611 | /* | |
1612 | * The current mode switch would be exclusive, but | |
1613 | * another context is active ... refuse the switch. | |
1614 | */ | |
1615 | err = -EBUSY; | |
1616 | goto out; | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | /* success */ | |
1621 | iwl_teardown_interface(priv, vif, true); | |
1622 | vif->type = newviftype; | |
1623 | vif->p2p = newp2p; | |
1624 | err = iwl_setup_interface(priv, ctx); | |
1625 | WARN_ON(err); | |
1626 | /* | |
1627 | * We've switched internally, but submitting to the | |
1628 | * device may have failed for some reason. Mask this | |
1629 | * error, because otherwise mac80211 will not switch | |
1630 | * (and set the interface type back) and we'll be | |
1631 | * out of sync with it. | |
1632 | */ | |
1633 | err = 0; | |
1634 | ||
1635 | out: | |
b1eea297 | 1636 | mutex_unlock(&priv->mutex); |
0b7a4c78 WYG |
1637 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
1638 | ||
1639 | return err; | |
1640 | } | |
1641 | ||
aca86268 JB |
1642 | static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw, |
1643 | struct ieee80211_vif *vif, | |
1644 | struct cfg80211_scan_request *req) | |
ba4c5319 | 1645 | { |
d0f76d68 | 1646 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
ba4c5319 WYG |
1647 | int ret; |
1648 | ||
1649 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
1650 | ||
1651 | if (req->n_channels == 0) | |
1652 | return -EINVAL; | |
1653 | ||
b1eea297 | 1654 | mutex_lock(&priv->mutex); |
ba4c5319 WYG |
1655 | |
1656 | /* | |
1657 | * If an internal scan is in progress, just set | |
1658 | * up the scan_request as per above. | |
1659 | */ | |
1660 | if (priv->scan_type != IWL_SCAN_NORMAL) { | |
1661 | IWL_DEBUG_SCAN(priv, | |
1662 | "SCAN request during internal scan - defer\n"); | |
1663 | priv->scan_request = req; | |
1664 | priv->scan_vif = vif; | |
1665 | ret = 0; | |
1666 | } else { | |
1667 | priv->scan_request = req; | |
1668 | priv->scan_vif = vif; | |
1669 | /* | |
1670 | * mac80211 will only ask for one band at a time | |
1671 | * so using channels[0] here is ok | |
1672 | */ | |
1673 | ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL, | |
1674 | req->channels[0]->band); | |
1675 | if (ret) { | |
1676 | priv->scan_request = NULL; | |
1677 | priv->scan_vif = NULL; | |
1678 | } | |
1679 | } | |
1680 | ||
1681 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
1682 | ||
b1eea297 | 1683 | mutex_unlock(&priv->mutex); |
ba4c5319 WYG |
1684 | |
1685 | return ret; | |
1686 | } | |
1687 | ||
76b29331 WYG |
1688 | static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) |
1689 | { | |
9451ca1a JB |
1690 | struct iwl_addsta_cmd cmd = { |
1691 | .mode = STA_CONTROL_MODIFY_MSK, | |
1692 | .station_flags_msk = STA_FLG_PWR_SAVE_MSK, | |
1693 | .sta.sta_id = sta_id, | |
1694 | }; | |
76b29331 | 1695 | |
9451ca1a | 1696 | iwl_send_add_sta(priv, &cmd, CMD_ASYNC); |
76b29331 WYG |
1697 | } |
1698 | ||
aca86268 JB |
1699 | static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw, |
1700 | struct ieee80211_vif *vif, | |
1701 | enum sta_notify_cmd cmd, | |
1702 | struct ieee80211_sta *sta) | |
76b29331 | 1703 | { |
d0f76d68 | 1704 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
76b29331 WYG |
1705 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
1706 | int sta_id; | |
1707 | ||
1708 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
1709 | ||
1710 | switch (cmd) { | |
1711 | case STA_NOTIFY_SLEEP: | |
1712 | WARN_ON(!sta_priv->client); | |
1713 | sta_priv->asleep = true; | |
1714 | if (atomic_read(&sta_priv->pending_frames) > 0) | |
1715 | ieee80211_sta_block_awake(hw, sta, true); | |
1716 | break; | |
1717 | case STA_NOTIFY_AWAKE: | |
1718 | WARN_ON(!sta_priv->client); | |
1719 | if (!sta_priv->asleep) | |
1720 | break; | |
1721 | sta_priv->asleep = false; | |
1722 | sta_id = iwl_sta_id(sta); | |
1723 | if (sta_id != IWL_INVALID_STATION) | |
1724 | iwl_sta_modify_ps_wake(priv, sta_id); | |
1725 | break; | |
1726 | default: | |
1727 | break; | |
1728 | } | |
1729 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
1730 | } | |
1731 | ||
7335613a WYG |
1732 | struct ieee80211_ops iwlagn_hw_ops = { |
1733 | .tx = iwlagn_mac_tx, | |
1734 | .start = iwlagn_mac_start, | |
1735 | .stop = iwlagn_mac_stop, | |
1736 | #ifdef CONFIG_PM_SLEEP | |
1737 | .suspend = iwlagn_mac_suspend, | |
1738 | .resume = iwlagn_mac_resume, | |
76ed2edd | 1739 | .set_wakeup = iwlagn_mac_set_wakeup, |
7335613a WYG |
1740 | #endif |
1741 | .add_interface = iwlagn_mac_add_interface, | |
1742 | .remove_interface = iwlagn_mac_remove_interface, | |
1743 | .change_interface = iwlagn_mac_change_interface, | |
1744 | .config = iwlagn_mac_config, | |
1745 | .configure_filter = iwlagn_configure_filter, | |
1746 | .set_key = iwlagn_mac_set_key, | |
1747 | .update_tkip_key = iwlagn_mac_update_tkip_key, | |
1748 | .set_rekey_data = iwlagn_mac_set_rekey_data, | |
1749 | .conf_tx = iwlagn_mac_conf_tx, | |
1750 | .bss_info_changed = iwlagn_bss_info_changed, | |
1751 | .ampdu_action = iwlagn_mac_ampdu_action, | |
1752 | .hw_scan = iwlagn_mac_hw_scan, | |
1753 | .sta_notify = iwlagn_mac_sta_notify, | |
fb5fe5b9 | 1754 | .sta_state = iwlagn_mac_sta_state, |
7335613a WYG |
1755 | .channel_switch = iwlagn_mac_channel_switch, |
1756 | .flush = iwlagn_mac_flush, | |
1757 | .tx_last_beacon = iwlagn_mac_tx_last_beacon, | |
1758 | .remain_on_channel = iwlagn_mac_remain_on_channel, | |
1759 | .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel, | |
1760 | .rssi_callback = iwlagn_mac_rssi_callback, | |
1761 | CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd) | |
1762 | CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump) | |
7335613a WYG |
1763 | .set_tim = iwlagn_mac_set_tim, |
1764 | }; | |
1765 | ||
1766 | /* This function both allocates and initializes hw and priv. */ | |
1767 | struct ieee80211_hw *iwl_alloc_all(void) | |
1768 | { | |
1769 | struct iwl_priv *priv; | |
d0f76d68 | 1770 | struct iwl_op_mode *op_mode; |
7335613a WYG |
1771 | /* mac80211 allocates memory for this device instance, including |
1772 | * space for this driver's private structure */ | |
1773 | struct ieee80211_hw *hw; | |
1774 | ||
d0f76d68 EG |
1775 | hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) + |
1776 | sizeof(struct iwl_op_mode), &iwlagn_hw_ops); | |
7335613a WYG |
1777 | if (!hw) |
1778 | goto out; | |
1779 | ||
d0f76d68 EG |
1780 | op_mode = hw->priv; |
1781 | priv = IWL_OP_MODE_GET_DVM(op_mode); | |
7335613a WYG |
1782 | priv->hw = hw; |
1783 | ||
1784 | out: | |
1785 | return hw; | |
1786 | } |