agg-tx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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-2009, 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. #include <linux/ieee80211.h>
  16. #include <linux/slab.h>
  17. #include <net/mac80211.h>
  18. #include "ieee80211_i.h"
  19. #include "driver-ops.h"
  20. #include "wme.h"
  21. /**
  22. * DOC: TX aggregation
  23. *
  24. * Aggregation on the TX side requires setting the hardware flag
  25. * %IEEE80211_HW_AMPDU_AGGREGATION as well as, if present, the @ampdu_queues
  26. * hardware parameter to the number of hardware AMPDU queues. If there are no
  27. * hardware queues then the driver will (currently) have to do all frame
  28. * buffering.
  29. *
  30. * When TX aggregation is started by some subsystem (usually the rate control
  31. * algorithm would be appropriate) by calling the
  32. * ieee80211_start_tx_ba_session() function, the driver will be notified via
  33. * its @ampdu_action function, with the %IEEE80211_AMPDU_TX_START action.
  34. *
  35. * In response to that, the driver is later required to call the
  36. * ieee80211_start_tx_ba_cb() (or ieee80211_start_tx_ba_cb_irqsafe())
  37. * function, which will start the aggregation session.
  38. *
  39. * Similarly, when the aggregation session is stopped by
  40. * ieee80211_stop_tx_ba_session(), the driver's @ampdu_action function will
  41. * be called with the action %IEEE80211_AMPDU_TX_STOP. In this case, the
  42. * call must not fail, and the driver must later call ieee80211_stop_tx_ba_cb()
  43. * (or ieee80211_stop_tx_ba_cb_irqsafe()).
  44. */
  45. static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
  46. const u8 *da, u16 tid,
  47. u8 dialog_token, u16 start_seq_num,
  48. u16 agg_size, u16 timeout)
  49. {
  50. struct ieee80211_local *local = sdata->local;
  51. struct sk_buff *skb;
  52. struct ieee80211_mgmt *mgmt;
  53. u16 capab;
  54. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  55. if (!skb) {
  56. printk(KERN_ERR "%s: failed to allocate buffer "
  57. "for addba request frame\n", sdata->name);
  58. return;
  59. }
  60. skb_reserve(skb, local->hw.extra_tx_headroom);
  61. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  62. memset(mgmt, 0, 24);
  63. memcpy(mgmt->da, da, ETH_ALEN);
  64. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  65. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  66. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  67. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  68. else if (sdata->vif.type == NL80211_IFTYPE_STATION)
  69. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  70. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  71. IEEE80211_STYPE_ACTION);
  72. skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
  73. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  74. mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
  75. mgmt->u.action.u.addba_req.dialog_token = dialog_token;
  76. capab = (u16)(1 << 1); /* bit 1 aggregation policy */
  77. capab |= (u16)(tid << 2); /* bit 5:2 TID number */
  78. capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
  79. mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
  80. mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
  81. mgmt->u.action.u.addba_req.start_seq_num =
  82. cpu_to_le16(start_seq_num << 4);
  83. ieee80211_tx_skb(sdata, skb);
  84. }
  85. void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn)
  86. {
  87. struct ieee80211_local *local = sdata->local;
  88. struct sk_buff *skb;
  89. struct ieee80211_bar *bar;
  90. u16 bar_control = 0;
  91. skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
  92. if (!skb) {
  93. printk(KERN_ERR "%s: failed to allocate buffer for "
  94. "bar frame\n", sdata->name);
  95. return;
  96. }
  97. skb_reserve(skb, local->hw.extra_tx_headroom);
  98. bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
  99. memset(bar, 0, sizeof(*bar));
  100. bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  101. IEEE80211_STYPE_BACK_REQ);
  102. memcpy(bar->ra, ra, ETH_ALEN);
  103. memcpy(bar->ta, sdata->vif.addr, ETH_ALEN);
  104. bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
  105. bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
  106. bar_control |= (u16)(tid << 12);
  107. bar->control = cpu_to_le16(bar_control);
  108. bar->start_seq_num = cpu_to_le16(ssn);
  109. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  110. ieee80211_tx_skb(sdata, skb);
  111. }
  112. static void kfree_tid_tx(struct rcu_head *rcu_head)
  113. {
  114. struct tid_ampdu_tx *tid_tx =
  115. container_of(rcu_head, struct tid_ampdu_tx, rcu_head);
  116. kfree(tid_tx);
  117. }
  118. static int ___ieee80211_stop_tx_ba_session(
  119. struct sta_info *sta, u16 tid,
  120. enum ieee80211_back_parties initiator)
  121. {
  122. struct ieee80211_local *local = sta->local;
  123. struct tid_ampdu_tx *tid_tx = sta->ampdu_mlme.tid_tx[tid];
  124. int ret;
  125. lockdep_assert_held(&sta->lock);
  126. if (WARN_ON(!tid_tx))
  127. return -ENOENT;
  128. #ifdef CONFIG_MAC80211_HT_DEBUG
  129. printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
  130. sta->sta.addr, tid);
  131. #endif /* CONFIG_MAC80211_HT_DEBUG */
  132. set_bit(HT_AGG_STATE_STOPPING, &tid_tx->state);
  133. /*
  134. * After this packets are no longer handed right through
  135. * to the driver but are put onto tid_tx->pending instead,
  136. * with locking to ensure proper access.
  137. */
  138. clear_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state);
  139. tid_tx->stop_initiator = initiator;
  140. ret = drv_ampdu_action(local, sta->sdata,
  141. IEEE80211_AMPDU_TX_STOP,
  142. &sta->sta, tid, NULL);
  143. /* HW shall not deny going back to legacy */
  144. if (WARN_ON(ret)) {
  145. /*
  146. * We may have pending packets get stuck in this case...
  147. * Not bothering with a workaround for now.
  148. */
  149. }
  150. return ret;
  151. }
  152. /*
  153. * After sending add Block Ack request we activated a timer until
  154. * add Block Ack response will arrive from the recipient.
  155. * If this timer expires sta_addba_resp_timer_expired will be executed.
  156. */
  157. static void sta_addba_resp_timer_expired(unsigned long data)
  158. {
  159. /* not an elegant detour, but there is no choice as the timer passes
  160. * only one argument, and both sta_info and TID are needed, so init
  161. * flow in sta_info_create gives the TID as data, while the timer_to_id
  162. * array gives the sta through container_of */
  163. u16 tid = *(u8 *)data;
  164. struct sta_info *sta = container_of((void *)data,
  165. struct sta_info, timer_to_tid[tid]);
  166. struct tid_ampdu_tx *tid_tx;
  167. /* check if the TID waits for addBA response */
  168. spin_lock_bh(&sta->lock);
  169. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  170. if (!tid_tx ||
  171. test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state)) {
  172. spin_unlock_bh(&sta->lock);
  173. #ifdef CONFIG_MAC80211_HT_DEBUG
  174. printk(KERN_DEBUG "timer expired on tid %d but we are not "
  175. "(or no longer) expecting addBA response there\n",
  176. tid);
  177. #endif
  178. return;
  179. }
  180. #ifdef CONFIG_MAC80211_HT_DEBUG
  181. printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
  182. #endif
  183. ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
  184. spin_unlock_bh(&sta->lock);
  185. }
  186. static inline int ieee80211_ac_from_tid(int tid)
  187. {
  188. return ieee802_1d_to_ac[tid & 7];
  189. }
  190. /*
  191. * When multiple aggregation sessions on multiple stations
  192. * are being created/destroyed simultaneously, we need to
  193. * refcount the global queue stop caused by that in order
  194. * to not get into a situation where one of the aggregation
  195. * setup or teardown re-enables queues before the other is
  196. * ready to handle that.
  197. *
  198. * These two functions take care of this issue by keeping
  199. * a global "agg_queue_stop" refcount.
  200. */
  201. static void __acquires(agg_queue)
  202. ieee80211_stop_queue_agg(struct ieee80211_local *local, int tid)
  203. {
  204. int queue = ieee80211_ac_from_tid(tid);
  205. if (atomic_inc_return(&local->agg_queue_stop[queue]) == 1)
  206. ieee80211_stop_queue_by_reason(
  207. &local->hw, queue,
  208. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  209. __acquire(agg_queue);
  210. }
  211. static void __releases(agg_queue)
  212. ieee80211_wake_queue_agg(struct ieee80211_local *local, int tid)
  213. {
  214. int queue = ieee80211_ac_from_tid(tid);
  215. if (atomic_dec_return(&local->agg_queue_stop[queue]) == 0)
  216. ieee80211_wake_queue_by_reason(
  217. &local->hw, queue,
  218. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  219. __release(agg_queue);
  220. }
  221. int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid)
  222. {
  223. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  224. struct ieee80211_sub_if_data *sdata = sta->sdata;
  225. struct ieee80211_local *local = sdata->local;
  226. struct tid_ampdu_tx *tid_tx;
  227. int ret = 0;
  228. u16 start_seq_num;
  229. trace_api_start_tx_ba_session(pubsta, tid);
  230. if (WARN_ON(!local->ops->ampdu_action))
  231. return -EINVAL;
  232. if ((tid >= STA_TID_NUM) ||
  233. !(local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION))
  234. return -EINVAL;
  235. #ifdef CONFIG_MAC80211_HT_DEBUG
  236. printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
  237. pubsta->addr, tid);
  238. #endif /* CONFIG_MAC80211_HT_DEBUG */
  239. /*
  240. * The aggregation code is not prepared to handle
  241. * anything but STA/AP due to the BSSID handling.
  242. * IBSS could work in the code but isn't supported
  243. * by drivers or the standard.
  244. */
  245. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  246. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  247. sdata->vif.type != NL80211_IFTYPE_AP)
  248. return -EINVAL;
  249. if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) {
  250. #ifdef CONFIG_MAC80211_HT_DEBUG
  251. printk(KERN_DEBUG "BA sessions blocked. "
  252. "Denying BA session request\n");
  253. #endif
  254. return -EINVAL;
  255. }
  256. spin_lock_bh(&sta->lock);
  257. /* we have tried too many times, receiver does not want A-MPDU */
  258. if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
  259. ret = -EBUSY;
  260. goto err_unlock_sta;
  261. }
  262. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  263. /* check if the TID is not in aggregation flow already */
  264. if (tid_tx) {
  265. #ifdef CONFIG_MAC80211_HT_DEBUG
  266. printk(KERN_DEBUG "BA request denied - session is not "
  267. "idle on tid %u\n", tid);
  268. #endif /* CONFIG_MAC80211_HT_DEBUG */
  269. ret = -EAGAIN;
  270. goto err_unlock_sta;
  271. }
  272. /*
  273. * While we're asking the driver about the aggregation,
  274. * stop the AC queue so that we don't have to worry
  275. * about frames that came in while we were doing that,
  276. * which would require us to put them to the AC pending
  277. * afterwards which just makes the code more complex.
  278. */
  279. ieee80211_stop_queue_agg(local, tid);
  280. /* prepare A-MPDU MLME for Tx aggregation */
  281. tid_tx = kzalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
  282. if (!tid_tx) {
  283. #ifdef CONFIG_MAC80211_HT_DEBUG
  284. if (net_ratelimit())
  285. printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
  286. tid);
  287. #endif
  288. ret = -ENOMEM;
  289. goto err_wake_queue;
  290. }
  291. skb_queue_head_init(&tid_tx->pending);
  292. /* Tx timer */
  293. tid_tx->addba_resp_timer.function = sta_addba_resp_timer_expired;
  294. tid_tx->addba_resp_timer.data = (unsigned long)&sta->timer_to_tid[tid];
  295. init_timer(&tid_tx->addba_resp_timer);
  296. start_seq_num = sta->tid_seq[tid] >> 4;
  297. ret = drv_ampdu_action(local, sdata, IEEE80211_AMPDU_TX_START,
  298. pubsta, tid, &start_seq_num);
  299. if (ret) {
  300. #ifdef CONFIG_MAC80211_HT_DEBUG
  301. printk(KERN_DEBUG "BA request denied - HW unavailable for"
  302. " tid %d\n", tid);
  303. #endif /* CONFIG_MAC80211_HT_DEBUG */
  304. goto err_free;
  305. }
  306. rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], tid_tx);
  307. /* Driver vetoed or OKed, but we can take packets again now */
  308. ieee80211_wake_queue_agg(local, tid);
  309. /* activate the timer for the recipient's addBA response */
  310. tid_tx->addba_resp_timer.expires = jiffies + ADDBA_RESP_INTERVAL;
  311. add_timer(&tid_tx->addba_resp_timer);
  312. #ifdef CONFIG_MAC80211_HT_DEBUG
  313. printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
  314. #endif
  315. /* prepare tid data */
  316. sta->ampdu_mlme.dialog_token_allocator++;
  317. tid_tx->dialog_token = sta->ampdu_mlme.dialog_token_allocator;
  318. tid_tx->ssn = start_seq_num;
  319. sta->ampdu_mlme.addba_req_num[tid]++;
  320. spin_unlock_bh(&sta->lock);
  321. /* send AddBA request */
  322. ieee80211_send_addba_request(sdata, pubsta->addr, tid,
  323. tid_tx->dialog_token, tid_tx->ssn,
  324. 0x40, 5000);
  325. return 0;
  326. err_free:
  327. kfree(tid_tx);
  328. err_wake_queue:
  329. ieee80211_wake_queue_agg(local, tid);
  330. err_unlock_sta:
  331. spin_unlock_bh(&sta->lock);
  332. return ret;
  333. }
  334. EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
  335. /*
  336. * splice packets from the STA's pending to the local pending,
  337. * requires a call to ieee80211_agg_splice_finish later
  338. */
  339. static void __acquires(agg_queue)
  340. ieee80211_agg_splice_packets(struct ieee80211_local *local,
  341. struct tid_ampdu_tx *tid_tx, u16 tid)
  342. {
  343. int queue = ieee80211_ac_from_tid(tid);
  344. unsigned long flags;
  345. ieee80211_stop_queue_agg(local, tid);
  346. if (WARN(!tid_tx, "TID %d gone but expected when splicing aggregates"
  347. " from the pending queue\n", tid))
  348. return;
  349. if (!skb_queue_empty(&tid_tx->pending)) {
  350. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  351. /* copy over remaining packets */
  352. skb_queue_splice_tail_init(&tid_tx->pending,
  353. &local->pending[queue]);
  354. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  355. }
  356. }
  357. static void __releases(agg_queue)
  358. ieee80211_agg_splice_finish(struct ieee80211_local *local, u16 tid)
  359. {
  360. ieee80211_wake_queue_agg(local, tid);
  361. }
  362. /* caller must hold sta->lock */
  363. static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
  364. struct sta_info *sta, u16 tid)
  365. {
  366. lockdep_assert_held(&sta->lock);
  367. #ifdef CONFIG_MAC80211_HT_DEBUG
  368. printk(KERN_DEBUG "Aggregation is on for tid %d\n", tid);
  369. #endif
  370. ieee80211_agg_splice_packets(local, sta->ampdu_mlme.tid_tx[tid], tid);
  371. /*
  372. * Now mark as operational. This will be visible
  373. * in the TX path, and lets it go lock-free in
  374. * the common case.
  375. */
  376. set_bit(HT_AGG_STATE_OPERATIONAL, &sta->ampdu_mlme.tid_tx[tid]->state);
  377. ieee80211_agg_splice_finish(local, tid);
  378. drv_ampdu_action(local, sta->sdata,
  379. IEEE80211_AMPDU_TX_OPERATIONAL,
  380. &sta->sta, tid, NULL);
  381. }
  382. void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
  383. {
  384. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  385. struct ieee80211_local *local = sdata->local;
  386. struct sta_info *sta;
  387. struct tid_ampdu_tx *tid_tx;
  388. trace_api_start_tx_ba_cb(sdata, ra, tid);
  389. if (tid >= STA_TID_NUM) {
  390. #ifdef CONFIG_MAC80211_HT_DEBUG
  391. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  392. tid, STA_TID_NUM);
  393. #endif
  394. return;
  395. }
  396. rcu_read_lock();
  397. sta = sta_info_get(sdata, ra);
  398. if (!sta) {
  399. rcu_read_unlock();
  400. #ifdef CONFIG_MAC80211_HT_DEBUG
  401. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  402. #endif
  403. return;
  404. }
  405. spin_lock_bh(&sta->lock);
  406. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  407. if (WARN_ON(!tid_tx)) {
  408. #ifdef CONFIG_MAC80211_HT_DEBUG
  409. printk(KERN_DEBUG "addBA was not requested!\n");
  410. #endif
  411. spin_unlock_bh(&sta->lock);
  412. rcu_read_unlock();
  413. return;
  414. }
  415. if (WARN_ON(test_and_set_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state)))
  416. goto out;
  417. if (test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state))
  418. ieee80211_agg_tx_operational(local, sta, tid);
  419. out:
  420. spin_unlock_bh(&sta->lock);
  421. rcu_read_unlock();
  422. }
  423. void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
  424. const u8 *ra, u16 tid)
  425. {
  426. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  427. struct ieee80211_local *local = sdata->local;
  428. struct ieee80211_ra_tid *ra_tid;
  429. struct sk_buff *skb = dev_alloc_skb(0);
  430. if (unlikely(!skb)) {
  431. #ifdef CONFIG_MAC80211_HT_DEBUG
  432. if (net_ratelimit())
  433. printk(KERN_WARNING "%s: Not enough memory, "
  434. "dropping start BA session", sdata->name);
  435. #endif
  436. return;
  437. }
  438. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  439. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  440. ra_tid->tid = tid;
  441. skb->pkt_type = IEEE80211_SDATA_QUEUE_AGG_START;
  442. skb_queue_tail(&sdata->skb_queue, skb);
  443. ieee80211_queue_work(&local->hw, &sdata->work);
  444. }
  445. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
  446. int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
  447. enum ieee80211_back_parties initiator)
  448. {
  449. struct tid_ampdu_tx *tid_tx;
  450. int ret;
  451. spin_lock_bh(&sta->lock);
  452. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  453. /* check if the TID is in aggregation */
  454. if (!tid_tx || !test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
  455. ret = -ENOENT;
  456. goto unlock;
  457. }
  458. ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator);
  459. unlock:
  460. spin_unlock_bh(&sta->lock);
  461. return ret;
  462. }
  463. int ieee80211_stop_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid)
  464. {
  465. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  466. struct ieee80211_sub_if_data *sdata = sta->sdata;
  467. struct ieee80211_local *local = sdata->local;
  468. trace_api_stop_tx_ba_session(pubsta, tid);
  469. if (!local->ops->ampdu_action)
  470. return -EINVAL;
  471. if (tid >= STA_TID_NUM)
  472. return -EINVAL;
  473. return __ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
  474. }
  475. EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
  476. void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
  477. {
  478. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  479. struct ieee80211_local *local = sdata->local;
  480. struct sta_info *sta;
  481. struct tid_ampdu_tx *tid_tx;
  482. trace_api_stop_tx_ba_cb(sdata, ra, tid);
  483. if (tid >= STA_TID_NUM) {
  484. #ifdef CONFIG_MAC80211_HT_DEBUG
  485. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  486. tid, STA_TID_NUM);
  487. #endif
  488. return;
  489. }
  490. #ifdef CONFIG_MAC80211_HT_DEBUG
  491. printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
  492. ra, tid);
  493. #endif /* CONFIG_MAC80211_HT_DEBUG */
  494. rcu_read_lock();
  495. sta = sta_info_get(sdata, ra);
  496. if (!sta) {
  497. #ifdef CONFIG_MAC80211_HT_DEBUG
  498. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  499. #endif
  500. rcu_read_unlock();
  501. return;
  502. }
  503. spin_lock_bh(&sta->lock);
  504. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  505. if (!tid_tx || !test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
  506. #ifdef CONFIG_MAC80211_HT_DEBUG
  507. printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
  508. #endif
  509. spin_unlock_bh(&sta->lock);
  510. rcu_read_unlock();
  511. return;
  512. }
  513. if (tid_tx->stop_initiator == WLAN_BACK_INITIATOR)
  514. ieee80211_send_delba(sta->sdata, ra, tid,
  515. WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
  516. /*
  517. * When we get here, the TX path will not be lockless any more wrt.
  518. * aggregation, since the OPERATIONAL bit has long been cleared.
  519. * Thus it will block on getting the lock, if it occurs. So if we
  520. * stop the queue now, we will not get any more packets, and any
  521. * that might be being processed will wait for us here, thereby
  522. * guaranteeing that no packets go to the tid_tx pending queue any
  523. * more.
  524. */
  525. ieee80211_agg_splice_packets(local, tid_tx, tid);
  526. /* future packets must not find the tid_tx struct any more */
  527. rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], NULL);
  528. ieee80211_agg_splice_finish(local, tid);
  529. call_rcu(&tid_tx->rcu_head, kfree_tid_tx);
  530. spin_unlock_bh(&sta->lock);
  531. rcu_read_unlock();
  532. }
  533. void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
  534. const u8 *ra, u16 tid)
  535. {
  536. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  537. struct ieee80211_local *local = sdata->local;
  538. struct ieee80211_ra_tid *ra_tid;
  539. struct sk_buff *skb = dev_alloc_skb(0);
  540. if (unlikely(!skb)) {
  541. #ifdef CONFIG_MAC80211_HT_DEBUG
  542. if (net_ratelimit())
  543. printk(KERN_WARNING "%s: Not enough memory, "
  544. "dropping stop BA session", sdata->name);
  545. #endif
  546. return;
  547. }
  548. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  549. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  550. ra_tid->tid = tid;
  551. skb->pkt_type = IEEE80211_SDATA_QUEUE_AGG_STOP;
  552. skb_queue_tail(&sdata->skb_queue, skb);
  553. ieee80211_queue_work(&local->hw, &sdata->work);
  554. }
  555. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
  556. void ieee80211_process_addba_resp(struct ieee80211_local *local,
  557. struct sta_info *sta,
  558. struct ieee80211_mgmt *mgmt,
  559. size_t len)
  560. {
  561. struct tid_ampdu_tx *tid_tx;
  562. u16 capab, tid;
  563. capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
  564. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  565. spin_lock_bh(&sta->lock);
  566. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  567. if (!tid_tx)
  568. goto out;
  569. if (mgmt->u.action.u.addba_resp.dialog_token != tid_tx->dialog_token) {
  570. #ifdef CONFIG_MAC80211_HT_DEBUG
  571. printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
  572. #endif
  573. goto out;
  574. }
  575. del_timer(&tid_tx->addba_resp_timer);
  576. #ifdef CONFIG_MAC80211_HT_DEBUG
  577. printk(KERN_DEBUG "switched off addBA timer for tid %d\n", tid);
  578. #endif
  579. if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
  580. == WLAN_STATUS_SUCCESS) {
  581. if (test_and_set_bit(HT_AGG_STATE_RESPONSE_RECEIVED,
  582. &tid_tx->state)) {
  583. /* ignore duplicate response */
  584. goto out;
  585. }
  586. if (test_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state))
  587. ieee80211_agg_tx_operational(local, sta, tid);
  588. sta->ampdu_mlme.addba_req_num[tid] = 0;
  589. } else {
  590. ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
  591. }
  592. out:
  593. spin_unlock_bh(&sta->lock);
  594. }