iwl-agn-tx.c 31 KB

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