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