• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/net/wireless/iwmc3200wifi/
1/*
2 * Intel Wireless Multicomm 3200 WiFi driver
3 *
4 * Copyright (C) 2009 Intel Corporation. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 *   * Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *   * Redistributions in binary form must reproduce the above copyright
13 *     notice, this list of conditions and the following disclaimer in
14 *     the documentation and/or other materials provided with the
15 *     distribution.
16 *   * Neither the name of Intel Corporation nor the names of its
17 *     contributors may be used to endorse or promote products derived
18 *     from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *
33 * Intel Corporation <ilw@linux.intel.com>
34 * Samuel Ortiz <samuel.ortiz@intel.com>
35 * Zhu Yi <yi.zhu@intel.com>
36 *
37 */
38
39#include <linux/kernel.h>
40#include <linux/netdevice.h>
41#include <linux/sched.h>
42#include <linux/ieee80211.h>
43#include <linux/wireless.h>
44#include <linux/slab.h>
45
46#include "iwm.h"
47#include "debug.h"
48#include "bus.h"
49#include "umac.h"
50#include "commands.h"
51#include "hal.h"
52#include "fw.h"
53#include "rx.h"
54
55static struct iwm_conf def_iwm_conf = {
56
57	.sdio_ior_timeout	= 5000,
58	.calib_map		= BIT(CALIB_CFG_DC_IDX)	|
59				  BIT(CALIB_CFG_LO_IDX)	|
60				  BIT(CALIB_CFG_TX_IQ_IDX)	|
61				  BIT(CALIB_CFG_RX_IQ_IDX)	|
62				  BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD),
63	.expected_calib_map	= BIT(PHY_CALIBRATE_DC_CMD)	|
64				  BIT(PHY_CALIBRATE_LO_CMD)	|
65				  BIT(PHY_CALIBRATE_TX_IQ_CMD)	|
66				  BIT(PHY_CALIBRATE_RX_IQ_CMD)	|
67				  BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD),
68	.ct_kill_entry		= 110,
69	.ct_kill_exit		= 110,
70	.reset_on_fatal_err	= 1,
71	.auto_connect		= 1,
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,
83	.wireless_mode		= WIRELESS_MODE_11A | WIRELESS_MODE_11G |
84				  WIRELESS_MODE_11N,
85
86	/* IBSS */
87	.ibss_band		= UMAC_BAND_2GHZ,
88	.ibss_channel		= 1,
89
90	.mac_addr		= {0x00, 0x02, 0xb3, 0x01, 0x02, 0x03},
91};
92
93static int modparam_reset;
94module_param_named(reset, modparam_reset, bool, 0644);
95MODULE_PARM_DESC(reset, "reset on firmware errors (default 0 [not reset])");
96
97static int modparam_wimax_enable = 1;
98module_param_named(wimax_enable, modparam_wimax_enable, bool, 0644);
99MODULE_PARM_DESC(wimax_enable, "Enable wimax core (default 1 [wimax enabled])");
100
101int iwm_mode_to_nl80211_iftype(int mode)
102{
103	switch (mode) {
104	case UMAC_MODE_BSS:
105		return NL80211_IFTYPE_STATION;
106	case UMAC_MODE_IBSS:
107		return NL80211_IFTYPE_ADHOC;
108	default:
109		return NL80211_IFTYPE_UNSPECIFIED;
110	}
111
112	return 0;
113}
114
115static void iwm_statistics_request(struct work_struct *work)
116{
117	struct iwm_priv *iwm =
118		container_of(work, struct iwm_priv, stats_request.work);
119
120	iwm_send_umac_stats_req(iwm, 0);
121}
122
123static void iwm_disconnect_work(struct work_struct *work)
124{
125	struct iwm_priv *iwm =
126		container_of(work, struct iwm_priv, disconnect.work);
127
128	if (iwm->umac_profile_active)
129		iwm_invalidate_mlme_profile(iwm);
130
131	clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
132	iwm->umac_profile_active = 0;
133	memset(iwm->bssid, 0, ETH_ALEN);
134	iwm->channel = 0;
135
136	iwm_link_off(iwm);
137
138	wake_up_interruptible(&iwm->mlme_queue);
139
140	cfg80211_disconnected(iwm_to_ndev(iwm), 0, NULL, 0, GFP_KERNEL);
141}
142
143static void iwm_ct_kill_work(struct work_struct *work)
144{
145	struct iwm_priv *iwm =
146		container_of(work, struct iwm_priv, ct_kill_delay.work);
147	struct wiphy *wiphy = iwm_to_wiphy(iwm);
148
149	IWM_INFO(iwm, "CT kill delay timeout\n");
150
151	wiphy_rfkill_set_hw_state(wiphy, false);
152}
153
154static int __iwm_up(struct iwm_priv *iwm);
155static int __iwm_down(struct iwm_priv *iwm);
156
157static void iwm_reset_worker(struct work_struct *work)
158{
159	struct iwm_priv *iwm;
160	struct iwm_umac_profile *profile = NULL;
161	int uninitialized_var(ret), retry = 0;
162
163	iwm = container_of(work, struct iwm_priv, reset_worker);
164
165	if (!mutex_trylock(&iwm->mutex)) {
166		IWM_WARN(iwm, "We are in the middle of interface bringing "
167			 "UP/DOWN. Skip driver resetting.\n");
168		return;
169	}
170
171	if (iwm->umac_profile_active) {
172		profile = kmalloc(sizeof(struct iwm_umac_profile), GFP_KERNEL);
173		if (profile)
174			memcpy(profile, iwm->umac_profile, sizeof(*profile));
175		else
176			IWM_ERR(iwm, "Couldn't alloc memory for profile\n");
177	}
178
179	__iwm_down(iwm);
180
181	while (retry++ < 3) {
182		ret = __iwm_up(iwm);
183		if (!ret)
184			break;
185
186		schedule_timeout_uninterruptible(10 * HZ);
187	}
188
189	if (ret) {
190		IWM_WARN(iwm, "iwm_up() failed: %d\n", ret);
191
192		kfree(profile);
193		goto out;
194	}
195
196	if (profile) {
197		IWM_DBG_MLME(iwm, DBG, "Resend UMAC profile\n");
198		memcpy(iwm->umac_profile, profile, sizeof(*profile));
199		iwm_send_mlme_profile(iwm);
200		kfree(profile);
201	} else
202		clear_bit(IWM_STATUS_RESETTING, &iwm->status);
203
204 out:
205	mutex_unlock(&iwm->mutex);
206}
207
208static void iwm_auth_retry_worker(struct work_struct *work)
209{
210	struct iwm_priv *iwm;
211	int i, ret;
212
213	iwm = container_of(work, struct iwm_priv, auth_retry_worker);
214	if (iwm->umac_profile_active) {
215		ret = iwm_invalidate_mlme_profile(iwm);
216		if (ret < 0)
217			return;
218	}
219
220	iwm->umac_profile->sec.auth_type = UMAC_AUTH_TYPE_LEGACY_PSK;
221
222	ret = iwm_send_mlme_profile(iwm);
223	if (ret < 0)
224		return;
225
226	for (i = 0; i < IWM_NUM_KEYS; i++)
227		if (iwm->keys[i].key_len)
228			iwm_set_key(iwm, 0, &iwm->keys[i]);
229
230	iwm_set_tx_key(iwm, iwm->default_key);
231}
232
233
234
235static void iwm_watchdog(unsigned long data)
236{
237	struct iwm_priv *iwm = (struct iwm_priv *)data;
238
239	IWM_WARN(iwm, "Watchdog expired: UMAC stalls!\n");
240
241	if (modparam_reset)
242		iwm_resetting(iwm);
243}
244
245int iwm_priv_init(struct iwm_priv *iwm)
246{
247	int i, j;
248	char name[32];
249
250	iwm->status = 0;
251	INIT_LIST_HEAD(&iwm->pending_notif);
252	init_waitqueue_head(&iwm->notif_queue);
253	init_waitqueue_head(&iwm->nonwifi_queue);
254	init_waitqueue_head(&iwm->wifi_ntfy_queue);
255	init_waitqueue_head(&iwm->mlme_queue);
256	memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf));
257	spin_lock_init(&iwm->tx_credit.lock);
258	INIT_LIST_HEAD(&iwm->wifi_pending_cmd);
259	INIT_LIST_HEAD(&iwm->nonwifi_pending_cmd);
260	iwm->wifi_seq_num = UMAC_WIFI_SEQ_NUM_BASE;
261	iwm->nonwifi_seq_num = UMAC_NONWIFI_SEQ_NUM_BASE;
262	spin_lock_init(&iwm->cmd_lock);
263	iwm->scan_id = 1;
264	INIT_DELAYED_WORK(&iwm->stats_request, iwm_statistics_request);
265	INIT_DELAYED_WORK(&iwm->disconnect, iwm_disconnect_work);
266	INIT_DELAYED_WORK(&iwm->ct_kill_delay, iwm_ct_kill_work);
267	INIT_WORK(&iwm->reset_worker, iwm_reset_worker);
268	INIT_WORK(&iwm->auth_retry_worker, iwm_auth_retry_worker);
269	INIT_LIST_HEAD(&iwm->bss_list);
270
271	skb_queue_head_init(&iwm->rx_list);
272	INIT_LIST_HEAD(&iwm->rx_tickets);
273	spin_lock_init(&iwm->ticket_lock);
274	for (i = 0; i < IWM_RX_ID_HASH; i++) {
275		INIT_LIST_HEAD(&iwm->rx_packets[i]);
276		spin_lock_init(&iwm->packet_lock[i]);
277	}
278
279	INIT_WORK(&iwm->rx_worker, iwm_rx_worker);
280
281	iwm->rx_wq = create_singlethread_workqueue(KBUILD_MODNAME "_rx");
282	if (!iwm->rx_wq)
283		return -EAGAIN;
284
285	for (i = 0; i < IWM_TX_QUEUES; i++) {
286		INIT_WORK(&iwm->txq[i].worker, iwm_tx_worker);
287		snprintf(name, 32, KBUILD_MODNAME "_tx_%d", i);
288		iwm->txq[i].id = i;
289		iwm->txq[i].wq = create_singlethread_workqueue(name);
290		if (!iwm->txq[i].wq)
291			return -EAGAIN;
292
293		skb_queue_head_init(&iwm->txq[i].queue);
294		skb_queue_head_init(&iwm->txq[i].stopped_queue);
295		spin_lock_init(&iwm->txq[i].lock);
296	}
297
298	for (i = 0; i < IWM_NUM_KEYS; i++)
299		memset(&iwm->keys[i], 0, sizeof(struct iwm_key));
300
301	iwm->default_key = -1;
302
303	for (i = 0; i < IWM_STA_TABLE_NUM; i++)
304		for (j = 0; j < IWM_UMAC_TID_NR; j++) {
305			mutex_init(&iwm->sta_table[i].tid_info[j].mutex);
306			iwm->sta_table[i].tid_info[j].stopped = false;
307		}
308
309	init_timer(&iwm->watchdog);
310	iwm->watchdog.function = iwm_watchdog;
311	iwm->watchdog.data = (unsigned long)iwm;
312	mutex_init(&iwm->mutex);
313
314	iwm->last_fw_err = kzalloc(sizeof(struct iwm_fw_error_hdr),
315				   GFP_KERNEL);
316	if (iwm->last_fw_err == NULL)
317		return -ENOMEM;
318
319	return 0;
320}
321
322void iwm_priv_deinit(struct iwm_priv *iwm)
323{
324	int i;
325
326	for (i = 0; i < IWM_TX_QUEUES; i++)
327		destroy_workqueue(iwm->txq[i].wq);
328
329	destroy_workqueue(iwm->rx_wq);
330	kfree(iwm->last_fw_err);
331}
332
333/*
334 * We reset all the structures, and we reset the UMAC.
335 * After calling this routine, you're expected to reload
336 * the firmware.
337 */
338void iwm_reset(struct iwm_priv *iwm)
339{
340	struct iwm_notif *notif, *next;
341
342	if (test_bit(IWM_STATUS_READY, &iwm->status))
343		iwm_target_reset(iwm);
344
345	if (test_bit(IWM_STATUS_RESETTING, &iwm->status)) {
346		iwm->status = 0;
347		set_bit(IWM_STATUS_RESETTING, &iwm->status);
348	} else
349		iwm->status = 0;
350	iwm->scan_id = 1;
351
352	list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) {
353		list_del(&notif->pending);
354		kfree(notif->buf);
355		kfree(notif);
356	}
357
358	iwm_cmd_flush(iwm);
359
360	flush_workqueue(iwm->rx_wq);
361
362	iwm_link_off(iwm);
363}
364
365void iwm_resetting(struct iwm_priv *iwm)
366{
367	set_bit(IWM_STATUS_RESETTING, &iwm->status);
368
369	schedule_work(&iwm->reset_worker);
370}
371
372int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
373		   u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size)
374{
375	struct iwm_notif *notif;
376
377	notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL);
378	if (!notif) {
379		IWM_ERR(iwm, "Couldn't alloc memory for notification\n");
380		return -ENOMEM;
381	}
382
383	INIT_LIST_HEAD(&notif->pending);
384	notif->cmd = cmd;
385	notif->cmd_id = cmd_id;
386	notif->src = source;
387	notif->buf = kzalloc(buf_size, GFP_KERNEL);
388	if (!notif->buf) {
389		IWM_ERR(iwm, "Couldn't alloc notification buffer\n");
390		kfree(notif);
391		return -ENOMEM;
392	}
393	notif->buf_size = buf_size;
394	memcpy(notif->buf, buf, buf_size);
395	list_add_tail(&notif->pending, &iwm->pending_notif);
396
397	wake_up_interruptible(&iwm->notif_queue);
398
399	return 0;
400}
401
402static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd,
403					u8 source)
404{
405	struct iwm_notif *notif;
406
407	list_for_each_entry(notif, &iwm->pending_notif, pending) {
408		if ((notif->cmd_id == cmd) && (notif->src == source)) {
409			list_del(&notif->pending);
410			return notif;
411		}
412	}
413
414	return NULL;
415}
416
417static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd,
418					u8 source, long timeout)
419{
420	int ret;
421	struct iwm_notif *notif;
422	unsigned long *map = NULL;
423
424	switch (source) {
425	case IWM_SRC_LMAC:
426		map = &iwm->lmac_handler_map[0];
427		break;
428	case IWM_SRC_UMAC:
429		map = &iwm->umac_handler_map[0];
430		break;
431	case IWM_SRC_UDMA:
432		map = &iwm->udma_handler_map[0];
433		break;
434	}
435
436	set_bit(cmd, map);
437
438	ret = wait_event_interruptible_timeout(iwm->notif_queue,
439			 ((notif = iwm_notif_find(iwm, cmd, source)) != NULL),
440					       timeout);
441	clear_bit(cmd, map);
442
443	if (!ret)
444		return NULL;
445
446	return notif;
447}
448
449int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout)
450{
451	int ret;
452	struct iwm_notif *notif;
453
454	notif = iwm_notif_wait(iwm, cmd, source, timeout);
455	if (!notif)
456		return -ETIME;
457
458	ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd);
459	kfree(notif->buf);
460	kfree(notif);
461
462	return ret;
463}
464
465static int iwm_config_boot_params(struct iwm_priv *iwm)
466{
467	struct iwm_udma_nonwifi_cmd target_cmd;
468	int ret;
469
470	/* check Wimax is off and config debug monitor */
471	if (!modparam_wimax_enable) {
472		u32 data1 = 0x1f;
473		u32 addr1 = 0x606BE258;
474
475		u32 data2_set = 0x0;
476		u32 data2_clr = 0x1;
477		u32 addr2 = 0x606BE100;
478
479		u32 data3 = 0x1;
480		u32 addr3 = 0x606BEC00;
481
482		target_cmd.resp = 0;
483		target_cmd.handle_by_hw = 0;
484		target_cmd.eop = 1;
485
486		target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE;
487		target_cmd.addr = cpu_to_le32(addr1);
488		target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
489		target_cmd.op2 = 0;
490
491		ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1);
492		if (ret < 0) {
493			IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
494			return ret;
495		}
496
497		target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE;
498		target_cmd.addr = cpu_to_le32(addr2);
499		target_cmd.op1_sz = cpu_to_le32(data2_set);
500		target_cmd.op2 = cpu_to_le32(data2_clr);
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_WRITE;
509		target_cmd.addr = cpu_to_le32(addr3);
510		target_cmd.op1_sz = cpu_to_le32(sizeof(u32));
511		target_cmd.op2 = 0;
512
513		ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3);
514		if (ret < 0) {
515			IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n");
516			return ret;
517		}
518	}
519
520	return 0;
521}
522
523void iwm_init_default_profile(struct iwm_priv *iwm,
524			      struct iwm_umac_profile *profile)
525{
526	memset(profile, 0, sizeof(struct iwm_umac_profile));
527
528	profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN;
529	profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE;
530	profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE;
531	profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE;
532
533	if (iwm->conf.enable_qos)
534		profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED);
535
536	profile->wireless_mode = iwm->conf.wireless_mode;
537	profile->mode = cpu_to_le32(iwm->conf.mode);
538
539	profile->ibss.atim = 0;
540	profile->ibss.beacon_interval = 100;
541	profile->ibss.join_only = 0;
542	profile->ibss.band = iwm->conf.ibss_band;
543	profile->ibss.channel = iwm->conf.ibss_channel;
544}
545
546void iwm_link_on(struct iwm_priv *iwm)
547{
548	netif_carrier_on(iwm_to_ndev(iwm));
549	netif_tx_wake_all_queues(iwm_to_ndev(iwm));
550
551	iwm_send_umac_stats_req(iwm, 0);
552}
553
554void iwm_link_off(struct iwm_priv *iwm)
555{
556	struct iw_statistics *wstats = &iwm->wstats;
557	int i;
558
559	netif_tx_stop_all_queues(iwm_to_ndev(iwm));
560	netif_carrier_off(iwm_to_ndev(iwm));
561
562	for (i = 0; i < IWM_TX_QUEUES; i++) {
563		skb_queue_purge(&iwm->txq[i].queue);
564		skb_queue_purge(&iwm->txq[i].stopped_queue);
565
566		iwm->txq[i].concat_count = 0;
567		iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf;
568
569		flush_workqueue(iwm->txq[i].wq);
570	}
571
572	iwm_rx_free(iwm);
573
574	cancel_delayed_work_sync(&iwm->stats_request);
575	memset(wstats, 0, sizeof(struct iw_statistics));
576	wstats->qual.updated = IW_QUAL_ALL_INVALID;
577
578	kfree(iwm->req_ie);
579	iwm->req_ie = NULL;
580	iwm->req_ie_len = 0;
581	kfree(iwm->resp_ie);
582	iwm->resp_ie = NULL;
583	iwm->resp_ie_len = 0;
584
585	del_timer_sync(&iwm->watchdog);
586}
587
588static void iwm_bss_list_clean(struct iwm_priv *iwm)
589{
590	struct iwm_bss_info *bss, *next;
591
592	list_for_each_entry_safe(bss, next, &iwm->bss_list, node) {
593		list_del(&bss->node);
594		kfree(bss->bss);
595		kfree(bss);
596	}
597}
598
599static int iwm_channels_init(struct iwm_priv *iwm)
600{
601	int ret;
602
603	ret = iwm_send_umac_channel_list(iwm);
604	if (ret) {
605		IWM_ERR(iwm, "Send channel list failed\n");
606		return ret;
607	}
608
609	ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST,
610			       IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
611	if (ret) {
612		IWM_ERR(iwm, "Didn't get a channel list notification\n");
613		return ret;
614	}
615
616	return 0;
617}
618
619static int __iwm_up(struct iwm_priv *iwm)
620{
621	int ret;
622	struct iwm_notif *notif_reboot, *notif_ack = NULL;
623	struct wiphy *wiphy = iwm_to_wiphy(iwm);
624	u32 wireless_mode;
625
626	ret = iwm_bus_enable(iwm);
627	if (ret) {
628		IWM_ERR(iwm, "Couldn't enable function\n");
629		return ret;
630	}
631
632	iwm_rx_setup_handlers(iwm);
633
634	/* Wait for initial BARKER_REBOOT from hardware */
635	notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION,
636				      IWM_SRC_UDMA, 2 * HZ);
637	if (!notif_reboot) {
638		IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n");
639		goto err_disable;
640	}
641
642	/* We send the barker back */
643	ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16);
644	if (ret) {
645		IWM_ERR(iwm, "REBOOT barker response failed\n");
646		kfree(notif_reboot);
647		goto err_disable;
648	}
649
650	kfree(notif_reboot->buf);
651	kfree(notif_reboot);
652
653	/* Wait for ACK_BARKER from hardware */
654	notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION,
655				   IWM_SRC_UDMA, 2 * HZ);
656	if (!notif_ack) {
657		IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n");
658		goto err_disable;
659	}
660
661	kfree(notif_ack->buf);
662	kfree(notif_ack);
663
664	/* We start to config static boot parameters */
665	ret = iwm_config_boot_params(iwm);
666	if (ret) {
667		IWM_ERR(iwm, "Config boot parameters failed\n");
668		goto err_disable;
669	}
670
671	ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr);
672	if (ret) {
673		IWM_ERR(iwm, "MAC reading failed\n");
674		goto err_disable;
675	}
676	memcpy(iwm_to_ndev(iwm)->perm_addr, iwm_to_ndev(iwm)->dev_addr,
677		ETH_ALEN);
678
679	/* We can load the FWs */
680	ret = iwm_load_fw(iwm);
681	if (ret) {
682		IWM_ERR(iwm, "FW loading failed\n");
683		goto err_disable;
684	}
685
686	ret = iwm_eeprom_fat_channels(iwm);
687	if (ret) {
688		IWM_ERR(iwm, "Couldnt read HT channels EEPROM entries\n");
689		goto err_fw;
690	}
691
692	/*
693	 * Read our SKU capabilities.
694	 * If it's valid, we AND the configured wireless mode with the
695	 * device EEPROM value as the current profile wireless mode.
696	 */
697	wireless_mode = iwm_eeprom_wireless_mode(iwm);
698	if (wireless_mode) {
699		iwm->conf.wireless_mode &= wireless_mode;
700		if (iwm->umac_profile)
701			iwm->umac_profile->wireless_mode =
702					iwm->conf.wireless_mode;
703	} else
704		IWM_ERR(iwm, "Wrong SKU capabilities: 0x%x\n",
705			*((u16 *)iwm_eeprom_access(iwm, IWM_EEPROM_SKU_CAP)));
706
707	snprintf(wiphy->fw_version, sizeof(wiphy->fw_version), "L%s_U%s",
708		 iwm->lmac_version, iwm->umac_version);
709
710	/* We configure the UMAC and enable the wifi module */
711	ret = iwm_send_umac_config(iwm,
712			cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) |
713			cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) |
714			cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN));
715	if (ret) {
716		IWM_ERR(iwm, "UMAC config failed\n");
717		goto err_fw;
718	}
719
720	ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
721			       IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
722	if (ret) {
723		IWM_ERR(iwm, "Didn't get a wifi core status notification\n");
724		goto err_fw;
725	}
726
727	if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
728				  UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
729		IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n",
730			     iwm->core_enabled);
731		ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS,
732			       IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT);
733		if (ret) {
734			IWM_ERR(iwm, "Didn't get a core status notification\n");
735			goto err_fw;
736		}
737
738		if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN |
739					  UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) {
740			IWM_ERR(iwm, "Not all cores enabled: 0x%x\n",
741				iwm->core_enabled);
742			goto err_fw;
743		} else {
744			IWM_INFO(iwm, "All cores enabled\n");
745		}
746	}
747
748	ret = iwm_channels_init(iwm);
749	if (ret < 0) {
750		IWM_ERR(iwm, "Couldn't init channels\n");
751		goto err_fw;
752	}
753
754	/* Set the READY bit to indicate interface is brought up successfully */
755	set_bit(IWM_STATUS_READY, &iwm->status);
756
757	return 0;
758
759 err_fw:
760	iwm_eeprom_exit(iwm);
761
762 err_disable:
763	ret = iwm_bus_disable(iwm);
764	if (ret < 0)
765		IWM_ERR(iwm, "Couldn't disable function\n");
766
767	return -EIO;
768}
769
770int iwm_up(struct iwm_priv *iwm)
771{
772	int ret;
773
774	mutex_lock(&iwm->mutex);
775	ret = __iwm_up(iwm);
776	mutex_unlock(&iwm->mutex);
777
778	return ret;
779}
780
781static int __iwm_down(struct iwm_priv *iwm)
782{
783	int ret;
784
785	/* The interface is already down */
786	if (!test_bit(IWM_STATUS_READY, &iwm->status))
787		return 0;
788
789	if (iwm->scan_request) {
790		cfg80211_scan_done(iwm->scan_request, true);
791		iwm->scan_request = NULL;
792	}
793
794	clear_bit(IWM_STATUS_READY, &iwm->status);
795
796	iwm_eeprom_exit(iwm);
797	iwm_bss_list_clean(iwm);
798	iwm_init_default_profile(iwm, iwm->umac_profile);
799	iwm->umac_profile_active = false;
800	iwm->default_key = -1;
801	iwm->core_enabled = 0;
802
803	ret = iwm_bus_disable(iwm);
804	if (ret < 0) {
805		IWM_ERR(iwm, "Couldn't disable function\n");
806		return ret;
807	}
808
809	return 0;
810}
811
812int iwm_down(struct iwm_priv *iwm)
813{
814	int ret;
815
816	mutex_lock(&iwm->mutex);
817	ret = __iwm_down(iwm);
818	mutex_unlock(&iwm->mutex);
819
820	return ret;
821}
822