iwl-agn-tx.c 33 KB

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