iwl-agn-tx.c 36 KB

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