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_vif
*vif
, u8
*node_addr
)
25 struct ath6kl
*ar
= vif
->ar
;
26 struct ath6kl_sta
*conn
= NULL
;
29 max_conn
= (vif
->nw_type
== AP_NETWORK
) ? AP_MAX_NUM_STA
: 0;
31 for (i
= 0; i
< max_conn
; i
++) {
32 if (memcmp(node_addr
, ar
->sta_list
[i
].mac
, ETH_ALEN
) == 0) {
33 conn
= &ar
->sta_list
[i
];
41 struct ath6kl_sta
*ath6kl_find_sta_by_aid(struct ath6kl
*ar
, u8 aid
)
43 struct ath6kl_sta
*conn
= NULL
;
46 for (ctr
= 0; ctr
< AP_MAX_NUM_STA
; ctr
++) {
47 if (ar
->sta_list
[ctr
].aid
== aid
) {
48 conn
= &ar
->sta_list
[ctr
];
55 static void ath6kl_add_new_sta(struct ath6kl
*ar
, u8
*mac
, u16 aid
, u8
*wpaie
,
56 u8 ielen
, u8 keymgmt
, u8 ucipher
, u8 auth
)
58 struct ath6kl_sta
*sta
;
63 sta
= &ar
->sta_list
[free_slot
];
64 memcpy(sta
->mac
, mac
, ETH_ALEN
);
65 if (ielen
<= ATH6KL_MAX_IE
)
66 memcpy(sta
->wpa_ie
, wpaie
, ielen
);
68 sta
->keymgmt
= keymgmt
;
69 sta
->ucipher
= ucipher
;
72 ar
->sta_list_index
= ar
->sta_list_index
| (1 << free_slot
);
73 ar
->ap_stats
.sta
[free_slot
].aid
= cpu_to_le32(aid
);
76 static void ath6kl_sta_cleanup(struct ath6kl
*ar
, u8 i
)
78 struct ath6kl_sta
*sta
= &ar
->sta_list
[i
];
80 /* empty the queued pkts in the PS queue if any */
81 spin_lock_bh(&sta
->psq_lock
);
82 skb_queue_purge(&sta
->psq
);
83 spin_unlock_bh(&sta
->psq_lock
);
85 memset(&ar
->ap_stats
.sta
[sta
->aid
- 1], 0,
86 sizeof(struct wmi_per_sta_stat
));
87 memset(sta
->mac
, 0, ETH_ALEN
);
88 memset(sta
->wpa_ie
, 0, ATH6KL_MAX_IE
);
92 ar
->sta_list_index
= ar
->sta_list_index
& ~(1 << i
);
96 static u8
ath6kl_remove_sta(struct ath6kl
*ar
, u8
*mac
, u16 reason
)
100 if (is_zero_ether_addr(mac
))
103 if (is_broadcast_ether_addr(mac
)) {
104 ath6kl_dbg(ATH6KL_DBG_TRC
, "deleting all station\n");
106 for (i
= 0; i
< AP_MAX_NUM_STA
; i
++) {
107 if (!is_zero_ether_addr(ar
->sta_list
[i
].mac
)) {
108 ath6kl_sta_cleanup(ar
, i
);
113 for (i
= 0; i
< AP_MAX_NUM_STA
; i
++) {
114 if (memcmp(ar
->sta_list
[i
].mac
, mac
, ETH_ALEN
) == 0) {
115 ath6kl_dbg(ATH6KL_DBG_TRC
,
116 "deleting station %pM aid=%d reason=%d\n",
117 mac
, ar
->sta_list
[i
].aid
, reason
);
118 ath6kl_sta_cleanup(ar
, i
);
128 enum htc_endpoint_id
ath6kl_ac2_endpoint_id(void *devt
, u8 ac
)
130 struct ath6kl
*ar
= devt
;
131 return ar
->ac2ep_map
[ac
];
134 struct ath6kl_cookie
*ath6kl_alloc_cookie(struct ath6kl
*ar
)
136 struct ath6kl_cookie
*cookie
;
138 cookie
= ar
->cookie_list
;
139 if (cookie
!= NULL
) {
140 ar
->cookie_list
= cookie
->arc_list_next
;
147 void ath6kl_cookie_init(struct ath6kl
*ar
)
151 ar
->cookie_list
= NULL
;
152 ar
->cookie_count
= 0;
154 memset(ar
->cookie_mem
, 0, sizeof(ar
->cookie_mem
));
156 for (i
= 0; i
< MAX_COOKIE_NUM
; i
++)
157 ath6kl_free_cookie(ar
, &ar
->cookie_mem
[i
]);
160 void ath6kl_cookie_cleanup(struct ath6kl
*ar
)
162 ar
->cookie_list
= NULL
;
163 ar
->cookie_count
= 0;
166 void ath6kl_free_cookie(struct ath6kl
*ar
, struct ath6kl_cookie
*cookie
)
173 cookie
->arc_list_next
= ar
->cookie_list
;
174 ar
->cookie_list
= cookie
;
178 /* set the window address register (using 4-byte register access ). */
179 static int ath6kl_set_addrwin_reg(struct ath6kl
*ar
, u32 reg_addr
, u32 addr
)
186 * Write bytes 1,2,3 of the register to set the upper address bytes,
187 * the LSB is written last to initiate the access cycle
190 for (i
= 1; i
<= 3; i
++) {
192 * Fill the buffer with the address byte value we want to
193 * hit 4 times. No need to worry about endianness as the
194 * same byte is copied to all four bytes of addr_val at
197 memset((u8
*)&addr_val
, ((u8
*)&addr
)[i
], 4);
200 * Hit each byte of the register address with a 4-byte
201 * write operation to the same address, this is a harmless
204 status
= hif_read_write_sync(ar
, reg_addr
+ i
, (u8
*)&addr_val
,
205 4, HIF_WR_SYNC_BYTE_FIX
);
211 ath6kl_err("failed to write initial bytes of 0x%x to window reg: 0x%X\n",
217 * Write the address register again, this time write the whole
218 * 4-byte value. The effect here is that the LSB write causes the
219 * cycle to start, the extra 3 byte write to bytes 1,2,3 has no
220 * effect since we are writing the same values again
222 addr_val
= cpu_to_le32(addr
);
223 status
= hif_read_write_sync(ar
, reg_addr
,
225 4, HIF_WR_SYNC_BYTE_INC
);
228 ath6kl_err("failed to write 0x%x to window reg: 0x%X\n",
237 * Read from the hardware through its diagnostic window. No cooperation
238 * from the firmware is required for this.
240 int ath6kl_diag_read32(struct ath6kl
*ar
, u32 address
, u32
*value
)
244 /* set window register to start read cycle */
245 ret
= ath6kl_set_addrwin_reg(ar
, WINDOW_READ_ADDR_ADDRESS
, address
);
250 ret
= hif_read_write_sync(ar
, WINDOW_DATA_ADDRESS
, (u8
*) value
,
251 sizeof(*value
), HIF_RD_SYNC_BYTE_INC
);
253 ath6kl_warn("failed to read32 through diagnose window: %d\n",
262 * Write to the ATH6KL through its diagnostic window. No cooperation from
263 * the Target is required for this.
265 int ath6kl_diag_write32(struct ath6kl
*ar
, u32 address
, __le32 value
)
270 ret
= hif_read_write_sync(ar
, WINDOW_DATA_ADDRESS
, (u8
*) &value
,
271 sizeof(value
), HIF_WR_SYNC_BYTE_INC
);
273 ath6kl_err("failed to write 0x%x during diagnose window to 0x%d\n",
278 /* set window register, which starts the write cycle */
279 return ath6kl_set_addrwin_reg(ar
, WINDOW_WRITE_ADDR_ADDRESS
,
283 int ath6kl_diag_read(struct ath6kl
*ar
, u32 address
, void *data
, u32 length
)
285 u32 count
, *buf
= data
;
288 if (WARN_ON(length
% 4))
291 for (count
= 0; count
< length
/ 4; count
++, address
+= 4) {
292 ret
= ath6kl_diag_read32(ar
, address
, &buf
[count
]);
300 int ath6kl_diag_write(struct ath6kl
*ar
, u32 address
, void *data
, u32 length
)
306 if (WARN_ON(length
% 4))
309 for (count
= 0; count
< length
/ 4; count
++, address
+= 4) {
310 ret
= ath6kl_diag_write32(ar
, address
, buf
[count
]);
318 int ath6kl_read_fwlogs(struct ath6kl
*ar
)
320 struct ath6kl_dbglog_hdr debug_hdr
;
321 struct ath6kl_dbglog_buf debug_buf
;
322 u32 address
, length
, dropped
, firstbuf
, debug_hdr_addr
;
326 buf
= kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE
, GFP_KERNEL
);
330 address
= TARG_VTOP(ar
->target_type
,
331 ath6kl_get_hi_item_addr(ar
,
332 HI_ITEM(hi_dbglog_hdr
)));
334 ret
= ath6kl_diag_read32(ar
, address
, &debug_hdr_addr
);
338 /* Get the contents of the ring buffer */
339 if (debug_hdr_addr
== 0) {
340 ath6kl_warn("Invalid address for debug_hdr_addr\n");
345 address
= TARG_VTOP(ar
->target_type
, debug_hdr_addr
);
346 ath6kl_diag_read(ar
, address
, &debug_hdr
, sizeof(debug_hdr
));
348 address
= TARG_VTOP(ar
->target_type
,
349 le32_to_cpu(debug_hdr
.dbuf_addr
));
351 dropped
= le32_to_cpu(debug_hdr
.dropped
);
352 ath6kl_diag_read(ar
, address
, &debug_buf
, sizeof(debug_buf
));
357 address
= TARG_VTOP(ar
->target_type
,
358 le32_to_cpu(debug_buf
.buffer_addr
));
359 length
= le32_to_cpu(debug_buf
.length
);
361 if (length
!= 0 && (le32_to_cpu(debug_buf
.length
) <=
362 le32_to_cpu(debug_buf
.bufsize
))) {
363 length
= ALIGN(length
, 4);
365 ret
= ath6kl_diag_read(ar
, address
,
370 ath6kl_debug_fwlog_event(ar
, buf
, length
);
373 address
= TARG_VTOP(ar
->target_type
,
374 le32_to_cpu(debug_buf
.next
));
375 ath6kl_diag_read(ar
, address
, &debug_buf
, sizeof(debug_buf
));
381 if (WARN_ON(loop
== 0)) {
385 } while (address
!= firstbuf
);
393 /* FIXME: move to a better place, target.h? */
394 #define AR6003_RESET_CONTROL_ADDRESS 0x00004000
395 #define AR6004_RESET_CONTROL_ADDRESS 0x00004000
397 void ath6kl_reset_device(struct ath6kl
*ar
, u32 target_type
,
398 bool wait_fot_compltn
, bool cold_reset
)
404 if (target_type
!= TARGET_TYPE_AR6003
&&
405 target_type
!= TARGET_TYPE_AR6004
)
408 data
= cold_reset
? cpu_to_le32(RESET_CONTROL_COLD_RST
) :
409 cpu_to_le32(RESET_CONTROL_MBOX_RST
);
411 switch (target_type
) {
412 case TARGET_TYPE_AR6003
:
413 address
= AR6003_RESET_CONTROL_ADDRESS
;
415 case TARGET_TYPE_AR6004
:
416 address
= AR6004_RESET_CONTROL_ADDRESS
;
419 address
= AR6003_RESET_CONTROL_ADDRESS
;
423 status
= ath6kl_diag_write32(ar
, address
, data
);
426 ath6kl_err("failed to reset target\n");
429 static void ath6kl_install_static_wep_keys(struct ath6kl_vif
*vif
)
434 for (index
= WMI_MIN_KEY_INDEX
; index
<= WMI_MAX_KEY_INDEX
; index
++) {
435 if (vif
->wep_key_list
[index
].key_len
) {
436 keyusage
= GROUP_USAGE
;
437 if (index
== vif
->def_txkey_index
)
438 keyusage
|= TX_USAGE
;
440 ath6kl_wmi_addkey_cmd(vif
->ar
->wmi
, vif
->fw_vif_idx
,
444 vif
->wep_key_list
[index
].key_len
,
446 vif
->wep_key_list
[index
].key
,
447 KEY_OP_INIT_VAL
, NULL
,
453 void ath6kl_connect_ap_mode_bss(struct ath6kl_vif
*vif
, u16 channel
)
455 struct ath6kl
*ar
= vif
->ar
;
456 struct ath6kl_req_key
*ik
;
458 u8 key_rsc
[ATH6KL_KEY_SEQ_LEN
];
460 ik
= &ar
->ap_mode_bkey
;
462 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG
, "AP mode started on %u MHz\n", channel
);
464 switch (vif
->auth_mode
) {
466 if (vif
->prwise_crypto
== WEP_CRYPT
)
467 ath6kl_install_static_wep_keys(vif
);
471 case (WPA_PSK_AUTH
| WPA2_PSK_AUTH
):
475 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG
, "Delayed addkey for "
476 "the initial group key for AP mode\n");
477 memset(key_rsc
, 0, sizeof(key_rsc
));
478 res
= ath6kl_wmi_addkey_cmd(
479 ar
->wmi
, vif
->fw_vif_idx
, ik
->key_index
, ik
->key_type
,
480 GROUP_USAGE
, ik
->key_len
, key_rsc
, ATH6KL_KEY_SEQ_LEN
,
482 KEY_OP_INIT_VAL
, NULL
, SYNC_BOTH_WMIFLAG
);
484 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG
, "Delayed "
485 "addkey failed: %d\n", res
);
490 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, vif
->fw_vif_idx
, NONE_BSS_FILTER
, 0);
491 set_bit(CONNECTED
, &vif
->flags
);
492 netif_carrier_on(vif
->ndev
);
495 void ath6kl_connect_ap_mode_sta(struct ath6kl_vif
*vif
, u16 aid
, u8
*mac_addr
,
496 u8 keymgmt
, u8 ucipher
, u8 auth
,
497 u8 assoc_req_len
, u8
*assoc_info
)
499 struct ath6kl
*ar
= vif
->ar
;
500 u8
*ies
= NULL
, *wpa_ie
= NULL
, *pos
;
502 struct station_info sinfo
;
504 ath6kl_dbg(ATH6KL_DBG_TRC
, "new station %pM aid=%d\n", mac_addr
, aid
);
506 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
;
523 while (pos
&& pos
+ 1 < ies
+ ies_len
) {
524 if (pos
+ 2 + pos
[1] > ies
+ ies_len
)
526 if (pos
[0] == WLAN_EID_RSN
)
527 wpa_ie
= pos
; /* RSN IE */
528 else if (pos
[0] == WLAN_EID_VENDOR_SPECIFIC
&&
530 pos
[2] == 0x00 && pos
[3] == 0x50 && pos
[4] == 0xf2) {
532 wpa_ie
= pos
; /* WPA IE */
533 else if (pos
[5] == 0x04) {
534 wpa_ie
= pos
; /* WPS IE */
535 break; /* overrides WPA/RSN IE */
541 ath6kl_add_new_sta(ar
, mac_addr
, aid
, wpa_ie
,
542 wpa_ie
? 2 + wpa_ie
[1] : 0,
543 keymgmt
, ucipher
, auth
);
545 /* send event to application */
546 memset(&sinfo
, 0, sizeof(sinfo
));
548 /* TODO: sinfo.generation */
550 sinfo
.assoc_req_ies
= ies
;
551 sinfo
.assoc_req_ies_len
= ies_len
;
552 sinfo
.filled
|= STATION_INFO_ASSOC_REQ_IES
;
554 cfg80211_new_sta(vif
->ndev
, mac_addr
, &sinfo
, GFP_KERNEL
);
556 netif_wake_queue(vif
->ndev
);
559 void disconnect_timer_handler(unsigned long ptr
)
561 struct net_device
*dev
= (struct net_device
*)ptr
;
562 struct ath6kl_vif
*vif
= netdev_priv(dev
);
564 ath6kl_init_profile_info(vif
);
565 ath6kl_disconnect(vif
);
568 void ath6kl_disconnect(struct ath6kl_vif
*vif
)
570 if (test_bit(CONNECTED
, &vif
->flags
) ||
571 test_bit(CONNECT_PEND
, &vif
->flags
)) {
572 ath6kl_wmi_disconnect_cmd(vif
->ar
->wmi
, vif
->fw_vif_idx
);
574 * Disconnect command is issued, clear the connect pending
575 * flag. The connected flag will be cleared in
576 * disconnect event notification.
578 clear_bit(CONNECT_PEND
, &vif
->flags
);
582 /* WMI Event handlers */
584 static const char *get_hw_id_string(u32 id
)
587 case AR6003_REV1_VERSION
:
589 case AR6003_REV2_VERSION
:
591 case AR6003_REV3_VERSION
:
598 void ath6kl_ready_event(void *devt
, u8
*datap
, u32 sw_ver
, u32 abi_ver
)
600 struct ath6kl
*ar
= devt
;
602 memcpy(ar
->mac_addr
, datap
, ETH_ALEN
);
603 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: mac addr = %pM\n",
604 __func__
, ar
->mac_addr
);
606 ar
->version
.wlan_ver
= sw_ver
;
607 ar
->version
.abi_ver
= abi_ver
;
609 snprintf(ar
->wiphy
->fw_version
,
610 sizeof(ar
->wiphy
->fw_version
),
612 (ar
->version
.wlan_ver
& 0xf0000000) >> 28,
613 (ar
->version
.wlan_ver
& 0x0f000000) >> 24,
614 (ar
->version
.wlan_ver
& 0x00ff0000) >> 16,
615 (ar
->version
.wlan_ver
& 0x0000ffff));
617 /* indicate to the waiting thread that the ready event was received */
618 set_bit(WMI_READY
, &ar
->flag
);
619 wake_up(&ar
->event_wq
);
621 if (test_and_clear_bit(FIRST_BOOT
, &ar
->flag
)) {
622 ath6kl_info("hw %s fw %s%s\n",
623 get_hw_id_string(ar
->wiphy
->hw_version
),
624 ar
->wiphy
->fw_version
,
625 test_bit(TESTMODE
, &ar
->flag
) ? " testmode" : "");
629 void ath6kl_scan_complete_evt(struct ath6kl_vif
*vif
, int status
)
631 struct ath6kl
*ar
= vif
->ar
;
632 bool aborted
= false;
634 if (status
!= WMI_SCAN_STATUS_SUCCESS
)
637 ath6kl_cfg80211_scan_complete_event(vif
, aborted
);
639 if (!ar
->usr_bss_filter
) {
640 clear_bit(CLEAR_BSSFILTER_ON_BEACON
, &vif
->flags
);
641 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, vif
->fw_vif_idx
,
645 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG
, "scan complete: %d\n", status
);
648 void ath6kl_connect_event(struct ath6kl_vif
*vif
, u16 channel
, u8
*bssid
,
649 u16 listen_int
, u16 beacon_int
,
650 enum network_type net_type
, u8 beacon_ie_len
,
651 u8 assoc_req_len
, u8 assoc_resp_len
,
654 struct ath6kl
*ar
= vif
->ar
;
656 ath6kl_cfg80211_connect_event(vif
, channel
, bssid
,
657 listen_int
, beacon_int
,
658 net_type
, beacon_ie_len
,
659 assoc_req_len
, assoc_resp_len
,
662 memcpy(vif
->bssid
, bssid
, sizeof(vif
->bssid
));
663 vif
->bss_ch
= channel
;
665 if ((vif
->nw_type
== INFRA_NETWORK
))
666 ath6kl_wmi_listeninterval_cmd(ar
->wmi
, vif
->fw_vif_idx
,
670 netif_wake_queue(vif
->ndev
);
672 /* Update connect & link status atomically */
673 spin_lock_bh(&vif
->if_lock
);
674 set_bit(CONNECTED
, &vif
->flags
);
675 clear_bit(CONNECT_PEND
, &vif
->flags
);
676 netif_carrier_on(vif
->ndev
);
677 spin_unlock_bh(&vif
->if_lock
);
679 aggr_reset_state(vif
->aggr_cntxt
);
680 vif
->reconnect_flag
= 0;
682 if ((vif
->nw_type
== ADHOC_NETWORK
) && ar
->ibss_ps_enable
) {
683 memset(ar
->node_map
, 0, sizeof(ar
->node_map
));
685 ar
->next_ep_id
= ENDPOINT_2
;
688 if (!ar
->usr_bss_filter
) {
689 set_bit(CLEAR_BSSFILTER_ON_BEACON
, &vif
->flags
);
690 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, vif
->fw_vif_idx
,
691 CURRENT_BSS_FILTER
, 0);
695 void ath6kl_tkip_micerr_event(struct ath6kl_vif
*vif
, u8 keyid
, bool ismcast
)
697 struct ath6kl_sta
*sta
;
698 struct ath6kl
*ar
= vif
->ar
;
702 * For AP case, keyid will have aid of STA which sent pkt with
703 * MIC error. Use this aid to get MAC & send it to hostapd.
705 if (vif
->nw_type
== AP_NETWORK
) {
706 sta
= ath6kl_find_sta_by_aid(ar
, (keyid
>> 2));
710 ath6kl_dbg(ATH6KL_DBG_TRC
,
711 "ap tkip mic error received from aid=%d\n", keyid
);
713 memset(tsc
, 0, sizeof(tsc
)); /* FIX: get correct TSC */
714 cfg80211_michael_mic_failure(vif
->ndev
, sta
->mac
,
715 NL80211_KEYTYPE_PAIRWISE
, keyid
,
718 ath6kl_cfg80211_tkip_micerr_event(vif
, keyid
, ismcast
);
722 static void ath6kl_update_target_stats(struct ath6kl_vif
*vif
, u8
*ptr
, u32 len
)
724 struct wmi_target_stats
*tgt_stats
=
725 (struct wmi_target_stats
*) ptr
;
726 struct ath6kl
*ar
= vif
->ar
;
727 struct target_stats
*stats
= &vif
->target_stats
;
728 struct tkip_ccmp_stats
*ccmp_stats
;
731 if (len
< sizeof(*tgt_stats
))
734 ath6kl_dbg(ATH6KL_DBG_TRC
, "updating target stats\n");
736 stats
->tx_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.pkt
);
737 stats
->tx_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.byte
);
738 stats
->tx_ucast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.ucast_pkt
);
739 stats
->tx_ucast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.ucast_byte
);
740 stats
->tx_mcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.mcast_pkt
);
741 stats
->tx_mcast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.mcast_byte
);
742 stats
->tx_bcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.bcast_pkt
);
743 stats
->tx_bcast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.bcast_byte
);
744 stats
->tx_rts_success_cnt
+=
745 le32_to_cpu(tgt_stats
->stats
.tx
.rts_success_cnt
);
747 for (ac
= 0; ac
< WMM_NUM_AC
; ac
++)
748 stats
->tx_pkt_per_ac
[ac
] +=
749 le32_to_cpu(tgt_stats
->stats
.tx
.pkt_per_ac
[ac
]);
751 stats
->tx_err
+= le32_to_cpu(tgt_stats
->stats
.tx
.err
);
752 stats
->tx_fail_cnt
+= le32_to_cpu(tgt_stats
->stats
.tx
.fail_cnt
);
753 stats
->tx_retry_cnt
+= le32_to_cpu(tgt_stats
->stats
.tx
.retry_cnt
);
754 stats
->tx_mult_retry_cnt
+=
755 le32_to_cpu(tgt_stats
->stats
.tx
.mult_retry_cnt
);
756 stats
->tx_rts_fail_cnt
+=
757 le32_to_cpu(tgt_stats
->stats
.tx
.rts_fail_cnt
);
758 stats
->tx_ucast_rate
=
759 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats
->stats
.tx
.ucast_rate
));
761 stats
->rx_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.pkt
);
762 stats
->rx_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.byte
);
763 stats
->rx_ucast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.ucast_pkt
);
764 stats
->rx_ucast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.ucast_byte
);
765 stats
->rx_mcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.mcast_pkt
);
766 stats
->rx_mcast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.mcast_byte
);
767 stats
->rx_bcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.bcast_pkt
);
768 stats
->rx_bcast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.bcast_byte
);
769 stats
->rx_frgment_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.frgment_pkt
);
770 stats
->rx_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.err
);
771 stats
->rx_crc_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.crc_err
);
772 stats
->rx_key_cache_miss
+=
773 le32_to_cpu(tgt_stats
->stats
.rx
.key_cache_miss
);
774 stats
->rx_decrypt_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.decrypt_err
);
775 stats
->rx_dupl_frame
+= le32_to_cpu(tgt_stats
->stats
.rx
.dupl_frame
);
776 stats
->rx_ucast_rate
=
777 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats
->stats
.rx
.ucast_rate
));
779 ccmp_stats
= &tgt_stats
->stats
.tkip_ccmp_stats
;
781 stats
->tkip_local_mic_fail
+=
782 le32_to_cpu(ccmp_stats
->tkip_local_mic_fail
);
783 stats
->tkip_cnter_measures_invoked
+=
784 le32_to_cpu(ccmp_stats
->tkip_cnter_measures_invoked
);
785 stats
->tkip_fmt_err
+= le32_to_cpu(ccmp_stats
->tkip_fmt_err
);
787 stats
->ccmp_fmt_err
+= le32_to_cpu(ccmp_stats
->ccmp_fmt_err
);
788 stats
->ccmp_replays
+= le32_to_cpu(ccmp_stats
->ccmp_replays
);
790 stats
->pwr_save_fail_cnt
+=
791 le32_to_cpu(tgt_stats
->pm_stats
.pwr_save_failure_cnt
);
792 stats
->noise_floor_calib
=
793 a_sle32_to_cpu(tgt_stats
->noise_floor_calib
);
795 stats
->cs_bmiss_cnt
+=
796 le32_to_cpu(tgt_stats
->cserv_stats
.cs_bmiss_cnt
);
797 stats
->cs_low_rssi_cnt
+=
798 le32_to_cpu(tgt_stats
->cserv_stats
.cs_low_rssi_cnt
);
799 stats
->cs_connect_cnt
+=
800 le16_to_cpu(tgt_stats
->cserv_stats
.cs_connect_cnt
);
801 stats
->cs_discon_cnt
+=
802 le16_to_cpu(tgt_stats
->cserv_stats
.cs_discon_cnt
);
804 stats
->cs_ave_beacon_rssi
=
805 a_sle16_to_cpu(tgt_stats
->cserv_stats
.cs_ave_beacon_rssi
);
807 stats
->cs_last_roam_msec
=
808 tgt_stats
->cserv_stats
.cs_last_roam_msec
;
809 stats
->cs_snr
= tgt_stats
->cserv_stats
.cs_snr
;
810 stats
->cs_rssi
= a_sle16_to_cpu(tgt_stats
->cserv_stats
.cs_rssi
);
812 stats
->lq_val
= le32_to_cpu(tgt_stats
->lq_val
);
814 stats
->wow_pkt_dropped
+=
815 le32_to_cpu(tgt_stats
->wow_stats
.wow_pkt_dropped
);
816 stats
->wow_host_pkt_wakeups
+=
817 tgt_stats
->wow_stats
.wow_host_pkt_wakeups
;
818 stats
->wow_host_evt_wakeups
+=
819 tgt_stats
->wow_stats
.wow_host_evt_wakeups
;
820 stats
->wow_evt_discarded
+=
821 le16_to_cpu(tgt_stats
->wow_stats
.wow_evt_discarded
);
823 if (test_bit(STATS_UPDATE_PEND
, &vif
->flags
)) {
824 clear_bit(STATS_UPDATE_PEND
, &vif
->flags
);
825 wake_up(&ar
->event_wq
);
829 static void ath6kl_add_le32(__le32
*var
, __le32 val
)
831 *var
= cpu_to_le32(le32_to_cpu(*var
) + le32_to_cpu(val
));
834 void ath6kl_tgt_stats_event(struct ath6kl_vif
*vif
, u8
*ptr
, u32 len
)
836 struct wmi_ap_mode_stat
*p
= (struct wmi_ap_mode_stat
*) ptr
;
837 struct ath6kl
*ar
= vif
->ar
;
838 struct wmi_ap_mode_stat
*ap
= &ar
->ap_stats
;
839 struct wmi_per_sta_stat
*st_ap
, *st_p
;
842 if (vif
->nw_type
== AP_NETWORK
) {
843 if (len
< sizeof(*p
))
846 for (ac
= 0; ac
< AP_MAX_NUM_STA
; ac
++) {
847 st_ap
= &ap
->sta
[ac
];
850 ath6kl_add_le32(&st_ap
->tx_bytes
, st_p
->tx_bytes
);
851 ath6kl_add_le32(&st_ap
->tx_pkts
, st_p
->tx_pkts
);
852 ath6kl_add_le32(&st_ap
->tx_error
, st_p
->tx_error
);
853 ath6kl_add_le32(&st_ap
->tx_discard
, st_p
->tx_discard
);
854 ath6kl_add_le32(&st_ap
->rx_bytes
, st_p
->rx_bytes
);
855 ath6kl_add_le32(&st_ap
->rx_pkts
, st_p
->rx_pkts
);
856 ath6kl_add_le32(&st_ap
->rx_error
, st_p
->rx_error
);
857 ath6kl_add_le32(&st_ap
->rx_discard
, st_p
->rx_discard
);
861 ath6kl_update_target_stats(vif
, ptr
, len
);
865 void ath6kl_wakeup_event(void *dev
)
867 struct ath6kl
*ar
= (struct ath6kl
*) dev
;
869 wake_up(&ar
->event_wq
);
872 void ath6kl_txpwr_rx_evt(void *devt
, u8 tx_pwr
)
874 struct ath6kl
*ar
= (struct ath6kl
*) devt
;
877 wake_up(&ar
->event_wq
);
880 void ath6kl_pspoll_event(struct ath6kl_vif
*vif
, u8 aid
)
882 struct ath6kl_sta
*conn
;
884 bool psq_empty
= false;
885 struct ath6kl
*ar
= vif
->ar
;
887 conn
= ath6kl_find_sta_by_aid(ar
, aid
);
892 * Send out a packet queued on ps queue. When the ps queue
893 * becomes empty update the PVB for this station.
895 spin_lock_bh(&conn
->psq_lock
);
896 psq_empty
= skb_queue_empty(&conn
->psq
);
897 spin_unlock_bh(&conn
->psq_lock
);
900 /* TODO: Send out a NULL data frame */
903 spin_lock_bh(&conn
->psq_lock
);
904 skb
= skb_dequeue(&conn
->psq
);
905 spin_unlock_bh(&conn
->psq_lock
);
907 conn
->sta_flags
|= STA_PS_POLLED
;
908 ath6kl_data_tx(skb
, vif
->ndev
);
909 conn
->sta_flags
&= ~STA_PS_POLLED
;
911 spin_lock_bh(&conn
->psq_lock
);
912 psq_empty
= skb_queue_empty(&conn
->psq
);
913 spin_unlock_bh(&conn
->psq_lock
);
916 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, vif
->fw_vif_idx
, conn
->aid
, 0);
919 void ath6kl_dtimexpiry_event(struct ath6kl_vif
*vif
)
921 bool mcastq_empty
= false;
923 struct ath6kl
*ar
= vif
->ar
;
926 * If there are no associated STAs, ignore the DTIM expiry event.
927 * There can be potential race conditions where the last associated
928 * STA may disconnect & before the host could clear the 'Indicate
929 * DTIM' request to the firmware, the firmware would have just
930 * indicated a DTIM expiry event. The race is between 'clear DTIM
931 * expiry cmd' going from the host to the firmware & the DTIM
932 * expiry event happening from the firmware to the host.
934 if (!ar
->sta_list_index
)
937 spin_lock_bh(&ar
->mcastpsq_lock
);
938 mcastq_empty
= skb_queue_empty(&ar
->mcastpsq
);
939 spin_unlock_bh(&ar
->mcastpsq_lock
);
944 /* set the STA flag to dtim_expired for the frame to go out */
945 set_bit(DTIM_EXPIRED
, &vif
->flags
);
947 spin_lock_bh(&ar
->mcastpsq_lock
);
948 while ((skb
= skb_dequeue(&ar
->mcastpsq
)) != NULL
) {
949 spin_unlock_bh(&ar
->mcastpsq_lock
);
951 ath6kl_data_tx(skb
, vif
->ndev
);
953 spin_lock_bh(&ar
->mcastpsq_lock
);
955 spin_unlock_bh(&ar
->mcastpsq_lock
);
957 clear_bit(DTIM_EXPIRED
, &vif
->flags
);
959 /* clear the LSB of the BitMapCtl field of the TIM IE */
960 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, vif
->fw_vif_idx
, MCAST_AID
, 0);
963 void ath6kl_disconnect_event(struct ath6kl_vif
*vif
, u8 reason
, u8
*bssid
,
964 u8 assoc_resp_len
, u8
*assoc_info
,
965 u16 prot_reason_status
)
967 struct ath6kl
*ar
= vif
->ar
;
969 if (vif
->nw_type
== AP_NETWORK
) {
970 if (!ath6kl_remove_sta(ar
, bssid
, prot_reason_status
))
973 /* if no more associated STAs, empty the mcast PS q */
974 if (ar
->sta_list_index
== 0) {
975 spin_lock_bh(&ar
->mcastpsq_lock
);
976 skb_queue_purge(&ar
->mcastpsq
);
977 spin_unlock_bh(&ar
->mcastpsq_lock
);
979 /* clear the LSB of the TIM IE's BitMapCtl field */
980 if (test_bit(WMI_READY
, &ar
->flag
))
981 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, vif
->fw_vif_idx
,
985 if (!is_broadcast_ether_addr(bssid
)) {
986 /* send event to application */
987 cfg80211_del_sta(vif
->ndev
, bssid
, GFP_KERNEL
);
990 if (memcmp(vif
->ndev
->dev_addr
, bssid
, ETH_ALEN
) == 0) {
991 memset(vif
->wep_key_list
, 0, sizeof(vif
->wep_key_list
));
992 clear_bit(CONNECTED
, &vif
->flags
);
997 ath6kl_cfg80211_disconnect_event(vif
, reason
, bssid
,
998 assoc_resp_len
, assoc_info
,
1001 aggr_reset_state(vif
->aggr_cntxt
);
1003 del_timer(&vif
->disconnect_timer
);
1005 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG
, "disconnect reason is %d\n", reason
);
1008 * If the event is due to disconnect cmd from the host, only they
1009 * the target would stop trying to connect. Under any other
1010 * condition, target would keep trying to connect.
1012 if (reason
== DISCONNECT_CMD
) {
1013 if (!ar
->usr_bss_filter
&& test_bit(WMI_READY
, &ar
->flag
))
1014 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, vif
->fw_vif_idx
,
1015 NONE_BSS_FILTER
, 0);
1017 set_bit(CONNECT_PEND
, &vif
->flags
);
1018 if (((reason
== ASSOC_FAILED
) &&
1019 (prot_reason_status
== 0x11)) ||
1020 ((reason
== ASSOC_FAILED
) && (prot_reason_status
== 0x0)
1021 && (vif
->reconnect_flag
== 1))) {
1022 set_bit(CONNECTED
, &vif
->flags
);
1027 /* update connect & link status atomically */
1028 spin_lock_bh(&vif
->if_lock
);
1029 clear_bit(CONNECTED
, &vif
->flags
);
1030 netif_carrier_off(vif
->ndev
);
1031 spin_unlock_bh(&vif
->if_lock
);
1033 if ((reason
!= CSERV_DISCONNECT
) || (vif
->reconnect_flag
!= 1))
1034 vif
->reconnect_flag
= 0;
1036 if (reason
!= CSERV_DISCONNECT
)
1037 ar
->user_key_ctrl
= 0;
1039 netif_stop_queue(vif
->ndev
);
1040 memset(vif
->bssid
, 0, sizeof(vif
->bssid
));
1043 ath6kl_tx_data_cleanup(ar
);
1046 struct ath6kl_vif
*ath6kl_vif_first(struct ath6kl
*ar
)
1048 struct ath6kl_vif
*vif
;
1050 spin_lock_bh(&ar
->list_lock
);
1051 if (list_empty(&ar
->vif_list
)) {
1052 spin_unlock_bh(&ar
->list_lock
);
1056 vif
= list_first_entry(&ar
->vif_list
, struct ath6kl_vif
, list
);
1058 spin_unlock_bh(&ar
->list_lock
);
1063 static int ath6kl_open(struct net_device
*dev
)
1065 struct ath6kl_vif
*vif
= netdev_priv(dev
);
1067 set_bit(WLAN_ENABLED
, &vif
->flags
);
1069 if (test_bit(CONNECTED
, &vif
->flags
)) {
1070 netif_carrier_on(dev
);
1071 netif_wake_queue(dev
);
1073 netif_carrier_off(dev
);
1078 static int ath6kl_close(struct net_device
*dev
)
1080 struct ath6kl
*ar
= ath6kl_priv(dev
);
1081 struct ath6kl_vif
*vif
= netdev_priv(dev
);
1083 netif_stop_queue(dev
);
1085 ath6kl_disconnect(vif
);
1087 if (test_bit(WMI_READY
, &ar
->flag
)) {
1088 if (ath6kl_wmi_scanparams_cmd(ar
->wmi
, vif
->fw_vif_idx
, 0xFFFF,
1089 0, 0, 0, 0, 0, 0, 0, 0, 0))
1094 ath6kl_cfg80211_scan_complete_event(vif
, true);
1096 clear_bit(WLAN_ENABLED
, &vif
->flags
);
1101 static struct net_device_stats
*ath6kl_get_stats(struct net_device
*dev
)
1103 struct ath6kl_vif
*vif
= netdev_priv(dev
);
1105 return &vif
->net_stats
;
1108 static struct net_device_ops ath6kl_netdev_ops
= {
1109 .ndo_open
= ath6kl_open
,
1110 .ndo_stop
= ath6kl_close
,
1111 .ndo_start_xmit
= ath6kl_data_tx
,
1112 .ndo_get_stats
= ath6kl_get_stats
,
1115 void init_netdev(struct net_device
*dev
)
1117 dev
->netdev_ops
= &ath6kl_netdev_ops
;
1118 dev
->destructor
= free_netdev
;
1119 dev
->watchdog_timeo
= ATH6KL_TX_TIMEOUT
;
1121 dev
->needed_headroom
= ETH_HLEN
;
1122 dev
->needed_headroom
+= sizeof(struct ath6kl_llc_snap_hdr
) +
1123 sizeof(struct wmi_data_hdr
) + HTC_HDR_LENGTH
1124 + WMI_MAX_TX_META_SZ
+ ATH6KL_HTC_ALIGN_BYTES
;