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
194 memset(addr_val
, ((u8
*)&addr
)[i
], 4);
197 * Hit each byte of the register address with a 4-byte
198 * write operation to the same address, this is a harmless
201 status
= hif_read_write_sync(ar
, reg_addr
+ i
, addr_val
,
202 4, HIF_WR_SYNC_BYTE_FIX
);
208 ath6kl_err("failed to write initial bytes of 0x%x to window reg: 0x%X\n",
214 * Write the address register again, this time write the whole
215 * 4-byte value. The effect here is that the LSB write causes the
216 * cycle to start, the extra 3 byte write to bytes 1,2,3 has no
217 * effect since we are writing the same values again
219 status
= hif_read_write_sync(ar
, reg_addr
, (u8
*)(&addr
),
220 4, HIF_WR_SYNC_BYTE_INC
);
223 ath6kl_err("failed to write 0x%x to window reg: 0x%X\n",
232 * Read from the ATH6KL through its diagnostic window. No cooperation from
233 * the Target is required for this.
235 int ath6kl_read_reg_diag(struct ath6kl
*ar
, u32
*address
, u32
*data
)
239 /* set window register to start read cycle */
240 status
= ath6kl_set_addrwin_reg(ar
, WINDOW_READ_ADDR_ADDRESS
,
247 status
= hif_read_write_sync(ar
, WINDOW_DATA_ADDRESS
, (u8
*)data
,
248 sizeof(u32
), HIF_RD_SYNC_BYTE_INC
);
250 ath6kl_err("failed to read from window data addr\n");
259 * Write to the ATH6KL through its diagnostic window. No cooperation from
260 * the Target is required for this.
262 static int ath6kl_write_reg_diag(struct ath6kl
*ar
, u32
*address
, u32
*data
)
267 status
= hif_read_write_sync(ar
, WINDOW_DATA_ADDRESS
, (u8
*)data
,
268 sizeof(u32
), HIF_WR_SYNC_BYTE_INC
);
270 ath6kl_err("failed to write 0x%x to window data addr\n", *data
);
274 /* set window register, which starts the write cycle */
275 return ath6kl_set_addrwin_reg(ar
, WINDOW_WRITE_ADDR_ADDRESS
,
279 int ath6kl_access_datadiag(struct ath6kl
*ar
, u32 address
,
280 u8
*data
, u32 length
, bool read
)
285 for (count
= 0; count
< length
; count
+= 4, address
+= 4) {
287 status
= ath6kl_read_reg_diag(ar
, &address
,
288 (u32
*) &data
[count
]);
292 status
= ath6kl_write_reg_diag(ar
, &address
,
293 (u32
*) &data
[count
]);
302 /* FIXME: move to a better place, target.h? */
303 #define AR6003_RESET_CONTROL_ADDRESS 0x00004000
304 #define AR6004_RESET_CONTROL_ADDRESS 0x00004000
306 static void ath6kl_reset_device(struct ath6kl
*ar
, u32 target_type
,
307 bool wait_fot_compltn
, bool cold_reset
)
313 if (target_type
!= TARGET_TYPE_AR6003
&&
314 target_type
!= TARGET_TYPE_AR6004
)
317 data
= cold_reset
? RESET_CONTROL_COLD_RST
: RESET_CONTROL_MBOX_RST
;
319 switch (target_type
) {
320 case TARGET_TYPE_AR6003
:
321 address
= AR6003_RESET_CONTROL_ADDRESS
;
323 case TARGET_TYPE_AR6004
:
324 address
= AR6004_RESET_CONTROL_ADDRESS
;
327 address
= AR6003_RESET_CONTROL_ADDRESS
;
331 status
= ath6kl_write_reg_diag(ar
, &address
, &data
);
334 ath6kl_err("failed to reset target\n");
337 void ath6kl_stop_endpoint(struct net_device
*dev
, bool keep_profile
,
340 struct ath6kl
*ar
= ath6kl_priv(dev
);
341 static u8 bcast_mac
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
344 netif_stop_queue(dev
);
346 /* disable the target and the interrupts associated with it */
347 if (test_bit(WMI_READY
, &ar
->flag
)) {
348 discon_issued
= (test_bit(CONNECTED
, &ar
->flag
) ||
349 test_bit(CONNECT_PEND
, &ar
->flag
));
350 ath6kl_disconnect(ar
);
352 ath6kl_init_profile_info(ar
);
354 del_timer(&ar
->disconnect_timer
);
356 clear_bit(WMI_READY
, &ar
->flag
);
357 ath6kl_wmi_shutdown(ar
->wmi
);
358 clear_bit(WMI_ENABLED
, &ar
->flag
);
362 * After wmi_shudown all WMI events will be dropped. We
363 * need to cleanup the buffers allocated in AP mode and
364 * give disconnect notification to stack, which usually
365 * happens in the disconnect_event. Simulate the disconnect
366 * event by calling the function directly. Sometimes
367 * disconnect_event will be received when the debug logs
371 ath6kl_disconnect_event(ar
, DISCONNECT_CMD
,
372 (ar
->nw_type
& AP_NETWORK
) ?
373 bcast_mac
: ar
->bssid
,
376 ar
->user_key_ctrl
= 0;
379 ath6kl_dbg(ATH6KL_DBG_TRC
,
380 "%s: wmi is not ready 0x%p 0x%p\n",
381 __func__
, ar
, ar
->wmi
);
383 /* Shut down WMI if we have started it */
384 if (test_bit(WMI_ENABLED
, &ar
->flag
)) {
385 ath6kl_dbg(ATH6KL_DBG_TRC
,
386 "%s: shut down wmi\n", __func__
);
387 ath6kl_wmi_shutdown(ar
->wmi
);
388 clear_bit(WMI_ENABLED
, &ar
->flag
);
393 if (ar
->htc_target
) {
394 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: shut down htc\n", __func__
);
395 ath6kl_htc_stop(ar
->htc_target
);
399 * Try to reset the device if we can. The driver may have been
400 * configure NOT to reset the target during a debug session.
402 ath6kl_dbg(ATH6KL_DBG_TRC
,
403 "attempting to reset target on instance destroy\n");
404 ath6kl_reset_device(ar
, ar
->target_type
, true, true);
407 static void ath6kl_install_static_wep_keys(struct ath6kl
*ar
)
412 for (index
= WMI_MIN_KEY_INDEX
; index
<= WMI_MAX_KEY_INDEX
; index
++) {
413 if (ar
->wep_key_list
[index
].key_len
) {
414 keyusage
= GROUP_USAGE
;
415 if (index
== ar
->def_txkey_index
)
416 keyusage
|= TX_USAGE
;
418 ath6kl_wmi_addkey_cmd(ar
->wmi
,
422 ar
->wep_key_list
[index
].key_len
,
424 ar
->wep_key_list
[index
].key
,
425 KEY_OP_INIT_VAL
, NULL
,
431 static void ath6kl_connect_ap_mode(struct ath6kl
*ar
, u16 channel
, u8
*bssid
,
432 u16 listen_int
, u16 beacon_int
,
433 u8 assoc_req_len
, u8
*assoc_info
)
435 struct net_device
*dev
= ar
->net_dev
;
436 u8
*ies
= NULL
, *wpa_ie
= NULL
, *pos
;
438 struct station_info sinfo
;
439 struct ath6kl_req_key
*ik
;
440 enum crypto_type keyType
= NONE_CRYPT
;
442 if (memcmp(dev
->dev_addr
, bssid
, ETH_ALEN
) == 0) {
443 ik
= &ar
->ap_mode_bkey
;
445 switch (ar
->auth_mode
) {
447 if (ar
->prwise_crypto
== WEP_CRYPT
)
448 ath6kl_install_static_wep_keys(ar
);
452 case (WPA_PSK_AUTH
|WPA2_PSK_AUTH
):
453 switch (ik
->ik_type
) {
454 case ATH6KL_CIPHER_TKIP
:
455 keyType
= TKIP_CRYPT
;
457 case ATH6KL_CIPHER_AES_CCM
:
463 ath6kl_wmi_addkey_cmd(ar
->wmi
, ik
->ik_keyix
, keyType
,
464 GROUP_USAGE
, ik
->ik_keylen
,
465 (u8
*)&ik
->ik_keyrsc
,
467 KEY_OP_INIT_VAL
, ik
->ik_macaddr
,
472 set_bit(CONNECTED
, &ar
->flag
);
476 ath6kl_dbg(ATH6KL_DBG_TRC
, "new station %pM aid=%d\n",
479 if (assoc_req_len
> sizeof(struct ieee80211_hdr_3addr
)) {
480 struct ieee80211_mgmt
*mgmt
=
481 (struct ieee80211_mgmt
*) assoc_info
;
482 if (ieee80211_is_assoc_req(mgmt
->frame_control
) &&
483 assoc_req_len
>= sizeof(struct ieee80211_hdr_3addr
) +
484 sizeof(mgmt
->u
.assoc_req
)) {
485 ies
= mgmt
->u
.assoc_req
.variable
;
486 ies_len
= assoc_info
+ assoc_req_len
- ies
;
487 } else if (ieee80211_is_reassoc_req(mgmt
->frame_control
) &&
488 assoc_req_len
>= sizeof(struct ieee80211_hdr_3addr
)
489 + sizeof(mgmt
->u
.reassoc_req
)) {
490 ies
= mgmt
->u
.reassoc_req
.variable
;
491 ies_len
= assoc_info
+ assoc_req_len
- ies
;
496 while (pos
&& pos
+ 1 < ies
+ ies_len
) {
497 if (pos
+ 2 + pos
[1] > ies
+ ies_len
)
499 if (pos
[0] == WLAN_EID_RSN
)
500 wpa_ie
= pos
; /* RSN IE */
501 else if (pos
[0] == WLAN_EID_VENDOR_SPECIFIC
&&
503 pos
[2] == 0x00 && pos
[3] == 0x50 && pos
[4] == 0xf2) {
505 wpa_ie
= pos
; /* WPA IE */
506 else if (pos
[5] == 0x04) {
507 wpa_ie
= pos
; /* WPS IE */
508 break; /* overrides WPA/RSN IE */
514 ath6kl_add_new_sta(ar
, bssid
, channel
, wpa_ie
,
515 wpa_ie
? 2 + wpa_ie
[1] : 0,
516 listen_int
& 0xFF, beacon_int
,
517 (listen_int
>> 8) & 0xFF);
519 /* send event to application */
520 memset(&sinfo
, 0, sizeof(sinfo
));
522 /* TODO: sinfo.generation */
524 sinfo
.assoc_req_ies
= ies
;
525 sinfo
.assoc_req_ies_len
= ies_len
;
526 sinfo
.filled
|= STATION_INFO_ASSOC_REQ_IES
;
528 cfg80211_new_sta(ar
->net_dev
, bssid
, &sinfo
, GFP_KERNEL
);
530 netif_wake_queue(ar
->net_dev
);
535 /* Functions for Tx credit handling */
536 void ath6k_credit_init(struct htc_credit_state_info
*cred_info
,
537 struct list_head
*ep_list
,
540 struct htc_endpoint_credit_dist
*cur_ep_dist
;
543 cred_info
->cur_free_credits
= tot_credits
;
544 cred_info
->total_avail_credits
= tot_credits
;
546 list_for_each_entry(cur_ep_dist
, ep_list
, list
) {
547 if (cur_ep_dist
->endpoint
== ENDPOINT_0
)
550 cur_ep_dist
->cred_min
= cur_ep_dist
->cred_per_msg
;
553 if ((cur_ep_dist
->svc_id
== WMI_DATA_BK_SVC
) ||
554 (cur_ep_dist
->svc_id
== WMI_DATA_BE_SVC
)) {
555 ath6kl_deposit_credit_to_ep(cred_info
,
557 cur_ep_dist
->cred_min
);
558 cur_ep_dist
->dist_flags
|= HTC_EP_ACTIVE
;
561 if (cur_ep_dist
->svc_id
== WMI_CONTROL_SVC
) {
562 ath6kl_deposit_credit_to_ep(cred_info
, cur_ep_dist
,
563 cur_ep_dist
->cred_min
);
565 * Control service is always marked active, it
566 * never goes inactive EVER.
568 cur_ep_dist
->dist_flags
|= HTC_EP_ACTIVE
;
569 } else if (cur_ep_dist
->svc_id
== WMI_DATA_BK_SVC
)
570 /* this is the lowest priority data endpoint */
571 cred_info
->lowestpri_ep_dist
= cur_ep_dist
->list
;
574 * Streams have to be created (explicit | implicit) for all
575 * kinds of traffic. BE endpoints are also inactive in the
576 * beginning. When BE traffic starts it creates implicit
577 * streams that redistributes credits.
579 * Note: all other endpoints have minimums set but are
580 * initially given NO credits. credits will be distributed
581 * as traffic activity demands
585 WARN_ON(cred_info
->cur_free_credits
<= 0);
587 list_for_each_entry(cur_ep_dist
, ep_list
, list
) {
588 if (cur_ep_dist
->endpoint
== ENDPOINT_0
)
591 if (cur_ep_dist
->svc_id
== WMI_CONTROL_SVC
)
592 cur_ep_dist
->cred_norm
= cur_ep_dist
->cred_per_msg
;
595 * For the remaining data endpoints, we assume that
596 * each cred_per_msg are the same. We use a simple
597 * calculation here, we take the remaining credits
598 * and determine how many max messages this can
599 * cover and then set each endpoint's normal value
600 * equal to 3/4 this amount.
602 count
= (cred_info
->cur_free_credits
/
603 cur_ep_dist
->cred_per_msg
)
604 * cur_ep_dist
->cred_per_msg
;
605 count
= (count
* 3) >> 2;
606 count
= max(count
, cur_ep_dist
->cred_per_msg
);
607 cur_ep_dist
->cred_norm
= count
;
613 /* initialize and setup credit distribution */
614 int ath6k_setup_credit_dist(void *htc_handle
,
615 struct htc_credit_state_info
*cred_info
)
617 u16 servicepriority
[5];
619 memset(cred_info
, 0, sizeof(struct htc_credit_state_info
));
621 servicepriority
[0] = WMI_CONTROL_SVC
; /* highest */
622 servicepriority
[1] = WMI_DATA_VO_SVC
;
623 servicepriority
[2] = WMI_DATA_VI_SVC
;
624 servicepriority
[3] = WMI_DATA_BE_SVC
;
625 servicepriority
[4] = WMI_DATA_BK_SVC
; /* lowest */
627 /* set priority list */
628 ath6kl_htc_set_credit_dist(htc_handle
, cred_info
, servicepriority
, 5);
633 /* reduce an ep's credits back to a set limit */
634 static void ath6k_reduce_credits(struct htc_credit_state_info
*cred_info
,
635 struct htc_endpoint_credit_dist
*ep_dist
,
640 ep_dist
->cred_assngd
= limit
;
642 if (ep_dist
->credits
<= limit
)
645 credits
= ep_dist
->credits
- limit
;
646 ep_dist
->credits
-= credits
;
647 cred_info
->cur_free_credits
+= credits
;
650 static void ath6k_credit_update(struct htc_credit_state_info
*cred_info
,
651 struct list_head
*epdist_list
)
653 struct htc_endpoint_credit_dist
*cur_dist_list
;
655 list_for_each_entry(cur_dist_list
, epdist_list
, list
) {
656 if (cur_dist_list
->endpoint
== ENDPOINT_0
)
659 if (cur_dist_list
->cred_to_dist
> 0) {
660 cur_dist_list
->credits
+=
661 cur_dist_list
->cred_to_dist
;
662 cur_dist_list
->cred_to_dist
= 0;
663 if (cur_dist_list
->credits
>
664 cur_dist_list
->cred_assngd
)
665 ath6k_reduce_credits(cred_info
,
667 cur_dist_list
->cred_assngd
);
669 if (cur_dist_list
->credits
>
670 cur_dist_list
->cred_norm
)
671 ath6k_reduce_credits(cred_info
, cur_dist_list
,
672 cur_dist_list
->cred_norm
);
674 if (!(cur_dist_list
->dist_flags
& HTC_EP_ACTIVE
)) {
675 if (cur_dist_list
->txq_depth
== 0)
676 ath6k_reduce_credits(cred_info
,
684 * HTC has an endpoint that needs credits, ep_dist is the endpoint in
687 void ath6k_seek_credits(struct htc_credit_state_info
*cred_info
,
688 struct htc_endpoint_credit_dist
*ep_dist
)
690 struct htc_endpoint_credit_dist
*curdist_list
;
694 if (ep_dist
->svc_id
== WMI_CONTROL_SVC
)
697 if ((ep_dist
->svc_id
== WMI_DATA_VI_SVC
) ||
698 (ep_dist
->svc_id
== WMI_DATA_VO_SVC
))
699 if ((ep_dist
->cred_assngd
>= ep_dist
->cred_norm
))
703 * For all other services, we follow a simple algorithm of:
705 * 1. checking the free pool for credits
706 * 2. checking lower priority endpoints for credits to take
709 credits
= min(cred_info
->cur_free_credits
, ep_dist
->seek_cred
);
711 if (credits
>= ep_dist
->seek_cred
)
715 * We don't have enough in the free pool, try taking away from
716 * lower priority services The rule for taking away credits:
718 * 1. Only take from lower priority endpoints
719 * 2. Only take what is allocated above the minimum (never
720 * starve an endpoint completely)
721 * 3. Only take what you need.
724 list_for_each_entry_reverse(curdist_list
,
725 &cred_info
->lowestpri_ep_dist
,
727 if (curdist_list
== ep_dist
)
730 need
= ep_dist
->seek_cred
- cred_info
->cur_free_credits
;
732 if ((curdist_list
->cred_assngd
- need
) >=
733 curdist_list
->cred_min
) {
735 * The current one has been allocated more than
736 * it's minimum and it has enough credits assigned
737 * above it's minimum to fulfill our need try to
738 * take away just enough to fulfill our need.
740 ath6k_reduce_credits(cred_info
, curdist_list
,
741 curdist_list
->cred_assngd
- need
);
743 if (cred_info
->cur_free_credits
>=
748 if (curdist_list
->endpoint
== ENDPOINT_0
)
752 credits
= min(cred_info
->cur_free_credits
, ep_dist
->seek_cred
);
755 /* did we find some credits? */
757 ath6kl_deposit_credit_to_ep(cred_info
, ep_dist
, credits
);
759 ep_dist
->seek_cred
= 0;
762 /* redistribute credits based on activity change */
763 static void ath6k_redistribute_credits(struct htc_credit_state_info
*info
,
764 struct list_head
*ep_dist_list
)
766 struct htc_endpoint_credit_dist
*curdist_list
;
768 list_for_each_entry(curdist_list
, ep_dist_list
, list
) {
769 if (curdist_list
->endpoint
== ENDPOINT_0
)
772 if ((curdist_list
->svc_id
== WMI_DATA_BK_SVC
) ||
773 (curdist_list
->svc_id
== WMI_DATA_BE_SVC
))
774 curdist_list
->dist_flags
|= HTC_EP_ACTIVE
;
776 if ((curdist_list
->svc_id
!= WMI_CONTROL_SVC
) &&
777 !(curdist_list
->dist_flags
& HTC_EP_ACTIVE
)) {
778 if (curdist_list
->txq_depth
== 0)
779 ath6k_reduce_credits(info
,
782 ath6k_reduce_credits(info
,
784 curdist_list
->cred_min
);
791 * This function is invoked whenever endpoints require credit
792 * distributions. A lock is held while this function is invoked, this
793 * function shall NOT block. The ep_dist_list is a list of distribution
794 * structures in prioritized order as defined by the call to the
795 * htc_set_credit_dist() api.
797 void ath6k_credit_distribute(struct htc_credit_state_info
*cred_info
,
798 struct list_head
*ep_dist_list
,
799 enum htc_credit_dist_reason reason
)
802 case HTC_CREDIT_DIST_SEND_COMPLETE
:
803 ath6k_credit_update(cred_info
, ep_dist_list
);
805 case HTC_CREDIT_DIST_ACTIVITY_CHANGE
:
806 ath6k_redistribute_credits(cred_info
, ep_dist_list
);
812 WARN_ON(cred_info
->cur_free_credits
> cred_info
->total_avail_credits
);
813 WARN_ON(cred_info
->cur_free_credits
< 0);
816 void disconnect_timer_handler(unsigned long ptr
)
818 struct net_device
*dev
= (struct net_device
*)ptr
;
819 struct ath6kl
*ar
= ath6kl_priv(dev
);
821 ath6kl_init_profile_info(ar
);
822 ath6kl_disconnect(ar
);
825 void ath6kl_disconnect(struct ath6kl
*ar
)
827 if (test_bit(CONNECTED
, &ar
->flag
) ||
828 test_bit(CONNECT_PEND
, &ar
->flag
)) {
829 ath6kl_wmi_disconnect_cmd(ar
->wmi
);
831 * Disconnect command is issued, clear the connect pending
832 * flag. The connected flag will be cleared in
833 * disconnect event notification.
835 clear_bit(CONNECT_PEND
, &ar
->flag
);
839 void ath6kl_deep_sleep_enable(struct ath6kl
*ar
)
841 switch (ar
->sme_state
) {
843 cfg80211_connect_result(ar
->net_dev
, ar
->bssid
, NULL
, 0,
845 WLAN_STATUS_UNSPECIFIED_FAILURE
,
851 * FIXME: oddly enough smeState is in DISCONNECTED during
852 * suspend, why? Need to send disconnected event in that
855 cfg80211_disconnected(ar
->net_dev
, 0, NULL
, 0, GFP_KERNEL
);
859 if (test_bit(CONNECTED
, &ar
->flag
) ||
860 test_bit(CONNECT_PEND
, &ar
->flag
))
861 ath6kl_wmi_disconnect_cmd(ar
->wmi
);
863 ar
->sme_state
= SME_DISCONNECTED
;
865 /* disable scanning */
866 if (ath6kl_wmi_scanparams_cmd(ar
->wmi
, 0xFFFF, 0, 0, 0, 0, 0, 0, 0,
868 printk(KERN_WARNING
"ath6kl: failed to disable scan "
871 ath6kl_cfg80211_scan_complete_event(ar
, -ECANCELED
);
874 /* WMI Event handlers */
876 static const char *get_hw_id_string(u32 id
)
879 case AR6003_REV1_VERSION
:
881 case AR6003_REV2_VERSION
:
883 case AR6003_REV3_VERSION
:
890 void ath6kl_ready_event(void *devt
, u8
*datap
, u32 sw_ver
, u32 abi_ver
)
892 struct ath6kl
*ar
= devt
;
893 struct net_device
*dev
= ar
->net_dev
;
895 memcpy(dev
->dev_addr
, datap
, ETH_ALEN
);
896 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: mac addr = %pM\n",
897 __func__
, dev
->dev_addr
);
899 ar
->version
.wlan_ver
= sw_ver
;
900 ar
->version
.abi_ver
= abi_ver
;
902 snprintf(ar
->wdev
->wiphy
->fw_version
,
903 sizeof(ar
->wdev
->wiphy
->fw_version
),
905 (ar
->version
.wlan_ver
& 0xf0000000) >> 28,
906 (ar
->version
.wlan_ver
& 0x0f000000) >> 24,
907 (ar
->version
.wlan_ver
& 0x00ff0000) >> 16,
908 (ar
->version
.wlan_ver
& 0x0000ffff));
910 /* indicate to the waiting thread that the ready event was received */
911 set_bit(WMI_READY
, &ar
->flag
);
912 wake_up(&ar
->event_wq
);
914 ath6kl_info("hw %s fw %s\n",
915 get_hw_id_string(ar
->wdev
->wiphy
->hw_version
),
916 ar
->wdev
->wiphy
->fw_version
);
919 void ath6kl_scan_complete_evt(struct ath6kl
*ar
, int status
)
921 ath6kl_cfg80211_scan_complete_event(ar
, status
);
923 if (!ar
->usr_bss_filter
)
924 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
926 ath6kl_dbg(ATH6KL_DBG_WLAN_SCAN
, "scan complete: %d\n", status
);
929 void ath6kl_connect_event(struct ath6kl
*ar
, u16 channel
, u8
*bssid
,
930 u16 listen_int
, u16 beacon_int
,
931 enum network_type net_type
, u8 beacon_ie_len
,
932 u8 assoc_req_len
, u8 assoc_resp_len
,
937 if (ar
->nw_type
== AP_NETWORK
) {
938 ath6kl_connect_ap_mode(ar
, channel
, bssid
, listen_int
,
939 beacon_int
, assoc_req_len
,
940 assoc_info
+ beacon_ie_len
);
944 ath6kl_cfg80211_connect_event(ar
, channel
, bssid
,
945 listen_int
, beacon_int
,
946 net_type
, beacon_ie_len
,
947 assoc_req_len
, assoc_resp_len
,
950 memcpy(ar
->bssid
, bssid
, sizeof(ar
->bssid
));
951 ar
->bss_ch
= channel
;
953 if ((ar
->nw_type
== INFRA_NETWORK
))
954 ath6kl_wmi_listeninterval_cmd(ar
->wmi
, ar
->listen_intvl_t
,
957 netif_wake_queue(ar
->net_dev
);
959 /* Update connect & link status atomically */
960 spin_lock_irqsave(&ar
->lock
, flags
);
961 set_bit(CONNECTED
, &ar
->flag
);
962 clear_bit(CONNECT_PEND
, &ar
->flag
);
963 netif_carrier_on(ar
->net_dev
);
964 spin_unlock_irqrestore(&ar
->lock
, flags
);
966 aggr_reset_state(ar
->aggr_cntxt
);
967 ar
->reconnect_flag
= 0;
969 if ((ar
->nw_type
== ADHOC_NETWORK
) && ar
->ibss_ps_enable
) {
970 memset(ar
->node_map
, 0, sizeof(ar
->node_map
));
972 ar
->next_ep_id
= ENDPOINT_2
;
975 if (!ar
->usr_bss_filter
)
976 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
979 void ath6kl_tkip_micerr_event(struct ath6kl
*ar
, u8 keyid
, bool ismcast
)
981 struct ath6kl_sta
*sta
;
984 * For AP case, keyid will have aid of STA which sent pkt with
985 * MIC error. Use this aid to get MAC & send it to hostapd.
987 if (ar
->nw_type
== AP_NETWORK
) {
988 sta
= ath6kl_find_sta_by_aid(ar
, (keyid
>> 2));
992 ath6kl_dbg(ATH6KL_DBG_TRC
,
993 "ap tkip mic error received from aid=%d\n", keyid
);
995 memset(tsc
, 0, sizeof(tsc
)); /* FIX: get correct TSC */
996 cfg80211_michael_mic_failure(ar
->net_dev
, sta
->mac
,
997 NL80211_KEYTYPE_PAIRWISE
, keyid
,
1000 ath6kl_cfg80211_tkip_micerr_event(ar
, keyid
, ismcast
);
1004 static void ath6kl_update_target_stats(struct ath6kl
*ar
, u8
*ptr
, u32 len
)
1006 struct wmi_target_stats
*tgt_stats
=
1007 (struct wmi_target_stats
*) ptr
;
1008 struct target_stats
*stats
= &ar
->target_stats
;
1009 struct tkip_ccmp_stats
*ccmp_stats
;
1010 struct bss
*conn_bss
= NULL
;
1011 struct cserv_stats
*c_stats
;
1014 if (len
< sizeof(*tgt_stats
))
1017 /* update the RSSI of the connected bss */
1018 if (test_bit(CONNECTED
, &ar
->flag
)) {
1019 conn_bss
= ath6kl_wmi_find_node(ar
->wmi
, ar
->bssid
);
1021 c_stats
= &tgt_stats
->cserv_stats
;
1023 a_sle16_to_cpu(c_stats
->cs_ave_beacon_rssi
);
1025 tgt_stats
->cserv_stats
.cs_ave_beacon_snr
;
1026 ath6kl_wmi_node_return(ar
->wmi
, conn_bss
);
1030 ath6kl_dbg(ATH6KL_DBG_TRC
, "updating target stats\n");
1032 stats
->tx_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.pkt
);
1033 stats
->tx_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.byte
);
1034 stats
->tx_ucast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.ucast_pkt
);
1035 stats
->tx_ucast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.ucast_byte
);
1036 stats
->tx_mcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.mcast_pkt
);
1037 stats
->tx_mcast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.mcast_byte
);
1038 stats
->tx_bcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.tx
.bcast_pkt
);
1039 stats
->tx_bcast_byte
+= le32_to_cpu(tgt_stats
->stats
.tx
.bcast_byte
);
1040 stats
->tx_rts_success_cnt
+=
1041 le32_to_cpu(tgt_stats
->stats
.tx
.rts_success_cnt
);
1043 for (ac
= 0; ac
< WMM_NUM_AC
; ac
++)
1044 stats
->tx_pkt_per_ac
[ac
] +=
1045 le32_to_cpu(tgt_stats
->stats
.tx
.pkt_per_ac
[ac
]);
1047 stats
->tx_err
+= le32_to_cpu(tgt_stats
->stats
.tx
.err
);
1048 stats
->tx_fail_cnt
+= le32_to_cpu(tgt_stats
->stats
.tx
.fail_cnt
);
1049 stats
->tx_retry_cnt
+= le32_to_cpu(tgt_stats
->stats
.tx
.retry_cnt
);
1050 stats
->tx_mult_retry_cnt
+=
1051 le32_to_cpu(tgt_stats
->stats
.tx
.mult_retry_cnt
);
1052 stats
->tx_rts_fail_cnt
+=
1053 le32_to_cpu(tgt_stats
->stats
.tx
.rts_fail_cnt
);
1054 stats
->tx_ucast_rate
=
1055 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats
->stats
.tx
.ucast_rate
));
1057 stats
->rx_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.pkt
);
1058 stats
->rx_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.byte
);
1059 stats
->rx_ucast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.ucast_pkt
);
1060 stats
->rx_ucast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.ucast_byte
);
1061 stats
->rx_mcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.mcast_pkt
);
1062 stats
->rx_mcast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.mcast_byte
);
1063 stats
->rx_bcast_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.bcast_pkt
);
1064 stats
->rx_bcast_byte
+= le32_to_cpu(tgt_stats
->stats
.rx
.bcast_byte
);
1065 stats
->rx_frgment_pkt
+= le32_to_cpu(tgt_stats
->stats
.rx
.frgment_pkt
);
1066 stats
->rx_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.err
);
1067 stats
->rx_crc_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.crc_err
);
1068 stats
->rx_key_cache_miss
+=
1069 le32_to_cpu(tgt_stats
->stats
.rx
.key_cache_miss
);
1070 stats
->rx_decrypt_err
+= le32_to_cpu(tgt_stats
->stats
.rx
.decrypt_err
);
1071 stats
->rx_dupl_frame
+= le32_to_cpu(tgt_stats
->stats
.rx
.dupl_frame
);
1072 stats
->rx_ucast_rate
=
1073 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats
->stats
.rx
.ucast_rate
));
1075 ccmp_stats
= &tgt_stats
->stats
.tkip_ccmp_stats
;
1077 stats
->tkip_local_mic_fail
+=
1078 le32_to_cpu(ccmp_stats
->tkip_local_mic_fail
);
1079 stats
->tkip_cnter_measures_invoked
+=
1080 le32_to_cpu(ccmp_stats
->tkip_cnter_measures_invoked
);
1081 stats
->tkip_fmt_err
+= le32_to_cpu(ccmp_stats
->tkip_fmt_err
);
1083 stats
->ccmp_fmt_err
+= le32_to_cpu(ccmp_stats
->ccmp_fmt_err
);
1084 stats
->ccmp_replays
+= le32_to_cpu(ccmp_stats
->ccmp_replays
);
1086 stats
->pwr_save_fail_cnt
+=
1087 le32_to_cpu(tgt_stats
->pm_stats
.pwr_save_failure_cnt
);
1088 stats
->noise_floor_calib
=
1089 a_sle32_to_cpu(tgt_stats
->noise_floor_calib
);
1091 stats
->cs_bmiss_cnt
+=
1092 le32_to_cpu(tgt_stats
->cserv_stats
.cs_bmiss_cnt
);
1093 stats
->cs_low_rssi_cnt
+=
1094 le32_to_cpu(tgt_stats
->cserv_stats
.cs_low_rssi_cnt
);
1095 stats
->cs_connect_cnt
+=
1096 le16_to_cpu(tgt_stats
->cserv_stats
.cs_connect_cnt
);
1097 stats
->cs_discon_cnt
+=
1098 le16_to_cpu(tgt_stats
->cserv_stats
.cs_discon_cnt
);
1100 stats
->cs_ave_beacon_rssi
=
1101 a_sle16_to_cpu(tgt_stats
->cserv_stats
.cs_ave_beacon_rssi
);
1103 stats
->cs_last_roam_msec
=
1104 tgt_stats
->cserv_stats
.cs_last_roam_msec
;
1105 stats
->cs_snr
= tgt_stats
->cserv_stats
.cs_snr
;
1106 stats
->cs_rssi
= a_sle16_to_cpu(tgt_stats
->cserv_stats
.cs_rssi
);
1108 stats
->lq_val
= le32_to_cpu(tgt_stats
->lq_val
);
1110 stats
->wow_pkt_dropped
+=
1111 le32_to_cpu(tgt_stats
->wow_stats
.wow_pkt_dropped
);
1112 stats
->wow_host_pkt_wakeups
+=
1113 tgt_stats
->wow_stats
.wow_host_pkt_wakeups
;
1114 stats
->wow_host_evt_wakeups
+=
1115 tgt_stats
->wow_stats
.wow_host_evt_wakeups
;
1116 stats
->wow_evt_discarded
+=
1117 le16_to_cpu(tgt_stats
->wow_stats
.wow_evt_discarded
);
1119 if (test_bit(STATS_UPDATE_PEND
, &ar
->flag
)) {
1120 clear_bit(STATS_UPDATE_PEND
, &ar
->flag
);
1121 wake_up(&ar
->event_wq
);
1125 static void ath6kl_add_le32(__le32
*var
, __le32 val
)
1127 *var
= cpu_to_le32(le32_to_cpu(*var
) + le32_to_cpu(val
));
1130 void ath6kl_tgt_stats_event(struct ath6kl
*ar
, u8
*ptr
, u32 len
)
1132 struct wmi_ap_mode_stat
*p
= (struct wmi_ap_mode_stat
*) ptr
;
1133 struct wmi_ap_mode_stat
*ap
= &ar
->ap_stats
;
1134 struct wmi_per_sta_stat
*st_ap
, *st_p
;
1137 if (ar
->nw_type
== AP_NETWORK
) {
1138 if (len
< sizeof(*p
))
1141 for (ac
= 0; ac
< AP_MAX_NUM_STA
; ac
++) {
1142 st_ap
= &ap
->sta
[ac
];
1145 ath6kl_add_le32(&st_ap
->tx_bytes
, st_p
->tx_bytes
);
1146 ath6kl_add_le32(&st_ap
->tx_pkts
, st_p
->tx_pkts
);
1147 ath6kl_add_le32(&st_ap
->tx_error
, st_p
->tx_error
);
1148 ath6kl_add_le32(&st_ap
->tx_discard
, st_p
->tx_discard
);
1149 ath6kl_add_le32(&st_ap
->rx_bytes
, st_p
->rx_bytes
);
1150 ath6kl_add_le32(&st_ap
->rx_pkts
, st_p
->rx_pkts
);
1151 ath6kl_add_le32(&st_ap
->rx_error
, st_p
->rx_error
);
1152 ath6kl_add_le32(&st_ap
->rx_discard
, st_p
->rx_discard
);
1156 ath6kl_update_target_stats(ar
, ptr
, len
);
1160 void ath6kl_wakeup_event(void *dev
)
1162 struct ath6kl
*ar
= (struct ath6kl
*) dev
;
1164 wake_up(&ar
->event_wq
);
1167 void ath6kl_txpwr_rx_evt(void *devt
, u8 tx_pwr
)
1169 struct ath6kl
*ar
= (struct ath6kl
*) devt
;
1171 ar
->tx_pwr
= tx_pwr
;
1172 wake_up(&ar
->event_wq
);
1175 void ath6kl_pspoll_event(struct ath6kl
*ar
, u8 aid
)
1177 struct ath6kl_sta
*conn
;
1178 struct sk_buff
*skb
;
1179 bool psq_empty
= false;
1181 conn
= ath6kl_find_sta_by_aid(ar
, aid
);
1186 * Send out a packet queued on ps queue. When the ps queue
1187 * becomes empty update the PVB for this station.
1189 spin_lock_bh(&conn
->psq_lock
);
1190 psq_empty
= skb_queue_empty(&conn
->psq
);
1191 spin_unlock_bh(&conn
->psq_lock
);
1194 /* TODO: Send out a NULL data frame */
1197 spin_lock_bh(&conn
->psq_lock
);
1198 skb
= skb_dequeue(&conn
->psq
);
1199 spin_unlock_bh(&conn
->psq_lock
);
1201 conn
->sta_flags
|= STA_PS_POLLED
;
1202 ath6kl_data_tx(skb
, ar
->net_dev
);
1203 conn
->sta_flags
&= ~STA_PS_POLLED
;
1205 spin_lock_bh(&conn
->psq_lock
);
1206 psq_empty
= skb_queue_empty(&conn
->psq
);
1207 spin_unlock_bh(&conn
->psq_lock
);
1210 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, conn
->aid
, 0);
1213 void ath6kl_dtimexpiry_event(struct ath6kl
*ar
)
1215 bool mcastq_empty
= false;
1216 struct sk_buff
*skb
;
1219 * If there are no associated STAs, ignore the DTIM expiry event.
1220 * There can be potential race conditions where the last associated
1221 * STA may disconnect & before the host could clear the 'Indicate
1222 * DTIM' request to the firmware, the firmware would have just
1223 * indicated a DTIM expiry event. The race is between 'clear DTIM
1224 * expiry cmd' going from the host to the firmware & the DTIM
1225 * expiry event happening from the firmware to the host.
1227 if (!ar
->sta_list_index
)
1230 spin_lock_bh(&ar
->mcastpsq_lock
);
1231 mcastq_empty
= skb_queue_empty(&ar
->mcastpsq
);
1232 spin_unlock_bh(&ar
->mcastpsq_lock
);
1237 /* set the STA flag to dtim_expired for the frame to go out */
1238 set_bit(DTIM_EXPIRED
, &ar
->flag
);
1240 spin_lock_bh(&ar
->mcastpsq_lock
);
1241 while ((skb
= skb_dequeue(&ar
->mcastpsq
)) != NULL
) {
1242 spin_unlock_bh(&ar
->mcastpsq_lock
);
1244 ath6kl_data_tx(skb
, ar
->net_dev
);
1246 spin_lock_bh(&ar
->mcastpsq_lock
);
1248 spin_unlock_bh(&ar
->mcastpsq_lock
);
1250 clear_bit(DTIM_EXPIRED
, &ar
->flag
);
1252 /* clear the LSB of the BitMapCtl field of the TIM IE */
1253 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, MCAST_AID
, 0);
1256 void ath6kl_disconnect_event(struct ath6kl
*ar
, u8 reason
, u8
*bssid
,
1257 u8 assoc_resp_len
, u8
*assoc_info
,
1258 u16 prot_reason_status
)
1260 struct bss
*wmi_ssid_node
= NULL
;
1261 unsigned long flags
;
1263 if (ar
->nw_type
== AP_NETWORK
) {
1264 if (!ath6kl_remove_sta(ar
, bssid
, prot_reason_status
))
1267 /* if no more associated STAs, empty the mcast PS q */
1268 if (ar
->sta_list_index
== 0) {
1269 spin_lock_bh(&ar
->mcastpsq_lock
);
1270 skb_queue_purge(&ar
->mcastpsq
);
1271 spin_unlock_bh(&ar
->mcastpsq_lock
);
1273 /* clear the LSB of the TIM IE's BitMapCtl field */
1274 if (test_bit(WMI_READY
, &ar
->flag
))
1275 ath6kl_wmi_set_pvb_cmd(ar
->wmi
, MCAST_AID
, 0);
1278 if (!is_broadcast_ether_addr(bssid
)) {
1279 /* send event to application */
1280 cfg80211_del_sta(ar
->net_dev
, bssid
, GFP_KERNEL
);
1283 clear_bit(CONNECTED
, &ar
->flag
);
1287 ath6kl_cfg80211_disconnect_event(ar
, reason
, bssid
,
1288 assoc_resp_len
, assoc_info
,
1289 prot_reason_status
);
1291 aggr_reset_state(ar
->aggr_cntxt
);
1293 del_timer(&ar
->disconnect_timer
);
1295 ath6kl_dbg(ATH6KL_DBG_WLAN_CONNECT
,
1296 "disconnect reason is %d\n", reason
);
1299 * If the event is due to disconnect cmd from the host, only they
1300 * the target would stop trying to connect. Under any other
1301 * condition, target would keep trying to connect.
1303 if (reason
== DISCONNECT_CMD
) {
1304 if (!ar
->usr_bss_filter
&& test_bit(WMI_READY
, &ar
->flag
))
1305 ath6kl_wmi_bssfilter_cmd(ar
->wmi
, NONE_BSS_FILTER
, 0);
1307 set_bit(CONNECT_PEND
, &ar
->flag
);
1308 if (((reason
== ASSOC_FAILED
) &&
1309 (prot_reason_status
== 0x11)) ||
1310 ((reason
== ASSOC_FAILED
) && (prot_reason_status
== 0x0)
1311 && (ar
->reconnect_flag
== 1))) {
1312 set_bit(CONNECTED
, &ar
->flag
);
1317 if ((reason
== NO_NETWORK_AVAIL
) && test_bit(WMI_READY
, &ar
->flag
)) {
1318 ath6kl_wmi_node_free(ar
->wmi
, bssid
);
1321 * In case any other same SSID nodes are present remove it,
1322 * since those nodes also not available now.
1326 * Find the nodes based on SSID and remove it
1328 * Note: This case will not work out for
1331 wmi_ssid_node
= ath6kl_wmi_find_ssid_node(ar
->wmi
,
1338 ath6kl_wmi_node_free(ar
->wmi
,
1339 wmi_ssid_node
->ni_macaddr
);
1341 } while (wmi_ssid_node
);
1344 /* update connect & link status atomically */
1345 spin_lock_irqsave(&ar
->lock
, flags
);
1346 clear_bit(CONNECTED
, &ar
->flag
);
1347 netif_carrier_off(ar
->net_dev
);
1348 spin_unlock_irqrestore(&ar
->lock
, flags
);
1350 if ((reason
!= CSERV_DISCONNECT
) || (ar
->reconnect_flag
!= 1))
1351 ar
->reconnect_flag
= 0;
1353 if (reason
!= CSERV_DISCONNECT
)
1354 ar
->user_key_ctrl
= 0;
1356 netif_stop_queue(ar
->net_dev
);
1357 memset(ar
->bssid
, 0, sizeof(ar
->bssid
));
1360 ath6kl_tx_data_cleanup(ar
);
1363 static int ath6kl_open(struct net_device
*dev
)
1365 struct ath6kl
*ar
= ath6kl_priv(dev
);
1366 unsigned long flags
;
1368 spin_lock_irqsave(&ar
->lock
, flags
);
1370 set_bit(WLAN_ENABLED
, &ar
->flag
);
1372 if (test_bit(CONNECTED
, &ar
->flag
)) {
1373 netif_carrier_on(dev
);
1374 netif_wake_queue(dev
);
1376 netif_carrier_off(dev
);
1378 spin_unlock_irqrestore(&ar
->lock
, flags
);
1383 static int ath6kl_close(struct net_device
*dev
)
1385 struct ath6kl
*ar
= ath6kl_priv(dev
);
1387 netif_stop_queue(dev
);
1389 ath6kl_disconnect(ar
);
1391 if (test_bit(WMI_READY
, &ar
->flag
)) {
1392 if (ath6kl_wmi_scanparams_cmd(ar
->wmi
, 0xFFFF, 0, 0, 0, 0, 0, 0,
1396 clear_bit(WLAN_ENABLED
, &ar
->flag
);
1399 ath6kl_cfg80211_scan_complete_event(ar
, -ECANCELED
);
1404 static struct net_device_stats
*ath6kl_get_stats(struct net_device
*dev
)
1406 struct ath6kl
*ar
= ath6kl_priv(dev
);
1408 return &ar
->net_stats
;
1411 static struct net_device_ops ath6kl_netdev_ops
= {
1412 .ndo_open
= ath6kl_open
,
1413 .ndo_stop
= ath6kl_close
,
1414 .ndo_start_xmit
= ath6kl_data_tx
,
1415 .ndo_get_stats
= ath6kl_get_stats
,
1418 void init_netdev(struct net_device
*dev
)
1420 dev
->netdev_ops
= &ath6kl_netdev_ops
;
1421 dev
->watchdog_timeo
= ATH6KL_TX_TIMEOUT
;
1423 dev
->needed_headroom
= ETH_HLEN
;
1424 dev
->needed_headroom
+= sizeof(struct ath6kl_llc_snap_hdr
) +
1425 sizeof(struct wmi_data_hdr
) + HTC_HDR_LENGTH
1426 + WMI_MAX_TX_META_SZ
+ ATH6KL_HTC_ALIGN_BYTES
;