mac80211: handle protection mode, RIFS and ADDBA for HT IBSS
[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>
cfcdbde3 9 * Copyright 2007-2010, Intel Corporation
b8695a8f
JB
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>
5a0e3ad6 17#include <linux/slab.h>
bc3b2d7f 18#include <linux/export.h>
b8695a8f
JB
19#include <net/mac80211.h>
20#include "ieee80211_i.h"
24487981 21#include "driver-ops.h"
b8695a8f
JB
22#include "wme.h"
23
86ab6c5a 24/**
73a72a81 25 * DOC: TX A-MPDU aggregation
86ab6c5a
JB
26 *
27 * Aggregation on the TX side requires setting the hardware flag
73a72a81
JB
28 * %IEEE80211_HW_AMPDU_AGGREGATION. The driver will then be handed
29 * packets with a flag indicating A-MPDU aggregation. The driver
30 * or device is responsible for actually aggregating the frames,
31 * as well as deciding how many and which to aggregate.
86ab6c5a 32 *
73a72a81
JB
33 * When TX aggregation is started by some subsystem (usually the rate
34 * control algorithm would be appropriate) by calling the
35 * ieee80211_start_tx_ba_session() function, the driver will be
36 * notified via its @ampdu_action function, with the
37 * %IEEE80211_AMPDU_TX_START action.
86ab6c5a
JB
38 *
39 * In response to that, the driver is later required to call the
73a72a81
JB
40 * ieee80211_start_tx_ba_cb_irqsafe() function, which will really
41 * start the aggregation session after the peer has also responded.
42 * If the peer responds negatively, the session will be stopped
43 * again right away. Note that it is possible for the aggregation
44 * session to be stopped before the driver has indicated that it
45 * is done setting it up, in which case it must not indicate the
46 * setup completion.
86ab6c5a 47 *
73a72a81
JB
48 * Also note that, since we also need to wait for a response from
49 * the peer, the driver is notified of the completion of the
50 * handshake by the %IEEE80211_AMPDU_TX_OPERATIONAL action to the
51 * @ampdu_action callback.
52 *
53 * Similarly, when the aggregation session is stopped by the peer
54 * or something calling ieee80211_stop_tx_ba_session(), the driver's
55 * @ampdu_action function will be called with the action
56 * %IEEE80211_AMPDU_TX_STOP. In this case, the call must not fail,
57 * and the driver must later call ieee80211_stop_tx_ba_cb_irqsafe().
86ab6c5a
JB
58 */
59
b8695a8f
JB
60static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
61 const u8 *da, u16 tid,
62 u8 dialog_token, u16 start_seq_num,
63 u16 agg_size, u16 timeout)
64{
65 struct ieee80211_local *local = sdata->local;
b8695a8f
JB
66 struct sk_buff *skb;
67 struct ieee80211_mgmt *mgmt;
68 u16 capab;
69
70 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
71
d15b8459 72 if (!skb)
b8695a8f 73 return;
d15b8459 74
b8695a8f
JB
75 skb_reserve(skb, local->hw.extra_tx_headroom);
76 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
77 memset(mgmt, 0, 24);
78 memcpy(mgmt->da, da, ETH_ALEN);
47846c9b 79 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
8abd3f9b 80 if (sdata->vif.type == NL80211_IFTYPE_AP ||
ae2772b3
TP
81 sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
82 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
47846c9b 83 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
46900298
JB
84 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
85 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
b8695a8f
JB
86
87 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
88 IEEE80211_STYPE_ACTION);
89
90 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
91
92 mgmt->u.action.category = WLAN_CATEGORY_BACK;
93 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
94
95 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
96 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
97 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
98 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
99
100 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
101
102 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
103 mgmt->u.action.u.addba_req.start_seq_num =
104 cpu_to_le16(start_seq_num << 4);
105
62ae67be 106 ieee80211_tx_skb(sdata, skb);
b8695a8f
JB
107}
108
8c771244 109void ieee80211_send_bar(struct ieee80211_vif *vif, u8 *ra, u16 tid, u16 ssn)
b8695a8f 110{
8c771244 111 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
b8695a8f
JB
112 struct ieee80211_local *local = sdata->local;
113 struct sk_buff *skb;
114 struct ieee80211_bar *bar;
115 u16 bar_control = 0;
116
117 skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
d15b8459 118 if (!skb)
b8695a8f 119 return;
d15b8459 120
b8695a8f
JB
121 skb_reserve(skb, local->hw.extra_tx_headroom);
122 bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
123 memset(bar, 0, sizeof(*bar));
124 bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
125 IEEE80211_STYPE_BACK_REQ);
126 memcpy(bar->ra, ra, ETH_ALEN);
47846c9b 127 memcpy(bar->ta, sdata->vif.addr, ETH_ALEN);
b8695a8f
JB
128 bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
129 bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
c1407b6c 130 bar_control |= (u16)(tid << IEEE80211_BAR_CTRL_TID_INFO_SHIFT);
b8695a8f
JB
131 bar->control = cpu_to_le16(bar_control);
132 bar->start_seq_num = cpu_to_le16(ssn);
133
62ae67be
JB
134 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
135 ieee80211_tx_skb(sdata, skb);
b8695a8f 136}
8c771244 137EXPORT_SYMBOL(ieee80211_send_bar);
b8695a8f 138
ec034b20
JB
139void ieee80211_assign_tid_tx(struct sta_info *sta, int tid,
140 struct tid_ampdu_tx *tid_tx)
141{
142 lockdep_assert_held(&sta->ampdu_mlme.mtx);
143 lockdep_assert_held(&sta->lock);
144 rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], tid_tx);
145}
146
67c282c0 147int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
53f73c09
JB
148 enum ieee80211_back_parties initiator,
149 bool tx)
23e6a7ea 150{
849b7967 151 struct ieee80211_local *local = sta->local;
40b275b6 152 struct tid_ampdu_tx *tid_tx;
23e6a7ea 153 int ret;
a622ab72 154
cfcdbde3 155 lockdep_assert_held(&sta->ampdu_mlme.mtx);
a622ab72 156
cfcdbde3
JB
157 spin_lock_bh(&sta->lock);
158
40b275b6
JB
159 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
160 if (!tid_tx) {
161 spin_unlock_bh(&sta->lock);
162 return -ENOENT;
163 }
164
24f50a9d
JB
165 /* if we're already stopping ignore any new requests to stop */
166 if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
167 spin_unlock_bh(&sta->lock);
168 return -EALREADY;
169 }
170
0ab33703
JB
171 if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
172 /* not even started yet! */
ec034b20 173 ieee80211_assign_tid_tx(sta, tid, NULL);
cfcdbde3 174 spin_unlock_bh(&sta->lock);
0744371a 175 kfree_rcu(tid_tx, rcu_head);
0ab33703
JB
176 return 0;
177 }
178
24f50a9d
JB
179 set_bit(HT_AGG_STATE_STOPPING, &tid_tx->state);
180
cfcdbde3
JB
181 spin_unlock_bh(&sta->lock);
182
827d42c9
JB
183#ifdef CONFIG_MAC80211_HT_DEBUG
184 printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
185 sta->sta.addr, tid);
186#endif /* CONFIG_MAC80211_HT_DEBUG */
187
44271488 188 del_timer_sync(&tid_tx->addba_resp_timer);
285fa695 189 del_timer_sync(&tid_tx->session_timer);
44271488 190
a622ab72
JB
191 /*
192 * After this packets are no longer handed right through
193 * to the driver but are put onto tid_tx->pending instead,
194 * with locking to ensure proper access.
195 */
196 clear_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state);
736708bd 197
2a1e0fd1
EG
198 /*
199 * There might be a few packets being processed right now (on
200 * another CPU) that have already gotten past the aggregation
201 * check when it was still OPERATIONAL and consequently have
202 * IEEE80211_TX_CTL_AMPDU set. In that case, this code might
203 * call into the driver at the same time or even before the
204 * TX paths calls into it, which could confuse the driver.
205 *
206 * Wait for all currently running TX paths to finish before
207 * telling the driver. New packets will not go through since
208 * the aggregation session is no longer OPERATIONAL.
209 */
210 synchronize_net();
211
a622ab72 212 tid_tx->stop_initiator = initiator;
53f73c09 213 tid_tx->tx_stop = tx;
23e6a7ea 214
12375ef9 215 ret = drv_ampdu_action(local, sta->sdata,
c951ad35 216 IEEE80211_AMPDU_TX_STOP,
0b01f030 217 &sta->sta, tid, NULL, 0);
23e6a7ea
JB
218
219 /* HW shall not deny going back to legacy */
220 if (WARN_ON(ret)) {
cd8ffc80
JB
221 /*
222 * We may have pending packets get stuck in this case...
223 * Not bothering with a workaround for now.
224 */
23e6a7ea
JB
225 }
226
227 return ret;
228}
229
b8695a8f
JB
230/*
231 * After sending add Block Ack request we activated a timer until
232 * add Block Ack response will arrive from the recipient.
233 * If this timer expires sta_addba_resp_timer_expired will be executed.
234 */
235static void sta_addba_resp_timer_expired(unsigned long data)
236{
237 /* not an elegant detour, but there is no choice as the timer passes
238 * only one argument, and both sta_info and TID are needed, so init
239 * flow in sta_info_create gives the TID as data, while the timer_to_id
240 * array gives the sta through container_of */
241 u16 tid = *(u8 *)data;
23e6a7ea 242 struct sta_info *sta = container_of((void *)data,
b8695a8f 243 struct sta_info, timer_to_tid[tid]);
a622ab72 244 struct tid_ampdu_tx *tid_tx;
23e6a7ea 245
b8695a8f 246 /* check if the TID waits for addBA response */
83a5cbf7
JB
247 rcu_read_lock();
248 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
a622ab72
JB
249 if (!tid_tx ||
250 test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state)) {
83a5cbf7 251 rcu_read_unlock();
b8695a8f
JB
252#ifdef CONFIG_MAC80211_HT_DEBUG
253 printk(KERN_DEBUG "timer expired on tid %d but we are not "
67e0f392 254 "(or no longer) expecting addBA response there\n",
8ade0082 255 tid);
b8695a8f 256#endif
23e6a7ea 257 return;
b8695a8f
JB
258 }
259
260#ifdef CONFIG_MAC80211_HT_DEBUG
261 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
262#endif
263
83a5cbf7
JB
264 ieee80211_stop_tx_ba_session(&sta->sta, tid);
265 rcu_read_unlock();
b8695a8f
JB
266}
267
96f5e66e
JB
268static inline int ieee80211_ac_from_tid(int tid)
269{
270 return ieee802_1d_to_ac[tid & 7];
271}
272
a6a67db2
JB
273/*
274 * When multiple aggregation sessions on multiple stations
275 * are being created/destroyed simultaneously, we need to
276 * refcount the global queue stop caused by that in order
277 * to not get into a situation where one of the aggregation
278 * setup or teardown re-enables queues before the other is
279 * ready to handle that.
280 *
281 * These two functions take care of this issue by keeping
282 * a global "agg_queue_stop" refcount.
283 */
284static void __acquires(agg_queue)
285ieee80211_stop_queue_agg(struct ieee80211_local *local, int tid)
286{
287 int queue = ieee80211_ac_from_tid(tid);
288
289 if (atomic_inc_return(&local->agg_queue_stop[queue]) == 1)
290 ieee80211_stop_queue_by_reason(
291 &local->hw, queue,
292 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
293 __acquire(agg_queue);
294}
295
296static void __releases(agg_queue)
297ieee80211_wake_queue_agg(struct ieee80211_local *local, int tid)
298{
299 int queue = ieee80211_ac_from_tid(tid);
300
301 if (atomic_dec_return(&local->agg_queue_stop[queue]) == 0)
302 ieee80211_wake_queue_by_reason(
303 &local->hw, queue,
304 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
305 __release(agg_queue);
306}
307
67c282c0 308void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
0ab33703 309{
40b275b6 310 struct tid_ampdu_tx *tid_tx;
0ab33703
JB
311 struct ieee80211_local *local = sta->local;
312 struct ieee80211_sub_if_data *sdata = sta->sdata;
313 u16 start_seq_num;
314 int ret;
315
40b275b6 316 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
cfcdbde3 317
0ab33703
JB
318 /*
319 * While we're asking the driver about the aggregation,
320 * stop the AC queue so that we don't have to worry
321 * about frames that came in while we were doing that,
322 * which would require us to put them to the AC pending
323 * afterwards which just makes the code more complex.
324 */
325 ieee80211_stop_queue_agg(local, tid);
326
327 clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
328
329 /*
cfcdbde3
JB
330 * make sure no packets are being processed to get
331 * valid starting sequence number
0ab33703 332 */
cfcdbde3
JB
333 synchronize_net();
334
0ab33703
JB
335 start_seq_num = sta->tid_seq[tid] >> 4;
336
337 ret = drv_ampdu_action(local, sdata, IEEE80211_AMPDU_TX_START,
0b01f030 338 &sta->sta, tid, &start_seq_num, 0);
0ab33703
JB
339 if (ret) {
340#ifdef CONFIG_MAC80211_HT_DEBUG
341 printk(KERN_DEBUG "BA request denied - HW unavailable for"
342 " tid %d\n", tid);
343#endif
cfcdbde3 344 spin_lock_bh(&sta->lock);
ec034b20 345 ieee80211_assign_tid_tx(sta, tid, NULL);
cfcdbde3
JB
346 spin_unlock_bh(&sta->lock);
347
0ab33703 348 ieee80211_wake_queue_agg(local, tid);
0744371a 349 kfree_rcu(tid_tx, rcu_head);
0ab33703
JB
350 return;
351 }
352
353 /* we can take packets again now */
354 ieee80211_wake_queue_agg(local, tid);
355
356 /* activate the timer for the recipient's addBA response */
357 mod_timer(&tid_tx->addba_resp_timer, jiffies + ADDBA_RESP_INTERVAL);
358#ifdef CONFIG_MAC80211_HT_DEBUG
359 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
360#endif
361
cfcdbde3 362 spin_lock_bh(&sta->lock);
0ab33703 363 sta->ampdu_mlme.addba_req_num[tid]++;
cfcdbde3 364 spin_unlock_bh(&sta->lock);
0ab33703
JB
365
366 /* send AddBA request */
367 ieee80211_send_addba_request(sdata, sta->sta.addr, tid,
368 tid_tx->dialog_token, start_seq_num,
5dd36bc9
JB
369 local->hw.max_tx_aggregation_subframes,
370 tid_tx->timeout);
0ab33703
JB
371}
372
285fa695
NM
373/*
374 * After accepting the AddBA Response we activated a timer,
375 * resetting it after each frame that we send.
376 */
377static void sta_tx_agg_session_timer_expired(unsigned long data)
378{
379 /* not an elegant detour, but there is no choice as the timer passes
380 * only one argument, and various sta_info are needed here, so init
381 * flow in sta_info_create gives the TID as data, while the timer_to_id
382 * array gives the sta through container_of */
383 u8 *ptid = (u8 *)data;
384 u8 *timer_to_id = ptid - *ptid;
385 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
386 timer_to_tid[0]);
387
388#ifdef CONFIG_MAC80211_HT_DEBUG
389 printk(KERN_DEBUG "tx session timer expired on tid %d\n", (u16)*ptid);
390#endif
391
392 ieee80211_stop_tx_ba_session(&sta->sta, *ptid);
393}
394
bd2ce6e4
SM
395int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
396 u16 timeout)
b8695a8f 397{
c951ad35
JB
398 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
399 struct ieee80211_sub_if_data *sdata = sta->sdata;
400 struct ieee80211_local *local = sdata->local;
a622ab72 401 struct tid_ampdu_tx *tid_tx;
e4e72fb4 402 int ret = 0;
b8695a8f 403
b5878a2d
JB
404 trace_api_start_tx_ba_session(pubsta, tid);
405
23e6a7ea
JB
406 if (WARN_ON(!local->ops->ampdu_action))
407 return -EINVAL;
408
c951ad35 409 if ((tid >= STA_TID_NUM) ||
edf6b784
AN
410 !(local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) ||
411 (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW))
b8695a8f
JB
412 return -EINVAL;
413
414#ifdef CONFIG_MAC80211_HT_DEBUG
415 printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
c951ad35 416 pubsta->addr, tid);
b8695a8f
JB
417#endif /* CONFIG_MAC80211_HT_DEBUG */
418
c951ad35 419 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
ae2772b3 420 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
c951ad35
JB
421 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
422 sdata->vif.type != NL80211_IFTYPE_AP)
423 return -EINVAL;
8abd3f9b 424
c2c98fde 425 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
722f069a 426#ifdef CONFIG_MAC80211_HT_DEBUG
2a419056 427 printk(KERN_DEBUG "BA sessions blocked. "
722f069a
S
428 "Denying BA session request\n");
429#endif
c951ad35 430 return -EINVAL;
722f069a
S
431 }
432
ff3cc5f4
SW
433 /*
434 * 802.11n-2009 11.5.1.1: If the initiating STA is an HT STA, is a
435 * member of an IBSS, and has no other existing Block Ack agreement
436 * with the recipient STA, then the initiating STA shall transmit a
437 * Probe Request frame to the recipient STA and shall not transmit an
438 * ADDBA Request frame unless it receives a Probe Response frame
439 * from the recipient within dot11ADDBAFailureTimeout.
440 *
441 * The probe request mechanism for ADDBA is currently not implemented,
442 * but we only build up Block Ack session with HT STAs. This information
443 * is set when we receive a bss info from a probe response or a beacon.
444 */
445 if (sta->sdata->vif.type == NL80211_IFTYPE_ADHOC &&
446 !sta->sta.ht_cap.ht_supported) {
447#ifdef CONFIG_MAC80211_HT_DEBUG
448 printk(KERN_DEBUG "BA request denied - IBSS STA %pM"
449 "does not advertise HT support\n", pubsta->addr);
450#endif /* CONFIG_MAC80211_HT_DEBUG */
451 return -EINVAL;
452 }
453
b8695a8f
JB
454 spin_lock_bh(&sta->lock);
455
456 /* we have tried too many times, receiver does not want A-MPDU */
457 if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
458 ret = -EBUSY;
459 goto err_unlock_sta;
460 }
461
40b275b6 462 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
b8695a8f 463 /* check if the TID is not in aggregation flow already */
ec034b20 464 if (tid_tx || sta->ampdu_mlme.tid_start_tx[tid]) {
b8695a8f
JB
465#ifdef CONFIG_MAC80211_HT_DEBUG
466 printk(KERN_DEBUG "BA request denied - session is not "
467 "idle on tid %u\n", tid);
468#endif /* CONFIG_MAC80211_HT_DEBUG */
469 ret = -EAGAIN;
470 goto err_unlock_sta;
471 }
472
473 /* prepare A-MPDU MLME for Tx aggregation */
a622ab72
JB
474 tid_tx = kzalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
475 if (!tid_tx) {
b8695a8f 476 ret = -ENOMEM;
0ab33703 477 goto err_unlock_sta;
b8695a8f 478 }
96f5e66e 479
a622ab72 480 skb_queue_head_init(&tid_tx->pending);
0ab33703 481 __set_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
cd8ffc80 482
bd2ce6e4
SM
483 tid_tx->timeout = timeout;
484
285fa695 485 /* response timer */
a622ab72
JB
486 tid_tx->addba_resp_timer.function = sta_addba_resp_timer_expired;
487 tid_tx->addba_resp_timer.data = (unsigned long)&sta->timer_to_tid[tid];
488 init_timer(&tid_tx->addba_resp_timer);
b8695a8f 489
285fa695
NM
490 /* tx timer */
491 tid_tx->session_timer.function = sta_tx_agg_session_timer_expired;
492 tid_tx->session_timer.data = (unsigned long)&sta->timer_to_tid[tid];
493 init_timer(&tid_tx->session_timer);
494
0ab33703 495 /* assign a dialog token */
b8695a8f 496 sta->ampdu_mlme.dialog_token_allocator++;
a622ab72 497 tid_tx->dialog_token = sta->ampdu_mlme.dialog_token_allocator;
b8695a8f 498
ec034b20
JB
499 /*
500 * Finally, assign it to the start array; the work item will
501 * collect it and move it to the normal array.
502 */
503 sta->ampdu_mlme.tid_start_tx[tid] = tid_tx;
51a0d38d 504
0ab33703 505 ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
b8695a8f 506
0ab33703 507 /* this flow continues off the work */
96f5e66e 508 err_unlock_sta:
b8695a8f 509 spin_unlock_bh(&sta->lock);
b8695a8f
JB
510 return ret;
511}
512EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
513
cd8ffc80
JB
514/*
515 * splice packets from the STA's pending to the local pending,
a6a67db2 516 * requires a call to ieee80211_agg_splice_finish later
cd8ffc80 517 */
a6a67db2
JB
518static void __acquires(agg_queue)
519ieee80211_agg_splice_packets(struct ieee80211_local *local,
520 struct tid_ampdu_tx *tid_tx, u16 tid)
cd8ffc80 521{
a6a67db2 522 int queue = ieee80211_ac_from_tid(tid);
cd8ffc80 523 unsigned long flags;
cd8ffc80 524
a6a67db2 525 ieee80211_stop_queue_agg(local, tid);
cd8ffc80 526
a622ab72
JB
527 if (WARN(!tid_tx, "TID %d gone but expected when splicing aggregates"
528 " from the pending queue\n", tid))
416fbdff
LR
529 return;
530
a622ab72 531 if (!skb_queue_empty(&tid_tx->pending)) {
cd8ffc80 532 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
cd8ffc80 533 /* copy over remaining packets */
a622ab72
JB
534 skb_queue_splice_tail_init(&tid_tx->pending,
535 &local->pending[queue]);
cd8ffc80
JB
536 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
537 }
538}
539
a6a67db2
JB
540static void __releases(agg_queue)
541ieee80211_agg_splice_finish(struct ieee80211_local *local, u16 tid)
cd8ffc80 542{
a6a67db2 543 ieee80211_wake_queue_agg(local, tid);
cd8ffc80
JB
544}
545
b1720231
JB
546static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
547 struct sta_info *sta, u16 tid)
548{
40b275b6
JB
549 struct tid_ampdu_tx *tid_tx;
550
cfcdbde3 551 lockdep_assert_held(&sta->ampdu_mlme.mtx);
a622ab72 552
40b275b6
JB
553 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
554
b1720231 555#ifdef CONFIG_MAC80211_HT_DEBUG
55f98938 556 printk(KERN_DEBUG "Aggregation is on for tid %d\n", tid);
b1720231
JB
557#endif
558
cfcdbde3
JB
559 drv_ampdu_action(local, sta->sdata,
560 IEEE80211_AMPDU_TX_OPERATIONAL,
40b275b6 561 &sta->sta, tid, NULL, tid_tx->buf_size);
cfcdbde3
JB
562
563 /*
564 * synchronize with TX path, while splicing the TX path
565 * should block so it won't put more packets onto pending.
566 */
567 spin_lock_bh(&sta->lock);
568
40b275b6 569 ieee80211_agg_splice_packets(local, tid_tx, tid);
cd8ffc80 570 /*
a622ab72
JB
571 * Now mark as operational. This will be visible
572 * in the TX path, and lets it go lock-free in
573 * the common case.
cd8ffc80 574 */
40b275b6 575 set_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state);
a622ab72 576 ieee80211_agg_splice_finish(local, tid);
b1720231 577
cfcdbde3 578 spin_unlock_bh(&sta->lock);
b1720231
JB
579}
580
c951ad35 581void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
b8695a8f 582{
c951ad35
JB
583 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
584 struct ieee80211_local *local = sdata->local;
b8695a8f 585 struct sta_info *sta;
a622ab72 586 struct tid_ampdu_tx *tid_tx;
b8695a8f 587
b5878a2d
JB
588 trace_api_start_tx_ba_cb(sdata, ra, tid);
589
b8695a8f
JB
590 if (tid >= STA_TID_NUM) {
591#ifdef CONFIG_MAC80211_HT_DEBUG
592 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
593 tid, STA_TID_NUM);
594#endif
595 return;
596 }
597
cfcdbde3 598 mutex_lock(&local->sta_mtx);
bc192f89 599 sta = sta_info_get_bss(sdata, ra);
b8695a8f 600 if (!sta) {
cfcdbde3 601 mutex_unlock(&local->sta_mtx);
b8695a8f
JB
602#ifdef CONFIG_MAC80211_HT_DEBUG
603 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
604#endif
605 return;
606 }
607
cfcdbde3 608 mutex_lock(&sta->ampdu_mlme.mtx);
40b275b6 609 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
b8695a8f 610
a622ab72 611 if (WARN_ON(!tid_tx)) {
b8695a8f 612#ifdef CONFIG_MAC80211_HT_DEBUG
a622ab72 613 printk(KERN_DEBUG "addBA was not requested!\n");
b8695a8f 614#endif
cfcdbde3 615 goto unlock;
b8695a8f
JB
616 }
617
a622ab72 618 if (WARN_ON(test_and_set_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state)))
cfcdbde3 619 goto unlock;
b8695a8f 620
a622ab72 621 if (test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state))
b1720231 622 ieee80211_agg_tx_operational(local, sta, tid);
96f5e66e 623
cfcdbde3
JB
624 unlock:
625 mutex_unlock(&sta->ampdu_mlme.mtx);
626 mutex_unlock(&local->sta_mtx);
b8695a8f 627}
b8695a8f 628
c951ad35 629void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
86ab6c5a
JB
630 const u8 *ra, u16 tid)
631{
c951ad35
JB
632 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
633 struct ieee80211_local *local = sdata->local;
86ab6c5a
JB
634 struct ieee80211_ra_tid *ra_tid;
635 struct sk_buff *skb = dev_alloc_skb(0);
636
d15b8459 637 if (unlikely(!skb))
86ab6c5a 638 return;
d15b8459 639
86ab6c5a
JB
640 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
641 memcpy(&ra_tid->ra, ra, ETH_ALEN);
642 ra_tid->tid = tid;
643
c1475ca9
JB
644 skb->pkt_type = IEEE80211_SDATA_QUEUE_AGG_START;
645 skb_queue_tail(&sdata->skb_queue, skb);
646 ieee80211_queue_work(&local->hw, &sdata->work);
86ab6c5a
JB
647}
648EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
649
849b7967 650int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
53f73c09
JB
651 enum ieee80211_back_parties initiator,
652 bool tx)
849b7967 653{
849b7967
JB
654 int ret;
655
cfcdbde3 656 mutex_lock(&sta->ampdu_mlme.mtx);
849b7967 657
53f73c09 658 ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator, tx);
849b7967 659
cfcdbde3
JB
660 mutex_unlock(&sta->ampdu_mlme.mtx);
661
849b7967
JB
662 return ret;
663}
b8695a8f 664
6a8579d0 665int ieee80211_stop_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid)
b8695a8f 666{
c951ad35
JB
667 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
668 struct ieee80211_sub_if_data *sdata = sta->sdata;
669 struct ieee80211_local *local = sdata->local;
0ab33703
JB
670 struct tid_ampdu_tx *tid_tx;
671 int ret = 0;
b8695a8f 672
6a8579d0 673 trace_api_stop_tx_ba_session(pubsta, tid);
b5878a2d 674
4253119a 675 if (!local->ops->ampdu_action)
23e6a7ea
JB
676 return -EINVAL;
677
b8695a8f
JB
678 if (tid >= STA_TID_NUM)
679 return -EINVAL;
680
0ab33703 681 spin_lock_bh(&sta->lock);
40b275b6 682 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
0ab33703
JB
683
684 if (!tid_tx) {
685 ret = -ENOENT;
686 goto unlock;
687 }
688
689 if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
690 /* already in progress stopping it */
691 ret = 0;
692 goto unlock;
693 }
694
695 set_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state);
696 ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
697
698 unlock:
699 spin_unlock_bh(&sta->lock);
700 return ret;
b8695a8f
JB
701}
702EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
703
c951ad35 704void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
b8695a8f 705{
c951ad35
JB
706 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
707 struct ieee80211_local *local = sdata->local;
b8695a8f 708 struct sta_info *sta;
a622ab72 709 struct tid_ampdu_tx *tid_tx;
b8695a8f 710
b5878a2d
JB
711 trace_api_stop_tx_ba_cb(sdata, ra, tid);
712
b8695a8f
JB
713 if (tid >= STA_TID_NUM) {
714#ifdef CONFIG_MAC80211_HT_DEBUG
715 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
716 tid, STA_TID_NUM);
717#endif
718 return;
719 }
720
721#ifdef CONFIG_MAC80211_HT_DEBUG
722 printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
723 ra, tid);
724#endif /* CONFIG_MAC80211_HT_DEBUG */
725
cfcdbde3
JB
726 mutex_lock(&local->sta_mtx);
727
bc192f89 728 sta = sta_info_get_bss(sdata, ra);
b8695a8f
JB
729 if (!sta) {
730#ifdef CONFIG_MAC80211_HT_DEBUG
731 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
732#endif
cfcdbde3 733 goto unlock;
b8695a8f 734 }
b8695a8f 735
cfcdbde3 736 mutex_lock(&sta->ampdu_mlme.mtx);
a622ab72 737 spin_lock_bh(&sta->lock);
40b275b6 738 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
a622ab72
JB
739
740 if (!tid_tx || !test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
b8695a8f
JB
741#ifdef CONFIG_MAC80211_HT_DEBUG
742 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
743#endif
cfcdbde3 744 goto unlock_sta;
b8695a8f
JB
745 }
746
53f73c09 747 if (tid_tx->stop_initiator == WLAN_BACK_INITIATOR && tid_tx->tx_stop)
b8695a8f
JB
748 ieee80211_send_delba(sta->sdata, ra, tid,
749 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
750
a622ab72
JB
751 /*
752 * When we get here, the TX path will not be lockless any more wrt.
753 * aggregation, since the OPERATIONAL bit has long been cleared.
754 * Thus it will block on getting the lock, if it occurs. So if we
755 * stop the queue now, we will not get any more packets, and any
756 * that might be being processed will wait for us here, thereby
757 * guaranteeing that no packets go to the tid_tx pending queue any
758 * more.
759 */
b8695a8f 760
a622ab72 761 ieee80211_agg_splice_packets(local, tid_tx, tid);
96f5e66e 762
a622ab72 763 /* future packets must not find the tid_tx struct any more */
ec034b20 764 ieee80211_assign_tid_tx(sta, tid, NULL);
cd8ffc80 765
a622ab72 766 ieee80211_agg_splice_finish(local, tid);
cd8ffc80 767
0744371a 768 kfree_rcu(tid_tx, rcu_head);
b8695a8f 769
cfcdbde3 770 unlock_sta:
a622ab72 771 spin_unlock_bh(&sta->lock);
cfcdbde3
JB
772 mutex_unlock(&sta->ampdu_mlme.mtx);
773 unlock:
774 mutex_unlock(&local->sta_mtx);
b8695a8f 775}
b8695a8f 776
c951ad35 777void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
b8695a8f
JB
778 const u8 *ra, u16 tid)
779{
c951ad35
JB
780 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
781 struct ieee80211_local *local = sdata->local;
b8695a8f
JB
782 struct ieee80211_ra_tid *ra_tid;
783 struct sk_buff *skb = dev_alloc_skb(0);
784
d15b8459 785 if (unlikely(!skb))
b8695a8f 786 return;
d15b8459 787
b8695a8f
JB
788 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
789 memcpy(&ra_tid->ra, ra, ETH_ALEN);
790 ra_tid->tid = tid;
791
c1475ca9
JB
792 skb->pkt_type = IEEE80211_SDATA_QUEUE_AGG_STOP;
793 skb_queue_tail(&sdata->skb_queue, skb);
794 ieee80211_queue_work(&local->hw, &sdata->work);
b8695a8f
JB
795}
796EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
797
86ab6c5a 798
b8695a8f
JB
799void ieee80211_process_addba_resp(struct ieee80211_local *local,
800 struct sta_info *sta,
801 struct ieee80211_mgmt *mgmt,
802 size_t len)
803{
a622ab72 804 struct tid_ampdu_tx *tid_tx;
b1720231 805 u16 capab, tid;
0b01f030 806 u8 buf_size;
b8695a8f
JB
807
808 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
809 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
0b01f030 810 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
b8695a8f 811
cfcdbde3 812 mutex_lock(&sta->ampdu_mlme.mtx);
b8695a8f 813
40b275b6 814 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
a622ab72 815 if (!tid_tx)
8ade0082 816 goto out;
b8695a8f 817
a622ab72 818 if (mgmt->u.action.u.addba_resp.dialog_token != tid_tx->dialog_token) {
b8695a8f
JB
819#ifdef CONFIG_MAC80211_HT_DEBUG
820 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
a622ab72 821#endif
8ade0082 822 goto out;
b8695a8f
JB
823 }
824
d305a655 825 del_timer_sync(&tid_tx->addba_resp_timer);
8ade0082 826
b8695a8f 827#ifdef CONFIG_MAC80211_HT_DEBUG
55f98938 828 printk(KERN_DEBUG "switched off addBA timer for tid %d\n", tid);
a622ab72 829#endif
d305a655
NM
830
831 /*
832 * addba_resp_timer may have fired before we got here, and
833 * caused WANT_STOP to be set. If the stop then was already
834 * processed further, STOPPING might be set.
835 */
836 if (test_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state) ||
837 test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
838#ifdef CONFIG_MAC80211_HT_DEBUG
839 printk(KERN_DEBUG
840 "got addBA resp for tid %d but we already gave up\n",
841 tid);
842#endif
843 goto out;
844 }
845
3ca97880
HS
846 /*
847 * IEEE 802.11-2007 7.3.1.14:
848 * In an ADDBA Response frame, when the Status Code field
849 * is set to 0, the Buffer Size subfield is set to a value
850 * of at least 1.
851 */
b8695a8f 852 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
3ca97880 853 == WLAN_STATUS_SUCCESS && buf_size) {
a622ab72
JB
854 if (test_and_set_bit(HT_AGG_STATE_RESPONSE_RECEIVED,
855 &tid_tx->state)) {
856 /* ignore duplicate response */
857 goto out;
858 }
b8695a8f 859
0b01f030
JB
860 tid_tx->buf_size = buf_size;
861
a622ab72 862 if (test_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state))
b1720231 863 ieee80211_agg_tx_operational(local, sta, tid);
b8695a8f 864
b1720231 865 sta->ampdu_mlme.addba_req_num[tid] = 0;
285fa695
NM
866
867 if (tid_tx->timeout)
868 mod_timer(&tid_tx->session_timer,
869 TU_TO_EXP_TIME(tid_tx->timeout));
870
b8695a8f 871 } else {
53f73c09
JB
872 ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR,
873 true);
b8695a8f 874 }
2171abc5 875
2171abc5 876 out:
cfcdbde3 877 mutex_unlock(&sta->ampdu_mlme.mtx);
b8695a8f 878}
This page took 0.304499 seconds and 5 git commands to generate.