uap_txrx.c 12 KB

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