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