blob: a10002de824771d51622d645662c30a5f90baaa9 [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "core.h"
18#include "hif-ops.h"
19#include "cfg80211.h"
20#include "target.h"
21#include "debug.h"
22
23struct ath6kl_sta *ath6kl_find_sta(struct ath6kl *ar, u8 *node_addr)
24{
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +053025 /* TODO: Findout vif */
26 struct ath6kl_vif *vif = ar->vif;
Kalle Valobdcd8172011-07-18 00:22:30 +030027 struct ath6kl_sta *conn = NULL;
28 u8 i, max_conn;
29
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +053030 max_conn = (vif->nw_type == AP_NETWORK) ? AP_MAX_NUM_STA : 0;
Kalle Valobdcd8172011-07-18 00:22:30 +030031
32 for (i = 0; i < max_conn; i++) {
33 if (memcmp(node_addr, ar->sta_list[i].mac, ETH_ALEN) == 0) {
34 conn = &ar->sta_list[i];
35 break;
36 }
37 }
38
39 return conn;
40}
41
42struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid)
43{
44 struct ath6kl_sta *conn = NULL;
45 u8 ctr;
46
47 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
48 if (ar->sta_list[ctr].aid == aid) {
49 conn = &ar->sta_list[ctr];
50 break;
51 }
52 }
53 return conn;
54}
55
56static void ath6kl_add_new_sta(struct ath6kl *ar, u8 *mac, u16 aid, u8 *wpaie,
57 u8 ielen, u8 keymgmt, u8 ucipher, u8 auth)
58{
59 struct ath6kl_sta *sta;
60 u8 free_slot;
61
62 free_slot = aid - 1;
63
64 sta = &ar->sta_list[free_slot];
65 memcpy(sta->mac, mac, ETH_ALEN);
Jouni Malinen3c774bb2011-08-30 21:57:51 +030066 if (ielen <= ATH6KL_MAX_IE)
67 memcpy(sta->wpa_ie, wpaie, ielen);
Kalle Valobdcd8172011-07-18 00:22:30 +030068 sta->aid = aid;
69 sta->keymgmt = keymgmt;
70 sta->ucipher = ucipher;
71 sta->auth = auth;
72
73 ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
74 ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid);
75}
76
77static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i)
78{
79 struct ath6kl_sta *sta = &ar->sta_list[i];
80
81 /* empty the queued pkts in the PS queue if any */
82 spin_lock_bh(&sta->psq_lock);
83 skb_queue_purge(&sta->psq);
84 spin_unlock_bh(&sta->psq_lock);
85
86 memset(&ar->ap_stats.sta[sta->aid - 1], 0,
87 sizeof(struct wmi_per_sta_stat));
88 memset(sta->mac, 0, ETH_ALEN);
89 memset(sta->wpa_ie, 0, ATH6KL_MAX_IE);
90 sta->aid = 0;
91 sta->sta_flags = 0;
92
93 ar->sta_list_index = ar->sta_list_index & ~(1 << i);
94
95}
96
97static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason)
98{
99 u8 i, removed = 0;
100
101 if (is_zero_ether_addr(mac))
102 return removed;
103
104 if (is_broadcast_ether_addr(mac)) {
105 ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n");
106
107 for (i = 0; i < AP_MAX_NUM_STA; i++) {
108 if (!is_zero_ether_addr(ar->sta_list[i].mac)) {
109 ath6kl_sta_cleanup(ar, i);
110 removed = 1;
111 }
112 }
113 } else {
114 for (i = 0; i < AP_MAX_NUM_STA; i++) {
115 if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) {
116 ath6kl_dbg(ATH6KL_DBG_TRC,
117 "deleting station %pM aid=%d reason=%d\n",
118 mac, ar->sta_list[i].aid, reason);
119 ath6kl_sta_cleanup(ar, i);
120 removed = 1;
121 break;
122 }
123 }
124 }
125
126 return removed;
127}
128
129enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac)
130{
131 struct ath6kl *ar = devt;
132 return ar->ac2ep_map[ac];
133}
134
135struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar)
136{
137 struct ath6kl_cookie *cookie;
138
139 cookie = ar->cookie_list;
140 if (cookie != NULL) {
141 ar->cookie_list = cookie->arc_list_next;
142 ar->cookie_count--;
143 }
144
145 return cookie;
146}
147
148void ath6kl_cookie_init(struct ath6kl *ar)
149{
150 u32 i;
151
152 ar->cookie_list = NULL;
153 ar->cookie_count = 0;
154
155 memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem));
156
157 for (i = 0; i < MAX_COOKIE_NUM; i++)
158 ath6kl_free_cookie(ar, &ar->cookie_mem[i]);
159}
160
161void ath6kl_cookie_cleanup(struct ath6kl *ar)
162{
163 ar->cookie_list = NULL;
164 ar->cookie_count = 0;
165}
166
167void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie)
168{
169 /* Insert first */
170
171 if (!ar || !cookie)
172 return;
173
174 cookie->arc_list_next = ar->cookie_list;
175 ar->cookie_list = cookie;
176 ar->cookie_count++;
177}
178
179/* set the window address register (using 4-byte register access ). */
180static int ath6kl_set_addrwin_reg(struct ath6kl *ar, u32 reg_addr, u32 addr)
181{
182 int status;
Kalle Valobdcd8172011-07-18 00:22:30 +0300183 s32 i;
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530184 __le32 addr_val;
Kalle Valobdcd8172011-07-18 00:22:30 +0300185
186 /*
187 * Write bytes 1,2,3 of the register to set the upper address bytes,
188 * the LSB is written last to initiate the access cycle
189 */
190
191 for (i = 1; i <= 3; i++) {
192 /*
193 * Fill the buffer with the address byte value we want to
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530194 * hit 4 times. No need to worry about endianness as the
195 * same byte is copied to all four bytes of addr_val at
196 * any time.
Kalle Valobdcd8172011-07-18 00:22:30 +0300197 */
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530198 memset((u8 *)&addr_val, ((u8 *)&addr)[i], 4);
Kalle Valobdcd8172011-07-18 00:22:30 +0300199
200 /*
201 * Hit each byte of the register address with a 4-byte
202 * write operation to the same address, this is a harmless
203 * operation.
204 */
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530205 status = hif_read_write_sync(ar, reg_addr + i, (u8 *)&addr_val,
Kalle Valobdcd8172011-07-18 00:22:30 +0300206 4, HIF_WR_SYNC_BYTE_FIX);
207 if (status)
208 break;
209 }
210
211 if (status) {
212 ath6kl_err("failed to write initial bytes of 0x%x to window reg: 0x%X\n",
213 addr, reg_addr);
214 return status;
215 }
216
217 /*
218 * Write the address register again, this time write the whole
219 * 4-byte value. The effect here is that the LSB write causes the
220 * cycle to start, the extra 3 byte write to bytes 1,2,3 has no
221 * effect since we are writing the same values again
222 */
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530223 addr_val = cpu_to_le32(addr);
224 status = hif_read_write_sync(ar, reg_addr,
225 (u8 *)&(addr_val),
Kalle Valobdcd8172011-07-18 00:22:30 +0300226 4, HIF_WR_SYNC_BYTE_INC);
227
228 if (status) {
229 ath6kl_err("failed to write 0x%x to window reg: 0x%X\n",
230 addr, reg_addr);
231 return status;
232 }
233
234 return 0;
235}
236
237/*
Kalle Valoaddb44b2011-09-02 10:32:05 +0300238 * Read from the hardware through its diagnostic window. No cooperation
239 * from the firmware is required for this.
Kalle Valobdcd8172011-07-18 00:22:30 +0300240 */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300241int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value)
Kalle Valobdcd8172011-07-18 00:22:30 +0300242{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300243 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300244
245 /* set window register to start read cycle */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300246 ret = ath6kl_set_addrwin_reg(ar, WINDOW_READ_ADDR_ADDRESS, address);
247 if (ret)
248 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300249
250 /* read the data */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300251 ret = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *) value,
252 sizeof(*value), HIF_RD_SYNC_BYTE_INC);
253 if (ret) {
254 ath6kl_warn("failed to read32 through diagnose window: %d\n",
255 ret);
256 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300257 }
258
Kalle Valoaddb44b2011-09-02 10:32:05 +0300259 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300260}
261
Kalle Valobdcd8172011-07-18 00:22:30 +0300262/*
263 * Write to the ATH6KL through its diagnostic window. No cooperation from
264 * the Target is required for this.
265 */
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300266int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value)
Kalle Valobdcd8172011-07-18 00:22:30 +0300267{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300268 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300269
270 /* set write data */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300271 ret = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *) &value,
272 sizeof(value), HIF_WR_SYNC_BYTE_INC);
273 if (ret) {
274 ath6kl_err("failed to write 0x%x during diagnose window to 0x%d\n",
275 address, value);
276 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300277 }
278
279 /* set window register, which starts the write cycle */
280 return ath6kl_set_addrwin_reg(ar, WINDOW_WRITE_ADDR_ADDRESS,
Kalle Valoaddb44b2011-09-02 10:32:05 +0300281 address);
Kalle Valobdcd8172011-07-18 00:22:30 +0300282}
283
Kalle Valoaddb44b2011-09-02 10:32:05 +0300284int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length)
Kalle Valobdcd8172011-07-18 00:22:30 +0300285{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300286 u32 count, *buf = data;
287 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300288
Kalle Valoaddb44b2011-09-02 10:32:05 +0300289 if (WARN_ON(length % 4))
290 return -EINVAL;
291
292 for (count = 0; count < length / 4; count++, address += 4) {
293 ret = ath6kl_diag_read32(ar, address, &buf[count]);
294 if (ret)
295 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300296 }
297
Kalle Valoaddb44b2011-09-02 10:32:05 +0300298 return 0;
299}
300
301int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length)
302{
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300303 u32 count;
304 __le32 *buf = data;
Kalle Valoaddb44b2011-09-02 10:32:05 +0300305 int ret;
306
307 if (WARN_ON(length % 4))
308 return -EINVAL;
309
310 for (count = 0; count < length / 4; count++, address += 4) {
311 ret = ath6kl_diag_write32(ar, address, buf[count]);
312 if (ret)
313 return ret;
314 }
315
316 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300317}
318
Kalle Valobc07ddb2011-09-02 10:32:05 +0300319int ath6kl_read_fwlogs(struct ath6kl *ar)
320{
321 struct ath6kl_dbglog_hdr debug_hdr;
322 struct ath6kl_dbglog_buf debug_buf;
323 u32 address, length, dropped, firstbuf, debug_hdr_addr;
324 int ret = 0, loop;
325 u8 *buf;
326
327 buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL);
328 if (!buf)
329 return -ENOMEM;
330
331 address = TARG_VTOP(ar->target_type,
332 ath6kl_get_hi_item_addr(ar,
333 HI_ITEM(hi_dbglog_hdr)));
334
335 ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr);
336 if (ret)
337 goto out;
338
339 /* Get the contents of the ring buffer */
340 if (debug_hdr_addr == 0) {
341 ath6kl_warn("Invalid address for debug_hdr_addr\n");
342 ret = -EINVAL;
343 goto out;
344 }
345
346 address = TARG_VTOP(ar->target_type, debug_hdr_addr);
347 ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr));
348
349 address = TARG_VTOP(ar->target_type,
350 le32_to_cpu(debug_hdr.dbuf_addr));
351 firstbuf = address;
352 dropped = le32_to_cpu(debug_hdr.dropped);
353 ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
354
355 loop = 100;
356
357 do {
358 address = TARG_VTOP(ar->target_type,
359 le32_to_cpu(debug_buf.buffer_addr));
360 length = le32_to_cpu(debug_buf.length);
361
362 if (length != 0 && (le32_to_cpu(debug_buf.length) <=
363 le32_to_cpu(debug_buf.bufsize))) {
364 length = ALIGN(length, 4);
365
366 ret = ath6kl_diag_read(ar, address,
367 buf, length);
368 if (ret)
369 goto out;
370
371 ath6kl_debug_fwlog_event(ar, buf, length);
372 }
373
374 address = TARG_VTOP(ar->target_type,
375 le32_to_cpu(debug_buf.next));
376 ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
377 if (ret)
378 goto out;
379
380 loop--;
381
382 if (WARN_ON(loop == 0)) {
383 ret = -ETIMEDOUT;
384 goto out;
385 }
386 } while (address != firstbuf);
387
388out:
389 kfree(buf);
390
391 return ret;
392}
393
Kevin Fang31024d92011-07-11 17:14:13 +0800394/* FIXME: move to a better place, target.h? */
395#define AR6003_RESET_CONTROL_ADDRESS 0x00004000
396#define AR6004_RESET_CONTROL_ADDRESS 0x00004000
397
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +0530398void ath6kl_reset_device(struct ath6kl *ar, u32 target_type,
399 bool wait_fot_compltn, bool cold_reset)
Kalle Valobdcd8172011-07-18 00:22:30 +0300400{
401 int status = 0;
402 u32 address;
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300403 __le32 data;
Kalle Valobdcd8172011-07-18 00:22:30 +0300404
Kevin Fang31024d92011-07-11 17:14:13 +0800405 if (target_type != TARGET_TYPE_AR6003 &&
406 target_type != TARGET_TYPE_AR6004)
Kalle Valobdcd8172011-07-18 00:22:30 +0300407 return;
408
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300409 data = cold_reset ? cpu_to_le32(RESET_CONTROL_COLD_RST) :
410 cpu_to_le32(RESET_CONTROL_MBOX_RST);
Kalle Valobdcd8172011-07-18 00:22:30 +0300411
Kevin Fang31024d92011-07-11 17:14:13 +0800412 switch (target_type) {
413 case TARGET_TYPE_AR6003:
414 address = AR6003_RESET_CONTROL_ADDRESS;
415 break;
416 case TARGET_TYPE_AR6004:
417 address = AR6004_RESET_CONTROL_ADDRESS;
418 break;
419 default:
420 address = AR6003_RESET_CONTROL_ADDRESS;
421 break;
422 }
423
Kalle Valoaddb44b2011-09-02 10:32:05 +0300424 status = ath6kl_diag_write32(ar, address, data);
Kalle Valobdcd8172011-07-18 00:22:30 +0300425
426 if (status)
427 ath6kl_err("failed to reset target\n");
428}
429
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530430static void ath6kl_install_static_wep_keys(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300431{
432 u8 index;
433 u8 keyusage;
434
435 for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) {
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530436 if (vif->wep_key_list[index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300437 keyusage = GROUP_USAGE;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530438 if (index == vif->def_txkey_index)
Kalle Valobdcd8172011-07-18 00:22:30 +0300439 keyusage |= TX_USAGE;
440
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530441 ath6kl_wmi_addkey_cmd(vif->ar->wmi, vif->fw_vif_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300442 index,
443 WEP_CRYPT,
444 keyusage,
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530445 vif->wep_key_list[index].key_len,
Kalle Valobdcd8172011-07-18 00:22:30 +0300446 NULL,
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530447 vif->wep_key_list[index].key,
Kalle Valobdcd8172011-07-18 00:22:30 +0300448 KEY_OP_INIT_VAL, NULL,
449 NO_SYNC_WMIFLAG);
450 }
451 }
452}
453
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530454void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +0300455{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530456 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300457 struct ath6kl_req_key *ik;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300458 int res;
459 u8 key_rsc[ATH6KL_KEY_SEQ_LEN];
Kalle Valobdcd8172011-07-18 00:22:30 +0300460
Jouni Malinen572e27c2011-09-05 17:38:45 +0300461 ik = &ar->ap_mode_bkey;
Kalle Valobdcd8172011-07-18 00:22:30 +0300462
Jouni Malinen572e27c2011-09-05 17:38:45 +0300463 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", channel);
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300464
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530465 switch (vif->auth_mode) {
Jouni Malinen572e27c2011-09-05 17:38:45 +0300466 case NONE_AUTH:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530467 if (vif->prwise_crypto == WEP_CRYPT)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530468 ath6kl_install_static_wep_keys(vif);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300469 break;
470 case WPA_PSK_AUTH:
471 case WPA2_PSK_AUTH:
472 case (WPA_PSK_AUTH | WPA2_PSK_AUTH):
473 if (!ik->valid)
Kalle Valobdcd8172011-07-18 00:22:30 +0300474 break;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300475
Jouni Malinen572e27c2011-09-05 17:38:45 +0300476 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey for "
477 "the initial group key for AP mode\n");
478 memset(key_rsc, 0, sizeof(key_rsc));
479 res = ath6kl_wmi_addkey_cmd(
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530480 ar->wmi, vif->fw_vif_idx, ik->key_index, ik->key_type,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300481 GROUP_USAGE, ik->key_len, key_rsc, ik->key,
482 KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG);
483 if (res) {
484 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed "
485 "addkey failed: %d\n", res);
Kalle Valobdcd8172011-07-18 00:22:30 +0300486 }
Jouni Malinen572e27c2011-09-05 17:38:45 +0300487 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300488 }
489
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530490 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530491 set_bit(CONNECTED, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530492 netif_carrier_on(vif->ndev);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300493}
494
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530495void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300496 u8 keymgmt, u8 ucipher, u8 auth,
497 u8 assoc_req_len, u8 *assoc_info)
498{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530499 struct ath6kl *ar = vif->ar;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300500 u8 *ies = NULL, *wpa_ie = NULL, *pos;
501 size_t ies_len = 0;
502 struct station_info sinfo;
503
504 ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid);
Kalle Valobdcd8172011-07-18 00:22:30 +0300505
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300506 if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) {
507 struct ieee80211_mgmt *mgmt =
508 (struct ieee80211_mgmt *) assoc_info;
509 if (ieee80211_is_assoc_req(mgmt->frame_control) &&
510 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) +
511 sizeof(mgmt->u.assoc_req)) {
512 ies = mgmt->u.assoc_req.variable;
513 ies_len = assoc_info + assoc_req_len - ies;
514 } else if (ieee80211_is_reassoc_req(mgmt->frame_control) &&
515 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr)
516 + sizeof(mgmt->u.reassoc_req)) {
517 ies = mgmt->u.reassoc_req.variable;
518 ies_len = assoc_info + assoc_req_len - ies;
519 }
520 }
521
522 pos = ies;
523 while (pos && pos + 1 < ies + ies_len) {
524 if (pos + 2 + pos[1] > ies + ies_len)
525 break;
526 if (pos[0] == WLAN_EID_RSN)
527 wpa_ie = pos; /* RSN IE */
528 else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
529 pos[1] >= 4 &&
530 pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) {
531 if (pos[5] == 0x01)
532 wpa_ie = pos; /* WPA IE */
533 else if (pos[5] == 0x04) {
534 wpa_ie = pos; /* WPS IE */
535 break; /* overrides WPA/RSN IE */
536 }
537 }
538 pos += 2 + pos[1];
539 }
540
Jouni Malinen572e27c2011-09-05 17:38:45 +0300541 ath6kl_add_new_sta(ar, mac_addr, aid, wpa_ie,
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300542 wpa_ie ? 2 + wpa_ie[1] : 0,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300543 keymgmt, ucipher, auth);
Kalle Valobdcd8172011-07-18 00:22:30 +0300544
545 /* send event to application */
546 memset(&sinfo, 0, sizeof(sinfo));
547
548 /* TODO: sinfo.generation */
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300549
550 sinfo.assoc_req_ies = ies;
551 sinfo.assoc_req_ies_len = ies_len;
552 sinfo.filled |= STATION_INFO_ASSOC_REQ_IES;
553
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530554 cfg80211_new_sta(vif->ndev, mac_addr, &sinfo, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300555
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530556 netif_wake_queue(vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300557}
558
559/* Functions for Tx credit handling */
560void ath6k_credit_init(struct htc_credit_state_info *cred_info,
561 struct list_head *ep_list,
562 int tot_credits)
563{
564 struct htc_endpoint_credit_dist *cur_ep_dist;
565 int count;
566
567 cred_info->cur_free_credits = tot_credits;
568 cred_info->total_avail_credits = tot_credits;
569
570 list_for_each_entry(cur_ep_dist, ep_list, list) {
571 if (cur_ep_dist->endpoint == ENDPOINT_0)
572 continue;
573
574 cur_ep_dist->cred_min = cur_ep_dist->cred_per_msg;
575
576 if (tot_credits > 4)
577 if ((cur_ep_dist->svc_id == WMI_DATA_BK_SVC) ||
578 (cur_ep_dist->svc_id == WMI_DATA_BE_SVC)) {
579 ath6kl_deposit_credit_to_ep(cred_info,
580 cur_ep_dist,
581 cur_ep_dist->cred_min);
582 cur_ep_dist->dist_flags |= HTC_EP_ACTIVE;
583 }
584
585 if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) {
586 ath6kl_deposit_credit_to_ep(cred_info, cur_ep_dist,
587 cur_ep_dist->cred_min);
588 /*
589 * Control service is always marked active, it
590 * never goes inactive EVER.
591 */
592 cur_ep_dist->dist_flags |= HTC_EP_ACTIVE;
593 } else if (cur_ep_dist->svc_id == WMI_DATA_BK_SVC)
594 /* this is the lowest priority data endpoint */
595 cred_info->lowestpri_ep_dist = cur_ep_dist->list;
596
597 /*
598 * Streams have to be created (explicit | implicit) for all
599 * kinds of traffic. BE endpoints are also inactive in the
600 * beginning. When BE traffic starts it creates implicit
601 * streams that redistributes credits.
602 *
603 * Note: all other endpoints have minimums set but are
604 * initially given NO credits. credits will be distributed
605 * as traffic activity demands
606 */
607 }
608
609 WARN_ON(cred_info->cur_free_credits <= 0);
610
611 list_for_each_entry(cur_ep_dist, ep_list, list) {
612 if (cur_ep_dist->endpoint == ENDPOINT_0)
613 continue;
614
615 if (cur_ep_dist->svc_id == WMI_CONTROL_SVC)
616 cur_ep_dist->cred_norm = cur_ep_dist->cred_per_msg;
617 else {
618 /*
619 * For the remaining data endpoints, we assume that
620 * each cred_per_msg are the same. We use a simple
621 * calculation here, we take the remaining credits
622 * and determine how many max messages this can
623 * cover and then set each endpoint's normal value
624 * equal to 3/4 this amount.
625 */
626 count = (cred_info->cur_free_credits /
627 cur_ep_dist->cred_per_msg)
628 * cur_ep_dist->cred_per_msg;
629 count = (count * 3) >> 2;
630 count = max(count, cur_ep_dist->cred_per_msg);
631 cur_ep_dist->cred_norm = count;
632
633 }
634 }
635}
636
637/* initialize and setup credit distribution */
638int ath6k_setup_credit_dist(void *htc_handle,
639 struct htc_credit_state_info *cred_info)
640{
641 u16 servicepriority[5];
642
643 memset(cred_info, 0, sizeof(struct htc_credit_state_info));
644
645 servicepriority[0] = WMI_CONTROL_SVC; /* highest */
646 servicepriority[1] = WMI_DATA_VO_SVC;
647 servicepriority[2] = WMI_DATA_VI_SVC;
648 servicepriority[3] = WMI_DATA_BE_SVC;
649 servicepriority[4] = WMI_DATA_BK_SVC; /* lowest */
650
651 /* set priority list */
Kalle Vaload226ec2011-08-10 09:49:12 +0300652 ath6kl_htc_set_credit_dist(htc_handle, cred_info, servicepriority, 5);
Kalle Valobdcd8172011-07-18 00:22:30 +0300653
654 return 0;
655}
656
657/* reduce an ep's credits back to a set limit */
658static void ath6k_reduce_credits(struct htc_credit_state_info *cred_info,
659 struct htc_endpoint_credit_dist *ep_dist,
660 int limit)
661{
662 int credits;
663
664 ep_dist->cred_assngd = limit;
665
666 if (ep_dist->credits <= limit)
667 return;
668
669 credits = ep_dist->credits - limit;
670 ep_dist->credits -= credits;
671 cred_info->cur_free_credits += credits;
672}
673
674static void ath6k_credit_update(struct htc_credit_state_info *cred_info,
675 struct list_head *epdist_list)
676{
677 struct htc_endpoint_credit_dist *cur_dist_list;
678
679 list_for_each_entry(cur_dist_list, epdist_list, list) {
680 if (cur_dist_list->endpoint == ENDPOINT_0)
681 continue;
682
683 if (cur_dist_list->cred_to_dist > 0) {
684 cur_dist_list->credits +=
685 cur_dist_list->cred_to_dist;
686 cur_dist_list->cred_to_dist = 0;
687 if (cur_dist_list->credits >
688 cur_dist_list->cred_assngd)
689 ath6k_reduce_credits(cred_info,
690 cur_dist_list,
691 cur_dist_list->cred_assngd);
692
693 if (cur_dist_list->credits >
694 cur_dist_list->cred_norm)
695 ath6k_reduce_credits(cred_info, cur_dist_list,
696 cur_dist_list->cred_norm);
697
698 if (!(cur_dist_list->dist_flags & HTC_EP_ACTIVE)) {
699 if (cur_dist_list->txq_depth == 0)
700 ath6k_reduce_credits(cred_info,
701 cur_dist_list, 0);
702 }
703 }
704 }
705}
706
707/*
708 * HTC has an endpoint that needs credits, ep_dist is the endpoint in
709 * question.
710 */
711void ath6k_seek_credits(struct htc_credit_state_info *cred_info,
712 struct htc_endpoint_credit_dist *ep_dist)
713{
714 struct htc_endpoint_credit_dist *curdist_list;
715 int credits = 0;
716 int need;
717
718 if (ep_dist->svc_id == WMI_CONTROL_SVC)
719 goto out;
720
721 if ((ep_dist->svc_id == WMI_DATA_VI_SVC) ||
722 (ep_dist->svc_id == WMI_DATA_VO_SVC))
723 if ((ep_dist->cred_assngd >= ep_dist->cred_norm))
724 goto out;
725
726 /*
727 * For all other services, we follow a simple algorithm of:
728 *
729 * 1. checking the free pool for credits
730 * 2. checking lower priority endpoints for credits to take
731 */
732
733 credits = min(cred_info->cur_free_credits, ep_dist->seek_cred);
734
735 if (credits >= ep_dist->seek_cred)
736 goto out;
737
738 /*
739 * We don't have enough in the free pool, try taking away from
740 * lower priority services The rule for taking away credits:
741 *
742 * 1. Only take from lower priority endpoints
743 * 2. Only take what is allocated above the minimum (never
744 * starve an endpoint completely)
745 * 3. Only take what you need.
746 */
747
748 list_for_each_entry_reverse(curdist_list,
749 &cred_info->lowestpri_ep_dist,
750 list) {
751 if (curdist_list == ep_dist)
752 break;
753
754 need = ep_dist->seek_cred - cred_info->cur_free_credits;
755
756 if ((curdist_list->cred_assngd - need) >=
757 curdist_list->cred_min) {
758 /*
759 * The current one has been allocated more than
760 * it's minimum and it has enough credits assigned
761 * above it's minimum to fulfill our need try to
762 * take away just enough to fulfill our need.
763 */
764 ath6k_reduce_credits(cred_info, curdist_list,
765 curdist_list->cred_assngd - need);
766
767 if (cred_info->cur_free_credits >=
768 ep_dist->seek_cred)
769 break;
770 }
771
772 if (curdist_list->endpoint == ENDPOINT_0)
773 break;
774 }
775
776 credits = min(cred_info->cur_free_credits, ep_dist->seek_cred);
777
778out:
779 /* did we find some credits? */
780 if (credits)
781 ath6kl_deposit_credit_to_ep(cred_info, ep_dist, credits);
782
783 ep_dist->seek_cred = 0;
784}
785
786/* redistribute credits based on activity change */
787static void ath6k_redistribute_credits(struct htc_credit_state_info *info,
788 struct list_head *ep_dist_list)
789{
790 struct htc_endpoint_credit_dist *curdist_list;
791
792 list_for_each_entry(curdist_list, ep_dist_list, list) {
793 if (curdist_list->endpoint == ENDPOINT_0)
794 continue;
795
796 if ((curdist_list->svc_id == WMI_DATA_BK_SVC) ||
797 (curdist_list->svc_id == WMI_DATA_BE_SVC))
798 curdist_list->dist_flags |= HTC_EP_ACTIVE;
799
800 if ((curdist_list->svc_id != WMI_CONTROL_SVC) &&
801 !(curdist_list->dist_flags & HTC_EP_ACTIVE)) {
802 if (curdist_list->txq_depth == 0)
803 ath6k_reduce_credits(info,
804 curdist_list, 0);
805 else
806 ath6k_reduce_credits(info,
807 curdist_list,
808 curdist_list->cred_min);
809 }
810 }
811}
812
813/*
814 *
815 * This function is invoked whenever endpoints require credit
816 * distributions. A lock is held while this function is invoked, this
817 * function shall NOT block. The ep_dist_list is a list of distribution
818 * structures in prioritized order as defined by the call to the
819 * htc_set_credit_dist() api.
820 */
821void ath6k_credit_distribute(struct htc_credit_state_info *cred_info,
822 struct list_head *ep_dist_list,
823 enum htc_credit_dist_reason reason)
824{
825 switch (reason) {
826 case HTC_CREDIT_DIST_SEND_COMPLETE:
827 ath6k_credit_update(cred_info, ep_dist_list);
828 break;
829 case HTC_CREDIT_DIST_ACTIVITY_CHANGE:
830 ath6k_redistribute_credits(cred_info, ep_dist_list);
831 break;
832 default:
833 break;
834 }
835
836 WARN_ON(cred_info->cur_free_credits > cred_info->total_avail_credits);
837 WARN_ON(cred_info->cur_free_credits < 0);
838}
839
840void disconnect_timer_handler(unsigned long ptr)
841{
842 struct net_device *dev = (struct net_device *)ptr;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530843 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300844
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +0530845 ath6kl_init_profile_info(vif);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530846 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +0300847}
848
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530849void ath6kl_disconnect(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300850{
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530851 if (test_bit(CONNECTED, &vif->flags) ||
852 test_bit(CONNECT_PEND, &vif->flags)) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530853 ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +0300854 /*
855 * Disconnect command is issued, clear the connect pending
856 * flag. The connected flag will be cleared in
857 * disconnect event notification.
858 */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530859 clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300860 }
861}
862
Kalle Valoabcb3442011-07-22 08:26:20 +0300863void ath6kl_deep_sleep_enable(struct ath6kl *ar)
864{
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530865 /* TODO: Pass vif instead of taking it from ar */
866 struct ath6kl_vif *vif = ar->vif;
867
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530868 switch (vif->sme_state) {
Kalle Valoabcb3442011-07-22 08:26:20 +0300869 case SME_CONNECTING:
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +0530870 cfg80211_connect_result(vif->ndev, vif->bssid, NULL, 0,
Kalle Valoabcb3442011-07-22 08:26:20 +0300871 NULL, 0,
872 WLAN_STATUS_UNSPECIFIED_FAILURE,
873 GFP_KERNEL);
874 break;
875 case SME_CONNECTED:
876 default:
877 /*
878 * FIXME: oddly enough smeState is in DISCONNECTED during
879 * suspend, why? Need to send disconnected event in that
880 * state.
881 */
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +0530882 cfg80211_disconnected(vif->ndev, 0, NULL, 0, GFP_KERNEL);
Kalle Valoabcb3442011-07-22 08:26:20 +0300883 break;
884 }
885
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530886 if (test_bit(CONNECTED, &vif->flags) ||
887 test_bit(CONNECT_PEND, &vif->flags))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530888 ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
Kalle Valoabcb3442011-07-22 08:26:20 +0300889
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530890 vif->sme_state = SME_DISCONNECTED;
Kalle Valoabcb3442011-07-22 08:26:20 +0300891
892 /* disable scanning */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530893 if (ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0xFFFF, 0, 0,
894 0, 0, 0, 0, 0, 0, 0) != 0)
Kalle Valoabcb3442011-07-22 08:26:20 +0300895 printk(KERN_WARNING "ath6kl: failed to disable scan "
896 "during suspend\n");
897
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530898 ath6kl_cfg80211_scan_complete_event(vif, -ECANCELED);
Chilam Ngaa6cffc2011-10-05 10:12:52 +0300899
900 /* save the current power mode before enabling power save */
901 ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
902
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530903 if (ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER) != 0)
Chilam Ngaa6cffc2011-10-05 10:12:52 +0300904 ath6kl_warn("ath6kl_deep_sleep_enable: "
905 "wmi_powermode_cmd failed\n");
Kalle Valoabcb3442011-07-22 08:26:20 +0300906}
907
Kalle Valobdcd8172011-07-18 00:22:30 +0300908/* WMI Event handlers */
909
910static const char *get_hw_id_string(u32 id)
911{
912 switch (id) {
913 case AR6003_REV1_VERSION:
914 return "1.0";
915 case AR6003_REV2_VERSION:
916 return "2.0";
917 case AR6003_REV3_VERSION:
918 return "2.1.1";
919 default:
920 return "unknown";
921 }
922}
923
924void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver)
925{
926 struct ath6kl *ar = devt;
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +0530927 struct net_device *dev = ar->vif->ndev;
Kalle Valobdcd8172011-07-18 00:22:30 +0300928
929 memcpy(dev->dev_addr, datap, ETH_ALEN);
930 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n",
931 __func__, dev->dev_addr);
932
933 ar->version.wlan_ver = sw_ver;
934 ar->version.abi_ver = abi_ver;
935
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530936 snprintf(ar->wiphy->fw_version,
937 sizeof(ar->wiphy->fw_version),
Kalle Valobdcd8172011-07-18 00:22:30 +0300938 "%u.%u.%u.%u",
939 (ar->version.wlan_ver & 0xf0000000) >> 28,
940 (ar->version.wlan_ver & 0x0f000000) >> 24,
941 (ar->version.wlan_ver & 0x00ff0000) >> 16,
942 (ar->version.wlan_ver & 0x0000ffff));
943
944 /* indicate to the waiting thread that the ready event was received */
945 set_bit(WMI_READY, &ar->flag);
946 wake_up(&ar->event_wq);
947
Kalle Valo003353b2011-09-01 10:14:21 +0300948 ath6kl_info("hw %s fw %s%s\n",
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530949 get_hw_id_string(ar->wiphy->hw_version),
950 ar->wiphy->fw_version,
Kalle Valo003353b2011-09-01 10:14:21 +0300951 test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
Kalle Valobdcd8172011-07-18 00:22:30 +0300952}
953
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530954void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
Kalle Valobdcd8172011-07-18 00:22:30 +0300955{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530956 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530957
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530958 ath6kl_cfg80211_scan_complete_event(vif, status);
Kalle Valobdcd8172011-07-18 00:22:30 +0300959
Jouni Malinen551185c2011-09-19 19:15:06 +0300960 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530961 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530962 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
963 NONE_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +0300964 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300965
966 ath6kl_dbg(ATH6KL_DBG_WLAN_SCAN, "scan complete: %d\n", status);
967}
968
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530969void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300970 u16 listen_int, u16 beacon_int,
971 enum network_type net_type, u8 beacon_ie_len,
972 u8 assoc_req_len, u8 assoc_resp_len,
973 u8 *assoc_info)
974{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530975 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530976
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530977 ath6kl_cfg80211_connect_event(vif, channel, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300978 listen_int, beacon_int,
979 net_type, beacon_ie_len,
980 assoc_req_len, assoc_resp_len,
981 assoc_info);
982
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530983 memcpy(vif->bssid, bssid, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530984 vif->bss_ch = channel;
Kalle Valobdcd8172011-07-18 00:22:30 +0300985
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530986 if ((vif->nw_type == INFRA_NETWORK))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530987 ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
988 ar->listen_intvl_t,
Kalle Valobdcd8172011-07-18 00:22:30 +0300989 ar->listen_intvl_b);
990
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530991 netif_wake_queue(vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300992
993 /* Update connect & link status atomically */
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530994 spin_lock_bh(&ar->lock);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530995 set_bit(CONNECTED, &vif->flags);
996 clear_bit(CONNECT_PEND, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530997 netif_carrier_on(vif->ndev);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530998 spin_unlock_bh(&ar->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300999
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05301000 aggr_reset_state(vif->aggr_cntxt);
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301001 vif->reconnect_flag = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001002
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301003 if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001004 memset(ar->node_map, 0, sizeof(ar->node_map));
1005 ar->node_num = 0;
1006 ar->next_ep_id = ENDPOINT_2;
1007 }
1008
Jouni Malinen551185c2011-09-19 19:15:06 +03001009 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301010 set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301011 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1012 CURRENT_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +03001013 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001014}
1015
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301016void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast)
Kalle Valobdcd8172011-07-18 00:22:30 +03001017{
1018 struct ath6kl_sta *sta;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301019 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +03001020 u8 tsc[6];
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301021
Kalle Valobdcd8172011-07-18 00:22:30 +03001022 /*
1023 * For AP case, keyid will have aid of STA which sent pkt with
1024 * MIC error. Use this aid to get MAC & send it to hostapd.
1025 */
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301026 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001027 sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
1028 if (!sta)
1029 return;
1030
1031 ath6kl_dbg(ATH6KL_DBG_TRC,
1032 "ap tkip mic error received from aid=%d\n", keyid);
1033
1034 memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301035 cfg80211_michael_mic_failure(vif->ndev, sta->mac,
Kalle Valobdcd8172011-07-18 00:22:30 +03001036 NL80211_KEYTYPE_PAIRWISE, keyid,
1037 tsc, GFP_KERNEL);
1038 } else
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301039 ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast);
Kalle Valobdcd8172011-07-18 00:22:30 +03001040
1041}
1042
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301043static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +03001044{
1045 struct wmi_target_stats *tgt_stats =
1046 (struct wmi_target_stats *) ptr;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301047 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301048 struct target_stats *stats = &vif->target_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +03001049 struct tkip_ccmp_stats *ccmp_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +03001050 u8 ac;
1051
1052 if (len < sizeof(*tgt_stats))
1053 return;
1054
Kalle Valobdcd8172011-07-18 00:22:30 +03001055 ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
1056
1057 stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
1058 stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
1059 stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
1060 stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
1061 stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
1062 stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
1063 stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
1064 stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
1065 stats->tx_rts_success_cnt +=
1066 le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
1067
1068 for (ac = 0; ac < WMM_NUM_AC; ac++)
1069 stats->tx_pkt_per_ac[ac] +=
1070 le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
1071
1072 stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
1073 stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
1074 stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
1075 stats->tx_mult_retry_cnt +=
1076 le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
1077 stats->tx_rts_fail_cnt +=
1078 le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
1079 stats->tx_ucast_rate =
1080 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate));
1081
1082 stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
1083 stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
1084 stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
1085 stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
1086 stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
1087 stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
1088 stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
1089 stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
1090 stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
1091 stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
1092 stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
1093 stats->rx_key_cache_miss +=
1094 le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
1095 stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
1096 stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
1097 stats->rx_ucast_rate =
1098 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate));
1099
1100 ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
1101
1102 stats->tkip_local_mic_fail +=
1103 le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
1104 stats->tkip_cnter_measures_invoked +=
1105 le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
1106 stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
1107
1108 stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
1109 stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
1110
1111 stats->pwr_save_fail_cnt +=
1112 le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
1113 stats->noise_floor_calib =
1114 a_sle32_to_cpu(tgt_stats->noise_floor_calib);
1115
1116 stats->cs_bmiss_cnt +=
1117 le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
1118 stats->cs_low_rssi_cnt +=
1119 le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
1120 stats->cs_connect_cnt +=
1121 le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
1122 stats->cs_discon_cnt +=
1123 le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
1124
1125 stats->cs_ave_beacon_rssi =
1126 a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
1127
1128 stats->cs_last_roam_msec =
1129 tgt_stats->cserv_stats.cs_last_roam_msec;
1130 stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
1131 stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
1132
1133 stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
1134
1135 stats->wow_pkt_dropped +=
1136 le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
1137 stats->wow_host_pkt_wakeups +=
1138 tgt_stats->wow_stats.wow_host_pkt_wakeups;
1139 stats->wow_host_evt_wakeups +=
1140 tgt_stats->wow_stats.wow_host_evt_wakeups;
1141 stats->wow_evt_discarded +=
1142 le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
1143
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301144 if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
1145 clear_bit(STATS_UPDATE_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001146 wake_up(&ar->event_wq);
1147 }
1148}
1149
1150static void ath6kl_add_le32(__le32 *var, __le32 val)
1151{
1152 *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
1153}
1154
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301155void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +03001156{
1157 struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301158 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +03001159 struct wmi_ap_mode_stat *ap = &ar->ap_stats;
1160 struct wmi_per_sta_stat *st_ap, *st_p;
1161 u8 ac;
1162
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301163 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001164 if (len < sizeof(*p))
1165 return;
1166
1167 for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
1168 st_ap = &ap->sta[ac];
1169 st_p = &p->sta[ac];
1170
1171 ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
1172 ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
1173 ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
1174 ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
1175 ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
1176 ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
1177 ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
1178 ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
1179 }
1180
1181 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301182 ath6kl_update_target_stats(vif, ptr, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001183 }
1184}
1185
1186void ath6kl_wakeup_event(void *dev)
1187{
1188 struct ath6kl *ar = (struct ath6kl *) dev;
1189
1190 wake_up(&ar->event_wq);
1191}
1192
1193void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
1194{
1195 struct ath6kl *ar = (struct ath6kl *) devt;
1196
1197 ar->tx_pwr = tx_pwr;
1198 wake_up(&ar->event_wq);
1199}
1200
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301201void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid)
Kalle Valobdcd8172011-07-18 00:22:30 +03001202{
1203 struct ath6kl_sta *conn;
1204 struct sk_buff *skb;
1205 bool psq_empty = false;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301206 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +03001207
1208 conn = ath6kl_find_sta_by_aid(ar, aid);
1209
1210 if (!conn)
1211 return;
1212 /*
1213 * Send out a packet queued on ps queue. When the ps queue
1214 * becomes empty update the PVB for this station.
1215 */
1216 spin_lock_bh(&conn->psq_lock);
1217 psq_empty = skb_queue_empty(&conn->psq);
1218 spin_unlock_bh(&conn->psq_lock);
1219
1220 if (psq_empty)
1221 /* TODO: Send out a NULL data frame */
1222 return;
1223
1224 spin_lock_bh(&conn->psq_lock);
1225 skb = skb_dequeue(&conn->psq);
1226 spin_unlock_bh(&conn->psq_lock);
1227
1228 conn->sta_flags |= STA_PS_POLLED;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301229 ath6kl_data_tx(skb, vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001230 conn->sta_flags &= ~STA_PS_POLLED;
1231
1232 spin_lock_bh(&conn->psq_lock);
1233 psq_empty = skb_queue_empty(&conn->psq);
1234 spin_unlock_bh(&conn->psq_lock);
1235
1236 if (psq_empty)
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301237 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, conn->aid, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001238}
1239
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301240void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001241{
1242 bool mcastq_empty = false;
1243 struct sk_buff *skb;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301244 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +03001245
1246 /*
1247 * If there are no associated STAs, ignore the DTIM expiry event.
1248 * There can be potential race conditions where the last associated
1249 * STA may disconnect & before the host could clear the 'Indicate
1250 * DTIM' request to the firmware, the firmware would have just
1251 * indicated a DTIM expiry event. The race is between 'clear DTIM
1252 * expiry cmd' going from the host to the firmware & the DTIM
1253 * expiry event happening from the firmware to the host.
1254 */
1255 if (!ar->sta_list_index)
1256 return;
1257
1258 spin_lock_bh(&ar->mcastpsq_lock);
1259 mcastq_empty = skb_queue_empty(&ar->mcastpsq);
1260 spin_unlock_bh(&ar->mcastpsq_lock);
1261
1262 if (mcastq_empty)
1263 return;
1264
1265 /* set the STA flag to dtim_expired for the frame to go out */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301266 set_bit(DTIM_EXPIRED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001267
1268 spin_lock_bh(&ar->mcastpsq_lock);
1269 while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
1270 spin_unlock_bh(&ar->mcastpsq_lock);
1271
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301272 ath6kl_data_tx(skb, vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001273
1274 spin_lock_bh(&ar->mcastpsq_lock);
1275 }
1276 spin_unlock_bh(&ar->mcastpsq_lock);
1277
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301278 clear_bit(DTIM_EXPIRED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001279
1280 /* clear the LSB of the BitMapCtl field of the TIM IE */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301281 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, MCAST_AID, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001282}
1283
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301284void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001285 u8 assoc_resp_len, u8 *assoc_info,
1286 u16 prot_reason_status)
1287{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301288 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301289
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301290 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001291 if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
1292 return;
1293
1294 /* if no more associated STAs, empty the mcast PS q */
1295 if (ar->sta_list_index == 0) {
1296 spin_lock_bh(&ar->mcastpsq_lock);
1297 skb_queue_purge(&ar->mcastpsq);
1298 spin_unlock_bh(&ar->mcastpsq_lock);
1299
1300 /* clear the LSB of the TIM IE's BitMapCtl field */
1301 if (test_bit(WMI_READY, &ar->flag))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301302 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
1303 MCAST_AID, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001304 }
1305
1306 if (!is_broadcast_ether_addr(bssid)) {
1307 /* send event to application */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301308 cfg80211_del_sta(vif->ndev, bssid, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +03001309 }
1310
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301311 if (memcmp(vif->ndev->dev_addr, bssid, ETH_ALEN) == 0) {
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301312 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301313 clear_bit(CONNECTED, &vif->flags);
Jouni Malinen151411e2011-09-15 15:10:16 +03001314 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001315 return;
1316 }
1317
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301318 ath6kl_cfg80211_disconnect_event(vif, reason, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001319 assoc_resp_len, assoc_info,
1320 prot_reason_status);
1321
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05301322 aggr_reset_state(vif->aggr_cntxt);
Kalle Valobdcd8172011-07-18 00:22:30 +03001323
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05301324 del_timer(&vif->disconnect_timer);
Kalle Valobdcd8172011-07-18 00:22:30 +03001325
1326 ath6kl_dbg(ATH6KL_DBG_WLAN_CONNECT,
1327 "disconnect reason is %d\n", reason);
1328
1329 /*
1330 * If the event is due to disconnect cmd from the host, only they
1331 * the target would stop trying to connect. Under any other
1332 * condition, target would keep trying to connect.
1333 */
1334 if (reason == DISCONNECT_CMD) {
1335 if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301336 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1337 NONE_BSS_FILTER, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001338 } else {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301339 set_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001340 if (((reason == ASSOC_FAILED) &&
1341 (prot_reason_status == 0x11)) ||
1342 ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0)
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301343 && (vif->reconnect_flag == 1))) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301344 set_bit(CONNECTED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001345 return;
1346 }
1347 }
1348
Kalle Valobdcd8172011-07-18 00:22:30 +03001349 /* update connect & link status atomically */
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301350 spin_lock_bh(&ar->lock);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301351 clear_bit(CONNECTED, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301352 netif_carrier_off(vif->ndev);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301353 spin_unlock_bh(&ar->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001354
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301355 if ((reason != CSERV_DISCONNECT) || (vif->reconnect_flag != 1))
1356 vif->reconnect_flag = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001357
1358 if (reason != CSERV_DISCONNECT)
1359 ar->user_key_ctrl = 0;
1360
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301361 netif_stop_queue(vif->ndev);
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301362 memset(vif->bssid, 0, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301363 vif->bss_ch = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001364
1365 ath6kl_tx_data_cleanup(ar);
1366}
1367
1368static int ath6kl_open(struct net_device *dev)
1369{
1370 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301371 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001372
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301373 spin_lock_bh(&ar->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001374
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301375 set_bit(WLAN_ENABLED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001376
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301377 if (test_bit(CONNECTED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001378 netif_carrier_on(dev);
1379 netif_wake_queue(dev);
1380 } else
1381 netif_carrier_off(dev);
1382
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301383 spin_unlock_bh(&ar->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001384
1385 return 0;
1386}
1387
1388static int ath6kl_close(struct net_device *dev)
1389{
1390 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301391 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001392
1393 netif_stop_queue(dev);
1394
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301395 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +03001396
1397 if (test_bit(WMI_READY, &ar->flag)) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301398 if (ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0xFFFF,
1399 0, 0, 0, 0, 0, 0, 0, 0, 0))
Kalle Valobdcd8172011-07-18 00:22:30 +03001400 return -EIO;
1401
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301402 clear_bit(WLAN_ENABLED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001403 }
1404
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301405 ath6kl_cfg80211_scan_complete_event(vif, -ECANCELED);
Kalle Valobdcd8172011-07-18 00:22:30 +03001406
1407 return 0;
1408}
1409
1410static struct net_device_stats *ath6kl_get_stats(struct net_device *dev)
1411{
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301412 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001413
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301414 return &vif->net_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +03001415}
1416
1417static struct net_device_ops ath6kl_netdev_ops = {
1418 .ndo_open = ath6kl_open,
1419 .ndo_stop = ath6kl_close,
1420 .ndo_start_xmit = ath6kl_data_tx,
1421 .ndo_get_stats = ath6kl_get_stats,
1422};
1423
1424void init_netdev(struct net_device *dev)
1425{
1426 dev->netdev_ops = &ath6kl_netdev_ops;
1427 dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
1428
1429 dev->needed_headroom = ETH_HLEN;
1430 dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) +
1431 sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH
Vasanthakumar Thiagarajan1df94a82011-08-17 18:45:10 +05301432 + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES;
Kalle Valobdcd8172011-07-18 00:22:30 +03001433
1434 return;
1435}