iwl-agn-tx.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  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-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. priv->cfg->bt_params &&
  71. priv->cfg->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_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  85. }
  86. iwlagn_tx_cmd_protection(priv, info, fc, &tx_flags);
  87. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  88. if (ieee80211_is_mgmt(fc)) {
  89. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  90. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
  91. else
  92. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
  93. } else {
  94. tx_cmd->timeout.pm_frame_timeout = 0;
  95. }
  96. tx_cmd->driver_txop = 0;
  97. tx_cmd->tx_flags = tx_flags;
  98. tx_cmd->next_frame_len = 0;
  99. }
  100. static void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv,
  101. struct iwl_tx_cmd *tx_cmd,
  102. struct ieee80211_tx_info *info,
  103. __le16 fc)
  104. {
  105. u32 rate_flags;
  106. int rate_idx;
  107. u8 rts_retry_limit;
  108. u8 data_retry_limit;
  109. u8 rate_plcp;
  110. if (priv->shrd->wowlan) {
  111. rts_retry_limit = IWLAGN_LOW_RETRY_LIMIT;
  112. data_retry_limit = IWLAGN_LOW_RETRY_LIMIT;
  113. } else {
  114. /* Set retry limit on RTS packets */
  115. rts_retry_limit = IWLAGN_RTS_DFAULT_RETRY_LIMIT;
  116. /* Set retry limit on DATA packets and Probe Responses*/
  117. if (ieee80211_is_probe_resp(fc)) {
  118. data_retry_limit = IWLAGN_MGMT_DFAULT_RETRY_LIMIT;
  119. rts_retry_limit =
  120. min(data_retry_limit, rts_retry_limit);
  121. } else if (ieee80211_is_back_req(fc))
  122. data_retry_limit = IWLAGN_BAR_DFAULT_RETRY_LIMIT;
  123. else
  124. data_retry_limit = IWLAGN_DEFAULT_TX_RETRY;
  125. }
  126. tx_cmd->data_retry_limit = data_retry_limit;
  127. tx_cmd->rts_retry_limit = rts_retry_limit;
  128. /* DATA packets will use the uCode station table for rate/antenna
  129. * selection */
  130. if (ieee80211_is_data(fc)) {
  131. tx_cmd->initial_rate_index = 0;
  132. tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  133. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  134. if (priv->tm_fixed_rate) {
  135. /*
  136. * rate overwrite by testmode
  137. * we not only send lq command to change rate
  138. * we also re-enforce per data pkt base.
  139. */
  140. tx_cmd->tx_flags &= ~TX_CMD_FLG_STA_RATE_MSK;
  141. memcpy(&tx_cmd->rate_n_flags, &priv->tm_fixed_rate,
  142. sizeof(tx_cmd->rate_n_flags));
  143. }
  144. #endif
  145. return;
  146. } else if (ieee80211_is_back_req(fc))
  147. tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  148. /**
  149. * If the current TX rate stored in mac80211 has the MCS bit set, it's
  150. * not really a TX rate. Thus, we use the lowest supported rate for
  151. * this band. Also use the lowest supported rate if the stored rate
  152. * index is invalid.
  153. */
  154. rate_idx = info->control.rates[0].idx;
  155. if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS ||
  156. (rate_idx < 0) || (rate_idx > IWL_RATE_COUNT_LEGACY))
  157. rate_idx = rate_lowest_index(&priv->bands[info->band],
  158. info->control.sta);
  159. /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
  160. if (info->band == IEEE80211_BAND_5GHZ)
  161. rate_idx += IWL_FIRST_OFDM_RATE;
  162. /* Get PLCP rate for tx_cmd->rate_n_flags */
  163. rate_plcp = iwl_rates[rate_idx].plcp;
  164. /* Zero out flags for this packet */
  165. rate_flags = 0;
  166. /* Set CCK flag as needed */
  167. if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
  168. rate_flags |= RATE_MCS_CCK_MSK;
  169. /* Set up antennas */
  170. if (priv->cfg->bt_params &&
  171. priv->cfg->bt_params->advanced_bt_coexist &&
  172. priv->bt_full_concurrent) {
  173. /* operated as 1x1 in full concurrency mode */
  174. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  175. first_antenna(hw_params(priv).valid_tx_ant));
  176. } else
  177. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  178. hw_params(priv).valid_tx_ant);
  179. rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  180. /* Set the rate in the TX cmd */
  181. tx_cmd->rate_n_flags = iwl_hw_set_rate_n_flags(rate_plcp, rate_flags);
  182. }
  183. static void iwlagn_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
  184. struct ieee80211_tx_info *info,
  185. struct iwl_tx_cmd *tx_cmd,
  186. struct sk_buff *skb_frag,
  187. int sta_id)
  188. {
  189. struct ieee80211_key_conf *keyconf = info->control.hw_key;
  190. switch (keyconf->cipher) {
  191. case WLAN_CIPHER_SUITE_CCMP:
  192. tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
  193. memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
  194. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  195. tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
  196. IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
  197. break;
  198. case WLAN_CIPHER_SUITE_TKIP:
  199. tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
  200. ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
  201. IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n");
  202. break;
  203. case WLAN_CIPHER_SUITE_WEP104:
  204. tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
  205. /* fall through */
  206. case WLAN_CIPHER_SUITE_WEP40:
  207. tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP |
  208. (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
  209. memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
  210. IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
  211. "with key %d\n", keyconf->keyidx);
  212. break;
  213. default:
  214. IWL_ERR(priv, "Unknown encode cipher %x\n", keyconf->cipher);
  215. break;
  216. }
  217. }
  218. /*
  219. * start REPLY_TX command process
  220. */
  221. int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
  222. {
  223. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  224. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  225. struct iwl_station_priv *sta_priv = NULL;
  226. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  227. struct iwl_device_cmd *dev_cmd = NULL;
  228. struct iwl_tx_cmd *tx_cmd;
  229. __le16 fc;
  230. u8 hdr_len;
  231. u16 len;
  232. u8 sta_id;
  233. unsigned long flags;
  234. bool is_agg = false;
  235. if (info->control.vif)
  236. ctx = iwl_rxon_ctx_from_vif(info->control.vif);
  237. spin_lock_irqsave(&priv->shrd->lock, flags);
  238. if (iwl_is_rfkill(priv->shrd)) {
  239. IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
  240. goto drop_unlock_priv;
  241. }
  242. fc = hdr->frame_control;
  243. #ifdef CONFIG_IWLWIFI_DEBUG
  244. if (ieee80211_is_auth(fc))
  245. IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
  246. else if (ieee80211_is_assoc_req(fc))
  247. IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
  248. else if (ieee80211_is_reassoc_req(fc))
  249. IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
  250. #endif
  251. if (unlikely(ieee80211_is_probe_resp(fc))) {
  252. struct iwl_wipan_noa_data *noa_data =
  253. rcu_dereference(priv->noa_data);
  254. if (noa_data &&
  255. pskb_expand_head(skb, 0, noa_data->length,
  256. GFP_ATOMIC) == 0) {
  257. memcpy(skb_put(skb, noa_data->length),
  258. noa_data->data, noa_data->length);
  259. hdr = (struct ieee80211_hdr *)skb->data;
  260. }
  261. }
  262. hdr_len = ieee80211_hdrlen(fc);
  263. /* For management frames use broadcast id to do not break aggregation */
  264. if (!ieee80211_is_data(fc))
  265. sta_id = ctx->bcast_sta_id;
  266. else {
  267. /* Find index into station table for destination station */
  268. sta_id = iwl_sta_id_or_broadcast(priv, ctx, info->control.sta);
  269. if (sta_id == IWL_INVALID_STATION) {
  270. IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
  271. hdr->addr1);
  272. goto drop_unlock_priv;
  273. }
  274. }
  275. IWL_DEBUG_TX(priv, "station Id %d\n", sta_id);
  276. if (info->control.sta)
  277. sta_priv = (void *)info->control.sta->drv_priv;
  278. if (sta_priv && sta_priv->asleep &&
  279. (info->flags & IEEE80211_TX_CTL_POLL_RESPONSE)) {
  280. /*
  281. * This sends an asynchronous command to the device,
  282. * but we can rely on it being processed before the
  283. * next frame is processed -- and the next frame to
  284. * this station is the one that will consume this
  285. * counter.
  286. * For now set the counter to just 1 since we do not
  287. * support uAPSD yet.
  288. */
  289. iwl_sta_modify_sleep_tx_count(priv, sta_id, 1);
  290. }
  291. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  292. is_agg = true;
  293. /* irqs already disabled/saved above when locking priv->shrd->lock */
  294. spin_lock(&priv->shrd->sta_lock);
  295. dev_cmd = kmem_cache_alloc(priv->tx_cmd_pool, GFP_ATOMIC);
  296. if (unlikely(!dev_cmd))
  297. goto drop_unlock_sta;
  298. memset(dev_cmd, 0, sizeof(*dev_cmd));
  299. tx_cmd = (struct iwl_tx_cmd *) dev_cmd->payload;
  300. /* Total # bytes to be transmitted */
  301. len = (u16)skb->len;
  302. tx_cmd->len = cpu_to_le16(len);
  303. if (info->control.hw_key)
  304. iwlagn_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb, sta_id);
  305. /* TODO need this for burst mode later on */
  306. iwlagn_tx_cmd_build_basic(priv, skb, tx_cmd, info, hdr, sta_id);
  307. iwl_dbg_log_tx_data_frame(priv, len, hdr);
  308. iwlagn_tx_cmd_build_rate(priv, tx_cmd, info, fc);
  309. iwl_update_stats(priv, true, fc, len);
  310. memset(&info->status, 0, sizeof(info->status));
  311. info->driver_data[0] = ctx;
  312. info->driver_data[1] = dev_cmd;
  313. if (iwl_trans_tx(trans(priv), skb, dev_cmd, ctx->ctxid, sta_id))
  314. goto drop_unlock_sta;
  315. spin_unlock(&priv->shrd->sta_lock);
  316. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  317. /*
  318. * Avoid atomic ops if it isn't an associated client.
  319. * Also, if this is a packet for aggregation, don't
  320. * increase the counter because the ucode will stop
  321. * aggregation queues when their respective station
  322. * goes to sleep.
  323. */
  324. if (sta_priv && sta_priv->client && !is_agg)
  325. atomic_inc(&sta_priv->pending_frames);
  326. return 0;
  327. drop_unlock_sta:
  328. if (dev_cmd)
  329. kmem_cache_free(priv->tx_cmd_pool, dev_cmd);
  330. spin_unlock(&priv->shrd->sta_lock);
  331. drop_unlock_priv:
  332. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  333. return -1;
  334. }
  335. int iwlagn_tx_agg_start(struct iwl_priv *priv, struct ieee80211_vif *vif,
  336. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  337. {
  338. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  339. int sta_id;
  340. int ret;
  341. IWL_DEBUG_HT(priv, "TX AGG request on ra = %pM tid = %d\n",
  342. sta->addr, tid);
  343. sta_id = iwl_sta_id(sta);
  344. if (sta_id == IWL_INVALID_STATION) {
  345. IWL_ERR(priv, "Start AGG on invalid station\n");
  346. return -ENXIO;
  347. }
  348. if (unlikely(tid >= IWL_MAX_TID_COUNT))
  349. return -EINVAL;
  350. if (priv->shrd->tid_data[sta_id][tid].agg.state != IWL_AGG_OFF) {
  351. IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n");
  352. return -ENXIO;
  353. }
  354. ret = iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
  355. if (ret)
  356. return ret;
  357. ret = iwl_trans_tx_agg_alloc(trans(priv), vif_priv->ctx->ctxid, sta_id,
  358. tid, ssn);
  359. return ret;
  360. }
  361. int iwlagn_tx_agg_stop(struct iwl_priv *priv, struct ieee80211_vif *vif,
  362. struct ieee80211_sta *sta, u16 tid)
  363. {
  364. int sta_id;
  365. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  366. sta_id = iwl_sta_id(sta);
  367. if (sta_id == IWL_INVALID_STATION) {
  368. IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
  369. return -ENXIO;
  370. }
  371. return iwl_trans_tx_agg_disable(trans(priv), vif_priv->ctx->ctxid,
  372. sta_id, tid);
  373. }
  374. static void iwlagn_non_agg_tx_status(struct iwl_priv *priv,
  375. struct iwl_rxon_context *ctx,
  376. const u8 *addr1)
  377. {
  378. struct ieee80211_sta *sta;
  379. struct iwl_station_priv *sta_priv;
  380. rcu_read_lock();
  381. sta = ieee80211_find_sta(ctx->vif, addr1);
  382. if (sta) {
  383. sta_priv = (void *)sta->drv_priv;
  384. /* avoid atomic ops if this isn't a client */
  385. if (sta_priv->client &&
  386. atomic_dec_return(&sta_priv->pending_frames) == 0)
  387. ieee80211_sta_block_awake(priv->hw, sta, false);
  388. }
  389. rcu_read_unlock();
  390. }
  391. /**
  392. * translate ucode response to mac80211 tx status control values
  393. */
  394. static void iwlagn_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
  395. struct ieee80211_tx_info *info)
  396. {
  397. struct ieee80211_tx_rate *r = &info->control.rates[0];
  398. info->antenna_sel_tx =
  399. ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
  400. if (rate_n_flags & RATE_MCS_HT_MSK)
  401. r->flags |= IEEE80211_TX_RC_MCS;
  402. if (rate_n_flags & RATE_MCS_GF_MSK)
  403. r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
  404. if (rate_n_flags & RATE_MCS_HT40_MSK)
  405. r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  406. if (rate_n_flags & RATE_MCS_DUP_MSK)
  407. r->flags |= IEEE80211_TX_RC_DUP_DATA;
  408. if (rate_n_flags & RATE_MCS_SGI_MSK)
  409. r->flags |= IEEE80211_TX_RC_SHORT_GI;
  410. r->idx = iwlagn_hwrate_to_mac80211_idx(rate_n_flags, info->band);
  411. }
  412. #ifdef CONFIG_IWLWIFI_DEBUG
  413. const char *iwl_get_tx_fail_reason(u32 status)
  414. {
  415. #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
  416. #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
  417. switch (status & TX_STATUS_MSK) {
  418. case TX_STATUS_SUCCESS:
  419. return "SUCCESS";
  420. TX_STATUS_POSTPONE(DELAY);
  421. TX_STATUS_POSTPONE(FEW_BYTES);
  422. TX_STATUS_POSTPONE(BT_PRIO);
  423. TX_STATUS_POSTPONE(QUIET_PERIOD);
  424. TX_STATUS_POSTPONE(CALC_TTAK);
  425. TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
  426. TX_STATUS_FAIL(SHORT_LIMIT);
  427. TX_STATUS_FAIL(LONG_LIMIT);
  428. TX_STATUS_FAIL(FIFO_UNDERRUN);
  429. TX_STATUS_FAIL(DRAIN_FLOW);
  430. TX_STATUS_FAIL(RFKILL_FLUSH);
  431. TX_STATUS_FAIL(LIFE_EXPIRE);
  432. TX_STATUS_FAIL(DEST_PS);
  433. TX_STATUS_FAIL(HOST_ABORTED);
  434. TX_STATUS_FAIL(BT_RETRY);
  435. TX_STATUS_FAIL(STA_INVALID);
  436. TX_STATUS_FAIL(FRAG_DROPPED);
  437. TX_STATUS_FAIL(TID_DISABLE);
  438. TX_STATUS_FAIL(FIFO_FLUSHED);
  439. TX_STATUS_FAIL(INSUFFICIENT_CF_POLL);
  440. TX_STATUS_FAIL(PASSIVE_NO_RX);
  441. TX_STATUS_FAIL(NO_BEACON_ON_RADAR);
  442. }
  443. return "UNKNOWN";
  444. #undef TX_STATUS_FAIL
  445. #undef TX_STATUS_POSTPONE
  446. }
  447. #endif /* CONFIG_IWLWIFI_DEBUG */
  448. static void iwlagn_count_agg_tx_err_status(struct iwl_priv *priv, u16 status)
  449. {
  450. status &= AGG_TX_STATUS_MSK;
  451. switch (status) {
  452. case AGG_TX_STATE_UNDERRUN_MSK:
  453. priv->reply_agg_tx_stats.underrun++;
  454. break;
  455. case AGG_TX_STATE_BT_PRIO_MSK:
  456. priv->reply_agg_tx_stats.bt_prio++;
  457. break;
  458. case AGG_TX_STATE_FEW_BYTES_MSK:
  459. priv->reply_agg_tx_stats.few_bytes++;
  460. break;
  461. case AGG_TX_STATE_ABORT_MSK:
  462. priv->reply_agg_tx_stats.abort++;
  463. break;
  464. case AGG_TX_STATE_LAST_SENT_TTL_MSK:
  465. priv->reply_agg_tx_stats.last_sent_ttl++;
  466. break;
  467. case AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK:
  468. priv->reply_agg_tx_stats.last_sent_try++;
  469. break;
  470. case AGG_TX_STATE_LAST_SENT_BT_KILL_MSK:
  471. priv->reply_agg_tx_stats.last_sent_bt_kill++;
  472. break;
  473. case AGG_TX_STATE_SCD_QUERY_MSK:
  474. priv->reply_agg_tx_stats.scd_query++;
  475. break;
  476. case AGG_TX_STATE_TEST_BAD_CRC32_MSK:
  477. priv->reply_agg_tx_stats.bad_crc32++;
  478. break;
  479. case AGG_TX_STATE_RESPONSE_MSK:
  480. priv->reply_agg_tx_stats.response++;
  481. break;
  482. case AGG_TX_STATE_DUMP_TX_MSK:
  483. priv->reply_agg_tx_stats.dump_tx++;
  484. break;
  485. case AGG_TX_STATE_DELAY_TX_MSK:
  486. priv->reply_agg_tx_stats.delay_tx++;
  487. break;
  488. default:
  489. priv->reply_agg_tx_stats.unknown++;
  490. break;
  491. }
  492. }
  493. static void iwl_rx_reply_tx_agg(struct iwl_priv *priv,
  494. struct iwlagn_tx_resp *tx_resp)
  495. {
  496. struct agg_tx_status *frame_status = &tx_resp->status;
  497. int tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
  498. IWLAGN_TX_RES_TID_POS;
  499. int sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
  500. IWLAGN_TX_RES_RA_POS;
  501. struct iwl_ht_agg *agg = &priv->shrd->tid_data[sta_id][tid].agg;
  502. u32 status = le16_to_cpu(tx_resp->status.status);
  503. int i;
  504. if (agg->wait_for_ba)
  505. IWL_DEBUG_TX_REPLY(priv,
  506. "got tx response w/o block-ack\n");
  507. agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  508. agg->wait_for_ba = (tx_resp->frame_count > 1);
  509. /*
  510. * If the BT kill count is non-zero, we'll get this
  511. * notification again.
  512. */
  513. if (tx_resp->bt_kill_count && tx_resp->frame_count == 1 &&
  514. priv->cfg->bt_params &&
  515. priv->cfg->bt_params->advanced_bt_coexist) {
  516. IWL_DEBUG_COEX(priv, "receive reply tx w/ bt_kill\n");
  517. }
  518. if (tx_resp->frame_count == 1)
  519. return;
  520. /* Construct bit-map of pending frames within Tx window */
  521. for (i = 0; i < tx_resp->frame_count; i++) {
  522. u16 fstatus = le16_to_cpu(frame_status[i].status);
  523. if (status & AGG_TX_STATUS_MSK)
  524. iwlagn_count_agg_tx_err_status(priv, fstatus);
  525. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  526. AGG_TX_STATE_ABORT_MSK))
  527. continue;
  528. IWL_DEBUG_TX_REPLY(priv, "status %s (0x%08x), "
  529. "try-count (0x%08x)\n",
  530. iwl_get_agg_tx_fail_reason(fstatus),
  531. fstatus & AGG_TX_STATUS_MSK,
  532. fstatus & AGG_TX_TRY_MSK);
  533. }
  534. }
  535. #ifdef CONFIG_IWLWIFI_DEBUG
  536. #define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x
  537. const char *iwl_get_agg_tx_fail_reason(u16 status)
  538. {
  539. status &= AGG_TX_STATUS_MSK;
  540. switch (status) {
  541. case AGG_TX_STATE_TRANSMITTED:
  542. return "SUCCESS";
  543. AGG_TX_STATE_FAIL(UNDERRUN_MSK);
  544. AGG_TX_STATE_FAIL(BT_PRIO_MSK);
  545. AGG_TX_STATE_FAIL(FEW_BYTES_MSK);
  546. AGG_TX_STATE_FAIL(ABORT_MSK);
  547. AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK);
  548. AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK);
  549. AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK);
  550. AGG_TX_STATE_FAIL(SCD_QUERY_MSK);
  551. AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK);
  552. AGG_TX_STATE_FAIL(RESPONSE_MSK);
  553. AGG_TX_STATE_FAIL(DUMP_TX_MSK);
  554. AGG_TX_STATE_FAIL(DELAY_TX_MSK);
  555. }
  556. return "UNKNOWN";
  557. }
  558. #endif /* CONFIG_IWLWIFI_DEBUG */
  559. static inline u32 iwlagn_get_scd_ssn(struct iwlagn_tx_resp *tx_resp)
  560. {
  561. return le32_to_cpup((__le32 *)&tx_resp->status +
  562. tx_resp->frame_count) & MAX_SN;
  563. }
  564. static void iwlagn_count_tx_err_status(struct iwl_priv *priv, u16 status)
  565. {
  566. status &= TX_STATUS_MSK;
  567. switch (status) {
  568. case TX_STATUS_POSTPONE_DELAY:
  569. priv->reply_tx_stats.pp_delay++;
  570. break;
  571. case TX_STATUS_POSTPONE_FEW_BYTES:
  572. priv->reply_tx_stats.pp_few_bytes++;
  573. break;
  574. case TX_STATUS_POSTPONE_BT_PRIO:
  575. priv->reply_tx_stats.pp_bt_prio++;
  576. break;
  577. case TX_STATUS_POSTPONE_QUIET_PERIOD:
  578. priv->reply_tx_stats.pp_quiet_period++;
  579. break;
  580. case TX_STATUS_POSTPONE_CALC_TTAK:
  581. priv->reply_tx_stats.pp_calc_ttak++;
  582. break;
  583. case TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY:
  584. priv->reply_tx_stats.int_crossed_retry++;
  585. break;
  586. case TX_STATUS_FAIL_SHORT_LIMIT:
  587. priv->reply_tx_stats.short_limit++;
  588. break;
  589. case TX_STATUS_FAIL_LONG_LIMIT:
  590. priv->reply_tx_stats.long_limit++;
  591. break;
  592. case TX_STATUS_FAIL_FIFO_UNDERRUN:
  593. priv->reply_tx_stats.fifo_underrun++;
  594. break;
  595. case TX_STATUS_FAIL_DRAIN_FLOW:
  596. priv->reply_tx_stats.drain_flow++;
  597. break;
  598. case TX_STATUS_FAIL_RFKILL_FLUSH:
  599. priv->reply_tx_stats.rfkill_flush++;
  600. break;
  601. case TX_STATUS_FAIL_LIFE_EXPIRE:
  602. priv->reply_tx_stats.life_expire++;
  603. break;
  604. case TX_STATUS_FAIL_DEST_PS:
  605. priv->reply_tx_stats.dest_ps++;
  606. break;
  607. case TX_STATUS_FAIL_HOST_ABORTED:
  608. priv->reply_tx_stats.host_abort++;
  609. break;
  610. case TX_STATUS_FAIL_BT_RETRY:
  611. priv->reply_tx_stats.bt_retry++;
  612. break;
  613. case TX_STATUS_FAIL_STA_INVALID:
  614. priv->reply_tx_stats.sta_invalid++;
  615. break;
  616. case TX_STATUS_FAIL_FRAG_DROPPED:
  617. priv->reply_tx_stats.frag_drop++;
  618. break;
  619. case TX_STATUS_FAIL_TID_DISABLE:
  620. priv->reply_tx_stats.tid_disable++;
  621. break;
  622. case TX_STATUS_FAIL_FIFO_FLUSHED:
  623. priv->reply_tx_stats.fifo_flush++;
  624. break;
  625. case TX_STATUS_FAIL_INSUFFICIENT_CF_POLL:
  626. priv->reply_tx_stats.insuff_cf_poll++;
  627. break;
  628. case TX_STATUS_FAIL_PASSIVE_NO_RX:
  629. priv->reply_tx_stats.fail_hw_drop++;
  630. break;
  631. case TX_STATUS_FAIL_NO_BEACON_ON_RADAR:
  632. priv->reply_tx_stats.sta_color_mismatch++;
  633. break;
  634. default:
  635. priv->reply_tx_stats.unknown++;
  636. break;
  637. }
  638. }
  639. static void iwlagn_set_tx_status(struct iwl_priv *priv,
  640. struct ieee80211_tx_info *info,
  641. struct iwlagn_tx_resp *tx_resp,
  642. bool is_agg)
  643. {
  644. u16 status = le16_to_cpu(tx_resp->status.status);
  645. info->status.rates[0].count = tx_resp->failure_frame + 1;
  646. if (is_agg)
  647. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  648. info->flags |= iwl_tx_status_to_mac80211(status);
  649. iwlagn_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
  650. info);
  651. if (!iwl_is_tx_success(status))
  652. iwlagn_count_tx_err_status(priv, status);
  653. }
  654. static void iwl_check_abort_status(struct iwl_priv *priv,
  655. u8 frame_count, u32 status)
  656. {
  657. if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
  658. IWL_ERR(priv, "Tx flush command to flush out all frames\n");
  659. if (!test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  660. queue_work(priv->shrd->workqueue, &priv->tx_flush);
  661. }
  662. }
  663. int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb,
  664. struct iwl_device_cmd *cmd)
  665. {
  666. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  667. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  668. int txq_id = SEQ_TO_QUEUE(sequence);
  669. int cmd_index __maybe_unused = SEQ_TO_INDEX(sequence);
  670. struct iwlagn_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  671. struct ieee80211_hdr *hdr;
  672. u32 status = le16_to_cpu(tx_resp->status.status);
  673. u32 ssn = iwlagn_get_scd_ssn(tx_resp);
  674. int tid;
  675. int sta_id;
  676. int freed;
  677. struct ieee80211_tx_info *info;
  678. unsigned long flags;
  679. struct sk_buff_head skbs;
  680. struct sk_buff *skb;
  681. struct iwl_rxon_context *ctx;
  682. bool is_agg = (txq_id >= IWLAGN_FIRST_AMPDU_QUEUE);
  683. tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
  684. IWLAGN_TX_RES_TID_POS;
  685. sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
  686. IWLAGN_TX_RES_RA_POS;
  687. spin_lock_irqsave(&priv->shrd->sta_lock, flags);
  688. if (is_agg)
  689. iwl_rx_reply_tx_agg(priv, tx_resp);
  690. if (tx_resp->frame_count == 1) {
  691. IWL_DEBUG_TX_REPLY(priv, "Q %d, ssn %d", txq_id, ssn);
  692. __skb_queue_head_init(&skbs);
  693. /*we can free until ssn % q.n_bd not inclusive */
  694. iwl_trans_reclaim(trans(priv), sta_id, tid, txq_id,
  695. ssn, status, &skbs);
  696. freed = 0;
  697. while (!skb_queue_empty(&skbs)) {
  698. skb = __skb_dequeue(&skbs);
  699. hdr = (struct ieee80211_hdr *)skb->data;
  700. if (!ieee80211_is_data_qos(hdr->frame_control))
  701. priv->last_seq_ctl = tx_resp->seq_ctl;
  702. info = IEEE80211_SKB_CB(skb);
  703. ctx = info->driver_data[0];
  704. kmem_cache_free(priv->tx_cmd_pool,
  705. (info->driver_data[1]));
  706. memset(&info->status, 0, sizeof(info->status));
  707. if (status == TX_STATUS_FAIL_PASSIVE_NO_RX &&
  708. iwl_is_associated_ctx(ctx) && ctx->vif &&
  709. ctx->vif->type == NL80211_IFTYPE_STATION) {
  710. ctx->last_tx_rejected = true;
  711. iwl_trans_stop_queue(trans(priv), txq_id,
  712. "Tx on passive channel");
  713. IWL_DEBUG_TX_REPLY(priv,
  714. "TXQ %d status %s (0x%08x) "
  715. "rate_n_flags 0x%x retries %d\n",
  716. txq_id,
  717. iwl_get_tx_fail_reason(status),
  718. status,
  719. le32_to_cpu(tx_resp->rate_n_flags),
  720. tx_resp->failure_frame);
  721. IWL_DEBUG_TX_REPLY(priv,
  722. "FrameCnt = %d, idx=%d\n",
  723. tx_resp->frame_count, cmd_index);
  724. }
  725. /* check if BAR is needed */
  726. if (is_agg && !iwl_is_tx_success(status))
  727. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  728. iwlagn_set_tx_status(priv, IEEE80211_SKB_CB(skb),
  729. tx_resp, is_agg);
  730. if (!is_agg)
  731. iwlagn_non_agg_tx_status(priv, ctx, hdr->addr1);
  732. ieee80211_tx_status_irqsafe(priv->hw, skb);
  733. freed++;
  734. }
  735. WARN_ON(!is_agg && freed != 1);
  736. }
  737. iwl_check_abort_status(priv, tx_resp->frame_count, status);
  738. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  739. return 0;
  740. }
  741. /**
  742. * iwlagn_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
  743. *
  744. * Handles block-acknowledge notification from device, which reports success
  745. * of frames sent via aggregation.
  746. */
  747. int iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
  748. struct iwl_rx_mem_buffer *rxb,
  749. struct iwl_device_cmd *cmd)
  750. {
  751. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  752. struct iwl_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
  753. struct iwl_ht_agg *agg;
  754. struct sk_buff_head reclaimed_skbs;
  755. struct ieee80211_tx_info *info;
  756. struct ieee80211_hdr *hdr;
  757. struct sk_buff *skb;
  758. unsigned long flags;
  759. int sta_id;
  760. int tid;
  761. int freed;
  762. /* "flow" corresponds to Tx queue */
  763. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  764. /* "ssn" is start of block-ack Tx window, corresponds to index
  765. * (in Tx queue's circular buffer) of first TFD/frame in window */
  766. u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
  767. if (scd_flow >= hw_params(priv).max_txq_num) {
  768. IWL_ERR(priv,
  769. "BUG_ON scd_flow is bigger than number of queues\n");
  770. return 0;
  771. }
  772. sta_id = ba_resp->sta_id;
  773. tid = ba_resp->tid;
  774. agg = &priv->shrd->tid_data[sta_id][tid].agg;
  775. spin_lock_irqsave(&priv->shrd->sta_lock, flags);
  776. if (unlikely(agg->txq_id != scd_flow)) {
  777. /*
  778. * FIXME: this is a uCode bug which need to be addressed,
  779. * log the information and return for now!
  780. * since it is possible happen very often and in order
  781. * not to fill the syslog, don't enable the logging by default
  782. */
  783. IWL_DEBUG_TX_REPLY(priv,
  784. "BA scd_flow %d does not match txq_id %d\n",
  785. scd_flow, agg->txq_id);
  786. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  787. return 0;
  788. }
  789. if (unlikely(!agg->wait_for_ba)) {
  790. if (unlikely(ba_resp->bitmap))
  791. IWL_ERR(priv, "Received BA when not expected\n");
  792. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  793. return 0;
  794. }
  795. IWL_DEBUG_TX_REPLY(priv, "REPLY_COMPRESSED_BA [%d] Received from %pM, "
  796. "sta_id = %d\n",
  797. agg->wait_for_ba,
  798. (u8 *) &ba_resp->sta_addr_lo32,
  799. ba_resp->sta_id);
  800. IWL_DEBUG_TX_REPLY(priv, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, "
  801. "scd_flow = %d, scd_ssn = %d\n",
  802. ba_resp->tid, ba_resp->seq_ctl,
  803. (unsigned long long)le64_to_cpu(ba_resp->bitmap),
  804. scd_flow, ba_resp_scd_ssn);
  805. /* Mark that the expected block-ack response arrived */
  806. agg->wait_for_ba = false;
  807. /* Sanity check values reported by uCode */
  808. if (ba_resp->txed_2_done > ba_resp->txed) {
  809. IWL_DEBUG_TX_REPLY(priv,
  810. "bogus sent(%d) and ack(%d) count\n",
  811. ba_resp->txed, ba_resp->txed_2_done);
  812. /*
  813. * set txed_2_done = txed,
  814. * so it won't impact rate scale
  815. */
  816. ba_resp->txed = ba_resp->txed_2_done;
  817. }
  818. IWL_DEBUG_HT(priv, "agg frames sent:%d, acked:%d\n",
  819. ba_resp->txed, ba_resp->txed_2_done);
  820. __skb_queue_head_init(&reclaimed_skbs);
  821. /* Release all TFDs before the SSN, i.e. all TFDs in front of
  822. * block-ack window (we assume that they've been successfully
  823. * transmitted ... if not, it's too late anyway). */
  824. iwl_trans_reclaim(trans(priv), sta_id, tid, scd_flow, ba_resp_scd_ssn,
  825. 0, &reclaimed_skbs);
  826. freed = 0;
  827. while (!skb_queue_empty(&reclaimed_skbs)) {
  828. skb = __skb_dequeue(&reclaimed_skbs);
  829. hdr = (struct ieee80211_hdr *)skb->data;
  830. if (ieee80211_is_data_qos(hdr->frame_control))
  831. freed++;
  832. else
  833. WARN_ON_ONCE(1);
  834. info = IEEE80211_SKB_CB(skb);
  835. kmem_cache_free(priv->tx_cmd_pool, (info->driver_data[1]));
  836. if (freed == 1) {
  837. /* this is the first skb we deliver in this batch */
  838. /* put the rate scaling data there */
  839. info = IEEE80211_SKB_CB(skb);
  840. memset(&info->status, 0, sizeof(info->status));
  841. info->flags |= IEEE80211_TX_STAT_ACK;
  842. info->flags |= IEEE80211_TX_STAT_AMPDU;
  843. info->status.ampdu_ack_len = ba_resp->txed_2_done;
  844. info->status.ampdu_len = ba_resp->txed;
  845. iwlagn_hwrate_to_tx_control(priv, agg->rate_n_flags,
  846. info);
  847. }
  848. ieee80211_tx_status_irqsafe(priv->hw, skb);
  849. }
  850. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  851. return 0;
  852. }