txrx.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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_index = priv->bss_index;
  48. return mwifiex_process_sta_rx_packet(adapter, skb);
  49. }
  50. EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
  51. /*
  52. * This function sends a packet to device.
  53. *
  54. * It processes the packet to add the TxPD, checks condition and
  55. * sends the processed packet to firmware for transmission.
  56. *
  57. * On successful completion, the function calls the completion callback
  58. * and logs the time.
  59. */
  60. int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
  61. struct mwifiex_tx_param *tx_param)
  62. {
  63. int ret = -1;
  64. struct mwifiex_adapter *adapter = priv->adapter;
  65. u8 *head_ptr;
  66. struct txpd *local_tx_pd = NULL;
  67. head_ptr = (u8 *) mwifiex_process_sta_txpd(priv, skb);
  68. if (head_ptr) {
  69. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
  70. local_tx_pd =
  71. (struct txpd *) (head_ptr + INTF_HEADER_LEN);
  72. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  73. skb->data, skb->len, tx_param);
  74. }
  75. switch (ret) {
  76. case -EBUSY:
  77. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  78. (adapter->pps_uapsd_mode) &&
  79. (adapter->tx_lock_flag)) {
  80. priv->adapter->tx_lock_flag = false;
  81. local_tx_pd->flags = 0;
  82. }
  83. dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
  84. break;
  85. case -1:
  86. adapter->data_sent = false;
  87. dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
  88. ret);
  89. adapter->dbg.num_tx_host_to_card_failure++;
  90. mwifiex_write_data_complete(adapter, skb, ret);
  91. break;
  92. case -EINPROGRESS:
  93. adapter->data_sent = false;
  94. break;
  95. case 0:
  96. mwifiex_write_data_complete(adapter, skb, ret);
  97. break;
  98. default:
  99. break;
  100. }
  101. return ret;
  102. }
  103. /*
  104. * Packet send completion callback handler.
  105. *
  106. * It either frees the buffer directly or forwards it to another
  107. * completion callback which checks conditions, updates statistics,
  108. * wakes up stalled traffic queue if required, and then frees the buffer.
  109. */
  110. int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
  111. struct sk_buff *skb, int status)
  112. {
  113. struct mwifiex_private *priv, *tpriv;
  114. struct mwifiex_txinfo *tx_info;
  115. int i;
  116. if (!skb)
  117. return 0;
  118. tx_info = MWIFIEX_SKB_TXCB(skb);
  119. priv = mwifiex_bss_index_to_priv(adapter, tx_info->bss_index);
  120. if (!priv)
  121. goto done;
  122. priv->netdev->trans_start = jiffies;
  123. if (!status) {
  124. priv->stats.tx_packets++;
  125. priv->stats.tx_bytes += skb->len;
  126. } else {
  127. priv->stats.tx_errors++;
  128. }
  129. if (atomic_dec_return(&adapter->tx_pending) >= LOW_TX_PENDING)
  130. goto done;
  131. for (i = 0; i < adapter->priv_num; i++) {
  132. tpriv = adapter->priv[i];
  133. if ((GET_BSS_ROLE(tpriv) == MWIFIEX_BSS_ROLE_STA)
  134. && (tpriv->media_connected)) {
  135. if (netif_queue_stopped(tpriv->netdev))
  136. netif_wake_queue(tpriv->netdev);
  137. }
  138. }
  139. done:
  140. dev_kfree_skb_any(skb);
  141. return 0;
  142. }
  143. /*
  144. * Packet receive completion callback handler.
  145. *
  146. * This function calls another completion callback handler which
  147. * updates the statistics, and optionally updates the parent buffer
  148. * use count before freeing the received packet.
  149. */
  150. int mwifiex_recv_packet_complete(struct mwifiex_adapter *adapter,
  151. struct sk_buff *skb, int status)
  152. {
  153. struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
  154. struct mwifiex_rxinfo *rx_info_parent;
  155. struct mwifiex_private *priv;
  156. struct sk_buff *skb_parent;
  157. unsigned long flags;
  158. priv = adapter->priv[rx_info->bss_index];
  159. if (priv && (status == -1))
  160. priv->stats.rx_dropped++;
  161. if (rx_info->parent) {
  162. skb_parent = rx_info->parent;
  163. rx_info_parent = MWIFIEX_SKB_RXCB(skb_parent);
  164. spin_lock_irqsave(&priv->rx_pkt_lock, flags);
  165. --rx_info_parent->use_count;
  166. if (!rx_info_parent->use_count) {
  167. spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
  168. dev_kfree_skb_any(skb_parent);
  169. } else {
  170. spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
  171. }
  172. } else {
  173. dev_kfree_skb_any(skb);
  174. }
  175. return 0;
  176. }