iwl-agn-tx.c 36 KB

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