rtl8188eu/os_dep/xmit_linux.c
Larry Finger 327817d32a rtl8188eu: Fix most sparse warnings other than endedness problems
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
2013-06-03 14:52:18 -05:00

436 lines
11 KiB
C

/******************************************************************************
*
* Copyright(c) 2007 - 2012 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.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#define _XMIT_OSDEP_C_
#include <drv_conf.h>
#include <osdep_service.h>
#include <drv_types.h>
#include <if_ether.h>
#include <ip.h>
#include <wifi.h>
#include <mlme_osdep.h>
#include <xmit_osdep.h>
#include <osdep_intf.h>
#include <circ_buf.h>
#include <usb_osintf.h>
uint rtw_remainder_len(struct pkt_file *pfile)
{
return (pfile->buf_len - ((SIZE_PTR)(pfile->cur_addr) - (SIZE_PTR)(pfile->buf_start)));
}
void _rtw_open_pktfile (_pkt *pktptr, struct pkt_file *pfile)
{
_func_enter_;
pfile->pkt = pktptr;
pfile->cur_addr = pfile->buf_start = pktptr->data;
pfile->pkt_len = pfile->buf_len = pktptr->len;
pfile->cur_buffer = pfile->buf_start ;
_func_exit_;
}
uint _rtw_pktfile_read (struct pkt_file *pfile, u8 *rmem, uint rlen)
{
uint len = 0;
_func_enter_;
len = rtw_remainder_len(pfile);
len = (rlen > len)? len: rlen;
if (rmem)
skb_copy_bits(pfile->pkt, pfile->buf_len-pfile->pkt_len, rmem, len);
pfile->cur_addr += len;
pfile->pkt_len -= len;
_func_exit_;
return len;
}
sint rtw_endofpktfile(struct pkt_file *pfile)
{
_func_enter_;
if (pfile->pkt_len == 0) {
_func_exit_;
return true;
}
_func_exit_;
return false;
}
void rtw_set_tx_chksum_offload(_pkt *pkt, struct pkt_attrib *pattrib)
{
#ifdef CONFIG_TCP_CSUM_OFFLOAD_TX
struct sk_buff *skb = (struct sk_buff *)pkt;
pattrib->hw_tcp_csum = 0;
if (skb->ip_summed == CHECKSUM_PARTIAL) {
if (skb_shinfo(skb)->nr_frags == 0)
{
const struct iphdr *ip = ip_hdr(skb);
if (ip->protocol == IPPROTO_TCP) {
// TCP checksum offload by HW
DBG_88E("CHECKSUM_PARTIAL TCP\n");
pattrib->hw_tcp_csum = 1;
//skb_checksum_help(skb);
} else if (ip->protocol == IPPROTO_UDP) {
//DBG_88E("CHECKSUM_PARTIAL UDP\n");
#if 1
skb_checksum_help(skb);
#else
// Set UDP checksum = 0 to skip checksum check
struct udphdr *udp = skb_transport_header(skb);
udp->check = 0;
#endif
} else {
DBG_88E("%s-%d TCP CSUM offload Error!!\n", __func__, __LINE__);
WARN_ON(1); /* we need a WARN() */
}
}
else { // IP fragmentation case
DBG_88E("%s-%d nr_frags != 0, using skb_checksum_help(skb);!!\n", __func__, __LINE__);
skb_checksum_help(skb);
}
}
#endif
}
int rtw_os_xmit_resource_alloc(_adapter *padapter, struct xmit_buf *pxmitbuf,u32 alloc_sz)
{
#ifdef CONFIG_USB_HCI
int i;
struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
struct usb_device *pusbd = pdvobjpriv->pusbdev;
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_TX
pxmitbuf->pallocated_buf = rtw_usb_buffer_alloc(pusbd, (size_t)alloc_sz, &pxmitbuf->dma_transfer_addr);
pxmitbuf->pbuf = pxmitbuf->pallocated_buf;
if (pxmitbuf->pallocated_buf == NULL)
return _FAIL;
#else // CONFIG_USE_USB_BUFFER_ALLOC_TX
pxmitbuf->pallocated_buf = rtw_zmalloc(alloc_sz);
if (pxmitbuf->pallocated_buf == NULL)
{
return _FAIL;
}
pxmitbuf->pbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitbuf->pallocated_buf), XMITBUF_ALIGN_SZ);
pxmitbuf->dma_transfer_addr = 0;
#endif // CONFIG_USE_USB_BUFFER_ALLOC_TX
for (i=0; i<8; i++)
{
pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
if (pxmitbuf->pxmit_urb[i] == NULL)
{
DBG_88E("pxmitbuf->pxmit_urb[i]==NULL");
return _FAIL;
}
}
#endif
#if defined(CONFIG_PCI_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
pxmitbuf->pallocated_buf = rtw_zmalloc(alloc_sz);
if (pxmitbuf->pallocated_buf == NULL)
{
return _FAIL;
}
pxmitbuf->pbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitbuf->pallocated_buf), XMITBUF_ALIGN_SZ);
#endif
return _SUCCESS;
}
void rtw_os_xmit_resource_free(_adapter *padapter, struct xmit_buf *pxmitbuf,u32 free_sz)
{
#ifdef CONFIG_USB_HCI
int i;
struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
struct usb_device *pusbd = pdvobjpriv->pusbdev;
for (i=0; i<8; i++)
{
if (pxmitbuf->pxmit_urb[i])
{
//usb_kill_urb(pxmitbuf->pxmit_urb[i]);
usb_free_urb(pxmitbuf->pxmit_urb[i]);
}
}
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_TX
rtw_usb_buffer_free(pusbd, (size_t)free_sz, pxmitbuf->pallocated_buf, pxmitbuf->dma_transfer_addr);
pxmitbuf->pallocated_buf = NULL;
pxmitbuf->dma_transfer_addr = 0;
#else // CONFIG_USE_USB_BUFFER_ALLOC_TX
if (pxmitbuf->pallocated_buf)
rtw_mfree(pxmitbuf->pallocated_buf, free_sz);
#endif // CONFIG_USE_USB_BUFFER_ALLOC_TX
#endif
#if defined(CONFIG_PCI_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
if (pxmitbuf->pallocated_buf)
rtw_mfree(pxmitbuf->pallocated_buf, free_sz);
#endif
}
#define WMM_XMIT_THRESHOLD (NR_XMITFRAME*2/5)
void rtw_os_pkt_complete(_adapter *padapter, _pkt *pkt)
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
u16 queue;
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
queue = skb_get_queue_mapping(pkt);
if (padapter->registrypriv.wifi_spec) {
if (__netif_subqueue_stopped(padapter->pnetdev, queue) &&
(pxmitpriv->hwxmits[queue].accnt < WMM_XMIT_THRESHOLD))
{
netif_wake_subqueue(padapter->pnetdev, queue);
}
} else {
if (__netif_subqueue_stopped(padapter->pnetdev, queue))
netif_wake_subqueue(padapter->pnetdev, queue);
}
#else
if (netif_queue_stopped(padapter->pnetdev))
netif_wake_queue(padapter->pnetdev);
#endif
dev_kfree_skb_any(pkt);
}
void rtw_os_xmit_complete(_adapter *padapter, struct xmit_frame *pxframe)
{
if (pxframe->pkt)
{
//RT_TRACE(_module_xmit_osdep_c_,_drv_err_,("linux : rtw_os_xmit_complete, dev_kfree_skb()\n"));
//dev_kfree_skb_any(pxframe->pkt);
rtw_os_pkt_complete(padapter, pxframe->pkt);
}
pxframe->pkt = NULL;
}
void rtw_os_xmit_schedule(_adapter *padapter)
{
_adapter *pri_adapter = padapter;
#if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
if (!padapter)
return;
#ifdef CONFIG_CONCURRENT_MODE
if (padapter->adapter_type > PRIMARY_ADAPTER)
pri_adapter = padapter->pbuddy_adapter;
#endif
if (_rtw_queue_empty(&pri_adapter->xmitpriv.pending_xmitbuf_queue) == false)
_rtw_up_sema(&pri_adapter->xmitpriv.xmit_sema);
#else
_irqL irqL;
struct xmit_priv *pxmitpriv;
if (!padapter)
return;
pxmitpriv = &padapter->xmitpriv;
_enter_critical_bh(&pxmitpriv->lock, &irqL);
if (rtw_txframes_pending(padapter))
{
tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
}
_exit_critical_bh(&pxmitpriv->lock, &irqL);
#endif
}
static void rtw_check_xmit_resource(_adapter *padapter, _pkt *pkt)
{
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
u16 queue;
queue = skb_get_queue_mapping(pkt);
if (padapter->registrypriv.wifi_spec) {
/* No free space for Tx, tx_worker is too slow */
if (pxmitpriv->hwxmits[queue].accnt > WMM_XMIT_THRESHOLD) {
//DBG_88E("%s(): stop netif_subqueue[%d]\n", __func__, queue);
netif_stop_subqueue(padapter->pnetdev, queue);
}
} else {
if (pxmitpriv->free_xmitframe_cnt<=4) {
if (!netif_tx_queue_stopped(netdev_get_tx_queue(padapter->pnetdev, queue)))
netif_stop_subqueue(padapter->pnetdev, queue);
}
}
#else
if (pxmitpriv->free_xmitframe_cnt<=4)
{
if (!rtw_netif_queue_stopped(padapter->pnetdev))
rtw_netif_stop_queue(padapter->pnetdev);
}
#endif
}
#ifdef CONFIG_TX_MCAST2UNI
static int rtw_mlcst2unicst(_adapter *padapter, struct sk_buff *skb)
{
struct sta_priv *pstapriv = &padapter->stapriv;
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
_irqL irqL;
_list *phead, *plist;
struct sk_buff *newskb;
struct sta_info *psta = NULL;
s32 res;
_enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
phead = &pstapriv->asoc_list;
plist = get_next(phead);
//free sta asoc_queue
while ((rtw_end_of_queue_search(phead, plist)) == false)
{
psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
plist = get_next(plist);
/* avoid come from STA1 and send back STA1 */
if (!memcmp(psta->hwaddr, &skb->data[6], 6))
continue;
newskb = skb_copy(skb, GFP_ATOMIC);
if (newskb) {
memcpy(newskb->data, psta->hwaddr, 6);
res = rtw_xmit(padapter, &newskb);
if (res < 0) {
DBG_88E("%s()-%d: rtw_xmit() return error!\n", __func__, __LINE__);
pxmitpriv->tx_drop++;
dev_kfree_skb_any(newskb);
} else
pxmitpriv->tx_pkts++;
} else {
DBG_88E("%s-%d: skb_copy() failed!\n", __func__, __LINE__);
pxmitpriv->tx_drop++;
_exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
//dev_kfree_skb_any(skb);
return false; // Caller shall tx this multicast frame via normal way.
}
}
_exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
dev_kfree_skb_any(skb);
return true;
}
#endif // CONFIG_TX_MCAST2UNI
int rtw_xmit_entry(_pkt *pkt, _nic_hdl pnetdev)
{
_adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
#ifdef CONFIG_TX_MCAST2UNI
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
#endif // CONFIG_TX_MCAST2UNI
s32 res = 0;
#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
u16 queue;
#endif
_func_enter_;
RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("+xmit_enry\n"));
if (rtw_if_up(padapter) == false) {
RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit_entry: rtw_if_up fail\n"));
#ifdef DBG_TX_DROP_FRAME
DBG_88E("DBG_TX_DROP_FRAME %s if_up fail\n", __func__);
#endif
goto drop_packet;
}
rtw_check_xmit_resource(padapter, pkt);
#ifdef CONFIG_TX_MCAST2UNI
if ( !rtw_mc2u_disable
&& check_fwstate(pmlmepriv, WIFI_AP_STATE) == true
&& ( IP_MCAST_MAC(pkt->data)
|| ICMPV6_MCAST_MAC(pkt->data) )
&& (padapter->registrypriv.wifi_spec == 0)
)
{
if ( pxmitpriv->free_xmitframe_cnt > (NR_XMITFRAME/4) ) {
res = rtw_mlcst2unicst(padapter, pkt);
if (res == true) {
goto exit;
}
} else {
//DBG_88E("Stop M2U(%d, %d)! ", pxmitpriv->free_xmitframe_cnt, pxmitpriv->free_xmitbuf_cnt);
//DBG_88E("!m2u );
}
}
#endif // CONFIG_TX_MCAST2UNI
res = rtw_xmit(padapter, &pkt);
if (res < 0) {
#ifdef DBG_TX_DROP_FRAME
DBG_88E("DBG_TX_DROP_FRAME %s rtw_xmit fail\n", __func__);
#endif
goto drop_packet;
}
pxmitpriv->tx_pkts++;
RT_TRACE(_module_xmit_osdep_c_, _drv_info_, ("rtw_xmit_entry: tx_pkts=%d\n", (u32)pxmitpriv->tx_pkts));
goto exit;
drop_packet:
pxmitpriv->tx_drop++;
dev_kfree_skb_any(pkt);
RT_TRACE(_module_xmit_osdep_c_, _drv_notice_, ("rtw_xmit_entry: drop, tx_drop=%d\n", (u32)pxmitpriv->tx_drop));
exit:
_func_exit_;
return 0;
}