11n_aggr.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. skb_push(skb, sizeof(*local_tx_pd));
  91. local_tx_pd = (struct txpd *) skb->data;
  92. memset(local_tx_pd, 0, sizeof(struct txpd));
  93. /* Original priority has been overwritten */
  94. local_tx_pd->priority = (u8) skb->priority;
  95. local_tx_pd->pkt_delay_2ms =
  96. mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
  97. local_tx_pd->bss_num = priv->bss_num;
  98. local_tx_pd->bss_type = priv->bss_type;
  99. /* Always zero as the data is followed by struct txpd */
  100. local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
  101. local_tx_pd->tx_pkt_type = cpu_to_le16(PKT_TYPE_AMSDU);
  102. local_tx_pd->tx_pkt_length = cpu_to_le16(skb->len -
  103. sizeof(*local_tx_pd));
  104. if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
  105. local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
  106. if (local_tx_pd->tx_control == 0)
  107. /* TxCtrl set by user or default */
  108. local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  109. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
  110. priv->adapter->pps_uapsd_mode) {
  111. if (true == mwifiex_check_last_packet_indication(priv)) {
  112. priv->adapter->tx_lock_flag = true;
  113. local_tx_pd->flags =
  114. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
  115. }
  116. }
  117. }
  118. /*
  119. * Create aggregated packet.
  120. *
  121. * This function creates an aggregated MSDU packet, by combining buffers
  122. * from the RA list. Each individual buffer is encapsulated as an AMSDU
  123. * subframe and all such subframes are concatenated together to form the
  124. * AMSDU packet.
  125. *
  126. * A TxPD is also added to the front of the resultant AMSDU packets for
  127. * transmission. The resultant packets format is -
  128. *
  129. * +---- ~ ----+------ ~ ------+------ ~ ------+-..-+------ ~ ------+
  130. * | TxPD |AMSDU sub-frame|AMSDU sub-frame| .. |AMSDU sub-frame|
  131. * | | 1 | 2 | .. | n |
  132. * +---- ~ ----+------ ~ ------+------ ~ ------+ .. +------ ~ ------+
  133. */
  134. int
  135. mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
  136. struct mwifiex_ra_list_tbl *pra_list,
  137. int ptrindex, unsigned long ra_list_flags)
  138. __releases(&priv->wmm.ra_list_spinlock)
  139. {
  140. struct mwifiex_adapter *adapter = priv->adapter;
  141. struct sk_buff *skb_aggr, *skb_src;
  142. struct mwifiex_txinfo *tx_info_aggr, *tx_info_src;
  143. int pad = 0, aggr_num = 0, ret;
  144. struct mwifiex_tx_param tx_param;
  145. struct txpd *ptx_pd = NULL;
  146. int headroom = adapter->iface_type == MWIFIEX_USB ? 0 : INTF_HEADER_LEN;
  147. skb_src = skb_peek(&pra_list->skb_head);
  148. if (!skb_src) {
  149. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  150. ra_list_flags);
  151. return 0;
  152. }
  153. tx_info_src = MWIFIEX_SKB_TXCB(skb_src);
  154. skb_aggr = mwifiex_alloc_dma_align_buf(adapter->tx_buf_size,
  155. GFP_ATOMIC | GFP_DMA);
  156. if (!skb_aggr) {
  157. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  158. ra_list_flags);
  159. return -1;
  160. }
  161. /* skb_aggr->data already 64 byte align, just reserve bus interface
  162. * header and txpd.
  163. */
  164. skb_reserve(skb_aggr, headroom + sizeof(struct txpd));
  165. tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr);
  166. memset(tx_info_aggr, 0, sizeof(*tx_info_aggr));
  167. tx_info_aggr->bss_type = tx_info_src->bss_type;
  168. tx_info_aggr->bss_num = tx_info_src->bss_num;
  169. if (tx_info_src->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
  170. tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
  171. tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_AGGR_PKT;
  172. skb_aggr->priority = skb_src->priority;
  173. skb_aggr->tstamp = skb_src->tstamp;
  174. skb_aggr->tstamp = ktime_get_real();
  175. do {
  176. /* Check if AMSDU can accommodate this MSDU */
  177. if (skb_tailroom(skb_aggr) < (skb_src->len + LLC_SNAP_LEN))
  178. break;
  179. skb_src = skb_dequeue(&pra_list->skb_head);
  180. pra_list->total_pkt_count--;
  181. atomic_dec(&priv->wmm.tx_pkts_queued);
  182. aggr_num++;
  183. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  184. ra_list_flags);
  185. mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad);
  186. mwifiex_write_data_complete(adapter, skb_src, 0, 0);
  187. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  188. if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
  189. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  190. ra_list_flags);
  191. return -1;
  192. }
  193. if (skb_tailroom(skb_aggr) < pad) {
  194. pad = 0;
  195. break;
  196. }
  197. skb_put(skb_aggr, pad);
  198. skb_src = skb_peek(&pra_list->skb_head);
  199. } while (skb_src);
  200. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  201. /* Last AMSDU packet does not need padding */
  202. skb_trim(skb_aggr, skb_aggr->len - pad);
  203. /* Form AMSDU */
  204. mwifiex_11n_form_amsdu_txpd(priv, skb_aggr);
  205. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
  206. ptx_pd = (struct txpd *)skb_aggr->data;
  207. skb_push(skb_aggr, headroom);
  208. tx_info_aggr->aggr_num = aggr_num * 2;
  209. if (adapter->data_sent || adapter->tx_lock_flag) {
  210. atomic_add(aggr_num * 2, &adapter->tx_queued);
  211. skb_queue_tail(&adapter->tx_data_q, skb_aggr);
  212. return 0;
  213. }
  214. if (adapter->iface_type == MWIFIEX_USB) {
  215. ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
  216. skb_aggr, NULL);
  217. } else {
  218. if (skb_src)
  219. tx_param.next_pkt_len =
  220. skb_src->len + sizeof(struct txpd);
  221. else
  222. tx_param.next_pkt_len = 0;
  223. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  224. skb_aggr, &tx_param);
  225. }
  226. switch (ret) {
  227. case -EBUSY:
  228. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  229. if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
  230. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  231. ra_list_flags);
  232. mwifiex_write_data_complete(adapter, skb_aggr, 1, -1);
  233. return -1;
  234. }
  235. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
  236. adapter->pps_uapsd_mode && adapter->tx_lock_flag) {
  237. priv->adapter->tx_lock_flag = false;
  238. if (ptx_pd)
  239. ptx_pd->flags = 0;
  240. }
  241. skb_queue_tail(&pra_list->skb_head, skb_aggr);
  242. pra_list->total_pkt_count++;
  243. atomic_inc(&priv->wmm.tx_pkts_queued);
  244. tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  245. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  246. ra_list_flags);
  247. mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
  248. break;
  249. case -1:
  250. mwifiex_dbg(adapter, ERROR, "%s: host_to_card failed: %#x\n",
  251. __func__, ret);
  252. adapter->dbg.num_tx_host_to_card_failure++;
  253. mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
  254. return 0;
  255. case -EINPROGRESS:
  256. break;
  257. case 0:
  258. mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
  259. break;
  260. default:
  261. break;
  262. }
  263. if (ret != -EBUSY) {
  264. mwifiex_rotate_priolists(priv, pra_list, ptrindex);
  265. }
  266. return 0;
  267. }