Linux Audio

Check our new training course

Loading...
v6.8
  1/*
  2 * Copyright (c) 2004-2011 Atheros Communications Inc.
  3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4 *
  5 * Permission to use, copy, modify, and/or distribute this software for any
  6 * purpose with or without fee is hereby granted, provided that the above
  7 * copyright notice and this permission notice appear in all copies.
  8 *
  9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 16 */
 17
 18#include "core.h"
 19
 20#include <linux/module.h>
 21#include <linux/moduleparam.h>
 22#include <linux/export.h>
 23#include <linux/vmalloc.h>
 24
 25#include "debug.h"
 26#include "hif-ops.h"
 27#include "htc-ops.h"
 28#include "cfg80211.h"
 29
 30unsigned int debug_mask;
 31static unsigned int suspend_mode;
 32static unsigned int wow_mode;
 33static unsigned int uart_debug;
 34static unsigned int uart_rate = 115200;
 35static unsigned int ath6kl_p2p;
 36static unsigned int testmode;
 37static unsigned int recovery_enable;
 38static unsigned int heart_beat_poll;
 39
 40module_param(debug_mask, uint, 0644);
 41module_param(suspend_mode, uint, 0644);
 42module_param(wow_mode, uint, 0644);
 43module_param(uart_debug, uint, 0644);
 44module_param(uart_rate, uint, 0644);
 45module_param(ath6kl_p2p, uint, 0644);
 46module_param(testmode, uint, 0644);
 47module_param(recovery_enable, uint, 0644);
 48module_param(heart_beat_poll, uint, 0644);
 49MODULE_PARM_DESC(recovery_enable, "Enable recovery from firmware error");
 50MODULE_PARM_DESC(heart_beat_poll,
 51		 "Enable fw error detection periodic polling in msecs - Also set recovery_enable for this to be effective");
 52
 53
 54void ath6kl_core_tx_complete(struct ath6kl *ar, struct sk_buff *skb)
 55{
 56	ath6kl_htc_tx_complete(ar, skb);
 57}
 58EXPORT_SYMBOL(ath6kl_core_tx_complete);
 59
 60void ath6kl_core_rx_complete(struct ath6kl *ar, struct sk_buff *skb, u8 pipe)
 61{
 62	ath6kl_htc_rx_complete(ar, skb, pipe);
 63}
 64EXPORT_SYMBOL(ath6kl_core_rx_complete);
 65
 66int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type)
 67{
 68	struct ath6kl_bmi_target_info targ_info;
 69	struct wireless_dev *wdev;
 70	int ret = 0, i;
 71
 72	switch (htc_type) {
 73	case ATH6KL_HTC_TYPE_MBOX:
 74		ath6kl_htc_mbox_attach(ar);
 75		break;
 76	case ATH6KL_HTC_TYPE_PIPE:
 77		ath6kl_htc_pipe_attach(ar);
 78		break;
 79	default:
 80		WARN_ON(1);
 81		return -ENOMEM;
 82	}
 83
 84	ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
 85	if (!ar->ath6kl_wq)
 86		return -ENOMEM;
 87
 88	ret = ath6kl_bmi_init(ar);
 89	if (ret)
 90		goto err_wq;
 91
 92	/*
 93	 * Turn on power to get hardware (target) version and leave power
 94	 * on delibrately as we will boot the hardware anyway within few
 95	 * seconds.
 96	 */
 97	ret = ath6kl_hif_power_on(ar);
 98	if (ret)
 99		goto err_bmi_cleanup;
100
101	ret = ath6kl_bmi_get_target_info(ar, &targ_info);
102	if (ret)
103		goto err_power_off;
104
105	ar->version.target_ver = le32_to_cpu(targ_info.version);
106	ar->target_type = le32_to_cpu(targ_info.type);
107	ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
108
109	ret = ath6kl_init_hw_params(ar);
110	if (ret)
111		goto err_power_off;
112
113	ar->htc_target = ath6kl_htc_create(ar);
114
115	if (!ar->htc_target) {
116		ret = -ENOMEM;
117		goto err_power_off;
118	}
119
120	ar->testmode = testmode;
121
122	ret = ath6kl_init_fetch_firmwares(ar);
123	if (ret)
124		goto err_htc_cleanup;
125
126	/* FIXME: we should free all firmwares in the error cases below */
127
128	/*
129	 * Backwards compatibility support for older ar6004 firmware images
130	 * which do not set these feature flags.
131	 */
132	if (ar->target_type == TARGET_TYPE_AR6004 &&
133	    ar->fw_api <= 4) {
134		__set_bit(ATH6KL_FW_CAPABILITY_64BIT_RATES,
135			  ar->fw_capabilities);
136		__set_bit(ATH6KL_FW_CAPABILITY_AP_INACTIVITY_MINS,
137			  ar->fw_capabilities);
138
139		if (ar->hw.id == AR6004_HW_1_3_VERSION)
140			__set_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT,
141				  ar->fw_capabilities);
142	}
143
144	/* Indicate that WMI is enabled (although not ready yet) */
145	set_bit(WMI_ENABLED, &ar->flag);
146	ar->wmi = ath6kl_wmi_init(ar);
147	if (!ar->wmi) {
148		ath6kl_err("failed to initialize wmi\n");
149		ret = -EIO;
150		goto err_htc_cleanup;
151	}
152
153	ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
154
155	/* setup access class priority mappings */
156	ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest  */
157	ar->ac_stream_pri_map[WMM_AC_BE] = 1;
158	ar->ac_stream_pri_map[WMM_AC_VI] = 2;
159	ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
160
161	/* allocate some buffers that handle larger AMSDU frames */
162	ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
163
164	ath6kl_cookie_init(ar);
165
166	ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
167			 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
168
169	if (suspend_mode &&
170	    suspend_mode >= WLAN_POWER_STATE_CUT_PWR &&
171	    suspend_mode <= WLAN_POWER_STATE_WOW)
172		ar->suspend_mode = suspend_mode;
173	else
174		ar->suspend_mode = 0;
175
176	if (suspend_mode == WLAN_POWER_STATE_WOW &&
177	    (wow_mode == WLAN_POWER_STATE_CUT_PWR ||
178	     wow_mode == WLAN_POWER_STATE_DEEP_SLEEP))
179		ar->wow_suspend_mode = wow_mode;
180	else
181		ar->wow_suspend_mode = 0;
182
183	if (uart_debug)
184		ar->conf_flags |= ATH6KL_CONF_UART_DEBUG;
185	ar->hw.uarttx_rate = uart_rate;
186
187	set_bit(FIRST_BOOT, &ar->flag);
188
189	ath6kl_debug_init(ar);
190
191	ret = ath6kl_init_hw_start(ar);
192	if (ret) {
193		ath6kl_err("Failed to start hardware: %d\n", ret);
194		goto err_rxbuf_cleanup;
195	}
196
197	/* give our connected endpoints some buffers */
198	ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
199	ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
200
201	ret = ath6kl_cfg80211_init(ar);
202	if (ret)
203		goto err_rxbuf_cleanup;
204
205	ret = ath6kl_debug_init_fs(ar);
206	if (ret) {
207		wiphy_unregister(ar->wiphy);
208		goto err_rxbuf_cleanup;
209	}
210
211	for (i = 0; i < ar->vif_max; i++)
212		ar->avail_idx_map |= BIT(i);
213
214	rtnl_lock();
215	wiphy_lock(ar->wiphy);
216
217	/* Add an initial station interface */
218	wdev = ath6kl_interface_add(ar, "wlan%d", NET_NAME_ENUM,
219				    NL80211_IFTYPE_STATION, 0, INFRA_NETWORK);
220
221	wiphy_unlock(ar->wiphy);
222	rtnl_unlock();
223
224	if (!wdev) {
225		ath6kl_err("Failed to instantiate a network device\n");
226		ret = -ENOMEM;
227		wiphy_unregister(ar->wiphy);
228		goto err_rxbuf_cleanup;
229	}
230
231	ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
232		   __func__, wdev->netdev->name, wdev->netdev, ar);
233
234	ar->fw_recovery.enable = !!recovery_enable;
235	if (!ar->fw_recovery.enable)
236		return ret;
237
238	if (heart_beat_poll &&
239	    test_bit(ATH6KL_FW_CAPABILITY_HEART_BEAT_POLL,
240		     ar->fw_capabilities))
241		ar->fw_recovery.hb_poll = heart_beat_poll;
242
243	ath6kl_recovery_init(ar);
244
245	return ret;
246
247err_rxbuf_cleanup:
248	ath6kl_debug_cleanup(ar);
249	ath6kl_htc_flush_rx_buf(ar->htc_target);
250	ath6kl_cleanup_amsdu_rxbufs(ar);
251	ath6kl_wmi_shutdown(ar->wmi);
252	clear_bit(WMI_ENABLED, &ar->flag);
253	ar->wmi = NULL;
254err_htc_cleanup:
255	ath6kl_htc_cleanup(ar->htc_target);
256err_power_off:
257	ath6kl_hif_power_off(ar);
258err_bmi_cleanup:
259	ath6kl_bmi_cleanup(ar);
260err_wq:
261	destroy_workqueue(ar->ath6kl_wq);
262
263	return ret;
264}
265EXPORT_SYMBOL(ath6kl_core_init);
266
267struct ath6kl *ath6kl_core_create(struct device *dev)
268{
269	struct ath6kl *ar;
270	u8 ctr;
271
272	ar = ath6kl_cfg80211_create();
273	if (!ar)
274		return NULL;
275
276	ar->p2p = !!ath6kl_p2p;
277	ar->dev = dev;
278
279	ar->vif_max = 1;
280
281	ar->max_norm_iface = 1;
282
283	spin_lock_init(&ar->lock);
284	spin_lock_init(&ar->mcastpsq_lock);
285	spin_lock_init(&ar->list_lock);
286
287	init_waitqueue_head(&ar->event_wq);
288	sema_init(&ar->sem, 1);
289
290	INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
291	INIT_LIST_HEAD(&ar->vif_list);
292
293	clear_bit(WMI_ENABLED, &ar->flag);
294	clear_bit(SKIP_SCAN, &ar->flag);
295	clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
296
297	ar->tx_pwr = 0;
298	ar->intra_bss = 1;
299	ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD;
300
301	ar->state = ATH6KL_STATE_OFF;
302
303	memset((u8 *)ar->sta_list, 0,
304	       AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
305
306	/* Init the PS queues */
307	for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
308		spin_lock_init(&ar->sta_list[ctr].psq_lock);
309		skb_queue_head_init(&ar->sta_list[ctr].psq);
310		skb_queue_head_init(&ar->sta_list[ctr].apsdq);
311		ar->sta_list[ctr].mgmt_psq_len = 0;
312		INIT_LIST_HEAD(&ar->sta_list[ctr].mgmt_psq);
313		ar->sta_list[ctr].aggr_conn =
314			kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL);
315		if (!ar->sta_list[ctr].aggr_conn) {
316			ath6kl_err("Failed to allocate memory for sta aggregation information\n");
317			ath6kl_core_destroy(ar);
318			return NULL;
319		}
320	}
321
322	skb_queue_head_init(&ar->mcastpsq);
323
324	memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
325
326	return ar;
327}
328EXPORT_SYMBOL(ath6kl_core_create);
329
330void ath6kl_core_cleanup(struct ath6kl *ar)
331{
332	ath6kl_hif_power_off(ar);
333
334	ath6kl_recovery_cleanup(ar);
335
336	destroy_workqueue(ar->ath6kl_wq);
337
338	if (ar->htc_target)
339		ath6kl_htc_cleanup(ar->htc_target);
340
341	ath6kl_cookie_cleanup(ar);
342
343	ath6kl_cleanup_amsdu_rxbufs(ar);
344
345	ath6kl_bmi_cleanup(ar);
346
347	ath6kl_debug_cleanup(ar);
348
349	kfree(ar->fw_board);
350	kfree(ar->fw_otp);
351	vfree(ar->fw);
352	kfree(ar->fw_patch);
353	kfree(ar->fw_testscript);
354
355	ath6kl_cfg80211_cleanup(ar);
356}
357EXPORT_SYMBOL(ath6kl_core_cleanup);
358
359void ath6kl_core_destroy(struct ath6kl *ar)
360{
361	ath6kl_cfg80211_destroy(ar);
362}
363EXPORT_SYMBOL(ath6kl_core_destroy);
364
365MODULE_AUTHOR("Qualcomm Atheros");
366MODULE_DESCRIPTION("Core module for AR600x SDIO and USB devices.");
367MODULE_LICENSE("Dual BSD/GPL");
v4.6
  1/*
  2 * Copyright (c) 2004-2011 Atheros Communications Inc.
  3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4 *
  5 * Permission to use, copy, modify, and/or distribute this software for any
  6 * purpose with or without fee is hereby granted, provided that the above
  7 * copyright notice and this permission notice appear in all copies.
  8 *
  9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 16 */
 17
 18#include "core.h"
 19
 20#include <linux/module.h>
 21#include <linux/moduleparam.h>
 22#include <linux/export.h>
 23#include <linux/vmalloc.h>
 24
 25#include "debug.h"
 26#include "hif-ops.h"
 27#include "htc-ops.h"
 28#include "cfg80211.h"
 29
 30unsigned int debug_mask;
 31static unsigned int suspend_mode;
 32static unsigned int wow_mode;
 33static unsigned int uart_debug;
 
 34static unsigned int ath6kl_p2p;
 35static unsigned int testmode;
 36static unsigned int recovery_enable;
 37static unsigned int heart_beat_poll;
 38
 39module_param(debug_mask, uint, 0644);
 40module_param(suspend_mode, uint, 0644);
 41module_param(wow_mode, uint, 0644);
 42module_param(uart_debug, uint, 0644);
 
 43module_param(ath6kl_p2p, uint, 0644);
 44module_param(testmode, uint, 0644);
 45module_param(recovery_enable, uint, 0644);
 46module_param(heart_beat_poll, uint, 0644);
 47MODULE_PARM_DESC(recovery_enable, "Enable recovery from firmware error");
 48MODULE_PARM_DESC(heart_beat_poll,
 49		 "Enable fw error detection periodic polling in msecs - Also set recovery_enable for this to be effective");
 50
 51
 52void ath6kl_core_tx_complete(struct ath6kl *ar, struct sk_buff *skb)
 53{
 54	ath6kl_htc_tx_complete(ar, skb);
 55}
 56EXPORT_SYMBOL(ath6kl_core_tx_complete);
 57
 58void ath6kl_core_rx_complete(struct ath6kl *ar, struct sk_buff *skb, u8 pipe)
 59{
 60	ath6kl_htc_rx_complete(ar, skb, pipe);
 61}
 62EXPORT_SYMBOL(ath6kl_core_rx_complete);
 63
 64int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type)
 65{
 66	struct ath6kl_bmi_target_info targ_info;
 67	struct wireless_dev *wdev;
 68	int ret = 0, i;
 69
 70	switch (htc_type) {
 71	case ATH6KL_HTC_TYPE_MBOX:
 72		ath6kl_htc_mbox_attach(ar);
 73		break;
 74	case ATH6KL_HTC_TYPE_PIPE:
 75		ath6kl_htc_pipe_attach(ar);
 76		break;
 77	default:
 78		WARN_ON(1);
 79		return -ENOMEM;
 80	}
 81
 82	ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
 83	if (!ar->ath6kl_wq)
 84		return -ENOMEM;
 85
 86	ret = ath6kl_bmi_init(ar);
 87	if (ret)
 88		goto err_wq;
 89
 90	/*
 91	 * Turn on power to get hardware (target) version and leave power
 92	 * on delibrately as we will boot the hardware anyway within few
 93	 * seconds.
 94	 */
 95	ret = ath6kl_hif_power_on(ar);
 96	if (ret)
 97		goto err_bmi_cleanup;
 98
 99	ret = ath6kl_bmi_get_target_info(ar, &targ_info);
100	if (ret)
101		goto err_power_off;
102
103	ar->version.target_ver = le32_to_cpu(targ_info.version);
104	ar->target_type = le32_to_cpu(targ_info.type);
105	ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
106
107	ret = ath6kl_init_hw_params(ar);
108	if (ret)
109		goto err_power_off;
110
111	ar->htc_target = ath6kl_htc_create(ar);
112
113	if (!ar->htc_target) {
114		ret = -ENOMEM;
115		goto err_power_off;
116	}
117
118	ar->testmode = testmode;
119
120	ret = ath6kl_init_fetch_firmwares(ar);
121	if (ret)
122		goto err_htc_cleanup;
123
124	/* FIXME: we should free all firmwares in the error cases below */
125
126	/*
127	 * Backwards compatibility support for older ar6004 firmware images
128	 * which do not set these feature flags.
129	 */
130	if (ar->target_type == TARGET_TYPE_AR6004 &&
131	    ar->fw_api <= 4) {
132		__set_bit(ATH6KL_FW_CAPABILITY_64BIT_RATES,
133			  ar->fw_capabilities);
134		__set_bit(ATH6KL_FW_CAPABILITY_AP_INACTIVITY_MINS,
135			  ar->fw_capabilities);
136
137		if (ar->hw.id == AR6004_HW_1_3_VERSION)
138			__set_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT,
139				  ar->fw_capabilities);
140	}
141
142	/* Indicate that WMI is enabled (although not ready yet) */
143	set_bit(WMI_ENABLED, &ar->flag);
144	ar->wmi = ath6kl_wmi_init(ar);
145	if (!ar->wmi) {
146		ath6kl_err("failed to initialize wmi\n");
147		ret = -EIO;
148		goto err_htc_cleanup;
149	}
150
151	ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
152
153	/* setup access class priority mappings */
154	ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest  */
155	ar->ac_stream_pri_map[WMM_AC_BE] = 1;
156	ar->ac_stream_pri_map[WMM_AC_VI] = 2;
157	ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
158
159	/* allocate some buffers that handle larger AMSDU frames */
160	ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
161
162	ath6kl_cookie_init(ar);
163
164	ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
165			 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
166
167	if (suspend_mode &&
168	    suspend_mode >= WLAN_POWER_STATE_CUT_PWR &&
169	    suspend_mode <= WLAN_POWER_STATE_WOW)
170		ar->suspend_mode = suspend_mode;
171	else
172		ar->suspend_mode = 0;
173
174	if (suspend_mode == WLAN_POWER_STATE_WOW &&
175	    (wow_mode == WLAN_POWER_STATE_CUT_PWR ||
176	     wow_mode == WLAN_POWER_STATE_DEEP_SLEEP))
177		ar->wow_suspend_mode = wow_mode;
178	else
179		ar->wow_suspend_mode = 0;
180
181	if (uart_debug)
182		ar->conf_flags |= ATH6KL_CONF_UART_DEBUG;
 
