uap_txrx.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. * Marvell Wireless LAN device driver: AP TX and RX data handling
  3. *
  4. * Copyright (C) 2012-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 "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 ethhdr *p_ethhdr;
  89. struct mwifiex_sta_node *src_node;
  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. mwifiex_dbg(priv->adapter, ERROR,
  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. mwifiex_dbg(priv->adapter, ERROR,
  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. mwifiex_dbg(priv->adapter, ERROR,
  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. mwifiex_dbg(priv->adapter, INFO,
  157. "info: new skb headroom %d\n",
  158. skb_headroom(skb));
  159. }
  160. tx_info = MWIFIEX_SKB_TXCB(skb);
  161. memset(tx_info, 0, sizeof(*tx_info));
  162. tx_info->bss_num = priv->bss_num;
  163. tx_info->bss_type = priv->bss_type;
  164. tx_info->flags |= MWIFIEX_BUF_FLAG_BRIDGED_PKT;
  165. src_node = mwifiex_get_sta_entry(priv, rx_pkt_hdr->eth803_hdr.h_source);
  166. if (src_node) {
  167. src_node->stats.last_rx = jiffies;
  168. src_node->stats.rx_bytes += skb->len;
  169. src_node->stats.rx_packets++;
  170. src_node->stats.last_tx_rate = uap_rx_pd->rx_rate;
  171. src_node->stats.last_tx_htinfo = uap_rx_pd->ht_info;
  172. }
  173. if (is_unicast_ether_addr(rx_pkt_hdr->eth803_hdr.h_dest)) {
  174. /* Update bridge packet statistics as the
  175. * packet is not going to kernel/upper layer.
  176. */
  177. priv->stats.rx_bytes += skb->len;
  178. priv->stats.rx_packets++;
  179. /* Sending bridge packet to TX queue, so save the packet
  180. * length in TXCB to update statistics in TX complete.
  181. */
  182. tx_info->pkt_len = skb->len;
  183. }
  184. __net_timestamp(skb);
  185. mwifiex_wmm_add_buf_txqueue(priv, skb);
  186. atomic_inc(&adapter->tx_pending);
  187. atomic_inc(&adapter->pending_bridged_pkts);
  188. return;
  189. }
  190. /*
  191. * This function contains logic for AP packet forwarding.
  192. *
  193. * If a packet is multicast/broadcast, it is sent to kernel/upper layer
  194. * as well as queued back to AP TX queue so that it can be sent to other
  195. * associated stations.
  196. * If a packet is unicast and RA is present in associated station list,
  197. * it is again requeued into AP TX queue.
  198. * If a packet is unicast and RA is not in associated station list,
  199. * packet is forwarded to kernel to handle routing logic.
  200. */
  201. int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv,
  202. struct sk_buff *skb)
  203. {
  204. struct mwifiex_adapter *adapter = priv->adapter;
  205. struct uap_rxpd *uap_rx_pd;
  206. struct rx_packet_hdr *rx_pkt_hdr;
  207. u8 ra[ETH_ALEN];
  208. struct sk_buff *skb_uap;
  209. uap_rx_pd = (struct uap_rxpd *)(skb->data);
  210. rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
  211. /* don't do packet forwarding in disconnected state */
  212. if (!priv->media_connected) {
  213. mwifiex_dbg(adapter, ERROR,
  214. "drop packet in disconnected state.\n");
  215. dev_kfree_skb_any(skb);
  216. return 0;
  217. }
  218. memcpy(ra, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN);
  219. if (is_multicast_ether_addr(ra)) {
  220. skb_uap = skb_copy(skb, GFP_ATOMIC);
  221. mwifiex_uap_queue_bridged_pkt(priv, skb_uap);
  222. } else {
  223. if (mwifiex_get_sta_entry(priv, ra)) {
  224. /* Requeue Intra-BSS packet */
  225. mwifiex_uap_queue_bridged_pkt(priv, skb);
  226. return 0;
  227. }
  228. }
  229. /* Forward unicat/Inter-BSS packets to kernel. */
  230. return mwifiex_process_rx_packet(priv, skb);
  231. }
  232. /*
  233. * This function processes the packet received on AP interface.
  234. *
  235. * The function looks into the RxPD and performs sanity tests on the
  236. * received buffer to ensure its a valid packet before processing it
  237. * further. If the packet is determined to be aggregated, it is
  238. * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic.
  239. *
  240. * The completion callback is called after processing is complete.
  241. */
  242. int mwifiex_process_uap_rx_packet(struct mwifiex_private *priv,
  243. struct sk_buff *skb)
  244. {
  245. struct mwifiex_adapter *adapter = priv->adapter;
  246. int ret;
  247. struct uap_rxpd *uap_rx_pd;
  248. struct rx_packet_hdr *rx_pkt_hdr;
  249. u16 rx_pkt_type;
  250. u8 ta[ETH_ALEN], pkt_type;
  251. unsigned long flags;
  252. struct mwifiex_sta_node *node;
  253. uap_rx_pd = (struct uap_rxpd *)(skb->data);
  254. rx_pkt_type = le16_to_cpu(uap_rx_pd->rx_pkt_type);
  255. rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
  256. ether_addr_copy(ta, rx_pkt_hdr->eth803_hdr.h_source);
  257. if ((le16_to_cpu(uap_rx_pd->rx_pkt_offset) +
  258. le16_to_cpu(uap_rx_pd->rx_pkt_length)) > (u16) skb->len) {
  259. mwifiex_dbg(adapter, ERROR,
  260. "wrong rx packet: len=%d, offset=%d, length=%d\n",
  261. skb->len, le16_to_cpu(uap_rx_pd->rx_pkt_offset),
  262. le16_to_cpu(uap_rx_pd->rx_pkt_length));
  263. priv->stats.rx_dropped++;
  264. node = mwifiex_get_sta_entry(priv, ta);
  265. if (node)
  266. node->stats.tx_failed++;
  267. dev_kfree_skb_any(skb);
  268. return 0;
  269. }
  270. if (rx_pkt_type == PKT_TYPE_MGMT) {
  271. ret = mwifiex_process_mgmt_packet(priv, skb);
  272. if (ret)
  273. mwifiex_dbg(adapter, ERROR,
  274. "Rx of mgmt packet failed");
  275. dev_kfree_skb_any(skb);
  276. return ret;
  277. }
  278. if (rx_pkt_type != PKT_TYPE_BAR && uap_rx_pd->priority < MAX_NUM_TID) {
  279. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  280. node = mwifiex_get_sta_entry(priv, ta);
  281. if (node)
  282. node->rx_seq[uap_rx_pd->priority] =
  283. le16_to_cpu(uap_rx_pd->seq_num);
  284. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  285. }
  286. if (!priv->ap_11n_enabled ||
  287. (!mwifiex_11n_get_rx_reorder_tbl(priv, uap_rx_pd->priority, ta) &&
  288. (le16_to_cpu(uap_rx_pd->rx_pkt_type) != PKT_TYPE_AMSDU))) {
  289. ret = mwifiex_handle_uap_rx_forward(priv, skb);
  290. return ret;
  291. }
  292. /* Reorder and send to kernel */
  293. pkt_type = (u8)le16_to_cpu(uap_rx_pd->rx_pkt_type);
  294. ret = mwifiex_11n_rx_reorder_pkt(priv, le16_to_cpu(uap_rx_pd->seq_num),
  295. uap_rx_pd->priority, ta, pkt_type,
  296. skb);
  297. if (ret || (rx_pkt_type == PKT_TYPE_BAR))
  298. dev_kfree_skb_any(skb);
  299. if (ret)
  300. priv->stats.rx_dropped++;
  301. return ret;
  302. }
  303. /*
  304. * This function fills the TxPD for AP tx packets.
  305. *
  306. * The Tx buffer received by this function should already have the
  307. * header space allocated for TxPD.
  308. *
  309. * This function inserts the TxPD in between interface header and actual
  310. * data and adjusts the buffer pointers accordingly.
  311. *
  312. * The following TxPD fields are set by this function, as required -
  313. * - BSS number
  314. * - Tx packet length and offset
  315. * - Priority
  316. * - Packet delay
  317. * - Priority specific Tx control
  318. * - Flags
  319. */
  320. void *mwifiex_process_uap_txpd(struct mwifiex_private *priv,
  321. struct sk_buff *skb)
  322. {
  323. struct mwifiex_adapter *adapter = priv->adapter;
  324. struct uap_txpd *txpd;
  325. struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
  326. int pad;
  327. u16 pkt_type, pkt_offset;
  328. int hroom = (priv->adapter->iface_type == MWIFIEX_USB) ? 0 :
  329. INTF_HEADER_LEN;
  330. if (!skb->len) {
  331. mwifiex_dbg(adapter, ERROR,
  332. "Tx: bad packet length: %d\n", skb->len);
  333. tx_info->status_code = -1;
  334. return skb->data;
  335. }
  336. BUG_ON(skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN);
  337. pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
  338. pad = ((void *)skb->data - (sizeof(*txpd) + hroom) - NULL) &
  339. (MWIFIEX_DMA_ALIGN_SZ - 1);
  340. skb_push(skb, sizeof(*txpd) + pad);
  341. txpd = (struct uap_txpd *)skb->data;
  342. memset(txpd, 0, sizeof(*txpd));
  343. txpd->bss_num = priv->bss_num;
  344. txpd->bss_type = priv->bss_type;
  345. txpd->tx_pkt_length = cpu_to_le16((u16)(skb->len - (sizeof(*txpd) +
  346. pad)));
  347. txpd->priority = (u8)skb->priority;
  348. txpd->pkt_delay_2ms = mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
  349. if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS ||
  350. tx_info->flags & MWIFIEX_BUF_FLAG_ACTION_TX_STATUS) {
  351. txpd->tx_token_id = tx_info->ack_frame_id;
  352. txpd->flags |= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS;
  353. }
  354. if (txpd->priority < ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
  355. /*
  356. * Set the priority specific tx_control field, setting of 0 will
  357. * cause the default value to be used later in this function.
  358. */
  359. txpd->tx_control =
  360. cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[txpd->priority]);
  361. /* Offset of actual data */
  362. pkt_offset = sizeof(*txpd) + pad;
  363. if (pkt_type == PKT_TYPE_MGMT) {
  364. /* Set the packet type and add header for management frame */
  365. txpd->tx_pkt_type = cpu_to_le16(pkt_type);
  366. pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
  367. }
  368. txpd->tx_pkt_offset = cpu_to_le16(pkt_offset);
  369. /* make space for INTF_HEADER_LEN */
  370. skb_push(skb, hroom);
  371. if (!txpd->tx_control)
  372. /* TxCtrl set by user or default */
  373. txpd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
  374. return skb->data;
  375. }