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 ((!memcmp(&rx_pkt_hdr
->rfc1042_hdr
, bridge_tunnel_header
,
120 sizeof(bridge_tunnel_header
))) ||
121 (!memcmp(&rx_pkt_hdr
->rfc1042_hdr
, rfc1042_header
,
122 sizeof(rfc1042_header
)) &&
123 ntohs(rx_pkt_hdr
->rfc1042_hdr
.snap_type
) != ETH_P_AARP
&&
124 ntohs(rx_pkt_hdr
->rfc1042_hdr
.snap_type
) != ETH_P_IPX
)) {
125 /* Replace the 803 header and rfc1042 header (llc/snap) with
126 * an Ethernet II header, keep the src/dst and snap_type
129 * The firmware only passes up SNAP frames converting all RX
130 * data from 802.11 to 802.2/LLC/SNAP frames.
132 * To create the Ethernet II, just move the src, dst address
133 * right before the snap_type.
135 p_ethhdr
= (struct ethhdr
*)
136 ((u8
*)(&rx_pkt_hdr
->eth803_hdr
)
137 + sizeof(rx_pkt_hdr
->eth803_hdr
)
138 + sizeof(rx_pkt_hdr
->rfc1042_hdr
)
139 - sizeof(rx_pkt_hdr
->eth803_hdr
.h_dest
)
140 - sizeof(rx_pkt_hdr
->eth803_hdr
.h_source
)
141 - sizeof(rx_pkt_hdr
->rfc1042_hdr
.snap_type
));
142 memcpy(p_ethhdr
->h_source
, rx_pkt_hdr
->eth803_hdr
.h_source
,
143 sizeof(p_ethhdr
->h_source
));
144 memcpy(p_ethhdr
->h_dest
, rx_pkt_hdr
->eth803_hdr
.h_dest
,
145 sizeof(p_ethhdr
->h_dest
));
146 /* Chop off the rxpd + the excess memory from
147 * 802.2/llc/snap header that was removed.
149 hdr_chop
= (u8
*)p_ethhdr
- (u8
*)uap_rx_pd
;
151 /* Chop off the rxpd */
152 hdr_chop
= (u8
*)&rx_pkt_hdr
->eth803_hdr
- (u8
*)uap_rx_pd
;
155 /* Chop off the leading header bytes so that it points
156 * to the start of either the reconstructed EthII frame
157 * or the 802.2/llc/snap frame.
159 skb_pull(skb
, hdr_chop
);
161 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
162 mwifiex_dbg(priv
->adapter
, ERROR
,
163 "data: Tx: insufficient skb headroom %d\n",
165 /* Insufficient skb headroom - allocate a new skb */
167 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
168 if (unlikely(!new_skb
)) {
169 mwifiex_dbg(priv
->adapter
, ERROR
,
170 "Tx: cannot allocate new_skb\n");
172 priv
->stats
.tx_dropped
++;
178 mwifiex_dbg(priv
->adapter
, INFO
,
179 "info: new skb headroom %d\n",
183 tx_info
= MWIFIEX_SKB_TXCB(skb
);
184 memset(tx_info
, 0, sizeof(*tx_info
));
185 tx_info
->bss_num
= priv
->bss_num
;
186 tx_info
->bss_type
= priv
->bss_type
;
187 tx_info
->flags
|= MWIFIEX_BUF_FLAG_BRIDGED_PKT
;
189 src_node
= mwifiex_get_sta_entry(priv
, rx_pkt_hdr
->eth803_hdr
.h_source
);
191 src_node
->stats
.last_rx
= jiffies
;
192 src_node
->stats
.rx_bytes
+= skb
->len
;
193 src_node
->stats
.rx_packets
++;
194 src_node
->stats
.last_tx_rate
= uap_rx_pd
->rx_rate
;
195 src_node
->stats
.last_tx_htinfo
= uap_rx_pd
->ht_info
;
198 if (is_unicast_ether_addr(rx_pkt_hdr
->eth803_hdr
.h_dest
)) {
199 /* Update bridge packet statistics as the
200 * packet is not going to kernel/upper layer.
202 priv
->stats
.rx_bytes
+= skb
->len
;
203 priv
->stats
.rx_packets
++;
205 /* Sending bridge packet to TX queue, so save the packet
206 * length in TXCB to update statistics in TX complete.
208 tx_info
->pkt_len
= skb
->len
;
211 __net_timestamp(skb
);
213 index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
214 atomic_inc(&priv
->wmm_tx_pending
[index
]);
215 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
216 atomic_inc(&adapter
->tx_pending
);
217 atomic_inc(&adapter
->pending_bridged_pkts
);
219 mwifiex_queue_main_work(priv
->adapter
);
225 * This function contains logic for AP packet forwarding.
227 * If a packet is multicast/broadcast, it is sent to kernel/upper layer
228 * as well as queued back to AP TX queue so that it can be sent to other
229 * associated stations.
230 * If a packet is unicast and RA is present in associated station list,
231 * it is again requeued into AP TX queue.
232 * If a packet is unicast and RA is not in associated station list,
233 * packet is forwarded to kernel to handle routing logic.
235 int mwifiex_handle_uap_rx_forward(struct mwifiex_private
*priv
,
238 struct mwifiex_adapter
*adapter
= priv
->adapter
;
239 struct uap_rxpd
*uap_rx_pd
;
240 struct rx_packet_hdr
*rx_pkt_hdr
;
242 struct sk_buff
*skb_uap
;
244 uap_rx_pd
= (struct uap_rxpd
*)(skb
->data
);
245 rx_pkt_hdr
= (void *)uap_rx_pd
+ le16_to_cpu(uap_rx_pd
->rx_pkt_offset
);
247 /* don't do packet forwarding in disconnected state */
248 if (!priv
->media_connected
) {
249 mwifiex_dbg(adapter
, ERROR
,
250 "drop packet in disconnected state.\n");
251 dev_kfree_skb_any(skb
);
255 memcpy(ra
, rx_pkt_hdr
->eth803_hdr
.h_dest
, ETH_ALEN
);
257 if (is_multicast_ether_addr(ra
)) {
258 skb_uap
= skb_copy(skb
, GFP_ATOMIC
);
259 mwifiex_uap_queue_bridged_pkt(priv
, skb_uap
);
261 if (mwifiex_get_sta_entry(priv
, ra
)) {
262 /* Requeue Intra-BSS packet */
263 mwifiex_uap_queue_bridged_pkt(priv
, skb
);
268 /* Forward unicat/Inter-BSS packets to kernel. */
269 return mwifiex_process_rx_packet(priv
, skb
);
272 int mwifiex_uap_recv_packet(struct mwifiex_private
*priv
,
275 struct mwifiex_adapter
*adapter
= adapter
;
276 struct mwifiex_sta_node
*src_node
;
277 struct ethhdr
*p_ethhdr
;
278 struct sk_buff
*skb_uap
;
279 struct mwifiex_txinfo
*tx_info
;
284 p_ethhdr
= (void *)skb
->data
;
285 src_node
= mwifiex_get_sta_entry(priv
, p_ethhdr
->h_source
);
287 src_node
->stats
.last_rx
= jiffies
;
288 src_node
->stats
.rx_bytes
+= skb
->len
;
289 src_node
->stats
.rx_packets
++;
292 skb
->dev
= priv
->netdev
;
293 skb
->protocol
= eth_type_trans(skb
, priv
->netdev
);
294 skb
->ip_summed
= CHECKSUM_NONE
;
296 /* This is required only in case of 11n and USB/PCIE as we alloc
297 * a buffer of 4K only if its 11N (to be able to receive 4K
298 * AMSDU packets). In case of SD we allocate buffers based
299 * on the size of packet and hence this is not needed.
301 * Modifying the truesize here as our allocation for each
302 * skb is 4K but we only receive 2K packets and this cause
303 * the kernel to start dropping packets in case where
304 * application has allocated buffer based on 2K size i.e.
305 * if there a 64K packet received (in IP fragments and
306 * application allocates 64K to receive this packet but
307 * this packet would almost double up because we allocate
308 * each 1.5K fragment in 4K and pass it up. As soon as the
309 * 64K limit hits kernel will start to drop rest of the
310 * fragments. Currently we fail the Filesndl-ht.scr script
311 * for UDP, hence this fix
313 if ((adapter
->iface_type
== MWIFIEX_USB
||
314 adapter
->iface_type
== MWIFIEX_PCIE
) &&
315 (skb
->truesize
> MWIFIEX_RX_DATA_BUF_SIZE
))
316 skb
->truesize
+= (skb
->len
- MWIFIEX_RX_DATA_BUF_SIZE
);
318 if (is_multicast_ether_addr(p_ethhdr
->h_dest
) ||
319 mwifiex_get_sta_entry(priv
, p_ethhdr
->h_dest
)) {
320 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
)
322 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
324 skb_uap
= skb_copy(skb
, GFP_ATOMIC
);
326 if (likely(skb_uap
)) {
327 tx_info
= MWIFIEX_SKB_TXCB(skb_uap
);
328 memset(tx_info
, 0, sizeof(*tx_info
));
329 tx_info
->bss_num
= priv
->bss_num
;
330 tx_info
->bss_type
= priv
->bss_type
;
331 tx_info
->flags
|= MWIFIEX_BUF_FLAG_BRIDGED_PKT
;
332 __net_timestamp(skb_uap
);
333 mwifiex_wmm_add_buf_txqueue(priv
, skb_uap
);
334 atomic_inc(&adapter
->tx_pending
);
335 atomic_inc(&adapter
->pending_bridged_pkts
);
336 if ((atomic_read(&adapter
->pending_bridged_pkts
) >=
337 MWIFIEX_BRIDGED_PKTS_THR_HIGH
)) {
338 mwifiex_dbg(adapter
, ERROR
,
339 "Tx: Bridge packet limit reached. Drop packet!\n");
340 mwifiex_uap_cleanup_tx_queues(priv
);
344 mwifiex_dbg(adapter
, ERROR
, "failed to allocate skb_uap");
347 mwifiex_queue_main_work(adapter
);
348 /* Don't forward Intra-BSS unicast packet to upper layer*/
349 if (mwifiex_get_sta_entry(priv
, p_ethhdr
->h_dest
))
353 /* Forward multicast/broadcast packet to upper layer*/
363 * This function processes the packet received on AP interface.
365 * The function looks into the RxPD and performs sanity tests on the
366 * received buffer to ensure its a valid packet before processing it
367 * further. If the packet is determined to be aggregated, it is
368 * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic.
370 * The completion callback is called after processing is complete.
372 int mwifiex_process_uap_rx_packet(struct mwifiex_private
*priv
,
375 struct mwifiex_adapter
*adapter
= priv
->adapter
;
377 struct uap_rxpd
*uap_rx_pd
;
378 struct rx_packet_hdr
*rx_pkt_hdr
;
380 u8 ta
[ETH_ALEN
], pkt_type
;
382 struct mwifiex_sta_node
*node
;
384 uap_rx_pd
= (struct uap_rxpd
*)(skb
->data
);
385 rx_pkt_type
= le16_to_cpu(uap_rx_pd
->rx_pkt_type
);
386 rx_pkt_hdr
= (void *)uap_rx_pd
+ le16_to_cpu(uap_rx_pd
->rx_pkt_offset
);
388 ether_addr_copy(ta
, rx_pkt_hdr
->eth803_hdr
.h_source
);
390 if ((le16_to_cpu(uap_rx_pd
->rx_pkt_offset
) +
391 le16_to_cpu(uap_rx_pd
->rx_pkt_length
)) > (u16
) skb
->len
) {
392 mwifiex_dbg(adapter
, ERROR
,
393 "wrong rx packet: len=%d, offset=%d, length=%d\n",
394 skb
->len
, le16_to_cpu(uap_rx_pd
->rx_pkt_offset
),
395 le16_to_cpu(uap_rx_pd
->rx_pkt_length
));
396 priv
->stats
.rx_dropped
++;
398 node
= mwifiex_get_sta_entry(priv
, ta
);
400 node
->stats
.tx_failed
++;
402 dev_kfree_skb_any(skb
);
406 if (rx_pkt_type
== PKT_TYPE_MGMT
) {
407 ret
= mwifiex_process_mgmt_packet(priv
, skb
);
409 mwifiex_dbg(adapter
, DATA
, "Rx of mgmt packet failed");
410 dev_kfree_skb_any(skb
);
415 if (rx_pkt_type
!= PKT_TYPE_BAR
&& uap_rx_pd
->priority
< MAX_NUM_TID
) {
416 spin_lock_irqsave(&priv
->sta_list_spinlock
, flags
);
417 node
= mwifiex_get_sta_entry(priv
, ta
);
419 node
->rx_seq
[uap_rx_pd
->priority
] =
420 le16_to_cpu(uap_rx_pd
->seq_num
);
421 spin_unlock_irqrestore(&priv
->sta_list_spinlock
, flags
);
424 if (!priv
->ap_11n_enabled
||
425 (!mwifiex_11n_get_rx_reorder_tbl(priv
, uap_rx_pd
->priority
, ta
) &&
426 (le16_to_cpu(uap_rx_pd
->rx_pkt_type
) != PKT_TYPE_AMSDU
))) {
427 ret
= mwifiex_handle_uap_rx_forward(priv
, skb
);
431 /* Reorder and send to kernel */
432 pkt_type
= (u8
)le16_to_cpu(uap_rx_pd
->rx_pkt_type
);
433 ret
= mwifiex_11n_rx_reorder_pkt(priv
, le16_to_cpu(uap_rx_pd
->seq_num
),
434 uap_rx_pd
->priority
, ta
, pkt_type
,
437 if (ret
|| (rx_pkt_type
== PKT_TYPE_BAR
))
438 dev_kfree_skb_any(skb
);
441 priv
->stats
.rx_dropped
++;
447 * This function fills the TxPD for AP tx packets.
449 * The Tx buffer received by this function should already have the
450 * header space allocated for TxPD.
452 * This function inserts the TxPD in between interface header and actual
453 * data and adjusts the buffer pointers accordingly.
455 * The following TxPD fields are set by this function, as required -
457 * - Tx packet length and offset
460 * - Priority specific Tx control
463 void *mwifiex_process_uap_txpd(struct mwifiex_private
*priv
,
466 struct mwifiex_adapter
*adapter
= priv
->adapter
;
467 struct uap_txpd
*txpd
;
468 struct mwifiex_txinfo
*tx_info
= MWIFIEX_SKB_TXCB(skb
);
470 u16 pkt_type
, pkt_offset
;
471 int hroom
= (priv
->adapter
->iface_type
== MWIFIEX_USB
) ? 0 :
475 mwifiex_dbg(adapter
, ERROR
,
476 "Tx: bad packet length: %d\n", skb
->len
);
477 tx_info
->status_code
= -1;
481 BUG_ON(skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
);
483 pkt_type
= mwifiex_is_skb_mgmt_frame(skb
) ? PKT_TYPE_MGMT
: 0;
485 pad
= ((void *)skb
->data
- (sizeof(*txpd
) + hroom
) - NULL
) &
486 (MWIFIEX_DMA_ALIGN_SZ
- 1);
488 skb_push(skb
, sizeof(*txpd
) + pad
);
490 txpd
= (struct uap_txpd
*)skb
->data
;
491 memset(txpd
, 0, sizeof(*txpd
));
492 txpd
->bss_num
= priv
->bss_num
;
493 txpd
->bss_type
= priv
->bss_type
;
494 txpd
->tx_pkt_length
= cpu_to_le16((u16
)(skb
->len
- (sizeof(*txpd
) +
496 txpd
->priority
= (u8
)skb
->priority
;
498 txpd
->pkt_delay_2ms
= mwifiex_wmm_compute_drv_pkt_delay(priv
, skb
);
500 if (tx_info
->flags
& MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS
||
501 tx_info
->flags
& MWIFIEX_BUF_FLAG_ACTION_TX_STATUS
) {
502 txpd
->tx_token_id
= tx_info
->ack_frame_id
;
503 txpd
->flags
|= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS
;
506 if (txpd
->priority
< ARRAY_SIZE(priv
->wmm
.user_pri_pkt_tx_ctrl
))
508 * Set the priority specific tx_control field, setting of 0 will
509 * cause the default value to be used later in this function.
512 cpu_to_le32(priv
->wmm
.user_pri_pkt_tx_ctrl
[txpd
->priority
]);
514 /* Offset of actual data */
515 pkt_offset
= sizeof(*txpd
) + pad
;
516 if (pkt_type
== PKT_TYPE_MGMT
) {
517 /* Set the packet type and add header for management frame */
518 txpd
->tx_pkt_type
= cpu_to_le16(pkt_type
);
519 pkt_offset
+= MWIFIEX_MGMT_FRAME_HEADER_SIZE
;
522 txpd
->tx_pkt_offset
= cpu_to_le16(pkt_offset
);
524 /* make space for INTF_HEADER_LEN */
525 skb_push(skb
, hroom
);
527 if (!txpd
->tx_control
)
528 /* TxCtrl set by user or default */
529 txpd
->tx_control
= cpu_to_le32(priv
->pkt_tx_ctrl
);