1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * HT handling
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
6*4882a593Smuzhiyun * Copyright 2002-2005, Instant802 Networks, Inc.
7*4882a593Smuzhiyun * Copyright 2005-2006, Devicescape Software, Inc.
8*4882a593Smuzhiyun * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
9*4882a593Smuzhiyun * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
10*4882a593Smuzhiyun * Copyright 2007-2010, Intel Corporation
11*4882a593Smuzhiyun * Copyright(c) 2015-2017 Intel Deutschland GmbH
12*4882a593Smuzhiyun * Copyright (C) 2018 - 2022 Intel Corporation
13*4882a593Smuzhiyun */
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include <linux/ieee80211.h>
16*4882a593Smuzhiyun #include <linux/slab.h>
17*4882a593Smuzhiyun #include <linux/export.h>
18*4882a593Smuzhiyun #include <net/mac80211.h>
19*4882a593Smuzhiyun #include "ieee80211_i.h"
20*4882a593Smuzhiyun #include "driver-ops.h"
21*4882a593Smuzhiyun #include "wme.h"
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun /**
24*4882a593Smuzhiyun * DOC: TX A-MPDU aggregation
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * Aggregation on the TX side requires setting the hardware flag
27*4882a593Smuzhiyun * %IEEE80211_HW_AMPDU_AGGREGATION. The driver will then be handed
28*4882a593Smuzhiyun * packets with a flag indicating A-MPDU aggregation. The driver
29*4882a593Smuzhiyun * or device is responsible for actually aggregating the frames,
30*4882a593Smuzhiyun * as well as deciding how many and which to aggregate.
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun * When TX aggregation is started by some subsystem (usually the rate
33*4882a593Smuzhiyun * control algorithm would be appropriate) by calling the
34*4882a593Smuzhiyun * ieee80211_start_tx_ba_session() function, the driver will be
35*4882a593Smuzhiyun * notified via its @ampdu_action function, with the
36*4882a593Smuzhiyun * %IEEE80211_AMPDU_TX_START action.
37*4882a593Smuzhiyun *
38*4882a593Smuzhiyun * In response to that, the driver is later required to call the
39*4882a593Smuzhiyun * ieee80211_start_tx_ba_cb_irqsafe() function, which will really
40*4882a593Smuzhiyun * start the aggregation session after the peer has also responded.
41*4882a593Smuzhiyun * If the peer responds negatively, the session will be stopped
42*4882a593Smuzhiyun * again right away. Note that it is possible for the aggregation
43*4882a593Smuzhiyun * session to be stopped before the driver has indicated that it
44*4882a593Smuzhiyun * is done setting it up, in which case it must not indicate the
45*4882a593Smuzhiyun * setup completion.
46*4882a593Smuzhiyun *
47*4882a593Smuzhiyun * Also note that, since we also need to wait for a response from
48*4882a593Smuzhiyun * the peer, the driver is notified of the completion of the
49*4882a593Smuzhiyun * handshake by the %IEEE80211_AMPDU_TX_OPERATIONAL action to the
50*4882a593Smuzhiyun * @ampdu_action callback.
51*4882a593Smuzhiyun *
52*4882a593Smuzhiyun * Similarly, when the aggregation session is stopped by the peer
53*4882a593Smuzhiyun * or something calling ieee80211_stop_tx_ba_session(), the driver's
54*4882a593Smuzhiyun * @ampdu_action function will be called with the action
55*4882a593Smuzhiyun * %IEEE80211_AMPDU_TX_STOP. In this case, the call must not fail,
56*4882a593Smuzhiyun * and the driver must later call ieee80211_stop_tx_ba_cb_irqsafe().
57*4882a593Smuzhiyun * Note that the sta can get destroyed before the BA tear down is
58*4882a593Smuzhiyun * complete.
59*4882a593Smuzhiyun */
60*4882a593Smuzhiyun
ieee80211_send_addba_request(struct ieee80211_sub_if_data * sdata,const u8 * da,u16 tid,u8 dialog_token,u16 start_seq_num,u16 agg_size,u16 timeout)61*4882a593Smuzhiyun static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
62*4882a593Smuzhiyun const u8 *da, u16 tid,
63*4882a593Smuzhiyun u8 dialog_token, u16 start_seq_num,
64*4882a593Smuzhiyun u16 agg_size, u16 timeout)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
67*4882a593Smuzhiyun struct sk_buff *skb;
68*4882a593Smuzhiyun struct ieee80211_mgmt *mgmt;
69*4882a593Smuzhiyun u16 capab;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun if (!skb)
74*4882a593Smuzhiyun return;
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun skb_reserve(skb, local->hw.extra_tx_headroom);
77*4882a593Smuzhiyun mgmt = skb_put_zero(skb, 24);
78*4882a593Smuzhiyun memcpy(mgmt->da, da, ETH_ALEN);
79*4882a593Smuzhiyun memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
80*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP ||
81*4882a593Smuzhiyun sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
82*4882a593Smuzhiyun sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
83*4882a593Smuzhiyun memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
84*4882a593Smuzhiyun else if (sdata->vif.type == NL80211_IFTYPE_STATION)
85*4882a593Smuzhiyun memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
86*4882a593Smuzhiyun else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
87*4882a593Smuzhiyun memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
90*4882a593Smuzhiyun IEEE80211_STYPE_ACTION);
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun mgmt->u.action.category = WLAN_CATEGORY_BACK;
95*4882a593Smuzhiyun mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun mgmt->u.action.u.addba_req.dialog_token = dialog_token;
98*4882a593Smuzhiyun capab = (u16)(1 << 0); /* bit 0 A-MSDU support */
99*4882a593Smuzhiyun capab |= (u16)(1 << 1); /* bit 1 aggregation policy */
100*4882a593Smuzhiyun capab |= (u16)(tid << 2); /* bit 5:2 TID number */
101*4882a593Smuzhiyun capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
106*4882a593Smuzhiyun mgmt->u.action.u.addba_req.start_seq_num =
107*4882a593Smuzhiyun cpu_to_le16(start_seq_num << 4);
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun ieee80211_tx_skb_tid(sdata, skb, tid);
110*4882a593Smuzhiyun }
111*4882a593Smuzhiyun
ieee80211_send_bar(struct ieee80211_vif * vif,u8 * ra,u16 tid,u16 ssn)112*4882a593Smuzhiyun void ieee80211_send_bar(struct ieee80211_vif *vif, u8 *ra, u16 tid, u16 ssn)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
115*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
116*4882a593Smuzhiyun struct sk_buff *skb;
117*4882a593Smuzhiyun struct ieee80211_bar *bar;
118*4882a593Smuzhiyun u16 bar_control = 0;
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
121*4882a593Smuzhiyun if (!skb)
122*4882a593Smuzhiyun return;
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun skb_reserve(skb, local->hw.extra_tx_headroom);
125*4882a593Smuzhiyun bar = skb_put_zero(skb, sizeof(*bar));
126*4882a593Smuzhiyun bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
127*4882a593Smuzhiyun IEEE80211_STYPE_BACK_REQ);
128*4882a593Smuzhiyun memcpy(bar->ra, ra, ETH_ALEN);
129*4882a593Smuzhiyun memcpy(bar->ta, sdata->vif.addr, ETH_ALEN);
130*4882a593Smuzhiyun bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
131*4882a593Smuzhiyun bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
132*4882a593Smuzhiyun bar_control |= (u16)(tid << IEEE80211_BAR_CTRL_TID_INFO_SHIFT);
133*4882a593Smuzhiyun bar->control = cpu_to_le16(bar_control);
134*4882a593Smuzhiyun bar->start_seq_num = cpu_to_le16(ssn);
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
137*4882a593Smuzhiyun IEEE80211_TX_CTL_REQ_TX_STATUS;
138*4882a593Smuzhiyun ieee80211_tx_skb_tid(sdata, skb, tid);
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_send_bar);
141*4882a593Smuzhiyun
ieee80211_assign_tid_tx(struct sta_info * sta,int tid,struct tid_ampdu_tx * tid_tx)142*4882a593Smuzhiyun void ieee80211_assign_tid_tx(struct sta_info *sta, int tid,
143*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx)
144*4882a593Smuzhiyun {
145*4882a593Smuzhiyun lockdep_assert_held(&sta->ampdu_mlme.mtx);
146*4882a593Smuzhiyun lockdep_assert_held(&sta->lock);
147*4882a593Smuzhiyun rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], tid_tx);
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun /*
151*4882a593Smuzhiyun * When multiple aggregation sessions on multiple stations
152*4882a593Smuzhiyun * are being created/destroyed simultaneously, we need to
153*4882a593Smuzhiyun * refcount the global queue stop caused by that in order
154*4882a593Smuzhiyun * to not get into a situation where one of the aggregation
155*4882a593Smuzhiyun * setup or teardown re-enables queues before the other is
156*4882a593Smuzhiyun * ready to handle that.
157*4882a593Smuzhiyun *
158*4882a593Smuzhiyun * These two functions take care of this issue by keeping
159*4882a593Smuzhiyun * a global "agg_queue_stop" refcount.
160*4882a593Smuzhiyun */
__acquires(agg_queue)161*4882a593Smuzhiyun static void __acquires(agg_queue)
162*4882a593Smuzhiyun ieee80211_stop_queue_agg(struct ieee80211_sub_if_data *sdata, int tid)
163*4882a593Smuzhiyun {
164*4882a593Smuzhiyun int queue = sdata->vif.hw_queue[ieee80211_ac_from_tid(tid)];
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun /* we do refcounting here, so don't use the queue reason refcounting */
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun if (atomic_inc_return(&sdata->local->agg_queue_stop[queue]) == 1)
169*4882a593Smuzhiyun ieee80211_stop_queue_by_reason(
170*4882a593Smuzhiyun &sdata->local->hw, queue,
171*4882a593Smuzhiyun IEEE80211_QUEUE_STOP_REASON_AGGREGATION,
172*4882a593Smuzhiyun false);
173*4882a593Smuzhiyun __acquire(agg_queue);
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun
__releases(agg_queue)176*4882a593Smuzhiyun static void __releases(agg_queue)
177*4882a593Smuzhiyun ieee80211_wake_queue_agg(struct ieee80211_sub_if_data *sdata, int tid)
178*4882a593Smuzhiyun {
179*4882a593Smuzhiyun int queue = sdata->vif.hw_queue[ieee80211_ac_from_tid(tid)];
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun if (atomic_dec_return(&sdata->local->agg_queue_stop[queue]) == 0)
182*4882a593Smuzhiyun ieee80211_wake_queue_by_reason(
183*4882a593Smuzhiyun &sdata->local->hw, queue,
184*4882a593Smuzhiyun IEEE80211_QUEUE_STOP_REASON_AGGREGATION,
185*4882a593Smuzhiyun false);
186*4882a593Smuzhiyun __release(agg_queue);
187*4882a593Smuzhiyun }
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun static void
ieee80211_agg_stop_txq(struct sta_info * sta,int tid)190*4882a593Smuzhiyun ieee80211_agg_stop_txq(struct sta_info *sta, int tid)
191*4882a593Smuzhiyun {
192*4882a593Smuzhiyun struct ieee80211_txq *txq = sta->sta.txq[tid];
193*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata;
194*4882a593Smuzhiyun struct fq *fq;
195*4882a593Smuzhiyun struct txq_info *txqi;
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun if (!txq)
198*4882a593Smuzhiyun return;
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun txqi = to_txq_info(txq);
201*4882a593Smuzhiyun sdata = vif_to_sdata(txq->vif);
202*4882a593Smuzhiyun fq = &sdata->local->fq;
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun /* Lock here to protect against further seqno updates on dequeue */
205*4882a593Smuzhiyun spin_lock_bh(&fq->lock);
206*4882a593Smuzhiyun set_bit(IEEE80211_TXQ_STOP, &txqi->flags);
207*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun static void
ieee80211_agg_start_txq(struct sta_info * sta,int tid,bool enable)211*4882a593Smuzhiyun ieee80211_agg_start_txq(struct sta_info *sta, int tid, bool enable)
212*4882a593Smuzhiyun {
213*4882a593Smuzhiyun struct ieee80211_txq *txq = sta->sta.txq[tid];
214*4882a593Smuzhiyun struct txq_info *txqi;
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun lockdep_assert_held(&sta->ampdu_mlme.mtx);
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun if (!txq)
219*4882a593Smuzhiyun return;
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun txqi = to_txq_info(txq);
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun if (enable)
224*4882a593Smuzhiyun set_bit(IEEE80211_TXQ_AMPDU, &txqi->flags);
225*4882a593Smuzhiyun else
226*4882a593Smuzhiyun clear_bit(IEEE80211_TXQ_AMPDU, &txqi->flags);
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun clear_bit(IEEE80211_TXQ_STOP, &txqi->flags);
229*4882a593Smuzhiyun local_bh_disable();
230*4882a593Smuzhiyun rcu_read_lock();
231*4882a593Smuzhiyun schedule_and_wake_txq(sta->sdata->local, txqi);
232*4882a593Smuzhiyun rcu_read_unlock();
233*4882a593Smuzhiyun local_bh_enable();
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun /*
237*4882a593Smuzhiyun * splice packets from the STA's pending to the local pending,
238*4882a593Smuzhiyun * requires a call to ieee80211_agg_splice_finish later
239*4882a593Smuzhiyun */
__acquires(agg_queue)240*4882a593Smuzhiyun static void __acquires(agg_queue)
241*4882a593Smuzhiyun ieee80211_agg_splice_packets(struct ieee80211_sub_if_data *sdata,
242*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx, u16 tid)
243*4882a593Smuzhiyun {
244*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
245*4882a593Smuzhiyun int queue = sdata->vif.hw_queue[ieee80211_ac_from_tid(tid)];
246*4882a593Smuzhiyun unsigned long flags;
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun ieee80211_stop_queue_agg(sdata, tid);
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun if (WARN(!tid_tx,
251*4882a593Smuzhiyun "TID %d gone but expected when splicing aggregates from the pending queue\n",
252*4882a593Smuzhiyun tid))
253*4882a593Smuzhiyun return;
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun if (!skb_queue_empty(&tid_tx->pending)) {
256*4882a593Smuzhiyun spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
257*4882a593Smuzhiyun /* copy over remaining packets */
258*4882a593Smuzhiyun skb_queue_splice_tail_init(&tid_tx->pending,
259*4882a593Smuzhiyun &local->pending[queue]);
260*4882a593Smuzhiyun spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun }
263*4882a593Smuzhiyun
__releases(agg_queue)264*4882a593Smuzhiyun static void __releases(agg_queue)
265*4882a593Smuzhiyun ieee80211_agg_splice_finish(struct ieee80211_sub_if_data *sdata, u16 tid)
266*4882a593Smuzhiyun {
267*4882a593Smuzhiyun ieee80211_wake_queue_agg(sdata, tid);
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun
ieee80211_remove_tid_tx(struct sta_info * sta,int tid)270*4882a593Smuzhiyun static void ieee80211_remove_tid_tx(struct sta_info *sta, int tid)
271*4882a593Smuzhiyun {
272*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun lockdep_assert_held(&sta->ampdu_mlme.mtx);
275*4882a593Smuzhiyun lockdep_assert_held(&sta->lock);
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun /*
280*4882a593Smuzhiyun * When we get here, the TX path will not be lockless any more wrt.
281*4882a593Smuzhiyun * aggregation, since the OPERATIONAL bit has long been cleared.
282*4882a593Smuzhiyun * Thus it will block on getting the lock, if it occurs. So if we
283*4882a593Smuzhiyun * stop the queue now, we will not get any more packets, and any
284*4882a593Smuzhiyun * that might be being processed will wait for us here, thereby
285*4882a593Smuzhiyun * guaranteeing that no packets go to the tid_tx pending queue any
286*4882a593Smuzhiyun * more.
287*4882a593Smuzhiyun */
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun ieee80211_agg_splice_packets(sta->sdata, tid_tx, tid);
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun /* future packets must not find the tid_tx struct any more */
292*4882a593Smuzhiyun ieee80211_assign_tid_tx(sta, tid, NULL);
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun ieee80211_agg_splice_finish(sta->sdata, tid);
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun kfree_rcu(tid_tx, rcu_head);
297*4882a593Smuzhiyun }
298*4882a593Smuzhiyun
___ieee80211_stop_tx_ba_session(struct sta_info * sta,u16 tid,enum ieee80211_agg_stop_reason reason)299*4882a593Smuzhiyun int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
300*4882a593Smuzhiyun enum ieee80211_agg_stop_reason reason)
301*4882a593Smuzhiyun {
302*4882a593Smuzhiyun struct ieee80211_local *local = sta->local;
303*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
304*4882a593Smuzhiyun struct ieee80211_ampdu_params params = {
305*4882a593Smuzhiyun .sta = &sta->sta,
306*4882a593Smuzhiyun .tid = tid,
307*4882a593Smuzhiyun .buf_size = 0,
308*4882a593Smuzhiyun .amsdu = false,
309*4882a593Smuzhiyun .timeout = 0,
310*4882a593Smuzhiyun .ssn = 0,
311*4882a593Smuzhiyun };
312*4882a593Smuzhiyun int ret;
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun lockdep_assert_held(&sta->ampdu_mlme.mtx);
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun switch (reason) {
317*4882a593Smuzhiyun case AGG_STOP_DECLINED:
318*4882a593Smuzhiyun case AGG_STOP_LOCAL_REQUEST:
319*4882a593Smuzhiyun case AGG_STOP_PEER_REQUEST:
320*4882a593Smuzhiyun params.action = IEEE80211_AMPDU_TX_STOP_CONT;
321*4882a593Smuzhiyun break;
322*4882a593Smuzhiyun case AGG_STOP_DESTROY_STA:
323*4882a593Smuzhiyun params.action = IEEE80211_AMPDU_TX_STOP_FLUSH;
324*4882a593Smuzhiyun break;
325*4882a593Smuzhiyun default:
326*4882a593Smuzhiyun WARN_ON_ONCE(1);
327*4882a593Smuzhiyun return -EINVAL;
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun spin_lock_bh(&sta->lock);
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun /* free struct pending for start, if present */
333*4882a593Smuzhiyun tid_tx = sta->ampdu_mlme.tid_start_tx[tid];
334*4882a593Smuzhiyun kfree(tid_tx);
335*4882a593Smuzhiyun sta->ampdu_mlme.tid_start_tx[tid] = NULL;
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
338*4882a593Smuzhiyun if (!tid_tx) {
339*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
340*4882a593Smuzhiyun return -ENOENT;
341*4882a593Smuzhiyun }
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun /*
344*4882a593Smuzhiyun * if we're already stopping ignore any new requests to stop
345*4882a593Smuzhiyun * unless we're destroying it in which case notify the driver
346*4882a593Smuzhiyun */
347*4882a593Smuzhiyun if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
348*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
349*4882a593Smuzhiyun if (reason != AGG_STOP_DESTROY_STA)
350*4882a593Smuzhiyun return -EALREADY;
351*4882a593Smuzhiyun params.action = IEEE80211_AMPDU_TX_STOP_FLUSH_CONT;
352*4882a593Smuzhiyun ret = drv_ampdu_action(local, sta->sdata, ¶ms);
353*4882a593Smuzhiyun WARN_ON_ONCE(ret);
354*4882a593Smuzhiyun return 0;
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
358*4882a593Smuzhiyun /* not even started yet! */
359*4882a593Smuzhiyun ieee80211_assign_tid_tx(sta, tid, NULL);
360*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
361*4882a593Smuzhiyun kfree_rcu(tid_tx, rcu_head);
362*4882a593Smuzhiyun return 0;
363*4882a593Smuzhiyun }
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun set_bit(HT_AGG_STATE_STOPPING, &tid_tx->state);
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun ieee80211_agg_stop_txq(sta, tid);
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun ht_dbg(sta->sdata, "Tx BA session stop requested for %pM tid %u\n",
372*4882a593Smuzhiyun sta->sta.addr, tid);
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun del_timer_sync(&tid_tx->addba_resp_timer);
375*4882a593Smuzhiyun del_timer_sync(&tid_tx->session_timer);
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun /*
378*4882a593Smuzhiyun * After this packets are no longer handed right through
379*4882a593Smuzhiyun * to the driver but are put onto tid_tx->pending instead,
380*4882a593Smuzhiyun * with locking to ensure proper access.
381*4882a593Smuzhiyun */
382*4882a593Smuzhiyun clear_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state);
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun /*
385*4882a593Smuzhiyun * There might be a few packets being processed right now (on
386*4882a593Smuzhiyun * another CPU) that have already gotten past the aggregation
387*4882a593Smuzhiyun * check when it was still OPERATIONAL and consequently have
388*4882a593Smuzhiyun * IEEE80211_TX_CTL_AMPDU set. In that case, this code might
389*4882a593Smuzhiyun * call into the driver at the same time or even before the
390*4882a593Smuzhiyun * TX paths calls into it, which could confuse the driver.
391*4882a593Smuzhiyun *
392*4882a593Smuzhiyun * Wait for all currently running TX paths to finish before
393*4882a593Smuzhiyun * telling the driver. New packets will not go through since
394*4882a593Smuzhiyun * the aggregation session is no longer OPERATIONAL.
395*4882a593Smuzhiyun */
396*4882a593Smuzhiyun if (!local->in_reconfig)
397*4882a593Smuzhiyun synchronize_net();
398*4882a593Smuzhiyun
399*4882a593Smuzhiyun tid_tx->stop_initiator = reason == AGG_STOP_PEER_REQUEST ?
400*4882a593Smuzhiyun WLAN_BACK_RECIPIENT :
401*4882a593Smuzhiyun WLAN_BACK_INITIATOR;
402*4882a593Smuzhiyun tid_tx->tx_stop = reason == AGG_STOP_LOCAL_REQUEST;
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun ret = drv_ampdu_action(local, sta->sdata, ¶ms);
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun /* HW shall not deny going back to legacy */
407*4882a593Smuzhiyun if (WARN_ON(ret)) {
408*4882a593Smuzhiyun /*
409*4882a593Smuzhiyun * We may have pending packets get stuck in this case...
410*4882a593Smuzhiyun * Not bothering with a workaround for now.
411*4882a593Smuzhiyun */
412*4882a593Smuzhiyun }
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun /*
415*4882a593Smuzhiyun * In the case of AGG_STOP_DESTROY_STA, the driver won't
416*4882a593Smuzhiyun * necessarily call ieee80211_stop_tx_ba_cb(), so this may
417*4882a593Smuzhiyun * seem like we can leave the tid_tx data pending forever.
418*4882a593Smuzhiyun * This is true, in a way, but "forever" is only until the
419*4882a593Smuzhiyun * station struct is actually destroyed. In the meantime,
420*4882a593Smuzhiyun * leaving it around ensures that we don't transmit packets
421*4882a593Smuzhiyun * to the driver on this TID which might confuse it.
422*4882a593Smuzhiyun */
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun return 0;
425*4882a593Smuzhiyun }
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun /*
428*4882a593Smuzhiyun * After sending add Block Ack request we activated a timer until
429*4882a593Smuzhiyun * add Block Ack response will arrive from the recipient.
430*4882a593Smuzhiyun * If this timer expires sta_addba_resp_timer_expired will be executed.
431*4882a593Smuzhiyun */
sta_addba_resp_timer_expired(struct timer_list * t)432*4882a593Smuzhiyun static void sta_addba_resp_timer_expired(struct timer_list *t)
433*4882a593Smuzhiyun {
434*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx = from_timer(tid_tx, t, addba_resp_timer);
435*4882a593Smuzhiyun struct sta_info *sta = tid_tx->sta;
436*4882a593Smuzhiyun u8 tid = tid_tx->tid;
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun /* check if the TID waits for addBA response */
439*4882a593Smuzhiyun if (test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state)) {
440*4882a593Smuzhiyun ht_dbg(sta->sdata,
441*4882a593Smuzhiyun "timer expired on %pM tid %d not expecting addBA response\n",
442*4882a593Smuzhiyun sta->sta.addr, tid);
443*4882a593Smuzhiyun return;
444*4882a593Smuzhiyun }
445*4882a593Smuzhiyun
446*4882a593Smuzhiyun ht_dbg(sta->sdata, "addBA response timer expired on %pM tid %d\n",
447*4882a593Smuzhiyun sta->sta.addr, tid);
448*4882a593Smuzhiyun
449*4882a593Smuzhiyun ieee80211_stop_tx_ba_session(&sta->sta, tid);
450*4882a593Smuzhiyun }
451*4882a593Smuzhiyun
ieee80211_send_addba_with_timeout(struct sta_info * sta,struct tid_ampdu_tx * tid_tx)452*4882a593Smuzhiyun static void ieee80211_send_addba_with_timeout(struct sta_info *sta,
453*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx)
454*4882a593Smuzhiyun {
455*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = sta->sdata;
456*4882a593Smuzhiyun struct ieee80211_local *local = sta->local;
457*4882a593Smuzhiyun u8 tid = tid_tx->tid;
458*4882a593Smuzhiyun u16 buf_size;
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun /* activate the timer for the recipient's addBA response */
461*4882a593Smuzhiyun mod_timer(&tid_tx->addba_resp_timer, jiffies + ADDBA_RESP_INTERVAL);
462*4882a593Smuzhiyun ht_dbg(sdata, "activated addBA response timer on %pM tid %d\n",
463*4882a593Smuzhiyun sta->sta.addr, tid);
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun spin_lock_bh(&sta->lock);
466*4882a593Smuzhiyun sta->ampdu_mlme.last_addba_req_time[tid] = jiffies;
467*4882a593Smuzhiyun sta->ampdu_mlme.addba_req_num[tid]++;
468*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun if (sta->sta.he_cap.has_he) {
471*4882a593Smuzhiyun buf_size = local->hw.max_tx_aggregation_subframes;
472*4882a593Smuzhiyun } else {
473*4882a593Smuzhiyun /*
474*4882a593Smuzhiyun * We really should use what the driver told us it will
475*4882a593Smuzhiyun * transmit as the maximum, but certain APs (e.g. the
476*4882a593Smuzhiyun * LinkSys WRT120N with FW v1.0.07 build 002 Jun 18 2012)
477*4882a593Smuzhiyun * will crash when we use a lower number.
478*4882a593Smuzhiyun */
479*4882a593Smuzhiyun buf_size = IEEE80211_MAX_AMPDU_BUF_HT;
480*4882a593Smuzhiyun }
481*4882a593Smuzhiyun
482*4882a593Smuzhiyun /* send AddBA request */
483*4882a593Smuzhiyun ieee80211_send_addba_request(sdata, sta->sta.addr, tid,
484*4882a593Smuzhiyun tid_tx->dialog_token, tid_tx->ssn,
485*4882a593Smuzhiyun buf_size, tid_tx->timeout);
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun WARN_ON(test_and_set_bit(HT_AGG_STATE_SENT_ADDBA, &tid_tx->state));
488*4882a593Smuzhiyun }
489*4882a593Smuzhiyun
ieee80211_tx_ba_session_handle_start(struct sta_info * sta,int tid)490*4882a593Smuzhiyun void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
491*4882a593Smuzhiyun {
492*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
493*4882a593Smuzhiyun struct ieee80211_local *local = sta->local;
494*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = sta->sdata;
495*4882a593Smuzhiyun struct ieee80211_ampdu_params params = {
496*4882a593Smuzhiyun .sta = &sta->sta,
497*4882a593Smuzhiyun .action = IEEE80211_AMPDU_TX_START,
498*4882a593Smuzhiyun .tid = tid,
499*4882a593Smuzhiyun .buf_size = 0,
500*4882a593Smuzhiyun .amsdu = false,
501*4882a593Smuzhiyun .timeout = 0,
502*4882a593Smuzhiyun };
503*4882a593Smuzhiyun int ret;
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun /*
508*4882a593Smuzhiyun * Start queuing up packets for this aggregation session.
509*4882a593Smuzhiyun * We're going to release them once the driver is OK with
510*4882a593Smuzhiyun * that.
511*4882a593Smuzhiyun */
512*4882a593Smuzhiyun clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
513*4882a593Smuzhiyun
514*4882a593Smuzhiyun ieee80211_agg_stop_txq(sta, tid);
515*4882a593Smuzhiyun
516*4882a593Smuzhiyun /*
517*4882a593Smuzhiyun * Make sure no packets are being processed. This ensures that
518*4882a593Smuzhiyun * we have a valid starting sequence number and that in-flight
519*4882a593Smuzhiyun * packets have been flushed out and no packets for this TID
520*4882a593Smuzhiyun * will go into the driver during the ampdu_action call.
521*4882a593Smuzhiyun */
522*4882a593Smuzhiyun synchronize_net();
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun params.ssn = sta->tid_seq[tid] >> 4;
525*4882a593Smuzhiyun ret = drv_ampdu_action(local, sdata, ¶ms);
526*4882a593Smuzhiyun tid_tx->ssn = params.ssn;
527*4882a593Smuzhiyun if (ret == IEEE80211_AMPDU_TX_START_DELAY_ADDBA) {
528*4882a593Smuzhiyun return;
529*4882a593Smuzhiyun } else if (ret == IEEE80211_AMPDU_TX_START_IMMEDIATE) {
530*4882a593Smuzhiyun /*
531*4882a593Smuzhiyun * We didn't send the request yet, so don't need to check
532*4882a593Smuzhiyun * here if we already got a response, just mark as driver
533*4882a593Smuzhiyun * ready immediately.
534*4882a593Smuzhiyun */
535*4882a593Smuzhiyun set_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state);
536*4882a593Smuzhiyun } else if (ret) {
537*4882a593Smuzhiyun ht_dbg(sdata,
538*4882a593Smuzhiyun "BA request denied - HW unavailable for %pM tid %d\n",
539*4882a593Smuzhiyun sta->sta.addr, tid);
540*4882a593Smuzhiyun spin_lock_bh(&sta->lock);
541*4882a593Smuzhiyun ieee80211_agg_splice_packets(sdata, tid_tx, tid);
542*4882a593Smuzhiyun ieee80211_assign_tid_tx(sta, tid, NULL);
543*4882a593Smuzhiyun ieee80211_agg_splice_finish(sdata, tid);
544*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun ieee80211_agg_start_txq(sta, tid, false);
547*4882a593Smuzhiyun
548*4882a593Smuzhiyun kfree_rcu(tid_tx, rcu_head);
549*4882a593Smuzhiyun return;
550*4882a593Smuzhiyun }
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun ieee80211_send_addba_with_timeout(sta, tid_tx);
553*4882a593Smuzhiyun }
554*4882a593Smuzhiyun
555*4882a593Smuzhiyun /*
556*4882a593Smuzhiyun * After accepting the AddBA Response we activated a timer,
557*4882a593Smuzhiyun * resetting it after each frame that we send.
558*4882a593Smuzhiyun */
sta_tx_agg_session_timer_expired(struct timer_list * t)559*4882a593Smuzhiyun static void sta_tx_agg_session_timer_expired(struct timer_list *t)
560*4882a593Smuzhiyun {
561*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx = from_timer(tid_tx, t, session_timer);
562*4882a593Smuzhiyun struct sta_info *sta = tid_tx->sta;
563*4882a593Smuzhiyun u8 tid = tid_tx->tid;
564*4882a593Smuzhiyun unsigned long timeout;
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
567*4882a593Smuzhiyun return;
568*4882a593Smuzhiyun }
569*4882a593Smuzhiyun
570*4882a593Smuzhiyun timeout = tid_tx->last_tx + TU_TO_JIFFIES(tid_tx->timeout);
571*4882a593Smuzhiyun if (time_is_after_jiffies(timeout)) {
572*4882a593Smuzhiyun mod_timer(&tid_tx->session_timer, timeout);
573*4882a593Smuzhiyun return;
574*4882a593Smuzhiyun }
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun ht_dbg(sta->sdata, "tx session timer expired on %pM tid %d\n",
577*4882a593Smuzhiyun sta->sta.addr, tid);
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun ieee80211_stop_tx_ba_session(&sta->sta, tid);
580*4882a593Smuzhiyun }
581*4882a593Smuzhiyun
ieee80211_start_tx_ba_session(struct ieee80211_sta * pubsta,u16 tid,u16 timeout)582*4882a593Smuzhiyun int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
583*4882a593Smuzhiyun u16 timeout)
584*4882a593Smuzhiyun {
585*4882a593Smuzhiyun struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
586*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = sta->sdata;
587*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
588*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
589*4882a593Smuzhiyun int ret = 0;
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun trace_api_start_tx_ba_session(pubsta, tid);
592*4882a593Smuzhiyun
593*4882a593Smuzhiyun if (WARN(sta->reserved_tid == tid,
594*4882a593Smuzhiyun "Requested to start BA session on reserved tid=%d", tid))
595*4882a593Smuzhiyun return -EINVAL;
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun if (!pubsta->ht_cap.ht_supported &&
598*4882a593Smuzhiyun sta->sdata->vif.bss_conf.chandef.chan->band != NL80211_BAND_6GHZ)
599*4882a593Smuzhiyun return -EINVAL;
600*4882a593Smuzhiyun
601*4882a593Smuzhiyun if (WARN_ON_ONCE(!local->ops->ampdu_action))
602*4882a593Smuzhiyun return -EINVAL;
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun if ((tid >= IEEE80211_NUM_TIDS) ||
605*4882a593Smuzhiyun !ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) ||
606*4882a593Smuzhiyun ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW))
607*4882a593Smuzhiyun return -EINVAL;
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun if (WARN_ON(tid >= IEEE80211_FIRST_TSPEC_TSID))
610*4882a593Smuzhiyun return -EINVAL;
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun ht_dbg(sdata, "Open BA session requested for %pM tid %u\n",
613*4882a593Smuzhiyun pubsta->addr, tid);
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun if (sdata->vif.type != NL80211_IFTYPE_STATION &&
616*4882a593Smuzhiyun sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
617*4882a593Smuzhiyun sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
618*4882a593Smuzhiyun sdata->vif.type != NL80211_IFTYPE_AP &&
619*4882a593Smuzhiyun sdata->vif.type != NL80211_IFTYPE_ADHOC)
620*4882a593Smuzhiyun return -EINVAL;
621*4882a593Smuzhiyun
622*4882a593Smuzhiyun if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
623*4882a593Smuzhiyun ht_dbg(sdata,
624*4882a593Smuzhiyun "BA sessions blocked - Denying BA session request %pM tid %d\n",
625*4882a593Smuzhiyun sta->sta.addr, tid);
626*4882a593Smuzhiyun return -EINVAL;
627*4882a593Smuzhiyun }
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun if (test_sta_flag(sta, WLAN_STA_MFP) &&
630*4882a593Smuzhiyun !test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
631*4882a593Smuzhiyun ht_dbg(sdata,
632*4882a593Smuzhiyun "MFP STA not authorized - deny BA session request %pM tid %d\n",
633*4882a593Smuzhiyun sta->sta.addr, tid);
634*4882a593Smuzhiyun return -EINVAL;
635*4882a593Smuzhiyun }
636*4882a593Smuzhiyun
637*4882a593Smuzhiyun /*
638*4882a593Smuzhiyun * 802.11n-2009 11.5.1.1: If the initiating STA is an HT STA, is a
639*4882a593Smuzhiyun * member of an IBSS, and has no other existing Block Ack agreement
640*4882a593Smuzhiyun * with the recipient STA, then the initiating STA shall transmit a
641*4882a593Smuzhiyun * Probe Request frame to the recipient STA and shall not transmit an
642*4882a593Smuzhiyun * ADDBA Request frame unless it receives a Probe Response frame
643*4882a593Smuzhiyun * from the recipient within dot11ADDBAFailureTimeout.
644*4882a593Smuzhiyun *
645*4882a593Smuzhiyun * The probe request mechanism for ADDBA is currently not implemented,
646*4882a593Smuzhiyun * but we only build up Block Ack session with HT STAs. This information
647*4882a593Smuzhiyun * is set when we receive a bss info from a probe response or a beacon.
648*4882a593Smuzhiyun */
649*4882a593Smuzhiyun if (sta->sdata->vif.type == NL80211_IFTYPE_ADHOC &&
650*4882a593Smuzhiyun !sta->sta.ht_cap.ht_supported) {
651*4882a593Smuzhiyun ht_dbg(sdata,
652*4882a593Smuzhiyun "BA request denied - IBSS STA %pM does not advertise HT support\n",
653*4882a593Smuzhiyun pubsta->addr);
654*4882a593Smuzhiyun return -EINVAL;
655*4882a593Smuzhiyun }
656*4882a593Smuzhiyun
657*4882a593Smuzhiyun spin_lock_bh(&sta->lock);
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun /* we have tried too many times, receiver does not want A-MPDU */
660*4882a593Smuzhiyun if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
661*4882a593Smuzhiyun ret = -EBUSY;
662*4882a593Smuzhiyun goto err_unlock_sta;
663*4882a593Smuzhiyun }
664*4882a593Smuzhiyun
665*4882a593Smuzhiyun /*
666*4882a593Smuzhiyun * if we have tried more than HT_AGG_BURST_RETRIES times we
667*4882a593Smuzhiyun * will spread our requests in time to avoid stalling connection
668*4882a593Smuzhiyun * for too long
669*4882a593Smuzhiyun */
670*4882a593Smuzhiyun if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_BURST_RETRIES &&
671*4882a593Smuzhiyun time_before(jiffies, sta->ampdu_mlme.last_addba_req_time[tid] +
672*4882a593Smuzhiyun HT_AGG_RETRIES_PERIOD)) {
673*4882a593Smuzhiyun ht_dbg(sdata,
674*4882a593Smuzhiyun "BA request denied - %d failed requests on %pM tid %u\n",
675*4882a593Smuzhiyun sta->ampdu_mlme.addba_req_num[tid], sta->sta.addr, tid);
676*4882a593Smuzhiyun ret = -EBUSY;
677*4882a593Smuzhiyun goto err_unlock_sta;
678*4882a593Smuzhiyun }
679*4882a593Smuzhiyun
680*4882a593Smuzhiyun tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
681*4882a593Smuzhiyun /* check if the TID is not in aggregation flow already */
682*4882a593Smuzhiyun if (tid_tx || sta->ampdu_mlme.tid_start_tx[tid]) {
683*4882a593Smuzhiyun ht_dbg(sdata,
684*4882a593Smuzhiyun "BA request denied - session is not idle on %pM tid %u\n",
685*4882a593Smuzhiyun sta->sta.addr, tid);
686*4882a593Smuzhiyun ret = -EAGAIN;
687*4882a593Smuzhiyun goto err_unlock_sta;
688*4882a593Smuzhiyun }
689*4882a593Smuzhiyun
690*4882a593Smuzhiyun /* prepare A-MPDU MLME for Tx aggregation */
691*4882a593Smuzhiyun tid_tx = kzalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
692*4882a593Smuzhiyun if (!tid_tx) {
693*4882a593Smuzhiyun ret = -ENOMEM;
694*4882a593Smuzhiyun goto err_unlock_sta;
695*4882a593Smuzhiyun }
696*4882a593Smuzhiyun
697*4882a593Smuzhiyun skb_queue_head_init(&tid_tx->pending);
698*4882a593Smuzhiyun __set_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun tid_tx->timeout = timeout;
701*4882a593Smuzhiyun tid_tx->sta = sta;
702*4882a593Smuzhiyun tid_tx->tid = tid;
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun /* response timer */
705*4882a593Smuzhiyun timer_setup(&tid_tx->addba_resp_timer, sta_addba_resp_timer_expired, 0);
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun /* tx timer */
708*4882a593Smuzhiyun timer_setup(&tid_tx->session_timer,
709*4882a593Smuzhiyun sta_tx_agg_session_timer_expired, TIMER_DEFERRABLE);
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun /* assign a dialog token */
712*4882a593Smuzhiyun sta->ampdu_mlme.dialog_token_allocator++;
713*4882a593Smuzhiyun tid_tx->dialog_token = sta->ampdu_mlme.dialog_token_allocator;
714*4882a593Smuzhiyun
715*4882a593Smuzhiyun /*
716*4882a593Smuzhiyun * Finally, assign it to the start array; the work item will
717*4882a593Smuzhiyun * collect it and move it to the normal array.
718*4882a593Smuzhiyun */
719*4882a593Smuzhiyun sta->ampdu_mlme.tid_start_tx[tid] = tid_tx;
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
722*4882a593Smuzhiyun
723*4882a593Smuzhiyun /* this flow continues off the work */
724*4882a593Smuzhiyun err_unlock_sta:
725*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
726*4882a593Smuzhiyun return ret;
727*4882a593Smuzhiyun }
728*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
729*4882a593Smuzhiyun
ieee80211_agg_tx_operational(struct ieee80211_local * local,struct sta_info * sta,u16 tid)730*4882a593Smuzhiyun static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
731*4882a593Smuzhiyun struct sta_info *sta, u16 tid)
732*4882a593Smuzhiyun {
733*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
734*4882a593Smuzhiyun struct ieee80211_ampdu_params params = {
735*4882a593Smuzhiyun .sta = &sta->sta,
736*4882a593Smuzhiyun .action = IEEE80211_AMPDU_TX_OPERATIONAL,
737*4882a593Smuzhiyun .tid = tid,
738*4882a593Smuzhiyun .timeout = 0,
739*4882a593Smuzhiyun .ssn = 0,
740*4882a593Smuzhiyun };
741*4882a593Smuzhiyun
742*4882a593Smuzhiyun lockdep_assert_held(&sta->ampdu_mlme.mtx);
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
745*4882a593Smuzhiyun params.buf_size = tid_tx->buf_size;
746*4882a593Smuzhiyun params.amsdu = tid_tx->amsdu;
747*4882a593Smuzhiyun
748*4882a593Smuzhiyun ht_dbg(sta->sdata, "Aggregation is on for %pM tid %d\n",
749*4882a593Smuzhiyun sta->sta.addr, tid);
750*4882a593Smuzhiyun
751*4882a593Smuzhiyun drv_ampdu_action(local, sta->sdata, ¶ms);
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun /*
754*4882a593Smuzhiyun * synchronize with TX path, while splicing the TX path
755*4882a593Smuzhiyun * should block so it won't put more packets onto pending.
756*4882a593Smuzhiyun */
757*4882a593Smuzhiyun spin_lock_bh(&sta->lock);
758*4882a593Smuzhiyun
759*4882a593Smuzhiyun ieee80211_agg_splice_packets(sta->sdata, tid_tx, tid);
760*4882a593Smuzhiyun /*
761*4882a593Smuzhiyun * Now mark as operational. This will be visible
762*4882a593Smuzhiyun * in the TX path, and lets it go lock-free in
763*4882a593Smuzhiyun * the common case.
764*4882a593Smuzhiyun */
765*4882a593Smuzhiyun set_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state);
766*4882a593Smuzhiyun ieee80211_agg_splice_finish(sta->sdata, tid);
767*4882a593Smuzhiyun
768*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun ieee80211_agg_start_txq(sta, tid, true);
771*4882a593Smuzhiyun }
772*4882a593Smuzhiyun
ieee80211_start_tx_ba_cb(struct sta_info * sta,int tid,struct tid_ampdu_tx * tid_tx)773*4882a593Smuzhiyun void ieee80211_start_tx_ba_cb(struct sta_info *sta, int tid,
774*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx)
775*4882a593Smuzhiyun {
776*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = sta->sdata;
777*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
778*4882a593Smuzhiyun
779*4882a593Smuzhiyun if (WARN_ON(test_and_set_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state)))
780*4882a593Smuzhiyun return;
781*4882a593Smuzhiyun
782*4882a593Smuzhiyun if (!test_bit(HT_AGG_STATE_SENT_ADDBA, &tid_tx->state)) {
783*4882a593Smuzhiyun ieee80211_send_addba_with_timeout(sta, tid_tx);
784*4882a593Smuzhiyun /* RESPONSE_RECEIVED state whould trigger the flow again */
785*4882a593Smuzhiyun return;
786*4882a593Smuzhiyun }
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun if (test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state))
789*4882a593Smuzhiyun ieee80211_agg_tx_operational(local, sta, tid);
790*4882a593Smuzhiyun }
791*4882a593Smuzhiyun
792*4882a593Smuzhiyun static struct tid_ampdu_tx *
ieee80211_lookup_tid_tx(struct ieee80211_sub_if_data * sdata,const u8 * ra,u16 tid,struct sta_info ** sta)793*4882a593Smuzhiyun ieee80211_lookup_tid_tx(struct ieee80211_sub_if_data *sdata,
794*4882a593Smuzhiyun const u8 *ra, u16 tid, struct sta_info **sta)
795*4882a593Smuzhiyun {
796*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
797*4882a593Smuzhiyun
798*4882a593Smuzhiyun if (tid >= IEEE80211_NUM_TIDS) {
799*4882a593Smuzhiyun ht_dbg(sdata, "Bad TID value: tid = %d (>= %d)\n",
800*4882a593Smuzhiyun tid, IEEE80211_NUM_TIDS);
801*4882a593Smuzhiyun return NULL;
802*4882a593Smuzhiyun }
803*4882a593Smuzhiyun
804*4882a593Smuzhiyun *sta = sta_info_get_bss(sdata, ra);
805*4882a593Smuzhiyun if (!*sta) {
806*4882a593Smuzhiyun ht_dbg(sdata, "Could not find station: %pM\n", ra);
807*4882a593Smuzhiyun return NULL;
808*4882a593Smuzhiyun }
809*4882a593Smuzhiyun
810*4882a593Smuzhiyun tid_tx = rcu_dereference((*sta)->ampdu_mlme.tid_tx[tid]);
811*4882a593Smuzhiyun
812*4882a593Smuzhiyun if (WARN_ON(!tid_tx))
813*4882a593Smuzhiyun ht_dbg(sdata, "addBA was not requested!\n");
814*4882a593Smuzhiyun
815*4882a593Smuzhiyun return tid_tx;
816*4882a593Smuzhiyun }
817*4882a593Smuzhiyun
ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif * vif,const u8 * ra,u16 tid)818*4882a593Smuzhiyun void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
819*4882a593Smuzhiyun const u8 *ra, u16 tid)
820*4882a593Smuzhiyun {
821*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
822*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
823*4882a593Smuzhiyun struct sta_info *sta;
824*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
825*4882a593Smuzhiyun
826*4882a593Smuzhiyun trace_api_start_tx_ba_cb(sdata, ra, tid);
827*4882a593Smuzhiyun
828*4882a593Smuzhiyun rcu_read_lock();
829*4882a593Smuzhiyun tid_tx = ieee80211_lookup_tid_tx(sdata, ra, tid, &sta);
830*4882a593Smuzhiyun if (!tid_tx)
831*4882a593Smuzhiyun goto out;
832*4882a593Smuzhiyun
833*4882a593Smuzhiyun set_bit(HT_AGG_STATE_START_CB, &tid_tx->state);
834*4882a593Smuzhiyun ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
835*4882a593Smuzhiyun out:
836*4882a593Smuzhiyun rcu_read_unlock();
837*4882a593Smuzhiyun }
838*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
839*4882a593Smuzhiyun
__ieee80211_stop_tx_ba_session(struct sta_info * sta,u16 tid,enum ieee80211_agg_stop_reason reason)840*4882a593Smuzhiyun int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
841*4882a593Smuzhiyun enum ieee80211_agg_stop_reason reason)
842*4882a593Smuzhiyun {
843*4882a593Smuzhiyun int ret;
844*4882a593Smuzhiyun
845*4882a593Smuzhiyun mutex_lock(&sta->ampdu_mlme.mtx);
846*4882a593Smuzhiyun
847*4882a593Smuzhiyun ret = ___ieee80211_stop_tx_ba_session(sta, tid, reason);
848*4882a593Smuzhiyun
849*4882a593Smuzhiyun mutex_unlock(&sta->ampdu_mlme.mtx);
850*4882a593Smuzhiyun
851*4882a593Smuzhiyun return ret;
852*4882a593Smuzhiyun }
853*4882a593Smuzhiyun
ieee80211_stop_tx_ba_session(struct ieee80211_sta * pubsta,u16 tid)854*4882a593Smuzhiyun int ieee80211_stop_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid)
855*4882a593Smuzhiyun {
856*4882a593Smuzhiyun struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
857*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = sta->sdata;
858*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
859*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
860*4882a593Smuzhiyun int ret = 0;
861*4882a593Smuzhiyun
862*4882a593Smuzhiyun trace_api_stop_tx_ba_session(pubsta, tid);
863*4882a593Smuzhiyun
864*4882a593Smuzhiyun if (!local->ops->ampdu_action)
865*4882a593Smuzhiyun return -EINVAL;
866*4882a593Smuzhiyun
867*4882a593Smuzhiyun if (tid >= IEEE80211_NUM_TIDS)
868*4882a593Smuzhiyun return -EINVAL;
869*4882a593Smuzhiyun
870*4882a593Smuzhiyun spin_lock_bh(&sta->lock);
871*4882a593Smuzhiyun tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
872*4882a593Smuzhiyun
873*4882a593Smuzhiyun if (!tid_tx) {
874*4882a593Smuzhiyun ret = -ENOENT;
875*4882a593Smuzhiyun goto unlock;
876*4882a593Smuzhiyun }
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun WARN(sta->reserved_tid == tid,
879*4882a593Smuzhiyun "Requested to stop BA session on reserved tid=%d", tid);
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
882*4882a593Smuzhiyun /* already in progress stopping it */
883*4882a593Smuzhiyun ret = 0;
884*4882a593Smuzhiyun goto unlock;
885*4882a593Smuzhiyun }
886*4882a593Smuzhiyun
887*4882a593Smuzhiyun set_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state);
888*4882a593Smuzhiyun ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
889*4882a593Smuzhiyun
890*4882a593Smuzhiyun unlock:
891*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
892*4882a593Smuzhiyun return ret;
893*4882a593Smuzhiyun }
894*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
895*4882a593Smuzhiyun
ieee80211_stop_tx_ba_cb(struct sta_info * sta,int tid,struct tid_ampdu_tx * tid_tx)896*4882a593Smuzhiyun void ieee80211_stop_tx_ba_cb(struct sta_info *sta, int tid,
897*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx)
898*4882a593Smuzhiyun {
899*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = sta->sdata;
900*4882a593Smuzhiyun bool send_delba = false;
901*4882a593Smuzhiyun bool start_txq = false;
902*4882a593Smuzhiyun
903*4882a593Smuzhiyun ht_dbg(sdata, "Stopping Tx BA session for %pM tid %d\n",
904*4882a593Smuzhiyun sta->sta.addr, tid);
905*4882a593Smuzhiyun
906*4882a593Smuzhiyun spin_lock_bh(&sta->lock);
907*4882a593Smuzhiyun
908*4882a593Smuzhiyun if (!test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
909*4882a593Smuzhiyun ht_dbg(sdata,
910*4882a593Smuzhiyun "unexpected callback to A-MPDU stop for %pM tid %d\n",
911*4882a593Smuzhiyun sta->sta.addr, tid);
912*4882a593Smuzhiyun goto unlock_sta;
913*4882a593Smuzhiyun }
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun if (tid_tx->stop_initiator == WLAN_BACK_INITIATOR && tid_tx->tx_stop)
916*4882a593Smuzhiyun send_delba = true;
917*4882a593Smuzhiyun
918*4882a593Smuzhiyun ieee80211_remove_tid_tx(sta, tid);
919*4882a593Smuzhiyun start_txq = true;
920*4882a593Smuzhiyun
921*4882a593Smuzhiyun unlock_sta:
922*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
923*4882a593Smuzhiyun
924*4882a593Smuzhiyun if (start_txq)
925*4882a593Smuzhiyun ieee80211_agg_start_txq(sta, tid, false);
926*4882a593Smuzhiyun
927*4882a593Smuzhiyun if (send_delba)
928*4882a593Smuzhiyun ieee80211_send_delba(sdata, sta->sta.addr, tid,
929*4882a593Smuzhiyun WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
930*4882a593Smuzhiyun }
931*4882a593Smuzhiyun
ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif * vif,const u8 * ra,u16 tid)932*4882a593Smuzhiyun void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
933*4882a593Smuzhiyun const u8 *ra, u16 tid)
934*4882a593Smuzhiyun {
935*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
936*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
937*4882a593Smuzhiyun struct sta_info *sta;
938*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
939*4882a593Smuzhiyun
940*4882a593Smuzhiyun trace_api_stop_tx_ba_cb(sdata, ra, tid);
941*4882a593Smuzhiyun
942*4882a593Smuzhiyun rcu_read_lock();
943*4882a593Smuzhiyun tid_tx = ieee80211_lookup_tid_tx(sdata, ra, tid, &sta);
944*4882a593Smuzhiyun if (!tid_tx)
945*4882a593Smuzhiyun goto out;
946*4882a593Smuzhiyun
947*4882a593Smuzhiyun set_bit(HT_AGG_STATE_STOP_CB, &tid_tx->state);
948*4882a593Smuzhiyun ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
949*4882a593Smuzhiyun out:
950*4882a593Smuzhiyun rcu_read_unlock();
951*4882a593Smuzhiyun }
952*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
953*4882a593Smuzhiyun
954*4882a593Smuzhiyun
ieee80211_process_addba_resp(struct ieee80211_local * local,struct sta_info * sta,struct ieee80211_mgmt * mgmt,size_t len)955*4882a593Smuzhiyun void ieee80211_process_addba_resp(struct ieee80211_local *local,
956*4882a593Smuzhiyun struct sta_info *sta,
957*4882a593Smuzhiyun struct ieee80211_mgmt *mgmt,
958*4882a593Smuzhiyun size_t len)
959*4882a593Smuzhiyun {
960*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
961*4882a593Smuzhiyun struct ieee80211_txq *txq;
962*4882a593Smuzhiyun u16 capab, tid, buf_size;
963*4882a593Smuzhiyun bool amsdu;
964*4882a593Smuzhiyun
965*4882a593Smuzhiyun capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
966*4882a593Smuzhiyun amsdu = capab & IEEE80211_ADDBA_PARAM_AMSDU_MASK;
967*4882a593Smuzhiyun tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
968*4882a593Smuzhiyun buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
969*4882a593Smuzhiyun buf_size = min(buf_size, local->hw.max_tx_aggregation_subframes);
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun txq = sta->sta.txq[tid];
972*4882a593Smuzhiyun if (!amsdu && txq)
973*4882a593Smuzhiyun set_bit(IEEE80211_TXQ_NO_AMSDU, &to_txq_info(txq)->flags);
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun mutex_lock(&sta->ampdu_mlme.mtx);
976*4882a593Smuzhiyun
977*4882a593Smuzhiyun tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
978*4882a593Smuzhiyun if (!tid_tx)
979*4882a593Smuzhiyun goto out;
980*4882a593Smuzhiyun
981*4882a593Smuzhiyun if (mgmt->u.action.u.addba_resp.dialog_token != tid_tx->dialog_token) {
982*4882a593Smuzhiyun ht_dbg(sta->sdata, "wrong addBA response token, %pM tid %d\n",
983*4882a593Smuzhiyun sta->sta.addr, tid);
984*4882a593Smuzhiyun goto out;
985*4882a593Smuzhiyun }
986*4882a593Smuzhiyun
987*4882a593Smuzhiyun del_timer_sync(&tid_tx->addba_resp_timer);
988*4882a593Smuzhiyun
989*4882a593Smuzhiyun ht_dbg(sta->sdata, "switched off addBA timer for %pM tid %d\n",
990*4882a593Smuzhiyun sta->sta.addr, tid);
991*4882a593Smuzhiyun
992*4882a593Smuzhiyun /*
993*4882a593Smuzhiyun * addba_resp_timer may have fired before we got here, and
994*4882a593Smuzhiyun * caused WANT_STOP to be set. If the stop then was already
995*4882a593Smuzhiyun * processed further, STOPPING might be set.
996*4882a593Smuzhiyun */
997*4882a593Smuzhiyun if (test_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state) ||
998*4882a593Smuzhiyun test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
999*4882a593Smuzhiyun ht_dbg(sta->sdata,
1000*4882a593Smuzhiyun "got addBA resp for %pM tid %d but we already gave up\n",
1001*4882a593Smuzhiyun sta->sta.addr, tid);
1002*4882a593Smuzhiyun goto out;
1003*4882a593Smuzhiyun }
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun /*
1006*4882a593Smuzhiyun * IEEE 802.11-2007 7.3.1.14:
1007*4882a593Smuzhiyun * In an ADDBA Response frame, when the Status Code field
1008*4882a593Smuzhiyun * is set to 0, the Buffer Size subfield is set to a value
1009*4882a593Smuzhiyun * of at least 1.
1010*4882a593Smuzhiyun */
1011*4882a593Smuzhiyun if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1012*4882a593Smuzhiyun == WLAN_STATUS_SUCCESS && buf_size) {
1013*4882a593Smuzhiyun if (test_and_set_bit(HT_AGG_STATE_RESPONSE_RECEIVED,
1014*4882a593Smuzhiyun &tid_tx->state)) {
1015*4882a593Smuzhiyun /* ignore duplicate response */
1016*4882a593Smuzhiyun goto out;
1017*4882a593Smuzhiyun }
1018*4882a593Smuzhiyun
1019*4882a593Smuzhiyun tid_tx->buf_size = buf_size;
1020*4882a593Smuzhiyun tid_tx->amsdu = amsdu;
1021*4882a593Smuzhiyun
1022*4882a593Smuzhiyun if (test_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state))
1023*4882a593Smuzhiyun ieee80211_agg_tx_operational(local, sta, tid);
1024*4882a593Smuzhiyun
1025*4882a593Smuzhiyun sta->ampdu_mlme.addba_req_num[tid] = 0;
1026*4882a593Smuzhiyun
1027*4882a593Smuzhiyun tid_tx->timeout =
1028*4882a593Smuzhiyun le16_to_cpu(mgmt->u.action.u.addba_resp.timeout);
1029*4882a593Smuzhiyun
1030*4882a593Smuzhiyun if (tid_tx->timeout) {
1031*4882a593Smuzhiyun mod_timer(&tid_tx->session_timer,
1032*4882a593Smuzhiyun TU_TO_EXP_TIME(tid_tx->timeout));
1033*4882a593Smuzhiyun tid_tx->last_tx = jiffies;
1034*4882a593Smuzhiyun }
1035*4882a593Smuzhiyun
1036*4882a593Smuzhiyun } else {
1037*4882a593Smuzhiyun ___ieee80211_stop_tx_ba_session(sta, tid, AGG_STOP_DECLINED);
1038*4882a593Smuzhiyun }
1039*4882a593Smuzhiyun
1040*4882a593Smuzhiyun out:
1041*4882a593Smuzhiyun mutex_unlock(&sta->ampdu_mlme.mtx);
1042*4882a593Smuzhiyun }
1043