1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
6 * Linux device driver for RTL8192SU
8 * Modifications for inclusion into the Linux staging tree are
9 * Copyright(c) 2010 Larry Finger. All rights reserved.
11 * Contact information:
12 * WLAN FAE <wlanfae@realtek.com>
13 * Larry Finger <Larry.Finger@lwfinger.net>
15 ******************************************************************************/
17 #define _XMIT_OSDEP_C_
19 #include <linux/usb.h>
21 #include <linux/if_ether.h>
22 #include <linux/kmemleak.h>
24 #include "osdep_service.h"
25 #include "drv_types.h"
28 #include "mlme_osdep.h"
29 #include "xmit_osdep.h"
30 #include "osdep_intf.h"
32 static uint remainder_len(struct pkt_file *pfile)
34 return (uint)(pfile->buf_len - ((addr_t)(pfile->cur_addr) -
35 (addr_t)(pfile->buf_start)));
38 void _r8712_open_pktfile(_pkt *pktptr, struct pkt_file *pfile)
41 pfile->cur_addr = pfile->buf_start = pktptr->data;
42 pfile->pkt_len = pfile->buf_len = pktptr->len;
43 pfile->cur_buffer = pfile->buf_start;
46 uint _r8712_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
50 len = remainder_len(pfile);
51 len = (rlen > len) ? len : rlen;
53 skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len,
55 pfile->cur_addr += len;
56 pfile->pkt_len -= len;
60 sint r8712_endofpktfile(struct pkt_file *pfile)
62 return (pfile->pkt_len == 0);
65 void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
67 struct ethhdr etherhdr;
71 _r8712_open_pktfile(ppktfile->pkt, ppktfile);
72 _r8712_pktfile_read(ppktfile, (unsigned char *)ðerhdr, ETH_HLEN);
74 /* get UserPriority from IP hdr*/
75 if (pattrib->ether_type == 0x0800) {
76 _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
77 /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/
78 UserPriority = ip_hdr.tos >> 5;
80 /* "When priority processing of data frames is supported,
81 * a STA's SME should send EAPOL-Key frames at the highest
85 if (pattrib->ether_type == 0x888e)
88 pattrib->priority = UserPriority;
89 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
90 pattrib->subtype = WIFI_QOS_DATA_TYPE;
93 void r8712_SetFilter(struct work_struct *work)
95 struct _adapter *adapter = container_of(work, struct _adapter,
97 u8 oldvalue = 0x00, newvalue = 0x00;
99 oldvalue = r8712_read8(adapter, 0x117);
100 newvalue = oldvalue & 0xfe;
101 r8712_write8(adapter, 0x117, newvalue);
103 wait_for_completion(&adapter->rx_filter_ready);
104 r8712_write8(adapter, 0x117, oldvalue);
107 int r8712_xmit_resource_alloc(struct _adapter *padapter,
108 struct xmit_buf *pxmitbuf)
112 for (i = 0; i < 8; i++) {
113 pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
114 if (!pxmitbuf->pxmit_urb[i]) {
115 netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n");
118 kmemleak_not_leak(pxmitbuf->pxmit_urb[i]);
123 void r8712_xmit_resource_free(struct _adapter *padapter,
124 struct xmit_buf *pxmitbuf)
128 for (i = 0; i < 8; i++) {
129 if (pxmitbuf->pxmit_urb[i]) {
130 usb_kill_urb(pxmitbuf->pxmit_urb[i]);
131 usb_free_urb(pxmitbuf->pxmit_urb[i]);
136 void r8712_xmit_complete(struct _adapter *padapter, struct xmit_frame *pxframe)
139 dev_kfree_skb_any(pxframe->pkt);
143 int r8712_xmit_entry(_pkt *pkt, struct net_device *netdev)
145 struct xmit_frame *xmitframe = NULL;
146 struct _adapter *adapter = netdev_priv(netdev);
147 struct xmit_priv *xmitpriv = &(adapter->xmitpriv);
149 if (!r8712_if_up(adapter))
150 goto _xmit_entry_drop;
152 xmitframe = r8712_alloc_xmitframe(xmitpriv);
154 goto _xmit_entry_drop;
156 if (r8712_update_attrib(adapter, pkt, &xmitframe->attrib))
157 goto _xmit_entry_drop;
159 adapter->ledpriv.LedControlHandler(adapter, LED_CTL_TX);
160 xmitframe->pkt = pkt;
161 if (r8712_pre_xmit(adapter, xmitframe)) {
162 /*dump xmitframe directly or drop xframe*/
163 dev_kfree_skb_any(pkt);
164 xmitframe->pkt = NULL;
167 xmitpriv->tx_bytes += xmitframe->attrib.last_txcmdsz;
171 r8712_free_xmitframe(xmitpriv, xmitframe);
173 dev_kfree_skb_any(pkt);