staging: r8712u: Merging Realtek's latest (v2.6.6). Tx-code refactoring.
[pandora-kernel.git] / drivers / staging / rtl8712 / rtl871x_xmit.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2010 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  * Modifications for inclusion into the Linux staging tree are
19  * Copyright(c) 2010 Larry Finger. All rights reserved.
20  *
21  * Contact information:
22  * WLAN FAE <wlanfae@realtek.com>
23  * Larry Finger <Larry.Finger@lwfinger.net>
24  *
25  ******************************************************************************/
26 #ifndef _RTL871X_XMIT_H_
27 #define _RTL871X_XMIT_H_
28
29 #include "osdep_service.h"
30 #include "drv_types.h"
31 #include "xmit_osdep.h"
32
33 #define MAX_XMITBUF_SZ  (2048)
34 #define NR_XMITBUFF     (4)
35 #define XMITBUF_ALIGN_SZ 512
36 #define TX_GUARD_BAND           5
37 #define MAX_NUMBLKS             (1)
38
39 /* Fixed the Big Endian bug when using the software driver encryption.*/
40 #define WEP_IV(pattrib_iv, txpn, keyidx)\
41 do { \
42         pattrib_iv[0] = txpn._byte_.TSC0;\
43         pattrib_iv[1] = txpn._byte_.TSC1;\
44         pattrib_iv[2] = txpn._byte_.TSC2;\
45         pattrib_iv[3] = ((keyidx & 0x3)<<6);\
46         txpn.val = (txpn.val == 0xffffff) ? 0 : (txpn.val+1);\
47 } while (0)
48
49 /* Fixed the Big Endian bug when doing the Tx.
50  * The Linksys WRH54G will check this.*/
51 #define TKIP_IV(pattrib_iv, txpn, keyidx)\
52 do { \
53         pattrib_iv[0] = txpn._byte_.TSC1;\
54         pattrib_iv[1] = (txpn._byte_.TSC1 | 0x20) & 0x7f;\
55         pattrib_iv[2] = txpn._byte_.TSC0;\
56         pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\
57         pattrib_iv[4] = txpn._byte_.TSC2;\
58         pattrib_iv[5] = txpn._byte_.TSC3;\
59         pattrib_iv[6] = txpn._byte_.TSC4;\
60         pattrib_iv[7] = txpn._byte_.TSC5;\
61         txpn.val = txpn.val == 0xffffffffffffULL ? 0 : \
62         (txpn.val+1);\
63 } while (0)
64
65 #define AES_IV(pattrib_iv, txpn, keyidx)\
66 do { \
67         pattrib_iv[0] = txpn._byte_.TSC0;\
68         pattrib_iv[1] = txpn._byte_.TSC1;\
69         pattrib_iv[2] = 0;\
70         pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\
71         pattrib_iv[4] = txpn._byte_.TSC2;\
72         pattrib_iv[5] = txpn._byte_.TSC3;\
73         pattrib_iv[6] = txpn._byte_.TSC4;\
74         pattrib_iv[7] = txpn._byte_.TSC5;\
75         txpn.val = txpn.val == 0xffffffffffffULL ? 0 : \
76         (txpn.val+1);\
77 } while (0)
78
79 struct hw_xmit {
80         spinlock_t xmit_lock;
81         struct list_head pending;
82         struct  __queue *sta_queue;
83         struct hw_txqueue *phwtxqueue;
84         sint    txcmdcnt;
85         int     accnt;
86 };
87
88 struct pkt_attrib {
89         u8      type;
90         u8      subtype;
91         u8      bswenc;
92         u8      dhcp_pkt;
93
94         u16     seqnum;
95         u16     ether_type;
96         u32     pktlen;         /* the original 802.3 pkt raw_data len
97                                  * (not include ether_hdr data) */
98         u32     last_txcmdsz;
99
100         u8      pkt_hdrlen;     /*the original 802.3 pkt header len*/
101         u8      hdrlen;         /*the WLAN Header Len*/
102         u8      nr_frags;
103         u8      ack_policy;
104         u8      mac_id;
105         u8      vcs_mode;       /*virtual carrier sense method*/
106         u8      pctrl;/*per packet txdesc control enable*/
107         u8      qsel;
108
109         u8      priority;
110         u8      encrypt;        /* when 0 indicate no encrypt. when non-zero,
111                                  * indicate the encrypt algorith*/
112         u8      iv_len;
113         u8      icv_len;
114         unsigned char iv[8];
115         unsigned char icv[8];
116         u8      dst[ETH_ALEN];
117         u8      src[ETH_ALEN];
118         u8      ta[ETH_ALEN];
119         u8      ra[ETH_ALEN];
120         struct sta_info *psta;
121 };
122
123 #define WLANHDR_OFFSET  64
124 #define DATA_FRAMETAG           0x01
125 #define L2_FRAMETAG             0x02
126 #define MGNT_FRAMETAG           0x03
127 #define AMSDU_FRAMETAG  0x04
128 #define EII_FRAMETAG            0x05
129 #define IEEE8023_FRAMETAG  0x06
130 #define MP_FRAMETAG             0x07
131 #define TXAGG_FRAMETAG  0x08
132
133 struct xmit_buf {
134         struct list_head list;
135
136         u8 *pallocated_buf;
137         u8 *pbuf;
138         void *priv_data;
139         struct urb *pxmit_urb[8];
140         u32 aggr_nr;
141 };
142
143 struct xmit_frame {
144         struct list_head list;
145         struct pkt_attrib attrib;
146         _pkt *pkt;
147         int frame_tag;
148         struct _adapter *padapter;
149          u8 *buf_addr;
150          struct xmit_buf *pxmitbuf;
151         u8 *mem_addr;
152         u16 sz[8];
153         struct urb *pxmit_urb[8];
154         u8 bpending[8];
155         u8 last[8];
156 };
157
158 struct tx_servq {
159         struct list_head tx_pending;
160         struct  __queue sta_pending;
161         int qcnt;
162 };
163
164 struct sta_xmit_priv {
165         spinlock_t lock;
166         sint    option;
167         sint    apsd_setting;   /* When bit mask is on, the associated edca
168                                  * queue supports APSD.*/
169         struct tx_servq be_q;   /* priority == 0,3 */
170         struct tx_servq bk_q;   /* priority == 1,2*/
171         struct tx_servq vi_q;   /*priority == 4,5*/
172         struct tx_servq vo_q;   /*priority == 6,7*/
173         struct list_head  legacy_dz;
174         struct list_head apsd;
175         u16 txseq_tid[16];
176         uint    sta_tx_bytes;
177         u64     sta_tx_pkts;
178         uint    sta_tx_fail;
179 };
180
181 struct  hw_txqueue {
182         /*volatile*/ sint       head;
183         /*volatile*/ sint       tail;
184         /*volatile*/ sint       free_sz;        /*in units of 64 bytes*/
185         /*volatile*/ sint      free_cmdsz;
186         /*volatile*/ sint        txsz[8];
187         uint    ff_hwaddr;
188         uint    cmd_hwaddr;
189         sint    ac_tag;
190 };
191
192 struct  xmit_priv {
193         spinlock_t lock;
194         struct semaphore xmit_sema;
195         struct semaphore terminate_xmitthread_sema;
196         struct  __queue be_pending;
197         struct  __queue bk_pending;
198         struct  __queue vi_pending;
199         struct  __queue vo_pending;
200         struct  __queue bm_pending;
201         struct  __queue legacy_dz_queue;
202         struct  __queue apsd_queue;
203         u8 *pallocated_frame_buf;
204         u8 *pxmit_frame_buf;
205         uint free_xmitframe_cnt;
206         uint mapping_addr;
207         uint pkt_sz;
208         struct  __queue free_xmit_queue;
209         struct  hw_txqueue      be_txqueue;
210         struct  hw_txqueue      bk_txqueue;
211         struct  hw_txqueue      vi_txqueue;
212         struct  hw_txqueue      vo_txqueue;
213         struct  hw_txqueue      bmc_txqueue;
214         uint    frag_len;
215         struct _adapter *adapter;
216         u8   vcs_setting;
217         u8      vcs;
218         u8      vcs_type;
219         u16  rts_thresh;
220         uint    tx_bytes;
221         u64     tx_pkts;
222         uint    tx_drop;
223         struct hw_xmit *hwxmits;
224         u8      hwxmit_entry;
225         struct semaphore tx_retevt;/*all tx return event;*/
226         u8      txirp_cnt;
227         struct tasklet_struct xmit_tasklet;
228         /*per AC pending irp*/
229         int beq_cnt;
230         int bkq_cnt;
231         int viq_cnt;
232         int voq_cnt;
233         struct  __queue free_amsdu_xmit_queue;
234         u8 *pallocated_amsdu_frame_buf;
235         u8 *pxmit_amsdu_frame_buf;
236         uint free_amsdu_xmitframe_cnt;
237         struct  __queue free_txagg_xmit_queue;
238         u8 *pallocated_txagg_frame_buf;
239         u8 *pxmit_txagg_frame_buf;
240         uint free_txagg_xmitframe_cnt;
241         int cmdseq;
242         struct  __queue free_xmitbuf_queue;
243         struct  __queue pending_xmitbuf_queue;
244         u8 *pallocated_xmitbuf;
245         u8 *pxmitbuf;
246         uint free_xmitbuf_cnt;
247 };
248
249 static inline struct  __queue *get_free_xmit_queue(
250                                 struct xmit_priv *pxmitpriv)
251 {
252         return &(pxmitpriv->free_xmit_queue);
253 }
254
255 int r8712_free_xmitbuf(struct xmit_priv *pxmitpriv,
256                        struct xmit_buf *pxmitbuf);
257 struct xmit_buf *r8712_alloc_xmitbuf(struct xmit_priv *pxmitpriv);
258 void r8712_update_protection(struct _adapter *padapter, u8 *ie, uint ie_len);
259 struct xmit_frame *r8712_alloc_xmitframe(struct xmit_priv *pxmitpriv);
260 void r8712_free_xmitframe(struct xmit_priv *pxmitpriv,
261                           struct xmit_frame *pxmitframe);
262 void r8712_free_xmitframe_queue(struct xmit_priv *pxmitpriv,
263                                 struct  __queue *pframequeue);
264 sint r8712_xmit_classifier(struct _adapter *padapter,
265                             struct xmit_frame *pxmitframe);
266 sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt,
267                               struct xmit_frame *pxmitframe);
268 sint _r8712_init_hw_txqueue(struct hw_txqueue *phw_txqueue, u8 ac_tag);
269 void _r8712_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv);
270 sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
271                          struct pkt_attrib *pattrib);
272 int r8712_txframes_sta_ac_pending(struct _adapter *padapter,
273                                   struct pkt_attrib *pattrib);
274 sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
275                            struct _adapter *padapter);
276 void _free_xmit_priv(struct xmit_priv *pxmitpriv);
277 void r8712_free_xmitframe_ex(struct xmit_priv *pxmitpriv,
278                              struct xmit_frame *pxmitframe);
279 int r8712_pre_xmit(struct _adapter *padapter, struct xmit_frame *pxmitframe);
280 int r8712_xmit_enqueue(struct _adapter *padapter,
281                        struct xmit_frame *pxmitframe);
282 int r8712_xmit_direct(struct _adapter *padapter, struct xmit_frame *pxmitframe);
283 void r8712_xmit_bh(void *priv);
284
285 void xmitframe_xmitbuf_attach(struct xmit_frame *pxmitframe,
286                         struct xmit_buf *pxmitbuf);
287
288 #include "rtl8712_xmit.h"
289
290 #endif  /*_RTL871X_XMIT_H_*/
291