tx.c 40 KB

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