2 * Marvell Wireless LAN device driver: generic TX/RX data handling
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
28 * This function processes the received buffer.
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
36 int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
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);
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);
50 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
53 dev_err(adapter->dev, "data: priv not found. Drop RX packet\n");
54 dev_kfree_skb_any(skb);
58 memset(rx_info, 0, sizeof(*rx_info));
59 rx_info->bss_num = priv->bss_num;
60 rx_info->bss_type = priv->bss_type;
62 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
63 ret = mwifiex_process_uap_rx_packet(priv, skb);
65 ret = mwifiex_process_sta_rx_packet(priv, skb);
69 EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
72 * This function sends a packet to device.
74 * It processes the packet to add the TxPD, checks condition and
75 * sends the processed packet to firmware for transmission.
77 * On successful completion, the function calls the completion callback
80 int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
81 struct mwifiex_tx_param *tx_param)
84 struct mwifiex_adapter *adapter = priv->adapter;
86 struct txpd *local_tx_pd = NULL;
88 hroom = (adapter->iface_type == MWIFIEX_USB) ? 0 : INTF_HEADER_LEN;
90 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
91 head_ptr = mwifiex_process_uap_txpd(priv, skb);
93 head_ptr = mwifiex_process_sta_txpd(priv, skb);
95 if ((adapter->data_sent || adapter->tx_lock_flag) && head_ptr) {
96 skb_queue_tail(&adapter->tx_data_q, skb);
97 atomic_inc(&adapter->tx_queued);
102 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
103 local_tx_pd = (struct txpd *)(head_ptr + hroom);
104 if (adapter->iface_type == MWIFIEX_USB) {
105 adapter->data_sent = true;
106 ret = adapter->if_ops.host_to_card(adapter,
110 ret = adapter->if_ops.host_to_card(adapter,
118 dev_dbg(adapter->dev, "data: -ENOSR is returned\n");
121 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
122 (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
123 priv->adapter->tx_lock_flag = false;
125 local_tx_pd->flags = 0;
127 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
130 if (adapter->iface_type != MWIFIEX_PCIE)
131 adapter->data_sent = false;
132 dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
134 adapter->dbg.num_tx_host_to_card_failure++;
135 mwifiex_write_data_complete(adapter, skb, 0, ret);
138 if (adapter->iface_type != MWIFIEX_PCIE)
139 adapter->data_sent = false;
142 mwifiex_write_data_complete(adapter, skb, 0, ret);
151 static int mwifiex_host_to_card(struct mwifiex_adapter *adapter,
153 struct mwifiex_tx_param *tx_param)
155 struct txpd *local_tx_pd = NULL;
156 u8 *head_ptr = skb->data;
158 struct mwifiex_private *priv;
159 struct mwifiex_txinfo *tx_info;
161 tx_info = MWIFIEX_SKB_TXCB(skb);
162 priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
165 dev_err(adapter->dev, "data: priv not found. Drop TX packet\n");
166 adapter->dbg.num_tx_host_to_card_failure++;
167 mwifiex_write_data_complete(adapter, skb, 0, 0);
170 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
171 if (adapter->iface_type == MWIFIEX_USB)
172 local_tx_pd = (struct txpd *)head_ptr;
174 local_tx_pd = (struct txpd *) (head_ptr +
178 if (adapter->iface_type == MWIFIEX_USB) {
179 adapter->data_sent = true;
180 ret = adapter->if_ops.host_to_card(adapter,
184 ret = adapter->if_ops.host_to_card(adapter,
190 dev_err(adapter->dev, "data: -ENOSR is returned\n");
193 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
194 (adapter->pps_uapsd_mode) &&
195 (adapter->tx_lock_flag)) {
196 priv->adapter->tx_lock_flag = false;
198 local_tx_pd->flags = 0;
200 skb_queue_head(&adapter->tx_data_q, skb);
201 if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
202 atomic_add(tx_info->aggr_num, &adapter->tx_queued);
204 atomic_inc(&adapter->tx_queued);
205 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
208 if (adapter->iface_type != MWIFIEX_PCIE)
209 adapter->data_sent = false;
210 dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
212 adapter->dbg.num_tx_host_to_card_failure++;
213 mwifiex_write_data_complete(adapter, skb, 0, ret);
216 if (adapter->iface_type != MWIFIEX_PCIE)
217 adapter->data_sent = false;
220 mwifiex_write_data_complete(adapter, skb, 0, ret);
229 mwifiex_dequeue_tx_queue(struct mwifiex_adapter *adapter)
231 struct sk_buff *skb, *skb_next;
232 struct mwifiex_txinfo *tx_info;
233 struct mwifiex_tx_param tx_param;
235 skb = skb_dequeue(&adapter->tx_data_q);
239 tx_info = MWIFIEX_SKB_TXCB(skb);
240 if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
241 atomic_sub(tx_info->aggr_num, &adapter->tx_queued);
243 atomic_dec(&adapter->tx_queued);
245 if (!skb_queue_empty(&adapter->tx_data_q))
246 skb_next = skb_peek(&adapter->tx_data_q);
249 tx_param.next_pkt_len = ((skb_next) ? skb_next->len : 0);
250 if (!tx_param.next_pkt_len) {
251 if (!mwifiex_wmm_lists_empty(adapter))
252 tx_param.next_pkt_len = 1;
254 return mwifiex_host_to_card(adapter, skb, &tx_param);
258 mwifiex_process_tx_queue(struct mwifiex_adapter *adapter)
261 if (adapter->data_sent || adapter->tx_lock_flag)
263 if (mwifiex_dequeue_tx_queue(adapter))
265 } while (!skb_queue_empty(&adapter->tx_data_q));
269 * Packet send completion callback handler.
271 * It either frees the buffer directly or forwards it to another
272 * completion callback which checks conditions, updates statistics,
273 * wakes up stalled traffic queue if required, and then frees the buffer.
275 int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
276 struct sk_buff *skb, int aggr, int status)
278 struct mwifiex_private *priv;
279 struct mwifiex_txinfo *tx_info;
280 struct netdev_queue *txq;
286 tx_info = MWIFIEX_SKB_TXCB(skb);
287 priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
292 if (adapter->iface_type == MWIFIEX_USB)
293 adapter->data_sent = false;
295 mwifiex_set_trans_start(priv->netdev);
297 priv->stats.tx_packets++;
298 priv->stats.tx_bytes += tx_info->pkt_len;
299 if (priv->tx_timeout_cnt)
300 priv->tx_timeout_cnt = 0;
302 priv->stats.tx_errors++;
305 if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT) {
306 atomic_dec_return(&adapter->pending_bridged_pkts);
307 if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
312 /* For skb_aggr, do not wake up tx queue */
315 atomic_dec(&adapter->tx_pending);
317 index = mwifiex_1d_to_wmm_queue[skb->priority];
318 if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) {
319 txq = netdev_get_tx_queue(priv->netdev, index);
320 if (netif_tx_queue_stopped(txq)) {
321 netif_tx_wake_queue(txq);
322 dev_dbg(adapter->dev, "wake queue: %d\n", index);
326 dev_kfree_skb_any(skb);
330 EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);
332 void mwifiex_parse_tx_status_event(struct mwifiex_private *priv,
335 struct tx_status_event *tx_status = (void *)priv->adapter->event_body;
336 struct sk_buff *ack_skb;
338 struct mwifiex_txinfo *tx_info;
340 if (!tx_status->tx_token_id)
343 spin_lock_irqsave(&priv->ack_status_lock, flags);
344 ack_skb = idr_find(&priv->ack_status_frames, tx_status->tx_token_id);
346 idr_remove(&priv->ack_status_frames, tx_status->tx_token_id);
347 spin_unlock_irqrestore(&priv->ack_status_lock, flags);
350 tx_info = MWIFIEX_SKB_TXCB(ack_skb);
352 if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS) {
353 /* consumes ack_skb */
354 skb_complete_wifi_ack(ack_skb, !tx_status->status);
356 cfg80211_mgmt_tx_status(&priv->wdev, tx_info->cookie,
357 ack_skb->data, ack_skb->len,
358 !tx_status->status, GFP_ATOMIC);
359 dev_kfree_skb_any(ack_skb);