blob: 61c52fdf945d42140c000e2c8a298f1f4d08dc60 [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,
34 struct list_head *ra_list_head)
35{
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;
41
42 list_for_each_entry(ra_list, ra_list_head, list) {
43 if (skb_queue_empty(&ra_list->skb_head))
44 continue;
45
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,
51 -1);
52 atomic_dec(&priv->wmm.tx_pkts_queued);
53 pkt_deleted = true;
54 }
55 if ((atomic_read(&adapter->pending_bridged_pkts) <=
56 MWIFIEX_BRIDGED_PKTS_THR_LOW))
57 break;
58 }
59 }
60
61 return pkt_deleted;
62}
63
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.
67 */
68static void mwifiex_uap_cleanup_tx_queues(struct mwifiex_private *priv)
69{
70 unsigned long flags;
71 struct list_head *ra_list;
72 int i;
73
74 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
75
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)) {
81 priv->del_list_idx++;
82 break;
83 }
84 }
85
86 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
87}
88
89
Avinash Patil838e4f42012-08-03 18:06:08 -070090static void mwifiex_uap_queue_bridged_pkt(struct mwifiex_private *priv,
91 struct sk_buff *skb)
92{
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;
98 int hdr_chop;
Ujjal Roy8d93f1f2013-11-05 15:01:45 -080099 struct ethhdr *p_ethhdr;
Avinash Patil838e4f42012-08-03 18:06:08 -0700100
101 uap_rx_pd = (struct uap_rxpd *)(skb->data);
102 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
103
104 if ((atomic_read(&adapter->pending_bridged_pkts) >=
Avinash Patil61c873042013-07-22 19:17:41 -0700105 MWIFIEX_BRIDGED_PKTS_THR_HIGH)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530106 mwifiex_dbg(priv->adapter, ERROR,
107 "Tx: Bridge packet limit reached. Drop packet!\n");
Avinash Patil838e4f42012-08-03 18:06:08 -0700108 kfree_skb(skb);
Avinash Patil61c873042013-07-22 19:17:41 -0700109 mwifiex_uap_cleanup_tx_queues(priv);
Avinash Patil838e4f42012-08-03 18:06:08 -0700110 return;
111 }
112
Amitkumar Karwarc613d162013-12-02 23:17:51 -0800113 if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
114 sizeof(bridge_tunnel_header))) ||
115 (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
116 sizeof(rfc1042_header)) &&
117 ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
118 ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) {
Ujjal Roy8d93f1f2013-11-05 15:01:45 -0800119 /* Replace the 803 header and rfc1042 header (llc/snap) with
120 * an Ethernet II header, keep the src/dst and snap_type
121 * (ethertype).
122 *
123 * The firmware only passes up SNAP frames converting all RX
124 * data from 802.11 to 802.2/LLC/SNAP frames.
125 *
126 * To create the Ethernet II, just move the src, dst address
127 * right before the snap_type.
128 */
129 p_ethhdr = (struct ethhdr *)
130 ((u8 *)(&rx_pkt_hdr->eth803_hdr)
131 + sizeof(rx_pkt_hdr->eth803_hdr)
132 + sizeof(rx_pkt_hdr->rfc1042_hdr)
133 - sizeof(rx_pkt_hdr->eth803_hdr.h_dest)
134 - sizeof(rx_pkt_hdr->eth803_hdr.h_source)
135 - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type));
136 memcpy(p_ethhdr->h_source, rx_pkt_hdr->eth803_hdr.h_source,
137 sizeof(p_ethhdr->h_source));
138 memcpy(p_ethhdr->h_dest, rx_pkt_hdr->eth803_hdr.h_dest,
139 sizeof(p_ethhdr->h_dest));
Avinash Patil838e4f42012-08-03 18:06:08 -0700140 /* Chop off the rxpd + the excess memory from
141 * 802.2/llc/snap header that was removed.
142 */
Ujjal Roy8d93f1f2013-11-05 15:01:45 -0800143 hdr_chop = (u8 *)p_ethhdr - (u8 *)uap_rx_pd;
144 } else {
Avinash Patil838e4f42012-08-03 18:06:08 -0700145 /* Chop off the rxpd */
146 hdr_chop = (u8 *)&rx_pkt_hdr->eth803_hdr - (u8 *)uap_rx_pd;
Ujjal Roy8d93f1f2013-11-05 15:01:45 -0800147 }
Avinash Patil838e4f42012-08-03 18:06:08 -0700148
Ujjal Royf7b59852013-12-02 23:17:56 -0800149 /* Chop off the leading header bytes so that it points
Avinash Patil838e4f42012-08-03 18:06:08 -0700150 * to the start of either the reconstructed EthII frame
151 * or the 802.2/llc/snap frame.
152 */
153 skb_pull(skb, hdr_chop);
154
155 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530156 mwifiex_dbg(priv->adapter, ERROR,
157 "data: Tx: insufficient skb headroom %d\n",
158 skb_headroom(skb));
Avinash Patil838e4f42012-08-03 18:06:08 -0700159 /* Insufficient skb headroom - allocate a new skb */
160 new_skb =
161 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
162 if (unlikely(!new_skb)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530163 mwifiex_dbg(priv->adapter, ERROR,
164 "Tx: cannot allocate new_skb\n");
Avinash Patil838e4f42012-08-03 18:06:08 -0700165 kfree_skb(skb);
166 priv->stats.tx_dropped++;
167 return;
168 }
169
170 kfree_skb(skb);
171 skb = new_skb;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530172 mwifiex_dbg(priv->adapter, INFO,
173 "info: new skb headroom %d\n",
174 skb_headroom(skb));
Avinash Patil838e4f42012-08-03 18:06:08 -0700175 }
176
177 tx_info = MWIFIEX_SKB_TXCB(skb);
Amitkumar Karwar701a9e62014-07-01 14:39:04 -0700178 memset(tx_info, 0, sizeof(*tx_info));
Avinash Patil838e4f42012-08-03 18:06:08 -0700179 tx_info->bss_num = priv->bss_num;
180 tx_info->bss_type = priv->bss_type;
181 tx_info->flags |= MWIFIEX_BUF_FLAG_BRIDGED_PKT;
182
Ujjal Royf7b59852013-12-02 23:17:56 -0800183 if (is_unicast_ether_addr(rx_pkt_hdr->eth803_hdr.h_dest)) {
184 /* Update bridge packet statistics as the
185 * packet is not going to kernel/upper layer.
186 */
187 priv->stats.rx_bytes += skb->len;
188 priv->stats.rx_packets++;
189
190 /* Sending bridge packet to TX queue, so save the packet
191 * length in TXCB to update statistics in TX complete.
192 */
193 tx_info->pkt_len = skb->len;
194 }
195
Thomas Gleixnerc64800e2014-06-12 08:31:34 +0100196 __net_timestamp(skb);
Avinash Patil838e4f42012-08-03 18:06:08 -0700197 mwifiex_wmm_add_buf_txqueue(priv, skb);
198 atomic_inc(&adapter->tx_pending);
199 atomic_inc(&adapter->pending_bridged_pkts);
200
Avinash Patil838e4f42012-08-03 18:06:08 -0700201 return;
202}
203
204/*
205 * This function contains logic for AP packet forwarding.
206 *
207 * If a packet is multicast/broadcast, it is sent to kernel/upper layer
208 * as well as queued back to AP TX queue so that it can be sent to other
209 * associated stations.
210 * If a packet is unicast and RA is present in associated station list,
211 * it is again requeued into AP TX queue.
212 * If a packet is unicast and RA is not in associated station list,
213 * packet is forwarded to kernel to handle routing logic.
214 */
215int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv,
216 struct sk_buff *skb)
217{
218 struct mwifiex_adapter *adapter = priv->adapter;
219 struct uap_rxpd *uap_rx_pd;
220 struct rx_packet_hdr *rx_pkt_hdr;
221 u8 ra[ETH_ALEN];
222 struct sk_buff *skb_uap;
223
224 uap_rx_pd = (struct uap_rxpd *)(skb->data);
225 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
226
227 /* don't do packet forwarding in disconnected state */
228 if (!priv->media_connected) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530229 mwifiex_dbg(adapter, ERROR,
230 "drop packet in disconnected state.\n");
Avinash Patil838e4f42012-08-03 18:06:08 -0700231 dev_kfree_skb_any(skb);
232 return 0;
233 }
234
235 memcpy(ra, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN);
236
237 if (is_multicast_ether_addr(ra)) {
238 skb_uap = skb_copy(skb, GFP_ATOMIC);
239 mwifiex_uap_queue_bridged_pkt(priv, skb_uap);
240 } else {
241 if (mwifiex_get_sta_entry(priv, ra)) {
242 /* Requeue Intra-BSS packet */
243 mwifiex_uap_queue_bridged_pkt(priv, skb);
244 return 0;
245 }
246 }
247
248 /* Forward unicat/Inter-BSS packets to kernel. */
Avinash Patilf3b369e2012-10-19 19:19:21 -0700249 return mwifiex_process_rx_packet(priv, skb);
Avinash Patil838e4f42012-08-03 18:06:08 -0700250}
251
252/*
253 * This function processes the packet received on AP interface.
254 *
255 * The function looks into the RxPD and performs sanity tests on the
256 * received buffer to ensure its a valid packet before processing it
257 * further. If the packet is determined to be aggregated, it is
258 * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic.
259 *
260 * The completion callback is called after processing is complete.
261 */
Avinash Patilf3b369e2012-10-19 19:19:21 -0700262int mwifiex_process_uap_rx_packet(struct mwifiex_private *priv,
Avinash Patil838e4f42012-08-03 18:06:08 -0700263 struct sk_buff *skb)
264{
Avinash Patilf3b369e2012-10-19 19:19:21 -0700265 struct mwifiex_adapter *adapter = priv->adapter;
Avinash Patil838e4f42012-08-03 18:06:08 -0700266 int ret;
267 struct uap_rxpd *uap_rx_pd;
Avinash Patil838e4f42012-08-03 18:06:08 -0700268 struct rx_packet_hdr *rx_pkt_hdr;
269 u16 rx_pkt_type;
Avinash Patild1cf3b92012-08-03 18:06:09 -0700270 u8 ta[ETH_ALEN], pkt_type;
Avinash Patilc11fb982014-12-05 23:23:41 +0530271 unsigned long flags;
Avinash Patild1cf3b92012-08-03 18:06:09 -0700272 struct mwifiex_sta_node *node;
273
Avinash Patil838e4f42012-08-03 18:06:08 -0700274 uap_rx_pd = (struct uap_rxpd *)(skb->data);
275 rx_pkt_type = le16_to_cpu(uap_rx_pd->rx_pkt_type);
276 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
277
278 if ((le16_to_cpu(uap_rx_pd->rx_pkt_offset) +
279 le16_to_cpu(uap_rx_pd->rx_pkt_length)) > (u16) skb->len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530280 mwifiex_dbg(adapter, ERROR,
281 "wrong rx packet: len=%d, offset=%d, length=%d\n",
282 skb->len, le16_to_cpu(uap_rx_pd->rx_pkt_offset),
283 le16_to_cpu(uap_rx_pd->rx_pkt_length));
Avinash Patil838e4f42012-08-03 18:06:08 -0700284 priv->stats.rx_dropped++;
Ujjal Royca8d6df2013-12-02 23:17:53 -0800285 dev_kfree_skb_any(skb);
Avinash Patil838e4f42012-08-03 18:06:08 -0700286 return 0;
287 }
Avinash Patil838e4f42012-08-03 18:06:08 -0700288
Amitkumar Karwar4c9f9fb2014-03-07 19:41:31 -0800289 if (rx_pkt_type == PKT_TYPE_MGMT) {
Avinash Patilf3b369e2012-10-19 19:19:21 -0700290 ret = mwifiex_process_mgmt_packet(priv, skb);
Stone Piao2dbaf752012-09-25 20:23:35 -0700291 if (ret)
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530292 mwifiex_dbg(adapter, ERROR,
293 "Rx of mgmt packet failed");
Stone Piao2dbaf752012-09-25 20:23:35 -0700294 dev_kfree_skb_any(skb);
295 return ret;
Avinash Patild1cf3b92012-08-03 18:06:09 -0700296 }
297
298 memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN);
299
300 if (rx_pkt_type != PKT_TYPE_BAR && uap_rx_pd->priority < MAX_NUM_TID) {
Avinash Patilc11fb982014-12-05 23:23:41 +0530301 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
Avinash Patild1cf3b92012-08-03 18:06:09 -0700302 node = mwifiex_get_sta_entry(priv, ta);
303 if (node)
304 node->rx_seq[uap_rx_pd->priority] =
305 le16_to_cpu(uap_rx_pd->seq_num);
Avinash Patilc11fb982014-12-05 23:23:41 +0530306 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
Avinash Patild1cf3b92012-08-03 18:06:09 -0700307 }
308
309 if (!priv->ap_11n_enabled ||
310 (!mwifiex_11n_get_rx_reorder_tbl(priv, uap_rx_pd->priority, ta) &&
311 (le16_to_cpu(uap_rx_pd->rx_pkt_type) != PKT_TYPE_AMSDU))) {
312 ret = mwifiex_handle_uap_rx_forward(priv, skb);
313 return ret;
314 }
315
316 /* Reorder and send to kernel */
317 pkt_type = (u8)le16_to_cpu(uap_rx_pd->rx_pkt_type);
318 ret = mwifiex_11n_rx_reorder_pkt(priv, le16_to_cpu(uap_rx_pd->seq_num),
319 uap_rx_pd->priority, ta, pkt_type,
320 skb);
321
Ujjal Royca8d6df2013-12-02 23:17:53 -0800322 if (ret || (rx_pkt_type == PKT_TYPE_BAR))
323 dev_kfree_skb_any(skb);
Avinash Patil838e4f42012-08-03 18:06:08 -0700324
Avinash Patild1cf3b92012-08-03 18:06:09 -0700325 if (ret)
326 priv->stats.rx_dropped++;
327
Avinash Patil838e4f42012-08-03 18:06:08 -0700328 return ret;
329}
Avinash Patil4ac87642012-09-10 18:30:49 -0700330
331/*
332 * This function fills the TxPD for AP tx packets.
333 *
334 * The Tx buffer received by this function should already have the
335 * header space allocated for TxPD.
336 *
337 * This function inserts the TxPD in between interface header and actual
338 * data and adjusts the buffer pointers accordingly.
339 *
340 * The following TxPD fields are set by this function, as required -
341 * - BSS number
342 * - Tx packet length and offset
343 * - Priority
344 * - Packet delay
345 * - Priority specific Tx control
346 * - Flags
347 */
348void *mwifiex_process_uap_txpd(struct mwifiex_private *priv,
349 struct sk_buff *skb)
350{
351 struct mwifiex_adapter *adapter = priv->adapter;
352 struct uap_txpd *txpd;
353 struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
Xinming Hu84b313b32014-12-26 03:02:33 -0800354 int pad;
355 u16 pkt_type, pkt_offset;
356 int hroom = (priv->adapter->iface_type == MWIFIEX_USB) ? 0 :
357 INTF_HEADER_LEN;
Avinash Patil4ac87642012-09-10 18:30:49 -0700358
359 if (!skb->len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530360 mwifiex_dbg(adapter, ERROR,
361 "Tx: bad packet length: %d\n", skb->len);
Avinash Patil4ac87642012-09-10 18:30:49 -0700362 tx_info->status_code = -1;
363 return skb->data;
364 }
365
Xinming Hu84b313b32014-12-26 03:02:33 -0800366 BUG_ON(skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN);
367
Stone Piao32152152012-09-25 20:23:44 -0700368 pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
369
Xinming Hu84b313b32014-12-26 03:02:33 -0800370 pad = ((void *)skb->data - (sizeof(*txpd) + hroom) - NULL) &
371 (MWIFIEX_DMA_ALIGN_SZ - 1);
Avinash Patil4ac87642012-09-10 18:30:49 -0700372
Xinming Hu84b313b32014-12-26 03:02:33 -0800373 skb_push(skb, sizeof(*txpd) + pad);
Avinash Patil4ac87642012-09-10 18:30:49 -0700374
375 txpd = (struct uap_txpd *)skb->data;
376 memset(txpd, 0, sizeof(*txpd));
377 txpd->bss_num = priv->bss_num;
378 txpd->bss_type = priv->bss_type;
Xinming Hu84b313b32014-12-26 03:02:33 -0800379 txpd->tx_pkt_length = cpu_to_le16((u16)(skb->len - (sizeof(*txpd) +
380 pad)));
Avinash Patil4ac87642012-09-10 18:30:49 -0700381 txpd->priority = (u8)skb->priority;
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800382
Avinash Patil4ac87642012-09-10 18:30:49 -0700383 txpd->pkt_delay_2ms = mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
384
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800385 if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS ||
386 tx_info->flags & MWIFIEX_BUF_FLAG_ACTION_TX_STATUS) {
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800387 txpd->tx_token_id = tx_info->ack_frame_id;
388 txpd->flags |= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS;
389 }
390
Avinash Patil4ac87642012-09-10 18:30:49 -0700391 if (txpd->priority < ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
392 /*
393 * Set the priority specific tx_control field, setting of 0 will
394 * cause the default value to be used later in this function.
395 */
396 txpd->tx_control =
397 cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[txpd->priority]);
398
399 /* Offset of actual data */
Xinming Hu84b313b32014-12-26 03:02:33 -0800400 pkt_offset = sizeof(*txpd) + pad;
Stone Piao32152152012-09-25 20:23:44 -0700401 if (pkt_type == PKT_TYPE_MGMT) {
402 /* Set the packet type and add header for management frame */
403 txpd->tx_pkt_type = cpu_to_le16(pkt_type);
Xinming Hu84b313b32014-12-26 03:02:33 -0800404 pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
Stone Piao32152152012-09-25 20:23:44 -0700405 }
406
Xinming Hu84b313b32014-12-26 03:02:33 -0800407 txpd->tx_pkt_offset = cpu_to_le16(pkt_offset);
Avinash Patil4ac87642012-09-10 18:30:49 -0700408
409 /* make space for INTF_HEADER_LEN */
Xinming Hu84b313b32014-12-26 03:02:33 -0800410 skb_push(skb, hroom);
Avinash Patil4ac87642012-09-10 18:30:49 -0700411
412 if (!txpd->tx_control)
413 /* TxCtrl set by user or default */
414 txpd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
415
416 return skb->data;
417}