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 = (void *)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 =
73 le16_to_cpu(*(__le16 *) ((u8 *)skb_src->data + dt_offset));
74 dt_offset += sizeof(u16);
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 memcpy(skb_put(skb_aggr, skb_src->len), 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
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
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
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 -
119 sizeof(*local_tx_pd));
120
121 if (local_tx_pd->tx_control == 0)
122
123 local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
124
125 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
126 priv->adapter->pps_uapsd_mode) {
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151int
152mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
153 struct mwifiex_ra_list_tbl *pra_list,
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;
160 int pad = 0, ret;
161 struct mwifiex_tx_param tx_param;
162 struct txpd *ptx_pd = NULL;
163 int headroom = adapter->iface_type == MWIFIEX_USB ? 0 : INTF_HEADER_LEN;
164
165 skb_src = skb_peek(&pra_list->skb_head);
166 if (!skb_src) {
167 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
168 ra_list_flags);
169 return 0;
170 }
171
172 tx_info_src = MWIFIEX_SKB_TXCB(skb_src);
173 skb_aggr = dev_alloc_skb(adapter->tx_buf_size);
174 if (!skb_aggr) {
175 dev_err(adapter->dev, "%s: alloc skb_aggr\n", __func__);
176 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
177 ra_list_flags);
178 return -1;
179 }
180 skb_reserve(skb_aggr, headroom + sizeof(struct txpd));
181 tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr);
182
183 tx_info_aggr->bss_type = tx_info_src->bss_type;
184 tx_info_aggr->bss_num = tx_info_src->bss_num;
185 skb_aggr->priority = skb_src->priority;
186
187 do {
188
189 if (skb_tailroom(skb_aggr) < (skb_src->len + LLC_SNAP_LEN))
190 break;
191
192 skb_src = skb_dequeue(&pra_list->skb_head);
193
194 pra_list->total_pkt_count--;
195
196 atomic_dec(&priv->wmm.tx_pkts_queued);
197
198 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
199 ra_list_flags);
200 mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad);
201
202 mwifiex_write_data_complete(adapter, skb_src, 0, 0);
203
204 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
205
206 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
207 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
208 ra_list_flags);
209 return -1;
210 }
211
212 if (skb_tailroom(skb_aggr) < pad) {
213 pad = 0;
214 break;
215 }
216 skb_put(skb_aggr, pad);
217
218 skb_src = skb_peek(&pra_list->skb_head);
219
220 } while (skb_src);
221
222 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
223
224
225 skb_trim(skb_aggr, skb_aggr->len - pad);
226
227
228 mwifiex_11n_form_amsdu_txpd(priv, skb_aggr);
229 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
230 ptx_pd = (struct txpd *)skb_aggr->data;
231
232 skb_push(skb_aggr, headroom);
233
234 if (adapter->iface_type == MWIFIEX_USB) {
235 adapter->data_sent = true;
236 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA,
237 skb_aggr, NULL);
238 } else {
239
240
241
242
243
244
245
246
247
248
249
250 tx_param.next_pkt_len = 0;
251
252 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
253 skb_aggr, &tx_param);
254 }
255 switch (ret) {
256 case -EBUSY:
257 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
258 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
259 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
260 ra_list_flags);
261 mwifiex_write_data_complete(adapter, skb_aggr, 1, -1);
262 return -1;
263 }
264 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
265 adapter->pps_uapsd_mode && adapter->tx_lock_flag) {
266 priv->adapter->tx_lock_flag = false;
267 if (ptx_pd)
268 ptx_pd->flags = 0;
269 }
270
271 skb_queue_tail(&pra_list->skb_head, skb_aggr);
272
273 pra_list->total_pkt_count++;
274
275 atomic_inc(&priv->wmm.tx_pkts_queued);
276
277 tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
278 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
279 ra_list_flags);
280 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
281 break;
282 case -1:
283 if (adapter->iface_type != MWIFIEX_PCIE)
284 adapter->data_sent = false;
285 dev_err(adapter->dev, "%s: host_to_card failed: %#x\n",
286 __func__, ret);
287 adapter->dbg.num_tx_host_to_card_failure++;
288 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
289 return 0;
290 case -EINPROGRESS:
291 if (adapter->iface_type != MWIFIEX_PCIE)
292 adapter->data_sent = false;
293 break;
294 case 0:
295 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
296 break;
297 default:
298 break;
299 }
300 if (ret != -EBUSY) {
301 mwifiex_rotate_priolists(priv, pra_list, ptrindex);
302 }
303
304 return 0;
305}
306