Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: 802.11n Aggregation | |
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 | #include "11n.h" | |
27 | #include "11n_aggr.h" | |
28 | ||
29 | /* | |
30 | * Creates an AMSDU subframe for aggregation into one AMSDU packet. | |
31 | * | |
32 | * The resultant AMSDU subframe format is - | |
33 | * | |
34 | * +---- ~ -----+---- ~ ------+---- ~ -----+----- ~ -----+---- ~ -----+ | |
35 | * | DA | SA | Length | SNAP header | MSDU | | |
36 | * | data[0..5] | data[6..11] | | | data[14..] | | |
37 | * +---- ~ -----+---- ~ ------+---- ~ -----+----- ~ -----+---- ~ -----+ | |
38 | * <--6-bytes--> <--6-bytes--> <--2-bytes--><--8-bytes--> <--n-bytes--> | |
39 | * | |
40 | * This function also computes the amount of padding required to make the | |
41 | * buffer length multiple of 4 bytes. | |
42 | * | |
43 | * Data => |DA|SA|SNAP-TYPE|........ .| | |
44 | * MSDU => |DA|SA|Length|SNAP|...... ..| | |
45 | */ | |
46 | static int | |
572e8f3e | 47 | mwifiex_11n_form_amsdu_pkt(struct sk_buff *skb_aggr, |
5e6e3a92 BZ |
48 | struct sk_buff *skb_src, int *pad) |
49 | ||
50 | { | |
51 | int dt_offset; | |
52 | struct rfc_1042_hdr snap = { | |
53 | 0xaa, /* LLC DSAP */ | |
54 | 0xaa, /* LLC SSAP */ | |
55 | 0x03, /* LLC CTRL */ | |
56 | {0x00, 0x00, 0x00}, /* SNAP OUI */ | |
57 | 0x0000 /* SNAP type */ | |
58 | /* | |
59 | * This field will be overwritten | |
60 | * later with ethertype | |
61 | */ | |
62 | }; | |
270e58e8 | 63 | struct tx_packet_hdr *tx_header; |
5e6e3a92 | 64 | |
d92a6803 | 65 | tx_header = (void *)skb_put(skb_aggr, sizeof(*tx_header)); |
5e6e3a92 BZ |
66 | |
67 | /* Copy DA and SA */ | |
68 | dt_offset = 2 * ETH_ALEN; | |
69 | memcpy(&tx_header->eth803_hdr, skb_src->data, dt_offset); | |
70 | ||
71 | /* Copy SNAP header */ | |
a6efc5b7 AK |
72 | snap.snap_type = ((struct ethhdr *)skb_src->data)->h_proto; |
73 | ||
74 | dt_offset += sizeof(__be16); | |
5e6e3a92 BZ |
75 | |
76 | memcpy(&tx_header->rfc1042_hdr, &snap, sizeof(struct rfc_1042_hdr)); | |
77 | ||
78 | skb_pull(skb_src, dt_offset); | |
79 | ||
80 | /* Update Length field */ | |
81 | tx_header->eth803_hdr.h_proto = htons(skb_src->len + LLC_SNAP_LEN); | |
82 | ||
83 | /* Add payload */ | |
d92a6803 YAP |
84 | memcpy(skb_put(skb_aggr, skb_src->len), skb_src->data, skb_src->len); |
85 | ||
bda1b1b7 YAP |
86 | /* Add padding for new MSDU to start from 4 byte boundary */ |
87 | *pad = (4 - ((unsigned long)skb_aggr->tail & 0x3)) % 4; | |
5e6e3a92 BZ |
88 | |
89 | return skb_aggr->len + *pad; | |
90 | } | |
91 | ||
92 | /* | |
93 | * Adds TxPD to AMSDU header. | |
94 | * | |
95 | * Each AMSDU packet will contain one TxPD at the beginning, | |
96 | * followed by multiple AMSDU subframes. | |
97 | */ | |
98 | static void | |
99 | mwifiex_11n_form_amsdu_txpd(struct mwifiex_private *priv, | |
100 | struct sk_buff *skb) | |
101 | { | |
102 | struct txpd *local_tx_pd; | |
103 | ||
104 | skb_push(skb, sizeof(*local_tx_pd)); | |
105 | ||
106 | local_tx_pd = (struct txpd *) skb->data; | |
107 | memset(local_tx_pd, 0, sizeof(struct txpd)); | |
108 | ||
109 | /* Original priority has been overwritten */ | |
110 | local_tx_pd->priority = (u8) skb->priority; | |
111 | local_tx_pd->pkt_delay_2ms = | |
112 | mwifiex_wmm_compute_drv_pkt_delay(priv, skb); | |
113 | local_tx_pd->bss_num = priv->bss_num; | |
114 | local_tx_pd->bss_type = priv->bss_type; | |
115 | /* Always zero as the data is followed by struct txpd */ | |
116 | local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd)); | |
117 | local_tx_pd->tx_pkt_type = cpu_to_le16(PKT_TYPE_AMSDU); | |
118 | local_tx_pd->tx_pkt_length = cpu_to_le16(skb->len - | |
84266841 | 119 | sizeof(*local_tx_pd)); |
5e6e3a92 BZ |
120 | |
121 | if (local_tx_pd->tx_control == 0) | |
122 | /* TxCtrl set by user or default */ | |
123 | local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl); | |
124 | ||
84266841 YAP |
125 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA && |
126 | priv->adapter->pps_uapsd_mode) { | |
5e6e3a92 BZ |
127 | if (true == mwifiex_check_last_packet_indication(priv)) { |
128 | priv->adapter->tx_lock_flag = true; | |
129 | local_tx_pd->flags = | |
130 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET; | |
131 | } | |
132 | } | |
133 | } | |
134 | ||
5e6e3a92 BZ |
135 | /* |
136 | * Create aggregated packet. | |
137 | * | |
138 | * This function creates an aggregated MSDU packet, by combining buffers | |
139 | * from the RA list. Each individual buffer is encapsulated as an AMSDU | |
140 | * subframe and all such subframes are concatenated together to form the | |
141 | * AMSDU packet. | |
142 | * | |
143 | * A TxPD is also added to the front of the resultant AMSDU packets for | |
144 | * transmission. The resultant packets format is - | |
145 | * | |
146 | * +---- ~ ----+------ ~ ------+------ ~ ------+-..-+------ ~ ------+ | |
147 | * | TxPD |AMSDU sub-frame|AMSDU sub-frame| .. |AMSDU sub-frame| | |
148 | * | | 1 | 2 | .. | n | | |
149 | * +---- ~ ----+------ ~ ------+------ ~ ------+ .. +------ ~ ------+ | |
150 | */ | |
151 | int | |
152 | mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv, | |
bd1c6142 | 153 | struct mwifiex_ra_list_tbl *pra_list, |
5e6e3a92 BZ |
154 | int ptrindex, unsigned long ra_list_flags) |
155 | __releases(&priv->wmm.ra_list_spinlock) | |
156 | { | |
157 | struct mwifiex_adapter *adapter = priv->adapter; | |
158 | struct sk_buff *skb_aggr, *skb_src; | |
159 | struct mwifiex_txinfo *tx_info_aggr, *tx_info_src; | |
270e58e8 | 160 | int pad = 0, ret; |
5e6e3a92 BZ |
161 | struct mwifiex_tx_param tx_param; |
162 | struct txpd *ptx_pd = NULL; | |
5af3fae3 | 163 | struct timeval tv; |
bd1c6142 | 164 | int headroom = adapter->iface_type == MWIFIEX_USB ? 0 : INTF_HEADER_LEN; |
5e6e3a92 | 165 | |
a8fe3293 YAP |
166 | skb_src = skb_peek(&pra_list->skb_head); |
167 | if (!skb_src) { | |
5e6e3a92 BZ |
168 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
169 | ra_list_flags); | |
170 | return 0; | |
171 | } | |
a8fe3293 | 172 | |
5e6e3a92 BZ |
173 | tx_info_src = MWIFIEX_SKB_TXCB(skb_src); |
174 | skb_aggr = dev_alloc_skb(adapter->tx_buf_size); | |
175 | if (!skb_aggr) { | |
176 | dev_err(adapter->dev, "%s: alloc skb_aggr\n", __func__); | |
177 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
178 | ra_list_flags); | |
179 | return -1; | |
180 | } | |
181 | skb_reserve(skb_aggr, headroom + sizeof(struct txpd)); | |
182 | tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr); | |
183 | ||
9da9a3b2 YAP |
184 | tx_info_aggr->bss_type = tx_info_src->bss_type; |
185 | tx_info_aggr->bss_num = tx_info_src->bss_num; | |
5e6e3a92 BZ |
186 | skb_aggr->priority = skb_src->priority; |
187 | ||
5af3fae3 AP |
188 | do_gettimeofday(&tv); |
189 | skb_aggr->tstamp = timeval_to_ktime(tv); | |
190 | ||
fb3c19bc YAP |
191 | do { |
192 | /* Check if AMSDU can accommodate this MSDU */ | |
193 | if (skb_tailroom(skb_aggr) < (skb_src->len + LLC_SNAP_LEN)) | |
194 | break; | |
5e6e3a92 | 195 | |
a8fe3293 | 196 | skb_src = skb_dequeue(&pra_list->skb_head); |
5e6e3a92 | 197 | |
c7d9ed9e | 198 | pra_list->total_pkt_count--; |
5e6e3a92 | 199 | |
f699254c MY |
200 | atomic_dec(&priv->wmm.tx_pkts_queued); |
201 | ||
5e6e3a92 BZ |
202 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
203 | ra_list_flags); | |
572e8f3e | 204 | mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad); |
5e6e3a92 | 205 | |
47411a06 | 206 | mwifiex_write_data_complete(adapter, skb_src, 0, 0); |
5e6e3a92 BZ |
207 | |
208 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags); | |
209 | ||
210 | if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) { | |
211 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
212 | ra_list_flags); | |
213 | return -1; | |
214 | } | |
215 | ||
fb3c19bc YAP |
216 | if (skb_tailroom(skb_aggr) < pad) { |
217 | pad = 0; | |
218 | break; | |
219 | } | |
220 | skb_put(skb_aggr, pad); | |
221 | ||
a8fe3293 | 222 | skb_src = skb_peek(&pra_list->skb_head); |
fb3c19bc YAP |
223 | |
224 | } while (skb_src); | |
5e6e3a92 BZ |
225 | |
226 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags); | |
227 | ||
228 | /* Last AMSDU packet does not need padding */ | |
229 | skb_trim(skb_aggr, skb_aggr->len - pad); | |
230 | ||
231 | /* Form AMSDU */ | |
232 | mwifiex_11n_form_amsdu_txpd(priv, skb_aggr); | |
233 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) | |
234 | ptx_pd = (struct txpd *)skb_aggr->data; | |
235 | ||
236 | skb_push(skb_aggr, headroom); | |
237 | ||
4daffe35 AK |
238 | if (adapter->iface_type == MWIFIEX_USB) { |
239 | adapter->data_sent = true; | |
240 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA, | |
241 | skb_aggr, NULL); | |
242 | } else { | |
b2a13a25 AK |
243 | if (skb_src) |
244 | tx_param.next_pkt_len = | |
245 | skb_src->len + sizeof(struct txpd); | |
246 | else | |
247 | tx_param.next_pkt_len = 0; | |
4daffe35 AK |
248 | |
249 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA, | |
250 | skb_aggr, &tx_param); | |
251 | } | |
5e6e3a92 BZ |
252 | switch (ret) { |
253 | case -EBUSY: | |
254 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags); | |
255 | if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) { | |
256 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
257 | ra_list_flags); | |
47411a06 | 258 | mwifiex_write_data_complete(adapter, skb_aggr, 1, -1); |
5e6e3a92 BZ |
259 | return -1; |
260 | } | |
84266841 YAP |
261 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA && |
262 | adapter->pps_uapsd_mode && adapter->tx_lock_flag) { | |
5e6e3a92 | 263 | priv->adapter->tx_lock_flag = false; |
b53575ec CF |
264 | if (ptx_pd) |
265 | ptx_pd->flags = 0; | |
5e6e3a92 BZ |
266 | } |
267 | ||
268 | skb_queue_tail(&pra_list->skb_head, skb_aggr); | |
269 | ||
c7d9ed9e | 270 | pra_list->total_pkt_count++; |
5e6e3a92 | 271 | |
f699254c MY |
272 | atomic_inc(&priv->wmm.tx_pkts_queued); |
273 | ||
5e6e3a92 BZ |
274 | tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT; |
275 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
276 | ra_list_flags); | |
277 | dev_dbg(adapter->dev, "data: -EBUSY is returned\n"); | |
278 | break; | |
279 | case -1: | |
e7f767a7 AP |
280 | if (adapter->iface_type != MWIFIEX_PCIE) |
281 | adapter->data_sent = false; | |
5e6e3a92 | 282 | dev_err(adapter->dev, "%s: host_to_card failed: %#x\n", |
84266841 | 283 | __func__, ret); |
5e6e3a92 | 284 | adapter->dbg.num_tx_host_to_card_failure++; |
47411a06 | 285 | mwifiex_write_data_complete(adapter, skb_aggr, 1, ret); |
5e6e3a92 BZ |
286 | return 0; |
287 | case -EINPROGRESS: | |
e7f767a7 AP |
288 | if (adapter->iface_type != MWIFIEX_PCIE) |
289 | adapter->data_sent = false; | |
5e6e3a92 BZ |
290 | break; |
291 | case 0: | |
47411a06 | 292 | mwifiex_write_data_complete(adapter, skb_aggr, 1, ret); |
5e6e3a92 BZ |
293 | break; |
294 | default: | |
295 | break; | |
296 | } | |
297 | if (ret != -EBUSY) { | |
2e237319 | 298 | mwifiex_rotate_priolists(priv, pra_list, ptrindex); |
5e6e3a92 BZ |
299 | } |
300 | ||
301 | return 0; | |
302 | } |