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