blob: f06923cb1c4bae4468866af3a446f0414f7102b4 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
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{
39 int ret = 0;
40 struct mwifiex_private *priv =
41 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
42 struct rxpd *local_rx_pd;
43 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
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 rx_info->bss_index = priv->bss_index;
53 ret = mwifiex_process_sta_rx_packet(adapter, skb);
54
55 return ret;
56}
57EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
58
59/*
60 * This function sends a packet to device.
61 *
62 * It processes the packet to add the TxPD, checks condition and
63 * sends the processed packet to firmware for transmission.
64 *
65 * On successful completion, the function calls the completion callback
66 * and logs the time.
67 */
68int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
69 struct mwifiex_tx_param *tx_param)
70{
71 int ret = -1;
72 struct mwifiex_adapter *adapter = priv->adapter;
73 u8 *head_ptr = NULL;
74 struct txpd *local_tx_pd = NULL;
75
76 head_ptr = (u8 *) mwifiex_process_sta_txpd(priv, skb);
77 if (head_ptr) {
78 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
79 local_tx_pd =
80 (struct txpd *) (head_ptr + INTF_HEADER_LEN);
81
82 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
83 skb->data, skb->len, tx_param);
84 }
85
86 switch (ret) {
87 case -EBUSY:
88 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
89 (adapter->pps_uapsd_mode) &&
90 (adapter->tx_lock_flag)) {
91 priv->adapter->tx_lock_flag = false;
92 local_tx_pd->flags = 0;
93 }
94 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
95 break;
96 case -1:
97 adapter->data_sent = false;
98 dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
99 ret);
100 adapter->dbg.num_tx_host_to_card_failure++;
101 mwifiex_write_data_complete(adapter, skb, ret);
102 break;
103 case -EINPROGRESS:
104 adapter->data_sent = false;
105 break;
106 case 0:
107 mwifiex_write_data_complete(adapter, skb, ret);
108 break;
109 default:
110 break;
111 }
112
113 return ret;
114}
115
116/*
117 * Packet send completion callback handler.
118 *
119 * It either frees the buffer directly or forwards it to another
120 * completion callback which checks conditions, updates statistics,
121 * wakes up stalled traffic queue if required, and then frees the buffer.
122 */
123int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
124 struct sk_buff *skb, int status)
125{
126 struct mwifiex_private *priv = NULL, *tpriv = NULL;
127 struct mwifiex_txinfo *tx_info = NULL;
128 int i;
129
130 if (!skb)
131 return 0;
132
133 tx_info = MWIFIEX_SKB_TXCB(skb);
134 priv = mwifiex_bss_index_to_priv(adapter, tx_info->bss_index);
135 if (!priv)
136 goto done;
137
138 priv->netdev->trans_start = jiffies;
139 if (!status) {
140 priv->stats.tx_packets++;
141 priv->stats.tx_bytes += skb->len;
142 } else {
143 priv->stats.tx_errors++;
144 }
145 atomic_dec(&adapter->tx_pending);
146
147 for (i = 0; i < adapter->priv_num; i++) {
148
149 tpriv = adapter->priv[i];
150
151 if ((GET_BSS_ROLE(tpriv) == MWIFIEX_BSS_ROLE_STA)
152 && (tpriv->media_connected)) {
153 if (netif_queue_stopped(tpriv->netdev))
154 netif_wake_queue(tpriv->netdev);
155 }
156 }
157done:
158 dev_kfree_skb_any(skb);
159
160 return 0;
161}
162
163/*
164 * Packet receive completion callback handler.
165 *
166 * This function calls another completion callback handler which
167 * updates the statistics, and optionally updates the parent buffer
168 * use count before freeing the received packet.
169 */
170int mwifiex_recv_packet_complete(struct mwifiex_adapter *adapter,
171 struct sk_buff *skb, int status)
172{
173 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
174 struct mwifiex_rxinfo *rx_info_parent = NULL;
175 struct mwifiex_private *priv;
176 struct sk_buff *skb_parent = NULL;
177 unsigned long flags;
178
179 priv = adapter->priv[rx_info->bss_index];
180
181 if (priv && (status == -1))
182 priv->stats.rx_dropped++;
183
184 if (rx_info->parent) {
185 skb_parent = rx_info->parent;
186 rx_info_parent = MWIFIEX_SKB_RXCB(skb_parent);
187
188 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
189 --rx_info_parent->use_count;
190
191 if (!rx_info_parent->use_count) {
192 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
193 dev_kfree_skb_any(skb_parent);
194 } else {
195 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
196 }
197 } else {
198 dev_kfree_skb_any(skb);
199 }
200
201 return 0;
202}