txrx.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Marvell Wireless LAN device driver: generic TX/RX data handling
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. /*
  26. * This function processes the received buffer.
  27. *
  28. * Main responsibility of this function is to parse the RxPD to
  29. * identify the correct interface this packet is headed for and
  30. * forwarding it to the associated handling function, where the
  31. * packet will be further processed and sent to kernel/upper layer
  32. * if required.
  33. */
  34. int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
  35. struct sk_buff *skb)
  36. {
  37. struct mwifiex_private *priv =
  38. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  39. struct rxpd *local_rx_pd;
  40. struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
  41. local_rx_pd = (struct rxpd *) (skb->data);
  42. /* Get the BSS number from rxpd, get corresponding priv */
  43. priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num &
  44. BSS_NUM_MASK, local_rx_pd->bss_type);
  45. if (!priv)
  46. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  47. rx_info->bss_num = priv->bss_num;
  48. rx_info->bss_type = priv->bss_type;
  49. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
  50. return mwifiex_process_uap_rx_packet(adapter, skb);
  51. return mwifiex_process_sta_rx_packet(adapter, skb);
  52. }
  53. EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
  54. /*
  55. * This function sends a packet to device.
  56. *
  57. * It processes the packet to add the TxPD, checks condition and
  58. * sends the processed packet to firmware for transmission.
  59. *
  60. * On successful completion, the function calls the completion callback
  61. * and logs the time.
  62. */
  63. int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
  64. struct mwifiex_tx_param *tx_param)
  65. {
  66. int ret = -1;
  67. struct mwifiex_adapter *adapter = priv->adapter;
  68. u8 *head_ptr;
  69. struct txpd *local_tx_pd = NULL;
  70. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
  71. head_ptr = mwifiex_process_uap_txpd(priv, skb);
  72. else
  73. head_ptr = mwifiex_process_sta_txpd(priv, skb);
  74. if (head_ptr) {
  75. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
  76. local_tx_pd =
  77. (struct txpd *) (head_ptr + INTF_HEADER_LEN);
  78. if (adapter->iface_type == MWIFIEX_USB) {
  79. adapter->data_sent = true;
  80. skb_pull(skb, INTF_HEADER_LEN);
  81. ret = adapter->if_ops.host_to_card(adapter,
  82. MWIFIEX_USB_EP_DATA,
  83. skb, NULL);
  84. } else {
  85. ret = adapter->if_ops.host_to_card(adapter,
  86. MWIFIEX_TYPE_DATA,
  87. skb, tx_param);
  88. }
  89. }
  90. switch (ret) {
  91. case -ENOSR:
  92. dev_err(adapter->dev, "data: -ENOSR is returned\n");
  93. break;
  94. case -EBUSY:
  95. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  96. (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
  97. priv->adapter->tx_lock_flag = false;
  98. if (local_tx_pd)
  99. local_tx_pd->flags = 0;
  100. }
  101. dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
  102. break;
  103. case -1:
  104. adapter->data_sent = false;
  105. dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
  106. ret);
  107. adapter->dbg.num_tx_host_to_card_failure++;
  108. mwifiex_write_data_complete(adapter, skb, ret);
  109. break;
  110. case -EINPROGRESS:
  111. adapter->data_sent = false;
  112. break;
  113. case 0:
  114. mwifiex_write_data_complete(adapter, skb, ret);
  115. break;
  116. default:
  117. break;
  118. }
  119. return ret;
  120. }
  121. /*
  122. * Packet send completion callback handler.
  123. *
  124. * It either frees the buffer directly or forwards it to another
  125. * completion callback which checks conditions, updates statistics,
  126. * wakes up stalled traffic queue if required, and then frees the buffer.
  127. */
  128. int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
  129. struct sk_buff *skb, int status)
  130. {
  131. struct mwifiex_private *priv, *tpriv;
  132. struct mwifiex_txinfo *tx_info;
  133. int i;
  134. if (!skb)
  135. return 0;
  136. tx_info = MWIFIEX_SKB_TXCB(skb);
  137. priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
  138. tx_info->bss_type);
  139. if (!priv)
  140. goto done;
  141. if (adapter->iface_type == MWIFIEX_USB)
  142. adapter->data_sent = false;
  143. mwifiex_set_trans_start(priv->netdev);
  144. if (!status) {
  145. priv->stats.tx_packets++;
  146. priv->stats.tx_bytes += skb->len;
  147. } else {
  148. priv->stats.tx_errors++;
  149. }
  150. if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
  151. atomic_dec_return(&adapter->pending_bridged_pkts);
  152. if (atomic_dec_return(&adapter->tx_pending) >= LOW_TX_PENDING)
  153. goto done;
  154. for (i = 0; i < adapter->priv_num; i++) {
  155. tpriv = adapter->priv[i];
  156. if (tpriv->media_connected &&
  157. netif_queue_stopped(tpriv->netdev))
  158. mwifiex_wake_up_net_dev_queue(tpriv->netdev, adapter);
  159. }
  160. done:
  161. dev_kfree_skb_any(skb);
  162. return 0;
  163. }
  164. EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);