mac80211: fix aggregation to not require queue stop
[deliverable/linux.git] / net / mac80211 / agg-tx.c
CommitLineData
b8695a8f
JB
1/*
2 * HT handling
3 *
4 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
5 * Copyright 2002-2005, Instant802 Networks, Inc.
6 * Copyright 2005-2006, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2007-2009, Intel Corporation
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/ieee80211.h>
17#include <net/mac80211.h>
18#include "ieee80211_i.h"
19#include "wme.h"
20
86ab6c5a
JB
21/**
22 * DOC: TX aggregation
23 *
24 * Aggregation on the TX side requires setting the hardware flag
25 * %IEEE80211_HW_AMPDU_AGGREGATION as well as, if present, the @ampdu_queues
26 * hardware parameter to the number of hardware AMPDU queues. If there are no
27 * hardware queues then the driver will (currently) have to do all frame
28 * buffering.
29 *
30 * When TX aggregation is started by some subsystem (usually the rate control
31 * algorithm would be appropriate) by calling the
32 * ieee80211_start_tx_ba_session() function, the driver will be notified via
33 * its @ampdu_action function, with the %IEEE80211_AMPDU_TX_START action.
34 *
35 * In response to that, the driver is later required to call the
36 * ieee80211_start_tx_ba_cb() (or ieee80211_start_tx_ba_cb_irqsafe())
37 * function, which will start the aggregation session.
38 *
39 * Similarly, when the aggregation session is stopped by
40 * ieee80211_stop_tx_ba_session(), the driver's @ampdu_action function will
41 * be called with the action %IEEE80211_AMPDU_TX_STOP. In this case, the
42 * call must not fail, and the driver must later call ieee80211_stop_tx_ba_cb()
43 * (or ieee80211_stop_tx_ba_cb_irqsafe()).
44 */
45
b8695a8f
JB
46static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
47 const u8 *da, u16 tid,
48 u8 dialog_token, u16 start_seq_num,
49 u16 agg_size, u16 timeout)
50{
51 struct ieee80211_local *local = sdata->local;
b8695a8f
JB
52 struct sk_buff *skb;
53 struct ieee80211_mgmt *mgmt;
54 u16 capab;
55
56 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
57
58 if (!skb) {
59 printk(KERN_ERR "%s: failed to allocate buffer "
60 "for addba request frame\n", sdata->dev->name);
61 return;
62 }
63 skb_reserve(skb, local->hw.extra_tx_headroom);
64 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
65 memset(mgmt, 0, 24);
66 memcpy(mgmt->da, da, ETH_ALEN);
67 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
8abd3f9b
JB
68 if (sdata->vif.type == NL80211_IFTYPE_AP ||
69 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
b8695a8f 70 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
46900298
JB
71 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
72 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
b8695a8f
JB
73
74 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
75 IEEE80211_STYPE_ACTION);
76
77 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
78
79 mgmt->u.action.category = WLAN_CATEGORY_BACK;
80 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
81
82 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
83 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
84 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
85 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
86
87 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
88
89 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
90 mgmt->u.action.u.addba_req.start_seq_num =
91 cpu_to_le16(start_seq_num << 4);
92
93 ieee80211_tx_skb(sdata, skb, 1);
94}
95
96void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn)
97{
98 struct ieee80211_local *local = sdata->local;
99 struct sk_buff *skb;
100 struct ieee80211_bar *bar;
101 u16 bar_control = 0;
102
103 skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
104 if (!skb) {
105 printk(KERN_ERR "%s: failed to allocate buffer for "
106 "bar frame\n", sdata->dev->name);
107 return;
108 }
109 skb_reserve(skb, local->hw.extra_tx_headroom);
110 bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
111 memset(bar, 0, sizeof(*bar));
112 bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
113 IEEE80211_STYPE_BACK_REQ);
114 memcpy(bar->ra, ra, ETH_ALEN);
115 memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN);
116 bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
117 bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
118 bar_control |= (u16)(tid << 12);
119 bar->control = cpu_to_le16(bar_control);
120 bar->start_seq_num = cpu_to_le16(ssn);
121
122 ieee80211_tx_skb(sdata, skb, 0);
123}
124
849b7967
JB
125static int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
126 enum ieee80211_back_parties initiator)
23e6a7ea 127{
849b7967 128 struct ieee80211_local *local = sta->local;
23e6a7ea
JB
129 int ret;
130 u8 *state;
131
132 state = &sta->ampdu_mlme.tid_state_tx[tid];
133
96f5e66e 134 if (local->hw.ampdu_queues) {
96f5e66e
JB
135 /*
136 * Pretend the driver woke the queue, just in case
137 * it disabled it before the session was stopped.
138 */
139 ieee80211_wake_queue(
140 &local->hw, local->hw.queues + sta->tid_to_tx_q[tid]);
141 }
23e6a7ea
JB
142 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
143 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
144
145 ret = local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_STOP,
146 &sta->sta, tid, NULL);
147
148 /* HW shall not deny going back to legacy */
149 if (WARN_ON(ret)) {
150 *state = HT_AGG_STATE_OPERATIONAL;
cd8ffc80
JB
151 /*
152 * We may have pending packets get stuck in this case...
153 * Not bothering with a workaround for now.
154 */
23e6a7ea
JB
155 }
156
157 return ret;
158}
159
b8695a8f
JB
160/*
161 * After sending add Block Ack request we activated a timer until
162 * add Block Ack response will arrive from the recipient.
163 * If this timer expires sta_addba_resp_timer_expired will be executed.
164 */
165static void sta_addba_resp_timer_expired(unsigned long data)
166{
167 /* not an elegant detour, but there is no choice as the timer passes
168 * only one argument, and both sta_info and TID are needed, so init
169 * flow in sta_info_create gives the TID as data, while the timer_to_id
170 * array gives the sta through container_of */
171 u16 tid = *(u8 *)data;
23e6a7ea 172 struct sta_info *sta = container_of((void *)data,
b8695a8f 173 struct sta_info, timer_to_tid[tid]);
b8695a8f
JB
174 u8 *state;
175
b8695a8f 176 state = &sta->ampdu_mlme.tid_state_tx[tid];
23e6a7ea 177
b8695a8f
JB
178 /* check if the TID waits for addBA response */
179 spin_lock_bh(&sta->lock);
180 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
181 spin_unlock_bh(&sta->lock);
182 *state = HT_AGG_STATE_IDLE;
183#ifdef CONFIG_MAC80211_HT_DEBUG
184 printk(KERN_DEBUG "timer expired on tid %d but we are not "
185 "expecting addBA response there", tid);
186#endif
23e6a7ea 187 return;
b8695a8f
JB
188 }
189
190#ifdef CONFIG_MAC80211_HT_DEBUG
191 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
192#endif
193
849b7967 194 ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
b8695a8f 195 spin_unlock_bh(&sta->lock);
b8695a8f
JB
196}
197
96f5e66e
JB
198static inline int ieee80211_ac_from_tid(int tid)
199{
200 return ieee802_1d_to_ac[tid & 7];
201}
202
b8695a8f
JB
203int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
204{
205 struct ieee80211_local *local = hw_to_local(hw);
206 struct sta_info *sta;
207 struct ieee80211_sub_if_data *sdata;
b8695a8f 208 u8 *state;
96f5e66e
JB
209 int i, qn = -1, ret = 0;
210 u16 start_seq_num;
b8695a8f 211
23e6a7ea
JB
212 if (WARN_ON(!local->ops->ampdu_action))
213 return -EINVAL;
214
b8695a8f
JB
215 if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
216 return -EINVAL;
217
218#ifdef CONFIG_MAC80211_HT_DEBUG
219 printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
220 ra, tid);
221#endif /* CONFIG_MAC80211_HT_DEBUG */
222
223 rcu_read_lock();
224
225 sta = sta_info_get(local, ra);
226 if (!sta) {
227#ifdef CONFIG_MAC80211_HT_DEBUG
228 printk(KERN_DEBUG "Could not find the station\n");
229#endif
230 ret = -ENOENT;
96f5e66e 231 goto unlock;
b8695a8f
JB
232 }
233
8abd3f9b
JB
234 /*
235 * The aggregation code is not prepared to handle
236 * anything but STA/AP due to the BSSID handling.
237 * IBSS could work in the code but isn't supported
238 * by drivers or the standard.
239 */
240 if (sta->sdata->vif.type != NL80211_IFTYPE_STATION &&
241 sta->sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
242 sta->sdata->vif.type != NL80211_IFTYPE_AP) {
243 ret = -EINVAL;
96f5e66e 244 goto unlock;
8abd3f9b
JB
245 }
246
722f069a
S
247 if (test_sta_flags(sta, WLAN_STA_SUSPEND)) {
248#ifdef CONFIG_MAC80211_HT_DEBUG
249 printk(KERN_DEBUG "Suspend in progress. "
250 "Denying BA session request\n");
251#endif
252 ret = -EINVAL;
253 goto unlock;
254 }
255
b8695a8f 256 spin_lock_bh(&sta->lock);
cd8ffc80 257 spin_lock(&local->ampdu_lock);
b8695a8f 258
96f5e66e
JB
259 sdata = sta->sdata;
260
b8695a8f
JB
261 /* we have tried too many times, receiver does not want A-MPDU */
262 if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
263 ret = -EBUSY;
264 goto err_unlock_sta;
265 }
266
267 state = &sta->ampdu_mlme.tid_state_tx[tid];
268 /* check if the TID is not in aggregation flow already */
269 if (*state != HT_AGG_STATE_IDLE) {
270#ifdef CONFIG_MAC80211_HT_DEBUG
271 printk(KERN_DEBUG "BA request denied - session is not "
272 "idle on tid %u\n", tid);
273#endif /* CONFIG_MAC80211_HT_DEBUG */
274 ret = -EAGAIN;
275 goto err_unlock_sta;
276 }
277
96f5e66e
JB
278 if (hw->ampdu_queues) {
279 spin_lock(&local->queue_stop_reason_lock);
280 /* reserve a new queue for this session */
281 for (i = 0; i < local->hw.ampdu_queues; i++) {
282 if (local->ampdu_ac_queue[i] < 0) {
283 qn = i;
284 local->ampdu_ac_queue[qn] =
285 ieee80211_ac_from_tid(tid);
286 break;
287 }
288 }
289 spin_unlock(&local->queue_stop_reason_lock);
290
291 if (qn < 0) {
292#ifdef CONFIG_MAC80211_HT_DEBUG
293 printk(KERN_DEBUG "BA request denied - "
294 "queue unavailable for tid %d\n", tid);
295#endif /* CONFIG_MAC80211_HT_DEBUG */
296 ret = -ENOSPC;
297 goto err_unlock_sta;
298 }
96f5e66e
JB
299 }
300
cd8ffc80
JB
301 /*
302 * While we're asking the driver about the aggregation,
303 * stop the AC queue so that we don't have to worry
304 * about frames that came in while we were doing that,
305 * which would require us to put them to the AC pending
306 * afterwards which just makes the code more complex.
307 */
308 ieee80211_stop_queue_by_reason(
309 &local->hw, ieee80211_ac_from_tid(tid),
310 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
311
b8695a8f
JB
312 /* prepare A-MPDU MLME for Tx aggregation */
313 sta->ampdu_mlme.tid_tx[tid] =
314 kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
315 if (!sta->ampdu_mlme.tid_tx[tid]) {
316#ifdef CONFIG_MAC80211_HT_DEBUG
317 if (net_ratelimit())
318 printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
319 tid);
320#endif
321 ret = -ENOMEM;
96f5e66e 322 goto err_return_queue;
b8695a8f 323 }
96f5e66e 324
cd8ffc80
JB
325 skb_queue_head_init(&sta->ampdu_mlme.tid_tx[tid]->pending);
326
b8695a8f
JB
327 /* Tx timer */
328 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
329 sta_addba_resp_timer_expired;
330 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
331 (unsigned long)&sta->timer_to_tid[tid];
332 init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
333
b8695a8f
JB
334 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
335 * call back right away, it must see that the flow has begun */
336 *state |= HT_ADDBA_REQUESTED_MSK;
337
b8695a8f
JB
338 start_seq_num = sta->tid_seq[tid];
339
23e6a7ea
JB
340 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
341 &sta->sta, tid, &start_seq_num);
b8695a8f
JB
342
343 if (ret) {
b8695a8f
JB
344#ifdef CONFIG_MAC80211_HT_DEBUG
345 printk(KERN_DEBUG "BA request denied - HW unavailable for"
346 " tid %d\n", tid);
347#endif /* CONFIG_MAC80211_HT_DEBUG */
348 *state = HT_AGG_STATE_IDLE;
96f5e66e 349 goto err_free;
b8695a8f 350 }
96f5e66e 351 sta->tid_to_tx_q[tid] = qn;
b8695a8f 352
cd8ffc80
JB
353 /* Driver vetoed or OKed, but we can take packets again now */
354 ieee80211_wake_queue_by_reason(
355 &local->hw, ieee80211_ac_from_tid(tid),
356 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
357
358 spin_unlock(&local->ampdu_lock);
b8695a8f
JB
359 spin_unlock_bh(&sta->lock);
360
361 /* send an addBA request */
362 sta->ampdu_mlme.dialog_token_allocator++;
363 sta->ampdu_mlme.tid_tx[tid]->dialog_token =
364 sta->ampdu_mlme.dialog_token_allocator;
365 sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
366
b8695a8f
JB
367 ieee80211_send_addba_request(sta->sdata, ra, tid,
368 sta->ampdu_mlme.tid_tx[tid]->dialog_token,
369 sta->ampdu_mlme.tid_tx[tid]->ssn,
370 0x40, 5000);
371 /* activate the timer for the recipient's addBA response */
372 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
373 jiffies + ADDBA_RESP_INTERVAL;
374 add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
375#ifdef CONFIG_MAC80211_HT_DEBUG
376 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
377#endif
96f5e66e 378 goto unlock;
b8695a8f 379
96f5e66e 380 err_free:
b8695a8f
JB
381 kfree(sta->ampdu_mlme.tid_tx[tid]);
382 sta->ampdu_mlme.tid_tx[tid] = NULL;
96f5e66e
JB
383 err_return_queue:
384 if (qn >= 0) {
96f5e66e
JB
385 /* give queue back to pool */
386 spin_lock(&local->queue_stop_reason_lock);
387 local->ampdu_ac_queue[qn] = -1;
388 spin_unlock(&local->queue_stop_reason_lock);
389 }
cd8ffc80
JB
390 ieee80211_wake_queue_by_reason(
391 &local->hw, ieee80211_ac_from_tid(tid),
392 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
96f5e66e 393 err_unlock_sta:
cd8ffc80 394 spin_unlock(&local->ampdu_lock);
b8695a8f 395 spin_unlock_bh(&sta->lock);
96f5e66e 396 unlock:
b8695a8f
JB
397 rcu_read_unlock();
398 return ret;
399}
400EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
401
cd8ffc80
JB
402/*
403 * splice packets from the STA's pending to the local pending,
404 * requires a call to ieee80211_agg_splice_finish and holding
405 * local->ampdu_lock across both calls.
406 */
407static void ieee80211_agg_splice_packets(struct ieee80211_local *local,
408 struct sta_info *sta, u16 tid)
409{
410 unsigned long flags;
411 u16 queue = ieee80211_ac_from_tid(tid);
412
413 ieee80211_stop_queue_by_reason(
414 &local->hw, queue,
415 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
416
417 if (!skb_queue_empty(&sta->ampdu_mlme.tid_tx[tid]->pending)) {
418 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
419 /* mark queue as pending, it is stopped already */
420 __set_bit(IEEE80211_QUEUE_STOP_REASON_PENDING,
421 &local->queue_stop_reasons[queue]);
422 /* copy over remaining packets */
423 skb_queue_splice_tail_init(
424 &sta->ampdu_mlme.tid_tx[tid]->pending,
425 &local->pending[queue]);
426 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
427 }
428}
429
430static void ieee80211_agg_splice_finish(struct ieee80211_local *local,
431 struct sta_info *sta, u16 tid)
432{
433 u16 queue = ieee80211_ac_from_tid(tid);
434
435 ieee80211_wake_queue_by_reason(
436 &local->hw, queue,
437 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
438}
439
440/* caller must hold sta->lock */
b1720231
JB
441static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
442 struct sta_info *sta, u16 tid)
443{
444#ifdef CONFIG_MAC80211_HT_DEBUG
445 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
446#endif
447
cd8ffc80
JB
448 spin_lock(&local->ampdu_lock);
449 ieee80211_agg_splice_packets(local, sta, tid);
450 /*
451 * NB: we rely on sta->lock being taken in the TX
452 * processing here when adding to the pending queue,
453 * otherwise we could only change the state of the
454 * session to OPERATIONAL _here_.
455 */
456 ieee80211_agg_splice_finish(local, sta, tid);
457 spin_unlock(&local->ampdu_lock);
b1720231
JB
458
459 local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_OPERATIONAL,
460 &sta->sta, tid, NULL);
461}
462
b8695a8f
JB
463void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
464{
465 struct ieee80211_local *local = hw_to_local(hw);
466 struct sta_info *sta;
467 u8 *state;
468
469 if (tid >= STA_TID_NUM) {
470#ifdef CONFIG_MAC80211_HT_DEBUG
471 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
472 tid, STA_TID_NUM);
473#endif
474 return;
475 }
476
477 rcu_read_lock();
478 sta = sta_info_get(local, ra);
479 if (!sta) {
480 rcu_read_unlock();
481#ifdef CONFIG_MAC80211_HT_DEBUG
482 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
483#endif
484 return;
485 }
486
487 state = &sta->ampdu_mlme.tid_state_tx[tid];
488 spin_lock_bh(&sta->lock);
489
96f5e66e 490 if (WARN_ON(!(*state & HT_ADDBA_REQUESTED_MSK))) {
b8695a8f
JB
491#ifdef CONFIG_MAC80211_HT_DEBUG
492 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
493 *state);
494#endif
495 spin_unlock_bh(&sta->lock);
496 rcu_read_unlock();
497 return;
498 }
499
96f5e66e
JB
500 if (WARN_ON(*state & HT_ADDBA_DRV_READY_MSK))
501 goto out;
b8695a8f
JB
502
503 *state |= HT_ADDBA_DRV_READY_MSK;
504
b1720231
JB
505 if (*state == HT_AGG_STATE_OPERATIONAL)
506 ieee80211_agg_tx_operational(local, sta, tid);
96f5e66e
JB
507
508 out:
b8695a8f
JB
509 spin_unlock_bh(&sta->lock);
510 rcu_read_unlock();
511}
512EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
513
86ab6c5a
JB
514void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
515 const u8 *ra, u16 tid)
516{
517 struct ieee80211_local *local = hw_to_local(hw);
518 struct ieee80211_ra_tid *ra_tid;
519 struct sk_buff *skb = dev_alloc_skb(0);
520
521 if (unlikely(!skb)) {
522#ifdef CONFIG_MAC80211_HT_DEBUG
523 if (net_ratelimit())
524 printk(KERN_WARNING "%s: Not enough memory, "
525 "dropping start BA session", skb->dev->name);
526#endif
527 return;
528 }
529 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
530 memcpy(&ra_tid->ra, ra, ETH_ALEN);
531 ra_tid->tid = tid;
532
533 skb->pkt_type = IEEE80211_ADDBA_MSG;
534 skb_queue_tail(&local->skb_queue, skb);
535 tasklet_schedule(&local->tasklet);
536}
537EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
538
849b7967
JB
539int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
540 enum ieee80211_back_parties initiator)
541{
542 u8 *state;
543 int ret;
544
545 /* check if the TID is in aggregation */
546 state = &sta->ampdu_mlme.tid_state_tx[tid];
547 spin_lock_bh(&sta->lock);
548
549 if (*state != HT_AGG_STATE_OPERATIONAL) {
550 ret = -ENOENT;
551 goto unlock;
552 }
553
554#ifdef CONFIG_MAC80211_HT_DEBUG
555 printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
556 sta->sta.addr, tid);
557#endif /* CONFIG_MAC80211_HT_DEBUG */
558
559 ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator);
560
561 unlock:
562 spin_unlock_bh(&sta->lock);
563 return ret;
564}
b8695a8f
JB
565
566int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
567 u8 *ra, u16 tid,
568 enum ieee80211_back_parties initiator)
569{
570 struct ieee80211_local *local = hw_to_local(hw);
571 struct sta_info *sta;
b8695a8f
JB
572 int ret = 0;
573
23e6a7ea
JB
574 if (WARN_ON(!local->ops->ampdu_action))
575 return -EINVAL;
576
b8695a8f
JB
577 if (tid >= STA_TID_NUM)
578 return -EINVAL;
579
580 rcu_read_lock();
581 sta = sta_info_get(local, ra);
582 if (!sta) {
583 rcu_read_unlock();
584 return -ENOENT;
585 }
586
849b7967 587 ret = __ieee80211_stop_tx_ba_session(sta, tid, initiator);
b8695a8f
JB
588 rcu_read_unlock();
589 return ret;
590}
591EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
592
593void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
594{
595 struct ieee80211_local *local = hw_to_local(hw);
596 struct sta_info *sta;
597 u8 *state;
b8695a8f
JB
598
599 if (tid >= STA_TID_NUM) {
600#ifdef CONFIG_MAC80211_HT_DEBUG
601 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
602 tid, STA_TID_NUM);
603#endif
604 return;
605 }
606
607#ifdef CONFIG_MAC80211_HT_DEBUG
608 printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
609 ra, tid);
610#endif /* CONFIG_MAC80211_HT_DEBUG */
611
612 rcu_read_lock();
613 sta = sta_info_get(local, ra);
614 if (!sta) {
615#ifdef CONFIG_MAC80211_HT_DEBUG
616 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
617#endif
618 rcu_read_unlock();
619 return;
620 }
621 state = &sta->ampdu_mlme.tid_state_tx[tid];
622
623 /* NOTE: no need to use sta->lock in this state check, as
624 * ieee80211_stop_tx_ba_session will let only one stop call to
625 * pass through per sta/tid
626 */
627 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
628#ifdef CONFIG_MAC80211_HT_DEBUG
629 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
630#endif
631 rcu_read_unlock();
632 return;
633 }
634
635 if (*state & HT_AGG_STATE_INITIATOR_MSK)
636 ieee80211_send_delba(sta->sdata, ra, tid,
637 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
638
96f5e66e 639 spin_lock_bh(&sta->lock);
cd8ffc80 640 spin_lock(&local->ampdu_lock);
b8695a8f 641
cd8ffc80 642 ieee80211_agg_splice_packets(local, sta, tid);
96f5e66e 643
b8695a8f 644 *state = HT_AGG_STATE_IDLE;
cd8ffc80 645 /* from now on packets are no longer put onto sta->pending */
b8695a8f
JB
646 sta->ampdu_mlme.addba_req_num[tid] = 0;
647 kfree(sta->ampdu_mlme.tid_tx[tid]);
648 sta->ampdu_mlme.tid_tx[tid] = NULL;
cd8ffc80
JB
649
650 ieee80211_agg_splice_finish(local, sta, tid);
651
652 spin_unlock(&local->ampdu_lock);
b8695a8f
JB
653 spin_unlock_bh(&sta->lock);
654
655 rcu_read_unlock();
656}
657EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
658
b8695a8f
JB
659void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
660 const u8 *ra, u16 tid)
661{
662 struct ieee80211_local *local = hw_to_local(hw);
663 struct ieee80211_ra_tid *ra_tid;
664 struct sk_buff *skb = dev_alloc_skb(0);
665
666 if (unlikely(!skb)) {
667#ifdef CONFIG_MAC80211_HT_DEBUG
668 if (net_ratelimit())
669 printk(KERN_WARNING "%s: Not enough memory, "
670 "dropping stop BA session", skb->dev->name);
671#endif
672 return;
673 }
674 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
675 memcpy(&ra_tid->ra, ra, ETH_ALEN);
676 ra_tid->tid = tid;
677
678 skb->pkt_type = IEEE80211_DELBA_MSG;
679 skb_queue_tail(&local->skb_queue, skb);
680 tasklet_schedule(&local->tasklet);
681}
682EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
683
86ab6c5a 684
b8695a8f
JB
685void ieee80211_process_addba_resp(struct ieee80211_local *local,
686 struct sta_info *sta,
687 struct ieee80211_mgmt *mgmt,
688 size_t len)
689{
b1720231 690 u16 capab, tid;
b8695a8f
JB
691 u8 *state;
692
693 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
694 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
695
696 state = &sta->ampdu_mlme.tid_state_tx[tid];
697
698 spin_lock_bh(&sta->lock);
699
700 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
701 spin_unlock_bh(&sta->lock);
702 return;
703 }
704
705 if (mgmt->u.action.u.addba_resp.dialog_token !=
706 sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
707 spin_unlock_bh(&sta->lock);
708#ifdef CONFIG_MAC80211_HT_DEBUG
709 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
710#endif /* CONFIG_MAC80211_HT_DEBUG */
711 return;
712 }
713
714 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
715#ifdef CONFIG_MAC80211_HT_DEBUG
716 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
717#endif /* CONFIG_MAC80211_HT_DEBUG */
718 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
719 == WLAN_STATUS_SUCCESS) {
96f5e66e
JB
720 u8 curstate = *state;
721
b8695a8f 722 *state |= HT_ADDBA_RECEIVED_MSK;
b8695a8f 723
b1720231
JB
724 if (*state != curstate && *state == HT_AGG_STATE_OPERATIONAL)
725 ieee80211_agg_tx_operational(local, sta, tid);
b8695a8f 726
b1720231 727 sta->ampdu_mlme.addba_req_num[tid] = 0;
b8695a8f
JB
728 } else {
729 sta->ampdu_mlme.addba_req_num[tid]++;
849b7967 730 ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
b8695a8f 731 }
849b7967 732 spin_unlock_bh(&sta->lock);
b8695a8f 733}
This page took 0.073388 seconds and 5 git commands to generate.