hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
/* SPDX-License-Identifier: GPL-2.0 */
/******************************************************************************
 *
 * Copyright(c) 2007 - 2017 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 *****************************************************************************/
 
#define _RTL8188FU_XMIT_C_
 
#include <rtl8188f_hal.h>
 
 
s32    rtl8188fu_init_xmit_priv(_adapter *padapter)
{
   struct xmit_priv    *pxmitpriv = &padapter->xmitpriv;
 
#ifdef PLATFORM_LINUX
   tasklet_init(&pxmitpriv->xmit_tasklet,
            (void(*)(unsigned long))rtl8188fu_xmit_tasklet,
            (unsigned long)padapter);
#endif
   return _SUCCESS;
}
 
void    rtl8188fu_free_xmit_priv(_adapter *padapter)
{
}
 
void _dbg_dump_tx_info(_adapter    *padapter, int frame_tag, struct tx_desc *ptxdesc)
{
   u8 bDumpTxPkt;
   u8 bDumpTxDesc = _FALSE;
   rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DUMP_TXPKT, &(bDumpTxPkt));
 
   if (bDumpTxPkt == 1) { /*dump txdesc for data frame */
       RTW_INFO("dump tx_desc for data frame\n");
       if ((frame_tag & 0x0f) == DATA_FRAMETAG)
           bDumpTxDesc = _TRUE;
   } else if (bDumpTxPkt == 2) { /*dump txdesc for mgnt frame */
       RTW_INFO("dump tx_desc for mgnt frame\n");
       if ((frame_tag & 0x0f) == MGNT_FRAMETAG)
           bDumpTxDesc = _TRUE;
   } else if (bDumpTxPkt == 3) { /*dump early info */
   }
 
   if (bDumpTxDesc) {
       RTW_INFO("=====================================\n");
       RTW_INFO("txdw0(0x%08x)\n", ptxdesc->txdw0);
       RTW_INFO("txdw1(0x%08x)\n", ptxdesc->txdw1);
       RTW_INFO("txdw2(0x%08x)\n", ptxdesc->txdw2);
       RTW_INFO("txdw3(0x%08x)\n", ptxdesc->txdw3);
       RTW_INFO("txdw4(0x%08x)\n", ptxdesc->txdw4);
       RTW_INFO("txdw5(0x%08x)\n", ptxdesc->txdw5);
       RTW_INFO("txdw6(0x%08x)\n", ptxdesc->txdw6);
       RTW_INFO("txdw7(0x%08x)\n", ptxdesc->txdw7);
       RTW_INFO("txdw8(0x%08x)\n", ptxdesc->txdw8);
       RTW_INFO("txdw9(0x%08x)\n", ptxdesc->txdw9);
       RTW_INFO("=====================================\n");
   }
 
}
 
int urb_zero_packet_chk(_adapter *padapter, int sz)
{
   u8 blnSetTxDescOffset;
   HAL_DATA_TYPE    *pHalData    = GET_HAL_DATA(padapter);
   blnSetTxDescOffset = (((sz + TXDESC_SIZE) %  pHalData->UsbBulkOutSize) == 0) ? 1 : 0;
 
   return blnSetTxDescOffset;
}
void fill_txdesc_sectype(struct pkt_attrib *pattrib, struct tx_desc *ptxdesc)
{
   if ((pattrib->encrypt > 0) && !pattrib->bswenc) {
       switch (pattrib->encrypt) {
       /*SEC_TYPE */
       case _WEP40_:
       case _WEP104_:
           ptxdesc->txdw1 |= cpu_to_le32((0x01 << 22) & 0x00c00000);
           break;
       case _TKIP_:
       case _TKIP_WTMIC_:
           /*ptxdesc->txdw1 |= cpu_to_le32((0x02<<22)&0x00c00000); */
           ptxdesc->txdw1 |= cpu_to_le32((0x01 << 22) & 0x00c00000);
           break;
       case _AES_:
           ptxdesc->txdw1 |= cpu_to_le32((0x03 << 22) & 0x00c00000);
           break;
       case _NO_PRIVACY_:
       default:
           break;
 
       }
 
   }
 
}
 
