Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 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 | |
Ali Bahar | 359140a | 2011-09-04 03:14:11 +0800 | [diff] [blame] | 31 | #include <linux/usb.h> |
Paul Gortmaker | 2046782 | 2012-05-09 22:53:32 -0400 | [diff] [blame] | 32 | #include <linux/ip.h> |
Paul Gortmaker | be9a120 | 2012-05-09 22:42:45 -0400 | [diff] [blame] | 33 | #include <linux/if_ether.h> |
Ali Bahar | 359140a | 2011-09-04 03:14:11 +0800 | [diff] [blame] | 34 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 35 | #include "osdep_service.h" |
| 36 | #include "drv_types.h" |
| 37 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 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 | { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 45 | return (uint)(pfile->buf_len - ((addr_t)(pfile->cur_addr) - |
| 46 | (addr_t)(pfile->buf_start))); |
| 47 | } |
| 48 | |
| 49 | void _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 Cort | 77e73e8 | 2013-10-01 11:26:55 -0400 | [diff] [blame] | 54 | pfile->cur_buffer = pfile->buf_start; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | uint _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 | |
| 71 | sint r8712_endofpktfile(struct pkt_file *pfile) |
| 72 | { |
Bhaktipriya Shridhar | 6e4eb86 | 2016-02-22 18:59:45 +0530 | [diff] [blame] | 73 | return (pfile->pkt_len == 0); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | |
| 77 | void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib) |
| 78 | { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 79 | 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 *)ðerhdr, ETH_HLEN); |
| 85 | |
| 86 | /* get UserPriority from IP hdr*/ |
| 87 | if (pattrib->ether_type == 0x0800) { |
Sudip Mukherjee | e29d3eb | 2014-10-27 17:42:25 +0530 | [diff] [blame] | 88 | _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr)); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 89 | /*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 Bahar | f95302e | 2011-09-04 03:14:18 +0800 | [diff] [blame] | 104 | void 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 Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 124 | int 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 Bahar | 68e9b24 | 2011-09-04 03:14:07 +0800 | [diff] [blame] | 130 | pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL); |
Bhaktipriya Shridhar | 7cb07dc | 2016-02-19 00:24:30 +0530 | [diff] [blame] | 131 | if (!pxmitbuf->pxmit_urb[i]) { |
Przemo Firszt | 87a573a | 2012-12-10 23:21:21 +0000 | [diff] [blame] | 132 | netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n"); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 133 | return _FAIL; |
| 134 | } |
| 135 | } |
| 136 | return _SUCCESS; |
| 137 | } |
| 138 | |
| 139 | void 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 | |
| 152 | void 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 | |
| 159 | int r8712_xmit_entry(_pkt *pkt, struct net_device *pnetdev) |
| 160 | { |
| 161 | struct xmit_frame *pxmitframe = NULL; |
Julia Lawall | 8f47c28 | 2015-03-29 14:54:12 +0200 | [diff] [blame] | 162 | struct _adapter *padapter = netdev_priv(pnetdev); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 163 | struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 164 | |
Luis de Bethencourt | 1ca9688 | 2015-10-19 18:14:29 +0100 | [diff] [blame] | 165 | if (!r8712_if_up(padapter)) { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 166 | goto _xmit_entry_drop; |
| 167 | } |
| 168 | pxmitframe = r8712_alloc_xmitframe(pxmitpriv); |
Bhaktipriya Shridhar | 7cb07dc | 2016-02-19 00:24:30 +0530 | [diff] [blame] | 169 | if (!pxmitframe) { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 170 | goto _xmit_entry_drop; |
| 171 | } |
| 172 | if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 173 | goto _xmit_entry_drop; |
| 174 | } |
| 175 | padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX); |
| 176 | pxmitframe->pkt = pkt; |
Luis de Bethencourt | 1ca9688 | 2015-10-19 18:14:29 +0100 | [diff] [blame] | 177 | if (r8712_pre_xmit(padapter, pxmitframe)) { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 178 | /*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 Shridhar | 40430f0 | 2016-02-25 16:17:33 +0530 | [diff] [blame] | 184 | return 0; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 185 | _xmit_entry_drop: |
| 186 | if (pxmitframe) |
| 187 | r8712_free_xmitframe(pxmitpriv, pxmitframe); |
| 188 | pxmitpriv->tx_drop++; |
| 189 | dev_kfree_skb_any(pkt); |
Bhaktipriya Shridhar | 40430f0 | 2016-02-25 16:17:33 +0530 | [diff] [blame] | 190 | return 0; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 191 | } |