1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
15 #define _RTL8192C_XMIT_C_
16 #include <osdep_service.h>
17 #include <drv_types.h>
19 #include <osdep_intf.h>
21 /* include <rtl8192c_hal.h> */
22 #include <rtl8723a_hal.h>
24 static int urb_zero_packet_chk(struct rtw_adapter *padapter, int sz)
26 int blnSetTxDescOffset;
27 struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
29 if (pdvobj->ishighspeed) {
30 if (((sz + TXDESC_SIZE) % 512) == 0)
31 blnSetTxDescOffset = 1;
33 blnSetTxDescOffset = 0;
35 if (((sz + TXDESC_SIZE) % 64) == 0)
36 blnSetTxDescOffset = 1;
38 blnSetTxDescOffset = 0;
40 return blnSetTxDescOffset;
43 static void rtl8192cu_cal_txdesc_chksum(struct tx_desc *ptxdesc)
45 __le16 *usPtr = (__le16 *)ptxdesc;
46 u32 count = 16; /* (32 bytes / 2 bytes per XOR) => 16 times */
51 ptxdesc->txdw7 &= cpu_to_le32(0xffff0000);
53 for (index = 0 ; index < count ; index++)
54 checksum = checksum ^ le16_to_cpu(*(usPtr + index));
56 ptxdesc->txdw7 |= cpu_to_le32(0x0000ffff&checksum);
59 static void fill_txdesc_sectype(struct pkt_attrib *pattrib, struct tx_desc *ptxdesc)
61 if ((pattrib->encrypt > 0) && !pattrib->bswenc) {
62 switch (pattrib->encrypt) {
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 ptxdesc->txdw1 |= cpu_to_le32((0x01<<22)&0x00c00000);
68 case WLAN_CIPHER_SUITE_TKIP:
69 /* ptxdesc->txdw1 |= cpu_to_le32((0x02<<22)&0x00c00000); */
70 ptxdesc->txdw1 |= cpu_to_le32((0x01<<22)&0x00c00000);
72 case WLAN_CIPHER_SUITE_CCMP:
73 ptxdesc->txdw1 |= cpu_to_le32((0x03<<22)&0x00c00000);
82 static void fill_txdesc_vcs(struct pkt_attrib *pattrib, __le32 *pdw)
84 /* DBG_8723A("cvs_mode =%d\n", pattrib->vcs_mode); */
86 switch (pattrib->vcs_mode) {
88 *pdw |= cpu_to_le32(BIT(12));
91 *pdw |= cpu_to_le32(BIT(11));
98 if (pattrib->vcs_mode) {
99 *pdw |= cpu_to_le32(BIT(13));
102 if (pattrib->ht_en) {
103 *pdw |= (pattrib->bwmode&HT_CHANNEL_WIDTH_40) ? cpu_to_le32(BIT(27)) : 0;
105 if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
106 *pdw |= cpu_to_le32((0x01<<28)&0x30000000);
107 else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
108 *pdw |= cpu_to_le32((0x02<<28)&0x30000000);
109 else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)
112 *pdw |= cpu_to_le32((0x03<<28)&0x30000000);
117 static void fill_txdesc_phy(struct pkt_attrib *pattrib, __le32 *pdw)
119 if (pattrib->ht_en) {
120 *pdw |= (pattrib->bwmode&HT_CHANNEL_WIDTH_40) ? cpu_to_le32(BIT(25)) : 0;
122 if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
123 *pdw |= cpu_to_le32((0x01<<20)&0x003f0000);
124 else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
125 *pdw |= cpu_to_le32((0x02<<20)&0x003f0000);
126 else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)
129 *pdw |= cpu_to_le32((0x03<<20)&0x003f0000);
133 static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz)
137 struct rtw_adapter *padapter = pxmitframe->padapter;
138 struct pkt_attrib *pattrib = &pxmitframe->attrib;
139 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
140 struct dm_priv *pdmpriv = &pHalData->dmpriv;
141 struct tx_desc *ptxdesc = (struct tx_desc *)pmem;
142 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
143 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
144 int bmcst = is_multicast_ether_addr(pattrib->ra);
146 if (urb_zero_packet_chk(padapter, sz) == 0) {
147 ptxdesc = (struct tx_desc *)(pmem+PACKET_OFFSET_SZ);
149 pxmitframe->pkt_offset--;
152 memset(ptxdesc, 0, sizeof(struct tx_desc));
154 if (pxmitframe->frame_tag == DATA_FRAMETAG) {
156 ptxdesc->txdw1 |= cpu_to_le32(pattrib->mac_id&0x1f);
158 qsel = (uint)(pattrib->qsel & 0x0000001f);
159 ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00);
161 ptxdesc->txdw1 |= cpu_to_le32((pattrib->raid<<16) & 0x000f0000);
163 fill_txdesc_sectype(pattrib, ptxdesc);
165 if (pattrib->ampdu_en)
166 ptxdesc->txdw1 |= cpu_to_le32(BIT(5));/* AGG EN */
168 ptxdesc->txdw1 |= cpu_to_le32(BIT(6));/* AGG BK */
173 ptxdesc->txdw3 |= cpu_to_le32((pattrib->seqnum<<16)&0xffff0000);
175 /* offset 16 , offset 20 */
177 ptxdesc->txdw4 |= cpu_to_le32(BIT(6));/* QoS */
179 if ((pattrib->ether_type != 0x888e) &&
180 (pattrib->ether_type != 0x0806) &&
181 (pattrib->dhcp_pkt != 1)) {
182 /* Non EAP & ARP & DHCP type data packet */
184 fill_txdesc_vcs(pattrib, &ptxdesc->txdw4);
185 fill_txdesc_phy(pattrib, &ptxdesc->txdw4);
187 ptxdesc->txdw4 |= cpu_to_le32(0x00000008);/* RTS Rate = 24M */
188 ptxdesc->txdw5 |= cpu_to_le32(0x0001ff00);/* */
190 /* use REG_INIDATA_RATE_SEL value */
191 ptxdesc->txdw5 |= cpu_to_le32(pdmpriv->INIDATA_RATE[pattrib->mac_id]);
193 /* EAP data packet and ARP packet. */
194 /* Use the 1M data rate to send the EAP/ARP packet. */
195 /* This will maybe make the handshake smooth. */
197 ptxdesc->txdw1 |= cpu_to_le32(BIT(6));/* AGG BK */
199 ptxdesc->txdw4 |= cpu_to_le32(BIT(8));/* driver uses rate */
201 if (pmlmeinfo->preamble_mode == PREAMBLE_SHORT)
202 ptxdesc->txdw4 |= cpu_to_le32(BIT(24));/* DATA_SHORT */
204 ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate23a(pmlmeext->tx_rate));
206 } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) {
208 ptxdesc->txdw1 |= cpu_to_le32(pattrib->mac_id&0x1f);
210 qsel = (uint)(pattrib->qsel&0x0000001f);
211 ptxdesc->txdw1 |= cpu_to_le32((qsel<<QSEL_SHT)&0x00001f00);
213 ptxdesc->txdw1 |= cpu_to_le32((pattrib->raid<<16) & 0x000f0000);
216 /* CCX-TXRPT ack for xmit mgmt frames. */
217 if (pxmitframe->ack_report)
218 ptxdesc->txdw2 |= cpu_to_le32(BIT(19));
221 ptxdesc->txdw3 |= cpu_to_le32((pattrib->seqnum<<16)&0xffff0000);
224 ptxdesc->txdw4 |= cpu_to_le32(BIT(8));/* driver uses rate */
227 ptxdesc->txdw5 |= cpu_to_le32(BIT(17));/* retry limit enable */
228 ptxdesc->txdw5 |= cpu_to_le32(0x00180000);/* retry limit = 6 */
230 ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate23a(pmlmeext->tx_rate));
231 } else if (pxmitframe->frame_tag == TXAGG_FRAMETAG) {
232 DBG_8723A("pxmitframe->frame_tag == TXAGG_FRAMETAG\n");
234 DBG_8723A("pxmitframe->frame_tag = %d\n",
235 pxmitframe->frame_tag);
238 ptxdesc->txdw1 |= cpu_to_le32((4)&0x1f);/* CAM_ID(MAC_ID) */
240 ptxdesc->txdw1 |= cpu_to_le32((6<<16) & 0x000f0000);/* raid */
245 ptxdesc->txdw3 |= cpu_to_le32((pattrib->seqnum<<16)&0xffff0000);
248 ptxdesc->txdw4 |= cpu_to_le32(BIT(8));/* driver uses rate */
251 ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate23a(pmlmeext->tx_rate));
254 /* (1) The sequence number of each non-Qos frame / broadcast / multicast / */
255 /* mgnt frame should be controlled by Hw because Fw will also send null data */
256 /* which we cannot control when Fw LPS enable. */
257 /* --> default enable non-Qos data sequense number. 2010.06.23. by tynli. */
258 /* (2) Enable HW SEQ control for beacon packet, because we use Hw beacon. */
259 /* (3) Use HW Qos SEQ to control the seq num of Ext port non-Qos packets. */
260 if (!pattrib->qos_en) {
261 /* Hw set sequence number */
262 ptxdesc->txdw4 |= cpu_to_le32(BIT(7));
264 ptxdesc->txdw3 |= cpu_to_le32((8 << 28));
268 ptxdesc->txdw0 |= cpu_to_le32(sz&0x0000ffff);
269 ptxdesc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
270 ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE+OFFSET_SZ)<<OFFSET_SHT)&0x00ff0000);/* 32 bytes for TX Desc */
273 ptxdesc->txdw0 |= cpu_to_le32(BIT(24));
275 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
276 "offset0-txdesc = 0x%x\n", ptxdesc->txdw0);
279 /* pkt_offset, unit:8 bytes padding */
280 if (pxmitframe->pkt_offset > 0)
281 ptxdesc->txdw1 |= cpu_to_le32((pxmitframe->pkt_offset << 26) & 0x7c000000);
283 rtl8192cu_cal_txdesc_chksum(ptxdesc);
287 static int rtw_dump_xframe(struct rtw_adapter *padapter,
288 struct xmit_frame *pxmitframe)
291 int inner_ret = _SUCCESS;
292 int t, sz, w_sz, pull = 0;
295 struct xmit_buf *pxmitbuf = pxmitframe->pxmitbuf;
296 struct pkt_attrib *pattrib = &pxmitframe->attrib;
297 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
299 if (pxmitframe->frame_tag == DATA_FRAMETAG &&
300 pxmitframe->attrib.ether_type != ETH_P_ARP &&
301 pxmitframe->attrib.ether_type != ETH_P_PAE &&
302 pxmitframe->attrib.dhcp_pkt != 1)
303 rtw_issue_addbareq_cmd23a(padapter, pxmitframe);
305 mem_addr = pxmitframe->buf_addr;
307 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, "rtw_dump_xframe()\n");
309 for (t = 0; t < pattrib->nr_frags; t++) {
310 if (inner_ret != _SUCCESS && ret == _SUCCESS)
313 if (t != (pattrib->nr_frags - 1)) {
314 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
315 "pattrib->nr_frags =%d\n", pattrib->nr_frags);
317 sz = pxmitpriv->frag_len;
318 sz = sz - 4 - pattrib->icv_len;
321 sz = pattrib->last_txcmdsz;
324 pull = update_txdesc(pxmitframe, mem_addr, sz);
327 mem_addr += PACKET_OFFSET_SZ; /* pull txdesc head */
329 pxmitframe->buf_addr = mem_addr;
331 w_sz = sz + TXDESC_SIZE;
333 w_sz = sz + TXDESC_SIZE + PACKET_OFFSET_SZ;
336 ff_hwaddr = rtw_get_ff_hwaddr23a(pxmitframe);
337 inner_ret = rtl8723au_write_port(padapter, ff_hwaddr,
339 rtw_count_tx_stats23a(padapter, pxmitframe, sz);
341 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
342 "rtw_write_port, w_sz =%d\n", w_sz);
346 mem_addr = PTR_ALIGN(mem_addr, 4);
349 rtw_free_xmitframe23a(pxmitpriv, pxmitframe);
352 rtw23a_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_UNKNOWN);
357 bool rtl8723au_xmitframe_complete(struct rtw_adapter *padapter,
358 struct xmit_priv *pxmitpriv,
359 struct xmit_buf *pxmitbuf)
361 struct hw_xmit *phwxmits;
362 struct xmit_frame *pxmitframe;
364 int res = _SUCCESS, xcnt = 0;
366 phwxmits = pxmitpriv->hwxmits;
367 hwentry = pxmitpriv->hwxmit_entry;
369 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, "xmitframe_complete()\n");
371 if (pxmitbuf == NULL) {
372 pxmitbuf = rtw_alloc_xmitbuf23a(pxmitpriv);
376 pxmitframe = rtw_dequeue_xframe23a(pxmitpriv, phwxmits, hwentry);
379 pxmitframe->pxmitbuf = pxmitbuf;
381 pxmitframe->buf_addr = pxmitbuf->pbuf;
383 pxmitbuf->priv_data = pxmitframe;
385 if (pxmitframe->frame_tag == DATA_FRAMETAG) {
386 if (pxmitframe->attrib.priority <= 15)/* TID0~15 */
387 res = rtw_xmitframe_coalesce23a(padapter, pxmitframe->pkt, pxmitframe);
389 rtw_os_xmit_complete23a(padapter, pxmitframe);/* always return ndis_packet after rtw_xmitframe_coalesce23a */
392 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
393 "xmitframe_complete(): rtw_dump_xframe\n");
395 if (res == _SUCCESS) {
396 rtw_dump_xframe(padapter, pxmitframe);
398 rtw_free_xmitbuf23a(pxmitpriv, pxmitbuf);
399 rtw_free_xmitframe23a(pxmitpriv, pxmitframe);
403 rtw_free_xmitbuf23a(pxmitpriv, pxmitbuf);
409 static int xmitframe_direct(struct rtw_adapter *padapter,
410 struct xmit_frame *pxmitframe)
414 res = rtw_xmitframe_coalesce23a(padapter, pxmitframe->pkt, pxmitframe);
416 rtw_dump_xframe(padapter, pxmitframe);
422 * true dump packet directly
423 * false enqueue packet
425 bool rtl8723au_hal_xmit(struct rtw_adapter *padapter,
426 struct xmit_frame *pxmitframe)
429 struct xmit_buf *pxmitbuf = NULL;
430 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
431 struct pkt_attrib *pattrib = &pxmitframe->attrib;
432 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
434 pattrib->qsel = pattrib->priority;
435 spin_lock_bh(&pxmitpriv->lock);
437 #ifdef CONFIG_8723AU_AP_MODE
438 if (xmitframe_enqueue_for_sleeping_sta23a(padapter, pxmitframe)) {
439 struct sta_info *psta;
440 struct sta_priv *pstapriv = &padapter->stapriv;
442 spin_unlock_bh(&pxmitpriv->lock);
445 psta = pattrib->psta;
447 psta = rtw_get_stainfo23a(pstapriv, pattrib->ra);
450 if (psta->sleepq_len > (NR_XMITFRAME>>3))
451 wakeup_sta_to_xmit23a(padapter, psta);
458 if (rtw_txframes_sta_ac_pending23a(padapter, pattrib) > 0)
461 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == true)
464 pxmitbuf = rtw_alloc_xmitbuf23a(pxmitpriv);
465 if (pxmitbuf == NULL)
468 spin_unlock_bh(&pxmitpriv->lock);
470 pxmitframe->pxmitbuf = pxmitbuf;
471 pxmitframe->buf_addr = pxmitbuf->pbuf;
472 pxmitbuf->priv_data = pxmitframe;
474 if (xmitframe_direct(padapter, pxmitframe) != _SUCCESS) {
475 rtw_free_xmitbuf23a(pxmitpriv, pxmitbuf);
476 rtw_free_xmitframe23a(pxmitpriv, pxmitframe);
481 res = rtw_xmitframe_enqueue23a(padapter, pxmitframe);
482 spin_unlock_bh(&pxmitpriv->lock);
484 if (res != _SUCCESS) {
485 RT_TRACE(_module_xmit_osdep_c_, _drv_err_,
486 "pre_xmitframe: enqueue xmitframe fail\n");
487 rtw_free_xmitframe23a(pxmitpriv, pxmitframe);
489 /* Trick, make the statistics correct */
490 pxmitpriv->tx_pkts--;
491 pxmitpriv->tx_drop++;
497 int rtl8723au_mgnt_xmit(struct rtw_adapter *padapter,
498 struct xmit_frame *pmgntframe)
500 return rtw_dump_xframe(padapter, pmgntframe);
503 int rtl8723au_hal_xmitframe_enqueue(struct rtw_adapter *padapter,
504 struct xmit_frame *pxmitframe)
506 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
509 err = rtw_xmitframe_enqueue23a(padapter, pxmitframe);
510 if (err != _SUCCESS) {
511 rtw_free_xmitframe23a(pxmitpriv, pxmitframe);
513 /* Trick, make the statistics correct */
514 pxmitpriv->tx_pkts--;
515 pxmitpriv->tx_drop++;
517 tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);