void fill_txdesc_vcs(struct pkt_attrib *pattrib, u32 *pdw)
{
   /*RTW_INFO("cvs_mode=%d\n", pattrib->vcs_mode); */
 
   switch (pattrib->vcs_mode) {
   case RTS_CTS:
       *pdw |= cpu_to_le32(BIT(12));
       break;
   case CTS_TO_SELF:
       *pdw |= cpu_to_le32(BIT(11));
       break;
   case NONE_VCS:
   default:
       break;
   }
 
   if (pattrib->vcs_mode) {
       *pdw |= cpu_to_le32(BIT(13));
 
       /* Set RTS BW */
       if (pattrib->ht_en) {
           *pdw |= (pattrib->bwmode & CHANNEL_WIDTH_40) ?    cpu_to_le32(BIT(27)) : 0;
 
           if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
               *pdw |= cpu_to_le32((0x01 << 28) & 0x30000000);
           else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
               *pdw |= cpu_to_le32((0x02 << 28) & 0x30000000);
           else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)
               *pdw |= 0;
           else
               *pdw |= cpu_to_le32((0x03 << 28) & 0x30000000);
       }
   }
}
 
void fill_txdesc_phy(struct pkt_attrib *pattrib, u32 *pdw)
{
   /*RTW_INFO("bwmode=%d, ch_off=%d\n", pattrib->bwmode, pattrib->ch_offset); */
 
   if (pattrib->ht_en) {
       *pdw |= (pattrib->bwmode & CHANNEL_WIDTH_40) ?    cpu_to_le32(BIT(25)) : 0;
 
       if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
           *pdw |= cpu_to_le32((0x01 << 20) & 0x003f0000);
       else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
           *pdw |= cpu_to_le32((0x02 << 20) & 0x003f0000);
       else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)
           *pdw |= 0;
       else
           *pdw |= cpu_to_le32((0x03 << 20) & 0x003f0000);
   }
}
 
static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz, u8 bagg_pkt)
{
   int    pull = 0;
 
 
   _adapter            *padapter = pxmitframe->padapter;
   struct tx_desc    *ptxdesc = (struct tx_desc *)pmem;
#if 0
   uint    qsel;
   struct mlme_priv    *pmlmepriv = &padapter->mlmepriv;
   struct pkt_attrib    *pattrib = &pxmitframe->attrib;
   HAL_DATA_TYPE    *pHalData = GET_HAL_DATA(padapter);
   struct dm_priv    *pdmpriv = &pHalData->dmpriv;
 
   struct ht_priv        *phtpriv = &pmlmepriv->htpriv;
   struct mlme_ext_priv    *pmlmeext = &padapter->mlmeextpriv;
   struct mlme_ext_info    *pmlmeinfo = &(pmlmeext->mlmext_info);
   sint    bmcst = IS_MCAST(pattrib->ra);
#ifdef CONFIG_P2P
   struct wifidirect_info    *pwdinfo = &padapter->wdinfo;
#endif /*CONFIG_P2P */
#endif
#ifndef CONFIG_USE_USB_BUFFER_ALLOC_TX
   if ((PACKET_OFFSET_SZ != 0)
       && (_FALSE == bagg_pkt)
       && (urb_zero_packet_chk(padapter, sz) == 0)) {
       ptxdesc = (struct tx_desc *)(pmem + PACKET_OFFSET_SZ);
       pull = 1;
       pxmitframe->pkt_offset--;
   }
#endif    /* CONFIG_USE_USB_BUFFER_ALLOC_TX */
 
   _rtw_memset(ptxdesc, 0, sizeof(struct tx_desc));
 
   rtl8188f_update_txdesc(pxmitframe, (u8 *)ptxdesc);
   _dbg_dump_tx_info(padapter, pxmitframe->frame_tag, ptxdesc);
   return pull;
 
}
 
#ifdef CONFIG_XMIT_THREAD_MODE
/*
 * Description
 *    Transmit xmitbuf to hardware tx fifo
 *
 * Return
 *    _SUCCESS    ok
 *    _FAIL        something error
 */
