Linux Audio

Check our new training course

Embedded Linux training

Mar 10-20, 2025, special US time zones
Register
Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * NXP Wireless LAN device driver: generic TX/RX data handling
  4 *
  5 * Copyright 2011-2020 NXP
  6 */
  7
  8#include "decl.h"
  9#include "ioctl.h"
 10#include "util.h"
 11#include "fw.h"
 12#include "main.h"
 13#include "wmm.h"
 14
 15/*
 16 * This function processes the received buffer.
 17 *
 18 * Main responsibility of this function is to parse the RxPD to
 19 * identify the correct interface this packet is headed for and
 20 * forwarding it to the associated handling function, where the
 21 * packet will be further processed and sent to kernel/upper layer
 22 * if required.
 23 */
 24int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
 25			     struct sk_buff *skb)
 26{
 27	struct mwifiex_private *priv =
 28		mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
 29	struct rxpd *local_rx_pd;
 30	struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
 31	int ret;
 32
 33	local_rx_pd = (struct rxpd *) (skb->data);
 34	/* Get the BSS number from rxpd, get corresponding priv */
 35	priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num &
 36				      BSS_NUM_MASK, local_rx_pd->bss_type);
 37	if (!priv)
 38		priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
 39
 40	if (!priv) {
 41		mwifiex_dbg(adapter, ERROR,
 42			    "data: priv not found. Drop RX packet\n");
 43		dev_kfree_skb_any(skb);
 44		return -1;
 45	}
 46
 47	mwifiex_dbg_dump(adapter, DAT_D, "rx pkt:", skb->data,
 48			 min_t(size_t, skb->len, DEBUG_DUMP_DATA_MAX_LEN));
 49
 50	memset(rx_info, 0, sizeof(*rx_info));
 51	rx_info->bss_num = priv->bss_num;
 52	rx_info->bss_type = priv->bss_type;
 53
 54	if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
 55		ret = mwifiex_process_uap_rx_packet(priv, skb);
 56	else
 57		ret = mwifiex_process_sta_rx_packet(priv, skb);
 58
 59	return ret;
 60}
 61EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
 62
 63/*
 64 * This function sends a packet to device.
 65 *
 66 * It processes the packet to add the TxPD, checks condition and
 67 * sends the processed packet to firmware for transmission.
 68 *
 69 * On successful completion, the function calls the completion callback
 70 * and logs the time.
 71 */
 72int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
 73		       struct mwifiex_tx_param *tx_param)
 74{
 75	int hroom, ret;
 76	struct mwifiex_adapter *adapter = priv->adapter;
 
 77	struct txpd *local_tx_pd = NULL;
 78	struct mwifiex_sta_node *dest_node;
 79	struct ethhdr *hdr = (void *)skb->data;
 80
 81	if (unlikely(!skb->len ||
 82		     skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN)) {
 83		ret = -EINVAL;
 84		goto out;
 85	}
 86
 87	hroom = adapter->intf_hdr_len;
 88
 89	if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) {
 90		dest_node = mwifiex_get_sta_entry(priv, hdr->h_dest);
 91		if (dest_node) {
 92			dest_node->stats.tx_bytes += skb->len;
 93			dest_node->stats.tx_packets++;
 94		}
 95
 96		mwifiex_process_uap_txpd(priv, skb);
 97	} else {
 98		mwifiex_process_sta_txpd(priv, skb);
 99	}
