uap_txrx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * Marvell Wireless LAN device driver: AP TX and RX data handling
  3. *
  4. * Copyright (C) 2012, 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 "main.h"
  22. #include "wmm.h"
  23. #include "11n_aggr.h"
  24. #include "11n_rxreorder.h"
  25. /* This function checks if particular RA list has packets more than low bridge
  26. * packet threshold and then deletes packet from this RA list.
  27. * Function deletes packets from such RA list and returns true. If no such list
  28. * is found, false is returned.
  29. */
  30. static bool
  31. mwifiex_uap_del_tx_pkts_in_ralist(struct mwifiex_private *priv,
  32. struct list_head *ra_list_head)
  33. {
  34. struct mwifiex_ra_list_tbl *ra_list;
  35. struct sk_buff *skb, *tmp;
  36. bool pkt_deleted = false;
  37. struct mwifiex_txinfo *tx_info;
  38. struct mwifiex_adapter *adapter = priv->adapter;
  39. list_for_each_entry(ra_list, ra_list_head, list) {
  40. if (skb_queue_empty(&ra_list->skb_head))
  41. continue;
  42. skb_queue_walk_safe(&ra_list->skb_head, skb, tmp) {
  43. tx_info = MWIFIEX_SKB_TXCB(skb);
  44. if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT) {
  45. __skb_unlink(skb, &ra_list->skb_head);
  46. mwifiex_write_data_complete(adapter, skb, 0,
  47. -1);
  48. atomic_dec(&priv->wmm.tx_pkts_queued);
  49. pkt_deleted = true;
  50. }
  51. if ((atomic_read(&adapter->pending_bridged_pkts) <=
  52. MWIFIEX_BRIDGED_PKTS_THR_LOW))
  53. break;
  54. }
  55. }
  56. return pkt_deleted;
  57. }
  58. /* This function deletes packets from particular RA List. RA list index
  59. * from which packets are deleted is preserved so that packets from next RA
  60. * list are deleted upon subsequent call thus maintaining fairness.
  61. */
  62. static void mwifiex_uap_cleanup_tx_queues(struct mwifiex_private *priv)
  63. {
  64. unsigned long flags;
  65. struct list_head *ra_list;
  66. int i;
  67. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  68. for (i = 0; i < MAX_NUM_TID; i++, priv->del_list_idx++) {
  69. if (priv->del_list_idx == MAX_NUM_TID)
  70. priv->del_list_idx = 0;
  71. ra_list = &priv->wmm.tid_tbl_ptr[priv->del_list_idx].ra_list;
  72. if (mwifiex_uap_del_tx_pkts_in_ralist(priv, ra_list)) {
  73. priv->del_list_idx++;
  74. break;
  75. }
  76. }
  77. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  78. }
  79. static void mwifiex_uap_queue_bridged_pkt(struct mwifiex_private *priv,
  80. struct sk_buff *skb)
  81. {
  82. struct mwifiex_adapter *adapter = priv->adapter;
  83. struct uap_rxpd *uap_rx_pd;
  84. struct rx_packet_hdr *rx_pkt_hdr;
  85. struct sk_buff *new_skb;
  86. struct mwifiex_txinfo *tx_info;
  87. int hdr_chop;
  88. struct timeval tv;
  89. struct ethhdr *p_ethhdr;
  90. uap_rx_pd = (struct uap_rxpd *)(skb->data);
  91. rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
  92. if ((atomic_read(&adapter->pending_bridged_pkts) >=
  93. MWIFIEX_BRIDGED_PKTS_THR_HIGH)) {
  94. dev_err(priv->adapter->dev,
  95. "Tx: Bridge packet limit reached. Drop packet!\n");
  96. kfree_skb(skb);
  97. mwifiex_uap_cleanup_tx_queues(priv);
  98. return;
  99. }
  100. if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
  101. sizeof(bridge_tunnel_header))) ||
  102. (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
  103. sizeof(rfc1042_header)) &&
  104. ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
  105. ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) {
  106. /* Replace the 803 header and rfc1042 header (llc/snap) with
  107. * an Ethernet II header, keep the src/dst and snap_type
  108. * (ethertype).
  109. *
  110. * The firmware only passes up SNAP frames converting all RX
  111. * data from 802.11 to 802.2/LLC/SNAP frames.
  112. *
  113. * To create the Ethernet II, just move the src, dst address
  114. * right before the snap_type.
  115. */
  116. p_ethhdr = (struct ethhdr *)
  117. ((u8 *)(&rx_pkt_hdr->eth803_hdr)
  118. + sizeof(rx_pkt_hdr->eth803_hdr)
  119. + sizeof(rx_pkt_hdr->rfc1042_hdr)
  120. - sizeof(rx_pkt_hdr->eth803_hdr.h_dest)
  121. - sizeof(rx_pkt_hdr->eth803_hdr.h_source)
  122. - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type));
  123. memcpy(p_ethhdr->h_source, rx_pkt_hdr->eth803_hdr.h_source,
  124. sizeof(p_ethhdr->h_source));
  125. memcpy(p_ethhdr->h_dest, rx_pkt_hdr->eth803_hdr.h_dest,
  126. sizeof(p_ethhdr->h_dest));
  127. /* Chop off the rxpd + the excess memory from
  128. * 802.2/llc/snap header that was removed.
  129. */
  130. hdr_chop = (u8 *)p_ethhdr - (u8 *)uap_rx_pd;
  131. } else {
  132. /* Chop off the rxpd */
  133. hdr_chop = (u8 *)&rx_pkt_hdr->eth803_hdr - (u8 *)uap_rx_pd;
  134. }
  135. /* Chop off the leading header bytes so that it points
  136. * to the start of either the reconstructed EthII frame
  137. * or the 802.2/llc/snap frame.
  138. */
  139. skb_pull(skb, hdr_chop);
  140. if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
  141. dev_dbg(priv->adapter->dev,
  142. "data: Tx: insufficient skb headroom %d\n",
  143. skb_headroom(skb));
  144. /* Insufficient skb headroom - allocate a new skb */
  145. new_skb =
  146. skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
  147. if (unlikely(!new_skb)) {
  148. dev_err(priv->adapter->dev,
  149. "Tx: cannot allocate new_skb\n");
  150. kfree_skb(skb);
  151. priv->stats.tx_dropped++;
  152. return;
  153. }
  154. kfree_skb(skb);
  155. skb = new_skb;
  156. dev_dbg(priv->adapter->dev, "info: new skb headroom %d\n",
  157. skb_headroom(skb));
  158. }
  159. tx_info = MWIFIEX_SKB_TXCB(skb);
  160. memset(tx_info, 0, sizeof(*tx_info));
  161. tx_info->bss_num = priv->bss_num;
  162. tx_info->bss_type = priv->bss_type;
  163. tx_info->flags |= MWIFIEX_BUF_FLAG_BRIDGED_PKT;
  164. if (is_unicast_ether_addr(rx_pkt_hdr->eth803_hdr.h_dest)) {
  165. /* Update bridge packet statistics as the
  166. * packet is not going to kernel/upper layer.
  167. */
  168. priv->stats.rx_bytes += skb->len;
  169. priv->stats.rx_packets++;
  170. /* Sending bridge packet to TX queue, so save the packet
  171. * length in TXCB to update statistics in TX complete.
  172. */
  173. tx_info->pkt_len = skb->len;
  174. }
  175. do_gettimeofday(&tv);
  176. skb->tstamp = timeval_to_ktime(tv);
  177. mwifiex_wmm_add_buf_txqueue(priv, skb);
  178. atomic_inc(&adapter->tx_pending);
  179. atomic_inc(&adapter->pending_bridged_pkts);
  180. return;
  181. }
  182. /*
  183. * This function contains logic for AP packet forwarding.
  184. *
  185. * If a packet is multicast/broadcast, it is sent to kernel/upper layer
  186. * as well as queued back to AP TX queue so that it can be sent to other
  187. * associated stations.
  188. * If a packet is unicast and RA is present in associated station list,
  189. * it is again requeued into AP TX queue.
  190. * If a packet is unicast and RA is not in associated station list,
  191. * packet is forwarded to kernel to handle routing logic.
  192. */
  193. int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv,
  194. struct sk_buff *skb)
  195. {
  196. struct mwifiex_adapter *adapter = priv->adapter;
  197. struct uap_rxpd *uap_rx_pd;
  198. struct rx_packet_hdr *rx_pkt_hdr;
  199. u8 ra[ETH_ALEN];
  200. struct sk_buff *skb_uap;
  201. uap_rx_pd = (struct uap_rxpd *)(skb->data);
  202. rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
  203. /* don't do packet forwarding in disconnected state */
  204. if (!priv->media_connected) {
  205. dev_err(adapter->dev, "drop packet in disconnected state.\n");
  206. dev_kfree_skb_any(skb);
  207. return 0;
  208. }
  209. memcpy(ra, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN);
  210. if (is_multicast_ether_addr(ra)) {
  211. skb_uap = skb_copy(skb, GFP_ATOMIC);
  212. mwifiex_uap_queue_bridged_pkt(priv, skb_uap);
  213. } else {
  214. if (mwifiex_get_sta_entry(priv, ra)) {
  215. /* Requeue Intra-BSS packet */
  216. mwifiex_uap_queue_bridged_pkt(priv, skb);
  217. return 0;
  218. }
  219. }
  220. /* Forward unicat/Inter-BSS packets to kernel. */
  221. return mwifiex_process_rx_packet(priv, skb);
  222. }
  223. /*
  224. * This function processes the packet received on AP interface.
  225. *
  226. * The function looks into the RxPD and performs sanity tests on the
  227. * received buffer to ensure its a valid packet before processing it
  228. * further. If the packet is determined to be aggregated, it is
  229. * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic.
  230. *
  231. * The completion callback is called after processing is complete.
  232. */
  233. int mwifiex_process_uap_rx_packet(struct mwifiex_private *priv,
  234. struct sk_buff *skb)
  235. {
  236. struct mwifiex_adapter *adapter = priv->adapter;
  237. int ret;
  238. struct uap_rxpd *uap_rx_pd;
  239. struct rx_packet_hdr *rx_pkt_hdr;
  240. u16 rx_pkt_type;
  241. u8 ta[ETH_ALEN], pkt_type;
  242. struct mwifiex_sta_node *node;
  243. uap_rx_pd = (struct uap_rxpd *)(skb->data);
  244. rx_pkt_type = le16_to_cpu(uap_rx_pd->rx_pkt_type);
  245. rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
  246. if ((le16_to_cpu(uap_rx_pd->rx_pkt_offset) +
  247. le16_to_cpu(uap_rx_pd->rx_pkt_length)) > (u16) skb->len) {
  248. dev_err(adapter->dev,
  249. "wrong rx packet: len=%d, offset=%d, length=%d\n",
  250. skb->len, le16_to_cpu(uap_rx_pd->rx_pkt_offset),
  251. le16_to_cpu(uap_rx_pd->rx_pkt_length));
  252. priv->stats.rx_dropped++;
  253. dev_kfree_skb_any(skb);
  254. return 0;
  255. }
  256. if (rx_pkt_type == PKT_TYPE_MGMT) {
  257. ret = mwifiex_process_mgmt_packet(priv, skb);
  258. if (ret)
  259. dev_err(adapter->dev, "Rx of mgmt packet failed");
  260. dev_kfree_skb_any(skb);
  261. return ret;
  262. }
  263. memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN);
  264. if (rx_pkt_type != PKT_TYPE_BAR && uap_rx_pd->priority < MAX_NUM_TID) {
  265. node = mwifiex_get_sta_entry(priv, ta);
  266. if (node)
  267. node->rx_seq[uap_rx_pd->priority] =
  268. le16_to_cpu(uap_rx_pd->seq_num);
  269. }
  270. if (!priv->ap_11n_enabled ||
  271. (!mwifiex_11n_get_rx_reorder_tbl(priv, uap_rx_pd->priority, ta) &&
  272. (le16_to_cpu(uap_rx_pd->rx_pkt_type) != PKT_TYPE_AMSDU))) {
  273. ret = mwifiex_handle_uap_rx_forward(priv, skb);
  274. return ret;
  275. }
  276. /* Reorder and send to kernel */
  277. pkt_type = (u8)le16_to_cpu(uap_rx_pd->rx_pkt_type);
  278. ret = mwifiex_11n_rx_reorder_pkt(priv, le16_to_cpu(uap_rx_pd->seq_num),
  279. uap_rx_pd->priority, ta, pkt_type,
  280. skb);
  281. if (ret || (rx_pkt_type == PKT_TYPE_BAR))
  282. dev_kfree_skb_any(skb);
  283. if (ret)
  284. priv->stats.rx_dropped++;
  285. return ret;
  286. }
  287. /*
  288. * This function fills the TxPD for AP tx packets.
  289. *
  290. * The Tx buffer received by this function should already have the
  291. * header space allocated for TxPD.
  292. *
  293. * This function inserts the TxPD in between interface header and actual
  294. * data and adjusts the buffer pointers accordingly.
  295. *
  296. * The following TxPD fields are set by this function, as required -
  297. * - BSS number
  298. * - Tx packet length and offset
  299. * - Priority
  300. * - Packet delay
  301. * - Priority specific Tx control
  302. * - Flags
  303. */
  304. void *mwifiex_process_uap_txpd(struct mwifiex_private *priv,
  305. struct sk_buff *skb)
  306. {
  307. struct mwifiex_adapter *adapter = priv->adapter;
  308. struct uap_txpd *txpd;
  309. struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
  310. int pad, len;
  311. u16 pkt_type;
  312. if (!skb->len) {
  313. dev_err(adapter->dev, "Tx: bad packet length: %d\n", skb->len);
  314. tx_info->status_code = -1;
  315. return skb->data;
  316. }
  317. pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
  318. /* If skb->data is not aligned, add padding */
  319. pad = (4 - (((void *)skb->data - NULL) & 0x3)) % 4;
  320. len = sizeof(*txpd) + pad;
  321. BUG_ON(skb_headroom(skb) < len + INTF_HEADER_LEN);
  322. skb_push(skb, len);
  323. txpd = (struct uap_txpd *)skb->data;
  324. memset(txpd, 0, sizeof(*txpd));
  325. txpd->bss_num = priv->bss_num;
  326. txpd->bss_type = priv->bss_type;
  327. txpd->tx_pkt_length = cpu_to_le16((u16)(skb->len - len));
  328. txpd->priority = (u8)skb->priority;
  329. txpd->pkt_delay_2ms = mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
  330. if (txpd->priority < ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
  331. /*
  332. * Set the priority specific tx_control field, setting of 0 will
  333. * cause the default value to be used later in this function.
  334. */
  335. txpd->tx_control =
  336. cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[txpd->priority]);
  337. /* Offset of actual data */
  338. if (pkt_type == PKT_TYPE_MGMT) {
  339. /* Set the packet type and add header for management frame */
  340. txpd->tx_pkt_type = cpu_to_le16(pkt_type);
  341. len += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
  342. }
  343. txpd->tx_pkt_offset = cpu_to_le16(len);
  344. /* make space for INTF_HEADER_LEN */
  345. skb_push(skb, INTF_HEADER_LEN);
  346. if (!txpd->tx_control)
  347. /* TxCtrl set by user or default */
  348. txpd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  349. return skb->data;
  350. }