tx.c 39 KB

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