PageRenderTime 58ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/mwifiex/11n_aggr.c

https://github.com/mstsirkin/linux
C | 314 lines | 187 code | 44 blank | 83 comment | 22 complexity | dd02b40674f8c6a1634a6f189fb14fea MD5 | raw file
  1. /*
  2. * Marvell Wireless LAN device driver: 802.11n Aggregation
  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. #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. skb_put(skb_aggr, sizeof(*tx_header));
  62. tx_header = (struct tx_packet_hdr *) skb_aggr->data;
  63. /* Copy DA and SA */
  64. dt_offset = 2 * ETH_ALEN;
  65. memcpy(&tx_header->eth803_hdr, skb_src->data, dt_offset);
  66. /* Copy SNAP header */
  67. snap.snap_type = *(u16 *) ((u8 *)skb_src->data + dt_offset);
  68. dt_offset += sizeof(u16);
  69. memcpy(&tx_header->rfc1042_hdr, &snap, sizeof(struct rfc_1042_hdr));
  70. skb_pull(skb_src, dt_offset);
  71. /* Update Length field */
  72. tx_header->eth803_hdr.h_proto = htons(skb_src->len + LLC_SNAP_LEN);
  73. /* Add payload */
  74. skb_put(skb_aggr, skb_src->len);
  75. memcpy(skb_aggr->data + sizeof(*tx_header), skb_src->data,
  76. skb_src->len);
  77. *pad = (((skb_src->len + LLC_SNAP_LEN) & 3)) ? (4 - (((skb_src->len +
  78. LLC_SNAP_LEN)) & 3)) : 0;
  79. skb_put(skb_aggr, *pad);
  80. return skb_aggr->len + *pad;
  81. }
  82. /*
  83. * Adds TxPD to AMSDU header.
  84. *
  85. * Each AMSDU packet will contain one TxPD at the beginning,
  86. * followed by multiple AMSDU subframes.
  87. */
  88. static void
  89. mwifiex_11n_form_amsdu_txpd(struct mwifiex_private *priv,
  90. struct sk_buff *skb)
  91. {
  92. struct txpd *local_tx_pd;
  93. skb_push(skb, sizeof(*local_tx_pd));
  94. local_tx_pd = (struct txpd *) skb->data;
  95. memset(local_tx_pd, 0, sizeof(struct txpd));
  96. /* Original priority has been overwritten */
  97. local_tx_pd->priority = (u8) skb->priority;
  98. local_tx_pd->pkt_delay_2ms =
  99. mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
  100. local_tx_pd->bss_num = priv->bss_num;
  101. local_tx_pd->bss_type = priv->bss_type;
  102. /* Always zero as the data is followed by struct txpd */
  103. local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
  104. local_tx_pd->tx_pkt_type = cpu_to_le16(PKT_TYPE_AMSDU);
  105. local_tx_pd->tx_pkt_length = cpu_to_le16(skb->len -
  106. sizeof(*local_tx_pd));
  107. if (local_tx_pd->tx_control == 0)
  108. /* TxCtrl set by user or default */
  109. local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  110. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  111. (priv->adapter->pps_uapsd_mode)) {
  112. if (true == mwifiex_check_last_packet_indication(priv)) {
  113. priv->adapter->tx_lock_flag = true;
  114. local_tx_pd->flags =
  115. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
  116. }
  117. }
  118. }
  119. /*
  120. * Create aggregated packet.
  121. *
  122. * This function creates an aggregated MSDU packet, by combining buffers
  123. * from the RA list. Each individual buffer is encapsulated as an AMSDU
  124. * subframe and all such subframes are concatenated together to form the
  125. * AMSDU packet.
  126. *
  127. * A TxPD is also added to the front of the resultant AMSDU packets for
  128. * transmission. The resultant packets format is -
  129. *
  130. * +---- ~ ----+------ ~ ------+------ ~ ------+-..-+------ ~ ------+
  131. * | TxPD |AMSDU sub-frame|AMSDU sub-frame| .. |AMSDU sub-frame|
  132. * | | 1 | 2 | .. | n |
  133. * +---- ~ ----+------ ~ ------+------ ~ ------+ .. +------ ~ ------+
  134. */
  135. int
  136. mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
  137. struct mwifiex_ra_list_tbl *pra_list, int headroom,
  138. int ptrindex, unsigned long ra_list_flags)
  139. __releases(&priv->wmm.ra_list_spinlock)
  140. {
  141. struct mwifiex_adapter *adapter = priv->adapter;
  142. struct sk_buff *skb_aggr, *skb_src;
  143. struct mwifiex_txinfo *tx_info_aggr, *tx_info_src;
  144. int pad = 0, ret;
  145. struct mwifiex_tx_param tx_param;
  146. struct txpd *ptx_pd = NULL;
  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 = dev_alloc_skb(adapter->tx_buf_size);
  155. if (!skb_aggr) {
  156. dev_err(adapter->dev, "%s: alloc skb_aggr\n", __func__);
  157. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  158. ra_list_flags);
  159. return -1;
  160. }
  161. skb_reserve(skb_aggr, headroom + sizeof(struct txpd));
  162. tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr);
  163. tx_info_aggr->bss_index = tx_info_src->bss_index;
  164. skb_aggr->priority = skb_src->priority;
  165. do {
  166. /* Check if AMSDU can accommodate this MSDU */
  167. if (skb_tailroom(skb_aggr) < (skb_src->len + LLC_SNAP_LEN))
  168. break;
  169. skb_src = skb_dequeue(&pra_list->skb_head);
  170. pra_list->total_pkts_size -= skb_src->len;
  171. pra_list->total_pkts--;
  172. atomic_dec(&priv->wmm.tx_pkts_queued);
  173. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  174. ra_list_flags);
  175. mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad);
  176. mwifiex_write_data_complete(adapter, skb_src, 0);
  177. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  178. if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
  179. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  180. ra_list_flags);
  181. return -1;
  182. }
  183. if (skb_tailroom(skb_aggr) < pad) {
  184. pad = 0;
  185. break;
  186. }
  187. skb_put(skb_aggr, pad);
  188. skb_src = skb_peek(&pra_list->skb_head);
  189. } while (skb_src);
  190. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  191. /* Last AMSDU packet does not need padding */
  192. skb_trim(skb_aggr, skb_aggr->len - pad);
  193. /* Form AMSDU */
  194. mwifiex_11n_form_amsdu_txpd(priv, skb_aggr);
  195. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
  196. ptx_pd = (struct txpd *)skb_aggr->data;
  197. skb_push(skb_aggr, headroom);
  198. /*
  199. * Padding per MSDU will affect the length of next
  200. * packet and hence the exact length of next packet
  201. * is uncertain here.
  202. *
  203. * Also, aggregation of transmission buffer, while
  204. * downloading the data to the card, wont gain much
  205. * on the AMSDU packets as the AMSDU packets utilizes
  206. * the transmission buffer space to the maximum
  207. * (adapter->tx_buf_size).
  208. */
  209. tx_param.next_pkt_len = 0;
  210. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  211. skb_aggr->data,
  212. skb_aggr->len, &tx_param);
  213. switch (ret) {
  214. case -EBUSY:
  215. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  216. if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
  217. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  218. ra_list_flags);
  219. mwifiex_write_data_complete(adapter, skb_aggr, -1);
  220. return -1;
  221. }
  222. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  223. (adapter->pps_uapsd_mode) &&
  224. (adapter->tx_lock_flag)) {
  225. priv->adapter->tx_lock_flag = false;
  226. if (ptx_pd)
  227. ptx_pd->flags = 0;
  228. }
  229. skb_queue_tail(&pra_list->skb_head, skb_aggr);
  230. pra_list->total_pkts_size += skb_aggr->len;
  231. pra_list->total_pkts++;
  232. atomic_inc(&priv->wmm.tx_pkts_queued);
  233. tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  234. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  235. ra_list_flags);
  236. dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
  237. break;
  238. case -1:
  239. adapter->data_sent = false;
  240. dev_err(adapter->dev, "%s: host_to_card failed: %#x\n",
  241. __func__, ret);
  242. adapter->dbg.num_tx_host_to_card_failure++;
  243. mwifiex_write_data_complete(adapter, skb_aggr, ret);
  244. return 0;
  245. case -EINPROGRESS:
  246. adapter->data_sent = false;
  247. break;
  248. case 0:
  249. mwifiex_write_data_complete(adapter, skb_aggr, ret);
  250. break;
  251. default:
  252. break;
  253. }
  254. if (ret != -EBUSY) {
  255. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  256. if (mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
  257. priv->wmm.packets_out[ptrindex]++;
  258. priv->wmm.tid_tbl_ptr[ptrindex].ra_list_curr = pra_list;
  259. }
  260. /* Now bss_prio_cur pointer points to next node */
  261. adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur =
  262. list_first_entry(
  263. &adapter->bss_prio_tbl[priv->bss_priority]
  264. .bss_prio_cur->list,
  265. struct mwifiex_bss_prio_node, list);
  266. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  267. ra_list_flags);
  268. }
  269. return 0;
  270. }