mwifiex: add Tx status support for EAPOL packets
[deliverable/linux.git] / drivers / net / wireless / mwifiex / sta_tx.c
1 /*
2 * Marvell Wireless LAN device driver: station TX data handling
3 *
4 * Copyright (C) 2011-2014, 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 */
44 void *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);
50 u8 pad;
51 u16 pkt_type, pkt_offset;
52
53 if (!skb->len) {
54 dev_err(adapter->dev, "Tx: bad packet length: %d\n", skb->len);
55 tx_info->status_code = -1;
56 return skb->data;
57 }
58
59 pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0;
60
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
65 + pad));
66 skb_push(skb, sizeof(*local_tx_pd) + pad);
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;
72 local_tx_pd->tx_pkt_length = cpu_to_le16((u16)(skb->len -
73 (sizeof(struct txpd)
74 + pad)));
75
76 local_tx_pd->priority = (u8) skb->priority;
77 local_tx_pd->pkt_delay_2ms =
78 mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
79
80 if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS) {
81 local_tx_pd->tx_token_id = tx_info->ack_frame_id;
82 local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS;
83 }
84
85 if (local_tx_pd->priority <
86 ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl))
87 /*
88 * Set the priority specific tx_control field, setting of 0 will
89 * cause the default value to be used later in this function
90 */
91 local_tx_pd->tx_control =
92 cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd->
93 priority]);
94
95 if (adapter->pps_uapsd_mode) {
96 if (mwifiex_check_last_packet_indication(priv)) {
97 adapter->tx_lock_flag = true;
98 local_tx_pd->flags =
99 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
100 }
101 }
102
103 if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
104 local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
105
106 /* Offset of actual data */
107 pkt_offset = sizeof(struct txpd) + pad;
108 if (pkt_type == PKT_TYPE_MGMT) {
109 /* Set the packet type and add header for management frame */
110 local_tx_pd->tx_pkt_type = cpu_to_le16(pkt_type);
111 pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE;
112 }
113
114 local_tx_pd->tx_pkt_offset = cpu_to_le16(pkt_offset);
115
116 /* make space for INTF_HEADER_LEN */
117 skb_push(skb, INTF_HEADER_LEN);
118
119 if (!local_tx_pd->tx_control)
120 /* TxCtrl set by user or default */
121 local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
122
123 return skb->data;
124 }
125
126 /*
127 * This function tells firmware to send a NULL data packet.
128 *
129 * The function creates a NULL data packet with TxPD and sends to the
130 * firmware for transmission, with highest priority setting.
131 */
132 int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags)
133 {
134 struct mwifiex_adapter *adapter = priv->adapter;
135 struct txpd *local_tx_pd;
136 struct mwifiex_tx_param tx_param;
137 /* sizeof(struct txpd) + Interface specific header */
138 #define NULL_PACKET_HDR 64
139 u32 data_len = NULL_PACKET_HDR;
140 struct sk_buff *skb;
141 int ret;
142 struct mwifiex_txinfo *tx_info = NULL;
143
144 if (adapter->surprise_removed)
145 return -1;
146
147 if (!priv->media_connected)
148 return -1;
149
150 if (adapter->data_sent)
151 return -1;
152
153 skb = dev_alloc_skb(data_len);
154 if (!skb)
155 return -1;
156
157 tx_info = MWIFIEX_SKB_TXCB(skb);
158 memset(tx_info, 0, sizeof(*tx_info));
159 tx_info->bss_num = priv->bss_num;
160 tx_info->bss_type = priv->bss_type;
161 tx_info->pkt_len = data_len - (sizeof(struct txpd) + INTF_HEADER_LEN);
162 skb_reserve(skb, sizeof(struct txpd) + INTF_HEADER_LEN);
163 skb_push(skb, sizeof(struct txpd));
164
165 local_tx_pd = (struct txpd *) skb->data;
166 local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
167 local_tx_pd->flags = flags;
168 local_tx_pd->priority = WMM_HIGHEST_PRIORITY;
169 local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
170 local_tx_pd->bss_num = priv->bss_num;
171 local_tx_pd->bss_type = priv->bss_type;
172
173 if (adapter->iface_type == MWIFIEX_USB) {
174 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA,
175 skb, NULL);
176 } else {
177 skb_push(skb, INTF_HEADER_LEN);
178 tx_param.next_pkt_len = 0;
179 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
180 skb, &tx_param);
181 }
182 switch (ret) {
183 case -EBUSY:
184 adapter->data_sent = true;
185 /* Fall through FAILURE handling */
186 case -1:
187 dev_kfree_skb_any(skb);
188 dev_err(adapter->dev, "%s: host_to_card failed: ret=%d\n",
189 __func__, ret);
190 adapter->dbg.num_tx_host_to_card_failure++;
191 break;
192 case 0:
193 dev_kfree_skb_any(skb);
194 dev_dbg(adapter->dev, "data: %s: host_to_card succeeded\n",
195 __func__);
196 adapter->tx_lock_flag = true;
197 break;
198 case -EINPROGRESS:
199 break;
200 default:
201 break;
202 }
203
204 return ret;
205 }
206
207 /*
208 * This function checks if we need to send last packet indication.
209 */
210 u8
211 mwifiex_check_last_packet_indication(struct mwifiex_private *priv)
212 {
213 struct mwifiex_adapter *adapter = priv->adapter;
214 u8 ret = false;
215
216 if (!adapter->sleep_period.period)
217 return ret;
218 if (mwifiex_wmm_lists_empty(adapter))
219 ret = true;
220
221 if (ret && !adapter->cmd_sent && !adapter->curr_cmd &&
222 !is_command_pending(adapter)) {
223 adapter->delay_null_pkt = false;
224 ret = true;
225 } else {
226 ret = false;
227 adapter->delay_null_pkt = true;
228 }
229 return ret;
230 }
This page took 0.085001 seconds and 5 git commands to generate.