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