Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /******************************************************************************
0003  * xmit_linux.c
0004  *
0005  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
0006  * Linux device driver for RTL8192SU
0007  *
0008  * Modifications for inclusion into the Linux staging tree are
0009  * Copyright(c) 2010 Larry Finger. All rights reserved.
0010  *
0011  * Contact information:
0012  * WLAN FAE <wlanfae@realtek.com>
0013  * Larry Finger <Larry.Finger@lwfinger.net>
0014  *
0015  ******************************************************************************/
0016 
0017 #define _XMIT_OSDEP_C_
0018 
0019 #include <linux/usb.h>
0020 #include <linux/ip.h>
0021 #include <linux/if_ether.h>
0022 #include <linux/kmemleak.h>
0023 
0024 #include "osdep_service.h"
0025 #include "drv_types.h"
0026 
0027 #include "wifi.h"
0028 #include "mlme_osdep.h"
0029 #include "xmit_osdep.h"
0030 #include "osdep_intf.h"
0031 
0032 static uint remainder_len(struct pkt_file *pfile)
0033 {
0034     return (uint)(pfile->buf_len - ((addr_t)(pfile->cur_addr) -
0035            (addr_t)(pfile->buf_start)));
0036 }
0037 
0038 void _r8712_open_pktfile(_pkt *pktptr, struct pkt_file *pfile)
0039 {
0040     pfile->pkt = pktptr;
0041     pfile->cur_addr = pfile->buf_start = pktptr->data;
0042     pfile->pkt_len = pfile->buf_len = pktptr->len;
0043     pfile->cur_buffer = pfile->buf_start;
0044 }
0045 
0046 uint _r8712_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
0047 {
0048     uint len;
0049 
0050     len = remainder_len(pfile);
0051     len = (rlen > len) ? len : rlen;
0052     if (rmem)
0053         skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len,
0054                   rmem, len);
0055     pfile->cur_addr += len;
0056     pfile->pkt_len -= len;
0057     return len;
0058 }
0059 
0060 sint r8712_endofpktfile(struct pkt_file *pfile)
0061 {
0062     return (pfile->pkt_len == 0);
0063 }
0064 
0065 void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
0066 {
0067     struct ethhdr etherhdr;
0068     struct iphdr ip_hdr;
0069     u16 UserPriority = 0;
0070 
0071     _r8712_open_pktfile(ppktfile->pkt, ppktfile);
0072     _r8712_pktfile_read(ppktfile, (unsigned char *)&etherhdr, ETH_HLEN);
0073 
0074     /* get UserPriority from IP hdr*/
0075     if (pattrib->ether_type == 0x0800) {
0076         _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
0077         /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/
0078         UserPriority = ip_hdr.tos >> 5;
0079     } else {
0080         /* "When priority processing of data frames is supported,
0081          * a STA's SME should send EAPOL-Key frames at the highest
0082          * priority."
0083          */
0084 
0085         if (pattrib->ether_type == 0x888e)
0086             UserPriority = 7;
0087     }
0088     pattrib->priority = UserPriority;
0089     pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
0090     pattrib->subtype = WIFI_QOS_DATA_TYPE;
0091 }
0092 
0093 void r8712_SetFilter(struct work_struct *work)
0094 {
0095     struct _adapter *adapter = container_of(work, struct _adapter,
0096                         wk_filter_rx_ff0);
0097     u8  oldvalue = 0x00, newvalue = 0x00;
0098 
0099     oldvalue = r8712_read8(adapter, 0x117);
0100     newvalue = oldvalue & 0xfe;
0101     r8712_write8(adapter, 0x117, newvalue);
0102 
0103     wait_for_completion(&adapter->rx_filter_ready);
0104     r8712_write8(adapter, 0x117, oldvalue);
0105 }
0106 
0107 int r8712_xmit_resource_alloc(struct _adapter *padapter,
0108                   struct xmit_buf *pxmitbuf)
0109 {
0110     int i;
0111 
0112     for (i = 0; i < 8; i++) {
0113         pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
0114         if (!pxmitbuf->pxmit_urb[i]) {
0115             netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n");
0116             return -ENOMEM;
0117         }
0118         kmemleak_not_leak(pxmitbuf->pxmit_urb[i]);
0119     }
0120     return 0;
0121 }
0122 
0123 void r8712_xmit_resource_free(struct _adapter *padapter,
0124                   struct xmit_buf *pxmitbuf)
0125 {
0126     int i;
0127 
0128     for (i = 0; i < 8; i++) {
0129         if (pxmitbuf->pxmit_urb[i]) {
0130             usb_kill_urb(pxmitbuf->pxmit_urb[i]);
0131             usb_free_urb(pxmitbuf->pxmit_urb[i]);
0132         }
0133     }
0134 }
0135 
0136 void r8712_xmit_complete(struct _adapter *padapter, struct xmit_frame *pxframe)
0137 {
0138     if (pxframe->pkt)
0139         dev_kfree_skb_any(pxframe->pkt);
0140     pxframe->pkt = NULL;
0141 }
0142 
0143 int r8712_xmit_entry(_pkt *pkt, struct  net_device *netdev)
0144 {
0145     struct xmit_frame *xmitframe = NULL;
0146     struct _adapter *adapter = netdev_priv(netdev);
0147     struct xmit_priv *xmitpriv = &(adapter->xmitpriv);
0148 
0149     if (!r8712_if_up(adapter))
0150         goto _xmit_entry_drop;
0151 
0152     xmitframe = r8712_alloc_xmitframe(xmitpriv);
0153     if (!xmitframe)
0154         goto _xmit_entry_drop;
0155 
0156     if (r8712_update_attrib(adapter, pkt, &xmitframe->attrib))
0157         goto _xmit_entry_drop;
0158 
0159     adapter->ledpriv.LedControlHandler(adapter, LED_CTL_TX);
0160     xmitframe->pkt = pkt;
0161     if (r8712_pre_xmit(adapter, xmitframe)) {
0162         /*dump xmitframe directly or drop xframe*/
0163         dev_kfree_skb_any(pkt);
0164         xmitframe->pkt = NULL;
0165     }
0166     xmitpriv->tx_pkts++;
0167     xmitpriv->tx_bytes += xmitframe->attrib.last_txcmdsz;
0168     return 0;
0169 _xmit_entry_drop:
0170     if (xmitframe)
0171         r8712_free_xmitframe(xmitpriv, xmitframe);
0172     xmitpriv->tx_drop++;
0173     dev_kfree_skb_any(pkt);
0174     return 0;
0175 }