USB: ftdi_sio: Add more identifiers
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / rtl8712 / xmit_linux.c
blobc9703627c8f5b499515b6f3a8aa1d36fc9c9207c
1 /******************************************************************************
2 * xmit_linux.c
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU
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.
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.
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
20 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved.
23 * Contact information:
24 * WLAN FAE <wlanfae@realtek.com>
25 * Larry Finger <Larry.Finger@lwfinger.net>
27 ******************************************************************************/
29 #define _XMIT_OSDEP_C_
31 #include <linux/usb.h>
33 #include "osdep_service.h"
34 #include "drv_types.h"
37 #include "if_ether.h"
38 #include "ip.h"
39 #include "rtl871x_byteorder.h"
40 #include "wifi.h"
41 #include "mlme_osdep.h"
42 #include "xmit_osdep.h"
43 #include "osdep_intf.h"
45 static uint remainder_len(struct pkt_file *pfile)
47 return (uint)(pfile->buf_len - ((addr_t)(pfile->cur_addr) -
48 (addr_t)(pfile->buf_start)));
51 void _r8712_open_pktfile(_pkt *pktptr, struct pkt_file *pfile)
53 pfile->pkt = pktptr;
54 pfile->cur_addr = pfile->buf_start = pktptr->data;
55 pfile->pkt_len = pfile->buf_len = pktptr->len;
56 pfile->cur_buffer = pfile->buf_start ;
59 uint _r8712_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
61 uint len;
63 len = remainder_len(pfile);
64 len = (rlen > len) ? len : rlen;
65 if (rmem)
66 skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len,
67 rmem, len);
68 pfile->cur_addr += len;
69 pfile->pkt_len -= len;
70 return len;
73 sint r8712_endofpktfile(struct pkt_file *pfile)
75 if (pfile->pkt_len == 0)
76 return true;
77 else
78 return false;
82 void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
84 int i;
85 struct ethhdr etherhdr;
86 struct iphdr ip_hdr;
87 u16 UserPriority = 0;
89 _r8712_open_pktfile(ppktfile->pkt, ppktfile);
90 _r8712_pktfile_read(ppktfile, (unsigned char *)&etherhdr, ETH_HLEN);
92 /* get UserPriority from IP hdr*/
93 if (pattrib->ether_type == 0x0800) {
94 i = _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr,
95 sizeof(ip_hdr));
96 /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/
97 UserPriority = ip_hdr.tos >> 5;
98 } else {
99 /* "When priority processing of data frames is supported,
100 * a STA's SME should send EAPOL-Key frames at the highest
101 * priority." */
103 if (pattrib->ether_type == 0x888e)
104 UserPriority = 7;
106 pattrib->priority = UserPriority;
107 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
108 pattrib->subtype = WIFI_QOS_DATA_TYPE;
111 void r8712_SetFilter(struct work_struct *work)
113 struct _adapter *padapter = container_of(work, struct _adapter,
114 wkFilterRxFF0);
115 u8 oldvalue = 0x00, newvalue = 0x00;
116 unsigned long irqL;
118 oldvalue = r8712_read8(padapter, 0x117);
119 newvalue = oldvalue & 0xfe;
120 r8712_write8(padapter, 0x117, newvalue);
122 spin_lock_irqsave(&padapter->lockRxFF0Filter, irqL);
123 padapter->blnEnableRxFF0Filter = 1;
124 spin_unlock_irqrestore(&padapter->lockRxFF0Filter, irqL);
125 do {
126 msleep(100);
127 } while (padapter->blnEnableRxFF0Filter == 1);
128 r8712_write8(padapter, 0x117, oldvalue);
131 int r8712_xmit_resource_alloc(struct _adapter *padapter,
132 struct xmit_buf *pxmitbuf)
134 int i;
136 for (i = 0; i < 8; i++) {
137 pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
138 if (pxmitbuf->pxmit_urb[i] == NULL) {
139 printk(KERN_ERR "r8712u: pxmitbuf->pxmit_urb[i]"
140 " == NULL");
141 return _FAIL;
144 return _SUCCESS;
147 void r8712_xmit_resource_free(struct _adapter *padapter,
148 struct xmit_buf *pxmitbuf)
150 int i;
152 for (i = 0; i < 8; i++) {
153 if (pxmitbuf->pxmit_urb[i]) {
154 usb_kill_urb(pxmitbuf->pxmit_urb[i]);
155 usb_free_urb(pxmitbuf->pxmit_urb[i]);
160 void r8712_xmit_complete(struct _adapter *padapter, struct xmit_frame *pxframe)
162 if (pxframe->pkt)
163 dev_kfree_skb_any(pxframe->pkt);
164 pxframe->pkt = NULL;
167 int r8712_xmit_entry(_pkt *pkt, struct net_device *pnetdev)
169 struct xmit_frame *pxmitframe = NULL;
170 struct _adapter *padapter = (struct _adapter *)netdev_priv(pnetdev);
171 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
172 int ret = 0;
174 if (r8712_if_up(padapter) == false) {
175 ret = 0;
176 goto _xmit_entry_drop;
178 pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
179 if (pxmitframe == NULL) {
180 ret = 0;
181 goto _xmit_entry_drop;
183 if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) {
184 ret = 0;
185 goto _xmit_entry_drop;
187 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
188 pxmitframe->pkt = pkt;
189 if (r8712_pre_xmit(padapter, pxmitframe) == true) {
190 /*dump xmitframe directly or drop xframe*/
191 dev_kfree_skb_any(pkt);
192 pxmitframe->pkt = NULL;
194 pxmitpriv->tx_pkts++;
195 pxmitpriv->tx_bytes += pxmitframe->attrib.last_txcmdsz;
196 return ret;
197 _xmit_entry_drop:
198 if (pxmitframe)
199 r8712_free_xmitframe(pxmitpriv, pxmitframe);
200 pxmitpriv->tx_drop++;
201 dev_kfree_skb_any(pkt);
202 return ret;