2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
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.
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.
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/export.h>
28 unsigned int debug_mask
;
29 static unsigned int suspend_mode
;
30 static unsigned int wow_mode
;
31 static unsigned int uart_debug
;
32 static unsigned int ath6kl_p2p
;
33 static unsigned int testmode
;
35 module_param(debug_mask
, uint
, 0644);
36 module_param(suspend_mode
, uint
, 0644);
37 module_param(wow_mode
, uint
, 0644);
38 module_param(uart_debug
, uint
, 0644);
39 module_param(ath6kl_p2p
, uint
, 0644);
40 module_param(testmode
, uint
, 0644);
42 int ath6kl_core_init(struct ath6kl
*ar
)
44 struct ath6kl_bmi_target_info targ_info
;
45 struct net_device
*ndev
;
48 ar
->ath6kl_wq
= create_singlethread_workqueue("ath6kl");
52 ret
= ath6kl_bmi_init(ar
);
57 * Turn on power to get hardware (target) version and leave power
58 * on delibrately as we will boot the hardware anyway within few
61 ret
= ath6kl_hif_power_on(ar
);
65 ret
= ath6kl_bmi_get_target_info(ar
, &targ_info
);
69 ar
->version
.target_ver
= le32_to_cpu(targ_info
.version
);
70 ar
->target_type
= le32_to_cpu(targ_info
.type
);
71 ar
->wiphy
->hw_version
= le32_to_cpu(targ_info
.version
);
73 ret
= ath6kl_init_hw_params(ar
);
77 ar
->htc_target
= ath6kl_htc_create(ar
);
79 if (!ar
->htc_target
) {
84 ar
->testmode
= testmode
;
86 ret
= ath6kl_init_fetch_firmwares(ar
);
90 /* FIXME: we should free all firmwares in the error cases below */
92 /* Indicate that WMI is enabled (although not ready yet) */
93 set_bit(WMI_ENABLED
, &ar
->flag
);
94 ar
->wmi
= ath6kl_wmi_init(ar
);
96 ath6kl_err("failed to initialize wmi\n");
101 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: got wmi @ 0x%p.\n", __func__
, ar
->wmi
);
103 /* setup access class priority mappings */
104 ar
->ac_stream_pri_map
[WMM_AC_BK
] = 0; /* lowest */
105 ar
->ac_stream_pri_map
[WMM_AC_BE
] = 1;
106 ar
->ac_stream_pri_map
[WMM_AC_VI
] = 2;
107 ar
->ac_stream_pri_map
[WMM_AC_VO
] = 3; /* highest */
109 /* allocate some buffers that handle larger AMSDU frames */
110 ath6kl_refill_amsdu_rxbufs(ar
, ATH6KL_MAX_AMSDU_RX_BUFFERS
);
112 ath6kl_cookie_init(ar
);
114 ar
->conf_flags
= ATH6KL_CONF_IGNORE_ERP_BARKER
|
115 ATH6KL_CONF_ENABLE_11N
| ATH6KL_CONF_ENABLE_TX_BURST
;
118 suspend_mode
>= WLAN_POWER_STATE_CUT_PWR
&&
119 suspend_mode
<= WLAN_POWER_STATE_WOW
)
120 ar
->suspend_mode
= suspend_mode
;
122 ar
->suspend_mode
= 0;
124 if (suspend_mode
== WLAN_POWER_STATE_WOW
&&
125 (wow_mode
== WLAN_POWER_STATE_CUT_PWR
||
126 wow_mode
== WLAN_POWER_STATE_DEEP_SLEEP
))
127 ar
->wow_suspend_mode
= wow_mode
;
129 ar
->wow_suspend_mode
= 0;
132 ar
->conf_flags
|= ATH6KL_CONF_UART_DEBUG
;
134 set_bit(FIRST_BOOT
, &ar
->flag
);
136 ath6kl_debug_init(ar
);
138 ret
= ath6kl_init_hw_start(ar
);
140 ath6kl_err("Failed to start hardware: %d\n", ret
);
141 goto err_rxbuf_cleanup
;
144 /* give our connected endpoints some buffers */
145 ath6kl_rx_refill(ar
->htc_target
, ar
->ctrl_ep
);
146 ath6kl_rx_refill(ar
->htc_target
, ar
->ac2ep_map
[WMM_AC_BE
]);
148 ret
= ath6kl_cfg80211_init(ar
);
150 goto err_rxbuf_cleanup
;
152 ret
= ath6kl_debug_init_fs(ar
);
154 wiphy_unregister(ar
->wiphy
);
155 goto err_rxbuf_cleanup
;
158 for (i
= 0; i
< ar
->vif_max
; i
++)
159 ar
->avail_idx_map
|= BIT(i
);
163 /* Add an initial station interface */
164 ndev
= ath6kl_interface_add(ar
, "wlan%d", NL80211_IFTYPE_STATION
, 0,
170 ath6kl_err("Failed to instantiate a network device\n");
172 wiphy_unregister(ar
->wiphy
);
173 goto err_rxbuf_cleanup
;
176 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: name=%s dev=0x%p, ar=0x%p\n",
177 __func__
, ndev
->name
, ndev
, ar
);
182 ath6kl_debug_cleanup(ar
);
183 ath6kl_htc_flush_rx_buf(ar
->htc_target
);
184 ath6kl_cleanup_amsdu_rxbufs(ar
);
185 ath6kl_wmi_shutdown(ar
->wmi
);
186 clear_bit(WMI_ENABLED
, &ar
->flag
);
189 ath6kl_htc_cleanup(ar
->htc_target
);
191 ath6kl_hif_power_off(ar
);
193 ath6kl_bmi_cleanup(ar
);
195 destroy_workqueue(ar
->ath6kl_wq
);
199 EXPORT_SYMBOL(ath6kl_core_init
);
201 struct ath6kl
*ath6kl_core_create(struct device
*dev
)
206 ar
= ath6kl_cfg80211_create();
210 ar
->p2p
= !!ath6kl_p2p
;
215 ar
->max_norm_iface
= 1;
217 spin_lock_init(&ar
->lock
);
218 spin_lock_init(&ar
->mcastpsq_lock
);
219 spin_lock_init(&ar
->list_lock
);
221 init_waitqueue_head(&ar
->event_wq
);
222 sema_init(&ar
->sem
, 1);
224 INIT_LIST_HEAD(&ar
->amsdu_rx_buffer_queue
);
225 INIT_LIST_HEAD(&ar
->vif_list
);
227 clear_bit(WMI_ENABLED
, &ar
->flag
);
228 clear_bit(SKIP_SCAN
, &ar
->flag
);
229 clear_bit(DESTROY_IN_PROGRESS
, &ar
->flag
);
233 ar
->lrssi_roam_threshold
= DEF_LRSSI_ROAM_THRESHOLD
;
235 ar
->state
= ATH6KL_STATE_OFF
;
237 memset((u8
*)ar
->sta_list
, 0,
238 AP_MAX_NUM_STA
* sizeof(struct ath6kl_sta
));
240 /* Init the PS queues */
241 for (ctr
= 0; ctr
< AP_MAX_NUM_STA
; ctr
++) {
242 spin_lock_init(&ar
->sta_list
[ctr
].psq_lock
);
243 skb_queue_head_init(&ar
->sta_list
[ctr
].psq
);
244 skb_queue_head_init(&ar
->sta_list
[ctr
].apsdq
);
245 ar
->sta_list
[ctr
].mgmt_psq_len
= 0;
246 INIT_LIST_HEAD(&ar
->sta_list
[ctr
].mgmt_psq
);
247 ar
->sta_list
[ctr
].aggr_conn
=
248 kzalloc(sizeof(struct aggr_info_conn
), GFP_KERNEL
);
249 if (!ar
->sta_list
[ctr
].aggr_conn
) {
250 ath6kl_err("Failed to allocate memory for sta aggregation information\n");
251 ath6kl_core_destroy(ar
);
256 skb_queue_head_init(&ar
->mcastpsq
);
258 memcpy(ar
->ap_country_code
, DEF_AP_COUNTRY_CODE
, 3);
262 EXPORT_SYMBOL(ath6kl_core_create
);
264 void ath6kl_core_cleanup(struct ath6kl
*ar
)
266 ath6kl_hif_power_off(ar
);
268 destroy_workqueue(ar
->ath6kl_wq
);
271 ath6kl_htc_cleanup(ar
->htc_target
);
273 ath6kl_cookie_cleanup(ar
);
275 ath6kl_cleanup_amsdu_rxbufs(ar
);
277 ath6kl_bmi_cleanup(ar
);
279 ath6kl_debug_cleanup(ar
);
285 kfree(ar
->fw_testscript
);
287 ath6kl_cfg80211_cleanup(ar
);
289 EXPORT_SYMBOL(ath6kl_core_cleanup
);
291 void ath6kl_core_destroy(struct ath6kl
*ar
)
293 ath6kl_cfg80211_destroy(ar
);
295 EXPORT_SYMBOL(ath6kl_core_destroy
);
297 MODULE_AUTHOR("Qualcomm Atheros");
298 MODULE_DESCRIPTION("Core module for AR600x SDIO and USB devices.");
299 MODULE_LICENSE("Dual BSD/GPL");