agg-tx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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-2010, 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. int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
  119. enum ieee80211_back_parties initiator)
  120. {
  121. struct ieee80211_local *local = sta->local;
  122. struct tid_ampdu_tx *tid_tx = sta->ampdu_mlme.tid_tx[tid];
  123. int ret;
  124. lockdep_assert_held(&sta->ampdu_mlme.mtx);
  125. if (!tid_tx)
  126. return -ENOENT;
  127. spin_lock_bh(&sta->lock);
  128. if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
  129. /* not even started yet! */
  130. rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], NULL);
  131. spin_unlock_bh(&sta->lock);
  132. call_rcu(&tid_tx->rcu_head, kfree_tid_tx);
  133. return 0;
  134. }
  135. spin_unlock_bh(&sta->lock);
  136. #ifdef CONFIG_MAC80211_HT_DEBUG
  137. printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
  138. sta->sta.addr, tid);
  139. #endif /* CONFIG_MAC80211_HT_DEBUG */
  140. set_bit(HT_AGG_STATE_STOPPING, &tid_tx->state);
  141. /*
  142. * After this packets are no longer handed right through
  143. * to the driver but are put onto tid_tx->pending instead,
  144. * with locking to ensure proper access.
  145. */
  146. clear_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state);
  147. tid_tx->stop_initiator = initiator;
  148. ret = drv_ampdu_action(local, sta->sdata,
  149. IEEE80211_AMPDU_TX_STOP,
  150. &sta->sta, tid, NULL);
  151. /* HW shall not deny going back to legacy */
  152. if (WARN_ON(ret)) {
  153. /*
  154. * We may have pending packets get stuck in this case...
  155. * Not bothering with a workaround for now.
  156. */
  157. }
  158. return ret;
  159. }
  160. /*
  161. * After sending add Block Ack request we activated a timer until
  162. * add Block Ack response will arrive from the recipient.
  163. * If this timer expires sta_addba_resp_timer_expired will be executed.
  164. */
  165. static void sta_addba_resp_timer_expired(unsigned long data)
  166. {
  167. /* not an elegant detour, but there is no choice as the timer passes
  168. * only one argument, and both sta_info and TID are needed, so init
  169. * flow in sta_info_create gives the TID as data, while the timer_to_id
  170. * array gives the sta through container_of */
  171. u16 tid = *(u8 *)data;
  172. struct sta_info *sta = container_of((void *)data,
  173. struct sta_info, timer_to_tid[tid]);
  174. struct tid_ampdu_tx *tid_tx;
  175. /* check if the TID waits for addBA response */
  176. rcu_read_lock();
  177. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  178. if (!tid_tx ||
  179. test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state)) {
  180. rcu_read_unlock();
  181. #ifdef CONFIG_MAC80211_HT_DEBUG
  182. printk(KERN_DEBUG "timer expired on tid %d but we are not "
  183. "(or no longer) expecting addBA response there\n",
  184. tid);
  185. #endif
  186. return;
  187. }
  188. #ifdef CONFIG_MAC80211_HT_DEBUG
  189. printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
  190. #endif
  191. ieee80211_stop_tx_ba_session(&sta->sta, tid);
  192. rcu_read_unlock();
  193. }
  194. static inline int ieee80211_ac_from_tid(int tid)
  195. {
  196. return ieee802_1d_to_ac[tid & 7];
  197. }
  198. /*
  199. * When multiple aggregation sessions on multiple stations
  200. * are being created/destroyed simultaneously, we need to
  201. * refcount the global queue stop caused by that in order
  202. * to not get into a situation where one of the aggregation
  203. * setup or teardown re-enables queues before the other is
  204. * ready to handle that.
  205. *
  206. * These two functions take care of this issue by keeping
  207. * a global "agg_queue_stop" refcount.
  208. */
  209. static void __acquires(agg_queue)
  210. ieee80211_stop_queue_agg(struct ieee80211_local *local, int tid)
  211. {
  212. int queue = ieee80211_ac_from_tid(tid);
  213. if (atomic_inc_return(&local->agg_queue_stop[queue]) == 1)
  214. ieee80211_stop_queue_by_reason(
  215. &local->hw, queue,
  216. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  217. __acquire(agg_queue);
  218. }
  219. static void __releases(agg_queue)
  220. ieee80211_wake_queue_agg(struct ieee80211_local *local, int tid)
  221. {
  222. int queue = ieee80211_ac_from_tid(tid);
  223. if (atomic_dec_return(&local->agg_queue_stop[queue]) == 0)
  224. ieee80211_wake_queue_by_reason(
  225. &local->hw, queue,
  226. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  227. __release(agg_queue);
  228. }
  229. void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
  230. {
  231. struct tid_ampdu_tx *tid_tx = sta->ampdu_mlme.tid_tx[tid];
  232. struct ieee80211_local *local = sta->local;
  233. struct ieee80211_sub_if_data *sdata = sta->sdata;
  234. u16 start_seq_num;
  235. int ret;
  236. lockdep_assert_held(&sta->ampdu_mlme.mtx);
  237. /*
  238. * While we're asking the driver about the aggregation,
  239. * stop the AC queue so that we don't have to worry
  240. * about frames that came in while we were doing that,
  241. * which would require us to put them to the AC pending
  242. * afterwards which just makes the code more complex.
  243. */
  244. ieee80211_stop_queue_agg(local, tid);
  245. clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
  246. /*
  247. * make sure no packets are being processed to get
  248. * valid starting sequence number
  249. */
  250. synchronize_net();
  251. start_seq_num = sta->tid_seq[tid] >> 4;
  252. ret = drv_ampdu_action(local, sdata, IEEE80211_AMPDU_TX_START,
  253. &sta->sta, tid, &start_seq_num);
  254. if (ret) {
  255. #ifdef CONFIG_MAC80211_HT_DEBUG
  256. printk(KERN_DEBUG "BA request denied - HW unavailable for"
  257. " tid %d\n", tid);
  258. #endif
  259. spin_lock_bh(&sta->lock);
  260. rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], NULL);
  261. spin_unlock_bh(&sta->lock);
  262. ieee80211_wake_queue_agg(local, tid);
  263. call_rcu(&tid_tx->rcu_head, kfree_tid_tx);
  264. return;
  265. }
  266. /* we can take packets again now */
  267. ieee80211_wake_queue_agg(local, tid);
  268. /* activate the timer for the recipient's addBA response */
  269. mod_timer(&tid_tx->addba_resp_timer, jiffies + ADDBA_RESP_INTERVAL);
  270. #ifdef CONFIG_MAC80211_HT_DEBUG
  271. printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
  272. #endif
  273. spin_lock_bh(&sta->lock);
  274. sta->ampdu_mlme.addba_req_num[tid]++;
  275. spin_unlock_bh(&sta->lock);
  276. /* send AddBA request */
  277. ieee80211_send_addba_request(sdata, sta->sta.addr, tid,
  278. tid_tx->dialog_token, start_seq_num,
  279. 0x40, 5000);
  280. }
  281. int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid)
  282. {
  283. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  284. struct ieee80211_sub_if_data *sdata = sta->sdata;
  285. struct ieee80211_local *local = sdata->local;
  286. struct tid_ampdu_tx *tid_tx;
  287. int ret = 0;
  288. trace_api_start_tx_ba_session(pubsta, tid);
  289. if (WARN_ON(!local->ops->ampdu_action))
  290. return -EINVAL;
  291. if ((tid >= STA_TID_NUM) ||
  292. !(local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION))
  293. return -EINVAL;
  294. #ifdef CONFIG_MAC80211_HT_DEBUG
  295. printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
  296. pubsta->addr, tid);
  297. #endif /* CONFIG_MAC80211_HT_DEBUG */
  298. /*
  299. * The aggregation code is not prepared to handle
  300. * anything but STA/AP due to the BSSID handling.
  301. * IBSS could work in the code but isn't supported
  302. * by drivers or the standard.
  303. */
  304. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  305. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  306. sdata->vif.type != NL80211_IFTYPE_AP)
  307. return -EINVAL;
  308. if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) {
  309. #ifdef CONFIG_MAC80211_HT_DEBUG
  310. printk(KERN_DEBUG "BA sessions blocked. "
  311. "Denying BA session request\n");
  312. #endif
  313. return -EINVAL;
  314. }
  315. spin_lock_bh(&sta->lock);
  316. /* we have tried too many times, receiver does not want A-MPDU */
  317. if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
  318. ret = -EBUSY;
  319. goto err_unlock_sta;
  320. }
  321. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  322. /* check if the TID is not in aggregation flow already */
  323. if (tid_tx) {
  324. #ifdef CONFIG_MAC80211_HT_DEBUG
  325. printk(KERN_DEBUG "BA request denied - session is not "
  326. "idle on tid %u\n", tid);
  327. #endif /* CONFIG_MAC80211_HT_DEBUG */
  328. ret = -EAGAIN;
  329. goto err_unlock_sta;
  330. }
  331. /* prepare A-MPDU MLME for Tx aggregation */
  332. tid_tx = kzalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
  333. if (!tid_tx) {
  334. #ifdef CONFIG_MAC80211_HT_DEBUG
  335. if (net_ratelimit())
  336. printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
  337. tid);
  338. #endif
  339. ret = -ENOMEM;
  340. goto err_unlock_sta;
  341. }
  342. skb_queue_head_init(&tid_tx->pending);
  343. __set_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
  344. /* Tx timer */
  345. tid_tx->addba_resp_timer.function = sta_addba_resp_timer_expired;
  346. tid_tx->addba_resp_timer.data = (unsigned long)&sta->timer_to_tid[tid];
  347. init_timer(&tid_tx->addba_resp_timer);
  348. /* assign a dialog token */
  349. sta->ampdu_mlme.dialog_token_allocator++;
  350. tid_tx->dialog_token = sta->ampdu_mlme.dialog_token_allocator;
  351. /* finally, assign it to the array */
  352. rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], tid_tx);
  353. ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
  354. /* this flow continues off the work */
  355. err_unlock_sta:
  356. spin_unlock_bh(&sta->lock);
  357. return ret;
  358. }
  359. EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
  360. /*
  361. * splice packets from the STA's pending to the local pending,
  362. * requires a call to ieee80211_agg_splice_finish later
  363. */
  364. static void __acquires(agg_queue)
  365. ieee80211_agg_splice_packets(struct ieee80211_local *local,
  366. struct tid_ampdu_tx *tid_tx, u16 tid)
  367. {
  368. int queue = ieee80211_ac_from_tid(tid);
  369. unsigned long flags;
  370. ieee80211_stop_queue_agg(local, tid);
  371. if (WARN(!tid_tx, "TID %d gone but expected when splicing aggregates"
  372. " from the pending queue\n", tid))
  373. return;
  374. if (!skb_queue_empty(&tid_tx->pending)) {
  375. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  376. /* copy over remaining packets */
  377. skb_queue_splice_tail_init(&tid_tx->pending,
  378. &local->pending[queue]);
  379. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  380. }
  381. }
  382. static void __releases(agg_queue)
  383. ieee80211_agg_splice_finish(struct ieee80211_local *local, u16 tid)
  384. {
  385. ieee80211_wake_queue_agg(local, tid);
  386. }
  387. static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
  388. struct sta_info *sta, u16 tid)
  389. {
  390. lockdep_assert_held(&sta->ampdu_mlme.mtx);
  391. #ifdef CONFIG_MAC80211_HT_DEBUG
  392. printk(KERN_DEBUG "Aggregation is on for tid %d\n", tid);
  393. #endif
  394. drv_ampdu_action(local, sta->sdata,
  395. IEEE80211_AMPDU_TX_OPERATIONAL,
  396. &sta->sta, tid, NULL);
  397. /*
  398. * synchronize with TX path, while splicing the TX path
  399. * should block so it won't put more packets onto pending.
  400. */
  401. spin_lock_bh(&sta->lock);
  402. ieee80211_agg_splice_packets(local, sta->ampdu_mlme.tid_tx[tid], tid);
  403. /*
  404. * Now mark as operational. This will be visible
  405. * in the TX path, and lets it go lock-free in
  406. * the common case.
  407. */
  408. set_bit(HT_AGG_STATE_OPERATIONAL, &sta->ampdu_mlme.tid_tx[tid]->state);
  409. ieee80211_agg_splice_finish(local, tid);
  410. spin_unlock_bh(&sta->lock);
  411. }
  412. void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
  413. {
  414. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  415. struct ieee80211_local *local = sdata->local;
  416. struct sta_info *sta;
  417. struct tid_ampdu_tx *tid_tx;
  418. trace_api_start_tx_ba_cb(sdata, ra, tid);
  419. if (tid >= STA_TID_NUM) {
  420. #ifdef CONFIG_MAC80211_HT_DEBUG
  421. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  422. tid, STA_TID_NUM);
  423. #endif
  424. return;
  425. }
  426. mutex_lock(&local->sta_mtx);
  427. sta = sta_info_get(sdata, ra);
  428. if (!sta) {
  429. mutex_unlock(&local->sta_mtx);
  430. #ifdef CONFIG_MAC80211_HT_DEBUG
  431. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  432. #endif
  433. return;
  434. }
  435. mutex_lock(&sta->ampdu_mlme.mtx);
  436. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  437. if (WARN_ON(!tid_tx)) {
  438. #ifdef CONFIG_MAC80211_HT_DEBUG
  439. printk(KERN_DEBUG "addBA was not requested!\n");
  440. #endif
  441. goto unlock;
  442. }
  443. if (WARN_ON(test_and_set_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state)))
  444. goto unlock;
  445. if (test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state))
  446. ieee80211_agg_tx_operational(local, sta, tid);
  447. unlock:
  448. mutex_unlock(&sta->ampdu_mlme.mtx);
  449. mutex_unlock(&local->sta_mtx);
  450. }
  451. void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
  452. const u8 *ra, u16 tid)
  453. {
  454. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  455. struct ieee80211_local *local = sdata->local;
  456. struct ieee80211_ra_tid *ra_tid;
  457. struct sk_buff *skb = dev_alloc_skb(0);
  458. if (unlikely(!skb)) {
  459. #ifdef CONFIG_MAC80211_HT_DEBUG
  460. if (net_ratelimit())
  461. printk(KERN_WARNING "%s: Not enough memory, "
  462. "dropping start BA session", sdata->name);
  463. #endif
  464. return;
  465. }
  466. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  467. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  468. ra_tid->tid = tid;
  469. skb->pkt_type = IEEE80211_SDATA_QUEUE_AGG_START;
  470. skb_queue_tail(&sdata->skb_queue, skb);
  471. ieee80211_queue_work(&local->hw, &sdata->work);
  472. }
  473. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
  474. int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
  475. enum ieee80211_back_parties initiator)
  476. {
  477. int ret;
  478. mutex_lock(&sta->ampdu_mlme.mtx);
  479. ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator);
  480. mutex_unlock(&sta->ampdu_mlme.mtx);
  481. return ret;
  482. }
  483. int ieee80211_stop_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid)
  484. {
  485. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  486. struct ieee80211_sub_if_data *sdata = sta->sdata;
  487. struct ieee80211_local *local = sdata->local;
  488. struct tid_ampdu_tx *tid_tx;
  489. int ret = 0;
  490. trace_api_stop_tx_ba_session(pubsta, tid);
  491. if (!local->ops->ampdu_action)
  492. return -EINVAL;
  493. if (tid >= STA_TID_NUM)
  494. return -EINVAL;
  495. spin_lock_bh(&sta->lock);
  496. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  497. if (!tid_tx) {
  498. ret = -ENOENT;
  499. goto unlock;
  500. }
  501. if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
  502. /* already in progress stopping it */
  503. ret = 0;
  504. goto unlock;
  505. }
  506. set_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state);
  507. ieee80211_queue_work(&local->hw, &sta->ampdu_mlme.work);
  508. unlock:
  509. spin_unlock_bh(&sta->lock);
  510. return ret;
  511. }
  512. EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
  513. void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
  514. {
  515. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  516. struct ieee80211_local *local = sdata->local;
  517. struct sta_info *sta;
  518. struct tid_ampdu_tx *tid_tx;
  519. trace_api_stop_tx_ba_cb(sdata, ra, tid);
  520. if (tid >= STA_TID_NUM) {
  521. #ifdef CONFIG_MAC80211_HT_DEBUG
  522. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  523. tid, STA_TID_NUM);
  524. #endif
  525. return;
  526. }
  527. #ifdef CONFIG_MAC80211_HT_DEBUG
  528. printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
  529. ra, tid);
  530. #endif /* CONFIG_MAC80211_HT_DEBUG */
  531. mutex_lock(&local->sta_mtx);
  532. sta = sta_info_get(sdata, ra);
  533. if (!sta) {
  534. #ifdef CONFIG_MAC80211_HT_DEBUG
  535. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  536. #endif
  537. goto unlock;
  538. }
  539. mutex_lock(&sta->ampdu_mlme.mtx);
  540. spin_lock_bh(&sta->lock);
  541. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  542. if (!tid_tx || !test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
  543. #ifdef CONFIG_MAC80211_HT_DEBUG
  544. printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
  545. #endif
  546. goto unlock_sta;
  547. }
  548. if (tid_tx->stop_initiator == WLAN_BACK_INITIATOR)
  549. ieee80211_send_delba(sta->sdata, ra, tid,
  550. WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
  551. /*
  552. * When we get here, the TX path will not be lockless any more wrt.
  553. * aggregation, since the OPERATIONAL bit has long been cleared.
  554. * Thus it will block on getting the lock, if it occurs. So if we
  555. * stop the queue now, we will not get any more packets, and any
  556. * that might be being processed will wait for us here, thereby
  557. * guaranteeing that no packets go to the tid_tx pending queue any
  558. * more.
  559. */
  560. ieee80211_agg_splice_packets(local, tid_tx, tid);
  561. /* future packets must not find the tid_tx struct any more */
  562. rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], NULL);
  563. ieee80211_agg_splice_finish(local, tid);
  564. call_rcu(&tid_tx->rcu_head, kfree_tid_tx);
  565. unlock_sta:
  566. spin_unlock_bh(&sta->lock);
  567. mutex_unlock(&sta->ampdu_mlme.mtx);
  568. unlock:
  569. mutex_unlock(&local->sta_mtx);
  570. }
  571. void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
  572. const u8 *ra, u16 tid)
  573. {
  574. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  575. struct ieee80211_local *local = sdata->local;
  576. struct ieee80211_ra_tid *ra_tid;
  577. struct sk_buff *skb = dev_alloc_skb(0);
  578. if (unlikely(!skb)) {
  579. #ifdef CONFIG_MAC80211_HT_DEBUG
  580. if (net_ratelimit())
  581. printk(KERN_WARNING "%s: Not enough memory, "
  582. "dropping stop BA session", sdata->name);
  583. #endif
  584. return;
  585. }
  586. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  587. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  588. ra_tid->tid = tid;
  589. skb->pkt_type = IEEE80211_SDATA_QUEUE_AGG_STOP;
  590. skb_queue_tail(&sdata->skb_queue, skb);
  591. ieee80211_queue_work(&local->hw, &sdata->work);
  592. }
  593. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
  594. void ieee80211_process_addba_resp(struct ieee80211_local *local,
  595. struct sta_info *sta,
  596. struct ieee80211_mgmt *mgmt,
  597. size_t len)
  598. {
  599. struct tid_ampdu_tx *tid_tx;
  600. u16 capab, tid;
  601. capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
  602. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  603. mutex_lock(&sta->ampdu_mlme.mtx);
  604. tid_tx = sta->ampdu_mlme.tid_tx[tid];
  605. if (!tid_tx)
  606. goto out;
  607. if (mgmt->u.action.u.addba_resp.dialog_token != tid_tx->dialog_token) {
  608. #ifdef CONFIG_MAC80211_HT_DEBUG
  609. printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
  610. #endif
  611. goto out;
  612. }
  613. del_timer(&tid_tx->addba_resp_timer);
  614. #ifdef CONFIG_MAC80211_HT_DEBUG
  615. printk(KERN_DEBUG "switched off addBA timer for tid %d\n", tid);
  616. #endif
  617. if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
  618. == WLAN_STATUS_SUCCESS) {
  619. if (test_and_set_bit(HT_AGG_STATE_RESPONSE_RECEIVED,
  620. &tid_tx->state)) {
  621. /* ignore duplicate response */
  622. goto out;
  623. }
  624. if (test_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state))
  625. ieee80211_agg_tx_operational(local, sta, tid);
  626. sta->ampdu_mlme.addba_req_num[tid] = 0;
  627. } else {
  628. ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
  629. }
  630. out:
  631. mutex_unlock(&sta->ampdu_mlme.mtx);
  632. }