s32 rtl8188fu_xmit_buf_handler(PADAPTER padapter)
{
   /*PHAL_DATA_TYPE phal; */
   struct xmit_priv *pxmitpriv;
   struct xmit_buf *pxmitbuf;
   struct xmit_frame *pxmitframe;
   s32 ret;
 
 
   /*phal = GET_HAL_DATA(padapter); */
   pxmitpriv = &padapter->xmitpriv;
 
   ret = _rtw_down_sema(&pxmitpriv->xmit_sema);
   if (ret == _FAIL)
       return _FAIL;
 
   if (RTW_CANNOT_RUN(padapter)) {
       RTW_DBG(FUNC_ADPT_FMT "- bDriverStopped(%s) bSurpriseRemoved(%s)\n",
           FUNC_ADPT_ARG(padapter),
           rtw_is_drv_stopped(padapter) ? "True" : "False",
           rtw_is_surprise_removed(padapter) ? "True" : "False");
            return _FAIL;
   }
 
   if (rtw_mi_check_pending_xmitbuf(padapter) == 0)
       return _SUCCESS;
 
#ifdef CONFIG_LPS_LCLK
   ret = rtw_register_tx_alive(padapter);
   if (ret != _SUCCESS) {
       return _SUCCESS;
   }
#endif
 
   do {
       pxmitbuf = dequeue_pending_xmitbuf(pxmitpriv);
       if (pxmitbuf == NULL)
           break;
       pxmitframe = (struct xmit_frame *) pxmitbuf->priv_data;
       rtw_write_port_and_wait(padapter, pxmitbuf->ff_hwaddr, pxmitbuf->len, (unsigned char *)pxmitbuf, 500);
       rtw_free_xmitframe(pxmitpriv, pxmitframe);
 
   } while (1);
 
#ifdef CONFIG_LPS_LCLK
   rtw_unregister_tx_alive(padapter);
#endif
 
   return _SUCCESS;
}
#endif
 
 
static s32 rtw_dump_xframe(_adapter *padapter, struct xmit_frame *pxmitframe)
{
   s32 ret = _SUCCESS;
   s32 inner_ret = _SUCCESS;
   int t, sz, w_sz, pull = 0;
   u8 *mem_addr;
   u32 ff_hwaddr;
   struct xmit_buf *pxmitbuf = pxmitframe->pxmitbuf;
   struct pkt_attrib *pattrib = &pxmitframe->attrib;
   struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
   struct security_priv *psecuritypriv = &padapter->securitypriv;
#ifdef CONFIG_80211N_HT
   if ((pxmitframe->frame_tag == DATA_FRAMETAG) &&
       (pxmitframe->attrib.ether_type != 0x0806) &&
       (pxmitframe->attrib.ether_type != 0x888e) &&
       (pxmitframe->attrib.dhcp_pkt != 1))
       rtw_issue_addbareq_cmd(padapter, pxmitframe);
#endif /* CONFIG_80211N_HT */
   mem_addr = pxmitframe->buf_addr;
 
 
   for (t = 0; t < pattrib->nr_frags; t++) {
       if (inner_ret != _SUCCESS && ret == _SUCCESS)
           ret = _FAIL;
 
       if (t != (pattrib->nr_frags - 1)) {
 
           sz = pxmitpriv->frag_len;
           sz = sz - 4 - (psecuritypriv->sw_encrypt ? 0 : pattrib->icv_len);
       } else   /*no frag */
           sz = pattrib->last_txcmdsz;
 
       pull = update_txdesc(pxmitframe, mem_addr, sz, _FALSE);
       /*        rtl8188f_update_txdesc(pxmitframe, mem_addr+PACKET_OFFSET_SZ); */
 
       if (pull) {
           mem_addr += PACKET_OFFSET_SZ; /*pull txdesc head */
 
           /*pxmitbuf->pbuf = mem_addr; */
           pxmitframe->buf_addr = mem_addr;
 
           w_sz = sz + TXDESC_SIZE;
       } else
           w_sz = sz + TXDESC_SIZE + PACKET_OFFSET_SZ;
 
       ff_hwaddr = rtw_get_ff_hwaddr(pxmitframe);
#ifdef CONFIG_XMIT_THREAD_MODE
       pxmitbuf->len = w_sz;
       pxmitbuf->ff_hwaddr = ff_hwaddr;
       if (pxmitframe->attrib.qsel == QSLT_BEACON)
           /* download rsvd page or fw */
           inner_ret = rtw_write_port(padapter, ff_hwaddr, w_sz, (unsigned char *)pxmitbuf);
       else
           enqueue_pending_xmitbuf(pxmitpriv, pxmitbuf);
#else
       inner_ret = rtw_write_port(padapter, ff_hwaddr, w_sz, (unsigned char *)pxmitbuf);
#endif
       rtw_count_tx_stats(padapter, pxmitframe, sz);
 
 
       /*RTW_INFO("rtw_write_port, w_sz=%d, sz=%d, txdesc_sz=%d, tid=%d\n", w_sz, sz, w_sz-sz, pattrib->priority); */
 
       mem_addr += w_sz;
 
       mem_addr = (u8 *)RND4(((SIZE_PTR)(mem_addr)));
 
   }
 
#ifdef CONFIG_XMIT_THREAD_MODE
   if (pxmitframe->attrib.qsel == QSLT_BEACON)
#endif
   rtw_free_xmitframe(pxmitpriv, pxmitframe);
 
   if (ret != _SUCCESS)
       rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_UNKNOWN);
 
   return ret;
}
 
