agg-tx.c 19 KB

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