• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * rtl871x_xmit.c
3  *
4  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5  * Linux device driver for RTL8192SU
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of version 2 of the GNU General Public License as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19  *
20  * Modifications for inclusion into the Linux staging tree are
21  * Copyright(c) 2010 Larry Finger. All rights reserved.
22  *
23  * Contact information:
24  * WLAN FAE <wlanfae@realtek.com>
25  * Larry Finger <Larry.Finger@lwfinger.net>
26  *
27  ******************************************************************************/
28 
29 #define _RTL871X_XMIT_C_
30 
31 #include "osdep_service.h"
32 #include "drv_types.h"
33 #include "wifi.h"
34 #include "osdep_intf.h"
35 #include "usb_ops.h"
36 
37 
38 static const u8 P802_1H_OUI[P80211_OUI_LEN] = {0x00, 0x00, 0xf8};
39 static const u8 RFC1042_OUI[P80211_OUI_LEN] = {0x00, 0x00, 0x00};
40 static void init_hwxmits(struct hw_xmit *phwxmit, sint entry);
41 static void alloc_hwxmits(struct _adapter *padapter);
42 static void free_hwxmits(struct _adapter *padapter);
43 
_init_txservq(struct tx_servq * ptxservq)44 static void _init_txservq(struct tx_servq *ptxservq)
45 {
46 	INIT_LIST_HEAD(&ptxservq->tx_pending);
47 	_init_queue(&ptxservq->sta_pending);
48 	ptxservq->qcnt = 0;
49 }
50 
_r8712_init_sta_xmit_priv(struct sta_xmit_priv * psta_xmitpriv)51 void _r8712_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv)
52 {
53 	memset((unsigned char *)psta_xmitpriv, 0,
54 		 sizeof(struct sta_xmit_priv));
55 	spin_lock_init(&psta_xmitpriv->lock);
56 	_init_txservq(&psta_xmitpriv->be_q);
57 	_init_txservq(&psta_xmitpriv->bk_q);
58 	_init_txservq(&psta_xmitpriv->vi_q);
59 	_init_txservq(&psta_xmitpriv->vo_q);
60 	INIT_LIST_HEAD(&psta_xmitpriv->legacy_dz);
61 	INIT_LIST_HEAD(&psta_xmitpriv->apsd);
62 }
63 
_r8712_init_xmit_priv(struct xmit_priv * pxmitpriv,struct _adapter * padapter)64 sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
65 			   struct _adapter *padapter)
66 {
67 	sint i;
68 	struct xmit_buf *pxmitbuf;
69 	struct xmit_frame *pxframe;
70 
71 	memset((unsigned char *)pxmitpriv, 0, sizeof(struct xmit_priv));
72 	spin_lock_init(&pxmitpriv->lock);
73 	/*
74 	Please insert all the queue initialization using _init_queue below
75 	*/
76 	pxmitpriv->adapter = padapter;
77 	_init_queue(&pxmitpriv->be_pending);
78 	_init_queue(&pxmitpriv->bk_pending);
79 	_init_queue(&pxmitpriv->vi_pending);
80 	_init_queue(&pxmitpriv->vo_pending);
81 	_init_queue(&pxmitpriv->bm_pending);
82 	_init_queue(&pxmitpriv->legacy_dz_queue);
83 	_init_queue(&pxmitpriv->apsd_queue);
84 	_init_queue(&pxmitpriv->free_xmit_queue);
85 	/*
86 	Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME,
87 	and initialize free_xmit_frame below.
88 	Please also apply  free_txobj to link_up all the xmit_frames...
89 	*/
90 	pxmitpriv->pallocated_frame_buf = kmalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4,
91 						  GFP_ATOMIC);
92 	if (pxmitpriv->pallocated_frame_buf == NULL) {
93 		pxmitpriv->pxmit_frame_buf = NULL;
94 		return _FAIL;
95 	}
96 	pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 -
97 			((addr_t) (pxmitpriv->pallocated_frame_buf) & 3);
98 	pxframe = (struct xmit_frame *) pxmitpriv->pxmit_frame_buf;
99 	for (i = 0; i < NR_XMITFRAME; i++) {
100 		INIT_LIST_HEAD(&(pxframe->list));
101 		pxframe->padapter = padapter;
102 		pxframe->frame_tag = DATA_FRAMETAG;
103 		pxframe->pkt = NULL;
104 		pxframe->buf_addr = NULL;
105 		pxframe->pxmitbuf = NULL;
106 		list_add_tail(&(pxframe->list),
107 				 &(pxmitpriv->free_xmit_queue.queue));
108 		pxframe++;
109 	}
110 	pxmitpriv->free_xmitframe_cnt = NR_XMITFRAME;
111 	/*
112 		init xmit hw_txqueue
113 	*/
114 	_r8712_init_hw_txqueue(&pxmitpriv->be_txqueue, BE_QUEUE_INX);
115 	_r8712_init_hw_txqueue(&pxmitpriv->bk_txqueue, BK_QUEUE_INX);
116 	_r8712_init_hw_txqueue(&pxmitpriv->vi_txqueue, VI_QUEUE_INX);
117 	_r8712_init_hw_txqueue(&pxmitpriv->vo_txqueue, VO_QUEUE_INX);
118 	_r8712_init_hw_txqueue(&pxmitpriv->bmc_txqueue, BMC_QUEUE_INX);
119 	pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
120 	pxmitpriv->txirp_cnt = 1;
121 	/*per AC pending irp*/
122 	pxmitpriv->beq_cnt = 0;
123 	pxmitpriv->bkq_cnt = 0;
124 	pxmitpriv->viq_cnt = 0;
125 	pxmitpriv->voq_cnt = 0;
126 	/*init xmit_buf*/
127 	_init_queue(&pxmitpriv->free_xmitbuf_queue);
128 	_init_queue(&pxmitpriv->pending_xmitbuf_queue);
129 	pxmitpriv->pallocated_xmitbuf = kmalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4,
130 						GFP_ATOMIC);
131 	if (pxmitpriv->pallocated_xmitbuf  == NULL)
132 		return _FAIL;
133 	pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 -
134 			      ((addr_t)(pxmitpriv->pallocated_xmitbuf) & 3);
135 	pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
136 	for (i = 0; i < NR_XMITBUFF; i++) {
137 		INIT_LIST_HEAD(&pxmitbuf->list);
138 		pxmitbuf->pallocated_buf = kmalloc(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ,
139 						   GFP_ATOMIC);
140 		if (pxmitbuf->pallocated_buf == NULL)
141 			return _FAIL;
142 		pxmitbuf->pbuf = pxmitbuf->pallocated_buf + XMITBUF_ALIGN_SZ -
143 				 ((addr_t) (pxmitbuf->pallocated_buf) &
144 				 (XMITBUF_ALIGN_SZ - 1));
145 		r8712_xmit_resource_alloc(padapter, pxmitbuf);
146 		list_add_tail(&pxmitbuf->list,
147 				 &(pxmitpriv->free_xmitbuf_queue.queue));
148 		pxmitbuf++;
149 	}
150 	pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
151 	INIT_WORK(&padapter->wkFilterRxFF0, r8712_SetFilter);
152 	alloc_hwxmits(padapter);
153 	init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
154 	tasklet_init(&pxmitpriv->xmit_tasklet,
155 		(void(*)(unsigned long))r8712_xmit_bh,
156 		(unsigned long)padapter);
157 	return _SUCCESS;
158 }
159 
_free_xmit_priv(struct xmit_priv * pxmitpriv)160 void _free_xmit_priv(struct xmit_priv *pxmitpriv)
161 {
162 	int i;
163 	struct _adapter *padapter = pxmitpriv->adapter;
164 	struct xmit_frame *pxmitframe = (struct xmit_frame *)
165 					pxmitpriv->pxmit_frame_buf;
166 	struct xmit_buf *pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
167 
168 	if (pxmitpriv->pxmit_frame_buf == NULL)
169 		return;
170 	for (i = 0; i < NR_XMITFRAME; i++) {
171 		r8712_xmit_complete(padapter, pxmitframe);
172 		pxmitframe++;
173 	}
174 	for (i = 0; i < NR_XMITBUFF; i++) {
175 		r8712_xmit_resource_free(padapter, pxmitbuf);
176 		kfree(pxmitbuf->pallocated_buf);
177 		pxmitbuf++;
178 	}
179 	kfree(pxmitpriv->pallocated_frame_buf);
180 	kfree(pxmitpriv->pallocated_xmitbuf);
181 	free_hwxmits(padapter);
182 }
183 
r8712_update_attrib(struct _adapter * padapter,_pkt * pkt,struct pkt_attrib * pattrib)184 sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
185 		   struct pkt_attrib *pattrib)
186 {
187 	uint i;
188 	struct pkt_file pktfile;
189 	struct sta_info *psta = NULL;
190 	struct ethhdr etherhdr;
191 
192 	struct tx_cmd txdesc;
193 
194 	sint bmcast;
195 	struct sta_priv		*pstapriv = &padapter->stapriv;
196 	struct security_priv	*psecuritypriv = &padapter->securitypriv;
197 	struct mlme_priv	*pmlmepriv = &padapter->mlmepriv;
198 	struct qos_priv		*pqospriv = &pmlmepriv->qospriv;
199 
200 	_r8712_open_pktfile(pkt, &pktfile);
201 
202 	i = _r8712_pktfile_read(&pktfile, (unsigned char *)&etherhdr, ETH_HLEN);
203 
204 	pattrib->ether_type = ntohs(etherhdr.h_proto);
205 
206 {
207 	u8 bool;
208 	/*If driver xmit ARP packet, driver can set ps mode to initial
209 	 * setting. It stands for getting DHCP or fix IP.*/
210 	if (pattrib->ether_type == 0x0806) {
211 		if (padapter->pwrctrlpriv.pwr_mode !=
212 		    padapter->registrypriv.power_mgnt) {
213 			_cancel_timer(&(pmlmepriv->dhcp_timer), &bool);
214 			r8712_set_ps_mode(padapter, padapter->registrypriv.
215 				power_mgnt, padapter->registrypriv.smart_ps);
216 		}
217 	}
218 }
219 	memcpy(pattrib->dst, &etherhdr.h_dest, ETH_ALEN);
220 	memcpy(pattrib->src, &etherhdr.h_source, ETH_ALEN);
221 	pattrib->pctrl = 0;
222 	if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
223 	    (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
224 		memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
225 		memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
226 	} else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
227 		memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
228 		memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
229 	} else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
230 		memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
231 		memcpy(pattrib->ta, get_bssid(pmlmepriv), ETH_ALEN);
232 	} else if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
233 		/*firstly, filter packet not belongs to mp*/
234 		if (pattrib->ether_type != 0x8712)
235 			return _FAIL;
236 		/* for mp storing the txcmd per packet,
237 		 * according to the info of txcmd to update pattrib */
238 		/*get MP_TXDESC_SIZE bytes txcmd per packet*/
239 		i = _r8712_pktfile_read(&pktfile, (u8 *)&txdesc, TXDESC_SIZE);
240 		memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
241 		memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
242 		pattrib->pctrl = 1;
243 	}
244 	/* r8712_xmitframe_coalesce() overwrite this!*/
245 	pattrib->pktlen = pktfile.pkt_len;
246 	if (ETH_P_IP == pattrib->ether_type) {
247 		/* The following is for DHCP and ARP packet, we use cck1M to
248 		 * tx these packets and let LPS awake some time
249 		 * to prevent DHCP protocol fail */
250 		u8 tmp[24];
251 
252 		_r8712_pktfile_read(&pktfile, &tmp[0], 24);
253 		pattrib->dhcp_pkt = 0;
254 		if (pktfile.pkt_len > 282) {/*MINIMUM_DHCP_PACKET_SIZE)*/
255 			if (ETH_P_IP == pattrib->ether_type) {/* IP header*/
256 				if (((tmp[21] == 68) && (tmp[23] == 67)) ||
257 					((tmp[21] == 67) && (tmp[23] == 68))) {
258 					/* 68 : UDP BOOTP client
259 					 * 67 : UDP BOOTP server
260 					 * Use low rate to send DHCP packet.*/
261 					pattrib->dhcp_pkt = 1;
262 				}
263 			}
264 		}
265 	}
266 	bmcast = IS_MCAST(pattrib->ra);
267 	/* get sta_info*/
268 	if (bmcast) {
269 		psta = r8712_get_bcmc_stainfo(padapter);
270 		pattrib->mac_id = 4;
271 	} else {
272 		if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
273 			psta = r8712_get_stainfo(pstapriv,
274 						 get_bssid(pmlmepriv));
275 			pattrib->mac_id = 5;
276 		} else {
277 			psta = r8712_get_stainfo(pstapriv, pattrib->ra);
278 			if (psta == NULL)  /* drop the pkt */
279 				return _FAIL;
280 			if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
281 				pattrib->mac_id = 5;
282 			else
283 				pattrib->mac_id = psta->mac_id;
284 		}
285 	}
286 
287 	if (psta) {
288 		pattrib->psta = psta;
289 	} else {
290 		/* if we cannot get psta => drrp the pkt */
291 		return _FAIL;
292 	}
293 
294 	pattrib->ack_policy = 0;
295 	/* get ether_hdr_len */
296 	pattrib->pkt_hdrlen = ETH_HLEN;
297 
298 	if (pqospriv->qos_option)
299 		r8712_set_qos(&pktfile, pattrib);
300 	else {
301 		pattrib->hdrlen = WLAN_HDR_A3_LEN;
302 		pattrib->subtype = WIFI_DATA_TYPE;
303 		pattrib->priority = 0;
304 	}
305 	if (psta->ieee8021x_blocked == true) {
306 		pattrib->encrypt = 0;
307 		if ((pattrib->ether_type != 0x888e) &&
308 		    (check_fwstate(pmlmepriv, WIFI_MP_STATE) == false))
309 			return _FAIL;
310 	} else
311 		GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
312 	switch (pattrib->encrypt) {
313 	case _WEP40_:
314 	case _WEP104_:
315 		pattrib->iv_len = 4;
316 		pattrib->icv_len = 4;
317 		break;
318 	case _TKIP_:
319 		pattrib->iv_len = 8;
320 		pattrib->icv_len = 4;
321 		if (padapter->securitypriv.busetkipkey == _FAIL)
322 			return _FAIL;
323 		break;
324 	case _AES_:
325 		pattrib->iv_len = 8;
326 		pattrib->icv_len = 8;
327 		break;
328 	default:
329 		pattrib->iv_len = 0;
330 		pattrib->icv_len = 0;
331 		break;
332 	}
333 
334 	if (pattrib->encrypt &&
335 	    ((padapter->securitypriv.sw_encrypt == true) ||
336 	     (psecuritypriv->hw_decrypted == false)))
337 		pattrib->bswenc = true;
338 	else
339 		pattrib->bswenc = false;
340 	/* if in MP_STATE, update pkt_attrib from mp_txcmd, and overwrite
341 	 * some settings above.*/
342 	if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
343 		pattrib->priority =
344 		    (le32_to_cpu(txdesc.txdw1) >> QSEL_SHT) & 0x1f;
345 	return _SUCCESS;
346 }
347 
xmitframe_addmic(struct _adapter * padapter,struct xmit_frame * pxmitframe)348 static sint xmitframe_addmic(struct _adapter *padapter,
349 			     struct xmit_frame *pxmitframe)
350 {
351 	u32	curfragnum, length, datalen;
352 	u8	*pframe, *payload, mic[8];
353 	struct	mic_data micdata;
354 	struct	sta_info *stainfo;
355 	struct	qos_priv *pqospriv = &(padapter->mlmepriv.qospriv);
356 	struct	pkt_attrib  *pattrib = &pxmitframe->attrib;
357 	struct	security_priv *psecuritypriv = &padapter->securitypriv;
358 	struct	xmit_priv *pxmitpriv = &padapter->xmitpriv;
359 	u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
360 	sint bmcst = IS_MCAST(pattrib->ra);
361 
362 	if (pattrib->psta)
363 		stainfo = pattrib->psta;
364 	else
365 		stainfo = r8712_get_stainfo(&padapter->stapriv,
366 					    &pattrib->ra[0]);
367 	if (pattrib->encrypt == _TKIP_) {
368 		/*encode mic code*/
369 		if (stainfo != NULL) {
370 			u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
371 					   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
372 					   0x0, 0x0};
373 			datalen = pattrib->pktlen - pattrib->hdrlen;
374 			pframe = pxmitframe->buf_addr + TXDESC_OFFSET;
375 			if (bmcst) {
376 				if (!memcmp(psecuritypriv->XGrptxmickey
377 				   [psecuritypriv->XGrpKeyid].skey,
378 				   null_key, 16))
379 					return _FAIL;
380 				/*start to calculate the mic code*/
381 				r8712_secmicsetkey(&micdata,
382 					 psecuritypriv->
383 					 XGrptxmickey[psecuritypriv->
384 					XGrpKeyid].skey);
385 			} else {
386 				if (!memcmp(&stainfo->tkiptxmickey.skey[0],
387 					    null_key, 16))
388 					return _FAIL;
389 				/* start to calculate the mic code */
390 				r8712_secmicsetkey(&micdata,
391 					     &stainfo->tkiptxmickey.skey[0]);
392 			}
393 			if (pframe[1] & 1) {   /* ToDS==1 */
394 				r8712_secmicappend(&micdata,
395 						   &pframe[16], 6); /*DA*/
396 				if (pframe[1]&2)  /* From Ds==1 */
397 					r8712_secmicappend(&micdata,
398 							   &pframe[24], 6);
399 				else
400 					r8712_secmicappend(&micdata,
401 							   &pframe[10], 6);
402 			} else {	/* ToDS==0 */
403 				r8712_secmicappend(&micdata,
404 						   &pframe[4], 6); /* DA */
405 				if (pframe[1]&2)  /* From Ds==1 */
406 					r8712_secmicappend(&micdata,
407 							   &pframe[16], 6);
408 				else
409 					r8712_secmicappend(&micdata,
410 							   &pframe[10], 6);
411 			}
412 			if (pqospriv->qos_option == 1)
413 					priority[0] = (u8)pxmitframe->
414 						      attrib.priority;
415 			r8712_secmicappend(&micdata, &priority[0], 4);
416 			payload = pframe;
417 			for (curfragnum = 0; curfragnum < pattrib->nr_frags;
418 			     curfragnum++) {
419 				payload = (u8 *)RND4((addr_t)(payload));
420 				payload = payload+pattrib->
421 					  hdrlen+pattrib->iv_len;
422 				if ((curfragnum + 1) == pattrib->nr_frags) {
423 					length = pattrib->last_txcmdsz -
424 						  pattrib->hdrlen -
425 						  pattrib->iv_len -
426 						  ((psecuritypriv->sw_encrypt)
427 						  ? pattrib->icv_len : 0);
428 					r8712_secmicappend(&micdata, payload,
429 							   length);
430 					payload = payload+length;
431 				} else{
432 					length = pxmitpriv->frag_len -
433 					    pattrib->hdrlen-pattrib->iv_len -
434 					    ((psecuritypriv->sw_encrypt) ?
435 					    pattrib->icv_len : 0);
436 					r8712_secmicappend(&micdata, payload,
437 							   length);
438 					payload = payload + length +
439 						  pattrib->icv_len;
440 				}
441 			}
442 			r8712_secgetmic(&micdata, &(mic[0]));
443 			/* add mic code  and add the mic code length in
444 			 * last_txcmdsz */
445 			memcpy(payload, &(mic[0]), 8);
446 			pattrib->last_txcmdsz += 8;
447 			payload = payload-pattrib->last_txcmdsz + 8;
448 		}
449 	}
450 	return _SUCCESS;
451 }
452 
xmitframe_swencrypt(struct _adapter * padapter,struct xmit_frame * pxmitframe)453 static sint xmitframe_swencrypt(struct _adapter *padapter,
454 				struct xmit_frame *pxmitframe)
455 {
456 	struct pkt_attrib	*pattrib = &pxmitframe->attrib;
457 
458 	if (pattrib->bswenc) {
459 		switch (pattrib->encrypt) {
460 		case _WEP40_:
461 		case _WEP104_:
462 			r8712_wep_encrypt(padapter, (u8 *)pxmitframe);
463 			break;
464 		case _TKIP_:
465 			r8712_tkip_encrypt(padapter, (u8 *)pxmitframe);
466 			break;
467 		case _AES_:
468 			r8712_aes_encrypt(padapter, (u8 *)pxmitframe);
469 			break;
470 		default:
471 				break;
472 		}
473 	}
474 	return _SUCCESS;
475 }
476 
make_wlanhdr(struct _adapter * padapter,u8 * hdr,struct pkt_attrib * pattrib)477 static sint make_wlanhdr(struct _adapter *padapter , u8 *hdr,
478 			 struct pkt_attrib *pattrib)
479 {
480 	u16 *qc;
481 
482 	struct ieee80211_hdr *pwlanhdr = (struct ieee80211_hdr *)hdr;
483 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
484 	struct qos_priv *pqospriv = &pmlmepriv->qospriv;
485 	__le16 *fctrl = &pwlanhdr->frame_ctl;
486 
487 	memset(hdr, 0, WLANHDR_OFFSET);
488 	SetFrameSubType(fctrl, pattrib->subtype);
489 	if (pattrib->subtype & WIFI_DATA_TYPE) {
490 		if ((check_fwstate(pmlmepriv,  WIFI_STATION_STATE) == true)) {
491 			/* to_ds = 1, fr_ds = 0; */
492 			SetToDs(fctrl);
493 			memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv),
494 				ETH_ALEN);
495 			memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
496 			memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
497 		} else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
498 			/* to_ds = 0, fr_ds = 1; */
499 			SetFrDs(fctrl);
500 			memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
501 			memcpy(pwlanhdr->addr2, get_bssid(pmlmepriv),
502 				ETH_ALEN);
503 			memcpy(pwlanhdr->addr3, pattrib->src, ETH_ALEN);
504 		} else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)
505 			   || (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)
506 			   == true)) {
507 			memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
508 			memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
509 			memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv),
510 				ETH_ALEN);
511 		} else if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
512 			memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
513 			memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
514 			memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv),
515 				ETH_ALEN);
516 		} else
517 			return _FAIL;
518 
519 		if (pattrib->encrypt)
520 			SetPrivacy(fctrl);
521 		if (pqospriv->qos_option) {
522 			qc = (unsigned short *)(hdr + pattrib->hdrlen - 2);
523 			if (pattrib->priority)
524 				SetPriority(qc, pattrib->priority);
525 			SetAckpolicy(qc, pattrib->ack_policy);
526 		}
527 		/* TODO: fill HT Control Field */
528 		/* Update Seq Num will be handled by f/w */
529 		{
530 			struct sta_info *psta;
531 			sint bmcst = IS_MCAST(pattrib->ra);
532 
533 			if (pattrib->psta)
534 				psta = pattrib->psta;
535 			else {
536 				if (bmcst)
537 					psta = r8712_get_bcmc_stainfo(padapter);
538 				else
539 					psta =
540 					 r8712_get_stainfo(&padapter->stapriv,
541 					 pattrib->ra);
542 			}
543 			if (psta) {
544 				psta->sta_xmitpriv.txseq_tid
545 						  [pattrib->priority]++;
546 				psta->sta_xmitpriv.txseq_tid[pattrib->priority]
547 						   &= 0xFFF;
548 				pattrib->seqnum = psta->sta_xmitpriv.
549 						  txseq_tid[pattrib->priority];
550 				SetSeqNum(hdr, pattrib->seqnum);
551 			}
552 		}
553 	}
554 	return _SUCCESS;
555 }
556 
r8712_put_snap(u8 * data,u16 h_proto)557 static sint r8712_put_snap(u8 *data, u16 h_proto)
558 {
559 	struct ieee80211_snap_hdr *snap;
560 	const u8 *oui;
561 
562 	snap = (struct ieee80211_snap_hdr *)data;
563 	snap->dsap = 0xaa;
564 	snap->ssap = 0xaa;
565 	snap->ctrl = 0x03;
566 	if (h_proto == 0x8137 || h_proto == 0x80f3)
567 		oui = P802_1H_OUI;
568 	else
569 		oui = RFC1042_OUI;
570 	snap->oui[0] = oui[0];
571 	snap->oui[1] = oui[1];
572 	snap->oui[2] = oui[2];
573 	*(__be16 *)(data + SNAP_SIZE) = htons(h_proto);
574 	return SNAP_SIZE + sizeof(u16);
575 }
576 
577 /*
578  * This sub-routine will perform all the following:
579  * 1. remove 802.3 header.
580  * 2. create wlan_header, based on the info in pxmitframe
581  * 3. append sta's iv/ext-iv
582  * 4. append LLC
583  * 5. move frag chunk from pframe to pxmitframe->mem
584  * 6. apply sw-encrypt, if necessary.
585  */
r8712_xmitframe_coalesce(struct _adapter * padapter,_pkt * pkt,struct xmit_frame * pxmitframe)586 sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt,
587 			struct xmit_frame *pxmitframe)
588 {
589 	struct pkt_file pktfile;
590 
591 	sint	frg_len, mpdu_len, llc_sz;
592 	u32	mem_sz;
593 	u8	frg_inx;
594 	addr_t addr;
595 	u8 *pframe, *mem_start, *ptxdesc;
596 	struct sta_info		*psta;
597 	struct security_priv	*psecuritypriv = &padapter->securitypriv;
598 	struct mlme_priv	*pmlmepriv = &padapter->mlmepriv;
599 	struct xmit_priv	*pxmitpriv = &padapter->xmitpriv;
600 	struct pkt_attrib	*pattrib = &pxmitframe->attrib;
601 	u8 *pbuf_start;
602 	sint bmcst = IS_MCAST(pattrib->ra);
603 
604 	if (pattrib->psta == NULL)
605 		return _FAIL;
606 	psta = pattrib->psta;
607 	if (pxmitframe->buf_addr == NULL)
608 		return _FAIL;
609 	pbuf_start = pxmitframe->buf_addr;
610 	ptxdesc = pbuf_start;
611 	mem_start = pbuf_start + TXDESC_OFFSET;
612 	if (make_wlanhdr(padapter, mem_start, pattrib) == _FAIL)
613 		return _FAIL;
614 	_r8712_open_pktfile(pkt, &pktfile);
615 	_r8712_pktfile_read(&pktfile, NULL, (uint) pattrib->pkt_hdrlen);
616 	if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
617 		/* truncate TXDESC_SIZE bytes txcmd if at mp mode for 871x */
618 		if (pattrib->ether_type == 0x8712) {
619 			/* take care -  update_txdesc overwrite this */
620 			_r8712_pktfile_read(&pktfile, ptxdesc, TXDESC_SIZE);
621 		}
622 	}
623 	pattrib->pktlen = pktfile.pkt_len;
624 	frg_inx = 0;
625 	frg_len = pxmitpriv->frag_len - 4;
626 	while (1) {
627 		llc_sz = 0;
628 		mpdu_len = frg_len;
629 		pframe = mem_start;
630 		SetMFrag(mem_start);
631 		pframe += pattrib->hdrlen;
632 		mpdu_len -= pattrib->hdrlen;
633 		/* adding icv, if necessary...*/
634 		if (pattrib->iv_len) {
635 			if (psta != NULL) {
636 				switch (pattrib->encrypt) {
637 				case _WEP40_:
638 				case _WEP104_:
639 					WEP_IV(pattrib->iv, psta->txpn,
640 					       (u8)psecuritypriv->
641 					       PrivacyKeyIndex);
642 					break;
643 				case _TKIP_:
644 					if (bmcst)
645 						TKIP_IV(pattrib->iv,
646 						    psta->txpn,
647 						    (u8)psecuritypriv->
648 						    XGrpKeyid);
649 					else
650 						TKIP_IV(pattrib->iv, psta->txpn,
651 							0);
652 					break;
653 				case _AES_:
654 					if (bmcst)
655 						AES_IV(pattrib->iv, psta->txpn,
656 						    (u8)psecuritypriv->
657 						    XGrpKeyid);
658 					else
659 						AES_IV(pattrib->iv, psta->txpn,
660 						       0);
661 					break;
662 				}
663 			}
664 			memcpy(pframe, pattrib->iv, pattrib->iv_len);
665 			pframe += pattrib->iv_len;
666 			mpdu_len -= pattrib->iv_len;
667 		}
668 		if (frg_inx == 0) {
669 			llc_sz = r8712_put_snap(pframe, pattrib->ether_type);
670 			pframe += llc_sz;
671 			mpdu_len -= llc_sz;
672 		}
673 		if ((pattrib->icv_len > 0) && (pattrib->bswenc))
674 			mpdu_len -= pattrib->icv_len;
675 		if (bmcst)
676 			mem_sz = _r8712_pktfile_read(&pktfile, pframe,
677 				 pattrib->pktlen);
678 		else
679 			mem_sz = _r8712_pktfile_read(&pktfile, pframe,
680 				 mpdu_len);
681 		pframe += mem_sz;
682 		if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
683 			memcpy(pframe, pattrib->icv, pattrib->icv_len);
684 			pframe += pattrib->icv_len;
685 		}
686 		frg_inx++;
687 		if (bmcst || (r8712_endofpktfile(&pktfile) == true)) {
688 			pattrib->nr_frags = frg_inx;
689 			pattrib->last_txcmdsz = pattrib->hdrlen +
690 						pattrib->iv_len +
691 						((pattrib->nr_frags == 1) ?
692 						llc_sz : 0) +
693 						((pattrib->bswenc) ?
694 						pattrib->icv_len : 0) + mem_sz;
695 			ClearMFrag(mem_start);
696 			break;
697 		}
698 		addr = (addr_t)(pframe);
699 		mem_start = (unsigned char *)RND4(addr) + TXDESC_OFFSET;
700 		memcpy(mem_start, pbuf_start + TXDESC_OFFSET, pattrib->hdrlen);
701 	}
702 
703 	if (xmitframe_addmic(padapter, pxmitframe) == _FAIL)
704 		return _FAIL;
705 	xmitframe_swencrypt(padapter, pxmitframe);
706 	return _SUCCESS;
707 }
708 
r8712_update_protection(struct _adapter * padapter,u8 * ie,uint ie_len)709 void r8712_update_protection(struct _adapter *padapter, u8 *ie, uint ie_len)
710 {
711 	uint	protection;
712 	u8	*perp;
713 	sint	 erp_len;
714 	struct	xmit_priv *pxmitpriv = &padapter->xmitpriv;
715 	struct	registry_priv *pregistrypriv = &padapter->registrypriv;
716 
717 	switch (pxmitpriv->vcs_setting) {
718 	case DISABLE_VCS:
719 		pxmitpriv->vcs = NONE_VCS;
720 		break;
721 	case ENABLE_VCS:
722 		break;
723 	case AUTO_VCS:
724 	default:
725 		perp = r8712_get_ie(ie, _ERPINFO_IE_, &erp_len, ie_len);
726 		if (perp == NULL)
727 			pxmitpriv->vcs = NONE_VCS;
728 		else {
729 			protection = (*(perp + 2)) & BIT(1);
730 			if (protection) {
731 				if (pregistrypriv->vcs_type == RTS_CTS)
732 					pxmitpriv->vcs = RTS_CTS;
733 				else
734 					pxmitpriv->vcs = CTS_TO_SELF;
735 			} else
736 				pxmitpriv->vcs = NONE_VCS;
737 		}
738 		break;
739 	}
740 }
741 
r8712_alloc_xmitbuf(struct xmit_priv * pxmitpriv)742 struct xmit_buf *r8712_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
743 {
744 	unsigned long irqL;
745 	struct xmit_buf *pxmitbuf =  NULL;
746 	struct list_head *plist, *phead;
747 	struct  __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
748 
749 	spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
750 	if (list_empty(&pfree_xmitbuf_queue->queue))
751 		pxmitbuf = NULL;
752 	else {
753 		phead = &pfree_xmitbuf_queue->queue;
754 		plist = phead->next;
755 		pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
756 		list_del_init(&(pxmitbuf->list));
757 	}
758 	if (pxmitbuf !=  NULL)
759 		pxmitpriv->free_xmitbuf_cnt--;
760 	spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
761 	return pxmitbuf;
762 }
763 
r8712_free_xmitbuf(struct xmit_priv * pxmitpriv,struct xmit_buf * pxmitbuf)764 int r8712_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
765 {
766 	unsigned long irqL;
767 	struct  __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
768 
769 	if (pxmitbuf == NULL)
770 		return _FAIL;
771 	spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
772 	list_del_init(&pxmitbuf->list);
773 	list_add_tail(&(pxmitbuf->list), &pfree_xmitbuf_queue->queue);
774 	pxmitpriv->free_xmitbuf_cnt++;
775 	spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
776 	return _SUCCESS;
777 }
778 
779 /*
780 Calling context:
781 1. OS_TXENTRY
782 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack)
783 
784 If we turn on USE_RXTHREAD, then, no need for critical section.
785 Otherwise, we must use _enter/_exit critical to protect free_xmit_queue...
786 
787 Must be very very cautious...
788 
789 */
790 
r8712_alloc_xmitframe(struct xmit_priv * pxmitpriv)791 struct xmit_frame *r8712_alloc_xmitframe(struct xmit_priv *pxmitpriv)
792 {
793 	/*
794 		Please remember to use all the osdep_service api,
795 		and lock/unlock or _enter/_exit critical to protect
796 		pfree_xmit_queue
797 	*/
798 	unsigned long irqL;
799 	struct xmit_frame *pxframe = NULL;
800 	struct list_head *plist, *phead;
801 	struct  __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
802 
803 	spin_lock_irqsave(&pfree_xmit_queue->lock, irqL);
804 	if (list_empty(&pfree_xmit_queue->queue))
805 		pxframe =  NULL;
806 	else {
807 		phead = &pfree_xmit_queue->queue;
808 		plist = phead->next;
809 		pxframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
810 		list_del_init(&(pxframe->list));
811 	}
812 	if (pxframe !=  NULL) {
813 		pxmitpriv->free_xmitframe_cnt--;
814 		pxframe->buf_addr = NULL;
815 		pxframe->pxmitbuf = NULL;
816 		pxframe->attrib.psta = NULL;
817 		pxframe->pkt = NULL;
818 	}
819 	spin_unlock_irqrestore(&pfree_xmit_queue->lock, irqL);
820 	return pxframe;
821 }
822 
r8712_free_xmitframe(struct xmit_priv * pxmitpriv,struct xmit_frame * pxmitframe)823 void r8712_free_xmitframe(struct xmit_priv *pxmitpriv,
824 			  struct xmit_frame *pxmitframe)
825 {
826 	unsigned long irqL;
827 	struct  __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
828 	struct _adapter *padapter = pxmitpriv->adapter;
829 	struct sk_buff *pndis_pkt = NULL;
830 
831 	if (pxmitframe == NULL)
832 		return;
833 	spin_lock_irqsave(&pfree_xmit_queue->lock, irqL);
834 	list_del_init(&pxmitframe->list);
835 	if (pxmitframe->pkt) {
836 		pndis_pkt = pxmitframe->pkt;
837 		pxmitframe->pkt = NULL;
838 	}
839 	list_add_tail(&pxmitframe->list, &pfree_xmit_queue->queue);
840 	pxmitpriv->free_xmitframe_cnt++;
841 	spin_unlock_irqrestore(&pfree_xmit_queue->lock, irqL);
842 	if (netif_queue_stopped(padapter->pnetdev))
843 		netif_wake_queue(padapter->pnetdev);
844 }
845 
r8712_free_xmitframe_ex(struct xmit_priv * pxmitpriv,struct xmit_frame * pxmitframe)846 void r8712_free_xmitframe_ex(struct xmit_priv *pxmitpriv,
847 		      struct xmit_frame *pxmitframe)
848 {
849 	if (pxmitframe == NULL)
850 		return;
851 	if (pxmitframe->frame_tag == DATA_FRAMETAG)
852 		r8712_free_xmitframe(pxmitpriv, pxmitframe);
853 }
854 
r8712_free_xmitframe_queue(struct xmit_priv * pxmitpriv,struct __queue * pframequeue)855 void r8712_free_xmitframe_queue(struct xmit_priv *pxmitpriv,
856 				struct  __queue *pframequeue)
857 {
858 	unsigned long irqL;
859 	struct list_head *plist, *phead;
860 	struct	xmit_frame	*pxmitframe;
861 
862 	spin_lock_irqsave(&(pframequeue->lock), irqL);
863 	phead = &pframequeue->queue;
864 	plist = phead->next;
865 	while (end_of_queue_search(phead, plist) == false) {
866 		pxmitframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
867 		plist = plist->next;
868 		r8712_free_xmitframe(pxmitpriv, pxmitframe);
869 	}
870 	spin_unlock_irqrestore(&(pframequeue->lock), irqL);
871 }
872 
get_sta_pending(struct _adapter * padapter,struct __queue ** ppstapending,struct sta_info * psta,sint up)873 static inline struct tx_servq *get_sta_pending(struct _adapter *padapter,
874 					       struct  __queue **ppstapending,
875 					       struct sta_info *psta, sint up)
876 {
877 
878 	struct tx_servq *ptxservq;
879 	struct hw_xmit *phwxmits =  padapter->xmitpriv.hwxmits;
880 
881 	switch (up) {
882 	case 1:
883 	case 2:
884 		ptxservq = &(psta->sta_xmitpriv.bk_q);
885 		*ppstapending = &padapter->xmitpriv.bk_pending;
886 		(phwxmits+3)->accnt++;
887 		break;
888 	case 4:
889 	case 5:
890 		ptxservq = &(psta->sta_xmitpriv.vi_q);
891 		*ppstapending = &padapter->xmitpriv.vi_pending;
892 		(phwxmits+1)->accnt++;
893 		break;
894 	case 6:
895 	case 7:
896 		ptxservq = &(psta->sta_xmitpriv.vo_q);
897 		*ppstapending = &padapter->xmitpriv.vo_pending;
898 		(phwxmits+0)->accnt++;
899 		break;
900 	case 0:
901 	case 3:
902 	default:
903 		ptxservq = &(psta->sta_xmitpriv.be_q);
904 		*ppstapending = &padapter->xmitpriv.be_pending;
905 		(phwxmits + 2)->accnt++;
906 		break;
907 	}
908 	return ptxservq;
909 }
910 
911 /*
912  * Will enqueue pxmitframe to the proper queue, and indicate it
913  * to xx_pending list.....
914  */
r8712_xmit_classifier(struct _adapter * padapter,struct xmit_frame * pxmitframe)915 sint r8712_xmit_classifier(struct _adapter *padapter,
916 			   struct xmit_frame *pxmitframe)
917 {
918 	unsigned long irqL0;
919 	struct  __queue *pstapending;
920 	struct sta_info	*psta;
921 	struct tx_servq	*ptxservq;
922 	struct pkt_attrib *pattrib = &pxmitframe->attrib;
923 	struct sta_priv *pstapriv = &padapter->stapriv;
924 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
925 	sint bmcst = IS_MCAST(pattrib->ra);
926 
927 	if (pattrib->psta)
928 		psta = pattrib->psta;
929 	else {
930 		if (bmcst)
931 			psta = r8712_get_bcmc_stainfo(padapter);
932 		else {
933 			if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
934 				psta = r8712_get_stainfo(pstapriv,
935 				       get_bssid(pmlmepriv));
936 			else
937 				psta = r8712_get_stainfo(pstapriv, pattrib->ra);
938 		}
939 	}
940 	if (psta == NULL)
941 		return _FAIL;
942 	ptxservq = get_sta_pending(padapter, &pstapending,
943 		   psta, pattrib->priority);
944 	spin_lock_irqsave(&pstapending->lock, irqL0);
945 	if (list_empty(&ptxservq->tx_pending))
946 		list_add_tail(&ptxservq->tx_pending, &pstapending->queue);
947 	list_add_tail(&pxmitframe->list, &ptxservq->sta_pending.queue);
948 	ptxservq->qcnt++;
949 	spin_unlock_irqrestore(&pstapending->lock, irqL0);
950 	return _SUCCESS;
951 }
952 
alloc_hwxmits(struct _adapter * padapter)953 static void alloc_hwxmits(struct _adapter *padapter)
954 {
955 	struct hw_xmit *hwxmits;
956 	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
957 
958 	pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;
959 	pxmitpriv->hwxmits = kmalloc_array(pxmitpriv->hwxmit_entry,
960 				sizeof(struct hw_xmit), GFP_ATOMIC);
961 	if (pxmitpriv->hwxmits == NULL)
962 		return;
963 	hwxmits = pxmitpriv->hwxmits;
964 	if (pxmitpriv->hwxmit_entry == 5) {
965 		pxmitpriv->bmc_txqueue.head = 0;
966 		hwxmits[0] .phwtxqueue = &pxmitpriv->bmc_txqueue;
967 		hwxmits[0] .sta_queue = &pxmitpriv->bm_pending;
968 		pxmitpriv->vo_txqueue.head = 0;
969 		hwxmits[1] .phwtxqueue = &pxmitpriv->vo_txqueue;
970 		hwxmits[1] .sta_queue = &pxmitpriv->vo_pending;
971 	pxmitpriv->vi_txqueue.head = 0;
972 		hwxmits[2] .phwtxqueue = &pxmitpriv->vi_txqueue;
973 		hwxmits[2] .sta_queue = &pxmitpriv->vi_pending;
974 		pxmitpriv->bk_txqueue.head = 0;
975 		hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue;
976 		hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
977 		pxmitpriv->be_txqueue.head = 0;
978 		hwxmits[4] .phwtxqueue = &pxmitpriv->be_txqueue;
979 		hwxmits[4] .sta_queue = &pxmitpriv->be_pending;
980 	} else if (pxmitpriv->hwxmit_entry == 4) {
981 		pxmitpriv->vo_txqueue.head = 0;
982 		hwxmits[0] .phwtxqueue = &pxmitpriv->vo_txqueue;
983 		hwxmits[0] .sta_queue = &pxmitpriv->vo_pending;
984 		pxmitpriv->vi_txqueue.head = 0;
985 		hwxmits[1] .phwtxqueue = &pxmitpriv->vi_txqueue;
986 		hwxmits[1] .sta_queue = &pxmitpriv->vi_pending;
987 		pxmitpriv->be_txqueue.head = 0;
988 		hwxmits[2] .phwtxqueue = &pxmitpriv->be_txqueue;
989 		hwxmits[2] .sta_queue = &pxmitpriv->be_pending;
990 		pxmitpriv->bk_txqueue.head = 0;
991 		hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue;
992 		hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
993 	}
994 }
995 
free_hwxmits(struct _adapter * padapter)996 static void free_hwxmits(struct _adapter *padapter)
997 {
998 	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
999 
1000 	kfree(pxmitpriv->hwxmits);
1001 }
1002 
init_hwxmits(struct hw_xmit * phwxmit,sint entry)1003 static void init_hwxmits(struct hw_xmit *phwxmit, sint entry)
1004 {
1005 	sint i;
1006 
1007 	for (i = 0; i < entry; i++, phwxmit++) {
1008 		spin_lock_init(&phwxmit->xmit_lock);
1009 		INIT_LIST_HEAD(&phwxmit->pending);
1010 		phwxmit->txcmdcnt = 0;
1011 		phwxmit->accnt = 0;
1012 	}
1013 }
1014 
xmitframe_xmitbuf_attach(struct xmit_frame * pxmitframe,struct xmit_buf * pxmitbuf)1015 void xmitframe_xmitbuf_attach(struct xmit_frame *pxmitframe,
1016 			struct xmit_buf *pxmitbuf)
1017 {
1018 	/* pxmitbuf attach to pxmitframe */
1019 	pxmitframe->pxmitbuf = pxmitbuf;
1020 	/* urb and irp connection */
1021 	pxmitframe->pxmit_urb[0] = pxmitbuf->pxmit_urb[0];
1022 	/* buffer addr assoc */
1023 	pxmitframe->buf_addr = pxmitbuf->pbuf;
1024 	/* pxmitframe attach to pxmitbuf */
1025 	pxmitbuf->priv_data = pxmitframe;
1026 }
1027 
1028 /*
1029  * tx_action == 0 == no frames to transmit
1030  * tx_action > 0 ==> we have frames to transmit
1031  * tx_action < 0 ==> we have frames to transmit, but TXFF is not even enough
1032  *						 to transmit 1 frame.
1033  */
1034 
r8712_pre_xmit(struct _adapter * padapter,struct xmit_frame * pxmitframe)1035 int r8712_pre_xmit(struct _adapter *padapter, struct xmit_frame *pxmitframe)
1036 {
1037 	unsigned long irqL;
1038 	int ret;
1039 	struct xmit_buf *pxmitbuf = NULL;
1040 	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1041 	struct pkt_attrib *pattrib = &pxmitframe->attrib;
1042 
1043 	r8712_do_queue_select(padapter, pattrib);
1044 	spin_lock_irqsave(&pxmitpriv->lock, irqL);
1045 	if (r8712_txframes_sta_ac_pending(padapter, pattrib) > 0) {
1046 		ret = false;
1047 		r8712_xmit_enqueue(padapter, pxmitframe);
1048 		spin_unlock_irqrestore(&pxmitpriv->lock, irqL);
1049 		return ret;
1050 	}
1051 	pxmitbuf = r8712_alloc_xmitbuf(pxmitpriv);
1052 	if (pxmitbuf == NULL) { /*enqueue packet*/
1053 		ret = false;
1054 		r8712_xmit_enqueue(padapter, pxmitframe);
1055 		spin_unlock_irqrestore(&pxmitpriv->lock, irqL);
1056 	} else { /*dump packet directly*/
1057 		spin_unlock_irqrestore(&pxmitpriv->lock, irqL);
1058 		ret = true;
1059 		xmitframe_xmitbuf_attach(pxmitframe, pxmitbuf);
1060 		r8712_xmit_direct(padapter, pxmitframe);
1061 	}
1062 	return ret;
1063 }
1064