sta_tx.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Marvell Wireless LAN device driver: station TX 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 fills the TxPD for tx packets.
  27. *
  28. * The Tx buffer received by this function should already have the
  29. * header space allocated for TxPD.
  30. *
  31. * This function inserts the TxPD in between interface header and actual
  32. * data and adjusts the buffer pointers accordingly.
  33. *
  34. * The following TxPD fields are set by this function, as required -
  35. * - BSS number
  36. * - Tx packet length and offset
  37. * - Priority
  38. * - Packet delay
  39. * - Priority specific Tx control
  40. * - Flags
  41. */
  42. void *mwifiex_process_sta_txpd(struct mwifiex_private *priv,
  43. struct sk_buff *skb)
  44. {
  45. struct mwifiex_adapter *adapter = priv->adapter;
  46. struct txpd *local_tx_pd;
  47. struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
  48. if (!skb->len) {
  49. dev_err(adapter->dev, "Tx: bad packet length: %d\n",
  50. skb->len);
  51. tx_info->status_code = -1;
  52. return skb->data;
  53. }
  54. BUG_ON(skb_headroom(skb) < (sizeof(*local_tx_pd) + INTF_HEADER_LEN));
  55. skb_push(skb, sizeof(*local_tx_pd));
  56. local_tx_pd = (struct txpd *) skb->data;
  57. memset(local_tx_pd, 0, sizeof(struct txpd));
  58. local_tx_pd->bss_num = priv->bss_num;
  59. local_tx_pd->bss_type = priv->bss_type;
  60. local_tx_pd->tx_pkt_length = cpu_to_le16((u16) (skb->len -
  61. sizeof(struct txpd)));
  62. local_tx_pd->priority = (u8) skb->priority;
  63. local_tx_pd->pkt_delay_2ms =
  64. mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
  65. if (local_tx_pd->priority <
  66. ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
  67. /*
  68. * Set the priority specific tx_control field, setting of 0 will
  69. * cause the default value to be used later in this function
  70. */
  71. local_tx_pd->tx_control =
  72. cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd->
  73. priority]);
  74. if (adapter->pps_uapsd_mode) {
  75. if (mwifiex_check_last_packet_indication(priv)) {
  76. adapter->tx_lock_flag = true;
  77. local_tx_pd->flags =
  78. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
  79. }
  80. }
  81. /* Offset of actual data */
  82. local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
  83. /* make space for INTF_HEADER_LEN */
  84. skb_push(skb, INTF_HEADER_LEN);
  85. if (!local_tx_pd->tx_control)
  86. /* TxCtrl set by user or default */
  87. local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  88. return skb->data;
  89. }
  90. /*
  91. * This function tells firmware to send a NULL data packet.
  92. *
  93. * The function creates a NULL data packet with TxPD and sends to the
  94. * firmware for transmission, with highest priority setting.
  95. */
  96. int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags)
  97. {
  98. struct mwifiex_adapter *adapter = priv->adapter;
  99. struct txpd *local_tx_pd;
  100. /* sizeof(struct txpd) + Interface specific header */
  101. #define NULL_PACKET_HDR 64
  102. u32 data_len = NULL_PACKET_HDR;
  103. struct sk_buff *skb = NULL;
  104. int ret = 0;
  105. struct mwifiex_txinfo *tx_info = NULL;
  106. if (adapter->surprise_removed)
  107. return -1;
  108. if (!priv->media_connected)
  109. return -1;
  110. if (adapter->data_sent)
  111. return -1;
  112. skb = dev_alloc_skb(data_len);
  113. if (!skb)
  114. return -1;
  115. tx_info = MWIFIEX_SKB_TXCB(skb);
  116. tx_info->bss_index = priv->bss_index;
  117. skb_reserve(skb, sizeof(struct txpd) + INTF_HEADER_LEN);
  118. skb_push(skb, sizeof(struct txpd));
  119. local_tx_pd = (struct txpd *) skb->data;
  120. local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  121. local_tx_pd->flags = flags;
  122. local_tx_pd->priority = WMM_HIGHEST_PRIORITY;
  123. local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
  124. local_tx_pd->bss_num = priv->bss_num;
  125. local_tx_pd->bss_type = priv->bss_type;
  126. skb_push(skb, INTF_HEADER_LEN);
  127. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  128. skb->data, skb->len, NULL);
  129. switch (ret) {
  130. case -EBUSY:
  131. adapter->data_sent = true;
  132. /* Fall through FAILURE handling */
  133. case -1:
  134. dev_kfree_skb_any(skb);
  135. dev_err(adapter->dev, "%s: host_to_card failed: ret=%d\n",
  136. __func__, ret);
  137. adapter->dbg.num_tx_host_to_card_failure++;
  138. break;
  139. case 0:
  140. dev_kfree_skb_any(skb);
  141. dev_dbg(adapter->dev, "data: %s: host_to_card succeeded\n",
  142. __func__);
  143. adapter->tx_lock_flag = true;
  144. break;
  145. case -EINPROGRESS:
  146. break;
  147. default:
  148. break;
  149. }
  150. return ret;
  151. }
  152. /*
  153. * This function checks if we need to send last packet indication.
  154. */
  155. u8
  156. mwifiex_check_last_packet_indication(struct mwifiex_private *priv)
  157. {
  158. struct mwifiex_adapter *adapter = priv->adapter;
  159. u8 ret = false;
  160. if (!adapter->sleep_period.period)
  161. return ret;
  162. if (mwifiex_wmm_lists_empty(adapter))
  163. ret = true;
  164. if (ret && !adapter->cmd_sent && !adapter->curr_cmd
  165. && !is_command_pending(adapter)) {
  166. adapter->delay_null_pkt = false;
  167. ret = true;
  168. } else {
  169. ret = false;
  170. adapter->delay_null_pkt = true;
  171. }
  172. return ret;
  173. }