2 * Marvell Wireless LAN device driver: AP TX and RX data handling
4 * Copyright (C) 2012-2014, Marvell International Ltd.
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.
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.
25 #include "11n_rxreorder.h"
27 /* This function checks if particular RA list has packets more than low bridge
28 * packet threshold and then deletes packet from this RA list.
29 * Function deletes packets from such RA list and returns true. If no such list
30 * is found, false is returned.
33 mwifiex_uap_del_tx_pkts_in_ralist(struct mwifiex_private *priv,
34 struct list_head *ra_list_head,
37 struct mwifiex_ra_list_tbl *ra_list;
38 struct sk_buff *skb, *tmp;
39 bool pkt_deleted = false;
40 struct mwifiex_txinfo *tx_info;
41 struct mwifiex_adapter *adapter = priv->adapter;
43 list_for_each_entry(ra_list, ra_list_head, list) {
44 if (skb_queue_empty(&ra_list->skb_head))
47 skb_queue_walk_safe(&ra_list->skb_head, skb, tmp) {
48 tx_info = MWIFIEX_SKB_TXCB(skb);
49 if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT) {
50 __skb_unlink(skb, &ra_list->skb_head);
51 mwifiex_write_data_complete(adapter, skb, 0,
53 if (ra_list->tx_paused)
54 priv->wmm.pkts_paused[tid]--;
56 atomic_dec(&priv->wmm.tx_pkts_queued);
59 if ((atomic_read(&adapter->pending_bridged_pkts) <=
60 MWIFIEX_BRIDGED_PKTS_THR_LOW))
68 /* This function deletes packets from particular RA List. RA list index
69 * from which packets are deleted is preserved so that packets from next RA
70 * list are deleted upon subsequent call thus maintaining fairness.
72 static void mwifiex_uap_cleanup_tx_queues(struct mwifiex_private *priv)
75 struct list_head *ra_list;
78 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
80 for (i = 0; i < MAX_NUM_TID; i++, priv->del_list_idx++) {
81 if (priv->del_list_idx == MAX_NUM_TID)
82 priv->del_list_idx = 0;
83 ra_list = &priv->wmm.tid_tbl_ptr[priv->del_list_idx].ra_list;
84 if (mwifiex_uap_del_tx_pkts_in_ralist(priv, ra_list, i)) {
90 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
94 static void mwifiex_uap_queue_bridged_pkt(struct mwifiex_private *priv,
97 struct mwifiex_adapter *adapter = priv->adapter;
98 struct uap_rxpd *uap_rx_pd;
99 struct rx_packet_hdr *rx_pkt_hdr;
100 struct sk_buff *new_skb;
101 struct mwifiex_txinfo *tx_info;
103 struct ethhdr *p_ethhdr;
104 struct mwifiex_sta_node *src_node;
107 uap_rx_pd = (struct uap_rxpd *)(skb->data);
108 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
110 if ((atomic_read(&adapter->pending_bridged_pkts) >=
111 MWIFIEX_BRIDGED_PKTS_THR_HIGH)) {
112 mwifiex_dbg(priv->adapter, ERROR,
113 "Tx: Bridge packet limit reached. Drop packet!\n");
115 mwifiex_uap_cleanup_tx_queues(priv);
119 if (sizeof(*rx_pkt_hdr) +
120 le16_to_cpu(uap_rx_pd->rx_pkt_offset) > skb->len) {
121 mwifiex_dbg(adapter, ERROR,
122 "wrong rx packet offset: len=%d,rx_pkt_offset=%d\n",
123 skb->len, le16_to_cpu(uap_rx_pd->rx_pkt_offset));
124 priv->stats.rx_dropped++;
125 dev_kfree_skb_any(skb);
129 if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
130 sizeof(bridge_tunnel_header))) ||
131 (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
132 sizeof(rfc1042_header)) &&
133 ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
134 ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) {
135 /* Replace the 803 header and rfc1042 header (llc/snap) with
136 * an Ethernet II header, keep the src/dst and snap_type
139 * The firmware only passes up SNAP frames converting all RX
140 * data from 802.11 to 802.2/LLC/SNAP frames.
142 * To create the Ethernet II, just move the src, dst address
143 * right before the snap_type.
145 p_ethhdr = (struct ethhdr *)
146 ((u8 *)(&rx_pkt_hdr->eth803_hdr)
147 + sizeof(rx_pkt_hdr->eth803_hdr)
148 + sizeof(rx_pkt_hdr->rfc1042_hdr)
149 - sizeof(rx_pkt_hdr->eth803_hdr.h_dest)
150 - sizeof(rx_pkt_hdr->eth803_hdr.h_source)
151 - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type));
152 memcpy(p_ethhdr->h_source, rx_pkt_hdr->eth803_hdr.h_source,
153 sizeof(p_ethhdr->h_source));
154 memcpy(p_ethhdr->h_dest, rx_pkt_hdr->eth803_hdr.h_dest,
155 sizeof(p_ethhdr->h_dest));
156 /* Chop off the rxpd + the excess memory from
157 * 802.2/llc/snap header that was removed.
159 hdr_chop = (u8 *)p_ethhdr - (u8 *)uap_rx_pd;
161 /* Chop off the rxpd */
162 hdr_chop = (u8 *)&rx_pkt_hdr->eth803_hdr - (u8 *)uap_rx_pd;
165 /* Chop off the leading header bytes so that it points
166 * to the start of either the reconstructed EthII frame
167 * or the 802.2/llc/snap frame.
169 skb_pull(skb, hdr_chop);
171 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
172 mwifiex_dbg(priv->adapter, ERROR,
173 "data: Tx: insufficient skb headroom %d\n",
175 /* Insufficient skb headroom - allocate a new skb */
177 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
178 if (unlikely(!new_skb)) {
179 mwifiex_dbg(priv->adapter, ERROR,
180 "Tx: cannot allocate new_skb\n");
182 priv->stats.tx_dropped++;
188 mwifiex_dbg(priv->adapter, INFO,
189 "info: new skb headroom %d\n",
193 tx_info = MWIFIEX_SKB_TXCB(skb);
194 memset(tx_info, 0, sizeof(*tx_info));
195 tx_info->bss_num = priv->bss_num;
196 tx_info->bss_type = priv->bss_type;
197 tx_info->flags |= MWIFIEX_BUF_FLAG_BRIDGED_PKT;
199 src_node = mwifiex_get_sta_entry(priv, rx_pkt_hdr->eth803_hdr.h_source);
201 src_node->stats.last_rx = jiffies;
202 src_node->stats.rx_bytes += skb->len;
203 src_node->stats.rx_packets++;
204 src_node->stats.last_tx_rate = uap_rx_pd->rx_rate;
205 src_node->stats.last_tx_htinfo = uap_rx_pd->ht_info;
208 if (is_unicast_ether_addr(rx_pkt_hdr->eth803_hdr.h_dest)) {
209 /* Update bridge packet statistics as the
210 * packet is not going to kernel/upper layer.
212 priv->stats.rx_bytes += skb->len;
213 priv->stats.rx_packets++;
215 /* Sending bridge packet to TX queue, so save the packet
216 * length in TXCB to update statistics in TX complete.
218 tx_info->pkt_len = skb->len;
221 __net_timestamp(skb);
223 index = mwifiex_1d_to_wmm_queue[skb->priority];
224 atomic_inc(&priv->wmm_tx_pending[index]);
225 mwifiex_wmm_add_buf_txqueue(priv, skb);
226 atomic_inc(&adapter->tx_pending);
227 atomic_inc(&adapter->pending_bridged_pkts);
229 mwifiex_queue_main_work(priv->adapter);
235 * This function contains logic for AP packet forwarding.
237 * If a packet is multicast/broadcast, it is sent to kernel/upper layer
238 * as well as queued back to AP TX queue so that it can be sent to other
239 * associated stations.
240 * If a packet is unicast and RA is present in associated station list,
241 * it is again requeued into AP TX queue.
242 * If a packet is unicast and RA is not in associated station list,
243 * packet is forwarded to kernel to handle routing logic.
245 int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv,
248 struct mwifiex_adapter *adapter = priv->adapter;
249 struct uap_rxpd *uap_rx_pd;
250 struct rx_packet_hdr *rx_pkt_hdr;
252 struct sk_buff *skb_uap;
254 uap_rx_pd = (struct uap_rxpd *)(skb->data);
255 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
257 /* don't do packet forwarding in disconnected state */
258 if (!priv->media_connected) {
259 mwifiex_dbg(adapter, ERROR,
260 "drop packet in disconnected state.\n");
261 dev_kfree_skb_any(skb);
265 memcpy(ra, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN);
267 if (is_multicast_ether_addr(ra)) {
268 skb_uap = skb_copy(skb, GFP_ATOMIC);
269 if (likely(skb_uap)) {
270 mwifiex_uap_queue_bridged_pkt(priv, skb_uap);
272 mwifiex_dbg(adapter, ERROR,
273 "failed to copy skb for uAP\n");
274 priv->stats.rx_dropped++;
275 dev_kfree_skb_any(skb);
279 if (mwifiex_get_sta_entry(priv, ra)) {
280 /* Requeue Intra-BSS packet */
281 mwifiex_uap_queue_bridged_pkt(priv, skb);
286 /* Forward unicat/Inter-BSS packets to kernel. */
287 return mwifiex_process_rx_packet(priv, skb);
290 int mwifiex_uap_recv_packet(struct mwifiex_private *priv,
293 struct mwifiex_adapter *adapter = priv->adapter;
294 struct mwifiex_sta_node *src_node;
295 struct ethhdr *p_ethhdr;
296 struct sk_buff *skb_uap;
297 struct mwifiex_txinfo *tx_info;
302 p_ethhdr = (void *)skb->data;
303 src_node = mwifiex_get_sta_entry(priv, p_ethhdr->h_source);
305 src_node->stats.last_rx = jiffies;
306 src_node->stats.rx_bytes += skb->len;
307 src_node->stats.rx_packets++;
310 if (is_multicast_ether_addr(p_ethhdr->h_dest) ||
311 mwifiex_get_sta_entry(priv, p_ethhdr->h_dest)) {
312 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN)
314 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
316 skb_uap = skb_copy(skb, GFP_ATOMIC);
318 if (likely(skb_uap)) {
319 tx_info = MWIFIEX_SKB_TXCB(skb_uap);
320 memset(tx_info, 0, sizeof(*tx_info));
321 tx_info->bss_num = priv->bss_num;
322 tx_info->bss_type = priv->bss_type;
323 tx_info->flags |= MWIFIEX_BUF_FLAG_BRIDGED_PKT;
324 __net_timestamp(skb_uap);
325 mwifiex_wmm_add_buf_txqueue(priv, skb_uap);
326 atomic_inc(&adapter->tx_pending);
327 atomic_inc(&adapter->pending_bridged_pkts);
328 if ((atomic_read(&adapter->pending_bridged_pkts) >=
329 MWIFIEX_BRIDGED_PKTS_THR_HIGH)) {
330 mwifiex_dbg(adapter, ERROR,
331 "Tx: Bridge packet limit reached. Drop packet!\n");
332 mwifiex_uap_cleanup_tx_queues(priv);
336 mwifiex_dbg(adapter, ERROR, "failed to allocate skb_uap");
339 mwifiex_queue_main_work(adapter);
340 /* Don't forward Intra-BSS unicast packet to upper layer*/
341 if (mwifiex_get_sta_entry(priv, p_ethhdr->h_dest))
345 skb->dev = priv->netdev;
346 skb->protocol = eth_type_trans(skb, priv->netdev);
347 skb->ip_summed = CHECKSUM_NONE;
349 /* This is required only in case of 11n and USB/PCIE as we alloc
350 * a buffer of 4K only if its 11N (to be able to receive 4K
351 * AMSDU packets). In case of SD we allocate buffers based
352 * on the size of packet and hence this is not needed.
354 * Modifying the truesize here as our allocation for each
355 * skb is 4K but we only receive 2K packets and this cause
356 * the kernel to start dropping packets in case where
357 * application has allocated buffer based on 2K size i.e.
358 * if there a 64K packet received (in IP fragments and
359 * application allocates 64K to receive this packet but
360 * this packet would almost double up because we allocate
361 * each 1.5K fragment in 4K and pass it up. As soon as the
362 * 64K limit hits kernel will start to drop rest of the
363 * fragments. Currently we fail the Filesndl-ht.scr script
364 * for UDP, hence this fix
366 if ((adapter->iface_type == MWIFIEX_USB ||
367 adapter->iface_type == MWIFIEX_PCIE) &&
368 skb->truesize > MWIFIEX_RX_DATA_BUF_SIZE)
369 skb->truesize += (skb->len - MWIFIEX_RX_DATA_BUF_SIZE);
371 /* Forward multicast/broadcast packet to upper layer*/
381 * This function processes the packet received on AP interface.
383 * The function looks into the RxPD and performs sanity tests on the
384 * received buffer to ensure its a valid packet before processing it
385 * further. If the packet is determined to be aggregated, it is
386 * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic.
388 * The completion callback is called after processing is complete.
390 int mwifiex_process_uap_rx_packet(struct mwifiex_private *priv,
393 struct mwifiex_adapter *adapter = priv->adapter;
395 struct uap_rxpd *uap_rx_pd;
396 struct rx_packet_hdr *rx_pkt_hdr;
398 u8 ta[ETH_ALEN], pkt_type;
400 struct mwifiex_sta_node *node;
402 uap_rx_pd = (struct uap_rxpd *)(skb->data);
403 rx_pkt_type = le16_to_cpu(uap_rx_pd->rx_pkt_type);
404 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
406 if (le16_to_cpu(uap_rx_pd->rx_pkt_offset) +
407 sizeof(rx_pkt_hdr->eth803_hdr) > skb->len) {
408 mwifiex_dbg(adapter, ERROR,
409 "wrong rx packet for struct ethhdr: len=%d, offset=%d\n",
410 skb->len, le16_to_cpu(uap_rx_pd->rx_pkt_offset));
411 priv->stats.rx_dropped++;
412 dev_kfree_skb_any(skb);
416 ether_addr_copy(ta, rx_pkt_hdr->eth803_hdr.h_source);
418 if ((le16_to_cpu(uap_rx_pd->rx_pkt_offset) +
419 le16_to_cpu(uap_rx_pd->rx_pkt_length)) > (u16) skb->len) {
420 mwifiex_dbg(adapter, ERROR,
421 "wrong rx packet: len=%d, offset=%d, length=%d\n",
422 skb->len, le16_to_cpu(uap_rx_pd->rx_pkt_offset),
423 le16_to_cpu(uap_rx_pd->rx_pkt_length));
424 priv->stats.rx_dropped++;
426 node = mwifiex_get_sta_entry(priv, ta);
428 node->stats.tx_failed++;
430 dev_kfree_skb_any(skb);
434 if (rx_pkt_type == PKT_TYPE_MGMT) {
435 ret = mwifiex_process_mgmt_packet(priv, skb);
437 mwifiex_dbg(adapter, DATA, "Rx of mgmt packet failed");
438 dev_kfree_skb_any(skb);
443 if (rx_pkt_type != PKT_TYPE_BAR && uap_rx_pd->priority < MAX_NUM_TID) {
444 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
445 node = mwifiex_get_sta_entry(priv, ta);
447 node->rx_seq[uap_rx_pd->priority] =
448 le16_to_cpu(uap_rx_pd->seq_num);
449 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
452 if (!priv->ap_11n_enabled ||
453 (!mwifiex_11n_get_rx_reorder_tbl(priv, uap_rx_pd->priority, ta) &&
454 (le16_to_cpu(uap_rx_pd->rx_pkt_type) != PKT_TYPE_AMSDU))) {
455 ret = mwifiex_handle_uap_rx_forward(priv, skb);
459 /* Reorder and send to kernel */
460 pkt_type = (u8)le16_to_cpu(uap_rx_pd->rx_pkt_type);
461 ret = mwifiex_11n_rx_reorder_pkt(priv, le16_to_cpu(uap_rx_pd->seq_num),
462 uap_rx_pd->priority, ta, pkt_type,
465 if (ret || (rx_pkt_type == PKT_TYPE_BAR))
466 dev_kfree_skb_any(skb);
469 priv->stats.rx_dropped++;
475 * This function fills the TxPD for AP tx packets.
477 * The Tx buffer received by this function should already have the
478 * header space allocated for TxPD.
480 * This function inserts the TxPD in between interface header and actual
481 * data and adjusts the buffer pointers accordingly.
483 * The following TxPD fields are set by this function, as required -
485 * - Tx packet length and offset
488 * - Priority specific Tx control
491 void *mwifiex_process_uap_txpd(struct mwifiex_private *priv,
494 struct mwifiex_adapter *adapter = priv->adapter;
495 struct uap_txpd *txpd;
496 struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
498 u16 pkt_type, pkt_offset;
499 int hroom = adapter->intf_hdr_len;
502 mwifiex_dbg(adapter, ERROR,
503 "Tx: bad packet length: %d\n", skb->len);
504 tx_info->status_code = -1;
508 BUG_ON(skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN);
510 pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
512 pad = ((void *)skb->data - (sizeof(*txpd) + hroom) - NULL) &
513 (MWIFIEX_DMA_ALIGN_SZ - 1);
515 skb_push(skb, sizeof(*txpd) + pad);
517 txpd = (struct uap_txpd *)skb->data;
518 memset(txpd, 0, sizeof(*txpd));
519 txpd->bss_num = priv->bss_num;
520 txpd->bss_type = priv->bss_type;
521 txpd->tx_pkt_length = cpu_to_le16((u16)(skb->len - (sizeof(*txpd) +
523 txpd->priority = (u8)skb->priority;
525 txpd->pkt_delay_2ms = mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
527 if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS ||
528 tx_info->flags & MWIFIEX_BUF_FLAG_ACTION_TX_STATUS) {
529 txpd->tx_token_id = tx_info->ack_frame_id;
530 txpd->flags |= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS;
533 if (txpd->priority < ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
535 * Set the priority specific tx_control field, setting of 0 will
536 * cause the default value to be used later in this function.
539 cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[txpd->priority]);
541 /* Offset of actual data */
542 pkt_offset = sizeof(*txpd) + pad;
543 if (pkt_type == PKT_TYPE_MGMT) {
544 /* Set the packet type and add header for management frame */
545 txpd->tx_pkt_type = cpu_to_le16(pkt_type);
546 pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
549 txpd->tx_pkt_offset = cpu_to_le16(pkt_offset);
551 /* make space for adapter->intf_hdr_len */
552 skb_push(skb, hroom);
554 if (!txpd->tx_control)
555 /* TxCtrl set by user or default */
556 txpd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);