1 /******************************************************************************
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
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:
27 ******************************************************************************/
29 #define _XMIT_OSDEP_C_
31 #include <linux/usb.h>
33 #include <linux/if_ether.h>
35 #include "osdep_service.h"
36 #include "drv_types.h"
39 #include "mlme_osdep.h"
40 #include "xmit_osdep.h"
41 #include "osdep_intf.h"
43 static uint remainder_len(struct pkt_file *pfile)
45 return (uint)(pfile->buf_len - ((addr_t)(pfile->cur_addr) -
46 (addr_t)(pfile->buf_start)));
49 void _r8712_open_pktfile(_pkt *pktptr, struct pkt_file *pfile)
52 pfile->cur_addr = pfile->buf_start = pktptr->data;
53 pfile->pkt_len = pfile->buf_len = pktptr->len;
54 pfile->cur_buffer = pfile->buf_start;
57 uint _r8712_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
61 len = remainder_len(pfile);
62 len = (rlen > len) ? len : rlen;
64 skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len,
66 pfile->cur_addr += len;
67 pfile->pkt_len -= len;
71 sint r8712_endofpktfile(struct pkt_file *pfile)
73 return (pfile->pkt_len == 0);
77 void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
79 struct ethhdr etherhdr;
83 _r8712_open_pktfile(ppktfile->pkt, ppktfile);
84 _r8712_pktfile_read(ppktfile, (unsigned char *)ðerhdr, ETH_HLEN);
86 /* get UserPriority from IP hdr*/
87 if (pattrib->ether_type == 0x0800) {
88 _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
89 /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/
90 UserPriority = ip_hdr.tos >> 5;
92 /* "When priority processing of data frames is supported,
93 * a STA's SME should send EAPOL-Key frames at the highest
96 if (pattrib->ether_type == 0x888e)
99 pattrib->priority = UserPriority;
100 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
101 pattrib->subtype = WIFI_QOS_DATA_TYPE;
104 void r8712_SetFilter(struct work_struct *work)
106 struct _adapter *padapter = container_of(work, struct _adapter,
108 u8 oldvalue = 0x00, newvalue = 0x00;
111 oldvalue = r8712_read8(padapter, 0x117);
112 newvalue = oldvalue & 0xfe;
113 r8712_write8(padapter, 0x117, newvalue);
115 spin_lock_irqsave(&padapter->lockRxFF0Filter, irqL);
116 padapter->blnEnableRxFF0Filter = 1;
117 spin_unlock_irqrestore(&padapter->lockRxFF0Filter, irqL);
120 } while (padapter->blnEnableRxFF0Filter == 1);
121 r8712_write8(padapter, 0x117, oldvalue);
124 int r8712_xmit_resource_alloc(struct _adapter *padapter,
125 struct xmit_buf *pxmitbuf)
129 for (i = 0; i < 8; i++) {
130 pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
131 if (!pxmitbuf->pxmit_urb[i]) {
132 netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n");
139 void r8712_xmit_resource_free(struct _adapter *padapter,
140 struct xmit_buf *pxmitbuf)
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]);
152 void r8712_xmit_complete(struct _adapter *padapter, struct xmit_frame *pxframe)
155 dev_kfree_skb_any(pxframe->pkt);
159 int r8712_xmit_entry(_pkt *pkt, struct net_device *pnetdev)
161 struct xmit_frame *pxmitframe = NULL;
162 struct _adapter *padapter = netdev_priv(pnetdev);
163 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
165 if (!r8712_if_up(padapter)) {
166 goto _xmit_entry_drop;
168 pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
170 goto _xmit_entry_drop;
172 if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) {
173 goto _xmit_entry_drop;
175 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
176 pxmitframe->pkt = pkt;
177 if (r8712_pre_xmit(padapter, pxmitframe)) {
178 /*dump xmitframe directly or drop xframe*/
179 dev_kfree_skb_any(pkt);
180 pxmitframe->pkt = NULL;
182 pxmitpriv->tx_pkts++;
183 pxmitpriv->tx_bytes += pxmitframe->attrib.last_txcmdsz;
187 r8712_free_xmitframe(pxmitpriv, pxmitframe);
188 pxmitpriv->tx_drop++;
189 dev_kfree_skb_any(pkt);