iwl-agn-tx.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/sched.h>
  33. #include <linux/ieee80211.h>
  34. #include "iwl-dev.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. #include "iwl-agn-hw.h"
  38. #include "iwl-agn.h"
  39. #include "iwl-trans.h"
  40. static void iwlagn_tx_cmd_protection(struct iwl_priv *priv,
  41. struct ieee80211_tx_info *info,
  42. __le16 fc, __le32 *tx_flags)
  43. {
  44. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS ||
  45. info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT ||
  46. info->flags & IEEE80211_TX_CTL_AMPDU)
  47. *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK;
  48. }
  49. /*
  50. * handle build REPLY_TX command notification.
  51. */
  52. static void iwlagn_tx_cmd_build_basic(struct iwl_priv *priv,
  53. struct sk_buff *skb,
  54. struct iwl_tx_cmd *tx_cmd,
  55. struct ieee80211_tx_info *info,
  56. struct ieee80211_hdr *hdr, u8 sta_id)
  57. {
  58. __le16 fc = hdr->frame_control;
  59. __le32 tx_flags = tx_cmd->tx_flags;
  60. tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  61. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  62. tx_flags |= TX_CMD_FLG_ACK_MSK;
  63. else
  64. tx_flags &= ~TX_CMD_FLG_ACK_MSK;
  65. if (ieee80211_is_probe_resp(fc))
  66. tx_flags |= TX_CMD_FLG_TSF_MSK;
  67. else if (ieee80211_is_back_req(fc))
  68. tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
  69. else if (info->band == IEEE80211_BAND_2GHZ &&
  70. cfg(priv)->bt_params &&
  71. cfg(priv)->bt_params->advanced_bt_coexist &&
  72. (ieee80211_is_auth(fc) || ieee80211_is_assoc_req(fc) ||
  73. ieee80211_is_reassoc_req(fc) ||
  74. skb->protocol == cpu_to_be16(ETH_P_PAE)))
  75. tx_flags |= TX_CMD_FLG_IGNORE_BT;
  76. tx_cmd->sta_id = sta_id;
  77. if (ieee80211_has_morefrags(fc))
  78. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  79. if (ieee80211_is_data_qos(fc)) {
  80. u8 *qc = ieee80211_get_qos_ctl(hdr);
  81. tx_cmd->tid_tspec = qc[0] & 0xf;
  82. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  83. } else {
  84. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
  85. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  86. else
  87. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  88. }
  89. iwlagn_tx_cmd_protection(priv, info, fc, &tx_flags);
  90. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  91. if (ieee80211_is_mgmt(fc)) {
  92. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  93. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
  94. else
  95. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
  96. } else {
  97. tx_cmd->timeout.pm_frame_timeout = 0;
  98. }
  99. tx_cmd->driver_txop = 0;
  100. tx_cmd->tx_flags = tx_flags;
  101. tx_cmd->next_frame_len = 0;
  102. }
  103. static void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv,
  104. struct iwl_tx_cmd *tx_cmd,
  105. struct ieee80211_tx_info *info,
  106. __le16 fc)
  107. {
  108. u32 rate_flags;
  109. int rate_idx;
  110. u8 rts_retry_limit;
  111. u8 data_retry_limit;
  112. u8 rate_plcp;
  113. if (priv->shrd->wowlan) {
  114. rts_retry_limit = IWLAGN_LOW_RETRY_LIMIT;
  115. data_retry_limit = IWLAGN_LOW_RETRY_LIMIT;
  116. } else {
  117. /* Set retry limit on RTS packets */
  118. rts_retry_limit = IWLAGN_RTS_DFAULT_RETRY_LIMIT;
  119. /* Set retry limit on DATA packets and Probe Responses*/
  120. if (ieee80211_is_probe_resp(fc)) {
  121. data_retry_limit = IWLAGN_MGMT_DFAULT_RETRY_LIMIT;
  122. rts_retry_limit =
  123. min(data_retry_limit, rts_retry_limit);
  124. } else if (ieee80211_is_back_req(fc))
  125. data_retry_limit = IWLAGN_BAR_DFAULT_RETRY_LIMIT;
  126. else
  127. data_retry_limit = IWLAGN_DEFAULT_TX_RETRY;
  128. }
  129. tx_cmd->data_retry_limit = data_retry_limit;
  130. tx_cmd->rts_retry_limit = rts_retry_limit;
  131. /* DATA packets will use the uCode station table for rate/antenna
  132. * selection */
  133. if (ieee80211_is_data(fc)) {
  134. tx_cmd->initial_rate_index = 0;
  135. tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  136. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  137. if (priv->tm_fixed_rate) {
  138. /*
  139. * rate overwrite by testmode
  140. * we not only send lq command to change rate
  141. * we also re-enforce per data pkt base.
  142. */
  143. tx_cmd->tx_flags &= ~TX_CMD_FLG_STA_RATE_MSK;
  144. memcpy(&tx_cmd->rate_n_flags, &priv->tm_fixed_rate,
  145. sizeof(tx_cmd->rate_n_flags));
  146. }
  147. #endif
  148. return;
  149. } else if (ieee80211_is_back_req(fc))
  150. tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  151. /**
  152. * If the current TX rate stored in mac80211 has the MCS bit set, it's
  153. * not really a TX rate. Thus, we use the lowest supported rate for
  154. * this band. Also use the lowest supported rate if the stored rate
  155. * index is invalid.
  156. */
  157. rate_idx = info->control.rates[0].idx;
  158. if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS ||
  159. (rate_idx < 0) || (rate_idx > IWL_RATE_COUNT_LEGACY))
  160. rate_idx = rate_lowest_index(&priv->bands[info->band],
  161. info->control.sta);
  162. /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
  163. if (info->band == IEEE80211_BAND_5GHZ)
  164. rate_idx += IWL_FIRST_OFDM_RATE;
  165. /* Get PLCP rate for tx_cmd->rate_n_flags */
  166. rate_plcp = iwl_rates[rate_idx].plcp;
  167. /* Zero out flags for this packet */
  168. rate_flags = 0;
  169. /* Set CCK flag as needed */
  170. if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
  171. rate_flags |= RATE_MCS_CCK_MSK;
  172. /* Set up antennas */
  173. if (cfg(priv)->bt_params &&
  174. cfg(priv)->bt_params->advanced_bt_coexist &&
  175. priv->bt_full_concurrent) {
  176. /* operated as 1x1 in full concurrency mode */
  177. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  178. first_antenna(hw_params(priv).valid_tx_ant));
  179. } else
  180. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  181. hw_params(priv).valid_tx_ant);
  182. rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  183. /* Set the rate in the TX cmd */
  184. tx_cmd->rate_n_flags = iwl_hw_set_rate_n_flags(rate_plcp, rate_flags);
  185. }
  186. static void iwlagn_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
  187. struct ieee80211_tx_info *info,
  188. struct iwl_tx_cmd *tx_cmd,
  189. struct sk_buff *skb_frag,
  190. int sta_id)
  191. {
  192. struct ieee80211_key_conf *keyconf = info->control.hw_key;
  193. switch (keyconf->cipher) {
  194. case WLAN_CIPHER_SUITE_CCMP:
  195. tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
  196. memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
  197. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  198. tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
  199. IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
  200. break;
  201. case WLAN_CIPHER_SUITE_TKIP:
  202. tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
  203. ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
  204. IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n");
  205. break;
  206. case WLAN_CIPHER_SUITE_WEP104:
  207. tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
  208. /* fall through */
  209. case WLAN_CIPHER_SUITE_WEP40:
  210. tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP |
  211. (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
  212. memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
  213. IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
  214. "with key %d\n", keyconf->keyidx);
  215. break;
  216. default:
  217. IWL_ERR(priv, "Unknown encode cipher %x\n", keyconf->cipher);
  218. break;
  219. }
  220. }
  221. /*
  222. * start REPLY_TX command process
  223. */
  224. int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
  225. {
  226. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  227. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  228. struct iwl_station_priv *sta_priv = NULL;
  229. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  230. struct iwl_device_cmd *dev_cmd = NULL;
  231. struct iwl_tx_cmd *tx_cmd;
  232. __le16 fc;
  233. u8 hdr_len;
  234. u16 len;
  235. u8 sta_id;
  236. unsigned long flags;
  237. bool is_agg = false;
  238. if (info->control.vif)
  239. ctx = iwl_rxon_ctx_from_vif(info->control.vif);
  240. spin_lock_irqsave(&priv->shrd->lock, flags);
  241. if (iwl_is_rfkill(priv->shrd)) {
  242. IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
  243. goto drop_unlock_priv;
  244. }
  245. fc = hdr->frame_control;
  246. #ifdef CONFIG_IWLWIFI_DEBUG
  247. if (ieee80211_is_auth(fc))
  248. IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
  249. else if (ieee80211_is_assoc_req(fc))
  250. IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
  251. else if (ieee80211_is_reassoc_req(fc))
  252. IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
  253. #endif
  254. if (unlikely(ieee80211_is_probe_resp(fc))) {
  255. struct iwl_wipan_noa_data *noa_data =
  256. rcu_dereference(priv->noa_data);
  257. if (noa_data &&
  258. pskb_expand_head(skb, 0, noa_data->length,
  259. GFP_ATOMIC) == 0) {
  260. memcpy(skb_put(skb, noa_data->length),
  261. noa_data->data, noa_data->length);
  262. hdr = (struct ieee80211_hdr *)skb->data;
  263. }
  264. }
  265. hdr_len = ieee80211_hdrlen(fc);
  266. /* For management frames use broadcast id to do not break aggregation */
  267. if (!ieee80211_is_data(fc))
  268. sta_id = ctx->bcast_sta_id;
  269. else {
  270. /* Find index into station table for destination station */
  271. sta_id = iwl_sta_id_or_broadcast(priv, ctx, info->control.sta);
  272. if (sta_id == IWL_INVALID_STATION) {
  273. IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
  274. hdr->addr1);
  275. goto drop_unlock_priv;
  276. }
  277. }
  278. IWL_DEBUG_TX(priv, "station Id %d\n", sta_id);
  279. if (info->control.sta)
  280. sta_priv = (void *)info->control.sta->drv_priv;
  281. if (sta_priv && sta_priv->asleep &&
  282. (info->flags & IEEE80211_TX_CTL_POLL_RESPONSE)) {
  283. /*
  284. * This sends an asynchronous command to the device,
  285. * but we can rely on it being processed before the
  286. * next frame is processed -- and the next frame to
  287. * this station is the one that will consume this
  288. * counter.
  289. * For now set the counter to just 1 since we do not
  290. * support uAPSD yet.
  291. */
  292. iwl_sta_modify_sleep_tx_count(priv, sta_id, 1);
  293. }
  294. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  295. is_agg = true;
  296. /* irqs already disabled/saved above when locking priv->shrd->lock */
  297. spin_lock(&priv->shrd->sta_lock);
  298. dev_cmd = kmem_cache_alloc(priv->tx_cmd_pool, GFP_ATOMIC);
  299. if (unlikely(!dev_cmd))
  300. goto drop_unlock_sta;
  301. memset(dev_cmd, 0, sizeof(*dev_cmd));
  302. tx_cmd = (struct iwl_tx_cmd *) dev_cmd->payload;
  303. /* Total # bytes to be transmitted */
  304. len = (u16)skb->len;
  305. tx_cmd->len = cpu_to_le16(len);
  306. if (info->control.hw_key)
  307. iwlagn_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb, sta_id);
  308. /* TODO need this for burst mode later on */
  309. iwlagn_tx_cmd_build_basic(priv, skb, tx_cmd, info, hdr, sta_id);
  310. iwl_dbg_log_tx_data_frame(priv, len, hdr);
  311. iwlagn_tx_cmd_build_rate(priv, tx_cmd, info, fc);
  312. iwl_update_stats(priv, true, fc, len);
  313. memset(&info->status, 0, sizeof(info->status));
  314. info->driver_data[0] = ctx;
  315. info->driver_data[1] = dev_cmd;
  316. if (iwl_trans_tx(trans(priv), skb, dev_cmd, ctx->ctxid, sta_id))
  317. goto drop_unlock_sta;
  318. spin_unlock(&priv->shrd->sta_lock);
  319. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  320. /*
  321. * Avoid atomic ops if it isn't an associated client.
  322. * Also, if this is a packet for aggregation, don't
  323. * increase the counter because the ucode will stop
  324. * aggregation queues when their respective station
  325. * goes to sleep.
  326. */
  327. if (sta_priv && sta_priv->client && !is_agg)
  328. atomic_inc(&sta_priv->pending_frames);
  329. return 0;
  330. drop_unlock_sta:
  331. if (dev_cmd)
  332. kmem_cache_free(priv->tx_cmd_pool, dev_cmd);
  333. spin_unlock(&priv->shrd->sta_lock);
  334. drop_unlock_priv:
  335. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  336. return -1;
  337. }
  338. int iwlagn_tx_agg_stop(struct iwl_priv *priv, struct ieee80211_vif *vif,
  339. struct ieee80211_sta *sta, u16 tid)
  340. {
  341. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  342. struct iwl_tid_data *tid_data;
  343. unsigned long flags;
  344. int sta_id;
  345. sta_id = iwl_sta_id(sta);
  346. if (sta_id == IWL_INVALID_STATION) {
  347. IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
  348. return -ENXIO;
  349. }
  350. spin_lock_irqsave(&priv->shrd->sta_lock, flags);
  351. tid_data = &priv->shrd->tid_data[sta_id][tid];
  352. switch (priv->shrd->tid_data[sta_id][tid].agg.state) {
  353. case IWL_EMPTYING_HW_QUEUE_ADDBA:
  354. /*
  355. * This can happen if the peer stops aggregation
  356. * again before we've had a chance to drain the
  357. * queue we selected previously, i.e. before the
  358. * session was really started completely.
  359. */
  360. IWL_DEBUG_HT(priv, "AGG stop before setup done\n");
  361. goto turn_off;
  362. case IWL_AGG_ON:
  363. break;
  364. default:
  365. IWL_WARN(priv, "Stopping AGG while state not ON "
  366. "or starting for %d on %d (%d)\n", sta_id, tid,
  367. priv->shrd->tid_data[sta_id][tid].agg.state);
  368. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  369. return 0;
  370. }
  371. tid_data->agg.ssn = SEQ_TO_SN(tid_data->seq_number);
  372. /* There are still packets for this RA / TID in the HW */
  373. if (tid_data->agg.ssn != tid_data->next_reclaimed) {
  374. IWL_DEBUG_TX_QUEUES(priv, "Can't proceed: ssn %d, "
  375. "next_recl = %d",
  376. tid_data->agg.ssn,
  377. tid_data->next_reclaimed);
  378. priv->shrd->tid_data[sta_id][tid].agg.state =
  379. IWL_EMPTYING_HW_QUEUE_DELBA;
  380. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  381. return 0;
  382. }
  383. IWL_DEBUG_TX_QUEUES(priv, "Can proceed: ssn = next_recl = %d",
  384. tid_data->agg.ssn);
  385. turn_off:
  386. priv->shrd->tid_data[sta_id][tid].agg.state = IWL_AGG_OFF;
  387. /* do not restore/save irqs */
  388. spin_unlock(&priv->shrd->sta_lock);
  389. spin_lock(&priv->shrd->lock);
  390. iwl_trans_tx_agg_disable(trans(priv), sta_id, tid);
  391. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  392. iwl_stop_tx_ba_trans_ready(priv, vif_priv->ctx->ctxid, sta_id, tid);
  393. return 0;
  394. }
  395. int iwlagn_tx_agg_start(struct iwl_priv *priv, struct ieee80211_vif *vif,
  396. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  397. {
  398. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  399. int sta_id;
  400. int ret;
  401. IWL_DEBUG_HT(priv, "TX AGG request on ra = %pM tid = %d\n",
  402. sta->addr, tid);
  403. sta_id = iwl_sta_id(sta);
  404. if (sta_id == IWL_INVALID_STATION) {
  405. IWL_ERR(priv, "Start AGG on invalid station\n");
  406. return -ENXIO;
  407. }
  408. if (unlikely(tid >= IWL_MAX_TID_COUNT))
  409. return -EINVAL;
  410. if (priv->shrd->tid_data[sta_id][tid].agg.state != IWL_AGG_OFF) {
  411. IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n");
  412. return -ENXIO;
  413. }
  414. ret = iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
  415. if (ret)
  416. return ret;
  417. ret = iwl_trans_tx_agg_alloc(trans(priv), vif_priv->ctx->ctxid, sta_id,
  418. tid, ssn);
  419. return ret;
  420. }
  421. static void iwlagn_non_agg_tx_status(struct iwl_priv *priv,
  422. struct iwl_rxon_context *ctx,
  423. const u8 *addr1)
  424. {
  425. struct ieee80211_sta *sta;
  426. struct iwl_station_priv *sta_priv;
  427. rcu_read_lock();
  428. sta = ieee80211_find_sta(ctx->vif, addr1);
  429. if (sta) {
  430. sta_priv = (void *)sta->drv_priv;
  431. /* avoid atomic ops if this isn't a client */
  432. if (sta_priv->client &&
  433. atomic_dec_return(&sta_priv->pending_frames) == 0)
  434. ieee80211_sta_block_awake(priv->hw, sta, false);
  435. }
  436. rcu_read_unlock();
  437. }
  438. /**
  439. * translate ucode response to mac80211 tx status control values
  440. */
  441. static void iwlagn_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
  442. struct ieee80211_tx_info *info)
  443. {
  444. struct ieee80211_tx_rate *r = &info->control.rates[0];
  445. info->antenna_sel_tx =
  446. ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
  447. if (rate_n_flags & RATE_MCS_HT_MSK)
  448. r->flags |= IEEE80211_TX_RC_MCS;
  449. if (rate_n_flags & RATE_MCS_GF_MSK)
  450. r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
  451. if (rate_n_flags & RATE_MCS_HT40_MSK)
  452. r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  453. if (rate_n_flags & RATE_MCS_DUP_MSK)
  454. r->flags |= IEEE80211_TX_RC_DUP_DATA;
  455. if (rate_n_flags & RATE_MCS_SGI_MSK)
  456. r->flags |= IEEE80211_TX_RC_SHORT_GI;
  457. r->idx = iwlagn_hwrate_to_mac80211_idx(rate_n_flags, info->band);
  458. }
  459. #ifdef CONFIG_IWLWIFI_DEBUG
  460. const char *iwl_get_tx_fail_reason(u32 status)
  461. {
  462. #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
  463. #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
  464. switch (status & TX_STATUS_MSK) {
  465. case TX_STATUS_SUCCESS:
  466. return "SUCCESS";
  467. TX_STATUS_POSTPONE(DELAY);
  468. TX_STATUS_POSTPONE(FEW_BYTES);
  469. TX_STATUS_POSTPONE(BT_PRIO);
  470. TX_STATUS_POSTPONE(QUIET_PERIOD);
  471. TX_STATUS_POSTPONE(CALC_TTAK);
  472. TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
  473. TX_STATUS_FAIL(SHORT_LIMIT);
  474. TX_STATUS_FAIL(LONG_LIMIT);
  475. TX_STATUS_FAIL(FIFO_UNDERRUN);
  476. TX_STATUS_FAIL(DRAIN_FLOW);
  477. TX_STATUS_FAIL(RFKILL_FLUSH);
  478. TX_STATUS_FAIL(LIFE_EXPIRE);
  479. TX_STATUS_FAIL(DEST_PS);
  480. TX_STATUS_FAIL(HOST_ABORTED);
  481. TX_STATUS_FAIL(BT_RETRY);
  482. TX_STATUS_FAIL(STA_INVALID);
  483. TX_STATUS_FAIL(FRAG_DROPPED);
  484. TX_STATUS_FAIL(TID_DISABLE);
  485. TX_STATUS_FAIL(FIFO_FLUSHED);
  486. TX_STATUS_FAIL(INSUFFICIENT_CF_POLL);
  487. TX_STATUS_FAIL(PASSIVE_NO_RX);
  488. TX_STATUS_FAIL(NO_BEACON_ON_RADAR);
  489. }
  490. return "UNKNOWN";
  491. #undef TX_STATUS_FAIL
  492. #undef TX_STATUS_POSTPONE
  493. }
  494. #endif /* CONFIG_IWLWIFI_DEBUG */
  495. static void iwlagn_count_agg_tx_err_status(struct iwl_priv *priv, u16 status)
  496. {
  497. status &= AGG_TX_STATUS_MSK;
  498. switch (status) {
  499. case AGG_TX_STATE_UNDERRUN_MSK:
  500. priv->reply_agg_tx_stats.underrun++;
  501. break;
  502. case AGG_TX_STATE_BT_PRIO_MSK:
  503. priv->reply_agg_tx_stats.bt_prio++;
  504. break;
  505. case AGG_TX_STATE_FEW_BYTES_MSK:
  506. priv->reply_agg_tx_stats.few_bytes++;
  507. break;
  508. case AGG_TX_STATE_ABORT_MSK:
  509. priv->reply_agg_tx_stats.abort++;
  510. break;
  511. case AGG_TX_STATE_LAST_SENT_TTL_MSK:
  512. priv->reply_agg_tx_stats.last_sent_ttl++;
  513. break;
  514. case AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK:
  515. priv->reply_agg_tx_stats.last_sent_try++;
  516. break;
  517. case AGG_TX_STATE_LAST_SENT_BT_KILL_MSK:
  518. priv->reply_agg_tx_stats.last_sent_bt_kill++;
  519. break;
  520. case AGG_TX_STATE_SCD_QUERY_MSK:
  521. priv->reply_agg_tx_stats.scd_query++;
  522. break;
  523. case AGG_TX_STATE_TEST_BAD_CRC32_MSK:
  524. priv->reply_agg_tx_stats.bad_crc32++;
  525. break;
  526. case AGG_TX_STATE_RESPONSE_MSK:
  527. priv->reply_agg_tx_stats.response++;
  528. break;
  529. case AGG_TX_STATE_DUMP_TX_MSK:
  530. priv->reply_agg_tx_stats.dump_tx++;
  531. break;
  532. case AGG_TX_STATE_DELAY_TX_MSK:
  533. priv->reply_agg_tx_stats.delay_tx++;
  534. break;
  535. default:
  536. priv->reply_agg_tx_stats.unknown++;
  537. break;
  538. }
  539. }
  540. static void iwl_rx_reply_tx_agg(struct iwl_priv *priv,
  541. struct iwlagn_tx_resp *tx_resp)
  542. {
  543. struct agg_tx_status *frame_status = &tx_resp->status;
  544. int tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
  545. IWLAGN_TX_RES_TID_POS;
  546. int sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
  547. IWLAGN_TX_RES_RA_POS;
  548. struct iwl_ht_agg *agg = &priv->shrd->tid_data[sta_id][tid].agg;
  549. u32 status = le16_to_cpu(tx_resp->status.status);
  550. int i;
  551. if (agg->wait_for_ba)
  552. IWL_DEBUG_TX_REPLY(priv,
  553. "got tx response w/o block-ack\n");
  554. agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  555. agg->wait_for_ba = (tx_resp->frame_count > 1);
  556. /*
  557. * If the BT kill count is non-zero, we'll get this
  558. * notification again.
  559. */
  560. if (tx_resp->bt_kill_count && tx_resp->frame_count == 1 &&
  561. cfg(priv)->bt_params &&
  562. cfg(priv)->bt_params->advanced_bt_coexist) {
  563. IWL_DEBUG_COEX(priv, "receive reply tx w/ bt_kill\n");
  564. }
  565. if (tx_resp->frame_count == 1)
  566. return;
  567. /* Construct bit-map of pending frames within Tx window */
  568. for (i = 0; i < tx_resp->frame_count; i++) {
  569. u16 fstatus = le16_to_cpu(frame_status[i].status);
  570. if (status & AGG_TX_STATUS_MSK)
  571. iwlagn_count_agg_tx_err_status(priv, fstatus);
  572. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  573. AGG_TX_STATE_ABORT_MSK))
  574. continue;
  575. IWL_DEBUG_TX_REPLY(priv, "status %s (0x%08x), "
  576. "try-count (0x%08x)\n",
  577. iwl_get_agg_tx_fail_reason(fstatus),
  578. fstatus & AGG_TX_STATUS_MSK,
  579. fstatus & AGG_TX_TRY_MSK);
  580. }
  581. }
  582. #ifdef CONFIG_IWLWIFI_DEBUG
  583. #define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x
  584. const char *iwl_get_agg_tx_fail_reason(u16 status)
  585. {
  586. status &= AGG_TX_STATUS_MSK;
  587. switch (status) {
  588. case AGG_TX_STATE_TRANSMITTED:
  589. return "SUCCESS";
  590. AGG_TX_STATE_FAIL(UNDERRUN_MSK);
  591. AGG_TX_STATE_FAIL(BT_PRIO_MSK);
  592. AGG_TX_STATE_FAIL(FEW_BYTES_MSK);
  593. AGG_TX_STATE_FAIL(ABORT_MSK);
  594. AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK);
  595. AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK);
  596. AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK);
  597. AGG_TX_STATE_FAIL(SCD_QUERY_MSK);
  598. AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK);
  599. AGG_TX_STATE_FAIL(RESPONSE_MSK);
  600. AGG_TX_STATE_FAIL(DUMP_TX_MSK);
  601. AGG_TX_STATE_FAIL(DELAY_TX_MSK);
  602. }
  603. return "UNKNOWN";
  604. }
  605. #endif /* CONFIG_IWLWIFI_DEBUG */
  606. static inline u32 iwlagn_get_scd_ssn(struct iwlagn_tx_resp *tx_resp)
  607. {
  608. return le32_to_cpup((__le32 *)&tx_resp->status +
  609. tx_resp->frame_count) & MAX_SN;
  610. }
  611. static void iwlagn_count_tx_err_status(struct iwl_priv *priv, u16 status)
  612. {
  613. status &= TX_STATUS_MSK;
  614. switch (status) {
  615. case TX_STATUS_POSTPONE_DELAY:
  616. priv->reply_tx_stats.pp_delay++;
  617. break;
  618. case TX_STATUS_POSTPONE_FEW_BYTES:
  619. priv->reply_tx_stats.pp_few_bytes++;
  620. break;
  621. case TX_STATUS_POSTPONE_BT_PRIO:
  622. priv->reply_tx_stats.pp_bt_prio++;
  623. break;
  624. case TX_STATUS_POSTPONE_QUIET_PERIOD:
  625. priv->reply_tx_stats.pp_quiet_period++;
  626. break;
  627. case TX_STATUS_POSTPONE_CALC_TTAK:
  628. priv->reply_tx_stats.pp_calc_ttak++;
  629. break;
  630. case TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY:
  631. priv->reply_tx_stats.int_crossed_retry++;
  632. break;
  633. case TX_STATUS_FAIL_SHORT_LIMIT:
  634. priv->reply_tx_stats.short_limit++;
  635. break;
  636. case TX_STATUS_FAIL_LONG_LIMIT:
  637. priv->reply_tx_stats.long_limit++;
  638. break;
  639. case TX_STATUS_FAIL_FIFO_UNDERRUN:
  640. priv->reply_tx_stats.fifo_underrun++;
  641. break;
  642. case TX_STATUS_FAIL_DRAIN_FLOW:
  643. priv->reply_tx_stats.drain_flow++;
  644. break;
  645. case TX_STATUS_FAIL_RFKILL_FLUSH:
  646. priv->reply_tx_stats.rfkill_flush++;
  647. break;
  648. case TX_STATUS_FAIL_LIFE_EXPIRE:
  649. priv->reply_tx_stats.life_expire++;
  650. break;
  651. case TX_STATUS_FAIL_DEST_PS:
  652. priv->reply_tx_stats.dest_ps++;
  653. break;
  654. case TX_STATUS_FAIL_HOST_ABORTED:
  655. priv->reply_tx_stats.host_abort++;
  656. break;
  657. case TX_STATUS_FAIL_BT_RETRY:
  658. priv->reply_tx_stats.bt_retry++;
  659. break;
  660. case TX_STATUS_FAIL_STA_INVALID:
  661. priv->reply_tx_stats.sta_invalid++;
  662. break;
  663. case TX_STATUS_FAIL_FRAG_DROPPED:
  664. priv->reply_tx_stats.frag_drop++;
  665. break;
  666. case TX_STATUS_FAIL_TID_DISABLE:
  667. priv->reply_tx_stats.tid_disable++;
  668. break;
  669. case TX_STATUS_FAIL_FIFO_FLUSHED:
  670. priv->reply_tx_stats.fifo_flush++;
  671. break;
  672. case TX_STATUS_FAIL_INSUFFICIENT_CF_POLL:
  673. priv->reply_tx_stats.insuff_cf_poll++;
  674. break;
  675. case TX_STATUS_FAIL_PASSIVE_NO_RX:
  676. priv->reply_tx_stats.fail_hw_drop++;
  677. break;
  678. case TX_STATUS_FAIL_NO_BEACON_ON_RADAR:
  679. priv->reply_tx_stats.sta_color_mismatch++;
  680. break;
  681. default:
  682. priv->reply_tx_stats.unknown++;
  683. break;
  684. }
  685. }
  686. static void iwlagn_set_tx_status(struct iwl_priv *priv,
  687. struct ieee80211_tx_info *info,
  688. struct iwlagn_tx_resp *tx_resp,
  689. bool is_agg)
  690. {
  691. u16 status = le16_to_cpu(tx_resp->status.status);
  692. info->status.rates[0].count = tx_resp->failure_frame + 1;
  693. if (is_agg)
  694. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  695. info->flags |= iwl_tx_status_to_mac80211(status);
  696. iwlagn_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
  697. info);
  698. if (!iwl_is_tx_success(status))
  699. iwlagn_count_tx_err_status(priv, status);
  700. }
  701. static void iwl_check_abort_status(struct iwl_priv *priv,
  702. u8 frame_count, u32 status)
  703. {
  704. if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
  705. IWL_ERR(priv, "Tx flush command to flush out all frames\n");
  706. if (!test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  707. queue_work(priv->shrd->workqueue, &priv->tx_flush);
  708. }
  709. }
  710. int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb,
  711. struct iwl_device_cmd *cmd)
  712. {
  713. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  714. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  715. int txq_id = SEQ_TO_QUEUE(sequence);
  716. int cmd_index __maybe_unused = SEQ_TO_INDEX(sequence);
  717. struct iwlagn_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  718. struct ieee80211_hdr *hdr;
  719. u32 status = le16_to_cpu(tx_resp->status.status);
  720. u16 ssn = iwlagn_get_scd_ssn(tx_resp);
  721. int tid;
  722. int sta_id;
  723. int freed;
  724. struct ieee80211_tx_info *info;
  725. unsigned long flags;
  726. struct sk_buff_head skbs;
  727. struct sk_buff *skb;
  728. struct iwl_rxon_context *ctx;
  729. bool is_agg = (txq_id >= IWLAGN_FIRST_AMPDU_QUEUE);
  730. tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
  731. IWLAGN_TX_RES_TID_POS;
  732. sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
  733. IWLAGN_TX_RES_RA_POS;
  734. spin_lock_irqsave(&priv->shrd->sta_lock, flags);
  735. if (is_agg)
  736. iwl_rx_reply_tx_agg(priv, tx_resp);
  737. if (tx_resp->frame_count == 1) {
  738. u16 next_reclaimed = le16_to_cpu(tx_resp->seq_ctl);
  739. next_reclaimed = SEQ_TO_SN(next_reclaimed + 0x10);
  740. if (is_agg) {
  741. /* If this is an aggregation queue, we can rely on the
  742. * ssn since the wifi sequence number corresponds to
  743. * the index in the TFD ring (%256).
  744. * The seq_ctl is the sequence control of the packet
  745. * to which this Tx response relates. But if there is a
  746. * hole in the bitmap of the BA we received, this Tx
  747. * response may allow to reclaim the hole and all the
  748. * subsequent packets that were already acked.
  749. * In that case, seq_ctl != ssn, and the next packet
  750. * to be reclaimed will be ssn and not seq_ctl.
  751. */
  752. next_reclaimed = ssn;
  753. }
  754. __skb_queue_head_init(&skbs);
  755. priv->shrd->tid_data[sta_id][tid].next_reclaimed =
  756. next_reclaimed;
  757. IWL_DEBUG_TX_REPLY(priv, "Next reclaimed packet:%d",
  758. next_reclaimed);
  759. /*we can free until ssn % q.n_bd not inclusive */
  760. iwl_trans_reclaim(trans(priv), sta_id, tid, txq_id,
  761. ssn, status, &skbs);
  762. freed = 0;
  763. while (!skb_queue_empty(&skbs)) {
  764. skb = __skb_dequeue(&skbs);
  765. hdr = (struct ieee80211_hdr *)skb->data;
  766. if (!ieee80211_is_data_qos(hdr->frame_control))
  767. priv->last_seq_ctl = tx_resp->seq_ctl;
  768. info = IEEE80211_SKB_CB(skb);
  769. ctx = info->driver_data[0];
  770. kmem_cache_free(priv->tx_cmd_pool,
  771. (info->driver_data[1]));
  772. memset(&info->status, 0, sizeof(info->status));
  773. if (status == TX_STATUS_FAIL_PASSIVE_NO_RX &&
  774. iwl_is_associated_ctx(ctx) && ctx->vif &&
  775. ctx->vif->type == NL80211_IFTYPE_STATION) {
  776. ctx->last_tx_rejected = true;
  777. iwl_trans_stop_queue(trans(priv), txq_id,
  778. "Tx on passive channel");
  779. IWL_DEBUG_TX_REPLY(priv,
  780. "TXQ %d status %s (0x%08x) "
  781. "rate_n_flags 0x%x retries %d\n",
  782. txq_id,
  783. iwl_get_tx_fail_reason(status),
  784. status,
  785. le32_to_cpu(tx_resp->rate_n_flags),
  786. tx_resp->failure_frame);
  787. IWL_DEBUG_TX_REPLY(priv,
  788. "FrameCnt = %d, idx=%d\n",
  789. tx_resp->frame_count, cmd_index);
  790. }
  791. /* check if BAR is needed */
  792. if (is_agg && !iwl_is_tx_success(status))
  793. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  794. iwlagn_set_tx_status(priv, IEEE80211_SKB_CB(skb),
  795. tx_resp, is_agg);
  796. if (!is_agg)
  797. iwlagn_non_agg_tx_status(priv, ctx, hdr->addr1);
  798. ieee80211_tx_status_irqsafe(priv->hw, skb);
  799. freed++;
  800. }
  801. WARN_ON(!is_agg && freed != 1);
  802. }
  803. iwl_check_abort_status(priv, tx_resp->frame_count, status);
  804. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  805. return 0;
  806. }
  807. /**
  808. * iwlagn_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
  809. *
  810. * Handles block-acknowledge notification from device, which reports success
  811. * of frames sent via aggregation.
  812. */
  813. int iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
  814. struct iwl_rx_mem_buffer *rxb,
  815. struct iwl_device_cmd *cmd)
  816. {
  817. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  818. struct iwl_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
  819. struct iwl_ht_agg *agg;
  820. struct sk_buff_head reclaimed_skbs;
  821. struct ieee80211_tx_info *info;
  822. struct ieee80211_hdr *hdr;
  823. struct sk_buff *skb;
  824. unsigned long flags;
  825. int sta_id;
  826. int tid;
  827. int freed;
  828. /* "flow" corresponds to Tx queue */
  829. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  830. /* "ssn" is start of block-ack Tx window, corresponds to index
  831. * (in Tx queue's circular buffer) of first TFD/frame in window */
  832. u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
  833. if (scd_flow >= hw_params(priv).max_txq_num) {
  834. IWL_ERR(priv,
  835. "BUG_ON scd_flow is bigger than number of queues\n");
  836. return 0;
  837. }
  838. sta_id = ba_resp->sta_id;
  839. tid = ba_resp->tid;
  840. agg = &priv->shrd->tid_data[sta_id][tid].agg;
  841. spin_lock_irqsave(&priv->shrd->sta_lock, flags);
  842. if (unlikely(agg->txq_id != scd_flow)) {
  843. /*
  844. * FIXME: this is a uCode bug which need to be addressed,
  845. * log the information and return for now!
  846. * since it is possible happen very often and in order
  847. * not to fill the syslog, don't enable the logging by default
  848. */
  849. IWL_DEBUG_TX_REPLY(priv,
  850. "BA scd_flow %d does not match txq_id %d\n",
  851. scd_flow, agg->txq_id);
  852. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  853. return 0;
  854. }
  855. if (unlikely(!agg->wait_for_ba)) {
  856. if (unlikely(ba_resp->bitmap))
  857. IWL_ERR(priv, "Received BA when not expected\n");
  858. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  859. return 0;
  860. }
  861. IWL_DEBUG_TX_REPLY(priv, "REPLY_COMPRESSED_BA [%d] Received from %pM, "
  862. "sta_id = %d\n",
  863. agg->wait_for_ba,
  864. (u8 *) &ba_resp->sta_addr_lo32,
  865. ba_resp->sta_id);
  866. IWL_DEBUG_TX_REPLY(priv, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, "
  867. "scd_flow = %d, scd_ssn = %d\n",
  868. ba_resp->tid, le16_to_cpu(ba_resp->seq_ctl),
  869. (unsigned long long)le64_to_cpu(ba_resp->bitmap),
  870. scd_flow, ba_resp_scd_ssn);
  871. /* Mark that the expected block-ack response arrived */
  872. agg->wait_for_ba = false;
  873. /* Sanity check values reported by uCode */
  874. if (ba_resp->txed_2_done > ba_resp->txed) {
  875. IWL_DEBUG_TX_REPLY(priv,
  876. "bogus sent(%d) and ack(%d) count\n",
  877. ba_resp->txed, ba_resp->txed_2_done);
  878. /*
  879. * set txed_2_done = txed,
  880. * so it won't impact rate scale
  881. */
  882. ba_resp->txed = ba_resp->txed_2_done;
  883. }
  884. IWL_DEBUG_HT(priv, "agg frames sent:%d, acked:%d\n",
  885. ba_resp->txed, ba_resp->txed_2_done);
  886. __skb_queue_head_init(&reclaimed_skbs);
  887. /* Release all TFDs before the SSN, i.e. all TFDs in front of
  888. * block-ack window (we assume that they've been successfully
  889. * transmitted ... if not, it's too late anyway). */
  890. priv->shrd->tid_data[sta_id][tid].next_reclaimed = ba_resp_scd_ssn;
  891. iwl_trans_reclaim(trans(priv), sta_id, tid, scd_flow, ba_resp_scd_ssn,
  892. 0, &reclaimed_skbs);
  893. freed = 0;
  894. while (!skb_queue_empty(&reclaimed_skbs)) {
  895. skb = __skb_dequeue(&reclaimed_skbs);
  896. hdr = (struct ieee80211_hdr *)skb->data;
  897. if (ieee80211_is_data_qos(hdr->frame_control))
  898. freed++;
  899. else
  900. WARN_ON_ONCE(1);
  901. info = IEEE80211_SKB_CB(skb);
  902. kmem_cache_free(priv->tx_cmd_pool, (info->driver_data[1]));
  903. if (freed == 1) {
  904. /* this is the first skb we deliver in this batch */
  905. /* put the rate scaling data there */
  906. info = IEEE80211_SKB_CB(skb);
  907. memset(&info->status, 0, sizeof(info->status));
  908. info->flags |= IEEE80211_TX_STAT_ACK;
  909. info->flags |= IEEE80211_TX_STAT_AMPDU;
  910. info->status.ampdu_ack_len = ba_resp->txed_2_done;
  911. info->status.ampdu_len = ba_resp->txed;
  912. iwlagn_hwrate_to_tx_control(priv, agg->rate_n_flags,
  913. info);
  914. }
  915. ieee80211_tx_status_irqsafe(priv->hw, skb);
  916. }
  917. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  918. return 0;
  919. }