100
101	if (adapter->data_sent || adapter->tx_lock_flag) {
102		skb_queue_tail(&adapter->tx_data_q, skb);
103		atomic_inc(&adapter->tx_queued);
104		return 0;
105	}
106
107	if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
108		local_tx_pd = (struct txpd *)(skb->data + hroom);
109	if (adapter->iface_type == MWIFIEX_USB) {
110		ret = adapter->if_ops.host_to_card(adapter,
111						   priv->usb_port,
112						   skb, tx_param);
113	} else {
114		ret = adapter->if_ops.host_to_card(adapter,
115						   MWIFIEX_TYPE_DATA,
116						   skb, tx_param);
 
 
117	}
118	mwifiex_dbg_dump(adapter, DAT_D, "tx pkt:", skb->data,
119			 min_t(size_t, skb->len, DEBUG_DUMP_DATA_MAX_LEN));
120out:
121	switch (ret) {
122	case -ENOSR:
123		mwifiex_dbg(adapter, DATA, "data: -ENOSR is returned\n");
124		break;
125	case -EBUSY:
126		if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
127		    (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
128				priv->adapter->tx_lock_flag = false;
129				if (local_tx_pd)
130					local_tx_pd->flags = 0;
131		}
132		mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
133		break;
134	case -1:
135		mwifiex_dbg(adapter, ERROR,
136			    "mwifiex_write_data_async failed: 0x%X\n",
137			    ret);
138		adapter->dbg.num_tx_host_to_card_failure++;
139		mwifiex_write_data_complete(adapter, skb, 0, ret);
140		break;
141	case -EINPROGRESS:
142		break;
143	case -EINVAL:
144		mwifiex_dbg(adapter, ERROR,
145			    "malformed skb (length: %u, headroom: %u)\n",
146			    skb->len, skb_headroom(skb));
147		fallthrough;
148	case 0:
149		mwifiex_write_data_complete(adapter, skb, 0, ret);
150		break;
151	default:
152		break;
153	}
154
155	return ret;
156}
157
158static int mwifiex_host_to_card(struct mwifiex_adapter *adapter,
159				struct sk_buff *skb,
160				struct mwifiex_tx_param *tx_param)
161{
162	struct txpd *local_tx_pd = NULL;
163	u8 *head_ptr = skb->data;
164	int ret = 0;
165	struct mwifiex_private *priv;
166	struct mwifiex_txinfo *tx_info;
167
168	tx_info = MWIFIEX_SKB_TXCB(skb);
169	priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
170				      tx_info->bss_type);
171	if (!priv) {
172		mwifiex_dbg(adapter, ERROR,
173			    "data: priv not found. Drop TX packet\n");
174		adapter->dbg.num_tx_host_to_card_failure++;
175		mwifiex_write_data_complete(adapter, skb, 0, 0);
176		return ret;
177	}
178	if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
179		local_tx_pd = (struct txpd *)(head_ptr + adapter->intf_hdr_len);
180
181	if (adapter->iface_type == MWIFIEX_USB) {
182		ret = adapter->if_ops.host_to_card(adapter,
183						   priv->usb_port,
184						   skb, tx_param);
185	} else {
186		ret = adapter->if_ops.host_to_card(adapter,
187						   MWIFIEX_TYPE_DATA,
188						   skb, tx_param);
189	}
190	switch (ret) {
191	case -ENOSR:
192		mwifiex_dbg(adapter, ERROR, "data: -ENOSR is returned\n");
193		break;
194	case -EBUSY:
195		if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
196		    (adapter->pps_uapsd_mode) &&
197		    (adapter->tx_lock_flag)) {
198			priv->adapter->tx_lock_flag = false;
199			if (local_tx_pd)
200				local_tx_pd->flags = 0;
201		}
202		skb_queue_head(&adapter->tx_data_q, skb);
203		if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
204			atomic_add(tx_info->aggr_num, &adapter->tx_queued);
205		else
206			atomic_inc(&adapter->tx_queued);
207		mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
208		break;
209	case -1:
210		mwifiex_dbg(adapter, ERROR,
211			    "mwifiex_write_data_async failed: 0x%X\n", ret);
212		adapter->dbg.num_tx_host_to_card_failure++;
213		mwifiex_write_data_complete(adapter, skb, 0, ret);
214		break;
215	case -EINPROGRESS:
216		break;
217	case 0:
218		mwifiex_write_data_complete(adapter, skb, 0, ret);
219		break;
220	default:
221		break;
222	}
223	return ret;
224}
225
226static int
227mwifiex_dequeue_tx_queue(struct mwifiex_adapter *adapter)
228{
229	struct sk_buff *skb, *skb_next;
230	struct mwifiex_txinfo *tx_info;
231	struct mwifiex_tx_param tx_param;
232
233	skb = skb_dequeue(&adapter->tx_data_q);
234	if (!skb)
235		return -1;
236
237	tx_info = MWIFIEX_SKB_TXCB(skb);
238	if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
239		atomic_sub(tx_info->aggr_num, &adapter->tx_queued);
240	else
241		atomic_dec(&adapter->tx_queued);
242
243	if (!skb_queue_empty(&adapter->tx_data_q))
244		skb_next = skb_peek(&adapter->tx_data_q);
245	else
246		skb_next = NULL;
247	tx_param.next_pkt_len = ((skb_next) ? skb_next->len : 0);
248	if (!tx_param.next_pkt_len) {
249		if (!mwifiex_wmm_lists_empty(adapter))
250			tx_param.next_pkt_len = 1;
251	}
252	return mwifiex_host_to_card(adapter, skb, &tx_param);
253}
254
255void
256mwifiex_process_tx_queue(struct mwifiex_adapter *adapter)
257{
258	do {
259		if (adapter->data_sent || adapter->tx_lock_flag)
260			break;
261		if (mwifiex_dequeue_tx_queue(adapter))
262			break;
263	} while (!skb_queue_empty(&adapter->tx_data_q));
264}
265
266/*
267 * Packet send completion callback handler.
268 *
269 * It either frees the buffer directly or forwards it to another
270 * completion callback which checks conditions, updates statistics,
271 * wakes up stalled traffic queue if required, and then frees the buffer.
272 */
273int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
274				struct sk_buff *skb, int aggr, int status)
275{
276	struct mwifiex_private *priv;
277	struct mwifiex_txinfo *tx_info;
278	struct netdev_queue *txq;
279	int index;
280
281	if (!skb)
282		return 0;
283
284	tx_info = MWIFIEX_SKB_TXCB(skb);
285	priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
286				      tx_info->bss_type);
287	if (!priv)
288		goto done;
289
290	mwifiex_set_trans_start(priv->netdev);
291
292	if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
293		atomic_dec_return(&adapter->pending_bridged_pkts);
294
295	if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
296		goto done;
297
298	if (!status) {
299		priv->stats.tx_packets++;
300		priv->stats.tx_bytes += tx_info->pkt_len;
301		if (priv->tx_timeout_cnt)
302			priv->tx_timeout_cnt = 0;
303	} else {
304		priv->stats.tx_errors++;
305	}
306
307	if (aggr)
308		/* For skb_aggr, do not wake up tx queue */
309		goto done;
310
311	atomic_dec(&adapter->tx_pending);
312
313	index = mwifiex_1d_to_wmm_queue[skb->priority];
314	if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) {
315		txq = netdev_get_tx_queue(priv->netdev, index);
316		if (netif_tx_queue_stopped(txq)) {
317			netif_tx_wake_queue(txq);
318			mwifiex_dbg(adapter, DATA, "wake queue: %d\n", index);
319		}
320	}
321done:
322	dev_kfree_skb_any(skb);
323
324	return 0;
325}
326EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);
327
328void mwifiex_parse_tx_status_event(struct mwifiex_private *priv,
329				   void *event_body)
330{
331	struct tx_status_event *tx_status = (void *)priv->adapter->event_body;
332	struct sk_buff *ack_skb;
333	struct mwifiex_txinfo *tx_info;
334
335	if (!tx_status->tx_token_id)
336		return;
337
338	spin_lock_bh(&priv->ack_status_lock);
339	ack_skb = idr_remove(&priv->ack_status_frames, tx_status->tx_token_id);
340	spin_unlock_bh(&priv->ack_status_lock);
341
342	if (ack_skb) {
343		tx_info = MWIFIEX_SKB_TXCB(ack_skb);
344
345		if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS) {
346			/* consumes ack_skb */
347			skb_complete_wifi_ack(ack_skb, !tx_status->status);
348		} else {
349			/* Remove broadcast address which was added by driver */
350			memmove(ack_skb->data +
351				sizeof(struct ieee80211_hdr_3addr) +
352				MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16),
353				ack_skb->data +
354				sizeof(struct ieee80211_hdr_3addr) +
355				MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16) +
356				ETH_ALEN, ack_skb->len -
357				(sizeof(struct ieee80211_hdr_3addr) +
358				MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16) +
359				ETH_ALEN));
360			ack_skb->len = ack_skb->len - ETH_ALEN;
361			/* Remove driver's proprietary header including 2 bytes
362			 * of packet length and pass actual management frame buffer
363			 * to cfg80211.
364			 */
365			cfg80211_mgmt_tx_status(&priv->wdev, tx_info->cookie,
366						ack_skb->data +
367						MWIFIEX_MGMT_FRAME_HEADER_SIZE +
368						sizeof(u16), ack_skb->len -
369						(MWIFIEX_MGMT_FRAME_HEADER_SIZE
370						 + sizeof(u16)),
371						!tx_status->status, GFP_ATOMIC);
372			dev_kfree_skb_any(ack_skb);
373		}
374	}
375}
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * NXP Wireless LAN device driver: generic TX/RX data handling
  4 *
  5 * Copyright 2011-2020 NXP
  6 */
  7
  8#include "decl.h"
  9#include "ioctl.h"
 10#include "util.h"
 11#include "fw.h"
 12#include "main.h"
 13#include "wmm.h"
 14
 15/*
 16 * This function processes the received buffer.
 17 *
 18 * Main responsibility of this function is to parse the RxPD to
 19 * identify the correct interface this packet is headed for and
 20 * forwarding it to the associated handling function, where the
 21 * packet will be further processed and sent to kernel/upper layer
 22 * if required.
 23 */
 24int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
 25			     struct sk_buff *skb)
 26{
 27	struct mwifiex_private *priv =
 28		mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
 29	struct rxpd *local_rx_pd;
 30	struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
 31	int ret;
 32
 33	local_rx_pd = (struct rxpd *) (skb->data);
 34	/* Get the BSS number from rxpd, get corresponding priv */
 35	priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num &
 36				      BSS_NUM_MASK, local_rx_pd->bss_type);
 37	if (!priv)
 38		priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
 39
 40	if (!priv) {
 41		mwifiex_dbg(adapter, ERROR,
 42			    "data: priv not found. Drop RX packet\n");
 43		dev_kfree_skb_any(skb);
 44		return -1;
 45	}
 46
 47	mwifiex_dbg_dump(adapter, DAT_D, "rx pkt:", skb->data,
 48			 min_t(size_t, skb->len, DEBUG_DUMP_DATA_MAX_LEN));
 49
 50	memset(rx_info, 0, sizeof(*rx_info));
 51	rx_info->bss_num = priv->bss_num;
 52	rx_info->bss_type = priv->bss_type;
 53
 54	if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
 55		ret = mwifiex_process_uap_rx_packet(priv, skb);
 56	else
 57		ret = mwifiex_process_sta_rx_packet(priv, skb);
 58
 59	return ret;
 60}
 61EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
 62
 63/*
 64 * This function sends a packet to device.
 65 *
 66 * It processes the packet to add the TxPD, checks condition and
 67 * sends the processed packet to firmware for transmission.
 68 *
 69 * On successful completion, the function calls the completion callback
 70 * and logs the time.
 71 */
 72int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
 73		       struct mwifiex_tx_param *tx_param)
 74{
 75	int hroom, ret = -1;
 76	struct mwifiex_adapter *adapter = priv->adapter;
 77	u8 *head_ptr;
 78	struct txpd *local_tx_pd = NULL;
 79	struct mwifiex_sta_node *dest_node;
 80	struct ethhdr *hdr = (void *)skb->data;
 81
 
 
 
 
 
 
 82	hroom = adapter->intf_hdr_len;
 83
 84	if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) {
 85		dest_node = mwifiex_get_sta_entry(priv, hdr->h_dest);
 86		if (dest_node) {
 87			dest_node->stats.tx_bytes += skb->len;
 88			dest_node->stats.tx_packets++;
 89		}
 90
 91		head_ptr = mwifiex_process_uap_txpd(priv, skb);
 92	} else {
 93		head_ptr = mwifiex_process_sta_txpd(priv, skb);
 94	}
 95
 96	if ((adapter->data_sent || adapter->tx_lock_flag) && head_ptr) {
 97		skb_queue_tail(&adapter->tx_data_q, skb);
 98		atomic_inc(&adapter->tx_queued);
 99		return 0;
100	}
101
102	if (head_ptr) {
103		if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
104			local_tx_pd = (struct txpd *)(head_ptr + hroom);
105		if (adapter->iface_type == MWIFIEX_USB) {
106			ret = adapter->if_ops.host_to_card(adapter,
107							   priv->usb_port,
108							   skb, tx_param);
109		} else {
110			ret = adapter->if_ops.host_to_card(adapter,
111							   MWIFIEX_TYPE_DATA,
112							   skb, tx_param);
113		}
114	}
115	mwifiex_dbg_dump(adapter, DAT_D, "tx pkt:", skb->data,
116			 min_t(size_t, skb->len, DEBUG_DUMP_DATA_MAX_LEN));
117
118	switch (ret) {
119	case -ENOSR:
120		mwifiex_dbg(adapter, DATA, "data: -ENOSR is returned\n");
121		break;
122	case -EBUSY:
123		if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
124		    (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
125				priv->adapter->tx_lock_flag = false;
126				if (local_tx_pd)
127					local_tx_pd->flags = 0;
128		}
129		mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
130		break;
131	case -1:
132		mwifiex_dbg(adapter, ERROR,
133			    "mwifiex_write_data_async failed: 0x%X\n",
134			    ret);
135		adapter->dbg.num_tx_host_to_card_failure++;
136		mwifiex_write_data_complete(adapter, skb, 0, ret);
137		break;
138	case -EINPROGRESS:
139		break;
 
 
 
 
 
140	case 0:
141		mwifiex_write_data_complete(adapter, skb, 0, ret);
142		break;
143	default:
144		break;
145	}
146
147	return ret;
148}
149
150static int mwifiex_host_to_card(struct mwifiex_adapter *adapter,
151				struct sk_buff *skb,
152				struct mwifiex_tx_param *tx_param)
153{
154	struct txpd *local_tx_pd = NULL;
155	u8 *head_ptr = skb->data;
156	int ret = 0;
157	struct mwifiex_private *priv;
158	struct mwifiex_txinfo *tx_info;
159
160	tx_info = MWIFIEX_SKB_TXCB(skb);
161	priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
162				      tx_info->bss_type);
163	if (!priv) {
164		mwifiex_dbg(adapter, ERROR,
165			    "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);
168		return ret;
169	}
170	if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
171		local_tx_pd = (struct txpd *)(head_ptr + adapter->intf_hdr_len);
172
173	if (adapter->iface_type == MWIFIEX_USB) {
174		ret = adapter->if_ops.host_to_card(adapter,
175						   priv->usb_port,
176						   skb, tx_param);
177	} else {
178		ret = adapter->if_ops.host_to_card(adapter,
179						   MWIFIEX_TYPE_DATA,
180						   skb, tx_param);
181	}
182	switch (ret) {
183	case -ENOSR:
184		mwifiex_dbg(adapter, ERROR, "data: -ENOSR is returned\n");
185		break;
186	case -EBUSY:
187		if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
188		    (adapter->pps_uapsd_mode) &&
189		    (adapter->tx_lock_flag)) {
190			priv->adapter->tx_lock_flag = false;
191			if (local_tx_pd)
192				local_tx_pd->flags = 0;
193		}
194		skb_queue_head(&adapter->tx_data_q, skb);
195		if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
196			atomic_add(tx_info->aggr_num, &adapter->tx_queued);
197		else
198			atomic_inc(&adapter->tx_queued);
199		mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
200		break;
201	case -1:
202		mwifiex_dbg(adapter, ERROR,
203			    "mwifiex_write_data_async failed: 0x%X\n", ret);
204		adapter->dbg.num_tx_host_to_card_failure++;
205		mwifiex_write_data_complete(adapter, skb, 0, ret);
206		break;
207	case -EINPROGRESS:
208		break;
209	case 0:
210		mwifiex_write_data_complete(adapter, skb, 0, ret);
211		break;
212	default:
213		break;
214	}
215	return ret;
216}
217
218static int
219mwifiex_dequeue_tx_queue(struct mwifiex_adapter *adapter)
220{
221	struct sk_buff *skb, *skb_next;
222	struct mwifiex_txinfo *tx_info;
223	struct mwifiex_tx_param tx_param;
224
225	skb = skb_dequeue(&adapter->tx_data_q);
226	if (!skb)
227		return -1;
228
229	tx_info = MWIFIEX_SKB_TXCB(skb);
230	if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
231		atomic_sub(tx_info->aggr_num, &adapter->tx_queued);
232	else
233		atomic_dec(&adapter->tx_queued);
234
235	if (!skb_queue_empty(&adapter->tx_data_q))
236		skb_next = skb_peek(&adapter->tx_data_q);
237	else
238		skb_next = NULL;
239	tx_param.next_pkt_len = ((skb_next) ? skb_next->len : 0);
240	if (!tx_param.next_pkt_len) {
241		if (!mwifiex_wmm_lists_empty(adapter))
242			tx_param.next_pkt_len = 1;
243	}
244	return mwifiex_host_to_card(adapter, skb, &tx_param);
245}
246
247void
248mwifiex_process_tx_queue(struct mwifiex_adapter *adapter)
249{
250	do {
251		if (adapter->data_sent || adapter->tx_lock_flag)
252			break;
253		if (mwifiex_dequeue_tx_queue(adapter))
254			break;
255	} while (!skb_queue_empty(&adapter->tx_data_q));
256}
257
258/*
259 * Packet send completion callback handler.
260 *
261 * It either frees the buffer directly or forwards it to another
262 * completion callback which checks conditions, updates statistics,
263 * wakes up stalled traffic queue if required, and then frees the buffer.
264 */
265int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
266				struct sk_buff *skb, int aggr, int status)
267{
268	struct mwifiex_private *priv;
269	struct mwifiex_txinfo *tx_info;
270	struct netdev_queue *txq;
271	int index;
272
273	if (!skb)
274		return 0;
275
276	tx_info = MWIFIEX_SKB_TXCB(skb);
277	priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
278				      tx_info->bss_type);
279	if (!priv)
280		goto done;
281
282	mwifiex_set_trans_start(priv->netdev);
283
284	if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
285		atomic_dec_return(&adapter->pending_bridged_pkts);
286
287	if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
288		goto done;
289
290	if (!status) {
291		priv->stats.tx_packets++;
292		priv->stats.tx_bytes += tx_info->pkt_len;
293		if (priv->tx_timeout_cnt)
294			priv->tx_timeout_cnt = 0;
295	} else {
296		priv->stats.tx_errors++;
297	}
298
299	if (aggr)
300		/* For skb_aggr, do not wake up tx queue */
301		goto done;
302
303	atomic_dec(&adapter->tx_pending);
304
305	index = mwifiex_1d_to_wmm_queue[skb->priority];
306	if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) {
307		txq = netdev_get_tx_queue(priv->netdev, index);
308		if (netif_tx_queue_stopped(txq)) {
309			netif_tx_wake_queue(txq);
310			mwifiex_dbg(adapter, DATA, "wake queue: %d\n", index);
311		}
312	}
313done:
314	dev_kfree_skb_any(skb);
315
316	return 0;
317}
318EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);
319
320void mwifiex_parse_tx_status_event(struct mwifiex_private *priv,
321				   void *event_body)
322{
323	struct tx_status_event *tx_status = (void *)priv->adapter->event_body;
324	struct sk_buff *ack_skb;
325	struct mwifiex_txinfo *tx_info;
326
327	if (!tx_status->tx_token_id)
328		return;
329
330	spin_lock_bh(&priv->ack_status_lock);
331	ack_skb = idr_remove(&priv->ack_status_frames, tx_status->tx_token_id);
332	spin_unlock_bh(&priv->ack_status_lock);
333
334	if (ack_skb) {
335		tx_info = MWIFIEX_SKB_TXCB(ack_skb);
336
337		if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS) {
338			/* consumes ack_skb */
339			skb_complete_wifi_ack(ack_skb, !tx_status->status);
340		} else {
341			/* Remove broadcast address which was added by driver */
342			memmove(ack_skb->data +
343				sizeof(struct ieee80211_hdr_3addr) +
344				MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16),
345				ack_skb->data +
346				sizeof(struct ieee80211_hdr_3addr) +
347				MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16) +
348				ETH_ALEN, ack_skb->len -
349				(sizeof(struct ieee80211_hdr_3addr) +
350				MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16) +
351				ETH_ALEN));
352			ack_skb->len = ack_skb->len - ETH_ALEN;
353			/* Remove driver's proprietary header including 2 bytes
354			 * of packet length and pass actual management frame buffer
355			 * to cfg80211.
356			 */
357			cfg80211_mgmt_tx_status(&priv->wdev, tx_info->cookie,
358						ack_skb->data +
359						MWIFIEX_MGMT_FRAME_HEADER_SIZE +
360						sizeof(u16), ack_skb->len -
361						(MWIFIEX_MGMT_FRAME_HEADER_SIZE
362						 + sizeof(u16)),
363						!tx_status->status, GFP_ATOMIC);
364			dev_kfree_skb_any(ack_skb);
365		}
366	}
367}