blob: 170f33706490dbf4c8af441eef00184d27644259 [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,
Samuel Ortizd04bd622009-09-01 15:14:04 +020056 .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) |
Zhu Yibb9f8692009-05-21 21:20:45 +080062 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
Zhu Yic7436272009-09-01 15:14:02 +0200116static 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
Zhu Yi314524202009-09-01 15:14:03 +0200136static int __iwm_up(struct iwm_priv *iwm);
137static int __iwm_down(struct iwm_priv *iwm);
Zhu Yi68810c52009-06-15 21:59:49 +0200138
Zhu Yibb9f8692009-05-21 21:20:45 +0800139static 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
Zhu Yi68810c52009-06-15 21:59:49 +0200147 /*
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
Zhu Yibb9f8692009-05-21 21:20:45 +0800160 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
Zhu Yi68810c52009-06-15 21:59:49 +0200168 __iwm_down(iwm);
Zhu Yibb9f8692009-05-21 21:20:45 +0800169
170 while (retry++ < 3) {
Zhu Yi68810c52009-06-15 21:59:49 +0200171 ret = __iwm_up(iwm);
Zhu Yibb9f8692009-05-21 21:20:45 +0800172 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);
Zhu Yi68810c52009-06-15 21:59:49 +0200182 goto out;
Zhu Yibb9f8692009-05-21 21:20:45 +0800183 }
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);
Samuel Ortizd2101762009-09-01 15:14:05 +0200190 } else
191 clear_bit(IWM_STATUS_RESETTING, &iwm->status);
Zhu Yi68810c52009-06-15 21:59:49 +0200192
193 out:
194 mutex_unlock(&iwm->mutex);
Zhu Yibb9f8692009-05-21 21:20:45 +0800195}
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)
Samuel Ortizd2101762009-09-01 15:14:05 +0200204 iwm_resetting(iwm);
Zhu Yibb9f8692009-05-21 21:20:45 +0800205}
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);
Samuel Ortiza70742f2009-06-15 21:59:51 +0200216 init_waitqueue_head(&iwm->wifi_ntfy_queue);
Zhu Yibb9f8692009-05-21 21:20:45 +0800217 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);
Zhu Yic7436272009-09-01 15:14:02 +0200227 INIT_DELAYED_WORK(&iwm->disconnect, iwm_disconnect_work);
Zhu Yibb9f8692009-05-21 21:20:45 +0800228 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
Samuel Ortiz13e0fe702009-06-15 21:59:52 +0200256 iwm->default_key = -1;
Zhu Yibb9f8692009-05-21 21:20:45 +0800257
258 init_timer(&iwm->watchdog);
259 iwm->watchdog.function = iwm_watchdog;
260 iwm->watchdog.data = (unsigned long)iwm;
Zhu Yi68810c52009-06-15 21:59:49 +0200261 mutex_init(&iwm->mutex);
Zhu Yibb9f8692009-05-21 21:20:45 +0800262
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200263 iwm->last_fw_err = kzalloc(sizeof(struct iwm_fw_error_hdr),
264 GFP_KERNEL);
265 if (iwm->last_fw_err == NULL)
266 return -ENOMEM;
267
Zhu Yibb9f8692009-05-21 21:20:45 +0800268 return 0;
269}
270
Zhu Yi8d96e792009-06-15 21:36:13 +0200271void iwm_priv_deinit(struct iwm_priv *iwm)
272{
273 int i;
274
275 for (i = 0; i < IWM_TX_QUEUES; i++)
276 destroy_workqueue(iwm->txq[i].wq);
277
278 destroy_workqueue(iwm->rx_wq);
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200279 kfree(iwm->last_fw_err);
Zhu Yi8d96e792009-06-15 21:36:13 +0200280}
281
Zhu Yibb9f8692009-05-21 21:20:45 +0800282/*
283 * We reset all the structures, and we reset the UMAC.
284 * After calling this routine, you're expected to reload
285 * the firmware.
286 */
287void iwm_reset(struct iwm_priv *iwm)
288{
289 struct iwm_notif *notif, *next;
290
291 if (test_bit(IWM_STATUS_READY, &iwm->status))
292 iwm_target_reset(iwm);
293
Samuel Ortizd2101762009-09-01 15:14:05 +0200294 if (test_bit(IWM_STATUS_RESETTING, &iwm->status)) {
295 iwm->status = 0;
296 set_bit(IWM_STATUS_RESETTING, &iwm->status);
297 } else
298 iwm->status = 0;
Zhu Yibb9f8692009-05-21 21:20:45 +0800299 iwm->scan_id = 1;
300
301 list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
302 list_del(&notif->pending);
303 kfree(notif->buf);
304 kfree(notif);
305 }
306
307 iwm_cmd_flush(iwm);
308
309 flush_workqueue(iwm->rx_wq);
310
311 iwm_link_off(iwm);
312}
313
Samuel Ortizd2101762009-09-01 15:14:05 +0200314void iwm_resetting(struct iwm_priv *iwm)
315{
316 set_bit(IWM_STATUS_RESETTING, &iwm->status);
317
318 schedule_work(&iwm->reset_worker);
319}
320
Zhu Yibb9f8692009-05-21 21:20:45 +0800321/*
322 * Notification code:
323 *
324 * We're faced with the following issue: Any host command can
325 * have an answer or not, and if there's an answer to expect,
326 * it can be treated synchronously or asynchronously.
327 * To work around the synchronous answer case, we implemented
328 * our notification mechanism.
329 * When a code path needs to wait for a command response
330 * synchronously, it calls notif_handle(), which waits for the
331 * right notification to show up, and then process it. Before
332 * starting to wait, it registered as a waiter for this specific
333 * answer (by toggling a bit in on of the handler_map), so that
334 * the rx code knows that it needs to send a notification to the
335 * waiting processes. It does so by calling iwm_notif_send(),
336 * which adds the notification to the pending notifications list,
337 * and then wakes the waiting processes up.
338 */
339int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
340 u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size)
341{
342 struct iwm_notif *notif;
343
344 notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL);
345 if (!notif) {
346 IWM_ERR(iwm, "Couldn't alloc memory for notification\n");
347 return -ENOMEM;
348 }
349
350 INIT_LIST_HEAD(&notif->pending);
351 notif->cmd = cmd;
352 notif->cmd_id = cmd_id;
353 notif->src = source;
354 notif->buf = kzalloc(buf_size, GFP_KERNEL);
355 if (!notif->buf) {
356 IWM_ERR(iwm, "Couldn't alloc notification buffer\n");
357 kfree(notif);
358 return -ENOMEM;
359 }
360 notif->buf_size = buf_size;
361 memcpy(notif->buf, buf, buf_size);
362 list_add_tail(&notif->pending, &iwm->pending_notif);
363
364 wake_up_interruptible(&iwm->notif_queue);
365
366 return 0;
367}
368
369static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd,
370 u8 source)
371{
372 struct iwm_notif *notif, *next;
373
374 list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
375 if ((notif->cmd_id == cmd) && (notif->src == source)) {
376 list_del(&notif->pending);
377 return notif;
378 }
379 }
380
381 return NULL;
382}
383
384static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd,
385 u8 source, long timeout)
386{
387 int ret;
388 struct iwm_notif *notif;
389 unsigned long *map = NULL;
390
391 switch (source) {
392 case IWM_SRC_LMAC:
393 map = &iwm->lmac_handler_map[0];
394 break;
395 case IWM_SRC_UMAC:
396 map = &iwm->umac_handler_map[0];
397 break;
398 case IWM_SRC_UDMA:
399 map = &iwm->udma_handler_map[0];
400 break;
401 }
402
403 set_bit(cmd, map);
404
405 ret = wait_event_interruptible_timeout(iwm->notif_queue,
406 ((notif = iwm_notif_find(iwm, cmd, source)) != NULL),
407 timeout);
408 clear_bit(cmd, map);
409
410 if (!ret)
411 return NULL;
412
413 return notif;
414}
415
416int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout)
417{
418 int ret;
419 struct iwm_notif *notif;
420
421 notif = iwm_notif_wait(iwm, cmd, source, timeout);
422 if (!notif)
423 return -ETIME;
424
425 ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd);
426 kfree(notif->buf);
427 kfree(notif);
428
429 return ret;
430}
431
432static int iwm_config_boot_params(struct iwm_priv *iwm)
433{
434 struct iwm_udma_nonwifi_cmd target_cmd;
435 int ret;
436
437 /* check Wimax is off and config debug monitor */
438 if (iwm->conf.wimax_not_present) {
439 u32 data1 = 0x1f;
440 u32 addr1 = 0x606BE258;
441
442 u32 data2_set = 0x0;
443 u32 data2_clr = 0x1;
444 u32 addr2 = 0x606BE100;
445
446 u32 data3 = 0x1;
447 u32 addr3 = 0x606BEC00;
448
449 target_cmd.resp = 0;
450 target_cmd.handle_by_hw = 0;
451 target_cmd.eop = 1;
452
453 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
454 target_cmd.addr = cpu_to_le32(addr1);
455 target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
456 target_cmd.op2 = 0;
457
458 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
459 if (ret < 0) {
460 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
461 return ret;
462 }
463
464 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE;
465 target_cmd.addr = cpu_to_le32(addr2);
466 target_cmd.op1_sz = cpu_to_le32(data2_set);
467 target_cmd.op2 = cpu_to_le32(data2_clr);
468
469 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
470 if (ret < 0) {
471 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
472 return ret;
473 }
474
475 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
476 target_cmd.addr = cpu_to_le32(addr3);
477 target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
478 target_cmd.op2 = 0;
479
480 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3);
481 if (ret < 0) {
482 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
483 return ret;
484 }
485 }
486
487 return 0;
488}
489
490void iwm_init_default_profile(struct iwm_priv *iwm,
491 struct iwm_umac_profile *profile)
492{
493 memset(profile, 0, sizeof(struct iwm_umac_profile));
494
495 profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN;
496 profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE;
497 profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE;
498 profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE;
499
500 if (iwm->conf.enable_qos)
501 profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED);
502
503 profile->wireless_mode = iwm->conf.wireless_mode;
504 profile->mode = cpu_to_le32(iwm->conf.mode);
505
506 profile->ibss.atim = 0;
507 profile->ibss.beacon_interval = 100;
508 profile->ibss.join_only = 0;
509 profile->ibss.band = iwm->conf.ibss_band;
510 profile->ibss.channel = iwm->conf.ibss_channel;
511}
512
513void iwm_link_on(struct iwm_priv *iwm)
514{
515 netif_carrier_on(iwm_to_ndev(iwm));
516 netif_tx_wake_all_queues(iwm_to_ndev(iwm));
517
518 iwm_send_umac_stats_req(iwm, 0);
519}
520
521void iwm_link_off(struct iwm_priv *iwm)
522{
523 struct iw_statistics *wstats = &iwm->wstats;
524 int i;
525
526 netif_tx_stop_all_queues(iwm_to_ndev(iwm));
527 netif_carrier_off(iwm_to_ndev(iwm));
528
529 for (i = 0; i < IWM_TX_QUEUES; i++) {
530 skb_queue_purge(&iwm->txq[i].queue);
531
532 iwm->txq[i].concat_count = 0;
533 iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf;
534
535 flush_workqueue(iwm->txq[i].wq);
536 }
537
538 iwm_rx_free(iwm);
539
Zhu Yi68810c52009-06-15 21:59:49 +0200540 cancel_delayed_work_sync(&iwm->stats_request);
Zhu Yibb9f8692009-05-21 21:20:45 +0800541 memset(wstats, 0, sizeof(struct iw_statistics));
542 wstats->qual.updated = IW_QUAL_ALL_INVALID;
543
Zhu Yib68518f2009-07-20 11:47:45 +0800544 kfree(iwm->req_ie);
545 iwm->req_ie = NULL;
546 iwm->req_ie_len = 0;
547 kfree(iwm->resp_ie);
548 iwm->resp_ie = NULL;
549 iwm->resp_ie_len = 0;
550
Zhu Yibb9f8692009-05-21 21:20:45 +0800551 del_timer_sync(&iwm->watchdog);
552}
553
554static void iwm_bss_list_clean(struct iwm_priv *iwm)
555{
556 struct iwm_bss_info *bss, *next;
557
558 list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
559 list_del(&bss->node);
560 kfree(bss->bss);
561 kfree(bss);
562 }
563}
564
565static int iwm_channels_init(struct iwm_priv *iwm)
566{
567 int ret;
568
Zhu Yibb9f8692009-05-21 21:20:45 +0800569 ret = iwm_send_umac_channel_list(iwm);
570 if (ret) {
571 IWM_ERR(iwm, "Send channel list failed\n");
572 return ret;
573 }
574
575 ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST,
576 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
577 if (ret) {
578 IWM_ERR(iwm, "Didn't get a channel list notification\n");
579 return ret;
580 }
581
582 return 0;
583}
584
Zhu Yi314524202009-09-01 15:14:03 +0200585static int __iwm_up(struct iwm_priv *iwm)
Zhu Yibb9f8692009-05-21 21:20:45 +0800586{
587 int ret;
588 struct iwm_notif *notif_reboot, *notif_ack = NULL;
589
590 ret = iwm_bus_enable(iwm);
591 if (ret) {
592 IWM_ERR(iwm, "Couldn't enable function\n");
593 return ret;
594 }
595
596 iwm_rx_setup_handlers(iwm);
597
598 /* Wait for initial BARKER_REBOOT from hardware */
599 notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION,
600 IWM_SRC_UDMA, 2 * HZ);
601 if (!notif_reboot) {
602 IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n");
603 goto err_disable;
604 }
605
606 /* We send the barker back */
607 ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16);
608 if (ret) {
609 IWM_ERR(iwm, "REBOOT barker response failed\n");
610 kfree(notif_reboot);
611 goto err_disable;
612 }
613
614 kfree(notif_reboot->buf);
615 kfree(notif_reboot);
616
617 /* Wait for ACK_BARKER from hardware */
618 notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION,
619 IWM_SRC_UDMA, 2 * HZ);
620 if (!notif_ack) {
621 IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n");
622 goto err_disable;
623 }
624
625 kfree(notif_ack->buf);
626 kfree(notif_ack);
627
628 /* We start to config static boot parameters */
629 ret = iwm_config_boot_params(iwm);
630 if (ret) {
631 IWM_ERR(iwm, "Config boot parameters failed\n");
632 goto err_disable;
633 }
634
635 ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr);
636 if (ret) {
637 IWM_ERR(iwm, "MAC reading failed\n");
638 goto err_disable;
639 }
John W. Linville5b367372009-10-06 16:41:21 -0400640 memcpy(iwm_to_ndev(iwm)->perm_addr, iwm_to_ndev(iwm)->dev_addr,
641 ETH_ALEN);
Zhu Yibb9f8692009-05-21 21:20:45 +0800642
643 /* We can load the FWs */
644 ret = iwm_load_fw(iwm);
645 if (ret) {
646 IWM_ERR(iwm, "FW loading failed\n");
647 goto err_disable;
648 }
649
650 /* We configure the UMAC and enable the wifi module */
651 ret = iwm_send_umac_config(iwm,
652 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) |
653 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) |
654 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN));
655 if (ret) {
656 IWM_ERR(iwm, "UMAC config failed\n");
657 goto err_fw;
658 }
659
660 ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
661 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
662 if (ret) {
663 IWM_ERR(iwm, "Didn't get a wifi core status notification\n");
664 goto err_fw;
665 }
666
667 if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
668 UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
669 IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n",
670 iwm->core_enabled);
671 ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
672 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
673 if (ret) {
674 IWM_ERR(iwm, "Didn't get a core status notification\n");
675 goto err_fw;
676 }
677
678 if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
679 UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
680 IWM_ERR(iwm, "Not all cores enabled: 0x%x\n",
681 iwm->core_enabled);
682 goto err_fw;
683 } else {
684 IWM_INFO(iwm, "All cores enabled\n");
685 }
686 }
687
Zhu Yibb9f8692009-05-21 21:20:45 +0800688 ret = iwm_channels_init(iwm);
689 if (ret < 0) {
690 IWM_ERR(iwm, "Couldn't init channels\n");
Samuel Ortiz35497162009-06-15 21:59:54 +0200691 goto err_fw;
Zhu Yibb9f8692009-05-21 21:20:45 +0800692 }
693
694 /* Set the READY bit to indicate interface is brought up successfully */
695 set_bit(IWM_STATUS_READY, &iwm->status);
696
697 return 0;
698
Zhu Yibb9f8692009-05-21 21:20:45 +0800699 err_fw:
700 iwm_eeprom_exit(iwm);
701
702 err_disable:
703 ret = iwm_bus_disable(iwm);
704 if (ret < 0)
705 IWM_ERR(iwm, "Couldn't disable function\n");
706
707 return -EIO;
708}
709
Zhu Yi68810c52009-06-15 21:59:49 +0200710int iwm_up(struct iwm_priv *iwm)
711{
712 int ret;
713
714 mutex_lock(&iwm->mutex);
715 ret = __iwm_up(iwm);
716 mutex_unlock(&iwm->mutex);
717
718 return ret;
719}
720
Zhu Yi314524202009-09-01 15:14:03 +0200721static int __iwm_down(struct iwm_priv *iwm)
Zhu Yibb9f8692009-05-21 21:20:45 +0800722{
723 int ret;
724
725 /* The interface is already down */
726 if (!test_bit(IWM_STATUS_READY, &iwm->status))
727 return 0;
728
729 if (iwm->scan_request) {
730 cfg80211_scan_done(iwm->scan_request, true);
731 iwm->scan_request = NULL;
732 }
733
734 clear_bit(IWM_STATUS_READY, &iwm->status);
735
736 iwm_eeprom_exit(iwm);
Zhu Yibb9f8692009-05-21 21:20:45 +0800737 iwm_bss_list_clean(iwm);
Samuel Ortiz35497162009-06-15 21:59:54 +0200738 iwm_init_default_profile(iwm, iwm->umac_profile);
739 iwm->umac_profile_active = false;
Samuel Ortiz13e0fe702009-06-15 21:59:52 +0200740 iwm->default_key = -1;
Zhu Yibb9f8692009-05-21 21:20:45 +0800741 iwm->core_enabled = 0;
742
743 ret = iwm_bus_disable(iwm);
744 if (ret < 0) {
745 IWM_ERR(iwm, "Couldn't disable function\n");
746 return ret;
747 }
748
749 return 0;
750}
Zhu Yi68810c52009-06-15 21:59:49 +0200751
752int iwm_down(struct iwm_priv *iwm)
753{
754 int ret;
755
756 mutex_lock(&iwm->mutex);
757 ret = __iwm_down(iwm);
758 mutex_unlock(&iwm->mutex);
759
760 return ret;
761}