Merge remote-tracking branch 'asoc/fix/arizona' into asoc-linus
[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
f3b369e4
AP
51 if (!priv) {
52 dev_err(adapter->dev, "data: priv not found. Drop RX packet\n");
53 dev_kfree_skb_any(skb);
54 return -1;
55 }
56
9da9a3b2
YAP
57 rx_info->bss_num = priv->bss_num;
58 rx_info->bss_type = priv->bss_type;
5e6e3a92 59
838e4f44 60 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
f3b369e4 61 return mwifiex_process_uap_rx_packet(priv, skb);
838e4f44 62
f3b369e4 63 return mwifiex_process_sta_rx_packet(priv, skb);
5e6e3a92
BZ
64}
65EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
66
67/*
68 * This function sends a packet to device.
69 *
70 * It processes the packet to add the TxPD, checks condition and
71 * sends the processed packet to firmware for transmission.
72 *
73 * On successful completion, the function calls the completion callback
74 * and logs the time.
75 */
76int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
77 struct mwifiex_tx_param *tx_param)
78{
79 int ret = -1;
80 struct mwifiex_adapter *adapter = priv->adapter;
270e58e8 81 u8 *head_ptr;
5e6e3a92
BZ
82 struct txpd *local_tx_pd = NULL;
83
4ac8764a
AP
84 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
85 head_ptr = mwifiex_process_uap_txpd(priv, skb);
86 else
87 head_ptr = mwifiex_process_sta_txpd(priv, skb);
88
5e6e3a92
BZ
89 if (head_ptr) {
90 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
91 local_tx_pd =
92 (struct txpd *) (head_ptr + INTF_HEADER_LEN);
4daffe35
AK
93 if (adapter->iface_type == MWIFIEX_USB) {
94 adapter->data_sent = true;
95 skb_pull(skb, INTF_HEADER_LEN);
96 ret = adapter->if_ops.host_to_card(adapter,
97 MWIFIEX_USB_EP_DATA,
98 skb, NULL);
99 } else {
100 ret = adapter->if_ops.host_to_card(adapter,
101 MWIFIEX_TYPE_DATA,
102 skb, tx_param);
103 }
5e6e3a92
BZ
104 }
105
106 switch (ret) {
4daffe35
AK
107 case -ENOSR:
108 dev_err(adapter->dev, "data: -ENOSR is returned\n");
109 break;
5e6e3a92
BZ
110 case -EBUSY:
111 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
c65a30f3 112 (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
5e6e3a92 113 priv->adapter->tx_lock_flag = false;
3d82de0f
YAP
114 if (local_tx_pd)
115 local_tx_pd->flags = 0;
5e6e3a92
BZ
116 }
117 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
118 break;
119 case -1:
e7f767a7
AP
120 if (adapter->iface_type != MWIFIEX_PCIE)
121 adapter->data_sent = false;
5e6e3a92 122 dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
c65a30f3 123 ret);
5e6e3a92 124 adapter->dbg.num_tx_host_to_card_failure++;
47411a06 125 mwifiex_write_data_complete(adapter, skb, 0, ret);
5e6e3a92
BZ
126 break;
127 case -EINPROGRESS:
e7f767a7
AP
128 if (adapter->iface_type != MWIFIEX_PCIE)
129 adapter->data_sent = false;
5e6e3a92
BZ
130 break;
131 case 0:
47411a06 132 mwifiex_write_data_complete(adapter, skb, 0, ret);
5e6e3a92
BZ
133 break;
134 default:
135 break;
136 }
137
138 return ret;
139}
140
141/*
142 * Packet send completion callback handler.
143 *
144 * It either frees the buffer directly or forwards it to another
145 * completion callback which checks conditions, updates statistics,
146 * wakes up stalled traffic queue if required, and then frees the buffer.
147 */
148int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
47411a06 149 struct sk_buff *skb, int aggr, int status)
5e6e3a92 150{
47411a06 151 struct mwifiex_private *priv;
270e58e8 152 struct mwifiex_txinfo *tx_info;
47411a06
AP
153 struct netdev_queue *txq;
154 int index;
5e6e3a92
BZ
155
156 if (!skb)
157 return 0;
158
159 tx_info = MWIFIEX_SKB_TXCB(skb);
9da9a3b2 160 priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
c65a30f3 161 tx_info->bss_type);
5e6e3a92
BZ
162 if (!priv)
163 goto done;
164
4daffe35
AK
165 if (adapter->iface_type == MWIFIEX_USB)
166 adapter->data_sent = false;
167
bbea3bc4 168 mwifiex_set_trans_start(priv->netdev);
5e6e3a92
BZ
169 if (!status) {
170 priv->stats.tx_packets++;
171 priv->stats.tx_bytes += skb->len;
8908c7d5
AN
172 if (priv->tx_timeout_cnt)
173 priv->tx_timeout_cnt = 0;
5e6e3a92
BZ
174 } else {
175 priv->stats.tx_errors++;
176 }
62a5b7dc 177
838e4f44
AP
178 if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
179 atomic_dec_return(&adapter->pending_bridged_pkts);
47411a06
AP
180
181 if (aggr)
182 /* For skb_aggr, do not wake up tx queue */
62a5b7dc 183 goto done;
5e6e3a92 184
47411a06 185 atomic_dec(&adapter->tx_pending);
5e6e3a92 186
47411a06
AP
187 index = mwifiex_1d_to_wmm_queue[skb->priority];
188 if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) {
189 txq = netdev_get_tx_queue(priv->netdev, index);
190 if (netif_tx_queue_stopped(txq)) {
191 netif_tx_wake_queue(txq);
192 dev_dbg(adapter->dev, "wake queue: %d\n", index);
193 }
5e6e3a92
BZ
194 }
195done:
196 dev_kfree_skb_any(skb);
197
198 return 0;
199}
4daffe35 200EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);
5e6e3a92 201
This page took 0.263939 seconds and 5 git commands to generate.