#ifdef CONFIG_USB_TX_AGGREGATION
#define IDEA_CONDITION 1    /* check all packets before enqueue */
s32 rtl8188fu_xmitframe_complete(_adapter *padapter, struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
{
   HAL_DATA_TYPE    *pHalData = GET_HAL_DATA(padapter);
   struct xmit_frame *pxmitframe = NULL;
   struct xmit_frame *pfirstframe = NULL;
 
   /* aggregate variable */
   struct hw_xmit *phwxmit;
   struct sta_info *psta = NULL;
   struct tx_servq *ptxservq = NULL;
 
   _irqL irqL;
   _list *xmitframe_plist = NULL, *xmitframe_phead = NULL;
 
   u32    pbuf;    /* next pkt address */
   u32    pbuf_tail;    /* last pkt tail */
   u32    len;    /* packet length, except TXDESC_SIZE and PKT_OFFSET */
 
   u32    bulkSize = pHalData->UsbBulkOutSize;
   u8    descCount;
   u32    bulkPtr;
 
   /* dump frame variable */
   u32 ff_hwaddr;
 
   _list *sta_plist, *sta_phead;
   u8 single_sta_in_queue = _FALSE;
 
#ifndef IDEA_CONDITION
   int res = _SUCCESS;
#endif
 
 
 
   /* check xmitbuffer is ok */
   if (pxmitbuf == NULL) {
       pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
       if (pxmitbuf == NULL)
           return _FALSE;
   }
 
 
   /*3 1. pick up first frame */
   do {
       rtw_free_xmitframe(pxmitpriv, pxmitframe);
 
       pxmitframe = rtw_dequeue_xframe(pxmitpriv, pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
       if (pxmitframe == NULL) {
           /* no more xmit frame, release xmit buffer */
           rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
           return _FALSE;
       }
 
 
#ifndef IDEA_CONDITION
       if (pxmitframe->frame_tag != DATA_FRAMETAG) {
           /*            rtw_free_xmitframe(pxmitpriv, pxmitframe); */
           continue;
       }
 
       /* TID 0~15 */
       if ((pxmitframe->attrib.priority < 0) ||
           (pxmitframe->attrib.priority > 15)) {
           /*            rtw_free_xmitframe(pxmitpriv, pxmitframe); */
           continue;
       }
#endif
 
       pxmitframe->pxmitbuf = pxmitbuf;
       pxmitframe->buf_addr = pxmitbuf->pbuf;
       pxmitbuf->priv_data = pxmitframe;
 
       /* pxmitframe->agg_num = 1; */ /* alloc xmitframe should assign to 1. */
       /* pxmitframe->pkt_offset = 1; */ /* first frame of aggregation, reserve offset */
       pxmitframe->pkt_offset = (PACKET_OFFSET_SZ / 8);
 
       if (rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe) == _FALSE) {
           RTW_INFO("%s coalesce 1st xmitframe failed\n", __func__);
           continue;
       }
 
 
       /* always return ndis_packet after rtw_xmitframe_coalesce */
       rtw_os_xmit_complete(padapter, pxmitframe);
 
       break;
   } while (1);
 
   /*3 2. aggregate same priority and same DA(AP or STA) frames */
   pfirstframe = pxmitframe;
   len = rtw_wlan_pkt_size(pfirstframe) + TXDESC_OFFSET;
   pbuf_tail = len;
   pbuf = _RND8(pbuf_tail);
 
   /* check pkt amount in one bluk */
   descCount = 0;
   bulkPtr = bulkSize;
   if (pbuf < bulkPtr)
       descCount++;
   else {
       descCount = 0;
       bulkPtr = ((pbuf / bulkSize) + 1) * bulkSize; /* round to next bulkSize */
   }
 
   /* dequeue same priority packet from station tx queue */
   psta = pfirstframe->attrib.psta;
   switch (pfirstframe->attrib.priority) {
   case 1:
   case 2:
       ptxservq = &(psta->sta_xmitpriv.bk_q);
       phwxmit = pxmitpriv->hwxmits + 3;
       break;
 
   case 4:
   case 5:
       ptxservq = &(psta->sta_xmitpriv.vi_q);
       phwxmit = pxmitpriv->hwxmits + 1;
       break;
 
   case 6:
   case 7:
       ptxservq = &(psta->sta_xmitpriv.vo_q);
       phwxmit = pxmitpriv->hwxmits;
       break;
 
   case 0:
   case 3:
   default:
       ptxservq = &(psta->sta_xmitpriv.be_q);
       phwxmit = pxmitpriv->hwxmits + 2;
       break;
   }
 
   _enter_critical_bh(&pxmitpriv->lock, &irqL);
 
   sta_phead = get_list_head(phwxmit->sta_queue);
   sta_plist = get_next(sta_phead);
   single_sta_in_queue = rtw_end_of_queue_search(sta_phead, get_next(sta_plist));
 
   xmitframe_phead = get_list_head(&ptxservq->sta_pending);
   xmitframe_plist = get_next(xmitframe_phead);
   while (rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist) == _FALSE) {
       pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
       xmitframe_plist = get_next(xmitframe_plist);
 
       if (_FAIL == rtw_hal_busagg_qsel_check(padapter, pfirstframe->attrib.qsel, pxmitframe->attrib.qsel))
           break;
 
       len = rtw_wlan_pkt_size(pxmitframe) + TXDESC_SIZE; /* no offset */
       if (pbuf + len > MAX_XMITBUF_SZ)
           break;
 
       rtw_list_delete(&pxmitframe->list);
       ptxservq->qcnt--;
       phwxmit->accnt--;
 
#ifndef IDEA_CONDITION
       /* suppose only data frames would be in queue */
       if (pxmitframe->frame_tag != DATA_FRAMETAG) {
           rtw_free_xmitframe(pxmitpriv, pxmitframe);
           continue;
       }
 
       /* TID 0~15 */
       if ((pxmitframe->attrib.priority < 0) ||
           (pxmitframe->attrib.priority > 15)) {
           rtw_free_xmitframe(pxmitpriv, pxmitframe);
           continue;
       }
#endif
 
       /*        pxmitframe->pxmitbuf = pxmitbuf; */
       pxmitframe->buf_addr = pxmitbuf->pbuf + pbuf;
 
       pxmitframe->agg_num = 0; /* not first frame of aggregation */
       pxmitframe->pkt_offset = 0; /* not first frame of aggregation, no need to reserve offset */
 
       if (rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe) == _FALSE) {
           RTW_INFO("%s coalesce failed\n", __func__);
           rtw_free_xmitframe(pxmitpriv, pxmitframe);
           continue;
       }
 
 
       /* always return ndis_packet after rtw_xmitframe_coalesce */
       rtw_os_xmit_complete(padapter, pxmitframe);
 
       /* (len - TXDESC_SIZE) == pxmitframe->attrib.last_txcmdsz */
       update_txdesc(pxmitframe, pxmitframe->buf_addr, pxmitframe->attrib.last_txcmdsz, _TRUE);
 
       /* don't need xmitframe any more */
       rtw_free_xmitframe(pxmitpriv, pxmitframe);
 
       /* handle pointer and stop condition */
       pbuf_tail = pbuf + len;
       pbuf = _RND8(pbuf_tail);
 
       pfirstframe->agg_num++;
       if (MAX_TX_AGG_PACKET_NUMBER == pfirstframe->agg_num)
           break;
 
       if (pbuf < bulkPtr) {
           descCount++;
           if (descCount == pHalData->UsbTxAggDescNum)
               break;
       } else {
           descCount = 0;
           bulkPtr = ((pbuf / bulkSize) + 1) * bulkSize;
       }
   }
   if (_rtw_queue_empty(&ptxservq->sta_pending) == _TRUE)
       rtw_list_delete(&ptxservq->tx_pending);
   else if (single_sta_in_queue == _FALSE) {
       /* Re-arrange the order of stations in this ac queue to balance the service for these stations */
       rtw_list_delete(&ptxservq->tx_pending);
       rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(phwxmit->sta_queue));
   }
 
   _exit_critical_bh(&pxmitpriv->lock, &irqL);
