uap_txrx.c 13 KB

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