iwl-agn-tx.c 39 KB

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