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 memcpy(sta
->wpa_ie
, wpaie
, ielen
);
66 sta
->keymgmt
= keymgmt
;
67 sta
->ucipher
= ucipher
;
70 ar
->sta_list_index
= ar
->sta_list_index
| (1 << free_slot
);
71 ar
->ap_stats
.sta
[free_slot
].aid
= cpu_to_le32(aid
);
74 static void ath6kl_sta_cleanup(struct ath6kl
*ar
, u8 i
)
76 struct ath6kl_sta
*sta
= &ar
->sta_list
[i
];
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
);
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
);
90 ar
->sta_list_index
= ar
->sta_list_index
& ~(1 << i
);
94 static u8
ath6kl_remove_sta(struct ath6kl
*ar
, u8
*mac
, u16 reason
)
98 if (is_zero_ether_addr(mac
))
101 if (is_broadcast_ether_addr(mac
)) {
102 ath6kl_dbg(ATH6KL_DBG_TRC
, "deleting all station\n");
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
);
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
);
126 enum htc_endpoint_id
ath6kl_ac2_endpoint_id(void *devt
, u8 ac
)
128 struct ath6kl
*ar
= devt
;
129 return ar
->ac2ep_map
[ac
];
132 struct ath6kl_cookie
*ath6kl_alloc_cookie(struct ath6kl
*ar
)
134 struct ath6kl_cookie
*cookie
;
136 cookie
= ar
->cookie_list
;
137 if (cookie
!= NULL
) {
138 ar
->cookie_list
= cookie
->arc_list_next
;
145 void ath6kl_cookie_init(struct ath6kl
*ar
)
149 ar
->cookie_list
= NULL
;
150 ar
->cookie_count
= 0;
152 memset(ar
->cookie_mem
, 0, sizeof(ar
->cookie_mem
));
154 for (i
= 0; i
< MAX_COOKIE_NUM
; i
++)
155 ath6kl_free_cookie(ar
, &ar
->cookie_mem
[i
]);
158 void ath6kl_cookie_cleanup(struct ath6kl
*ar
)
160 ar
->cookie_list
= NULL
;
161 ar
->cookie_count
= 0;
164 void ath6kl_free_cookie(struct ath6kl
*ar
, struct ath6kl_cookie
*cookie
)
171 cookie
->arc_list_next
= ar
->cookie_list
;
172 ar
->cookie_list
= cookie
;
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
)
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
188 for (i
= 1; i
<= 3; i
++) {
190 * Fill the buffer with the address byte value we want to
193 memset(addr_val
, ((u8
*)&addr
)[i
], 4);
196 * Hit each byte of the register address with a 4-byte
197 * write operation to the same address, this is a harmless
200 status
= hif_read_write_sync(ar
, reg_addr
+ i
, addr_val
,
201 4, HIF_WR_SYNC_BYTE_FIX
);
207 ath6kl_err("failed to write initial bytes of 0x%x to window reg: 0x%X\n",
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
218 status
= hif_read_write_sync(ar
, reg_addr
, (u8
*)(&addr
),
219 4, HIF_WR_SYNC_BYTE_INC
);
222 ath6kl_err("failed to write 0x%x to window reg: 0x%X\n",
231 * Read from the ATH6KL through its diagnostic window. No cooperation from
232 * the Target is required for this.
234 int ath6kl_read_reg_diag(struct ath6kl
*ar
, u32
*address
, u32
*data
)
238 /* set window register to start read cycle */
239 status
= ath6kl_set_addrwin_reg(ar
, WINDOW_READ_ADDR_ADDRESS
,
246 status
= hif_read_write_sync(ar
, WINDOW_DATA_ADDRESS
, (u8
*)data
,
247 sizeof(u32
), HIF_RD_SYNC_BYTE_INC
);
249 ath6kl_err("failed to read from window data addr\n");
258 * Write to the ATH6KL through its diagnostic window. No cooperation from
259 * the Target is required for this.
261 static int ath6kl_write_reg_diag(struct ath6kl
*ar
, u32
*address
, u32
*data
)
266 status
= hif_read_write_sync(ar
, WINDOW_DATA_ADDRESS
, (u8
*)data
,
267 sizeof(u32
), HIF_WR_SYNC_BYTE_INC
);
269 ath6kl_err("failed to write 0x%x to window data addr\n", *data
);
273 /* set window register, which starts the write cycle */
274 return ath6kl_set_addrwin_reg(ar
, WINDOW_WRITE_ADDR_ADDRESS
,
278 int ath6kl_access_datadiag(struct ath6kl
*ar
, u32 address
,
279 u8
*data
, u32 length
, bool read
)
284 for (count
= 0; count
< length
; count
+= 4, address
+= 4) {
286 status
= ath6kl_read_reg_diag(ar
, &address
,
287 (u32
*) &data
[count
]);
291 status
= ath6kl_write_reg_diag(ar
, &address
,
292 (u32
*) &data
[count
]);
301 static void ath6kl_reset_device(struct ath6kl
*ar
, u32 target_type
,
302 bool wait_fot_compltn
, bool cold_reset
)
308 if (target_type
!= TARGET_TYPE_AR6003
)
311 data
= cold_reset
? RESET_CONTROL_COLD_RST
: RESET_CONTROL_MBOX_RST
;
313 address
= RTC_BASE_ADDRESS
;
314 status
= ath6kl_write_reg_diag(ar
, &address
, &data
);
317 ath6kl_err("failed to reset target\n");
320 void ath6kl_stop_endpoint(struct net_device
*dev
, bool keep_profile
,
323 struct ath6kl
*ar
= ath6kl_priv(dev
);
324 static u8 bcast_mac
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
327 netif_stop_queue(dev
);
329 /* disable the target and the interrupts associated with it */
330 if (test_bit(WMI_READY
, &ar
->flag
)) {
331 discon_issued
= (test_bit(CONNECTED
, &ar
->flag
) ||
332 test_bit(CONNECT_PEND
, &ar
->flag
));
333 ath6kl_disconnect(ar
);
335 ath6kl_init_profile_info(ar
);
337 del_timer(&ar
->disconnect_timer
);
339 clear_bit(WMI_READY
, &ar
->flag
);
340 ath6kl_wmi_shutdown(ar
->wmi
);
341 clear_bit(WMI_ENABLED
, &ar
->flag
);
345 * After wmi_shudown all WMI events will be dropped. We
346 * need to cleanup the buffers allocated in AP mode and
347 * give disconnect notification to stack, which usually
348 * happens in the disconnect_event. Simulate the disconnect
349 * event by calling the function directly. Sometimes
350 * disconnect_event will be received when the debug logs
354 ath6kl_disconnect_event(ar
, DISCONNECT_CMD
,
355 (ar
->nw_type
& AP_NETWORK
) ?
356 bcast_mac
: ar
->bssid
,
359 ar
->user_key_ctrl
= 0;
362 ath6kl_dbg(ATH6KL_DBG_TRC
,
363 "%s: wmi is not ready 0x%p 0x%p\n",
364 __func__
, ar
, ar
->wmi
);
366 /* Shut down WMI if we have started it */
367 if (test_bit(WMI_ENABLED
, &ar
->flag
)) {
368 ath6kl_dbg(ATH6KL_DBG_TRC
,
369 "%s: shut down wmi\n", __func__
);
370 ath6kl_wmi_shutdown(ar
->wmi
);
371 clear_bit(WMI_ENABLED
, &ar
->flag
);
376 if (ar
->htc_target
) {
377 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: shut down htc\n", __func__
);
378 ath6kl_htc_stop(ar
->htc_target
);
382 * Try to reset the device if we can. The driver may have been
383 * configure NOT to reset the target during a debug session.
385 ath6kl_dbg(ATH6KL_DBG_TRC
,
386 "attempting to reset target on instance destroy\n");
387 ath6kl_reset_device(ar
, ar
->target_type
, true, true);
390 static void ath6kl_install_static_wep_keys(struct ath6kl
*ar
)
395 for (index
= WMI_MIN_KEY_INDEX
; index
<= WMI_MAX_KEY_INDEX
; index
++) {
396 if (ar
->wep_key_list
[index
].key_len
) {
397 keyusage
= GROUP_USAGE
;
398 if (index
== ar
->def_txkey_index
)
399 keyusage
|= TX_USAGE
;
401 ath6kl_wmi_addkey_cmd(ar
->wmi
,
405 ar
->wep_key_list
[index
].key_len
,
407 ar
->wep_key_list
[index
].key
,
408 KEY_OP_INIT_VAL
, NULL
,
414 static void ath6kl_connect_ap_mode(struct ath6kl
*ar
, u16 channel
, u8
*bssid
,
415 u16 listen_int
, u16 beacon_int
,
416 u8 assoc_resp_len
, u8
*assoc_info
)
418 struct net_device
*dev
= ar
->net_dev
;
419 struct station_info sinfo
;
420 struct ath6kl_req_key
*ik
;
421 enum crypto_type keyType
= NONE_CRYPT
;
423 if (memcmp(dev
->dev_addr
, bssid
, ETH_ALEN
) == 0) {
424 ik
= &ar
->ap_mode_bkey
;
426 switch (ar
->auth_mode
) {
428 if (ar
->prwise_crypto
== WEP_CRYPT
)
429 ath6kl_install_static_wep_keys(ar
);
433 case (WPA_PSK_AUTH
|WPA2_PSK_AUTH
):
434 switch (ik
->ik_type
) {
435 case ATH6KL_CIPHER_TKIP
:
436 keyType
= TKIP_CRYPT
;
438 case ATH6KL_CIPHER_AES_CCM
:
444 ath6kl_wmi_addkey_cmd(ar
->wmi
, ik
->ik_keyix
, keyType
,
445 GROUP_USAGE
, ik
->ik_keylen
,
446 (u8
*)&ik
->ik_keyrsc
,
448 KEY_OP_INIT_VAL
, ik
->ik_macaddr
,
453 set_bit(CONNECTED
, &ar
->flag
);
457 ath6kl_dbg(ATH6KL_DBG_TRC
, "new station %pM aid=%d\n",
460 ath6kl_add_new_sta(ar
, bssid
, channel
, assoc_info
, assoc_resp_len
,
461 listen_int
& 0xFF, beacon_int
,
462 (listen_int
>> 8) & 0xFF);
464 /* send event to application */
465 memset(&sinfo
, 0, sizeof(sinfo
));
467 /* TODO: sinfo.generation */
468 /* TODO: need to deliver (Re)AssocReq IEs somehow.. change in
469 * cfg80211 needed, e.g., by adding those into sinfo
471 cfg80211_new_sta(ar
->net_dev
, bssid
, &sinfo
, GFP_KERNEL
);
473 netif_wake_queue(ar
->net_dev
);
478 /* Functions for Tx credit handling */
479 void ath6k_credit_init(struct htc_credit_state_info
*cred_info
,
480 struct list_head
*ep_list
,
483 struct htc_endpoint_credit_dist
*cur_ep_dist
;
486 cred_info
->cur_free_credits
= tot_credits
;
487 cred_info
->total_avail_credits
= tot_credits
;
489 list_for_each_entry(cur_ep_dist
, ep_list
, list
) {
490 if (cur_ep_dist
->endpoint
== ENDPOINT_0
)
493 cur_ep_dist
->cred_min
= cur_ep_dist
->cred_per_msg
;
496 if ((cur_ep_dist
->svc_id
== WMI_DATA_BK_SVC
) ||
497 (cur_ep_dist
->svc_id
== WMI_DATA_BE_SVC
)) {
498 ath6kl_deposit_credit_to_ep(cred_info
,
500 cur_ep_dist
->cred_min
);
501 cur_ep_dist
->dist_flags
|= HTC_EP_ACTIVE
;
504 if (cur_ep_dist
->svc_id
== WMI_CONTROL_SVC
) {
505 ath6kl_deposit_credit_to_ep(cred_info
, cur_ep_dist
,
506 cur_ep_dist
->cred_min
);
508 * Control service is always marked active, it
509 * never goes inactive EVER.
511 cur_ep_dist
->dist_flags
|= HTC_EP_ACTIVE
;
512 } else if (cur_ep_dist
->svc_id
== WMI_DATA_BK_SVC
)
513 /* this is the lowest priority data endpoint */
514 cred_info
->lowestpri_ep_dist
= cur_ep_dist
->list
;
517 * Streams have to be created (explicit | implicit) for all
518 * kinds of traffic. BE endpoints are also inactive in the
519 * beginning. When BE traffic starts it creates implicit
520 * streams that redistributes credits.
522 * Note: all other endpoints have minimums set but are
523 * initially given NO credits. credits will be distributed
524 * as traffic activity demands
528 WARN_ON(cred_info
->cur_free_credits
<= 0);
530 list_for_each_entry(cur_ep_dist
, ep_list
, list
) {
531 if (cur_ep_dist
->endpoint
== ENDPOINT_0
)
534 if (cur_ep_dist
->svc_id
== WMI_CONTROL_SVC
)
535 cur_ep_dist
->cred_norm
= cur_ep_dist
->cred_per_msg
;
538 * For the remaining data endpoints, we assume that
539 * each cred_per_msg are the same. We use a simple
540 * calculation here, we take the remaining credits
541 * and determine how many max messages this can
542 * cover and then set each endpoint's normal value
543 * equal to 3/4 this amount.
545 count
= (cred_info
->cur_free_credits
/
546 cur_ep_dist
->cred_per_msg
)
547 * cur_ep_dist
->cred_per_msg
;
548 count
= (count
* 3) >> 2;
549 count
= max(count
, cur_ep_dist
->cred_per_msg
);
550 cur_ep_dist
->cred_norm
= count
;
556 /* initialize and setup credit distribution */
557 int ath6k_setup_credit_dist(void *htc_handle
,
558 struct htc_credit_state_info
*cred_info
)
560 u16 servicepriority
[5];
562 memset(cred_info
, 0, sizeof(struct htc_credit_state_info
));
564 servicepriority
[0] = WMI_CONTROL_SVC
; /* highest */
565 servicepriority
[1] = WMI_DATA_VO_SVC
;
566 servicepriority
[2] = WMI_DATA_VI_SVC
;
567 servicepriority
[3] = WMI_DATA_BE_SVC
;
568 servicepriority
[4] = WMI_DATA_BK_SVC
; /* lowest */
570 /* set priority list */
571 ath6kl_htc_set_credit_dist(htc_handle
, cred_info
, servicepriority
, 5);
576 /* reduce an ep's credits back to a set limit */
577 static void ath6k_reduce_credits(struct htc_credit_state_info
*cred_info
,
578 struct htc_endpoint_credit_dist
*ep_dist
,
583 ep_dist
->cred_assngd
= limit
;
585 if (ep_dist
->credits
<= limit
)
588 credits
= ep_dist
->credits
- limit
;
589 ep_dist
->credits
-= credits
;
590 cred_info
->cur_free_credits
+= credits
;
593 static void ath6k_credit_update(struct htc_credit_state_info
*cred_info
,
594 struct list_head
*epdist_list
)
596 struct htc_endpoint_credit_dist
*cur_dist_list
;
598 list_for_each_entry(cur_dist_list
, epdist_list
, list
) {
599 if (cur_dist_list
->endpoint
== ENDPOINT_0
)
602 if (cur_dist_list
->cred_to_dist
> 0) {
603 cur_dist_list
->credits
+=
604 cur_dist_list
->cred_to_dist
;
605 cur_dist_list
->cred_to_dist
= 0;
606 if (cur_dist_list
->credits
>
607 cur_dist_list
->cred_assngd
)
608 ath6k_reduce_credits(cred_info
,
610 cur_dist_list
->cred_assngd
);
612 if (cur_dist_list
->credits
>
613 cur_dist_list
->cred_norm
)
614 ath6k_reduce_credits(cred_info
, cur_dist_list
,
615 cur_dist_list
->cred_norm
);
617 if (!(cur_dist_list
->dist_flags
& HTC_EP_ACTIVE
)) {
618 if (cur_dist_list
->txq_depth
== 0)
619 ath6k_reduce_credits(cred_info
,
627 * HTC has an endpoint that needs credits, ep_dist is the endpoint in
630 void ath6k_seek_credits(struct htc_credit_state_info
*cred_info
,
631 struct htc_endpoint_credit_dist
*ep_dist
)
633 struct htc_endpoint_credit_dist
*curdist_list
;
637 if (ep_dist
->svc_id
== WMI_CONTROL_SVC
)
640 if ((ep_dist
->svc_id
== WMI_DATA_VI_SVC
) ||
641 (ep_dist
->svc_id
== WMI_DATA_VO_SVC
))
642 if ((ep_dist
->cred_assngd
>= ep_dist
->cred_norm
))
646 * For all other services, we follow a simple algorithm of:
648 * 1. checking the free pool for credits
649 * 2. checking lower priority endpoints for credits to take
652 credits
= min(cred_info
->cur_free_credits
, ep_dist
->seek_cred
);
654 if (credits
>= ep_dist
->seek_cred
)
658 * We don't have enough in the free pool, try taking away from
659 * lower priority services The rule for taking away credits:
661 * 1. Only take from lower priority endpoints
662 * 2. Only take what is allocated above the minimum (never
663 * starve an endpoint completely)
664 * 3. Only take what you need.
667 list_for_each_entry_reverse(curdist_list
,
668 &cred_info
->lowestpri_ep_dist
,
670 if (curdist_list
== ep_dist
)
673 need
= ep_dist
->seek_cred
- cred_info
->cur_free_credits
;
675 if ((curdist_list
->cred_assngd
- need
) >=
676 curdist_list
->cred_min
) {
678 * The current one has been allocated more than
679 * it's minimum and it has enough credits assigned
680 * above it's minimum to fulfill our need try to
681 * take away just enough to fulfill our need.
683 ath6k_reduce_credits(cred_info
, curdist_list
,
684 curdist_list
->cred_assngd
- need
);
686 if (cred_info
->cur_free_credits
>=
691 if (curdist_list
->endpoint
== ENDPOINT_0
)
695 credits
= min(cred_info
->cur_free_credits
, ep_dist
->seek_cred
);
698 /* did we find some credits? */
700 ath6kl_deposit_credit_to_ep(cred_info
, ep_dist
, credits
);
702 ep_dist
->seek_cred
= 0;
705 /* redistribute credits based on activity change */
706 static void ath6k_redistribute_credits(struct htc_credit_state_info
*info
,
707 struct list_head
*ep_dist_list
)
709 struct htc_endpoint_credit_dist
*curdist_list
;
711 list_for_each_entry(curdist_list
, ep_dist_list
, list
) {
712 if (curdist_list
->endpoint
== ENDPOINT_0
)
715 if ((curdist_list
->svc_id
== WMI_DATA_BK_SVC
) ||
716 (curdist_list
->svc_id
== WMI_DATA_BE_SVC
))
717 curdist_list
->dist_flags
|= HTC_EP_ACTIVE
;
719 if ((curdist_list
->svc_id
!= WMI_CONTROL_SVC
) &&
720 !(curdist_list
->dist_flags
& HTC_EP_ACTIVE
)) {
721 if (curdist_list
->txq_depth
== 0)
722 ath6k_reduce_credits(info
,
725 ath6k_reduce_credits(info
,
727 curdist_list
->cred_min
);
734 * This function is invoked whenever endpoints require credit
735 * distributions. A lock is held while this function is invoked, this
736 * function shall NOT block. The ep_dist_list is a list of distribution
737 * structures in prioritized order as defined by the call to the
738 * htc_set_credit_dist() api.
740 void ath6k_credit_distribute(struct htc_credit_state_info
*cred_info
,
741 struct list_head
*ep_dist_list
,
742 enum htc_credit_dist_reason reason
)
745 case HTC_CREDIT_DIST_SEND_COMPLETE
:
746 ath6k_credit_update(cred_info
, ep_dist_list
);
748 case HTC_CREDIT_DIST_ACTIVITY_CHANGE
:
749 ath6k_redistribute_credits(cred_info
, ep_dist_list
);
755 WARN_ON(cred_info
->cur_free_credits
> cred_info
->total_avail_credits
);
756 WARN_ON(cred_info
->cur_free_credits
< 0);
759 void disconnect_timer_handler(unsigned long ptr
)
761 struct net_device
*dev
= (struct net_device
*)ptr
;
762 struct ath6kl
*ar
= ath6kl_priv(dev
);
764 ath6kl_init_profile_info(ar
);
765 ath6kl_disconnect(ar
);
768 void ath6kl_disconnect(struct ath6kl
*ar
)
770 if (test_bit(CONNECTED
, &ar
->flag
) ||
771 test_bit(CONNECT_PEND
, &ar
->flag
)) {
772 ath6kl_wmi_disconnect_cmd(ar
->wmi
);
774 * Disconnect command is issued, clear the connect pending
775 * flag. The connected flag will be cleared in
776 * disconnect event notification.
778 clear_bit(CONNECT_PEND
, &ar
->flag
);
782 /* WMI Event handlers */
784 static const char *get_hw_id_string(u32 id
)
787 case AR6003_REV1_VERSION
:
789 case AR6003_REV2_VERSION
:
791 case AR6003_REV3_VERSION
:
798 void ath6kl_ready_event(void *devt
, u8
*datap
, u32 sw_ver
, u32 abi_ver
)
800 struct ath6kl
*ar
= devt
;
801 struct net_device
*dev
= ar
->net_dev
;
803 memcpy(dev
->dev_addr
, datap
, ETH_ALEN
);
804 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: mac addr = %pM\n",
805 __func__
, dev
->dev_addr
);
807 ar
->version
.wlan_ver
= sw_ver
;
808 ar
->version
.abi_ver
= abi_ver
;
810 snprintf(ar
->wdev
->wiphy
->fw_version
,
811 sizeof(ar
->wdev
->wiphy
->fw_version
),
813 (ar
->version
.wlan_ver
& 0xf0000000) >> 28,
814 (ar
->version
.wlan_ver
& 0x0f000000) >> 24,
815 (ar
->version
.wlan_ver
& 0x00ff0000) >> 16,
816 (ar
->version
.wlan_ver
& 0x0000ffff));
818 /* indicate to the waiting thread that the ready event was received */
819 set_bit(WMI_READY
, &ar
->flag
);
820 wake_up(&ar
->event_wq
);
822 ath6kl_info("hw %s fw %s\n",
823 get_hw_id_string(ar
->wdev
->wiphy
->hw_version
),
824 ar
->wdev
->wiphy
->fw_version
);
827 void ath6kl_scan_complete_evt(struct ath6kl
*ar
, int status
)
829 ath6kl_cfg80211_scan_complete_event(ar
, status
);
831 if (!ar
->usr_bss_filter
)
832 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
834 ath6kl_dbg(ATH6KL_DBG_WLAN_SCAN
, "scan complete: %d\n", status
);
837 void ath6kl_connect_event(struct ath6kl
*ar
, u16 channel
, u8
*bssid
,
838 u16 listen_int
, u16 beacon_int
,
839 enum network_type net_type
, u8 beacon_ie_len
,
840 u8 assoc_req_len
, u8 assoc_resp_len
,
845 if (ar
->nw_type
== AP_NETWORK
) {
846 ath6kl_connect_ap_mode(ar
, channel
, bssid
, listen_int
,
847 beacon_int
, assoc_resp_len
,
852 ath6kl_cfg80211_connect_event(ar
, channel
, bssid
,
853 listen_int
, beacon_int
,
854 net_type
, beacon_ie_len
,
855 assoc_req_len
, assoc_resp_len
,
858 memcpy(ar
->bssid
, bssid
, sizeof(ar
->bssid
));
859 ar
->bss_ch
= channel
;
861 if ((ar
->nw_type
== INFRA_NETWORK
))
862 ath6kl_wmi_listeninterval_cmd(ar
->wmi
, ar
->listen_intvl_t
,
865 netif_wake_queue(ar
->net_dev
);
867 /* Update connect & link status atomically */
868 spin_lock_irqsave(&ar
->lock
, flags
);
869 set_bit(CONNECTED
, &ar
->flag
);
870 clear_bit(CONNECT_PEND
, &ar
->flag
);
871 netif_carrier_on(ar
->net_dev
);
872 spin_unlock_irqrestore(&ar
->lock
, flags
);
874 aggr_reset_state(ar
->aggr_cntxt
);
875 ar
->reconnect_flag
= 0;
877 if ((ar
->nw_type
== ADHOC_NETWORK
) && ar
->ibss_ps_enable
) {
878 memset(ar
->node_map
, 0, sizeof(ar
->node_map
));
880 ar
->next_ep_id
= ENDPOINT_2
;
883 if (!ar
->usr_bss_filter
)
884 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
887 void ath6kl_tkip_micerr_event(struct ath6kl
*ar
, u8 keyid
, bool ismcast
)
889 struct ath6kl_sta
*sta
;
892 * For AP case, keyid will have aid of STA which sent pkt with
893 * MIC error. Use this aid to get MAC & send it to hostapd.
895 if (ar
->nw_type
== AP_NETWORK
) {
896 sta
= ath6kl_find_sta_by_aid(ar
, (keyid
>> 2));
900 ath6kl_dbg(ATH6KL_DBG_TRC
,
901 "ap tkip mic error received from aid=%d\n", keyid
);
903 memset(tsc
, 0, sizeof(tsc
)); /* FIX: get correct TSC */
904 cfg80211_michael_mic_failure(ar
->net_dev
, sta
->mac
,
905 NL80211_KEYTYPE_PAIRWISE
, keyid
,
908 ath6kl_cfg80211_tkip_micerr_event(ar
, keyid
, ismcast
);
912 static void ath6kl_update_target_stats(struct ath6kl
*ar
, u8
*ptr
, u32 len
)
914 struct wmi_target_stats
*tgt_stats
=
915 (struct wmi_target_stats
*) ptr
;
916 struct target_stats
*stats
= &ar
->target_stats
;
917 struct tkip_ccmp_stats
*ccmp_stats
;
918 struct bss
*conn_bss
= NULL
;
919 struct cserv_stats
*c_stats
;
922 if (len
< sizeof(*tgt_stats
))
925 /* update the RSSI of the connected bss */
926 if (test_bit(CONNECTED
, &ar
->flag
)) {
927 conn_bss
= ath6kl_wmi_find_node(ar
->wmi
, ar
->bssid
);
929 c_stats
= &tgt_stats
->cserv_stats
;
931 a_sle16_to_cpu(c_stats
->cs_ave_beacon_rssi
);
933 tgt_stats
->cserv_stats
.cs_ave_beacon_snr
;
934 ath6kl_wmi_node_return(ar
->wmi
, conn_bss
);
938 ath6kl_dbg(ATH6KL_DBG_TRC
, "updating target stats\n");
940 stats
->tx_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.pkt
);
941 stats
->tx_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.byte
);
942 stats
->tx_ucast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.ucast_pkt
);
943 stats
->tx_ucast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.ucast_byte
);
944 stats
->tx_mcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.mcast_pkt
);
945 stats
->tx_mcast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.mcast_byte
);
946 stats
->tx_bcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.bcast_pkt
);
947 stats
->tx_bcast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.bcast_byte
);
948 stats
->tx_rts_success_cnt
+=
949 le32_to_cpu(tgt_stats
->stats
.tx
.rts_success_cnt
);
951 for (ac
= 0; ac
< WMM_NUM_AC
; ac
++)
952 stats
->tx_pkt_per_ac
[ac
] +=
953 le32_to_cpu(tgt_stats
->stats
.tx
.pkt_per_ac
[ac
]);
955 stats
->tx_err
+= le32_to_cpu(tgt_stats
->stats
.tx
.err
);
956 stats
->tx_fail_cnt
+= le32_to_cpu(tgt_stats
->stats
.tx
.fail_cnt
);
957 stats
->tx_retry_cnt
+= le32_to_cpu(tgt_stats
->stats
.tx
.retry_cnt
);
958 stats
->tx_mult_retry_cnt
+=
959 le32_to_cpu(tgt_stats
->stats
.tx
.mult_retry_cnt
);
960 stats
->tx_rts_fail_cnt
+=
961 le32_to_cpu(tgt_stats
->stats
.tx
.rts_fail_cnt
);
962 stats
->tx_ucast_rate
=
963 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats
->stats
.tx
.ucast_rate
));
965 stats
->rx_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.pkt
);
966 stats
->rx_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.byte
);
967 stats
->rx_ucast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.ucast_pkt
);
968 stats
->rx_ucast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.ucast_byte
);
969 stats
->rx_mcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.mcast_pkt
);
970 stats
->rx_mcast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.mcast_byte
);
971 stats
->rx_bcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.bcast_pkt
);
972 stats
->rx_bcast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.bcast_byte
);
973 stats
->rx_frgment_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.frgment_pkt
);
974 stats
->rx_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.err
);
975 stats
->rx_crc_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.crc_err
);
976 stats
->rx_key_cache_miss
+=
977 le32_to_cpu(tgt_stats
->stats
.rx
.key_cache_miss
);
978 stats
->rx_decrypt_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.decrypt_err
);
979 stats
->rx_dupl_frame
+= le32_to_cpu(tgt_stats
->stats
.rx
.dupl_frame
);
980 stats
->rx_ucast_rate
=
981 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats
->stats
.rx
.ucast_rate
));
983 ccmp_stats
= &tgt_stats
->stats
.tkip_ccmp_stats
;
985 stats
->tkip_local_mic_fail
+=
986 le32_to_cpu(ccmp_stats
->tkip_local_mic_fail
);
987 stats
->tkip_cnter_measures_invoked
+=
988 le32_to_cpu(ccmp_stats
->tkip_cnter_measures_invoked
);
989 stats
->tkip_fmt_err
+= le32_to_cpu(ccmp_stats
->tkip_fmt_err
);
991 stats
->ccmp_fmt_err
+= le32_to_cpu(ccmp_stats
->ccmp_fmt_err
);
992 stats
->ccmp_replays
+= le32_to_cpu(ccmp_stats
->ccmp_replays
);
994 stats
->pwr_save_fail_cnt
+=
995 le32_to_cpu(tgt_stats
->pm_stats
.pwr_save_failure_cnt
);
996 stats
->noise_floor_calib
=
997 a_sle32_to_cpu(tgt_stats
->noise_floor_calib
);
999 stats
->cs_bmiss_cnt
+=
1000 le32_to_cpu(tgt_stats
->cserv_stats
.cs_bmiss_cnt
);
1001 stats
->cs_low_rssi_cnt
+=
1002 le32_to_cpu(tgt_stats
->cserv_stats
.cs_low_rssi_cnt
);
1003 stats
->cs_connect_cnt
+=
1004 le16_to_cpu(tgt_stats
->cserv_stats
.cs_connect_cnt
);
1005 stats
->cs_discon_cnt
+=
1006 le16_to_cpu(tgt_stats
->cserv_stats
.cs_discon_cnt
);
1008 stats
->cs_ave_beacon_rssi
=
1009 a_sle16_to_cpu(tgt_stats
->cserv_stats
.cs_ave_beacon_rssi
);
1011 stats
->cs_last_roam_msec
=
1012 tgt_stats
->cserv_stats
.cs_last_roam_msec
;
1013 stats
->cs_snr
= tgt_stats
->cserv_stats
.cs_snr
;
1014 stats
->cs_rssi
= a_sle16_to_cpu(tgt_stats
->cserv_stats
.cs_rssi
);
1016 stats
->lq_val
= le32_to_cpu(tgt_stats
->lq_val
);
1018 stats
->wow_pkt_dropped
+=
1019 le32_to_cpu(tgt_stats
->wow_stats
.wow_pkt_dropped
);
1020 stats
->wow_host_pkt_wakeups
+=
1021 tgt_stats
->wow_stats
.wow_host_pkt_wakeups
;
1022 stats
->wow_host_evt_wakeups
+=
1023 tgt_stats
->wow_stats
.wow_host_evt_wakeups
;
1024 stats
->wow_evt_discarded
+=
1025 le16_to_cpu(tgt_stats
->wow_stats
.wow_evt_discarded
);
1027 if (test_bit(STATS_UPDATE_PEND
, &ar
->flag
)) {
1028 clear_bit(STATS_UPDATE_PEND
, &ar
->flag
);
1029 wake_up(&ar
->event_wq
);
1033 static void ath6kl_add_le32(__le32
*var
, __le32 val
)
1035 *var
= cpu_to_le32(le32_to_cpu(*var
) + le32_to_cpu(val
));
1038 void ath6kl_tgt_stats_event(struct ath6kl
*ar
, u8
*ptr
, u32 len
)
1040 struct wmi_ap_mode_stat
*p
= (struct wmi_ap_mode_stat
*) ptr
;
1041 struct wmi_ap_mode_stat
*ap
= &ar
->ap_stats
;
1042 struct wmi_per_sta_stat
*st_ap
, *st_p
;
1045 if (ar
->nw_type
== AP_NETWORK
) {
1046 if (len
< sizeof(*p
))
1049 for (ac
= 0; ac
< AP_MAX_NUM_STA
; ac
++) {
1050 st_ap
= &ap
->sta
[ac
];
1053 ath6kl_add_le32(&st_ap
->tx_bytes
, st_p
->tx_bytes
);
1054 ath6kl_add_le32(&st_ap
->tx_pkts
, st_p
->tx_pkts
);
1055 ath6kl_add_le32(&st_ap
->tx_error
, st_p
->tx_error
);
1056 ath6kl_add_le32(&st_ap
->tx_discard
, st_p
->tx_discard
);
1057 ath6kl_add_le32(&st_ap
->rx_bytes
, st_p
->rx_bytes
);
1058 ath6kl_add_le32(&st_ap
->rx_pkts
, st_p
->rx_pkts
);
1059 ath6kl_add_le32(&st_ap
->rx_error
, st_p
->rx_error
);
1060 ath6kl_add_le32(&st_ap
->rx_discard
, st_p
->rx_discard
);
1064 ath6kl_update_target_stats(ar
, ptr
, len
);
1068 void ath6kl_wakeup_event(void *dev
)
1070 struct ath6kl
*ar
= (struct ath6kl
*) dev
;
1072 wake_up(&ar
->event_wq
);
1075 void ath6kl_txpwr_rx_evt(void *devt
, u8 tx_pwr
)
1077 struct ath6kl
*ar
= (struct ath6kl
*) devt
;
1079 ar
->tx_pwr
= tx_pwr
;
1080 wake_up(&ar
->event_wq
);
1083 void ath6kl_pspoll_event(struct ath6kl
*ar
, u8 aid
)
1085 struct ath6kl_sta
*conn
;
1086 struct sk_buff
*skb
;
1087 bool psq_empty
= false;
1089 conn
= ath6kl_find_sta_by_aid(ar
, aid
);
1094 * Send out a packet queued on ps queue. When the ps queue
1095 * becomes empty update the PVB for this station.
1097 spin_lock_bh(&conn
->psq_lock
);
1098 psq_empty
= skb_queue_empty(&conn
->psq
);
1099 spin_unlock_bh(&conn
->psq_lock
);
1102 /* TODO: Send out a NULL data frame */
1105 spin_lock_bh(&conn
->psq_lock
);
1106 skb
= skb_dequeue(&conn
->psq
);
1107 spin_unlock_bh(&conn
->psq_lock
);
1109 conn
->sta_flags
|= STA_PS_POLLED
;
1110 ath6kl_data_tx(skb
, ar
->net_dev
);
1111 conn
->sta_flags
&= ~STA_PS_POLLED
;
1113 spin_lock_bh(&conn
->psq_lock
);
1114 psq_empty
= skb_queue_empty(&conn
->psq
);
1115 spin_unlock_bh(&conn
->psq_lock
);
1118 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, conn
->aid
, 0);
1121 void ath6kl_dtimexpiry_event(struct ath6kl
*ar
)
1123 bool mcastq_empty
= false;
1124 struct sk_buff
*skb
;
1127 * If there are no associated STAs, ignore the DTIM expiry event.
1128 * There can be potential race conditions where the last associated
1129 * STA may disconnect & before the host could clear the 'Indicate
1130 * DTIM' request to the firmware, the firmware would have just
1131 * indicated a DTIM expiry event. The race is between 'clear DTIM
1132 * expiry cmd' going from the host to the firmware & the DTIM
1133 * expiry event happening from the firmware to the host.
1135 if (!ar
->sta_list_index
)
1138 spin_lock_bh(&ar
->mcastpsq_lock
);
1139 mcastq_empty
= skb_queue_empty(&ar
->mcastpsq
);
1140 spin_unlock_bh(&ar
->mcastpsq_lock
);
1145 /* set the STA flag to dtim_expired for the frame to go out */
1146 set_bit(DTIM_EXPIRED
, &ar
->flag
);
1148 spin_lock_bh(&ar
->mcastpsq_lock
);
1149 while ((skb
= skb_dequeue(&ar
->mcastpsq
)) != NULL
) {
1150 spin_unlock_bh(&ar
->mcastpsq_lock
);
1152 ath6kl_data_tx(skb
, ar
->net_dev
);
1154 spin_lock_bh(&ar
->mcastpsq_lock
);
1156 spin_unlock_bh(&ar
->mcastpsq_lock
);
1158 clear_bit(DTIM_EXPIRED
, &ar
->flag
);
1160 /* clear the LSB of the BitMapCtl field of the TIM IE */
1161 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, MCAST_AID
, 0);
1164 void ath6kl_disconnect_event(struct ath6kl
*ar
, u8 reason
, u8
*bssid
,
1165 u8 assoc_resp_len
, u8
*assoc_info
,
1166 u16 prot_reason_status
)
1168 struct bss
*wmi_ssid_node
= NULL
;
1169 unsigned long flags
;
1171 if (ar
->nw_type
== AP_NETWORK
) {
1172 if (!ath6kl_remove_sta(ar
, bssid
, prot_reason_status
))
1175 /* if no more associated STAs, empty the mcast PS q */
1176 if (ar
->sta_list_index
== 0) {
1177 spin_lock_bh(&ar
->mcastpsq_lock
);
1178 skb_queue_purge(&ar
->mcastpsq
);
1179 spin_unlock_bh(&ar
->mcastpsq_lock
);
1181 /* clear the LSB of the TIM IE's BitMapCtl field */
1182 if (test_bit(WMI_READY
, &ar
->flag
))
1183 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, MCAST_AID
, 0);
1186 if (!is_broadcast_ether_addr(bssid
)) {
1187 /* send event to application */
1188 cfg80211_del_sta(ar
->net_dev
, bssid
, GFP_KERNEL
);
1191 clear_bit(CONNECTED
, &ar
->flag
);
1195 ath6kl_cfg80211_disconnect_event(ar
, reason
, bssid
,
1196 assoc_resp_len
, assoc_info
,
1197 prot_reason_status
);
1199 aggr_reset_state(ar
->aggr_cntxt
);
1201 del_timer(&ar
->disconnect_timer
);
1203 ath6kl_dbg(ATH6KL_DBG_WLAN_CONNECT
,
1204 "disconnect reason is %d\n", reason
);
1207 * If the event is due to disconnect cmd from the host, only they
1208 * the target would stop trying to connect. Under any other
1209 * condition, target would keep trying to connect.
1211 if (reason
== DISCONNECT_CMD
) {
1212 if (!ar
->usr_bss_filter
&& test_bit(WMI_READY
, &ar
->flag
))
1213 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
1215 set_bit(CONNECT_PEND
, &ar
->flag
);
1216 if (((reason
== ASSOC_FAILED
) &&
1217 (prot_reason_status
== 0x11)) ||
1218 ((reason
== ASSOC_FAILED
) && (prot_reason_status
== 0x0)
1219 && (ar
->reconnect_flag
== 1))) {
1220 set_bit(CONNECTED
, &ar
->flag
);
1225 if ((reason
== NO_NETWORK_AVAIL
) && test_bit(WMI_READY
, &ar
->flag
)) {
1226 ath6kl_wmi_node_free(ar
->wmi
, bssid
);
1229 * In case any other same SSID nodes are present remove it,
1230 * since those nodes also not available now.
1234 * Find the nodes based on SSID and remove it
1236 * Note: This case will not work out for
1239 wmi_ssid_node
= ath6kl_wmi_find_ssid_node(ar
->wmi
,
1246 ath6kl_wmi_node_free(ar
->wmi
,
1247 wmi_ssid_node
->ni_macaddr
);
1249 } while (wmi_ssid_node
);
1252 /* update connect & link status atomically */
1253 spin_lock_irqsave(&ar
->lock
, flags
);
1254 clear_bit(CONNECTED
, &ar
->flag
);
1255 netif_carrier_off(ar
->net_dev
);
1256 spin_unlock_irqrestore(&ar
->lock
, flags
);
1258 if ((reason
!= CSERV_DISCONNECT
) || (ar
->reconnect_flag
!= 1))
1259 ar
->reconnect_flag
= 0;
1261 if (reason
!= CSERV_DISCONNECT
)
1262 ar
->user_key_ctrl
= 0;
1264 netif_stop_queue(ar
->net_dev
);
1265 memset(ar
->bssid
, 0, sizeof(ar
->bssid
));
1268 ath6kl_tx_data_cleanup(ar
);
1271 static int ath6kl_open(struct net_device
*dev
)
1273 struct ath6kl
*ar
= ath6kl_priv(dev
);
1274 unsigned long flags
;
1276 spin_lock_irqsave(&ar
->lock
, flags
);
1278 set_bit(WLAN_ENABLED
, &ar
->flag
);
1280 if (test_bit(CONNECTED
, &ar
->flag
)) {
1281 netif_carrier_on(dev
);
1282 netif_wake_queue(dev
);
1284 netif_carrier_off(dev
);
1286 spin_unlock_irqrestore(&ar
->lock
, flags
);
1291 static int ath6kl_close(struct net_device
*dev
)
1293 struct ath6kl
*ar
= ath6kl_priv(dev
);
1295 netif_stop_queue(dev
);
1297 ath6kl_disconnect(ar
);
1299 if (test_bit(WMI_READY
, &ar
->flag
)) {
1300 if (ath6kl_wmi_scanparams_cmd(ar
->wmi
, 0xFFFF, 0, 0, 0, 0, 0, 0,
1304 clear_bit(WLAN_ENABLED
, &ar
->flag
);
1307 ath6kl_cfg80211_scan_complete_event(ar
, -ECANCELED
);
1312 static struct net_device_stats
*ath6kl_get_stats(struct net_device
*dev
)
1314 struct ath6kl
*ar
= ath6kl_priv(dev
);
1316 return &ar
->net_stats
;
1319 static struct net_device_ops ath6kl_netdev_ops
= {
1320 .ndo_open
= ath6kl_open
,
1321 .ndo_stop
= ath6kl_close
,
1322 .ndo_start_xmit
= ath6kl_data_tx
,
1323 .ndo_get_stats
= ath6kl_get_stats
,
1326 void init_netdev(struct net_device
*dev
)
1328 dev
->netdev_ops
= &ath6kl_netdev_ops
;
1329 dev
->watchdog_timeo
= ATH6KL_TX_TIMEOUT
;
1331 dev
->needed_headroom
= ETH_HLEN
;
1332 dev
->needed_headroom
+= sizeof(struct ath6kl_llc_snap_hdr
) +
1333 sizeof(struct wmi_data_hdr
) + HTC_HDR_LENGTH
1334 + WMI_MAX_TX_META_SZ
;