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