sta_tx.c 6.1 KB

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