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 BZ |
64 | |
65 | skb_put(skb_aggr, sizeof(*tx_header)); | |
66 | ||
67 | tx_header = (struct tx_packet_hdr *) skb_aggr->data; | |
68 | ||
69 | /* Copy DA and SA */ | |
70 | dt_offset = 2 * ETH_ALEN; | |
71 | memcpy(&tx_header->eth803_hdr, skb_src->data, dt_offset); | |
72 | ||
73 | /* Copy SNAP header */ | |
74 | snap.snap_type = *(u16 *) ((u8 *)skb_src->data + dt_offset); | |
75 | dt_offset += sizeof(u16); | |
76 | ||
77 | memcpy(&tx_header->rfc1042_hdr, &snap, sizeof(struct rfc_1042_hdr)); | |
78 | ||
79 | skb_pull(skb_src, dt_offset); | |
80 | ||
81 | /* Update Length field */ | |
82 | tx_header->eth803_hdr.h_proto = htons(skb_src->len + LLC_SNAP_LEN); | |
83 | ||
84 | /* Add payload */ | |
85 | skb_put(skb_aggr, skb_src->len); | |
86 | memcpy(skb_aggr->data + sizeof(*tx_header), skb_src->data, | |
87 | skb_src->len); | |
88 | *pad = (((skb_src->len + LLC_SNAP_LEN) & 3)) ? (4 - (((skb_src->len + | |
89 | LLC_SNAP_LEN)) & 3)) : 0; | |
90 | skb_put(skb_aggr, *pad); | |
91 | ||
92 | return skb_aggr->len + *pad; | |
93 | } | |
94 | ||
95 | /* | |
96 | * Adds TxPD to AMSDU header. | |
97 | * | |
98 | * Each AMSDU packet will contain one TxPD at the beginning, | |
99 | * followed by multiple AMSDU subframes. | |
100 | */ | |
101 | static void | |
102 | mwifiex_11n_form_amsdu_txpd(struct mwifiex_private *priv, | |
103 | struct sk_buff *skb) | |
104 | { | |
105 | struct txpd *local_tx_pd; | |
106 | ||
107 | skb_push(skb, sizeof(*local_tx_pd)); | |
108 | ||
109 | local_tx_pd = (struct txpd *) skb->data; | |
110 | memset(local_tx_pd, 0, sizeof(struct txpd)); | |
111 | ||
112 | /* Original priority has been overwritten */ | |
113 | local_tx_pd->priority = (u8) skb->priority; | |
114 | local_tx_pd->pkt_delay_2ms = | |
115 | mwifiex_wmm_compute_drv_pkt_delay(priv, skb); | |
116 | local_tx_pd->bss_num = priv->bss_num; | |
117 | local_tx_pd->bss_type = priv->bss_type; | |
118 | /* Always zero as the data is followed by struct txpd */ | |
119 | local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd)); | |
120 | local_tx_pd->tx_pkt_type = cpu_to_le16(PKT_TYPE_AMSDU); | |
121 | local_tx_pd->tx_pkt_length = cpu_to_le16(skb->len - | |
122 | sizeof(*local_tx_pd)); | |
123 | ||
124 | if (local_tx_pd->tx_control == 0) | |
125 | /* TxCtrl set by user or default */ | |
126 | local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl); | |
127 | ||
128 | if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && | |
129 | (priv->adapter->pps_uapsd_mode)) { | |
130 | if (true == mwifiex_check_last_packet_indication(priv)) { | |
131 | priv->adapter->tx_lock_flag = true; | |
132 | local_tx_pd->flags = | |
133 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET; | |
134 | } | |
135 | } | |
136 | } | |
137 | ||
138 | /* | |
139 | * Counts the number of subframes in an aggregate packet. | |
140 | * | |
141 | * This function parses an aggregate packet buffer, looking for | |
142 | * subframes and counting the number of such subframe found. The | |
143 | * function automatically skips the DA/SA fields at the beginning | |
144 | * of each subframe and padding at the end. | |
145 | */ | |
146 | static int | |
147 | mwifiex_11n_get_num_aggr_pkts(u8 *data, int total_pkt_len) | |
148 | { | |
149 | int pkt_count = 0, pkt_len, pad; | |
150 | ||
151 | while (total_pkt_len > 0) { | |
152 | /* Length will be in network format, change it to host */ | |
153 | pkt_len = ntohs((*(__be16 *)(data + 2 * ETH_ALEN))); | |
154 | pad = (((pkt_len + sizeof(struct ethhdr)) & 3)) ? | |
155 | (4 - ((pkt_len + sizeof(struct ethhdr)) & 3)) : 0; | |
156 | data += pkt_len + pad + sizeof(struct ethhdr); | |
157 | total_pkt_len -= pkt_len + pad + sizeof(struct ethhdr); | |
158 | ++pkt_count; | |
159 | } | |
160 | ||
161 | return pkt_count; | |
162 | } | |
163 | ||
164 | /* | |
165 | * De-aggregate received packets. | |
166 | * | |
167 | * This function parses the received aggregate buffer, extracts each subframe, | |
168 | * strips off the SNAP header from them and sends the data portion for further | |
169 | * processing. | |
170 | * | |
171 | * Each subframe body is copied onto a separate buffer, which are freed by | |
172 | * upper layer after processing. The function also performs sanity tests on | |
173 | * the received buffer. | |
174 | */ | |
175 | int mwifiex_11n_deaggregate_pkt(struct mwifiex_private *priv, | |
176 | struct sk_buff *skb) | |
177 | { | |
178 | u16 pkt_len; | |
179 | int total_pkt_len; | |
180 | u8 *data; | |
181 | int pad; | |
182 | struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); | |
183 | struct rxpd *local_rx_pd = (struct rxpd *) skb->data; | |
184 | struct sk_buff *skb_daggr; | |
270e58e8 | 185 | struct mwifiex_rxinfo *rx_info_daggr; |
5e6e3a92 BZ |
186 | int ret = -1; |
187 | struct rx_packet_hdr *rx_pkt_hdr; | |
188 | struct mwifiex_adapter *adapter = priv->adapter; | |
189 | u8 rfc1042_eth_hdr[ETH_ALEN] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; | |
190 | ||
191 | data = (u8 *) (local_rx_pd + local_rx_pd->rx_pkt_offset); | |
192 | total_pkt_len = local_rx_pd->rx_pkt_length; | |
193 | ||
194 | /* Sanity test */ | |
195 | if (total_pkt_len > MWIFIEX_RX_DATA_BUF_SIZE) { | |
196 | dev_err(adapter->dev, "total pkt len greater than buffer" | |
197 | " size %d\n", total_pkt_len); | |
198 | return -1; | |
199 | } | |
200 | ||
201 | rx_info->use_count = mwifiex_11n_get_num_aggr_pkts(data, total_pkt_len); | |
202 | ||
203 | while (total_pkt_len > 0) { | |
204 | rx_pkt_hdr = (struct rx_packet_hdr *) data; | |
205 | /* Length will be in network format, change it to host */ | |
206 | pkt_len = ntohs((*(__be16 *) (data + 2 * ETH_ALEN))); | |
207 | if (pkt_len > total_pkt_len) { | |
208 | dev_err(adapter->dev, "pkt_len %d > total_pkt_len %d\n", | |
209 | total_pkt_len, pkt_len); | |
210 | break; | |
211 | } | |
212 | ||
213 | pad = (((pkt_len + sizeof(struct ethhdr)) & 3)) ? | |
214 | (4 - ((pkt_len + sizeof(struct ethhdr)) & 3)) : 0; | |
215 | ||
216 | total_pkt_len -= pkt_len + pad + sizeof(struct ethhdr); | |
217 | ||
218 | if (memcmp(&rx_pkt_hdr->rfc1042_hdr, | |
219 | rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)) == 0) { | |
220 | memmove(data + LLC_SNAP_LEN, data, 2 * ETH_ALEN); | |
221 | data += LLC_SNAP_LEN; | |
222 | pkt_len += sizeof(struct ethhdr) - LLC_SNAP_LEN; | |
223 | } else { | |
224 | *(u16 *) (data + 2 * ETH_ALEN) = (u16) 0; | |
225 | pkt_len += sizeof(struct ethhdr); | |
226 | } | |
227 | ||
228 | skb_daggr = dev_alloc_skb(pkt_len); | |
229 | if (!skb_daggr) { | |
230 | dev_err(adapter->dev, "%s: failed to alloc skb_daggr\n", | |
231 | __func__); | |
232 | return -1; | |
233 | } | |
234 | rx_info_daggr = MWIFIEX_SKB_RXCB(skb_daggr); | |
235 | ||
236 | rx_info_daggr->bss_index = rx_info->bss_index; | |
237 | skb_daggr->tstamp = skb->tstamp; | |
238 | rx_info_daggr->parent = skb; | |
239 | skb_daggr->priority = skb->priority; | |
240 | skb_put(skb_daggr, pkt_len); | |
241 | memcpy(skb_daggr->data, data, pkt_len); | |
242 | ||
243 | ret = mwifiex_recv_packet(adapter, skb_daggr); | |
244 | ||
245 | switch (ret) { | |
246 | case -EINPROGRESS: | |
247 | break; | |
248 | case -1: | |
249 | dev_err(adapter->dev, "deaggr: host_to_card failed\n"); | |
250 | case 0: | |
251 | mwifiex_recv_packet_complete(adapter, skb_daggr, ret); | |
252 | break; | |
253 | default: | |
254 | break; | |
255 | } | |
256 | ||
257 | data += pkt_len + pad; | |
258 | } | |
259 | ||
260 | return ret; | |
261 | } | |
262 | ||
263 | /* | |
264 | * Create aggregated packet. | |
265 | * | |
266 | * This function creates an aggregated MSDU packet, by combining buffers | |
267 | * from the RA list. Each individual buffer is encapsulated as an AMSDU | |
268 | * subframe and all such subframes are concatenated together to form the | |
269 | * AMSDU packet. | |
270 | * | |
271 | * A TxPD is also added to the front of the resultant AMSDU packets for | |
272 | * transmission. The resultant packets format is - | |
273 | * | |
274 | * +---- ~ ----+------ ~ ------+------ ~ ------+-..-+------ ~ ------+ | |
275 | * | TxPD |AMSDU sub-frame|AMSDU sub-frame| .. |AMSDU sub-frame| | |
276 | * | | 1 | 2 | .. | n | | |
277 | * +---- ~ ----+------ ~ ------+------ ~ ------+ .. +------ ~ ------+ | |
278 | */ | |
279 | int | |
280 | mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv, | |
281 | struct mwifiex_ra_list_tbl *pra_list, int headroom, | |
282 | int ptrindex, unsigned long ra_list_flags) | |
283 | __releases(&priv->wmm.ra_list_spinlock) | |
284 | { | |
285 | struct mwifiex_adapter *adapter = priv->adapter; | |
286 | struct sk_buff *skb_aggr, *skb_src; | |
287 | struct mwifiex_txinfo *tx_info_aggr, *tx_info_src; | |
270e58e8 | 288 | int pad = 0, ret; |
5e6e3a92 BZ |
289 | struct mwifiex_tx_param tx_param; |
290 | struct txpd *ptx_pd = NULL; | |
291 | ||
292 | if (skb_queue_empty(&pra_list->skb_head)) { | |
293 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
294 | ra_list_flags); | |
295 | return 0; | |
296 | } | |
297 | skb_src = skb_peek(&pra_list->skb_head); | |
298 | tx_info_src = MWIFIEX_SKB_TXCB(skb_src); | |
299 | skb_aggr = dev_alloc_skb(adapter->tx_buf_size); | |
300 | if (!skb_aggr) { | |
301 | dev_err(adapter->dev, "%s: alloc skb_aggr\n", __func__); | |
302 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
303 | ra_list_flags); | |
304 | return -1; | |
305 | } | |
306 | skb_reserve(skb_aggr, headroom + sizeof(struct txpd)); | |
307 | tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr); | |
308 | ||
309 | tx_info_aggr->bss_index = tx_info_src->bss_index; | |
310 | skb_aggr->priority = skb_src->priority; | |
311 | ||
312 | while (skb_src && ((skb_headroom(skb_aggr) + skb_src->len | |
313 | + LLC_SNAP_LEN) | |
314 | <= adapter->tx_buf_size)) { | |
315 | ||
316 | if (!skb_queue_empty(&pra_list->skb_head)) | |
317 | skb_src = skb_dequeue(&pra_list->skb_head); | |
318 | else | |
319 | skb_src = NULL; | |
320 | ||
321 | pra_list->total_pkts_size -= skb_src->len; | |
322 | ||
323 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
324 | ra_list_flags); | |
572e8f3e | 325 | mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad); |
5e6e3a92 BZ |
326 | |
327 | mwifiex_write_data_complete(adapter, skb_src, 0); | |
328 | ||
329 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags); | |
330 | ||
331 | if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) { | |
332 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
333 | ra_list_flags); | |
334 | return -1; | |
335 | } | |
336 | ||
337 | if (!skb_queue_empty(&pra_list->skb_head)) | |
338 | skb_src = skb_peek(&pra_list->skb_head); | |
339 | else | |
340 | skb_src = NULL; | |
341 | } | |
342 | ||
343 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags); | |
344 | ||
345 | /* Last AMSDU packet does not need padding */ | |
346 | skb_trim(skb_aggr, skb_aggr->len - pad); | |
347 | ||
348 | /* Form AMSDU */ | |
349 | mwifiex_11n_form_amsdu_txpd(priv, skb_aggr); | |
350 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) | |
351 | ptx_pd = (struct txpd *)skb_aggr->data; | |
352 | ||
353 | skb_push(skb_aggr, headroom); | |
354 | ||
355 | tx_param.next_pkt_len = ((pra_list->total_pkts_size) ? | |
356 | (((pra_list->total_pkts_size) > | |
357 | adapter->tx_buf_size) ? adapter-> | |
358 | tx_buf_size : pra_list->total_pkts_size + | |
359 | LLC_SNAP_LEN + sizeof(struct txpd)) : 0); | |
360 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA, | |
361 | skb_aggr->data, | |
362 | skb_aggr->len, &tx_param); | |
363 | switch (ret) { | |
364 | case -EBUSY: | |
365 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags); | |
366 | if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) { | |
367 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
368 | ra_list_flags); | |
369 | mwifiex_write_data_complete(adapter, skb_aggr, -1); | |
370 | return -1; | |
371 | } | |
372 | if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && | |
373 | (adapter->pps_uapsd_mode) && | |
374 | (adapter->tx_lock_flag)) { | |
375 | priv->adapter->tx_lock_flag = false; | |
376 | ptx_pd->flags = 0; | |
377 | } | |
378 | ||
379 | skb_queue_tail(&pra_list->skb_head, skb_aggr); | |
380 | ||
381 | pra_list->total_pkts_size += skb_aggr->len; | |
382 | ||
383 | tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT; | |
384 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
385 | ra_list_flags); | |
386 | dev_dbg(adapter->dev, "data: -EBUSY is returned\n"); | |
387 | break; | |
388 | case -1: | |
389 | adapter->data_sent = false; | |
390 | dev_err(adapter->dev, "%s: host_to_card failed: %#x\n", | |
391 | __func__, ret); | |
392 | adapter->dbg.num_tx_host_to_card_failure++; | |
393 | mwifiex_write_data_complete(adapter, skb_aggr, ret); | |
394 | return 0; | |
395 | case -EINPROGRESS: | |
396 | adapter->data_sent = false; | |
397 | break; | |
398 | case 0: | |
399 | mwifiex_write_data_complete(adapter, skb_aggr, ret); | |
400 | break; | |
401 | default: | |
402 | break; | |
403 | } | |
404 | if (ret != -EBUSY) { | |
405 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags); | |
406 | if (mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) { | |
407 | priv->wmm.packets_out[ptrindex]++; | |
408 | priv->wmm.tid_tbl_ptr[ptrindex].ra_list_curr = pra_list; | |
409 | } | |
410 | /* Now bss_prio_cur pointer points to next node */ | |
411 | adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur = | |
412 | list_first_entry( | |
413 | &adapter->bss_prio_tbl[priv->bss_priority] | |
414 | .bss_prio_cur->list, | |
415 | struct mwifiex_bss_prio_node, list); | |
416 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, | |
417 | ra_list_flags); | |
418 | } | |
419 | ||
420 | return 0; | |
421 | } |