8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / include / rtw_xmit.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *
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.
8  *
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
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #ifndef _RTW_XMIT_H_
21 #define _RTW_XMIT_H_
22
23
24 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
25 #ifdef CONFIG_TX_AGGREGATION
26 #define MAX_XMITBUF_SZ  (20480) // 20k
27 //#define SDIO_TX_AGG_MAX       5
28 #else
29 #define MAX_XMITBUF_SZ (1664)
30 #define SDIO_TX_AGG_MAX 1
31 #endif
32
33 #if defined CONFIG_SDIO_HCI
34 #define NR_XMITBUFF     (16)
35 #endif
36 #if defined(CONFIG_GSPI_HCI)
37 #define NR_XMITBUFF     (128)
38 #endif
39
40 #elif defined (CONFIG_USB_HCI)
41
42 #ifdef CONFIG_USB_TX_AGGREGATION
43         #if defined(CONFIG_PLATFORM_ARM_SUNxI) || defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I) || defined(CONFIG_PLATFORM_ARM_SUN8I)
44                 #define MAX_XMITBUF_SZ (12288)  //12k 1536*8
45         #elif defined (CONFIG_PLATFORM_MSTAR)
46                 #define MAX_XMITBUF_SZ  7680    // 7.5k
47         #else
48         #define MAX_XMITBUF_SZ  (20480) // 20k
49         #endif
50 #else
51 #define MAX_XMITBUF_SZ  (2048)
52 #endif
53
54 #ifdef CONFIG_SINGLE_XMIT_BUF
55 #define NR_XMITBUFF     (1)
56 #else
57 #define NR_XMITBUFF     (4)
58 #endif //CONFIG_SINGLE_XMIT_BUF
59 #elif defined (CONFIG_PCI_HCI)
60 #define MAX_XMITBUF_SZ  (1664)
61 #define NR_XMITBUFF     (128)
62 #endif
63
64 #ifdef PLATFORM_OS_CE
65 #define XMITBUF_ALIGN_SZ 4
66 #else
67 #ifdef CONFIG_PCI_HCI
68 #define XMITBUF_ALIGN_SZ 4
69 #else
70 #ifdef USB_XMITBUF_ALIGN_SZ
71 #define XMITBUF_ALIGN_SZ (USB_XMITBUF_ALIGN_SZ)
72 #else
73 #define XMITBUF_ALIGN_SZ 512
74 #endif
75 #endif
76 #endif
77
78 // xmit extension buff defination
79 #define MAX_XMIT_EXTBUF_SZ      (1536)
80
81 #ifdef CONFIG_SINGLE_XMIT_BUF
82 #define NR_XMIT_EXTBUFF (1)
83 #else
84 #define NR_XMIT_EXTBUFF (32)
85 #endif
86
87 #define MAX_CMDBUF_SZ   (5120)  //(4096)
88
89 #define MAX_NUMBLKS             (1)
90
91 #define XMIT_VO_QUEUE (0)
92 #define XMIT_VI_QUEUE (1)
93 #define XMIT_BE_QUEUE (2)
94 #define XMIT_BK_QUEUE (3)
95
96 #define VO_QUEUE_INX            0
97 #define VI_QUEUE_INX            1
98 #define BE_QUEUE_INX            2
99 #define BK_QUEUE_INX            3
100 #define BCN_QUEUE_INX           4
101 #define MGT_QUEUE_INX           5
102 #define HIGH_QUEUE_INX          6
103 #define TXCMD_QUEUE_INX 7
104
105 #define HW_QUEUE_ENTRY  8
106
107 #ifdef CONFIG_PCI_HCI
108 //#define TXDESC_NUM                                            64
109 #define TXDESC_NUM                                              128
110 #define TXDESC_NUM_BE_QUEUE                     128
111 #endif
112
113 #define WEP_IV(pattrib_iv, dot11txpn, keyidx)\
114 do{\
115         pattrib_iv[0] = dot11txpn._byte_.TSC0;\
116         pattrib_iv[1] = dot11txpn._byte_.TSC1;\
117         pattrib_iv[2] = dot11txpn._byte_.TSC2;\
118         pattrib_iv[3] = ((keyidx & 0x3)<<6);\
119         dot11txpn.val = (dot11txpn.val == 0xffffff) ? 0: (dot11txpn.val+1);\
120 }while(0)
121
122
123 #define TKIP_IV(pattrib_iv, dot11txpn, keyidx)\
124 do{\
125         pattrib_iv[0] = dot11txpn._byte_.TSC1;\
126         pattrib_iv[1] = (dot11txpn._byte_.TSC1 | 0x20) & 0x7f;\
127         pattrib_iv[2] = dot11txpn._byte_.TSC0;\
128         pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\
129         pattrib_iv[4] = dot11txpn._byte_.TSC2;\
130         pattrib_iv[5] = dot11txpn._byte_.TSC3;\
131         pattrib_iv[6] = dot11txpn._byte_.TSC4;\
132         pattrib_iv[7] = dot11txpn._byte_.TSC5;\
133         dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0: (dot11txpn.val+1);\
134 }while(0)
135
136 #define AES_IV(pattrib_iv, dot11txpn, keyidx)\
137 do{\
138         pattrib_iv[0] = dot11txpn._byte_.TSC0;\
139         pattrib_iv[1] = dot11txpn._byte_.TSC1;\
140         pattrib_iv[2] = 0;\
141         pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\
142         pattrib_iv[4] = dot11txpn._byte_.TSC2;\
143         pattrib_iv[5] = dot11txpn._byte_.TSC3;\
144         pattrib_iv[6] = dot11txpn._byte_.TSC4;\
145         pattrib_iv[7] = dot11txpn._byte_.TSC5;\
146         dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0: (dot11txpn.val+1);\
147 }while(0)
148
149
150 #define HWXMIT_ENTRY    4
151
152 // For Buffer Descriptor ring architecture
153 #ifdef BUF_DESC_ARCH    
154 #if defined (CONFIG_RTL8192E)
155 #define TX_BUFFER_SEG_NUM       1 // 0:2 seg, 1: 4 seg, 2: 8 seg.       
156 #endif
157 #endif
158
159 #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)|| defined(CONFIG_RTL8723B) || defined(CONFIG_RTL8814A)
160 #define TXDESC_SIZE 40
161 //8192EE_TODO
162 #elif defined (CONFIG_RTL8192E) // this section is defined for buffer descriptor ring architecture
163         #ifdef CONFIG_PCI_HCI
164                 #define TXDESC_SIZE ((TX_BUFFER_SEG_NUM ==0)?16: ((TX_BUFFER_SEG_NUM ==1)? 32:64) )
165                 #define TX_WIFI_INFO_SIZE 40  
166         #else  //8192E USB or SDIO
167                 #define TXDESC_SIZE 40
168         #endif
169 //8192EE_TODO
170 #else
171 #define TXDESC_SIZE 32
172 #endif
173
174 #ifdef CONFIG_TX_EARLY_MODE
175 #define EARLY_MODE_INFO_SIZE    8
176 #endif
177
178
179 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
180 #define TXDESC_OFFSET TXDESC_SIZE
181 #endif
182
183 #ifdef CONFIG_USB_HCI
184 #ifdef USB_PACKET_OFFSET_SZ
185 #define PACKET_OFFSET_SZ (USB_PACKET_OFFSET_SZ)
186 #else
187 #define PACKET_OFFSET_SZ (8)
188 #endif
189 #define TXDESC_OFFSET (TXDESC_SIZE + PACKET_OFFSET_SZ)
190 #endif
191
192 #ifdef CONFIG_PCI_HCI
193 #if defined(CONFIG_RTL8192E) // this section is defined for buffer descriptor ring architecture
194 #define TXDESC_OFFSET TX_WIFI_INFO_SIZE
195 #else
196 #define TXDESC_OFFSET 0
197 #endif 
198 #define TX_DESC_NEXT_DESC_OFFSET        (TXDESC_SIZE + 8)
199 #endif //CONFIG_PCI_HCI
200
201 enum TXDESC_SC{
202         SC_DONT_CARE = 0x00,
203         SC_UPPER= 0x01, 
204         SC_LOWER=0x02,
205         SC_DUPLICATE=0x03
206 };
207
208 #ifdef CONFIG_PCI_HCI
209 #define TXDESC_64_BYTES
210 #elif defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A) || defined(CONFIG_RTL8723B)
211 #define TXDESC_40_BYTES
212 #endif
213
214 #if defined(CONFIG_RTL8192E) && defined(CONFIG_PCI_HCI) //8192ee
215 //8192EE_TODO
216 struct tx_desc
217 {
218         unsigned int txdw0;
219         unsigned int txdw1;
220         unsigned int txdw2;
221         unsigned int txdw3;
222         unsigned int txdw4;
223         unsigned int txdw5;
224         unsigned int txdw6;
225         unsigned int txdw7;
226 };
227 #else
228 struct tx_desc
229 {
230         unsigned int txdw0;
231         unsigned int txdw1;
232         unsigned int txdw2;
233         unsigned int txdw3;
234         unsigned int txdw4;
235         unsigned int txdw5;
236         unsigned int txdw6;
237         unsigned int txdw7;
238
239 #if defined(TXDESC_40_BYTES) || defined(TXDESC_64_BYTES)
240         unsigned int txdw8;
241         unsigned int txdw9;
242 #endif // TXDESC_40_BYTES
243
244 #ifdef TXDESC_64_BYTES
245         unsigned int txdw10;
246         unsigned int txdw11;
247
248         // 2008/05/15 MH Because PCIE HW memory R/W 4K limit. And now,  our descriptor
249         // size is 40 bytes. If you use more than 102 descriptor( 103*40>4096), HW will execute
250         // memoryR/W CRC error. And then all DMA fetch will fail. We must decrease descriptor
251         // number or enlarge descriptor size as 64 bytes.
252         unsigned int txdw12;
253         unsigned int txdw13;
254         unsigned int txdw14;
255         unsigned int txdw15;
256 #endif
257 };
258 #endif
259
260 union txdesc {
261         struct tx_desc txdesc;
262         unsigned int value[TXDESC_SIZE>>2];
263 };
264
265 #ifdef CONFIG_PCI_HCI
266 #define PCI_MAX_TX_QUEUE_COUNT  8
267
268 struct rtw_tx_ring {
269         unsigned char   qid;
270         struct tx_desc  *desc;
271         dma_addr_t      dma;
272         unsigned int    idx;
273         unsigned int    entries;
274         _queue          queue;
275         u32             qlen;
276 };
277 #endif
278
279 struct  hw_xmit {
280         //_lock xmit_lock;
281         //_list pending;
282         _queue *sta_queue;
283         //struct hw_txqueue *phwtxqueue;
284         //sint  txcmdcnt;
285         int     accnt;
286 };
287
288 #if 0
289 struct pkt_attrib
290 {
291         u8      type;
292         u8      subtype;
293         u8      bswenc;
294         u8      dhcp_pkt;
295         u16     ether_type;
296         int     pktlen;         //the original 802.3 pkt raw_data len (not include ether_hdr data)
297         int     pkt_hdrlen;     //the original 802.3 pkt header len
298         int     hdrlen;         //the WLAN Header Len
299         int     nr_frags;
300         int     last_txcmdsz;
301         int     encrypt;        //when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith
302         u8      iv[8];
303         int     iv_len;
304         u8      icv[8];
305         int     icv_len;
306         int     priority;
307         int     ack_policy;
308         int     mac_id;
309         int     vcs_mode;       //virtual carrier sense method
310
311         u8      dst[ETH_ALEN];
312         u8      src[ETH_ALEN];
313         u8      ta[ETH_ALEN];
314         u8      ra[ETH_ALEN];
315
316         u8      key_idx;
317
318         u8      qos_en;
319         u8      ht_en;
320         u8      raid;//rate adpative id
321         u8      bwmode;
322         u8      ch_offset;//PRIME_CHNL_OFFSET
323         u8      sgi;//short GI
324         u8      ampdu_en;//tx ampdu enable
325         u8      mdata;//more data bit
326         u8      eosp;
327
328         u8      triggered;//for ap mode handling Power Saving sta
329
330         u32     qsel;
331         u16     seqnum;
332
333         struct sta_info * psta;
334 #ifdef CONFIG_TCP_CSUM_OFFLOAD_TX
335         u8      hw_tcp_csum;
336 #endif
337 };
338 #else
339 //reduce size
340 struct pkt_attrib
341 {
342         u8      type;
343         u8      subtype;
344         u8      bswenc;
345         u8      dhcp_pkt;
346         u16     ether_type;
347         u16     seqnum;
348         u8      hw_ssn_sel;     //for HW_SEQ0,1,2,3
349         u16     pkt_hdrlen;     //the original 802.3 pkt header len
350         u16     hdrlen;         //the WLAN Header Len
351         u32     pktlen;         //the original 802.3 pkt raw_data len (not include ether_hdr data)
352         u32     last_txcmdsz;
353         u8      nr_frags;
354         u8      encrypt;        //when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith
355         u8      iv_len;
356         u8      icv_len;
357         u8      iv[18];
358         u8      icv[16];
359         u8      priority;
360         u8      ack_policy;
361         u8      mac_id;
362         u8      vcs_mode;       //virtual carrier sense method
363         u8      dst[ETH_ALEN];
364         u8      src[ETH_ALEN];
365         u8      ta[ETH_ALEN];
366         u8      ra[ETH_ALEN];
367         u8      key_idx;
368         u8      qos_en;
369         u8      ht_en;
370         u8      raid;//rate adpative id
371         u8      bwmode;
372         u8      ch_offset;//PRIME_CHNL_OFFSET
373         u8      sgi;//short GI
374         u8      ampdu_en;//tx ampdu enable
375         u8      ampdu_spacing; //ampdu_min_spacing for peer sta's rx
376         u8      mdata;//more data bit
377         u8      pctrl;//per packet txdesc control enable
378         u8      triggered;//for ap mode handling Power Saving sta
379         u8      qsel;
380         u8      order;//order bit
381         u8      eosp;
382         u8      rate;
383         u8      intel_proxim;
384         u8      retry_ctrl;
385         u8   mbssid;
386         u8      ldpc;
387         u8      stbc;
388         struct sta_info * psta;
389 #ifdef CONFIG_TCP_CSUM_OFFLOAD_TX
390         u8      hw_tcp_csum;
391 #endif
392
393         u8 rtsen;
394         u8 cts2self;
395         union Keytype   dot11tkiptxmickey;
396         //union Keytype dot11tkiprxmickey;
397         union Keytype   dot118021x_UncstKey;
398
399 #ifdef CONFIG_TDLS
400         u8 direct_link;
401         struct sta_info *ptdls_sta;
402 #endif //CONFIG_TDLS
403
404         u8 icmp_pkt;
405         
406 };
407 #endif
408
409 #ifdef PLATFORM_FREEBSD
410 #define ETH_ALEN        6               /* Octets in one ethernet addr   */
411 #define ETH_HLEN        14              /* Total octets in header.       */
412 #define ETH_P_IP        0x0800          /* Internet Protocol packet     */
413
414 /*struct rtw_ieee80211_hdr {
415         uint16_t frame_control;
416         uint16_t duration_id;
417         u8 addr1[6];
418         u8 addr2[6];
419         u8 addr3[6];
420         uint16_t seq_ctrl;
421         u8 addr4[6];
422 } ;*/
423 #endif //PLATFORM_FREEBSD
424
425 #define WLANHDR_OFFSET  64
426
427 #define NULL_FRAMETAG           (0x0)
428 #define DATA_FRAMETAG           0x01
429 #define L2_FRAMETAG             0x02
430 #define MGNT_FRAMETAG           0x03
431 #define AMSDU_FRAMETAG  0x04
432
433 #define EII_FRAMETAG            0x05
434 #define IEEE8023_FRAMETAG  0x06
435
436 #define MP_FRAMETAG             0x07
437
438 #define TXAGG_FRAMETAG  0x08
439
440 enum {
441         XMITBUF_DATA = 0,
442         XMITBUF_MGNT = 1,
443         XMITBUF_CMD = 2,
444 };
445
446 struct  submit_ctx{
447         u32 submit_time; /* */
448         u32 timeout_ms; /* <0: not synchronous, 0: wait forever, >0: up to ms waiting */
449         int status; /* status for operation */
450 #ifdef PLATFORM_LINUX
451         struct completion done;
452 #endif
453 };
454
455 enum {
456         RTW_SCTX_SUBMITTED = -1,
457         RTW_SCTX_DONE_SUCCESS = 0,
458         RTW_SCTX_DONE_UNKNOWN,
459         RTW_SCTX_DONE_TIMEOUT,
460         RTW_SCTX_DONE_BUF_ALLOC,
461         RTW_SCTX_DONE_BUF_FREE,
462         RTW_SCTX_DONE_WRITE_PORT_ERR,
463         RTW_SCTX_DONE_TX_DESC_NA,
464         RTW_SCTX_DONE_TX_DENY,
465         RTW_SCTX_DONE_CCX_PKT_FAIL,
466         RTW_SCTX_DONE_DRV_STOP,
467         RTW_SCTX_DONE_DEV_REMOVE,
468         RTW_SCTX_DONE_CMD_ERROR,
469 };
470
471
472 void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms);
473 int rtw_sctx_wait(struct submit_ctx *sctx, const char *msg);
474 void rtw_sctx_done_err(struct submit_ctx **sctx, int status);
475 void rtw_sctx_done(struct submit_ctx **sctx);
476
477 struct xmit_buf
478 {
479         _list   list;
480
481         _adapter *padapter;
482
483         u8 *pallocated_buf;
484
485         u8 *pbuf;
486
487         void *priv_data;
488
489         u16 buf_tag; // 0: Normal xmitbuf, 1: extension xmitbuf, 2:cmd xmitbuf
490         u16 flags;
491         u32 alloc_sz;
492
493         u32  len;
494
495         struct submit_ctx *sctx;
496
497 #ifdef CONFIG_USB_HCI
498
499         //u32 sz[8];
500         u32     ff_hwaddr;
501
502 #if defined(PLATFORM_OS_XP)||defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
503         PURB    pxmit_urb[8];
504         dma_addr_t dma_transfer_addr;   /* (in) dma addr for transfer_buffer */
505 #endif
506
507 #ifdef PLATFORM_OS_XP
508         PIRP            pxmit_irp[8];
509 #endif
510
511 #ifdef PLATFORM_OS_CE
512         USB_TRANSFER    usb_transfer_write_port;
513 #endif
514
515         u8 bpending[8];
516
517         sint last[8];
518
519 #endif
520
521 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
522         u8 *phead;
523         u8 *pdata;
524         u8 *ptail;
525         u8 *pend;
526         u32 ff_hwaddr;
527         u8      pg_num; 
528         u8      agg_num;
529 #ifdef PLATFORM_OS_XP
530         PMDL pxmitbuf_mdl;
531         PIRP  pxmitbuf_irp;
532         PSDBUS_REQUEST_PACKET pxmitbuf_sdrp;
533 #endif
534 #endif
535
536 #ifdef CONFIG_PCI_HCI
537         struct tx_desc *desc;
538 #endif
539
540 #if defined(DBG_XMIT_BUF )|| defined(DBG_XMIT_BUF_EXT)
541         u8 no;
542 #endif
543
544 };
545
546
547 struct xmit_frame
548 {
549         _list   list;
550
551         struct pkt_attrib attrib;
552
553         _pkt *pkt;
554
555         int     frame_tag;
556
557         _adapter *padapter;
558
559         u8      *buf_addr;
560
561         struct xmit_buf *pxmitbuf;
562
563 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
564         u8      pg_num;
565         u8      agg_num;
566 #endif
567
568 #ifdef CONFIG_USB_HCI
569 #ifdef CONFIG_USB_TX_AGGREGATION
570         u8      agg_num;
571 #endif
572         s8      pkt_offset;
573 #endif
574
575 #ifdef CONFIG_XMIT_ACK
576         u8 ack_report;
577 #endif
578
579         u8 *alloc_addr; /* the actual address this xmitframe allocated */
580         u8 ext_tag; /* 0:data, 1:mgmt */
581
582 };
583
584 struct tx_servq {
585         _list   tx_pending;
586         _queue  sta_pending;
587         int qcnt;
588 };
589
590
591 struct sta_xmit_priv
592 {
593         _lock   lock;
594         sint    option;
595         sint    apsd_setting;   //When bit mask is on, the associated edca queue supports APSD.
596
597
598         //struct tx_servq blk_q[MAX_NUMBLKS];
599         struct tx_servq be_q;                   //priority == 0,3
600         struct tx_servq bk_q;                   //priority == 1,2
601         struct tx_servq vi_q;                   //priority == 4,5
602         struct tx_servq vo_q;                   //priority == 6,7
603         _list   legacy_dz;
604         _list  apsd;
605
606         u16 txseq_tid[16];
607
608         //uint  sta_tx_bytes;
609         //u64   sta_tx_pkts;
610         //uint  sta_tx_fail;
611
612
613 };
614
615
616 struct  hw_txqueue      {
617         volatile sint   head;
618         volatile sint   tail;
619         volatile sint   free_sz;        //in units of 64 bytes
620         volatile sint      free_cmdsz;
621         volatile sint    txsz[8];
622         uint    ff_hwaddr;
623         uint    cmd_hwaddr;
624         sint    ac_tag;
625 };
626
627 struct agg_pkt_info{
628         u16 offset;
629         u16 pkt_len;
630 };
631
632 enum cmdbuf_type {
633         CMDBUF_BEACON = 0x00,
634         CMDBUF_RSVD,
635         CMDBUF_MAX
636 };
637
638 u8 rtw_get_hwseq_no(_adapter *padapter);
639
640 struct  xmit_priv       {
641
642         _lock   lock;
643
644         _sema   xmit_sema;
645         _sema   terminate_xmitthread_sema;
646
647         //_queue        blk_strms[MAX_NUMBLKS];
648         _queue  be_pending;
649         _queue  bk_pending;
650         _queue  vi_pending;
651         _queue  vo_pending;
652         _queue  bm_pending;
653
654         //_queue        legacy_dz_queue;
655         //_queue        apsd_queue;
656
657         u8 *pallocated_frame_buf;
658         u8 *pxmit_frame_buf;
659         uint free_xmitframe_cnt;
660         _queue  free_xmit_queue;
661
662         //uint mapping_addr;
663         //uint pkt_sz;
664
665         u8 *xframe_ext_alloc_addr;
666         u8 *xframe_ext;
667         uint free_xframe_ext_cnt;
668         _queue free_xframe_ext_queue;
669
670         //struct        hw_txqueue      be_txqueue;
671         //struct        hw_txqueue      bk_txqueue;
672         //struct        hw_txqueue      vi_txqueue;
673         //struct        hw_txqueue      vo_txqueue;
674         //struct        hw_txqueue      bmc_txqueue;
675
676         uint    frag_len;
677
678         _adapter        *adapter;
679
680         u8   vcs_setting;
681         u8      vcs;
682         u8      vcs_type;
683         //u16  rts_thresh;
684
685         u64     tx_bytes;
686         u64     tx_pkts;
687         u64     tx_drop;
688         u64     last_tx_pkts;
689
690         struct hw_xmit *hwxmits;
691         u8      hwxmit_entry;
692
693         u8      wmm_para_seq[4];//sequence for wmm ac parameter strength from large to small. it's value is 0->vo, 1->vi, 2->be, 3->bk.
694
695 #ifdef CONFIG_USB_HCI
696         _sema   tx_retevt;//all tx return event;
697         u8              txirp_cnt;//
698
699 #ifdef PLATFORM_OS_CE
700         USB_TRANSFER    usb_transfer_write_port;
701 //      USB_TRANSFER    usb_transfer_write_mem;
702 #endif
703 #ifdef PLATFORM_LINUX
704         struct tasklet_struct xmit_tasklet;
705 #endif
706 #ifdef PLATFORM_FREEBSD
707         struct task xmit_tasklet;
708 #endif
709         //per AC pending irp
710         int beq_cnt;
711         int bkq_cnt;
712         int viq_cnt;
713         int voq_cnt;
714
715 #endif
716
717 #ifdef CONFIG_PCI_HCI
718         // Tx
719         struct rtw_tx_ring      tx_ring[PCI_MAX_TX_QUEUE_COUNT];
720         int     txringcount[PCI_MAX_TX_QUEUE_COUNT];
721         u8      beaconDMAing;           //flag of indicating beacon is transmiting to HW by DMA
722 #ifdef PLATFORM_LINUX
723         struct tasklet_struct xmit_tasklet;
724 #endif
725 #endif
726
727 #if defined (CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
728 #ifdef CONFIG_SDIO_TX_TASKLET
729         #ifdef PLATFORM_LINUX
730         struct tasklet_struct xmit_tasklet;
731         #endif /* PLATFORM_LINUX */
732 #else
733         _thread_hdl_    SdioXmitThread;
734         _sema           SdioXmitSema;
735         _sema           SdioXmitTerminateSema;
736 #endif /* CONFIG_SDIO_TX_TASKLET */
737 #endif /* CONFIG_SDIO_HCI */
738
739         _queue free_xmitbuf_queue;
740         _queue pending_xmitbuf_queue;
741         u8 *pallocated_xmitbuf;
742         u8 *pxmitbuf;
743         uint free_xmitbuf_cnt;
744
745         _queue free_xmit_extbuf_queue;
746         u8 *pallocated_xmit_extbuf;
747         u8 *pxmit_extbuf;
748         uint free_xmit_extbuf_cnt;
749
750         struct xmit_buf pcmd_xmitbuf[CMDBUF_MAX];
751         u8   hw_ssn_seq_no;//mapping to REG_HW_SEQ 0,1,2,3
752         u16     nqos_ssn;
753         #ifdef CONFIG_TX_EARLY_MODE
754
755         #ifdef CONFIG_SDIO_HCI
756         #define MAX_AGG_PKT_NUM 20      
757         #else
758         #define MAX_AGG_PKT_NUM 256 //Max tx ampdu coounts              
759         #endif
760         
761         struct agg_pkt_info agg_pkt[MAX_AGG_PKT_NUM];
762         #endif
763
764 #ifdef CONFIG_XMIT_ACK
765         int     ack_tx;
766         _mutex ack_tx_mutex;
767         struct submit_ctx ack_tx_ops;
768         u8 seq_no;
769 #endif
770         _lock lock_sctx;
771 };
772
773 extern struct xmit_frame *__rtw_alloc_cmdxmitframe(struct xmit_priv *pxmitpriv,
774                 enum cmdbuf_type buf_type);
775 #define rtw_alloc_cmdxmitframe(p) __rtw_alloc_cmdxmitframe(p, CMDBUF_RSVD)
776 #if defined(CONFIG_RTL8192E) && defined(CONFIG_PCI_HCI) 
777 extern struct xmit_frame *__rtw_alloc_cmdxmitframe_8192ee(struct xmit_priv *pxmitpriv,
778                 enum cmdbuf_type buf_type);
779 #define rtw_alloc_bcnxmitframe(p) __rtw_alloc_cmdxmitframe_8192ee(p, CMDBUF_BEACON)
780 #else
781 #define rtw_alloc_bcnxmitframe(p) __rtw_alloc_cmdxmitframe(p, CMDBUF_BEACON)
782 #endif
783
784 extern struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv);
785 extern s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf);
786
787 extern struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv);
788 extern s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf);
789
790 void rtw_count_tx_stats(_adapter *padapter, struct xmit_frame *pxmitframe, int sz);
791 extern void rtw_update_protection(_adapter *padapter, u8 *ie, uint ie_len);
792 static s32 update_attrib_sec_info(_adapter *padapter, struct pkt_attrib *pattrib, struct sta_info *psta);
793 static void update_attrib_phy_info(_adapter *padapter, struct pkt_attrib *pattrib, struct sta_info *psta);
794 extern s32 rtw_make_wlanhdr(_adapter *padapter, u8 *hdr, struct pkt_attrib *pattrib);
795 extern s32 rtw_put_snap(u8 *data, u16 h_proto);
796
797 extern struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv);
798 struct xmit_frame *rtw_alloc_xmitframe_ext(struct xmit_priv *pxmitpriv);
799 struct xmit_frame *rtw_alloc_xmitframe_once(struct xmit_priv *pxmitpriv);
800 extern s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe);
801 extern void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, _queue *pframequeue);
802 struct tx_servq *rtw_get_sta_pending(_adapter *padapter, struct sta_info *psta, sint up, u8 *ac);
803 extern s32 rtw_xmitframe_enqueue(_adapter *padapter, struct xmit_frame *pxmitframe);
804 extern struct xmit_frame* rtw_dequeue_xframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit_i, sint entry);
805
806 extern s32 rtw_xmit_classifier(_adapter *padapter, struct xmit_frame *pxmitframe);
807 extern u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib);
808 #define rtw_wlan_pkt_size(f) rtw_calculate_wlan_pkt_size_by_attribue(&f->attrib)
809 extern s32 rtw_xmitframe_coalesce(_adapter *padapter, _pkt *pkt, struct xmit_frame *pxmitframe);
810 #ifdef CONFIG_IEEE80211W
811 extern s32 rtw_mgmt_xmitframe_coalesce(_adapter *padapter, _pkt *pkt, struct xmit_frame *pxmitframe);
812 #endif //CONFIG_IEEE80211W
813 #ifdef CONFIG_TDLS
814 extern struct tdls_txmgmt *ptxmgmt;
815 s32 rtw_xmit_tdls_coalesce(_adapter *padapter, struct xmit_frame *pxmitframe, struct tdls_txmgmt *ptxmgmt);
816 s32 update_tdls_attrib(_adapter *padapter, struct pkt_attrib *pattrib);
817 #endif
818 s32 _rtw_init_hw_txqueue(struct hw_txqueue* phw_txqueue, u8 ac_tag);
819 void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv);
820
821
822 s32 rtw_txframes_pending(_adapter *padapter);
823 s32 rtw_txframes_sta_ac_pending(_adapter *padapter, struct pkt_attrib *pattrib);
824 void rtw_init_hwxmits(struct hw_xmit *phwxmit, sint entry);
825
826
827 s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, _adapter *padapter);
828 void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv);
829
830
831 void rtw_alloc_hwxmits(_adapter *padapter);
832 void rtw_free_hwxmits(_adapter *padapter);
833
834
835 s32 rtw_xmit(_adapter *padapter, _pkt **pkt);
836 bool xmitframe_hiq_filter(struct xmit_frame *xmitframe);
837 #if defined(CONFIG_AP_MODE) || defined(CONFIG_TDLS)
838 sint xmitframe_enqueue_for_sleeping_sta(_adapter *padapter, struct xmit_frame *pxmitframe);
839 void stop_sta_xmit(_adapter *padapter, struct sta_info *psta);
840 void wakeup_sta_to_xmit(_adapter *padapter, struct sta_info *psta);
841 void xmit_delivery_enabled_frames(_adapter *padapter, struct sta_info *psta);
842 #endif
843
844 u8      query_ra_short_GI(struct sta_info *psta);
845
846 u8      qos_acm(u8 acm_mask, u8 priority);
847
848 #ifdef CONFIG_XMIT_THREAD_MODE
849 void    enqueue_pending_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf);
850 void enqueue_pending_xmitbuf_to_head(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf);
851 struct xmit_buf*        dequeue_pending_xmitbuf(struct xmit_priv *pxmitpriv);
852 struct xmit_buf*        dequeue_pending_xmitbuf_under_survey(struct xmit_priv *pxmitpriv);
853 sint    check_pending_xmitbuf(struct xmit_priv *pxmitpriv);
854 thread_return   rtw_xmit_thread(thread_context context);
855 #endif
856
857 static void do_queue_select(_adapter * padapter, struct pkt_attrib * pattrib);
858 u32     rtw_get_ff_hwaddr(struct xmit_frame     *pxmitframe);
859
860 #ifdef CONFIG_XMIT_ACK
861 int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms);
862 void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status);
863 #endif //CONFIG_XMIT_ACK
864
865
866 //include after declaring struct xmit_buf, in order to avoid warning
867 #include <xmit_osdep.h>
868
869 #endif  //_RTL871X_XMIT_H_
870