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