blob: d448f7a3dbc034498ea2948c0a5ec2e0fc87604b [file] [log] [blame]
Johannes Bergb8695a82009-02-10 21:25:46 +01001/*
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>
Johannes Bergcfcdbde2010-06-10 10:21:48 +02009 * Copyright 2007-2010, Intel Corporation
Johannes Bergb8695a82009-02-10 21:25:46 +010010 *
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Johannes Bergb8695a82009-02-10 21:25:46 +010018#include <net/mac80211.h>
19#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020020#include "driver-ops.h"
Johannes Bergb8695a82009-02-10 21:25:46 +010021#include "wme.h"
22
Johannes Berg86ab6c52009-02-10 21:25:49 +010023/**
Johannes Berg73a72a82010-06-10 10:21:50 +020024 * DOC: TX A-MPDU aggregation
Johannes Berg86ab6c52009-02-10 21:25:49 +010025 *
26 * Aggregation on the TX side requires setting the hardware flag
Johannes Berg73a72a82010-06-10 10:21:50 +020027 * %IEEE80211_HW_AMPDU_AGGREGATION. The driver will then be handed
28 * packets with a flag indicating A-MPDU aggregation. The driver
29 * or device is responsible for actually aggregating the frames,
30 * as well as deciding how many and which to aggregate.
Johannes Berg86ab6c52009-02-10 21:25:49 +010031 *
Johannes Berg73a72a82010-06-10 10:21:50 +020032 * When TX aggregation is started by some subsystem (usually the rate
33 * control algorithm would be appropriate) by calling the
34 * ieee80211_start_tx_ba_session() function, the driver will be
35 * notified via its @ampdu_action function, with the
36 * %IEEE80211_AMPDU_TX_START action.
Johannes Berg86ab6c52009-02-10 21:25:49 +010037 *
38 * In response to that, the driver is later required to call the
Johannes Berg73a72a82010-06-10 10:21:50 +020039 * ieee80211_start_tx_ba_cb_irqsafe() function, which will really
40 * start the aggregation session after the peer has also responded.
41 * If the peer responds negatively, the session will be stopped
42 * again right away. Note that it is possible for the aggregation
43 * session to be stopped before the driver has indicated that it
44 * is done setting it up, in which case it must not indicate the
45 * setup completion.
Johannes Berg86ab6c52009-02-10 21:25:49 +010046 *
Johannes Berg73a72a82010-06-10 10:21:50 +020047 * Also note that, since we also need to wait for a response from
48 * the peer, the driver is notified of the completion of the
49 * handshake by the %IEEE80211_AMPDU_TX_OPERATIONAL action to the
50 * @ampdu_action callback.
51 *
52 * Similarly, when the aggregation session is stopped by the peer
53 * or something calling ieee80211_stop_tx_ba_session(), the driver's
54 * @ampdu_action function will be called with the action
55 * %IEEE80211_AMPDU_TX_STOP. In this case, the call must not fail,
56 * and the driver must later call ieee80211_stop_tx_ba_cb_irqsafe().
Johannes Berg86ab6c52009-02-10 21:25:49 +010057 */
58
Johannes Bergb8695a82009-02-10 21:25:46 +010059static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
60 const u8 *da, u16 tid,
61 u8 dialog_token, u16 start_seq_num,
62 u16 agg_size, u16 timeout)
63{
64 struct ieee80211_local *local = sdata->local;
Johannes Bergb8695a82009-02-10 21:25:46 +010065 struct sk_buff *skb;
66 struct ieee80211_mgmt *mgmt;
67 u16 capab;
68
69 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
70
Joe Perchesd15b8452011-08-29 14:17:31 -070071 if (!skb)
Johannes Bergb8695a82009-02-10 21:25:46 +010072 return;
Joe Perchesd15b8452011-08-29 14:17:31 -070073
Johannes Bergb8695a82009-02-10 21:25:46 +010074 skb_reserve(skb, local->hw.extra_tx_headroom);
75 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
76 memset(mgmt, 0, 24);
77 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +010078 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg8abd3f92009-02-10 21:25:47 +010079 if (sdata->vif.type == NL80211_IFTYPE_AP ||
80 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
Johannes Berg47846c92009-11-25 17:46:19 +010081 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +010082 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
83 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
Johannes Bergb8695a82009-02-10 21:25:46 +010084
85 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
86 IEEE80211_STYPE_ACTION);
87
88 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
89
90 mgmt->u.action.category = WLAN_CATEGORY_BACK;
91 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
92
93 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
94 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
95 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
96 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
97
98 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
99
100 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
101 mgmt->u.action.u.addba_req.start_seq_num =
102 cpu_to_le16(start_seq_num << 4);
103
Johannes Berg62ae67b2009-11-18 18:42:05 +0100104 ieee80211_tx_skb(sdata, skb);
Johannes Bergb8695a82009-02-10 21:25:46 +0100105}
106
Felix Fietkau8c771242011-08-20 15:53:55 +0200107void ieee80211_send_bar(struct ieee80211_vif *vif, u8 *ra, u16 tid, u16 ssn)
Johannes Bergb8695a82009-02-10 21:25:46 +0100108{
Felix Fietkau8c771242011-08-20 15:53:55 +0200109 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Johannes Bergb8695a82009-02-10 21:25:46 +0100110 struct ieee80211_local *local = sdata->local;
111 struct sk_buff *skb;
112 struct ieee80211_bar *bar;
113 u16 bar_control = 0;
114
115 skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
Joe Perchesd15b8452011-08-29 14:17:31 -0700116 if (!skb)
Johannes Bergb8695a82009-02-10 21:25:46 +0100117 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700118
Johannes Bergb8695a82009-02-10 21:25:46 +0100119 skb_reserve(skb, local->hw.extra_tx_headroom);
120 bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
121 memset(bar, 0, sizeof(*bar));
122 bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
123 IEEE80211_STYPE_BACK_REQ);
124 memcpy(bar->ra, ra, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100125 memcpy(bar->ta, sdata->vif.addr, ETH_ALEN);
Johannes Bergb8695a82009-02-10 21:25:46 +0100126 bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
127 bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
Helmut Schaac1407b62011-08-11 16:17:41 +0200128 bar_control |= (u16)(tid << IEEE80211_BAR_CTRL_TID_INFO_SHIFT);
Johannes Bergb8695a82009-02-10 21:25:46 +0100129 bar->control = cpu_to_le16(bar_control);
130 bar->start_seq_num = cpu_to_le16(ssn);
131
Johannes Berg62ae67b2009-11-18 18:42:05 +0100132 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
133 ieee80211_tx_skb(sdata, skb);
Johannes Bergb8695a82009-02-10 21:25:46 +0100134}
Felix Fietkau8c771242011-08-20 15:53:55 +0200135EXPORT_SYMBOL(ieee80211_send_bar);
Johannes Bergb8695a82009-02-10 21:25:46 +0100136
Johannes Bergec034b22011-05-13 13:35:40 +0200137void ieee80211_assign_tid_tx(struct sta_info *sta, int tid,
138 struct tid_ampdu_tx *tid_tx)
139{
140 lockdep_assert_held(&sta->ampdu_mlme.mtx);
141 lockdep_assert_held(&sta->lock);
142 rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], tid_tx);
143}
144
Johannes Berg67c282c2010-06-10 10:21:43 +0200145int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
Johannes Berg53f73c02010-10-05 19:37:40 +0200146 enum ieee80211_back_parties initiator,
147 bool tx)
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100148{
Johannes Berg849b7962009-02-10 21:25:54 +0100149 struct ieee80211_local *local = sta->local;
Johannes Berg40b275b2011-05-13 14:15:49 +0200150 struct tid_ampdu_tx *tid_tx;
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100151 int ret;
Johannes Berga622ab72010-06-10 10:21:39 +0200152
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200153 lockdep_assert_held(&sta->ampdu_mlme.mtx);
Johannes Berga622ab72010-06-10 10:21:39 +0200154
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200155 spin_lock_bh(&sta->lock);
156
Johannes Berg40b275b2011-05-13 14:15:49 +0200157 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
158 if (!tid_tx) {
159 spin_unlock_bh(&sta->lock);
160 return -ENOENT;
161 }
162
Johannes Berg24f50a92011-11-24 20:06:14 +0100163 /* if we're already stopping ignore any new requests to stop */
164 if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
165 spin_unlock_bh(&sta->lock);
166 return -EALREADY;
167 }
168
Johannes Berg0ab33702010-06-10 10:21:42 +0200169 if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
170 /* not even started yet! */
Johannes Bergec034b22011-05-13 13:35:40 +0200171 ieee80211_assign_tid_tx(sta, tid, NULL);
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200172 spin_unlock_bh(&sta->lock);
Lai Jiangshan07443712011-03-15 18:02:42 +0800173 kfree_rcu(tid_tx, rcu_head);
Johannes Berg0ab33702010-06-10 10:21:42 +0200174 return 0;
175 }
176
Johannes Berg24f50a92011-11-24 20:06:14 +0100177 set_bit(HT_AGG_STATE_STOPPING, &tid_tx->state);
178
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200179 spin_unlock_bh(&sta->lock);
180
Johannes Berg827d42c2009-11-22 12:28:41 +0100181#ifdef CONFIG_MAC80211_HT_DEBUG
182 printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
183 sta->sta.addr, tid);
184#endif /* CONFIG_MAC80211_HT_DEBUG */
185
Johannes Berg442714882010-10-05 21:40:33 +0200186 del_timer_sync(&tid_tx->addba_resp_timer);
187
Johannes Berga622ab72010-06-10 10:21:39 +0200188 /*
189 * After this packets are no longer handed right through
190 * to the driver but are put onto tid_tx->pending instead,
191 * with locking to ensure proper access.
192 */
193 clear_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state);
Vasanthakumar Thiagarajan736708b2009-06-09 14:11:46 +0530194
Emmanuel Grumbach2a1e0fd2011-11-27 15:29:44 +0200195 /*
196 * There might be a few packets being processed right now (on
197 * another CPU) that have already gotten past the aggregation
198 * check when it was still OPERATIONAL and consequently have
199 * IEEE80211_TX_CTL_AMPDU set. In that case, this code might
200 * call into the driver at the same time or even before the
201 * TX paths calls into it, which could confuse the driver.
202 *
203 * Wait for all currently running TX paths to finish before
204 * telling the driver. New packets will not go through since
205 * the aggregation session is no longer OPERATIONAL.
206 */
207 synchronize_net();
208
Johannes Berga622ab72010-06-10 10:21:39 +0200209 tid_tx->stop_initiator = initiator;
Johannes Berg53f73c02010-10-05 19:37:40 +0200210 tid_tx->tx_stop = tx;
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100211
Johannes Berg12375ef2009-11-25 20:30:31 +0100212 ret = drv_ampdu_action(local, sta->sdata,
Johannes Bergc951ad32009-11-16 12:00:38 +0100213 IEEE80211_AMPDU_TX_STOP,
Johannes Berg0b01f032011-01-18 13:51:05 +0100214 &sta->sta, tid, NULL, 0);
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100215
216 /* HW shall not deny going back to legacy */
217 if (WARN_ON(ret)) {
Johannes Bergcd8ffc82009-03-23 17:28:41 +0100218 /*
219 * We may have pending packets get stuck in this case...
220 * Not bothering with a workaround for now.
221 */
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100222 }
223
224 return ret;
225}
226
Johannes Bergb8695a82009-02-10 21:25:46 +0100227/*
228 * After sending add Block Ack request we activated a timer until
229 * add Block Ack response will arrive from the recipient.
230 * If this timer expires sta_addba_resp_timer_expired will be executed.
231 */
232static void sta_addba_resp_timer_expired(unsigned long data)
233{
234 /* not an elegant detour, but there is no choice as the timer passes
235 * only one argument, and both sta_info and TID are needed, so init
236 * flow in sta_info_create gives the TID as data, while the timer_to_id
237 * array gives the sta through container_of */
238 u16 tid = *(u8 *)data;
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100239 struct sta_info *sta = container_of((void *)data,
Johannes Bergb8695a82009-02-10 21:25:46 +0100240 struct sta_info, timer_to_tid[tid]);
Johannes Berga622ab72010-06-10 10:21:39 +0200241 struct tid_ampdu_tx *tid_tx;
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100242
Johannes Bergb8695a82009-02-10 21:25:46 +0100243 /* check if the TID waits for addBA response */
Johannes Berg83a5cbf2010-06-10 10:21:47 +0200244 rcu_read_lock();
245 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
Johannes Berga622ab72010-06-10 10:21:39 +0200246 if (!tid_tx ||
247 test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state)) {
Johannes Berg83a5cbf2010-06-10 10:21:47 +0200248 rcu_read_unlock();
Johannes Bergb8695a82009-02-10 21:25:46 +0100249#ifdef CONFIG_MAC80211_HT_DEBUG
250 printk(KERN_DEBUG "timer expired on tid %d but we are not "
Johannes Berg67e0f392010-04-19 11:03:13 +0200251 "(or no longer) expecting addBA response there\n",
Johannes Berg8ade0082009-11-18 17:15:06 +0100252 tid);
Johannes Bergb8695a82009-02-10 21:25:46 +0100253#endif
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100254 return;
Johannes Bergb8695a82009-02-10 21:25:46 +0100255 }
256
257#ifdef CONFIG_MAC80211_HT_DEBUG
258 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
259#endif
260
Johannes Berg83a5cbf2010-06-10 10:21:47 +0200261 ieee80211_stop_tx_ba_session(&sta->sta, tid);
262 rcu_read_unlock();
Johannes Bergb8695a82009-02-10 21:25:46 +0100263}
264
Johannes Berg96f5e662009-02-12 00:51:53 +0100265static inline int ieee80211_ac_from_tid(int tid)
266{
267 return ieee802_1d_to_ac[tid & 7];
268}
269
Johannes Berga6a67db2010-06-10 10:21:41 +0200270/*
271 * When multiple aggregation sessions on multiple stations
272 * are being created/destroyed simultaneously, we need to
273 * refcount the global queue stop caused by that in order
274 * to not get into a situation where one of the aggregation
275 * setup or teardown re-enables queues before the other is
276 * ready to handle that.
277 *
278 * These two functions take care of this issue by keeping
279 * a global "agg_queue_stop" refcount.
280 */
281static void __acquires(agg_queue)
282ieee80211_stop_queue_agg(struct ieee80211_local *local, int tid)
283{
284 int queue = ieee80211_ac_from_tid(tid);
285
286 if (atomic_inc_return(&local->agg_queue_stop[queue]) == 1)
287 ieee80211_stop_queue_by_reason(
288 &local->hw, queue,
289 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
290 __acquire(agg_queue);
291}
292
293static void __releases(agg_queue)
294ieee80211_wake_queue_agg(struct ieee80211_local *local, int tid)
295{
296 int queue = ieee80211_ac_from_tid(tid);
297
298 if (atomic_dec_return(&local->agg_queue_stop[queue]) == 0)
299 ieee80211_wake_queue_by_reason(
300 &local->hw, queue,
301 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
302 __release(agg_queue);
303}
304
Johannes Berg15062e62011-12-07 09:02:21 +0100305/*
306 * splice packets from the STA's pending to the local pending,
307 * requires a call to ieee80211_agg_splice_finish later
308 */
309static void __acquires(agg_queue)
310ieee80211_agg_splice_packets(struct ieee80211_local *local,
311 struct tid_ampdu_tx *tid_tx, u16 tid)
312{
313 int queue = ieee80211_ac_from_tid(tid);
314 unsigned long flags;
315
316 ieee80211_stop_queue_agg(local, tid);
317
318 if (WARN(!tid_tx, "TID %d gone but expected when splicing aggregates"
319 " from the pending queue\n", tid))
320 return;
321
322 if (!skb_queue_empty(&tid_tx->pending)) {
323 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
324 /* copy over remaining packets */
325 skb_queue_splice_tail_init(&tid_tx->pending,
326 &local->pending[queue]);
327 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
328 }
329}
330
331static void __releases(agg_queue)
332ieee80211_agg_splice_finish(struct ieee80211_local *local, u16 tid)
333{
334 ieee80211_wake_queue_agg(local, tid);
335}
336
Johannes Berg67c282c2010-06-10 10:21:43 +0200337void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
Johannes Berg0ab33702010-06-10 10:21:42 +0200338{
Johannes Berg40b275b2011-05-13 14:15:49 +0200339 struct tid_ampdu_tx *tid_tx;
Johannes Berg0ab33702010-06-10 10:21:42 +0200340 struct ieee80211_local *local = sta->local;
341 struct ieee80211_sub_if_data *sdata = sta->sdata;
342 u16 start_seq_num;
343 int ret;
344
Johannes Berg40b275b2011-05-13 14:15:49 +0200345 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200346
Johannes Berg0ab33702010-06-10 10:21:42 +0200347 /*
Johannes Berg15062e62011-12-07 09:02:21 +0100348 * Start queuing up packets for this aggregation session.
349 * We're going to release them once the driver is OK with
350 * that.
Johannes Berg0ab33702010-06-10 10:21:42 +0200351 */
Johannes Berg0ab33702010-06-10 10:21:42 +0200352 clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
353
354 /*
Johannes Berg15062e62011-12-07 09:02:21 +0100355 * Make sure no packets are being processed. This ensures that
356 * we have a valid starting sequence number and that in-flight
357 * packets have been flushed out and no packets for this TID
358 * will go into the driver during the ampdu_action call.
Johannes Berg0ab33702010-06-10 10:21:42 +0200359 */
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200360 synchronize_net();
361
Johannes Berg0ab33702010-06-10 10:21:42 +0200362 start_seq_num = sta->tid_seq[tid] >> 4;
363
364 ret = drv_ampdu_action(local, sdata, IEEE80211_AMPDU_TX_START,
Johannes Berg0b01f032011-01-18 13:51:05 +0100365 &sta->sta, tid, &start_seq_num, 0);
Johannes Berg0ab33702010-06-10 10:21:42 +0200366 if (ret) {
367#ifdef CONFIG_MAC80211_HT_DEBUG
368 printk(KERN_DEBUG "BA request denied - HW unavailable for"
369 " tid %d\n", tid);
370#endif
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200371 spin_lock_bh(&sta->lock);
Johannes Berg15062e62011-12-07 09:02:21 +0100372 ieee80211_agg_splice_packets(local, tid_tx, tid);
Johannes Bergec034b22011-05-13 13:35:40 +0200373 ieee80211_assign_tid_tx(sta, tid, NULL);
Johannes Berg15062e62011-12-07 09:02:21 +0100374 ieee80211_agg_splice_finish(local, tid);
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200375 spin_unlock_bh(&sta->lock);
376
Lai Jiangshan07443712011-03-15 18:02:42 +0800377 kfree_rcu(tid_tx, rcu_head);
Johannes Berg0ab33702010-06-10 10:21:42 +0200378 return;
379 }
380
Johannes Berg0ab33702010-06-10 10:21:42 +0200381 /* activate the timer for the recipient's addBA response */
382 mod_timer(&tid_tx->addba_resp_timer, jiffies + ADDBA_RESP_INTERVAL);
383#ifdef CONFIG_MAC80211_HT_DEBUG
384 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
385#endif
386
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200387 spin_lock_bh(&sta->lock);
Johannes Berg0ab33702010-06-10 10:21:42 +0200388 sta->ampdu_mlme.addba_req_num[tid]++;
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200389 spin_unlock_bh(&sta->lock);
Johannes Berg0ab33702010-06-10 10:21:42 +0200390
391 /* send AddBA request */
392 ieee80211_send_addba_request(sdata, sta->sta.addr, tid,
393 tid_tx->dialog_token, start_seq_num,
Johannes Berg5dd36bc2011-01-18 13:52:23 +0100394 local->hw.max_tx_aggregation_subframes,
395 tid_tx->timeout);
Johannes Berg0ab33702010-06-10 10:21:42 +0200396}
397
Sujith Manoharanbd2ce6e2010-12-15 07:47:10 +0530398int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
399 u16 timeout)
Johannes Bergb8695a82009-02-10 21:25:46 +0100400{
Johannes Bergc951ad32009-11-16 12:00:38 +0100401 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
402 struct ieee80211_sub_if_data *sdata = sta->sdata;
403 struct ieee80211_local *local = sdata->local;
Johannes Berga622ab72010-06-10 10:21:39 +0200404 struct tid_ampdu_tx *tid_tx;
Johannes Berge4e72fb2009-03-23 17:28:42 +0100405 int ret = 0;
Johannes Bergb8695a82009-02-10 21:25:46 +0100406
Johannes Bergb5878a22010-04-07 16:48:40 +0200407 trace_api_start_tx_ba_session(pubsta, tid);
408
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100409 if (WARN_ON(!local->ops->ampdu_action))
410 return -EINVAL;
411
Johannes Bergc951ad32009-11-16 12:00:38 +0100412 if ((tid >= STA_TID_NUM) ||
Arik Nemtsovedf6b782011-08-30 09:32:38 +0300413 !(local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) ||
414 (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW))
Johannes Bergb8695a82009-02-10 21:25:46 +0100415 return -EINVAL;
416
417#ifdef CONFIG_MAC80211_HT_DEBUG
418 printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
Johannes Bergc951ad32009-11-16 12:00:38 +0100419 pubsta->addr, tid);
Johannes Bergb8695a82009-02-10 21:25:46 +0100420#endif /* CONFIG_MAC80211_HT_DEBUG */
421
Johannes Berg8abd3f92009-02-10 21:25:47 +0100422 /*
423 * The aggregation code is not prepared to handle
424 * anything but STA/AP due to the BSSID handling.
425 * IBSS could work in the code but isn't supported
426 * by drivers or the standard.
427 */
Johannes Bergc951ad32009-11-16 12:00:38 +0100428 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
429 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
430 sdata->vif.type != NL80211_IFTYPE_AP)
431 return -EINVAL;
Johannes Berg8abd3f92009-02-10 21:25:47 +0100432
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200433 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
Sujith722f0692009-03-17 08:50:06 +0530434#ifdef CONFIG_MAC80211_HT_DEBUG
Johannes Berg2a419052010-06-10 10:21:29 +0200435 printk(KERN_DEBUG "BA sessions blocked. "
Sujith722f0692009-03-17 08:50:06 +0530436 "Denying BA session request\n");
437#endif
Johannes Bergc951ad32009-11-16 12:00:38 +0100438 return -EINVAL;
Sujith722f0692009-03-17 08:50:06 +0530439 }
440
Johannes Bergb8695a82009-02-10 21:25:46 +0100441 spin_lock_bh(&sta->lock);
442
443 /* we have tried too many times, receiver does not want A-MPDU */
444 if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
445 ret = -EBUSY;
446 goto err_unlock_sta;
447 }
448
Johannes Berg40b275b2011-05-13 14:15:49 +0200449 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
Johannes Bergb8695a82009-02-10 21:25:46 +0100450 /* check if the TID is not in aggregation flow already */
Johannes Bergec034b22011-05-13 13:35:40 +0200451 if (tid_tx || sta->ampdu_mlme.tid_start_tx[tid]) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100452#ifdef CONFIG_MAC80211_HT_DEBUG
453 printk(KERN_DEBUG "BA request denied - session is not "
454 "idle on tid %u\n", tid);
455#endif /* CONFIG_MAC80211_HT_DEBUG */
456 ret = -EAGAIN;
457 goto err_unlock_sta;
458 }
459
460 /* prepare A-MPDU MLME for Tx aggregation */
Johannes Berga622ab72010-06-10 10:21:39 +0200461 tid_tx = kzalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
462 if (!tid_tx) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100463 ret = -ENOMEM;
Johannes Berg0ab33702010-06-10 10:21:42 +0200464 goto err_unlock_sta;
Johannes Bergb8695a82009-02-10 21:25:46 +0100465 }
Johannes Berg96f5e662009-02-12 00:51:53 +0100466
Johannes Berga622ab72010-06-10 10:21:39 +0200467 skb_queue_head_init(&tid_tx->pending);
Johannes Berg0ab33702010-06-10 10:21:42 +0200468 __set_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
Johannes Bergcd8ffc82009-03-23 17:28:41 +0100469
Sujith Manoharanbd2ce6e2010-12-15 07:47:10 +0530470 tid_tx->timeout = timeout;
471
Johannes Bergb8695a82009-02-10 21:25:46 +0100472 /* Tx timer */
Johannes Berga622ab72010-06-10 10:21:39 +0200473 tid_tx->addba_resp_timer.function = sta_addba_resp_timer_expired;
474 tid_tx->addba_resp_timer.data = (unsigned long)&sta->timer_to_tid[tid];
475 init_timer(&tid_tx->addba_resp_timer);
Johannes Bergb8695a82009-02-10 21:25:46 +0100476
Johannes Berg0ab33702010-06-10 10:21:42 +0200477 /* assign a dialog token */
Johannes Bergb8695a82009-02-10 21:25:46 +0100478 sta->ampdu_mlme.dialog_token_allocator++;
Johannes Berga622ab72010-06-10 10:21:39 +0200479 tid_tx->dialog_token = sta->ampdu_mlme.dialog_token_allocator;
Johannes Berga622ab72010-06-10 10:21:39 +0200480
Johannes Bergec034b22011-05-13 13:35:40 +0200481 /*
482 * Finally, assign it to the start array; the work item will
483 * collect it and move it to the normal array.
484 */
485 sta->ampdu_mlme.tid_start_tx[tid] = tid_tx;
Johannes Bergb8695a82009-02-10 21:25:46 +0100486
Johannes Berg0ab33702010-06-10 10:21:42 +0200487 ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
Johannes Berg51a0d382010-05-31 12:00:12 +0200488
Johannes Berg0ab33702010-06-10 10:21:42 +0200489 /* this flow continues off the work */
Johannes Berg96f5e662009-02-12 00:51:53 +0100490 err_unlock_sta:
Johannes Bergb8695a82009-02-10 21:25:46 +0100491 spin_unlock_bh(&sta->lock);
Johannes Bergb8695a82009-02-10 21:25:46 +0100492 return ret;
493}
494EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
495
Johannes Bergb1720232009-03-23 17:28:39 +0100496static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
497 struct sta_info *sta, u16 tid)
498{
Johannes Berg40b275b2011-05-13 14:15:49 +0200499 struct tid_ampdu_tx *tid_tx;
500
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200501 lockdep_assert_held(&sta->ampdu_mlme.mtx);
Johannes Berga622ab72010-06-10 10:21:39 +0200502
Johannes Berg40b275b2011-05-13 14:15:49 +0200503 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
504
Johannes Bergb1720232009-03-23 17:28:39 +0100505#ifdef CONFIG_MAC80211_HT_DEBUG
Frans Pop55f98932010-03-24 19:46:29 +0100506 printk(KERN_DEBUG "Aggregation is on for tid %d\n", tid);
Johannes Bergb1720232009-03-23 17:28:39 +0100507#endif
508
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200509 drv_ampdu_action(local, sta->sdata,
510 IEEE80211_AMPDU_TX_OPERATIONAL,
Johannes Berg40b275b2011-05-13 14:15:49 +0200511 &sta->sta, tid, NULL, tid_tx->buf_size);
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200512
513 /*
514 * synchronize with TX path, while splicing the TX path
515 * should block so it won't put more packets onto pending.
516 */
517 spin_lock_bh(&sta->lock);
518
Johannes Berg40b275b2011-05-13 14:15:49 +0200519 ieee80211_agg_splice_packets(local, tid_tx, tid);
Johannes Bergcd8ffc82009-03-23 17:28:41 +0100520 /*
Johannes Berga622ab72010-06-10 10:21:39 +0200521 * Now mark as operational. This will be visible
522 * in the TX path, and lets it go lock-free in
523 * the common case.
Johannes Bergcd8ffc82009-03-23 17:28:41 +0100524 */
Johannes Berg40b275b2011-05-13 14:15:49 +0200525 set_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state);
Johannes Berga622ab72010-06-10 10:21:39 +0200526 ieee80211_agg_splice_finish(local, tid);
Johannes Bergb1720232009-03-23 17:28:39 +0100527
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200528 spin_unlock_bh(&sta->lock);
Johannes Bergb1720232009-03-23 17:28:39 +0100529}
530
Johannes Bergc951ad32009-11-16 12:00:38 +0100531void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
Johannes Bergb8695a82009-02-10 21:25:46 +0100532{
Johannes Bergc951ad32009-11-16 12:00:38 +0100533 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
534 struct ieee80211_local *local = sdata->local;
Johannes Bergb8695a82009-02-10 21:25:46 +0100535 struct sta_info *sta;
Johannes Berga622ab72010-06-10 10:21:39 +0200536 struct tid_ampdu_tx *tid_tx;
Johannes Bergb8695a82009-02-10 21:25:46 +0100537
Johannes Bergb5878a22010-04-07 16:48:40 +0200538 trace_api_start_tx_ba_cb(sdata, ra, tid);
539
Johannes Bergb8695a82009-02-10 21:25:46 +0100540 if (tid >= STA_TID_NUM) {
541#ifdef CONFIG_MAC80211_HT_DEBUG
542 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
543 tid, STA_TID_NUM);
544#endif
545 return;
546 }
547
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200548 mutex_lock(&local->sta_mtx);
Johannes Bergabe60632009-11-25 17:46:18 +0100549 sta = sta_info_get(sdata, ra);
Johannes Bergb8695a82009-02-10 21:25:46 +0100550 if (!sta) {
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200551 mutex_unlock(&local->sta_mtx);
Johannes Bergb8695a82009-02-10 21:25:46 +0100552#ifdef CONFIG_MAC80211_HT_DEBUG
553 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
554#endif
555 return;
556 }
557
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200558 mutex_lock(&sta->ampdu_mlme.mtx);
Johannes Berg40b275b2011-05-13 14:15:49 +0200559 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
Johannes Bergb8695a82009-02-10 21:25:46 +0100560
Johannes Berga622ab72010-06-10 10:21:39 +0200561 if (WARN_ON(!tid_tx)) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100562#ifdef CONFIG_MAC80211_HT_DEBUG
Johannes Berga622ab72010-06-10 10:21:39 +0200563 printk(KERN_DEBUG "addBA was not requested!\n");
Johannes Bergb8695a82009-02-10 21:25:46 +0100564#endif
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200565 goto unlock;
Johannes Bergb8695a82009-02-10 21:25:46 +0100566 }
567
Johannes Berga622ab72010-06-10 10:21:39 +0200568 if (WARN_ON(test_and_set_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state)))
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200569 goto unlock;
Johannes Bergb8695a82009-02-10 21:25:46 +0100570
Johannes Berga622ab72010-06-10 10:21:39 +0200571 if (test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state))
Johannes Bergb1720232009-03-23 17:28:39 +0100572 ieee80211_agg_tx_operational(local, sta, tid);
Johannes Berg96f5e662009-02-12 00:51:53 +0100573
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200574 unlock:
575 mutex_unlock(&sta->ampdu_mlme.mtx);
576 mutex_unlock(&local->sta_mtx);
Johannes Bergb8695a82009-02-10 21:25:46 +0100577}
Johannes Bergb8695a82009-02-10 21:25:46 +0100578
Johannes Bergc951ad32009-11-16 12:00:38 +0100579void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
Johannes Berg86ab6c52009-02-10 21:25:49 +0100580 const u8 *ra, u16 tid)
581{
Johannes Bergc951ad32009-11-16 12:00:38 +0100582 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
583 struct ieee80211_local *local = sdata->local;
Johannes Berg86ab6c52009-02-10 21:25:49 +0100584 struct ieee80211_ra_tid *ra_tid;
585 struct sk_buff *skb = dev_alloc_skb(0);
586
Joe Perchesd15b8452011-08-29 14:17:31 -0700587 if (unlikely(!skb))
Johannes Berg86ab6c52009-02-10 21:25:49 +0100588 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700589
Johannes Berg86ab6c52009-02-10 21:25:49 +0100590 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
591 memcpy(&ra_tid->ra, ra, ETH_ALEN);
592 ra_tid->tid = tid;
593
Johannes Bergc1475ca2010-06-10 10:21:37 +0200594 skb->pkt_type = IEEE80211_SDATA_QUEUE_AGG_START;
595 skb_queue_tail(&sdata->skb_queue, skb);
596 ieee80211_queue_work(&local->hw, &sdata->work);
Johannes Berg86ab6c52009-02-10 21:25:49 +0100597}
598EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
599
Johannes Berg849b7962009-02-10 21:25:54 +0100600int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
Johannes Berg53f73c02010-10-05 19:37:40 +0200601 enum ieee80211_back_parties initiator,
602 bool tx)
Johannes Berg849b7962009-02-10 21:25:54 +0100603{
Johannes Berg849b7962009-02-10 21:25:54 +0100604 int ret;
605
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200606 mutex_lock(&sta->ampdu_mlme.mtx);
Johannes Berg849b7962009-02-10 21:25:54 +0100607
Johannes Berg53f73c02010-10-05 19:37:40 +0200608 ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator, tx);
Johannes Berg849b7962009-02-10 21:25:54 +0100609
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200610 mutex_unlock(&sta->ampdu_mlme.mtx);
611
Johannes Berg849b7962009-02-10 21:25:54 +0100612 return ret;
613}
Johannes Bergb8695a82009-02-10 21:25:46 +0100614
Johannes Berg6a8579d2010-05-27 14:41:07 +0200615int ieee80211_stop_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid)
Johannes Bergb8695a82009-02-10 21:25:46 +0100616{
Johannes Bergc951ad32009-11-16 12:00:38 +0100617 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
618 struct ieee80211_sub_if_data *sdata = sta->sdata;
619 struct ieee80211_local *local = sdata->local;
Johannes Berg0ab33702010-06-10 10:21:42 +0200620 struct tid_ampdu_tx *tid_tx;
621 int ret = 0;
Johannes Bergb8695a82009-02-10 21:25:46 +0100622
Johannes Berg6a8579d2010-05-27 14:41:07 +0200623 trace_api_stop_tx_ba_session(pubsta, tid);
Johannes Bergb5878a22010-04-07 16:48:40 +0200624
Johannes Berg42531192009-11-20 09:15:51 +0100625 if (!local->ops->ampdu_action)
Johannes Berg23e6a7e2009-02-10 21:25:50 +0100626 return -EINVAL;
627
Johannes Bergb8695a82009-02-10 21:25:46 +0100628 if (tid >= STA_TID_NUM)
629 return -EINVAL;
630
Johannes Berg0ab33702010-06-10 10:21:42 +0200631 spin_lock_bh(&sta->lock);
Johannes Berg40b275b2011-05-13 14:15:49 +0200632 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
Johannes Berg0ab33702010-06-10 10:21:42 +0200633
634 if (!tid_tx) {
635 ret = -ENOENT;
636 goto unlock;
637 }
638
639 if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
640 /* already in progress stopping it */
641 ret = 0;
642 goto unlock;
643 }
644
645 set_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state);
646 ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
647
648 unlock:
649 spin_unlock_bh(&sta->lock);
650 return ret;
Johannes Bergb8695a82009-02-10 21:25:46 +0100651}
652EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
653
Johannes Bergc951ad32009-11-16 12:00:38 +0100654void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
Johannes Bergb8695a82009-02-10 21:25:46 +0100655{
Johannes Bergc951ad32009-11-16 12:00:38 +0100656 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
657 struct ieee80211_local *local = sdata->local;
Johannes Bergb8695a82009-02-10 21:25:46 +0100658 struct sta_info *sta;
Johannes Berga622ab72010-06-10 10:21:39 +0200659 struct tid_ampdu_tx *tid_tx;
Johannes Bergb8695a82009-02-10 21:25:46 +0100660
Johannes Bergb5878a22010-04-07 16:48:40 +0200661 trace_api_stop_tx_ba_cb(sdata, ra, tid);
662
Johannes Bergb8695a82009-02-10 21:25:46 +0100663 if (tid >= STA_TID_NUM) {
664#ifdef CONFIG_MAC80211_HT_DEBUG
665 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
666 tid, STA_TID_NUM);
667#endif
668 return;
669 }
670
671#ifdef CONFIG_MAC80211_HT_DEBUG
672 printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
673 ra, tid);
674#endif /* CONFIG_MAC80211_HT_DEBUG */
675
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200676 mutex_lock(&local->sta_mtx);
677
Johannes Bergabe60632009-11-25 17:46:18 +0100678 sta = sta_info_get(sdata, ra);
Johannes Bergb8695a82009-02-10 21:25:46 +0100679 if (!sta) {
680#ifdef CONFIG_MAC80211_HT_DEBUG
681 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
682#endif
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200683 goto unlock;
Johannes Bergb8695a82009-02-10 21:25:46 +0100684 }
Johannes Bergb8695a82009-02-10 21:25:46 +0100685
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200686 mutex_lock(&sta->ampdu_mlme.mtx);
Johannes Berga622ab72010-06-10 10:21:39 +0200687 spin_lock_bh(&sta->lock);
Johannes Berg40b275b2011-05-13 14:15:49 +0200688 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
Johannes Berga622ab72010-06-10 10:21:39 +0200689
690 if (!tid_tx || !test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100691#ifdef CONFIG_MAC80211_HT_DEBUG
692 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
693#endif
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200694 goto unlock_sta;
Johannes Bergb8695a82009-02-10 21:25:46 +0100695 }
696
Johannes Berg53f73c02010-10-05 19:37:40 +0200697 if (tid_tx->stop_initiator == WLAN_BACK_INITIATOR && tid_tx->tx_stop)
Johannes Bergb8695a82009-02-10 21:25:46 +0100698 ieee80211_send_delba(sta->sdata, ra, tid,
699 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
700
Johannes Berga622ab72010-06-10 10:21:39 +0200701 /*
702 * When we get here, the TX path will not be lockless any more wrt.
703 * aggregation, since the OPERATIONAL bit has long been cleared.
704 * Thus it will block on getting the lock, if it occurs. So if we
705 * stop the queue now, we will not get any more packets, and any
706 * that might be being processed will wait for us here, thereby
707 * guaranteeing that no packets go to the tid_tx pending queue any
708 * more.
709 */
710
Johannes Berga622ab72010-06-10 10:21:39 +0200711 ieee80211_agg_splice_packets(local, tid_tx, tid);
Johannes Berg96f5e662009-02-12 00:51:53 +0100712
Johannes Berga622ab72010-06-10 10:21:39 +0200713 /* future packets must not find the tid_tx struct any more */
Johannes Bergec034b22011-05-13 13:35:40 +0200714 ieee80211_assign_tid_tx(sta, tid, NULL);
Johannes Berg96f5e662009-02-12 00:51:53 +0100715
Johannes Berga622ab72010-06-10 10:21:39 +0200716 ieee80211_agg_splice_finish(local, tid);
Johannes Bergcd8ffc82009-03-23 17:28:41 +0100717
Lai Jiangshan07443712011-03-15 18:02:42 +0800718 kfree_rcu(tid_tx, rcu_head);
Johannes Bergb8695a82009-02-10 21:25:46 +0100719
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200720 unlock_sta:
Johannes Berga622ab72010-06-10 10:21:39 +0200721 spin_unlock_bh(&sta->lock);
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200722 mutex_unlock(&sta->ampdu_mlme.mtx);
723 unlock:
724 mutex_unlock(&local->sta_mtx);
Johannes Bergb8695a82009-02-10 21:25:46 +0100725}
Johannes Bergb8695a82009-02-10 21:25:46 +0100726
Johannes Bergc951ad32009-11-16 12:00:38 +0100727void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
Johannes Bergb8695a82009-02-10 21:25:46 +0100728 const u8 *ra, u16 tid)
729{
Johannes Bergc951ad32009-11-16 12:00:38 +0100730 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
731 struct ieee80211_local *local = sdata->local;
Johannes Bergb8695a82009-02-10 21:25:46 +0100732 struct ieee80211_ra_tid *ra_tid;
733 struct sk_buff *skb = dev_alloc_skb(0);
734
Joe Perchesd15b8452011-08-29 14:17:31 -0700735 if (unlikely(!skb))
Johannes Bergb8695a82009-02-10 21:25:46 +0100736 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700737
Johannes Bergb8695a82009-02-10 21:25:46 +0100738 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
739 memcpy(&ra_tid->ra, ra, ETH_ALEN);
740 ra_tid->tid = tid;
741
Johannes Bergc1475ca2010-06-10 10:21:37 +0200742 skb->pkt_type = IEEE80211_SDATA_QUEUE_AGG_STOP;
743 skb_queue_tail(&sdata->skb_queue, skb);
744 ieee80211_queue_work(&local->hw, &sdata->work);
Johannes Bergb8695a82009-02-10 21:25:46 +0100745}
746EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
747
Johannes Berg86ab6c52009-02-10 21:25:49 +0100748
Johannes Bergb8695a82009-02-10 21:25:46 +0100749void ieee80211_process_addba_resp(struct ieee80211_local *local,
750 struct sta_info *sta,
751 struct ieee80211_mgmt *mgmt,
752 size_t len)
753{
Johannes Berga622ab72010-06-10 10:21:39 +0200754 struct tid_ampdu_tx *tid_tx;
Johannes Bergb1720232009-03-23 17:28:39 +0100755 u16 capab, tid;
Johannes Berg0b01f032011-01-18 13:51:05 +0100756 u8 buf_size;
Johannes Bergb8695a82009-02-10 21:25:46 +0100757
758 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
759 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
Johannes Berg0b01f032011-01-18 13:51:05 +0100760 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
Johannes Bergb8695a82009-02-10 21:25:46 +0100761
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200762 mutex_lock(&sta->ampdu_mlme.mtx);
Johannes Bergb8695a82009-02-10 21:25:46 +0100763
Johannes Berg40b275b2011-05-13 14:15:49 +0200764 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
Johannes Berga622ab72010-06-10 10:21:39 +0200765 if (!tid_tx)
Johannes Berg8ade0082009-11-18 17:15:06 +0100766 goto out;
Johannes Bergb8695a82009-02-10 21:25:46 +0100767
Johannes Berga622ab72010-06-10 10:21:39 +0200768 if (mgmt->u.action.u.addba_resp.dialog_token != tid_tx->dialog_token) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100769#ifdef CONFIG_MAC80211_HT_DEBUG
770 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
Johannes Berga622ab72010-06-10 10:21:39 +0200771#endif
Johannes Berg8ade0082009-11-18 17:15:06 +0100772 goto out;
Johannes Bergb8695a82009-02-10 21:25:46 +0100773 }
774
Nikolay Martynovd305a652011-11-28 09:18:00 +0100775 del_timer_sync(&tid_tx->addba_resp_timer);
Johannes Berg8ade0082009-11-18 17:15:06 +0100776
Johannes Bergb8695a82009-02-10 21:25:46 +0100777#ifdef CONFIG_MAC80211_HT_DEBUG
Frans Pop55f98932010-03-24 19:46:29 +0100778 printk(KERN_DEBUG "switched off addBA timer for tid %d\n", tid);
Johannes Berga622ab72010-06-10 10:21:39 +0200779#endif
Nikolay Martynovd305a652011-11-28 09:18:00 +0100780
781 /*
782 * addba_resp_timer may have fired before we got here, and
783 * caused WANT_STOP to be set. If the stop then was already
784 * processed further, STOPPING might be set.
785 */
786 if (test_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state) ||
787 test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
788#ifdef CONFIG_MAC80211_HT_DEBUG
789 printk(KERN_DEBUG
790 "got addBA resp for tid %d but we already gave up\n",
791 tid);
792#endif
793 goto out;
794 }
795
Helmut Schaa3ca97882011-07-26 12:18:27 +0200796 /*
797 * IEEE 802.11-2007 7.3.1.14:
798 * In an ADDBA Response frame, when the Status Code field
799 * is set to 0, the Buffer Size subfield is set to a value
800 * of at least 1.
801 */
Johannes Bergb8695a82009-02-10 21:25:46 +0100802 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
Helmut Schaa3ca97882011-07-26 12:18:27 +0200803 == WLAN_STATUS_SUCCESS && buf_size) {
Johannes Berga622ab72010-06-10 10:21:39 +0200804 if (test_and_set_bit(HT_AGG_STATE_RESPONSE_RECEIVED,
805 &tid_tx->state)) {
806 /* ignore duplicate response */
807 goto out;
808 }
Johannes Bergb8695a82009-02-10 21:25:46 +0100809
Johannes Berg0b01f032011-01-18 13:51:05 +0100810 tid_tx->buf_size = buf_size;
811
Johannes Berga622ab72010-06-10 10:21:39 +0200812 if (test_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state))
Johannes Bergb1720232009-03-23 17:28:39 +0100813 ieee80211_agg_tx_operational(local, sta, tid);
Johannes Bergb8695a82009-02-10 21:25:46 +0100814
Johannes Bergb1720232009-03-23 17:28:39 +0100815 sta->ampdu_mlme.addba_req_num[tid] = 0;
Johannes Bergb8695a82009-02-10 21:25:46 +0100816 } else {
Johannes Berg53f73c02010-10-05 19:37:40 +0200817 ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR,
818 true);
Johannes Bergb8695a82009-02-10 21:25:46 +0100819 }
Johannes Berg2171abc2009-10-29 08:34:00 +0100820
Johannes Berg2171abc2009-10-29 08:34:00 +0100821 out:
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200822 mutex_unlock(&sta->ampdu_mlme.mtx);
Johannes Bergb8695a82009-02-10 21:25:46 +0100823}