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