blob: 06e4912f03216d161ac4ff1a662a808fc4954eec [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "core.h"
18#include "debug.h"
19
20static u8 ath6kl_ibss_map_epid(struct sk_buff *skb, struct net_device *dev,
21 u32 *map_no)
22{
23 struct ath6kl *ar = ath6kl_priv(dev);
24 struct ethhdr *eth_hdr;
25 u32 i, ep_map = -1;
26 u8 *datap;
27
28 *map_no = 0;
29 datap = skb->data;
30 eth_hdr = (struct ethhdr *) (datap + sizeof(struct wmi_data_hdr));
31
32 if (is_multicast_ether_addr(eth_hdr->h_dest))
33 return ENDPOINT_2;
34
35 for (i = 0; i < ar->node_num; i++) {
36 if (memcmp(eth_hdr->h_dest, ar->node_map[i].mac_addr,
37 ETH_ALEN) == 0) {
38 *map_no = i + 1;
39 ar->node_map[i].tx_pend++;
40 return ar->node_map[i].ep_id;
41 }
42
43 if ((ep_map == -1) && !ar->node_map[i].tx_pend)
44 ep_map = i;
45 }
46
47 if (ep_map == -1) {
48 ep_map = ar->node_num;
49 ar->node_num++;
50 if (ar->node_num > MAX_NODE_NUM)
51 return ENDPOINT_UNUSED;
52 }
53
54 memcpy(ar->node_map[ep_map].mac_addr, eth_hdr->h_dest, ETH_ALEN);
55
56 for (i = ENDPOINT_2; i <= ENDPOINT_5; i++) {
57 if (!ar->tx_pending[i]) {
58 ar->node_map[ep_map].ep_id = i;
59 break;
60 }
61
62 /*
63 * No free endpoint is available, start redistribution on
64 * the inuse endpoints.
65 */
66 if (i == ENDPOINT_5) {
67 ar->node_map[ep_map].ep_id = ar->next_ep_id;
68 ar->next_ep_id++;
69 if (ar->next_ep_id > ENDPOINT_5)
70 ar->next_ep_id = ENDPOINT_2;
71 }
72 }
73
74 *map_no = ep_map + 1;
75 ar->node_map[ep_map].tx_pend++;
76
77 return ar->node_map[ep_map].ep_id;
78}
79
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +053080static bool ath6kl_powersave_ap(struct ath6kl_vif *vif, struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +030081 bool *more_data)
82{
83 struct ethhdr *datap = (struct ethhdr *) skb->data;
84 struct ath6kl_sta *conn = NULL;
85 bool ps_queued = false, is_psq_empty = false;
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +053086 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +030087
88 if (is_multicast_ether_addr(datap->h_dest)) {
89 u8 ctr = 0;
90 bool q_mcast = false;
91
92 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
93 if (ar->sta_list[ctr].sta_flags & STA_PS_SLEEP) {
94 q_mcast = true;
95 break;
96 }
97 }
98
99 if (q_mcast) {
100 /*
101 * If this transmit is not because of a Dtim Expiry
102 * q it.
103 */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530104 if (!test_bit(DTIM_EXPIRED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300105 bool is_mcastq_empty = false;
106
107 spin_lock_bh(&ar->mcastpsq_lock);
108 is_mcastq_empty =
109 skb_queue_empty(&ar->mcastpsq);
110 skb_queue_tail(&ar->mcastpsq, skb);
111 spin_unlock_bh(&ar->mcastpsq_lock);
112
113 /*
114 * If this is the first Mcast pkt getting
115 * queued indicate to the target to set the
116 * BitmapControl LSB of the TIM IE.
117 */
118 if (is_mcastq_empty)
119 ath6kl_wmi_set_pvb_cmd(ar->wmi,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530120 vif->fw_vif_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300121 MCAST_AID, 1);
122
123 ps_queued = true;
124 } else {
125 /*
126 * This transmit is because of Dtim expiry.
127 * Determine if MoreData bit has to be set.
128 */
129 spin_lock_bh(&ar->mcastpsq_lock);
130 if (!skb_queue_empty(&ar->mcastpsq))
131 *more_data = true;
132 spin_unlock_bh(&ar->mcastpsq_lock);
133 }
134 }
135 } else {
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +0530136 conn = ath6kl_find_sta(vif, datap->h_dest);
Kalle Valobdcd8172011-07-18 00:22:30 +0300137 if (!conn) {
138 dev_kfree_skb(skb);
139
140 /* Inform the caller that the skb is consumed */
141 return true;
142 }
143
144 if (conn->sta_flags & STA_PS_SLEEP) {
145 if (!(conn->sta_flags & STA_PS_POLLED)) {
146 /* Queue the frames if the STA is sleeping */
147 spin_lock_bh(&conn->psq_lock);
148 is_psq_empty = skb_queue_empty(&conn->psq);
149 skb_queue_tail(&conn->psq, skb);
150 spin_unlock_bh(&conn->psq_lock);
151
152 /*
153 * If this is the first pkt getting queued
154 * for this STA, update the PVB for this
155 * STA.
156 */
157 if (is_psq_empty)
158 ath6kl_wmi_set_pvb_cmd(ar->wmi,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530159 vif->fw_vif_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300160 conn->aid, 1);
161
162 ps_queued = true;
163 } else {
164 /*
165 * This tx is because of a PsPoll.
166 * Determine if MoreData bit has to be set.
167 */
168 spin_lock_bh(&conn->psq_lock);
169 if (!skb_queue_empty(&conn->psq))
170 *more_data = true;
171 spin_unlock_bh(&conn->psq_lock);
172 }
173 }
174 }
175
176 return ps_queued;
177}
178
179/* Tx functions */
180
181int ath6kl_control_tx(void *devt, struct sk_buff *skb,
182 enum htc_endpoint_id eid)
183{
184 struct ath6kl *ar = devt;
185 int status = 0;
186 struct ath6kl_cookie *cookie = NULL;
187
188 spin_lock_bh(&ar->lock);
189
190 ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
191 "%s: skb=0x%p, len=0x%x eid =%d\n", __func__,
192 skb, skb->len, eid);
193
194 if (test_bit(WMI_CTRL_EP_FULL, &ar->flag) && (eid == ar->ctrl_ep)) {
195 /*
196 * Control endpoint is full, don't allocate resources, we
197 * are just going to drop this packet.
198 */
199 cookie = NULL;
200 ath6kl_err("wmi ctrl ep full, dropping pkt : 0x%p, len:%d\n",
201 skb, skb->len);
202 } else
203 cookie = ath6kl_alloc_cookie(ar);
204
205 if (cookie == NULL) {
206 spin_unlock_bh(&ar->lock);
207 status = -ENOMEM;
208 goto fail_ctrl_tx;
209 }
210
211 ar->tx_pending[eid]++;
212
213 if (eid != ar->ctrl_ep)
214 ar->total_tx_data_pend++;
215
216 spin_unlock_bh(&ar->lock);
217
218 cookie->skb = skb;
219 cookie->map_no = 0;
220 set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
221 eid, ATH6KL_CONTROL_PKT_TAG);
222
223 /*
224 * This interface is asynchronous, if there is an error, cleanup
225 * will happen in the TX completion callback.
226 */
Kalle Vaload226ec2011-08-10 09:49:12 +0300227 ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt);
Kalle Valobdcd8172011-07-18 00:22:30 +0300228
229 return 0;
230
231fail_ctrl_tx:
232 dev_kfree_skb(skb);
233 return status;
234}
235
236int ath6kl_data_tx(struct sk_buff *skb, struct net_device *dev)
237{
238 struct ath6kl *ar = ath6kl_priv(dev);
239 struct ath6kl_cookie *cookie = NULL;
240 enum htc_endpoint_id eid = ENDPOINT_UNUSED;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530241 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300242 u32 map_no = 0;
243 u16 htc_tag = ATH6KL_DATA_PKT_TAG;
244 u8 ac = 99 ; /* initialize to unmapped ac */
245 bool chk_adhoc_ps_mapping = false, more_data = false;
Kalle Valobdcd8172011-07-18 00:22:30 +0300246 int ret;
247
248 ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
249 "%s: skb=0x%p, data=0x%p, len=0x%x\n", __func__,
250 skb, skb->data, skb->len);
251
252 /* If target is not associated */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530253 if (!test_bit(CONNECTED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300254 dev_kfree_skb(skb);
255 return 0;
256 }
257
258 if (!test_bit(WMI_READY, &ar->flag))
259 goto fail_tx;
260
261 /* AP mode Power saving processing */
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530262 if (vif->nw_type == AP_NETWORK) {
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +0530263 if (ath6kl_powersave_ap(vif, skb, &more_data))
Kalle Valobdcd8172011-07-18 00:22:30 +0300264 return 0;
265 }
266
267 if (test_bit(WMI_ENABLED, &ar->flag)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300268 if (skb_headroom(skb) < dev->needed_headroom) {
269 WARN_ON(1);
270 goto fail_tx;
271 }
272
273 if (ath6kl_wmi_dix_2_dot3(ar->wmi, skb)) {
274 ath6kl_err("ath6kl_wmi_dix_2_dot3 failed\n");
275 goto fail_tx;
276 }
277
278 if (ath6kl_wmi_data_hdr_add(ar->wmi, skb, DATA_MSGTYPE,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +0530279 more_data, 0, 0, NULL,
280 vif->fw_vif_idx)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300281 ath6kl_err("wmi_data_hdr_add failed\n");
282 goto fail_tx;
283 }
284
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530285 if ((vif->nw_type == ADHOC_NETWORK) &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530286 ar->ibss_ps_enable && test_bit(CONNECTED, &vif->flags))
Kalle Valobdcd8172011-07-18 00:22:30 +0300287 chk_adhoc_ps_mapping = true;
288 else {
289 /* get the stream mapping */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530290 ret = ath6kl_wmi_implicit_create_pstream(ar->wmi,
291 vif->fw_vif_idx, skb,
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530292 0, test_bit(WMM_ENABLED, &vif->flags), &ac);
Kalle Valobdcd8172011-07-18 00:22:30 +0300293 if (ret)
294 goto fail_tx;
295 }
296 } else
297 goto fail_tx;
298
299 spin_lock_bh(&ar->lock);
300
301 if (chk_adhoc_ps_mapping)
302 eid = ath6kl_ibss_map_epid(skb, dev, &map_no);
303 else
304 eid = ar->ac2ep_map[ac];
305
306 if (eid == 0 || eid == ENDPOINT_UNUSED) {
307 ath6kl_err("eid %d is not mapped!\n", eid);
308 spin_unlock_bh(&ar->lock);
309 goto fail_tx;
310 }
311
312 /* allocate resource for this packet */
313 cookie = ath6kl_alloc_cookie(ar);
314
315 if (!cookie) {
316 spin_unlock_bh(&ar->lock);
317 goto fail_tx;
318 }
319
320 /* update counts while the lock is held */
321 ar->tx_pending[eid]++;
322 ar->total_tx_data_pend++;
323
324 spin_unlock_bh(&ar->lock);
325
Jouni Malinen00b1edf2011-09-27 11:00:08 +0300326 if (!IS_ALIGNED((unsigned long) skb->data - HTC_HDR_LENGTH, 4) &&
327 skb_cloned(skb)) {
328 /*
329 * We will touch (move the buffer data to align it. Since the
330 * skb buffer is cloned and not only the header is changed, we
331 * have to copy it to allow the changes. Since we are copying
332 * the data here, we may as well align it by reserving suitable
333 * headroom to avoid the memmove in ath6kl_htc_tx_buf_align().
334 */
335 struct sk_buff *nskb;
336
337 nskb = skb_copy_expand(skb, HTC_HDR_LENGTH, 0, GFP_ATOMIC);
338 if (nskb == NULL)
339 goto fail_tx;
340 kfree_skb(skb);
341 skb = nskb;
342 }
343
Kalle Valobdcd8172011-07-18 00:22:30 +0300344 cookie->skb = skb;
345 cookie->map_no = map_no;
346 set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
347 eid, htc_tag);
348
Kalle Valoef094102011-09-27 14:30:45 +0300349 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "tx ",
350 skb->data, skb->len);
Kalle Valobdcd8172011-07-18 00:22:30 +0300351
352 /*
353 * HTC interface is asynchronous, if this fails, cleanup will
354 * happen in the ath6kl_tx_complete callback.
355 */
Kalle Vaload226ec2011-08-10 09:49:12 +0300356 ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt);
Kalle Valobdcd8172011-07-18 00:22:30 +0300357
358 return 0;
359
360fail_tx:
361 dev_kfree_skb(skb);
362
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530363 vif->net_stats.tx_dropped++;
364 vif->net_stats.tx_aborted_errors++;
Kalle Valobdcd8172011-07-18 00:22:30 +0300365
366 return 0;
367}
368
369/* indicate tx activity or inactivity on a WMI stream */
370void ath6kl_indicate_tx_activity(void *devt, u8 traffic_class, bool active)
371{
372 struct ath6kl *ar = devt;
373 enum htc_endpoint_id eid;
374 int i;
375
376 eid = ar->ac2ep_map[traffic_class];
377
378 if (!test_bit(WMI_ENABLED, &ar->flag))
379 goto notify_htc;
380
381 spin_lock_bh(&ar->lock);
382
383 ar->ac_stream_active[traffic_class] = active;
384
385 if (active) {
386 /*
387 * Keep track of the active stream with the highest
388 * priority.
389 */
390 if (ar->ac_stream_pri_map[traffic_class] >
391 ar->hiac_stream_active_pri)
392 /* set the new highest active priority */
393 ar->hiac_stream_active_pri =
394 ar->ac_stream_pri_map[traffic_class];
395
396 } else {
397 /*
398 * We may have to search for the next active stream
399 * that is the highest priority.
400 */
401 if (ar->hiac_stream_active_pri ==
402 ar->ac_stream_pri_map[traffic_class]) {
403 /*
404 * The highest priority stream just went inactive
405 * reset and search for the "next" highest "active"
406 * priority stream.
407 */
408 ar->hiac_stream_active_pri = 0;
409
410 for (i = 0; i < WMM_NUM_AC; i++) {
411 if (ar->ac_stream_active[i] &&
412 (ar->ac_stream_pri_map[i] >
413 ar->hiac_stream_active_pri))
414 /*
415 * Set the new highest active
416 * priority.
417 */
418 ar->hiac_stream_active_pri =
419 ar->ac_stream_pri_map[i];
420 }
421 }
422 }
423
424 spin_unlock_bh(&ar->lock);
425
426notify_htc:
427 /* notify HTC, this may cause credit distribution changes */
Kalle Vaload226ec2011-08-10 09:49:12 +0300428 ath6kl_htc_indicate_activity_change(ar->htc_target, eid, active);
Kalle Valobdcd8172011-07-18 00:22:30 +0300429}
430
431enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target,
432 struct htc_packet *packet)
433{
434 struct ath6kl *ar = target->dev->ar;
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530435 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +0300436 enum htc_endpoint_id endpoint = packet->endpoint;
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530437 enum htc_send_full_action action = HTC_SEND_FULL_KEEP;
Kalle Valobdcd8172011-07-18 00:22:30 +0300438
439 if (endpoint == ar->ctrl_ep) {
440 /*
441 * Under normal WMI if this is getting full, then something
442 * is running rampant the host should not be exhausting the
443 * WMI queue with too many commands the only exception to
444 * this is during testing using endpointping.
445 */
446 spin_lock_bh(&ar->lock);
447 set_bit(WMI_CTRL_EP_FULL, &ar->flag);
448 spin_unlock_bh(&ar->lock);
449 ath6kl_err("wmi ctrl ep is full\n");
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530450 goto stop_adhoc_netq;
Kalle Valobdcd8172011-07-18 00:22:30 +0300451 }
452
453 if (packet->info.tx.tag == ATH6KL_CONTROL_PKT_TAG)
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530454 goto stop_adhoc_netq;
Kalle Valobdcd8172011-07-18 00:22:30 +0300455
456 /*
457 * The last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for
458 * the highest active stream.
459 */
460 if (ar->ac_stream_pri_map[ar->ep2ac_map[endpoint]] <
461 ar->hiac_stream_active_pri &&
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530462 ar->cookie_count <= MAX_HI_COOKIE_NUM) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300463 /*
464 * Give preference to the highest priority stream by
465 * dropping the packets which overflowed.
466 */
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530467 action = HTC_SEND_FULL_DROP;
468 goto stop_adhoc_netq;
469 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300470
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530471stop_adhoc_netq:
472 /* FIXME: Locking */
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530473 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530474 list_for_each_entry(vif, &ar->vif_list, list) {
475 if (vif->nw_type == ADHOC_NETWORK) {
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530476 spin_unlock_bh(&ar->list_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300477
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530478 spin_lock_bh(&vif->if_lock);
479 set_bit(NETQ_STOPPED, &vif->flags);
480 spin_unlock_bh(&vif->if_lock);
481 netif_stop_queue(vif->ndev);
482
483 return action;
484 }
485 }
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530486 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530487
488 return action;
Kalle Valobdcd8172011-07-18 00:22:30 +0300489}
490
491/* TODO this needs to be looked at */
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530492static void ath6kl_tx_clear_node_map(struct ath6kl_vif *vif,
Kalle Valobdcd8172011-07-18 00:22:30 +0300493 enum htc_endpoint_id eid, u32 map_no)
494{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530495 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300496 u32 i;
497
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530498 if (vif->nw_type != ADHOC_NETWORK)
Kalle Valobdcd8172011-07-18 00:22:30 +0300499 return;
500
501 if (!ar->ibss_ps_enable)
502 return;
503
504 if (eid == ar->ctrl_ep)
505 return;
506
507 if (map_no == 0)
508 return;
509
510 map_no--;
511 ar->node_map[map_no].tx_pend--;
512
513 if (ar->node_map[map_no].tx_pend)
514 return;
515
516 if (map_no != (ar->node_num - 1))
517 return;
518
519 for (i = ar->node_num; i > 0; i--) {
520 if (ar->node_map[i - 1].tx_pend)
521 break;
522
523 memset(&ar->node_map[i - 1], 0,
524 sizeof(struct ath6kl_node_mapping));
525 ar->node_num--;
526 }
527}
528
529void ath6kl_tx_complete(void *context, struct list_head *packet_queue)
530{
531 struct ath6kl *ar = context;
532 struct sk_buff_head skb_queue;
533 struct htc_packet *packet;
534 struct sk_buff *skb;
535 struct ath6kl_cookie *ath6kl_cookie;
536 u32 map_no = 0;
537 int status;
538 enum htc_endpoint_id eid;
539 bool wake_event = false;
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530540 bool flushing[MAX_NUM_VIF] = {false};
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +0530541 u8 if_idx;
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530542 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +0300543
544 skb_queue_head_init(&skb_queue);
545
546 /* lock the driver as we update internal state */
547 spin_lock_bh(&ar->lock);
548
549 /* reap completed packets */
550 while (!list_empty(packet_queue)) {
551
552 packet = list_first_entry(packet_queue, struct htc_packet,
553 list);
554 list_del(&packet->list);
555
556 ath6kl_cookie = (struct ath6kl_cookie *)packet->pkt_cntxt;
557 if (!ath6kl_cookie)
558 goto fatal;
559
560 status = packet->status;
561 skb = ath6kl_cookie->skb;
562 eid = packet->endpoint;
563 map_no = ath6kl_cookie->map_no;
564
565 if (!skb || !skb->data)
566 goto fatal;
567
568 packet->buf = skb->data;
569
570 __skb_queue_tail(&skb_queue, skb);
571
572 if (!status && (packet->act_len != skb->len))
573 goto fatal;
574
575 ar->tx_pending[eid]--;
576
577 if (eid != ar->ctrl_ep)
578 ar->total_tx_data_pend--;
579
580 if (eid == ar->ctrl_ep) {
581 if (test_bit(WMI_CTRL_EP_FULL, &ar->flag))
582 clear_bit(WMI_CTRL_EP_FULL, &ar->flag);
583
584 if (ar->tx_pending[eid] == 0)
585 wake_event = true;
586 }
587
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +0530588 if (eid == ar->ctrl_ep) {
589 if_idx = wmi_cmd_hdr_get_if_idx(
590 (struct wmi_cmd_hdr *) skb->data);
591 } else {
592 if_idx = wmi_data_hdr_get_if_idx(
593 (struct wmi_data_hdr *) skb->data);
594 }
595
596 vif = ath6kl_get_vif_by_index(ar, if_idx);
597 if (!vif) {
598 ath6kl_free_cookie(ar, ath6kl_cookie);
599 continue;
600 }
601
Kalle Valobdcd8172011-07-18 00:22:30 +0300602 if (status) {
603 if (status == -ECANCELED)
604 /* a packet was flushed */
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530605 flushing[if_idx] = true;
Kalle Valobdcd8172011-07-18 00:22:30 +0300606
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530607 vif->net_stats.tx_errors++;
Kalle Valobdcd8172011-07-18 00:22:30 +0300608
Kalle Valo778e6502011-10-27 18:49:08 +0300609 if (status != -ENOSPC && status != -ECANCELED)
610 ath6kl_warn("tx complete error: %d\n", status);
611
Kalle Valobdcd8172011-07-18 00:22:30 +0300612 ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
613 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
614 __func__, skb, packet->buf, packet->act_len,
615 eid, "error!");
616 } else {
617 ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
618 "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
619 __func__, skb, packet->buf, packet->act_len,
620 eid, "OK");
621
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530622 flushing[if_idx] = false;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530623 vif->net_stats.tx_packets++;
624 vif->net_stats.tx_bytes += skb->len;
Kalle Valobdcd8172011-07-18 00:22:30 +0300625 }
626
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530627 ath6kl_tx_clear_node_map(vif, eid, map_no);
Kalle Valobdcd8172011-07-18 00:22:30 +0300628
629 ath6kl_free_cookie(ar, ath6kl_cookie);
630
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530631 if (test_bit(NETQ_STOPPED, &vif->flags))
632 clear_bit(NETQ_STOPPED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300633 }
634
635 spin_unlock_bh(&ar->lock);
636
637 __skb_queue_purge(&skb_queue);
638
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530639 /* FIXME: Locking */
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530640 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530641 list_for_each_entry(vif, &ar->vif_list, list) {
642 if (test_bit(CONNECTED, &vif->flags) &&
643 !flushing[vif->fw_vif_idx]) {
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530644 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +0530645 netif_wake_queue(vif->ndev);
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530646 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530647 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300648 }
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530649 spin_unlock_bh(&ar->list_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300650
651 if (wake_event)
652 wake_up(&ar->event_wq);
653
654 return;
655
656fatal:
657 WARN_ON(1);
658 spin_unlock_bh(&ar->lock);
659 return;
660}
661
662void ath6kl_tx_data_cleanup(struct ath6kl *ar)
663{
664 int i;
665
666 /* flush all the data (non-control) streams */
667 for (i = 0; i < WMM_NUM_AC; i++)
Kalle Vaload226ec2011-08-10 09:49:12 +0300668 ath6kl_htc_flush_txep(ar->htc_target, ar->ac2ep_map[i],
669 ATH6KL_DATA_PKT_TAG);
Kalle Valobdcd8172011-07-18 00:22:30 +0300670}
671
672/* Rx functions */
673
674static void ath6kl_deliver_frames_to_nw_stack(struct net_device *dev,
675 struct sk_buff *skb)
676{
677 if (!skb)
678 return;
679
680 skb->dev = dev;
681
682 if (!(skb->dev->flags & IFF_UP)) {
683 dev_kfree_skb(skb);
684 return;
685 }
686
687 skb->protocol = eth_type_trans(skb, skb->dev);
688
689 netif_rx_ni(skb);
690}
691
692static void ath6kl_alloc_netbufs(struct sk_buff_head *q, u16 num)
693{
694 struct sk_buff *skb;
695
696 while (num) {
697 skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE);
698 if (!skb) {
699 ath6kl_err("netbuf allocation failed\n");
700 return;
701 }
702 skb_queue_tail(q, skb);
703 num--;
704 }
705}
706
707static struct sk_buff *aggr_get_free_skb(struct aggr_info *p_aggr)
708{
709 struct sk_buff *skb = NULL;
710
711 if (skb_queue_len(&p_aggr->free_q) < (AGGR_NUM_OF_FREE_NETBUFS >> 2))
712 ath6kl_alloc_netbufs(&p_aggr->free_q, AGGR_NUM_OF_FREE_NETBUFS);
713
714 skb = skb_dequeue(&p_aggr->free_q);
715
716 return skb;
717}
718
719void ath6kl_rx_refill(struct htc_target *target, enum htc_endpoint_id endpoint)
720{
721 struct ath6kl *ar = target->dev->ar;
722 struct sk_buff *skb;
723 int rx_buf;
724 int n_buf_refill;
725 struct htc_packet *packet;
726 struct list_head queue;
727
728 n_buf_refill = ATH6KL_MAX_RX_BUFFERS -
Kalle Vaload226ec2011-08-10 09:49:12 +0300729 ath6kl_htc_get_rxbuf_num(ar->htc_target, endpoint);
Kalle Valobdcd8172011-07-18 00:22:30 +0300730
731 if (n_buf_refill <= 0)
732 return;
733
734 INIT_LIST_HEAD(&queue);
735
736 ath6kl_dbg(ATH6KL_DBG_WLAN_RX,
737 "%s: providing htc with %d buffers at eid=%d\n",
738 __func__, n_buf_refill, endpoint);
739
740 for (rx_buf = 0; rx_buf < n_buf_refill; rx_buf++) {
741 skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE);
742 if (!skb)
743 break;
744
745 packet = (struct htc_packet *) skb->head;
Vasanthakumar Thiagarajan94e532d2011-08-22 20:14:31 +0530746 if (!IS_ALIGNED((unsigned long) skb->data, 4))
747 skb->data = PTR_ALIGN(skb->data - 4, 4);
Kalle Valobdcd8172011-07-18 00:22:30 +0300748 set_htc_rxpkt_info(packet, skb, skb->data,
749 ATH6KL_BUFFER_SIZE, endpoint);
750 list_add_tail(&packet->list, &queue);
751 }
752
753 if (!list_empty(&queue))
Kalle Vaload226ec2011-08-10 09:49:12 +0300754 ath6kl_htc_add_rxbuf_multiple(ar->htc_target, &queue);
Kalle Valobdcd8172011-07-18 00:22:30 +0300755}
756
757void ath6kl_refill_amsdu_rxbufs(struct ath6kl *ar, int count)
758{
759 struct htc_packet *packet;
760 struct sk_buff *skb;
761
762 while (count) {
763 skb = ath6kl_buf_alloc(ATH6KL_AMSDU_BUFFER_SIZE);
764 if (!skb)
765 return;
766
767 packet = (struct htc_packet *) skb->head;
Vasanthakumar Thiagarajan94e532d2011-08-22 20:14:31 +0530768 if (!IS_ALIGNED((unsigned long) skb->data, 4))
769 skb->data = PTR_ALIGN(skb->data - 4, 4);
Kalle Valobdcd8172011-07-18 00:22:30 +0300770 set_htc_rxpkt_info(packet, skb, skb->data,
771 ATH6KL_AMSDU_BUFFER_SIZE, 0);
772 spin_lock_bh(&ar->lock);
773 list_add_tail(&packet->list, &ar->amsdu_rx_buffer_queue);
774 spin_unlock_bh(&ar->lock);
775 count--;
776 }
777}
778
779/*
780 * Callback to allocate a receive buffer for a pending packet. We use a
781 * pre-allocated list of buffers of maximum AMSDU size (4K).
782 */
783struct htc_packet *ath6kl_alloc_amsdu_rxbuf(struct htc_target *target,
784 enum htc_endpoint_id endpoint,
785 int len)
786{
787 struct ath6kl *ar = target->dev->ar;
788 struct htc_packet *packet = NULL;
789 struct list_head *pkt_pos;
790 int refill_cnt = 0, depth = 0;
791
792 ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: eid=%d, len:%d\n",
793 __func__, endpoint, len);
794
795 if ((len <= ATH6KL_BUFFER_SIZE) ||
796 (len > ATH6KL_AMSDU_BUFFER_SIZE))
797 return NULL;
798
799 spin_lock_bh(&ar->lock);
800
801 if (list_empty(&ar->amsdu_rx_buffer_queue)) {
802 spin_unlock_bh(&ar->lock);
803 refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS;
804 goto refill_buf;
805 }
806
807 packet = list_first_entry(&ar->amsdu_rx_buffer_queue,
808 struct htc_packet, list);
809 list_del(&packet->list);
810 list_for_each(pkt_pos, &ar->amsdu_rx_buffer_queue)
811 depth++;
812
813 refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS - depth;
814 spin_unlock_bh(&ar->lock);
815
816 /* set actual endpoint ID */
817 packet->endpoint = endpoint;
818
819refill_buf:
820 if (refill_cnt >= ATH6KL_AMSDU_REFILL_THRESHOLD)
821 ath6kl_refill_amsdu_rxbufs(ar, refill_cnt);
822
823 return packet;
824}
825
826static void aggr_slice_amsdu(struct aggr_info *p_aggr,
827 struct rxtid *rxtid, struct sk_buff *skb)
828{
829 struct sk_buff *new_skb;
830 struct ethhdr *hdr;
831 u16 frame_8023_len, payload_8023_len, mac_hdr_len, amsdu_len;
832 u8 *framep;
833
834 mac_hdr_len = sizeof(struct ethhdr);
835 framep = skb->data + mac_hdr_len;
836 amsdu_len = skb->len - mac_hdr_len;
837
838 while (amsdu_len > mac_hdr_len) {
839 hdr = (struct ethhdr *) framep;
840 payload_8023_len = ntohs(hdr->h_proto);
841
842 if (payload_8023_len < MIN_MSDU_SUBFRAME_PAYLOAD_LEN ||
843 payload_8023_len > MAX_MSDU_SUBFRAME_PAYLOAD_LEN) {
844 ath6kl_err("802.3 AMSDU frame bound check failed. len %d\n",
845 payload_8023_len);
846 break;
847 }
848
849 frame_8023_len = payload_8023_len + mac_hdr_len;
850 new_skb = aggr_get_free_skb(p_aggr);
851 if (!new_skb) {
852 ath6kl_err("no buffer available\n");
853 break;
854 }
855
856 memcpy(new_skb->data, framep, frame_8023_len);
857 skb_put(new_skb, frame_8023_len);
858 if (ath6kl_wmi_dot3_2_dix(new_skb)) {
859 ath6kl_err("dot3_2_dix error\n");
860 dev_kfree_skb(new_skb);
861 break;
862 }
863
864 skb_queue_tail(&rxtid->q, new_skb);
865
866 /* Is this the last subframe within this aggregate ? */
867 if ((amsdu_len - frame_8023_len) == 0)
868 break;
869
870 /* Add the length of A-MSDU subframe padding bytes -
871 * Round to nearest word.
872 */
Vasanthakumar Thiagarajan13e34ea2011-08-16 11:19:38 +0530873 frame_8023_len = ALIGN(frame_8023_len, 4);
Kalle Valobdcd8172011-07-18 00:22:30 +0300874
875 framep += frame_8023_len;
876 amsdu_len -= frame_8023_len;
877 }
878
879 dev_kfree_skb(skb);
880}
881
882static void aggr_deque_frms(struct aggr_info *p_aggr, u8 tid,
883 u16 seq_no, u8 order)
884{
885 struct sk_buff *skb;
886 struct rxtid *rxtid;
887 struct skb_hold_q *node;
888 u16 idx, idx_end, seq_end;
889 struct rxtid_stats *stats;
890
891 if (!p_aggr)
892 return;
893
894 rxtid = &p_aggr->rx_tid[tid];
895 stats = &p_aggr->stat[tid];
896
897 idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz);
898
899 /*
900 * idx_end is typically the last possible frame in the window,
901 * but changes to 'the' seq_no, when BAR comes. If seq_no
902 * is non-zero, we will go up to that and stop.
903 * Note: last seq no in current window will occupy the same
904 * index position as index that is just previous to start.
905 * An imp point : if win_sz is 7, for seq_no space of 4095,
906 * then, there would be holes when sequence wrap around occurs.
907 * Target should judiciously choose the win_sz, based on
908 * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz
909 * 2, 4, 8, 16 win_sz works fine).
910 * We must deque from "idx" to "idx_end", including both.
911 */
912 seq_end = seq_no ? seq_no : rxtid->seq_next;
913 idx_end = AGGR_WIN_IDX(seq_end, rxtid->hold_q_sz);
914
915 spin_lock_bh(&rxtid->lock);
916
917 do {
918 node = &rxtid->hold_q[idx];
919 if ((order == 1) && (!node->skb))
920 break;
921
922 if (node->skb) {
923 if (node->is_amsdu)
924 aggr_slice_amsdu(p_aggr, rxtid, node->skb);
925 else
926 skb_queue_tail(&rxtid->q, node->skb);
927 node->skb = NULL;
928 } else
929 stats->num_hole++;
930
931 rxtid->seq_next = ATH6KL_NEXT_SEQ_NO(rxtid->seq_next);
932 idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz);
933 } while (idx != idx_end);
934
935 spin_unlock_bh(&rxtid->lock);
936
937 stats->num_delivered += skb_queue_len(&rxtid->q);
938
939 while ((skb = skb_dequeue(&rxtid->q)))
940 ath6kl_deliver_frames_to_nw_stack(p_aggr->dev, skb);
941}
942
943static bool aggr_process_recv_frm(struct aggr_info *agg_info, u8 tid,
944 u16 seq_no,
945 bool is_amsdu, struct sk_buff *frame)
946{
947 struct rxtid *rxtid;
948 struct rxtid_stats *stats;
949 struct sk_buff *skb;
950 struct skb_hold_q *node;
951 u16 idx, st, cur, end;
952 bool is_queued = false;
953 u16 extended_end;
954
955 rxtid = &agg_info->rx_tid[tid];
956 stats = &agg_info->stat[tid];
957
958 stats->num_into_aggr++;
959
960 if (!rxtid->aggr) {
961 if (is_amsdu) {
962 aggr_slice_amsdu(agg_info, rxtid, frame);
963 is_queued = true;
964 stats->num_amsdu++;
965 while ((skb = skb_dequeue(&rxtid->q)))
966 ath6kl_deliver_frames_to_nw_stack(agg_info->dev,
967 skb);
968 }
969 return is_queued;
970 }
971
972 /* Check the incoming sequence no, if it's in the window */
973 st = rxtid->seq_next;
974 cur = seq_no;
975 end = (st + rxtid->hold_q_sz-1) & ATH6KL_MAX_SEQ_NO;
976
977 if (((st < end) && (cur < st || cur > end)) ||
978 ((st > end) && (cur > end) && (cur < st))) {
979 extended_end = (end + rxtid->hold_q_sz - 1) &
980 ATH6KL_MAX_SEQ_NO;
981
982 if (((end < extended_end) &&
983 (cur < end || cur > extended_end)) ||
984 ((end > extended_end) && (cur > extended_end) &&
985 (cur < end))) {
986 aggr_deque_frms(agg_info, tid, 0, 0);
987 if (cur >= rxtid->hold_q_sz - 1)
988 rxtid->seq_next = cur - (rxtid->hold_q_sz - 1);
989 else
990 rxtid->seq_next = ATH6KL_MAX_SEQ_NO -
991 (rxtid->hold_q_sz - 2 - cur);
992 } else {
993 /*
994 * Dequeue only those frames that are outside the
995 * new shifted window.
996 */
997 if (cur >= rxtid->hold_q_sz - 1)
998 st = cur - (rxtid->hold_q_sz - 1);
999 else
1000 st = ATH6KL_MAX_SEQ_NO -
1001 (rxtid->hold_q_sz - 2 - cur);
1002
1003 aggr_deque_frms(agg_info, tid, st, 0);
1004 }
1005
1006 stats->num_oow++;
1007 }
1008
1009 idx = AGGR_WIN_IDX(seq_no, rxtid->hold_q_sz);
1010
1011 node = &rxtid->hold_q[idx];
1012
1013 spin_lock_bh(&rxtid->lock);
1014
1015 /*
1016 * Is the cur frame duplicate or something beyond our window(hold_q
1017 * -> which is 2x, already)?
1018 *
1019 * 1. Duplicate is easy - drop incoming frame.
1020 * 2. Not falling in current sliding window.
1021 * 2a. is the frame_seq_no preceding current tid_seq_no?
1022 * -> drop the frame. perhaps sender did not get our ACK.
1023 * this is taken care of above.
1024 * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ);
1025 * -> Taken care of it above, by moving window forward.
1026 */
1027 dev_kfree_skb(node->skb);
1028 stats->num_dups++;
1029
1030 node->skb = frame;
1031 is_queued = true;
1032 node->is_amsdu = is_amsdu;
1033 node->seq_no = seq_no;
1034
1035 if (node->is_amsdu)
1036 stats->num_amsdu++;
1037 else
1038 stats->num_mpdu++;
1039
1040 spin_unlock_bh(&rxtid->lock);
1041
1042 aggr_deque_frms(agg_info, tid, 0, 1);
1043
1044 if (agg_info->timer_scheduled)
1045 rxtid->progress = true;
1046 else
1047 for (idx = 0 ; idx < rxtid->hold_q_sz; idx++) {
1048 if (rxtid->hold_q[idx].skb) {
1049 /*
1050 * There is a frame in the queue and no
1051 * timer so start a timer to ensure that
1052 * the frame doesn't remain stuck
1053 * forever.
1054 */
1055 agg_info->timer_scheduled = true;
1056 mod_timer(&agg_info->timer,
1057 (jiffies +
1058 HZ * (AGGR_RX_TIMEOUT) / 1000));
1059 rxtid->progress = false;
1060 rxtid->timer_mon = true;
1061 break;
1062 }
1063 }
1064
1065 return is_queued;
1066}
1067
1068void ath6kl_rx(struct htc_target *target, struct htc_packet *packet)
1069{
1070 struct ath6kl *ar = target->dev->ar;
1071 struct sk_buff *skb = packet->pkt_cntxt;
1072 struct wmi_rx_meta_v2 *meta;
1073 struct wmi_data_hdr *dhdr;
1074 int min_hdr_len;
1075 u8 meta_type, dot11_hdr = 0;
1076 int status = packet->status;
1077 enum htc_endpoint_id ept = packet->endpoint;
1078 bool is_amsdu, prev_ps, ps_state = false;
1079 struct ath6kl_sta *conn = NULL;
1080 struct sk_buff *skb1 = NULL;
1081 struct ethhdr *datap = NULL;
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301082 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001083 u16 seq_no, offset;
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301084 u8 tid, if_idx;
Kalle Valobdcd8172011-07-18 00:22:30 +03001085
1086 ath6kl_dbg(ATH6KL_DBG_WLAN_RX,
1087 "%s: ar=0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d",
1088 __func__, ar, ept, skb, packet->buf,
1089 packet->act_len, status);
1090
1091 if (status || !(skb->data + HTC_HDR_LENGTH)) {
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301092 dev_kfree_skb(skb);
1093 return;
1094 }
1095
1096 skb_put(skb, packet->act_len + HTC_HDR_LENGTH);
1097 skb_pull(skb, HTC_HDR_LENGTH);
1098
1099 if (ept == ar->ctrl_ep) {
1100 if_idx =
1101 wmi_cmd_hdr_get_if_idx((struct wmi_cmd_hdr *) skb->data);
1102 } else {
1103 if_idx =
1104 wmi_data_hdr_get_if_idx((struct wmi_data_hdr *) skb->data);
1105 }
1106
1107 vif = ath6kl_get_vif_by_index(ar, if_idx);
1108 if (!vif) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001109 dev_kfree_skb(skb);
1110 return;
1111 }
1112
1113 /*
1114 * Take lock to protect buffer counts and adaptive power throughput
1115 * state.
1116 */
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +05301117 spin_lock_bh(&vif->if_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001118
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301119 vif->net_stats.rx_packets++;
1120 vif->net_stats.rx_bytes += packet->act_len;
Kalle Valobdcd8172011-07-18 00:22:30 +03001121
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +05301122 spin_unlock_bh(&vif->if_lock);
Vasanthakumar Thiagarajan83dc5f22011-08-14 17:08:33 +05301123
Kalle Valobdcd8172011-07-18 00:22:30 +03001124
Kalle Valoef094102011-09-27 14:30:45 +03001125 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "rx ",
1126 skb->data, skb->len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001127
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +05301128 skb->dev = vif->ndev;
Kalle Valobdcd8172011-07-18 00:22:30 +03001129
1130 if (!test_bit(WMI_ENABLED, &ar->flag)) {
1131 if (EPPING_ALIGNMENT_PAD > 0)
1132 skb_pull(skb, EPPING_ALIGNMENT_PAD);
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +05301133 ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03001134 return;
1135 }
1136
1137 if (ept == ar->ctrl_ep) {
1138 ath6kl_wmi_control_rx(ar->wmi, skb);
1139 return;
1140 }
1141
Vasanthakumar Thiagarajan67f91782011-08-14 17:08:34 +05301142 min_hdr_len = sizeof(struct ethhdr) + sizeof(struct wmi_data_hdr) +
1143 sizeof(struct ath6kl_llc_snap_hdr);
Kalle Valobdcd8172011-07-18 00:22:30 +03001144
1145 dhdr = (struct wmi_data_hdr *) skb->data;
1146
1147 /*
1148 * In the case of AP mode we may receive NULL data frames
1149 * that do not have LLC hdr. They are 16 bytes in size.
1150 * Allow these frames in the AP mode.
1151 */
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301152 if (vif->nw_type != AP_NETWORK &&
Kalle Valobdcd8172011-07-18 00:22:30 +03001153 ((packet->act_len < min_hdr_len) ||
1154 (packet->act_len > WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH))) {
1155 ath6kl_info("frame len is too short or too long\n");
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301156 vif->net_stats.rx_errors++;
1157 vif->net_stats.rx_length_errors++;
Kalle Valobdcd8172011-07-18 00:22:30 +03001158 dev_kfree_skb(skb);
1159 return;
1160 }
1161
1162 /* Get the Power save state of the STA */
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301163 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001164 meta_type = wmi_data_hdr_get_meta(dhdr);
1165
1166 ps_state = !!((dhdr->info >> WMI_DATA_HDR_PS_SHIFT) &
1167 WMI_DATA_HDR_PS_MASK);
1168
1169 offset = sizeof(struct wmi_data_hdr);
1170
1171 switch (meta_type) {
1172 case 0:
1173 break;
1174 case WMI_META_VERSION_1:
1175 offset += sizeof(struct wmi_rx_meta_v1);
1176 break;
1177 case WMI_META_VERSION_2:
1178 offset += sizeof(struct wmi_rx_meta_v2);
1179 break;
1180 default:
1181 break;
1182 }
1183
1184 datap = (struct ethhdr *) (skb->data + offset);
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301185 conn = ath6kl_find_sta(vif, datap->h_source);
Kalle Valobdcd8172011-07-18 00:22:30 +03001186
1187 if (!conn) {
1188 dev_kfree_skb(skb);
1189 return;
1190 }
1191
1192 /*
1193 * If there is a change in PS state of the STA,
1194 * take appropriate steps:
1195 *
1196 * 1. If Sleep-->Awake, flush the psq for the STA
1197 * Clear the PVB for the STA.
1198 * 2. If Awake-->Sleep, Starting queueing frames
1199 * the STA.
1200 */
1201 prev_ps = !!(conn->sta_flags & STA_PS_SLEEP);
1202
1203 if (ps_state)
1204 conn->sta_flags |= STA_PS_SLEEP;
1205 else
1206 conn->sta_flags &= ~STA_PS_SLEEP;
1207
1208 if (prev_ps ^ !!(conn->sta_flags & STA_PS_SLEEP)) {
1209 if (!(conn->sta_flags & STA_PS_SLEEP)) {
1210 struct sk_buff *skbuff = NULL;
1211
1212 spin_lock_bh(&conn->psq_lock);
1213 while ((skbuff = skb_dequeue(&conn->psq))
1214 != NULL) {
1215 spin_unlock_bh(&conn->psq_lock);
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +05301216 ath6kl_data_tx(skbuff, vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001217 spin_lock_bh(&conn->psq_lock);
1218 }
1219 spin_unlock_bh(&conn->psq_lock);
1220 /* Clear the PVB for this STA */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301221 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
1222 conn->aid, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001223 }
1224 }
1225
1226 /* drop NULL data frames here */
1227 if ((packet->act_len < min_hdr_len) ||
1228 (packet->act_len >
1229 WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH)) {
1230 dev_kfree_skb(skb);
1231 return;
1232 }
1233 }
1234
1235 is_amsdu = wmi_data_hdr_is_amsdu(dhdr) ? true : false;
1236 tid = wmi_data_hdr_get_up(dhdr);
1237 seq_no = wmi_data_hdr_get_seqno(dhdr);
1238 meta_type = wmi_data_hdr_get_meta(dhdr);
1239 dot11_hdr = wmi_data_hdr_get_dot11(dhdr);
Vasanthakumar Thiagarajan594a0bc2011-08-14 17:08:35 +05301240 skb_pull(skb, sizeof(struct wmi_data_hdr));
Kalle Valobdcd8172011-07-18 00:22:30 +03001241
1242 switch (meta_type) {
1243 case WMI_META_VERSION_1:
1244 skb_pull(skb, sizeof(struct wmi_rx_meta_v1));
1245 break;
1246 case WMI_META_VERSION_2:
1247 meta = (struct wmi_rx_meta_v2 *) skb->data;
1248 if (meta->csum_flags & 0x1) {
1249 skb->ip_summed = CHECKSUM_COMPLETE;
1250 skb->csum = (__force __wsum) meta->csum;
1251 }
1252 skb_pull(skb, sizeof(struct wmi_rx_meta_v2));
1253 break;
1254 default:
1255 break;
1256 }
1257
1258 if (dot11_hdr)
1259 status = ath6kl_wmi_dot11_hdr_remove(ar->wmi, skb);
1260 else if (!is_amsdu)
1261 status = ath6kl_wmi_dot3_2_dix(skb);
1262
1263 if (status) {
1264 /*
1265 * Drop frames that could not be processed (lack of
1266 * memory, etc.)
1267 */
1268 dev_kfree_skb(skb);
1269 return;
1270 }
1271
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +05301272 if (!(vif->ndev->flags & IFF_UP)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001273 dev_kfree_skb(skb);
1274 return;
1275 }
1276
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301277 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001278 datap = (struct ethhdr *) skb->data;
1279 if (is_multicast_ether_addr(datap->h_dest))
1280 /*
1281 * Bcast/Mcast frames should be sent to the
1282 * OS stack as well as on the air.
1283 */
1284 skb1 = skb_copy(skb, GFP_ATOMIC);
1285 else {
1286 /*
1287 * Search for a connected STA with dstMac
1288 * as the Mac address. If found send the
1289 * frame to it on the air else send the
1290 * frame up the stack.
1291 */
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301292 conn = ath6kl_find_sta(vif, datap->h_dest);
Kalle Valobdcd8172011-07-18 00:22:30 +03001293
1294 if (conn && ar->intra_bss) {
1295 skb1 = skb;
1296 skb = NULL;
1297 } else if (conn && !ar->intra_bss) {
1298 dev_kfree_skb(skb);
1299 skb = NULL;
1300 }
1301 }
1302 if (skb1)
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +05301303 ath6kl_data_tx(skb1, vif->ndev);
Kalle Vaload3f78b2011-10-06 14:32:32 +03001304
1305 if (skb == NULL) {
1306 /* nothing to deliver up the stack */
1307 return;
1308 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001309 }
1310
Kalle Valo5694f9622011-09-19 21:38:44 +03001311 datap = (struct ethhdr *) skb->data;
1312
1313 if (is_unicast_ether_addr(datap->h_dest) &&
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05301314 aggr_process_recv_frm(vif->aggr_cntxt, tid, seq_no,
Kalle Valo5694f9622011-09-19 21:38:44 +03001315 is_amsdu, skb))
1316 /* aggregation code will handle the skb */
1317 return;
1318
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +05301319 ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03001320}
1321
1322static void aggr_timeout(unsigned long arg)
1323{
1324 u8 i, j;
1325 struct aggr_info *p_aggr = (struct aggr_info *) arg;
1326 struct rxtid *rxtid;
1327 struct rxtid_stats *stats;
1328
1329 for (i = 0; i < NUM_OF_TIDS; i++) {
1330 rxtid = &p_aggr->rx_tid[i];
1331 stats = &p_aggr->stat[i];
1332
1333 if (!rxtid->aggr || !rxtid->timer_mon || rxtid->progress)
1334 continue;
1335
1336 stats->num_timeouts++;
Kalle Valo37ca6332011-07-21 10:54:26 +03001337 ath6kl_dbg(ATH6KL_DBG_AGGR,
1338 "aggr timeout (st %d end %d)\n",
Kalle Valobdcd8172011-07-18 00:22:30 +03001339 rxtid->seq_next,
1340 ((rxtid->seq_next + rxtid->hold_q_sz-1) &
1341 ATH6KL_MAX_SEQ_NO));
1342 aggr_deque_frms(p_aggr, i, 0, 0);
1343 }
1344
1345 p_aggr->timer_scheduled = false;
1346
1347 for (i = 0; i < NUM_OF_TIDS; i++) {
1348 rxtid = &p_aggr->rx_tid[i];
1349
1350 if (rxtid->aggr && rxtid->hold_q) {
1351 for (j = 0; j < rxtid->hold_q_sz; j++) {
1352 if (rxtid->hold_q[j].skb) {
1353 p_aggr->timer_scheduled = true;
1354 rxtid->timer_mon = true;
1355 rxtid->progress = false;
1356 break;
1357 }
1358 }
1359
1360 if (j >= rxtid->hold_q_sz)
1361 rxtid->timer_mon = false;
1362 }
1363 }
1364
1365 if (p_aggr->timer_scheduled)
1366 mod_timer(&p_aggr->timer,
1367 jiffies + msecs_to_jiffies(AGGR_RX_TIMEOUT));
1368}
1369
1370static void aggr_delete_tid_state(struct aggr_info *p_aggr, u8 tid)
1371{
1372 struct rxtid *rxtid;
1373 struct rxtid_stats *stats;
1374
1375 if (!p_aggr || tid >= NUM_OF_TIDS)
1376 return;
1377
1378 rxtid = &p_aggr->rx_tid[tid];
1379 stats = &p_aggr->stat[tid];
1380
1381 if (rxtid->aggr)
1382 aggr_deque_frms(p_aggr, tid, 0, 0);
1383
1384 rxtid->aggr = false;
1385 rxtid->progress = false;
1386 rxtid->timer_mon = false;
1387 rxtid->win_sz = 0;
1388 rxtid->seq_next = 0;
1389 rxtid->hold_q_sz = 0;
1390
1391 kfree(rxtid->hold_q);
1392 rxtid->hold_q = NULL;
1393
1394 memset(stats, 0, sizeof(struct rxtid_stats));
1395}
1396
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301397void aggr_recv_addba_req_evt(struct ath6kl_vif *vif, u8 tid, u16 seq_no,
1398 u8 win_sz)
Kalle Valobdcd8172011-07-18 00:22:30 +03001399{
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05301400 struct aggr_info *p_aggr = vif->aggr_cntxt;
Kalle Valobdcd8172011-07-18 00:22:30 +03001401 struct rxtid *rxtid;
1402 struct rxtid_stats *stats;
1403 u16 hold_q_size;
1404
1405 if (!p_aggr)
1406 return;
1407
1408 rxtid = &p_aggr->rx_tid[tid];
1409 stats = &p_aggr->stat[tid];
1410
1411 if (win_sz < AGGR_WIN_SZ_MIN || win_sz > AGGR_WIN_SZ_MAX)
1412 ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: win_sz %d, tid %d\n",
1413 __func__, win_sz, tid);
1414
1415 if (rxtid->aggr)
1416 aggr_delete_tid_state(p_aggr, tid);
1417
1418 rxtid->seq_next = seq_no;
1419 hold_q_size = TID_WINDOW_SZ(win_sz) * sizeof(struct skb_hold_q);
1420 rxtid->hold_q = kzalloc(hold_q_size, GFP_KERNEL);
1421 if (!rxtid->hold_q)
1422 return;
1423
1424 rxtid->win_sz = win_sz;
1425 rxtid->hold_q_sz = TID_WINDOW_SZ(win_sz);
1426 if (!skb_queue_empty(&rxtid->q))
1427 return;
1428
1429 rxtid->aggr = true;
1430}
1431
1432struct aggr_info *aggr_init(struct net_device *dev)
1433{
1434 struct aggr_info *p_aggr = NULL;
1435 struct rxtid *rxtid;
1436 u8 i;
1437
1438 p_aggr = kzalloc(sizeof(struct aggr_info), GFP_KERNEL);
1439 if (!p_aggr) {
1440 ath6kl_err("failed to alloc memory for aggr_node\n");
1441 return NULL;
1442 }
1443
1444 p_aggr->aggr_sz = AGGR_SZ_DEFAULT;
1445 p_aggr->dev = dev;
1446 init_timer(&p_aggr->timer);
1447 p_aggr->timer.function = aggr_timeout;
1448 p_aggr->timer.data = (unsigned long) p_aggr;
1449
1450 p_aggr->timer_scheduled = false;
1451 skb_queue_head_init(&p_aggr->free_q);
1452
1453 ath6kl_alloc_netbufs(&p_aggr->free_q, AGGR_NUM_OF_FREE_NETBUFS);
1454
1455 for (i = 0; i < NUM_OF_TIDS; i++) {
1456 rxtid = &p_aggr->rx_tid[i];
1457 rxtid->aggr = false;
1458 rxtid->progress = false;
1459 rxtid->timer_mon = false;
1460 skb_queue_head_init(&rxtid->q);
1461 spin_lock_init(&rxtid->lock);
1462 }
1463
1464 return p_aggr;
1465}
1466
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301467void aggr_recv_delba_req_evt(struct ath6kl_vif *vif, u8 tid)
Kalle Valobdcd8172011-07-18 00:22:30 +03001468{
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05301469 struct aggr_info *p_aggr = vif->aggr_cntxt;
Kalle Valobdcd8172011-07-18 00:22:30 +03001470 struct rxtid *rxtid;
1471
1472 if (!p_aggr)
1473 return;
1474
1475 rxtid = &p_aggr->rx_tid[tid];
1476
1477 if (rxtid->aggr)
1478 aggr_delete_tid_state(p_aggr, tid);
1479}
1480
1481void aggr_reset_state(struct aggr_info *aggr_info)
1482{
1483 u8 tid;
1484
1485 for (tid = 0; tid < NUM_OF_TIDS; tid++)
1486 aggr_delete_tid_state(aggr_info, tid);
1487}
1488
1489/* clean up our amsdu buffer list */
1490void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl *ar)
1491{
1492 struct htc_packet *packet, *tmp_pkt;
1493
1494 spin_lock_bh(&ar->lock);
1495 if (list_empty(&ar->amsdu_rx_buffer_queue)) {
1496 spin_unlock_bh(&ar->lock);
1497 return;
1498 }
1499
1500 list_for_each_entry_safe(packet, tmp_pkt, &ar->amsdu_rx_buffer_queue,
1501 list) {
1502 list_del(&packet->list);
1503 spin_unlock_bh(&ar->lock);
1504 dev_kfree_skb(packet->pkt_cntxt);
1505 spin_lock_bh(&ar->lock);
1506 }
1507
1508 spin_unlock_bh(&ar->lock);
1509}
1510
1511void aggr_module_destroy(struct aggr_info *aggr_info)
1512{
1513 struct rxtid *rxtid;
1514 u8 i, k;
1515
1516 if (!aggr_info)
1517 return;
1518
1519 if (aggr_info->timer_scheduled) {
1520 del_timer(&aggr_info->timer);
1521 aggr_info->timer_scheduled = false;
1522 }
1523
1524 for (i = 0; i < NUM_OF_TIDS; i++) {
1525 rxtid = &aggr_info->rx_tid[i];
1526 if (rxtid->hold_q) {
1527 for (k = 0; k < rxtid->hold_q_sz; k++)
1528 dev_kfree_skb(rxtid->hold_q[k].skb);
1529 kfree(rxtid->hold_q);
1530 }
1531
1532 skb_queue_purge(&rxtid->q);
1533 }
1534
1535 skb_queue_purge(&aggr_info->free_q);
1536 kfree(aggr_info);
1537}