agg-tx.c 20 KB

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