sta_tx.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. u8 pad;
  49. if (!skb->len) {
  50. dev_err(adapter->dev, "Tx: bad packet length: %d\n", skb->len);
  51. tx_info->status_code = -1;
  52. return skb->data;
  53. }
  54. /* If skb->data is not aligned; add padding */
  55. pad = (4 - (((void *)skb->data - NULL) & 0x3)) % 4;
  56. BUG_ON(skb_headroom(skb) < (sizeof(*local_tx_pd) + INTF_HEADER_LEN
  57. + pad));
  58. skb_push(skb, sizeof(*local_tx_pd) + pad);
  59. local_tx_pd = (struct txpd *) skb->data;
  60. memset(local_tx_pd, 0, sizeof(struct txpd));
  61. local_tx_pd->bss_num = priv->bss_num;
  62. local_tx_pd->bss_type = priv->bss_type;
  63. local_tx_pd->tx_pkt_length = cpu_to_le16((u16)(skb->len -
  64. (sizeof(struct txpd)
  65. + pad)));
  66. local_tx_pd->priority = (u8) skb->priority;
  67. local_tx_pd->pkt_delay_2ms =
  68. mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
  69. if (local_tx_pd->priority <
  70. ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
  71. /*
  72. * Set the priority specific tx_control field, setting of 0 will
  73. * cause the default value to be used later in this function
  74. */
  75. local_tx_pd->tx_control =
  76. cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd->
  77. priority]);
  78. if (adapter->pps_uapsd_mode) {
  79. if (mwifiex_check_last_packet_indication(priv)) {
  80. adapter->tx_lock_flag = true;
  81. local_tx_pd->flags =
  82. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
  83. }
  84. }
  85. /* Offset of actual data */
  86. local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd) + pad);
  87. /* make space for INTF_HEADER_LEN */
  88. skb_push(skb, INTF_HEADER_LEN);
  89. if (!local_tx_pd->tx_control)
  90. /* TxCtrl set by user or default */
  91. local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  92. return skb->data;
  93. }
  94. /*
  95. * This function tells firmware to send a NULL data packet.
  96. *
  97. * The function creates a NULL data packet with TxPD and sends to the
  98. * firmware for transmission, with highest priority setting.
  99. */
  100. int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags)
  101. {
  102. struct mwifiex_adapter *adapter = priv->adapter;
  103. struct txpd *local_tx_pd;
  104. /* sizeof(struct txpd) + Interface specific header */
  105. #define NULL_PACKET_HDR 64
  106. u32 data_len = NULL_PACKET_HDR;
  107. struct sk_buff *skb;
  108. int ret;
  109. struct mwifiex_txinfo *tx_info = NULL;
  110. if (adapter->surprise_removed)
  111. return -1;
  112. if (!priv->media_connected)
  113. return -1;
  114. if (adapter->data_sent)
  115. return -1;
  116. skb = dev_alloc_skb(data_len);
  117. if (!skb)
  118. return -1;
  119. tx_info = MWIFIEX_SKB_TXCB(skb);
  120. tx_info->bss_num = priv->bss_num;
  121. tx_info->bss_type = priv->bss_type;
  122. skb_reserve(skb, sizeof(struct txpd) + INTF_HEADER_LEN);
  123. skb_push(skb, sizeof(struct txpd));
  124. local_tx_pd = (struct txpd *) skb->data;
  125. local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  126. local_tx_pd->flags = flags;
  127. local_tx_pd->priority = WMM_HIGHEST_PRIORITY;
  128. local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
  129. local_tx_pd->bss_num = priv->bss_num;
  130. local_tx_pd->bss_type = priv->bss_type;
  131. skb_push(skb, INTF_HEADER_LEN);
  132. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  133. skb, NULL);
  134. switch (ret) {
  135. case -EBUSY:
  136. adapter->data_sent = true;
  137. /* Fall through FAILURE handling */
  138. case -1:
  139. dev_kfree_skb_any(skb);
  140. dev_err(adapter->dev, "%s: host_to_card failed: ret=%d\n",
  141. __func__, ret);
  142. adapter->dbg.num_tx_host_to_card_failure++;
  143. break;
  144. case 0:
  145. dev_kfree_skb_any(skb);
  146. dev_dbg(adapter->dev, "data: %s: host_to_card succeeded\n",
  147. __func__);
  148. adapter->tx_lock_flag = true;
  149. break;
  150. case -EINPROGRESS:
  151. break;
  152. default:
  153. break;
  154. }
  155. return ret;
  156. }
  157. /*
  158. * This function checks if we need to send last packet indication.
  159. */
  160. u8
  161. mwifiex_check_last_packet_indication(struct mwifiex_private *priv)
  162. {
  163. struct mwifiex_adapter *adapter = priv->adapter;
  164. u8 ret = false;
  165. if (!adapter->sleep_period.period)
  166. return ret;
  167. if (mwifiex_wmm_lists_empty(adapter))
  168. ret = true;
  169. if (ret && !adapter->cmd_sent && !adapter->curr_cmd &&
  170. !is_command_pending(adapter)) {
  171. adapter->delay_null_pkt = false;
  172. ret = true;
  173. } else {
  174. ret = false;
  175. adapter->delay_null_pkt = true;
  176. }
  177. return ret;
  178. }