1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
17 #include <osdep_service.h>
18 #include <drv_types.h>
20 #include <osdep_intf.h>
23 #include <rtl8723a_xmit.h>
25 static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
26 static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
28 static void _init_txservq(struct tx_servq *ptxservq)
31 INIT_LIST_HEAD(&ptxservq->tx_pending);
32 _rtw_init_queue23a(&ptxservq->sta_pending);
37 void _rtw_init_sta_xmit_priv23a(struct sta_xmit_priv *psta_xmitpriv)
40 spin_lock_init(&psta_xmitpriv->lock);
42 /* for (i = 0 ; i < MAX_NUMBLKS; i++) */
43 /* _init_txservq(&psta_xmitpriv->blk_q[i]); */
45 _init_txservq(&psta_xmitpriv->be_q);
46 _init_txservq(&psta_xmitpriv->bk_q);
47 _init_txservq(&psta_xmitpriv->vi_q);
48 _init_txservq(&psta_xmitpriv->vo_q);
49 INIT_LIST_HEAD(&psta_xmitpriv->legacy_dz);
50 INIT_LIST_HEAD(&psta_xmitpriv->apsd);
54 int _rtw_init_xmit_priv23a(struct xmit_priv *pxmitpriv,
55 struct rtw_adapter *padapter)
58 struct xmit_buf *pxmitbuf;
59 struct xmit_frame *pxframe;
61 u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
62 u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
64 spin_lock_init(&pxmitpriv->lock);
65 spin_lock_init(&pxmitpriv->lock_sctx);
66 sema_init(&pxmitpriv->xmit_sema, 0);
67 sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
69 pxmitpriv->adapter = padapter;
71 _rtw_init_queue23a(&pxmitpriv->be_pending);
72 _rtw_init_queue23a(&pxmitpriv->bk_pending);
73 _rtw_init_queue23a(&pxmitpriv->vi_pending);
74 _rtw_init_queue23a(&pxmitpriv->vo_pending);
75 _rtw_init_queue23a(&pxmitpriv->bm_pending);
77 _rtw_init_queue23a(&pxmitpriv->free_xmit_queue);
79 for (i = 0; i < NR_XMITFRAME; i++) {
80 pxframe = kzalloc(sizeof(struct xmit_frame), GFP_KERNEL);
83 INIT_LIST_HEAD(&pxframe->list);
85 pxframe->padapter = padapter;
86 pxframe->frame_tag = NULL_FRAMETAG;
88 list_add_tail(&pxframe->list,
89 &pxmitpriv->free_xmit_queue.queue);
92 pxmitpriv->free_xmitframe_cnt = i;
94 pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
97 _rtw_init_queue23a(&pxmitpriv->free_xmitbuf_queue);
98 INIT_LIST_HEAD(&pxmitpriv->xmitbuf_list);
99 _rtw_init_queue23a(&pxmitpriv->pending_xmitbuf_queue);
101 for (i = 0; i < NR_XMITBUFF; i++) {
102 pxmitbuf = kzalloc(sizeof(struct xmit_buf), GFP_KERNEL);
105 INIT_LIST_HEAD(&pxmitbuf->list);
106 INIT_LIST_HEAD(&pxmitbuf->list2);
108 pxmitbuf->padapter = padapter;
110 /* Tx buf allocation may fail sometimes, so sleep and retry. */
111 res = rtw_os_xmit_resource_alloc23a(padapter, pxmitbuf,
112 (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
117 list_add_tail(&pxmitbuf->list,
118 &pxmitpriv->free_xmitbuf_queue.queue);
119 list_add_tail(&pxmitbuf->list2,
120 &pxmitpriv->xmitbuf_list);
123 pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
125 /* init xframe_ext queue, the same count as extbuf */
126 _rtw_init_queue23a(&pxmitpriv->free_xframe_ext_queue);
128 for (i = 0; i < num_xmit_extbuf; i++) {
129 pxframe = kzalloc(sizeof(struct xmit_frame), GFP_KERNEL);
132 INIT_LIST_HEAD(&pxframe->list);
134 pxframe->padapter = padapter;
135 pxframe->frame_tag = NULL_FRAMETAG;
139 pxframe->buf_addr = NULL;
140 pxframe->pxmitbuf = NULL;
142 pxframe->ext_tag = 1;
144 list_add_tail(&pxframe->list,
145 &pxmitpriv->free_xframe_ext_queue.queue);
147 pxmitpriv->free_xframe_ext_cnt = i;
149 /* Init xmit extension buff */
150 _rtw_init_queue23a(&pxmitpriv->free_xmit_extbuf_queue);
151 INIT_LIST_HEAD(&pxmitpriv->xmitextbuf_list);
153 for (i = 0; i < num_xmit_extbuf; i++) {
154 pxmitbuf = kzalloc(sizeof(struct xmit_buf), GFP_KERNEL);
157 INIT_LIST_HEAD(&pxmitbuf->list);
158 INIT_LIST_HEAD(&pxmitbuf->list2);
160 pxmitbuf->padapter = padapter;
162 /* Tx buf allocation may fail sometimes, so sleep and retry. */
163 res = rtw_os_xmit_resource_alloc23a(padapter, pxmitbuf,
164 max_xmit_extbuf_size + XMITBUF_ALIGN_SZ);
169 list_add_tail(&pxmitbuf->list,
170 &pxmitpriv->free_xmit_extbuf_queue.queue);
171 list_add_tail(&pxmitbuf->list2,
172 &pxmitpriv->xmitextbuf_list);
175 pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
177 rtw_alloc_hwxmits23a(padapter);
178 rtw_init_hwxmits23a(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
180 for (i = 0; i < 4; i ++)
181 pxmitpriv->wmm_para_seq[i] = i;
183 pxmitpriv->txirp_cnt = 1;
185 sema_init(&pxmitpriv->tx_retevt, 0);
187 /* per AC pending irp */
188 pxmitpriv->beq_cnt = 0;
189 pxmitpriv->bkq_cnt = 0;
190 pxmitpriv->viq_cnt = 0;
191 pxmitpriv->voq_cnt = 0;
193 pxmitpriv->ack_tx = false;
194 mutex_init(&pxmitpriv->ack_tx_mutex);
195 rtw_sctx_init23a(&pxmitpriv->ack_tx_ops, 0);
196 tasklet_init(&padapter->xmitpriv.xmit_tasklet,
197 (void(*)(unsigned long))rtl8723au_xmit_tasklet,
198 (unsigned long)padapter);
207 void _rtw_free_xmit_priv23a (struct xmit_priv *pxmitpriv)
209 struct rtw_adapter *padapter = pxmitpriv->adapter;
210 struct xmit_frame *pxframe;
211 struct xmit_buf *pxmitbuf;
212 struct list_head *plist, *ptmp;
214 list_for_each_safe(plist, ptmp, &pxmitpriv->free_xmit_queue.queue) {
215 pxframe = container_of(plist, struct xmit_frame, list);
216 list_del_init(&pxframe->list);
217 rtw_os_xmit_complete23a(padapter, pxframe);
221 list_for_each_safe(plist, ptmp, &pxmitpriv->xmitbuf_list) {
222 pxmitbuf = container_of(plist, struct xmit_buf, list2);
223 list_del_init(&pxmitbuf->list2);
224 rtw_os_xmit_resource_free23a(padapter, pxmitbuf);
228 /* free xframe_ext queue, the same count as extbuf */
229 list_for_each_safe(plist, ptmp,
230 &pxmitpriv->free_xframe_ext_queue.queue) {
231 pxframe = container_of(plist, struct xmit_frame, list);
232 list_del_init(&pxframe->list);
233 rtw_os_xmit_complete23a(padapter, pxframe);
237 /* free xmit extension buff */
238 list_for_each_safe(plist, ptmp, &pxmitpriv->xmitextbuf_list) {
239 pxmitbuf = container_of(plist, struct xmit_buf, list2);
240 list_del_init(&pxmitbuf->list2);
241 rtw_os_xmit_resource_free23a(padapter, pxmitbuf);
245 rtw_free_hwxmits23a(padapter);
246 mutex_destroy(&pxmitpriv->ack_tx_mutex);
249 static void update_attrib_vcs_info(struct rtw_adapter *padapter, struct xmit_frame *pxmitframe)
252 struct pkt_attrib *pattrib = &pxmitframe->attrib;
253 struct sta_info *psta = pattrib->psta;
254 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
255 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
258 psta = pattrib->psta;
260 DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
261 psta = rtw_get_stainfo23a(&padapter->stapriv, &pattrib->ra[0]);
265 DBG_8723A("%s, psta == NUL\n", __func__);
269 if (!(psta->state &_FW_LINKED)) {
270 DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
274 if (pattrib->nr_frags != 1)
275 sz = padapter->xmitpriv.frag_len;
277 sz = pattrib->last_txcmdsz;
279 /* (1) RTS_Threshold is compared to the MPDU, not MSDU. */
280 /* (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. */
281 /* Other fragments are protected by previous fragment. */
282 /* So we only need to check the length of first fragment. */
283 if (pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec) {
284 if (sz > padapter->registrypriv.rts_thresh) {
285 pattrib->vcs_mode = RTS_CTS;
288 pattrib->vcs_mode = RTS_CTS;
289 else if (psta->cts2self)
290 pattrib->vcs_mode = CTS_TO_SELF;
292 pattrib->vcs_mode = NONE_VCS;
297 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_ATHEROS &&
299 padapter->securitypriv.dot11PrivacyAlgrthm ==
300 WLAN_CIPHER_SUITE_CCMP) {
301 pattrib->vcs_mode = CTS_TO_SELF;
305 /* check ERP protection */
306 if (psta->rtsen || psta->cts2self) {
308 pattrib->vcs_mode = RTS_CTS;
309 else if (psta->cts2self)
310 pattrib->vcs_mode = CTS_TO_SELF;
315 /* check HT op mode */
316 if (pattrib->ht_en) {
317 u8 HTOpMode = pmlmeinfo->HT_protection;
318 if ((pmlmeext->cur_bwmode && (HTOpMode == 2 || HTOpMode == 3)) ||
319 (!pmlmeext->cur_bwmode && HTOpMode == 3)) {
320 pattrib->vcs_mode = RTS_CTS;
326 if (sz > padapter->registrypriv.rts_thresh) {
327 pattrib->vcs_mode = RTS_CTS;
331 /* to do list: check MIMO power save condition. */
333 /* check AMPDU aggregation for TXOP */
334 if (pattrib->ampdu_en) {
335 pattrib->vcs_mode = RTS_CTS;
339 pattrib->vcs_mode = NONE_VCS;
345 static void update_attrib_phy_info(struct pkt_attrib *pattrib, struct sta_info *psta)
348 pattrib->vcs_mode = RTS_CTS;
349 else if (psta->cts2self)
350 pattrib->vcs_mode = CTS_TO_SELF;
352 pattrib->vcs_mode = NONE_VCS;*/
356 pattrib->triggered = 0;
358 /* qos_en, ht_en, init rate, , bw, ch_offset, sgi */
359 pattrib->qos_en = psta->qos_option;
361 pattrib->raid = psta->raid;
362 pattrib->ht_en = psta->htpriv.ht_option;
363 pattrib->bwmode = psta->htpriv.bwmode;
364 pattrib->ch_offset = psta->htpriv.ch_offset;
365 pattrib->sgi = psta->htpriv.sgi;
366 pattrib->ampdu_en = false;
368 pattrib->retry_ctrl = false;
371 u8 qos_acm23a(u8 acm_mask, u8 priority)
373 u8 change_priority = priority;
378 if (acm_mask & BIT(1))
386 if (acm_mask & BIT(2))
391 if (acm_mask & BIT(3))
395 DBG_8723A("qos_acm23a(): invalid pattrib->priority: %d!!!\n",
401 return change_priority;
404 static void set_qos(struct sk_buff *skb, struct pkt_attrib *pattrib)
406 u8 *pframe = skb->data;
407 struct iphdr *ip_hdr;
410 /* get UserPriority from IP hdr */
411 if (pattrib->ether_type == ETH_P_IP) {
412 ip_hdr = (struct iphdr *)(pframe + ETH_HLEN);
413 UserPriority = ip_hdr->tos >> 5;
414 } else if (pattrib->ether_type == ETH_P_PAE) {
415 /* "When priority processing of data frames is supported, */
416 /* a STA's SME should send EAPOL-Key frames at the highest
421 pattrib->priority = UserPriority;
422 pattrib->hdrlen = sizeof(struct ieee80211_qos_hdr);
423 pattrib->type = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA;
426 static int update_attrib(struct rtw_adapter *padapter,
427 struct sk_buff *skb, struct pkt_attrib *pattrib)
429 struct sta_info *psta = NULL;
431 struct sta_priv *pstapriv = &padapter->stapriv;
432 struct security_priv *psecuritypriv = &padapter->securitypriv;
433 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
435 struct ethhdr *ehdr = (struct ethhdr *) skb->data;
437 pattrib->ether_type = ntohs(ehdr->h_proto);
439 ether_addr_copy(pattrib->dst, ehdr->h_dest);
440 ether_addr_copy(pattrib->src, ehdr->h_source);
444 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
445 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
446 ether_addr_copy(pattrib->ra, pattrib->dst);
447 ether_addr_copy(pattrib->ta, pattrib->src);
448 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
449 ether_addr_copy(pattrib->ra, get_bssid(pmlmepriv));
450 ether_addr_copy(pattrib->ta, pattrib->src);
451 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
452 ether_addr_copy(pattrib->ra, pattrib->dst);
453 ether_addr_copy(pattrib->ta, get_bssid(pmlmepriv));
456 pattrib->pktlen = skb->len - ETH_HLEN;
458 if (pattrib->ether_type == ETH_P_IP) {
459 /* The following is for DHCP and ARP packet, we use cck1M
460 to tx these packets and let LPS awake some time */
461 /* to prevent DHCP protocol fail */
462 pattrib->dhcp_pkt = 0;
463 /* MINIMUM_DHCP_PACKET_SIZE) { */
464 if (pattrib->pktlen > 282 + 24) {
465 if (pattrib->ether_type == ETH_P_IP) {/* IP header */
466 u8 *pframe = skb->data;
469 if ((pframe[21] == 68 && pframe[23] == 67) ||
470 (pframe[21] == 67 && pframe[23] == 68)) {
471 /* 68 : UDP BOOTP client */
472 /* 67 : UDP BOOTP server */
473 RT_TRACE(_module_rtl871x_xmit_c_,
475 ("======================"
476 "update_attrib: get DHCP "
478 pattrib->dhcp_pkt = 1;
482 } else if (pattrib->ether_type == ETH_P_PAE) {
483 DBG_8723A_LEVEL(_drv_always_, "send eapol packet\n");
486 if ((pattrib->ether_type == ETH_P_PAE) || (pattrib->dhcp_pkt == 1)) {
487 rtw_set_scan_deny(padapter, 3000);
490 /* If EAPOL , ARP , OR DHCP packet, driver must be in active mode. */
491 if ((pattrib->ether_type == ETH_P_ARP) ||
492 (pattrib->ether_type == ETH_P_PAE) || (pattrib->dhcp_pkt == 1)) {
493 rtw_lps_ctrl_wk_cmd23a(padapter, LPS_CTRL_SPECIAL_PACKET, 1);
496 bmcast = is_multicast_ether_addr(pattrib->ra);
500 psta = rtw_get_bcmc_stainfo23a(padapter);
502 psta = rtw_get_stainfo23a(pstapriv, pattrib->ra);
503 if (psta == NULL) { /* if we cannot get psta => drrp the pkt */
504 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_,
505 ("\nupdate_attrib => get sta_info fail, ra:"
506 MAC_FMT"\n", MAC_ARG(pattrib->ra)));
509 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) &&
510 (!(psta->state & _FW_LINKED))) {
517 pattrib->mac_id = psta->mac_id;
518 /* DBG_8723A("%s ==> mac_id(%d)\n", __func__, pattrib->mac_id); */
519 pattrib->psta = psta;
521 /* if we cannot get psta => drop the pkt */
522 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_,
523 ("\nupdate_attrib => get sta_info fail, ra:" MAC_FMT
524 "\n", MAC_ARG(pattrib->ra)));
529 pattrib->ack_policy = 0;
530 /* get ether_hdr_len */
532 /* pattrib->ether_type == 0x8100) ? (14 + 4): 14; vlan tag */
533 pattrib->pkt_hdrlen = ETH_HLEN;
535 pattrib->hdrlen = sizeof(struct ieee80211_hdr_3addr);
536 pattrib->type = IEEE80211_FTYPE_DATA;
537 pattrib->priority = 0;
539 if (check_fwstate(pmlmepriv, WIFI_AP_STATE | WIFI_ADHOC_STATE |
540 WIFI_ADHOC_MASTER_STATE)) {
541 if (psta->qos_option)
542 set_qos(skb, pattrib);
544 if (pmlmepriv->qos_option) {
545 set_qos(skb, pattrib);
547 if (pmlmepriv->acm_mask != 0) {
548 pattrib->priority = qos_acm23a(pmlmepriv->acm_mask,
554 if (psta->ieee8021x_blocked == true) {
555 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
556 ("\n psta->ieee8021x_blocked == true\n"));
558 pattrib->encrypt = 0;
560 if ((pattrib->ether_type != ETH_P_PAE) &&
561 !check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
562 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
563 ("\npsta->ieee8021x_blocked == true, "
564 "pattrib->ether_type(%.4x) != 0x888e\n",
565 pattrib->ether_type));
570 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
572 switch (psecuritypriv->dot11AuthAlgrthm) {
573 case dot11AuthAlgrthm_Open:
574 case dot11AuthAlgrthm_Shared:
575 case dot11AuthAlgrthm_Auto:
577 (u8)psecuritypriv->dot11PrivacyKeyIndex;
579 case dot11AuthAlgrthm_8021X:
582 (u8)psecuritypriv->dot118021XGrpKeyid;
584 pattrib->key_idx = 0;
587 pattrib->key_idx = 0;
593 switch (pattrib->encrypt) {
594 case WLAN_CIPHER_SUITE_WEP40:
595 case WLAN_CIPHER_SUITE_WEP104:
596 pattrib->iv_len = IEEE80211_WEP_IV_LEN;
597 pattrib->icv_len = IEEE80211_WEP_ICV_LEN;
600 case WLAN_CIPHER_SUITE_TKIP:
601 pattrib->iv_len = IEEE80211_TKIP_IV_LEN;
602 pattrib->icv_len = IEEE80211_TKIP_ICV_LEN;
604 if (!padapter->securitypriv.busetkipkey) {
605 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
606 ("\npadapter->securitypriv.busetkip"
607 "key(%d) == false drop packet\n",
608 padapter->securitypriv.busetkipkey));
614 case WLAN_CIPHER_SUITE_CCMP:
615 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
616 ("pattrib->encrypt =%d (WLAN_CIPHER_SUITE_CCMP)\n",
618 pattrib->iv_len = IEEE80211_CCMP_HDR_LEN;
619 pattrib->icv_len = IEEE80211_CCMP_MIC_LEN;
624 pattrib->icv_len = 0;
628 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
629 ("update_attrib: encrypt =%d\n", pattrib->encrypt));
631 if (pattrib->encrypt && !psecuritypriv->hw_decrypted) {
632 pattrib->bswenc = true;
633 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
634 ("update_attrib: encrypt =%d bswenc = true\n",
637 pattrib->bswenc = false;
638 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
639 ("update_attrib: bswenc = false\n"));
641 update_attrib_phy_info(pattrib, psta);
648 static int xmitframe_addmic(struct rtw_adapter *padapter,
649 struct xmit_frame *pxmitframe) {
650 struct mic_data micdata;
651 struct sta_info *stainfo;
652 struct pkt_attrib *pattrib = &pxmitframe->attrib;
653 struct security_priv *psecuritypriv = &padapter->securitypriv;
654 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
655 int curfragnum, length;
656 u8 *pframe, *payload, mic[8];
657 u8 priority[4]= {0x0, 0x0, 0x0, 0x0};
658 u8 hw_hdr_offset = 0;
659 int bmcst = is_multicast_ether_addr(pattrib->ra);
662 stainfo = pattrib->psta;
664 DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
665 stainfo = rtw_get_stainfo23a(&padapter->stapriv, &pattrib->ra[0]);
669 DBG_8723A("%s, psta == NUL\n", __func__);
673 if (!(stainfo->state &_FW_LINKED)) {
674 DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n",
675 __func__, stainfo->state);
679 hw_hdr_offset = TXDESC_OFFSET;
681 if (pattrib->encrypt == WLAN_CIPHER_SUITE_TKIP) {
682 /* encode mic code */
684 u8 null_key[16]={0x0, 0x0, 0x0, 0x0,
689 pframe = pxmitframe->buf_addr + hw_hdr_offset;
692 if (!memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16)) {
695 /* start to calculate the mic code */
696 rtw_secmicsetkey23a(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey);
698 if (!memcmp(&stainfo->dot11tkiptxmickey.skey[0],
702 /* start to calculate the mic code */
703 rtw_secmicsetkey23a(&micdata, &stainfo->dot11tkiptxmickey.skey[0]);
706 if (pframe[1] & 1) { /* ToDS == 1 */
708 rtw_secmicappend23a(&micdata, &pframe[16], 6);
709 if (pframe[1] & 2) /* From Ds == 1 */
710 rtw_secmicappend23a(&micdata,
713 rtw_secmicappend23a(&micdata,
715 } else { /* ToDS == 0 */
717 rtw_secmicappend23a(&micdata, &pframe[4], 6);
718 if (pframe[1] & 2) /* From Ds == 1 */
719 rtw_secmicappend23a(&micdata,
722 rtw_secmicappend23a(&micdata,
726 /* if (pmlmepriv->qos_option == 1) */
728 priority[0] = (u8)pxmitframe->attrib.priority;
730 rtw_secmicappend23a(&micdata, &priority[0], 4);
734 for (curfragnum = 0; curfragnum < pattrib->nr_frags;
736 payload = PTR_ALIGN(payload, 4);
737 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
738 ("=== curfragnum =%d, pframe = 0x%.2x, "
739 "0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x"
740 "%.2x, 0x%.2x, 0x%.2x,!!!\n",
741 curfragnum, *payload, *(payload + 1),
742 *(payload + 2), *(payload + 3),
743 *(payload + 4), *(payload + 5),
744 *(payload + 6), *(payload + 7)));
746 payload = payload + pattrib->hdrlen +
748 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
749 ("curfragnum =%d pattrib->hdrlen =%d "
750 "pattrib->iv_len =%d", curfragnum,
751 pattrib->hdrlen, pattrib->iv_len));
752 if ((curfragnum + 1) == pattrib->nr_frags) {
753 length = pattrib->last_txcmdsz -
757 pattrib->icv_len : 0);
758 rtw_secmicappend23a(&micdata, payload,
760 payload = payload + length;
762 length = pxmitpriv->frag_len -
766 pattrib->icv_len : 0);
767 rtw_secmicappend23a(&micdata, payload,
769 payload = payload + length +
771 RT_TRACE(_module_rtl871x_xmit_c_,
773 ("curfragnum =%d length =%d "
774 "pattrib->icv_len =%d",
779 rtw_secgetmic23a(&micdata, &mic[0]);
780 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
781 ("xmitframe_addmic: before add mic code!!\n"));
782 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
783 ("xmitframe_addmic: pattrib->last_txcmdsz ="
784 "%d!!!\n", pattrib->last_txcmdsz));
785 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
786 ("xmitframe_addmic: mic[0]= 0x%.2x , mic[1]="
787 "0x%.2x , mic[2]= 0x%.2x , mic[3]= 0x%.2x\n"
788 "mic[4]= 0x%.2x , mic[5]= 0x%.2x , mic[6]= 0x%.2x "
789 ", mic[7]= 0x%.2x !!!!\n", mic[0], mic[1],
790 mic[2], mic[3], mic[4], mic[5], mic[6],
792 /* add mic code and add the mic code length
795 memcpy(payload, &mic[0], 8);
796 pattrib->last_txcmdsz += 8;
798 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
799 ("\n ======== last pkt ========\n"));
800 payload = payload - pattrib->last_txcmdsz + 8;
801 for (curfragnum = 0; curfragnum < pattrib->last_txcmdsz;
802 curfragnum = curfragnum + 8)
803 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
804 (" %.2x, %.2x, %.2x, %.2x, %.2x, "
805 " %.2x, %.2x, %.2x ",
806 *(payload + curfragnum),
807 *(payload + curfragnum + 1),
808 *(payload + curfragnum + 2),
809 *(payload + curfragnum + 3),
810 *(payload + curfragnum + 4),
811 *(payload + curfragnum + 5),
812 *(payload + curfragnum + 6),
813 *(payload + curfragnum + 7)));
815 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
816 ("xmitframe_addmic: rtw_get_stainfo23a =="
824 static int xmitframe_swencrypt(struct rtw_adapter *padapter,
825 struct xmit_frame *pxmitframe)
827 struct pkt_attrib *pattrib = &pxmitframe->attrib;
829 /* if ((psecuritypriv->sw_encrypt)||(pattrib->bswenc)) */
830 if (pattrib->bswenc) {
831 /* DBG_8723A("start xmitframe_swencrypt\n"); */
832 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_,
833 ("### xmitframe_swencrypt\n"));
834 switch (pattrib->encrypt) {
835 case WLAN_CIPHER_SUITE_WEP40:
836 case WLAN_CIPHER_SUITE_WEP104:
837 rtw_wep_encrypt23a(padapter, pxmitframe);
839 case WLAN_CIPHER_SUITE_TKIP:
840 rtw_tkip_encrypt23a(padapter, pxmitframe);
842 case WLAN_CIPHER_SUITE_CCMP:
843 rtw_aes_encrypt23a(padapter, pxmitframe);
850 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
851 ("### xmitframe_hwencrypt\n"));
857 static int rtw_make_wlanhdr(struct rtw_adapter *padapter, u8 *hdr,
858 struct pkt_attrib *pattrib)
860 struct ieee80211_hdr *pwlanhdr = (struct ieee80211_hdr *)hdr;
861 struct ieee80211_qos_hdr *qoshdr;
862 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
863 u8 qos_option = false;
866 struct sta_info *psta;
868 int bmcst = is_multicast_ether_addr(pattrib->ra);
871 psta = pattrib->psta;
873 DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
875 psta = rtw_get_bcmc_stainfo23a(padapter);
877 psta = rtw_get_stainfo23a(&padapter->stapriv, pattrib->ra);
882 DBG_8723A("%s, psta == NUL\n", __func__);
886 if (!(psta->state &_FW_LINKED)) {
887 DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
891 memset(hdr, 0, WLANHDR_OFFSET);
893 pwlanhdr->frame_control = cpu_to_le16(pattrib->type);
895 if (pattrib->type & IEEE80211_FTYPE_DATA) {
896 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
897 /* to_ds = 1, fr_ds = 0; */
898 /* Data transfer to AP */
899 pwlanhdr->frame_control |=
900 cpu_to_le16(IEEE80211_FCTL_TODS);
901 ether_addr_copy(pwlanhdr->addr1, get_bssid(pmlmepriv));
902 ether_addr_copy(pwlanhdr->addr2, pattrib->src);
903 ether_addr_copy(pwlanhdr->addr3, pattrib->dst);
905 if (pmlmepriv->qos_option)
908 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
909 /* to_ds = 0, fr_ds = 1; */
910 pwlanhdr->frame_control |=
911 cpu_to_le16(IEEE80211_FCTL_FROMDS);
912 ether_addr_copy(pwlanhdr->addr1, pattrib->dst);
913 ether_addr_copy(pwlanhdr->addr2, get_bssid(pmlmepriv));
914 ether_addr_copy(pwlanhdr->addr3, pattrib->src);
916 if (psta->qos_option)
918 } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
919 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
920 ether_addr_copy(pwlanhdr->addr1, pattrib->dst);
921 ether_addr_copy(pwlanhdr->addr2, pattrib->src);
922 ether_addr_copy(pwlanhdr->addr3, get_bssid(pmlmepriv));
924 if (psta->qos_option)
928 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("fw_state:%x is not allowed to xmit frame\n", get_fwstate(pmlmepriv)));
933 pwlanhdr->frame_control |=
934 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
935 if (pattrib->encrypt)
936 pwlanhdr->frame_control |=
937 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
939 qoshdr = (struct ieee80211_qos_hdr *)hdr;
941 qoshdr->qos_ctrl = cpu_to_le16(
942 pattrib->priority & IEEE80211_QOS_CTL_TID_MASK);
944 qoshdr->qos_ctrl |= cpu_to_le16(
945 (pattrib->ack_policy << 5) &
946 IEEE80211_QOS_CTL_ACK_POLICY_MASK);
950 cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
952 /* TODO: fill HT Control Field */
954 /* Update Seq Num will be handled by f/w */
956 psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
957 psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
958 pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
959 /* We dont need to worry about frag bits here */
960 pwlanhdr->seq_ctrl = cpu_to_le16(IEEE80211_SN_TO_SEQ(
962 /* check if enable ampdu */
963 if (pattrib->ht_en && psta->htpriv.ampdu_enable) {
964 if (pattrib->priority >= 16)
965 printk(KERN_WARNING "%s: Invalid "
966 "pattrib->priority %i\n",
967 __func__, pattrib->priority);
968 if (psta->htpriv.agg_enable_bitmap &
969 BIT(pattrib->priority))
970 pattrib->ampdu_en = true;
972 /* re-check if enable ampdu by BA_starting_seqctrl */
973 if (pattrib->ampdu_en) {
976 tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
978 /* check BA_starting_seqctrl */
979 if (SN_LESS(pattrib->seqnum, tx_seq)) {
980 /* DBG_8723A("tx ampdu seqnum(%d) < tx_seq(%d)\n", pattrib->seqnum, tx_seq); */
981 pattrib->ampdu_en = false;/* AGG BK */
982 } else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
983 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
984 pattrib->ampdu_en = true;/* AGG EN */
986 /* DBG_8723A("tx ampdu over run\n"); */
987 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
988 pattrib->ampdu_en = true;/* AGG EN */
997 s32 rtw_txframes_pending23a(struct rtw_adapter *padapter)
999 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1001 return (!list_empty(&pxmitpriv->be_pending.queue)) ||
1002 (!list_empty(&pxmitpriv->bk_pending.queue)) ||
1003 (!list_empty(&pxmitpriv->vi_pending.queue)) ||
1004 (!list_empty(&pxmitpriv->vo_pending.queue));
1007 s32 rtw_txframes_sta_ac_pending23a(struct rtw_adapter *padapter,
1008 struct pkt_attrib *pattrib)
1010 struct sta_info *psta;
1011 struct tx_servq *ptxservq;
1012 int priority = pattrib->priority;
1014 if (pattrib->psta) {
1015 psta = pattrib->psta;
1017 DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
1018 psta = rtw_get_stainfo23a(&padapter->stapriv, &pattrib->ra[0]);
1021 DBG_8723A("%s, psta == NUL\n", __func__);
1024 if (!(psta->state &_FW_LINKED)) {
1025 DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__,
1032 ptxservq = &psta->sta_xmitpriv.bk_q;
1036 ptxservq = &psta->sta_xmitpriv.vi_q;
1040 ptxservq = &psta->sta_xmitpriv.vo_q;
1045 ptxservq = &psta->sta_xmitpriv.be_q;
1048 return ptxservq->qcnt;
1052 * Calculate wlan 802.11 packet MAX size from pkt_attrib
1053 * This function doesn't consider fragment case
1055 u32 rtw_calculate_wlan_pkt_size_by_attribue23a(struct pkt_attrib *pattrib)
1059 len = pattrib->hdrlen + pattrib->iv_len; /* WLAN Header and IV */
1060 len += SNAP_SIZE + sizeof(u16); /* LLC */
1061 len += pattrib->pktlen;
1062 if (pattrib->encrypt == WLAN_CIPHER_SUITE_TKIP) len += 8; /* MIC */
1063 len += ((pattrib->bswenc) ? pattrib->icv_len : 0); /* ICV */
1070 This sub-routine will perform all the following:
1072 1. remove 802.3 header.
1073 2. create wlan_header, based on the info in pxmitframe
1074 3. append sta's iv/ext-iv
1076 5. move frag chunk from pframe to pxmitframe->mem
1077 6. apply sw-encrypt, if necessary.
1080 int rtw_xmitframe_coalesce23a(struct rtw_adapter *padapter, struct sk_buff *skb,
1081 struct xmit_frame *pxmitframe)
1083 struct sta_info *psta;
1084 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1085 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1086 struct ieee80211_hdr *hdr;
1087 s32 frg_inx, frg_len, mpdu_len, llc_sz, mem_sz;
1088 u8 *pframe, *mem_start;
1091 u8 *pdata = skb->data;
1092 int data_len = skb->len;
1093 s32 bmcst = is_multicast_ether_addr(pattrib->ra);
1097 psta = pattrib->psta;
1099 DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
1100 psta = rtw_get_stainfo23a(&padapter->stapriv, pattrib->ra);
1104 DBG_8723A("%s, psta == NUL\n", __func__);
1108 if (!(psta->state &_FW_LINKED)) {
1109 DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n",
1110 __func__, psta->state);
1114 if (!pxmitframe->buf_addr) {
1115 DBG_8723A("==> %s buf_addr == NULL\n", __func__);
1119 pbuf_start = pxmitframe->buf_addr;
1121 hw_hdr_offset = TXDESC_OFFSET;
1123 mem_start = pbuf_start + hw_hdr_offset;
1125 if (rtw_make_wlanhdr(padapter, mem_start, pattrib) == _FAIL) {
1126 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
1127 ("%s: rtw_make_wlanhdr fail; drop pkt\n", __func__));
1132 pdata += pattrib->pkt_hdrlen;
1133 data_len -= pattrib->pkt_hdrlen;
1136 frg_len = pxmitpriv->frag_len - 4;/* 2346-4 = 2342 */
1144 hdr = (struct ieee80211_hdr *)mem_start;
1146 pframe += pattrib->hdrlen;
1147 mpdu_len -= pattrib->hdrlen;
1149 /* adding icv, if necessary... */
1150 if (pattrib->iv_len) {
1152 switch (pattrib->encrypt) {
1153 case WLAN_CIPHER_SUITE_WEP40:
1154 case WLAN_CIPHER_SUITE_WEP104:
1155 WEP_IV(pattrib->iv, psta->dot11txpn,
1158 case WLAN_CIPHER_SUITE_TKIP:
1160 TKIP_IV(pattrib->iv,
1164 TKIP_IV(pattrib->iv,
1165 psta->dot11txpn, 0);
1167 case WLAN_CIPHER_SUITE_CCMP:
1174 psta->dot11txpn, 0);
1179 memcpy(pframe, pattrib->iv, pattrib->iv_len);
1181 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
1182 ("rtw_xmiaframe_coalesce23a: keyid =%d pattrib"
1183 "->iv[3]=%.2x pframe =%.2x %.2x %.2x %.2x\n",
1184 padapter->securitypriv.dot11PrivacyKeyIndex,
1185 pattrib->iv[3], *pframe, *(pframe+1),
1186 *(pframe+2), *(pframe+3)));
1187 pframe += pattrib->iv_len;
1188 mpdu_len -= pattrib->iv_len;
1191 llc_sz = rtw_put_snap23a(pframe, pattrib->ether_type);
1196 if (pattrib->icv_len > 0 && pattrib->bswenc)
1197 mpdu_len -= pattrib->icv_len;
1200 /* don't do fragment to broadcast/multicast packets */
1201 mem_sz = min_t(s32, data_len, pattrib->pktlen);
1203 mem_sz = min_t(s32, data_len, mpdu_len);
1205 memcpy(pframe, pdata, mem_sz);
1211 if ((pattrib->icv_len >0) && (pattrib->bswenc)) {
1212 memcpy(pframe, pattrib->icv, pattrib->icv_len);
1213 pframe += pattrib->icv_len;
1218 if (bmcst || data_len <= 0) {
1219 pattrib->nr_frags = frg_inx;
1221 pattrib->last_txcmdsz = pattrib->hdrlen +
1223 ((pattrib->nr_frags == 1) ?
1225 ((pattrib->bswenc) ?
1226 pattrib->icv_len : 0) + mem_sz;
1227 hdr->frame_control &=
1228 ~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
1232 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
1233 ("%s: There're still something in packet!\n",
1236 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
1238 mem_start = PTR_ALIGN(pframe, 4) + hw_hdr_offset;
1239 memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen);
1242 if (xmitframe_addmic(padapter, pxmitframe) == _FAIL) {
1243 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
1244 ("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n"));
1245 DBG_8723A("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n");
1250 xmitframe_swencrypt(padapter, pxmitframe);
1253 update_attrib_vcs_info(padapter, pxmitframe);
1255 pattrib->vcs_mode = NONE_VCS;
1261 /* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
1262 * IEEE LLC/SNAP header contains 8 octets
1263 * First 3 octets comprise the LLC portion
1264 * SNAP portion, 5 octets, is divided into two fields:
1265 * Organizationally Unique Identifier(OUI), 3 octets,
1266 * type, defined by that organization, 2 octets.
1268 s32 rtw_put_snap23a(u8 *data, u16 h_proto)
1270 struct ieee80211_snap_hdr *snap;
1273 snap = (struct ieee80211_snap_hdr *)data;
1278 if (h_proto == 0x8137 || h_proto == 0x80f3)
1282 snap->oui[0] = oui[0];
1283 snap->oui[1] = oui[1];
1284 snap->oui[2] = oui[2];
1285 *(u16 *)(data + SNAP_SIZE) = htons(h_proto);
1286 return SNAP_SIZE + sizeof(u16);
1289 void rtw_update_protection23a(struct rtw_adapter *padapter, u8 *ie, uint ie_len)
1291 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1292 struct registry_priv *pregistrypriv = &padapter->registrypriv;
1296 switch (pxmitpriv->vcs_setting) {
1298 pxmitpriv->vcs = NONE_VCS;
1304 p = cfg80211_find_ie(WLAN_EID_ERP_INFO, ie, ie_len);
1306 pxmitpriv->vcs = NONE_VCS;
1308 protection = (*(p + 2)) & BIT(1);
1310 if (pregistrypriv->vcs_type == RTS_CTS)
1311 pxmitpriv->vcs = RTS_CTS;
1313 pxmitpriv->vcs = CTS_TO_SELF;
1315 pxmitpriv->vcs = NONE_VCS;
1322 void rtw_count_tx_stats23a(struct rtw_adapter *padapter, struct xmit_frame *pxmitframe, int sz)
1324 struct sta_info *psta = NULL;
1325 struct stainfo_stats *pstats = NULL;
1326 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1327 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1329 if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG) {
1330 pxmitpriv->tx_bytes += sz;
1331 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod++;
1333 psta = pxmitframe->attrib.psta;
1335 pstats = &psta->sta_stats;
1337 pstats->tx_bytes += sz;
1342 struct xmit_buf *rtw_alloc_xmitbuf23a_ext(struct xmit_priv *pxmitpriv)
1345 struct xmit_buf *pxmitbuf = NULL;
1346 struct list_head *phead;
1347 struct rtw_queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1349 spin_lock_irqsave(&pfree_queue->lock, irqL);
1351 phead = get_list_head(pfree_queue);
1353 if (!list_empty(phead)) {
1354 pxmitbuf = list_first_entry(phead, struct xmit_buf, list);
1356 list_del_init(&pxmitbuf->list);
1358 pxmitpriv->free_xmit_extbuf_cnt--;
1359 pxmitbuf->priv_data = NULL;
1360 pxmitbuf->ext_tag = true;
1362 if (pxmitbuf->sctx) {
1363 DBG_8723A("%s pxmitbuf->sctx is not NULL\n", __func__);
1364 rtw23a_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1368 spin_unlock_irqrestore(&pfree_queue->lock, irqL);
1373 int rtw_free_xmitbuf_ext23a(struct xmit_priv *pxmitpriv,
1374 struct xmit_buf *pxmitbuf)
1377 struct rtw_queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1379 if (pxmitbuf == NULL)
1382 spin_lock_irqsave(&pfree_queue->lock, irqL);
1384 list_del_init(&pxmitbuf->list);
1386 list_add_tail(&pxmitbuf->list, get_list_head(pfree_queue));
1387 pxmitpriv->free_xmit_extbuf_cnt++;
1389 spin_unlock_irqrestore(&pfree_queue->lock, irqL);
1394 struct xmit_buf *rtw_alloc_xmitbuf23a(struct xmit_priv *pxmitpriv)
1397 struct xmit_buf *pxmitbuf = NULL;
1398 struct list_head *phead;
1399 struct rtw_queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1401 /* DBG_8723A("+rtw_alloc_xmitbuf23a\n"); */
1403 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
1405 phead = get_list_head(pfree_xmitbuf_queue);
1407 if (!list_empty(phead)) {
1408 pxmitbuf = list_first_entry(phead, struct xmit_buf, list);
1410 list_del_init(&pxmitbuf->list);
1412 pxmitpriv->free_xmitbuf_cnt--;
1413 pxmitbuf->priv_data = NULL;
1414 pxmitbuf->ext_tag = false;
1415 pxmitbuf->flags = XMIT_VO_QUEUE;
1417 if (pxmitbuf->sctx) {
1418 DBG_8723A("%s pxmitbuf->sctx is not NULL\n", __func__);
1419 rtw23a_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1423 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
1428 int rtw_free_xmitbuf23a(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
1431 struct rtw_queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1433 /* DBG_8723A("+rtw_free_xmitbuf23a\n"); */
1435 if (pxmitbuf == NULL)
1438 if (pxmitbuf->sctx) {
1439 DBG_8723A("%s pxmitbuf->sctx is not NULL\n", __func__);
1440 rtw23a_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_FREE);
1443 if (pxmitbuf->ext_tag) {
1444 rtw_free_xmitbuf_ext23a(pxmitpriv, pxmitbuf);
1446 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
1448 list_del_init(&pxmitbuf->list);
1450 list_add_tail(&pxmitbuf->list,
1451 get_list_head(pfree_xmitbuf_queue));
1453 pxmitpriv->free_xmitbuf_cnt++;
1454 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
1460 static void rtw_init_xmitframe(struct xmit_frame *pxframe)
1462 if (pxframe != NULL) {
1463 /* default value setting */
1464 pxframe->buf_addr = NULL;
1465 pxframe->pxmitbuf = NULL;
1467 memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib));
1468 /* pxframe->attrib.psta = NULL; */
1470 pxframe->frame_tag = DATA_FRAMETAG;
1472 pxframe->pkt = NULL;
1473 pxframe->pkt_offset = 1;/* default use pkt_offset to fill tx desc */
1475 pxframe->ack_report = 0;
1482 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack)
1484 If we turn on USE_RXTHREAD, then, no need for critical section.
1485 Otherwise, we must use _enter/_exit critical to protect free_xmit_queue...
1487 Must be very very cautious...
1490 static struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
1492 struct xmit_frame *pxframe = NULL;
1493 struct list_head *plist, *phead;
1494 struct rtw_queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
1496 spin_lock_bh(&pfree_xmit_queue->lock);
1498 if (list_empty(&pfree_xmit_queue->queue)) {
1499 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1500 ("rtw_alloc_xmitframe:%d\n",
1501 pxmitpriv->free_xmitframe_cnt));
1504 phead = get_list_head(pfree_xmit_queue);
1506 plist = phead->next;
1508 pxframe = container_of(plist, struct xmit_frame, list);
1510 list_del_init(&pxframe->list);
1511 pxmitpriv->free_xmitframe_cnt--;
1512 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1513 ("rtw_alloc_xmitframe():free_xmitframe_cnt =%d\n",
1514 pxmitpriv->free_xmitframe_cnt));
1517 spin_unlock_bh(&pfree_xmit_queue->lock);
1519 rtw_init_xmitframe(pxframe);
1524 struct xmit_frame *rtw_alloc_xmitframe23a_ext(struct xmit_priv *pxmitpriv)
1526 struct xmit_frame *pxframe = NULL;
1527 struct list_head *plist, *phead;
1528 struct rtw_queue *queue = &pxmitpriv->free_xframe_ext_queue;
1530 spin_lock_bh(&queue->lock);
1532 if (list_empty(&queue->queue)) {
1533 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe23a_ext:%d\n", pxmitpriv->free_xframe_ext_cnt));
1536 phead = get_list_head(queue);
1537 plist = phead->next;
1538 pxframe = container_of(plist, struct xmit_frame, list);
1540 list_del_init(&pxframe->list);
1541 pxmitpriv->free_xframe_ext_cnt--;
1542 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe23a_ext():free_xmitframe_cnt =%d\n", pxmitpriv->free_xframe_ext_cnt));
1545 spin_unlock_bh(&queue->lock);
1547 rtw_init_xmitframe(pxframe);
1552 s32 rtw_free_xmitframe23a(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe)
1554 struct rtw_queue *queue = NULL;
1555 struct rtw_adapter *padapter = pxmitpriv->adapter;
1556 struct sk_buff *pndis_pkt = NULL;
1558 if (pxmitframe == NULL) {
1559 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("====== rtw_free_xmitframe23a():pxmitframe == NULL!!!!!!!!!!\n"));
1563 if (pxmitframe->pkt) {
1564 pndis_pkt = pxmitframe->pkt;
1565 pxmitframe->pkt = NULL;
1568 if (pxmitframe->ext_tag == 0)
1569 queue = &pxmitpriv->free_xmit_queue;
1570 else if (pxmitframe->ext_tag == 1)
1571 queue = &pxmitpriv->free_xframe_ext_queue;
1574 goto check_pkt_complete;
1575 spin_lock_bh(&queue->lock);
1577 list_del_init(&pxmitframe->list);
1578 list_add_tail(&pxmitframe->list, get_list_head(queue));
1579 if (pxmitframe->ext_tag == 0) {
1580 pxmitpriv->free_xmitframe_cnt++;
1581 RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_, ("rtw_free_xmitframe23a():free_xmitframe_cnt =%d\n", pxmitpriv->free_xmitframe_cnt));
1582 } else if (pxmitframe->ext_tag == 1) {
1583 pxmitpriv->free_xframe_ext_cnt++;
1584 RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_, ("rtw_free_xmitframe23a():free_xframe_ext_cnt =%d\n", pxmitpriv->free_xframe_ext_cnt));
1587 spin_unlock_bh(&queue->lock);
1592 rtw_os_pkt_complete23a(padapter, pndis_pkt);
1599 void rtw_free_xmitframe_queue23a(struct xmit_priv *pxmitpriv,
1600 struct rtw_queue *pframequeue)
1602 struct list_head *plist, *phead, *ptmp;
1603 struct xmit_frame *pxmitframe;
1605 spin_lock_bh(&pframequeue->lock);
1607 phead = get_list_head(pframequeue);
1609 list_for_each_safe(plist, ptmp, phead) {
1610 pxmitframe = container_of(plist, struct xmit_frame, list);
1612 rtw_free_xmitframe23a(pxmitpriv, pxmitframe);
1614 spin_unlock_bh(&pframequeue->lock);
1618 int rtw_xmitframe_enqueue23a(struct rtw_adapter *padapter,
1619 struct xmit_frame *pxmitframe)
1621 if (rtw_xmit23a_classifier(padapter, pxmitframe) == _FAIL) {
1622 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
1623 ("rtw_xmitframe_enqueue23a: drop xmit pkt for "
1624 "classifier fail\n"));
1631 static struct xmit_frame *
1632 dequeue_one_xmitframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit,
1633 struct tx_servq *ptxservq, struct rtw_queue *pframe_queue)
1635 struct list_head *phead;
1636 struct xmit_frame *pxmitframe = NULL;
1638 phead = get_list_head(pframe_queue);
1640 if (!list_empty(phead)) {
1641 pxmitframe = list_first_entry(phead, struct xmit_frame, list);
1642 list_del_init(&pxmitframe->list);
1649 rtw_dequeue_xframe23a(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit_i,
1652 struct list_head *sta_plist, *sta_phead, *ptmp;
1653 struct hw_xmit *phwxmit;
1654 struct tx_servq *ptxservq = NULL;
1655 struct rtw_queue *pframe_queue = NULL;
1656 struct xmit_frame *pxmitframe = NULL;
1657 struct rtw_adapter *padapter = pxmitpriv->adapter;
1658 struct registry_priv *pregpriv = &padapter->registrypriv;
1665 if (pregpriv->wifi_spec == 1) {
1668 for (j = 0; j < 4; j++)
1669 inx[j] = pxmitpriv->wmm_para_seq[j];
1672 spin_lock_bh(&pxmitpriv->lock);
1674 for (i = 0; i < entry; i++) {
1675 phwxmit = phwxmit_i + inx[i];
1677 sta_phead = get_list_head(phwxmit->sta_queue);
1679 list_for_each_safe(sta_plist, ptmp, sta_phead) {
1680 ptxservq = container_of(sta_plist, struct tx_servq,
1683 pframe_queue = &ptxservq->sta_pending;
1685 pxmitframe = dequeue_one_xmitframe(pxmitpriv, phwxmit, ptxservq, pframe_queue);
1690 /* Remove sta node when there is no pending packets. */
1691 /* must be done after get_next and
1693 if (list_empty(&pframe_queue->queue))
1694 list_del_init(&ptxservq->tx_pending);
1700 spin_unlock_bh(&pxmitpriv->lock);
1704 struct tx_servq *rtw_get_sta_pending23a(struct rtw_adapter *padapter, struct sta_info *psta, int up, u8 *ac)
1706 struct tx_servq *ptxservq = NULL;
1711 ptxservq = &psta->sta_xmitpriv.bk_q;
1713 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending23a : BK\n"));
1717 ptxservq = &psta->sta_xmitpriv.vi_q;
1719 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending23a : VI\n"));
1723 ptxservq = &psta->sta_xmitpriv.vo_q;
1725 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending23a : VO\n"));
1730 ptxservq = &psta->sta_xmitpriv.be_q;
1732 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending23a : BE\n"));
1739 * Will enqueue pxmitframe to the proper queue,
1740 * and indicate it to xx_pending list.....
1742 int rtw_xmit23a_classifier(struct rtw_adapter *padapter,
1743 struct xmit_frame *pxmitframe)
1745 struct sta_info *psta;
1746 struct tx_servq *ptxservq;
1747 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1748 struct sta_priv *pstapriv = &padapter->stapriv;
1749 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
1753 if (pattrib->psta) {
1754 psta = pattrib->psta;
1756 DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
1757 psta = rtw_get_stainfo23a(pstapriv, pattrib->ra);
1761 DBG_8723A("rtw_xmit23a_classifier: psta == NULL\n");
1762 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
1763 ("rtw_xmit23a_classifier: psta == NULL\n"));
1766 if (!(psta->state & _FW_LINKED)) {
1767 DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__,
1771 ptxservq = rtw_get_sta_pending23a(padapter, psta, pattrib->priority,
1774 if (list_empty(&ptxservq->tx_pending)) {
1775 list_add_tail(&ptxservq->tx_pending,
1776 get_list_head(phwxmits[ac_index].sta_queue));
1779 list_add_tail(&pxmitframe->list, get_list_head(&ptxservq->sta_pending));
1781 phwxmits[ac_index].accnt++;
1786 void rtw_alloc_hwxmits23a(struct rtw_adapter *padapter)
1788 struct hw_xmit *hwxmits;
1789 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1792 pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;
1794 size = sizeof(struct hw_xmit) * (pxmitpriv->hwxmit_entry + 1);
1795 pxmitpriv->hwxmits = kzalloc(size, GFP_KERNEL);
1797 hwxmits = pxmitpriv->hwxmits;
1799 if (pxmitpriv->hwxmit_entry == 5) {
1800 /* pxmitpriv->bmc_txqueue.head = 0; */
1801 /* hwxmits[0] .phwtxqueue = &pxmitpriv->bmc_txqueue; */
1802 hwxmits[0] .sta_queue = &pxmitpriv->bm_pending;
1804 /* pxmitpriv->vo_txqueue.head = 0; */
1805 /* hwxmits[1] .phwtxqueue = &pxmitpriv->vo_txqueue; */
1806 hwxmits[1] .sta_queue = &pxmitpriv->vo_pending;
1808 /* pxmitpriv->vi_txqueue.head = 0; */
1809 /* hwxmits[2] .phwtxqueue = &pxmitpriv->vi_txqueue; */
1810 hwxmits[2] .sta_queue = &pxmitpriv->vi_pending;
1812 /* pxmitpriv->bk_txqueue.head = 0; */
1813 /* hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue; */
1814 hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
1816 /* pxmitpriv->be_txqueue.head = 0; */
1817 /* hwxmits[4] .phwtxqueue = &pxmitpriv->be_txqueue; */
1818 hwxmits[4] .sta_queue = &pxmitpriv->be_pending;
1820 } else if (pxmitpriv->hwxmit_entry == 4) {
1822 /* pxmitpriv->vo_txqueue.head = 0; */
1823 /* hwxmits[0] .phwtxqueue = &pxmitpriv->vo_txqueue; */
1824 hwxmits[0] .sta_queue = &pxmitpriv->vo_pending;
1826 /* pxmitpriv->vi_txqueue.head = 0; */
1827 /* hwxmits[1] .phwtxqueue = &pxmitpriv->vi_txqueue; */
1828 hwxmits[1] .sta_queue = &pxmitpriv->vi_pending;
1830 /* pxmitpriv->be_txqueue.head = 0; */
1831 /* hwxmits[2] .phwtxqueue = &pxmitpriv->be_txqueue; */
1832 hwxmits[2] .sta_queue = &pxmitpriv->be_pending;
1834 /* pxmitpriv->bk_txqueue.head = 0; */
1835 /* hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue; */
1836 hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
1842 void rtw_free_hwxmits23a(struct rtw_adapter *padapter)
1844 struct hw_xmit *hwxmits;
1845 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1847 hwxmits = pxmitpriv->hwxmits;
1851 void rtw_init_hwxmits23a(struct hw_xmit *phwxmit, int entry)
1855 for (i = 0; i < entry; i++, phwxmit++)
1859 u32 rtw_get_ff_hwaddr23a(struct xmit_frame *pxmitframe)
1862 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1864 switch (pattrib->qsel) {
1867 addr = BE_QUEUE_INX;
1871 addr = BK_QUEUE_INX;
1875 addr = VI_QUEUE_INX;
1879 addr = VO_QUEUE_INX;
1882 addr = BCN_QUEUE_INX;
1884 case 0x11:/* BC/MC in PS (HIQ) */
1885 addr = HIGH_QUEUE_INX;
1889 addr = MGT_QUEUE_INX;
1896 static void do_queue_select(struct rtw_adapter *padapter, struct pkt_attrib *pattrib)
1900 qsel = pattrib->priority;
1901 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1902 ("### do_queue_select priority =%d , qsel = %d\n",
1903 pattrib->priority, qsel));
1905 pattrib->qsel = qsel;
1909 * The main transmit(tx) entry
1913 * 0 success, hardware will handle this xmit frame(packet)
1916 int rtw_xmit23a(struct rtw_adapter *padapter, struct sk_buff *skb)
1918 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1919 struct xmit_frame *pxmitframe = NULL;
1922 pxmitframe = rtw_alloc_xmitframe(pxmitpriv);
1924 if (pxmitframe == NULL) {
1925 RT_TRACE(_module_xmit_osdep_c_, _drv_err_,
1926 ("rtw_xmit23a: no more pxmitframe\n"));
1930 res = update_attrib(padapter, skb, &pxmitframe->attrib);
1933 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit23a: update attrib fail\n"));
1934 rtw_free_xmitframe23a(pxmitpriv, pxmitframe);
1937 pxmitframe->pkt = skb;
1939 rtw_led_control(padapter, LED_CTL_TX);
1941 do_queue_select(padapter, &pxmitframe->attrib);
1943 #ifdef CONFIG_8723AU_AP_MODE
1944 spin_lock_bh(&pxmitpriv->lock);
1945 if (xmitframe_enqueue_for_sleeping_sta23a(padapter, pxmitframe)) {
1946 spin_unlock_bh(&pxmitpriv->lock);
1949 spin_unlock_bh(&pxmitpriv->lock);
1952 if (rtl8723au_hal_xmit(padapter, pxmitframe) == false)
1958 #if defined(CONFIG_8723AU_AP_MODE)
1960 int xmitframe_enqueue_for_sleeping_sta23a(struct rtw_adapter *padapter, struct xmit_frame *pxmitframe)
1963 struct sta_info *psta = NULL;
1964 struct sta_priv *pstapriv = &padapter->stapriv;
1965 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1966 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1967 int bmcst = is_multicast_ether_addr(pattrib->ra);
1969 if (!check_fwstate(pmlmepriv, WIFI_AP_STATE))
1972 if (pattrib->psta) {
1973 psta = pattrib->psta;
1975 DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
1976 psta = rtw_get_stainfo23a(pstapriv, pattrib->ra);
1980 DBG_8723A("%s, psta == NUL\n", __func__);
1984 if (!(psta->state & _FW_LINKED)) {
1985 DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__,
1990 if (pattrib->triggered == 1) {
1992 pattrib->qsel = 0x11;/* HIQ */
1997 spin_lock_bh(&psta->sleep_q.lock);
1999 if (pstapriv->sta_dz_bitmap) {
2000 /* if anyone sta is in ps mode */
2001 list_del_init(&pxmitframe->list);
2003 /* spin_lock_bh(&psta->sleep_q.lock); */
2005 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
2009 pstapriv->tim_bitmap |= BIT(0);/* */
2010 pstapriv->sta_dz_bitmap |= BIT(0);
2012 /* DBG_8723A("enqueue, sq_len =%d, tim =%x\n", psta->sleepq_len, pstapriv->tim_bitmap); */
2014 /* tx bc/mc packets after update bcn */
2015 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
2017 /* spin_unlock_bh(&psta->sleep_q.lock); */
2023 spin_unlock_bh(&psta->sleep_q.lock);
2029 spin_lock_bh(&psta->sleep_q.lock);
2031 if (psta->state&WIFI_SLEEP_STATE) {
2034 if (pstapriv->sta_dz_bitmap & CHKBIT(psta->aid)) {
2035 list_del_init(&pxmitframe->list);
2037 /* spin_lock_bh(&psta->sleep_q.lock); */
2039 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
2043 switch (pattrib->priority) {
2046 wmmps_ac = psta->uapsd_bk & BIT(0);
2050 wmmps_ac = psta->uapsd_vi & BIT(0);
2054 wmmps_ac = psta->uapsd_vo & BIT(0);
2059 wmmps_ac = psta->uapsd_be & BIT(0);
2064 psta->sleepq_ac_len++;
2066 if (((psta->has_legacy_ac) && (!wmmps_ac)) ||
2067 ((!psta->has_legacy_ac) && (wmmps_ac))) {
2068 pstapriv->tim_bitmap |= CHKBIT(psta->aid);
2070 if (psta->sleepq_len == 1) {
2071 /* update BCN for TIM IE */
2072 update_beacon23a(padapter, WLAN_EID_TIM,
2077 /* spin_unlock_bh(&psta->sleep_q.lock); */
2079 /* if (psta->sleepq_len > (NR_XMITFRAME>>3)) */
2081 /* wakeup_sta_to_xmit23a(padapter, psta); */
2090 spin_unlock_bh(&psta->sleep_q.lock);
2096 dequeue_xmitframes_to_sleeping_queue(struct rtw_adapter *padapter,
2097 struct sta_info *psta,
2098 struct rtw_queue *pframequeue)
2101 struct list_head *plist, *phead, *ptmp;
2103 struct tx_servq *ptxservq;
2104 struct pkt_attrib *pattrib;
2105 struct xmit_frame *pxmitframe;
2106 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
2108 phead = get_list_head(pframequeue);
2110 list_for_each_safe(plist, ptmp, phead) {
2111 pxmitframe = container_of(plist, struct xmit_frame, list);
2113 ret = xmitframe_enqueue_for_sleeping_sta23a(padapter, pxmitframe);
2116 pattrib = &pxmitframe->attrib;
2118 ptxservq = rtw_get_sta_pending23a(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
2121 phwxmits[ac_index].accnt--;
2123 /* DBG_8723A("xmitframe_enqueue_for_sleeping_sta23a return false\n"); */
2128 void stop_sta_xmit23a(struct rtw_adapter *padapter, struct sta_info *psta)
2130 struct sta_info *psta_bmc;
2131 struct sta_xmit_priv *pstaxmitpriv;
2132 struct sta_priv *pstapriv = &padapter->stapriv;
2133 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2135 pstaxmitpriv = &psta->sta_xmitpriv;
2137 /* for BC/MC Frames */
2138 psta_bmc = rtw_get_bcmc_stainfo23a(padapter);
2140 spin_lock_bh(&pxmitpriv->lock);
2142 psta->state |= WIFI_SLEEP_STATE;
2144 pstapriv->sta_dz_bitmap |= CHKBIT(psta->aid);
2146 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vo_q.sta_pending);
2147 list_del_init(&pstaxmitpriv->vo_q.tx_pending);
2149 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vi_q.sta_pending);
2150 list_del_init(&pstaxmitpriv->vi_q.tx_pending);
2152 dequeue_xmitframes_to_sleeping_queue(padapter, psta,
2153 &pstaxmitpriv->be_q.sta_pending);
2154 list_del_init(&pstaxmitpriv->be_q.tx_pending);
2156 dequeue_xmitframes_to_sleeping_queue(padapter, psta,
2157 &pstaxmitpriv->bk_q.sta_pending);
2158 list_del_init(&pstaxmitpriv->bk_q.tx_pending);
2160 /* for BC/MC Frames */
2161 pstaxmitpriv = &psta_bmc->sta_xmitpriv;
2162 dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc,
2163 &pstaxmitpriv->be_q.sta_pending);
2164 list_del_init(&pstaxmitpriv->be_q.tx_pending);
2166 spin_unlock_bh(&pxmitpriv->lock);
2169 void wakeup_sta_to_xmit23a(struct rtw_adapter *padapter, struct sta_info *psta)
2171 u8 update_mask = 0, wmmps_ac = 0;
2172 struct sta_info *psta_bmc;
2173 struct list_head *plist, *phead, *ptmp;
2174 struct xmit_frame *pxmitframe = NULL;
2175 struct sta_priv *pstapriv = &padapter->stapriv;
2176 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2178 spin_lock_bh(&pxmitpriv->lock);
2180 phead = get_list_head(&psta->sleep_q);
2182 list_for_each_safe(plist, ptmp, phead) {
2183 pxmitframe = container_of(plist, struct xmit_frame, list);
2184 list_del_init(&pxmitframe->list);
2186 switch (pxmitframe->attrib.priority) {
2189 wmmps_ac = psta->uapsd_bk & BIT(1);
2193 wmmps_ac = psta->uapsd_vi & BIT(1);
2197 wmmps_ac = psta->uapsd_vo & BIT(1);
2202 wmmps_ac = psta->uapsd_be & BIT(1);
2207 if (psta->sleepq_len > 0)
2208 pxmitframe->attrib.mdata = 1;
2210 pxmitframe->attrib.mdata = 0;
2213 psta->sleepq_ac_len--;
2214 if (psta->sleepq_ac_len > 0) {
2215 pxmitframe->attrib.mdata = 1;
2216 pxmitframe->attrib.eosp = 0;
2218 pxmitframe->attrib.mdata = 0;
2219 pxmitframe->attrib.eosp = 1;
2223 pxmitframe->attrib.triggered = 1;
2224 rtl8723au_hal_xmitframe_enqueue(padapter, pxmitframe);
2227 if (psta->sleepq_len == 0) {
2228 pstapriv->tim_bitmap &= ~CHKBIT(psta->aid);
2230 /* update BCN for TIM IE */
2231 update_mask = BIT(0);
2233 if (psta->state&WIFI_SLEEP_STATE)
2234 psta->state ^= WIFI_SLEEP_STATE;
2236 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
2237 psta->expire_to = pstapriv->expire_to;
2238 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
2241 pstapriv->sta_dz_bitmap &= ~CHKBIT(psta->aid);
2244 /* spin_unlock_bh(&psta->sleep_q.lock); */
2245 spin_unlock_bh(&pxmitpriv->lock);
2247 /* for BC/MC Frames */
2248 psta_bmc = rtw_get_bcmc_stainfo23a(padapter);
2252 if ((pstapriv->sta_dz_bitmap&0xfffe) == 0x0) {
2253 /* no any sta in ps mode */
2254 spin_lock_bh(&pxmitpriv->lock);
2256 phead = get_list_head(&psta_bmc->sleep_q);
2258 list_for_each_safe(plist, ptmp, phead) {
2259 pxmitframe = container_of(plist, struct xmit_frame,
2262 list_del_init(&pxmitframe->list);
2264 psta_bmc->sleepq_len--;
2265 if (psta_bmc->sleepq_len > 0)
2266 pxmitframe->attrib.mdata = 1;
2268 pxmitframe->attrib.mdata = 0;
2270 pxmitframe->attrib.triggered = 1;
2271 rtl8723au_hal_xmitframe_enqueue(padapter, pxmitframe);
2273 if (psta_bmc->sleepq_len == 0) {
2274 pstapriv->tim_bitmap &= ~BIT(0);
2275 pstapriv->sta_dz_bitmap &= ~BIT(0);
2277 /* update BCN for TIM IE */
2278 /* update_BCNTIM(padapter); */
2279 update_mask |= BIT(1);
2282 /* spin_unlock_bh(&psta_bmc->sleep_q.lock); */
2283 spin_unlock_bh(&pxmitpriv->lock);
2287 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
2290 void xmit_delivery_enabled_frames23a(struct rtw_adapter *padapter,
2291 struct sta_info *psta)
2294 struct list_head *plist, *phead, *ptmp;
2295 struct xmit_frame *pxmitframe;
2296 struct sta_priv *pstapriv = &padapter->stapriv;
2297 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2299 /* spin_lock_bh(&psta->sleep_q.lock); */
2300 spin_lock_bh(&pxmitpriv->lock);
2302 phead = get_list_head(&psta->sleep_q);
2304 list_for_each_safe(plist, ptmp, phead) {
2305 pxmitframe = container_of(plist, struct xmit_frame, list);
2307 switch (pxmitframe->attrib.priority) {
2310 wmmps_ac = psta->uapsd_bk & BIT(1);
2314 wmmps_ac = psta->uapsd_vi & BIT(1);
2318 wmmps_ac = psta->uapsd_vo & BIT(1);
2323 wmmps_ac = psta->uapsd_be & BIT(1);
2330 list_del_init(&pxmitframe->list);
2333 psta->sleepq_ac_len--;
2335 if (psta->sleepq_ac_len > 0) {
2336 pxmitframe->attrib.mdata = 1;
2337 pxmitframe->attrib.eosp = 0;
2339 pxmitframe->attrib.mdata = 0;
2340 pxmitframe->attrib.eosp = 1;
2343 pxmitframe->attrib.triggered = 1;
2345 rtl8723au_hal_xmitframe_enqueue(padapter, pxmitframe);
2347 if ((psta->sleepq_ac_len == 0) && (!psta->has_legacy_ac) &&
2349 pstapriv->tim_bitmap &= ~CHKBIT(psta->aid);
2351 /* update BCN for TIM IE */
2352 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
2355 spin_unlock_bh(&pxmitpriv->lock);
2360 void rtw_sctx_init23a(struct submit_ctx *sctx, int timeout_ms)
2362 sctx->timeout_ms = timeout_ms;
2363 init_completion(&sctx->done);
2364 sctx->status = RTW_SCTX_SUBMITTED;
2367 int rtw_sctx_wait23a(struct submit_ctx *sctx)
2370 unsigned long expire;
2373 expire = sctx->timeout_ms ? msecs_to_jiffies(sctx->timeout_ms) :
2374 MAX_SCHEDULE_TIMEOUT;
2375 if (!wait_for_completion_timeout(&sctx->done, expire)) {
2376 /* timeout, do something?? */
2377 status = RTW_SCTX_DONE_TIMEOUT;
2378 DBG_8723A("%s timeout\n", __func__);
2380 status = sctx->status;
2383 if (status == RTW_SCTX_DONE_SUCCESS)
2389 static bool rtw_sctx_chk_waring_status(int status)
2392 case RTW_SCTX_DONE_UNKNOWN:
2393 case RTW_SCTX_DONE_BUF_ALLOC:
2394 case RTW_SCTX_DONE_BUF_FREE:
2395 case RTW_SCTX_DONE_DRV_STOP:
2396 case RTW_SCTX_DONE_DEV_REMOVE:
2403 void rtw23a_sctx_done_err(struct submit_ctx **sctx, int status)
2406 if (rtw_sctx_chk_waring_status(status))
2407 DBG_8723A("%s status:%d\n", __func__, status);
2408 (*sctx)->status = status;
2409 complete(&(*sctx)->done);
2414 void rtw_sctx_done23a(struct submit_ctx **sctx)
2416 rtw23a_sctx_done_err(sctx, RTW_SCTX_DONE_SUCCESS);
2419 int rtw_ack_tx_wait23a(struct xmit_priv *pxmitpriv, u32 timeout_ms)
2421 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
2423 pack_tx_ops->timeout_ms = timeout_ms;
2424 pack_tx_ops->status = RTW_SCTX_SUBMITTED;
2426 return rtw_sctx_wait23a(pack_tx_ops);
2429 void rtw_ack_tx_done23a(struct xmit_priv *pxmitpriv, int status)
2431 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
2433 if (pxmitpriv->ack_tx)
2434 rtw23a_sctx_done_err(&pack_tx_ops, status);
2436 DBG_8723A("%s ack_tx not set\n", __func__);