blob: 8c80024c30ff6345399d53e7132bed310a6c12a6 [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{
Bing Zhao5e6e3a92011-03-21 18:00:50 -070039 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
Avinash Patilf3b369e2012-10-19 19:19:21 -070051 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
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -080057 rx_info->bss_num = priv->bss_num;
58 rx_info->bss_type = priv->bss_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059
Avinash Patil838e4f42012-08-03 18:06:08 -070060 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
Avinash Patilf3b369e2012-10-19 19:19:21 -070061 return mwifiex_process_uap_rx_packet(priv, skb);
Avinash Patil838e4f42012-08-03 18:06:08 -070062
Avinash Patilf3b369e2012-10-19 19:19:21 -070063 return mwifiex_process_sta_rx_packet(priv, skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070064}
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;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -070081 u8 *head_ptr;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070082 struct txpd *local_tx_pd = NULL;
83
Avinash Patil4ac87642012-09-10 18:30:49 -070084 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
Bing Zhao5e6e3a92011-03-21 18:00:50 -070089 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);
Amitkumar Karwar4daffe32012-04-18 20:08:28 -070093 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 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700104 }
105
106 switch (ret) {
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700107 case -ENOSR:
108 dev_err(adapter->dev, "data: -ENOSR is returned\n");
109 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700110 case -EBUSY:
111 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700112 (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700113 priv->adapter->tx_lock_flag = false;
Yogesh Ashok Powar3d82de02011-10-05 14:58:24 -0700114 if (local_tx_pd)
115 local_tx_pd->flags = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700116 }
117 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
118 break;
119 case -1:
120 adapter->data_sent = false;
121 dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700122 ret);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700123 adapter->dbg.num_tx_host_to_card_failure++;
Avinash Patil47411a02012-11-01 18:44:16 -0700124 mwifiex_write_data_complete(adapter, skb, 0, ret);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700125 break;
126 case -EINPROGRESS:
127 adapter->data_sent = false;
128 break;
129 case 0:
Avinash Patil47411a02012-11-01 18:44:16 -0700130 mwifiex_write_data_complete(adapter, skb, 0, ret);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700131 break;
132 default:
133 break;
134 }
135
136 return ret;
137}
138
139/*
140 * Packet send completion callback handler.
141 *
142 * It either frees the buffer directly or forwards it to another
143 * completion callback which checks conditions, updates statistics,
144 * wakes up stalled traffic queue if required, and then frees the buffer.
145 */
146int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
Avinash Patil47411a02012-11-01 18:44:16 -0700147 struct sk_buff *skb, int aggr, int status)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700148{
Avinash Patil47411a02012-11-01 18:44:16 -0700149 struct mwifiex_private *priv;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700150 struct mwifiex_txinfo *tx_info;
Avinash Patil47411a02012-11-01 18:44:16 -0700151 struct netdev_queue *txq;
152 int index;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700153
154 if (!skb)
155 return 0;
156
157 tx_info = MWIFIEX_SKB_TXCB(skb);
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -0800158 priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700159 tx_info->bss_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700160 if (!priv)
161 goto done;
162
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700163 if (adapter->iface_type == MWIFIEX_USB)
164 adapter->data_sent = false;
165
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800166 mwifiex_set_trans_start(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700167 if (!status) {
168 priv->stats.tx_packets++;
169 priv->stats.tx_bytes += skb->len;
170 } else {
171 priv->stats.tx_errors++;
172 }
Marc Yang62a5b7d2011-05-16 19:17:53 -0700173
Avinash Patil838e4f42012-08-03 18:06:08 -0700174 if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
175 atomic_dec_return(&adapter->pending_bridged_pkts);
Avinash Patil47411a02012-11-01 18:44:16 -0700176
177 if (aggr)
178 /* For skb_aggr, do not wake up tx queue */
Marc Yang62a5b7d2011-05-16 19:17:53 -0700179 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700180
Avinash Patil47411a02012-11-01 18:44:16 -0700181 atomic_dec(&adapter->tx_pending);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700182
Avinash Patil47411a02012-11-01 18:44:16 -0700183 index = mwifiex_1d_to_wmm_queue[skb->priority];
184 if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) {
185 txq = netdev_get_tx_queue(priv->netdev, index);
186 if (netif_tx_queue_stopped(txq)) {
187 netif_tx_wake_queue(txq);
188 dev_dbg(adapter->dev, "wake queue: %d\n", index);
189 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700190 }
191done:
192 dev_kfree_skb_any(skb);
193
194 return 0;
195}
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700196EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700197