]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/net/wireless/ath/ath6kl/core.c
ath6kl: Add unicast mgmt frame buffering
[mirror_ubuntu-zesty-kernel.git] / drivers / net / wireless / ath / ath6kl / core.c
CommitLineData
45eaa78f
KV
1/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
1b2df407 3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
45eaa78f
KV
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
d6a434d6 20#include <linux/module.h>
45eaa78f 21#include <linux/moduleparam.h>
d6a434d6 22#include <linux/export.h>
45eaa78f
KV
23
24#include "debug.h"
25#include "hif-ops.h"
26#include "cfg80211.h"
27
28unsigned int debug_mask;
e390af77 29static unsigned int suspend_mode;
45eaa78f
KV
30static unsigned int uart_debug;
31static unsigned int ath6kl_p2p;
5f1127ff 32static unsigned int testmode;
45eaa78f
KV
33
34module_param(debug_mask, uint, 0644);
e390af77 35module_param(suspend_mode, uint, 0644);
45eaa78f
KV
36module_param(uart_debug, uint, 0644);
37module_param(ath6kl_p2p, uint, 0644);
5f1127ff 38module_param(testmode, uint, 0644);
45eaa78f
KV
39
40int ath6kl_core_init(struct ath6kl *ar)
41{
42 struct ath6kl_bmi_target_info targ_info;
43 struct net_device *ndev;
44 int ret = 0, i;
45
46 ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
47 if (!ar->ath6kl_wq)
48 return -ENOMEM;
49
50 ret = ath6kl_bmi_init(ar);
51 if (ret)
52 goto err_wq;
53
54 /*
55 * Turn on power to get hardware (target) version and leave power
56 * on delibrately as we will boot the hardware anyway within few
57 * seconds.
58 */
59 ret = ath6kl_hif_power_on(ar);
60 if (ret)
61 goto err_bmi_cleanup;
62
63 ret = ath6kl_bmi_get_target_info(ar, &targ_info);
64 if (ret)
65 goto err_power_off;
66
67 ar->version.target_ver = le32_to_cpu(targ_info.version);
68 ar->target_type = le32_to_cpu(targ_info.type);
69 ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
70
71 ret = ath6kl_init_hw_params(ar);
72 if (ret)
73 goto err_power_off;
74
75 ar->htc_target = ath6kl_htc_create(ar);
76
77 if (!ar->htc_target) {
78 ret = -ENOMEM;
79 goto err_power_off;
80 }
81
5f1127ff
KV
82 ar->testmode = testmode;
83
45eaa78f
KV
84 ret = ath6kl_init_fetch_firmwares(ar);
85 if (ret)
86 goto err_htc_cleanup;
87
88 /* FIXME: we should free all firmwares in the error cases below */
89
90 /* Indicate that WMI is enabled (although not ready yet) */
91 set_bit(WMI_ENABLED, &ar->flag);
92 ar->wmi = ath6kl_wmi_init(ar);
93 if (!ar->wmi) {
94 ath6kl_err("failed to initialize wmi\n");
95 ret = -EIO;
96 goto err_htc_cleanup;
97 }
98
99 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
100
101 ret = ath6kl_cfg80211_init(ar);
102 if (ret)
103 goto err_node_cleanup;
104
105 ret = ath6kl_debug_init(ar);
106 if (ret) {
107 wiphy_unregister(ar->wiphy);
108 goto err_node_cleanup;
109 }
110
111 for (i = 0; i < ar->vif_max; i++)
112 ar->avail_idx_map |= BIT(i);
113
114 rtnl_lock();
115
116 /* Add an initial station interface */
117 ndev = ath6kl_interface_add(ar, "wlan%d", NL80211_IFTYPE_STATION, 0,
118 INFRA_NETWORK);
119
120 rtnl_unlock();
121
122 if (!ndev) {
123 ath6kl_err("Failed to instantiate a network device\n");
124 ret = -ENOMEM;
125 wiphy_unregister(ar->wiphy);
126 goto err_debug_init;
127 }
128
129
130 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
131 __func__, ndev->name, ndev, ar);
132
133 /* setup access class priority mappings */
134 ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
135 ar->ac_stream_pri_map[WMM_AC_BE] = 1;
136 ar->ac_stream_pri_map[WMM_AC_VI] = 2;
137 ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
138
139 /* give our connected endpoints some buffers */
140 ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
141 ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
142
143 /* allocate some buffers that handle larger AMSDU frames */
144 ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
145
146 ath6kl_cookie_init(ar);
147
148 ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
149 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
150
e390af77
RM
151 if (suspend_mode &&
152 suspend_mode >= WLAN_POWER_STATE_CUT_PWR &&
153 suspend_mode <= WLAN_POWER_STATE_WOW)
154 ar->suspend_mode = suspend_mode;
155 else
156 ar->suspend_mode = 0;
45eaa78f
KV
157
158 if (uart_debug)
159 ar->conf_flags |= ATH6KL_CONF_UART_DEBUG;
160
161 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
162 WIPHY_FLAG_HAVE_AP_SME |
163 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
164 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
165
166 if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN, ar->fw_capabilities))
167 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
168
169 ar->wiphy->probe_resp_offload =
170 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
171 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
172 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P |
173 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U;
174
175 set_bit(FIRST_BOOT, &ar->flag);
176
177 ndev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
178
179 ret = ath6kl_init_hw_start(ar);
180 if (ret) {
181 ath6kl_err("Failed to start hardware: %d\n", ret);
182 goto err_rxbuf_cleanup;
183 }
184
185 /*
186 * Set mac address which is received in ready event
187 * FIXME: Move to ath6kl_interface_add()
188 */
189 memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
190
191 return ret;
192
193err_rxbuf_cleanup:
194 ath6kl_htc_flush_rx_buf(ar->htc_target);
195 ath6kl_cleanup_amsdu_rxbufs(ar);
196 rtnl_lock();
197 ath6kl_cfg80211_vif_cleanup(netdev_priv(ndev));
198 rtnl_unlock();
199 wiphy_unregister(ar->wiphy);
200err_debug_init:
201 ath6kl_debug_cleanup(ar);
202err_node_cleanup:
203 ath6kl_wmi_shutdown(ar->wmi);
204 clear_bit(WMI_ENABLED, &ar->flag);
205 ar->wmi = NULL;
206err_htc_cleanup:
207 ath6kl_htc_cleanup(ar->htc_target);
208err_power_off:
209 ath6kl_hif_power_off(ar);
210err_bmi_cleanup:
211 ath6kl_bmi_cleanup(ar);
212err_wq:
213 destroy_workqueue(ar->ath6kl_wq);
214
215 return ret;
216}
d6a434d6 217EXPORT_SYMBOL(ath6kl_core_init);
45eaa78f
KV
218
219struct ath6kl *ath6kl_core_create(struct device *dev)
220{
221 struct ath6kl *ar;
222 u8 ctr;
223
224 ar = ath6kl_cfg80211_create();
225 if (!ar)
226 return NULL;
227
228 ar->p2p = !!ath6kl_p2p;
229 ar->dev = dev;
230
231 ar->vif_max = 1;
232
233 ar->max_norm_iface = 1;
234
235 spin_lock_init(&ar->lock);
236 spin_lock_init(&ar->mcastpsq_lock);
237 spin_lock_init(&ar->list_lock);
238
239 init_waitqueue_head(&ar->event_wq);
240 sema_init(&ar->sem, 1);
241
242 INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
243 INIT_LIST_HEAD(&ar->vif_list);
244
245 clear_bit(WMI_ENABLED, &ar->flag);
246 clear_bit(SKIP_SCAN, &ar->flag);
247 clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
248
249 ar->listen_intvl_b = A_DEFAULT_LISTEN_INTERVAL;
250 ar->tx_pwr = 0;
251
252 ar->intra_bss = 1;
253 ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD;
254
255 ar->state = ATH6KL_STATE_OFF;
256
257 memset((u8 *)ar->sta_list, 0,
258 AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
259
260 /* Init the PS queues */
261 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
262 spin_lock_init(&ar->sta_list[ctr].psq_lock);
263 skb_queue_head_init(&ar->sta_list[ctr].psq);
264 skb_queue_head_init(&ar->sta_list[ctr].apsdq);
d0ff7383
NG
265 ar->sta_list[ctr].mgmt_psq_len = 0;
266 INIT_LIST_HEAD(&ar->sta_list[ctr].mgmt_psq);
1d2a4456
VT
267 ar->sta_list[ctr].aggr_conn =
268 kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL);
269 if (!ar->sta_list[ctr].aggr_conn) {
270 ath6kl_err("Failed to allocate memory for sta aggregation information\n");
271 ath6kl_core_destroy(ar);
272 return NULL;
273 }
45eaa78f
KV
274 }
275
276 skb_queue_head_init(&ar->mcastpsq);
277
278 memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
279
280 return ar;
281}
d6a434d6 282EXPORT_SYMBOL(ath6kl_core_create);
45eaa78f
KV
283
284void ath6kl_core_cleanup(struct ath6kl *ar)
285{
286 ath6kl_hif_power_off(ar);
287
288 destroy_workqueue(ar->ath6kl_wq);
289
290 if (ar->htc_target)
291 ath6kl_htc_cleanup(ar->htc_target);
292
293 ath6kl_cookie_cleanup(ar);
294
295 ath6kl_cleanup_amsdu_rxbufs(ar);
296
297 ath6kl_bmi_cleanup(ar);
298
299 ath6kl_debug_cleanup(ar);
300
301 kfree(ar->fw_board);
302 kfree(ar->fw_otp);
303 kfree(ar->fw);
304 kfree(ar->fw_patch);
305 kfree(ar->fw_testscript);
306
307 ath6kl_cfg80211_cleanup(ar);
308}
d6a434d6 309EXPORT_SYMBOL(ath6kl_core_cleanup);
45eaa78f
KV
310
311void ath6kl_core_destroy(struct ath6kl *ar)
312{
313 ath6kl_cfg80211_destroy(ar);
314}
d6a434d6 315EXPORT_SYMBOL(ath6kl_core_destroy);
45eaa78f 316
d6a434d6
KV
317MODULE_AUTHOR("Qualcomm Atheros");
318MODULE_DESCRIPTION("Core module for AR600x SDIO and USB devices.");
319MODULE_LICENSE("Dual BSD/GPL");