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