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. spin_lock_bh(&sta->lock);
  224. sdata = sta->sdata;
  225. /* we have tried too many times, receiver does not want A-MPDU */
  226. if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
  227. ret = -EBUSY;
  228. goto err_unlock_sta;
  229. }
  230. state = &sta->ampdu_mlme.tid_state_tx[tid];
  231. /* check if the TID is not in aggregation flow already */
  232. if (*state != HT_AGG_STATE_IDLE) {
  233. #ifdef CONFIG_MAC80211_HT_DEBUG
  234. printk(KERN_DEBUG "BA request denied - session is not "
  235. "idle on tid %u\n", tid);
  236. #endif /* CONFIG_MAC80211_HT_DEBUG */
  237. ret = -EAGAIN;
  238. goto err_unlock_sta;
  239. }
  240. if (hw->ampdu_queues) {
  241. spin_lock(&local->queue_stop_reason_lock);
  242. /* reserve a new queue for this session */
  243. for (i = 0; i < local->hw.ampdu_queues; i++) {
  244. if (local->ampdu_ac_queue[i] < 0) {
  245. qn = i;
  246. local->ampdu_ac_queue[qn] =
  247. ieee80211_ac_from_tid(tid);
  248. break;
  249. }
  250. }
  251. spin_unlock(&local->queue_stop_reason_lock);
  252. if (qn < 0) {
  253. #ifdef CONFIG_MAC80211_HT_DEBUG
  254. printk(KERN_DEBUG "BA request denied - "
  255. "queue unavailable for tid %d\n", tid);
  256. #endif /* CONFIG_MAC80211_HT_DEBUG */
  257. ret = -ENOSPC;
  258. goto err_unlock_sta;
  259. }
  260. /*
  261. * If we successfully allocate the session, we can't have
  262. * anything going on on the queue this TID maps into, so
  263. * stop it for now. This is a "virtual" stop using the same
  264. * mechanism that drivers will use.
  265. *
  266. * XXX: queue up frames for this session in the sta_info
  267. * struct instead to avoid hitting all other STAs.
  268. */
  269. ieee80211_stop_queue_by_reason(
  270. &local->hw, hw->queues + qn,
  271. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  272. }
  273. /* prepare A-MPDU MLME for Tx aggregation */
  274. sta->ampdu_mlme.tid_tx[tid] =
  275. kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
  276. if (!sta->ampdu_mlme.tid_tx[tid]) {
  277. #ifdef CONFIG_MAC80211_HT_DEBUG
  278. if (net_ratelimit())
  279. printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
  280. tid);
  281. #endif
  282. ret = -ENOMEM;
  283. goto err_return_queue;
  284. }
  285. /* Tx timer */
  286. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
  287. sta_addba_resp_timer_expired;
  288. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
  289. (unsigned long)&sta->timer_to_tid[tid];
  290. init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  291. /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
  292. * call back right away, it must see that the flow has begun */
  293. *state |= HT_ADDBA_REQUESTED_MSK;
  294. start_seq_num = sta->tid_seq[tid];
  295. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
  296. &sta->sta, tid, &start_seq_num);
  297. if (ret) {
  298. #ifdef CONFIG_MAC80211_HT_DEBUG
  299. printk(KERN_DEBUG "BA request denied - HW unavailable for"
  300. " tid %d\n", tid);
  301. #endif /* CONFIG_MAC80211_HT_DEBUG */
  302. *state = HT_AGG_STATE_IDLE;
  303. goto err_free;
  304. }
  305. sta->tid_to_tx_q[tid] = qn;
  306. spin_unlock_bh(&sta->lock);
  307. /* send an addBA request */
  308. sta->ampdu_mlme.dialog_token_allocator++;
  309. sta->ampdu_mlme.tid_tx[tid]->dialog_token =
  310. sta->ampdu_mlme.dialog_token_allocator;
  311. sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
  312. ieee80211_send_addba_request(sta->sdata, ra, tid,
  313. sta->ampdu_mlme.tid_tx[tid]->dialog_token,
  314. sta->ampdu_mlme.tid_tx[tid]->ssn,
  315. 0x40, 5000);
  316. /* activate the timer for the recipient's addBA response */
  317. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
  318. jiffies + ADDBA_RESP_INTERVAL;
  319. add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  320. #ifdef CONFIG_MAC80211_HT_DEBUG
  321. printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
  322. #endif
  323. goto unlock;
  324. err_free:
  325. kfree(sta->ampdu_mlme.tid_tx[tid]);
  326. sta->ampdu_mlme.tid_tx[tid] = NULL;
  327. err_return_queue:
  328. if (qn >= 0) {
  329. /* We failed, so start queue again right away. */
  330. ieee80211_wake_queue_by_reason(hw, hw->queues + qn,
  331. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  332. /* give queue back to pool */
  333. spin_lock(&local->queue_stop_reason_lock);
  334. local->ampdu_ac_queue[qn] = -1;
  335. spin_unlock(&local->queue_stop_reason_lock);
  336. }
  337. err_unlock_sta:
  338. spin_unlock_bh(&sta->lock);
  339. unlock:
  340. rcu_read_unlock();
  341. return ret;
  342. }
  343. EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
  344. void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  345. {
  346. struct ieee80211_local *local = hw_to_local(hw);
  347. struct sta_info *sta;
  348. u8 *state;
  349. if (tid >= STA_TID_NUM) {
  350. #ifdef CONFIG_MAC80211_HT_DEBUG
  351. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  352. tid, STA_TID_NUM);
  353. #endif
  354. return;
  355. }
  356. rcu_read_lock();
  357. sta = sta_info_get(local, ra);
  358. if (!sta) {
  359. rcu_read_unlock();
  360. #ifdef CONFIG_MAC80211_HT_DEBUG
  361. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  362. #endif
  363. return;
  364. }
  365. state = &sta->ampdu_mlme.tid_state_tx[tid];
  366. spin_lock_bh(&sta->lock);
  367. if (WARN_ON(!(*state & HT_ADDBA_REQUESTED_MSK))) {
  368. #ifdef CONFIG_MAC80211_HT_DEBUG
  369. printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
  370. *state);
  371. #endif
  372. spin_unlock_bh(&sta->lock);
  373. rcu_read_unlock();
  374. return;
  375. }
  376. if (WARN_ON(*state & HT_ADDBA_DRV_READY_MSK))
  377. goto out;
  378. *state |= HT_ADDBA_DRV_READY_MSK;
  379. if (*state == HT_AGG_STATE_OPERATIONAL) {
  380. #ifdef CONFIG_MAC80211_HT_DEBUG
  381. printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
  382. #endif
  383. if (hw->ampdu_queues) {
  384. /*
  385. * Wake up this queue, we stopped it earlier,
  386. * this will in turn wake the entire AC.
  387. */
  388. ieee80211_wake_queue_by_reason(hw,
  389. hw->queues + sta->tid_to_tx_q[tid],
  390. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  391. }
  392. }
  393. out:
  394. spin_unlock_bh(&sta->lock);
  395. rcu_read_unlock();
  396. }
  397. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
  398. void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  399. const u8 *ra, u16 tid)
  400. {
  401. struct ieee80211_local *local = hw_to_local(hw);
  402. struct ieee80211_ra_tid *ra_tid;
  403. struct sk_buff *skb = dev_alloc_skb(0);
  404. if (unlikely(!skb)) {
  405. #ifdef CONFIG_MAC80211_HT_DEBUG
  406. if (net_ratelimit())
  407. printk(KERN_WARNING "%s: Not enough memory, "
  408. "dropping start BA session", skb->dev->name);
  409. #endif
  410. return;
  411. }
  412. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  413. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  414. ra_tid->tid = tid;
  415. skb->pkt_type = IEEE80211_ADDBA_MSG;
  416. skb_queue_tail(&local->skb_queue, skb);
  417. tasklet_schedule(&local->tasklet);
  418. }
  419. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
  420. int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
  421. enum ieee80211_back_parties initiator)
  422. {
  423. u8 *state;
  424. int ret;
  425. /* check if the TID is in aggregation */
  426. state = &sta->ampdu_mlme.tid_state_tx[tid];
  427. spin_lock_bh(&sta->lock);
  428. if (*state != HT_AGG_STATE_OPERATIONAL) {
  429. ret = -ENOENT;
  430. goto unlock;
  431. }
  432. #ifdef CONFIG_MAC80211_HT_DEBUG
  433. printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
  434. sta->sta.addr, tid);
  435. #endif /* CONFIG_MAC80211_HT_DEBUG */
  436. ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator);
  437. unlock:
  438. spin_unlock_bh(&sta->lock);
  439. return ret;
  440. }
  441. int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
  442. u8 *ra, u16 tid,
  443. enum ieee80211_back_parties initiator)
  444. {
  445. struct ieee80211_local *local = hw_to_local(hw);
  446. struct sta_info *sta;
  447. int ret = 0;
  448. if (WARN_ON(!local->ops->ampdu_action))
  449. return -EINVAL;
  450. if (tid >= STA_TID_NUM)
  451. return -EINVAL;
  452. rcu_read_lock();
  453. sta = sta_info_get(local, ra);
  454. if (!sta) {
  455. rcu_read_unlock();
  456. return -ENOENT;
  457. }
  458. ret = __ieee80211_stop_tx_ba_session(sta, tid, initiator);
  459. rcu_read_unlock();
  460. return ret;
  461. }
  462. EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
  463. void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
  464. {
  465. struct ieee80211_local *local = hw_to_local(hw);
  466. struct sta_info *sta;
  467. u8 *state;
  468. if (tid >= STA_TID_NUM) {
  469. #ifdef CONFIG_MAC80211_HT_DEBUG
  470. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  471. tid, STA_TID_NUM);
  472. #endif
  473. return;
  474. }
  475. #ifdef CONFIG_MAC80211_HT_DEBUG
  476. printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
  477. ra, tid);
  478. #endif /* CONFIG_MAC80211_HT_DEBUG */
  479. rcu_read_lock();
  480. sta = sta_info_get(local, ra);
  481. if (!sta) {
  482. #ifdef CONFIG_MAC80211_HT_DEBUG
  483. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  484. #endif
  485. rcu_read_unlock();
  486. return;
  487. }
  488. state = &sta->ampdu_mlme.tid_state_tx[tid];
  489. /* NOTE: no need to use sta->lock in this state check, as
  490. * ieee80211_stop_tx_ba_session will let only one stop call to
  491. * pass through per sta/tid
  492. */
  493. if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
  494. #ifdef CONFIG_MAC80211_HT_DEBUG
  495. printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
  496. #endif
  497. rcu_read_unlock();
  498. return;
  499. }
  500. if (*state & HT_AGG_STATE_INITIATOR_MSK)
  501. ieee80211_send_delba(sta->sdata, ra, tid,
  502. WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
  503. spin_lock_bh(&sta->lock);
  504. if (*state & HT_AGG_STATE_INITIATOR_MSK &&
  505. hw->ampdu_queues) {
  506. /*
  507. * Wake up this queue, we stopped it earlier,
  508. * this will in turn wake the entire AC.
  509. */
  510. ieee80211_wake_queue_by_reason(hw,
  511. hw->queues + sta->tid_to_tx_q[tid],
  512. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  513. }
  514. *state = HT_AGG_STATE_IDLE;
  515. sta->ampdu_mlme.addba_req_num[tid] = 0;
  516. kfree(sta->ampdu_mlme.tid_tx[tid]);
  517. sta->ampdu_mlme.tid_tx[tid] = NULL;
  518. spin_unlock_bh(&sta->lock);
  519. rcu_read_unlock();
  520. }
  521. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
  522. void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  523. const u8 *ra, u16 tid)
  524. {
  525. struct ieee80211_local *local = hw_to_local(hw);
  526. struct ieee80211_ra_tid *ra_tid;
  527. struct sk_buff *skb = dev_alloc_skb(0);
  528. if (unlikely(!skb)) {
  529. #ifdef CONFIG_MAC80211_HT_DEBUG
  530. if (net_ratelimit())
  531. printk(KERN_WARNING "%s: Not enough memory, "
  532. "dropping stop BA session", skb->dev->name);
  533. #endif
  534. return;
  535. }
  536. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  537. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  538. ra_tid->tid = tid;
  539. skb->pkt_type = IEEE80211_DELBA_MSG;
  540. skb_queue_tail(&local->skb_queue, skb);
  541. tasklet_schedule(&local->tasklet);
  542. }
  543. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
  544. void ieee80211_process_addba_resp(struct ieee80211_local *local,
  545. struct sta_info *sta,
  546. struct ieee80211_mgmt *mgmt,
  547. size_t len)
  548. {
  549. struct ieee80211_hw *hw = &local->hw;
  550. u16 capab;
  551. u16 tid, start_seq_num;
  552. u8 *state;
  553. capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
  554. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  555. state = &sta->ampdu_mlme.tid_state_tx[tid];
  556. spin_lock_bh(&sta->lock);
  557. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  558. spin_unlock_bh(&sta->lock);
  559. return;
  560. }
  561. if (mgmt->u.action.u.addba_resp.dialog_token !=
  562. sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
  563. spin_unlock_bh(&sta->lock);
  564. #ifdef CONFIG_MAC80211_HT_DEBUG
  565. printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
  566. #endif /* CONFIG_MAC80211_HT_DEBUG */
  567. return;
  568. }
  569. del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  570. #ifdef CONFIG_MAC80211_HT_DEBUG
  571. printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
  572. #endif /* CONFIG_MAC80211_HT_DEBUG */
  573. if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
  574. == WLAN_STATUS_SUCCESS) {
  575. u8 curstate = *state;
  576. *state |= HT_ADDBA_RECEIVED_MSK;
  577. if (hw->ampdu_queues && *state != curstate &&
  578. *state == HT_AGG_STATE_OPERATIONAL) {
  579. /*
  580. * Wake up this queue, we stopped it earlier,
  581. * this will in turn wake the entire AC.
  582. */
  583. ieee80211_wake_queue_by_reason(hw,
  584. hw->queues + sta->tid_to_tx_q[tid],
  585. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  586. }
  587. sta->ampdu_mlme.addba_req_num[tid] = 0;
  588. if (local->ops->ampdu_action) {
  589. (void)local->ops->ampdu_action(hw,
  590. IEEE80211_AMPDU_TX_RESUME,
  591. &sta->sta, tid, &start_seq_num);
  592. }
  593. #ifdef CONFIG_MAC80211_HT_DEBUG
  594. printk(KERN_DEBUG "Resuming TX aggregation for tid %d\n", tid);
  595. #endif /* CONFIG_MAC80211_HT_DEBUG */
  596. } else {
  597. sta->ampdu_mlme.addba_req_num[tid]++;
  598. ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
  599. }
  600. spin_unlock_bh(&sta->lock);
  601. }