sta_tx.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 = (priv->adapter->iface_type == MWIFIEX_USB) ? 0 :
  51. INTF_HEADER_LEN;
  52. if (!skb->len) {
  53. mwifiex_dbg(adapter, ERROR,
  54. "Tx: bad packet length: %d\n", skb->len);
  55. tx_info->status_code = -1;
  56. return skb->data;
  57. }
  58. BUG_ON(skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN);
  59. pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
  60. pad = ((void *)skb->data - (sizeof(*local_tx_pd) + hroom)-
  61. NULL) & (MWIFIEX_DMA_ALIGN_SZ - 1);
  62. skb_push(skb, sizeof(*local_tx_pd) + pad);
  63. local_tx_pd = (struct txpd *) skb->data;
  64. memset(local_tx_pd, 0, sizeof(struct txpd));
  65. local_tx_pd->bss_num = priv->bss_num;
  66. local_tx_pd->bss_type = priv->bss_type;
  67. local_tx_pd->tx_pkt_length = cpu_to_le16((u16)(skb->len -
  68. (sizeof(struct txpd) +
  69. pad)));
  70. local_tx_pd->priority = (u8) skb->priority;
  71. local_tx_pd->pkt_delay_2ms =
  72. mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
  73. if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS ||
  74. tx_info->flags & MWIFIEX_BUF_FLAG_ACTION_TX_STATUS) {
  75. local_tx_pd->tx_token_id = tx_info->ack_frame_id;
  76. local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS;
  77. }
  78. if (local_tx_pd->priority <
  79. ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
  80. /*
  81. * Set the priority specific tx_control field, setting of 0 will
  82. * cause the default value to be used later in this function
  83. */
  84. local_tx_pd->tx_control =
  85. cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd->
  86. priority]);
  87. if (adapter->pps_uapsd_mode) {
  88. if (mwifiex_check_last_packet_indication(priv)) {
  89. adapter->tx_lock_flag = true;
  90. local_tx_pd->flags =
  91. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
  92. }
  93. }
  94. if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
  95. local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
  96. /* Offset of actual data */
  97. pkt_offset = sizeof(struct txpd) + pad;
  98. if (pkt_type == PKT_TYPE_MGMT) {
  99. /* Set the packet type and add header for management frame */
  100. local_tx_pd->tx_pkt_type = cpu_to_le16(pkt_type);
  101. pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
  102. }
  103. local_tx_pd->tx_pkt_offset = cpu_to_le16(pkt_offset);
  104. /* make space for INTF_HEADER_LEN */
  105. skb_push(skb, hroom);
  106. if (!local_tx_pd->tx_control)
  107. /* TxCtrl set by user or default */
  108. local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  109. return skb->data;
  110. }
  111. /*
  112. * This function tells firmware to send a NULL data packet.
  113. *
  114. * The function creates a NULL data packet with TxPD and sends to the
  115. * firmware for transmission, with highest priority setting.
  116. */
  117. int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags)
  118. {
  119. struct mwifiex_adapter *adapter = priv->adapter;
  120. struct txpd *local_tx_pd;
  121. struct mwifiex_tx_param tx_param;
  122. /* sizeof(struct txpd) + Interface specific header */
  123. #define NULL_PACKET_HDR 64
  124. u32 data_len = NULL_PACKET_HDR;
  125. struct sk_buff *skb;
  126. int ret;
  127. struct mwifiex_txinfo *tx_info = NULL;
  128. if (adapter->surprise_removed)
  129. return -1;
  130. if (!priv->media_connected)
  131. return -1;
  132. if (adapter->data_sent)
  133. return -1;
  134. if (adapter->if_ops.is_port_ready &&
  135. !adapter->if_ops.is_port_ready(priv))
  136. return -1;
  137. skb = dev_alloc_skb(data_len);
  138. if (!skb)
  139. return -1;
  140. tx_info = MWIFIEX_SKB_TXCB(skb);
  141. memset(tx_info, 0, sizeof(*tx_info));
  142. tx_info->bss_num = priv->bss_num;
  143. tx_info->bss_type = priv->bss_type;
  144. tx_info->pkt_len = data_len - (sizeof(struct txpd) + INTF_HEADER_LEN);
  145. skb_reserve(skb, sizeof(struct txpd) + INTF_HEADER_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. if (adapter->iface_type == MWIFIEX_USB) {
  155. ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
  156. skb, NULL);
  157. } else {
  158. skb_push(skb, INTF_HEADER_LEN);
  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. }