iwl-trans-tx-pcie.c 30 KB

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