uap_txrx.c 13 KB

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