tx.c 39 KB

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