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