Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[cascardo/linux.git] / net / mac80211 / ht.c
1 /*
2  * HT handling
3  *
4  * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
5  * Copyright 2002-2005, Instant802 Networks, Inc.
6  * Copyright 2005-2006, Devicescape Software, Inc.
7  * Copyright 2006-2007  Jiri Benc <jbenc@suse.cz>
8  * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9  * Copyright 2007-2008, Intel Corporation
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  */
15
16 #include <linux/ieee80211.h>
17 #include <net/wireless.h>
18 #include <net/mac80211.h>
19 #include "ieee80211_i.h"
20 #include "sta_info.h"
21 #include "wme.h"
22
23 void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
24                                        struct ieee80211_ht_cap *ht_cap_ie,
25                                        struct ieee80211_sta_ht_cap *ht_cap)
26 {
27         u8 ampdu_info, tx_mcs_set_cap;
28         int i, max_tx_streams;
29
30         BUG_ON(!ht_cap);
31
32         memset(ht_cap, 0, sizeof(*ht_cap));
33
34         if (!ht_cap_ie)
35                 return;
36
37         ht_cap->ht_supported = true;
38
39         ht_cap->cap = le16_to_cpu(ht_cap_ie->cap_info) & sband->ht_cap.cap;
40         ht_cap->cap &= ~IEEE80211_HT_CAP_SM_PS;
41         ht_cap->cap |= sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS;
42
43         ampdu_info = ht_cap_ie->ampdu_params_info;
44         ht_cap->ampdu_factor =
45                 ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
46         ht_cap->ampdu_density =
47                 (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
48
49         /* own MCS TX capabilities */
50         tx_mcs_set_cap = sband->ht_cap.mcs.tx_params;
51
52         /* can we TX with MCS rates? */
53         if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
54                 return;
55
56         /* Counting from 0, therefore +1 */
57         if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
58                 max_tx_streams =
59                         ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
60                                 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
61         else
62                 max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
63
64         /*
65          * 802.11n D5.0 20.3.5 / 20.6 says:
66          * - indices 0 to 7 and 32 are single spatial stream
67          * - 8 to 31 are multiple spatial streams using equal modulation
68          *   [8..15 for two streams, 16..23 for three and 24..31 for four]
69          * - remainder are multiple spatial streams using unequal modulation
70          */
71         for (i = 0; i < max_tx_streams; i++)
72                 ht_cap->mcs.rx_mask[i] =
73                         sband->ht_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
74
75         if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
76                 for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
77                      i < IEEE80211_HT_MCS_MASK_LEN; i++)
78                         ht_cap->mcs.rx_mask[i] =
79                                 sband->ht_cap.mcs.rx_mask[i] &
80                                         ht_cap_ie->mcs.rx_mask[i];
81
82         /* handle MCS rate 32 too */
83         if (sband->ht_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
84                 ht_cap->mcs.rx_mask[32/8] |= 1;
85 }
86
87 /*
88  * ieee80211_enable_ht should be called only after the operating band
89  * has been determined as ht configuration depends on the hw's
90  * HT abilities for a specific band.
91  */
92 u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
93                         struct ieee80211_ht_info *hti,
94                         u16 ap_ht_cap_flags)
95 {
96         struct ieee80211_local *local = sdata->local;
97         struct ieee80211_supported_band *sband;
98         struct ieee80211_bss_ht_conf ht;
99         u32 changed = 0;
100         bool enable_ht = true, ht_changed;
101         enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
102
103         sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
104
105         memset(&ht, 0, sizeof(ht));
106
107         /* HT is not supported */
108         if (!sband->ht_cap.ht_supported)
109                 enable_ht = false;
110
111         /* check that channel matches the right operating channel */
112         if (local->hw.conf.channel->center_freq !=
113             ieee80211_channel_to_frequency(hti->control_chan))
114                 enable_ht = false;
115
116         if (enable_ht) {
117                 channel_type = NL80211_CHAN_HT20;
118
119                 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
120                     (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
121                     (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
122                         switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
123                         case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
124                                 channel_type = NL80211_CHAN_HT40PLUS;
125                                 break;
126                         case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
127                                 channel_type = NL80211_CHAN_HT40MINUS;
128                                 break;
129                         }
130                 }
131         }
132
133         ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
134                      channel_type != local->hw.conf.channel_type;
135
136         local->oper_channel_type = channel_type;
137
138         if (ht_changed) {
139                 /* channel_type change automatically detected */
140                 ieee80211_hw_config(local, 0);
141         }
142
143         /* disable HT */
144         if (!enable_ht)
145                 return 0;
146
147         ht.operation_mode = le16_to_cpu(hti->operation_mode);
148
149         /* if bss configuration changed store the new one */
150         if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
151                 changed |= BSS_CHANGED_HT;
152                 sdata->vif.bss_conf.ht = ht;
153         }
154
155         return changed;
156 }
157
158 static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
159                                          const u8 *da, u16 tid,
160                                          u8 dialog_token, u16 start_seq_num,
161                                          u16 agg_size, u16 timeout)
162 {
163         struct ieee80211_local *local = sdata->local;
164         struct ieee80211_if_sta *ifsta = &sdata->u.sta;
165         struct sk_buff *skb;
166         struct ieee80211_mgmt *mgmt;
167         u16 capab;
168
169         skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
170
171         if (!skb) {
172                 printk(KERN_ERR "%s: failed to allocate buffer "
173                                 "for addba request frame\n", sdata->dev->name);
174                 return;
175         }
176         skb_reserve(skb, local->hw.extra_tx_headroom);
177         mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
178         memset(mgmt, 0, 24);
179         memcpy(mgmt->da, da, ETH_ALEN);
180         memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
181         if (sdata->vif.type == NL80211_IFTYPE_AP)
182                 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
183         else
184                 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
185
186         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
187                                           IEEE80211_STYPE_ACTION);
188
189         skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
190
191         mgmt->u.action.category = WLAN_CATEGORY_BACK;
192         mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
193
194         mgmt->u.action.u.addba_req.dialog_token = dialog_token;
195         capab = (u16)(1 << 1);          /* bit 1 aggregation policy */
196         capab |= (u16)(tid << 2);       /* bit 5:2 TID number */
197         capab |= (u16)(agg_size << 6);  /* bit 15:6 max size of aggergation */
198
199         mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
200
201         mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
202         mgmt->u.action.u.addba_req.start_seq_num =
203                                         cpu_to_le16(start_seq_num << 4);
204
205         ieee80211_tx_skb(sdata, skb, 1);
206 }
207
208 static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid,
209                                       u8 dialog_token, u16 status, u16 policy,
210                                       u16 buf_size, u16 timeout)
211 {
212         struct ieee80211_if_sta *ifsta = &sdata->u.sta;
213         struct ieee80211_local *local = sdata->local;
214         struct sk_buff *skb;
215         struct ieee80211_mgmt *mgmt;
216         u16 capab;
217
218         skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
219
220         if (!skb) {
221                 printk(KERN_DEBUG "%s: failed to allocate buffer "
222                        "for addba resp frame\n", sdata->dev->name);
223                 return;
224         }
225
226         skb_reserve(skb, local->hw.extra_tx_headroom);
227         mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
228         memset(mgmt, 0, 24);
229         memcpy(mgmt->da, da, ETH_ALEN);
230         memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
231         if (sdata->vif.type == NL80211_IFTYPE_AP)
232                 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
233         else
234                 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
235         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
236                                           IEEE80211_STYPE_ACTION);
237
238         skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
239         mgmt->u.action.category = WLAN_CATEGORY_BACK;
240         mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
241         mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
242
243         capab = (u16)(policy << 1);     /* bit 1 aggregation policy */
244         capab |= (u16)(tid << 2);       /* bit 5:2 TID number */
245         capab |= (u16)(buf_size << 6);  /* bit 15:6 max size of aggregation */
246
247         mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
248         mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
249         mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
250
251         ieee80211_tx_skb(sdata, skb, 1);
252 }
253
254 static void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
255                                  const u8 *da, u16 tid,
256                                  u16 initiator, u16 reason_code)
257 {
258         struct ieee80211_local *local = sdata->local;
259         struct ieee80211_if_sta *ifsta = &sdata->u.sta;
260         struct sk_buff *skb;
261         struct ieee80211_mgmt *mgmt;
262         u16 params;
263
264         skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
265
266         if (!skb) {
267                 printk(KERN_ERR "%s: failed to allocate buffer "
268                                         "for delba frame\n", sdata->dev->name);
269                 return;
270         }
271
272         skb_reserve(skb, local->hw.extra_tx_headroom);
273         mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
274         memset(mgmt, 0, 24);
275         memcpy(mgmt->da, da, ETH_ALEN);
276         memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
277         if (sdata->vif.type == NL80211_IFTYPE_AP)
278                 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
279         else
280                 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
281         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
282                                           IEEE80211_STYPE_ACTION);
283
284         skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
285
286         mgmt->u.action.category = WLAN_CATEGORY_BACK;
287         mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
288         params = (u16)(initiator << 11);        /* bit 11 initiator */
289         params |= (u16)(tid << 12);             /* bit 15:12 TID number */
290
291         mgmt->u.action.u.delba.params = cpu_to_le16(params);
292         mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
293
294         ieee80211_tx_skb(sdata, skb, 1);
295 }
296
297 void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn)
298 {
299         struct ieee80211_local *local = sdata->local;
300         struct sk_buff *skb;
301         struct ieee80211_bar *bar;
302         u16 bar_control = 0;
303
304         skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
305         if (!skb) {
306                 printk(KERN_ERR "%s: failed to allocate buffer for "
307                         "bar frame\n", sdata->dev->name);
308                 return;
309         }
310         skb_reserve(skb, local->hw.extra_tx_headroom);
311         bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
312         memset(bar, 0, sizeof(*bar));
313         bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
314                                          IEEE80211_STYPE_BACK_REQ);
315         memcpy(bar->ra, ra, ETH_ALEN);
316         memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN);
317         bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
318         bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
319         bar_control |= (u16)(tid << 12);
320         bar->control = cpu_to_le16(bar_control);
321         bar->start_seq_num = cpu_to_le16(ssn);
322
323         ieee80211_tx_skb(sdata, skb, 0);
324 }
325
326 void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid,
327                                         u16 initiator, u16 reason)
328 {
329         struct ieee80211_local *local = sdata->local;
330         struct ieee80211_hw *hw = &local->hw;
331         struct sta_info *sta;
332         int ret, i;
333
334         rcu_read_lock();
335
336         sta = sta_info_get(local, ra);
337         if (!sta) {
338                 rcu_read_unlock();
339                 return;
340         }
341
342         /* check if TID is in operational state */
343         spin_lock_bh(&sta->lock);
344         if (sta->ampdu_mlme.tid_state_rx[tid]
345                                 != HT_AGG_STATE_OPERATIONAL) {
346                 spin_unlock_bh(&sta->lock);
347                 rcu_read_unlock();
348                 return;
349         }
350         sta->ampdu_mlme.tid_state_rx[tid] =
351                 HT_AGG_STATE_REQ_STOP_BA_MSK |
352                 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
353         spin_unlock_bh(&sta->lock);
354
355         /* stop HW Rx aggregation. ampdu_action existence
356          * already verified in session init so we add the BUG_ON */
357         BUG_ON(!local->ops->ampdu_action);
358
359 #ifdef CONFIG_MAC80211_HT_DEBUG
360         printk(KERN_DEBUG "Rx BA session stop requested for %pM tid %u\n",
361                ra, tid);
362 #endif /* CONFIG_MAC80211_HT_DEBUG */
363
364         ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
365                                        &sta->sta, tid, NULL);
366         if (ret)
367                 printk(KERN_DEBUG "HW problem - can not stop rx "
368                                 "aggregation for tid %d\n", tid);
369
370         /* shutdown timer has not expired */
371         if (initiator != WLAN_BACK_TIMER)
372                 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
373
374         /* check if this is a self generated aggregation halt */
375         if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
376                 ieee80211_send_delba(sdata, ra, tid, 0, reason);
377
378         /* free the reordering buffer */
379         for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
380                 if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
381                         /* release the reordered frames */
382                         dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
383                         sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
384                         sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
385                 }
386         }
387         /* free resources */
388         kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
389         kfree(sta->ampdu_mlme.tid_rx[tid]);
390         sta->ampdu_mlme.tid_rx[tid] = NULL;
391         sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
392
393         rcu_read_unlock();
394 }
395
396
397 /*
398  * After sending add Block Ack request we activated a timer until
399  * add Block Ack response will arrive from the recipient.
400  * If this timer expires sta_addba_resp_timer_expired will be executed.
401  */
402 static void sta_addba_resp_timer_expired(unsigned long data)
403 {
404         /* not an elegant detour, but there is no choice as the timer passes
405          * only one argument, and both sta_info and TID are needed, so init
406          * flow in sta_info_create gives the TID as data, while the timer_to_id
407          * array gives the sta through container_of */
408         u16 tid = *(u8 *)data;
409         struct sta_info *temp_sta = container_of((void *)data,
410                 struct sta_info, timer_to_tid[tid]);
411
412         struct ieee80211_local *local = temp_sta->local;
413         struct ieee80211_hw *hw = &local->hw;
414         struct sta_info *sta;
415         u8 *state;
416
417         rcu_read_lock();
418
419         sta = sta_info_get(local, temp_sta->sta.addr);
420         if (!sta) {
421                 rcu_read_unlock();
422                 return;
423         }
424
425         state = &sta->ampdu_mlme.tid_state_tx[tid];
426         /* check if the TID waits for addBA response */
427         spin_lock_bh(&sta->lock);
428         if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
429                 spin_unlock_bh(&sta->lock);
430                 *state = HT_AGG_STATE_IDLE;
431 #ifdef CONFIG_MAC80211_HT_DEBUG
432                 printk(KERN_DEBUG "timer expired on tid %d but we are not "
433                                 "expecting addBA response there", tid);
434 #endif
435                 goto timer_expired_exit;
436         }
437
438 #ifdef CONFIG_MAC80211_HT_DEBUG
439         printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
440 #endif
441
442         /* go through the state check in stop_BA_session */
443         *state = HT_AGG_STATE_OPERATIONAL;
444         spin_unlock_bh(&sta->lock);
445         ieee80211_stop_tx_ba_session(hw, temp_sta->sta.addr, tid,
446                                      WLAN_BACK_INITIATOR);
447
448 timer_expired_exit:
449         rcu_read_unlock();
450 }
451
452 void ieee80211_sta_tear_down_BA_sessions(struct ieee80211_sub_if_data *sdata, u8 *addr)
453 {
454         struct ieee80211_local *local = sdata->local;
455         int i;
456
457         for (i = 0; i <  STA_TID_NUM; i++) {
458                 ieee80211_stop_tx_ba_session(&local->hw, addr, i,
459                                              WLAN_BACK_INITIATOR);
460                 ieee80211_sta_stop_rx_ba_session(sdata, addr, i,
461                                                  WLAN_BACK_RECIPIENT,
462                                                  WLAN_REASON_QSTA_LEAVE_QBSS);
463         }
464 }
465
466 int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
467 {
468         struct ieee80211_local *local = hw_to_local(hw);
469         struct sta_info *sta;
470         struct ieee80211_sub_if_data *sdata;
471         u16 start_seq_num;
472         u8 *state;
473         int ret = 0;
474
475         if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
476                 return -EINVAL;
477
478 #ifdef CONFIG_MAC80211_HT_DEBUG
479         printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
480                ra, tid);
481 #endif /* CONFIG_MAC80211_HT_DEBUG */
482
483         rcu_read_lock();
484
485         sta = sta_info_get(local, ra);
486         if (!sta) {
487 #ifdef CONFIG_MAC80211_HT_DEBUG
488                 printk(KERN_DEBUG "Could not find the station\n");
489 #endif
490                 ret = -ENOENT;
491                 goto exit;
492         }
493
494         spin_lock_bh(&sta->lock);
495
496         /* we have tried too many times, receiver does not want A-MPDU */
497         if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
498                 ret = -EBUSY;
499                 goto err_unlock_sta;
500         }
501
502         state = &sta->ampdu_mlme.tid_state_tx[tid];
503         /* check if the TID is not in aggregation flow already */
504         if (*state != HT_AGG_STATE_IDLE) {
505 #ifdef CONFIG_MAC80211_HT_DEBUG
506                 printk(KERN_DEBUG "BA request denied - session is not "
507                                  "idle on tid %u\n", tid);
508 #endif /* CONFIG_MAC80211_HT_DEBUG */
509                 ret = -EAGAIN;
510                 goto err_unlock_sta;
511         }
512
513         /* prepare A-MPDU MLME for Tx aggregation */
514         sta->ampdu_mlme.tid_tx[tid] =
515                         kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
516         if (!sta->ampdu_mlme.tid_tx[tid]) {
517 #ifdef CONFIG_MAC80211_HT_DEBUG
518                 if (net_ratelimit())
519                         printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
520                                         tid);
521 #endif
522                 ret = -ENOMEM;
523                 goto err_unlock_sta;
524         }
525         /* Tx timer */
526         sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
527                         sta_addba_resp_timer_expired;
528         sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
529                         (unsigned long)&sta->timer_to_tid[tid];
530         init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
531
532         if (hw->ampdu_queues) {
533                 /* create a new queue for this aggregation */
534                 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
535
536                 /* case no queue is available to aggregation
537                  * don't switch to aggregation */
538                 if (ret) {
539 #ifdef CONFIG_MAC80211_HT_DEBUG
540                         printk(KERN_DEBUG "BA request denied - "
541                                "queue unavailable for tid %d\n", tid);
542 #endif /* CONFIG_MAC80211_HT_DEBUG */
543                         goto err_unlock_queue;
544                 }
545         }
546         sdata = sta->sdata;
547
548         /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
549          * call back right away, it must see that the flow has begun */
550         *state |= HT_ADDBA_REQUESTED_MSK;
551
552         /* This is slightly racy because the queue isn't stopped */
553         start_seq_num = sta->tid_seq[tid];
554
555         if (local->ops->ampdu_action)
556                 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
557                                                &sta->sta, tid, &start_seq_num);
558
559         if (ret) {
560                 /* No need to requeue the packets in the agg queue, since we
561                  * held the tx lock: no packet could be enqueued to the newly
562                  * allocated queue */
563                 if (hw->ampdu_queues)
564                         ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
565 #ifdef CONFIG_MAC80211_HT_DEBUG
566                 printk(KERN_DEBUG "BA request denied - HW unavailable for"
567                                         " tid %d\n", tid);
568 #endif /* CONFIG_MAC80211_HT_DEBUG */
569                 *state = HT_AGG_STATE_IDLE;
570                 goto err_unlock_queue;
571         }
572
573         /* Will put all the packets in the new SW queue */
574         if (hw->ampdu_queues)
575                 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
576         spin_unlock_bh(&sta->lock);
577
578         /* send an addBA request */
579         sta->ampdu_mlme.dialog_token_allocator++;
580         sta->ampdu_mlme.tid_tx[tid]->dialog_token =
581                         sta->ampdu_mlme.dialog_token_allocator;
582         sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
583
584
585         ieee80211_send_addba_request(sta->sdata, ra, tid,
586                          sta->ampdu_mlme.tid_tx[tid]->dialog_token,
587                          sta->ampdu_mlme.tid_tx[tid]->ssn,
588                          0x40, 5000);
589         /* activate the timer for the recipient's addBA response */
590         sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
591                                 jiffies + ADDBA_RESP_INTERVAL;
592         add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
593 #ifdef CONFIG_MAC80211_HT_DEBUG
594         printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
595 #endif
596         goto exit;
597
598 err_unlock_queue:
599         kfree(sta->ampdu_mlme.tid_tx[tid]);
600         sta->ampdu_mlme.tid_tx[tid] = NULL;
601         ret = -EBUSY;
602 err_unlock_sta:
603         spin_unlock_bh(&sta->lock);
604 exit:
605         rcu_read_unlock();
606         return ret;
607 }
608 EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
609
610 int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
611                                  u8 *ra, u16 tid,
612                                  enum ieee80211_back_parties initiator)
613 {
614         struct ieee80211_local *local = hw_to_local(hw);
615         struct sta_info *sta;
616         u8 *state;
617         int ret = 0;
618
619         if (tid >= STA_TID_NUM)
620                 return -EINVAL;
621
622         rcu_read_lock();
623         sta = sta_info_get(local, ra);
624         if (!sta) {
625                 rcu_read_unlock();
626                 return -ENOENT;
627         }
628
629         /* check if the TID is in aggregation */
630         state = &sta->ampdu_mlme.tid_state_tx[tid];
631         spin_lock_bh(&sta->lock);
632
633         if (*state != HT_AGG_STATE_OPERATIONAL) {
634                 ret = -ENOENT;
635                 goto stop_BA_exit;
636         }
637
638 #ifdef CONFIG_MAC80211_HT_DEBUG
639         printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
640                ra, tid);
641 #endif /* CONFIG_MAC80211_HT_DEBUG */
642
643         if (hw->ampdu_queues)
644                 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
645
646         *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
647                 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
648
649         if (local->ops->ampdu_action)
650                 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
651                                                &sta->sta, tid, NULL);
652
653         /* case HW denied going back to legacy */
654         if (ret) {
655                 WARN_ON(ret != -EBUSY);
656                 *state = HT_AGG_STATE_OPERATIONAL;
657                 if (hw->ampdu_queues)
658                         ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
659                 goto stop_BA_exit;
660         }
661
662 stop_BA_exit:
663         spin_unlock_bh(&sta->lock);
664         rcu_read_unlock();
665         return ret;
666 }
667 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
668
669 void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
670 {
671         struct ieee80211_local *local = hw_to_local(hw);
672         struct sta_info *sta;
673         u8 *state;
674
675         if (tid >= STA_TID_NUM) {
676 #ifdef CONFIG_MAC80211_HT_DEBUG
677                 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
678                                 tid, STA_TID_NUM);
679 #endif
680                 return;
681         }
682
683         rcu_read_lock();
684         sta = sta_info_get(local, ra);
685         if (!sta) {
686                 rcu_read_unlock();
687 #ifdef CONFIG_MAC80211_HT_DEBUG
688                 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
689 #endif
690                 return;
691         }
692
693         state = &sta->ampdu_mlme.tid_state_tx[tid];
694         spin_lock_bh(&sta->lock);
695
696         if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
697 #ifdef CONFIG_MAC80211_HT_DEBUG
698                 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
699                                 *state);
700 #endif
701                 spin_unlock_bh(&sta->lock);
702                 rcu_read_unlock();
703                 return;
704         }
705
706         WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
707
708         *state |= HT_ADDBA_DRV_READY_MSK;
709
710         if (*state == HT_AGG_STATE_OPERATIONAL) {
711 #ifdef CONFIG_MAC80211_HT_DEBUG
712                 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
713 #endif
714                 if (hw->ampdu_queues)
715                         ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
716         }
717         spin_unlock_bh(&sta->lock);
718         rcu_read_unlock();
719 }
720 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
721
722 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
723 {
724         struct ieee80211_local *local = hw_to_local(hw);
725         struct sta_info *sta;
726         u8 *state;
727         int agg_queue;
728
729         if (tid >= STA_TID_NUM) {
730 #ifdef CONFIG_MAC80211_HT_DEBUG
731                 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
732                                 tid, STA_TID_NUM);
733 #endif
734                 return;
735         }
736
737 #ifdef CONFIG_MAC80211_HT_DEBUG
738         printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
739                ra, tid);
740 #endif /* CONFIG_MAC80211_HT_DEBUG */
741
742         rcu_read_lock();
743         sta = sta_info_get(local, ra);
744         if (!sta) {
745 #ifdef CONFIG_MAC80211_HT_DEBUG
746                 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
747 #endif
748                 rcu_read_unlock();
749                 return;
750         }
751         state = &sta->ampdu_mlme.tid_state_tx[tid];
752
753         /* NOTE: no need to use sta->lock in this state check, as
754          * ieee80211_stop_tx_ba_session will let only one stop call to
755          * pass through per sta/tid
756          */
757         if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
758 #ifdef CONFIG_MAC80211_HT_DEBUG
759                 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
760 #endif
761                 rcu_read_unlock();
762                 return;
763         }
764
765         if (*state & HT_AGG_STATE_INITIATOR_MSK)
766                 ieee80211_send_delba(sta->sdata, ra, tid,
767                         WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
768
769         if (hw->ampdu_queues) {
770                 agg_queue = sta->tid_to_tx_q[tid];
771                 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
772
773                 /* We just requeued the all the frames that were in the
774                  * removed queue, and since we might miss a softirq we do
775                  * netif_schedule_queue.  ieee80211_wake_queue is not used
776                  * here as this queue is not necessarily stopped
777                  */
778                 netif_schedule_queue(netdev_get_tx_queue(local->mdev,
779                                                          agg_queue));
780         }
781         spin_lock_bh(&sta->lock);
782         *state = HT_AGG_STATE_IDLE;
783         sta->ampdu_mlme.addba_req_num[tid] = 0;
784         kfree(sta->ampdu_mlme.tid_tx[tid]);
785         sta->ampdu_mlme.tid_tx[tid] = NULL;
786         spin_unlock_bh(&sta->lock);
787
788         rcu_read_unlock();
789 }
790 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
791
792 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
793                                       const u8 *ra, u16 tid)
794 {
795         struct ieee80211_local *local = hw_to_local(hw);
796         struct ieee80211_ra_tid *ra_tid;
797         struct sk_buff *skb = dev_alloc_skb(0);
798
799         if (unlikely(!skb)) {
800 #ifdef CONFIG_MAC80211_HT_DEBUG
801                 if (net_ratelimit())
802                         printk(KERN_WARNING "%s: Not enough memory, "
803                                "dropping start BA session", skb->dev->name);
804 #endif
805                 return;
806         }
807         ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
808         memcpy(&ra_tid->ra, ra, ETH_ALEN);
809         ra_tid->tid = tid;
810
811         skb->pkt_type = IEEE80211_ADDBA_MSG;
812         skb_queue_tail(&local->skb_queue, skb);
813         tasklet_schedule(&local->tasklet);
814 }
815 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
816
817 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
818                                      const u8 *ra, u16 tid)
819 {
820         struct ieee80211_local *local = hw_to_local(hw);
821         struct ieee80211_ra_tid *ra_tid;
822         struct sk_buff *skb = dev_alloc_skb(0);
823
824         if (unlikely(!skb)) {
825 #ifdef CONFIG_MAC80211_HT_DEBUG
826                 if (net_ratelimit())
827                         printk(KERN_WARNING "%s: Not enough memory, "
828                                "dropping stop BA session", skb->dev->name);
829 #endif
830                 return;
831         }
832         ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
833         memcpy(&ra_tid->ra, ra, ETH_ALEN);
834         ra_tid->tid = tid;
835
836         skb->pkt_type = IEEE80211_DELBA_MSG;
837         skb_queue_tail(&local->skb_queue, skb);
838         tasklet_schedule(&local->tasklet);
839 }
840 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
841
842 /*
843  * After accepting the AddBA Request we activated a timer,
844  * resetting it after each frame that arrives from the originator.
845  * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
846  */
847 static void sta_rx_agg_session_timer_expired(unsigned long data)
848 {
849         /* not an elegant detour, but there is no choice as the timer passes
850          * only one argument, and various sta_info are needed here, so init
851          * flow in sta_info_create gives the TID as data, while the timer_to_id
852          * array gives the sta through container_of */
853         u8 *ptid = (u8 *)data;
854         u8 *timer_to_id = ptid - *ptid;
855         struct sta_info *sta = container_of(timer_to_id, struct sta_info,
856                                          timer_to_tid[0]);
857
858 #ifdef CONFIG_MAC80211_HT_DEBUG
859         printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
860 #endif
861         ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
862                                          (u16)*ptid, WLAN_BACK_TIMER,
863                                          WLAN_REASON_QSTA_TIMEOUT);
864 }
865
866 void ieee80211_process_addba_request(struct ieee80211_local *local,
867                                      struct sta_info *sta,
868                                      struct ieee80211_mgmt *mgmt,
869                                      size_t len)
870 {
871         struct ieee80211_hw *hw = &local->hw;
872         struct ieee80211_conf *conf = &hw->conf;
873         struct tid_ampdu_rx *tid_agg_rx;
874         u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
875         u8 dialog_token;
876         int ret = -EOPNOTSUPP;
877
878         /* extract session parameters from addba request frame */
879         dialog_token = mgmt->u.action.u.addba_req.dialog_token;
880         timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
881         start_seq_num =
882                 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
883
884         capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
885         ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
886         tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
887         buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
888
889         status = WLAN_STATUS_REQUEST_DECLINED;
890
891         /* sanity check for incoming parameters:
892          * check if configuration can support the BA policy
893          * and if buffer size does not exceeds max value */
894         /* XXX: check own ht delayed BA capability?? */
895         if (((ba_policy != 1)
896                 && (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA)))
897                 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
898                 status = WLAN_STATUS_INVALID_QOS_PARAM;
899 #ifdef CONFIG_MAC80211_HT_DEBUG
900                 if (net_ratelimit())
901                         printk(KERN_DEBUG "AddBA Req with bad params from "
902                                 "%pM on tid %u. policy %d, buffer size %d\n",
903                                 mgmt->sa, tid, ba_policy,
904                                 buf_size);
905 #endif /* CONFIG_MAC80211_HT_DEBUG */
906                 goto end_no_lock;
907         }
908         /* determine default buffer size */
909         if (buf_size == 0) {
910                 struct ieee80211_supported_band *sband;
911
912                 sband = local->hw.wiphy->bands[conf->channel->band];
913                 buf_size = IEEE80211_MIN_AMPDU_BUF;
914                 buf_size = buf_size << sband->ht_cap.ampdu_factor;
915         }
916
917
918         /* examine state machine */
919         spin_lock_bh(&sta->lock);
920
921         if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
922 #ifdef CONFIG_MAC80211_HT_DEBUG
923                 if (net_ratelimit())
924                         printk(KERN_DEBUG "unexpected AddBA Req from "
925                                 "%pM on tid %u\n",
926                                 mgmt->sa, tid);
927 #endif /* CONFIG_MAC80211_HT_DEBUG */
928                 goto end;
929         }
930
931         /* prepare A-MPDU MLME for Rx aggregation */
932         sta->ampdu_mlme.tid_rx[tid] =
933                         kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
934         if (!sta->ampdu_mlme.tid_rx[tid]) {
935 #ifdef CONFIG_MAC80211_HT_DEBUG
936                 if (net_ratelimit())
937                         printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
938                                         tid);
939 #endif
940                 goto end;
941         }
942         /* rx timer */
943         sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
944                                 sta_rx_agg_session_timer_expired;
945         sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
946                                 (unsigned long)&sta->timer_to_tid[tid];
947         init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
948
949         tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
950
951         /* prepare reordering buffer */
952         tid_agg_rx->reorder_buf =
953                 kcalloc(buf_size, sizeof(struct sk_buff *), GFP_ATOMIC);
954         if (!tid_agg_rx->reorder_buf) {
955 #ifdef CONFIG_MAC80211_HT_DEBUG
956                 if (net_ratelimit())
957                         printk(KERN_ERR "can not allocate reordering buffer "
958                                "to tid %d\n", tid);
959 #endif
960                 kfree(sta->ampdu_mlme.tid_rx[tid]);
961                 goto end;
962         }
963
964         if (local->ops->ampdu_action)
965                 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
966                                                &sta->sta, tid, &start_seq_num);
967 #ifdef CONFIG_MAC80211_HT_DEBUG
968         printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
969 #endif /* CONFIG_MAC80211_HT_DEBUG */
970
971         if (ret) {
972                 kfree(tid_agg_rx->reorder_buf);
973                 kfree(tid_agg_rx);
974                 sta->ampdu_mlme.tid_rx[tid] = NULL;
975                 goto end;
976         }
977
978         /* change state and send addba resp */
979         sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
980         tid_agg_rx->dialog_token = dialog_token;
981         tid_agg_rx->ssn = start_seq_num;
982         tid_agg_rx->head_seq_num = start_seq_num;
983         tid_agg_rx->buf_size = buf_size;
984         tid_agg_rx->timeout = timeout;
985         tid_agg_rx->stored_mpdu_num = 0;
986         status = WLAN_STATUS_SUCCESS;
987 end:
988         spin_unlock_bh(&sta->lock);
989
990 end_no_lock:
991         ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid,
992                                   dialog_token, status, 1, buf_size, timeout);
993 }
994
995 void ieee80211_process_addba_resp(struct ieee80211_local *local,
996                                   struct sta_info *sta,
997                                   struct ieee80211_mgmt *mgmt,
998                                   size_t len)
999 {
1000         struct ieee80211_hw *hw = &local->hw;
1001         u16 capab;
1002         u16 tid, start_seq_num;
1003         u8 *state;
1004
1005         capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1006         tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1007
1008         state = &sta->ampdu_mlme.tid_state_tx[tid];
1009
1010         spin_lock_bh(&sta->lock);
1011
1012         if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1013                 spin_unlock_bh(&sta->lock);
1014                 return;
1015         }
1016
1017         if (mgmt->u.action.u.addba_resp.dialog_token !=
1018                 sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
1019                 spin_unlock_bh(&sta->lock);
1020 #ifdef CONFIG_MAC80211_HT_DEBUG
1021                 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1022 #endif /* CONFIG_MAC80211_HT_DEBUG */
1023                 return;
1024         }
1025
1026         del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
1027 #ifdef CONFIG_MAC80211_HT_DEBUG
1028         printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1029 #endif /* CONFIG_MAC80211_HT_DEBUG */
1030         if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1031                         == WLAN_STATUS_SUCCESS) {
1032                 *state |= HT_ADDBA_RECEIVED_MSK;
1033                 sta->ampdu_mlme.addba_req_num[tid] = 0;
1034
1035                 if (*state == HT_AGG_STATE_OPERATIONAL &&
1036                     local->hw.ampdu_queues)
1037                         ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1038
1039                 if (local->ops->ampdu_action) {
1040                         (void)local->ops->ampdu_action(hw,
1041                                                IEEE80211_AMPDU_TX_RESUME,
1042                                                &sta->sta, tid, &start_seq_num);
1043                 }
1044 #ifdef CONFIG_MAC80211_HT_DEBUG
1045                 printk(KERN_DEBUG "Resuming TX aggregation for tid %d\n", tid);
1046 #endif /* CONFIG_MAC80211_HT_DEBUG */
1047                 spin_unlock_bh(&sta->lock);
1048         } else {
1049                 sta->ampdu_mlme.addba_req_num[tid]++;
1050                 /* this will allow the state check in stop_BA_session */
1051                 *state = HT_AGG_STATE_OPERATIONAL;
1052                 spin_unlock_bh(&sta->lock);
1053                 ieee80211_stop_tx_ba_session(hw, sta->sta.addr, tid,
1054                                              WLAN_BACK_INITIATOR);
1055         }
1056 }
1057
1058 void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
1059                              struct sta_info *sta,
1060                              struct ieee80211_mgmt *mgmt, size_t len)
1061 {
1062         struct ieee80211_local *local = sdata->local;
1063         u16 tid, params;
1064         u16 initiator;
1065
1066         params = le16_to_cpu(mgmt->u.action.u.delba.params);
1067         tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1068         initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1069
1070 #ifdef CONFIG_MAC80211_HT_DEBUG
1071         if (net_ratelimit())
1072                 printk(KERN_DEBUG "delba from %pM (%s) tid %d reason code %d\n",
1073                         mgmt->sa, initiator ? "initiator" : "recipient", tid,
1074                         mgmt->u.action.u.delba.reason_code);
1075 #endif /* CONFIG_MAC80211_HT_DEBUG */
1076
1077         if (initiator == WLAN_BACK_INITIATOR)
1078                 ieee80211_sta_stop_rx_ba_session(sdata, sta->sta.addr, tid,
1079                                                  WLAN_BACK_INITIATOR, 0);
1080         else { /* WLAN_BACK_RECIPIENT */
1081                 spin_lock_bh(&sta->lock);
1082                 sta->ampdu_mlme.tid_state_tx[tid] =
1083                                 HT_AGG_STATE_OPERATIONAL;
1084                 spin_unlock_bh(&sta->lock);
1085                 ieee80211_stop_tx_ba_session(&local->hw, sta->sta.addr, tid,
1086                                              WLAN_BACK_RECIPIENT);
1087         }
1088 }