Merge branch 'for-linus2' of git://git.kernel.org/pub/scm/linux/kernel/git/mason...
[deliverable/linux.git] / drivers / net / wireless / mwifiex / sta_tx.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: station TX data handling
3 *
65da33f5 4 * Copyright (C) 2011-2014, Marvell International Ltd.
5e6e3a92
BZ
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);
e156103c 50 u8 pad;
e39faa73 51 u16 pkt_type, pkt_offset;
5e6e3a92
BZ
52
53 if (!skb->len) {
c65a30f3 54 dev_err(adapter->dev, "Tx: bad packet length: %d\n", skb->len);
600f5d90 55 tx_info->status_code = -1;
5e6e3a92
BZ
56 return skb->data;
57 }
58
e39faa73
SP
59 pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
60
e156103c
YAP
61 /* 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
c65a30f3 65 + pad));
e156103c 66 skb_push(skb, sizeof(*local_tx_pd) + pad);
5e6e3a92
BZ
67
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;
c65a30f3
YAP
72 local_tx_pd->tx_pkt_length = cpu_to_le16((u16)(skb->len -
73 (sizeof(struct txpd)
74 + pad)));
5e6e3a92
BZ
75
76 local_tx_pd->priority = (u8) skb->priority;
77 local_tx_pd->pkt_delay_2ms =
c65a30f3 78 mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
5e6e3a92
BZ
79
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->
c65a30f3 88 priority]);
5e6e3a92
BZ
89
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
b23bce29
AP
98 if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
99 local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
100
5e6e3a92 101 /* Offset of actual data */
e39faa73
SP
102 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);
5e6e3a92
BZ
110
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;
8d767dcb 131 struct mwifiex_tx_param tx_param;
5e6e3a92
BZ
132/* sizeof(struct txpd) + Interface specific header */
133#define NULL_PACKET_HDR 64
134 u32 data_len = NULL_PACKET_HDR;
270e58e8
YAP
135 struct sk_buff *skb;
136 int ret;
5e6e3a92
BZ
137 struct mwifiex_txinfo *tx_info = NULL;
138
139 if (adapter->surprise_removed)
140 return -1;
141
142 if (!priv->media_connected)
143 return -1;
144
145 if (adapter->data_sent)
146 return -1;
147
148 skb = dev_alloc_skb(data_len);
149 if (!skb)
150 return -1;
151
152 tx_info = MWIFIEX_SKB_TXCB(skb);
701a9e61 153 memset(tx_info, 0, sizeof(*tx_info));
9da9a3b2
YAP
154 tx_info->bss_num = priv->bss_num;
155 tx_info->bss_type = priv->bss_type;
a1ed4849 156 tx_info->pkt_len = data_len - (sizeof(struct txpd) + INTF_HEADER_LEN);
5e6e3a92
BZ
157 skb_reserve(skb, sizeof(struct txpd) + INTF_HEADER_LEN);
158 skb_push(skb, sizeof(struct txpd));
159
160 local_tx_pd = (struct txpd *) skb->data;
161 local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
162 local_tx_pd->flags = flags;
163 local_tx_pd->priority = WMM_HIGHEST_PRIORITY;
164 local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
165 local_tx_pd->bss_num = priv->bss_num;
166 local_tx_pd->bss_type = priv->bss_type;
167
4daffe35
AK
168 if (adapter->iface_type == MWIFIEX_USB) {
169 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA,
170 skb, NULL);
171 } else {
172 skb_push(skb, INTF_HEADER_LEN);
8d767dcb 173 tx_param.next_pkt_len = 0;
4daffe35 174 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
8d767dcb 175 skb, &tx_param);
4daffe35 176 }
5e6e3a92
BZ
177 switch (ret) {
178 case -EBUSY:
179 adapter->data_sent = true;
180 /* Fall through FAILURE handling */
181 case -1:
182 dev_kfree_skb_any(skb);
183 dev_err(adapter->dev, "%s: host_to_card failed: ret=%d\n",
c65a30f3 184 __func__, ret);
5e6e3a92
BZ
185 adapter->dbg.num_tx_host_to_card_failure++;
186 break;
187 case 0:
188 dev_kfree_skb_any(skb);
189 dev_dbg(adapter->dev, "data: %s: host_to_card succeeded\n",
c65a30f3 190 __func__);
5e6e3a92
BZ
191 adapter->tx_lock_flag = true;
192 break;
193 case -EINPROGRESS:
194 break;
195 default:
196 break;
197 }
198
199 return ret;
200}
201
202/*
203 * This function checks if we need to send last packet indication.
204 */
205u8
206mwifiex_check_last_packet_indication(struct mwifiex_private *priv)
207{
208 struct mwifiex_adapter *adapter = priv->adapter;
209 u8 ret = false;
5e6e3a92
BZ
210
211 if (!adapter->sleep_period.period)
212 return ret;
636c4598 213 if (mwifiex_wmm_lists_empty(adapter))
5e6e3a92 214 ret = true;
5e6e3a92 215
c65a30f3
YAP
216 if (ret && !adapter->cmd_sent && !adapter->curr_cmd &&
217 !is_command_pending(adapter)) {
5e6e3a92
BZ
218 adapter->delay_null_pkt = false;
219 ret = true;
220 } else {
221 ret = false;
222 adapter->delay_null_pkt = true;
223 }
224 return ret;
225}
This page took 0.289996 seconds and 5 git commands to generate.