txrx.c 5.9 KB

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