2 * Copyright (c) 2004-2011 Atheros Communications Inc.
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.
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.
23 struct ath6kl_sta
*ath6kl_find_sta(struct ath6kl
*ar
, u8
*node_addr
)
25 struct ath6kl_sta
*conn
= NULL
;
28 max_conn
= (ar
->nw_type
== AP_NETWORK
) ? AP_MAX_NUM_STA
: 0;
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
];
40 struct ath6kl_sta
*ath6kl_find_sta_by_aid(struct ath6kl
*ar
, u8 aid
)
42 struct ath6kl_sta
*conn
= NULL
;
45 for (ctr
= 0; ctr
< AP_MAX_NUM_STA
; ctr
++) {
46 if (ar
->sta_list
[ctr
].aid
== aid
) {
47 conn
= &ar
->sta_list
[ctr
];
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
)
57 struct ath6kl_sta
*sta
;
62 sta
= &ar
->sta_list
[free_slot
];
63 memcpy(sta
->mac
, mac
, ETH_ALEN
);
64 if (ielen
<= ATH6KL_MAX_IE
)
65 memcpy(sta
->wpa_ie
, wpaie
, ielen
);
67 sta
->keymgmt
= keymgmt
;
68 sta
->ucipher
= ucipher
;
71 ar
->sta_list_index
= ar
->sta_list_index
| (1 << free_slot
);
72 ar
->ap_stats
.sta
[free_slot
].aid
= cpu_to_le32(aid
);
75 static void ath6kl_sta_cleanup(struct ath6kl
*ar
, u8 i
)
77 struct ath6kl_sta
*sta
= &ar
->sta_list
[i
];
79 /* empty the queued pkts in the PS queue if any */
80 spin_lock_bh(&sta
->psq_lock
);
81 skb_queue_purge(&sta
->psq
);
82 spin_unlock_bh(&sta
->psq_lock
);
84 memset(&ar
->ap_stats
.sta
[sta
->aid
- 1], 0,
85 sizeof(struct wmi_per_sta_stat
));
86 memset(sta
->mac
, 0, ETH_ALEN
);
87 memset(sta
->wpa_ie
, 0, ATH6KL_MAX_IE
);
91 ar
->sta_list_index
= ar
->sta_list_index
& ~(1 << i
);
95 static u8
ath6kl_remove_sta(struct ath6kl
*ar
, u8
*mac
, u16 reason
)
99 if (is_zero_ether_addr(mac
))
102 if (is_broadcast_ether_addr(mac
)) {
103 ath6kl_dbg(ATH6KL_DBG_TRC
, "deleting all station\n");
105 for (i
= 0; i
< AP_MAX_NUM_STA
; i
++) {
106 if (!is_zero_ether_addr(ar
->sta_list
[i
].mac
)) {
107 ath6kl_sta_cleanup(ar
, i
);
112 for (i
= 0; i
< AP_MAX_NUM_STA
; i
++) {
113 if (memcmp(ar
->sta_list
[i
].mac
, mac
, ETH_ALEN
) == 0) {
114 ath6kl_dbg(ATH6KL_DBG_TRC
,
115 "deleting station %pM aid=%d reason=%d\n",
116 mac
, ar
->sta_list
[i
].aid
, reason
);
117 ath6kl_sta_cleanup(ar
, i
);
127 enum htc_endpoint_id
ath6kl_ac2_endpoint_id(void *devt
, u8 ac
)
129 struct ath6kl
*ar
= devt
;
130 return ar
->ac2ep_map
[ac
];
133 struct ath6kl_cookie
*ath6kl_alloc_cookie(struct ath6kl
*ar
)
135 struct ath6kl_cookie
*cookie
;
137 cookie
= ar
->cookie_list
;
138 if (cookie
!= NULL
) {
139 ar
->cookie_list
= cookie
->arc_list_next
;
146 void ath6kl_cookie_init(struct ath6kl
*ar
)
150 ar
->cookie_list
= NULL
;
151 ar
->cookie_count
= 0;
153 memset(ar
->cookie_mem
, 0, sizeof(ar
->cookie_mem
));
155 for (i
= 0; i
< MAX_COOKIE_NUM
; i
++)
156 ath6kl_free_cookie(ar
, &ar
->cookie_mem
[i
]);
159 void ath6kl_cookie_cleanup(struct ath6kl
*ar
)
161 ar
->cookie_list
= NULL
;
162 ar
->cookie_count
= 0;
165 void ath6kl_free_cookie(struct ath6kl
*ar
, struct ath6kl_cookie
*cookie
)
172 cookie
->arc_list_next
= ar
->cookie_list
;
173 ar
->cookie_list
= cookie
;
177 /* set the window address register (using 4-byte register access ). */
178 static int ath6kl_set_addrwin_reg(struct ath6kl
*ar
, u32 reg_addr
, u32 addr
)
185 * Write bytes 1,2,3 of the register to set the upper address bytes,
186 * the LSB is written last to initiate the access cycle
189 for (i
= 1; i
<= 3; i
++) {
191 * Fill the buffer with the address byte value we want to
192 * hit 4 times. No need to worry about endianness as the
193 * same byte is copied to all four bytes of addr_val at
196 memset((u8
*)&addr_val
, ((u8
*)&addr
)[i
], 4);
199 * Hit each byte of the register address with a 4-byte
200 * write operation to the same address, this is a harmless
203 status
= hif_read_write_sync(ar
, reg_addr
+ i
, (u8
*)&addr_val
,
204 4, HIF_WR_SYNC_BYTE_FIX
);
210 ath6kl_err("failed to write initial bytes of 0x%x to window reg: 0x%X\n",
216 * Write the address register again, this time write the whole
217 * 4-byte value. The effect here is that the LSB write causes the
218 * cycle to start, the extra 3 byte write to bytes 1,2,3 has no
219 * effect since we are writing the same values again
221 addr_val
= cpu_to_le32(addr
);
222 status
= hif_read_write_sync(ar
, reg_addr
,
224 4, HIF_WR_SYNC_BYTE_INC
);
227 ath6kl_err("failed to write 0x%x to window reg: 0x%X\n",
236 * Read from the hardware through its diagnostic window. No cooperation
237 * from the firmware is required for this.
239 int ath6kl_diag_read32(struct ath6kl
*ar
, u32 address
, u32
*value
)
243 /* set window register to start read cycle */
244 ret
= ath6kl_set_addrwin_reg(ar
, WINDOW_READ_ADDR_ADDRESS
, address
);
249 ret
= hif_read_write_sync(ar
, WINDOW_DATA_ADDRESS
, (u8
*) value
,
250 sizeof(*value
), HIF_RD_SYNC_BYTE_INC
);
252 ath6kl_warn("failed to read32 through diagnose window: %d\n",
261 * Write to the ATH6KL through its diagnostic window. No cooperation from
262 * the Target is required for this.
264 int ath6kl_diag_write32(struct ath6kl
*ar
, u32 address
, u32 value
)
269 ret
= hif_read_write_sync(ar
, WINDOW_DATA_ADDRESS
, (u8
*) &value
,
270 sizeof(value
), HIF_WR_SYNC_BYTE_INC
);
272 ath6kl_err("failed to write 0x%x during diagnose window to 0x%d\n",
277 /* set window register, which starts the write cycle */
278 return ath6kl_set_addrwin_reg(ar
, WINDOW_WRITE_ADDR_ADDRESS
,
282 int ath6kl_diag_read(struct ath6kl
*ar
, u32 address
, void *data
, u32 length
)
284 u32 count
, *buf
= data
;
287 if (WARN_ON(length
% 4))
290 for (count
= 0; count
< length
/ 4; count
++, address
+= 4) {
291 ret
= ath6kl_diag_read32(ar
, address
, &buf
[count
]);
299 int ath6kl_diag_write(struct ath6kl
*ar
, u32 address
, void *data
, u32 length
)
301 u32 count
, *buf
= data
;
304 if (WARN_ON(length
% 4))
307 for (count
= 0; count
< length
/ 4; count
++, address
+= 4) {
308 ret
= ath6kl_diag_write32(ar
, address
, buf
[count
]);
316 int ath6kl_read_fwlogs(struct ath6kl
*ar
)
318 struct ath6kl_dbglog_hdr debug_hdr
;
319 struct ath6kl_dbglog_buf debug_buf
;
320 u32 address
, length
, dropped
, firstbuf
, debug_hdr_addr
;
324 buf
= kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE
, GFP_KERNEL
);
328 address
= TARG_VTOP(ar
->target_type
,
329 ath6kl_get_hi_item_addr(ar
,
330 HI_ITEM(hi_dbglog_hdr
)));
332 ret
= ath6kl_diag_read32(ar
, address
, &debug_hdr_addr
);
336 /* Get the contents of the ring buffer */
337 if (debug_hdr_addr
== 0) {
338 ath6kl_warn("Invalid address for debug_hdr_addr\n");
343 address
= TARG_VTOP(ar
->target_type
, debug_hdr_addr
);
344 ath6kl_diag_read(ar
, address
, &debug_hdr
, sizeof(debug_hdr
));
346 address
= TARG_VTOP(ar
->target_type
,
347 le32_to_cpu(debug_hdr
.dbuf_addr
));
349 dropped
= le32_to_cpu(debug_hdr
.dropped
);
350 ath6kl_diag_read(ar
, address
, &debug_buf
, sizeof(debug_buf
));
355 address
= TARG_VTOP(ar
->target_type
,
356 le32_to_cpu(debug_buf
.buffer_addr
));
357 length
= le32_to_cpu(debug_buf
.length
);
359 if (length
!= 0 && (le32_to_cpu(debug_buf
.length
) <=
360 le32_to_cpu(debug_buf
.bufsize
))) {
361 length
= ALIGN(length
, 4);
363 ret
= ath6kl_diag_read(ar
, address
,
368 ath6kl_debug_fwlog_event(ar
, buf
, length
);
371 address
= TARG_VTOP(ar
->target_type
,
372 le32_to_cpu(debug_buf
.next
));
373 ath6kl_diag_read(ar
, address
, &debug_buf
, sizeof(debug_buf
));
379 if (WARN_ON(loop
== 0)) {
383 } while (address
!= firstbuf
);
391 /* FIXME: move to a better place, target.h? */
392 #define AR6003_RESET_CONTROL_ADDRESS 0x00004000
393 #define AR6004_RESET_CONTROL_ADDRESS 0x00004000
395 static void ath6kl_reset_device(struct ath6kl
*ar
, u32 target_type
,
396 bool wait_fot_compltn
, bool cold_reset
)
402 if (target_type
!= TARGET_TYPE_AR6003
&&
403 target_type
!= TARGET_TYPE_AR6004
)
406 data
= cold_reset
? RESET_CONTROL_COLD_RST
: RESET_CONTROL_MBOX_RST
;
408 switch (target_type
) {
409 case TARGET_TYPE_AR6003
:
410 address
= AR6003_RESET_CONTROL_ADDRESS
;
412 case TARGET_TYPE_AR6004
:
413 address
= AR6004_RESET_CONTROL_ADDRESS
;
416 address
= AR6003_RESET_CONTROL_ADDRESS
;
420 status
= ath6kl_diag_write32(ar
, address
, data
);
423 ath6kl_err("failed to reset target\n");
426 void ath6kl_stop_endpoint(struct net_device
*dev
, bool keep_profile
,
429 struct ath6kl
*ar
= ath6kl_priv(dev
);
430 static u8 bcast_mac
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
433 netif_stop_queue(dev
);
435 /* disable the target and the interrupts associated with it */
436 if (test_bit(WMI_READY
, &ar
->flag
)) {
437 discon_issued
= (test_bit(CONNECTED
, &ar
->flag
) ||
438 test_bit(CONNECT_PEND
, &ar
->flag
));
439 ath6kl_disconnect(ar
);
441 ath6kl_init_profile_info(ar
);
443 del_timer(&ar
->disconnect_timer
);
445 clear_bit(WMI_READY
, &ar
->flag
);
446 ath6kl_wmi_shutdown(ar
->wmi
);
447 clear_bit(WMI_ENABLED
, &ar
->flag
);
451 * After wmi_shudown all WMI events will be dropped. We
452 * need to cleanup the buffers allocated in AP mode and
453 * give disconnect notification to stack, which usually
454 * happens in the disconnect_event. Simulate the disconnect
455 * event by calling the function directly. Sometimes
456 * disconnect_event will be received when the debug logs
460 ath6kl_disconnect_event(ar
, DISCONNECT_CMD
,
461 (ar
->nw_type
& AP_NETWORK
) ?
462 bcast_mac
: ar
->bssid
,
465 ar
->user_key_ctrl
= 0;
468 ath6kl_dbg(ATH6KL_DBG_TRC
,
469 "%s: wmi is not ready 0x%p 0x%p\n",
470 __func__
, ar
, ar
->wmi
);
472 /* Shut down WMI if we have started it */
473 if (test_bit(WMI_ENABLED
, &ar
->flag
)) {
474 ath6kl_dbg(ATH6KL_DBG_TRC
,
475 "%s: shut down wmi\n", __func__
);
476 ath6kl_wmi_shutdown(ar
->wmi
);
477 clear_bit(WMI_ENABLED
, &ar
->flag
);
482 if (ar
->htc_target
) {
483 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: shut down htc\n", __func__
);
484 ath6kl_htc_stop(ar
->htc_target
);
488 * Try to reset the device if we can. The driver may have been
489 * configure NOT to reset the target during a debug session.
491 ath6kl_dbg(ATH6KL_DBG_TRC
,
492 "attempting to reset target on instance destroy\n");
493 ath6kl_reset_device(ar
, ar
->target_type
, true, true);
496 static void ath6kl_install_static_wep_keys(struct ath6kl
*ar
)
501 for (index
= WMI_MIN_KEY_INDEX
; index
<= WMI_MAX_KEY_INDEX
; index
++) {
502 if (ar
->wep_key_list
[index
].key_len
) {
503 keyusage
= GROUP_USAGE
;
504 if (index
== ar
->def_txkey_index
)
505 keyusage
|= TX_USAGE
;
507 ath6kl_wmi_addkey_cmd(ar
->wmi
,
511 ar
->wep_key_list
[index
].key_len
,
513 ar
->wep_key_list
[index
].key
,
514 KEY_OP_INIT_VAL
, NULL
,
520 static void ath6kl_connect_ap_mode(struct ath6kl
*ar
, u16 channel
, u8
*bssid
,
521 u16 listen_int
, u16 beacon_int
,
522 u8 assoc_req_len
, u8
*assoc_info
)
524 struct net_device
*dev
= ar
->net_dev
;
525 u8
*ies
= NULL
, *wpa_ie
= NULL
, *pos
;
527 struct station_info sinfo
;
528 struct ath6kl_req_key
*ik
;
530 u8 key_rsc
[ATH6KL_KEY_SEQ_LEN
];
532 if (memcmp(dev
->dev_addr
, bssid
, ETH_ALEN
) == 0) {
533 ik
= &ar
->ap_mode_bkey
;
535 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG
, "AP mode started on %u MHz\n",
538 switch (ar
->auth_mode
) {
540 if (ar
->prwise_crypto
== WEP_CRYPT
)
541 ath6kl_install_static_wep_keys(ar
);
545 case (WPA_PSK_AUTH
|WPA2_PSK_AUTH
):
549 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG
, "Delayed addkey for "
550 "the initial group key for AP mode\n");
551 memset(key_rsc
, 0, sizeof(key_rsc
));
552 res
= ath6kl_wmi_addkey_cmd(
553 ar
->wmi
, ik
->key_index
, ik
->key_type
,
554 GROUP_USAGE
, ik
->key_len
, key_rsc
, ik
->key
,
555 KEY_OP_INIT_VAL
, NULL
, SYNC_BOTH_WMIFLAG
);
557 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG
, "Delayed "
558 "addkey failed: %d\n", res
);
563 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
564 set_bit(CONNECTED
, &ar
->flag
);
565 netif_carrier_on(ar
->net_dev
);
569 ath6kl_dbg(ATH6KL_DBG_TRC
, "new station %pM aid=%d\n",
572 if (assoc_req_len
> sizeof(struct ieee80211_hdr_3addr
)) {
573 struct ieee80211_mgmt
*mgmt
=
574 (struct ieee80211_mgmt
*) assoc_info
;
575 if (ieee80211_is_assoc_req(mgmt
->frame_control
) &&
576 assoc_req_len
>= sizeof(struct ieee80211_hdr_3addr
) +
577 sizeof(mgmt
->u
.assoc_req
)) {
578 ies
= mgmt
->u
.assoc_req
.variable
;
579 ies_len
= assoc_info
+ assoc_req_len
- ies
;
580 } else if (ieee80211_is_reassoc_req(mgmt
->frame_control
) &&
581 assoc_req_len
>= sizeof(struct ieee80211_hdr_3addr
)
582 + sizeof(mgmt
->u
.reassoc_req
)) {
583 ies
= mgmt
->u
.reassoc_req
.variable
;
584 ies_len
= assoc_info
+ assoc_req_len
- ies
;
589 while (pos
&& pos
+ 1 < ies
+ ies_len
) {
590 if (pos
+ 2 + pos
[1] > ies
+ ies_len
)
592 if (pos
[0] == WLAN_EID_RSN
)
593 wpa_ie
= pos
; /* RSN IE */
594 else if (pos
[0] == WLAN_EID_VENDOR_SPECIFIC
&&
596 pos
[2] == 0x00 && pos
[3] == 0x50 && pos
[4] == 0xf2) {
598 wpa_ie
= pos
; /* WPA IE */
599 else if (pos
[5] == 0x04) {
600 wpa_ie
= pos
; /* WPS IE */
601 break; /* overrides WPA/RSN IE */
607 ath6kl_add_new_sta(ar
, bssid
, channel
, wpa_ie
,
608 wpa_ie
? 2 + wpa_ie
[1] : 0,
609 listen_int
& 0xFF, beacon_int
,
610 (listen_int
>> 8) & 0xFF);
612 /* send event to application */
613 memset(&sinfo
, 0, sizeof(sinfo
));
615 /* TODO: sinfo.generation */
617 sinfo
.assoc_req_ies
= ies
;
618 sinfo
.assoc_req_ies_len
= ies_len
;
619 sinfo
.filled
|= STATION_INFO_ASSOC_REQ_IES
;
621 cfg80211_new_sta(ar
->net_dev
, bssid
, &sinfo
, GFP_KERNEL
);
623 netif_wake_queue(ar
->net_dev
);
628 /* Functions for Tx credit handling */
629 void ath6k_credit_init(struct htc_credit_state_info
*cred_info
,
630 struct list_head
*ep_list
,
633 struct htc_endpoint_credit_dist
*cur_ep_dist
;
636 cred_info
->cur_free_credits
= tot_credits
;
637 cred_info
->total_avail_credits
= tot_credits
;
639 list_for_each_entry(cur_ep_dist
, ep_list
, list
) {
640 if (cur_ep_dist
->endpoint
== ENDPOINT_0
)
643 cur_ep_dist
->cred_min
= cur_ep_dist
->cred_per_msg
;
646 if ((cur_ep_dist
->svc_id
== WMI_DATA_BK_SVC
) ||
647 (cur_ep_dist
->svc_id
== WMI_DATA_BE_SVC
)) {
648 ath6kl_deposit_credit_to_ep(cred_info
,
650 cur_ep_dist
->cred_min
);
651 cur_ep_dist
->dist_flags
|= HTC_EP_ACTIVE
;
654 if (cur_ep_dist
->svc_id
== WMI_CONTROL_SVC
) {
655 ath6kl_deposit_credit_to_ep(cred_info
, cur_ep_dist
,
656 cur_ep_dist
->cred_min
);
658 * Control service is always marked active, it
659 * never goes inactive EVER.
661 cur_ep_dist
->dist_flags
|= HTC_EP_ACTIVE
;
662 } else if (cur_ep_dist
->svc_id
== WMI_DATA_BK_SVC
)
663 /* this is the lowest priority data endpoint */
664 cred_info
->lowestpri_ep_dist
= cur_ep_dist
->list
;
667 * Streams have to be created (explicit | implicit) for all
668 * kinds of traffic. BE endpoints are also inactive in the
669 * beginning. When BE traffic starts it creates implicit
670 * streams that redistributes credits.
672 * Note: all other endpoints have minimums set but are
673 * initially given NO credits. credits will be distributed
674 * as traffic activity demands
678 WARN_ON(cred_info
->cur_free_credits
<= 0);
680 list_for_each_entry(cur_ep_dist
, ep_list
, list
) {
681 if (cur_ep_dist
->endpoint
== ENDPOINT_0
)
684 if (cur_ep_dist
->svc_id
== WMI_CONTROL_SVC
)
685 cur_ep_dist
->cred_norm
= cur_ep_dist
->cred_per_msg
;
688 * For the remaining data endpoints, we assume that
689 * each cred_per_msg are the same. We use a simple
690 * calculation here, we take the remaining credits
691 * and determine how many max messages this can
692 * cover and then set each endpoint's normal value
693 * equal to 3/4 this amount.
695 count
= (cred_info
->cur_free_credits
/
696 cur_ep_dist
->cred_per_msg
)
697 * cur_ep_dist
->cred_per_msg
;
698 count
= (count
* 3) >> 2;
699 count
= max(count
, cur_ep_dist
->cred_per_msg
);
700 cur_ep_dist
->cred_norm
= count
;
706 /* initialize and setup credit distribution */
707 int ath6k_setup_credit_dist(void *htc_handle
,
708 struct htc_credit_state_info
*cred_info
)
710 u16 servicepriority
[5];
712 memset(cred_info
, 0, sizeof(struct htc_credit_state_info
));
714 servicepriority
[0] = WMI_CONTROL_SVC
; /* highest */
715 servicepriority
[1] = WMI_DATA_VO_SVC
;
716 servicepriority
[2] = WMI_DATA_VI_SVC
;
717 servicepriority
[3] = WMI_DATA_BE_SVC
;
718 servicepriority
[4] = WMI_DATA_BK_SVC
; /* lowest */
720 /* set priority list */
721 ath6kl_htc_set_credit_dist(htc_handle
, cred_info
, servicepriority
, 5);
726 /* reduce an ep's credits back to a set limit */
727 static void ath6k_reduce_credits(struct htc_credit_state_info
*cred_info
,
728 struct htc_endpoint_credit_dist
*ep_dist
,
733 ep_dist
->cred_assngd
= limit
;
735 if (ep_dist
->credits
<= limit
)
738 credits
= ep_dist
->credits
- limit
;
739 ep_dist
->credits
-= credits
;
740 cred_info
->cur_free_credits
+= credits
;
743 static void ath6k_credit_update(struct htc_credit_state_info
*cred_info
,
744 struct list_head
*epdist_list
)
746 struct htc_endpoint_credit_dist
*cur_dist_list
;
748 list_for_each_entry(cur_dist_list
, epdist_list
, list
) {
749 if (cur_dist_list
->endpoint
== ENDPOINT_0
)
752 if (cur_dist_list
->cred_to_dist
> 0) {
753 cur_dist_list
->credits
+=
754 cur_dist_list
->cred_to_dist
;
755 cur_dist_list
->cred_to_dist
= 0;
756 if (cur_dist_list
->credits
>
757 cur_dist_list
->cred_assngd
)
758 ath6k_reduce_credits(cred_info
,
760 cur_dist_list
->cred_assngd
);
762 if (cur_dist_list
->credits
>
763 cur_dist_list
->cred_norm
)
764 ath6k_reduce_credits(cred_info
, cur_dist_list
,
765 cur_dist_list
->cred_norm
);
767 if (!(cur_dist_list
->dist_flags
& HTC_EP_ACTIVE
)) {
768 if (cur_dist_list
->txq_depth
== 0)
769 ath6k_reduce_credits(cred_info
,
777 * HTC has an endpoint that needs credits, ep_dist is the endpoint in
780 void ath6k_seek_credits(struct htc_credit_state_info
*cred_info
,
781 struct htc_endpoint_credit_dist
*ep_dist
)
783 struct htc_endpoint_credit_dist
*curdist_list
;
787 if (ep_dist
->svc_id
== WMI_CONTROL_SVC
)
790 if ((ep_dist
->svc_id
== WMI_DATA_VI_SVC
) ||
791 (ep_dist
->svc_id
== WMI_DATA_VO_SVC
))
792 if ((ep_dist
->cred_assngd
>= ep_dist
->cred_norm
))
796 * For all other services, we follow a simple algorithm of:
798 * 1. checking the free pool for credits
799 * 2. checking lower priority endpoints for credits to take
802 credits
= min(cred_info
->cur_free_credits
, ep_dist
->seek_cred
);
804 if (credits
>= ep_dist
->seek_cred
)
808 * We don't have enough in the free pool, try taking away from
809 * lower priority services The rule for taking away credits:
811 * 1. Only take from lower priority endpoints
812 * 2. Only take what is allocated above the minimum (never
813 * starve an endpoint completely)
814 * 3. Only take what you need.
817 list_for_each_entry_reverse(curdist_list
,
818 &cred_info
->lowestpri_ep_dist
,
820 if (curdist_list
== ep_dist
)
823 need
= ep_dist
->seek_cred
- cred_info
->cur_free_credits
;
825 if ((curdist_list
->cred_assngd
- need
) >=
826 curdist_list
->cred_min
) {
828 * The current one has been allocated more than
829 * it's minimum and it has enough credits assigned
830 * above it's minimum to fulfill our need try to
831 * take away just enough to fulfill our need.
833 ath6k_reduce_credits(cred_info
, curdist_list
,
834 curdist_list
->cred_assngd
- need
);
836 if (cred_info
->cur_free_credits
>=
841 if (curdist_list
->endpoint
== ENDPOINT_0
)
845 credits
= min(cred_info
->cur_free_credits
, ep_dist
->seek_cred
);
848 /* did we find some credits? */
850 ath6kl_deposit_credit_to_ep(cred_info
, ep_dist
, credits
);
852 ep_dist
->seek_cred
= 0;
855 /* redistribute credits based on activity change */
856 static void ath6k_redistribute_credits(struct htc_credit_state_info
*info
,
857 struct list_head
*ep_dist_list
)
859 struct htc_endpoint_credit_dist
*curdist_list
;
861 list_for_each_entry(curdist_list
, ep_dist_list
, list
) {
862 if (curdist_list
->endpoint
== ENDPOINT_0
)
865 if ((curdist_list
->svc_id
== WMI_DATA_BK_SVC
) ||
866 (curdist_list
->svc_id
== WMI_DATA_BE_SVC
))
867 curdist_list
->dist_flags
|= HTC_EP_ACTIVE
;
869 if ((curdist_list
->svc_id
!= WMI_CONTROL_SVC
) &&
870 !(curdist_list
->dist_flags
& HTC_EP_ACTIVE
)) {
871 if (curdist_list
->txq_depth
== 0)
872 ath6k_reduce_credits(info
,
875 ath6k_reduce_credits(info
,
877 curdist_list
->cred_min
);
884 * This function is invoked whenever endpoints require credit
885 * distributions. A lock is held while this function is invoked, this
886 * function shall NOT block. The ep_dist_list is a list of distribution
887 * structures in prioritized order as defined by the call to the
888 * htc_set_credit_dist() api.
890 void ath6k_credit_distribute(struct htc_credit_state_info
*cred_info
,
891 struct list_head
*ep_dist_list
,
892 enum htc_credit_dist_reason reason
)
895 case HTC_CREDIT_DIST_SEND_COMPLETE
:
896 ath6k_credit_update(cred_info
, ep_dist_list
);
898 case HTC_CREDIT_DIST_ACTIVITY_CHANGE
:
899 ath6k_redistribute_credits(cred_info
, ep_dist_list
);
905 WARN_ON(cred_info
->cur_free_credits
> cred_info
->total_avail_credits
);
906 WARN_ON(cred_info
->cur_free_credits
< 0);
909 void disconnect_timer_handler(unsigned long ptr
)
911 struct net_device
*dev
= (struct net_device
*)ptr
;
912 struct ath6kl
*ar
= ath6kl_priv(dev
);
914 ath6kl_init_profile_info(ar
);
915 ath6kl_disconnect(ar
);
918 void ath6kl_disconnect(struct ath6kl
*ar
)
920 if (test_bit(CONNECTED
, &ar
->flag
) ||
921 test_bit(CONNECT_PEND
, &ar
->flag
)) {
922 ath6kl_wmi_disconnect_cmd(ar
->wmi
);
924 * Disconnect command is issued, clear the connect pending
925 * flag. The connected flag will be cleared in
926 * disconnect event notification.
928 clear_bit(CONNECT_PEND
, &ar
->flag
);
932 void ath6kl_deep_sleep_enable(struct ath6kl
*ar
)
934 switch (ar
->sme_state
) {
936 cfg80211_connect_result(ar
->net_dev
, ar
->bssid
, NULL
, 0,
938 WLAN_STATUS_UNSPECIFIED_FAILURE
,
944 * FIXME: oddly enough smeState is in DISCONNECTED during
945 * suspend, why? Need to send disconnected event in that
948 cfg80211_disconnected(ar
->net_dev
, 0, NULL
, 0, GFP_KERNEL
);
952 if (test_bit(CONNECTED
, &ar
->flag
) ||
953 test_bit(CONNECT_PEND
, &ar
->flag
))
954 ath6kl_wmi_disconnect_cmd(ar
->wmi
);
956 ar
->sme_state
= SME_DISCONNECTED
;
958 /* disable scanning */
959 if (ath6kl_wmi_scanparams_cmd(ar
->wmi
, 0xFFFF, 0, 0, 0, 0, 0, 0, 0,
961 printk(KERN_WARNING
"ath6kl: failed to disable scan "
964 ath6kl_cfg80211_scan_complete_event(ar
, -ECANCELED
);
967 /* WMI Event handlers */
969 static const char *get_hw_id_string(u32 id
)
972 case AR6003_REV1_VERSION
:
974 case AR6003_REV2_VERSION
:
976 case AR6003_REV3_VERSION
:
983 void ath6kl_ready_event(void *devt
, u8
*datap
, u32 sw_ver
, u32 abi_ver
)
985 struct ath6kl
*ar
= devt
;
986 struct net_device
*dev
= ar
->net_dev
;
988 memcpy(dev
->dev_addr
, datap
, ETH_ALEN
);
989 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: mac addr = %pM\n",
990 __func__
, dev
->dev_addr
);
992 ar
->version
.wlan_ver
= sw_ver
;
993 ar
->version
.abi_ver
= abi_ver
;
995 snprintf(ar
->wdev
->wiphy
->fw_version
,
996 sizeof(ar
->wdev
->wiphy
->fw_version
),
998 (ar
->version
.wlan_ver
& 0xf0000000) >> 28,
999 (ar
->version
.wlan_ver
& 0x0f000000) >> 24,
1000 (ar
->version
.wlan_ver
& 0x00ff0000) >> 16,
1001 (ar
->version
.wlan_ver
& 0x0000ffff));
1003 /* indicate to the waiting thread that the ready event was received */
1004 set_bit(WMI_READY
, &ar
->flag
);
1005 wake_up(&ar
->event_wq
);
1007 ath6kl_info("hw %s fw %s%s\n",
1008 get_hw_id_string(ar
->wdev
->wiphy
->hw_version
),
1009 ar
->wdev
->wiphy
->fw_version
,
1010 test_bit(TESTMODE
, &ar
->flag
) ? " testmode" : "");
1013 void ath6kl_scan_complete_evt(struct ath6kl
*ar
, int status
)
1015 ath6kl_cfg80211_scan_complete_event(ar
, status
);
1017 if (!ar
->usr_bss_filter
)
1018 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
1020 ath6kl_dbg(ATH6KL_DBG_WLAN_SCAN
, "scan complete: %d\n", status
);
1023 void ath6kl_connect_event(struct ath6kl
*ar
, u16 channel
, u8
*bssid
,
1024 u16 listen_int
, u16 beacon_int
,
1025 enum network_type net_type
, u8 beacon_ie_len
,
1026 u8 assoc_req_len
, u8 assoc_resp_len
,
1029 unsigned long flags
;
1031 if (ar
->nw_type
== AP_NETWORK
) {
1032 ath6kl_connect_ap_mode(ar
, channel
, bssid
, listen_int
,
1033 beacon_int
, assoc_req_len
,
1034 assoc_info
+ beacon_ie_len
);
1038 ath6kl_cfg80211_connect_event(ar
, channel
, bssid
,
1039 listen_int
, beacon_int
,
1040 net_type
, beacon_ie_len
,
1041 assoc_req_len
, assoc_resp_len
,
1044 memcpy(ar
->bssid
, bssid
, sizeof(ar
->bssid
));
1045 ar
->bss_ch
= channel
;
1047 if ((ar
->nw_type
== INFRA_NETWORK
))
1048 ath6kl_wmi_listeninterval_cmd(ar
->wmi
, ar
->listen_intvl_t
,
1049 ar
->listen_intvl_b
);
1051 netif_wake_queue(ar
->net_dev
);
1053 /* Update connect & link status atomically */
1054 spin_lock_irqsave(&ar
->lock
, flags
);
1055 set_bit(CONNECTED
, &ar
->flag
);
1056 clear_bit(CONNECT_PEND
, &ar
->flag
);
1057 netif_carrier_on(ar
->net_dev
);
1058 spin_unlock_irqrestore(&ar
->lock
, flags
);
1060 aggr_reset_state(ar
->aggr_cntxt
);
1061 ar
->reconnect_flag
= 0;
1063 if ((ar
->nw_type
== ADHOC_NETWORK
) && ar
->ibss_ps_enable
) {
1064 memset(ar
->node_map
, 0, sizeof(ar
->node_map
));
1066 ar
->next_ep_id
= ENDPOINT_2
;
1069 if (!ar
->usr_bss_filter
)
1070 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
1073 void ath6kl_tkip_micerr_event(struct ath6kl
*ar
, u8 keyid
, bool ismcast
)
1075 struct ath6kl_sta
*sta
;
1078 * For AP case, keyid will have aid of STA which sent pkt with
1079 * MIC error. Use this aid to get MAC & send it to hostapd.
1081 if (ar
->nw_type
== AP_NETWORK
) {
1082 sta
= ath6kl_find_sta_by_aid(ar
, (keyid
>> 2));
1086 ath6kl_dbg(ATH6KL_DBG_TRC
,
1087 "ap tkip mic error received from aid=%d\n", keyid
);
1089 memset(tsc
, 0, sizeof(tsc
)); /* FIX: get correct TSC */
1090 cfg80211_michael_mic_failure(ar
->net_dev
, sta
->mac
,
1091 NL80211_KEYTYPE_PAIRWISE
, keyid
,
1094 ath6kl_cfg80211_tkip_micerr_event(ar
, keyid
, ismcast
);
1098 static void ath6kl_update_target_stats(struct ath6kl
*ar
, u8
*ptr
, u32 len
)
1100 struct wmi_target_stats
*tgt_stats
=
1101 (struct wmi_target_stats
*) ptr
;
1102 struct target_stats
*stats
= &ar
->target_stats
;
1103 struct tkip_ccmp_stats
*ccmp_stats
;
1104 struct bss
*conn_bss
= NULL
;
1105 struct cserv_stats
*c_stats
;
1108 if (len
< sizeof(*tgt_stats
))
1111 /* update the RSSI of the connected bss */
1112 if (test_bit(CONNECTED
, &ar
->flag
)) {
1113 conn_bss
= ath6kl_wmi_find_node(ar
->wmi
, ar
->bssid
);
1115 c_stats
= &tgt_stats
->cserv_stats
;
1117 a_sle16_to_cpu(c_stats
->cs_ave_beacon_rssi
);
1119 tgt_stats
->cserv_stats
.cs_ave_beacon_snr
;
1120 ath6kl_wmi_node_return(ar
->wmi
, conn_bss
);
1124 ath6kl_dbg(ATH6KL_DBG_TRC
, "updating target stats\n");
1126 stats
->tx_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.pkt
);
1127 stats
->tx_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.byte
);
1128 stats
->tx_ucast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.ucast_pkt
);
1129 stats
->tx_ucast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.ucast_byte
);
1130 stats
->tx_mcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.mcast_pkt
);
1131 stats
->tx_mcast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.mcast_byte
);
1132 stats
->tx_bcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.bcast_pkt
);
1133 stats
->tx_bcast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.bcast_byte
);
1134 stats
->tx_rts_success_cnt
+=
1135 le32_to_cpu(tgt_stats
->stats
.tx
.rts_success_cnt
);
1137 for (ac
= 0; ac
< WMM_NUM_AC
; ac
++)
1138 stats
->tx_pkt_per_ac
[ac
] +=
1139 le32_to_cpu(tgt_stats
->stats
.tx
.pkt_per_ac
[ac
]);
1141 stats
->tx_err
+= le32_to_cpu(tgt_stats
->stats
.tx
.err
);
1142 stats
->tx_fail_cnt
+= le32_to_cpu(tgt_stats
->stats
.tx
.fail_cnt
);
1143 stats
->tx_retry_cnt
+= le32_to_cpu(tgt_stats
->stats
.tx
.retry_cnt
);
1144 stats
->tx_mult_retry_cnt
+=
1145 le32_to_cpu(tgt_stats
->stats
.tx
.mult_retry_cnt
);
1146 stats
->tx_rts_fail_cnt
+=
1147 le32_to_cpu(tgt_stats
->stats
.tx
.rts_fail_cnt
);
1148 stats
->tx_ucast_rate
=
1149 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats
->stats
.tx
.ucast_rate
));
1151 stats
->rx_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.pkt
);
1152 stats
->rx_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.byte
);
1153 stats
->rx_ucast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.ucast_pkt
);
1154 stats
->rx_ucast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.ucast_byte
);
1155 stats
->rx_mcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.mcast_pkt
);
1156 stats
->rx_mcast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.mcast_byte
);
1157 stats
->rx_bcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.bcast_pkt
);
1158 stats
->rx_bcast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.bcast_byte
);
1159 stats
->rx_frgment_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.frgment_pkt
);
1160 stats
->rx_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.err
);
1161 stats
->rx_crc_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.crc_err
);
1162 stats
->rx_key_cache_miss
+=
1163 le32_to_cpu(tgt_stats
->stats
.rx
.key_cache_miss
);
1164 stats
->rx_decrypt_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.decrypt_err
);
1165 stats
->rx_dupl_frame
+= le32_to_cpu(tgt_stats
->stats
.rx
.dupl_frame
);
1166 stats
->rx_ucast_rate
=
1167 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats
->stats
.rx
.ucast_rate
));
1169 ccmp_stats
= &tgt_stats
->stats
.tkip_ccmp_stats
;
1171 stats
->tkip_local_mic_fail
+=
1172 le32_to_cpu(ccmp_stats
->tkip_local_mic_fail
);
1173 stats
->tkip_cnter_measures_invoked
+=
1174 le32_to_cpu(ccmp_stats
->tkip_cnter_measures_invoked
);
1175 stats
->tkip_fmt_err
+= le32_to_cpu(ccmp_stats
->tkip_fmt_err
);
1177 stats
->ccmp_fmt_err
+= le32_to_cpu(ccmp_stats
->ccmp_fmt_err
);
1178 stats
->ccmp_replays
+= le32_to_cpu(ccmp_stats
->ccmp_replays
);
1180 stats
->pwr_save_fail_cnt
+=
1181 le32_to_cpu(tgt_stats
->pm_stats
.pwr_save_failure_cnt
);
1182 stats
->noise_floor_calib
=
1183 a_sle32_to_cpu(tgt_stats
->noise_floor_calib
);
1185 stats
->cs_bmiss_cnt
+=
1186 le32_to_cpu(tgt_stats
->cserv_stats
.cs_bmiss_cnt
);
1187 stats
->cs_low_rssi_cnt
+=
1188 le32_to_cpu(tgt_stats
->cserv_stats
.cs_low_rssi_cnt
);
1189 stats
->cs_connect_cnt
+=
1190 le16_to_cpu(tgt_stats
->cserv_stats
.cs_connect_cnt
);
1191 stats
->cs_discon_cnt
+=
1192 le16_to_cpu(tgt_stats
->cserv_stats
.cs_discon_cnt
);
1194 stats
->cs_ave_beacon_rssi
=
1195 a_sle16_to_cpu(tgt_stats
->cserv_stats
.cs_ave_beacon_rssi
);
1197 stats
->cs_last_roam_msec
=
1198 tgt_stats
->cserv_stats
.cs_last_roam_msec
;
1199 stats
->cs_snr
= tgt_stats
->cserv_stats
.cs_snr
;
1200 stats
->cs_rssi
= a_sle16_to_cpu(tgt_stats
->cserv_stats
.cs_rssi
);
1202 stats
->lq_val
= le32_to_cpu(tgt_stats
->lq_val
);
1204 stats
->wow_pkt_dropped
+=
1205 le32_to_cpu(tgt_stats
->wow_stats
.wow_pkt_dropped
);
1206 stats
->wow_host_pkt_wakeups
+=
1207 tgt_stats
->wow_stats
.wow_host_pkt_wakeups
;
1208 stats
->wow_host_evt_wakeups
+=
1209 tgt_stats
->wow_stats
.wow_host_evt_wakeups
;
1210 stats
->wow_evt_discarded
+=
1211 le16_to_cpu(tgt_stats
->wow_stats
.wow_evt_discarded
);
1213 if (test_bit(STATS_UPDATE_PEND
, &ar
->flag
)) {
1214 clear_bit(STATS_UPDATE_PEND
, &ar
->flag
);
1215 wake_up(&ar
->event_wq
);
1219 static void ath6kl_add_le32(__le32
*var
, __le32 val
)
1221 *var
= cpu_to_le32(le32_to_cpu(*var
) + le32_to_cpu(val
));
1224 void ath6kl_tgt_stats_event(struct ath6kl
*ar
, u8
*ptr
, u32 len
)
1226 struct wmi_ap_mode_stat
*p
= (struct wmi_ap_mode_stat
*) ptr
;
1227 struct wmi_ap_mode_stat
*ap
= &ar
->ap_stats
;
1228 struct wmi_per_sta_stat
*st_ap
, *st_p
;
1231 if (ar
->nw_type
== AP_NETWORK
) {
1232 if (len
< sizeof(*p
))
1235 for (ac
= 0; ac
< AP_MAX_NUM_STA
; ac
++) {
1236 st_ap
= &ap
->sta
[ac
];
1239 ath6kl_add_le32(&st_ap
->tx_bytes
, st_p
->tx_bytes
);
1240 ath6kl_add_le32(&st_ap
->tx_pkts
, st_p
->tx_pkts
);
1241 ath6kl_add_le32(&st_ap
->tx_error
, st_p
->tx_error
);
1242 ath6kl_add_le32(&st_ap
->tx_discard
, st_p
->tx_discard
);
1243 ath6kl_add_le32(&st_ap
->rx_bytes
, st_p
->rx_bytes
);
1244 ath6kl_add_le32(&st_ap
->rx_pkts
, st_p
->rx_pkts
);
1245 ath6kl_add_le32(&st_ap
->rx_error
, st_p
->rx_error
);
1246 ath6kl_add_le32(&st_ap
->rx_discard
, st_p
->rx_discard
);
1250 ath6kl_update_target_stats(ar
, ptr
, len
);
1254 void ath6kl_wakeup_event(void *dev
)
1256 struct ath6kl
*ar
= (struct ath6kl
*) dev
;
1258 wake_up(&ar
->event_wq
);
1261 void ath6kl_txpwr_rx_evt(void *devt
, u8 tx_pwr
)
1263 struct ath6kl
*ar
= (struct ath6kl
*) devt
;
1265 ar
->tx_pwr
= tx_pwr
;
1266 wake_up(&ar
->event_wq
);
1269 void ath6kl_pspoll_event(struct ath6kl
*ar
, u8 aid
)
1271 struct ath6kl_sta
*conn
;
1272 struct sk_buff
*skb
;
1273 bool psq_empty
= false;
1275 conn
= ath6kl_find_sta_by_aid(ar
, aid
);
1280 * Send out a packet queued on ps queue. When the ps queue
1281 * becomes empty update the PVB for this station.
1283 spin_lock_bh(&conn
->psq_lock
);
1284 psq_empty
= skb_queue_empty(&conn
->psq
);
1285 spin_unlock_bh(&conn
->psq_lock
);
1288 /* TODO: Send out a NULL data frame */
1291 spin_lock_bh(&conn
->psq_lock
);
1292 skb
= skb_dequeue(&conn
->psq
);
1293 spin_unlock_bh(&conn
->psq_lock
);
1295 conn
->sta_flags
|= STA_PS_POLLED
;
1296 ath6kl_data_tx(skb
, ar
->net_dev
);
1297 conn
->sta_flags
&= ~STA_PS_POLLED
;
1299 spin_lock_bh(&conn
->psq_lock
);
1300 psq_empty
= skb_queue_empty(&conn
->psq
);
1301 spin_unlock_bh(&conn
->psq_lock
);
1304 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, conn
->aid
, 0);
1307 void ath6kl_dtimexpiry_event(struct ath6kl
*ar
)
1309 bool mcastq_empty
= false;
1310 struct sk_buff
*skb
;
1313 * If there are no associated STAs, ignore the DTIM expiry event.
1314 * There can be potential race conditions where the last associated
1315 * STA may disconnect & before the host could clear the 'Indicate
1316 * DTIM' request to the firmware, the firmware would have just
1317 * indicated a DTIM expiry event. The race is between 'clear DTIM
1318 * expiry cmd' going from the host to the firmware & the DTIM
1319 * expiry event happening from the firmware to the host.
1321 if (!ar
->sta_list_index
)
1324 spin_lock_bh(&ar
->mcastpsq_lock
);
1325 mcastq_empty
= skb_queue_empty(&ar
->mcastpsq
);
1326 spin_unlock_bh(&ar
->mcastpsq_lock
);
1331 /* set the STA flag to dtim_expired for the frame to go out */
1332 set_bit(DTIM_EXPIRED
, &ar
->flag
);
1334 spin_lock_bh(&ar
->mcastpsq_lock
);
1335 while ((skb
= skb_dequeue(&ar
->mcastpsq
)) != NULL
) {
1336 spin_unlock_bh(&ar
->mcastpsq_lock
);
1338 ath6kl_data_tx(skb
, ar
->net_dev
);
1340 spin_lock_bh(&ar
->mcastpsq_lock
);
1342 spin_unlock_bh(&ar
->mcastpsq_lock
);
1344 clear_bit(DTIM_EXPIRED
, &ar
->flag
);
1346 /* clear the LSB of the BitMapCtl field of the TIM IE */
1347 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, MCAST_AID
, 0);
1350 void ath6kl_disconnect_event(struct ath6kl
*ar
, u8 reason
, u8
*bssid
,
1351 u8 assoc_resp_len
, u8
*assoc_info
,
1352 u16 prot_reason_status
)
1354 struct bss
*wmi_ssid_node
= NULL
;
1355 unsigned long flags
;
1357 if (ar
->nw_type
== AP_NETWORK
) {
1358 if (!ath6kl_remove_sta(ar
, bssid
, prot_reason_status
))
1361 /* if no more associated STAs, empty the mcast PS q */
1362 if (ar
->sta_list_index
== 0) {
1363 spin_lock_bh(&ar
->mcastpsq_lock
);
1364 skb_queue_purge(&ar
->mcastpsq
);
1365 spin_unlock_bh(&ar
->mcastpsq_lock
);
1367 /* clear the LSB of the TIM IE's BitMapCtl field */
1368 if (test_bit(WMI_READY
, &ar
->flag
))
1369 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, MCAST_AID
, 0);
1372 if (!is_broadcast_ether_addr(bssid
)) {
1373 /* send event to application */
1374 cfg80211_del_sta(ar
->net_dev
, bssid
, GFP_KERNEL
);
1377 if (memcmp(ar
->net_dev
->dev_addr
, bssid
, ETH_ALEN
) == 0)
1378 clear_bit(CONNECTED
, &ar
->flag
);
1382 ath6kl_cfg80211_disconnect_event(ar
, reason
, bssid
,
1383 assoc_resp_len
, assoc_info
,
1384 prot_reason_status
);
1386 aggr_reset_state(ar
->aggr_cntxt
);
1388 del_timer(&ar
->disconnect_timer
);
1390 ath6kl_dbg(ATH6KL_DBG_WLAN_CONNECT
,
1391 "disconnect reason is %d\n", reason
);
1394 * If the event is due to disconnect cmd from the host, only they
1395 * the target would stop trying to connect. Under any other
1396 * condition, target would keep trying to connect.
1398 if (reason
== DISCONNECT_CMD
) {
1399 if (!ar
->usr_bss_filter
&& test_bit(WMI_READY
, &ar
->flag
))
1400 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
1402 set_bit(CONNECT_PEND
, &ar
->flag
);
1403 if (((reason
== ASSOC_FAILED
) &&
1404 (prot_reason_status
== 0x11)) ||
1405 ((reason
== ASSOC_FAILED
) && (prot_reason_status
== 0x0)
1406 && (ar
->reconnect_flag
== 1))) {
1407 set_bit(CONNECTED
, &ar
->flag
);
1412 if ((reason
== NO_NETWORK_AVAIL
) && test_bit(WMI_READY
, &ar
->flag
)) {
1413 ath6kl_wmi_node_free(ar
->wmi
, bssid
);
1416 * In case any other same SSID nodes are present remove it,
1417 * since those nodes also not available now.
1421 * Find the nodes based on SSID and remove it
1423 * Note: This case will not work out for
1426 wmi_ssid_node
= ath6kl_wmi_find_ssid_node(ar
->wmi
,
1433 ath6kl_wmi_node_free(ar
->wmi
,
1434 wmi_ssid_node
->ni_macaddr
);
1436 } while (wmi_ssid_node
);
1439 /* update connect & link status atomically */
1440 spin_lock_irqsave(&ar
->lock
, flags
);
1441 clear_bit(CONNECTED
, &ar
->flag
);
1442 netif_carrier_off(ar
->net_dev
);
1443 spin_unlock_irqrestore(&ar
->lock
, flags
);
1445 if ((reason
!= CSERV_DISCONNECT
) || (ar
->reconnect_flag
!= 1))
1446 ar
->reconnect_flag
= 0;
1448 if (reason
!= CSERV_DISCONNECT
)
1449 ar
->user_key_ctrl
= 0;
1451 netif_stop_queue(ar
->net_dev
);
1452 memset(ar
->bssid
, 0, sizeof(ar
->bssid
));
1455 ath6kl_tx_data_cleanup(ar
);
1458 static int ath6kl_open(struct net_device
*dev
)
1460 struct ath6kl
*ar
= ath6kl_priv(dev
);
1461 unsigned long flags
;
1463 spin_lock_irqsave(&ar
->lock
, flags
);
1465 set_bit(WLAN_ENABLED
, &ar
->flag
);
1467 if (test_bit(CONNECTED
, &ar
->flag
)) {
1468 netif_carrier_on(dev
);
1469 netif_wake_queue(dev
);
1471 netif_carrier_off(dev
);
1473 spin_unlock_irqrestore(&ar
->lock
, flags
);
1478 static int ath6kl_close(struct net_device
*dev
)
1480 struct ath6kl
*ar
= ath6kl_priv(dev
);
1482 netif_stop_queue(dev
);
1484 ath6kl_disconnect(ar
);
1486 if (test_bit(WMI_READY
, &ar
->flag
)) {
1487 if (ath6kl_wmi_scanparams_cmd(ar
->wmi
, 0xFFFF, 0, 0, 0, 0, 0, 0,
1491 clear_bit(WLAN_ENABLED
, &ar
->flag
);
1494 ath6kl_cfg80211_scan_complete_event(ar
, -ECANCELED
);
1499 static struct net_device_stats
*ath6kl_get_stats(struct net_device
*dev
)
1501 struct ath6kl
*ar
= ath6kl_priv(dev
);
1503 return &ar
->net_stats
;
1506 static struct net_device_ops ath6kl_netdev_ops
= {
1507 .ndo_open
= ath6kl_open
,
1508 .ndo_stop
= ath6kl_close
,
1509 .ndo_start_xmit
= ath6kl_data_tx
,
1510 .ndo_get_stats
= ath6kl_get_stats
,
1513 void init_netdev(struct net_device
*dev
)
1515 dev
->netdev_ops
= &ath6kl_netdev_ops
;
1516 dev
->watchdog_timeo
= ATH6KL_TX_TIMEOUT
;
1518 dev
->needed_headroom
= ETH_HLEN
;
1519 dev
->needed_headroom
+= sizeof(struct ath6kl_llc_snap_hdr
) +
1520 sizeof(struct wmi_data_hdr
) + HTC_HDR_LENGTH
1521 + WMI_MAX_TX_META_SZ
+ ATH6KL_HTC_ALIGN_BYTES
;