GNU Linux-libre 4.9.297-gnu1
[releases.git] / drivers / staging / rtl8188eu / 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  ******************************************************************************/
15 #ifndef _RTW_XMIT_H_
16 #define _RTW_XMIT_H_
17
18 #include <osdep_service.h>
19 #include <drv_types.h>
20
21 #define MAX_XMITBUF_SZ  (20480) /*  20k */
22 #define NR_XMITBUFF             (4)
23
24 #define XMITBUF_ALIGN_SZ        4
25
26 /*  xmit extension buff defination */
27 #define MAX_XMIT_EXTBUF_SZ      (1536)
28 #define NR_XMIT_EXTBUFF         (32)
29
30 #define MAX_NUMBLKS             (1)
31
32 #define XMIT_VO_QUEUE           (0)
33 #define XMIT_VI_QUEUE           (1)
34 #define XMIT_BE_QUEUE           (2)
35 #define XMIT_BK_QUEUE           (3)
36
37 #define VO_QUEUE_INX            0
38 #define VI_QUEUE_INX            1
39 #define BE_QUEUE_INX            2
40 #define BK_QUEUE_INX            3
41 #define BCN_QUEUE_INX           4
42 #define MGT_QUEUE_INX           5
43 #define HIGH_QUEUE_INX          6
44 #define TXCMD_QUEUE_INX         7
45
46 #define HW_QUEUE_ENTRY          8
47
48 #define WEP_IV(pattrib_iv, dot11txpn, keyidx)\
49 do {\
50         pattrib_iv[0] = dot11txpn._byte_.TSC0;\
51         pattrib_iv[1] = dot11txpn._byte_.TSC1;\
52         pattrib_iv[2] = dot11txpn._byte_.TSC2;\
53         pattrib_iv[3] = ((keyidx & 0x3)<<6);\
54         dot11txpn.val = (dot11txpn.val == 0xffffff) ? 0 : (dot11txpn.val+1);\
55 } while (0)
56
57
58 #define TKIP_IV(pattrib_iv, dot11txpn, keyidx)\
59 do {\
60         pattrib_iv[0] = dot11txpn._byte_.TSC1;\
61         pattrib_iv[1] = (dot11txpn._byte_.TSC1 | 0x20) & 0x7f;\
62         pattrib_iv[2] = dot11txpn._byte_.TSC0;\
63         pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\
64         pattrib_iv[4] = dot11txpn._byte_.TSC2;\
65         pattrib_iv[5] = dot11txpn._byte_.TSC3;\
66         pattrib_iv[6] = dot11txpn._byte_.TSC4;\
67         pattrib_iv[7] = dot11txpn._byte_.TSC5;\
68         dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0 : (dot11txpn.val+1);\
69 } while (0)
70
71 #define AES_IV(pattrib_iv, dot11txpn, keyidx)\
72 do {                                                    \
73         pattrib_iv[0] = dot11txpn._byte_.TSC0;          \
74         pattrib_iv[1] = dot11txpn._byte_.TSC1;          \
75         pattrib_iv[2] = 0;                              \
76         pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);   \
77         pattrib_iv[4] = dot11txpn._byte_.TSC2;          \
78         pattrib_iv[5] = dot11txpn._byte_.TSC3;          \
79         pattrib_iv[6] = dot11txpn._byte_.TSC4;          \
80         pattrib_iv[7] = dot11txpn._byte_.TSC5;          \
81         dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0 : (dot11txpn.val+1);\
82 } while (0)
83
84 #define HWXMIT_ENTRY    4
85
86 #define TXDESC_SIZE 32
87
88 #define PACKET_OFFSET_SZ (8)
89 #define TXDESC_OFFSET (TXDESC_SIZE + PACKET_OFFSET_SZ)
90
91 struct tx_desc {
92         /* DWORD 0 */
93         __le32 txdw0;
94         __le32 txdw1;
95         __le32 txdw2;
96         __le32 txdw3;
97         __le32 txdw4;
98         __le32 txdw5;
99         __le32 txdw6;
100         __le32 txdw7;
101 };
102
103 struct  hw_xmit {
104         struct __queue *sta_queue;
105         int     accnt;
106 };
107
108 /* reduce size */
109 struct pkt_attrib {
110         u8      type;
111         u8      subtype;
112         u8      bswenc;
113         u8      dhcp_pkt;
114         u16     ether_type;
115         u16     seqnum;
116         u16     hdrlen;         /* the WLAN Header Len */
117         u32     pktlen;         /* the original 802.3 pkt raw_data len (not include
118                                  * ether_hdr data) */
119         u32     last_txcmdsz;
120         u8      nr_frags;
121         u8      encrypt;        /* when 0 indicate no encrypt. when non-zero,
122                                  * indicate the encrypt algorith */
123         u8      iv_len;
124         u8      icv_len;
125         u8      iv[18];
126         u8      icv[16];
127         u8      priority;
128         u8      ack_policy;
129         u8      mac_id;
130         u8      vcs_mode;       /* virtual carrier sense method */
131         u8      dst[ETH_ALEN];
132         u8      src[ETH_ALEN];
133         u8      ta[ETH_ALEN];
134         u8      ra[ETH_ALEN];
135         u8      key_idx;
136         u8      qos_en;
137         u8      ht_en;
138         u8      raid;/* rate adpative id */
139         u8      bwmode;
140         u8      ch_offset;/* PRIME_CHNL_OFFSET */
141         u8      sgi;/* short GI */
142         u8      ampdu_en;/* tx ampdu enable */
143         u8      mdata;/* more data bit */
144         u8      pctrl;/* per packet txdesc control enable */
145         u8      triggered;/* for ap mode handling Power Saving sta */
146         u8      qsel;
147         u8      eosp;
148         u8      rate;
149         u8      intel_proxim;
150         u8      retry_ctrl;
151         struct sta_info *psta;
152 };
153
154 #define WLANHDR_OFFSET  64
155
156 #define NULL_FRAMETAG           (0x0)
157 #define DATA_FRAMETAG           0x01
158 #define L2_FRAMETAG             0x02
159 #define MGNT_FRAMETAG           0x03
160 #define AMSDU_FRAMETAG  0x04
161
162 #define EII_FRAMETAG            0x05
163 #define IEEE8023_FRAMETAG  0x06
164
165 #define MP_FRAMETAG             0x07
166
167 #define TXAGG_FRAMETAG  0x08
168
169 struct  submit_ctx {
170         u32 submit_time; /* */
171         u32 timeout_ms; /* <0: not synchronous, 0: wait forever, >0: up to ms waiting */
172         int status; /* status for operation */
173         struct completion done;
174 };
175
176 enum {
177         RTW_SCTX_SUBMITTED = -1,
178         RTW_SCTX_DONE_SUCCESS = 0,
179         RTW_SCTX_DONE_UNKNOWN,
180         RTW_SCTX_DONE_TIMEOUT,
181         RTW_SCTX_DONE_BUF_ALLOC,
182         RTW_SCTX_DONE_BUF_FREE,
183         RTW_SCTX_DONE_WRITE_PORT_ERR,
184         RTW_SCTX_DONE_TX_DESC_NA,
185         RTW_SCTX_DONE_TX_DENY,
186         RTW_SCTX_DONE_CCX_PKT_FAIL,
187         RTW_SCTX_DONE_DRV_STOP,
188         RTW_SCTX_DONE_DEV_REMOVE,
189 };
190
191 void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms);
192 int rtw_sctx_wait(struct submit_ctx *sctx);
193 void rtw_sctx_done_err(struct submit_ctx **sctx, int status);
194
195 struct xmit_buf {
196         struct list_head list;
197         struct adapter *padapter;
198         u8 *pallocated_buf;
199         u8 *pbuf;
200         void *priv_data;
201         u16 ext_tag; /*  0: Normal xmitbuf, 1: extension xmitbuf. */
202         u16 flags;
203         u32 alloc_sz;
204         u32  len;
205         struct submit_ctx *sctx;
206         u32     ff_hwaddr;
207         struct urb *pxmit_urb[8];
208         dma_addr_t dma_transfer_addr;   /* (in) dma addr for transfer_buffer */
209         u8 bpending[8];
210         int last[8];
211 };
212
213 struct xmit_frame {
214         struct list_head list;
215         struct pkt_attrib attrib;
216         struct sk_buff *pkt;
217         int     frame_tag;
218         struct adapter *padapter;
219         u8      *buf_addr;
220         struct xmit_buf *pxmitbuf;
221
222         u8      agg_num;
223         s8      pkt_offset;
224         u8 ack_report;
225 };
226
227 struct tx_servq {
228         struct list_head tx_pending;
229         struct __queue sta_pending;
230         int qcnt;
231 };
232
233 struct sta_xmit_priv {
234         spinlock_t lock;
235         int     option;
236         int     apsd_setting;   /* When bit mask is on, the associated edca
237                                  * queue supports APSD. */
238         struct tx_servq be_q;                   /* priority == 0,3 */
239         struct tx_servq bk_q;                   /* priority == 1,2 */
240         struct tx_servq vi_q;                   /* priority == 4,5 */
241         struct tx_servq vo_q;                   /* priority == 6,7 */
242         struct list_head legacy_dz;
243         struct list_head apsd;
244         u16 txseq_tid[16];
245 };
246
247 struct  hw_txqueue {
248         volatile int    head;
249         volatile int    tail;
250         volatile int    free_sz;        /* in units of 64 bytes */
251         volatile int      free_cmdsz;
252         volatile int     txsz[8];
253         uint    ff_hwaddr;
254         uint    cmd_hwaddr;
255         int     ac_tag;
256 };
257
258 struct  xmit_priv {
259         spinlock_t lock;
260         struct __queue be_pending;
261         struct __queue bk_pending;
262         struct __queue vi_pending;
263         struct __queue vo_pending;
264         struct __queue bm_pending;
265         u8 *pallocated_frame_buf;
266         u8 *pxmit_frame_buf;
267         uint free_xmitframe_cnt;
268         struct __queue free_xmit_queue;
269         uint    frag_len;
270         struct adapter  *adapter;
271         u8   vcs_setting;
272         u8      vcs;
273         u8      vcs_type;
274         u64     tx_bytes;
275         u64     tx_pkts;
276         u64     tx_drop;
277         u64     last_tx_bytes;
278         u64     last_tx_pkts;
279         struct hw_xmit *hwxmits;
280         u8      hwxmit_entry;
281         u8      wmm_para_seq[4];/* sequence for wmm ac parameter strength
282                                  * from large to small. it's value is 0->vo,
283                                  * 1->vi, 2->be, 3->bk. */
284         u8              txirp_cnt;/*  */
285         struct tasklet_struct xmit_tasklet;
286         /* per AC pending irp */
287         int beq_cnt;
288         int bkq_cnt;
289         int viq_cnt;
290         int voq_cnt;
291         struct __queue free_xmitbuf_queue;
292         struct __queue pending_xmitbuf_queue;
293         u8 *pallocated_xmitbuf;
294         u8 *pxmitbuf;
295         uint free_xmitbuf_cnt;
296         struct __queue free_xmit_extbuf_queue;
297         u8 *pallocated_xmit_extbuf;
298         u8 *pxmit_extbuf;
299         uint free_xmit_extbuf_cnt;
300         u16     nqos_ssn;
301         int     ack_tx;
302         struct mutex ack_tx_mutex;
303         struct submit_ctx ack_tx_ops;
304 };
305
306 struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv);
307 s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv,
308                          struct xmit_buf *pxmitbuf);
309 struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv);
310 s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv,
311                      struct xmit_buf *pxmitbuf);
312 void rtw_count_tx_stats(struct adapter *padapter,
313                         struct xmit_frame *pxmitframe, int sz);
314 void rtw_update_protection(struct adapter *padapter, u8 *ie, uint ie_len);
315 s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr,
316                      struct pkt_attrib *pattrib);
317 s32 rtw_put_snap(u8 *data, u16 h_proto);
318
319 struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv);
320 s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv,
321                        struct xmit_frame *pxmitframe);
322 void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv,
323                               struct __queue *pframequeue);
324 struct tx_servq *rtw_get_sta_pending(struct adapter *padapter,
325                                      struct sta_info *psta, int up, u8 *ac);
326 s32 rtw_xmitframe_enqueue(struct adapter *padapter,
327                           struct xmit_frame *pxmitframe);
328 struct xmit_frame *rtw_dequeue_xframe(struct xmit_priv *pxmitpriv,
329                                       struct hw_xmit *phwxmit_i, int entry);
330
331 s32 rtw_xmit_classifier(struct adapter *padapter,
332                         struct xmit_frame *pxmitframe);
333 u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib);
334 #define rtw_wlan_pkt_size(f) rtw_calculate_wlan_pkt_size_by_attribue(&f->attrib)
335 s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt,
336                            struct xmit_frame *pxmitframe);
337 s32 _rtw_init_hw_txqueue(struct hw_txqueue *phw_txqueue, u8 ac_tag);
338 void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv);
339 s32 rtw_txframes_pending(struct adapter *padapter);
340 s32 rtw_txframes_sta_ac_pending(struct adapter *padapter,
341                                 struct pkt_attrib *pattrib);
342 void rtw_init_hwxmits(struct hw_xmit *phwxmit, int entry);
343 s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter);
344 void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv);
345 void rtw_alloc_hwxmits(struct adapter *padapter);
346 void rtw_free_hwxmits(struct adapter *padapter);
347 s32 rtw_xmit(struct adapter *padapter, struct sk_buff **pkt);
348
349 #if defined(CONFIG_88EU_AP_MODE)
350 int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_frame *pxmitframe);
351 void stop_sta_xmit(struct adapter *padapter, struct sta_info *psta);
352 void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta);
353 void xmit_delivery_enabled_frames(struct adapter *padapter, struct sta_info *psta);
354 #endif
355
356 u8      qos_acm(u8 acm_mask, u8 priority);
357 u32     rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe);
358 int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms);
359 void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status);
360
361 /* include after declaring struct xmit_buf, in order to avoid warning */
362 #include <xmit_osdep.h>
363
364 #endif  /* _RTL871X_XMIT_H_ */