#ifdef CONFIG_80211N_HT
   if ((pfirstframe->attrib.ether_type != 0x0806) &&
       (pfirstframe->attrib.ether_type != 0x888e) &&
       (pfirstframe->attrib.dhcp_pkt != 1))
       rtw_issue_addbareq_cmd(padapter, pfirstframe);
#endif /* CONFIG_80211N_HT */
#ifndef CONFIG_USE_USB_BUFFER_ALLOC_TX
   /*3 3. update first frame txdesc */
   if ((PACKET_OFFSET_SZ != 0)
       && (pbuf_tail % bulkSize) == 0) {
       /* remove pkt_offset */
       pbuf_tail -= PACKET_OFFSET_SZ;
       pfirstframe->buf_addr += PACKET_OFFSET_SZ;
       pfirstframe->pkt_offset = 0;
   }
#endif    /* CONFIG_USE_USB_BUFFER_ALLOC_TX */
   update_txdesc(pfirstframe, pfirstframe->buf_addr, pfirstframe->attrib.last_txcmdsz, _TRUE);
 
   /*3 4. write xmit buffer to USB FIFO */
   ff_hwaddr = rtw_get_ff_hwaddr(pfirstframe);
 
   /* xmit address == ((xmit_frame*)pxmitbuf->priv_data)->buf_addr */
