Commit | Line | Data |
---|---|---|
bdcd8170 KV |
1 | /* |
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 | ||
23 | struct ath6kl_sta *ath6kl_find_sta(struct ath6kl *ar, u8 *node_addr) | |
24 | { | |
25 | struct ath6kl_sta *conn = NULL; | |
26 | u8 i, max_conn; | |
27 | ||
28 | max_conn = (ar->nw_type == AP_NETWORK) ? AP_MAX_NUM_STA : 0; | |
29 | ||
30 | for (i = 0; i < max_conn; i++) { | |
31 | if (memcmp(node_addr, ar->sta_list[i].mac, ETH_ALEN) == 0) { | |
32 | conn = &ar->sta_list[i]; | |
33 | break; | |
34 | } | |
35 | } | |
36 | ||
37 | return conn; | |
38 | } | |
39 | ||
40 | struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid) | |
41 | { | |
42 | struct ath6kl_sta *conn = NULL; | |
43 | u8 ctr; | |
44 | ||
45 | for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) { | |
46 | if (ar->sta_list[ctr].aid == aid) { | |
47 | conn = &ar->sta_list[ctr]; | |
48 | break; | |
49 | } | |
50 | } | |
51 | return conn; | |
52 | } | |
53 | ||
54 | static void ath6kl_add_new_sta(struct ath6kl *ar, u8 *mac, u16 aid, u8 *wpaie, | |
55 | u8 ielen, u8 keymgmt, u8 ucipher, u8 auth) | |
56 | { | |
57 | struct ath6kl_sta *sta; | |
58 | u8 free_slot; | |
59 | ||
60 | free_slot = aid - 1; | |
61 | ||
62 | sta = &ar->sta_list[free_slot]; | |
63 | memcpy(sta->mac, mac, ETH_ALEN); | |
64 | memcpy(sta->wpa_ie, wpaie, ielen); | |
65 | sta->aid = aid; | |
66 | sta->keymgmt = keymgmt; | |
67 | sta->ucipher = ucipher; | |
68 | sta->auth = auth; | |
69 | ||
70 | ar->sta_list_index = ar->sta_list_index | (1 << free_slot); | |
71 | ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid); | |
72 | } | |
73 | ||
74 | static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i) | |
75 | { | |
76 | struct ath6kl_sta *sta = &ar->sta_list[i]; | |
77 | ||
78 | /* empty the queued pkts in the PS queue if any */ | |
79 | spin_lock_bh(&sta->psq_lock); | |
80 | skb_queue_purge(&sta->psq); | |
81 | spin_unlock_bh(&sta->psq_lock); | |
82 | ||
83 | memset(&ar->ap_stats.sta[sta->aid - 1], 0, | |
84 | sizeof(struct wmi_per_sta_stat)); | |
85 | memset(sta->mac, 0, ETH_ALEN); | |
86 | memset(sta->wpa_ie, 0, ATH6KL_MAX_IE); | |
87 | sta->aid = 0; | |
88 | sta->sta_flags = 0; | |
89 | ||
90 | ar->sta_list_index = ar->sta_list_index & ~(1 << i); | |
91 | ||
92 | } | |
93 | ||
94 | static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason) | |
95 | { | |
96 | u8 i, removed = 0; | |
97 | ||
98 | if (is_zero_ether_addr(mac)) | |
99 | return removed; | |
100 | ||
101 | if (is_broadcast_ether_addr(mac)) { | |
102 | ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n"); | |
103 | ||
104 | for (i = 0; i < AP_MAX_NUM_STA; i++) { | |
105 | if (!is_zero_ether_addr(ar->sta_list[i].mac)) { | |
106 | ath6kl_sta_cleanup(ar, i); | |
107 | removed = 1; | |
108 | } | |
109 | } | |
110 | } else { | |
111 | for (i = 0; i < AP_MAX_NUM_STA; i++) { | |
112 | if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) { | |
113 | ath6kl_dbg(ATH6KL_DBG_TRC, | |
114 | "deleting station %pM aid=%d reason=%d\n", | |
115 | mac, ar->sta_list[i].aid, reason); | |
116 | ath6kl_sta_cleanup(ar, i); | |
117 | removed = 1; | |
118 | break; | |
119 | } | |
120 | } | |
121 | } | |
122 | ||
123 | return removed; | |
124 | } | |
125 | ||
126 | enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac) | |
127 | { | |
128 | struct ath6kl *ar = devt; | |
129 | return ar->ac2ep_map[ac]; | |
130 | } | |
131 | ||
132 | struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar) | |
133 | { | |
134 | struct ath6kl_cookie *cookie; | |
135 | ||
136 | cookie = ar->cookie_list; | |
137 | if (cookie != NULL) { | |
138 | ar->cookie_list = cookie->arc_list_next; | |
139 | ar->cookie_count--; | |
140 | } | |
141 | ||
142 | return cookie; | |
143 | } | |
144 | ||
145 | void ath6kl_cookie_init(struct ath6kl *ar) | |
146 | { | |
147 | u32 i; | |
148 | ||
149 | ar->cookie_list = NULL; | |
150 | ar->cookie_count = 0; | |
151 | ||
152 | memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem)); | |
153 | ||
154 | for (i = 0; i < MAX_COOKIE_NUM; i++) | |
155 | ath6kl_free_cookie(ar, &ar->cookie_mem[i]); | |
156 | } | |
157 | ||
158 | void ath6kl_cookie_cleanup(struct ath6kl *ar) | |
159 | { | |
160 | ar->cookie_list = NULL; | |
161 | ar->cookie_count = 0; | |
162 | } | |
163 | ||
164 | void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie) | |
165 | { | |
166 | /* Insert first */ | |
167 | ||
168 | if (!ar || !cookie) | |
169 | return; | |
170 | ||
171 | cookie->arc_list_next = ar->cookie_list; | |
172 | ar->cookie_list = cookie; | |
173 | ar->cookie_count++; | |
174 | } | |
175 | ||
176 | /* set the window address register (using 4-byte register access ). */ | |
177 | static int ath6kl_set_addrwin_reg(struct ath6kl *ar, u32 reg_addr, u32 addr) | |
178 | { | |
179 | int status; | |
180 | u8 addr_val[4]; | |
181 | s32 i; | |
182 | ||
183 | /* | |
184 | * Write bytes 1,2,3 of the register to set the upper address bytes, | |
185 | * the LSB is written last to initiate the access cycle | |
186 | */ | |
187 | ||
188 | for (i = 1; i <= 3; i++) { | |
189 | /* | |
190 | * Fill the buffer with the address byte value we want to | |
191 | * hit 4 times. | |
192 | */ | |
193 | memset(addr_val, ((u8 *)&addr)[i], 4); | |
194 | ||
195 | /* | |
196 | * Hit each byte of the register address with a 4-byte | |
197 | * write operation to the same address, this is a harmless | |
198 | * operation. | |
199 | */ | |
200 | status = hif_read_write_sync(ar, reg_addr + i, addr_val, | |
201 | 4, HIF_WR_SYNC_BYTE_FIX); | |
202 | if (status) | |
203 | break; | |
204 | } | |
205 | ||
206 | if (status) { | |
207 | ath6kl_err("failed to write initial bytes of 0x%x to window reg: 0x%X\n", | |
208 | addr, reg_addr); | |
209 | return status; | |
210 | } | |
211 | ||
212 | /* | |
213 | * Write the address register again, this time write the whole | |
214 | * 4-byte value. The effect here is that the LSB write causes the | |
215 | * cycle to start, the extra 3 byte write to bytes 1,2,3 has no | |
216 | * effect since we are writing the same values again | |
217 | */ | |
218 | status = hif_read_write_sync(ar, reg_addr, (u8 *)(&addr), | |
219 | 4, HIF_WR_SYNC_BYTE_INC); | |
220 | ||
221 | if (status) { | |
222 | ath6kl_err("failed to write 0x%x to window reg: 0x%X\n", | |
223 | addr, reg_addr); | |
224 | return status; | |
225 | } | |
226 | ||
227 | return 0; | |
228 | } | |
229 | ||
230 | /* | |
231 | * Read from the ATH6KL through its diagnostic window. No cooperation from | |
232 | * the Target is required for this. | |
233 | */ | |
234 | int ath6kl_read_reg_diag(struct ath6kl *ar, u32 *address, u32 *data) | |
235 | { | |
236 | int status; | |
237 | ||
238 | /* set window register to start read cycle */ | |
239 | status = ath6kl_set_addrwin_reg(ar, WINDOW_READ_ADDR_ADDRESS, | |
240 | *address); | |
241 | ||
242 | if (status) | |
243 | return status; | |
244 | ||
245 | /* read the data */ | |
246 | status = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *)data, | |
247 | sizeof(u32), HIF_RD_SYNC_BYTE_INC); | |
248 | if (status) { | |
249 | ath6kl_err("failed to read from window data addr\n"); | |
250 | return status; | |
251 | } | |
252 | ||
253 | return status; | |
254 | } | |
255 | ||
256 | ||
257 | /* | |
258 | * Write to the ATH6KL through its diagnostic window. No cooperation from | |
259 | * the Target is required for this. | |
260 | */ | |
261 | static int ath6kl_write_reg_diag(struct ath6kl *ar, u32 *address, u32 *data) | |
262 | { | |
263 | int status; | |
264 | ||
265 | /* set write data */ | |
266 | status = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *)data, | |
267 | sizeof(u32), HIF_WR_SYNC_BYTE_INC); | |
268 | if (status) { | |
269 | ath6kl_err("failed to write 0x%x to window data addr\n", *data); | |
270 | return status; | |
271 | } | |
272 | ||
273 | /* set window register, which starts the write cycle */ | |
274 | return ath6kl_set_addrwin_reg(ar, WINDOW_WRITE_ADDR_ADDRESS, | |
275 | *address); | |
276 | } | |
277 | ||
278 | int ath6kl_access_datadiag(struct ath6kl *ar, u32 address, | |
279 | u8 *data, u32 length, bool read) | |
280 | { | |
281 | u32 count; | |
282 | int status = 0; | |
283 | ||
284 | for (count = 0; count < length; count += 4, address += 4) { | |
285 | if (read) { | |
286 | status = ath6kl_read_reg_diag(ar, &address, | |
287 | (u32 *) &data[count]); | |
288 | if (status) | |
289 | break; | |
290 | } else { | |
291 | status = ath6kl_write_reg_diag(ar, &address, | |
292 | (u32 *) &data[count]); | |
293 | if (status) | |
294 | break; | |
295 | } | |
296 | } | |
297 | ||
298 | return status; | |
299 | } | |
300 | ||
31024d99 KF |
301 | /* FIXME: move to a better place, target.h? */ |
302 | #define AR6003_RESET_CONTROL_ADDRESS 0x00004000 | |
303 | #define AR6004_RESET_CONTROL_ADDRESS 0x00004000 | |
304 | ||
bdcd8170 KV |
305 | static void ath6kl_reset_device(struct ath6kl *ar, u32 target_type, |
306 | bool wait_fot_compltn, bool cold_reset) | |
307 | { | |
308 | int status = 0; | |
309 | u32 address; | |
310 | u32 data; | |
311 | ||
31024d99 KF |
312 | if (target_type != TARGET_TYPE_AR6003 && |
313 | target_type != TARGET_TYPE_AR6004) | |
bdcd8170 KV |
314 | return; |
315 | ||
316 | data = cold_reset ? RESET_CONTROL_COLD_RST : RESET_CONTROL_MBOX_RST; | |
317 | ||
31024d99 KF |
318 | switch (target_type) { |
319 | case TARGET_TYPE_AR6003: | |
320 | address = AR6003_RESET_CONTROL_ADDRESS; | |
321 | break; | |
322 | case TARGET_TYPE_AR6004: | |
323 | address = AR6004_RESET_CONTROL_ADDRESS; | |
324 | break; | |
325 | default: | |
326 | address = AR6003_RESET_CONTROL_ADDRESS; | |
327 | break; | |
328 | } | |
329 | ||
bdcd8170 KV |
330 | status = ath6kl_write_reg_diag(ar, &address, &data); |
331 | ||
332 | if (status) | |
333 | ath6kl_err("failed to reset target\n"); | |
334 | } | |
335 | ||
336 | void ath6kl_stop_endpoint(struct net_device *dev, bool keep_profile, | |
337 | bool get_dbglogs) | |
338 | { | |
339 | struct ath6kl *ar = ath6kl_priv(dev); | |
340 | static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
341 | bool discon_issued; | |
342 | ||
343 | netif_stop_queue(dev); | |
344 | ||
345 | /* disable the target and the interrupts associated with it */ | |
346 | if (test_bit(WMI_READY, &ar->flag)) { | |
347 | discon_issued = (test_bit(CONNECTED, &ar->flag) || | |
348 | test_bit(CONNECT_PEND, &ar->flag)); | |
349 | ath6kl_disconnect(ar); | |
350 | if (!keep_profile) | |
351 | ath6kl_init_profile_info(ar); | |
352 | ||
353 | del_timer(&ar->disconnect_timer); | |
354 | ||
355 | clear_bit(WMI_READY, &ar->flag); | |
356 | ath6kl_wmi_shutdown(ar->wmi); | |
357 | clear_bit(WMI_ENABLED, &ar->flag); | |
358 | ar->wmi = NULL; | |
359 | ||
360 | /* | |
361 | * After wmi_shudown all WMI events will be dropped. We | |
362 | * need to cleanup the buffers allocated in AP mode and | |
363 | * give disconnect notification to stack, which usually | |
364 | * happens in the disconnect_event. Simulate the disconnect | |
365 | * event by calling the function directly. Sometimes | |
366 | * disconnect_event will be received when the debug logs | |
367 | * are collected. | |
368 | */ | |
369 | if (discon_issued) | |
370 | ath6kl_disconnect_event(ar, DISCONNECT_CMD, | |
371 | (ar->nw_type & AP_NETWORK) ? | |
372 | bcast_mac : ar->bssid, | |
373 | 0, NULL, 0); | |
374 | ||
375 | ar->user_key_ctrl = 0; | |
376 | ||
377 | } else { | |
378 | ath6kl_dbg(ATH6KL_DBG_TRC, | |
379 | "%s: wmi is not ready 0x%p 0x%p\n", | |
380 | __func__, ar, ar->wmi); | |
381 | ||
382 | /* Shut down WMI if we have started it */ | |
383 | if (test_bit(WMI_ENABLED, &ar->flag)) { | |
384 | ath6kl_dbg(ATH6KL_DBG_TRC, | |
385 | "%s: shut down wmi\n", __func__); | |
386 | ath6kl_wmi_shutdown(ar->wmi); | |
387 | clear_bit(WMI_ENABLED, &ar->flag); | |
388 | ar->wmi = NULL; | |
389 | } | |
390 | } | |
391 | ||
392 | if (ar->htc_target) { | |
393 | ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__); | |
ad226ec2 | 394 | ath6kl_htc_stop(ar->htc_target); |
bdcd8170 KV |
395 | } |
396 | ||
397 | /* | |
398 | * Try to reset the device if we can. The driver may have been | |
399 | * configure NOT to reset the target during a debug session. | |
400 | */ | |
401 | ath6kl_dbg(ATH6KL_DBG_TRC, | |
402 | "attempting to reset target on instance destroy\n"); | |
403 | ath6kl_reset_device(ar, ar->target_type, true, true); | |
404 | } | |
405 | ||
406 | static void ath6kl_install_static_wep_keys(struct ath6kl *ar) | |
407 | { | |
408 | u8 index; | |
409 | u8 keyusage; | |
410 | ||
411 | for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) { | |
412 | if (ar->wep_key_list[index].key_len) { | |
413 | keyusage = GROUP_USAGE; | |
414 | if (index == ar->def_txkey_index) | |
415 | keyusage |= TX_USAGE; | |
416 | ||
417 | ath6kl_wmi_addkey_cmd(ar->wmi, | |
418 | index, | |
419 | WEP_CRYPT, | |
420 | keyusage, | |
421 | ar->wep_key_list[index].key_len, | |
422 | NULL, | |
423 | ar->wep_key_list[index].key, | |
424 | KEY_OP_INIT_VAL, NULL, | |
425 | NO_SYNC_WMIFLAG); | |
426 | } | |
427 | } | |
428 | } | |
429 | ||
430 | static void ath6kl_connect_ap_mode(struct ath6kl *ar, u16 channel, u8 *bssid, | |
431 | u16 listen_int, u16 beacon_int, | |
432 | u8 assoc_resp_len, u8 *assoc_info) | |
433 | { | |
434 | struct net_device *dev = ar->net_dev; | |
435 | struct station_info sinfo; | |
436 | struct ath6kl_req_key *ik; | |
437 | enum crypto_type keyType = NONE_CRYPT; | |
438 | ||
439 | if (memcmp(dev->dev_addr, bssid, ETH_ALEN) == 0) { | |
440 | ik = &ar->ap_mode_bkey; | |
441 | ||
442 | switch (ar->auth_mode) { | |
443 | case NONE_AUTH: | |
444 | if (ar->prwise_crypto == WEP_CRYPT) | |
445 | ath6kl_install_static_wep_keys(ar); | |
446 | break; | |
447 | case WPA_PSK_AUTH: | |
448 | case WPA2_PSK_AUTH: | |
449 | case (WPA_PSK_AUTH|WPA2_PSK_AUTH): | |
450 | switch (ik->ik_type) { | |
451 | case ATH6KL_CIPHER_TKIP: | |
452 | keyType = TKIP_CRYPT; | |
453 | break; | |
454 | case ATH6KL_CIPHER_AES_CCM: | |
455 | keyType = AES_CRYPT; | |
456 | break; | |
457 | default: | |
458 | goto skip_key; | |
459 | } | |
460 | ath6kl_wmi_addkey_cmd(ar->wmi, ik->ik_keyix, keyType, | |
461 | GROUP_USAGE, ik->ik_keylen, | |
462 | (u8 *)&ik->ik_keyrsc, | |
463 | ik->ik_keydata, | |
464 | KEY_OP_INIT_VAL, ik->ik_macaddr, | |
465 | SYNC_BOTH_WMIFLAG); | |
466 | break; | |
467 | } | |
468 | skip_key: | |
469 | set_bit(CONNECTED, &ar->flag); | |
470 | return; | |
471 | } | |
472 | ||
473 | ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", | |
474 | bssid, channel); | |
475 | ||
476 | ath6kl_add_new_sta(ar, bssid, channel, assoc_info, assoc_resp_len, | |
477 | listen_int & 0xFF, beacon_int, | |
478 | (listen_int >> 8) & 0xFF); | |
479 | ||
480 | /* send event to application */ | |
481 | memset(&sinfo, 0, sizeof(sinfo)); | |
482 | ||
483 | /* TODO: sinfo.generation */ | |
484 | /* TODO: need to deliver (Re)AssocReq IEs somehow.. change in | |
485 | * cfg80211 needed, e.g., by adding those into sinfo | |
486 | */ | |
487 | cfg80211_new_sta(ar->net_dev, bssid, &sinfo, GFP_KERNEL); | |
488 | ||
489 | netif_wake_queue(ar->net_dev); | |
490 | ||
491 | return; | |
492 | } | |
493 | ||
494 | /* Functions for Tx credit handling */ | |
495 | void ath6k_credit_init(struct htc_credit_state_info *cred_info, | |
496 | struct list_head *ep_list, | |
497 | int tot_credits) | |
498 | { | |
499 | struct htc_endpoint_credit_dist *cur_ep_dist; | |
500 | int count; | |
501 | ||
502 | cred_info->cur_free_credits = tot_credits; | |
503 | cred_info->total_avail_credits = tot_credits; | |
504 | ||
505 | list_for_each_entry(cur_ep_dist, ep_list, list) { | |
506 | if (cur_ep_dist->endpoint == ENDPOINT_0) | |
507 | continue; | |
508 | ||
509 | cur_ep_dist->cred_min = cur_ep_dist->cred_per_msg; | |
510 | ||
511 | if (tot_credits > 4) | |
512 | if ((cur_ep_dist->svc_id == WMI_DATA_BK_SVC) || | |
513 | (cur_ep_dist->svc_id == WMI_DATA_BE_SVC)) { | |
514 | ath6kl_deposit_credit_to_ep(cred_info, | |
515 | cur_ep_dist, | |
516 | cur_ep_dist->cred_min); | |
517 | cur_ep_dist->dist_flags |= HTC_EP_ACTIVE; | |
518 | } | |
519 | ||
520 | if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) { | |
521 | ath6kl_deposit_credit_to_ep(cred_info, cur_ep_dist, | |
522 | cur_ep_dist->cred_min); | |
523 | /* | |
524 | * Control service is always marked active, it | |
525 | * never goes inactive EVER. | |
526 | */ | |
527 | cur_ep_dist->dist_flags |= HTC_EP_ACTIVE; | |
528 | } else if (cur_ep_dist->svc_id == WMI_DATA_BK_SVC) | |
529 | /* this is the lowest priority data endpoint */ | |
530 | cred_info->lowestpri_ep_dist = cur_ep_dist->list; | |
531 | ||
532 | /* | |
533 | * Streams have to be created (explicit | implicit) for all | |
534 | * kinds of traffic. BE endpoints are also inactive in the | |
535 | * beginning. When BE traffic starts it creates implicit | |
536 | * streams that redistributes credits. | |
537 | * | |
538 | * Note: all other endpoints have minimums set but are | |
539 | * initially given NO credits. credits will be distributed | |
540 | * as traffic activity demands | |
541 | */ | |
542 | } | |
543 | ||
544 | WARN_ON(cred_info->cur_free_credits <= 0); | |
545 | ||
546 | list_for_each_entry(cur_ep_dist, ep_list, list) { | |
547 | if (cur_ep_dist->endpoint == ENDPOINT_0) | |
548 | continue; | |
549 | ||
550 | if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) | |
551 | cur_ep_dist->cred_norm = cur_ep_dist->cred_per_msg; | |
552 | else { | |
553 | /* | |
554 | * For the remaining data endpoints, we assume that | |
555 | * each cred_per_msg are the same. We use a simple | |
556 | * calculation here, we take the remaining credits | |
557 | * and determine how many max messages this can | |
558 | * cover and then set each endpoint's normal value | |
559 | * equal to 3/4 this amount. | |
560 | */ | |
561 | count = (cred_info->cur_free_credits / | |
562 | cur_ep_dist->cred_per_msg) | |
563 | * cur_ep_dist->cred_per_msg; | |
564 | count = (count * 3) >> 2; | |
565 | count = max(count, cur_ep_dist->cred_per_msg); | |
566 | cur_ep_dist->cred_norm = count; | |
567 | ||
568 | } | |
569 | } | |
570 | } | |
571 | ||
572 | /* initialize and setup credit distribution */ | |
573 | int ath6k_setup_credit_dist(void *htc_handle, | |
574 | struct htc_credit_state_info *cred_info) | |
575 | { | |
576 | u16 servicepriority[5]; | |
577 | ||
578 | memset(cred_info, 0, sizeof(struct htc_credit_state_info)); | |
579 | ||
580 | servicepriority[0] = WMI_CONTROL_SVC; /* highest */ | |
581 | servicepriority[1] = WMI_DATA_VO_SVC; | |
582 | servicepriority[2] = WMI_DATA_VI_SVC; | |
583 | servicepriority[3] = WMI_DATA_BE_SVC; | |
584 | servicepriority[4] = WMI_DATA_BK_SVC; /* lowest */ | |
585 | ||
586 | /* set priority list */ | |
ad226ec2 | 587 | ath6kl_htc_set_credit_dist(htc_handle, cred_info, servicepriority, 5); |
bdcd8170 KV |
588 | |
589 | return 0; | |
590 | } | |
591 | ||
592 | /* reduce an ep's credits back to a set limit */ | |
593 | static void ath6k_reduce_credits(struct htc_credit_state_info *cred_info, | |
594 | struct htc_endpoint_credit_dist *ep_dist, | |
595 | int limit) | |
596 | { | |
597 | int credits; | |
598 | ||
599 | ep_dist->cred_assngd = limit; | |
600 | ||
601 | if (ep_dist->credits <= limit) | |
602 | return; | |
603 | ||
604 | credits = ep_dist->credits - limit; | |
605 | ep_dist->credits -= credits; | |
606 | cred_info->cur_free_credits += credits; | |
607 | } | |
608 | ||
609 | static void ath6k_credit_update(struct htc_credit_state_info *cred_info, | |
610 | struct list_head *epdist_list) | |
611 | { | |
612 | struct htc_endpoint_credit_dist *cur_dist_list; | |
613 | ||
614 | list_for_each_entry(cur_dist_list, epdist_list, list) { | |
615 | if (cur_dist_list->endpoint == ENDPOINT_0) | |
616 | continue; | |
617 | ||
618 | if (cur_dist_list->cred_to_dist > 0) { | |
619 | cur_dist_list->credits += | |
620 | cur_dist_list->cred_to_dist; | |
621 | cur_dist_list->cred_to_dist = 0; | |
622 | if (cur_dist_list->credits > | |
623 | cur_dist_list->cred_assngd) | |
624 | ath6k_reduce_credits(cred_info, | |
625 | cur_dist_list, | |
626 | cur_dist_list->cred_assngd); | |
627 | ||
628 | if (cur_dist_list->credits > | |
629 | cur_dist_list->cred_norm) | |
630 | ath6k_reduce_credits(cred_info, cur_dist_list, | |
631 | cur_dist_list->cred_norm); | |
632 | ||
633 | if (!(cur_dist_list->dist_flags & HTC_EP_ACTIVE)) { | |
634 | if (cur_dist_list->txq_depth == 0) | |
635 | ath6k_reduce_credits(cred_info, | |
636 | cur_dist_list, 0); | |
637 | } | |
638 | } | |
639 | } | |
640 | } | |
641 | ||
642 | /* | |
643 | * HTC has an endpoint that needs credits, ep_dist is the endpoint in | |
644 | * question. | |
645 | */ | |
646 | void ath6k_seek_credits(struct htc_credit_state_info *cred_info, | |
647 | struct htc_endpoint_credit_dist *ep_dist) | |
648 | { | |
649 | struct htc_endpoint_credit_dist *curdist_list; | |
650 | int credits = 0; | |
651 | int need; | |
652 | ||
653 | if (ep_dist->svc_id == WMI_CONTROL_SVC) | |
654 | goto out; | |
655 | ||
656 | if ((ep_dist->svc_id == WMI_DATA_VI_SVC) || | |
657 | (ep_dist->svc_id == WMI_DATA_VO_SVC)) | |
658 | if ((ep_dist->cred_assngd >= ep_dist->cred_norm)) | |
659 | goto out; | |
660 | ||
661 | /* | |
662 | * For all other services, we follow a simple algorithm of: | |
663 | * | |
664 | * 1. checking the free pool for credits | |
665 | * 2. checking lower priority endpoints for credits to take | |
666 | */ | |
667 | ||
668 | credits = min(cred_info->cur_free_credits, ep_dist->seek_cred); | |
669 | ||
670 | if (credits >= ep_dist->seek_cred) | |
671 | goto out; | |
672 | ||
673 | /* | |
674 | * We don't have enough in the free pool, try taking away from | |
675 | * lower priority services The rule for taking away credits: | |
676 | * | |
677 | * 1. Only take from lower priority endpoints | |
678 | * 2. Only take what is allocated above the minimum (never | |
679 | * starve an endpoint completely) | |
680 | * 3. Only take what you need. | |
681 | */ | |
682 | ||
683 | list_for_each_entry_reverse(curdist_list, | |
684 | &cred_info->lowestpri_ep_dist, | |
685 | list) { | |
686 | if (curdist_list == ep_dist) | |
687 | break; | |
688 | ||
689 | need = ep_dist->seek_cred - cred_info->cur_free_credits; | |
690 | ||
691 | if ((curdist_list->cred_assngd - need) >= | |
692 | curdist_list->cred_min) { | |
693 | /* | |
694 | * The current one has been allocated more than | |
695 | * it's minimum and it has enough credits assigned | |
696 | * above it's minimum to fulfill our need try to | |
697 | * take away just enough to fulfill our need. | |
698 | */ | |
699 | ath6k_reduce_credits(cred_info, curdist_list, | |
700 | curdist_list->cred_assngd - need); | |
701 | ||
702 | if (cred_info->cur_free_credits >= | |
703 | ep_dist->seek_cred) | |
704 | break; | |
705 | } | |
706 | ||
707 | if (curdist_list->endpoint == ENDPOINT_0) | |
708 | break; | |
709 | } | |
710 | ||
711 | credits = min(cred_info->cur_free_credits, ep_dist->seek_cred); | |
712 | ||
713 | out: | |
714 | /* did we find some credits? */ | |
715 | if (credits) | |
716 | ath6kl_deposit_credit_to_ep(cred_info, ep_dist, credits); | |
717 | ||
718 | ep_dist->seek_cred = 0; | |
719 | } | |
720 | ||
721 | /* redistribute credits based on activity change */ | |
722 | static void ath6k_redistribute_credits(struct htc_credit_state_info *info, | |
723 | struct list_head *ep_dist_list) | |
724 | { | |
725 | struct htc_endpoint_credit_dist *curdist_list; | |
726 | ||
727 | list_for_each_entry(curdist_list, ep_dist_list, list) { | |
728 | if (curdist_list->endpoint == ENDPOINT_0) | |
729 | continue; | |
730 | ||
731 | if ((curdist_list->svc_id == WMI_DATA_BK_SVC) || | |
732 | (curdist_list->svc_id == WMI_DATA_BE_SVC)) | |
733 | curdist_list->dist_flags |= HTC_EP_ACTIVE; | |
734 | ||
735 | if ((curdist_list->svc_id != WMI_CONTROL_SVC) && | |
736 | !(curdist_list->dist_flags & HTC_EP_ACTIVE)) { | |
737 | if (curdist_list->txq_depth == 0) | |
738 | ath6k_reduce_credits(info, | |
739 | curdist_list, 0); | |
740 | else | |
741 | ath6k_reduce_credits(info, | |
742 | curdist_list, | |
743 | curdist_list->cred_min); | |
744 | } | |
745 | } | |
746 | } | |
747 | ||
748 | /* | |
749 | * | |
750 | * This function is invoked whenever endpoints require credit | |
751 | * distributions. A lock is held while this function is invoked, this | |
752 | * function shall NOT block. The ep_dist_list is a list of distribution | |
753 | * structures in prioritized order as defined by the call to the | |
754 | * htc_set_credit_dist() api. | |
755 | */ | |
756 | void ath6k_credit_distribute(struct htc_credit_state_info *cred_info, | |
757 | struct list_head *ep_dist_list, | |
758 | enum htc_credit_dist_reason reason) | |
759 | { | |
760 | switch (reason) { | |
761 | case HTC_CREDIT_DIST_SEND_COMPLETE: | |
762 | ath6k_credit_update(cred_info, ep_dist_list); | |
763 | break; | |
764 | case HTC_CREDIT_DIST_ACTIVITY_CHANGE: | |
765 | ath6k_redistribute_credits(cred_info, ep_dist_list); | |
766 | break; | |
767 | default: | |
768 | break; | |
769 | } | |
770 | ||
771 | WARN_ON(cred_info->cur_free_credits > cred_info->total_avail_credits); | |
772 | WARN_ON(cred_info->cur_free_credits < 0); | |
773 | } | |
774 | ||
775 | void disconnect_timer_handler(unsigned long ptr) | |
776 | { | |
777 | struct net_device *dev = (struct net_device *)ptr; | |
778 | struct ath6kl *ar = ath6kl_priv(dev); | |
779 | ||
780 | ath6kl_init_profile_info(ar); | |
781 | ath6kl_disconnect(ar); | |
782 | } | |
783 | ||
784 | void ath6kl_disconnect(struct ath6kl *ar) | |
785 | { | |
786 | if (test_bit(CONNECTED, &ar->flag) || | |
787 | test_bit(CONNECT_PEND, &ar->flag)) { | |
788 | ath6kl_wmi_disconnect_cmd(ar->wmi); | |
789 | /* | |
790 | * Disconnect command is issued, clear the connect pending | |
791 | * flag. The connected flag will be cleared in | |
792 | * disconnect event notification. | |
793 | */ | |
794 | clear_bit(CONNECT_PEND, &ar->flag); | |
795 | } | |
796 | } | |
797 | ||
abcb344b KV |
798 | void ath6kl_deep_sleep_enable(struct ath6kl *ar) |
799 | { | |
800 | switch (ar->sme_state) { | |
801 | case SME_CONNECTING: | |
802 | cfg80211_connect_result(ar->net_dev, ar->bssid, NULL, 0, | |
803 | NULL, 0, | |
804 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
805 | GFP_KERNEL); | |
806 | break; | |
807 | case SME_CONNECTED: | |
808 | default: | |
809 | /* | |
810 | * FIXME: oddly enough smeState is in DISCONNECTED during | |
811 | * suspend, why? Need to send disconnected event in that | |
812 | * state. | |
813 | */ | |
814 | cfg80211_disconnected(ar->net_dev, 0, NULL, 0, GFP_KERNEL); | |
815 | break; | |
816 | } | |
817 | ||
818 | if (test_bit(CONNECTED, &ar->flag) || | |
819 | test_bit(CONNECT_PEND, &ar->flag)) | |
820 | ath6kl_wmi_disconnect_cmd(ar->wmi); | |
821 | ||
822 | ar->sme_state = SME_DISCONNECTED; | |
823 | ||
824 | /* disable scanning */ | |
825 | if (ath6kl_wmi_scanparams_cmd(ar->wmi, 0xFFFF, 0, 0, 0, 0, 0, 0, 0, | |
826 | 0, 0) != 0) | |
827 | printk(KERN_WARNING "ath6kl: failed to disable scan " | |
828 | "during suspend\n"); | |
829 | ||
830 | ath6kl_cfg80211_scan_complete_event(ar, -ECANCELED); | |
831 | } | |
832 | ||
bdcd8170 KV |
833 | /* WMI Event handlers */ |
834 | ||
835 | static const char *get_hw_id_string(u32 id) | |
836 | { | |
837 | switch (id) { | |
838 | case AR6003_REV1_VERSION: | |
839 | return "1.0"; | |
840 | case AR6003_REV2_VERSION: | |
841 | return "2.0"; | |
842 | case AR6003_REV3_VERSION: | |
843 | return "2.1.1"; | |
844 | default: | |
845 | return "unknown"; | |
846 | } | |
847 | } | |
848 | ||
849 | void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver) | |
850 | { | |
851 | struct ath6kl *ar = devt; | |
852 | struct net_device *dev = ar->net_dev; | |
853 | ||
854 | memcpy(dev->dev_addr, datap, ETH_ALEN); | |
855 | ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n", | |
856 | __func__, dev->dev_addr); | |
857 | ||
858 | ar->version.wlan_ver = sw_ver; | |
859 | ar->version.abi_ver = abi_ver; | |
860 | ||
861 | snprintf(ar->wdev->wiphy->fw_version, | |
862 | sizeof(ar->wdev->wiphy->fw_version), | |
863 | "%u.%u.%u.%u", | |
864 | (ar->version.wlan_ver & 0xf0000000) >> 28, | |
865 | (ar->version.wlan_ver & 0x0f000000) >> 24, | |
866 | (ar->version.wlan_ver & 0x00ff0000) >> 16, | |
867 | (ar->version.wlan_ver & 0x0000ffff)); | |
868 | ||
869 | /* indicate to the waiting thread that the ready event was received */ | |
870 | set_bit(WMI_READY, &ar->flag); | |
871 | wake_up(&ar->event_wq); | |
872 | ||
873 | ath6kl_info("hw %s fw %s\n", | |
874 | get_hw_id_string(ar->wdev->wiphy->hw_version), | |
875 | ar->wdev->wiphy->fw_version); | |
876 | } | |
877 | ||
878 | void ath6kl_scan_complete_evt(struct ath6kl *ar, int status) | |
879 | { | |
880 | ath6kl_cfg80211_scan_complete_event(ar, status); | |
881 | ||
882 | if (!ar->usr_bss_filter) | |
883 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); | |
884 | ||
885 | ath6kl_dbg(ATH6KL_DBG_WLAN_SCAN, "scan complete: %d\n", status); | |
886 | } | |
887 | ||
888 | void ath6kl_connect_event(struct ath6kl *ar, u16 channel, u8 *bssid, | |
889 | u16 listen_int, u16 beacon_int, | |
890 | enum network_type net_type, u8 beacon_ie_len, | |
891 | u8 assoc_req_len, u8 assoc_resp_len, | |
892 | u8 *assoc_info) | |
893 | { | |
894 | unsigned long flags; | |
895 | ||
896 | if (ar->nw_type == AP_NETWORK) { | |
897 | ath6kl_connect_ap_mode(ar, channel, bssid, listen_int, | |
898 | beacon_int, assoc_resp_len, | |
899 | assoc_info); | |
900 | return; | |
901 | } | |
902 | ||
903 | ath6kl_cfg80211_connect_event(ar, channel, bssid, | |
904 | listen_int, beacon_int, | |
905 | net_type, beacon_ie_len, | |
906 | assoc_req_len, assoc_resp_len, | |
907 | assoc_info); | |
908 | ||
909 | memcpy(ar->bssid, bssid, sizeof(ar->bssid)); | |
910 | ar->bss_ch = channel; | |
911 | ||
912 | if ((ar->nw_type == INFRA_NETWORK)) | |
913 | ath6kl_wmi_listeninterval_cmd(ar->wmi, ar->listen_intvl_t, | |
914 | ar->listen_intvl_b); | |
915 | ||
916 | netif_wake_queue(ar->net_dev); | |
917 | ||
918 | /* Update connect & link status atomically */ | |
919 | spin_lock_irqsave(&ar->lock, flags); | |
920 | set_bit(CONNECTED, &ar->flag); | |
921 | clear_bit(CONNECT_PEND, &ar->flag); | |
922 | netif_carrier_on(ar->net_dev); | |
923 | spin_unlock_irqrestore(&ar->lock, flags); | |
924 | ||
925 | aggr_reset_state(ar->aggr_cntxt); | |
926 | ar->reconnect_flag = 0; | |
927 | ||
928 | if ((ar->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) { | |
929 | memset(ar->node_map, 0, sizeof(ar->node_map)); | |
930 | ar->node_num = 0; | |
931 | ar->next_ep_id = ENDPOINT_2; | |
932 | } | |
933 | ||
934 | if (!ar->usr_bss_filter) | |
935 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); | |
936 | } | |
937 | ||
938 | void ath6kl_tkip_micerr_event(struct ath6kl *ar, u8 keyid, bool ismcast) | |
939 | { | |
940 | struct ath6kl_sta *sta; | |
941 | u8 tsc[6]; | |
942 | /* | |
943 | * For AP case, keyid will have aid of STA which sent pkt with | |
944 | * MIC error. Use this aid to get MAC & send it to hostapd. | |
945 | */ | |
946 | if (ar->nw_type == AP_NETWORK) { | |
947 | sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2)); | |
948 | if (!sta) | |
949 | return; | |
950 | ||
951 | ath6kl_dbg(ATH6KL_DBG_TRC, | |
952 | "ap tkip mic error received from aid=%d\n", keyid); | |
953 | ||
954 | memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */ | |
955 | cfg80211_michael_mic_failure(ar->net_dev, sta->mac, | |
956 | NL80211_KEYTYPE_PAIRWISE, keyid, | |
957 | tsc, GFP_KERNEL); | |
958 | } else | |
959 | ath6kl_cfg80211_tkip_micerr_event(ar, keyid, ismcast); | |
960 | ||
961 | } | |
962 | ||
963 | static void ath6kl_update_target_stats(struct ath6kl *ar, u8 *ptr, u32 len) | |
964 | { | |
965 | struct wmi_target_stats *tgt_stats = | |
966 | (struct wmi_target_stats *) ptr; | |
967 | struct target_stats *stats = &ar->target_stats; | |
968 | struct tkip_ccmp_stats *ccmp_stats; | |
969 | struct bss *conn_bss = NULL; | |
970 | struct cserv_stats *c_stats; | |
971 | u8 ac; | |
972 | ||
973 | if (len < sizeof(*tgt_stats)) | |
974 | return; | |
975 | ||
976 | /* update the RSSI of the connected bss */ | |
977 | if (test_bit(CONNECTED, &ar->flag)) { | |
978 | conn_bss = ath6kl_wmi_find_node(ar->wmi, ar->bssid); | |
979 | if (conn_bss) { | |
980 | c_stats = &tgt_stats->cserv_stats; | |
981 | conn_bss->ni_rssi = | |
982 | a_sle16_to_cpu(c_stats->cs_ave_beacon_rssi); | |
983 | conn_bss->ni_snr = | |
984 | tgt_stats->cserv_stats.cs_ave_beacon_snr; | |
985 | ath6kl_wmi_node_return(ar->wmi, conn_bss); | |
986 | } | |
987 | } | |
988 | ||
989 | ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n"); | |
990 | ||
991 | stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt); | |
992 | stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte); | |
993 | stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt); | |
994 | stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte); | |
995 | stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt); | |
996 | stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte); | |
997 | stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt); | |
998 | stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte); | |
999 | stats->tx_rts_success_cnt += | |
1000 | le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt); | |
1001 | ||
1002 | for (ac = 0; ac < WMM_NUM_AC; ac++) | |
1003 | stats->tx_pkt_per_ac[ac] += | |
1004 | le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]); | |
1005 | ||
1006 | stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err); | |
1007 | stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt); | |
1008 | stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt); | |
1009 | stats->tx_mult_retry_cnt += | |
1010 | le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt); | |
1011 | stats->tx_rts_fail_cnt += | |
1012 | le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt); | |
1013 | stats->tx_ucast_rate = | |
1014 | ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate)); | |
1015 | ||
1016 | stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt); | |
1017 | stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte); | |
1018 | stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt); | |
1019 | stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte); | |
1020 | stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt); | |
1021 | stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte); | |
1022 | stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt); | |
1023 | stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte); | |
1024 | stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt); | |
1025 | stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err); | |
1026 | stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err); | |
1027 | stats->rx_key_cache_miss += | |
1028 | le32_to_cpu(tgt_stats->stats.rx.key_cache_miss); | |
1029 | stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err); | |
1030 | stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame); | |
1031 | stats->rx_ucast_rate = | |
1032 | ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate)); | |
1033 | ||
1034 | ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats; | |
1035 | ||
1036 | stats->tkip_local_mic_fail += | |
1037 | le32_to_cpu(ccmp_stats->tkip_local_mic_fail); | |
1038 | stats->tkip_cnter_measures_invoked += | |
1039 | le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked); | |
1040 | stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err); | |
1041 | ||
1042 | stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err); | |
1043 | stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays); | |
1044 | ||
1045 | stats->pwr_save_fail_cnt += | |
1046 | le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt); | |
1047 | stats->noise_floor_calib = | |
1048 | a_sle32_to_cpu(tgt_stats->noise_floor_calib); | |
1049 | ||
1050 | stats->cs_bmiss_cnt += | |
1051 | le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt); | |
1052 | stats->cs_low_rssi_cnt += | |
1053 | le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt); | |
1054 | stats->cs_connect_cnt += | |
1055 | le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt); | |
1056 | stats->cs_discon_cnt += | |
1057 | le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt); | |
1058 | ||
1059 | stats->cs_ave_beacon_rssi = | |
1060 | a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi); | |
1061 | ||
1062 | stats->cs_last_roam_msec = | |
1063 | tgt_stats->cserv_stats.cs_last_roam_msec; | |
1064 | stats->cs_snr = tgt_stats->cserv_stats.cs_snr; | |
1065 | stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi); | |
1066 | ||
1067 | stats->lq_val = le32_to_cpu(tgt_stats->lq_val); | |
1068 | ||
1069 | stats->wow_pkt_dropped += | |
1070 | le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped); | |
1071 | stats->wow_host_pkt_wakeups += | |
1072 | tgt_stats->wow_stats.wow_host_pkt_wakeups; | |
1073 | stats->wow_host_evt_wakeups += | |
1074 | tgt_stats->wow_stats.wow_host_evt_wakeups; | |
1075 | stats->wow_evt_discarded += | |
1076 | le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded); | |
1077 | ||
1078 | if (test_bit(STATS_UPDATE_PEND, &ar->flag)) { | |
1079 | clear_bit(STATS_UPDATE_PEND, &ar->flag); | |
1080 | wake_up(&ar->event_wq); | |
1081 | } | |
1082 | } | |
1083 | ||
1084 | static void ath6kl_add_le32(__le32 *var, __le32 val) | |
1085 | { | |
1086 | *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val)); | |
1087 | } | |
1088 | ||
1089 | void ath6kl_tgt_stats_event(struct ath6kl *ar, u8 *ptr, u32 len) | |
1090 | { | |
1091 | struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr; | |
1092 | struct wmi_ap_mode_stat *ap = &ar->ap_stats; | |
1093 | struct wmi_per_sta_stat *st_ap, *st_p; | |
1094 | u8 ac; | |
1095 | ||
1096 | if (ar->nw_type == AP_NETWORK) { | |
1097 | if (len < sizeof(*p)) | |
1098 | return; | |
1099 | ||
1100 | for (ac = 0; ac < AP_MAX_NUM_STA; ac++) { | |
1101 | st_ap = &ap->sta[ac]; | |
1102 | st_p = &p->sta[ac]; | |
1103 | ||
1104 | ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes); | |
1105 | ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts); | |
1106 | ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error); | |
1107 | ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard); | |
1108 | ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes); | |
1109 | ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts); | |
1110 | ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error); | |
1111 | ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard); | |
1112 | } | |
1113 | ||
1114 | } else { | |
1115 | ath6kl_update_target_stats(ar, ptr, len); | |
1116 | } | |
1117 | } | |
1118 | ||
1119 | void ath6kl_wakeup_event(void *dev) | |
1120 | { | |
1121 | struct ath6kl *ar = (struct ath6kl *) dev; | |
1122 | ||
1123 | wake_up(&ar->event_wq); | |
1124 | } | |
1125 | ||
1126 | void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr) | |
1127 | { | |
1128 | struct ath6kl *ar = (struct ath6kl *) devt; | |
1129 | ||
1130 | ar->tx_pwr = tx_pwr; | |
1131 | wake_up(&ar->event_wq); | |
1132 | } | |
1133 | ||
1134 | void ath6kl_pspoll_event(struct ath6kl *ar, u8 aid) | |
1135 | { | |
1136 | struct ath6kl_sta *conn; | |
1137 | struct sk_buff *skb; | |
1138 | bool psq_empty = false; | |
1139 | ||
1140 | conn = ath6kl_find_sta_by_aid(ar, aid); | |
1141 | ||
1142 | if (!conn) | |
1143 | return; | |
1144 | /* | |
1145 | * Send out a packet queued on ps queue. When the ps queue | |
1146 | * becomes empty update the PVB for this station. | |
1147 | */ | |
1148 | spin_lock_bh(&conn->psq_lock); | |
1149 | psq_empty = skb_queue_empty(&conn->psq); | |
1150 | spin_unlock_bh(&conn->psq_lock); | |
1151 | ||
1152 | if (psq_empty) | |
1153 | /* TODO: Send out a NULL data frame */ | |
1154 | return; | |
1155 | ||
1156 | spin_lock_bh(&conn->psq_lock); | |
1157 | skb = skb_dequeue(&conn->psq); | |
1158 | spin_unlock_bh(&conn->psq_lock); | |
1159 | ||
1160 | conn->sta_flags |= STA_PS_POLLED; | |
1161 | ath6kl_data_tx(skb, ar->net_dev); | |
1162 | conn->sta_flags &= ~STA_PS_POLLED; | |
1163 | ||
1164 | spin_lock_bh(&conn->psq_lock); | |
1165 | psq_empty = skb_queue_empty(&conn->psq); | |
1166 | spin_unlock_bh(&conn->psq_lock); | |
1167 | ||
1168 | if (psq_empty) | |
1169 | ath6kl_wmi_set_pvb_cmd(ar->wmi, conn->aid, 0); | |
1170 | } | |
1171 | ||
1172 | void ath6kl_dtimexpiry_event(struct ath6kl *ar) | |
1173 | { | |
1174 | bool mcastq_empty = false; | |
1175 | struct sk_buff *skb; | |
1176 | ||
1177 | /* | |
1178 | * If there are no associated STAs, ignore the DTIM expiry event. | |
1179 | * There can be potential race conditions where the last associated | |
1180 | * STA may disconnect & before the host could clear the 'Indicate | |
1181 | * DTIM' request to the firmware, the firmware would have just | |
1182 | * indicated a DTIM expiry event. The race is between 'clear DTIM | |
1183 | * expiry cmd' going from the host to the firmware & the DTIM | |
1184 | * expiry event happening from the firmware to the host. | |
1185 | */ | |
1186 | if (!ar->sta_list_index) | |
1187 | return; | |
1188 | ||
1189 | spin_lock_bh(&ar->mcastpsq_lock); | |
1190 | mcastq_empty = skb_queue_empty(&ar->mcastpsq); | |
1191 | spin_unlock_bh(&ar->mcastpsq_lock); | |
1192 | ||
1193 | if (mcastq_empty) | |
1194 | return; | |
1195 | ||
1196 | /* set the STA flag to dtim_expired for the frame to go out */ | |
1197 | set_bit(DTIM_EXPIRED, &ar->flag); | |
1198 | ||
1199 | spin_lock_bh(&ar->mcastpsq_lock); | |
1200 | while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) { | |
1201 | spin_unlock_bh(&ar->mcastpsq_lock); | |
1202 | ||
1203 | ath6kl_data_tx(skb, ar->net_dev); | |
1204 | ||
1205 | spin_lock_bh(&ar->mcastpsq_lock); | |
1206 | } | |
1207 | spin_unlock_bh(&ar->mcastpsq_lock); | |
1208 | ||
1209 | clear_bit(DTIM_EXPIRED, &ar->flag); | |
1210 | ||
1211 | /* clear the LSB of the BitMapCtl field of the TIM IE */ | |
1212 | ath6kl_wmi_set_pvb_cmd(ar->wmi, MCAST_AID, 0); | |
1213 | } | |
1214 | ||
1215 | void ath6kl_disconnect_event(struct ath6kl *ar, u8 reason, u8 *bssid, | |
1216 | u8 assoc_resp_len, u8 *assoc_info, | |
1217 | u16 prot_reason_status) | |
1218 | { | |
1219 | struct bss *wmi_ssid_node = NULL; | |
1220 | unsigned long flags; | |
1221 | ||
1222 | if (ar->nw_type == AP_NETWORK) { | |
1223 | if (!ath6kl_remove_sta(ar, bssid, prot_reason_status)) | |
1224 | return; | |
1225 | ||
1226 | /* if no more associated STAs, empty the mcast PS q */ | |
1227 | if (ar->sta_list_index == 0) { | |
1228 | spin_lock_bh(&ar->mcastpsq_lock); | |
1229 | skb_queue_purge(&ar->mcastpsq); | |
1230 | spin_unlock_bh(&ar->mcastpsq_lock); | |
1231 | ||
1232 | /* clear the LSB of the TIM IE's BitMapCtl field */ | |
1233 | if (test_bit(WMI_READY, &ar->flag)) | |
1234 | ath6kl_wmi_set_pvb_cmd(ar->wmi, MCAST_AID, 0); | |
1235 | } | |
1236 | ||
1237 | if (!is_broadcast_ether_addr(bssid)) { | |
1238 | /* send event to application */ | |
1239 | cfg80211_del_sta(ar->net_dev, bssid, GFP_KERNEL); | |
1240 | } | |
1241 | ||
1242 | clear_bit(CONNECTED, &ar->flag); | |
1243 | return; | |
1244 | } | |
1245 | ||
1246 | ath6kl_cfg80211_disconnect_event(ar, reason, bssid, | |
1247 | assoc_resp_len, assoc_info, | |
1248 | prot_reason_status); | |
1249 | ||
1250 | aggr_reset_state(ar->aggr_cntxt); | |
1251 | ||
1252 | del_timer(&ar->disconnect_timer); | |
1253 | ||
1254 | ath6kl_dbg(ATH6KL_DBG_WLAN_CONNECT, | |
1255 | "disconnect reason is %d\n", reason); | |
1256 | ||
1257 | /* | |
1258 | * If the event is due to disconnect cmd from the host, only they | |
1259 | * the target would stop trying to connect. Under any other | |
1260 | * condition, target would keep trying to connect. | |
1261 | */ | |
1262 | if (reason == DISCONNECT_CMD) { | |
1263 | if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag)) | |
1264 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); | |
1265 | } else { | |
1266 | set_bit(CONNECT_PEND, &ar->flag); | |
1267 | if (((reason == ASSOC_FAILED) && | |
1268 | (prot_reason_status == 0x11)) || | |
1269 | ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0) | |
1270 | && (ar->reconnect_flag == 1))) { | |
1271 | set_bit(CONNECTED, &ar->flag); | |
1272 | return; | |
1273 | } | |
1274 | } | |
1275 | ||
1276 | if ((reason == NO_NETWORK_AVAIL) && test_bit(WMI_READY, &ar->flag)) { | |
1277 | ath6kl_wmi_node_free(ar->wmi, bssid); | |
1278 | ||
1279 | /* | |
1280 | * In case any other same SSID nodes are present remove it, | |
1281 | * since those nodes also not available now. | |
1282 | */ | |
1283 | do { | |
1284 | /* | |
1285 | * Find the nodes based on SSID and remove it | |
1286 | * | |
1287 | * Note: This case will not work out for | |
1288 | * Hidden-SSID | |
1289 | */ | |
1290 | wmi_ssid_node = ath6kl_wmi_find_ssid_node(ar->wmi, | |
1291 | ar->ssid, | |
1292 | ar->ssid_len, | |
1293 | false, | |
1294 | true); | |
1295 | ||
1296 | if (wmi_ssid_node) | |
1297 | ath6kl_wmi_node_free(ar->wmi, | |
1298 | wmi_ssid_node->ni_macaddr); | |
1299 | ||
1300 | } while (wmi_ssid_node); | |
1301 | } | |
1302 | ||
1303 | /* update connect & link status atomically */ | |
1304 | spin_lock_irqsave(&ar->lock, flags); | |
1305 | clear_bit(CONNECTED, &ar->flag); | |
1306 | netif_carrier_off(ar->net_dev); | |
1307 | spin_unlock_irqrestore(&ar->lock, flags); | |
1308 | ||
1309 | if ((reason != CSERV_DISCONNECT) || (ar->reconnect_flag != 1)) | |
1310 | ar->reconnect_flag = 0; | |
1311 | ||
1312 | if (reason != CSERV_DISCONNECT) | |
1313 | ar->user_key_ctrl = 0; | |
1314 | ||
1315 | netif_stop_queue(ar->net_dev); | |
1316 | memset(ar->bssid, 0, sizeof(ar->bssid)); | |
1317 | ar->bss_ch = 0; | |
1318 | ||
1319 | ath6kl_tx_data_cleanup(ar); | |
1320 | } | |
1321 | ||
1322 | static int ath6kl_open(struct net_device *dev) | |
1323 | { | |
1324 | struct ath6kl *ar = ath6kl_priv(dev); | |
1325 | unsigned long flags; | |
1326 | ||
1327 | spin_lock_irqsave(&ar->lock, flags); | |
1328 | ||
575b5f34 | 1329 | set_bit(WLAN_ENABLED, &ar->flag); |
bdcd8170 KV |
1330 | |
1331 | if (test_bit(CONNECTED, &ar->flag)) { | |
1332 | netif_carrier_on(dev); | |
1333 | netif_wake_queue(dev); | |
1334 | } else | |
1335 | netif_carrier_off(dev); | |
1336 | ||
1337 | spin_unlock_irqrestore(&ar->lock, flags); | |
1338 | ||
1339 | return 0; | |
1340 | } | |
1341 | ||
1342 | static int ath6kl_close(struct net_device *dev) | |
1343 | { | |
1344 | struct ath6kl *ar = ath6kl_priv(dev); | |
1345 | ||
1346 | netif_stop_queue(dev); | |
1347 | ||
1348 | ath6kl_disconnect(ar); | |
1349 | ||
1350 | if (test_bit(WMI_READY, &ar->flag)) { | |
1351 | if (ath6kl_wmi_scanparams_cmd(ar->wmi, 0xFFFF, 0, 0, 0, 0, 0, 0, | |
1352 | 0, 0, 0)) | |
1353 | return -EIO; | |
1354 | ||
575b5f34 | 1355 | clear_bit(WLAN_ENABLED, &ar->flag); |
bdcd8170 KV |
1356 | } |
1357 | ||
1358 | ath6kl_cfg80211_scan_complete_event(ar, -ECANCELED); | |
1359 | ||
1360 | return 0; | |
1361 | } | |
1362 | ||
1363 | static struct net_device_stats *ath6kl_get_stats(struct net_device *dev) | |
1364 | { | |
1365 | struct ath6kl *ar = ath6kl_priv(dev); | |
1366 | ||
1367 | return &ar->net_stats; | |
1368 | } | |
1369 | ||
1370 | static struct net_device_ops ath6kl_netdev_ops = { | |
1371 | .ndo_open = ath6kl_open, | |
1372 | .ndo_stop = ath6kl_close, | |
1373 | .ndo_start_xmit = ath6kl_data_tx, | |
1374 | .ndo_get_stats = ath6kl_get_stats, | |
1375 | }; | |
1376 | ||
1377 | void init_netdev(struct net_device *dev) | |
1378 | { | |
1379 | dev->netdev_ops = &ath6kl_netdev_ops; | |
1380 | dev->watchdog_timeo = ATH6KL_TX_TIMEOUT; | |
1381 | ||
1382 | dev->needed_headroom = ETH_HLEN; | |
1383 | dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) + | |
1384 | sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH | |
1df94a85 | 1385 | + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES; |
bdcd8170 KV |
1386 | |
1387 | return; | |
1388 | } |