6ef030a61a94b3c7482089dde3c5e22f05bd4a9c
[deliverable/linux.git] / drivers / net / wireless / mwifiex / txrx.c
1 /*
2 * Marvell Wireless LAN device driver: generic TX/RX data handling
3 *
4 * Copyright (C) 2011-2014, 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 "util.h"
23 #include "fw.h"
24 #include "main.h"
25 #include "wmm.h"
26
27 /*
28 * This function processes the received buffer.
29 *
30 * Main responsibility of this function is to parse the RxPD to
31 * identify the correct interface this packet is headed for and
32 * forwarding it to the associated handling function, where the
33 * packet will be further processed and sent to kernel/upper layer
34 * if required.
35 */
36 int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
37 struct sk_buff *skb)
38 {
39 struct mwifiex_private *priv =
40 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
41 struct rxpd *local_rx_pd;
42 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
43 int ret;
44
45 local_rx_pd = (struct rxpd *) (skb->data);
46 /* Get the BSS number from rxpd, get corresponding priv */
47 priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num &
48 BSS_NUM_MASK, local_rx_pd->bss_type);
49 if (!priv)
50 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
51
52 if (!priv) {
53 mwifiex_dbg(adapter, ERROR,
54 "data: priv not found. Drop RX packet\n");
55 dev_kfree_skb_any(skb);
56 return -1;
57 }
58
59 mwifiex_dbg_dump(adapter, DAT_D, "rx pkt:", skb->data,
60 min_t(size_t, skb->len, DEBUG_DUMP_DATA_MAX_LEN));
61
62 memset(rx_info, 0, sizeof(*rx_info));
63 rx_info->bss_num = priv->bss_num;
64 rx_info->bss_type = priv->bss_type;
65
66 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
67 ret = mwifiex_process_uap_rx_packet(priv, skb);
68 else
69 ret = mwifiex_process_sta_rx_packet(priv, skb);
70
71 return ret;
72 }
73 EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
74
75 /*
76 * This function sends a packet to device.
77 *
78 * It processes the packet to add the TxPD, checks condition and
79 * sends the processed packet to firmware for transmission.
80 *
81 * On successful completion, the function calls the completion callback
82 * and logs the time.
83 */
84 int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
85 struct mwifiex_tx_param *tx_param)
86 {
87 int hroom, ret = -1;
88 struct mwifiex_adapter *adapter = priv->adapter;
89 u8 *head_ptr;
90 struct txpd *local_tx_pd = NULL;
91 struct mwifiex_sta_node *dest_node;
92 struct ethhdr *hdr = (void *)skb->data;
93
94 hroom = (adapter->iface_type == MWIFIEX_USB) ? 0 : INTF_HEADER_LEN;
95
96 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) {
97 dest_node = mwifiex_get_sta_entry(priv, hdr->h_dest);
98 if (dest_node) {
99 dest_node->stats.tx_bytes += skb->len;
100 dest_node->stats.tx_packets++;
101 }
102
103 head_ptr = mwifiex_process_uap_txpd(priv, skb);
104 } else {
105 head_ptr = mwifiex_process_sta_txpd(priv, skb);
106 }
107
108 if ((adapter->data_sent || adapter->tx_lock_flag) && head_ptr) {
109 skb_queue_tail(&adapter->tx_data_q, skb);
110 atomic_inc(&adapter->tx_queued);
111 return 0;
112 }
113
114 if (head_ptr) {
115 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
116 local_tx_pd = (struct txpd *)(head_ptr + hroom);
117 if (adapter->iface_type == MWIFIEX_USB) {
118 adapter->data_sent = true;
119 ret = adapter->if_ops.host_to_card(adapter,
120 MWIFIEX_USB_EP_DATA,
121 skb, NULL);
122 } else {
123 ret = adapter->if_ops.host_to_card(adapter,
124 MWIFIEX_TYPE_DATA,
125 skb, tx_param);
126 }
127 }
128 mwifiex_dbg_dump(adapter, DAT_D, "tx pkt:", skb->data,
129 min_t(size_t, skb->len, DEBUG_DUMP_DATA_MAX_LEN));
130
131 switch (ret) {
132 case -ENOSR:
133 mwifiex_dbg(adapter, DATA, "data: -ENOSR is returned\n");
134 break;
135 case -EBUSY:
136 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
137 (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
138 priv->adapter->tx_lock_flag = false;
139 if (local_tx_pd)
140 local_tx_pd->flags = 0;
141 }
142 mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
143 break;
144 case -1:
145 if (adapter->iface_type == MWIFIEX_USB)
146 adapter->data_sent = false;
147 mwifiex_dbg(adapter, ERROR,
148 "mwifiex_write_data_async failed: 0x%X\n",
149 ret);
150 adapter->dbg.num_tx_host_to_card_failure++;
151 mwifiex_write_data_complete(adapter, skb, 0, ret);
152 break;
153 case -EINPROGRESS:
154 if (adapter->iface_type == MWIFIEX_USB)
155 adapter->data_sent = false;
156 break;
157 case 0:
158 mwifiex_write_data_complete(adapter, skb, 0, ret);
159 break;
160 default:
161 break;
162 }
163
164 return ret;
165 }
166
167 static int mwifiex_host_to_card(struct mwifiex_adapter *adapter,
168 struct sk_buff *skb,
169 struct mwifiex_tx_param *tx_param)
170 {
171 struct txpd *local_tx_pd = NULL;
172 u8 *head_ptr = skb->data;
173 int ret = 0;
174 struct mwifiex_private *priv;
175 struct mwifiex_txinfo *tx_info;
176
177 tx_info = MWIFIEX_SKB_TXCB(skb);
178 priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
179 tx_info->bss_type);
180 if (!priv) {
181 mwifiex_dbg(adapter, ERROR,
182 "data: priv not found. Drop TX packet\n");
183 adapter->dbg.num_tx_host_to_card_failure++;
184 mwifiex_write_data_complete(adapter, skb, 0, 0);
185 return ret;
186 }
187 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
188 if (adapter->iface_type == MWIFIEX_USB)
189 local_tx_pd = (struct txpd *)head_ptr;
190 else
191 local_tx_pd = (struct txpd *) (head_ptr +
192 INTF_HEADER_LEN);
193 }
194
195 if (adapter->iface_type == MWIFIEX_USB) {
196 adapter->data_sent = true;
197 ret = adapter->if_ops.host_to_card(adapter,
198 MWIFIEX_USB_EP_DATA,
199 skb, NULL);
200 } else {
201 ret = adapter->if_ops.host_to_card(adapter,
202 MWIFIEX_TYPE_DATA,
203 skb, tx_param);
204 }
205 switch (ret) {
206 case -ENOSR:
207 mwifiex_dbg(adapter, ERROR, "data: -ENOSR is returned\n");
208 break;
209 case -EBUSY:
210 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
211 (adapter->pps_uapsd_mode) &&
212 (adapter->tx_lock_flag)) {
213 priv->adapter->tx_lock_flag = false;
214 if (local_tx_pd)
215 local_tx_pd->flags = 0;
216 }
217 skb_queue_head(&adapter->tx_data_q, skb);
218 if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
219 atomic_add(tx_info->aggr_num, &adapter->tx_queued);
220 else
221 atomic_inc(&adapter->tx_queued);
222 mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
223 break;
224 case -1:
225 if (adapter->iface_type == MWIFIEX_USB)
226 adapter->data_sent = false;
227 mwifiex_dbg(adapter, ERROR,
228 "mwifiex_write_data_async failed: 0x%X\n", ret);
229 adapter->dbg.num_tx_host_to_card_failure++;
230 mwifiex_write_data_complete(adapter, skb, 0, ret);
231 break;
232 case -EINPROGRESS:
233 if (adapter->iface_type == MWIFIEX_USB)
234 adapter->data_sent = false;
235 break;
236 case 0:
237 mwifiex_write_data_complete(adapter, skb, 0, ret);
238 break;
239 default:
240 break;
241 }
242 return ret;
243 }
244
245 static int
246 mwifiex_dequeue_tx_queue(struct mwifiex_adapter *adapter)
247 {
248 struct sk_buff *skb, *skb_next;
249 struct mwifiex_txinfo *tx_info;
250 struct mwifiex_tx_param tx_param;
251
252 skb = skb_dequeue(&adapter->tx_data_q);
253 if (!skb)
254 return -1;
255
256 tx_info = MWIFIEX_SKB_TXCB(skb);
257 if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
258 atomic_sub(tx_info->aggr_num, &adapter->tx_queued);
259 else
260 atomic_dec(&adapter->tx_queued);
261
262 if (!skb_queue_empty(&adapter->tx_data_q))
263 skb_next = skb_peek(&adapter->tx_data_q);
264 else
265 skb_next = NULL;
266 tx_param.next_pkt_len = ((skb_next) ? skb_next->len : 0);
267 if (!tx_param.next_pkt_len) {
268 if (!mwifiex_wmm_lists_empty(adapter))
269 tx_param.next_pkt_len = 1;
270 }
271 return mwifiex_host_to_card(adapter, skb, &tx_param);
272 }
273
274 void
275 mwifiex_process_tx_queue(struct mwifiex_adapter *adapter)
276 {
277 do {
278 if (adapter->data_sent || adapter->tx_lock_flag)
279 break;
280 if (mwifiex_dequeue_tx_queue(adapter))
281 break;
282 } while (!skb_queue_empty(&adapter->tx_data_q));
283 }
284
285 /*
286 * Packet send completion callback handler.
287 *
288 * It either frees the buffer directly or forwards it to another
289 * completion callback which checks conditions, updates statistics,
290 * wakes up stalled traffic queue if required, and then frees the buffer.
291 */
292 int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
293 struct sk_buff *skb, int aggr, int status)
294 {
295 struct mwifiex_private *priv;
296 struct mwifiex_txinfo *tx_info;
297 struct netdev_queue *txq;
298 int index;
299
300 if (!skb)
301 return 0;
302
303 tx_info = MWIFIEX_SKB_TXCB(skb);
304 priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
305 tx_info->bss_type);
306 if (!priv)
307 goto done;
308
309 if (adapter->iface_type == MWIFIEX_USB)
310 adapter->data_sent = false;
311
312 mwifiex_set_trans_start(priv->netdev);
313 if (!status) {
314 priv->stats.tx_packets++;
315 priv->stats.tx_bytes += tx_info->pkt_len;
316 if (priv->tx_timeout_cnt)
317 priv->tx_timeout_cnt = 0;
318 } else {
319 priv->stats.tx_errors++;
320 }
321
322 if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
323 atomic_dec_return(&adapter->pending_bridged_pkts);
324
325 if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
326 goto done;
327
328 if (aggr)
329 /* For skb_aggr, do not wake up tx queue */
330 goto done;
331
332 atomic_dec(&adapter->tx_pending);
333
334 index = mwifiex_1d_to_wmm_queue[skb->priority];
335 if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) {
336 txq = netdev_get_tx_queue(priv->netdev, index);
337 if (netif_tx_queue_stopped(txq)) {
338 netif_tx_wake_queue(txq);
339 mwifiex_dbg(adapter, DATA, "wake queue: %d\n", index);
340 }
341 }
342 done:
343 dev_kfree_skb_any(skb);
344
345 return 0;
346 }
347 EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);
348
349 void mwifiex_parse_tx_status_event(struct mwifiex_private *priv,
350 void *event_body)
351 {
352 struct tx_status_event *tx_status = (void *)priv->adapter->event_body;
353 struct sk_buff *ack_skb;
354 unsigned long flags;
355 struct mwifiex_txinfo *tx_info;
356
357 if (!tx_status->tx_token_id)
358 return;
359
360 spin_lock_irqsave(&priv->ack_status_lock, flags);
361 ack_skb = idr_find(&priv->ack_status_frames, tx_status->tx_token_id);
362 if (ack_skb)
363 idr_remove(&priv->ack_status_frames, tx_status->tx_token_id);
364 spin_unlock_irqrestore(&priv->ack_status_lock, flags);
365
366 if (ack_skb) {
367 tx_info = MWIFIEX_SKB_TXCB(ack_skb);
368
369 if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS) {
370 /* consumes ack_skb */
371 skb_complete_wifi_ack(ack_skb, !tx_status->status);
372 } else {
373 /* Remove broadcast address which was added by driver */
374 memmove(ack_skb->data +
375 sizeof(struct ieee80211_hdr_3addr) +
376 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16),
377 ack_skb->data +
378 sizeof(struct ieee80211_hdr_3addr) +
379 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16) +
380 ETH_ALEN, ack_skb->len -
381 (sizeof(struct ieee80211_hdr_3addr) +
382 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16) +
383 ETH_ALEN));
384 ack_skb->len = ack_skb->len - ETH_ALEN;
385 /* Remove driver's proprietary header including 2 bytes
386 * of packet length and pass actual management frame buffer
387 * to cfg80211.
388 */
389 cfg80211_mgmt_tx_status(&priv->wdev, tx_info->cookie,
390 ack_skb->data +
391 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
392 sizeof(u16), ack_skb->len -
393 (MWIFIEX_MGMT_FRAME_HEADER_SIZE
394 + sizeof(u16)),
395 !tx_status->status, GFP_ATOMIC);
396 dev_kfree_skb_any(ack_skb);
397 }
398 }
399 }
This page took 0.041954 seconds and 4 git commands to generate.