txrx.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. if (!priv) {
  48. dev_err(adapter->dev, "data: priv not found. Drop RX packet\n");
  49. dev_kfree_skb_any(skb);
  50. return -1;
  51. }
  52. rx_info->bss_num = priv->bss_num;
  53. rx_info->bss_type = priv->bss_type;
  54. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
  55. return mwifiex_process_uap_rx_packet(priv, skb);
  56. return mwifiex_process_sta_rx_packet(priv, skb);
  57. }
  58. EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
  59. /*
  60. * This function sends a packet to device.
  61. *
  62. * It processes the packet to add the TxPD, checks condition and
  63. * sends the processed packet to firmware for transmission.
  64. *
  65. * On successful completion, the function calls the completion callback
  66. * and logs the time.
  67. */
  68. int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
  69. struct mwifiex_tx_param *tx_param)
  70. {
  71. int ret = -1;
  72. struct mwifiex_adapter *adapter = priv->adapter;
  73. u8 *head_ptr;
  74. struct txpd *local_tx_pd = NULL;
  75. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
  76. head_ptr = mwifiex_process_uap_txpd(priv, skb);
  77. else
  78. head_ptr = mwifiex_process_sta_txpd(priv, skb);
  79. if (head_ptr) {
  80. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
  81. local_tx_pd =
  82. (struct txpd *) (head_ptr + INTF_HEADER_LEN);
  83. if (adapter->iface_type == MWIFIEX_USB) {
  84. adapter->data_sent = true;
  85. skb_pull(skb, INTF_HEADER_LEN);
  86. ret = adapter->if_ops.host_to_card(adapter,
  87. MWIFIEX_USB_EP_DATA,
  88. skb, NULL);
  89. } else {
  90. ret = adapter->if_ops.host_to_card(adapter,
  91. MWIFIEX_TYPE_DATA,
  92. skb, tx_param);
  93. }
  94. }
  95. switch (ret) {
  96. case -ENOSR:
  97. dev_err(adapter->dev, "data: -ENOSR is returned\n");
  98. break;
  99. case -EBUSY:
  100. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  101. (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
  102. priv->adapter->tx_lock_flag = false;
  103. if (local_tx_pd)
  104. local_tx_pd->flags = 0;
  105. }
  106. dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
  107. break;
  108. case -1:
  109. if (adapter->iface_type != MWIFIEX_PCIE)
  110. adapter->data_sent = false;
  111. dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
  112. ret);
  113. adapter->dbg.num_tx_host_to_card_failure++;
  114. mwifiex_write_data_complete(adapter, skb, 0, ret);
  115. break;
  116. case -EINPROGRESS:
  117. if (adapter->iface_type != MWIFIEX_PCIE)
  118. adapter->data_sent = false;
  119. break;
  120. case 0:
  121. mwifiex_write_data_complete(adapter, skb, 0, ret);
  122. break;
  123. default:
  124. break;
  125. }
  126. return ret;
  127. }
  128. /*
  129. * Packet send completion callback handler.
  130. *
  131. * It either frees the buffer directly or forwards it to another
  132. * completion callback which checks conditions, updates statistics,
  133. * wakes up stalled traffic queue if required, and then frees the buffer.
  134. */
  135. int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
  136. struct sk_buff *skb, int aggr, int status)
  137. {
  138. struct mwifiex_private *priv;
  139. struct mwifiex_txinfo *tx_info;
  140. struct netdev_queue *txq;
  141. int index;
  142. if (!skb)
  143. return 0;
  144. tx_info = MWIFIEX_SKB_TXCB(skb);
  145. priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
  146. tx_info->bss_type);
  147. if (!priv)
  148. goto done;
  149. if (adapter->iface_type == MWIFIEX_USB)
  150. adapter->data_sent = false;
  151. mwifiex_set_trans_start(priv->netdev);
  152. if (!status) {
  153. priv->stats.tx_packets++;
  154. priv->stats.tx_bytes += skb->len;
  155. if (priv->tx_timeout_cnt)
  156. priv->tx_timeout_cnt = 0;
  157. } else {
  158. priv->stats.tx_errors++;
  159. }
  160. if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
  161. atomic_dec_return(&adapter->pending_bridged_pkts);
  162. if (aggr)
  163. /* For skb_aggr, do not wake up tx queue */
  164. goto done;
  165. atomic_dec(&adapter->tx_pending);
  166. index = mwifiex_1d_to_wmm_queue[skb->priority];
  167. if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) {
  168. txq = netdev_get_tx_queue(priv->netdev, index);
  169. if (netif_tx_queue_stopped(txq)) {
  170. netif_tx_wake_queue(txq);
  171. dev_dbg(adapter->dev, "wake queue: %d\n", index);
  172. }
  173. }
  174. done:
  175. dev_kfree_skb_any(skb);
  176. return 0;
  177. }
  178. EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);