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
;
106 uap_rx_pd
= (struct uap_rxpd
*)(skb
->data
);
107 rx_pkt_hdr
= (void *)uap_rx_pd
+ le16_to_cpu(uap_rx_pd
->rx_pkt_offset
);
109 if ((atomic_read(&adapter
->pending_bridged_pkts
) >=
110 MWIFIEX_BRIDGED_PKTS_THR_HIGH
)) {
111 mwifiex_dbg(priv
->adapter
, ERROR
,
112 "Tx: Bridge packet limit reached. Drop packet!\n");
114 mwifiex_uap_cleanup_tx_queues(priv
);
118 if ((!memcmp(&rx_pkt_hdr
->rfc1042_hdr
, bridge_tunnel_header
,
119 sizeof(bridge_tunnel_header
))) ||
120 (!memcmp(&rx_pkt_hdr
->rfc1042_hdr
, rfc1042_header
,
121 sizeof(rfc1042_header
)) &&
122 ntohs(rx_pkt_hdr
->rfc1042_hdr
.snap_type
) != ETH_P_AARP
&&
123 ntohs(rx_pkt_hdr
->rfc1042_hdr
.snap_type
) != ETH_P_IPX
)) {
124 /* Replace the 803 header and rfc1042 header (llc/snap) with
125 * an Ethernet II header, keep the src/dst and snap_type
128 * The firmware only passes up SNAP frames converting all RX
129 * data from 802.11 to 802.2/LLC/SNAP frames.
131 * To create the Ethernet II, just move the src, dst address
132 * right before the snap_type.
134 p_ethhdr
= (struct ethhdr
*)
135 ((u8
*)(&rx_pkt_hdr
->eth803_hdr
)
136 + sizeof(rx_pkt_hdr
->eth803_hdr
)
137 + sizeof(rx_pkt_hdr
->rfc1042_hdr
)
138 - sizeof(rx_pkt_hdr
->eth803_hdr
.h_dest
)
139 - sizeof(rx_pkt_hdr
->eth803_hdr
.h_source
)
140 - sizeof(rx_pkt_hdr
->rfc1042_hdr
.snap_type
));
141 memcpy(p_ethhdr
->h_source
, rx_pkt_hdr
->eth803_hdr
.h_source
,
142 sizeof(p_ethhdr
->h_source
));
143 memcpy(p_ethhdr
->h_dest
, rx_pkt_hdr
->eth803_hdr
.h_dest
,
144 sizeof(p_ethhdr
->h_dest
));
145 /* Chop off the rxpd + the excess memory from
146 * 802.2/llc/snap header that was removed.
148 hdr_chop
= (u8
*)p_ethhdr
- (u8
*)uap_rx_pd
;
150 /* Chop off the rxpd */
151 hdr_chop
= (u8
*)&rx_pkt_hdr
->eth803_hdr
- (u8
*)uap_rx_pd
;
154 /* Chop off the leading header bytes so that it points
155 * to the start of either the reconstructed EthII frame
156 * or the 802.2/llc/snap frame.
158 skb_pull(skb
, hdr_chop
);
160 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
161 mwifiex_dbg(priv
->adapter
, ERROR
,
162 "data: Tx: insufficient skb headroom %d\n",
164 /* Insufficient skb headroom - allocate a new skb */
166 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
167 if (unlikely(!new_skb
)) {
168 mwifiex_dbg(priv
->adapter
, ERROR
,
169 "Tx: cannot allocate new_skb\n");
171 priv
->stats
.tx_dropped
++;
177 mwifiex_dbg(priv
->adapter
, INFO
,
178 "info: new skb headroom %d\n",
182 tx_info
= MWIFIEX_SKB_TXCB(skb
);
183 memset(tx_info
, 0, sizeof(*tx_info
));
184 tx_info
->bss_num
= priv
->bss_num
;
185 tx_info
->bss_type
= priv
->bss_type
;
186 tx_info
->flags
|= MWIFIEX_BUF_FLAG_BRIDGED_PKT
;
188 src_node
= mwifiex_get_sta_entry(priv
, rx_pkt_hdr
->eth803_hdr
.h_source
);
190 src_node
->stats
.last_rx
= jiffies
;
191 src_node
->stats
.rx_bytes
+= skb
->len
;
192 src_node
->stats
.rx_packets
++;
193 src_node
->stats
.last_tx_rate
= uap_rx_pd
->rx_rate
;
194 src_node
->stats
.last_tx_htinfo
= uap_rx_pd
->ht_info
;
197 if (is_unicast_ether_addr(rx_pkt_hdr
->eth803_hdr
.h_dest
)) {
198 /* Update bridge packet statistics as the
199 * packet is not going to kernel/upper layer.
201 priv
->stats
.rx_bytes
+= skb
->len
;
202 priv
->stats
.rx_packets
++;
204 /* Sending bridge packet to TX queue, so save the packet
205 * length in TXCB to update statistics in TX complete.
207 tx_info
->pkt_len
= skb
->len
;
210 __net_timestamp(skb
);
211 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
212 atomic_inc(&adapter
->tx_pending
);
213 atomic_inc(&adapter
->pending_bridged_pkts
);
219 * This function contains logic for AP packet forwarding.
221 * If a packet is multicast/broadcast, it is sent to kernel/upper layer
222 * as well as queued back to AP TX queue so that it can be sent to other
223 * associated stations.
224 * If a packet is unicast and RA is present in associated station list,
225 * it is again requeued into AP TX queue.
226 * If a packet is unicast and RA is not in associated station list,
227 * packet is forwarded to kernel to handle routing logic.
229 int mwifiex_handle_uap_rx_forward(struct mwifiex_private
*priv
,
232 struct mwifiex_adapter
*adapter
= priv
->adapter
;
233 struct uap_rxpd
*uap_rx_pd
;
234 struct rx_packet_hdr
*rx_pkt_hdr
;
236 struct sk_buff
*skb_uap
;
238 uap_rx_pd
= (struct uap_rxpd
*)(skb
->data
);
239 rx_pkt_hdr
= (void *)uap_rx_pd
+ le16_to_cpu(uap_rx_pd
->rx_pkt_offset
);
241 /* don't do packet forwarding in disconnected state */
242 if (!priv
->media_connected
) {
243 mwifiex_dbg(adapter
, ERROR
,
244 "drop packet in disconnected state.\n");
245 dev_kfree_skb_any(skb
);
249 memcpy(ra
, rx_pkt_hdr
->eth803_hdr
.h_dest
, ETH_ALEN
);
251 if (is_multicast_ether_addr(ra
)) {
252 skb_uap
= skb_copy(skb
, GFP_ATOMIC
);
253 mwifiex_uap_queue_bridged_pkt(priv
, skb_uap
);
255 if (mwifiex_get_sta_entry(priv
, ra
)) {
256 /* Requeue Intra-BSS packet */
257 mwifiex_uap_queue_bridged_pkt(priv
, skb
);
262 /* Forward unicat/Inter-BSS packets to kernel. */
263 return mwifiex_process_rx_packet(priv
, skb
);
267 * This function processes the packet received on AP interface.
269 * The function looks into the RxPD and performs sanity tests on the
270 * received buffer to ensure its a valid packet before processing it
271 * further. If the packet is determined to be aggregated, it is
272 * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic.
274 * The completion callback is called after processing is complete.
276 int mwifiex_process_uap_rx_packet(struct mwifiex_private
*priv
,
279 struct mwifiex_adapter
*adapter
= priv
->adapter
;
281 struct uap_rxpd
*uap_rx_pd
;
282 struct rx_packet_hdr
*rx_pkt_hdr
;
284 u8 ta
[ETH_ALEN
], pkt_type
;
286 struct mwifiex_sta_node
*node
;
288 uap_rx_pd
= (struct uap_rxpd
*)(skb
->data
);
289 rx_pkt_type
= le16_to_cpu(uap_rx_pd
->rx_pkt_type
);
290 rx_pkt_hdr
= (void *)uap_rx_pd
+ le16_to_cpu(uap_rx_pd
->rx_pkt_offset
);
292 ether_addr_copy(ta
, rx_pkt_hdr
->eth803_hdr
.h_source
);
294 if ((le16_to_cpu(uap_rx_pd
->rx_pkt_offset
) +
295 le16_to_cpu(uap_rx_pd
->rx_pkt_length
)) > (u16
) skb
->len
) {
296 mwifiex_dbg(adapter
, ERROR
,
297 "wrong rx packet: len=%d, offset=%d, length=%d\n",
298 skb
->len
, le16_to_cpu(uap_rx_pd
->rx_pkt_offset
),
299 le16_to_cpu(uap_rx_pd
->rx_pkt_length
));
300 priv
->stats
.rx_dropped
++;
302 node
= mwifiex_get_sta_entry(priv
, ta
);
304 node
->stats
.tx_failed
++;
306 dev_kfree_skb_any(skb
);
310 if (rx_pkt_type
== PKT_TYPE_MGMT
) {
311 ret
= mwifiex_process_mgmt_packet(priv
, skb
);
313 mwifiex_dbg(adapter
, DATA
, "Rx of mgmt packet failed");
314 dev_kfree_skb_any(skb
);
319 if (rx_pkt_type
!= PKT_TYPE_BAR
&& uap_rx_pd
->priority
< MAX_NUM_TID
) {
320 spin_lock_irqsave(&priv
->sta_list_spinlock
, flags
);
321 node
= mwifiex_get_sta_entry(priv
, ta
);
323 node
->rx_seq
[uap_rx_pd
->priority
] =
324 le16_to_cpu(uap_rx_pd
->seq_num
);
325 spin_unlock_irqrestore(&priv
->sta_list_spinlock
, flags
);
328 if (!priv
->ap_11n_enabled
||
329 (!mwifiex_11n_get_rx_reorder_tbl(priv
, uap_rx_pd
->priority
, ta
) &&
330 (le16_to_cpu(uap_rx_pd
->rx_pkt_type
) != PKT_TYPE_AMSDU
))) {
331 ret
= mwifiex_handle_uap_rx_forward(priv
, skb
);
335 /* Reorder and send to kernel */
336 pkt_type
= (u8
)le16_to_cpu(uap_rx_pd
->rx_pkt_type
);
337 ret
= mwifiex_11n_rx_reorder_pkt(priv
, le16_to_cpu(uap_rx_pd
->seq_num
),
338 uap_rx_pd
->priority
, ta
, pkt_type
,
341 if (ret
|| (rx_pkt_type
== PKT_TYPE_BAR
))
342 dev_kfree_skb_any(skb
);
345 priv
->stats
.rx_dropped
++;
351 * This function fills the TxPD for AP tx packets.
353 * The Tx buffer received by this function should already have the
354 * header space allocated for TxPD.
356 * This function inserts the TxPD in between interface header and actual
357 * data and adjusts the buffer pointers accordingly.
359 * The following TxPD fields are set by this function, as required -
361 * - Tx packet length and offset
364 * - Priority specific Tx control
367 void *mwifiex_process_uap_txpd(struct mwifiex_private
*priv
,
370 struct mwifiex_adapter
*adapter
= priv
->adapter
;
371 struct uap_txpd
*txpd
;
372 struct mwifiex_txinfo
*tx_info
= MWIFIEX_SKB_TXCB(skb
);
374 u16 pkt_type
, pkt_offset
;
375 int hroom
= (priv
->adapter
->iface_type
== MWIFIEX_USB
) ? 0 :
379 mwifiex_dbg(adapter
, ERROR
,
380 "Tx: bad packet length: %d\n", skb
->len
);
381 tx_info
->status_code
= -1;
385 BUG_ON(skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
);
387 pkt_type
= mwifiex_is_skb_mgmt_frame(skb
) ? PKT_TYPE_MGMT
: 0;
389 pad
= ((void *)skb
->data
- (sizeof(*txpd
) + hroom
) - NULL
) &
390 (MWIFIEX_DMA_ALIGN_SZ
- 1);
392 skb_push(skb
, sizeof(*txpd
) + pad
);
394 txpd
= (struct uap_txpd
*)skb
->data
;
395 memset(txpd
, 0, sizeof(*txpd
));
396 txpd
->bss_num
= priv
->bss_num
;
397 txpd
->bss_type
= priv
->bss_type
;
398 txpd
->tx_pkt_length
= cpu_to_le16((u16
)(skb
->len
- (sizeof(*txpd
) +
400 txpd
->priority
= (u8
)skb
->priority
;
402 txpd
->pkt_delay_2ms
= mwifiex_wmm_compute_drv_pkt_delay(priv
, skb
);
404 if (tx_info
->flags
& MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS
||
405 tx_info
->flags
& MWIFIEX_BUF_FLAG_ACTION_TX_STATUS
) {
406 txpd
->tx_token_id
= tx_info
->ack_frame_id
;
407 txpd
->flags
|= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS
;
410 if (txpd
->priority
< ARRAY_SIZE(priv
->wmm
.user_pri_pkt_tx_ctrl
))
412 * Set the priority specific tx_control field, setting of 0 will
413 * cause the default value to be used later in this function.
416 cpu_to_le32(priv
->wmm
.user_pri_pkt_tx_ctrl
[txpd
->priority
]);
418 /* Offset of actual data */
419 pkt_offset
= sizeof(*txpd
) + pad
;
420 if (pkt_type
== PKT_TYPE_MGMT
) {
421 /* Set the packet type and add header for management frame */
422 txpd
->tx_pkt_type
= cpu_to_le16(pkt_type
);
423 pkt_offset
+= MWIFIEX_MGMT_FRAME_HEADER_SIZE
;
426 txpd
->tx_pkt_offset
= cpu_to_le16(pkt_offset
);
428 /* make space for INTF_HEADER_LEN */
429 skb_push(skb
, hroom
);
431 if (!txpd
->tx_control
)
432 /* TxCtrl set by user or default */
433 txpd
->tx_control
= cpu_to_le32(priv
->pkt_tx_ctrl
);