Merge tag 'pm-for-3.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[deliverable/linux.git] / drivers / net / wireless / mwifiex / txrx.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: generic TX/RX data handling
3 *
4 * Copyright (C) 2011, 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 */
36int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
37 struct sk_buff *skb)
38{
5e6e3a92
BZ
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
44 local_rx_pd = (struct rxpd *) (skb->data);
45 /* Get the BSS number from rxpd, get corresponding priv */
46 priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num &
47 BSS_NUM_MASK, local_rx_pd->bss_type);
48 if (!priv)
49 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
50
9da9a3b2
YAP
51 rx_info->bss_num = priv->bss_num;
52 rx_info->bss_type = priv->bss_type;
5e6e3a92 53
838e4f44
AP
54 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
55 return mwifiex_process_uap_rx_packet(adapter, skb);
56
636c4598 57 return mwifiex_process_sta_rx_packet(adapter, skb);
5e6e3a92
BZ
58}
59EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
60
61/*
62 * This function sends a packet to device.
63 *
64 * It processes the packet to add the TxPD, checks condition and
65 * sends the processed packet to firmware for transmission.
66 *
67 * On successful completion, the function calls the completion callback
68 * and logs the time.
69 */
70int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
71 struct mwifiex_tx_param *tx_param)
72{
73 int ret = -1;
74 struct mwifiex_adapter *adapter = priv->adapter;
270e58e8 75 u8 *head_ptr;
5e6e3a92
BZ
76 struct txpd *local_tx_pd = NULL;
77
4ac8764a
AP
78 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
79 head_ptr = mwifiex_process_uap_txpd(priv, skb);
80 else
81 head_ptr = mwifiex_process_sta_txpd(priv, skb);
82
5e6e3a92
BZ
83 if (head_ptr) {
84 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
85 local_tx_pd =
86 (struct txpd *) (head_ptr + INTF_HEADER_LEN);
4daffe35
AK
87 if (adapter->iface_type == MWIFIEX_USB) {
88 adapter->data_sent = true;
89 skb_pull(skb, INTF_HEADER_LEN);
90 ret = adapter->if_ops.host_to_card(adapter,
91 MWIFIEX_USB_EP_DATA,
92 skb, NULL);
93 } else {
94 ret = adapter->if_ops.host_to_card(adapter,
95 MWIFIEX_TYPE_DATA,
96 skb, tx_param);
97 }
5e6e3a92
BZ
98 }
99
100 switch (ret) {
4daffe35
AK
101 case -ENOSR:
102 dev_err(adapter->dev, "data: -ENOSR is returned\n");
103 break;
5e6e3a92
BZ
104 case -EBUSY:
105 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
c65a30f3 106 (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
5e6e3a92 107 priv->adapter->tx_lock_flag = false;
3d82de0f
YAP
108 if (local_tx_pd)
109 local_tx_pd->flags = 0;
5e6e3a92
BZ
110 }
111 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
112 break;
113 case -1:
114 adapter->data_sent = false;
115 dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
c65a30f3 116 ret);
5e6e3a92
BZ
117 adapter->dbg.num_tx_host_to_card_failure++;
118 mwifiex_write_data_complete(adapter, skb, ret);
119 break;
120 case -EINPROGRESS:
121 adapter->data_sent = false;
122 break;
123 case 0:
124 mwifiex_write_data_complete(adapter, skb, ret);
125 break;
126 default:
127 break;
128 }
129
130 return ret;
131}
132
133/*
134 * Packet send completion callback handler.
135 *
136 * It either frees the buffer directly or forwards it to another
137 * completion callback which checks conditions, updates statistics,
138 * wakes up stalled traffic queue if required, and then frees the buffer.
139 */
140int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
141 struct sk_buff *skb, int status)
142{
270e58e8
YAP
143 struct mwifiex_private *priv, *tpriv;
144 struct mwifiex_txinfo *tx_info;
5e6e3a92
BZ
145 int i;
146
147 if (!skb)
148 return 0;
149
150 tx_info = MWIFIEX_SKB_TXCB(skb);
9da9a3b2 151 priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
c65a30f3 152 tx_info->bss_type);
5e6e3a92
BZ
153 if (!priv)
154 goto done;
155
4daffe35
AK
156 if (adapter->iface_type == MWIFIEX_USB)
157 adapter->data_sent = false;
158
bbea3bc4 159 mwifiex_set_trans_start(priv->netdev);
5e6e3a92
BZ
160 if (!status) {
161 priv->stats.tx_packets++;
162 priv->stats.tx_bytes += skb->len;
163 } else {
164 priv->stats.tx_errors++;
165 }
62a5b7dc 166
838e4f44
AP
167 if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
168 atomic_dec_return(&adapter->pending_bridged_pkts);
62a5b7dc
MY
169 if (atomic_dec_return(&adapter->tx_pending) >= LOW_TX_PENDING)
170 goto done;
5e6e3a92
BZ
171
172 for (i = 0; i < adapter->priv_num; i++) {
5e6e3a92
BZ
173 tpriv = adapter->priv[i];
174
73dc3b90
AP
175 if (tpriv->media_connected &&
176 netif_queue_stopped(tpriv->netdev))
177 mwifiex_wake_up_net_dev_queue(tpriv->netdev, adapter);
5e6e3a92
BZ
178 }
179done:
180 dev_kfree_skb_any(skb);
181
182 return 0;
183}
4daffe35 184EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);
5e6e3a92 185
This page took 0.244659 seconds and 5 git commands to generate.