xmit_linux.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #define _XMIT_OSDEP_C_
  29. #include <linux/usb.h>
  30. #include <linux/ip.h>
  31. #include <linux/if_ether.h>
  32. #include "osdep_service.h"
  33. #include "drv_types.h"
  34. #include "wifi.h"
  35. #include "mlme_osdep.h"
  36. #include "xmit_osdep.h"
  37. #include "osdep_intf.h"
  38. static uint remainder_len(struct pkt_file *pfile)
  39. {
  40. return (uint)(pfile->buf_len - ((addr_t)(pfile->cur_addr) -
  41. (addr_t)(pfile->buf_start)));
  42. }
  43. void _r8712_open_pktfile(_pkt *pktptr, struct pkt_file *pfile)
  44. {
  45. pfile->pkt = pktptr;
  46. pfile->cur_addr = pfile->buf_start = pktptr->data;
  47. pfile->pkt_len = pfile->buf_len = pktptr->len;
  48. pfile->cur_buffer = pfile->buf_start;
  49. }
  50. uint _r8712_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
  51. {
  52. uint len;
  53. len = remainder_len(pfile);
  54. len = (rlen > len) ? len : rlen;
  55. if (rmem)
  56. skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len,
  57. rmem, len);
  58. pfile->cur_addr += len;
  59. pfile->pkt_len -= len;
  60. return len;
  61. }
  62. sint r8712_endofpktfile(struct pkt_file *pfile)
  63. {
  64. if (pfile->pkt_len == 0)
  65. return true;
  66. else
  67. return false;
  68. }
  69. void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
  70. {
  71. struct ethhdr etherhdr;
  72. struct iphdr ip_hdr;
  73. u16 UserPriority = 0;
  74. _r8712_open_pktfile(ppktfile->pkt, ppktfile);
  75. _r8712_pktfile_read(ppktfile, (unsigned char *)&etherhdr, ETH_HLEN);
  76. /* get UserPriority from IP hdr*/
  77. if (pattrib->ether_type == 0x0800) {
  78. _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
  79. /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/
  80. UserPriority = ip_hdr.tos >> 5;
  81. } else {
  82. /* "When priority processing of data frames is supported,
  83. * a STA's SME should send EAPOL-Key frames at the highest
  84. * priority." */
  85. if (pattrib->ether_type == 0x888e)
  86. UserPriority = 7;
  87. }
  88. pattrib->priority = UserPriority;
  89. pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
  90. pattrib->subtype = WIFI_QOS_DATA_TYPE;
  91. }
  92. void r8712_SetFilter(struct work_struct *work)
  93. {
  94. struct _adapter *padapter = container_of(work, struct _adapter,
  95. wkFilterRxFF0);
  96. u8 oldvalue = 0x00, newvalue = 0x00;
  97. unsigned long irqL;
  98. oldvalue = r8712_read8(padapter, 0x117);
  99. newvalue = oldvalue & 0xfe;
  100. r8712_write8(padapter, 0x117, newvalue);
  101. spin_lock_irqsave(&padapter->lockRxFF0Filter, irqL);
  102. padapter->blnEnableRxFF0Filter = 1;
  103. spin_unlock_irqrestore(&padapter->lockRxFF0Filter, irqL);
  104. do {
  105. msleep(100);
  106. } while (padapter->blnEnableRxFF0Filter == 1);
  107. r8712_write8(padapter, 0x117, oldvalue);
  108. }
  109. int r8712_xmit_resource_alloc(struct _adapter *padapter,
  110. struct xmit_buf *pxmitbuf)
  111. {
  112. int i;
  113. for (i = 0; i < 8; i++) {
  114. pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
  115. if (pxmitbuf->pxmit_urb[i] == NULL) {
  116. netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n");
  117. return _FAIL;
  118. }
  119. }
  120. return _SUCCESS;
  121. }
  122. void r8712_xmit_resource_free(struct _adapter *padapter,
  123. struct xmit_buf *pxmitbuf)
  124. {
  125. int i;
  126. for (i = 0; i < 8; i++) {
  127. if (pxmitbuf->pxmit_urb[i]) {
  128. usb_kill_urb(pxmitbuf->pxmit_urb[i]);
  129. usb_free_urb(pxmitbuf->pxmit_urb[i]);
  130. }
  131. }
  132. }
  133. void r8712_xmit_complete(struct _adapter *padapter, struct xmit_frame *pxframe)
  134. {
  135. if (pxframe->pkt)
  136. dev_kfree_skb_any(pxframe->pkt);
  137. pxframe->pkt = NULL;
  138. }
  139. int r8712_xmit_entry(_pkt *pkt, struct net_device *pnetdev)
  140. {
  141. struct xmit_frame *pxmitframe = NULL;
  142. struct _adapter *padapter = netdev_priv(pnetdev);
  143. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  144. int ret = 0;
  145. if (!r8712_if_up(padapter)) {
  146. ret = 0;
  147. goto _xmit_entry_drop;
  148. }
  149. pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
  150. if (pxmitframe == NULL) {
  151. ret = 0;
  152. goto _xmit_entry_drop;
  153. }
  154. if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) {
  155. ret = 0;
  156. goto _xmit_entry_drop;
  157. }
  158. padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
  159. pxmitframe->pkt = pkt;
  160. if (r8712_pre_xmit(padapter, pxmitframe)) {
  161. /*dump xmitframe directly or drop xframe*/
  162. dev_kfree_skb_any(pkt);
  163. pxmitframe->pkt = NULL;
  164. }
  165. pxmitpriv->tx_pkts++;
  166. pxmitpriv->tx_bytes += pxmitframe->attrib.last_txcmdsz;
  167. return ret;
  168. _xmit_entry_drop:
  169. if (pxmitframe)
  170. r8712_free_xmitframe(pxmitpriv, pxmitframe);
  171. pxmitpriv->tx_drop++;
  172. dev_kfree_skb_any(pkt);
  173. return ret;
  174. }