• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
mwifiex_handle_rx_packet(struct mwifiex_adapter * adapter,struct sk_buff * skb)36 int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
37 			     struct sk_buff *skb)
38 {
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 
51 	rx_info->bss_num = priv->bss_num;
52 	rx_info->bss_type = priv->bss_type;
53 
54 	return mwifiex_process_sta_rx_packet(adapter, skb);
55 }
56 EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
57 
58 /*
59  * This function sends a packet to device.
60  *
61  * It processes the packet to add the TxPD, checks condition and
62  * sends the processed packet to firmware for transmission.
63  *
64  * On successful completion, the function calls the completion callback
65  * and logs the time.
66  */
mwifiex_process_tx(struct mwifiex_private * priv,struct sk_buff * skb,struct mwifiex_tx_param * tx_param)67 int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
68 		       struct mwifiex_tx_param *tx_param)
69 {
70 	int ret = -1;
71 	struct mwifiex_adapter *adapter = priv->adapter;
72 	u8 *head_ptr;
73 	struct txpd *local_tx_pd = NULL;
74 
75 	head_ptr = mwifiex_process_sta_txpd(priv, skb);
76 	if (head_ptr) {
77 		if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
78 			local_tx_pd =
79 				(struct txpd *) (head_ptr + INTF_HEADER_LEN);
80 
81 		ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
82 						   skb, tx_param);
83 	}
84 
85 	switch (ret) {
86 	case -EBUSY:
87 		if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
88 		    (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
89 				priv->adapter->tx_lock_flag = false;
90 				if (local_tx_pd)
91 					local_tx_pd->flags = 0;
92 		}
93 		dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
94 		break;
95 	case -1:
96 		adapter->data_sent = false;
97 		dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
98 			ret);
99 		adapter->dbg.num_tx_host_to_card_failure++;
100 		mwifiex_write_data_complete(adapter, skb, ret);
101 		break;
102 	case -EINPROGRESS:
103 		adapter->data_sent = false;
104 		break;
105 	case 0:
106 		mwifiex_write_data_complete(adapter, skb, ret);
107 		break;
108 	default:
109 		break;
110 	}
111 
112 	return ret;
113 }
114 
115 /*
116  * Packet send completion callback handler.
117  *
118  * It either frees the buffer directly or forwards it to another
119  * completion callback which checks conditions, updates statistics,
120  * wakes up stalled traffic queue if required, and then frees the buffer.
121  */
mwifiex_write_data_complete(struct mwifiex_adapter * adapter,struct sk_buff * skb,int status)122 int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
123 				struct sk_buff *skb, int status)
124 {
125 	struct mwifiex_private *priv, *tpriv;
126 	struct mwifiex_txinfo *tx_info;
127 	int i;
128 
129 	if (!skb)
130 		return 0;
131 
132 	tx_info = MWIFIEX_SKB_TXCB(skb);
133 	priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
134 				      tx_info->bss_type);
135 	if (!priv)
136 		goto done;
137 
138 	mwifiex_set_trans_start(priv->netdev);
139 	if (!status) {
140 		priv->stats.tx_packets++;
141 		priv->stats.tx_bytes += skb->len;
142 	} else {
143 		priv->stats.tx_errors++;
144 	}
145 
146 	if (atomic_dec_return(&adapter->tx_pending) >= LOW_TX_PENDING)
147 		goto done;
148 
149 	for (i = 0; i < adapter->priv_num; i++) {
150 
151 		tpriv = adapter->priv[i];
152 
153 		if ((GET_BSS_ROLE(tpriv) == MWIFIEX_BSS_ROLE_STA) &&
154 		    (tpriv->media_connected)) {
155 			if (netif_queue_stopped(tpriv->netdev))
156 				mwifiex_wake_up_net_dev_queue(tpriv->netdev,
157 							      adapter);
158 		}
159 	}
160 done:
161 	dev_kfree_skb_any(skb);
162 
163 	return 0;
164 }
165 
166