File Index
Files and directories
Sign in
FILE

sta_tx.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/wireless/marvell/mwifiex/sta_tx.c C
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * NXP Wireless LAN device driver: station TX 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 fills the TxPD for tx packets.
 17 *
 18 * The Tx buffer received by this function should already have the
 19 * header space allocated for TxPD.
 20 *
 21 * This function inserts the TxPD in between interface header and actual
 22 * data and adjusts the buffer pointers accordingly.
 23 *
 24 * The following TxPD fields are set by this function, as required -
 25 *      - BSS number
 26 *      - Tx packet length and offset
 27 *      - Priority
 28 *      - Packet delay
 29 *      - Priority specific Tx control
 30 *      - Flags
 31 */
 32void mwifiex_process_sta_txpd(struct mwifiex_private *priv,
 33			      struct sk_buff *skb)
 34{
 35	struct mwifiex_adapter *adapter = priv->adapter;
 36	struct txpd *local_tx_pd;
 37	struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
 38	unsigned int pad;
 39	u16 pkt_type, pkt_length, pkt_offset;
 40	int hroom = adapter->intf_hdr_len;
 41
 42	pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
 43
 44	pad = ((uintptr_t)skb->data - (sizeof(*local_tx_pd) + hroom)) &
 45	       (MWIFIEX_DMA_ALIGN_SZ - 1);
 46	skb_push(skb, sizeof(*local_tx_pd) + pad);
 47
 48	local_tx_pd = (struct txpd *) skb->data;
 49	memset(local_tx_pd, 0, sizeof(struct txpd));
 50	local_tx_pd->bss_num = priv->bss_num;
 51	local_tx_pd->bss_type = priv->bss_type;
 52	pkt_length = (u16)(skb->len - (sizeof(struct txpd) + pad));
 53	if (pkt_type == PKT_TYPE_MGMT)
 54		pkt_length -= MWIFIEX_MGMT_FRAME_HEADER_SIZE;
 55	local_tx_pd->tx_pkt_length = cpu_to_le16(pkt_length);
 56
 57	local_tx_pd->priority = (u8) skb->priority;
 58	local_tx_pd->pkt_delay_2ms =
 59				mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
 60
 61	if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS ||
 62	    tx_info->flags & MWIFIEX_BUF_FLAG_ACTION_TX_STATUS) {
 63		local_tx_pd->tx_token_id = tx_info->ack_frame_id;
 64		local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS;
 65	}
 66
 67	if (local_tx_pd->priority <
 68	    ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
 69		/*
 70		 * Set the priority specific tx_control field, setting of 0 will
 71		 *   cause the default value to be used later in this function
 72		 */
 73		local_tx_pd->tx_control =
 74			cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd->
 75								   priority]);
 76
 77	if (adapter->pps_uapsd_mode) {
 78		if (mwifiex_check_last_packet_indication(priv)) {
 79			adapter->tx_lock_flag = true;
 80			local_tx_pd->flags =
 81				MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
 82		}
 83	}
 84
 85	if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
 86		local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
 87
 88	/* Offset of actual data */
 89	pkt_offset = sizeof(struct txpd) + pad;
 90	if (pkt_type == PKT_TYPE_MGMT) {
 91		/* Set the packet type and add header for management frame */
 92		local_tx_pd->tx_pkt_type = cpu_to_le16(pkt_type);
 93		pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
 94	}
 95
 96	local_tx_pd->tx_pkt_offset = cpu_to_le16(pkt_offset);
 97
 98	/* make space for adapter->intf_hdr_len */
 99	skb_push(skb, hroom);
100
101	if (!local_tx_pd->tx_control)
102		/* TxCtrl set by user or default */
103		local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
104}
105
106/*
107 * This function tells firmware to send a NULL data packet.
108 *
109 * The function creates a NULL data packet with TxPD and sends to the
110 * firmware for transmission, with highest priority setting.
111 */
112int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags)
113{
114	struct mwifiex_adapter *adapter = priv->adapter;
115	struct txpd *local_tx_pd;
116	struct mwifiex_tx_param tx_param;
117/* sizeof(struct txpd) + Interface specific header */
118#define NULL_PACKET_HDR 64
119	u32 data_len = NULL_PACKET_HDR;
120	struct sk_buff *skb;
121	int ret;
122	struct mwifiex_txinfo *tx_info = NULL;
123
124	if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags))
125		return -1;
126
127	if (!priv->media_connected)
128		return -1;
129
130	if (adapter->data_sent)
131		return -1;
132
133	if (adapter->if_ops.is_port_ready &&
134	    !adapter->if_ops.is_port_ready(priv))
135		return -1;
136
137	skb = dev_alloc_skb(data_len);
138	if (!skb)
139		return -1;
140
141	tx_info = MWIFIEX_SKB_TXCB(skb);
142	memset(tx_info, 0, sizeof(*tx_info));
143	tx_info->bss_num = priv->bss_num;
144	tx_info->bss_type = priv->bss_type;
145	tx_info->pkt_len = data_len -
146			(sizeof(struct txpd) + adapter->intf_hdr_len);
147	skb_reserve(skb, sizeof(struct txpd) + adapter->intf_hdr_len);
148	skb_push(skb, sizeof(struct txpd));
149
150	local_tx_pd = (struct txpd *) skb->data;
151	local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
152	local_tx_pd->flags = flags;
153	local_tx_pd->priority = WMM_HIGHEST_PRIORITY;
154	local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
155	local_tx_pd->bss_num = priv->bss_num;
156	local_tx_pd->bss_type = priv->bss_type;
157
158	skb_push(skb, adapter->intf_hdr_len);
159	if (adapter->iface_type == MWIFIEX_USB) {
160		ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
161						   skb, NULL);
162	} else {
163		tx_param.next_pkt_len = 0;
164		ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
165						   skb, &tx_param);
166	}
167	switch (ret) {
168	case -EBUSY:
169		dev_kfree_skb_any(skb);
170		mwifiex_dbg(adapter, ERROR,
171			    "%s: host_to_card failed: ret=%d\n",
172			    __func__, ret);
173		adapter->dbg.num_tx_host_to_card_failure++;
174		break;
175	case -1:
176		dev_kfree_skb_any(skb);
177		mwifiex_dbg(adapter, ERROR,
178			    "%s: host_to_card failed: ret=%d\n",
179			    __func__, ret);
180		adapter->dbg.num_tx_host_to_card_failure++;
181		break;
182	case 0:
183		dev_kfree_skb_any(skb);
184		mwifiex_dbg(adapter, DATA,
185			    "data: %s: host_to_card succeeded\n",
186			    __func__);
187		adapter->tx_lock_flag = true;
188		break;
189	case -EINPROGRESS:
190		adapter->tx_lock_flag = true;
191		break;
192	default:
193		break;
194	}
195
196	return ret;
197}
198
199/*
200 * This function checks if we need to send last packet indication.
201 */
202u8
203mwifiex_check_last_packet_indication(struct mwifiex_private *priv)
204{
205	struct mwifiex_adapter *adapter = priv->adapter;
206	u8 ret = false;
207
208	if (!adapter->sleep_period.period)
209		return ret;
210	if (mwifiex_wmm_lists_empty(adapter))
211			ret = true;
212
213	if (ret && !adapter->cmd_sent && !adapter->curr_cmd &&
214	    !is_command_pending(adapter)) {
215		adapter->delay_null_pkt = false;
216		ret = true;
217	} else {
218		ret = false;
219		adapter->delay_null_pkt = true;
220	}
221	return ret;
222}
~/ Read-only file preview.