agg-tx.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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. if (initiator) {
  118. /*
  119. * Stop the AC queue to avoid issues where we send
  120. * unaggregated frames already before the delba.
  121. */
  122. ieee80211_stop_queue_by_reason(&local->hw,
  123. local->hw.queues + sta->tid_to_tx_q[tid],
  124. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  125. }
  126. /*
  127. * Pretend the driver woke the queue, just in case
  128. * it disabled it before the session was stopped.
  129. */
  130. ieee80211_wake_queue(
  131. &local->hw, local->hw.queues + sta->tid_to_tx_q[tid]);
  132. }
  133. *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
  134. (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
  135. ret = local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_STOP,
  136. &sta->sta, tid, NULL);
  137. /* HW shall not deny going back to legacy */
  138. if (WARN_ON(ret)) {
  139. *state = HT_AGG_STATE_OPERATIONAL;
  140. }
  141. return ret;
  142. }
  143. /*
  144. * After sending add Block Ack request we activated a timer until
  145. * add Block Ack response will arrive from the recipient.
  146. * If this timer expires sta_addba_resp_timer_expired will be executed.
  147. */
  148. static void sta_addba_resp_timer_expired(unsigned long data)
  149. {
  150. /* not an elegant detour, but there is no choice as the timer passes
  151. * only one argument, and both sta_info and TID are needed, so init
  152. * flow in sta_info_create gives the TID as data, while the timer_to_id
  153. * array gives the sta through container_of */
  154. u16 tid = *(u8 *)data;
  155. struct sta_info *sta = container_of((void *)data,
  156. struct sta_info, timer_to_tid[tid]);
  157. u8 *state;
  158. state = &sta->ampdu_mlme.tid_state_tx[tid];
  159. /* check if the TID waits for addBA response */
  160. spin_lock_bh(&sta->lock);
  161. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  162. spin_unlock_bh(&sta->lock);
  163. *state = HT_AGG_STATE_IDLE;
  164. #ifdef CONFIG_MAC80211_HT_DEBUG
  165. printk(KERN_DEBUG "timer expired on tid %d but we are not "
  166. "expecting addBA response there", tid);
  167. #endif
  168. return;
  169. }
  170. #ifdef CONFIG_MAC80211_HT_DEBUG
  171. printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
  172. #endif
  173. ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
  174. spin_unlock_bh(&sta->lock);
  175. }
  176. static inline int ieee80211_ac_from_tid(int tid)
  177. {
  178. return ieee802_1d_to_ac[tid & 7];
  179. }
  180. int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  181. {
  182. struct ieee80211_local *local = hw_to_local(hw);
  183. struct sta_info *sta;
  184. struct ieee80211_sub_if_data *sdata;
  185. u8 *state;
  186. int i, qn = -1, ret = 0;
  187. u16 start_seq_num;
  188. if (WARN_ON(!local->ops->ampdu_action))
  189. return -EINVAL;
  190. if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
  191. return -EINVAL;
  192. #ifdef CONFIG_MAC80211_HT_DEBUG
  193. printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
  194. ra, tid);
  195. #endif /* CONFIG_MAC80211_HT_DEBUG */
  196. if (hw->ampdu_queues && ieee80211_ac_from_tid(tid) == 0) {
  197. #ifdef CONFIG_MAC80211_HT_DEBUG
  198. printk(KERN_DEBUG "rejecting on voice AC\n");
  199. #endif
  200. return -EINVAL;
  201. }
  202. rcu_read_lock();
  203. sta = sta_info_get(local, ra);
  204. if (!sta) {
  205. #ifdef CONFIG_MAC80211_HT_DEBUG
  206. printk(KERN_DEBUG "Could not find the station\n");
  207. #endif
  208. ret = -ENOENT;
  209. goto unlock;
  210. }
  211. /*
  212. * The aggregation code is not prepared to handle
  213. * anything but STA/AP due to the BSSID handling.
  214. * IBSS could work in the code but isn't supported
  215. * by drivers or the standard.
  216. */
  217. if (sta->sdata->vif.type != NL80211_IFTYPE_STATION &&
  218. sta->sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  219. sta->sdata->vif.type != NL80211_IFTYPE_AP) {
  220. ret = -EINVAL;
  221. goto unlock;
  222. }
  223. if (test_sta_flags(sta, WLAN_STA_SUSPEND)) {
  224. #ifdef CONFIG_MAC80211_HT_DEBUG
  225. printk(KERN_DEBUG "Suspend in progress. "
  226. "Denying BA session request\n");
  227. #endif
  228. ret = -EINVAL;
  229. goto unlock;
  230. }
  231. spin_lock_bh(&sta->lock);
  232. sdata = sta->sdata;
  233. /* we have tried too many times, receiver does not want A-MPDU */
  234. if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
  235. ret = -EBUSY;
  236. goto err_unlock_sta;
  237. }
  238. state = &sta->ampdu_mlme.tid_state_tx[tid];
  239. /* check if the TID is not in aggregation flow already */
  240. if (*state != HT_AGG_STATE_IDLE) {
  241. #ifdef CONFIG_MAC80211_HT_DEBUG
  242. printk(KERN_DEBUG "BA request denied - session is not "
  243. "idle on tid %u\n", tid);
  244. #endif /* CONFIG_MAC80211_HT_DEBUG */
  245. ret = -EAGAIN;
  246. goto err_unlock_sta;
  247. }
  248. if (hw->ampdu_queues) {
  249. spin_lock(&local->queue_stop_reason_lock);
  250. /* reserve a new queue for this session */
  251. for (i = 0; i < local->hw.ampdu_queues; i++) {
  252. if (local->ampdu_ac_queue[i] < 0) {
  253. qn = i;
  254. local->ampdu_ac_queue[qn] =
  255. ieee80211_ac_from_tid(tid);
  256. break;
  257. }
  258. }
  259. spin_unlock(&local->queue_stop_reason_lock);
  260. if (qn < 0) {
  261. #ifdef CONFIG_MAC80211_HT_DEBUG
  262. printk(KERN_DEBUG "BA request denied - "
  263. "queue unavailable for tid %d\n", tid);
  264. #endif /* CONFIG_MAC80211_HT_DEBUG */
  265. ret = -ENOSPC;
  266. goto err_unlock_sta;
  267. }
  268. /*
  269. * If we successfully allocate the session, we can't have
  270. * anything going on on the queue this TID maps into, so
  271. * stop it for now. This is a "virtual" stop using the same
  272. * mechanism that drivers will use.
  273. *
  274. * XXX: queue up frames for this session in the sta_info
  275. * struct instead to avoid hitting all other STAs.
  276. */
  277. ieee80211_stop_queue_by_reason(
  278. &local->hw, hw->queues + qn,
  279. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  280. }
  281. /* prepare A-MPDU MLME for Tx aggregation */
  282. sta->ampdu_mlme.tid_tx[tid] =
  283. kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
  284. if (!sta->ampdu_mlme.tid_tx[tid]) {
  285. #ifdef CONFIG_MAC80211_HT_DEBUG
  286. if (net_ratelimit())
  287. printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
  288. tid);
  289. #endif
  290. ret = -ENOMEM;
  291. goto err_return_queue;
  292. }
  293. /* Tx timer */
  294. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
  295. sta_addba_resp_timer_expired;
  296. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
  297. (unsigned long)&sta->timer_to_tid[tid];
  298. init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  299. /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
  300. * call back right away, it must see that the flow has begun */
  301. *state |= HT_ADDBA_REQUESTED_MSK;
  302. start_seq_num = sta->tid_seq[tid];
  303. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
  304. &sta->sta, tid, &start_seq_num);
  305. if (ret) {
  306. #ifdef CONFIG_MAC80211_HT_DEBUG
  307. printk(KERN_DEBUG "BA request denied - HW unavailable for"
  308. " tid %d\n", tid);
  309. #endif /* CONFIG_MAC80211_HT_DEBUG */
  310. *state = HT_AGG_STATE_IDLE;
  311. goto err_free;
  312. }
  313. sta->tid_to_tx_q[tid] = qn;
  314. spin_unlock_bh(&sta->lock);
  315. /* send an addBA request */
  316. sta->ampdu_mlme.dialog_token_allocator++;
  317. sta->ampdu_mlme.tid_tx[tid]->dialog_token =
  318. sta->ampdu_mlme.dialog_token_allocator;
  319. sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
  320. ieee80211_send_addba_request(sta->sdata, ra, tid,
  321. sta->ampdu_mlme.tid_tx[tid]->dialog_token,
  322. sta->ampdu_mlme.tid_tx[tid]->ssn,
  323. 0x40, 5000);
  324. /* activate the timer for the recipient's addBA response */
  325. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
  326. jiffies + ADDBA_RESP_INTERVAL;
  327. add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  328. #ifdef CONFIG_MAC80211_HT_DEBUG
  329. printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
  330. #endif
  331. goto unlock;
  332. err_free:
  333. kfree(sta->ampdu_mlme.tid_tx[tid]);
  334. sta->ampdu_mlme.tid_tx[tid] = NULL;
  335. err_return_queue:
  336. if (qn >= 0) {
  337. /* We failed, so start queue again right away. */
  338. ieee80211_wake_queue_by_reason(hw, hw->queues + qn,
  339. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  340. /* give queue back to pool */
  341. spin_lock(&local->queue_stop_reason_lock);
  342. local->ampdu_ac_queue[qn] = -1;
  343. spin_unlock(&local->queue_stop_reason_lock);
  344. }
  345. err_unlock_sta:
  346. spin_unlock_bh(&sta->lock);
  347. unlock:
  348. rcu_read_unlock();
  349. return ret;
  350. }
  351. EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
  352. static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
  353. struct sta_info *sta, u16 tid)
  354. {
  355. #ifdef CONFIG_MAC80211_HT_DEBUG
  356. printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
  357. #endif
  358. if (local->hw.ampdu_queues) {
  359. /*
  360. * Wake up the A-MPDU queue, we stopped it earlier,
  361. * this will in turn wake the entire AC.
  362. */
  363. ieee80211_wake_queue_by_reason(&local->hw,
  364. local->hw.queues + sta->tid_to_tx_q[tid],
  365. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  366. }
  367. local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_OPERATIONAL,
  368. &sta->sta, tid, NULL);
  369. }
  370. void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  371. {
  372. struct ieee80211_local *local = hw_to_local(hw);
  373. struct sta_info *sta;
  374. u8 *state;
  375. if (tid >= STA_TID_NUM) {
  376. #ifdef CONFIG_MAC80211_HT_DEBUG
  377. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  378. tid, STA_TID_NUM);
  379. #endif
  380. return;
  381. }
  382. rcu_read_lock();
  383. sta = sta_info_get(local, ra);
  384. if (!sta) {
  385. rcu_read_unlock();
  386. #ifdef CONFIG_MAC80211_HT_DEBUG
  387. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  388. #endif
  389. return;
  390. }
  391. state = &sta->ampdu_mlme.tid_state_tx[tid];
  392. spin_lock_bh(&sta->lock);
  393. if (WARN_ON(!(*state & HT_ADDBA_REQUESTED_MSK))) {
  394. #ifdef CONFIG_MAC80211_HT_DEBUG
  395. printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
  396. *state);
  397. #endif
  398. spin_unlock_bh(&sta->lock);
  399. rcu_read_unlock();
  400. return;
  401. }
  402. if (WARN_ON(*state & HT_ADDBA_DRV_READY_MSK))
  403. goto out;
  404. *state |= HT_ADDBA_DRV_READY_MSK;
  405. if (*state == HT_AGG_STATE_OPERATIONAL)
  406. ieee80211_agg_tx_operational(local, sta, tid);
  407. out:
  408. spin_unlock_bh(&sta->lock);
  409. rcu_read_unlock();
  410. }
  411. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
  412. void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  413. const u8 *ra, u16 tid)
  414. {
  415. struct ieee80211_local *local = hw_to_local(hw);
  416. struct ieee80211_ra_tid *ra_tid;
  417. struct sk_buff *skb = dev_alloc_skb(0);
  418. if (unlikely(!skb)) {
  419. #ifdef CONFIG_MAC80211_HT_DEBUG
  420. if (net_ratelimit())
  421. printk(KERN_WARNING "%s: Not enough memory, "
  422. "dropping start BA session", skb->dev->name);
  423. #endif
  424. return;
  425. }
  426. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  427. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  428. ra_tid->tid = tid;
  429. skb->pkt_type = IEEE80211_ADDBA_MSG;
  430. skb_queue_tail(&local->skb_queue, skb);
  431. tasklet_schedule(&local->tasklet);
  432. }
  433. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
  434. int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
  435. enum ieee80211_back_parties initiator)
  436. {
  437. u8 *state;
  438. int ret;
  439. /* check if the TID is in aggregation */
  440. state = &sta->ampdu_mlme.tid_state_tx[tid];
  441. spin_lock_bh(&sta->lock);
  442. if (*state != HT_AGG_STATE_OPERATIONAL) {
  443. ret = -ENOENT;
  444. goto unlock;
  445. }
  446. #ifdef CONFIG_MAC80211_HT_DEBUG
  447. printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
  448. sta->sta.addr, tid);
  449. #endif /* CONFIG_MAC80211_HT_DEBUG */
  450. ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator);
  451. unlock:
  452. spin_unlock_bh(&sta->lock);
  453. return ret;
  454. }
  455. int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
  456. u8 *ra, u16 tid,
  457. enum ieee80211_back_parties initiator)
  458. {
  459. struct ieee80211_local *local = hw_to_local(hw);
  460. struct sta_info *sta;
  461. int ret = 0;
  462. if (WARN_ON(!local->ops->ampdu_action))
  463. return -EINVAL;
  464. if (tid >= STA_TID_NUM)
  465. return -EINVAL;
  466. rcu_read_lock();
  467. sta = sta_info_get(local, ra);
  468. if (!sta) {
  469. rcu_read_unlock();
  470. return -ENOENT;
  471. }
  472. ret = __ieee80211_stop_tx_ba_session(sta, tid, initiator);
  473. rcu_read_unlock();
  474. return ret;
  475. }
  476. EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
  477. void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
  478. {
  479. struct ieee80211_local *local = hw_to_local(hw);
  480. struct sta_info *sta;
  481. u8 *state;
  482. if (tid >= STA_TID_NUM) {
  483. #ifdef CONFIG_MAC80211_HT_DEBUG
  484. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  485. tid, STA_TID_NUM);
  486. #endif
  487. return;
  488. }
  489. #ifdef CONFIG_MAC80211_HT_DEBUG
  490. printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
  491. ra, tid);
  492. #endif /* CONFIG_MAC80211_HT_DEBUG */
  493. rcu_read_lock();
  494. sta = sta_info_get(local, ra);
  495. if (!sta) {
  496. #ifdef CONFIG_MAC80211_HT_DEBUG
  497. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  498. #endif
  499. rcu_read_unlock();
  500. return;
  501. }
  502. state = &sta->ampdu_mlme.tid_state_tx[tid];
  503. /* NOTE: no need to use sta->lock in this state check, as
  504. * ieee80211_stop_tx_ba_session will let only one stop call to
  505. * pass through per sta/tid
  506. */
  507. if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
  508. #ifdef CONFIG_MAC80211_HT_DEBUG
  509. printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
  510. #endif
  511. rcu_read_unlock();
  512. return;
  513. }
  514. if (*state & HT_AGG_STATE_INITIATOR_MSK)
  515. ieee80211_send_delba(sta->sdata, ra, tid,
  516. WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
  517. spin_lock_bh(&sta->lock);
  518. if (*state & HT_AGG_STATE_INITIATOR_MSK &&
  519. hw->ampdu_queues) {
  520. /*
  521. * Wake up this queue, we stopped it earlier,
  522. * this will in turn wake the entire AC.
  523. */
  524. ieee80211_wake_queue_by_reason(hw,
  525. hw->queues + sta->tid_to_tx_q[tid],
  526. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  527. }
  528. *state = HT_AGG_STATE_IDLE;
  529. sta->ampdu_mlme.addba_req_num[tid] = 0;
  530. kfree(sta->ampdu_mlme.tid_tx[tid]);
  531. sta->ampdu_mlme.tid_tx[tid] = NULL;
  532. spin_unlock_bh(&sta->lock);
  533. rcu_read_unlock();
  534. }
  535. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
  536. void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  537. const u8 *ra, u16 tid)
  538. {
  539. struct ieee80211_local *local = hw_to_local(hw);
  540. struct ieee80211_ra_tid *ra_tid;
  541. struct sk_buff *skb = dev_alloc_skb(0);
  542. if (unlikely(!skb)) {
  543. #ifdef CONFIG_MAC80211_HT_DEBUG
  544. if (net_ratelimit())
  545. printk(KERN_WARNING "%s: Not enough memory, "
  546. "dropping stop BA session", skb->dev->name);
  547. #endif
  548. return;
  549. }
  550. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  551. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  552. ra_tid->tid = tid;
  553. skb->pkt_type = IEEE80211_DELBA_MSG;
  554. skb_queue_tail(&local->skb_queue, skb);
  555. tasklet_schedule(&local->tasklet);
  556. }
  557. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
  558. void ieee80211_process_addba_resp(struct ieee80211_local *local,
  559. struct sta_info *sta,
  560. struct ieee80211_mgmt *mgmt,
  561. size_t len)
  562. {
  563. u16 capab, tid;
  564. u8 *state;
  565. capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
  566. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  567. state = &sta->ampdu_mlme.tid_state_tx[tid];
  568. spin_lock_bh(&sta->lock);
  569. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  570. spin_unlock_bh(&sta->lock);
  571. return;
  572. }
  573. if (mgmt->u.action.u.addba_resp.dialog_token !=
  574. sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
  575. spin_unlock_bh(&sta->lock);
  576. #ifdef CONFIG_MAC80211_HT_DEBUG
  577. printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
  578. #endif /* CONFIG_MAC80211_HT_DEBUG */
  579. return;
  580. }
  581. del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  582. #ifdef CONFIG_MAC80211_HT_DEBUG
  583. printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
  584. #endif /* CONFIG_MAC80211_HT_DEBUG */
  585. if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
  586. == WLAN_STATUS_SUCCESS) {
  587. u8 curstate = *state;
  588. *state |= HT_ADDBA_RECEIVED_MSK;
  589. if (*state != curstate && *state == HT_AGG_STATE_OPERATIONAL)
  590. ieee80211_agg_tx_operational(local, sta, tid);
  591. sta->ampdu_mlme.addba_req_num[tid] = 0;
  592. } else {
  593. sta->ampdu_mlme.addba_req_num[tid]++;
  594. ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
  595. }
  596. spin_unlock_bh(&sta->lock);
  597. }