11n_aggr.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Marvell Wireless LAN device driver: 802.11n Aggregation
  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. #include "11n.h"
  26. #include "11n_aggr.h"
  27. /*
  28. * Creates an AMSDU subframe for aggregation into one AMSDU packet.
  29. *
  30. * The resultant AMSDU subframe format is -
  31. *
  32. * +---- ~ -----+---- ~ ------+---- ~ -----+----- ~ -----+---- ~ -----+
  33. * | DA | SA | Length | SNAP header | MSDU |
  34. * | data[0..5] | data[6..11] | | | data[14..] |
  35. * +---- ~ -----+---- ~ ------+---- ~ -----+----- ~ -----+---- ~ -----+
  36. * <--6-bytes--> <--6-bytes--> <--2-bytes--><--8-bytes--> <--n-bytes-->
  37. *
  38. * This function also computes the amount of padding required to make the
  39. * buffer length multiple of 4 bytes.
  40. *
  41. * Data => |DA|SA|SNAP-TYPE|........ .|
  42. * MSDU => |DA|SA|Length|SNAP|...... ..|
  43. */
  44. static int
  45. mwifiex_11n_form_amsdu_pkt(struct sk_buff *skb_aggr,
  46. struct sk_buff *skb_src, int *pad)
  47. {
  48. int dt_offset;
  49. struct rfc_1042_hdr snap = {
  50. 0xaa, /* LLC DSAP */
  51. 0xaa, /* LLC SSAP */
  52. 0x03, /* LLC CTRL */
  53. {0x00, 0x00, 0x00}, /* SNAP OUI */
  54. 0x0000 /* SNAP type */
  55. /*
  56. * This field will be overwritten
  57. * later with ethertype
  58. */
  59. };
  60. struct tx_packet_hdr *tx_header;
  61. tx_header = (void *)skb_put(skb_aggr, sizeof(*tx_header));
  62. /* Copy DA and SA */
  63. dt_offset = 2 * ETH_ALEN;
  64. memcpy(&tx_header->eth803_hdr, skb_src->data, dt_offset);
  65. /* Copy SNAP header */
  66. snap.snap_type = ((struct ethhdr *)skb_src->data)->h_proto;
  67. dt_offset += sizeof(__be16);
  68. memcpy(&tx_header->rfc1042_hdr, &snap, sizeof(struct rfc_1042_hdr));
  69. skb_pull(skb_src, dt_offset);
  70. /* Update Length field */
  71. tx_header->eth803_hdr.h_proto = htons(skb_src->len + LLC_SNAP_LEN);
  72. /* Add payload */
  73. memcpy(skb_put(skb_aggr, skb_src->len), skb_src->data, skb_src->len);
  74. /* Add padding for new MSDU to start from 4 byte boundary */
  75. *pad = (4 - ((unsigned long)skb_aggr->tail & 0x3)) % 4;
  76. return skb_aggr->len + *pad;
  77. }
  78. /*
  79. * Adds TxPD to AMSDU header.
  80. *
  81. * Each AMSDU packet will contain one TxPD at the beginning,
  82. * followed by multiple AMSDU subframes.
  83. */
  84. static void
  85. mwifiex_11n_form_amsdu_txpd(struct mwifiex_private *priv,
  86. struct sk_buff *skb)
  87. {
  88. struct txpd *local_tx_pd;
  89. struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
  90. unsigned int pad;
  91. int headroom = (priv->adapter->iface_type ==
  92. MWIFIEX_USB) ? 0 : INTF_HEADER_LEN;
  93. pad = ((void *)skb->data - sizeof(*local_tx_pd) -
  94. headroom - NULL) & (MWIFIEX_DMA_ALIGN_SZ - 1);
  95. skb_push(skb, pad);
  96. skb_push(skb, sizeof(*local_tx_pd));
  97. local_tx_pd = (struct txpd *) skb->data;
  98. memset(local_tx_pd, 0, sizeof(struct txpd));
  99. /* Original priority has been overwritten */
  100. local_tx_pd->priority = (u8) skb->priority;
  101. local_tx_pd->pkt_delay_2ms =
  102. mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
  103. local_tx_pd->bss_num = priv->bss_num;
  104. local_tx_pd->bss_type = priv->bss_type;
  105. /* Always zero as the data is followed by struct txpd */
  106. local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd) +
  107. pad);
  108. local_tx_pd->tx_pkt_type = cpu_to_le16(PKT_TYPE_AMSDU);
  109. local_tx_pd->tx_pkt_length = cpu_to_le16(skb->len -
  110. sizeof(*local_tx_pd) -
  111. pad);
  112. if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
  113. local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
  114. if (local_tx_pd->tx_control == 0)
  115. /* TxCtrl set by user or default */
  116. local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  117. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
  118. priv->adapter->pps_uapsd_mode) {
  119. if (true == mwifiex_check_last_packet_indication(priv)) {
  120. priv->adapter->tx_lock_flag = true;
  121. local_tx_pd->flags =
  122. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
  123. }
  124. }
  125. }
  126. /*
  127. * Create aggregated packet.
  128. *
  129. * This function creates an aggregated MSDU packet, by combining buffers
  130. * from the RA list. Each individual buffer is encapsulated as an AMSDU
  131. * subframe and all such subframes are concatenated together to form the
  132. * AMSDU packet.
  133. *
  134. * A TxPD is also added to the front of the resultant AMSDU packets for
  135. * transmission. The resultant packets format is -
  136. *
  137. * +---- ~ ----+------ ~ ------+------ ~ ------+-..-+------ ~ ------+
  138. * | TxPD |AMSDU sub-frame|AMSDU sub-frame| .. |AMSDU sub-frame|
  139. * | | 1 | 2 | .. | n |
  140. * +---- ~ ----+------ ~ ------+------ ~ ------+ .. +------ ~ ------+
  141. */
  142. int
  143. mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
  144. struct mwifiex_ra_list_tbl *pra_list,
  145. int ptrindex, unsigned long ra_list_flags)
  146. __releases(&priv->wmm.ra_list_spinlock)
  147. {
  148. struct mwifiex_adapter *adapter = priv->adapter;
  149. struct sk_buff *skb_aggr, *skb_src;
  150. struct mwifiex_txinfo *tx_info_aggr, *tx_info_src;
  151. int pad = 0, aggr_num = 0, ret;
  152. struct mwifiex_tx_param tx_param;
  153. struct txpd *ptx_pd = NULL;
  154. struct timeval tv;
  155. int headroom = adapter->iface_type == MWIFIEX_USB ? 0 : INTF_HEADER_LEN;
  156. skb_src = skb_peek(&pra_list->skb_head);
  157. if (!skb_src) {
  158. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  159. ra_list_flags);
  160. return 0;
  161. }
  162. tx_info_src = MWIFIEX_SKB_TXCB(skb_src);
  163. skb_aggr = mwifiex_alloc_dma_align_buf(adapter->tx_buf_size,
  164. GFP_ATOMIC | GFP_DMA);
  165. if (!skb_aggr) {
  166. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  167. ra_list_flags);
  168. return -1;
  169. }
  170. skb_reserve(skb_aggr, MWIFIEX_MIN_DATA_HEADER_LEN);
  171. tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr);
  172. memset(tx_info_aggr, 0, sizeof(*tx_info_aggr));
  173. tx_info_aggr->bss_type = tx_info_src->bss_type;
  174. tx_info_aggr->bss_num = tx_info_src->bss_num;
  175. if (tx_info_src->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
  176. tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
  177. tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_AGGR_PKT;
  178. skb_aggr->priority = skb_src->priority;
  179. do_gettimeofday(&tv);
  180. skb_aggr->tstamp = timeval_to_ktime(tv);
  181. do {
  182. /* Check if AMSDU can accommodate this MSDU */
  183. if (skb_tailroom(skb_aggr) < (skb_src->len + LLC_SNAP_LEN))
  184. break;
  185. skb_src = skb_dequeue(&pra_list->skb_head);
  186. pra_list->total_pkt_count--;
  187. atomic_dec(&priv->wmm.tx_pkts_queued);
  188. aggr_num++;
  189. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  190. ra_list_flags);
  191. mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad);
  192. mwifiex_write_data_complete(adapter, skb_src, 0, 0);
  193. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  194. if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
  195. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  196. ra_list_flags);
  197. return -1;
  198. }
  199. if (skb_tailroom(skb_aggr) < pad) {
  200. pad = 0;
  201. break;
  202. }
  203. skb_put(skb_aggr, pad);
  204. skb_src = skb_peek(&pra_list->skb_head);
  205. } while (skb_src);
  206. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  207. /* Last AMSDU packet does not need padding */
  208. skb_trim(skb_aggr, skb_aggr->len - pad);
  209. /* Form AMSDU */
  210. mwifiex_11n_form_amsdu_txpd(priv, skb_aggr);
  211. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
  212. ptx_pd = (struct txpd *)skb_aggr->data;
  213. skb_push(skb_aggr, headroom);
  214. tx_info_aggr->aggr_num = aggr_num * 2;
  215. if (adapter->data_sent || adapter->tx_lock_flag) {
  216. atomic_add(aggr_num * 2, &adapter->tx_queued);
  217. skb_queue_tail(&adapter->tx_data_q, skb_aggr);
  218. return 0;
  219. }
  220. if (adapter->iface_type == MWIFIEX_USB) {
  221. adapter->data_sent = true;
  222. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA,
  223. skb_aggr, NULL);
  224. } else {
  225. if (skb_src)
  226. tx_param.next_pkt_len =
  227. skb_src->len + sizeof(struct txpd);
  228. else
  229. tx_param.next_pkt_len = 0;
  230. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  231. skb_aggr, &tx_param);
  232. }
  233. switch (ret) {
  234. case -EBUSY:
  235. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  236. if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
  237. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  238. ra_list_flags);
  239. mwifiex_write_data_complete(adapter, skb_aggr, 1, -1);
  240. return -1;
  241. }
  242. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
  243. adapter->pps_uapsd_mode && adapter->tx_lock_flag) {
  244. priv->adapter->tx_lock_flag = false;
  245. if (ptx_pd)
  246. ptx_pd->flags = 0;
  247. }
  248. skb_queue_tail(&pra_list->skb_head, skb_aggr);
  249. pra_list->total_pkt_count++;
  250. atomic_inc(&priv->wmm.tx_pkts_queued);
  251. tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  252. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  253. ra_list_flags);
  254. mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
  255. break;
  256. case -1:
  257. if (adapter->iface_type != MWIFIEX_PCIE)
  258. adapter->data_sent = false;
  259. mwifiex_dbg(adapter, ERROR, "%s: host_to_card failed: %#x\n",
  260. __func__, ret);
  261. adapter->dbg.num_tx_host_to_card_failure++;
  262. mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
  263. return 0;
  264. case -EINPROGRESS:
  265. if (adapter->iface_type != MWIFIEX_PCIE)
  266. adapter->data_sent = false;
  267. break;
  268. case 0:
  269. mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
  270. break;
  271. default:
  272. break;
  273. }
  274. if (ret != -EBUSY) {
  275. mwifiex_rotate_priolists(priv, pra_list, ptrindex);
  276. }
  277. return 0;
  278. }