blob: 952701e6127e72ceaa8ec94ecde77003a0fb331a [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
Samuel Ortiz9829e1b2009-10-16 13:18:57 +0800210static void iwm_auth_retry_worker(struct work_struct *work)
211{
212 struct iwm_priv *iwm;
213 int i, ret;
214
215 iwm = container_of(work, struct iwm_priv, auth_retry_worker);
216 if (iwm->umac_profile_active) {
217 ret = iwm_invalidate_mlme_profile(iwm);
218 if (ret < 0)
219 return;
220 }
221
222 iwm->umac_profile->sec.auth_type = UMAC_AUTH_TYPE_LEGACY_PSK;
223
224 ret = iwm_send_mlme_profile(iwm);
225 if (ret < 0)
226 return;
227
228 for (i = 0; i < IWM_NUM_KEYS; i++)
229 if (iwm->keys[i].key_len)
230 iwm_set_key(iwm, 0, &iwm->keys[i]);
231
232 iwm_set_tx_key(iwm, iwm->default_key);
233}
234
235
236
Zhu Yibb9f8692009-05-21 21:20:45 +0800237static void iwm_watchdog(unsigned long data)
238{
239 struct iwm_priv *iwm = (struct iwm_priv *)data;
240
241 IWM_WARN(iwm, "Watchdog expired: UMAC stalls!\n");
242
243 if (modparam_reset)
Samuel Ortizd2101762009-09-01 15:14:05 +0200244 iwm_resetting(iwm);
Zhu Yibb9f8692009-05-21 21:20:45 +0800245}
246
247int iwm_priv_init(struct iwm_priv *iwm)
248{
249 int i;
250 char name[32];
251
252 iwm->status = 0;
253 INIT_LIST_HEAD(&iwm->pending_notif);
254 init_waitqueue_head(&iwm->notif_queue);
255 init_waitqueue_head(&iwm->nonwifi_queue);
Samuel Ortiza70742f2009-06-15 21:59:51 +0200256 init_waitqueue_head(&iwm->wifi_ntfy_queue);
Zhu Yibb9f8692009-05-21 21:20:45 +0800257 init_waitqueue_head(&iwm->mlme_queue);
258 memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf));
259 spin_lock_init(&iwm->tx_credit.lock);
260 INIT_LIST_HEAD(&iwm->wifi_pending_cmd);
261 INIT_LIST_HEAD(&iwm->nonwifi_pending_cmd);
262 iwm->wifi_seq_num = UMAC_WIFI_SEQ_NUM_BASE;
263 iwm->nonwifi_seq_num = UMAC_NONWIFI_SEQ_NUM_BASE;
264 spin_lock_init(&iwm->cmd_lock);
265 iwm->scan_id = 1;
266 INIT_DELAYED_WORK(&iwm->stats_request, iwm_statistics_request);
Zhu Yic7436272009-09-01 15:14:02 +0200267 INIT_DELAYED_WORK(&iwm->disconnect, iwm_disconnect_work);
Samuel Ortize85498b2009-10-16 13:18:48 +0800268 INIT_DELAYED_WORK(&iwm->ct_kill_delay, iwm_ct_kill_work);
Zhu Yibb9f8692009-05-21 21:20:45 +0800269 INIT_WORK(&iwm->reset_worker, iwm_reset_worker);
Samuel Ortiz9829e1b2009-10-16 13:18:57 +0800270 INIT_WORK(&iwm->auth_retry_worker, iwm_auth_retry_worker);
Zhu Yibb9f8692009-05-21 21:20:45 +0800271 INIT_LIST_HEAD(&iwm->bss_list);
272
273 skb_queue_head_init(&iwm->rx_list);
274 INIT_LIST_HEAD(&iwm->rx_tickets);
275 for (i = 0; i < IWM_RX_ID_HASH; i++)
276 INIT_LIST_HEAD(&iwm->rx_packets[i]);
277
278 INIT_WORK(&iwm->rx_worker, iwm_rx_worker);
279
280 iwm->rx_wq = create_singlethread_workqueue(KBUILD_MODNAME "_rx");
281 if (!iwm->rx_wq)
282 return -EAGAIN;
283
284 for (i = 0; i < IWM_TX_QUEUES; i++) {
285 INIT_WORK(&iwm->txq[i].worker, iwm_tx_worker);
286 snprintf(name, 32, KBUILD_MODNAME "_tx_%d", i);
287 iwm->txq[i].id = i;
288 iwm->txq[i].wq = create_singlethread_workqueue(name);
289 if (!iwm->txq[i].wq)
290 return -EAGAIN;
291
292 skb_queue_head_init(&iwm->txq[i].queue);
293 }
294
295 for (i = 0; i < IWM_NUM_KEYS; i++)
296 memset(&iwm->keys[i], 0, sizeof(struct iwm_key));
297
Samuel Ortiz13e0fe72009-06-15 21:59:52 +0200298 iwm->default_key = -1;
Zhu Yibb9f8692009-05-21 21:20:45 +0800299
300 init_timer(&iwm->watchdog);
301 iwm->watchdog.function = iwm_watchdog;
302 iwm->watchdog.data = (unsigned long)iwm;
Zhu Yi68810c52009-06-15 21:59:49 +0200303 mutex_init(&iwm->mutex);
Zhu Yibb9f8692009-05-21 21:20:45 +0800304
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200305 iwm->last_fw_err = kzalloc(sizeof(struct iwm_fw_error_hdr),
306 GFP_KERNEL);
307 if (iwm->last_fw_err == NULL)
308 return -ENOMEM;
309
Zhu Yibb9f8692009-05-21 21:20:45 +0800310 return 0;
311}
312
Zhu Yi8d96e792009-06-15 21:36:13 +0200313void iwm_priv_deinit(struct iwm_priv *iwm)
314{
315 int i;
316
317 for (i = 0; i < IWM_TX_QUEUES; i++)
318 destroy_workqueue(iwm->txq[i].wq);
319
320 destroy_workqueue(iwm->rx_wq);
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200321 kfree(iwm->last_fw_err);
Zhu Yi8d96e792009-06-15 21:36:13 +0200322}
323
Zhu Yibb9f8692009-05-21 21:20:45 +0800324/*
325 * We reset all the structures, and we reset the UMAC.
326 * After calling this routine, you're expected to reload
327 * the firmware.
328 */
329void iwm_reset(struct iwm_priv *iwm)
330{
331 struct iwm_notif *notif, *next;
332
333 if (test_bit(IWM_STATUS_READY, &iwm->status))
334 iwm_target_reset(iwm);
335
Samuel Ortizd2101762009-09-01 15:14:05 +0200336 if (test_bit(IWM_STATUS_RESETTING, &iwm->status)) {
337 iwm->status = 0;
338 set_bit(IWM_STATUS_RESETTING, &iwm->status);
339 } else
340 iwm->status = 0;
Zhu Yibb9f8692009-05-21 21:20:45 +0800341 iwm->scan_id = 1;
342
343 list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
344 list_del(&notif->pending);
345 kfree(notif->buf);
346 kfree(notif);
347 }
348
349 iwm_cmd_flush(iwm);
350
351 flush_workqueue(iwm->rx_wq);
352
353 iwm_link_off(iwm);
354}
355
Samuel Ortizd2101762009-09-01 15:14:05 +0200356void iwm_resetting(struct iwm_priv *iwm)
357{
358 set_bit(IWM_STATUS_RESETTING, &iwm->status);
359
360 schedule_work(&iwm->reset_worker);
361}
362
Zhu Yibb9f8692009-05-21 21:20:45 +0800363/*
364 * Notification code:
365 *
366 * We're faced with the following issue: Any host command can
367 * have an answer or not, and if there's an answer to expect,
368 * it can be treated synchronously or asynchronously.
369 * To work around the synchronous answer case, we implemented
370 * our notification mechanism.
371 * When a code path needs to wait for a command response
372 * synchronously, it calls notif_handle(), which waits for the
373 * right notification to show up, and then process it. Before
374 * starting to wait, it registered as a waiter for this specific
375 * answer (by toggling a bit in on of the handler_map), so that
376 * the rx code knows that it needs to send a notification to the
377 * waiting processes. It does so by calling iwm_notif_send(),
378 * which adds the notification to the pending notifications list,
379 * and then wakes the waiting processes up.
380 */
381int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
382 u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size)
383{
384 struct iwm_notif *notif;
385
386 notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL);
387 if (!notif) {
388 IWM_ERR(iwm, "Couldn't alloc memory for notification\n");
389 return -ENOMEM;
390 }
391
392 INIT_LIST_HEAD(&notif->pending);
393 notif->cmd = cmd;
394 notif->cmd_id = cmd_id;
395 notif->src = source;
396 notif->buf = kzalloc(buf_size, GFP_KERNEL);
397 if (!notif->buf) {
398 IWM_ERR(iwm, "Couldn't alloc notification buffer\n");
399 kfree(notif);
400 return -ENOMEM;
401 }
402 notif->buf_size = buf_size;
403 memcpy(notif->buf, buf, buf_size);
404 list_add_tail(&notif->pending, &iwm->pending_notif);
405
406 wake_up_interruptible(&iwm->notif_queue);
407
408 return 0;
409}
410
411static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd,
412 u8 source)
413{
414 struct iwm_notif *notif, *next;
415
416 list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
417 if ((notif->cmd_id == cmd) && (notif->src == source)) {
418 list_del(&notif->pending);
419 return notif;
420 }
421 }
422
423 return NULL;
424}
425
426static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd,
427 u8 source, long timeout)
428{
429 int ret;
430 struct iwm_notif *notif;
431 unsigned long *map = NULL;
432
433 switch (source) {
434 case IWM_SRC_LMAC:
435 map = &iwm->lmac_handler_map[0];
436 break;
437 case IWM_SRC_UMAC:
438 map = &iwm->umac_handler_map[0];
439 break;
440 case IWM_SRC_UDMA:
441 map = &iwm->udma_handler_map[0];
442 break;
443 }
444
445 set_bit(cmd, map);
446
447 ret = wait_event_interruptible_timeout(iwm->notif_queue,
448 ((notif = iwm_notif_find(iwm, cmd, source)) != NULL),
449 timeout);
450 clear_bit(cmd, map);
451
452 if (!ret)
453 return NULL;
454
455 return notif;
456}
457
458int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout)
459{
460 int ret;
461 struct iwm_notif *notif;
462
463 notif = iwm_notif_wait(iwm, cmd, source, timeout);
464 if (!notif)
465 return -ETIME;
466
467 ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd);
468 kfree(notif->buf);
469 kfree(notif);
470
471 return ret;
472}
473
474static int iwm_config_boot_params(struct iwm_priv *iwm)
475{
476 struct iwm_udma_nonwifi_cmd target_cmd;
477 int ret;
478
479 /* check Wimax is off and config debug monitor */
480 if (iwm->conf.wimax_not_present) {
481 u32 data1 = 0x1f;
482 u32 addr1 = 0x606BE258;
483
484 u32 data2_set = 0x0;
485 u32 data2_clr = 0x1;
486 u32 addr2 = 0x606BE100;
487
488 u32 data3 = 0x1;
489 u32 addr3 = 0x606BEC00;
490
491 target_cmd.resp = 0;
492 target_cmd.handle_by_hw = 0;
493 target_cmd.eop = 1;
494
495 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
496 target_cmd.addr = cpu_to_le32(addr1);
497 target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
498 target_cmd.op2 = 0;
499
500 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
501 if (ret < 0) {
502 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
503 return ret;
504 }
505
506 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE;
507 target_cmd.addr = cpu_to_le32(addr2);
508 target_cmd.op1_sz = cpu_to_le32(data2_set);
509 target_cmd.op2 = cpu_to_le32(data2_clr);
510
511 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
512 if (ret < 0) {
513 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
514 return ret;
515 }
516
517 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
518 target_cmd.addr = cpu_to_le32(addr3);
519 target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
520 target_cmd.op2 = 0;
521
522 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3);
523 if (ret < 0) {
524 IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
525 return ret;
526 }
527 }
528
529 return 0;
530}
531
532void iwm_init_default_profile(struct iwm_priv *iwm,
533 struct iwm_umac_profile *profile)
534{
535 memset(profile, 0, sizeof(struct iwm_umac_profile));
536
537 profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN;
538 profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE;
539 profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE;
540 profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE;
541
542 if (iwm->conf.enable_qos)
543 profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED);
544
545 profile->wireless_mode = iwm->conf.wireless_mode;
546 profile->mode = cpu_to_le32(iwm->conf.mode);
547
548 profile->ibss.atim = 0;
549 profile->ibss.beacon_interval = 100;
550 profile->ibss.join_only = 0;
551 profile->ibss.band = iwm->conf.ibss_band;
552 profile->ibss.channel = iwm->conf.ibss_channel;
553}
554
555void iwm_link_on(struct iwm_priv *iwm)
556{
557 netif_carrier_on(iwm_to_ndev(iwm));
558 netif_tx_wake_all_queues(iwm_to_ndev(iwm));
559
560 iwm_send_umac_stats_req(iwm, 0);
561}
562
563void iwm_link_off(struct iwm_priv *iwm)
564{
565 struct iw_statistics *wstats = &iwm->wstats;
566 int i;
567
568 netif_tx_stop_all_queues(iwm_to_ndev(iwm));
569 netif_carrier_off(iwm_to_ndev(iwm));
570
571 for (i = 0; i < IWM_TX_QUEUES; i++) {
572 skb_queue_purge(&iwm->txq[i].queue);
573
574 iwm->txq[i].concat_count = 0;
575 iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf;
576
577 flush_workqueue(iwm->txq[i].wq);
578 }
579
580 iwm_rx_free(iwm);
581
Zhu Yi68810c52009-06-15 21:59:49 +0200582 cancel_delayed_work_sync(&iwm->stats_request);
Zhu Yibb9f8692009-05-21 21:20:45 +0800583 memset(wstats, 0, sizeof(struct iw_statistics));
584 wstats->qual.updated = IW_QUAL_ALL_INVALID;
585
Zhu Yib68518f2009-07-20 11:47:45 +0800586 kfree(iwm->req_ie);
587 iwm->req_ie = NULL;
588 iwm->req_ie_len = 0;
589 kfree(iwm->resp_ie);
590 iwm->resp_ie = NULL;
591 iwm->resp_ie_len = 0;
592
Zhu Yibb9f8692009-05-21 21:20:45 +0800593 del_timer_sync(&iwm->watchdog);
594}
595
596static void iwm_bss_list_clean(struct iwm_priv *iwm)
597{
598 struct iwm_bss_info *bss, *next;
599
600 list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
601 list_del(&bss->node);
602 kfree(bss->bss);
603 kfree(bss);
604 }
605}
606
607static int iwm_channels_init(struct iwm_priv *iwm)
608{
609 int ret;
610
Zhu Yibb9f8692009-05-21 21:20:45 +0800611 ret = iwm_send_umac_channel_list(iwm);
612 if (ret) {
613 IWM_ERR(iwm, "Send channel list failed\n");
614 return ret;
615 }
616
617 ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST,
618 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
619 if (ret) {
620 IWM_ERR(iwm, "Didn't get a channel list notification\n");
621 return ret;
622 }
623
624 return 0;
625}
626
Zhu Yi314524202009-09-01 15:14:03 +0200627static int __iwm_up(struct iwm_priv *iwm)
Zhu Yibb9f8692009-05-21 21:20:45 +0800628{
629 int ret;
630 struct iwm_notif *notif_reboot, *notif_ack = NULL;
631
632 ret = iwm_bus_enable(iwm);
633 if (ret) {
634 IWM_ERR(iwm, "Couldn't enable function\n");
635 return ret;
636 }
637
638 iwm_rx_setup_handlers(iwm);
639
640 /* Wait for initial BARKER_REBOOT from hardware */
641 notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION,
642 IWM_SRC_UDMA, 2 * HZ);
643 if (!notif_reboot) {
644 IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n");
645 goto err_disable;
646 }
647
648 /* We send the barker back */
649 ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16);
650 if (ret) {
651 IWM_ERR(iwm, "REBOOT barker response failed\n");
652 kfree(notif_reboot);
653 goto err_disable;
654 }
655
656 kfree(notif_reboot->buf);
657 kfree(notif_reboot);
658
659 /* Wait for ACK_BARKER from hardware */
660 notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION,
661 IWM_SRC_UDMA, 2 * HZ);
662 if (!notif_ack) {
663 IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n");
664 goto err_disable;
665 }
666
667 kfree(notif_ack->buf);
668 kfree(notif_ack);
669
670 /* We start to config static boot parameters */
671 ret = iwm_config_boot_params(iwm);
672 if (ret) {
673 IWM_ERR(iwm, "Config boot parameters failed\n");
674 goto err_disable;
675 }
676
677 ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr);
678 if (ret) {
679 IWM_ERR(iwm, "MAC reading failed\n");
680 goto err_disable;
681 }
John W. Linville5b367372009-10-06 16:41:21 -0400682 memcpy(iwm_to_ndev(iwm)->perm_addr, iwm_to_ndev(iwm)->dev_addr,
683 ETH_ALEN);
Zhu Yibb9f8692009-05-21 21:20:45 +0800684
685 /* We can load the FWs */
686 ret = iwm_load_fw(iwm);
687 if (ret) {
688 IWM_ERR(iwm, "FW loading failed\n");
689 goto err_disable;
690 }
691
692 /* We configure the UMAC and enable the wifi module */
693 ret = iwm_send_umac_config(iwm,
694 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) |
695 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) |
696 cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN));
697 if (ret) {
698 IWM_ERR(iwm, "UMAC config failed\n");
699 goto err_fw;
700 }
701
702 ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
703 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
704 if (ret) {
705 IWM_ERR(iwm, "Didn't get a wifi core status notification\n");
706 goto err_fw;
707 }
708
709 if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
710 UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
711 IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n",
712 iwm->core_enabled);
713 ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
714 IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
715 if (ret) {
716 IWM_ERR(iwm, "Didn't get a core status notification\n");
717 goto err_fw;
718 }
719
720 if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
721 UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
722 IWM_ERR(iwm, "Not all cores enabled: 0x%x\n",
723 iwm->core_enabled);
724 goto err_fw;
725 } else {
726 IWM_INFO(iwm, "All cores enabled\n");
727 }
728 }
729
Zhu Yibb9f8692009-05-21 21:20:45 +0800730 ret = iwm_channels_init(iwm);
731 if (ret < 0) {
732 IWM_ERR(iwm, "Couldn't init channels\n");
Samuel Ortiz35497162009-06-15 21:59:54 +0200733 goto err_fw;
Zhu Yibb9f8692009-05-21 21:20:45 +0800734 }
735
736 /* Set the READY bit to indicate interface is brought up successfully */
737 set_bit(IWM_STATUS_READY, &iwm->status);
738
739 return 0;
740
Zhu Yibb9f8692009-05-21 21:20:45 +0800741 err_fw:
742 iwm_eeprom_exit(iwm);
743
744 err_disable:
745 ret = iwm_bus_disable(iwm);
746 if (ret < 0)
747 IWM_ERR(iwm, "Couldn't disable function\n");
748
749 return -EIO;
750}
751
Zhu Yi68810c52009-06-15 21:59:49 +0200752int iwm_up(struct iwm_priv *iwm)
753{
754 int ret;
755
756 mutex_lock(&iwm->mutex);
757 ret = __iwm_up(iwm);
758 mutex_unlock(&iwm->mutex);
759
760 return ret;
761}
762
Zhu Yi314524202009-09-01 15:14:03 +0200763static int __iwm_down(struct iwm_priv *iwm)
Zhu Yibb9f8692009-05-21 21:20:45 +0800764{
765 int ret;
766
767 /* The interface is already down */
768 if (!test_bit(IWM_STATUS_READY, &iwm->status))
769 return 0;
770
771 if (iwm->scan_request) {
772 cfg80211_scan_done(iwm->scan_request, true);
773 iwm->scan_request = NULL;
774 }
775
776 clear_bit(IWM_STATUS_READY, &iwm->status);
777
778 iwm_eeprom_exit(iwm);
Zhu Yibb9f8692009-05-21 21:20:45 +0800779 iwm_bss_list_clean(iwm);
Samuel Ortiz35497162009-06-15 21:59:54 +0200780 iwm_init_default_profile(iwm, iwm->umac_profile);
781 iwm->umac_profile_active = false;
Samuel Ortiz13e0fe72009-06-15 21:59:52 +0200782 iwm->default_key = -1;
Zhu Yibb9f8692009-05-21 21:20:45 +0800783 iwm->core_enabled = 0;
784
785 ret = iwm_bus_disable(iwm);
786 if (ret < 0) {
787 IWM_ERR(iwm, "Couldn't disable function\n");
788 return ret;
789 }
790
791 return 0;
792}
Zhu Yi68810c52009-06-15 21:59:49 +0200793
794int iwm_down(struct iwm_priv *iwm)
795{
796 int ret;
797
798 mutex_lock(&iwm->mutex);
799 ret = __iwm_down(iwm);
800 mutex_unlock(&iwm->mutex);
801
802 return ret;
803}