xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/marvell/mwifiex/sta_tx.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * NXP Wireless LAN device driver: station TX data handling
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright 2011-2020 NXP
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * This software file (the "File") is distributed by NXP
7*4882a593Smuzhiyun  * under the terms of the GNU General Public License Version 2, June 1991
8*4882a593Smuzhiyun  * (the "License").  You may use, redistribute and/or modify this File in
9*4882a593Smuzhiyun  * accordance with the terms and conditions of the License, a copy of which
10*4882a593Smuzhiyun  * is available by writing to the Free Software Foundation, Inc.,
11*4882a593Smuzhiyun  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12*4882a593Smuzhiyun  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15*4882a593Smuzhiyun  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16*4882a593Smuzhiyun  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
17*4882a593Smuzhiyun  * this warranty disclaimer.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include "decl.h"
21*4882a593Smuzhiyun #include "ioctl.h"
22*4882a593Smuzhiyun #include "util.h"
23*4882a593Smuzhiyun #include "fw.h"
24*4882a593Smuzhiyun #include "main.h"
25*4882a593Smuzhiyun #include "wmm.h"
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /*
28*4882a593Smuzhiyun  * This function fills the TxPD for tx packets.
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * The Tx buffer received by this function should already have the
31*4882a593Smuzhiyun  * header space allocated for TxPD.
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * This function inserts the TxPD in between interface header and actual
34*4882a593Smuzhiyun  * data and adjusts the buffer pointers accordingly.
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * The following TxPD fields are set by this function, as required -
37*4882a593Smuzhiyun  *      - BSS number
38*4882a593Smuzhiyun  *      - Tx packet length and offset
39*4882a593Smuzhiyun  *      - Priority
40*4882a593Smuzhiyun  *      - Packet delay
41*4882a593Smuzhiyun  *      - Priority specific Tx control
42*4882a593Smuzhiyun  *      - Flags
43*4882a593Smuzhiyun  */
mwifiex_process_sta_txpd(struct mwifiex_private * priv,struct sk_buff * skb)44*4882a593Smuzhiyun void *mwifiex_process_sta_txpd(struct mwifiex_private *priv,
45*4882a593Smuzhiyun 				struct sk_buff *skb)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter = priv->adapter;
48*4882a593Smuzhiyun 	struct txpd *local_tx_pd;
49*4882a593Smuzhiyun 	struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
50*4882a593Smuzhiyun 	unsigned int pad;
51*4882a593Smuzhiyun 	u16 pkt_type, pkt_offset;
52*4882a593Smuzhiyun 	int hroom = adapter->intf_hdr_len;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	if (!skb->len) {
55*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
56*4882a593Smuzhiyun 			    "Tx: bad packet length: %d\n", skb->len);
57*4882a593Smuzhiyun 		tx_info->status_code = -1;
58*4882a593Smuzhiyun 		return skb->data;
59*4882a593Smuzhiyun 	}
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	BUG_ON(skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	pad = ((void *)skb->data - (sizeof(*local_tx_pd) + hroom)-
66*4882a593Smuzhiyun 			 NULL) & (MWIFIEX_DMA_ALIGN_SZ - 1);
67*4882a593Smuzhiyun 	skb_push(skb, sizeof(*local_tx_pd) + pad);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	local_tx_pd = (struct txpd *) skb->data;
70*4882a593Smuzhiyun 	memset(local_tx_pd, 0, sizeof(struct txpd));
71*4882a593Smuzhiyun 	local_tx_pd->bss_num = priv->bss_num;
72*4882a593Smuzhiyun 	local_tx_pd->bss_type = priv->bss_type;
73*4882a593Smuzhiyun 	local_tx_pd->tx_pkt_length = cpu_to_le16((u16)(skb->len -
74*4882a593Smuzhiyun 						       (sizeof(struct txpd) +
75*4882a593Smuzhiyun 							pad)));
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	local_tx_pd->priority = (u8) skb->priority;
78*4882a593Smuzhiyun 	local_tx_pd->pkt_delay_2ms =
79*4882a593Smuzhiyun 				mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS ||
82*4882a593Smuzhiyun 	    tx_info->flags & MWIFIEX_BUF_FLAG_ACTION_TX_STATUS) {
83*4882a593Smuzhiyun 		local_tx_pd->tx_token_id = tx_info->ack_frame_id;
84*4882a593Smuzhiyun 		local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS;
85*4882a593Smuzhiyun 	}
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun 	if (local_tx_pd->priority <
88*4882a593Smuzhiyun 	    ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
89*4882a593Smuzhiyun 		/*
90*4882a593Smuzhiyun 		 * Set the priority specific tx_control field, setting of 0 will
91*4882a593Smuzhiyun 		 *   cause the default value to be used later in this function
92*4882a593Smuzhiyun 		 */
93*4882a593Smuzhiyun 		local_tx_pd->tx_control =
94*4882a593Smuzhiyun 			cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd->
95*4882a593Smuzhiyun 								   priority]);
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun 	if (adapter->pps_uapsd_mode) {
98*4882a593Smuzhiyun 		if (mwifiex_check_last_packet_indication(priv)) {
99*4882a593Smuzhiyun 			adapter->tx_lock_flag = true;
100*4882a593Smuzhiyun 			local_tx_pd->flags =
101*4882a593Smuzhiyun 				MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
102*4882a593Smuzhiyun 		}
103*4882a593Smuzhiyun 	}
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 	if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
106*4882a593Smuzhiyun 		local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun 	/* Offset of actual data */
109*4882a593Smuzhiyun 	pkt_offset = sizeof(struct txpd) + pad;
110*4882a593Smuzhiyun 	if (pkt_type == PKT_TYPE_MGMT) {
111*4882a593Smuzhiyun 		/* Set the packet type and add header for management frame */
112*4882a593Smuzhiyun 		local_tx_pd->tx_pkt_type = cpu_to_le16(pkt_type);
113*4882a593Smuzhiyun 		pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
114*4882a593Smuzhiyun 	}
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	local_tx_pd->tx_pkt_offset = cpu_to_le16(pkt_offset);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 	/* make space for adapter->intf_hdr_len */
119*4882a593Smuzhiyun 	skb_push(skb, hroom);
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun 	if (!local_tx_pd->tx_control)
122*4882a593Smuzhiyun 		/* TxCtrl set by user or default */
123*4882a593Smuzhiyun 		local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun 	return skb->data;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun /*
129*4882a593Smuzhiyun  * This function tells firmware to send a NULL data packet.
130*4882a593Smuzhiyun  *
131*4882a593Smuzhiyun  * The function creates a NULL data packet with TxPD and sends to the
132*4882a593Smuzhiyun  * firmware for transmission, with highest priority setting.
133*4882a593Smuzhiyun  */
mwifiex_send_null_packet(struct mwifiex_private * priv,u8 flags)134*4882a593Smuzhiyun int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter = priv->adapter;
137*4882a593Smuzhiyun 	struct txpd *local_tx_pd;
138*4882a593Smuzhiyun 	struct mwifiex_tx_param tx_param;
139*4882a593Smuzhiyun /* sizeof(struct txpd) + Interface specific header */
140*4882a593Smuzhiyun #define NULL_PACKET_HDR 64
141*4882a593Smuzhiyun 	u32 data_len = NULL_PACKET_HDR;
142*4882a593Smuzhiyun 	struct sk_buff *skb;
143*4882a593Smuzhiyun 	int ret;
144*4882a593Smuzhiyun 	struct mwifiex_txinfo *tx_info = NULL;
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags))
147*4882a593Smuzhiyun 		return -1;
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun 	if (!priv->media_connected)
150*4882a593Smuzhiyun 		return -1;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	if (adapter->data_sent)
153*4882a593Smuzhiyun 		return -1;
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	if (adapter->if_ops.is_port_ready &&
156*4882a593Smuzhiyun 	    !adapter->if_ops.is_port_ready(priv))
157*4882a593Smuzhiyun 		return -1;
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	skb = dev_alloc_skb(data_len);
160*4882a593Smuzhiyun 	if (!skb)
161*4882a593Smuzhiyun 		return -1;
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun 	tx_info = MWIFIEX_SKB_TXCB(skb);
164*4882a593Smuzhiyun 	memset(tx_info, 0, sizeof(*tx_info));
165*4882a593Smuzhiyun 	tx_info->bss_num = priv->bss_num;
166*4882a593Smuzhiyun 	tx_info->bss_type = priv->bss_type;
167*4882a593Smuzhiyun 	tx_info->pkt_len = data_len -
168*4882a593Smuzhiyun 			(sizeof(struct txpd) + adapter->intf_hdr_len);
169*4882a593Smuzhiyun 	skb_reserve(skb, sizeof(struct txpd) + adapter->intf_hdr_len);
170*4882a593Smuzhiyun 	skb_push(skb, sizeof(struct txpd));
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun 	local_tx_pd = (struct txpd *) skb->data;
173*4882a593Smuzhiyun 	local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
174*4882a593Smuzhiyun 	local_tx_pd->flags = flags;
175*4882a593Smuzhiyun 	local_tx_pd->priority = WMM_HIGHEST_PRIORITY;
176*4882a593Smuzhiyun 	local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
177*4882a593Smuzhiyun 	local_tx_pd->bss_num = priv->bss_num;
178*4882a593Smuzhiyun 	local_tx_pd->bss_type = priv->bss_type;
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun 	skb_push(skb, adapter->intf_hdr_len);
181*4882a593Smuzhiyun 	if (adapter->iface_type == MWIFIEX_USB) {
182*4882a593Smuzhiyun 		ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
183*4882a593Smuzhiyun 						   skb, NULL);
184*4882a593Smuzhiyun 	} else {
185*4882a593Smuzhiyun 		tx_param.next_pkt_len = 0;
186*4882a593Smuzhiyun 		ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
187*4882a593Smuzhiyun 						   skb, &tx_param);
188*4882a593Smuzhiyun 	}
189*4882a593Smuzhiyun 	switch (ret) {
190*4882a593Smuzhiyun 	case -EBUSY:
191*4882a593Smuzhiyun 		dev_kfree_skb_any(skb);
192*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
193*4882a593Smuzhiyun 			    "%s: host_to_card failed: ret=%d\n",
194*4882a593Smuzhiyun 			    __func__, ret);
195*4882a593Smuzhiyun 		adapter->dbg.num_tx_host_to_card_failure++;
196*4882a593Smuzhiyun 		break;
197*4882a593Smuzhiyun 	case -1:
198*4882a593Smuzhiyun 		dev_kfree_skb_any(skb);
199*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
200*4882a593Smuzhiyun 			    "%s: host_to_card failed: ret=%d\n",
201*4882a593Smuzhiyun 			    __func__, ret);
202*4882a593Smuzhiyun 		adapter->dbg.num_tx_host_to_card_failure++;
203*4882a593Smuzhiyun 		break;
204*4882a593Smuzhiyun 	case 0:
205*4882a593Smuzhiyun 		dev_kfree_skb_any(skb);
206*4882a593Smuzhiyun 		mwifiex_dbg(adapter, DATA,
207*4882a593Smuzhiyun 			    "data: %s: host_to_card succeeded\n",
208*4882a593Smuzhiyun 			    __func__);
209*4882a593Smuzhiyun 		adapter->tx_lock_flag = true;
210*4882a593Smuzhiyun 		break;
211*4882a593Smuzhiyun 	case -EINPROGRESS:
212*4882a593Smuzhiyun 		adapter->tx_lock_flag = true;
213*4882a593Smuzhiyun 		break;
214*4882a593Smuzhiyun 	default:
215*4882a593Smuzhiyun 		break;
216*4882a593Smuzhiyun 	}
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun 	return ret;
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun /*
222*4882a593Smuzhiyun  * This function checks if we need to send last packet indication.
223*4882a593Smuzhiyun  */
224*4882a593Smuzhiyun u8
mwifiex_check_last_packet_indication(struct mwifiex_private * priv)225*4882a593Smuzhiyun mwifiex_check_last_packet_indication(struct mwifiex_private *priv)
226*4882a593Smuzhiyun {
227*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter = priv->adapter;
228*4882a593Smuzhiyun 	u8 ret = false;
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun 	if (!adapter->sleep_period.period)
231*4882a593Smuzhiyun 		return ret;
232*4882a593Smuzhiyun 	if (mwifiex_wmm_lists_empty(adapter))
233*4882a593Smuzhiyun 			ret = true;
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	if (ret && !adapter->cmd_sent && !adapter->curr_cmd &&
236*4882a593Smuzhiyun 	    !is_command_pending(adapter)) {
237*4882a593Smuzhiyun 		adapter->delay_null_pkt = false;
238*4882a593Smuzhiyun 		ret = true;
239*4882a593Smuzhiyun 	} else {
240*4882a593Smuzhiyun 		ret = false;
241*4882a593Smuzhiyun 		adapter->delay_null_pkt = true;
242*4882a593Smuzhiyun 	}
243*4882a593Smuzhiyun 	return ret;
244*4882a593Smuzhiyun }
245