#ifdef CONFIG_XMIT_THREAD_MODE
   pxmitbuf->len = pbuf_tail;
   pxmitbuf->ff_hwaddr = ff_hwaddr;
 
   if (pfirstframe->attrib.qsel == QSLT_BEACON)
       /* download rsvd page or fw */
       rtw_write_port(padapter, ff_hwaddr, pbuf_tail, (u8 *)pxmitbuf);
   else
       enqueue_pending_xmitbuf(pxmitpriv, pxmitbuf);
#else
   rtw_write_port(padapter, ff_hwaddr, pbuf_tail, (u8 *)pxmitbuf);
#endif
 
 
   /*3 5. update statisitc */
   pbuf_tail -= (pfirstframe->agg_num * TXDESC_SIZE);
   if (pfirstframe->pkt_offset == 1)
       pbuf_tail -= PACKET_OFFSET_SZ;
 
   rtw_count_tx_stats(padapter, pfirstframe, pbuf_tail);
 
#ifdef CONFIG_XMIT_THREAD_MODE
   if (pfirstframe->attrib.qsel == QSLT_BEACON)
#endif
   rtw_free_xmitframe(pxmitpriv, pfirstframe);
 
   return _TRUE;
}
 
#else
 
s32 rtl8188fu_xmitframe_complete(_adapter *padapter, struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
{
 
   struct hw_xmit *phwxmits;
   sint hwentry;
   struct xmit_frame *pxmitframe = NULL;
   int res = _SUCCESS, xcnt = 0;
 
   phwxmits = pxmitpriv->hwxmits;
   hwentry = pxmitpriv->hwxmit_entry;
 
 
   if (pxmitbuf == NULL) {
       pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
       if (!pxmitbuf)
           return _FALSE;
   }
 
 
   do {
       pxmitframe =  rtw_dequeue_xframe(pxmitpriv, phwxmits, hwentry);
 
       if (pxmitframe) {
           pxmitframe->pxmitbuf = pxmitbuf;
 
           pxmitframe->buf_addr = pxmitbuf->pbuf;
 
           pxmitbuf->priv_data = pxmitframe;
 
           if ((pxmitframe->frame_tag & 0x0f) == DATA_FRAMETAG) {
               if (pxmitframe->attrib.priority <= 15) /*TID0~15 */
                   res = rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
 
               rtw_os_xmit_complete(padapter, pxmitframe);/*always return ndis_packet after rtw_xmitframe_coalesce */
           }
 
 
 
 
           if (res == _SUCCESS)
               rtw_dump_xframe(padapter, pxmitframe);
           else {
               rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
               rtw_free_xmitframe(pxmitpriv, pxmitframe);
           }
 
           xcnt++;
 
       } else {
           rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
           return _FALSE;
       }
 
       break;
 
   } while (0/*xcnt < (NR_XMITFRAME >> 3)*/);
 
   return _TRUE;
 
}
#endif
 
 
 
static s32 xmitframe_direct(_adapter *padapter, struct xmit_frame *pxmitframe)
{
   s32 res = _SUCCESS;
 
 
   res = rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
   if (res == _SUCCESS)
       rtw_dump_xframe(padapter, pxmitframe);
 
   return res;
}
 
/*
 * Return
 *    _TRUE    dump packet directly
 *    _FALSE    enqueue packet
 */
static s32 pre_xmitframe(_adapter *padapter, struct xmit_frame *pxmitframe)
{
   _irqL irqL;
   s32 res;
   struct xmit_buf *pxmitbuf = NULL;
   struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
   struct pkt_attrib *pattrib = &pxmitframe->attrib;
   struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 
   _enter_critical_bh(&pxmitpriv->lock, &irqL);
 
   if (rtw_txframes_sta_ac_pending(padapter, pattrib) > 0)
       goto enqueue;
 
   if (rtw_xmit_ac_blocked(padapter) == _TRUE)
       goto enqueue;
 
   if (DEV_STA_LG_NUM(padapter->dvobj))
       goto enqueue;
 
   pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
   if (pxmitbuf == NULL)
       goto enqueue;
 
   _exit_critical_bh(&pxmitpriv->lock, &irqL);
 
   pxmitframe->pxmitbuf = pxmitbuf;
   pxmitframe->buf_addr = pxmitbuf->pbuf;
   pxmitbuf->priv_data = pxmitframe;
 
   if (xmitframe_direct(padapter, pxmitframe) != _SUCCESS) {
       rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
       rtw_free_xmitframe(pxmitpriv, pxmitframe);
   }
 
   return _TRUE;
 
enqueue:
   res = rtw_xmitframe_enqueue(padapter, pxmitframe);
   _exit_critical_bh(&pxmitpriv->lock, &irqL);
 
   if (res != _SUCCESS) {
       rtw_free_xmitframe(pxmitpriv, pxmitframe);
 
       pxmitpriv->tx_drop++;
       return _TRUE;
   }
 
   return _FALSE;
}
 
s32 rtl8188fu_mgnt_xmit(_adapter *padapter, struct xmit_frame *pmgntframe)
{
   return rtw_dump_xframe(padapter, pmgntframe);
}
 
/*
 * Return
 *    _TRUE    dump packet directly ok
 *    _FALSE    temporary can't transmit packets to hardware
 */
s32 rtl8188fu_hal_xmit(_adapter *padapter, struct xmit_frame *pxmitframe)
{
   return pre_xmitframe(padapter, pxmitframe);
}
 
s32    rtl8188fu_hal_xmitframe_enqueue(_adapter *padapter, struct xmit_frame *pxmitframe)
{
   struct xmit_priv    *pxmitpriv = &padapter->xmitpriv;
   s32 err;
 
   err = rtw_xmitframe_enqueue(padapter, pxmitframe);
   if (err != _SUCCESS) {
       rtw_free_xmitframe(pxmitpriv, pxmitframe);
 
       pxmitpriv->tx_drop++;
   } else {
#ifdef PLATFORM_LINUX
       tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
#endif
   }
 
   return err;
 
}
 
 
#ifdef CONFIG_HOSTAPD_MLME
 
static void rtl8188fu_hostap_mgnt_xmit_cb(struct urb *urb)
{
#ifdef PLATFORM_LINUX
   struct sk_buff *skb = (struct sk_buff *)urb->context;
 
   /*RTW_INFO("%s\n", __func__); */
 
   rtw_skb_free(skb);
#endif
}
 
s32 rtl8188fu_hostap_mgnt_xmit_entry(_adapter *padapter, _pkt *pkt)
{
#ifdef PLATFORM_LINUX
   u16 fc;
   int rc, len, pipe;
   unsigned int bmcst, tid, qsel;
   struct sk_buff *skb, *pxmit_skb;
   struct urb *urb;
   unsigned char *pxmitbuf;
   struct tx_desc *ptxdesc;
   struct ieee80211_hdr *tx_hdr;
   struct hostapd_priv *phostapdpriv = padapter->phostapdpriv;
   struct net_device *pnetdev = padapter->pnetdev;
   HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
   struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
 
 
   /*RTW_INFO("%s\n", __func__); */
 
   skb = pkt;
 
   len = skb->len;
   tx_hdr = (struct ieee80211_hdr *)(skb->data);
   fc = le16_to_cpu(tx_hdr->frame_ctl);
   bmcst = IS_MCAST(tx_hdr->addr1);
 
   if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
       goto _exit;
 
   pxmit_skb = rtw_skb_alloc(len + TXDESC_SIZE);
 
   if (!pxmit_skb)
       goto _exit;
 
   pxmitbuf = pxmit_skb->data;
 
   urb = usb_alloc_urb(0, GFP_ATOMIC);
   if (!urb)
       goto _exit;
 
   /* ----- fill tx desc ----- */
   ptxdesc = (struct tx_desc *)pxmitbuf;
   _rtw_memset(ptxdesc, 0, sizeof(*ptxdesc));
 
   /*offset 0 */
   ptxdesc->txdw0 |= cpu_to_le32(len & 0x0000ffff);
   ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) << OFFSET_SHT) & 0x00ff0000); /*default = 32 bytes for TX Desc */
   ptxdesc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
 
   if (bmcst)
       ptxdesc->txdw0 |= cpu_to_le32(BIT(24));
 
   /*offset 4 */
   ptxdesc->txdw1 |= cpu_to_le32(0x00);/*MAC_ID */
 
   ptxdesc->txdw1 |= cpu_to_le32((0x12 << QSEL_SHT) & 0x00001f00);
 
   ptxdesc->txdw1 |= cpu_to_le32((0x06 << 16) & 0x000f0000); /*b mode */
 
   /*offset 8 */
 
   /*offset 12 */
   ptxdesc->txdw3 |= cpu_to_le32((le16_to_cpu(tx_hdr->seq_ctl) << 16) & 0xffff0000);
 
   /*offset 16 */
   ptxdesc->txdw4 |= cpu_to_le32(BIT(8));/*driver uses rate */
 
   /*offset 20 */
 
 
   /*HW append seq */
   ptxdesc->txdw4 |= cpu_to_le32(BIT(7)); /* Hw set sequence number */
   ptxdesc->txdw3 |= cpu_to_le32((8 << 28)); /*set bit3 to 1. Suugested by TimChen. 2009.12.29. */
 
 
   rtl8192cu_cal_txdesc_chksum(ptxdesc);
   /* ----- end of fill tx desc ----- */
 
   /* */
   skb_put(pxmit_skb, len + TXDESC_SIZE);
   pxmitbuf = pxmitbuf + TXDESC_SIZE;
   _rtw_memcpy(pxmitbuf, skb->data, len);
 
   /*RTW_INFO("mgnt_xmit, len=%x\n", pxmit_skb->len); */
 
 
   /* ----- prepare urb for submit ----- */
 
   /*translate DMA FIFO addr to pipehandle */
   /*pipe = ffaddr2pipehdl(pdvobj, MGT_QUEUE_INX); */
   pipe = usb_sndbulkpipe(pdvobj->pusbdev, pHalData->Queue2EPNum[(u8)MGT_QUEUE_INX] & 0x0f);
 
   usb_fill_bulk_urb(urb, pdvobj->pusbdev, pipe,
       pxmit_skb->data, pxmit_skb->len, rtl8192cu_hostap_mgnt_xmit_cb, pxmit_skb);
 
   urb->transfer_flags |= URB_ZERO_PACKET;
   usb_anchor_urb(urb, &phostapdpriv->anchored);
   rc = usb_submit_urb(urb, GFP_ATOMIC);
   if (rc < 0) {
       usb_unanchor_urb(urb);
       kfree_skb(skb);
   }
   usb_free_urb(urb);
 
 
_exit:
 
   rtw_skb_free(skb);
 
#endif
 
   return 0;
 
}
#endif