]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/rtl8712/xmit_linux.c
Merge branch 'for-linus' of git://git.kernel.dk/linux-2.6-block
[mirror_ubuntu-artful-kernel.git] / drivers / staging / rtl8712 / xmit_linux.c
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 "osdep_service.h"
32 #include "drv_types.h"
33
34
35 #include "if_ether.h"
36 #include "ip.h"
37 #include "rtl871x_byteorder.h"
38 #include "wifi.h"
39 #include "mlme_osdep.h"
40 #include "xmit_osdep.h"
41 #include "osdep_intf.h"
42
43 static uint remainder_len(struct pkt_file *pfile)
44 {
45 /* Kovich: Need to extend the buf_len to 64 bit ?(unsigned long long) */
46 return (uint)(pfile->buf_len - ((addr_t)(pfile->cur_addr) -
47 (addr_t)(pfile->buf_start)));
48 }
49
50 void _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;
55 pfile->cur_buffer = pfile->buf_start ;
56 }
57
58 uint _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
72 sint r8712_endofpktfile(struct pkt_file *pfile)
73 {
74 if (pfile->pkt_len == 0)
75 return true;
76 else
77 return false;
78 }
79
80
81 void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
82 {
83 int i;
84 struct ethhdr etherhdr;
85 struct iphdr ip_hdr;
86 u16 UserPriority = 0;
87
88 _r8712_open_pktfile(ppktfile->pkt, ppktfile);
89 _r8712_pktfile_read(ppktfile, (unsigned char *)&etherhdr, ETH_HLEN);
90
91 /* get UserPriority from IP hdr*/
92 if (pattrib->ether_type == 0x0800) {
93 i = _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr,
94 sizeof(ip_hdr));
95 /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/
96 UserPriority = ip_hdr.tos >> 5;
97 } else {
98 /* "When priority processing of data frames is supported,
99 * a STA's SME should send EAPOL-Key frames at the highest
100 * priority." */
101
102 if (pattrib->ether_type == 0x888e)
103 UserPriority = 7;
104 }
105 pattrib->priority = UserPriority;
106 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
107 pattrib->subtype = WIFI_QOS_DATA_TYPE;
108 }
109
110 int r8712_xmit_resource_alloc(struct _adapter *padapter,
111 struct xmit_buf *pxmitbuf)
112 {
113 int i;
114
115 for (i = 0; i < 8; i++) {
116 pxmitbuf->pxmit_urb[i] = _usb_alloc_urb(0, GFP_KERNEL);
117 if (pxmitbuf->pxmit_urb[i] == NULL) {
118 printk(KERN_ERR "r8712u: pxmitbuf->pxmit_urb[i]"
119 " == NULL");
120 return _FAIL;
121 }
122 }
123 return _SUCCESS;
124 }
125
126 void r8712_xmit_resource_free(struct _adapter *padapter,
127 struct xmit_buf *pxmitbuf)
128 {
129 int i;
130
131 for (i = 0; i < 8; i++) {
132 if (pxmitbuf->pxmit_urb[i]) {
133 usb_kill_urb(pxmitbuf->pxmit_urb[i]);
134 usb_free_urb(pxmitbuf->pxmit_urb[i]);
135 }
136 }
137 }
138
139 void r8712_xmit_complete(struct _adapter *padapter, struct xmit_frame *pxframe)
140 {
141 if (pxframe->pkt)
142 dev_kfree_skb_any(pxframe->pkt);
143 pxframe->pkt = NULL;
144 }
145
146 int r8712_xmit_entry(_pkt *pkt, struct net_device *pnetdev)
147 {
148 struct xmit_frame *pxmitframe = NULL;
149 struct _adapter *padapter = (struct _adapter *)_netdev_priv(pnetdev);
150 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
151 int ret = 0;
152
153 if (r8712_if_up(padapter) == false) {
154 ret = 0;
155 goto _xmit_entry_drop;
156 }
157 pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
158 if (pxmitframe == NULL) {
159 ret = 0;
160 goto _xmit_entry_drop;
161 }
162 if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) {
163 ret = 0;
164 goto _xmit_entry_drop;
165 }
166 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
167 pxmitframe->pkt = pkt;
168 if (r8712_pre_xmit(padapter, pxmitframe) == true) {
169 /*dump xmitframe directly or drop xframe*/
170 dev_kfree_skb_any(pkt);
171 pxmitframe->pkt = NULL;
172 }
173 pxmitpriv->tx_pkts++;
174 pxmitpriv->tx_bytes += pxmitframe->attrib.last_txcmdsz;
175 return ret;
176 _xmit_entry_drop:
177 if (pxmitframe)
178 r8712_free_xmitframe(pxmitpriv, pxmitframe);
179 pxmitpriv->tx_drop++;
180 dev_kfree_skb_any(pkt);
181 return ret;
182 }