iwl-agn-tx.c 36 KB

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