iwl-tx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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/sched.h>
  31. #include <linux/slab.h>
  32. #include <net/mac80211.h>
  33. #include "iwl-eeprom.h"
  34. #include "iwl-dev.h"
  35. #include "iwl-core.h"
  36. #include "iwl-sta.h"
  37. #include "iwl-io.h"
  38. #include "iwl-helpers.h"
  39. /**
  40. * il_txq_update_write_ptr - Send new write index to hardware
  41. */
  42. void
  43. il_txq_update_write_ptr(struct il_priv *il, struct il_tx_queue *txq)
  44. {
  45. u32 reg = 0;
  46. int txq_id = txq->q.id;
  47. if (txq->need_update == 0)
  48. return;
  49. /* if we're trying to save power */
  50. if (test_bit(STATUS_POWER_PMI, &il->status)) {
  51. /* wake up nic if it's powered down ...
  52. * uCode will wake up, and interrupt us again, so next
  53. * time we'll skip this part. */
  54. reg = _il_rd(il, CSR_UCODE_DRV_GP1);
  55. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  56. D_INFO(
  57. "Tx queue %d requesting wakeup,"
  58. " GP1 = 0x%x\n", txq_id, reg);
  59. il_set_bit(il, CSR_GP_CNTRL,
  60. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  61. return;
  62. }
  63. il_wr(il, HBUS_TARG_WRPTR,
  64. txq->q.write_ptr | (txq_id << 8));
  65. /*
  66. * else not in power-save mode,
  67. * uCode will never sleep when we're
  68. * trying to tx (during RFKILL, we're not trying to tx).
  69. */
  70. } else
  71. _il_wr(il, HBUS_TARG_WRPTR,
  72. txq->q.write_ptr | (txq_id << 8));
  73. txq->need_update = 0;
  74. }
  75. EXPORT_SYMBOL(il_txq_update_write_ptr);
  76. /**
  77. * il_tx_queue_unmap - Unmap any remaining DMA mappings and free skb's
  78. */
  79. void il_tx_queue_unmap(struct il_priv *il, int txq_id)
  80. {
  81. struct il_tx_queue *txq = &il->txq[txq_id];
  82. struct il_queue *q = &txq->q;
  83. if (q->n_bd == 0)
  84. return;
  85. while (q->write_ptr != q->read_ptr) {
  86. il->cfg->ops->lib->txq_free_tfd(il, txq);
  87. q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd);
  88. }
  89. }
  90. EXPORT_SYMBOL(il_tx_queue_unmap);
  91. /**
  92. * il_tx_queue_free - Deallocate DMA queue.
  93. * @txq: Transmit queue to deallocate.
  94. *
  95. * Empty queue by removing and destroying all BD's.
  96. * Free all buffers.
  97. * 0-fill, but do not free "txq" descriptor structure.
  98. */
  99. void il_tx_queue_free(struct il_priv *il, int txq_id)
  100. {
  101. struct il_tx_queue *txq = &il->txq[txq_id];
  102. struct device *dev = &il->pci_dev->dev;
  103. int i;
  104. il_tx_queue_unmap(il, txq_id);
  105. /* De-alloc array of command/tx buffers */
  106. for (i = 0; i < TFD_TX_CMD_SLOTS; i++)
  107. kfree(txq->cmd[i]);
  108. /* De-alloc circular buffer of TFDs */
  109. if (txq->q.n_bd)
  110. dma_free_coherent(dev, il->hw_params.tfd_size *
  111. txq->q.n_bd, txq->tfds, txq->q.dma_addr);
  112. /* De-alloc array of per-TFD driver data */
  113. kfree(txq->txb);
  114. txq->txb = NULL;
  115. /* deallocate arrays */
  116. kfree(txq->cmd);
  117. kfree(txq->meta);
  118. txq->cmd = NULL;
  119. txq->meta = NULL;
  120. /* 0-fill queue descriptor structure */
  121. memset(txq, 0, sizeof(*txq));
  122. }
  123. EXPORT_SYMBOL(il_tx_queue_free);
  124. /**
  125. * il_cmd_queue_unmap - Unmap any remaining DMA mappings from command queue
  126. */
  127. void il_cmd_queue_unmap(struct il_priv *il)
  128. {
  129. struct il_tx_queue *txq = &il->txq[il->cmd_queue];
  130. struct il_queue *q = &txq->q;
  131. int i;
  132. if (q->n_bd == 0)
  133. return;
  134. while (q->read_ptr != q->write_ptr) {
  135. i = il_get_cmd_index(q, q->read_ptr, 0);
  136. if (txq->meta[i].flags & CMD_MAPPED) {
  137. pci_unmap_single(il->pci_dev,
  138. dma_unmap_addr(&txq->meta[i], mapping),
  139. dma_unmap_len(&txq->meta[i], len),
  140. PCI_DMA_BIDIRECTIONAL);
  141. txq->meta[i].flags = 0;
  142. }
  143. q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd);
  144. }
  145. i = q->n_window;
  146. if (txq->meta[i].flags & CMD_MAPPED) {
  147. pci_unmap_single(il->pci_dev,
  148. dma_unmap_addr(&txq->meta[i], mapping),
  149. dma_unmap_len(&txq->meta[i], len),
  150. PCI_DMA_BIDIRECTIONAL);
  151. txq->meta[i].flags = 0;
  152. }
  153. }
  154. EXPORT_SYMBOL(il_cmd_queue_unmap);
  155. /**
  156. * il_cmd_queue_free - Deallocate DMA queue.
  157. * @txq: Transmit queue to deallocate.
  158. *
  159. * Empty queue by removing and destroying all BD's.
  160. * Free all buffers.
  161. * 0-fill, but do not free "txq" descriptor structure.
  162. */
  163. void il_cmd_queue_free(struct il_priv *il)
  164. {
  165. struct il_tx_queue *txq = &il->txq[il->cmd_queue];
  166. struct device *dev = &il->pci_dev->dev;
  167. int i;
  168. il_cmd_queue_unmap(il);
  169. /* De-alloc array of command/tx buffers */
  170. for (i = 0; i <= TFD_CMD_SLOTS; i++)
  171. kfree(txq->cmd[i]);
  172. /* De-alloc circular buffer of TFDs */
  173. if (txq->q.n_bd)
  174. dma_free_coherent(dev, il->hw_params.tfd_size * txq->q.n_bd,
  175. txq->tfds, txq->q.dma_addr);
  176. /* deallocate arrays */
  177. kfree(txq->cmd);
  178. kfree(txq->meta);
  179. txq->cmd = NULL;
  180. txq->meta = NULL;
  181. /* 0-fill queue descriptor structure */
  182. memset(txq, 0, sizeof(*txq));
  183. }
  184. EXPORT_SYMBOL(il_cmd_queue_free);
  185. /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
  186. * DMA services
  187. *
  188. * Theory of operation
  189. *
  190. * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
  191. * of buffer descriptors, each of which points to one or more data buffers for
  192. * the device to read from or fill. Driver and device exchange status of each
  193. * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
  194. * entries in each circular buffer, to protect against confusing empty and full
  195. * queue states.
  196. *
  197. * The device reads or writes the data in the queues via the device's several
  198. * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
  199. *
  200. * For Tx queue, there are low mark and high mark limits. If, after queuing
  201. * the packet for Tx, free space become < low mark, Tx queue stopped. When
  202. * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
  203. * Tx queue resumed.
  204. *
  205. * See more detailed info in iwl-4965-hw.h.
  206. ***************************************************/
  207. int il_queue_space(const struct il_queue *q)
  208. {
  209. int s = q->read_ptr - q->write_ptr;
  210. if (q->read_ptr > q->write_ptr)
  211. s -= q->n_bd;
  212. if (s <= 0)
  213. s += q->n_window;
  214. /* keep some reserve to not confuse empty and full situations */
  215. s -= 2;
  216. if (s < 0)
  217. s = 0;
  218. return s;
  219. }
  220. EXPORT_SYMBOL(il_queue_space);
  221. /**
  222. * il_queue_init - Initialize queue's high/low-water and read/write indexes
  223. */
  224. static int il_queue_init(struct il_priv *il, struct il_queue *q,
  225. int count, int slots_num, u32 id)
  226. {
  227. q->n_bd = count;
  228. q->n_window = slots_num;
  229. q->id = id;
  230. /* count must be power-of-two size, otherwise il_queue_inc_wrap
  231. * and il_queue_dec_wrap are broken. */
  232. BUG_ON(!is_power_of_2(count));
  233. /* slots_num must be power-of-two size, otherwise
  234. * il_get_cmd_index is broken. */
  235. BUG_ON(!is_power_of_2(slots_num));
  236. q->low_mark = q->n_window / 4;
  237. if (q->low_mark < 4)
  238. q->low_mark = 4;
  239. q->high_mark = q->n_window / 8;
  240. if (q->high_mark < 2)
  241. q->high_mark = 2;
  242. q->write_ptr = q->read_ptr = 0;
  243. return 0;
  244. }
  245. /**
  246. * il_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
  247. */
  248. static int il_tx_queue_alloc(struct il_priv *il,
  249. struct il_tx_queue *txq, u32 id)
  250. {
  251. struct device *dev = &il->pci_dev->dev;
  252. size_t tfd_sz = il->hw_params.tfd_size * TFD_QUEUE_SIZE_MAX;
  253. /* Driver ilate data, only for Tx (not command) queues,
  254. * not shared with device. */
  255. if (id != il->cmd_queue) {
  256. txq->txb = kzalloc(sizeof(txq->txb[0]) *
  257. TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
  258. if (!txq->txb) {
  259. IL_ERR("kmalloc for auxiliary BD "
  260. "structures failed\n");
  261. goto error;
  262. }
  263. } else {
  264. txq->txb = NULL;
  265. }
  266. /* Circular buffer of transmit frame descriptors (TFDs),
  267. * shared with device */
  268. txq->tfds = dma_alloc_coherent(dev, tfd_sz, &txq->q.dma_addr,
  269. GFP_KERNEL);
  270. if (!txq->tfds) {
  271. IL_ERR("pci_alloc_consistent(%zd) failed\n", tfd_sz);
  272. goto error;
  273. }
  274. txq->q.id = id;
  275. return 0;
  276. error:
  277. kfree(txq->txb);
  278. txq->txb = NULL;
  279. return -ENOMEM;
  280. }
  281. /**
  282. * il_tx_queue_init - Allocate and initialize one tx/cmd queue
  283. */
  284. int il_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq,
  285. int slots_num, u32 txq_id)
  286. {
  287. int i, len;
  288. int ret;
  289. int actual_slots = slots_num;
  290. /*
  291. * Alloc buffer array for commands (Tx or other types of commands).
  292. * For the command queue (#4/#9), allocate command space + one big
  293. * command for scan, since scan command is very huge; the system will
  294. * not have two scans at the same time, so only one is needed.
  295. * For normal Tx queues (all other queues), no super-size command
  296. * space is needed.
  297. */
  298. if (txq_id == il->cmd_queue)
  299. actual_slots++;
  300. txq->meta = kzalloc(sizeof(struct il_cmd_meta) * actual_slots,
  301. GFP_KERNEL);
  302. txq->cmd = kzalloc(sizeof(struct il_device_cmd *) * actual_slots,
  303. GFP_KERNEL);
  304. if (!txq->meta || !txq->cmd)
  305. goto out_free_arrays;
  306. len = sizeof(struct il_device_cmd);
  307. for (i = 0; i < actual_slots; i++) {
  308. /* only happens for cmd queue */
  309. if (i == slots_num)
  310. len = IL_MAX_CMD_SIZE;
  311. txq->cmd[i] = kmalloc(len, GFP_KERNEL);
  312. if (!txq->cmd[i])
  313. goto err;
  314. }
  315. /* Alloc driver data array and TFD circular buffer */
  316. ret = il_tx_queue_alloc(il, txq, txq_id);
  317. if (ret)
  318. goto err;
  319. txq->need_update = 0;
  320. /*
  321. * For the default queues 0-3, set up the swq_id
  322. * already -- all others need to get one later
  323. * (if they need one at all).
  324. */
  325. if (txq_id < 4)
  326. il_set_swq_id(txq, txq_id, txq_id);
  327. /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
  328. * il_queue_inc_wrap and il_queue_dec_wrap are broken. */
  329. BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
  330. /* Initialize queue's high/low-water marks, and head/tail indexes */
  331. il_queue_init(il, &txq->q,
  332. TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
  333. /* Tell device where to find queue */
  334. il->cfg->ops->lib->txq_init(il, txq);
  335. return 0;
  336. err:
  337. for (i = 0; i < actual_slots; i++)
  338. kfree(txq->cmd[i]);
  339. out_free_arrays:
  340. kfree(txq->meta);
  341. kfree(txq->cmd);
  342. return -ENOMEM;
  343. }
  344. EXPORT_SYMBOL(il_tx_queue_init);
  345. void il_tx_queue_reset(struct il_priv *il, struct il_tx_queue *txq,
  346. int slots_num, u32 txq_id)
  347. {
  348. int actual_slots = slots_num;
  349. if (txq_id == il->cmd_queue)
  350. actual_slots++;
  351. memset(txq->meta, 0, sizeof(struct il_cmd_meta) * actual_slots);
  352. txq->need_update = 0;
  353. /* Initialize queue's high/low-water marks, and head/tail indexes */
  354. il_queue_init(il, &txq->q,
  355. TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
  356. /* Tell device where to find queue */
  357. il->cfg->ops->lib->txq_init(il, txq);
  358. }
  359. EXPORT_SYMBOL(il_tx_queue_reset);
  360. /*************** HOST COMMAND QUEUE FUNCTIONS *****/
  361. /**
  362. * il_enqueue_hcmd - enqueue a uCode command
  363. * @il: device ilate data point
  364. * @cmd: a point to the ucode command structure
  365. *
  366. * The function returns < 0 values to indicate the operation is
  367. * failed. On success, it turns the index (> 0) of command in the
  368. * command queue.
  369. */
  370. int il_enqueue_hcmd(struct il_priv *il, struct il_host_cmd *cmd)
  371. {
  372. struct il_tx_queue *txq = &il->txq[il->cmd_queue];
  373. struct il_queue *q = &txq->q;
  374. struct il_device_cmd *out_cmd;
  375. struct il_cmd_meta *out_meta;
  376. dma_addr_t phys_addr;
  377. unsigned long flags;
  378. int len;
  379. u32 idx;
  380. u16 fix_size;
  381. cmd->len = il->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len);
  382. fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
  383. /* If any of the command structures end up being larger than
  384. * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
  385. * we will need to increase the size of the TFD entries
  386. * Also, check to see if command buffer should not exceed the size
  387. * of device_cmd and max_cmd_size. */
  388. BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
  389. !(cmd->flags & CMD_SIZE_HUGE));
  390. BUG_ON(fix_size > IL_MAX_CMD_SIZE);
  391. if (il_is_rfkill(il) || il_is_ctkill(il)) {
  392. IL_WARN("Not sending command - %s KILL\n",
  393. il_is_rfkill(il) ? "RF" : "CT");
  394. return -EIO;
  395. }
  396. spin_lock_irqsave(&il->hcmd_lock, flags);
  397. if (il_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) {
  398. spin_unlock_irqrestore(&il->hcmd_lock, flags);
  399. IL_ERR("Restarting adapter due to command queue full\n");
  400. queue_work(il->workqueue, &il->restart);
  401. return -ENOSPC;
  402. }
  403. idx = il_get_cmd_index(q, q->write_ptr, cmd->flags & CMD_SIZE_HUGE);
  404. out_cmd = txq->cmd[idx];
  405. out_meta = &txq->meta[idx];
  406. if (WARN_ON(out_meta->flags & CMD_MAPPED)) {
  407. spin_unlock_irqrestore(&il->hcmd_lock, flags);
  408. return -ENOSPC;
  409. }
  410. memset(out_meta, 0, sizeof(*out_meta)); /* re-initialize to NULL */
  411. out_meta->flags = cmd->flags | CMD_MAPPED;
  412. if (cmd->flags & CMD_WANT_SKB)
  413. out_meta->source = cmd;
  414. if (cmd->flags & CMD_ASYNC)
  415. out_meta->callback = cmd->callback;
  416. out_cmd->hdr.cmd = cmd->id;
  417. memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
  418. /* At this point, the out_cmd now has all of the incoming cmd
  419. * information */
  420. out_cmd->hdr.flags = 0;
  421. out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(il->cmd_queue) |
  422. INDEX_TO_SEQ(q->write_ptr));
  423. if (cmd->flags & CMD_SIZE_HUGE)
  424. out_cmd->hdr.sequence |= SEQ_HUGE_FRAME;
  425. len = sizeof(struct il_device_cmd);
  426. if (idx == TFD_CMD_SLOTS)
  427. len = IL_MAX_CMD_SIZE;
  428. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  429. switch (out_cmd->hdr.cmd) {
  430. case REPLY_TX_LINK_QUALITY_CMD:
  431. case SENSITIVITY_CMD:
  432. D_HC_DUMP(
  433. "Sending command %s (#%x), seq: 0x%04X, "
  434. "%d bytes at %d[%d]:%d\n",
  435. il_get_cmd_string(out_cmd->hdr.cmd),
  436. out_cmd->hdr.cmd,
  437. le16_to_cpu(out_cmd->hdr.sequence), fix_size,
  438. q->write_ptr, idx, il->cmd_queue);
  439. break;
  440. default:
  441. D_HC("Sending command %s (#%x), seq: 0x%04X, "
  442. "%d bytes at %d[%d]:%d\n",
  443. il_get_cmd_string(out_cmd->hdr.cmd),
  444. out_cmd->hdr.cmd,
  445. le16_to_cpu(out_cmd->hdr.sequence), fix_size,
  446. q->write_ptr, idx, il->cmd_queue);
  447. }
  448. #endif
  449. txq->need_update = 1;
  450. if (il->cfg->ops->lib->txq_update_byte_cnt_tbl)
  451. /* Set up entry in queue's byte count circular buffer */
  452. il->cfg->ops->lib->txq_update_byte_cnt_tbl(il, txq, 0);
  453. phys_addr = pci_map_single(il->pci_dev, &out_cmd->hdr,
  454. fix_size, PCI_DMA_BIDIRECTIONAL);
  455. dma_unmap_addr_set(out_meta, mapping, phys_addr);
  456. dma_unmap_len_set(out_meta, len, fix_size);
  457. il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq,
  458. phys_addr, fix_size, 1,
  459. U32_PAD(cmd->len));
  460. /* Increment and update queue's write index */
  461. q->write_ptr = il_queue_inc_wrap(q->write_ptr, q->n_bd);
  462. il_txq_update_write_ptr(il, txq);
  463. spin_unlock_irqrestore(&il->hcmd_lock, flags);
  464. return idx;
  465. }
  466. /**
  467. * il_hcmd_queue_reclaim - Reclaim TX command queue entries already Tx'd
  468. *
  469. * When FW advances 'R' index, all entries between old and new 'R' index
  470. * need to be reclaimed. As result, some free space forms. If there is
  471. * enough free space (> low mark), wake the stack that feeds us.
  472. */
  473. static void il_hcmd_queue_reclaim(struct il_priv *il, int txq_id,
  474. int idx, int cmd_idx)
  475. {
  476. struct il_tx_queue *txq = &il->txq[txq_id];
  477. struct il_queue *q = &txq->q;
  478. int nfreed = 0;
  479. if (idx >= q->n_bd || il_queue_used(q, idx) == 0) {
  480. IL_ERR("Read index for DMA queue txq id (%d), index %d, "
  481. "is out of range [0-%d] %d %d.\n", txq_id,
  482. idx, q->n_bd, q->write_ptr, q->read_ptr);
  483. return;
  484. }
  485. for (idx = il_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
  486. q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  487. if (nfreed++ > 0) {
  488. IL_ERR("HCMD skipped: index (%d) %d %d\n", idx,
  489. q->write_ptr, q->read_ptr);
  490. queue_work(il->workqueue, &il->restart);
  491. }
  492. }
  493. }
  494. /**
  495. * il_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  496. * @rxb: Rx buffer to reclaim
  497. *
  498. * If an Rx buffer has an async callback associated with it the callback
  499. * will be executed. The attached skb (if present) will only be freed
  500. * if the callback returns 1
  501. */
  502. void
  503. il_tx_cmd_complete(struct il_priv *il, struct il_rx_mem_buffer *rxb)
  504. {
  505. struct il_rx_packet *pkt = rxb_addr(rxb);
  506. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  507. int txq_id = SEQ_TO_QUEUE(sequence);
  508. int index = SEQ_TO_INDEX(sequence);
  509. int cmd_index;
  510. bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
  511. struct il_device_cmd *cmd;
  512. struct il_cmd_meta *meta;
  513. struct il_tx_queue *txq = &il->txq[il->cmd_queue];
  514. unsigned long flags;
  515. /* If a Tx command is being handled and it isn't in the actual
  516. * command queue then there a command routing bug has been introduced
  517. * in the queue management code. */
  518. if (WARN(txq_id != il->cmd_queue,
  519. "wrong command queue %d (should be %d), sequence 0x%X readp=%d writep=%d\n",
  520. txq_id, il->cmd_queue, sequence,
  521. il->txq[il->cmd_queue].q.read_ptr,
  522. il->txq[il->cmd_queue].q.write_ptr)) {
  523. il_print_hex_error(il, pkt, 32);
  524. return;
  525. }
  526. cmd_index = il_get_cmd_index(&txq->q, index, huge);
  527. cmd = txq->cmd[cmd_index];
  528. meta = &txq->meta[cmd_index];
  529. txq->time_stamp = jiffies;
  530. pci_unmap_single(il->pci_dev,
  531. dma_unmap_addr(meta, mapping),
  532. dma_unmap_len(meta, len),
  533. PCI_DMA_BIDIRECTIONAL);
  534. /* Input error checking is done when commands are added to queue. */
  535. if (meta->flags & CMD_WANT_SKB) {
  536. meta->source->reply_page = (unsigned long)rxb_addr(rxb);
  537. rxb->page = NULL;
  538. } else if (meta->callback)
  539. meta->callback(il, cmd, pkt);
  540. spin_lock_irqsave(&il->hcmd_lock, flags);
  541. il_hcmd_queue_reclaim(il, txq_id, index, cmd_index);
  542. if (!(meta->flags & CMD_ASYNC)) {
  543. clear_bit(STATUS_HCMD_ACTIVE, &il->status);
  544. D_INFO("Clearing HCMD_ACTIVE for command %s\n",
  545. il_get_cmd_string(cmd->hdr.cmd));
  546. wake_up(&il->wait_command_queue);
  547. }
  548. /* Mark as unmapped */
  549. meta->flags = 0;
  550. spin_unlock_irqrestore(&il->hcmd_lock, flags);
  551. }
  552. EXPORT_SYMBOL(il_tx_cmd_complete);