1 /******************************************************************************
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU
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.
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
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
20 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved.
23 * Contact information:
27 ******************************************************************************/
29 #define _RTL8712_XMIT_C_
31 #include "osdep_service.h"
32 #include "drv_types.h"
34 #include "osdep_intf.h"
37 static void dump_xframe(struct _adapter *padapter,
38 struct xmit_frame *pxmitframe);
39 static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz);
41 sint _r8712_init_hw_txqueue(struct hw_txqueue *phw_txqueue, u8 ac_tag)
43 phw_txqueue->ac_tag = ac_tag;
46 phw_txqueue->ff_hwaddr = RTL8712_DMA_BEQ;
49 phw_txqueue->ff_hwaddr = RTL8712_DMA_BKQ;
52 phw_txqueue->ff_hwaddr = RTL8712_DMA_VIQ;
55 phw_txqueue->ff_hwaddr = RTL8712_DMA_VOQ;
58 phw_txqueue->ff_hwaddr = RTL8712_DMA_BEQ;
64 int r8712_txframes_sta_ac_pending(struct _adapter *padapter,
65 struct pkt_attrib *pattrib)
67 struct sta_info *psta;
68 struct tx_servq *ptxservq;
69 int priority = pattrib->priority;
75 ptxservq = &(psta->sta_xmitpriv.bk_q);
79 ptxservq = &(psta->sta_xmitpriv.vi_q);
83 ptxservq = &(psta->sta_xmitpriv.vo_q);
88 ptxservq = &(psta->sta_xmitpriv.be_q);
91 return ptxservq->qcnt;
94 static u32 get_ff_hwaddr(struct xmit_frame *pxmitframe)
97 struct pkt_attrib *pattrib = &pxmitframe->attrib;
98 struct _adapter *padapter = pxmitframe->padapter;
99 struct dvobj_priv *pdvobj = (struct dvobj_priv *)&padapter->dvobjpriv;
101 if (pxmitframe->frame_tag == TXAGG_FRAMETAG)
102 addr = RTL8712_DMA_H2CCMD;
103 else if (pxmitframe->frame_tag == MGNT_FRAMETAG)
104 addr = RTL8712_DMA_MGTQ;
105 else if (pdvobj->nr_endpoint == 6) {
106 switch (pattrib->priority) {
109 addr = RTL8712_DMA_BEQ;
113 addr = RTL8712_DMA_BKQ;
117 addr = RTL8712_DMA_VIQ;
121 addr = RTL8712_DMA_VOQ;
127 addr = RTL8712_DMA_H2CCMD;
130 addr = RTL8712_DMA_BEQ;
133 } else if (pdvobj->nr_endpoint == 4) {
134 switch (pattrib->qsel) {
139 addr = RTL8712_DMA_BEQ;/*RTL8712_EP_LO;*/
145 addr = RTL8712_DMA_VOQ;/*RTL8712_EP_HI;*/
151 addr = RTL8712_DMA_H2CCMD;
154 addr = RTL8712_DMA_BEQ;/*RTL8712_EP_LO;*/
161 static struct xmit_frame *dequeue_one_xmitframe(struct xmit_priv *pxmitpriv,
162 struct hw_xmit *phwxmit,
163 struct tx_servq *ptxservq,
164 struct __queue *pframe_queue)
166 struct list_head *xmitframe_plist, *xmitframe_phead;
167 struct xmit_frame *pxmitframe = NULL;
169 xmitframe_phead = get_list_head(pframe_queue);
170 xmitframe_plist = get_next(xmitframe_phead);
171 if ((end_of_queue_search(xmitframe_phead, xmitframe_plist)) == false) {
172 pxmitframe = LIST_CONTAINOR(xmitframe_plist,
173 struct xmit_frame, list);
174 list_delete(&pxmitframe->list);
181 static struct xmit_frame *dequeue_xframe_ex(struct xmit_priv *pxmitpriv,
182 struct hw_xmit *phwxmit_i, sint entry)
185 struct list_head *sta_plist, *sta_phead;
186 struct hw_xmit *phwxmit;
187 struct tx_servq *ptxservq = NULL;
188 struct __queue *pframe_queue = NULL;
189 struct xmit_frame *pxmitframe = NULL;
191 int j, tmp, acirp_cnt[4];
193 /*entry indx: 0->vo, 1->vi, 2->be, 3->bk.*/
194 inx[0] = 0; acirp_cnt[0] = pxmitpriv->voq_cnt;
195 inx[1] = 1; acirp_cnt[1] = pxmitpriv->viq_cnt;
196 inx[2] = 2; acirp_cnt[2] = pxmitpriv->beq_cnt;
197 inx[3] = 3; acirp_cnt[3] = pxmitpriv->bkq_cnt;
198 for (i = 0; i < 4; i++) {
199 for (j = i + 1; j < 4; j++) {
200 if (acirp_cnt[j] < acirp_cnt[i]) {
202 acirp_cnt[i] = acirp_cnt[j];
210 spin_lock_irqsave(&pxmitpriv->lock, irqL0);
211 for (i = 0; i < entry; i++) {
212 phwxmit = phwxmit_i + inx[i];
213 sta_phead = get_list_head(phwxmit->sta_queue);
214 sta_plist = get_next(sta_phead);
215 while ((end_of_queue_search(sta_phead, sta_plist)) == false) {
216 ptxservq = LIST_CONTAINOR(sta_plist, struct tx_servq,
218 pframe_queue = &ptxservq->sta_pending;
219 pxmitframe = dequeue_one_xmitframe(pxmitpriv, phwxmit,
220 ptxservq, pframe_queue);
223 goto exit_dequeue_xframe_ex;
225 sta_plist = get_next(sta_plist);
226 /*Remove sta node when there are no pending packets.*/
227 if (_queue_empty(pframe_queue)) {
228 /*must be done after get_next and before break*/
229 list_delete(&ptxservq->tx_pending);
233 exit_dequeue_xframe_ex:
234 spin_unlock_irqrestore(&pxmitpriv->lock, irqL0);
238 void r8712_do_queue_select(struct _adapter *padapter,
239 struct pkt_attrib *pattrib)
241 unsigned int qsel = 0;
242 struct dvobj_priv *pdvobj = (struct dvobj_priv *)&padapter->dvobjpriv;
244 if (pdvobj->nr_endpoint == 6)
245 qsel = (unsigned int) pattrib->priority;
246 else if (pdvobj->nr_endpoint == 4) {
247 qsel = (unsigned int) pattrib->priority;
248 if (qsel == 0 || qsel == 3)
250 else if (qsel == 1 || qsel == 2)
252 else if (qsel == 4 || qsel == 5)
254 else if (qsel == 6 || qsel == 7)
259 pattrib->qsel = qsel;
262 #ifdef CONFIG_R8712_TX_AGGR
263 u8 r8712_construct_txaggr_cmd_desc(struct xmit_buf *pxmitbuf)
265 struct tx_desc *ptx_desc = (struct tx_desc *)pxmitbuf->pbuf;
267 /* Fill up TxCmd Descriptor according as USB FW Tx Aaggregation info.*/
269 ptx_desc->txdw0 = cpu_to_le32(CMD_HDR_SZ&0xffff);
271 cpu_to_le32(((TXDESC_SIZE+OFFSET_SZ)<<OFFSET_SHT)&0x00ff0000);
272 ptx_desc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
275 ptx_desc->txdw1 |= cpu_to_le32((0x13<<QSEL_SHT)&0x00001f00);
280 u8 r8712_construct_txaggr_cmd_hdr(struct xmit_buf *pxmitbuf)
282 struct xmit_frame *pxmitframe = (struct xmit_frame *)
284 struct _adapter *padapter = pxmitframe->padapter;
285 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
286 struct cmd_hdr *pcmd_hdr = (struct cmd_hdr *)
287 (pxmitbuf->pbuf + TXDESC_SIZE);
289 /* Fill up Cmd Header for USB FW Tx Aggregation.*/
291 pcmd_hdr->cmd_dw0 = cpu_to_le32((GEN_CMD_CODE(_AMSDU_TO_AMPDU) << 16) |
292 (pcmdpriv->cmd_seq << 24));
298 u8 r8712_append_mpdu_unit(struct xmit_buf *pxmitbuf,
299 struct xmit_frame *pxmitframe)
301 struct _adapter *padapter = pxmitframe->padapter;
302 struct tx_desc *ptx_desc = (struct tx_desc *)pxmitbuf->pbuf;
303 int last_txcmdsz = 0;
306 /* 802.3->802.11 convertor */
307 r8712_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
308 /* free skb struct */
309 r8712_xmit_complete(padapter, pxmitframe);
310 if (pxmitframe->attrib.ether_type != 0x0806) {
311 if ((pxmitframe->attrib.ether_type != 0x888e) &&
312 (pxmitframe->attrib.dhcp_pkt != 1)) {
313 r8712_issue_addbareq_cmd(padapter,
314 pxmitframe->attrib.priority);
317 pxmitframe->last[0] = 1;
318 update_txdesc(pxmitframe, (uint *)(pxmitframe->buf_addr),
319 pxmitframe->attrib.last_txcmdsz);
321 last_txcmdsz = pxmitframe->attrib.last_txcmdsz;
322 padding_sz = (8 - (last_txcmdsz % 8));
323 if ((last_txcmdsz % 8) != 0) {
325 for (i = 0; i < padding_sz; i++)
326 *(pxmitframe->buf_addr+TXDESC_SIZE+last_txcmdsz+i) = 0;
328 /* Add the new mpdu's length */
329 ptx_desc->txdw0 = cpu_to_le32((ptx_desc->txdw0&0xffff0000) |
330 ((ptx_desc->txdw0&0x0000ffff)+
331 ((TXDESC_SIZE+last_txcmdsz+padding_sz)&0x0000ffff)));
337 u8 r8712_xmitframe_aggr_1st(struct xmit_buf *pxmitbuf,
338 struct xmit_frame *pxmitframe)
340 /* linux complete context doesnt need to protect */
341 pxmitframe->pxmitbuf = pxmitbuf;
342 pxmitbuf->priv_data = pxmitframe;
343 pxmitframe->pxmit_urb[0] = pxmitbuf->pxmit_urb[0];
344 /* buffer addr assoc */
345 pxmitframe->buf_addr = pxmitbuf->pbuf+TXDESC_SIZE+CMD_HDR_SZ;
346 /*RTL8712_DMA_H2CCMD */
347 r8712_construct_txaggr_cmd_desc(pxmitbuf);
348 r8712_construct_txaggr_cmd_hdr(pxmitbuf);
349 if (r8712_append_mpdu_unit(pxmitbuf, pxmitframe) == _SUCCESS)
350 pxmitbuf->aggr_nr = 1;
355 u16 r8712_xmitframe_aggr_next(struct xmit_buf *pxmitbuf,
356 struct xmit_frame *pxmitframe)
358 pxmitframe->pxmitbuf = pxmitbuf;
359 pxmitbuf->priv_data = pxmitframe;
360 pxmitframe->pxmit_urb[0] = pxmitbuf->pxmit_urb[0];
361 /* buffer addr assoc */
362 pxmitframe->buf_addr = pxmitbuf->pbuf + TXDESC_SIZE +
363 (((struct tx_desc *)pxmitbuf->pbuf)->txdw0 & 0x0000ffff);
364 if (r8712_append_mpdu_unit(pxmitbuf, pxmitframe) == _SUCCESS) {
365 r8712_free_xmitframe_ex(&pxmitframe->padapter->xmitpriv,
371 (((struct tx_desc *)pxmitbuf->pbuf)->txdw0 & 0x0000ffff);
374 u8 r8712_dump_aggr_xframe(struct xmit_buf *pxmitbuf,
375 struct xmit_frame *pxmitframe)
377 struct _adapter *padapter = pxmitframe->padapter;
378 struct dvobj_priv *pdvobj = (struct dvobj_priv *) &padapter->dvobjpriv;
379 struct tx_desc *ptxdesc = (struct tx_desc *)pxmitbuf->pbuf;
380 struct cmd_hdr *pcmd_hdr = (struct cmd_hdr *)
381 (pxmitbuf->pbuf + TXDESC_SIZE);
382 u16 total_length = (u16) (ptxdesc->txdw0 & 0xffff);
384 /* use 1st xmitframe as media */
385 xmitframe_xmitbuf_attach(pxmitframe, pxmitbuf);
386 pcmd_hdr->cmd_dw0 = cpu_to_le32(((total_length-CMD_HDR_SZ)&0x0000ffff)|
387 (pcmd_hdr->cmd_dw0&0xffff0000));
389 /* urb length in cmd_dw1 */
390 pcmd_hdr->cmd_dw1 = cpu_to_le32((pxmitbuf->aggr_nr & 0xff)|
391 ((total_length+TXDESC_SIZE) << 16));
392 pxmitframe->last[0] = 1;
393 pxmitframe->bpending[0] = false;
394 pxmitframe->mem_addr = pxmitbuf->pbuf;
396 if ((pdvobj->ishighspeed && ((total_length+TXDESC_SIZE)%0x200) == 0) ||
397 ((!pdvobj->ishighspeed &&
398 ((total_length+TXDESC_SIZE)%0x40) == 0))) {
399 ptxdesc->txdw0 |= cpu_to_le32
400 (((TXDESC_SIZE+OFFSET_SZ+8)<<OFFSET_SHT)&0x00ff0000);
401 /*32 bytes for TX Desc + 8 bytes pending*/
403 ptxdesc->txdw0 |= cpu_to_le32
404 (((TXDESC_SIZE+OFFSET_SZ)<<OFFSET_SHT)&0x00ff0000);
405 /*default = 32 bytes for TX Desc*/
407 r8712_write_port(pxmitframe->padapter, RTL8712_DMA_H2CCMD,
408 total_length+TXDESC_SIZE, (u8 *)pxmitframe);
415 static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz)
418 struct _adapter *padapter = pxmitframe->padapter;
419 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
420 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
421 struct security_priv *psecuritypriv = &padapter->securitypriv;
422 struct pkt_attrib *pattrib = &pxmitframe->attrib;
423 struct tx_desc *ptxdesc = (struct tx_desc *)pmem;
424 struct dvobj_priv *pdvobj = (struct dvobj_priv *)&padapter->dvobjpriv;
425 #ifdef CONFIG_R8712_TX_AGGR
426 struct cmd_priv *pcmdpriv = (struct cmd_priv *)&padapter->cmdpriv;
428 u8 blnSetTxDescOffset;
429 sint bmcst = IS_MCAST(pattrib->ra);
430 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
431 struct tx_desc txdesc_mp;
433 memcpy(&txdesc_mp, ptxdesc, sizeof(struct tx_desc));
434 memset(ptxdesc, 0, sizeof(struct tx_desc));
436 ptxdesc->txdw0 |= cpu_to_le32(sz&0x0000ffff);
437 if (pdvobj->ishighspeed) {
438 if (((sz + TXDESC_SIZE) % 512) == 0)
439 blnSetTxDescOffset = 1;
441 blnSetTxDescOffset = 0;
443 if (((sz + TXDESC_SIZE) % 64) == 0)
444 blnSetTxDescOffset = 1;
446 blnSetTxDescOffset = 0;
448 if (blnSetTxDescOffset) {
449 /* 32 bytes for TX Desc + 8 bytes pending */
450 ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE+OFFSET_SZ + 8) <<
451 OFFSET_SHT) & 0x00ff0000);
453 /* default = 32 bytes for TX Desc */
454 ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE+OFFSET_SZ) <<
455 OFFSET_SHT) & 0x00ff0000);
457 ptxdesc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
458 if (pxmitframe->frame_tag == DATA_FRAMETAG) {
460 ptxdesc->txdw1 |= cpu_to_le32((pattrib->mac_id)&0x1f);
462 #ifdef CONFIG_R8712_TX_AGGR
463 /* dirty workaround, need to check if it is aggr cmd. */
464 if ((u8 *)pmem != (u8 *)pxmitframe->pxmitbuf->pbuf) {
465 ptxdesc->txdw0 |= cpu_to_le32
466 ((0x3 << TYPE_SHT)&TYPE_MSK);
467 qsel = (uint)(pattrib->qsel & 0x0000001f);
470 ptxdesc->txdw1 |= cpu_to_le32
471 ((qsel << QSEL_SHT) & 0x00001f00);
472 ptxdesc->txdw2 = cpu_to_le32
473 ((qsel << RTS_RC_SHT)&0x001f0000);
474 ptxdesc->txdw6 |= cpu_to_le32
475 ((0x5 << RSVD6_SHT)&RSVD6_MSK);
477 ptxdesc->txdw0 |= cpu_to_le32
478 ((0x3 << TYPE_SHT)&TYPE_MSK);
479 ptxdesc->txdw1 |= cpu_to_le32
480 ((0x13 << QSEL_SHT) & 0x00001f00);
481 qsel = (uint)(pattrib->qsel & 0x0000001f);
484 ptxdesc->txdw2 = cpu_to_le32
485 ((qsel << RTS_RC_SHT)&0x0001f000);
486 ptxdesc->txdw7 |= cpu_to_le32
487 (pcmdpriv->cmd_seq << 24);
490 pattrib->qsel = 0x13;
492 qsel = (uint)(pattrib->qsel & 0x0000001f);
493 ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00);
495 if (!pqospriv->qos_option)
496 ptxdesc->txdw1 |= cpu_to_le32(BIT(16));/*Non-QoS*/
497 if ((pattrib->encrypt > 0) && !pattrib->bswenc) {
498 switch (pattrib->encrypt) { /*SEC_TYPE*/
501 ptxdesc->txdw1 |= cpu_to_le32((0x01 << 22) &
503 /*KEY_ID when WEP is used;*/
504 ptxdesc->txdw1 |= cpu_to_le32((psecuritypriv->
505 PrivacyKeyIndex << 17) &
510 ptxdesc->txdw1 |= cpu_to_le32((0x02 << 22) &
514 ptxdesc->txdw1 |= cpu_to_le32((0x03 << 22) &
524 ptxdesc->txdw2 |= cpu_to_le32(BMC);
527 /* f/w will increase the seqnum by itself, driver pass the
528 * correct priority to fw
529 * fw will check the correct priority for increasing the
530 * seqnum per tid. about usb using 4-endpoint, qsel points out
531 * the correct mapping between AC&Endpoint,
532 * the purpose is that correct mapping lets the MAC release
533 * the AC Queue list correctly. */
534 ptxdesc->txdw3 = cpu_to_le32((pattrib->priority << SEQ_SHT) &
536 if ((pattrib->ether_type != 0x888e) &&
537 (pattrib->ether_type != 0x0806) &&
538 (pattrib->dhcp_pkt != 1)) {
539 /*Not EAP & ARP type data packet*/
540 if (phtpriv->ht_option == 1) { /*B/G/N Mode*/
541 if (phtpriv->ampdu_enable != true)
542 ptxdesc->txdw2 |= cpu_to_le32(BK);
545 /* EAP data packet and ARP packet.
546 * Use the 1M data rate to send the EAP/ARP packet.
547 * This will maybe make the handshake smooth.
549 /*driver uses data rate*/
550 ptxdesc->txdw4 = cpu_to_le32(0x80000000);
551 ptxdesc->txdw5 = cpu_to_le32(0x001f8000);/*1M*/
553 if (pattrib->pctrl == 1) { /* mp tx packets */
554 struct tx_desc *ptxdesc_mp;
555 ptxdesc_mp = &txdesc_mp;
557 ptxdesc->txdw2 = cpu_to_le32(ptxdesc_mp->txdw2);
559 ptxdesc->txdw2 |= cpu_to_le32(BMC);
560 ptxdesc->txdw2 |= cpu_to_le32(BK);
562 ptxdesc->txdw4 = cpu_to_le32(ptxdesc_mp->txdw4);
564 ptxdesc->txdw5 = cpu_to_le32(ptxdesc_mp->txdw5);
565 pattrib->pctrl = 0;/* reset to zero; */
567 } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) {
569 ptxdesc->txdw1 |= (0x05) & 0x1f;/*CAM_ID(MAC_ID), default=5;*/
570 qsel = (uint)(pattrib->qsel & 0x0000001f);
571 ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00);
572 ptxdesc->txdw1 |= cpu_to_le32(BIT(16));/* Non-QoS */
575 ptxdesc->txdw2 |= cpu_to_le32(BMC);
577 /* f/w will increase the seqnum by itself, driver pass the
578 * correct priority to fw
579 * fw will check the correct priority for increasing the seqnum
580 * per tid. about usb using 4-endpoint, qsel points out the
581 * correct mapping between AC&Endpoint,
582 * the purpose is that correct mapping let the MAC releases
583 * the AC Queue list correctly. */
584 ptxdesc->txdw3 = cpu_to_le32((pattrib->priority << SEQ_SHT) &
587 ptxdesc->txdw4 = cpu_to_le32(0x80002040);/*gtest*/
589 ptxdesc->txdw5 = cpu_to_le32(0x001f8000);/* gtest 1M */
590 } else if (pxmitframe->frame_tag == TXAGG_FRAMETAG) {
593 ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00);
596 qsel = (uint)(pattrib->priority&0x0000001f);
597 ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00);
600 ptxdesc->txdw3 = cpu_to_le32((pattrib->seqnum << SEQ_SHT) &
603 ptxdesc->txdw4 = cpu_to_le32(0x80002040);/*gtest*/
605 ptxdesc->txdw5 = cpu_to_le32(0x001f9600);/*gtest*/
609 int r8712_xmitframe_complete(struct _adapter *padapter,
610 struct xmit_priv *pxmitpriv,
611 struct xmit_buf *pxmitbuf)
613 struct hw_xmit *phwxmits;
615 struct xmit_frame *pxmitframe = NULL;
616 #ifdef CONFIG_R8712_TX_AGGR
617 struct xmit_frame *p2ndxmitframe = NULL;
619 int res = _SUCCESS, xcnt = 0;
622 phwxmits = pxmitpriv->hwxmits;
623 hwentry = pxmitpriv->hwxmit_entry;
624 if (pxmitbuf == NULL) {
625 pxmitbuf = r8712_alloc_xmitbuf(pxmitpriv);
628 #ifdef CONFIG_R8712_TX_AGGR
629 pxmitbuf->aggr_nr = 0;
632 /* 1st frame dequeued */
633 pxmitframe = dequeue_xframe_ex(pxmitpriv, phwxmits, hwentry);
634 /* need to remember the 1st frame */
635 if (pxmitframe != NULL) {
637 #ifdef CONFIG_R8712_TX_AGGR
638 /* 1. dequeue 2nd frame
639 * 2. aggr if 2nd xframe is dequeued, else dump directly
641 if (AGGR_NR_HIGH_BOUND > 1)
642 p2ndxmitframe = dequeue_xframe_ex(pxmitpriv, phwxmits,
644 if (pxmitframe->frame_tag != DATA_FRAMETAG) {
645 r8712_free_xmitbuf(pxmitpriv, pxmitbuf);
648 if (p2ndxmitframe != NULL)
649 if (p2ndxmitframe->frame_tag != DATA_FRAMETAG) {
650 r8712_free_xmitbuf(pxmitpriv, pxmitbuf);
653 r8712_xmitframe_aggr_1st(pxmitbuf, pxmitframe);
654 if (p2ndxmitframe != NULL) {
656 total_length = r8712_xmitframe_aggr_next(
657 pxmitbuf, p2ndxmitframe);
659 p2ndxmitframe = dequeue_xframe_ex(
660 pxmitpriv, phwxmits, hwentry);
661 if (p2ndxmitframe != NULL)
663 r8712_xmitframe_aggr_next(
668 } while (total_length <= 0x1800 &&
669 pxmitbuf->aggr_nr <= AGGR_NR_HIGH_BOUND);
671 if (pxmitbuf->aggr_nr > 0)
672 r8712_dump_aggr_xframe(pxmitbuf, pxmitframe);
676 xmitframe_xmitbuf_attach(pxmitframe, pxmitbuf);
677 if (pxmitframe->frame_tag == DATA_FRAMETAG) {
678 if (pxmitframe->attrib.priority <= 15)
679 res = r8712_xmitframe_coalesce(padapter,
680 pxmitframe->pkt, pxmitframe);
681 /* always return ndis_packet after
682 * r8712_xmitframe_coalesce */
683 r8712_xmit_complete(padapter, pxmitframe);
686 dump_xframe(padapter, pxmitframe);
688 r8712_free_xmitframe_ex(pxmitpriv, pxmitframe);
692 } else { /* pxmitframe == NULL && p2ndxmitframe == NULL */
693 r8712_free_xmitbuf(pxmitpriv, pxmitbuf);
699 static void dump_xframe(struct _adapter *padapter,
700 struct xmit_frame *pxmitframe)
705 struct pkt_attrib *pattrib = &pxmitframe->attrib;
706 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
707 struct security_priv *psecuritypriv = &padapter->securitypriv;
709 if (pxmitframe->attrib.ether_type != 0x0806) {
710 if (pxmitframe->attrib.ether_type != 0x888e)
711 r8712_issue_addbareq_cmd(padapter, pattrib->priority);
713 mem_addr = pxmitframe->buf_addr;
714 for (t = 0; t < pattrib->nr_frags; t++) {
715 if (t != (pattrib->nr_frags - 1)) {
716 sz = pxmitpriv->frag_len;
717 sz = sz - 4 - (psecuritypriv->sw_encrypt ? 0 :
719 pxmitframe->last[t] = 0;
721 sz = pattrib->last_txcmdsz;
722 pxmitframe->last[t] = 1;
724 update_txdesc(pxmitframe, (uint *)mem_addr, sz);
725 w_sz = sz + TXDESC_SIZE;
726 pxmitframe->mem_addr = mem_addr;
727 pxmitframe->bpending[t] = false;
728 ff_hwaddr = get_ff_hwaddr(pxmitframe);
729 #ifdef CONFIG_R8712_TX_AGGR
730 r8712_write_port(padapter, RTL8712_DMA_H2CCMD, w_sz,
731 (unsigned char *)pxmitframe);
733 r8712_write_port(padapter, ff_hwaddr, w_sz,
734 (unsigned char *)pxmitframe);
737 mem_addr = (u8 *)RND4(((addr_t)(mem_addr)));
741 int r8712_xmit_direct(struct _adapter *padapter, struct xmit_frame *pxmitframe)
745 res = r8712_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
746 pxmitframe->pkt = NULL;
748 dump_xframe(padapter, pxmitframe);
752 int r8712_xmit_enqueue(struct _adapter *padapter, struct xmit_frame *pxmitframe)
754 if (r8712_xmit_classifier(padapter, pxmitframe) == _FAIL) {
755 pxmitframe->pkt = NULL;