blob: 1236a5de7bca833adfd0eab1ed6cce865047479b [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: station TX 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 fills the TxPD for tx packets.
29 *
30 * The Tx buffer received by this function should already have the
31 * header space allocated for TxPD.
32 *
33 * This function inserts the TxPD in between interface header and actual
34 * data and adjusts the buffer pointers accordingly.
35 *
36 * The following TxPD fields are set by this function, as required -
37 * - BSS number
38 * - Tx packet length and offset
39 * - Priority
40 * - Packet delay
41 * - Priority specific Tx control
42 * - Flags
43 */
44void *mwifiex_process_sta_txpd(struct mwifiex_private *priv,
45 struct sk_buff *skb)
46{
47 struct mwifiex_adapter *adapter = priv->adapter;
48 struct txpd *local_tx_pd;
49 struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
Yogesh Ashok Poware1561032011-07-07 17:37:09 -070050 u8 pad;
Stone Piaoe39faa72012-09-25 20:23:32 -070051 u16 pkt_type, pkt_offset;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070052
53 if (!skb->len) {
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -070054 dev_err(adapter->dev, "Tx: bad packet length: %d\n", skb->len);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070055 tx_info->status_code = -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070056 return skb->data;
57 }
58
Stone Piaoe39faa72012-09-25 20:23:32 -070059 pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
60
Yogesh Ashok Poware1561032011-07-07 17:37:09 -070061 /* If skb->data is not aligned; add padding */
62 pad = (4 - (((void *)skb->data - NULL) & 0x3)) % 4;
63
64 BUG_ON(skb_headroom(skb) < (sizeof(*local_tx_pd) + INTF_HEADER_LEN
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -070065 + pad));
Yogesh Ashok Poware1561032011-07-07 17:37:09 -070066 skb_push(skb, sizeof(*local_tx_pd) + pad);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070067
68 local_tx_pd = (struct txpd *) skb->data;
69 memset(local_tx_pd, 0, sizeof(struct txpd));
70 local_tx_pd->bss_num = priv->bss_num;
71 local_tx_pd->bss_type = priv->bss_type;
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -070072 local_tx_pd->tx_pkt_length = cpu_to_le16((u16)(skb->len -
73 (sizeof(struct txpd)
74 + pad)));
Bing Zhao5e6e3a92011-03-21 18:00:50 -070075
76 local_tx_pd->priority = (u8) skb->priority;
77 local_tx_pd->pkt_delay_2ms =
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -070078 mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070079
80 if (local_tx_pd->priority <
81 ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
82 /*
83 * Set the priority specific tx_control field, setting of 0 will
84 * cause the default value to be used later in this function
85 */
86 local_tx_pd->tx_control =
87 cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd->
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -070088 priority]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070089
90 if (adapter->pps_uapsd_mode) {
91 if (mwifiex_check_last_packet_indication(priv)) {
92 adapter->tx_lock_flag = true;
93 local_tx_pd->flags =
94 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
95 }
96 }
97
Avinash Patilb23bce22014-02-07 16:27:32 -080098 if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
99 local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
100
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700101 /* Offset of actual data */
Stone Piaoe39faa72012-09-25 20:23:32 -0700102 pkt_offset = sizeof(struct txpd) + pad;
103 if (pkt_type == PKT_TYPE_MGMT) {
104 /* Set the packet type and add header for management frame */
105 local_tx_pd->tx_pkt_type = cpu_to_le16(pkt_type);
106 pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
107 }
108
109 local_tx_pd->tx_pkt_offset = cpu_to_le16(pkt_offset);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700110
111 /* make space for INTF_HEADER_LEN */
112 skb_push(skb, INTF_HEADER_LEN);
113
114 if (!local_tx_pd->tx_control)
115 /* TxCtrl set by user or default */
116 local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
117
118 return skb->data;
119}
120
121/*
122 * This function tells firmware to send a NULL data packet.
123 *
124 * The function creates a NULL data packet with TxPD and sends to the
125 * firmware for transmission, with highest priority setting.
126 */
127int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags)
128{
129 struct mwifiex_adapter *adapter = priv->adapter;
130 struct txpd *local_tx_pd;
131/* sizeof(struct txpd) + Interface specific header */
132#define NULL_PACKET_HDR 64
133 u32 data_len = NULL_PACKET_HDR;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700134 struct sk_buff *skb;
135 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700136 struct mwifiex_txinfo *tx_info = NULL;
137
138 if (adapter->surprise_removed)
139 return -1;
140
141 if (!priv->media_connected)
142 return -1;
143
144 if (adapter->data_sent)
145 return -1;
146
147 skb = dev_alloc_skb(data_len);
148 if (!skb)
149 return -1;
150
151 tx_info = MWIFIEX_SKB_TXCB(skb);
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -0800152 tx_info->bss_num = priv->bss_num;
153 tx_info->bss_type = priv->bss_type;
Ujjal Roya1ed4842013-12-02 23:17:55 -0800154 tx_info->pkt_len = data_len - (sizeof(struct txpd) + INTF_HEADER_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700155 skb_reserve(skb, sizeof(struct txpd) + INTF_HEADER_LEN);
156 skb_push(skb, sizeof(struct txpd));
157
158 local_tx_pd = (struct txpd *) skb->data;
159 local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
160 local_tx_pd->flags = flags;
161 local_tx_pd->priority = WMM_HIGHEST_PRIORITY;
162 local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
163 local_tx_pd->bss_num = priv->bss_num;
164 local_tx_pd->bss_type = priv->bss_type;
165
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700166 if (adapter->iface_type == MWIFIEX_USB) {
167 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA,
168 skb, NULL);
169 } else {
170 skb_push(skb, INTF_HEADER_LEN);
171 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
172 skb, NULL);
173 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700174 switch (ret) {
175 case -EBUSY:
176 adapter->data_sent = true;
177 /* Fall through FAILURE handling */
178 case -1:
179 dev_kfree_skb_any(skb);
180 dev_err(adapter->dev, "%s: host_to_card failed: ret=%d\n",
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700181 __func__, ret);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700182 adapter->dbg.num_tx_host_to_card_failure++;
183 break;
184 case 0:
185 dev_kfree_skb_any(skb);
186 dev_dbg(adapter->dev, "data: %s: host_to_card succeeded\n",
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700187 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700188 adapter->tx_lock_flag = true;
189 break;
190 case -EINPROGRESS:
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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700207
208 if (!adapter->sleep_period.period)
209 return ret;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700210 if (mwifiex_wmm_lists_empty(adapter))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700211 ret = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700212
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700213 if (ret && !adapter->cmd_sent && !adapter->curr_cmd &&
214 !is_command_pending(adapter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700215 adapter->delay_null_pkt = false;
216 ret = true;
217 } else {
218 ret = false;
219 adapter->delay_null_pkt = true;
220 }
221 return ret;
222}