iwl-agn-tx.c 38 KB

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