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