OSDN Git Service

4ee4bf05d43eedb9e364476062554607abc3640c
[android-x86/external-modules-rtl8723au.git] / 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 #include <drv_conf.h>
24 #include <osdep_service.h>
25 #include <drv_types.h>
26
27 #ifdef CONFIG_USB_TX_AGGREGATION
28 #define MAX_XMITBUF_SZ  (20480) // 20k
29 #else
30 #define MAX_XMITBUF_SZ  (2048)
31 #endif
32 #ifdef CONFIG_SINGLE_XMIT_BUF
33 #define NR_XMITBUFF     (1)
34 #else
35 #define NR_XMITBUFF     (4)
36 #endif //CONFIG_SINGLE_XMIT_BUF
37
38 #define XMITBUF_ALIGN_SZ 512
39
40 // xmit extension buff defination
41 #define MAX_XMIT_EXTBUF_SZ      (1536)
42 #define NR_XMIT_EXTBUFF (32)
43
44 #define MAX_NUMBLKS             (1)
45
46 #define XMIT_VO_QUEUE (0)
47 #define XMIT_VI_QUEUE (1)
48 #define XMIT_BE_QUEUE (2)
49 #define XMIT_BK_QUEUE (3)
50
51 #define VO_QUEUE_INX            0
52 #define VI_QUEUE_INX            1
53 #define BE_QUEUE_INX            2
54 #define BK_QUEUE_INX            3
55 #define BCN_QUEUE_INX           4
56 #define MGT_QUEUE_INX           5
57 #define HIGH_QUEUE_INX          6
58 #define TXCMD_QUEUE_INX 7
59
60 #define HW_QUEUE_ENTRY  8
61
62 #define WEP_IV(pattrib_iv, dot11txpn, keyidx)\
63 do{\
64         pattrib_iv[0] = dot11txpn._byte_.TSC0;\
65         pattrib_iv[1] = dot11txpn._byte_.TSC1;\
66         pattrib_iv[2] = dot11txpn._byte_.TSC2;\
67         pattrib_iv[3] = ((keyidx & 0x3)<<6);\
68         dot11txpn.val = (dot11txpn.val == 0xffffff) ? 0: (dot11txpn.val+1);\
69 }while(0)
70
71
72 #define TKIP_IV(pattrib_iv, dot11txpn, keyidx)\
73 do{\
74         pattrib_iv[0] = dot11txpn._byte_.TSC1;\
75         pattrib_iv[1] = (dot11txpn._byte_.TSC1 | 0x20) & 0x7f;\
76         pattrib_iv[2] = dot11txpn._byte_.TSC0;\
77         pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\
78         pattrib_iv[4] = dot11txpn._byte_.TSC2;\
79         pattrib_iv[5] = dot11txpn._byte_.TSC3;\
80         pattrib_iv[6] = dot11txpn._byte_.TSC4;\
81         pattrib_iv[7] = dot11txpn._byte_.TSC5;\
82         dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0: (dot11txpn.val+1);\
83 }while(0)
84
85 #define AES_IV(pattrib_iv, dot11txpn, keyidx)\
86 do{\
87         pattrib_iv[0] = dot11txpn._byte_.TSC0;\
88         pattrib_iv[1] = dot11txpn._byte_.TSC1;\
89         pattrib_iv[2] = 0;\
90         pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\
91         pattrib_iv[4] = dot11txpn._byte_.TSC2;\
92         pattrib_iv[5] = dot11txpn._byte_.TSC3;\
93         pattrib_iv[6] = dot11txpn._byte_.TSC4;\
94         pattrib_iv[7] = dot11txpn._byte_.TSC5;\
95         dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0: (dot11txpn.val+1);\
96 }while(0)
97
98
99 #define HWXMIT_ENTRY    4
100
101
102 #define TXDESC_SIZE 32
103
104 #ifdef CONFIG_TX_EARLY_MODE
105 #define EARLY_MODE_INFO_SIZE    8
106 #endif
107
108
109 #define PACKET_OFFSET_SZ (8)
110 #define TXDESC_OFFSET (TXDESC_SIZE + PACKET_OFFSET_SZ)
111
112 struct tx_desc{
113
114         //DWORD 0
115         unsigned int txdw0;
116
117         unsigned int txdw1;
118
119         unsigned int txdw2;
120
121         unsigned int txdw3;
122
123         unsigned int txdw4;
124
125         unsigned int txdw5;
126
127         unsigned int txdw6;
128
129         unsigned int txdw7;
130 };
131
132
133 union txdesc {
134         struct tx_desc txdesc;
135         unsigned int value[TXDESC_SIZE>>2];
136 };
137
138 struct  hw_xmit {
139         //spinlock_t xmit_lock;
140         //struct list_head      pending;
141         _queue *sta_queue;
142         //struct hw_txqueue *phwtxqueue;
143         //int   txcmdcnt;
144         int     accnt;
145 };
146
147 //reduce size
148 struct pkt_attrib
149 {
150         u8      type;
151         u8      subtype;
152         u8      bswenc;
153         u8      dhcp_pkt;
154         u16     ether_type;
155         u16     seqnum;
156         u16     pkt_hdrlen;     //the original 802.3 pkt header len
157         u16     hdrlen;         //the WLAN Header Len
158         u32     pktlen;         //the original 802.3 pkt raw_data len (not include ether_hdr data)
159         u32     last_txcmdsz;
160         u8      nr_frags;
161         u8      encrypt;        //when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith
162         u8      iv_len;
163         u8      icv_len;
164         u8      iv[18];
165         u8      icv[16];
166         u8      priority;
167         u8      ack_policy;
168         u8      mac_id;
169         u8      vcs_mode;       //virtual carrier sense method
170         u8      dst[ETH_ALEN];
171         u8      src[ETH_ALEN];
172         u8      ta[ETH_ALEN];
173         u8      ra[ETH_ALEN];
174         u8      key_idx;
175         u8      qos_en;
176         u8      ht_en;
177         u8      raid;//rate adpative id
178         u8      bwmode;
179         u8      ch_offset;//PRIME_CHNL_OFFSET
180         u8      sgi;//short GI
181         u8      ampdu_en;//tx ampdu enable
182         u8      mdata;//more data bit
183         u8      pctrl;//per packet txdesc control enable
184         u8      triggered;//for ap mode handling Power Saving sta
185         u8      qsel;
186         u8      eosp;
187         u8      rate;
188         u8      intel_proxim;
189         u8      retry_ctrl;
190         struct sta_info * psta;
191 #ifdef CONFIG_TCP_CSUM_OFFLOAD_TX
192         u8      hw_tcp_csum;
193 #endif
194 };
195
196 #define WLANHDR_OFFSET  64
197
198 #define NULL_FRAMETAG           (0x0)
199 #define DATA_FRAMETAG           0x01
200 #define L2_FRAMETAG             0x02
201 #define MGNT_FRAMETAG           0x03
202 #define AMSDU_FRAMETAG  0x04
203
204 #define EII_FRAMETAG            0x05
205 #define IEEE8023_FRAMETAG  0x06
206
207 #define MP_FRAMETAG             0x07
208
209 #define TXAGG_FRAMETAG  0x08
210
211 struct  submit_ctx{
212         u32 submit_time; /* */
213         u32 timeout_ms; /* <0: not synchronous, 0: wait forever, >0: up to ms waiting */
214         int status; /* status for operation */
215         struct completion done;
216 };
217
218 enum {
219         RTW_SCTX_SUBMITTED = -1,
220         RTW_SCTX_DONE_SUCCESS = 0,
221         RTW_SCTX_DONE_UNKNOWN,
222         RTW_SCTX_DONE_TIMEOUT,
223         RTW_SCTX_DONE_BUF_ALLOC,
224         RTW_SCTX_DONE_BUF_FREE,
225         RTW_SCTX_DONE_WRITE_PORT_ERR,
226         RTW_SCTX_DONE_TX_DESC_NA,
227         RTW_SCTX_DONE_TX_DENY,
228         RTW_SCTX_DONE_CCX_PKT_FAIL,
229         RTW_SCTX_DONE_DRV_STOP,
230         RTW_SCTX_DONE_DEV_REMOVE,
231 };
232
233
234 void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms);
235 int rtw_sctx_wait(struct submit_ctx *sctx);
236 void rtw_sctx_done_err(struct submit_ctx **sctx, int status);
237 void rtw_sctx_done(struct submit_ctx **sctx);
238
239 struct xmit_buf
240 {
241         struct list_head        list;
242
243         _adapter *padapter;
244
245         u8 *pallocated_buf;
246
247         u8 *pbuf;
248
249         void *priv_data;
250
251         u16 ext_tag; // 0: Normal xmitbuf, 1: extension xmitbuf.
252         u16 flags;
253         u32 alloc_sz;
254         u32  len;
255         struct submit_ctx *sctx;
256         u32     ff_hwaddr;
257         struct urb *pxmit_urb[8];
258         dma_addr_t dma_transfer_addr;   /* (in) dma addr for transfer_buffer */
259         u8 bpending[8];
260         int last[8];
261 #if defined(DBG_XMIT_BUF )|| defined(DBG_XMIT_BUF_EXT)
262         u8 no;
263 #endif
264 };
265
266 struct xmit_frame
267 {
268         struct list_head        list;
269
270         struct pkt_attrib attrib;
271
272         _pkt *pkt;
273
274         int     frame_tag;
275
276         _adapter *padapter;
277
278         u8      *buf_addr;
279
280         struct xmit_buf *pxmitbuf;
281
282 #ifdef CONFIG_USB_TX_AGGREGATION
283         u8      agg_num;
284 #endif
285         s8      pkt_offset;
286 #ifdef CONFIG_RTL8192D
287         u8      EMPktNum;
288         u16     EMPktLen[5];//The max value by HW
289 #endif
290
291 #ifdef CONFIG_XMIT_ACK
292         u8 ack_report;
293 #endif
294
295         u8 *alloc_addr; /* the actual address this xmitframe allocated */
296         u8 ext_tag; /* 0:data, 1:mgmt */
297
298 };
299
300 struct tx_servq {
301         struct list_head        tx_pending;
302         _queue  sta_pending;
303         int qcnt;
304 };
305
306
307 struct sta_xmit_priv
308 {
309         spinlock_t      lock;
310         int     option;
311         int     apsd_setting;   //When bit mask is on, the associated edca queue supports APSD.
312
313
314         //struct tx_servq blk_q[MAX_NUMBLKS];
315         struct tx_servq be_q;                   //priority == 0,3
316         struct tx_servq bk_q;                   //priority == 1,2
317         struct tx_servq vi_q;                   //priority == 4,5
318         struct tx_servq vo_q;                   //priority == 6,7
319         struct list_head legacy_dz;
320         struct list_head apsd;
321
322         u16 txseq_tid[16];
323
324         //uint  sta_tx_bytes;
325         //u64   sta_tx_pkts;
326         //uint  sta_tx_fail;
327
328
329 };
330
331
332 struct  hw_txqueue      {
333         volatile int    head;
334         volatile int    tail;
335         volatile int    free_sz;        //in units of 64 bytes
336         volatile int      free_cmdsz;
337         volatile int     txsz[8];
338         uint    ff_hwaddr;
339         uint    cmd_hwaddr;
340         int     ac_tag;
341 };
342
343 struct agg_pkt_info{
344         u16 offset;
345         u16 pkt_len;
346 };
347
348 struct  xmit_priv       {
349
350         spinlock_t      lock;
351
352         struct semaphore        xmit_sema;
353         struct semaphore        terminate_xmitthread_sema;
354
355         //_queue        blk_strms[MAX_NUMBLKS];
356         _queue  be_pending;
357         _queue  bk_pending;
358         _queue  vi_pending;
359         _queue  vo_pending;
360         _queue  bm_pending;
361
362         //_queue        legacy_dz_queue;
363         //_queue        apsd_queue;
364
365         u8 *pallocated_frame_buf;
366         u8 *pxmit_frame_buf;
367         uint free_xmitframe_cnt;
368         _queue  free_xmit_queue;
369
370         //uint mapping_addr;
371         //uint pkt_sz;
372
373         u8 *xframe_ext_alloc_addr;
374         u8 *xframe_ext;
375         uint free_xframe_ext_cnt;
376         _queue free_xframe_ext_queue;
377
378         //struct        hw_txqueue      be_txqueue;
379         //struct        hw_txqueue      bk_txqueue;
380         //struct        hw_txqueue      vi_txqueue;
381         //struct        hw_txqueue      vo_txqueue;
382         //struct        hw_txqueue      bmc_txqueue;
383
384         uint    frag_len;
385
386         _adapter        *adapter;
387
388         u8   vcs_setting;
389         u8      vcs;
390         u8      vcs_type;
391         //u16  rts_thresh;
392
393         u64     tx_bytes;
394         u64     tx_pkts;
395         u64     tx_drop;
396         u64     last_tx_bytes;
397         u64     last_tx_pkts;
398
399         struct hw_xmit *hwxmits;
400         u8      hwxmit_entry;
401
402         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.
403
404         struct semaphore        tx_retevt;//all tx return event;
405         u8              txirp_cnt;//
406
407         struct tasklet_struct xmit_tasklet;
408         //per AC pending irp
409         int beq_cnt;
410         int bkq_cnt;
411         int viq_cnt;
412         int voq_cnt;
413
414         _queue free_xmitbuf_queue;
415         _queue pending_xmitbuf_queue;
416         u8 *pallocated_xmitbuf;
417         u8 *pxmitbuf;
418         uint free_xmitbuf_cnt;
419
420         _queue free_xmit_extbuf_queue;
421         u8 *pallocated_xmit_extbuf;
422         u8 *pxmit_extbuf;
423         uint free_xmit_extbuf_cnt;
424
425         u16     nqos_ssn;
426         #ifdef CONFIG_TX_EARLY_MODE
427
428         #define MAX_AGG_PKT_NUM 256 //Max tx ampdu coounts
429
430         struct agg_pkt_info agg_pkt[MAX_AGG_PKT_NUM];
431         #endif
432
433 #ifdef CONFIG_XMIT_ACK
434         int     ack_tx;
435         struct mutex ack_tx_mutex;
436         struct submit_ctx ack_tx_ops;
437 #endif
438         spinlock_t lock_sctx;
439 };
440
441 extern struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv);
442 extern s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf);
443
444 extern struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv);
445 extern s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf);
446
447 void rtw_count_tx_stats(_adapter *padapter, struct xmit_frame *pxmitframe, int sz);
448 extern void rtw_update_protection(_adapter *padapter, u8 *ie, uint ie_len);
449 extern s32 rtw_make_wlanhdr(_adapter *padapter, u8 *hdr, struct pkt_attrib *pattrib);
450 extern s32 rtw_put_snap(u8 *data, u16 h_proto);
451
452 extern struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv);
453 struct xmit_frame *rtw_alloc_xmitframe_ext(struct xmit_priv *pxmitpriv);
454 struct xmit_frame *rtw_alloc_xmitframe_once(struct xmit_priv *pxmitpriv);
455 extern s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe);
456 extern void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, _queue *pframequeue);
457 struct tx_servq *rtw_get_sta_pending(_adapter *padapter, struct sta_info *psta, int up, u8 *ac);
458 extern s32 rtw_xmitframe_enqueue(_adapter *padapter, struct xmit_frame *pxmitframe);
459 extern struct xmit_frame* rtw_dequeue_xframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit_i, int entry);
460
461 extern s32 rtw_xmit_classifier(_adapter *padapter, struct xmit_frame *pxmitframe);
462 extern u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib);
463 #define rtw_wlan_pkt_size(f) rtw_calculate_wlan_pkt_size_by_attribue(&f->attrib)
464 extern s32 rtw_xmitframe_coalesce(_adapter *padapter, _pkt *pkt, struct xmit_frame *pxmitframe);
465 #ifdef CONFIG_TDLS
466 s32 rtw_xmit_tdls_coalesce(_adapter *padapter, struct xmit_frame *pxmitframe, u8 action);
467 #endif
468 s32 _rtw_init_hw_txqueue(struct hw_txqueue* phw_txqueue, u8 ac_tag);
469 void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv);
470
471
472 s32 rtw_txframes_pending(_adapter *padapter);
473 s32 rtw_txframes_sta_ac_pending(_adapter *padapter, struct pkt_attrib *pattrib);
474 void rtw_init_hwxmits(struct hw_xmit *phwxmit, int entry);
475
476
477 s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, _adapter *padapter);
478 void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv);
479
480
481 void rtw_alloc_hwxmits(_adapter *padapter);
482 void rtw_free_hwxmits(_adapter *padapter);
483
484
485 s32 rtw_xmit(_adapter *padapter, _pkt **pkt);
486
487 #if defined(CONFIG_AP_MODE) || defined(CONFIG_TDLS)
488 int xmitframe_enqueue_for_sleeping_sta(_adapter *padapter, struct xmit_frame *pxmitframe);
489 void stop_sta_xmit(_adapter *padapter, struct sta_info *psta);
490 void wakeup_sta_to_xmit(_adapter *padapter, struct sta_info *psta);
491 void xmit_delivery_enabled_frames(_adapter *padapter, struct sta_info *psta);
492 #endif
493
494 u8      qos_acm(u8 acm_mask, u8 priority);
495
496 #ifdef CONFIG_XMIT_THREAD_MODE
497 void    enqueue_pending_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf);
498 struct xmit_buf*        dequeue_pending_xmitbuf(struct xmit_priv *pxmitpriv);
499 struct xmit_buf*        dequeue_pending_xmitbuf_under_survey(struct xmit_priv *pxmitpriv);
500 int     check_pending_xmitbuf(struct xmit_priv *pxmitpriv);
501 int     rtw_xmit_thread(void *context);
502 #endif
503
504 u32     rtw_get_ff_hwaddr(struct xmit_frame     *pxmitframe);
505
506 #ifdef CONFIG_XMIT_ACK
507 int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms);
508 void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status);
509 #endif //CONFIG_XMIT_ACK
510
511
512 //include after declaring struct xmit_buf, in order to avoid warning
513 #include <xmit_osdep.h>
514
515 #endif  //_RTL871X_XMIT_H_