blob: 4ee4136b5c28fa34d4af7aeb90ec043a238ce74c [file] [log] [blame]
Larry Finger2865d42c2010-08-20 10:15:30 -05001/******************************************************************************
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
Ali Bahar359140a2011-09-04 03:14:11 +080031#include <linux/usb.h>
Paul Gortmaker20467822012-05-09 22:53:32 -040032#include <linux/ip.h>
Paul Gortmakerbe9a1202012-05-09 22:42:45 -040033#include <linux/if_ether.h>
Larry Finger580b4102016-06-03 20:17:37 -050034#include <linux/kmemleak.h>
Ali Bahar359140a2011-09-04 03:14:11 +080035
Larry Finger2865d42c2010-08-20 10:15:30 -050036#include "osdep_service.h"
37#include "drv_types.h"
38
Larry Finger2865d42c2010-08-20 10:15:30 -050039#include "wifi.h"
40#include "mlme_osdep.h"
41#include "xmit_osdep.h"
42#include "osdep_intf.h"
43
44static uint remainder_len(struct pkt_file *pfile)
45{
Larry Finger2865d42c2010-08-20 10:15:30 -050046 return (uint)(pfile->buf_len - ((addr_t)(pfile->cur_addr) -
47 (addr_t)(pfile->buf_start)));
48}
49
50void _r8712_open_pktfile(_pkt *pktptr, struct pkt_file *pfile)
51{
52 pfile->pkt = pktptr;
53 pfile->cur_addr = pfile->buf_start = pktptr->data;
54 pfile->pkt_len = pfile->buf_len = pktptr->len;
Thomas Cort77e73e82013-10-01 11:26:55 -040055 pfile->cur_buffer = pfile->buf_start;
Larry Finger2865d42c2010-08-20 10:15:30 -050056}
57
58uint _r8712_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
59{
60 uint len;
61
62 len = remainder_len(pfile);
63 len = (rlen > len) ? len : rlen;
64 if (rmem)
65 skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len,
66 rmem, len);
67 pfile->cur_addr += len;
68 pfile->pkt_len -= len;
69 return len;
70}
71
72sint r8712_endofpktfile(struct pkt_file *pfile)
73{
Bhaktipriya Shridhar6e4eb862016-02-22 18:59:45 +053074 return (pfile->pkt_len == 0);
Larry Finger2865d42c2010-08-20 10:15:30 -050075}
76
77
78void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
79{
Larry Finger2865d42c2010-08-20 10:15:30 -050080 struct ethhdr etherhdr;
81 struct iphdr ip_hdr;
82 u16 UserPriority = 0;
83
84 _r8712_open_pktfile(ppktfile->pkt, ppktfile);
85 _r8712_pktfile_read(ppktfile, (unsigned char *)&etherhdr, ETH_HLEN);
86
87 /* get UserPriority from IP hdr*/
88 if (pattrib->ether_type == 0x0800) {
Sudip Mukherjeee29d3eb2014-10-27 17:42:25 +053089 _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
Larry Finger2865d42c2010-08-20 10:15:30 -050090 /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/
91 UserPriority = ip_hdr.tos >> 5;
92 } else {
93 /* "When priority processing of data frames is supported,
94 * a STA's SME should send EAPOL-Key frames at the highest
Anuradha Weeramanaf074772016-06-27 13:12:16 +053095 * priority."
96 */
Larry Finger2865d42c2010-08-20 10:15:30 -050097
98 if (pattrib->ether_type == 0x888e)
99 UserPriority = 7;
100 }
101 pattrib->priority = UserPriority;
102 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
103 pattrib->subtype = WIFI_QOS_DATA_TYPE;
104}
105
Ali Baharf95302e2011-09-04 03:14:18 +0800106void r8712_SetFilter(struct work_struct *work)
107{
108 struct _adapter *padapter = container_of(work, struct _adapter,
109 wkFilterRxFF0);
110 u8 oldvalue = 0x00, newvalue = 0x00;
111 unsigned long irqL;
112
113 oldvalue = r8712_read8(padapter, 0x117);
114 newvalue = oldvalue & 0xfe;
115 r8712_write8(padapter, 0x117, newvalue);
116
117 spin_lock_irqsave(&padapter->lockRxFF0Filter, irqL);
118 padapter->blnEnableRxFF0Filter = 1;
119 spin_unlock_irqrestore(&padapter->lockRxFF0Filter, irqL);
120 do {
121 msleep(100);
122 } while (padapter->blnEnableRxFF0Filter == 1);
123 r8712_write8(padapter, 0x117, oldvalue);
124}
125
Larry Finger2865d42c2010-08-20 10:15:30 -0500126int r8712_xmit_resource_alloc(struct _adapter *padapter,
127 struct xmit_buf *pxmitbuf)
128{
129 int i;
130
131 for (i = 0; i < 8; i++) {
Ali Bahar68e9b242011-09-04 03:14:07 +0800132 pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
Bhaktipriya Shridhar7cb07dc2016-02-19 00:24:30 +0530133 if (!pxmitbuf->pxmit_urb[i]) {
Przemo Firszt87a573a2012-12-10 23:21:21 +0000134 netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n");
Larry Finger2865d42c2010-08-20 10:15:30 -0500135 return _FAIL;
136 }
Larry Finger580b4102016-06-03 20:17:37 -0500137 kmemleak_not_leak(pxmitbuf->pxmit_urb[i]);
Larry Finger2865d42c2010-08-20 10:15:30 -0500138 }
139 return _SUCCESS;
140}
141
142void r8712_xmit_resource_free(struct _adapter *padapter,
143 struct xmit_buf *pxmitbuf)
144{
145 int i;
146
147 for (i = 0; i < 8; i++) {
148 if (pxmitbuf->pxmit_urb[i]) {
149 usb_kill_urb(pxmitbuf->pxmit_urb[i]);
150 usb_free_urb(pxmitbuf->pxmit_urb[i]);
151 }
152 }
153}
154
155void r8712_xmit_complete(struct _adapter *padapter, struct xmit_frame *pxframe)
156{
157 if (pxframe->pkt)
158 dev_kfree_skb_any(pxframe->pkt);
159 pxframe->pkt = NULL;
160}
161
162int r8712_xmit_entry(_pkt *pkt, struct net_device *pnetdev)
163{
164 struct xmit_frame *pxmitframe = NULL;
Julia Lawall8f47c282015-03-29 14:54:12 +0200165 struct _adapter *padapter = netdev_priv(pnetdev);
Larry Finger2865d42c2010-08-20 10:15:30 -0500166 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
Larry Finger2865d42c2010-08-20 10:15:30 -0500167
Anuradha Weeramanaf074772016-06-27 13:12:16 +0530168 if (!r8712_if_up(padapter))
Larry Finger2865d42c2010-08-20 10:15:30 -0500169 goto _xmit_entry_drop;
Anuradha Weeramanaf074772016-06-27 13:12:16 +0530170
Larry Finger2865d42c2010-08-20 10:15:30 -0500171 pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
Anuradha Weeramanaf074772016-06-27 13:12:16 +0530172 if (!pxmitframe)
Larry Finger2865d42c2010-08-20 10:15:30 -0500173 goto _xmit_entry_drop;
Anuradha Weeramanaf074772016-06-27 13:12:16 +0530174
175 if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib)))
Larry Finger2865d42c2010-08-20 10:15:30 -0500176 goto _xmit_entry_drop;
Anuradha Weeramanaf074772016-06-27 13:12:16 +0530177
Larry Finger2865d42c2010-08-20 10:15:30 -0500178 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
179 pxmitframe->pkt = pkt;
Luis de Bethencourt1ca96882015-10-19 18:14:29 +0100180 if (r8712_pre_xmit(padapter, pxmitframe)) {
Larry Finger2865d42c2010-08-20 10:15:30 -0500181 /*dump xmitframe directly or drop xframe*/
182 dev_kfree_skb_any(pkt);
183 pxmitframe->pkt = NULL;
184 }
185 pxmitpriv->tx_pkts++;
186 pxmitpriv->tx_bytes += pxmitframe->attrib.last_txcmdsz;
Bhaktipriya Shridhar40430f02016-02-25 16:17:33 +0530187 return 0;
Larry Finger2865d42c2010-08-20 10:15:30 -0500188_xmit_entry_drop:
189 if (pxmitframe)
190 r8712_free_xmitframe(pxmitpriv, pxmitframe);
191 pxmitpriv->tx_drop++;
192 dev_kfree_skb_any(pkt);
Bhaktipriya Shridhar40430f02016-02-25 16:17:33 +0530193 return 0;
Larry Finger2865d42c2010-08-20 10:15:30 -0500194}