/****************************************************************************** * * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * ******************************************************************************/ #define _RTL8192C_XMIT_C_ #include #include #include #include #include /* include */ #include static int urb_zero_packet_chk(struct rtw_adapter *padapter, int sz) { int blnSetTxDescOffset; struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter); if (pdvobj->ishighspeed) { if (((sz + TXDESC_SIZE) % 512) == 0) blnSetTxDescOffset = 1; else blnSetTxDescOffset = 0; } else { if (((sz + TXDESC_SIZE) % 64) == 0) blnSetTxDescOffset = 1; else blnSetTxDescOffset = 0; } return blnSetTxDescOffset; } static void rtl8192cu_cal_txdesc_chksum(struct tx_desc *ptxdesc) { __le16 *usPtr = (__le16 *)ptxdesc; u32 count = 16; /* (32 bytes / 2 bytes per XOR) => 16 times */ u32 index; u16 checksum = 0; /* Clear first */ ptxdesc->txdw7 &= cpu_to_le32(0xffff0000); for (index = 0 ; index < count ; index++) checksum = checksum ^ le16_to_cpu(*(usPtr + index)); ptxdesc->txdw7 |= cpu_to_le32(0x0000ffff&checksum); } static void fill_txdesc_sectype(struct pkt_attrib *pattrib, struct tx_desc *ptxdesc) { if ((pattrib->encrypt > 0) && !pattrib->bswenc) { switch (pattrib->encrypt) { /* SEC_TYPE */ case WLAN_CIPHER_SUITE_WEP40: case WLAN_CIPHER_SUITE_WEP104: ptxdesc->txdw1 |= cpu_to_le32((0x01<<22)&0x00c00000); break; case WLAN_CIPHER_SUITE_TKIP: /* ptxdesc->txdw1 |= cpu_to_le32((0x02<<22)&0x00c00000); */ ptxdesc->txdw1 |= cpu_to_le32((0x01<<22)&0x00c00000); break; case WLAN_CIPHER_SUITE_CCMP: ptxdesc->txdw1 |= cpu_to_le32((0x03<<22)&0x00c00000); break; case 0: default: break; } } } static void fill_txdesc_vcs(struct pkt_attrib *pattrib, __le32 *pdw) { /* DBG_8723A("cvs_mode =%d\n", pattrib->vcs_mode); */ switch (pattrib->vcs_mode) { case RTS_CTS: *pdw |= cpu_to_le32(BIT(12)); break; case CTS_TO_SELF: *pdw |= cpu_to_le32(BIT(11)); break; case NONE_VCS: default: break; } if (pattrib->vcs_mode) { *pdw |= cpu_to_le32(BIT(13)); /* Set RTS BW */ if (pattrib->ht_en) { *pdw |= (pattrib->bwmode&HT_CHANNEL_WIDTH_40) ? cpu_to_le32(BIT(27)) : 0; if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) *pdw |= cpu_to_le32((0x01<<28)&0x30000000); else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER) *pdw |= cpu_to_le32((0x02<<28)&0x30000000); else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) *pdw |= 0; else *pdw |= cpu_to_le32((0x03<<28)&0x30000000); } } } static void fill_txdesc_phy(struct pkt_attrib *pattrib, __le32 *pdw) { if (pattrib->ht_en) { *pdw |= (pattrib->bwmode&HT_CHANNEL_WIDTH_40) ? cpu_to_le32(BIT(25)) : 0; if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) *pdw |= cpu_to_le32((0x01<<20)&0x003f0000); else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER) *pdw |= cpu_to_le32((0x02<<20)&0x003f0000); else if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) *pdw |= 0; else *pdw |= cpu_to_le32((0x03<<20)&0x003f0000); } } static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz) { int pull = 0; uint qsel; struct rtw_adapter *padapter = pxmitframe->padapter; struct pkt_attrib *pattrib = &pxmitframe->attrib; struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter); struct dm_priv *pdmpriv = &pHalData->dmpriv; struct tx_desc *ptxdesc = (struct tx_desc *)pmem; struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; int bmcst = is_multicast_ether_addr(pattrib->ra); if (urb_zero_packet_chk(padapter, sz) == 0) { ptxdesc = (struct tx_desc *)(pmem+PACKET_OFFSET_SZ); pull = 1; pxmitframe->pkt_offset--; } memset(ptxdesc, 0, sizeof(struct tx_desc)); if (pxmitframe->frame_tag == DATA_FRAMETAG) { /* offset 4 */ ptxdesc->txdw1 |= cpu_to_le32(pattrib->mac_id&0x1f); qsel = (uint)(pattrib->qsel & 0x0000001f); ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00); ptxdesc->txdw1 |= cpu_to_le32((pattrib->raid<<16) & 0x000f0000); fill_txdesc_sectype(pattrib, ptxdesc); if (pattrib->ampdu_en) ptxdesc->txdw1 |= cpu_to_le32(BIT(5));/* AGG EN */ else ptxdesc->txdw1 |= cpu_to_le32(BIT(6));/* AGG BK */ /* offset 8 */ /* offset 12 */ ptxdesc->txdw3 |= cpu_to_le32((pattrib->seqnum<<16)&0xffff0000); /* offset 16 , offset 20 */ if (pattrib->qos_en) ptxdesc->txdw4 |= cpu_to_le32(BIT(6));/* QoS */ if ((pattrib->ether_type != 0x888e) && (pattrib->ether_type != 0x0806) && (pattrib->dhcp_pkt != 1)) { /* Non EAP & ARP & DHCP type data packet */ fill_txdesc_vcs(pattrib, &ptxdesc->txdw4); fill_txdesc_phy(pattrib, &ptxdesc->txdw4); ptxdesc->txdw4 |= cpu_to_le32(0x00000008);/* RTS Rate = 24M */ ptxdesc->txdw5 |= cpu_to_le32(0x0001ff00);/* */ /* use REG_INIDATA_RATE_SEL value */ ptxdesc->txdw5 |= cpu_to_le32(pdmpriv->INIDATA_RATE[pattrib->mac_id]); } else { /* EAP data packet and ARP packet. */ /* Use the 1M data rate to send the EAP/ARP packet. */ /* This will maybe make the handshake smooth. */ ptxdesc->txdw1 |= cpu_to_l
<