iwl-trans-tx-pcie.c 31 KB

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