sta_tx.c 6.9 KB

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