183
184	set_bit(FIRST_BOOT, &ar->flag);
185
186	ath6kl_debug_init(ar);
187
188	ret = ath6kl_init_hw_start(ar);
189	if (ret) {
190		ath6kl_err("Failed to start hardware: %d\n", ret);
191		goto err_rxbuf_cleanup;
192	}
193
194	/* give our connected endpoints some buffers */
195	ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
196	ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
197
198	ret = ath6kl_cfg80211_init(ar);
199	if (ret)
200		goto err_rxbuf_cleanup;
201
202	ret = ath6kl_debug_init_fs(ar);
203	if (ret) {
204		wiphy_unregister(ar->wiphy);
205		goto err_rxbuf_cleanup;
206	}
207
208	for (i = 0; i < ar->vif_max; i++)
209		ar->avail_idx_map |= BIT(i);
210
211	rtnl_lock();
 
212
213	/* Add an initial station interface */
214	wdev = ath6kl_interface_add(ar, "wlan%d", NET_NAME_ENUM,
215				    NL80211_IFTYPE_STATION, 0, INFRA_NETWORK);
216
 
217	rtnl_unlock();
218
219	if (!wdev) {
220		ath6kl_err("Failed to instantiate a network device\n");
221		ret = -ENOMEM;
222		wiphy_unregister(ar->wiphy);
223		goto err_rxbuf_cleanup;
224	}
225
226	ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
227		   __func__, wdev->netdev->name, wdev->netdev, ar);
228
229	ar->fw_recovery.enable = !!recovery_enable;
230	if (!ar->fw_recovery.enable)
231		return ret;
232
233	if (heart_beat_poll &&
234	    test_bit(ATH6KL_FW_CAPABILITY_HEART_BEAT_POLL,
235		     ar->fw_capabilities))
236		ar->fw_recovery.hb_poll = heart_beat_poll;
237
238	ath6kl_recovery_init(ar);
239
240	return ret;
241
242err_rxbuf_cleanup:
243	ath6kl_debug_cleanup(ar);
244	ath6kl_htc_flush_rx_buf(ar->htc_target);
245	ath6kl_cleanup_amsdu_rxbufs(ar);
246	ath6kl_wmi_shutdown(ar->wmi);
247	clear_bit(WMI_ENABLED, &ar->flag);
248	ar->wmi = NULL;
249err_htc_cleanup:
250	ath6kl_htc_cleanup(ar->htc_target);
251err_power_off:
252	ath6kl_hif_power_off(ar);
253err_bmi_cleanup:
254	ath6kl_bmi_cleanup(ar);
255err_wq:
256	destroy_workqueue(ar->ath6kl_wq);
257
258	return ret;
259}
260EXPORT_SYMBOL(ath6kl_core_init);
261
262struct ath6kl *ath6kl_core_create(struct device *dev)
263{
264	struct ath6kl *ar;
265	u8 ctr;
266
267	ar = ath6kl_cfg80211_create();
268	if (!ar)
269		return NULL;
270
271	ar->p2p = !!ath6kl_p2p;
272	ar->dev = dev;
273
274	ar->vif_max = 1;
275
276	ar->max_norm_iface = 1;
277
278	spin_lock_init(&ar->lock);
279	spin_lock_init(&ar->mcastpsq_lock);
280	spin_lock_init(&ar->list_lock);
281
282	init_waitqueue_head(&ar->event_wq);
283	sema_init(&ar->sem, 1);
284
285	INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
286	INIT_LIST_HEAD(&ar->vif_list);
287
288	clear_bit(WMI_ENABLED, &ar->flag);
289	clear_bit(SKIP_SCAN, &ar->flag);
290	clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
291
292	ar->tx_pwr = 0;
293	ar->intra_bss = 1;
294	ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD;
295
296	ar->state = ATH6KL_STATE_OFF;
297
298	memset((u8 *)ar->sta_list, 0,
299	       AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
300
301	/* Init the PS queues */
302	for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
303		spin_lock_init(&ar->sta_list[ctr].psq_lock);
304		skb_queue_head_init(&ar->sta_list[ctr].psq);
305		skb_queue_head_init(&ar->sta_list[ctr].apsdq);
306		ar->sta_list[ctr].mgmt_psq_len = 0;
307		INIT_LIST_HEAD(&ar->sta_list[ctr].mgmt_psq);
308		ar->sta_list[ctr].aggr_conn =
309			kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL);
310		if (!ar->sta_list[ctr].aggr_conn) {
311			ath6kl_err("Failed to allocate memory for sta aggregation information\n");
312			ath6kl_core_destroy(ar);
313			return NULL;
314		}
315	}
316
317	skb_queue_head_init(&ar->mcastpsq);
318
319	memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
320
321	return ar;
322}
323EXPORT_SYMBOL(ath6kl_core_create);
324
325void ath6kl_core_cleanup(struct ath6kl *ar)
326{
327	ath6kl_hif_power_off(ar);
328
329	ath6kl_recovery_cleanup(ar);
330
331	destroy_workqueue(ar->ath6kl_wq);
332
333	if (ar->htc_target)
334		ath6kl_htc_cleanup(ar->htc_target);
335
336	ath6kl_cookie_cleanup(ar);
337
338	ath6kl_cleanup_amsdu_rxbufs(ar);
339
340	ath6kl_bmi_cleanup(ar);
341
342	ath6kl_debug_cleanup(ar);
343
344	kfree(ar->fw_board);
345	kfree(ar->fw_otp);
346	vfree(ar->fw);
347	kfree(ar->fw_patch);
348	kfree(ar->fw_testscript);
349
350	ath6kl_cfg80211_cleanup(ar);
351}
352EXPORT_SYMBOL(ath6kl_core_cleanup);
353
354void ath6kl_core_destroy(struct ath6kl *ar)
355{
356	ath6kl_cfg80211_destroy(ar);
357}
358EXPORT_SYMBOL(ath6kl_core_destroy);
359
360MODULE_AUTHOR("Qualcomm Atheros");
361MODULE_DESCRIPTION("Core module for AR600x SDIO and USB devices.");
362MODULE_LICENSE("Dual BSD/GPL");