1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46static int
47mwifiex_11n_form_amsdu_pkt(struct sk_buff *skb_aggr,
48 struct sk_buff *skb_src, int *pad)
49
50{
51 int dt_offset;
52 struct rfc_1042_hdr snap = {
53 0xaa,
54 0xaa,
55 0x03,
56 {0x00, 0x00, 0x00},
57 0x0000
58
59
60
61
62 };
63 struct tx_packet_hdr *tx_header;
64
65 tx_header = skb_put(skb_aggr, sizeof(*tx_header));
66
67
68 dt_offset = 2 * ETH_ALEN;
69 memcpy(&tx_header->eth803_hdr, skb_src->data, dt_offset);
70
71
72 snap.snap_type = ((struct ethhdr *)skb_src->data)->h_proto;
73
74 dt_offset += sizeof(__be16);
75
76 memcpy(&tx_header->rfc1042_hdr, &snap, sizeof(struct rfc_1042_hdr));
77
78 skb_pull(skb_src, dt_offset);
79
80
81 tx_header->eth803_hdr.h_proto = htons(skb_src->len + LLC_SNAP_LEN);
82
83
84 skb_put_data(skb_aggr, skb_src->data, skb_src->len);
85
86
87 *pad = (4 - ((unsigned long)skb_aggr->tail & 0x3)) % 4;
88
89 return skb_aggr->len + *pad;
90}
91
92
93
94
95
96
97
98static void
99mwifiex_11n_form_amsdu_txpd(struct mwifiex_private *priv,
100 struct sk_buff *skb)
101{
102 struct txpd *local_tx_pd;
103 struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
104
105 skb_push(skb, sizeof(*local_tx_pd));
106
107 local_tx_pd = (struct txpd *) skb->data;
108 memset(local_tx_pd, 0, sizeof(struct txpd));
109
110
111 local_tx_pd->priority = (u8) skb->priority;
112 local_tx_pd->pkt_delay_2ms =
113 mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
114 local_tx_pd->bss_num = priv->bss_num;
115 local_tx_pd->bss_type = priv->bss_type;
116
117 local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
118 local_tx_pd->tx_pkt_type = cpu_to_le16(PKT_TYPE_AMSDU);
119 local_tx_pd->tx_pkt_length = cpu_to_le16(skb->len -
120 sizeof(*local_tx_pd));
121
122 if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
123 local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
124
125 if (local_tx_pd->tx_control == 0)
126
127 local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
128
129 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
130 priv->adapter->pps_uapsd_mode) {
131 if (true == mwifiex_check_last_packet_indication(priv)) {
132 priv->adapter->tx_lock_flag = true;
133 local_tx_pd->flags =
134 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
135 }
136 }
137}
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155int
156mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
157 struct mwifiex_ra_list_tbl *pra_list,
158 int ptrindex, unsigned long ra_list_flags)
159 __releases(&priv->wmm.ra_list_spinlock)
160{
161 struct mwifiex_adapter *adapter = priv->adapter;
162 struct sk_buff *skb_aggr, *skb_src;
163 struct mwifiex_txinfo *tx_info_aggr, *tx_info_src;
164 int pad = 0, aggr_num = 0, ret;
165 struct mwifiex_tx_param tx_param;
166 struct txpd *ptx_pd = NULL;
167 int headroom = adapter->intf_hdr_len;
168
169 skb_src = skb_peek(&pra_list->skb_head);
170 if (!skb_src) {
171 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
172 ra_list_flags);
173 return 0;
174 }
175
176 tx_info_src = MWIFIEX_SKB_TXCB(skb_src);
177 skb_aggr = mwifiex_alloc_dma_align_buf(adapter->tx_buf_size,
178 GFP_ATOMIC);
179 if (!skb_aggr) {
180 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
181 ra_list_flags);
182 return -1;
183 }
184
185
186
187
188 skb_reserve(skb_aggr, headroom + sizeof(struct txpd));
189 tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr);
190
191 memset(tx_info_aggr, 0, sizeof(*tx_info_aggr));
192 tx_info_aggr->bss_type = tx_info_src->bss_type;
193 tx_info_aggr->bss_num = tx_info_src->bss_num;
194
195 if (tx_info_src->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
196 tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
197 tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_AGGR_PKT;
198 skb_aggr->priority = skb_src->priority;
199 skb_aggr->tstamp = skb_src->tstamp;
200
201 do {
202
203 if ((skb_aggr->len + skb_src->len + LLC_SNAP_LEN) >
204 adapter->tx_buf_size)
205 break;
206
207 skb_src = skb_dequeue(&pra_list->skb_head);
208 pra_list->total_pkt_count--;
209 atomic_dec(&priv->wmm.tx_pkts_queued);
210 aggr_num++;
211 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
212 ra_list_flags);
213 mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad);
214
215 mwifiex_write_data_complete(adapter, skb_src, 0, 0);
216
217 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
218
219 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
220 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
221 ra_list_flags);
222 return -1;
223 }
224
225 if (skb_tailroom(skb_aggr) < pad) {
226 pad = 0;
227 break;
228 }
229 skb_put(skb_aggr, pad);
230
231 skb_src = skb_peek(&pra_list->skb_head);
232
233 } while (skb_src);
234
235 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
236
237
238 skb_trim(skb_aggr, skb_aggr->len - pad);
239
240
241 mwifiex_11n_form_amsdu_txpd(priv, skb_aggr);
242 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
243 ptx_pd = (struct txpd *)skb_aggr->data;
244
245 skb_push(skb_aggr, headroom);
246 tx_info_aggr->aggr_num = aggr_num * 2;
247 if (adapter->data_sent || adapter->tx_lock_flag) {
248 atomic_add(aggr_num * 2, &adapter->tx_queued);
249 skb_queue_tail(&adapter->tx_data_q, skb_aggr);
250 return 0;
251 }
252
253 if (skb_src)
254 tx_param.next_pkt_len = skb_src->len + sizeof(struct txpd);
255 else
256 tx_param.next_pkt_len = 0;
257
258 if (adapter->iface_type == MWIFIEX_USB) {
259 ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
260 skb_aggr, &tx_param);
261 } else {
262
263 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
264 skb_aggr, &tx_param);
265 }
266 switch (ret) {
267 case -EBUSY:
268 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
269 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
270 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
271 ra_list_flags);
272 mwifiex_write_data_complete(adapter, skb_aggr, 1, -1);
273 return -1;
274 }
275 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
276 adapter->pps_uapsd_mode && adapter->tx_lock_flag) {
277 priv->adapter->tx_lock_flag = false;
278 if (ptx_pd)
279 ptx_pd->flags = 0;
280 }
281
282 skb_queue_tail(&pra_list->skb_head, skb_aggr);
283
284 pra_list->total_pkt_count++;
285
286 atomic_inc(&priv->wmm.tx_pkts_queued);
287
288 tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
289 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
290 ra_list_flags);
291 mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
292 break;
293 case -1:
294 mwifiex_dbg(adapter, ERROR, "%s: host_to_card failed: %#x\n",
295 __func__, ret);
296 adapter->dbg.num_tx_host_to_card_failure++;
297 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
298 return 0;
299 case -EINPROGRESS:
300 break;
301 case 0:
302 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
303 break;
304 default:
305 break;
306 }
307 if (ret != -EBUSY) {
308 mwifiex_rotate_priolists(priv, pra_list, ptrindex);
309 }
310
311 return 0;
312}
313