mwifiex: add tdls_mgmt handler support
[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 *
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);
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;
131/* sizeof(struct txpd) + Interface specific header */
132#define NULL_PACKET_HDR 64
133 u32 data_len = NULL_PACKET_HDR;
270e58e8
YAP
134 struct sk_buff *skb;
135 int ret;
5e6e3a92
BZ
136 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);
9da9a3b2
YAP
152 tx_info->bss_num = priv->bss_num;
153 tx_info->bss_type = priv->bss_type;
a1ed4849 154 tx_info->pkt_len = data_len - (sizeof(struct txpd) + INTF_HEADER_LEN);
5e6e3a92
BZ
155 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
4daffe35
AK
166 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 }
5e6e3a92
BZ
174 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",
c65a30f3 181 __func__, ret);
5e6e3a92
BZ
182 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",
c65a30f3 187 __func__);
5e6e3a92
BZ
188 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;
5e6e3a92
BZ
207
208 if (!adapter->sleep_period.period)
209 return ret;
636c4598 210 if (mwifiex_wmm_lists_empty(adapter))
5e6e3a92 211 ret = true;
5e6e3a92 212
c65a30f3
YAP
213 if (ret && !adapter->cmd_sent && !adapter->curr_cmd &&
214 !is_command_pending(adapter)) {
5e6e3a92
BZ
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}
This page took 0.27391 seconds and 5 git commands to generate.