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