Commit | Line | Data |
---|---|---|
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 | */ | |
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); | |
84b313b3 | 50 | unsigned int pad; |
e39faa73 | 51 | u16 pkt_type, pkt_offset; |
84b313b3 XH |
52 | int hroom = (priv->adapter->iface_type == MWIFIEX_USB) ? 0 : |
53 | INTF_HEADER_LEN; | |
5e6e3a92 BZ |
54 | |
55 | if (!skb->len) { | |
acebe8c1 ZL |
56 | mwifiex_dbg(adapter, ERROR, |
57 | "Tx: bad packet length: %d\n", skb->len); | |
600f5d90 | 58 | tx_info->status_code = -1; |
5e6e3a92 BZ |
59 | return skb->data; |
60 | } | |
61 | ||
84b313b3 | 62 | BUG_ON(skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN); |
e39faa73 | 63 | |
84b313b3 | 64 | pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0; |
e156103c | 65 | |
84b313b3 XH |
66 | pad = ((void *)skb->data - (sizeof(*local_tx_pd) + hroom)- |
67 | NULL) & (MWIFIEX_DMA_ALIGN_SZ - 1); | |
e156103c | 68 | skb_push(skb, sizeof(*local_tx_pd) + pad); |
5e6e3a92 BZ |
69 | |
70 | local_tx_pd = (struct txpd *) skb->data; | |
71 | memset(local_tx_pd, 0, sizeof(struct txpd)); | |
72 | local_tx_pd->bss_num = priv->bss_num; | |
73 | local_tx_pd->bss_type = priv->bss_type; | |
c65a30f3 | 74 | local_tx_pd->tx_pkt_length = cpu_to_le16((u16)(skb->len - |
84b313b3 XH |
75 | (sizeof(struct txpd) + |
76 | pad))); | |
5e6e3a92 BZ |
77 | |
78 | local_tx_pd->priority = (u8) skb->priority; | |
79 | local_tx_pd->pkt_delay_2ms = | |
c65a30f3 | 80 | mwifiex_wmm_compute_drv_pkt_delay(priv, skb); |
5e6e3a92 | 81 | |
18ca4382 AK |
82 | if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS || |
83 | tx_info->flags & MWIFIEX_BUF_FLAG_ACTION_TX_STATUS) { | |
808bbebc AK |
84 | local_tx_pd->tx_token_id = tx_info->ack_frame_id; |
85 | local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_REQ_TX_STATUS; | |
86 | } | |
87 | ||
5e6e3a92 BZ |
88 | if (local_tx_pd->priority < |
89 | ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl)) | |
90 | /* | |
91 | * Set the priority specific tx_control field, setting of 0 will | |
92 | * cause the default value to be used later in this function | |
93 | */ | |
94 | local_tx_pd->tx_control = | |
95 | cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd-> | |
c65a30f3 | 96 | priority]); |
5e6e3a92 BZ |
97 | |
98 | if (adapter->pps_uapsd_mode) { | |
99 | if (mwifiex_check_last_packet_indication(priv)) { | |
100 | adapter->tx_lock_flag = true; | |
101 | local_tx_pd->flags = | |
102 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET; | |
103 | } | |
104 | } | |
105 | ||
b23bce29 AP |
106 | if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT) |
107 | local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET; | |
108 | ||
5e6e3a92 | 109 | /* Offset of actual data */ |
e39faa73 SP |
110 | pkt_offset = sizeof(struct txpd) + pad; |
111 | if (pkt_type == PKT_TYPE_MGMT) { | |
112 | /* Set the packet type and add header for management frame */ | |
113 | local_tx_pd->tx_pkt_type = cpu_to_le16(pkt_type); | |
114 | pkt_offset += MWIFIEX_MGMT_FRAME_HEADER_SIZE; | |
115 | } | |
116 | ||
117 | local_tx_pd->tx_pkt_offset = cpu_to_le16(pkt_offset); | |
5e6e3a92 BZ |
118 | |
119 | /* make space for INTF_HEADER_LEN */ | |
84b313b3 | 120 | skb_push(skb, hroom); |
5e6e3a92 BZ |
121 | |
122 | if (!local_tx_pd->tx_control) | |
123 | /* TxCtrl set by user or default */ | |
124 | local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl); | |
125 | ||
126 | return skb->data; | |
127 | } | |
128 | ||
129 | /* | |
130 | * This function tells firmware to send a NULL data packet. | |
131 | * | |
132 | * The function creates a NULL data packet with TxPD and sends to the | |
133 | * firmware for transmission, with highest priority setting. | |
134 | */ | |
135 | int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags) | |
136 | { | |
137 | struct mwifiex_adapter *adapter = priv->adapter; | |
138 | struct txpd *local_tx_pd; | |
8d767dcb | 139 | struct mwifiex_tx_param tx_param; |
5e6e3a92 BZ |
140 | /* sizeof(struct txpd) + Interface specific header */ |
141 | #define NULL_PACKET_HDR 64 | |
142 | u32 data_len = NULL_PACKET_HDR; | |
270e58e8 YAP |
143 | struct sk_buff *skb; |
144 | int ret; | |
5e6e3a92 BZ |
145 | struct mwifiex_txinfo *tx_info = NULL; |
146 | ||
147 | if (adapter->surprise_removed) | |
148 | return -1; | |
149 | ||
150 | if (!priv->media_connected) | |
151 | return -1; | |
152 | ||
153 | if (adapter->data_sent) | |
154 | return -1; | |
155 | ||
735ab6bf ZL |
156 | if (adapter->if_ops.is_port_ready && |
157 | !adapter->if_ops.is_port_ready(priv)) | |
158 | return -1; | |
159 | ||
5e6e3a92 BZ |
160 | skb = dev_alloc_skb(data_len); |
161 | if (!skb) | |
162 | return -1; | |
163 | ||
164 | tx_info = MWIFIEX_SKB_TXCB(skb); | |
701a9e61 | 165 | memset(tx_info, 0, sizeof(*tx_info)); |
9da9a3b2 YAP |
166 | tx_info->bss_num = priv->bss_num; |
167 | tx_info->bss_type = priv->bss_type; | |
a1ed4849 | 168 | tx_info->pkt_len = data_len - (sizeof(struct txpd) + INTF_HEADER_LEN); |
5e6e3a92 BZ |
169 | skb_reserve(skb, sizeof(struct txpd) + INTF_HEADER_LEN); |
170 | skb_push(skb, sizeof(struct txpd)); | |
171 | ||
172 | local_tx_pd = (struct txpd *) skb->data; | |
173 | local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl); | |
174 | local_tx_pd->flags = flags; | |
175 | local_tx_pd->priority = WMM_HIGHEST_PRIORITY; | |
176 | local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd)); | |
177 | local_tx_pd->bss_num = priv->bss_num; | |
178 | local_tx_pd->bss_type = priv->bss_type; | |
179 | ||
4daffe35 | 180 | if (adapter->iface_type == MWIFIEX_USB) { |
735ab6bf | 181 | ret = adapter->if_ops.host_to_card(adapter, priv->usb_port, |
4daffe35 AK |
182 | skb, NULL); |
183 | } else { | |
184 | skb_push(skb, INTF_HEADER_LEN); | |
8d767dcb | 185 | tx_param.next_pkt_len = 0; |
4daffe35 | 186 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA, |
8d767dcb | 187 | skb, &tx_param); |
4daffe35 | 188 | } |
5e6e3a92 BZ |
189 | switch (ret) { |
190 | case -EBUSY: | |
0ea3186c | 191 | dev_kfree_skb_any(skb); |
acebe8c1 ZL |
192 | mwifiex_dbg(adapter, ERROR, |
193 | "%s: host_to_card failed: ret=%d\n", | |
194 | __func__, ret); | |
0ea3186c AK |
195 | adapter->dbg.num_tx_host_to_card_failure++; |
196 | break; | |
5e6e3a92 BZ |
197 | case -1: |
198 | dev_kfree_skb_any(skb); | |
acebe8c1 ZL |
199 | mwifiex_dbg(adapter, ERROR, |
200 | "%s: host_to_card failed: ret=%d\n", | |
201 | __func__, ret); | |
5e6e3a92 BZ |
202 | adapter->dbg.num_tx_host_to_card_failure++; |
203 | break; | |
204 | case 0: | |
205 | dev_kfree_skb_any(skb); | |
acebe8c1 ZL |
206 | mwifiex_dbg(adapter, DATA, |
207 | "data: %s: host_to_card succeeded\n", | |
208 | __func__); | |
5e6e3a92 BZ |
209 | adapter->tx_lock_flag = true; |
210 | break; | |
211 | case -EINPROGRESS: | |
0ea3186c | 212 | adapter->tx_lock_flag = true; |
5e6e3a92 BZ |
213 | break; |
214 | default: | |
215 | break; | |
216 | } | |
217 | ||
218 | return ret; | |
219 | } | |
220 | ||
221 | /* | |
222 | * This function checks if we need to send last packet indication. | |
223 | */ | |
224 | u8 | |
225 | mwifiex_check_last_packet_indication(struct mwifiex_private *priv) | |
226 | { | |
227 | struct mwifiex_adapter *adapter = priv->adapter; | |
228 | u8 ret = false; | |
5e6e3a92 BZ |
229 | |
230 | if (!adapter->sleep_period.period) | |
231 | return ret; | |
636c4598 | 232 | if (mwifiex_wmm_lists_empty(adapter)) |
5e6e3a92 | 233 | ret = true; |
5e6e3a92 | 234 | |
c65a30f3 YAP |
235 | if (ret && !adapter->cmd_sent && !adapter->curr_cmd && |
236 | !is_command_pending(adapter)) { | |
5e6e3a92 BZ |
237 | adapter->delay_null_pkt = false; |
238 | ret = true; | |
239 | } else { | |
240 | ret = false; | |
241 | adapter->delay_null_pkt = true; | |
242 | } | |
243 | return ret; | |
244 | } |