blob: c95b61dc87c2a927c06506de0ea98ec34850d9db [file] [log] [blame]
Avinash Patil838e4f42012-08-03 18:06:08 -07001/*
2 * Marvell Wireless LAN device driver: AP TX and RX data handling
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2012-2014, Marvell International Ltd.
Avinash Patil838e4f42012-08-03 18:06:08 -07005 *
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
20#include "decl.h"
21#include "ioctl.h"
22#include "main.h"
23#include "wmm.h"
Avinash Patild1cf3b92012-08-03 18:06:09 -070024#include "11n_aggr.h"
25#include "11n_rxreorder.h"
Avinash Patil838e4f42012-08-03 18:06:08 -070026
Avinash Patil61c873042013-07-22 19:17:41 -070027/* 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.
31 */
32static bool
33mwifiex_uap_del_tx_pkts_in_ralist(struct mwifiex_private *priv,
Zhaoyang Liu70c5ad72015-09-18 06:32:11 -070034 struct list_head *ra_list_head,
35 int tid)
Avinash Patil61c873042013-07-22 19:17:41 -070036{
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;
42
43 list_for_each_entry(ra_list, ra_list_head, list) {
44 if (skb_queue_empty(&ra_list->skb_head))
45 continue;
46
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,
52 -1);
Zhaoyang Liu70c5ad72015-09-18 06:32:11 -070053 if (ra_list->tx_paused)
54 priv->wmm.pkts_paused[tid]--;
55 else
56 atomic_dec(&priv->wmm.tx_pkts_queued);
Avinash Patil61c873042013-07-22 19:17:41 -070057 pkt_deleted = true;
58 }
59 if ((atomic_read(&adapter->pending_bridged_pkts) <=
60 MWIFIEX_BRIDGED_PKTS_THR_LOW))
61 break;
62 }
63 }
64
65 return pkt_deleted;
66}
67
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.
71 */
72static void mwifiex_uap_cleanup_tx_queues(struct mwifiex_private *priv)
73{
74 unsigned long flags;
75 struct list_head *ra_list;
76 int i;
77
78 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
79
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;
Zhaoyang Liu70c5ad72015-09-18 06:32:11 -070084 if (mwifiex_uap_del_tx_pkts_in_ralist(priv, ra_list, i)) {
Avinash Patil61c873042013-07-22 19:17:41 -070085 priv->del_list_idx++;
86 break;
87 }
88 }
89
90 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
91}
92
93
Avinash Patil838e4f42012-08-03 18:06:08 -070094static void mwifiex_uap_queue_bridged_pkt(struct mwifiex_private *priv,
95 struct sk_buff *skb)
96{
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;
102 int hdr_chop;
Ujjal Roy8d93f1f2013-11-05 15:01:45 -0800103 struct ethhdr *p_ethhdr;
Xinming Hu442f6f92015-06-03 16:59:38 +0530104 struct mwifiex_sta_node *src_node;
Avinash Patil838e4f42012-08-03 18:06:08 -0700105
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);
108
109 if ((atomic_read(&adapter->pending_bridged_pkts) >=
Avinash Patil61c873042013-07-22 19:17:41 -0700110 MWIFIEX_BRIDGED_PKTS_THR_HIGH)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530111 mwifiex_dbg(priv->adapter, ERROR,
112 "Tx: Bridge packet limit reached. Drop packet!\n");
Avinash Patil838e4f42012-08-03 18:06:08 -0700113 kfree_skb(skb);
Avinash Patil61c873042013-07-22 19:17:41 -0700114 mwifiex_uap_cleanup_tx_queues(priv);
Avinash Patil838e4f42012-08-03 18:06:08 -0700115 return;
116 }
117
Amitkumar Karwarc613d162013-12-02 23:17:51 -0800118 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)) {
Ujjal Roy8d93f1f2013-11-05 15:01:45 -0800124 /* Replace the 803 header and rfc1042 header (llc/snap) with
125 * an Ethernet II header, keep the src/dst and snap_type
126 * (ethertype).
127 *
128 * The firmware only passes up SNAP frames converting all RX
129 * data from 802.11 to 802.2/LLC/SNAP frames.
130 *
131 * To create the Ethernet II, just move the src, dst address
132 * right before the snap_type.
133 */
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));
Avinash Patil838e4f42012-08-03 18:06:08 -0700145 /* Chop off the rxpd + the excess memory from
146 * 802.2/llc/snap header that was removed.
147 */
Ujjal Roy8d93f1f2013-11-05 15:01:45 -0800148 hdr_chop = (u8 *)p_ethhdr - (u8 *)uap_rx_pd;
149 } else {
Avinash Patil838e4f42012-08-03 18:06:08 -0700150 /* Chop off the rxpd */
151 hdr_chop = (u8 *)&rx_pkt_hdr->eth803_hdr - (u8 *)uap_rx_pd;
Ujjal Roy8d93f1f2013-11-05 15:01:45 -0800152 }
Avinash Patil838e4f42012-08-03 18:06:08 -0700153
Ujjal Royf7b59852013-12-02 23:17:56 -0800154 /* Chop off the leading header bytes so that it points
Avinash Patil838e4f42012-08-03 18:06:08 -0700155 * to the start of either the reconstructed EthII frame
156 * or the 802.2/llc/snap frame.
157 */
158 skb_pull(skb, hdr_chop);
159
160 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530161 mwifiex_dbg(priv->adapter, ERROR,
162 "data: Tx: insufficient skb headroom %d\n",
163 skb_headroom(skb));
Avinash Patil838e4f42012-08-03 18:06:08 -0700164 /* Insufficient skb headroom - allocate a new skb */
165 new_skb =
166 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
167 if (unlikely(!new_skb)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530168 mwifiex_dbg(priv->adapter, ERROR,
169 "Tx: cannot allocate new_skb\n");
Avinash Patil838e4f42012-08-03 18:06:08 -0700170 kfree_skb(skb);
171 priv->stats.tx_dropped++;
172 return;
173 }
174
175 kfree_skb(skb);
176 skb = new_skb;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530177 mwifiex_dbg(priv->adapter, INFO,
178 "info: new skb headroom %d\n",
179 skb_headroom(skb));
Avinash Patil838e4f42012-08-03 18:06:08 -0700180 }
181
182 tx_info = MWIFIEX_SKB_TXCB(skb);
Amitkumar Karwar701a9e62014-07-01 14:39:04 -0700183 memset(tx_info, 0, sizeof(*tx_info));
Avinash Patil838e4f42012-08-03 18:06:08 -0700184 tx_info->bss_num = priv->bss_num;
185 tx_info->bss_type = priv->bss_type;
186 tx_info->flags |= MWIFIEX_BUF_FLAG_BRIDGED_PKT;
187
Xinming Hu442f6f92015-06-03 16:59:38 +0530188 src_node = mwifiex_get_sta_entry(priv, rx_pkt_hdr->eth803_hdr.h_source);
189 if (src_node) {
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;
195 }
196
Ujjal Royf7b59852013-12-02 23:17:56 -0800197 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.
200 */
201 priv->stats.rx_bytes += skb->len;
202 priv->stats.rx_packets++;
203
204 /* Sending bridge packet to TX queue, so save the packet
205 * length in TXCB to update statistics in TX complete.
206 */
207 tx_info->pkt_len = skb->len;
208 }
209
Thomas Gleixnerc64800e2014-06-12 08:31:34 +0100210 __net_timestamp(skb);
Avinash Patil838e4f42012-08-03 18:06:08 -0700211 mwifiex_wmm_add_buf_txqueue(priv, skb);
212 atomic_inc(&adapter->tx_pending);
213 atomic_inc(&adapter->pending_bridged_pkts);
214
Xinming Huad5ca842016-04-05 01:04:38 -0700215 mwifiex_queue_main_work(priv->adapter);
216
Avinash Patil838e4f42012-08-03 18:06:08 -0700217 return;
218}
219
220/*
221 * This function contains logic for AP packet forwarding.
222 *
223 * If a packet is multicast/broadcast, it is sent to kernel/upper layer
224 * as well as queued back to AP TX queue so that it can be sent to other
225 * associated stations.
226 * If a packet is unicast and RA is present in associated station list,
227 * it is again requeued into AP TX queue.
228 * If a packet is unicast and RA is not in associated station list,
229 * packet is forwarded to kernel to handle routing logic.
230 */
231int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv,
232 struct sk_buff *skb)
233{
234 struct mwifiex_adapter *adapter = priv->adapter;
235 struct uap_rxpd *uap_rx_pd;
236 struct rx_packet_hdr *rx_pkt_hdr;
237 u8 ra[ETH_ALEN];
238 struct sk_buff *skb_uap;
239
240 uap_rx_pd = (struct uap_rxpd *)(skb->data);
241 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
242
243 /* don't do packet forwarding in disconnected state */
244 if (!priv->media_connected) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530245 mwifiex_dbg(adapter, ERROR,
246 "drop packet in disconnected state.\n");
Avinash Patil838e4f42012-08-03 18:06:08 -0700247 dev_kfree_skb_any(skb);
248 return 0;
249 }
250
251 memcpy(ra, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN);
252
253 if (is_multicast_ether_addr(ra)) {
254 skb_uap = skb_copy(skb, GFP_ATOMIC);
255 mwifiex_uap_queue_bridged_pkt(priv, skb_uap);
256 } else {
257 if (mwifiex_get_sta_entry(priv, ra)) {
258 /* Requeue Intra-BSS packet */
259 mwifiex_uap_queue_bridged_pkt(priv, skb);
260 return 0;
261 }
262 }
263
264 /* Forward unicat/Inter-BSS packets to kernel. */
Avinash Patilf3b369e2012-10-19 19:19:21 -0700265 return mwifiex_process_rx_packet(priv, skb);
Avinash Patil838e4f42012-08-03 18:06:08 -0700266}
267
Xinming Hubf00dc22016-04-05 01:04:39 -0700268int mwifiex_uap_recv_packet(struct mwifiex_private *priv,
269 struct sk_buff *skb)
270{
271 struct mwifiex_adapter *adapter = adapter;
272 struct mwifiex_sta_node *src_node;
273 struct ethhdr *p_ethhdr;
274 struct sk_buff *skb_uap;
275 struct mwifiex_txinfo *tx_info;
276
277 if (!skb)
278 return -1;
279
280 p_ethhdr = (void *)skb->data;
281 src_node = mwifiex_get_sta_entry(priv, p_ethhdr->h_source);
282 if (src_node) {
283 src_node->stats.last_rx = jiffies;
284 src_node->stats.rx_bytes += skb->len;
285 src_node->stats.rx_packets++;
286 }
287
288 skb->dev = priv->netdev;
289 skb->protocol = eth_type_trans(skb, priv->netdev);
290 skb->ip_summed = CHECKSUM_NONE;
291
292 /* This is required only in case of 11n and USB/PCIE as we alloc
293 * a buffer of 4K only if its 11N (to be able to receive 4K
294 * AMSDU packets). In case of SD we allocate buffers based
295 * on the size of packet and hence this is not needed.
296 *
297 * Modifying the truesize here as our allocation for each
298 * skb is 4K but we only receive 2K packets and this cause
299 * the kernel to start dropping packets in case where
300 * application has allocated buffer based on 2K size i.e.
301 * if there a 64K packet received (in IP fragments and
302 * application allocates 64K to receive this packet but
303 * this packet would almost double up because we allocate
304 * each 1.5K fragment in 4K and pass it up. As soon as the
305 * 64K limit hits kernel will start to drop rest of the
306 * fragments. Currently we fail the Filesndl-ht.scr script
307 * for UDP, hence this fix
308 */
309 if ((adapter->iface_type == MWIFIEX_USB ||
310 adapter->iface_type == MWIFIEX_PCIE) &&
311 (skb->truesize > MWIFIEX_RX_DATA_BUF_SIZE))
312 skb->truesize += (skb->len - MWIFIEX_RX_DATA_BUF_SIZE);
313
314 if (is_multicast_ether_addr(p_ethhdr->h_dest) ||
315 mwifiex_get_sta_entry(priv, p_ethhdr->h_dest)) {
316 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN)
317 skb_uap =
318 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
319 else
320 skb_uap = skb_copy(skb, GFP_ATOMIC);
321
322 if (likely(skb_uap)) {
323 tx_info = MWIFIEX_SKB_TXCB(skb_uap);
324 memset(tx_info, 0, sizeof(*tx_info));
325 tx_info->bss_num = priv->bss_num;
326 tx_info->bss_type = priv->bss_type;
327 tx_info->flags |= MWIFIEX_BUF_FLAG_BRIDGED_PKT;
328 __net_timestamp(skb_uap);
329 mwifiex_wmm_add_buf_txqueue(priv, skb_uap);
330 atomic_inc(&adapter->tx_pending);
331 atomic_inc(&adapter->pending_bridged_pkts);
332 if ((atomic_read(&adapter->pending_bridged_pkts) >=
333 MWIFIEX_BRIDGED_PKTS_THR_HIGH)) {
334 mwifiex_dbg(adapter, ERROR,
335 "Tx: Bridge packet limit reached. Drop packet!\n");
336 mwifiex_uap_cleanup_tx_queues(priv);
337 }
338
339 } else {
340 mwifiex_dbg(adapter, ERROR, "failed to allocate skb_uap");
341 }
342
343 mwifiex_queue_main_work(adapter);
344 /* Don't forward Intra-BSS unicast packet to upper layer*/
345 if (mwifiex_get_sta_entry(priv, p_ethhdr->h_dest))
346 return 0;
347 }
348
349 /* Forward multicast/broadcast packet to upper layer*/
350 if (in_interrupt())
351 netif_rx(skb);
352 else
353 netif_rx_ni(skb);
354
355 return 0;
356}
357
Avinash Patil838e4f42012-08-03 18:06:08 -0700358/*
359 * This function processes the packet received on AP interface.
360 *
361 * The function looks into the RxPD and performs sanity tests on the
362 * received buffer to ensure its a valid packet before processing it
363 * further. If the packet is determined to be aggregated, it is
364 * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic.
365 *
366 * The completion callback is called after processing is complete.
367 */
Avinash Patilf3b369e2012-10-19 19:19:21 -0700368int mwifiex_process_uap_rx_packet(struct mwifiex_private *priv,
Avinash Patil838e4f42012-08-03 18:06:08 -0700369 struct sk_buff *skb)
370{
Avinash Patilf3b369e2012-10-19 19:19:21 -0700371 struct mwifiex_adapter *adapter = priv->adapter;
Avinash Patil838e4f42012-08-03 18:06:08 -0700372 int ret;
373 struct uap_rxpd *uap_rx_pd;
Avinash Patil838e4f42012-08-03 18:06:08 -0700374 struct rx_packet_hdr *rx_pkt_hdr;
375 u16 rx_pkt_type;
Avinash Patild1cf3b92012-08-03 18:06:09 -0700376 u8 ta[ETH_ALEN], pkt_type;
Avinash Patilc11fb982014-12-05 23:23:41 +0530377 unsigned long flags;
Avinash Patild1cf3b92012-08-03 18:06:09 -0700378 struct mwifiex_sta_node *node;
379
Avinash Patil838e4f42012-08-03 18:06:08 -0700380 uap_rx_pd = (struct uap_rxpd *)(skb->data);
381 rx_pkt_type = le16_to_cpu(uap_rx_pd->rx_pkt_type);
382 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
383
Xinming Hu442f6f92015-06-03 16:59:38 +0530384 ether_addr_copy(ta, rx_pkt_hdr->eth803_hdr.h_source);
385
Avinash Patil838e4f42012-08-03 18:06:08 -0700386 if ((le16_to_cpu(uap_rx_pd->rx_pkt_offset) +
387 le16_to_cpu(uap_rx_pd->rx_pkt_length)) > (u16) skb->len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530388 mwifiex_dbg(adapter, ERROR,
389 "wrong rx packet: len=%d, offset=%d, length=%d\n",
390 skb->len, le16_to_cpu(uap_rx_pd->rx_pkt_offset),
391 le16_to_cpu(uap_rx_pd->rx_pkt_length));
Avinash Patil838e4f42012-08-03 18:06:08 -0700392 priv->stats.rx_dropped++;
Xinming Hu442f6f92015-06-03 16:59:38 +0530393
394 node = mwifiex_get_sta_entry(priv, ta);
395 if (node)
396 node->stats.tx_failed++;
397
Ujjal Royca8d6df2013-12-02 23:17:53 -0800398 dev_kfree_skb_any(skb);
Avinash Patil838e4f42012-08-03 18:06:08 -0700399 return 0;
400 }
Avinash Patil838e4f42012-08-03 18:06:08 -0700401
Amitkumar Karwar4c9f9fb2014-03-07 19:41:31 -0800402 if (rx_pkt_type == PKT_TYPE_MGMT) {
Avinash Patilf3b369e2012-10-19 19:19:21 -0700403 ret = mwifiex_process_mgmt_packet(priv, skb);
Stone Piao2dbaf752012-09-25 20:23:35 -0700404 if (ret)
Amitkumar Karwarbd642ac2015-12-14 04:15:08 -0800405 mwifiex_dbg(adapter, DATA, "Rx of mgmt packet failed");
Stone Piao2dbaf752012-09-25 20:23:35 -0700406 dev_kfree_skb_any(skb);
407 return ret;
Avinash Patild1cf3b92012-08-03 18:06:09 -0700408 }
409
Avinash Patild1cf3b92012-08-03 18:06:09 -0700410
411 if (rx_pkt_type != PKT_TYPE_BAR && uap_rx_pd->priority < MAX_NUM_TID) {
Avinash Patilc11fb982014-12-05 23:23:41 +0530412 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
Avinash Patild1cf3b92012-08-03 18:06:09 -0700413 node = mwifiex_get_sta_entry(priv, ta);
414 if (node)
415 node->rx_seq[uap_rx_pd->priority] =
416 le16_to_cpu(uap_rx_pd->seq_num);
Avinash Patilc11fb982014-12-05 23:23:41 +0530417 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
Avinash Patild1cf3b92012-08-03 18:06:09 -0700418 }
419
420 if (!priv->ap_11n_enabled ||
421 (!mwifiex_11n_get_rx_reorder_tbl(priv, uap_rx_pd->priority, ta) &&
422 (le16_to_cpu(uap_rx_pd->rx_pkt_type) != PKT_TYPE_AMSDU))) {
423 ret = mwifiex_handle_uap_rx_forward(priv, skb);
424 return ret;
425 }
426
427 /* Reorder and send to kernel */
428 pkt_type = (u8)le16_to_cpu(uap_rx_pd->rx_pkt_type);
429 ret = mwifiex_11n_rx_reorder_pkt(priv, le16_to_cpu(uap_rx_pd->seq_num),
430 uap_rx_pd->priority, ta, pkt_type,
431 skb);
432
Ujjal Royca8d6df2013-12-02 23:17:53 -0800433 if (ret || (rx_pkt_type == PKT_TYPE_BAR))
434 dev_kfree_skb_any(skb);
Avinash Patil838e4f42012-08-03 18:06:08 -0700435
Avinash Patild1cf3b92012-08-03 18:06:09 -0700436 if (ret)
437 priv->stats.rx_dropped++;
438
Avinash Patil838e4f42012-08-03 18:06:08 -0700439 return ret;
440}
Avinash Patil4ac87642012-09-10 18:30:49 -0700441
442/*
443 * This function fills the TxPD for AP tx packets.
444 *
445 * The Tx buffer received by this function should already have the
446 * header space allocated for TxPD.
447 *
448 * This function inserts the TxPD in between interface header and actual
449 * data and adjusts the buffer pointers accordingly.
450 *
451 * The following TxPD fields are set by this function, as required -
452 * - BSS number
453 * - Tx packet length and offset
454 * - Priority
455 * - Packet delay
456 * - Priority specific Tx control
457 * - Flags
458 */
459void *mwifiex_process_uap_txpd(struct mwifiex_private *priv,
460 struct sk_buff *skb)
461{
462 struct mwifiex_adapter *adapter = priv->adapter;
463 struct uap_txpd *txpd;
464 struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
Xinming Hu84b313b32014-12-26 03:02:33 -0800465 int pad;
466 u16 pkt_type, pkt_offset;
467 int hroom = (priv->adapter->iface_type == MWIFIEX_USB) ? 0 :
468 INTF_HEADER_LEN;
Avinash Patil4ac87642012-09-10 18:30:49 -0700469
470 if (!skb->len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530471 mwifiex_dbg(adapter, ERROR,
472 "Tx: bad packet length: %d\n", skb->len);
Avinash Patil4ac87642012-09-10 18:30:49 -0700473 tx_info->status_code = -1;
474 return skb->data;
475 }
476
Xinming Hu84b313b32014-12-26 03:02:33 -0800477 BUG_ON(skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN);
478
Stone Piao32152152012-09-25 20:23:44 -0700479 pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
480
Xinming Hu84b313b32014-12-26 03:02:33 -0800481 pad = ((void *)skb->data - (sizeof(*txpd) + hroom) - NULL) &
482 (MWIFIEX_DMA_ALIGN_SZ - 1);
Avinash Patil4ac87642012-09-10 18:30:49 -0700483
Xinming Hu84b313b32014-12-26 03:02:33 -0800484 skb_push(skb, sizeof(*txpd) + pad);
Avinash Patil4ac87642012-09-10 18:30:49 -0700485
486 txpd = (struct uap_txpd *)skb->data;
487 memset(txpd, 0, sizeof(*txpd));
488 txpd->bss_num = priv->bss_num;
489 txpd->bss_type = priv->bss_type;
Xinming Hu84b313b32014-12-26 03:02:33 -0800490 txpd->tx_pkt_length = cpu_to_le16((u16)(skb->len - (sizeof(*txpd) +
491 pad)));
Avinash Patil4ac87642012-09-10 18:30:49 -0700492 txpd->priority = (u8)skb->priority;
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800493
Avinash Patil4ac87642012-09-10 18:30:49 -0700494 txpd->pkt_delay_2ms = mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
495
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800496 if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS ||
497 tx_info->flags & MWIFIEX_BUF_FLAG_ACTION_TX_STATUS) {
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800498 txpd->tx_token_id = tx_info->ack_frame_id;
499 txpd->flags |= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS;
500 }
501
Avinash Patil4ac87642012-09-10 18:30:49 -0700502 if (txpd->priority < ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
503 /*
504 * Set the priority specific tx_control field, setting of 0 will
505 * cause the default value to be used later in this function.
506 */
507 txpd->tx_control =
508 cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[txpd->priority]);
509
510 /* Offset of actual data */
Xinming Hu84b313b32014-12-26 03:02:33 -0800511 pkt_offset = sizeof(*txpd) + pad;
Stone Piao32152152012-09-25 20:23:44 -0700512 if (pkt_type == PKT_TYPE_MGMT) {
513 /* Set the packet type and add header for management frame */
514 txpd->tx_pkt_type = cpu_to_le16(pkt_type);
Xinming Hu84b313b32014-12-26 03:02:33 -0800515 pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
Stone Piao32152152012-09-25 20:23:44 -0700516 }
517
Xinming Hu84b313b32014-12-26 03:02:33 -0800518 txpd->tx_pkt_offset = cpu_to_le16(pkt_offset);
Avinash Patil4ac87642012-09-10 18:30:49 -0700519
520 /* make space for INTF_HEADER_LEN */
Xinming Hu84b313b32014-12-26 03:02:33 -0800521 skb_push(skb, hroom);
Avinash Patil4ac87642012-09-10 18:30:49 -0700522
523 if (!txpd->tx_control)
524 /* TxCtrl set by user or default */
525 txpd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
526
527 return skb->data;
528}