mwifiex: add hscfg to debugfs
[deliverable/linux.git] / drivers / net / wireless / mwifiex / uap_txrx.c
CommitLineData
838e4f44
AP
1/*
2 * Marvell Wireless LAN device driver: AP TX and RX data handling
3 *
4 * Copyright (C) 2012, Marvell International Ltd.
5 *
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"
d1cf3b95
AP
24#include "11n_aggr.h"
25#include "11n_rxreorder.h"
838e4f44 26
61c87304
AP
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.
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
838e4f44
AP
90static 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;
8d93f1f3 99 struct ethhdr *p_ethhdr;
838e4f44
AP
100
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) >=
61c87304 105 MWIFIEX_BRIDGED_PKTS_THR_HIGH)) {
838e4f44
AP
106 dev_err(priv->adapter->dev,
107 "Tx: Bridge packet limit reached. Drop packet!\n");
108 kfree_skb(skb);
61c87304 109 mwifiex_uap_cleanup_tx_queues(priv);
838e4f44
AP
110 return;
111 }
112
c613d16f
AK
113 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)) {
8d93f1f3
UR
119 /* 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));
838e4f44
AP
140 /* Chop off the rxpd + the excess memory from
141 * 802.2/llc/snap header that was removed.
142 */
8d93f1f3
UR
143 hdr_chop = (u8 *)p_ethhdr - (u8 *)uap_rx_pd;
144 } else {
838e4f44
AP
145 /* Chop off the rxpd */
146 hdr_chop = (u8 *)&rx_pkt_hdr->eth803_hdr - (u8 *)uap_rx_pd;
8d93f1f3 147 }
838e4f44 148
f7b59853 149 /* Chop off the leading header bytes so that it points
838e4f44
AP
150 * 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) {
156 dev_dbg(priv->adapter->dev,
157 "data: Tx: insufficient skb headroom %d\n",
158 skb_headroom(skb));
159 /* 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)) {
163 dev_err(priv->adapter->dev,
164 "Tx: cannot allocate new_skb\n");
165 kfree_skb(skb);
166 priv->stats.tx_dropped++;
167 return;
168 }
169
170 kfree_skb(skb);
171 skb = new_skb;
172 dev_dbg(priv->adapter->dev, "info: new skb headroom %d\n",
173 skb_headroom(skb));
174 }
175
176 tx_info = MWIFIEX_SKB_TXCB(skb);
177 tx_info->bss_num = priv->bss_num;
178 tx_info->bss_type = priv->bss_type;
179 tx_info->flags |= MWIFIEX_BUF_FLAG_BRIDGED_PKT;
180
f7b59853
UR
181 if (is_unicast_ether_addr(rx_pkt_hdr->eth803_hdr.h_dest)) {
182 /* Update bridge packet statistics as the
183 * packet is not going to kernel/upper layer.
184 */
185 priv->stats.rx_bytes += skb->len;
186 priv->stats.rx_packets++;
187
188 /* Sending bridge packet to TX queue, so save the packet
189 * length in TXCB to update statistics in TX complete.
190 */
191 tx_info->pkt_len = skb->len;
192 }
193
6451acdc 194 __net_timestamp(skb);
838e4f44
AP
195 mwifiex_wmm_add_buf_txqueue(priv, skb);
196 atomic_inc(&adapter->tx_pending);
197 atomic_inc(&adapter->pending_bridged_pkts);
198
838e4f44
AP
199 return;
200}
201
202/*
203 * This function contains logic for AP packet forwarding.
204 *
205 * If a packet is multicast/broadcast, it is sent to kernel/upper layer
206 * as well as queued back to AP TX queue so that it can be sent to other
207 * associated stations.
208 * If a packet is unicast and RA is present in associated station list,
209 * it is again requeued into AP TX queue.
210 * If a packet is unicast and RA is not in associated station list,
211 * packet is forwarded to kernel to handle routing logic.
212 */
213int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv,
214 struct sk_buff *skb)
215{
216 struct mwifiex_adapter *adapter = priv->adapter;
217 struct uap_rxpd *uap_rx_pd;
218 struct rx_packet_hdr *rx_pkt_hdr;
219 u8 ra[ETH_ALEN];
220 struct sk_buff *skb_uap;
221
222 uap_rx_pd = (struct uap_rxpd *)(skb->data);
223 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
224
225 /* don't do packet forwarding in disconnected state */
226 if (!priv->media_connected) {
227 dev_err(adapter->dev, "drop packet in disconnected state.\n");
228 dev_kfree_skb_any(skb);
229 return 0;
230 }
231
232 memcpy(ra, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN);
233
234 if (is_multicast_ether_addr(ra)) {
235 skb_uap = skb_copy(skb, GFP_ATOMIC);
236 mwifiex_uap_queue_bridged_pkt(priv, skb_uap);
237 } else {
238 if (mwifiex_get_sta_entry(priv, ra)) {
239 /* Requeue Intra-BSS packet */
240 mwifiex_uap_queue_bridged_pkt(priv, skb);
241 return 0;
242 }
243 }
244
245 /* Forward unicat/Inter-BSS packets to kernel. */
f3b369e4 246 return mwifiex_process_rx_packet(priv, skb);
838e4f44
AP
247}
248
249/*
250 * This function processes the packet received on AP interface.
251 *
252 * The function looks into the RxPD and performs sanity tests on the
253 * received buffer to ensure its a valid packet before processing it
254 * further. If the packet is determined to be aggregated, it is
255 * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic.
256 *
257 * The completion callback is called after processing is complete.
258 */
f3b369e4 259int mwifiex_process_uap_rx_packet(struct mwifiex_private *priv,
838e4f44
AP
260 struct sk_buff *skb)
261{
f3b369e4 262 struct mwifiex_adapter *adapter = priv->adapter;
838e4f44
AP
263 int ret;
264 struct uap_rxpd *uap_rx_pd;
838e4f44
AP
265 struct rx_packet_hdr *rx_pkt_hdr;
266 u16 rx_pkt_type;
d1cf3b95
AP
267 u8 ta[ETH_ALEN], pkt_type;
268 struct mwifiex_sta_node *node;
269
838e4f44
AP
270 uap_rx_pd = (struct uap_rxpd *)(skb->data);
271 rx_pkt_type = le16_to_cpu(uap_rx_pd->rx_pkt_type);
272 rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset);
273
274 if ((le16_to_cpu(uap_rx_pd->rx_pkt_offset) +
275 le16_to_cpu(uap_rx_pd->rx_pkt_length)) > (u16) skb->len) {
276 dev_err(adapter->dev,
277 "wrong rx packet: len=%d, offset=%d, length=%d\n",
278 skb->len, le16_to_cpu(uap_rx_pd->rx_pkt_offset),
279 le16_to_cpu(uap_rx_pd->rx_pkt_length));
280 priv->stats.rx_dropped++;
ca8d6dfc 281 dev_kfree_skb_any(skb);
838e4f44
AP
282 return 0;
283 }
838e4f44 284
4c9f9fb2 285 if (rx_pkt_type == PKT_TYPE_MGMT) {
f3b369e4 286 ret = mwifiex_process_mgmt_packet(priv, skb);
2dbaf751
SP
287 if (ret)
288 dev_err(adapter->dev, "Rx of mgmt packet failed");
289 dev_kfree_skb_any(skb);
290 return ret;
d1cf3b95
AP
291 }
292
293 memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN);
294
295 if (rx_pkt_type != PKT_TYPE_BAR && uap_rx_pd->priority < MAX_NUM_TID) {
296 node = mwifiex_get_sta_entry(priv, ta);
297 if (node)
298 node->rx_seq[uap_rx_pd->priority] =
299 le16_to_cpu(uap_rx_pd->seq_num);
300 }
301
302 if (!priv->ap_11n_enabled ||
303 (!mwifiex_11n_get_rx_reorder_tbl(priv, uap_rx_pd->priority, ta) &&
304 (le16_to_cpu(uap_rx_pd->rx_pkt_type) != PKT_TYPE_AMSDU))) {
305 ret = mwifiex_handle_uap_rx_forward(priv, skb);
306 return ret;
307 }
308
309 /* Reorder and send to kernel */
310 pkt_type = (u8)le16_to_cpu(uap_rx_pd->rx_pkt_type);
311 ret = mwifiex_11n_rx_reorder_pkt(priv, le16_to_cpu(uap_rx_pd->seq_num),
312 uap_rx_pd->priority, ta, pkt_type,
313 skb);
314
ca8d6dfc
UR
315 if (ret || (rx_pkt_type == PKT_TYPE_BAR))
316 dev_kfree_skb_any(skb);
838e4f44 317
d1cf3b95
AP
318 if (ret)
319 priv->stats.rx_dropped++;
320
838e4f44
AP
321 return ret;
322}
4ac8764a
AP
323
324/*
325 * This function fills the TxPD for AP tx packets.
326 *
327 * The Tx buffer received by this function should already have the
328 * header space allocated for TxPD.
329 *
330 * This function inserts the TxPD in between interface header and actual
331 * data and adjusts the buffer pointers accordingly.
332 *
333 * The following TxPD fields are set by this function, as required -
334 * - BSS number
335 * - Tx packet length and offset
336 * - Priority
337 * - Packet delay
338 * - Priority specific Tx control
339 * - Flags
340 */
341void *mwifiex_process_uap_txpd(struct mwifiex_private *priv,
342 struct sk_buff *skb)
343{
344 struct mwifiex_adapter *adapter = priv->adapter;
345 struct uap_txpd *txpd;
346 struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
347 int pad, len;
3215215a 348 u16 pkt_type;
4ac8764a
AP
349
350 if (!skb->len) {
351 dev_err(adapter->dev, "Tx: bad packet length: %d\n", skb->len);
352 tx_info->status_code = -1;
353 return skb->data;
354 }
355
3215215a
SP
356 pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
357
4ac8764a
AP
358 /* If skb->data is not aligned, add padding */
359 pad = (4 - (((void *)skb->data - NULL) & 0x3)) % 4;
360
361 len = sizeof(*txpd) + pad;
362
363 BUG_ON(skb_headroom(skb) < len + INTF_HEADER_LEN);
364
365 skb_push(skb, len);
366
367 txpd = (struct uap_txpd *)skb->data;
368 memset(txpd, 0, sizeof(*txpd));
369 txpd->bss_num = priv->bss_num;
370 txpd->bss_type = priv->bss_type;
371 txpd->tx_pkt_length = cpu_to_le16((u16)(skb->len - len));
372
373 txpd->priority = (u8)skb->priority;
374 txpd->pkt_delay_2ms = mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
375
376 if (txpd->priority < ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
377 /*
378 * Set the priority specific tx_control field, setting of 0 will
379 * cause the default value to be used later in this function.
380 */
381 txpd->tx_control =
382 cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[txpd->priority]);
383
384 /* Offset of actual data */
3215215a
SP
385 if (pkt_type == PKT_TYPE_MGMT) {
386 /* Set the packet type and add header for management frame */
387 txpd->tx_pkt_type = cpu_to_le16(pkt_type);
388 len += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
389 }
390
4ac8764a
AP
391 txpd->tx_pkt_offset = cpu_to_le16(len);
392
393 /* make space for INTF_HEADER_LEN */
394 skb_push(skb, INTF_HEADER_LEN);
395
396 if (!txpd->tx_control)
397 /* TxCtrl set by user or default */
398 txpd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
399
400 return skb->data;
401}
This page took 0.187928 seconds and 5 git commands to generate.