ath9k: fix indentation in ar9003_hw_set_power_per_rate_table
[deliverable/linux.git] / drivers / net / wireless / mwifiex / 11n_aggr.c
CommitLineData
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 */
46static int
572e8f3e 47mwifiex_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,
84266841 87 skb_src->len);
5e6e3a92
BZ
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 */
101static void
102mwifiex_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 -
84266841 122 sizeof(*local_tx_pd));
5e6e3a92
BZ
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
84266841
YAP
128 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
129 priv->adapter->pps_uapsd_mode) {
5e6e3a92
BZ
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
5e6e3a92
BZ
138/*
139 * Create aggregated packet.
140 *
141 * This function creates an aggregated MSDU packet, by combining buffers
142 * from the RA list. Each individual buffer is encapsulated as an AMSDU
143 * subframe and all such subframes are concatenated together to form the
144 * AMSDU packet.
145 *
146 * A TxPD is also added to the front of the resultant AMSDU packets for
147 * transmission. The resultant packets format is -
148 *
149 * +---- ~ ----+------ ~ ------+------ ~ ------+-..-+------ ~ ------+
150 * | TxPD |AMSDU sub-frame|AMSDU sub-frame| .. |AMSDU sub-frame|
151 * | | 1 | 2 | .. | n |
152 * +---- ~ ----+------ ~ ------+------ ~ ------+ .. +------ ~ ------+
153 */
154int
155mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
156 struct mwifiex_ra_list_tbl *pra_list, int headroom,
157 int ptrindex, unsigned long ra_list_flags)
158 __releases(&priv->wmm.ra_list_spinlock)
159{
160 struct mwifiex_adapter *adapter = priv->adapter;
161 struct sk_buff *skb_aggr, *skb_src;
162 struct mwifiex_txinfo *tx_info_aggr, *tx_info_src;
270e58e8 163 int pad = 0, ret;
5e6e3a92
BZ
164 struct mwifiex_tx_param tx_param;
165 struct txpd *ptx_pd = NULL;
166
a8fe3293
YAP
167 skb_src = skb_peek(&pra_list->skb_head);
168 if (!skb_src) {
5e6e3a92
BZ
169 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
170 ra_list_flags);
171 return 0;
172 }
a8fe3293 173
5e6e3a92
BZ
174 tx_info_src = MWIFIEX_SKB_TXCB(skb_src);
175 skb_aggr = dev_alloc_skb(adapter->tx_buf_size);
176 if (!skb_aggr) {
177 dev_err(adapter->dev, "%s: alloc skb_aggr\n", __func__);
178 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
179 ra_list_flags);
180 return -1;
181 }
182 skb_reserve(skb_aggr, headroom + sizeof(struct txpd));
183 tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr);
184
9da9a3b2
YAP
185 tx_info_aggr->bss_type = tx_info_src->bss_type;
186 tx_info_aggr->bss_num = tx_info_src->bss_num;
5e6e3a92
BZ
187 skb_aggr->priority = skb_src->priority;
188
fb3c19bc
YAP
189 do {
190 /* Check if AMSDU can accommodate this MSDU */
191 if (skb_tailroom(skb_aggr) < (skb_src->len + LLC_SNAP_LEN))
192 break;
5e6e3a92 193
a8fe3293 194 skb_src = skb_dequeue(&pra_list->skb_head);
5e6e3a92 195
fb3c19bc 196 pra_list->total_pkts_size -= skb_src->len;
5e6e3a92 197
f699254c
MY
198 atomic_dec(&priv->wmm.tx_pkts_queued);
199
5e6e3a92
BZ
200 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
201 ra_list_flags);
572e8f3e 202 mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad);
5e6e3a92
BZ
203
204 mwifiex_write_data_complete(adapter, skb_src, 0);
205
206 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
207
208 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
209 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
210 ra_list_flags);
211 return -1;
212 }
213
fb3c19bc
YAP
214 if (skb_tailroom(skb_aggr) < pad) {
215 pad = 0;
216 break;
217 }
218 skb_put(skb_aggr, pad);
219
a8fe3293 220 skb_src = skb_peek(&pra_list->skb_head);
fb3c19bc
YAP
221
222 } while (skb_src);
5e6e3a92
BZ
223
224 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
225
226 /* Last AMSDU packet does not need padding */
227 skb_trim(skb_aggr, skb_aggr->len - pad);
228
229 /* Form AMSDU */
230 mwifiex_11n_form_amsdu_txpd(priv, skb_aggr);
231 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
232 ptx_pd = (struct txpd *)skb_aggr->data;
233
234 skb_push(skb_aggr, headroom);
235
4daffe35
AK
236 if (adapter->iface_type == MWIFIEX_USB) {
237 adapter->data_sent = true;
238 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA,
239 skb_aggr, NULL);
240 } else {
241 /*
242 * Padding per MSDU will affect the length of next
243 * packet and hence the exact length of next packet
244 * is uncertain here.
245 *
246 * Also, aggregation of transmission buffer, while
247 * downloading the data to the card, wont gain much
248 * on the AMSDU packets as the AMSDU packets utilizes
249 * the transmission buffer space to the maximum
250 * (adapter->tx_buf_size).
251 */
252 tx_param.next_pkt_len = 0;
253
254 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
255 skb_aggr, &tx_param);
256 }
5e6e3a92
BZ
257 switch (ret) {
258 case -EBUSY:
259 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
260 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
261 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
262 ra_list_flags);
263 mwifiex_write_data_complete(adapter, skb_aggr, -1);
264 return -1;
265 }
84266841
YAP
266 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
267 adapter->pps_uapsd_mode && adapter->tx_lock_flag) {
5e6e3a92 268 priv->adapter->tx_lock_flag = false;
b53575ec
CF
269 if (ptx_pd)
270 ptx_pd->flags = 0;
5e6e3a92
BZ
271 }
272
273 skb_queue_tail(&pra_list->skb_head, skb_aggr);
274
275 pra_list->total_pkts_size += skb_aggr->len;
276
f699254c
MY
277 atomic_inc(&priv->wmm.tx_pkts_queued);
278
5e6e3a92
BZ
279 tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
280 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
281 ra_list_flags);
282 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
283 break;
284 case -1:
285 adapter->data_sent = false;
286 dev_err(adapter->dev, "%s: host_to_card failed: %#x\n",
84266841 287 __func__, ret);
5e6e3a92
BZ
288 adapter->dbg.num_tx_host_to_card_failure++;
289 mwifiex_write_data_complete(adapter, skb_aggr, ret);
290 return 0;
291 case -EINPROGRESS:
292 adapter->data_sent = false;
293 break;
294 case 0:
295 mwifiex_write_data_complete(adapter, skb_aggr, ret);
296 break;
297 default:
298 break;
299 }
300 if (ret != -EBUSY) {
301 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
302 if (mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
303 priv->wmm.packets_out[ptrindex]++;
304 priv->wmm.tid_tbl_ptr[ptrindex].ra_list_curr = pra_list;
305 }
306 /* Now bss_prio_cur pointer points to next node */
307 adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur =
308 list_first_entry(
309 &adapter->bss_prio_tbl[priv->bss_priority]
310 .bss_prio_cur->list,
311 struct mwifiex_bss_prio_node, list);
312 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
313 ra_list_flags);
314 }
315
316 return 0;
317}
This page took 0.172393 seconds and 5 git commands to generate.