]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/net/wireless/iwmc3200wifi/main.c
iwmc3200wifi: Add wifi-wimax coexistence mode as a module parameter
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / iwmc3200wifi / main.c
CommitLineData
bb9f8692
ZY
1/*
2 * Intel Wireless Multicomm 3200 WiFi driver
3 *
4 * Copyright (C) 2009 Intel Corporation. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *
33 * Intel Corporation <ilw@linux.intel.com>
34 * Samuel Ortiz <samuel.ortiz@intel.com>
35 * Zhu Yi <yi.zhu@intel.com>
36 *
37 */
38
39#include <linux/kernel.h>
40#include <linux/netdevice.h>
d43c36dc 41#include <linux/sched.h>
bb9f8692
ZY
42#include <linux/ieee80211.h>
43#include <linux/wireless.h>
44
45#include "iwm.h"
46#include "debug.h"
47#include "bus.h"
48#include "umac.h"
49#include "commands.h"
50#include "hal.h"
51#include "fw.h"
52#include "rx.h"
53
54static struct iwm_conf def_iwm_conf = {
55
56 .sdio_ior_timeout = 5000,
d04bd628
SO
57 .calib_map = BIT(CALIB_CFG_DC_IDX) |
58 BIT(CALIB_CFG_LO_IDX) |
59 BIT(CALIB_CFG_TX_IQ_IDX) |
60 BIT(CALIB_CFG_RX_IQ_IDX) |
61 BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD),
62 .expected_calib_map = BIT(PHY_CALIBRATE_DC_CMD) |
bb9f8692
ZY
63 BIT(PHY_CALIBRATE_LO_CMD) |
64 BIT(PHY_CALIBRATE_TX_IQ_CMD) |
65 BIT(PHY_CALIBRATE_RX_IQ_CMD) |
66 BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD),
e85498b2
SO
67 .ct_kill_entry = 110,
68 .ct_kill_exit = 110,
bb9f8692
ZY
69 .reset_on_fatal_err = 1,
70 .auto_connect = 1,
71 .wimax_not_present = 0,
72 .enable_qos = 1,
73 .mode = UMAC_MODE_BSS,
74
75 /* UMAC configuration */
76 .power_index = 0,
77 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
78 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
79 .cts_to_self = 0,
80
81 .assoc_timeout = 2,
82 .roam_timeout = 10,
0bed08de
SO
83 .wireless_mode = WIRELESS_MODE_11A | WIRELESS_MODE_11G |
84 WIRELESS_MODE_11N,
bb9f8692
ZY
85
86 /* IBSS */
87 .ibss_band = UMAC_BAND_2GHZ,
88 .ibss_channel = 1,
89
90 .mac_addr = {0x00, 0x02, 0xb3, 0x01, 0x02, 0x03},
91};
92
93static int modparam_reset;
94module_param_named(reset, modparam_reset, bool, 0644);
95MODULE_PARM_DESC(reset, "reset on firmware errors (default 0 [not reset])");
96
97int iwm_mode_to_nl80211_iftype(int mode)
98{
99 switch (mode) {
100 case UMAC_MODE_BSS:
101 return NL80211_IFTYPE_STATION;
102 case UMAC_MODE_IBSS:
103 return NL80211_IFTYPE_ADHOC;
104 default:
105 return NL80211_IFTYPE_UNSPECIFIED;
106 }
107
108 return 0;
109}
110
111static void iwm_statistics_request(struct work_struct *work)
112{
113 struct iwm_priv *iwm =
114 container_of(work, struct iwm_priv, stats_request.work);
115
116 iwm_send_umac_stats_req(iwm, 0);
117}
118
c7436273
ZY
119static void iwm_disconnect_work(struct work_struct *work)
120{
121 struct iwm_priv *iwm =
122 container_of(work, struct iwm_priv, disconnect.work);
123
124 if (iwm->umac_profile_active)
125 iwm_invalidate_mlme_profile(iwm);
126
127 clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
128 iwm->umac_profile_active = 0;
129 memset(iwm->bssid, 0, ETH_ALEN);
130 iwm->channel = 0;
131
132 iwm_link_off(iwm);
133
134 wake_up_interruptible(&iwm->mlme_queue);
135
136 cfg80211_disconnected(iwm_to_ndev(iwm), 0, NULL, 0, GFP_KERNEL);
137}
138
e85498b2
SO
139static void iwm_ct_kill_work(struct work_struct *work)
140{
141 struct iwm_priv *iwm =
142 container_of(work, struct iwm_priv, ct_kill_delay.work);
143 struct wiphy *wiphy = iwm_to_wiphy(iwm);
144
145 IWM_INFO(iwm, "CT kill delay timeout\n");
146
147 wiphy_rfkill_set_hw_state(wiphy, false);
148}
149
31452420
ZY
150static int __iwm_up(struct iwm_priv *iwm);
151static int __iwm_down(struct iwm_priv *iwm);
68810c5d 152
bb9f8692
ZY
153static void iwm_reset_worker(struct work_struct *work)
154{
155 struct iwm_priv *iwm;
156 struct iwm_umac_profile *profile = NULL;
157 int uninitialized_var(ret), retry = 0;
158
159 iwm = container_of(work, struct iwm_priv, reset_worker);
160
68810c5d
ZY
161 /*
162 * XXX: The iwm->mutex is introduced purely for this reset work,
163 * because the other users for iwm_up and iwm_down are only netdev
164 * ndo_open and ndo_stop which are already protected by rtnl.
165 * Please remove iwm->mutex together if iwm_reset_worker() is not
166 * required in the future.
167 */
168 if (!mutex_trylock(&iwm->mutex)) {
169 IWM_WARN(iwm, "We are in the middle of interface bringing "
170 "UP/DOWN. Skip driver resetting.\n");
171 return;
172 }
173
bb9f8692
ZY
174 if (iwm->umac_profile_active) {
175 profile = kmalloc(sizeof(struct iwm_umac_profile), GFP_KERNEL);
176 if (profile)
177 memcpy(profile, iwm->umac_profile, sizeof(*profile));
178 else
179 IWM_ERR(iwm, "Couldn't alloc memory for profile\n");
180 }
181
68810c5d 182 __iwm_down(iwm);
bb9f8692
ZY
183
184 while (retry++ < 3) {
68810c5d 185 ret = __iwm_up(iwm);
bb9f8692
ZY
186 if (!ret)
187 break;
188
189 schedule_timeout_uninterruptible(10 * HZ);
190 }
191
192 if (ret) {
193 IWM_WARN(iwm, "iwm_up() failed: %d\n", ret);
194
195 kfree(profile);
68810c5d 196 goto out;
bb9f8692
ZY
197 }
198
199 if (profile) {
200 IWM_DBG_MLME(iwm, DBG, "Resend UMAC profile\n");
201 memcpy(iwm->umac_profile, profile, sizeof(*profile));
202 iwm_send_mlme_profile(iwm);
203 kfree(profile);
d210176e
SO
204 } else
205 clear_bit(IWM_STATUS_RESETTING, &iwm->status);
68810c5d
ZY
206
207 out:
208 mutex_unlock(&iwm->mutex);
bb9f8692
ZY
209}
210
9829e1b5
SO
211static void iwm_auth_retry_worker(struct work_struct *work)
212{
213 struct iwm_priv *iwm;
214 int i, ret;
215
216 iwm = container_of(work, struct iwm_priv, auth_retry_worker);
217 if (iwm->umac_profile_active) {
218 ret = iwm_invalidate_mlme_profile(iwm);
219 if (ret < 0)
220 return;
221 }
222
223 iwm->umac_profile->sec.auth_type = UMAC_AUTH_TYPE_LEGACY_PSK;
224
225 ret = iwm_send_mlme_profile(iwm);
226 if (ret < 0)
227 return;
228
229 for (i = 0; i < IWM_NUM_KEYS; i++)
230 if (iwm->keys[i].key_len)
231 iwm_set_key(iwm, 0, &iwm->keys[i]);
232
233 iwm_set_tx_key(iwm, iwm->default_key);
234}
235
236
237
bb9f8692
ZY
238static void iwm_watchdog(unsigned long data)
239{
240 struct iwm_priv *iwm = (struct iwm_priv *)data;
241
242 IWM_WARN(iwm, "Watchdog expired: UMAC stalls!\n");
243
244 if (modparam_reset)
d210176e 245 iwm_resetting(iwm);
bb9f8692
ZY
246}
247
248int iwm_priv_init(struct iwm_priv *iwm)
249{
a7af530d 250 int i, j;
bb9f8692
ZY
251 char name[32];
252
253 iwm->status = 0;
254 INIT_LIST_HEAD(&iwm->pending_notif);
255 init_waitqueue_head(&iwm->notif_queue);
256 init_waitqueue_head(&iwm->nonwifi_queue);
a70742f1 257 init_waitqueue_head(&iwm->wifi_ntfy_queue);
bb9f8692
ZY
258 init_waitqueue_head(&iwm->mlme_queue);
259 memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf));
260 spin_lock_init(&iwm->tx_credit.lock);
261 INIT_LIST_HEAD(&iwm->wifi_pending_cmd);
262 INIT_LIST_HEAD(&iwm->nonwifi_pending_cmd);
263 iwm->wifi_seq_num = UMAC_WIFI_SEQ_NUM_BASE;
264 iwm->nonwifi_seq_num = UMAC_NONWIFI_SEQ_NUM_BASE;
265 spin_lock_init(&iwm->cmd_lock);
266 iwm->scan_id = 1;
267 INIT_DELAYED_WORK(&iwm->stats_request, iwm_statistics_request);
c7436273 268 INIT_DELAYED_WORK(&iwm->disconnect, iwm_disconnect_work);
e85498b2 269 INIT_DELAYED_WORK(&iwm->ct_kill_delay, iwm_ct_kill_work);
bb9f8692 270 INIT_WORK(&iwm->reset_worker, iwm_reset_worker);
9829e1b5 271 INIT_WORK(&iwm->auth_retry_worker, iwm_auth_retry_worker);
bb9f8692
ZY
272 INIT_LIST_HEAD(&iwm->bss_list);
273
274 skb_queue_head_init(&iwm->rx_list);
275 INIT_LIST_HEAD(&iwm->rx_tickets);
276 for (i = 0; i < IWM_RX_ID_HASH; i++)
277 INIT_LIST_HEAD(&iwm->rx_packets[i]);
278
279 INIT_WORK(&iwm->rx_worker, iwm_rx_worker);
280
281 iwm->rx_wq = create_singlethread_workqueue(KBUILD_MODNAME "_rx");
282 if (!iwm->rx_wq)
283 return -EAGAIN;
284
285 for (i = 0; i < IWM_TX_QUEUES; i++) {
286 INIT_WORK(&iwm->txq[i].worker, iwm_tx_worker);
287 snprintf(name, 32, KBUILD_MODNAME "_tx_%d", i);
288 iwm->txq[i].id = i;
289 iwm->txq[i].wq = create_singlethread_workqueue(name);
290 if (!iwm->txq[i].wq)
291 return -EAGAIN;
292
293 skb_queue_head_init(&iwm->txq[i].queue);
a7af530d
SO
294 skb_queue_head_init(&iwm->txq[i].stopped_queue);
295 spin_lock_init(&iwm->txq[i].lock);
bb9f8692
ZY
296 }
297
298 for (i = 0; i < IWM_NUM_KEYS; i++)
299 memset(&iwm->keys[i], 0, sizeof(struct iwm_key));
300
13e0fe70 301 iwm->default_key = -1;
bb9f8692 302
a7af530d
SO
303 for (i = 0; i < IWM_STA_TABLE_NUM; i++)
304 for (j = 0; j < IWM_UMAC_TID_NR; j++) {
305 mutex_init(&iwm->sta_table[i].tid_info[j].mutex);
306 iwm->sta_table[i].tid_info[j].stopped = false;
307 }
308
bb9f8692
ZY
309 init_timer(&iwm->watchdog);
310 iwm->watchdog.function = iwm_watchdog;
311 iwm->watchdog.data = (unsigned long)iwm;
68810c5d 312 mutex_init(&iwm->mutex);
bb9f8692 313
04e715cd
SO
314 iwm->last_fw_err = kzalloc(sizeof(struct iwm_fw_error_hdr),
315 GFP_KERNEL);
316 if (iwm->last_fw_err == NULL)
317 return -ENOMEM;
318
bb9f8692
ZY
319 return 0;
320}
321
8d96e796
ZY
322void iwm_priv_deinit(struct iwm_priv *iwm)
323{
324 int i;
325
326 for (i = 0; i < IWM_TX_QUEUES; i++)
327 destroy_workqueue(iwm->txq[i].wq);
328
329 destroy_workqueue(iwm->rx_wq);
04e715cd 330 kfree(iwm->last_fw_err);
8d96e796
ZY
331}
332
bb9f8692
ZY
333/*
334 * We reset all the structures, and we reset the UMAC.
335 * After calling this routine, you're expected to reload
336 * the firmware.
337 */
338void iwm_reset(struct iwm_priv *iwm)
339{
340 struct iwm_notif *notif, *next;
341
342 if (test_bit(IWM_STATUS_READY, &iwm->status))
343 iwm_target_reset(iwm);
344
d210176e
SO
345 if (test_bit(IWM_STATUS_RESETTING, &iwm->status)) {
346 iwm->status = 0;
347 set_bit(IWM_STATUS_RESETTING, &iwm->status);
348 } else
349 iwm->status = 0;
bb9f8692
ZY
350 iwm->scan_id = 1;
351
352 list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
353 list_del(&notif->pending);
354 kfree(notif->buf);
355 kfree(notif);
356 }
357
358 iwm_cmd_flush(iwm);
359
360 flush_workqueue(iwm->rx_wq);
361
362 iwm_link_off(iwm);
363}
364
d210176e
SO
365void iwm_resetting(struct iwm_priv *iwm)
366{
367 set_bit(IWM_STATUS_RESETTING, &iwm->status);
368
369 schedule_work(&iwm->reset_worker);
370}
371
bb9f8692
ZY
372/*
373 * Notification code:
374 *
375 * We're faced with the following issue: Any host command can
376 * have an answer or not, and if there's an answer to expect,
377 * it can be treated synchronously or asynchronously.
378 * To work around the synchronous answer case, we implemented
379 * our notification mechanism.
380 * When a code path needs to wait for a command response
381 * synchronously, it calls notif_handle(), which waits for the
382 * right notification to show up, and then process it. Before
383 * starting to wait, it registered as a waiter for this specific
384 * answer (by toggling a bit in on of the handler_map), so that
385 * the rx code knows that it needs to send a notification to the
386 * waiting processes. It does so by calling iwm_notif_send(),
387 * which adds the notification to the pending notifications list,
388 * and then wakes the waiting processes up.
389 */
390int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
391 u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size)
392{
393 struct iwm_notif *notif;
394
395 notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL);
396 if (!notif) {
397 IWM_ERR(iwm, "Couldn't alloc memory for notification\n");
398 return -ENOMEM;
399 }
400
401 INIT_LIST_HEAD(&notif->pending);
402 notif->cmd = cmd;
403 notif->cmd_id = cmd_id;
404 notif->src = source;
405 notif->buf = kzalloc(buf_size, GFP_KERNEL);
406 if (!notif->buf) {
407 IWM_ERR(iwm, "Couldn't alloc notification buffer\n");
408 kfree(notif);
409 return -ENOMEM;
410 }
411 notif->buf_size = buf_size;
412 memcpy(notif->buf, buf, buf_size);
413 list_add_tail(&notif->pending, &iwm->pending_notif);
414
415 wake_up_interruptible(&iwm->notif_queue);
416
417 return 0;
418}
419
420static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd,
421 u8 source)
422{
423 struct iwm_notif *notif, *next;
424
425 list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
426 if ((notif->cmd_id == cmd) && (notif->src == source)) {
427 list_del(&notif->pending);
428 return notif;
429 }
430 }
431
432 return NULL;
433}
434
435static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd,
436 u8 source, long timeout)
437{
438 int ret;
439 struct iwm_notif *notif;
440 unsigned long *map = NULL;
441
442 switch (source) {
443 case IWM_SRC_LMAC:
444 map = &iwm->lmac_handler_map[0];
445 break;
446 case IWM_SRC_UMAC:
447 map = &iwm->umac_handler_map[0];
448 break;
449 case IWM_SRC_UDMA:
450 map = &iwm->udma_handler_map[0];
451 break;
452 }
453
454 set_bit(cmd, map);
455
456 ret = wait_event_interruptible_timeout(iwm->notif_queue,
457 ((notif = iwm_notif_find(iwm, cmd, source)) != NULL),
458 timeout);
459 clear_bit(cmd, map);
460
461 if (!ret)
462 return NULL;
463
464 return notif;
465}
466
467int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout)
468{
469 int ret;
470 struct iwm_notif *notif;
471
472 notif = iwm_notif_wait(iwm, cmd, source, timeout);
473 if (!notif)
474 return -ETIME;
475
476 ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd);
477 kfree(notif->buf);
478 kfree(notif);
479
480 return ret;
481}
482
483static int iwm_config_boot_params(struct iwm_priv *iwm)
484{
485 struct iwm_udma_nonwifi_cmd target_cmd;
486 int ret;
487
488 /* check Wimax is off and config debug monitor */
489 if (iwm->conf.wimax_not_present) {
490 u32 data1 = 0x1f;
491 u32 addr1 = 0x606BE258;
492
493 u32 data2_set = 0x0;
494 u32 data2_clr = 0x1;
495 u32 addr2 = 0x606BE100;
496
497 u32 data3 = 0x1;
498 u32 addr3 = 0x606BEC00;
499
500 target_cmd.resp = 0;
501 target_cmd.handle_by_hw = 0;
502 target_cmd.eop = 1;
503
504 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
505 target_cmd.addr = cpu_to_le32(addr1);
506 target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
507 target_cmd.op2 = 0;
508
509 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
510 if (ret < 0) {
511 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
512 return ret;
513 }
514
515 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE;
516 target_cmd.addr = cpu_to_le32(addr2);
517 target_cmd.op1_sz = cpu_to_le32(data2_set);
518 target_cmd.op2 = cpu_to_le32(data2_clr);
519
520 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
521 if (ret < 0) {
522 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
523 return ret;
524 }
525
526 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
527 target_cmd.addr = cpu_to_le32(addr3);
528 target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
529 target_cmd.op2 = 0;
530
531 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3);
532 if (ret < 0) {
533 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
534 return ret;
535 }
536 }
537
538 return 0;
539}
540
541void iwm_init_default_profile(struct iwm_priv *iwm,
542 struct iwm_umac_profile *profile)
543{
544 memset(profile, 0, sizeof(struct iwm_umac_profile));
545
546 profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN;
547 profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE;
548 profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE;
549 profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE;
550
551 if (iwm->conf.enable_qos)
552 profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED);
553
554 profile->wireless_mode = iwm->conf.wireless_mode;
555 profile->mode = cpu_to_le32(iwm->conf.mode);
556
557 profile->ibss.atim = 0;
558 profile->ibss.beacon_interval = 100;
559 profile->ibss.join_only = 0;
560 profile->ibss.band = iwm->conf.ibss_band;
561 profile->ibss.channel = iwm->conf.ibss_channel;
562}
563
564void iwm_link_on(struct iwm_priv *iwm)
565{
566 netif_carrier_on(iwm_to_ndev(iwm));
567 netif_tx_wake_all_queues(iwm_to_ndev(iwm));
568
569 iwm_send_umac_stats_req(iwm, 0);
570}
571
572void iwm_link_off(struct iwm_priv *iwm)
573{
574 struct iw_statistics *wstats = &iwm->wstats;
575 int i;
576
577 netif_tx_stop_all_queues(iwm_to_ndev(iwm));
578 netif_carrier_off(iwm_to_ndev(iwm));
579
580 for (i = 0; i < IWM_TX_QUEUES; i++) {
581 skb_queue_purge(&iwm->txq[i].queue);
a7af530d 582 skb_queue_purge(&iwm->txq[i].stopped_queue);
bb9f8692
ZY
583
584 iwm->txq[i].concat_count = 0;
585 iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf;
586
587 flush_workqueue(iwm->txq[i].wq);
588 }
589
590 iwm_rx_free(iwm);
591
68810c5d 592 cancel_delayed_work_sync(&iwm->stats_request);
bb9f8692
ZY
593 memset(wstats, 0, sizeof(struct iw_statistics));
594 wstats->qual.updated = IW_QUAL_ALL_INVALID;
595
b68518fc
ZY
596 kfree(iwm->req_ie);
597 iwm->req_ie = NULL;
598 iwm->req_ie_len = 0;
599 kfree(iwm->resp_ie);
600 iwm->resp_ie = NULL;
601 iwm->resp_ie_len = 0;
602
bb9f8692
ZY
603 del_timer_sync(&iwm->watchdog);
604}
605
606static void iwm_bss_list_clean(struct iwm_priv *iwm)
607{
608 struct iwm_bss_info *bss, *next;
609
610 list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
611 list_del(&bss->node);
612 kfree(bss->bss);
613 kfree(bss);
614 }
615}
616
617static int iwm_channels_init(struct iwm_priv *iwm)
618{
619 int ret;
620
bb9f8692
ZY
621 ret = iwm_send_umac_channel_list(iwm);
622 if (ret) {
623 IWM_ERR(iwm, "Send channel list failed\n");
624 return ret;
625 }
626
627 ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST,
628 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
629 if (ret) {
630 IWM_ERR(iwm, "Didn't get a channel list notification\n");
631 return ret;
632 }
633
634 return 0;
635}
636
31452420 637static int __iwm_up(struct iwm_priv *iwm)
bb9f8692
ZY
638{
639 int ret;
640 struct iwm_notif *notif_reboot, *notif_ack = NULL;
5dc53163 641 struct wiphy *wiphy = iwm_to_wiphy(iwm);
0bed08de 642 u32 wireless_mode;
bb9f8692
ZY
643
644 ret = iwm_bus_enable(iwm);
645 if (ret) {
646 IWM_ERR(iwm, "Couldn't enable function\n");
647 return ret;
648 }
649
650 iwm_rx_setup_handlers(iwm);
651
652 /* Wait for initial BARKER_REBOOT from hardware */
653 notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION,
654 IWM_SRC_UDMA, 2 * HZ);
655 if (!notif_reboot) {
656 IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n");
657 goto err_disable;
658 }
659
660 /* We send the barker back */
661 ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16);
662 if (ret) {
663 IWM_ERR(iwm, "REBOOT barker response failed\n");
664 kfree(notif_reboot);
665 goto err_disable;
666 }
667
668 kfree(notif_reboot->buf);
669 kfree(notif_reboot);
670
671 /* Wait for ACK_BARKER from hardware */
672 notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION,
673 IWM_SRC_UDMA, 2 * HZ);
674 if (!notif_ack) {
675 IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n");
676 goto err_disable;
677 }
678
679 kfree(notif_ack->buf);
680 kfree(notif_ack);
681
682 /* We start to config static boot parameters */
683 ret = iwm_config_boot_params(iwm);
684 if (ret) {
685 IWM_ERR(iwm, "Config boot parameters failed\n");
686 goto err_disable;
687 }
688
689 ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr);
690 if (ret) {
691 IWM_ERR(iwm, "MAC reading failed\n");
692 goto err_disable;
693 }
5b367378
JL
694 memcpy(iwm_to_ndev(iwm)->perm_addr, iwm_to_ndev(iwm)->dev_addr,
695 ETH_ALEN);
bb9f8692
ZY
696
697 /* We can load the FWs */
698 ret = iwm_load_fw(iwm);
699 if (ret) {
700 IWM_ERR(iwm, "FW loading failed\n");
701 goto err_disable;
702 }
703
902b6667
SO
704 ret = iwm_eeprom_fat_channels(iwm);
705 if (ret) {
706 IWM_ERR(iwm, "Couldnt read HT channels EEPROM entries\n");
707 goto err_fw;
708 }
709
0bed08de
SO
710 /*
711 * Read our SKU capabilities.
2351178c
ZY
712 * If it's valid, we AND the configured wireless mode with the
713 * device EEPROM value as the current profile wireless mode.
0bed08de
SO
714 */
715 wireless_mode = iwm_eeprom_wireless_mode(iwm);
716 if (wireless_mode) {
2351178c 717 iwm->conf.wireless_mode &= wireless_mode;
0bed08de
SO
718 if (iwm->umac_profile)
719 iwm->umac_profile->wireless_mode =
720 iwm->conf.wireless_mode;
721 } else
722 IWM_ERR(iwm, "Wrong SKU capabilities: 0x%x\n",
723 *((u16 *)iwm_eeprom_access(iwm, IWM_EEPROM_SKU_CAP)));
724
5dc53163
SO
725 snprintf(wiphy->fw_version, sizeof(wiphy->fw_version), "L%s_U%s",
726 iwm->lmac_version, iwm->umac_version);
727
bb9f8692
ZY
728 /* We configure the UMAC and enable the wifi module */
729 ret = iwm_send_umac_config(iwm,
730 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) |
731 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) |
732 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN));
733 if (ret) {
734 IWM_ERR(iwm, "UMAC config failed\n");
735 goto err_fw;
736 }
737
738 ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
739 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
740 if (ret) {
741 IWM_ERR(iwm, "Didn't get a wifi core status notification\n");
742 goto err_fw;
743 }
744
745 if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
746 UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
747 IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n",
748 iwm->core_enabled);
749 ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
750 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
751 if (ret) {
752 IWM_ERR(iwm, "Didn't get a core status notification\n");
753 goto err_fw;
754 }
755
756 if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
757 UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
758 IWM_ERR(iwm, "Not all cores enabled: 0x%x\n",
759 iwm->core_enabled);
760 goto err_fw;
761 } else {
762 IWM_INFO(iwm, "All cores enabled\n");
763 }
764 }
765
bb9f8692
ZY
766 ret = iwm_channels_init(iwm);
767 if (ret < 0) {
768 IWM_ERR(iwm, "Couldn't init channels\n");
35497164 769 goto err_fw;
bb9f8692
ZY
770 }
771
772 /* Set the READY bit to indicate interface is brought up successfully */
773 set_bit(IWM_STATUS_READY, &iwm->status);
774
775 return 0;
776
bb9f8692
ZY
777 err_fw:
778 iwm_eeprom_exit(iwm);
779
780 err_disable:
781 ret = iwm_bus_disable(iwm);
782 if (ret < 0)
783 IWM_ERR(iwm, "Couldn't disable function\n");
784
785 return -EIO;
786}
787
68810c5d
ZY
788int iwm_up(struct iwm_priv *iwm)
789{
790 int ret;
791
792 mutex_lock(&iwm->mutex);
793 ret = __iwm_up(iwm);
794 mutex_unlock(&iwm->mutex);
795
796 return ret;
797}
798
31452420 799static int __iwm_down(struct iwm_priv *iwm)
bb9f8692
ZY
800{
801 int ret;
802
803 /* The interface is already down */
804 if (!test_bit(IWM_STATUS_READY, &iwm->status))
805 return 0;
806
807 if (iwm->scan_request) {
808 cfg80211_scan_done(iwm->scan_request, true);
809 iwm->scan_request = NULL;
810 }
811
812 clear_bit(IWM_STATUS_READY, &iwm->status);
813
814 iwm_eeprom_exit(iwm);
bb9f8692 815 iwm_bss_list_clean(iwm);
35497164
SO
816 iwm_init_default_profile(iwm, iwm->umac_profile);
817 iwm->umac_profile_active = false;
13e0fe70 818 iwm->default_key = -1;
bb9f8692
ZY
819 iwm->core_enabled = 0;
820
821 ret = iwm_bus_disable(iwm);
822 if (ret < 0) {
823 IWM_ERR(iwm, "Couldn't disable function\n");
824 return ret;
825 }
826
827 return 0;
828}
68810c5d
ZY
829
830int iwm_down(struct iwm_priv *iwm)
831{
832 int ret;
833
834 mutex_lock(&iwm->mutex);
835 ret = __iwm_down(iwm);
836 mutex_unlock(&iwm->mutex);
837
838 return ret;
839}