iwmc3200wifi: Handle UMAC stalls and UMAC assert properly
[deliverable/linux.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>
41#include <linux/ieee80211.h>
42#include <linux/wireless.h>
43
44#include "iwm.h"
45#include "debug.h"
46#include "bus.h"
47#include "umac.h"
48#include "commands.h"
49#include "hal.h"
50#include "fw.h"
51#include "rx.h"
52
53static struct iwm_conf def_iwm_conf = {
54
55 .sdio_ior_timeout = 5000,
d04bd628
SO
56 .calib_map = BIT(CALIB_CFG_DC_IDX) |
57 BIT(CALIB_CFG_LO_IDX) |
58 BIT(CALIB_CFG_TX_IQ_IDX) |
59 BIT(CALIB_CFG_RX_IQ_IDX) |
60 BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD),
61 .expected_calib_map = BIT(PHY_CALIBRATE_DC_CMD) |
bb9f8692
ZY
62 BIT(PHY_CALIBRATE_LO_CMD) |
63 BIT(PHY_CALIBRATE_TX_IQ_CMD) |
64 BIT(PHY_CALIBRATE_RX_IQ_CMD) |
65 BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD),
66 .reset_on_fatal_err = 1,
67 .auto_connect = 1,
68 .wimax_not_present = 0,
69 .enable_qos = 1,
70 .mode = UMAC_MODE_BSS,
71
72 /* UMAC configuration */
73 .power_index = 0,
74 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
75 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
76 .cts_to_self = 0,
77
78 .assoc_timeout = 2,
79 .roam_timeout = 10,
80 .wireless_mode = WIRELESS_MODE_11A | WIRELESS_MODE_11G,
81 .coexist_mode = COEX_MODE_CM,
82
83 /* IBSS */
84 .ibss_band = UMAC_BAND_2GHZ,
85 .ibss_channel = 1,
86
87 .mac_addr = {0x00, 0x02, 0xb3, 0x01, 0x02, 0x03},
88};
89
90static int modparam_reset;
91module_param_named(reset, modparam_reset, bool, 0644);
92MODULE_PARM_DESC(reset, "reset on firmware errors (default 0 [not reset])");
93
94int iwm_mode_to_nl80211_iftype(int mode)
95{
96 switch (mode) {
97 case UMAC_MODE_BSS:
98 return NL80211_IFTYPE_STATION;
99 case UMAC_MODE_IBSS:
100 return NL80211_IFTYPE_ADHOC;
101 default:
102 return NL80211_IFTYPE_UNSPECIFIED;
103 }
104
105 return 0;
106}
107
108static void iwm_statistics_request(struct work_struct *work)
109{
110 struct iwm_priv *iwm =
111 container_of(work, struct iwm_priv, stats_request.work);
112
113 iwm_send_umac_stats_req(iwm, 0);
114}
115
c7436273
ZY
116static void iwm_disconnect_work(struct work_struct *work)
117{
118 struct iwm_priv *iwm =
119 container_of(work, struct iwm_priv, disconnect.work);
120
121 if (iwm->umac_profile_active)
122 iwm_invalidate_mlme_profile(iwm);
123
124 clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
125 iwm->umac_profile_active = 0;
126 memset(iwm->bssid, 0, ETH_ALEN);
127 iwm->channel = 0;
128
129 iwm_link_off(iwm);
130
131 wake_up_interruptible(&iwm->mlme_queue);
132
133 cfg80211_disconnected(iwm_to_ndev(iwm), 0, NULL, 0, GFP_KERNEL);
134}
135
31452420
ZY
136static int __iwm_up(struct iwm_priv *iwm);
137static int __iwm_down(struct iwm_priv *iwm);
68810c5d 138
bb9f8692
ZY
139static void iwm_reset_worker(struct work_struct *work)
140{
141 struct iwm_priv *iwm;
142 struct iwm_umac_profile *profile = NULL;
143 int uninitialized_var(ret), retry = 0;
144
145 iwm = container_of(work, struct iwm_priv, reset_worker);
146
68810c5d
ZY
147 /*
148 * XXX: The iwm->mutex is introduced purely for this reset work,
149 * because the other users for iwm_up and iwm_down are only netdev
150 * ndo_open and ndo_stop which are already protected by rtnl.
151 * Please remove iwm->mutex together if iwm_reset_worker() is not
152 * required in the future.
153 */
154 if (!mutex_trylock(&iwm->mutex)) {
155 IWM_WARN(iwm, "We are in the middle of interface bringing "
156 "UP/DOWN. Skip driver resetting.\n");
157 return;
158 }
159
bb9f8692
ZY
160 if (iwm->umac_profile_active) {
161 profile = kmalloc(sizeof(struct iwm_umac_profile), GFP_KERNEL);
162 if (profile)
163 memcpy(profile, iwm->umac_profile, sizeof(*profile));
164 else
165 IWM_ERR(iwm, "Couldn't alloc memory for profile\n");
166 }
167
68810c5d 168 __iwm_down(iwm);
bb9f8692
ZY
169
170 while (retry++ < 3) {
68810c5d 171 ret = __iwm_up(iwm);
bb9f8692
ZY
172 if (!ret)
173 break;
174
175 schedule_timeout_uninterruptible(10 * HZ);
176 }
177
178 if (ret) {
179 IWM_WARN(iwm, "iwm_up() failed: %d\n", ret);
180
181 kfree(profile);
68810c5d 182 goto out;
bb9f8692
ZY
183 }
184
185 if (profile) {
186 IWM_DBG_MLME(iwm, DBG, "Resend UMAC profile\n");
187 memcpy(iwm->umac_profile, profile, sizeof(*profile));
188 iwm_send_mlme_profile(iwm);
189 kfree(profile);
d210176e
SO
190 } else
191 clear_bit(IWM_STATUS_RESETTING, &iwm->status);
68810c5d
ZY
192
193 out:
194 mutex_unlock(&iwm->mutex);
bb9f8692
ZY
195}
196
197static void iwm_watchdog(unsigned long data)
198{
199 struct iwm_priv *iwm = (struct iwm_priv *)data;
200
201 IWM_WARN(iwm, "Watchdog expired: UMAC stalls!\n");
202
203 if (modparam_reset)
d210176e 204 iwm_resetting(iwm);
bb9f8692
ZY
205}
206
207int iwm_priv_init(struct iwm_priv *iwm)
208{
209 int i;
210 char name[32];
211
212 iwm->status = 0;
213 INIT_LIST_HEAD(&iwm->pending_notif);
214 init_waitqueue_head(&iwm->notif_queue);
215 init_waitqueue_head(&iwm->nonwifi_queue);
a70742f1 216 init_waitqueue_head(&iwm->wifi_ntfy_queue);
bb9f8692
ZY
217 init_waitqueue_head(&iwm->mlme_queue);
218 memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf));
219 spin_lock_init(&iwm->tx_credit.lock);
220 INIT_LIST_HEAD(&iwm->wifi_pending_cmd);
221 INIT_LIST_HEAD(&iwm->nonwifi_pending_cmd);
222 iwm->wifi_seq_num = UMAC_WIFI_SEQ_NUM_BASE;
223 iwm->nonwifi_seq_num = UMAC_NONWIFI_SEQ_NUM_BASE;
224 spin_lock_init(&iwm->cmd_lock);
225 iwm->scan_id = 1;
226 INIT_DELAYED_WORK(&iwm->stats_request, iwm_statistics_request);
c7436273 227 INIT_DELAYED_WORK(&iwm->disconnect, iwm_disconnect_work);
bb9f8692
ZY
228 INIT_WORK(&iwm->reset_worker, iwm_reset_worker);
229 INIT_LIST_HEAD(&iwm->bss_list);
230
231 skb_queue_head_init(&iwm->rx_list);
232 INIT_LIST_HEAD(&iwm->rx_tickets);
233 for (i = 0; i < IWM_RX_ID_HASH; i++)
234 INIT_LIST_HEAD(&iwm->rx_packets[i]);
235
236 INIT_WORK(&iwm->rx_worker, iwm_rx_worker);
237
238 iwm->rx_wq = create_singlethread_workqueue(KBUILD_MODNAME "_rx");
239 if (!iwm->rx_wq)
240 return -EAGAIN;
241
242 for (i = 0; i < IWM_TX_QUEUES; i++) {
243 INIT_WORK(&iwm->txq[i].worker, iwm_tx_worker);
244 snprintf(name, 32, KBUILD_MODNAME "_tx_%d", i);
245 iwm->txq[i].id = i;
246 iwm->txq[i].wq = create_singlethread_workqueue(name);
247 if (!iwm->txq[i].wq)
248 return -EAGAIN;
249
250 skb_queue_head_init(&iwm->txq[i].queue);
251 }
252
253 for (i = 0; i < IWM_NUM_KEYS; i++)
254 memset(&iwm->keys[i], 0, sizeof(struct iwm_key));
255
13e0fe70 256 iwm->default_key = -1;
bb9f8692
ZY
257
258 init_timer(&iwm->watchdog);
259 iwm->watchdog.function = iwm_watchdog;
260 iwm->watchdog.data = (unsigned long)iwm;
68810c5d 261 mutex_init(&iwm->mutex);
bb9f8692
ZY
262
263 return 0;
264}
265
8d96e796
ZY
266void iwm_priv_deinit(struct iwm_priv *iwm)
267{
268 int i;
269
270 for (i = 0; i < IWM_TX_QUEUES; i++)
271 destroy_workqueue(iwm->txq[i].wq);
272
273 destroy_workqueue(iwm->rx_wq);
274}
275
bb9f8692
ZY
276/*
277 * We reset all the structures, and we reset the UMAC.
278 * After calling this routine, you're expected to reload
279 * the firmware.
280 */
281void iwm_reset(struct iwm_priv *iwm)
282{
283 struct iwm_notif *notif, *next;
284
285 if (test_bit(IWM_STATUS_READY, &iwm->status))
286 iwm_target_reset(iwm);
287
d210176e
SO
288 if (test_bit(IWM_STATUS_RESETTING, &iwm->status)) {
289 iwm->status = 0;
290 set_bit(IWM_STATUS_RESETTING, &iwm->status);
291 } else
292 iwm->status = 0;
bb9f8692
ZY
293 iwm->scan_id = 1;
294
295 list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
296 list_del(&notif->pending);
297 kfree(notif->buf);
298 kfree(notif);
299 }
300
301 iwm_cmd_flush(iwm);
302
303 flush_workqueue(iwm->rx_wq);
304
305 iwm_link_off(iwm);
306}
307
d210176e
SO
308void iwm_resetting(struct iwm_priv *iwm)
309{
310 set_bit(IWM_STATUS_RESETTING, &iwm->status);
311
312 schedule_work(&iwm->reset_worker);
313}
314
bb9f8692
ZY
315/*
316 * Notification code:
317 *
318 * We're faced with the following issue: Any host command can
319 * have an answer or not, and if there's an answer to expect,
320 * it can be treated synchronously or asynchronously.
321 * To work around the synchronous answer case, we implemented
322 * our notification mechanism.
323 * When a code path needs to wait for a command response
324 * synchronously, it calls notif_handle(), which waits for the
325 * right notification to show up, and then process it. Before
326 * starting to wait, it registered as a waiter for this specific
327 * answer (by toggling a bit in on of the handler_map), so that
328 * the rx code knows that it needs to send a notification to the
329 * waiting processes. It does so by calling iwm_notif_send(),
330 * which adds the notification to the pending notifications list,
331 * and then wakes the waiting processes up.
332 */
333int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
334 u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size)
335{
336 struct iwm_notif *notif;
337
338 notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL);
339 if (!notif) {
340 IWM_ERR(iwm, "Couldn't alloc memory for notification\n");
341 return -ENOMEM;
342 }
343
344 INIT_LIST_HEAD(&notif->pending);
345 notif->cmd = cmd;
346 notif->cmd_id = cmd_id;
347 notif->src = source;
348 notif->buf = kzalloc(buf_size, GFP_KERNEL);
349 if (!notif->buf) {
350 IWM_ERR(iwm, "Couldn't alloc notification buffer\n");
351 kfree(notif);
352 return -ENOMEM;
353 }
354 notif->buf_size = buf_size;
355 memcpy(notif->buf, buf, buf_size);
356 list_add_tail(&notif->pending, &iwm->pending_notif);
357
358 wake_up_interruptible(&iwm->notif_queue);
359
360 return 0;
361}
362
363static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd,
364 u8 source)
365{
366 struct iwm_notif *notif, *next;
367
368 list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
369 if ((notif->cmd_id == cmd) && (notif->src == source)) {
370 list_del(&notif->pending);
371 return notif;
372 }
373 }
374
375 return NULL;
376}
377
378static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd,
379 u8 source, long timeout)
380{
381 int ret;
382 struct iwm_notif *notif;
383 unsigned long *map = NULL;
384
385 switch (source) {
386 case IWM_SRC_LMAC:
387 map = &iwm->lmac_handler_map[0];
388 break;
389 case IWM_SRC_UMAC:
390 map = &iwm->umac_handler_map[0];
391 break;
392 case IWM_SRC_UDMA:
393 map = &iwm->udma_handler_map[0];
394 break;
395 }
396
397 set_bit(cmd, map);
398
399 ret = wait_event_interruptible_timeout(iwm->notif_queue,
400 ((notif = iwm_notif_find(iwm, cmd, source)) != NULL),
401 timeout);
402 clear_bit(cmd, map);
403
404 if (!ret)
405 return NULL;
406
407 return notif;
408}
409
410int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout)
411{
412 int ret;
413 struct iwm_notif *notif;
414
415 notif = iwm_notif_wait(iwm, cmd, source, timeout);
416 if (!notif)
417 return -ETIME;
418
419 ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd);
420 kfree(notif->buf);
421 kfree(notif);
422
423 return ret;
424}
425
426static int iwm_config_boot_params(struct iwm_priv *iwm)
427{
428 struct iwm_udma_nonwifi_cmd target_cmd;
429 int ret;
430
431 /* check Wimax is off and config debug monitor */
432 if (iwm->conf.wimax_not_present) {
433 u32 data1 = 0x1f;
434 u32 addr1 = 0x606BE258;
435
436 u32 data2_set = 0x0;
437 u32 data2_clr = 0x1;
438 u32 addr2 = 0x606BE100;
439
440 u32 data3 = 0x1;
441 u32 addr3 = 0x606BEC00;
442
443 target_cmd.resp = 0;
444 target_cmd.handle_by_hw = 0;
445 target_cmd.eop = 1;
446
447 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
448 target_cmd.addr = cpu_to_le32(addr1);
449 target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
450 target_cmd.op2 = 0;
451
452 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
453 if (ret < 0) {
454 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
455 return ret;
456 }
457
458 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE;
459 target_cmd.addr = cpu_to_le32(addr2);
460 target_cmd.op1_sz = cpu_to_le32(data2_set);
461 target_cmd.op2 = cpu_to_le32(data2_clr);
462
463 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
464 if (ret < 0) {
465 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
466 return ret;
467 }
468
469 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
470 target_cmd.addr = cpu_to_le32(addr3);
471 target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
472 target_cmd.op2 = 0;
473
474 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3);
475 if (ret < 0) {
476 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
477 return ret;
478 }
479 }
480
481 return 0;
482}
483
484void iwm_init_default_profile(struct iwm_priv *iwm,
485 struct iwm_umac_profile *profile)
486{
487 memset(profile, 0, sizeof(struct iwm_umac_profile));
488
489 profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN;
490 profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE;
491 profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE;
492 profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE;
493
494 if (iwm->conf.enable_qos)
495 profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED);
496
497 profile->wireless_mode = iwm->conf.wireless_mode;
498 profile->mode = cpu_to_le32(iwm->conf.mode);
499
500 profile->ibss.atim = 0;
501 profile->ibss.beacon_interval = 100;
502 profile->ibss.join_only = 0;
503 profile->ibss.band = iwm->conf.ibss_band;
504 profile->ibss.channel = iwm->conf.ibss_channel;
505}
506
507void iwm_link_on(struct iwm_priv *iwm)
508{
509 netif_carrier_on(iwm_to_ndev(iwm));
510 netif_tx_wake_all_queues(iwm_to_ndev(iwm));
511
512 iwm_send_umac_stats_req(iwm, 0);
513}
514
515void iwm_link_off(struct iwm_priv *iwm)
516{
517 struct iw_statistics *wstats = &iwm->wstats;
518 int i;
519
520 netif_tx_stop_all_queues(iwm_to_ndev(iwm));
521 netif_carrier_off(iwm_to_ndev(iwm));
522
523 for (i = 0; i < IWM_TX_QUEUES; i++) {
524 skb_queue_purge(&iwm->txq[i].queue);
525
526 iwm->txq[i].concat_count = 0;
527 iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf;
528
529 flush_workqueue(iwm->txq[i].wq);
530 }
531
532 iwm_rx_free(iwm);
533
68810c5d 534 cancel_delayed_work_sync(&iwm->stats_request);
bb9f8692
ZY
535 memset(wstats, 0, sizeof(struct iw_statistics));
536 wstats->qual.updated = IW_QUAL_ALL_INVALID;
537
b68518fc
ZY
538 kfree(iwm->req_ie);
539 iwm->req_ie = NULL;
540 iwm->req_ie_len = 0;
541 kfree(iwm->resp_ie);
542 iwm->resp_ie = NULL;
543 iwm->resp_ie_len = 0;
544
bb9f8692
ZY
545 del_timer_sync(&iwm->watchdog);
546}
547
548static void iwm_bss_list_clean(struct iwm_priv *iwm)
549{
550 struct iwm_bss_info *bss, *next;
551
552 list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
553 list_del(&bss->node);
554 kfree(bss->bss);
555 kfree(bss);
556 }
557}
558
559static int iwm_channels_init(struct iwm_priv *iwm)
560{
561 int ret;
562
bb9f8692
ZY
563 ret = iwm_send_umac_channel_list(iwm);
564 if (ret) {
565 IWM_ERR(iwm, "Send channel list failed\n");
566 return ret;
567 }
568
569 ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST,
570 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
571 if (ret) {
572 IWM_ERR(iwm, "Didn't get a channel list notification\n");
573 return ret;
574 }
575
576 return 0;
577}
578
31452420 579static int __iwm_up(struct iwm_priv *iwm)
bb9f8692
ZY
580{
581 int ret;
582 struct iwm_notif *notif_reboot, *notif_ack = NULL;
583
584 ret = iwm_bus_enable(iwm);
585 if (ret) {
586 IWM_ERR(iwm, "Couldn't enable function\n");
587 return ret;
588 }
589
590 iwm_rx_setup_handlers(iwm);
591
592 /* Wait for initial BARKER_REBOOT from hardware */
593 notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION,
594 IWM_SRC_UDMA, 2 * HZ);
595 if (!notif_reboot) {
596 IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n");
597 goto err_disable;
598 }
599
600 /* We send the barker back */
601 ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16);
602 if (ret) {
603 IWM_ERR(iwm, "REBOOT barker response failed\n");
604 kfree(notif_reboot);
605 goto err_disable;
606 }
607
608 kfree(notif_reboot->buf);
609 kfree(notif_reboot);
610
611 /* Wait for ACK_BARKER from hardware */
612 notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION,
613 IWM_SRC_UDMA, 2 * HZ);
614 if (!notif_ack) {
615 IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n");
616 goto err_disable;
617 }
618
619 kfree(notif_ack->buf);
620 kfree(notif_ack);
621
622 /* We start to config static boot parameters */
623 ret = iwm_config_boot_params(iwm);
624 if (ret) {
625 IWM_ERR(iwm, "Config boot parameters failed\n");
626 goto err_disable;
627 }
628
629 ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr);
630 if (ret) {
631 IWM_ERR(iwm, "MAC reading failed\n");
632 goto err_disable;
633 }
634
635 /* We can load the FWs */
636 ret = iwm_load_fw(iwm);
637 if (ret) {
638 IWM_ERR(iwm, "FW loading failed\n");
639 goto err_disable;
640 }
641
642 /* We configure the UMAC and enable the wifi module */
643 ret = iwm_send_umac_config(iwm,
644 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) |
645 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) |
646 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN));
647 if (ret) {
648 IWM_ERR(iwm, "UMAC config failed\n");
649 goto err_fw;
650 }
651
652 ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
653 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
654 if (ret) {
655 IWM_ERR(iwm, "Didn't get a wifi core status notification\n");
656 goto err_fw;
657 }
658
659 if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
660 UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
661 IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n",
662 iwm->core_enabled);
663 ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
664 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
665 if (ret) {
666 IWM_ERR(iwm, "Didn't get a core status notification\n");
667 goto err_fw;
668 }
669
670 if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
671 UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
672 IWM_ERR(iwm, "Not all cores enabled: 0x%x\n",
673 iwm->core_enabled);
674 goto err_fw;
675 } else {
676 IWM_INFO(iwm, "All cores enabled\n");
677 }
678 }
679
bb9f8692
ZY
680 ret = iwm_channels_init(iwm);
681 if (ret < 0) {
682 IWM_ERR(iwm, "Couldn't init channels\n");
35497164 683 goto err_fw;
bb9f8692
ZY
684 }
685
686 /* Set the READY bit to indicate interface is brought up successfully */
687 set_bit(IWM_STATUS_READY, &iwm->status);
688
689 return 0;
690
bb9f8692
ZY
691 err_fw:
692 iwm_eeprom_exit(iwm);
693
694 err_disable:
695 ret = iwm_bus_disable(iwm);
696 if (ret < 0)
697 IWM_ERR(iwm, "Couldn't disable function\n");
698
699 return -EIO;
700}
701
68810c5d
ZY
702int iwm_up(struct iwm_priv *iwm)
703{
704 int ret;
705
706 mutex_lock(&iwm->mutex);
707 ret = __iwm_up(iwm);
708 mutex_unlock(&iwm->mutex);
709
710 return ret;
711}
712
31452420 713static int __iwm_down(struct iwm_priv *iwm)
bb9f8692
ZY
714{
715 int ret;
716
717 /* The interface is already down */
718 if (!test_bit(IWM_STATUS_READY, &iwm->status))
719 return 0;
720
721 if (iwm->scan_request) {
722 cfg80211_scan_done(iwm->scan_request, true);
723 iwm->scan_request = NULL;
724 }
725
726 clear_bit(IWM_STATUS_READY, &iwm->status);
727
728 iwm_eeprom_exit(iwm);
bb9f8692 729 iwm_bss_list_clean(iwm);
35497164
SO
730 iwm_init_default_profile(iwm, iwm->umac_profile);
731 iwm->umac_profile_active = false;
13e0fe70 732 iwm->default_key = -1;
bb9f8692
ZY
733 iwm->core_enabled = 0;
734
735 ret = iwm_bus_disable(iwm);
736 if (ret < 0) {
737 IWM_ERR(iwm, "Couldn't disable function\n");
738 return ret;
739 }
740
741 return 0;
742}
68810c5d
ZY
743
744int iwm_down(struct iwm_priv *iwm)
745{
746 int ret;
747
748 mutex_lock(&iwm->mutex);
749 ret = __iwm_down(iwm);
750 mutex_unlock(&iwm->mutex);
751
752 return ret;
753}
This page took 0.096573 seconds and 5 git commands to generate.