blob: 695f9b9fc749af5766d93f3462ee8b9ef9763f62 [file] [log] [blame]
Larry Finger2865d422010-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>
Ali Bahar359140a2011-09-04 03:14:11 +080034
Larry Finger2865d422010-08-20 10:15:30 -050035#include "osdep_service.h"
36#include "drv_types.h"
37
Larry Finger2865d422010-08-20 10:15:30 -050038#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{
Larry Finger2865d422010-08-20 10:15:30 -050045 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;
Thomas Cort77e73e82013-10-01 11:26:55 -040054 pfile->cur_buffer = pfile->buf_start;
Larry Finger2865d422010-08-20 10:15:30 -050055}
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{
Bhaktipriya Shridhar6e4eb862016-02-22 18:59:45 +053073 return (pfile->pkt_len == 0);
Larry Finger2865d422010-08-20 10:15:30 -050074}
75
76
77void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
78{
Larry Finger2865d422010-08-20 10:15:30 -050079 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) {
Sudip Mukherjeee29d3eb2014-10-27 17:42:25 +053088 _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
Larry Finger2865d422010-08-20 10:15:30 -050089 /*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
Ali Baharf95302e2011-09-04 03:14:18 +0800104void 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
Larry Finger2865d422010-08-20 10:15:30 -0500124int r8712_xmit_resource_alloc(struct _adapter *padapter,
125 struct xmit_buf *pxmitbuf)
126{
127 int i;
128
129 for (i = 0; i < 8; i++) {
Ali Bahar68e9b242011-09-04 03:14:07 +0800130 pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
Bhaktipriya Shridhar7cb07dc2016-02-19 00:24:30 +0530131 if (!pxmitbuf->pxmit_urb[i]) {
Przemo Firszt87a573a2012-12-10 23:21:21 +0000132 netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n");
Larry Finger2865d422010-08-20 10:15:30 -0500133 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;
Julia Lawall8f47c282015-03-29 14:54:12 +0200162 struct _adapter *padapter = netdev_priv(pnetdev);
Larry Finger2865d422010-08-20 10:15:30 -0500163 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
Larry Finger2865d422010-08-20 10:15:30 -0500164
Luis de Bethencourt1ca96882015-10-19 18:14:29 +0100165 if (!r8712_if_up(padapter)) {
Larry Finger2865d422010-08-20 10:15:30 -0500166 goto _xmit_entry_drop;
167 }
168 pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
Bhaktipriya Shridhar7cb07dc2016-02-19 00:24:30 +0530169 if (!pxmitframe) {
Larry Finger2865d422010-08-20 10:15:30 -0500170 goto _xmit_entry_drop;
171 }
172 if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) {
Larry Finger2865d422010-08-20 10:15:30 -0500173 goto _xmit_entry_drop;
174 }
175 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
176 pxmitframe->pkt = pkt;
Luis de Bethencourt1ca96882015-10-19 18:14:29 +0100177 if (r8712_pre_xmit(padapter, pxmitframe)) {
Larry Finger2865d422010-08-20 10:15:30 -0500178 /*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;
Bhaktipriya Shridhar40430f02016-02-25 16:17:33 +0530184 return 0;
Larry Finger2865d422010-08-20 10:15:30 -0500185_xmit_entry_drop:
186 if (pxmitframe)
187 r8712_free_xmitframe(pxmitpriv, pxmitframe);
188 pxmitpriv->tx_drop++;
189 dev_kfree_skb_any(pkt);
Bhaktipriya Shridhar40430f02016-02-25 16:17:33 +0530190 return 0;
Larry Finger2865d422010-08-20 10:15:30 -0500191}