iwl-trans-pcie-tx.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  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/etherdevice.h>
  30. #include <linux/slab.h>
  31. #include <linux/sched.h>
  32. #include "iwl-debug.h"
  33. #include "iwl-csr.h"
  34. #include "iwl-prph.h"
  35. #include "iwl-io.h"
  36. #include "iwl-agn-hw.h"
  37. #include "iwl-op-mode.h"
  38. #include "iwl-trans-pcie-int.h"
  39. #define IWL_TX_CRC_SIZE 4
  40. #define IWL_TX_DELIMITER_SIZE 4
  41. /*
  42. * mac80211 queues, ACs, hardware queues, FIFOs.
  43. *
  44. * Cf. http://wireless.kernel.org/en/developers/Documentation/mac80211/queues
  45. *
  46. * Mac80211 uses the following numbers, which we get as from it
  47. * by way of skb_get_queue_mapping(skb):
  48. *
  49. * VO 0
  50. * VI 1
  51. * BE 2
  52. * BK 3
  53. *
  54. *
  55. * Regular (not A-MPDU) frames are put into hardware queues corresponding
  56. * to the FIFOs, see comments in iwl-prph.h. Aggregated frames get their
  57. * own queue per aggregation session (RA/TID combination), such queues are
  58. * set up to map into FIFOs too, for which we need an AC->FIFO mapping. In
  59. * order to map frames to the right queue, we also need an AC->hw queue
  60. * mapping. This is implemented here.
  61. *
  62. * Due to the way hw queues are set up (by the hw specific code), the AC->hw
  63. * queue mapping is the identity mapping.
  64. */
  65. static const u8 tid_to_ac[] = {
  66. IEEE80211_AC_BE,
  67. IEEE80211_AC_BK,
  68. IEEE80211_AC_BK,
  69. IEEE80211_AC_BE,
  70. IEEE80211_AC_VI,
  71. IEEE80211_AC_VI,
  72. IEEE80211_AC_VO,
  73. IEEE80211_AC_VO
  74. };
  75. /**
  76. * iwl_trans_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  77. */
  78. void iwl_trans_txq_update_byte_cnt_tbl(struct iwl_trans *trans,
  79. struct iwl_tx_queue *txq,
  80. u16 byte_cnt)
  81. {
  82. struct iwlagn_scd_bc_tbl *scd_bc_tbl;
  83. struct iwl_trans_pcie *trans_pcie =
  84. IWL_TRANS_GET_PCIE_TRANS(trans);
  85. int write_ptr = txq->q.write_ptr;
  86. int txq_id = txq->q.id;
  87. u8 sec_ctl = 0;
  88. u8 sta_id = 0;
  89. u16 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  90. __le16 bc_ent;
  91. struct iwl_tx_cmd *tx_cmd =
  92. (struct iwl_tx_cmd *) txq->cmd[txq->q.write_ptr]->payload;
  93. scd_bc_tbl = trans_pcie->scd_bc_tbls.addr;
  94. WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
  95. sta_id = tx_cmd->sta_id;
  96. sec_ctl = tx_cmd->sec_ctl;
  97. switch (sec_ctl & TX_CMD_SEC_MSK) {
  98. case TX_CMD_SEC_CCM:
  99. len += CCMP_MIC_LEN;
  100. break;
  101. case TX_CMD_SEC_TKIP:
  102. len += TKIP_ICV_LEN;
  103. break;
  104. case TX_CMD_SEC_WEP:
  105. len += WEP_IV_LEN + WEP_ICV_LEN;
  106. break;
  107. }
  108. bc_ent = cpu_to_le16((len & 0xFFF) | (sta_id << 12));
  109. scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent;
  110. if (write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  111. scd_bc_tbl[txq_id].
  112. tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] = bc_ent;
  113. }
  114. /**
  115. * iwl_txq_update_write_ptr - Send new write index to hardware
  116. */
  117. void iwl_txq_update_write_ptr(struct iwl_trans *trans, struct iwl_tx_queue *txq)
  118. {
  119. u32 reg = 0;
  120. int txq_id = txq->q.id;
  121. if (txq->need_update == 0)
  122. return;
  123. if (cfg(trans)->base_params->shadow_reg_enable) {
  124. /* shadow register enabled */
  125. iwl_write32(trans, HBUS_TARG_WRPTR,
  126. txq->q.write_ptr | (txq_id << 8));
  127. } else {
  128. /* if we're trying to save power */
  129. if (test_bit(STATUS_POWER_PMI, &trans->shrd->status)) {
  130. /* wake up nic if it's powered down ...
  131. * uCode will wake up, and interrupt us again, so next
  132. * time we'll skip this part. */
  133. reg = iwl_read32(trans, CSR_UCODE_DRV_GP1);
  134. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  135. IWL_DEBUG_INFO(trans,
  136. "Tx queue %d requesting wakeup,"
  137. " GP1 = 0x%x\n", txq_id, reg);
  138. iwl_set_bit(trans, CSR_GP_CNTRL,
  139. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  140. return;
  141. }
  142. iwl_write_direct32(trans, HBUS_TARG_WRPTR,
  143. txq->q.write_ptr | (txq_id << 8));
  144. /*
  145. * else not in power-save mode,
  146. * uCode will never sleep when we're
  147. * trying to tx (during RFKILL, we're not trying to tx).
  148. */
  149. } else
  150. iwl_write32(trans, HBUS_TARG_WRPTR,
  151. txq->q.write_ptr | (txq_id << 8));
  152. }
  153. txq->need_update = 0;
  154. }
  155. static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
  156. {
  157. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  158. dma_addr_t addr = get_unaligned_le32(&tb->lo);
  159. if (sizeof(dma_addr_t) > sizeof(u32))
  160. addr |=
  161. ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
  162. return addr;
  163. }
  164. static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
  165. {
  166. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  167. return le16_to_cpu(tb->hi_n_len) >> 4;
  168. }
  169. static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
  170. dma_addr_t addr, u16 len)
  171. {
  172. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  173. u16 hi_n_len = len << 4;
  174. put_unaligned_le32(addr, &tb->lo);
  175. if (sizeof(dma_addr_t) > sizeof(u32))
  176. hi_n_len |= ((addr >> 16) >> 16) & 0xF;
  177. tb->hi_n_len = cpu_to_le16(hi_n_len);
  178. tfd->num_tbs = idx + 1;
  179. }
  180. static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
  181. {
  182. return tfd->num_tbs & 0x1f;
  183. }
  184. static void iwlagn_unmap_tfd(struct iwl_trans *trans, struct iwl_cmd_meta *meta,
  185. struct iwl_tfd *tfd, enum dma_data_direction dma_dir)
  186. {
  187. int i;
  188. int num_tbs;
  189. /* Sanity check on number of chunks */
  190. num_tbs = iwl_tfd_get_num_tbs(tfd);
  191. if (num_tbs >= IWL_NUM_OF_TBS) {
  192. IWL_ERR(trans, "Too many chunks: %i\n", num_tbs);
  193. /* @todo issue fatal error, it is quite serious situation */
  194. return;
  195. }
  196. /* Unmap tx_cmd */
  197. if (num_tbs)
  198. dma_unmap_single(trans->dev,
  199. dma_unmap_addr(meta, mapping),
  200. dma_unmap_len(meta, len),
  201. DMA_BIDIRECTIONAL);
  202. /* Unmap chunks, if any. */
  203. for (i = 1; i < num_tbs; i++)
  204. dma_unmap_single(trans->dev, iwl_tfd_tb_get_addr(tfd, i),
  205. iwl_tfd_tb_get_len(tfd, i), dma_dir);
  206. }
  207. /**
  208. * iwlagn_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  209. * @trans - transport private data
  210. * @txq - tx queue
  211. * @index - the index of the TFD to be freed
  212. *@dma_dir - the direction of the DMA mapping
  213. *
  214. * Does NOT advance any TFD circular buffer read/write indexes
  215. * Does NOT free the TFD itself (which is within circular buffer)
  216. */
  217. void iwlagn_txq_free_tfd(struct iwl_trans *trans, struct iwl_tx_queue *txq,
  218. int index, enum dma_data_direction dma_dir)
  219. {
  220. struct iwl_tfd *tfd_tmp = txq->tfds;
  221. lockdep_assert_held(&txq->lock);
  222. iwlagn_unmap_tfd(trans, &txq->meta[index], &tfd_tmp[index], dma_dir);
  223. /* free SKB */
  224. if (txq->skbs) {
  225. struct sk_buff *skb;
  226. skb = txq->skbs[index];
  227. /* Can be called from irqs-disabled context
  228. * If skb is not NULL, it means that the whole queue is being
  229. * freed and that the queue is not empty - free the skb
  230. */
  231. if (skb) {
  232. iwl_op_mode_free_skb(trans->op_mode, skb);
  233. txq->skbs[index] = NULL;
  234. }
  235. }
  236. }
  237. int iwlagn_txq_attach_buf_to_tfd(struct iwl_trans *trans,
  238. struct iwl_tx_queue *txq,
  239. dma_addr_t addr, u16 len,
  240. u8 reset)
  241. {
  242. struct iwl_queue *q;
  243. struct iwl_tfd *tfd, *tfd_tmp;
  244. u32 num_tbs;
  245. q = &txq->q;
  246. tfd_tmp = txq->tfds;
  247. tfd = &tfd_tmp[q->write_ptr];
  248. if (reset)
  249. memset(tfd, 0, sizeof(*tfd));
  250. num_tbs = iwl_tfd_get_num_tbs(tfd);
  251. /* Each TFD can point to a maximum 20 Tx buffers */
  252. if (num_tbs >= IWL_NUM_OF_TBS) {
  253. IWL_ERR(trans, "Error can not send more than %d chunks\n",
  254. IWL_NUM_OF_TBS);
  255. return -EINVAL;
  256. }
  257. if (WARN_ON(addr & ~DMA_BIT_MASK(36)))
  258. return -EINVAL;
  259. if (unlikely(addr & ~IWL_TX_DMA_MASK))
  260. IWL_ERR(trans, "Unaligned address = %llx\n",
  261. (unsigned long long)addr);
  262. iwl_tfd_set_tb(tfd, num_tbs, addr, len);
  263. return 0;
  264. }
  265. /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
  266. * DMA services
  267. *
  268. * Theory of operation
  269. *
  270. * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
  271. * of buffer descriptors, each of which points to one or more data buffers for
  272. * the device to read from or fill. Driver and device exchange status of each
  273. * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
  274. * entries in each circular buffer, to protect against confusing empty and full
  275. * queue states.
  276. *
  277. * The device reads or writes the data in the queues via the device's several
  278. * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
  279. *
  280. * For Tx queue, there are low mark and high mark limits. If, after queuing
  281. * the packet for Tx, free space become < low mark, Tx queue stopped. When
  282. * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
  283. * Tx queue resumed.
  284. *
  285. ***************************************************/
  286. int iwl_queue_space(const struct iwl_queue *q)
  287. {
  288. int s = q->read_ptr - q->write_ptr;
  289. if (q->read_ptr > q->write_ptr)
  290. s -= q->n_bd;
  291. if (s <= 0)
  292. s += q->n_window;
  293. /* keep some reserve to not confuse empty and full situations */
  294. s -= 2;
  295. if (s < 0)
  296. s = 0;
  297. return s;
  298. }
  299. /**
  300. * iwl_queue_init - Initialize queue's high/low-water and read/write indexes
  301. */
  302. int iwl_queue_init(struct iwl_queue *q, int count, int slots_num, u32 id)
  303. {
  304. q->n_bd = count;
  305. q->n_window = slots_num;
  306. q->id = id;
  307. /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
  308. * and iwl_queue_dec_wrap are broken. */
  309. if (WARN_ON(!is_power_of_2(count)))
  310. return -EINVAL;
  311. /* slots_num must be power-of-two size, otherwise
  312. * get_cmd_index is broken. */
  313. if (WARN_ON(!is_power_of_2(slots_num)))
  314. return -EINVAL;
  315. q->low_mark = q->n_window / 4;
  316. if (q->low_mark < 4)
  317. q->low_mark = 4;
  318. q->high_mark = q->n_window / 8;
  319. if (q->high_mark < 2)
  320. q->high_mark = 2;
  321. q->write_ptr = q->read_ptr = 0;
  322. return 0;
  323. }
  324. static void iwlagn_txq_inval_byte_cnt_tbl(struct iwl_trans *trans,
  325. struct iwl_tx_queue *txq)
  326. {
  327. struct iwl_trans_pcie *trans_pcie =
  328. IWL_TRANS_GET_PCIE_TRANS(trans);
  329. struct iwlagn_scd_bc_tbl *scd_bc_tbl = trans_pcie->scd_bc_tbls.addr;
  330. int txq_id = txq->q.id;
  331. int read_ptr = txq->q.read_ptr;
  332. u8 sta_id = 0;
  333. __le16 bc_ent;
  334. struct iwl_tx_cmd *tx_cmd =
  335. (struct iwl_tx_cmd *) txq->cmd[txq->q.read_ptr]->payload;
  336. WARN_ON(read_ptr >= TFD_QUEUE_SIZE_MAX);
  337. if (txq_id != trans_pcie->cmd_queue)
  338. sta_id = tx_cmd->sta_id;
  339. bc_ent = cpu_to_le16(1 | (sta_id << 12));
  340. scd_bc_tbl[txq_id].tfd_offset[read_ptr] = bc_ent;
  341. if (read_ptr < TFD_QUEUE_SIZE_BC_DUP)
  342. scd_bc_tbl[txq_id].
  343. tfd_offset[TFD_QUEUE_SIZE_MAX + read_ptr] = bc_ent;
  344. }
  345. static int iwlagn_tx_queue_set_q2ratid(struct iwl_trans *trans, u16 ra_tid,
  346. u16 txq_id)
  347. {
  348. u32 tbl_dw_addr;
  349. u32 tbl_dw;
  350. u16 scd_q2ratid;
  351. struct iwl_trans_pcie *trans_pcie =
  352. IWL_TRANS_GET_PCIE_TRANS(trans);
  353. scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  354. tbl_dw_addr = trans_pcie->scd_base_addr +
  355. SCD_TRANS_TBL_OFFSET_QUEUE(txq_id);
  356. tbl_dw = iwl_read_targ_mem(trans, tbl_dw_addr);
  357. if (txq_id & 0x1)
  358. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  359. else
  360. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  361. iwl_write_targ_mem(trans, tbl_dw_addr, tbl_dw);
  362. return 0;
  363. }
  364. static void iwlagn_tx_queue_stop_scheduler(struct iwl_trans *trans, u16 txq_id)
  365. {
  366. /* Simply stop the queue, but don't change any configuration;
  367. * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
  368. iwl_write_prph(trans,
  369. SCD_QUEUE_STATUS_BITS(txq_id),
  370. (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)|
  371. (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  372. }
  373. void iwl_trans_set_wr_ptrs(struct iwl_trans *trans,
  374. int txq_id, u32 index)
  375. {
  376. IWL_DEBUG_TX_QUEUES(trans, "Q %d WrPtr: %d", txq_id, index & 0xff);
  377. iwl_write_direct32(trans, HBUS_TARG_WRPTR,
  378. (index & 0xff) | (txq_id << 8));
  379. iwl_write_prph(trans, SCD_QUEUE_RDPTR(txq_id), index);
  380. }
  381. void iwl_trans_tx_queue_set_status(struct iwl_trans *trans,
  382. struct iwl_tx_queue *txq,
  383. int tx_fifo_id, int scd_retry)
  384. {
  385. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  386. int txq_id = txq->q.id;
  387. int active =
  388. test_bit(txq_id, &trans_pcie->txq_ctx_active_msk) ? 1 : 0;
  389. iwl_write_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id),
  390. (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  391. (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) |
  392. (1 << SCD_QUEUE_STTS_REG_POS_WSL) |
  393. SCD_QUEUE_STTS_REG_MSK);
  394. txq->sched_retry = scd_retry;
  395. if (active)
  396. IWL_DEBUG_TX_QUEUES(trans, "Activate %s Queue %d on FIFO %d\n",
  397. scd_retry ? "BA" : "AC/CMD", txq_id, tx_fifo_id);
  398. else
  399. IWL_DEBUG_TX_QUEUES(trans, "Deactivate %s Queue %d\n",
  400. scd_retry ? "BA" : "AC/CMD", txq_id);
  401. }
  402. static inline int get_ac_from_tid(u16 tid)
  403. {
  404. if (likely(tid < ARRAY_SIZE(tid_to_ac)))
  405. return tid_to_ac[tid];
  406. /* no support for TIDs 8-15 yet */
  407. return -EINVAL;
  408. }
  409. static inline int get_fifo_from_tid(struct iwl_trans_pcie *trans_pcie,
  410. u8 ctx, u16 tid)
  411. {
  412. const u8 *ac_to_fifo = trans_pcie->ac_to_fifo[ctx];
  413. if (likely(tid < ARRAY_SIZE(tid_to_ac)))
  414. return ac_to_fifo[tid_to_ac[tid]];
  415. /* no support for TIDs 8-15 yet */
  416. return -EINVAL;
  417. }
  418. static inline bool is_agg_txqid_valid(struct iwl_trans *trans, int txq_id)
  419. {
  420. if (txq_id < IWLAGN_FIRST_AMPDU_QUEUE)
  421. return false;
  422. return txq_id < (IWLAGN_FIRST_AMPDU_QUEUE +
  423. hw_params(trans).num_ampdu_queues);
  424. }
  425. void iwl_trans_pcie_tx_agg_setup(struct iwl_trans *trans,
  426. enum iwl_rxon_context_id ctx, int sta_id,
  427. int tid, int frame_limit, u16 ssn)
  428. {
  429. int tx_fifo, txq_id;
  430. u16 ra_tid;
  431. unsigned long flags;
  432. struct iwl_trans_pcie *trans_pcie =
  433. IWL_TRANS_GET_PCIE_TRANS(trans);
  434. if (WARN_ON(sta_id == IWL_INVALID_STATION))
  435. return;
  436. if (WARN_ON(tid >= IWL_MAX_TID_COUNT))
  437. return;
  438. tx_fifo = get_fifo_from_tid(trans_pcie, ctx, tid);
  439. if (WARN_ON(tx_fifo < 0)) {
  440. IWL_ERR(trans, "txq_agg_setup, bad fifo: %d\n", tx_fifo);
  441. return;
  442. }
  443. txq_id = trans_pcie->agg_txq[sta_id][tid];
  444. if (WARN_ON_ONCE(!is_agg_txqid_valid(trans, txq_id))) {
  445. IWL_ERR(trans,
  446. "queue number out of range: %d, must be %d to %d\n",
  447. txq_id, IWLAGN_FIRST_AMPDU_QUEUE,
  448. IWLAGN_FIRST_AMPDU_QUEUE +
  449. hw_params(trans).num_ampdu_queues - 1);
  450. return;
  451. }
  452. ra_tid = BUILD_RAxTID(sta_id, tid);
  453. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  454. /* Stop this Tx queue before configuring it */
  455. iwlagn_tx_queue_stop_scheduler(trans, txq_id);
  456. /* Map receiver-address / traffic-ID to this queue */
  457. iwlagn_tx_queue_set_q2ratid(trans, ra_tid, txq_id);
  458. /* Set this queue as a chain-building queue */
  459. iwl_set_bits_prph(trans, SCD_QUEUECHAIN_SEL, (1<<txq_id));
  460. /* enable aggregations for the queue */
  461. iwl_set_bits_prph(trans, SCD_AGGR_SEL, (1<<txq_id));
  462. /* Place first TFD at index corresponding to start sequence number.
  463. * Assumes that ssn_idx is valid (!= 0xFFF) */
  464. trans_pcie->txq[txq_id].q.read_ptr = (ssn & 0xff);
  465. trans_pcie->txq[txq_id].q.write_ptr = (ssn & 0xff);
  466. iwl_trans_set_wr_ptrs(trans, txq_id, ssn);
  467. /* Set up Tx window size and frame limit for this queue */
  468. iwl_write_targ_mem(trans, trans_pcie->scd_base_addr +
  469. SCD_CONTEXT_QUEUE_OFFSET(txq_id) +
  470. sizeof(u32),
  471. ((frame_limit <<
  472. SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  473. SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  474. ((frame_limit <<
  475. SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  476. SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  477. iwl_set_bits_prph(trans, SCD_INTERRUPT_MASK, (1 << txq_id));
  478. /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
  479. iwl_trans_tx_queue_set_status(trans, &trans_pcie->txq[txq_id],
  480. tx_fifo, 1);
  481. trans_pcie->txq[txq_id].sta_id = sta_id;
  482. trans_pcie->txq[txq_id].tid = tid;
  483. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  484. }
  485. /*
  486. * Find first available (lowest unused) Tx Queue, mark it "active".
  487. * Called only when finding queue for aggregation.
  488. * Should never return anything < 7, because they should already
  489. * be in use as EDCA AC (0-3), Command (4), reserved (5, 6)
  490. */
  491. static int iwlagn_txq_ctx_activate_free(struct iwl_trans *trans)
  492. {
  493. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  494. int txq_id;
  495. for (txq_id = 0; txq_id < cfg(trans)->base_params->num_of_queues;
  496. txq_id++)
  497. if (!test_and_set_bit(txq_id,
  498. &trans_pcie->txq_ctx_active_msk))
  499. return txq_id;
  500. return -1;
  501. }
  502. int iwl_trans_pcie_tx_agg_alloc(struct iwl_trans *trans,
  503. int sta_id, int tid)
  504. {
  505. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  506. int txq_id;
  507. txq_id = iwlagn_txq_ctx_activate_free(trans);
  508. if (txq_id == -1) {
  509. IWL_ERR(trans, "No free aggregation queue available\n");
  510. return -ENXIO;
  511. }
  512. trans_pcie->agg_txq[sta_id][tid] = txq_id;
  513. iwl_set_swq_id(&trans_pcie->txq[txq_id], get_ac_from_tid(tid), txq_id);
  514. return 0;
  515. }
  516. int iwl_trans_pcie_tx_agg_disable(struct iwl_trans *trans, int sta_id, int tid)
  517. {
  518. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  519. u8 txq_id = trans_pcie->agg_txq[sta_id][tid];
  520. if (WARN_ON_ONCE(!is_agg_txqid_valid(trans, txq_id))) {
  521. IWL_ERR(trans,
  522. "queue number out of range: %d, must be %d to %d\n",
  523. txq_id, IWLAGN_FIRST_AMPDU_QUEUE,
  524. IWLAGN_FIRST_AMPDU_QUEUE +
  525. hw_params(trans).num_ampdu_queues - 1);
  526. return -EINVAL;
  527. }
  528. iwlagn_tx_queue_stop_scheduler(trans, txq_id);
  529. iwl_clear_bits_prph(trans, SCD_AGGR_SEL, (1 << txq_id));
  530. trans_pcie->agg_txq[sta_id][tid] = 0;
  531. trans_pcie->txq[txq_id].q.read_ptr = 0;
  532. trans_pcie->txq[txq_id].q.write_ptr = 0;
  533. /* supposes that ssn_idx is valid (!= 0xFFF) */
  534. iwl_trans_set_wr_ptrs(trans, txq_id, 0);
  535. iwl_clear_bits_prph(trans, SCD_INTERRUPT_MASK, (1 << txq_id));
  536. iwl_txq_ctx_deactivate(trans_pcie, txq_id);
  537. iwl_trans_tx_queue_set_status(trans, &trans_pcie->txq[txq_id], 0, 0);
  538. return 0;
  539. }
  540. /*************** HOST COMMAND QUEUE FUNCTIONS *****/
  541. /**
  542. * iwl_enqueue_hcmd - enqueue a uCode command
  543. * @priv: device private data point
  544. * @cmd: a point to the ucode command structure
  545. *
  546. * The function returns < 0 values to indicate the operation is
  547. * failed. On success, it turns the index (> 0) of command in the
  548. * command queue.
  549. */
  550. static int iwl_enqueue_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
  551. {
  552. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  553. struct iwl_tx_queue *txq = &trans_pcie->txq[trans_pcie->cmd_queue];
  554. struct iwl_queue *q = &txq->q;
  555. struct iwl_device_cmd *out_cmd;
  556. struct iwl_cmd_meta *out_meta;
  557. dma_addr_t phys_addr;
  558. u32 idx;
  559. u16 copy_size, cmd_size;
  560. bool had_nocopy = false;
  561. int i;
  562. u8 *cmd_dest;
  563. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  564. const void *trace_bufs[IWL_MAX_CMD_TFDS + 1] = {};
  565. int trace_lens[IWL_MAX_CMD_TFDS + 1] = {};
  566. int trace_idx;
  567. #endif
  568. if (test_bit(STATUS_FW_ERROR, &trans->shrd->status)) {
  569. IWL_WARN(trans, "fw recovery, no hcmd send\n");
  570. return -EIO;
  571. }
  572. copy_size = sizeof(out_cmd->hdr);
  573. cmd_size = sizeof(out_cmd->hdr);
  574. /* need one for the header if the first is NOCOPY */
  575. BUILD_BUG_ON(IWL_MAX_CMD_TFDS > IWL_NUM_OF_TBS - 1);
  576. for (i = 0; i < IWL_MAX_CMD_TFDS; i++) {
  577. if (!cmd->len[i])
  578. continue;
  579. if (cmd->dataflags[i] & IWL_HCMD_DFL_NOCOPY) {
  580. had_nocopy = true;
  581. } else {
  582. /* NOCOPY must not be followed by normal! */
  583. if (WARN_ON(had_nocopy))
  584. return -EINVAL;
  585. copy_size += cmd->len[i];
  586. }
  587. cmd_size += cmd->len[i];
  588. }
  589. /*
  590. * If any of the command structures end up being larger than
  591. * the TFD_MAX_PAYLOAD_SIZE and they aren't dynamically
  592. * allocated into separate TFDs, then we will need to
  593. * increase the size of the buffers.
  594. */
  595. if (WARN_ON(copy_size > TFD_MAX_PAYLOAD_SIZE))
  596. return -EINVAL;
  597. spin_lock_bh(&txq->lock);
  598. if (iwl_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) {
  599. spin_unlock_bh(&txq->lock);
  600. IWL_ERR(trans, "No space in command queue\n");
  601. iwl_op_mode_cmd_queue_full(trans->op_mode);
  602. return -ENOSPC;
  603. }
  604. idx = get_cmd_index(q, q->write_ptr);
  605. out_cmd = txq->cmd[idx];
  606. out_meta = &txq->meta[idx];
  607. memset(out_meta, 0, sizeof(*out_meta)); /* re-initialize to NULL */
  608. if (cmd->flags & CMD_WANT_SKB)
  609. out_meta->source = cmd;
  610. /* set up the header */
  611. out_cmd->hdr.cmd = cmd->id;
  612. out_cmd->hdr.flags = 0;
  613. out_cmd->hdr.sequence =
  614. cpu_to_le16(QUEUE_TO_SEQ(trans_pcie->cmd_queue) |
  615. INDEX_TO_SEQ(q->write_ptr));
  616. /* and copy the data that needs to be copied */
  617. cmd_dest = out_cmd->payload;
  618. for (i = 0; i < IWL_MAX_CMD_TFDS; i++) {
  619. if (!cmd->len[i])
  620. continue;
  621. if (cmd->dataflags[i] & IWL_HCMD_DFL_NOCOPY)
  622. break;
  623. memcpy(cmd_dest, cmd->data[i], cmd->len[i]);
  624. cmd_dest += cmd->len[i];
  625. }
  626. IWL_DEBUG_HC(trans, "Sending command %s (#%x), seq: 0x%04X, "
  627. "%d bytes at %d[%d]:%d\n",
  628. get_cmd_string(out_cmd->hdr.cmd),
  629. out_cmd->hdr.cmd,
  630. le16_to_cpu(out_cmd->hdr.sequence), cmd_size,
  631. q->write_ptr, idx, trans_pcie->cmd_queue);
  632. phys_addr = dma_map_single(trans->dev, &out_cmd->hdr, copy_size,
  633. DMA_BIDIRECTIONAL);
  634. if (unlikely(dma_mapping_error(trans->dev, phys_addr))) {
  635. idx = -ENOMEM;
  636. goto out;
  637. }
  638. dma_unmap_addr_set(out_meta, mapping, phys_addr);
  639. dma_unmap_len_set(out_meta, len, copy_size);
  640. iwlagn_txq_attach_buf_to_tfd(trans, txq,
  641. phys_addr, copy_size, 1);
  642. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  643. trace_bufs[0] = &out_cmd->hdr;
  644. trace_lens[0] = copy_size;
  645. trace_idx = 1;
  646. #endif
  647. for (i = 0; i < IWL_MAX_CMD_TFDS; i++) {
  648. if (!cmd->len[i])
  649. continue;
  650. if (!(cmd->dataflags[i] & IWL_HCMD_DFL_NOCOPY))
  651. continue;
  652. phys_addr = dma_map_single(trans->dev,
  653. (void *)cmd->data[i],
  654. cmd->len[i], DMA_BIDIRECTIONAL);
  655. if (dma_mapping_error(trans->dev, phys_addr)) {
  656. iwlagn_unmap_tfd(trans, out_meta,
  657. &txq->tfds[q->write_ptr],
  658. DMA_BIDIRECTIONAL);
  659. idx = -ENOMEM;
  660. goto out;
  661. }
  662. iwlagn_txq_attach_buf_to_tfd(trans, txq, phys_addr,
  663. cmd->len[i], 0);
  664. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  665. trace_bufs[trace_idx] = cmd->data[i];
  666. trace_lens[trace_idx] = cmd->len[i];
  667. trace_idx++;
  668. #endif
  669. }
  670. out_meta->flags = cmd->flags;
  671. txq->need_update = 1;
  672. /* check that tracing gets all possible blocks */
  673. BUILD_BUG_ON(IWL_MAX_CMD_TFDS + 1 != 3);
  674. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  675. trace_iwlwifi_dev_hcmd(trans->dev, cmd->flags,
  676. trace_bufs[0], trace_lens[0],
  677. trace_bufs[1], trace_lens[1],
  678. trace_bufs[2], trace_lens[2]);
  679. #endif
  680. /* Increment and update queue's write index */
  681. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  682. iwl_txq_update_write_ptr(trans, txq);
  683. out:
  684. spin_unlock_bh(&txq->lock);
  685. return idx;
  686. }
  687. /**
  688. * iwl_hcmd_queue_reclaim - Reclaim TX command queue entries already Tx'd
  689. *
  690. * When FW advances 'R' index, all entries between old and new 'R' index
  691. * need to be reclaimed. As result, some free space forms. If there is
  692. * enough free space (> low mark), wake the stack that feeds us.
  693. */
  694. static void iwl_hcmd_queue_reclaim(struct iwl_trans *trans, int txq_id,
  695. int idx)
  696. {
  697. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  698. struct iwl_tx_queue *txq = &trans_pcie->txq[txq_id];
  699. struct iwl_queue *q = &txq->q;
  700. int nfreed = 0;
  701. lockdep_assert_held(&txq->lock);
  702. if ((idx >= q->n_bd) || (iwl_queue_used(q, idx) == 0)) {
  703. IWL_ERR(trans, "%s: Read index for DMA queue txq id (%d), "
  704. "index %d is out of range [0-%d] %d %d.\n", __func__,
  705. txq_id, idx, q->n_bd, q->write_ptr, q->read_ptr);
  706. return;
  707. }
  708. for (idx = iwl_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
  709. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  710. if (nfreed++ > 0) {
  711. IWL_ERR(trans, "HCMD skipped: index (%d) %d %d\n", idx,
  712. q->write_ptr, q->read_ptr);
  713. iwl_op_mode_nic_error(trans->op_mode);
  714. }
  715. }
  716. }
  717. /**
  718. * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  719. * @rxb: Rx buffer to reclaim
  720. * @handler_status: return value of the handler of the command
  721. * (put in setup_rx_handlers)
  722. *
  723. * If an Rx buffer has an async callback associated with it the callback
  724. * will be executed. The attached skb (if present) will only be freed
  725. * if the callback returns 1
  726. */
  727. void iwl_tx_cmd_complete(struct iwl_trans *trans, struct iwl_rx_cmd_buffer *rxb,
  728. int handler_status)
  729. {
  730. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  731. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  732. int txq_id = SEQ_TO_QUEUE(sequence);
  733. int index = SEQ_TO_INDEX(sequence);
  734. int cmd_index;
  735. struct iwl_device_cmd *cmd;
  736. struct iwl_cmd_meta *meta;
  737. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  738. struct iwl_tx_queue *txq = &trans_pcie->txq[trans_pcie->cmd_queue];
  739. /* If a Tx command is being handled and it isn't in the actual
  740. * command queue then there a command routing bug has been introduced
  741. * in the queue management code. */
  742. if (WARN(txq_id != trans_pcie->cmd_queue,
  743. "wrong command queue %d (should be %d), sequence 0x%X readp=%d writep=%d\n",
  744. txq_id, trans_pcie->cmd_queue, sequence,
  745. trans_pcie->txq[trans_pcie->cmd_queue].q.read_ptr,
  746. trans_pcie->txq[trans_pcie->cmd_queue].q.write_ptr)) {
  747. iwl_print_hex_error(trans, pkt, 32);
  748. return;
  749. }
  750. spin_lock(&txq->lock);
  751. cmd_index = get_cmd_index(&txq->q, index);
  752. cmd = txq->cmd[cmd_index];
  753. meta = &txq->meta[cmd_index];
  754. txq->time_stamp = jiffies;
  755. iwlagn_unmap_tfd(trans, meta, &txq->tfds[index],
  756. DMA_BIDIRECTIONAL);
  757. /* Input error checking is done when commands are added to queue. */
  758. if (meta->flags & CMD_WANT_SKB) {
  759. struct page *p = rxb_steal_page(rxb);
  760. meta->source->resp_pkt = pkt;
  761. meta->source->_rx_page_addr = (unsigned long)page_address(p);
  762. meta->source->_rx_page_order = hw_params(trans).rx_page_order;
  763. meta->source->handler_status = handler_status;
  764. }
  765. iwl_hcmd_queue_reclaim(trans, txq_id, index);
  766. if (!(meta->flags & CMD_ASYNC)) {
  767. if (!test_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status)) {
  768. IWL_WARN(trans,
  769. "HCMD_ACTIVE already clear for command %s\n",
  770. get_cmd_string(cmd->hdr.cmd));
  771. }
  772. clear_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status);
  773. IWL_DEBUG_INFO(trans, "Clearing HCMD_ACTIVE for command %s\n",
  774. get_cmd_string(cmd->hdr.cmd));
  775. wake_up(&trans->wait_command_queue);
  776. }
  777. meta->flags = 0;
  778. spin_unlock(&txq->lock);
  779. }
  780. #define HOST_COMPLETE_TIMEOUT (2 * HZ)
  781. static int iwl_send_cmd_async(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
  782. {
  783. int ret;
  784. /* An asynchronous command can not expect an SKB to be set. */
  785. if (WARN_ON(cmd->flags & CMD_WANT_SKB))
  786. return -EINVAL;
  787. ret = iwl_enqueue_hcmd(trans, cmd);
  788. if (ret < 0) {
  789. IWL_ERR(trans,
  790. "Error sending %s: enqueue_hcmd failed: %d\n",
  791. get_cmd_string(cmd->id), ret);
  792. return ret;
  793. }
  794. return 0;
  795. }
  796. static int iwl_send_cmd_sync(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
  797. {
  798. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  799. int cmd_idx;
  800. int ret;
  801. IWL_DEBUG_INFO(trans, "Attempting to send sync command %s\n",
  802. get_cmd_string(cmd->id));
  803. if (test_bit(STATUS_FW_ERROR, &trans->shrd->status)) {
  804. IWL_ERR(trans, "Command %s failed: FW Error\n",
  805. get_cmd_string(cmd->id));
  806. return -EIO;
  807. }
  808. if (WARN_ON(test_and_set_bit(STATUS_HCMD_ACTIVE,
  809. &trans->shrd->status))) {
  810. IWL_ERR(trans, "Command %s: a command is already active!\n",
  811. get_cmd_string(cmd->id));
  812. return -EIO;
  813. }
  814. IWL_DEBUG_INFO(trans, "Setting HCMD_ACTIVE for command %s\n",
  815. get_cmd_string(cmd->id));
  816. cmd_idx = iwl_enqueue_hcmd(trans, cmd);
  817. if (cmd_idx < 0) {
  818. ret = cmd_idx;
  819. clear_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status);
  820. IWL_ERR(trans,
  821. "Error sending %s: enqueue_hcmd failed: %d\n",
  822. get_cmd_string(cmd->id), ret);
  823. return ret;
  824. }
  825. ret = wait_event_timeout(trans->wait_command_queue,
  826. !test_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status),
  827. HOST_COMPLETE_TIMEOUT);
  828. if (!ret) {
  829. if (test_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status)) {
  830. struct iwl_tx_queue *txq =
  831. &trans_pcie->txq[trans_pcie->cmd_queue];
  832. struct iwl_queue *q = &txq->q;
  833. IWL_ERR(trans,
  834. "Error sending %s: time out after %dms.\n",
  835. get_cmd_string(cmd->id),
  836. jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
  837. IWL_ERR(trans,
  838. "Current CMD queue read_ptr %d write_ptr %d\n",
  839. q->read_ptr, q->write_ptr);
  840. clear_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status);
  841. IWL_DEBUG_INFO(trans, "Clearing HCMD_ACTIVE for command"
  842. "%s\n", get_cmd_string(cmd->id));
  843. ret = -ETIMEDOUT;
  844. goto cancel;
  845. }
  846. }
  847. if ((cmd->flags & CMD_WANT_SKB) && !cmd->resp_pkt) {
  848. IWL_ERR(trans, "Error: Response NULL in '%s'\n",
  849. get_cmd_string(cmd->id));
  850. ret = -EIO;
  851. goto cancel;
  852. }
  853. return 0;
  854. cancel:
  855. if (cmd->flags & CMD_WANT_SKB) {
  856. /*
  857. * Cancel the CMD_WANT_SKB flag for the cmd in the
  858. * TX cmd queue. Otherwise in case the cmd comes
  859. * in later, it will possibly set an invalid
  860. * address (cmd->meta.source).
  861. */
  862. trans_pcie->txq[trans_pcie->cmd_queue].meta[cmd_idx].flags &=
  863. ~CMD_WANT_SKB;
  864. }
  865. if (cmd->resp_pkt) {
  866. iwl_free_resp(cmd);
  867. cmd->resp_pkt = NULL;
  868. }
  869. return ret;
  870. }
  871. int iwl_trans_pcie_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
  872. {
  873. if (cmd->flags & CMD_ASYNC)
  874. return iwl_send_cmd_async(trans, cmd);
  875. return iwl_send_cmd_sync(trans, cmd);
  876. }
  877. /* Frees buffers until index _not_ inclusive */
  878. int iwl_tx_queue_reclaim(struct iwl_trans *trans, int txq_id, int index,
  879. struct sk_buff_head *skbs)
  880. {
  881. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  882. struct iwl_tx_queue *txq = &trans_pcie->txq[txq_id];
  883. struct iwl_queue *q = &txq->q;
  884. int last_to_free;
  885. int freed = 0;
  886. /* This function is not meant to release cmd queue*/
  887. if (WARN_ON(txq_id == trans_pcie->cmd_queue))
  888. return 0;
  889. lockdep_assert_held(&txq->lock);
  890. /*Since we free until index _not_ inclusive, the one before index is
  891. * the last we will free. This one must be used */
  892. last_to_free = iwl_queue_dec_wrap(index, q->n_bd);
  893. if ((index >= q->n_bd) ||
  894. (iwl_queue_used(q, last_to_free) == 0)) {
  895. IWL_ERR(trans, "%s: Read index for DMA queue txq id (%d), "
  896. "last_to_free %d is out of range [0-%d] %d %d.\n",
  897. __func__, txq_id, last_to_free, q->n_bd,
  898. q->write_ptr, q->read_ptr);
  899. return 0;
  900. }
  901. if (WARN_ON(!skb_queue_empty(skbs)))
  902. return 0;
  903. for (;
  904. q->read_ptr != index;
  905. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  906. if (WARN_ON_ONCE(txq->skbs[txq->q.read_ptr] == NULL))
  907. continue;
  908. __skb_queue_tail(skbs, txq->skbs[txq->q.read_ptr]);
  909. txq->skbs[txq->q.read_ptr] = NULL;
  910. iwlagn_txq_inval_byte_cnt_tbl(trans, txq);
  911. iwlagn_txq_free_tfd(trans, txq, txq->q.read_ptr, DMA_TO_DEVICE);
  912. freed++;
  913. }
  914. return freed;
  915. }