linux/drivers/staging/rtl8712/xmit_linux.c
<<
>>
Prefs
   1/******************************************************************************
   2 * xmit_linux.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 _XMIT_OSDEP_C_
  30
  31#include <linux/usb.h>
  32#include <linux/ip.h>
  33#include <linux/if_ether.h>
  34
  35#include "osdep_service.h"
  36#include "drv_types.h"
  37
  38#include "wifi.h"
  39#include "mlme_osdep.h"
  40#include "xmit_osdep.h"
  41#include "osdep_intf.h"
  42
  43static uint remainder_len(struct pkt_file *pfile)
  44{
  45        return (uint)(pfile->buf_len - ((addr_t)(pfile->cur_addr) -
  46               (addr_t)(pfile->buf_start)));
  47}
  48
  49void _r8712_open_pktfile(_pkt *pktptr, struct pkt_file *pfile)
  50{
  51        pfile->pkt = pktptr;
  52        pfile->cur_addr = pfile->buf_start = pktptr->data;
  53        pfile->pkt_len = pfile->buf_len = pktptr->len;
  54        pfile->cur_buffer = pfile->buf_start;
  55}
  56
  57uint _r8712_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
  58{
  59        uint len;
  60
  61        len = remainder_len(pfile);
  62        len = (rlen > len) ? len : rlen;
  63        if (rmem)
  64                skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len,
  65                              rmem, len);
  66        pfile->cur_addr += len;
  67        pfile->pkt_len -= len;
  68        return len;
  69}
  70
  71sint r8712_endofpktfile(struct pkt_file *pfile)
  72{
  73        return (pfile->pkt_len == 0);
  74}
  75
  76
  77void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
  78{
  79        struct ethhdr etherhdr;
  80        struct iphdr ip_hdr;
  81        u16 UserPriority = 0;
  82
  83        _r8712_open_pktfile(ppktfile->pkt, ppktfile);
  84        _r8712_pktfile_read(ppktfile, (unsigned char *)&etherhdr, ETH_HLEN);
  85
  86        /* get UserPriority from IP hdr*/
  87        if (pattrib->ether_type == 0x0800) {
  88                _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
  89                /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/
  90                UserPriority = ip_hdr.tos >> 5;
  91        } else {
  92                /* "When priority processing of data frames is supported,
  93                 * a STA's SME should send EAPOL-Key frames at the highest
  94                 * priority." */
  95
  96                if (pattrib->ether_type == 0x888e)
  97                        UserPriority = 7;
  98        }
  99        pattrib->priority = UserPriority;
 100        pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
 101        pattrib->subtype = WIFI_QOS_DATA_TYPE;
 102}
 103
 104void r8712_SetFilter(struct work_struct *work)
 105{
 106        struct _adapter *padapter = container_of(work, struct _adapter,
 107                                                wkFilterRxFF0);
 108        u8  oldvalue = 0x00, newvalue = 0x00;
 109        unsigned long irqL;
 110
 111        oldvalue = r8712_read8(padapter, 0x117);
 112        newvalue = oldvalue & 0xfe;
 113        r8712_write8(padapter, 0x117, newvalue);
 114
 115        spin_lock_irqsave(&padapter->lockRxFF0Filter, irqL);
 116        padapter->blnEnableRxFF0Filter = 1;
 117        spin_unlock_irqrestore(&padapter->lockRxFF0Filter, irqL);
 118        do {
 119                msleep(100);
 120        } while (padapter->blnEnableRxFF0Filter == 1);
 121        r8712_write8(padapter, 0x117, oldvalue);
 122}
 123
 124int r8712_xmit_resource_alloc(struct _adapter *padapter,
 125                              struct xmit_buf *pxmitbuf)
 126{
 127        int i;
 128
 129        for (i = 0; i < 8; i++) {
 130                pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
 131                if (!pxmitbuf->pxmit_urb[i]) {
 132                        netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n");
 133                        return _FAIL;
 134                }
 135        }
 136        return _SUCCESS;
 137}
 138
 139void r8712_xmit_resource_free(struct _adapter *padapter,
 140                              struct xmit_buf *pxmitbuf)
 141{
 142        int i;
 143
 144        for (i = 0; i < 8; i++) {
 145                if (pxmitbuf->pxmit_urb[i]) {
 146                        usb_kill_urb(pxmitbuf->pxmit_urb[i]);
 147                        usb_free_urb(pxmitbuf->pxmit_urb[i]);
 148                }
 149        }
 150}
 151
 152void r8712_xmit_complete(struct _adapter *padapter, struct xmit_frame *pxframe)
 153{
 154        if (pxframe->pkt)
 155                dev_kfree_skb_any(pxframe->pkt);
 156        pxframe->pkt = NULL;
 157}
 158
 159int r8712_xmit_entry(_pkt *pkt, struct  net_device *pnetdev)
 160{
 161        struct xmit_frame *pxmitframe = NULL;
 162        struct _adapter *padapter = netdev_priv(pnetdev);
 163        struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
 164
 165        if (!r8712_if_up(padapter)) {
 166                goto _xmit_entry_drop;
 167        }
 168        pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
 169        if (!pxmitframe) {
 170                goto _xmit_entry_drop;
 171        }
 172        if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) {
 173                goto _xmit_entry_drop;
 174        }
 175        padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
 176        pxmitframe->pkt = pkt;
 177        if (r8712_pre_xmit(padapter, pxmitframe)) {
 178                /*dump xmitframe directly or drop xframe*/
 179                dev_kfree_skb_any(pkt);
 180                pxmitframe->pkt = NULL;
 181        }
 182        pxmitpriv->tx_pkts++;
 183        pxmitpriv->tx_bytes += pxmitframe->attrib.last_txcmdsz;
 184        return 0;
 185_xmit_entry_drop:
 186        if (pxmitframe)
 187                r8712_free_xmitframe(pxmitpriv, pxmitframe);
 188        pxmitpriv->tx_drop++;
 189        dev_kfree_skb_any(pkt);
 190        return 0;
 191}
 192