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