2 * Marvell Wireless LAN device driver: AP TX and RX data handling
4 * Copyright (C) 2012, 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
)
36 struct mwifiex_ra_list_tbl
*ra_list
;
37 struct sk_buff
*skb
, *tmp
;
38 bool pkt_deleted
= false;
39 struct mwifiex_txinfo
*tx_info
;
40 struct mwifiex_adapter
*adapter
= priv
->adapter
;
42 list_for_each_entry(ra_list
, ra_list_head
, list
) {
43 if (skb_queue_empty(&ra_list
->skb_head
))
46 skb_queue_walk_safe(&ra_list
->skb_head
, skb
, tmp
) {
47 tx_info
= MWIFIEX_SKB_TXCB(skb
);
48 if (tx_info
->flags
& MWIFIEX_BUF_FLAG_BRIDGED_PKT
) {
49 __skb_unlink(skb
, &ra_list
->skb_head
);
50 mwifiex_write_data_complete(adapter
, skb
, 0,
52 atomic_dec(&priv
->wmm
.tx_pkts_queued
);
55 if ((atomic_read(&adapter
->pending_bridged_pkts
) <=
56 MWIFIEX_BRIDGED_PKTS_THR_LOW
))
64 /* This function deletes packets from particular RA List. RA list index
65 * from which packets are deleted is preserved so that packets from next RA
66 * list are deleted upon subsequent call thus maintaining fairness.
68 static void mwifiex_uap_cleanup_tx_queues(struct mwifiex_private
*priv
)
71 struct list_head
*ra_list
;
74 spin_lock_irqsave(&priv
->wmm
.ra_list_spinlock
, flags
);
76 for (i
= 0; i
< MAX_NUM_TID
; i
++, priv
->del_list_idx
++) {
77 if (priv
->del_list_idx
== MAX_NUM_TID
)
78 priv
->del_list_idx
= 0;
79 ra_list
= &priv
->wmm
.tid_tbl_ptr
[priv
->del_list_idx
].ra_list
;
80 if (mwifiex_uap_del_tx_pkts_in_ralist(priv
, ra_list
)) {
86 spin_unlock_irqrestore(&priv
->wmm
.ra_list_spinlock
, flags
);
90 static void mwifiex_uap_queue_bridged_pkt(struct mwifiex_private
*priv
,
93 struct mwifiex_adapter
*adapter
= priv
->adapter
;
94 struct uap_rxpd
*uap_rx_pd
;
95 struct rx_packet_hdr
*rx_pkt_hdr
;
96 struct sk_buff
*new_skb
;
97 struct mwifiex_txinfo
*tx_info
;
100 u8 rfc1042_eth_hdr
[ETH_ALEN
] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
102 uap_rx_pd
= (struct uap_rxpd
*)(skb
->data
);
103 rx_pkt_hdr
= (void *)uap_rx_pd
+ le16_to_cpu(uap_rx_pd
->rx_pkt_offset
);
105 if ((atomic_read(&adapter
->pending_bridged_pkts
) >=
106 MWIFIEX_BRIDGED_PKTS_THR_HIGH
)) {
107 dev_err(priv
->adapter
->dev
,
108 "Tx: Bridge packet limit reached. Drop packet!\n");
110 mwifiex_uap_cleanup_tx_queues(priv
);
114 if (!memcmp(&rx_pkt_hdr
->rfc1042_hdr
,
115 rfc1042_eth_hdr
, sizeof(rfc1042_eth_hdr
)))
116 /* Chop off the rxpd + the excess memory from
117 * 802.2/llc/snap header that was removed.
119 hdr_chop
= (u8
*)eth_hdr
- (u8
*)uap_rx_pd
;
121 /* Chop off the rxpd */
122 hdr_chop
= (u8
*)&rx_pkt_hdr
->eth803_hdr
- (u8
*)uap_rx_pd
;
124 /* Chop off the leading header bytes so the it points
125 * to the start of either the reconstructed EthII frame
126 * or the 802.2/llc/snap frame.
128 skb_pull(skb
, hdr_chop
);
130 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
131 dev_dbg(priv
->adapter
->dev
,
132 "data: Tx: insufficient skb headroom %d\n",
134 /* Insufficient skb headroom - allocate a new skb */
136 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
137 if (unlikely(!new_skb
)) {
138 dev_err(priv
->adapter
->dev
,
139 "Tx: cannot allocate new_skb\n");
141 priv
->stats
.tx_dropped
++;
147 dev_dbg(priv
->adapter
->dev
, "info: new skb headroom %d\n",
151 tx_info
= MWIFIEX_SKB_TXCB(skb
);
152 tx_info
->bss_num
= priv
->bss_num
;
153 tx_info
->bss_type
= priv
->bss_type
;
154 tx_info
->flags
|= MWIFIEX_BUF_FLAG_BRIDGED_PKT
;
156 do_gettimeofday(&tv
);
157 skb
->tstamp
= timeval_to_ktime(tv
);
158 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
159 atomic_inc(&adapter
->tx_pending
);
160 atomic_inc(&adapter
->pending_bridged_pkts
);
166 * This function contains logic for AP packet forwarding.
168 * If a packet is multicast/broadcast, it is sent to kernel/upper layer
169 * as well as queued back to AP TX queue so that it can be sent to other
170 * associated stations.
171 * If a packet is unicast and RA is present in associated station list,
172 * it is again requeued into AP TX queue.
173 * If a packet is unicast and RA is not in associated station list,
174 * packet is forwarded to kernel to handle routing logic.
176 int mwifiex_handle_uap_rx_forward(struct mwifiex_private
*priv
,
179 struct mwifiex_adapter
*adapter
= priv
->adapter
;
180 struct uap_rxpd
*uap_rx_pd
;
181 struct rx_packet_hdr
*rx_pkt_hdr
;
183 struct sk_buff
*skb_uap
;
185 uap_rx_pd
= (struct uap_rxpd
*)(skb
->data
);
186 rx_pkt_hdr
= (void *)uap_rx_pd
+ le16_to_cpu(uap_rx_pd
->rx_pkt_offset
);
188 /* don't do packet forwarding in disconnected state */
189 if (!priv
->media_connected
) {
190 dev_err(adapter
->dev
, "drop packet in disconnected state.\n");
191 dev_kfree_skb_any(skb
);
195 memcpy(ra
, rx_pkt_hdr
->eth803_hdr
.h_dest
, ETH_ALEN
);
197 if (is_multicast_ether_addr(ra
)) {
198 skb_uap
= skb_copy(skb
, GFP_ATOMIC
);
199 mwifiex_uap_queue_bridged_pkt(priv
, skb_uap
);
201 if (mwifiex_get_sta_entry(priv
, ra
)) {
202 /* Requeue Intra-BSS packet */
203 mwifiex_uap_queue_bridged_pkt(priv
, skb
);
208 /* Forward unicat/Inter-BSS packets to kernel. */
209 return mwifiex_process_rx_packet(priv
, skb
);
213 * This function processes the packet received on AP interface.
215 * The function looks into the RxPD and performs sanity tests on the
216 * received buffer to ensure its a valid packet before processing it
217 * further. If the packet is determined to be aggregated, it is
218 * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic.
220 * The completion callback is called after processing is complete.
222 int mwifiex_process_uap_rx_packet(struct mwifiex_private
*priv
,
225 struct mwifiex_adapter
*adapter
= priv
->adapter
;
227 struct uap_rxpd
*uap_rx_pd
;
228 struct rx_packet_hdr
*rx_pkt_hdr
;
230 u8 ta
[ETH_ALEN
], pkt_type
;
231 struct mwifiex_sta_node
*node
;
233 uap_rx_pd
= (struct uap_rxpd
*)(skb
->data
);
234 rx_pkt_type
= le16_to_cpu(uap_rx_pd
->rx_pkt_type
);
235 rx_pkt_hdr
= (void *)uap_rx_pd
+ le16_to_cpu(uap_rx_pd
->rx_pkt_offset
);
237 if ((le16_to_cpu(uap_rx_pd
->rx_pkt_offset
) +
238 le16_to_cpu(uap_rx_pd
->rx_pkt_length
)) > (u16
) skb
->len
) {
239 dev_err(adapter
->dev
,
240 "wrong rx packet: len=%d, offset=%d, length=%d\n",
241 skb
->len
, le16_to_cpu(uap_rx_pd
->rx_pkt_offset
),
242 le16_to_cpu(uap_rx_pd
->rx_pkt_length
));
243 priv
->stats
.rx_dropped
++;
245 if (adapter
->if_ops
.data_complete
)
246 adapter
->if_ops
.data_complete(adapter
, skb
);
248 dev_kfree_skb_any(skb
);
253 if (le16_to_cpu(uap_rx_pd
->rx_pkt_type
) == PKT_TYPE_AMSDU
) {
254 struct sk_buff_head list
;
255 struct sk_buff
*rx_skb
;
257 __skb_queue_head_init(&list
);
258 skb_pull(skb
, le16_to_cpu(uap_rx_pd
->rx_pkt_offset
));
259 skb_trim(skb
, le16_to_cpu(uap_rx_pd
->rx_pkt_length
));
261 ieee80211_amsdu_to_8023s(skb
, &list
, priv
->curr_addr
,
262 priv
->wdev
->iftype
, 0, false);
264 while (!skb_queue_empty(&list
)) {
265 rx_skb
= __skb_dequeue(&list
);
266 ret
= mwifiex_recv_packet(priv
, rx_skb
);
268 dev_err(adapter
->dev
,
269 "AP:Rx A-MSDU failed");
273 } else if (rx_pkt_type
== PKT_TYPE_MGMT
) {
274 ret
= mwifiex_process_mgmt_packet(priv
, skb
);
276 dev_err(adapter
->dev
, "Rx of mgmt packet failed");
277 dev_kfree_skb_any(skb
);
281 memcpy(ta
, rx_pkt_hdr
->eth803_hdr
.h_source
, ETH_ALEN
);
283 if (rx_pkt_type
!= PKT_TYPE_BAR
&& uap_rx_pd
->priority
< MAX_NUM_TID
) {
284 node
= mwifiex_get_sta_entry(priv
, ta
);
286 node
->rx_seq
[uap_rx_pd
->priority
] =
287 le16_to_cpu(uap_rx_pd
->seq_num
);
290 if (!priv
->ap_11n_enabled
||
291 (!mwifiex_11n_get_rx_reorder_tbl(priv
, uap_rx_pd
->priority
, ta
) &&
292 (le16_to_cpu(uap_rx_pd
->rx_pkt_type
) != PKT_TYPE_AMSDU
))) {
293 ret
= mwifiex_handle_uap_rx_forward(priv
, skb
);
297 /* Reorder and send to kernel */
298 pkt_type
= (u8
)le16_to_cpu(uap_rx_pd
->rx_pkt_type
);
299 ret
= mwifiex_11n_rx_reorder_pkt(priv
, le16_to_cpu(uap_rx_pd
->seq_num
),
300 uap_rx_pd
->priority
, ta
, pkt_type
,
303 if (ret
|| (rx_pkt_type
== PKT_TYPE_BAR
)) {
304 if (adapter
->if_ops
.data_complete
)
305 adapter
->if_ops
.data_complete(adapter
, skb
);
307 dev_kfree_skb_any(skb
);
311 priv
->stats
.rx_dropped
++;
317 * This function fills the TxPD for AP tx packets.
319 * The Tx buffer received by this function should already have the
320 * header space allocated for TxPD.
322 * This function inserts the TxPD in between interface header and actual
323 * data and adjusts the buffer pointers accordingly.
325 * The following TxPD fields are set by this function, as required -
327 * - Tx packet length and offset
330 * - Priority specific Tx control
333 void *mwifiex_process_uap_txpd(struct mwifiex_private
*priv
,
336 struct mwifiex_adapter
*adapter
= priv
->adapter
;
337 struct uap_txpd
*txpd
;
338 struct mwifiex_txinfo
*tx_info
= MWIFIEX_SKB_TXCB(skb
);
343 dev_err(adapter
->dev
, "Tx: bad packet length: %d\n", skb
->len
);
344 tx_info
->status_code
= -1;
348 pkt_type
= mwifiex_is_skb_mgmt_frame(skb
) ? PKT_TYPE_MGMT
: 0;
350 /* If skb->data is not aligned, add padding */
351 pad
= (4 - (((void *)skb
->data
- NULL
) & 0x3)) % 4;
353 len
= sizeof(*txpd
) + pad
;
355 BUG_ON(skb_headroom(skb
) < len
+ INTF_HEADER_LEN
);
359 txpd
= (struct uap_txpd
*)skb
->data
;
360 memset(txpd
, 0, sizeof(*txpd
));
361 txpd
->bss_num
= priv
->bss_num
;
362 txpd
->bss_type
= priv
->bss_type
;
363 txpd
->tx_pkt_length
= cpu_to_le16((u16
)(skb
->len
- len
));
365 txpd
->priority
= (u8
)skb
->priority
;
366 txpd
->pkt_delay_2ms
= mwifiex_wmm_compute_drv_pkt_delay(priv
, skb
);
368 if (txpd
->priority
< ARRAY_SIZE(priv
->wmm
.user_pri_pkt_tx_ctrl
))
370 * Set the priority specific tx_control field, setting of 0 will
371 * cause the default value to be used later in this function.
374 cpu_to_le32(priv
->wmm
.user_pri_pkt_tx_ctrl
[txpd
->priority
]);
376 /* Offset of actual data */
377 if (pkt_type
== PKT_TYPE_MGMT
) {
378 /* Set the packet type and add header for management frame */
379 txpd
->tx_pkt_type
= cpu_to_le16(pkt_type
);
380 len
+= MWIFIEX_MGMT_FRAME_HEADER_SIZE
;
383 txpd
->tx_pkt_offset
= cpu_to_le16(len
);
385 /* make space for INTF_HEADER_LEN */
386 skb_push(skb
, INTF_HEADER_LEN
);
388 if (!txpd
->tx_control
)
389 /* TxCtrl set by user or default */
390 txpd
->tx_control
= cpu_to_le32(priv
->pkt_tx_ctrl
);