Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 1f44780 | 2010-01-15 13:43:41 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved. |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 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: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 30 | #include <linux/etherdevice.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 31 | #include <linux/sched.h> |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 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 | |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 40 | /** |
| 41 | * iwl_txq_update_write_ptr - Send new write index to hardware |
| 42 | */ |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 43 | void iwl_txq_update_write_ptr(struct iwl_priv *priv, struct iwl_tx_queue *txq) |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 44 | { |
| 45 | u32 reg = 0; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 46 | int txq_id = txq->q.id; |
| 47 | |
| 48 | if (txq->need_update == 0) |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 49 | return; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 50 | |
| 51 | /* if we're trying to save power */ |
| 52 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 53 | /* wake up nic if it's powered down ... |
| 54 | * uCode will wake up, and interrupt us again, so next |
| 55 | * time we'll skip this part. */ |
| 56 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 57 | |
| 58 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Ben Cahill | 309e731 | 2009-11-06 14:53:03 -0800 | [diff] [blame] | 59 | IWL_DEBUG_INFO(priv, "Tx queue %d requesting wakeup, GP1 = 0x%x\n", |
| 60 | txq_id, reg); |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 61 | iwl_set_bit(priv, CSR_GP_CNTRL, |
| 62 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 63 | return; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 64 | } |
| 65 | |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 66 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
| 67 | txq->q.write_ptr | (txq_id << 8)); |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 68 | |
| 69 | /* else not in power-save mode, uCode will never sleep when we're |
| 70 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 71 | } else |
| 72 | iwl_write32(priv, HBUS_TARG_WRPTR, |
| 73 | txq->q.write_ptr | (txq_id << 8)); |
| 74 | |
| 75 | txq->need_update = 0; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 76 | } |
| 77 | EXPORT_SYMBOL(iwl_txq_update_write_ptr); |
| 78 | |
| 79 | |
Wey-Yi Guy | a239a8b | 2010-02-19 15:47:32 -0800 | [diff] [blame] | 80 | void iwl_free_tfds_in_queue(struct iwl_priv *priv, |
| 81 | int sta_id, int tid, int freed) |
| 82 | { |
| 83 | if (priv->stations[sta_id].tid[tid].tfds_in_queue >= freed) |
| 84 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 85 | else { |
| 86 | IWL_ERR(priv, "free more than tfds_in_queue (%u:%d)\n", |
| 87 | priv->stations[sta_id].tid[tid].tfds_in_queue, |
| 88 | freed); |
| 89 | priv->stations[sta_id].tid[tid].tfds_in_queue = 0; |
| 90 | } |
| 91 | } |
| 92 | EXPORT_SYMBOL(iwl_free_tfds_in_queue); |
| 93 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 94 | /** |
| 95 | * iwl_tx_queue_free - Deallocate DMA queue. |
| 96 | * @txq: Transmit queue to deallocate. |
| 97 | * |
| 98 | * Empty queue by removing and destroying all BD's. |
| 99 | * Free all buffers. |
| 100 | * 0-fill, but do not free "txq" descriptor structure. |
| 101 | */ |
Samuel Ortiz | a8e74e27 | 2009-01-23 13:45:14 -0800 | [diff] [blame] | 102 | void iwl_tx_queue_free(struct iwl_priv *priv, int txq_id) |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 103 | { |
Gregory Greenman | da99c4b | 2008-08-04 16:00:40 +0800 | [diff] [blame] | 104 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 105 | struct iwl_queue *q = &txq->q; |
Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 106 | struct device *dev = &priv->pci_dev->dev; |
Wey-Yi Guy | 71c55d9 | 2009-10-23 13:42:31 -0700 | [diff] [blame] | 107 | int i; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 108 | |
| 109 | if (q->n_bd == 0) |
| 110 | return; |
| 111 | |
| 112 | /* first, empty all BD's */ |
| 113 | for (; q->write_ptr != q->read_ptr; |
| 114 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 115 | priv->cfg->ops->lib->txq_free_tfd(priv, txq); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 116 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 117 | /* De-alloc array of command/tx buffers */ |
Tomas Winkler | 961ba60 | 2008-10-14 12:32:44 -0700 | [diff] [blame] | 118 | for (i = 0; i < TFD_TX_CMD_SLOTS; i++) |
Gregory Greenman | da99c4b | 2008-08-04 16:00:40 +0800 | [diff] [blame] | 119 | kfree(txq->cmd[i]); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 120 | |
| 121 | /* De-alloc circular buffer of TFDs */ |
| 122 | if (txq->q.n_bd) |
Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 123 | dma_free_coherent(dev, priv->hw_params.tfd_size * |
| 124 | txq->q.n_bd, txq->tfds, txq->q.dma_addr); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 125 | |
| 126 | /* De-alloc array of per-TFD driver data */ |
| 127 | kfree(txq->txb); |
| 128 | txq->txb = NULL; |
| 129 | |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 130 | /* deallocate arrays */ |
| 131 | kfree(txq->cmd); |
| 132 | kfree(txq->meta); |
| 133 | txq->cmd = NULL; |
| 134 | txq->meta = NULL; |
| 135 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 136 | /* 0-fill queue descriptor structure */ |
| 137 | memset(txq, 0, sizeof(*txq)); |
| 138 | } |
Samuel Ortiz | a8e74e27 | 2009-01-23 13:45:14 -0800 | [diff] [blame] | 139 | EXPORT_SYMBOL(iwl_tx_queue_free); |
Tomas Winkler | 961ba60 | 2008-10-14 12:32:44 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * iwl_cmd_queue_free - Deallocate DMA queue. |
| 143 | * @txq: Transmit queue to deallocate. |
| 144 | * |
| 145 | * Empty queue by removing and destroying all BD's. |
| 146 | * Free all buffers. |
| 147 | * 0-fill, but do not free "txq" descriptor structure. |
| 148 | */ |
Abhijeet Kolekar | 3e5d238 | 2009-03-17 21:51:49 -0700 | [diff] [blame] | 149 | void iwl_cmd_queue_free(struct iwl_priv *priv) |
Tomas Winkler | 961ba60 | 2008-10-14 12:32:44 -0700 | [diff] [blame] | 150 | { |
| 151 | struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 152 | struct iwl_queue *q = &txq->q; |
Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 153 | struct device *dev = &priv->pci_dev->dev; |
Wey-Yi Guy | 71c55d9 | 2009-10-23 13:42:31 -0700 | [diff] [blame] | 154 | int i; |
Tomas Winkler | 961ba60 | 2008-10-14 12:32:44 -0700 | [diff] [blame] | 155 | |
| 156 | if (q->n_bd == 0) |
| 157 | return; |
| 158 | |
Tomas Winkler | 961ba60 | 2008-10-14 12:32:44 -0700 | [diff] [blame] | 159 | /* De-alloc array of command/tx buffers */ |
| 160 | for (i = 0; i <= TFD_CMD_SLOTS; i++) |
| 161 | kfree(txq->cmd[i]); |
| 162 | |
| 163 | /* De-alloc circular buffer of TFDs */ |
| 164 | if (txq->q.n_bd) |
Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 165 | dma_free_coherent(dev, priv->hw_params.tfd_size * txq->q.n_bd, |
| 166 | txq->tfds, txq->q.dma_addr); |
Tomas Winkler | 961ba60 | 2008-10-14 12:32:44 -0700 | [diff] [blame] | 167 | |
Reinette Chatre | 2814298 | 2009-09-25 14:24:22 -0700 | [diff] [blame] | 168 | /* deallocate arrays */ |
| 169 | kfree(txq->cmd); |
| 170 | kfree(txq->meta); |
| 171 | txq->cmd = NULL; |
| 172 | txq->meta = NULL; |
| 173 | |
Tomas Winkler | 961ba60 | 2008-10-14 12:32:44 -0700 | [diff] [blame] | 174 | /* 0-fill queue descriptor structure */ |
| 175 | memset(txq, 0, sizeof(*txq)); |
| 176 | } |
Abhijeet Kolekar | 3e5d238 | 2009-03-17 21:51:49 -0700 | [diff] [blame] | 177 | EXPORT_SYMBOL(iwl_cmd_queue_free); |
| 178 | |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 179 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 180 | * DMA services |
| 181 | * |
| 182 | * Theory of operation |
| 183 | * |
| 184 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 185 | * of buffer descriptors, each of which points to one or more data buffers for |
| 186 | * the device to read from or fill. Driver and device exchange status of each |
| 187 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 188 | * entries in each circular buffer, to protect against confusing empty and full |
| 189 | * queue states. |
| 190 | * |
| 191 | * The device reads or writes the data in the queues via the device's several |
| 192 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
| 193 | * |
| 194 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 195 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 196 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 197 | * Tx queue resumed. |
| 198 | * |
| 199 | * See more detailed info in iwl-4965-hw.h. |
| 200 | ***************************************************/ |
| 201 | |
| 202 | int iwl_queue_space(const struct iwl_queue *q) |
| 203 | { |
| 204 | int s = q->read_ptr - q->write_ptr; |
| 205 | |
| 206 | if (q->read_ptr > q->write_ptr) |
| 207 | s -= q->n_bd; |
| 208 | |
| 209 | if (s <= 0) |
| 210 | s += q->n_window; |
| 211 | /* keep some reserve to not confuse empty and full situations */ |
| 212 | s -= 2; |
| 213 | if (s < 0) |
| 214 | s = 0; |
| 215 | return s; |
| 216 | } |
| 217 | EXPORT_SYMBOL(iwl_queue_space); |
| 218 | |
| 219 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 220 | /** |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 221 | * iwl_queue_init - Initialize queue's high/low-water and read/write indexes |
| 222 | */ |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 223 | static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q, |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 224 | int count, int slots_num, u32 id) |
| 225 | { |
| 226 | q->n_bd = count; |
| 227 | q->n_window = slots_num; |
| 228 | q->id = id; |
| 229 | |
| 230 | /* count must be power-of-two size, otherwise iwl_queue_inc_wrap |
| 231 | * and iwl_queue_dec_wrap are broken. */ |
| 232 | BUG_ON(!is_power_of_2(count)); |
| 233 | |
| 234 | /* slots_num must be power-of-two size, otherwise |
| 235 | * get_cmd_index is broken. */ |
| 236 | BUG_ON(!is_power_of_2(slots_num)); |
| 237 | |
| 238 | q->low_mark = q->n_window / 4; |
| 239 | if (q->low_mark < 4) |
| 240 | q->low_mark = 4; |
| 241 | |
| 242 | q->high_mark = q->n_window / 8; |
| 243 | if (q->high_mark < 2) |
| 244 | q->high_mark = 2; |
| 245 | |
| 246 | q->write_ptr = q->read_ptr = 0; |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 247 | q->last_read_ptr = 0; |
| 248 | q->repeat_same_read_ptr = 0; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * iwl_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 255 | */ |
| 256 | static int iwl_tx_queue_alloc(struct iwl_priv *priv, |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 257 | struct iwl_tx_queue *txq, u32 id) |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 258 | { |
Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 259 | struct device *dev = &priv->pci_dev->dev; |
Winkler, Tomas | 3978e5b | 2009-01-23 13:45:23 -0800 | [diff] [blame] | 260 | size_t tfd_sz = priv->hw_params.tfd_size * TFD_QUEUE_SIZE_MAX; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 261 | |
| 262 | /* Driver private data, only for Tx (not command) queues, |
| 263 | * not shared with device. */ |
| 264 | if (id != IWL_CMD_QUEUE_NUM) { |
| 265 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 266 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 267 | if (!txq->txb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 268 | IWL_ERR(priv, "kmalloc for auxiliary BD " |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 269 | "structures failed\n"); |
| 270 | goto error; |
| 271 | } |
Winkler, Tomas | 3978e5b | 2009-01-23 13:45:23 -0800 | [diff] [blame] | 272 | } else { |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 273 | txq->txb = NULL; |
Winkler, Tomas | 3978e5b | 2009-01-23 13:45:23 -0800 | [diff] [blame] | 274 | } |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 275 | |
| 276 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 277 | * shared with device */ |
Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 278 | txq->tfds = dma_alloc_coherent(dev, tfd_sz, &txq->q.dma_addr, |
| 279 | GFP_KERNEL); |
Tomas Winkler | 499b188 | 2008-10-14 12:32:48 -0700 | [diff] [blame] | 280 | if (!txq->tfds) { |
Winkler, Tomas | 3978e5b | 2009-01-23 13:45:23 -0800 | [diff] [blame] | 281 | IWL_ERR(priv, "pci_alloc_consistent(%zd) failed\n", tfd_sz); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 282 | goto error; |
| 283 | } |
| 284 | txq->q.id = id; |
| 285 | |
| 286 | return 0; |
| 287 | |
| 288 | error: |
| 289 | kfree(txq->txb); |
| 290 | txq->txb = NULL; |
| 291 | |
| 292 | return -ENOMEM; |
| 293 | } |
| 294 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 295 | /** |
| 296 | * iwl_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 297 | */ |
Samuel Ortiz | a8e74e27 | 2009-01-23 13:45:14 -0800 | [diff] [blame] | 298 | int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq, |
| 299 | int slots_num, u32 txq_id) |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 300 | { |
Gregory Greenman | da99c4b | 2008-08-04 16:00:40 +0800 | [diff] [blame] | 301 | int i, len; |
Tomas Winkler | 73b7d74 | 2008-09-03 11:18:48 +0800 | [diff] [blame] | 302 | int ret; |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 303 | int actual_slots = slots_num; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 304 | |
| 305 | /* |
| 306 | * Alloc buffer array for commands (Tx or other types of commands). |
| 307 | * For the command queue (#4), allocate command space + one big |
| 308 | * command for scan, since scan command is very huge; the system will |
| 309 | * not have two scans at the same time, so only one is needed. |
| 310 | * For normal Tx queues (all other queues), no super-size command |
| 311 | * space is needed. |
| 312 | */ |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 313 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 314 | actual_slots++; |
| 315 | |
| 316 | txq->meta = kzalloc(sizeof(struct iwl_cmd_meta) * actual_slots, |
| 317 | GFP_KERNEL); |
| 318 | txq->cmd = kzalloc(sizeof(struct iwl_device_cmd *) * actual_slots, |
| 319 | GFP_KERNEL); |
| 320 | |
| 321 | if (!txq->meta || !txq->cmd) |
| 322 | goto out_free_arrays; |
| 323 | |
| 324 | len = sizeof(struct iwl_device_cmd); |
| 325 | for (i = 0; i < actual_slots; i++) { |
| 326 | /* only happens for cmd queue */ |
| 327 | if (i == slots_num) |
Abhijeet Kolekar | 8961212 | 2010-02-19 11:49:49 -0800 | [diff] [blame] | 328 | len = IWL_MAX_CMD_SIZE; |
Gregory Greenman | da99c4b | 2008-08-04 16:00:40 +0800 | [diff] [blame] | 329 | |
John W. Linville | 4989885 | 2008-09-02 15:07:18 -0400 | [diff] [blame] | 330 | txq->cmd[i] = kmalloc(len, GFP_KERNEL); |
Gregory Greenman | da99c4b | 2008-08-04 16:00:40 +0800 | [diff] [blame] | 331 | if (!txq->cmd[i]) |
Tomas Winkler | 73b7d74 | 2008-09-03 11:18:48 +0800 | [diff] [blame] | 332 | goto err; |
Gregory Greenman | da99c4b | 2008-08-04 16:00:40 +0800 | [diff] [blame] | 333 | } |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 334 | |
| 335 | /* Alloc driver data array and TFD circular buffer */ |
Tomas Winkler | 73b7d74 | 2008-09-03 11:18:48 +0800 | [diff] [blame] | 336 | ret = iwl_tx_queue_alloc(priv, txq, txq_id); |
| 337 | if (ret) |
| 338 | goto err; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 339 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 340 | txq->need_update = 0; |
| 341 | |
Johannes Berg | 1a71655 | 2009-11-06 14:52:51 -0800 | [diff] [blame] | 342 | /* |
| 343 | * Aggregation TX queues will get their ID when aggregation begins; |
| 344 | * they overwrite the setting done here. The command FIFO doesn't |
| 345 | * need an swq_id so don't set one to catch errors, all others can |
| 346 | * be set up to the identity mapping. |
| 347 | */ |
| 348 | if (txq_id != IWL_CMD_QUEUE_NUM) |
Johannes Berg | 45af819 | 2009-06-19 13:52:43 -0700 | [diff] [blame] | 349 | txq->swq_id = txq_id; |
| 350 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 351 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
| 352 | * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ |
| 353 | BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); |
| 354 | |
| 355 | /* Initialize queue's high/low-water marks, and head/tail indexes */ |
| 356 | iwl_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id); |
| 357 | |
| 358 | /* Tell device where to find queue */ |
Samuel Ortiz | a8e74e27 | 2009-01-23 13:45:14 -0800 | [diff] [blame] | 359 | priv->cfg->ops->lib->txq_init(priv, txq); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 360 | |
| 361 | return 0; |
Tomas Winkler | 73b7d74 | 2008-09-03 11:18:48 +0800 | [diff] [blame] | 362 | err: |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 363 | for (i = 0; i < actual_slots; i++) |
Tomas Winkler | 73b7d74 | 2008-09-03 11:18:48 +0800 | [diff] [blame] | 364 | kfree(txq->cmd[i]); |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 365 | out_free_arrays: |
| 366 | kfree(txq->meta); |
| 367 | kfree(txq->cmd); |
Tomas Winkler | 73b7d74 | 2008-09-03 11:18:48 +0800 | [diff] [blame] | 368 | |
Tomas Winkler | 73b7d74 | 2008-09-03 11:18:48 +0800 | [diff] [blame] | 369 | return -ENOMEM; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 370 | } |
Samuel Ortiz | a8e74e27 | 2009-01-23 13:45:14 -0800 | [diff] [blame] | 371 | EXPORT_SYMBOL(iwl_tx_queue_init); |
| 372 | |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 373 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 374 | |
| 375 | /** |
| 376 | * iwl_enqueue_hcmd - enqueue a uCode command |
| 377 | * @priv: device private data point |
| 378 | * @cmd: a point to the ucode command structure |
| 379 | * |
| 380 | * The function returns < 0 values to indicate the operation is |
| 381 | * failed. On success, it turns the index (> 0) of command in the |
| 382 | * command queue. |
| 383 | */ |
| 384 | int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) |
| 385 | { |
| 386 | struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 387 | struct iwl_queue *q = &txq->q; |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 388 | struct iwl_device_cmd *out_cmd; |
| 389 | struct iwl_cmd_meta *out_meta; |
Tomas Winkler | f367422 | 2008-08-04 16:00:44 +0800 | [diff] [blame] | 390 | dma_addr_t phys_addr; |
| 391 | unsigned long flags; |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 392 | int len; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 393 | u32 idx; |
| 394 | u16 fix_size; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 395 | |
| 396 | cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len); |
| 397 | fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 398 | |
| 399 | /* If any of the command structures end up being larger than |
| 400 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
Abhijeet Kolekar | 8961212 | 2010-02-19 11:49:49 -0800 | [diff] [blame] | 401 | * we will need to increase the size of the TFD entries |
| 402 | * Also, check to see if command buffer should not exceed the size |
| 403 | * of device_cmd and max_cmd_size. */ |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 404 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 405 | !(cmd->flags & CMD_SIZE_HUGE)); |
Abhijeet Kolekar | 8961212 | 2010-02-19 11:49:49 -0800 | [diff] [blame] | 406 | BUG_ON(fix_size > IWL_MAX_CMD_SIZE); |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 407 | |
Wey-Yi Guy | 7812b16 | 2009-10-02 13:43:58 -0700 | [diff] [blame] | 408 | if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) { |
Reinette Chatre | f2f21b4 | 2009-10-30 14:36:15 -0700 | [diff] [blame] | 409 | IWL_WARN(priv, "Not sending command - %s KILL\n", |
| 410 | iwl_is_rfkill(priv) ? "RF" : "CT"); |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 411 | return -EIO; |
| 412 | } |
| 413 | |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 414 | if (iwl_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) { |
Wey-Yi Guy | 2d237f7 | 2009-11-20 12:05:08 -0800 | [diff] [blame] | 415 | IWL_ERR(priv, "No space in command queue\n"); |
Wey-Yi Guy | 7812b16 | 2009-10-02 13:43:58 -0700 | [diff] [blame] | 416 | if (iwl_within_ct_kill_margin(priv)) |
| 417 | iwl_tt_enter_ct_kill(priv); |
| 418 | else { |
| 419 | IWL_ERR(priv, "Restarting adapter due to queue full\n"); |
| 420 | queue_work(priv->workqueue, &priv->restart); |
| 421 | } |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 422 | return -ENOSPC; |
| 423 | } |
| 424 | |
| 425 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 426 | |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 427 | idx = get_cmd_index(q, q->write_ptr, cmd->flags & CMD_SIZE_HUGE); |
Gregory Greenman | da99c4b | 2008-08-04 16:00:40 +0800 | [diff] [blame] | 428 | out_cmd = txq->cmd[idx]; |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 429 | out_meta = &txq->meta[idx]; |
| 430 | |
Daniel C Halperin | 8ce73f3 | 2009-07-31 14:28:06 -0700 | [diff] [blame] | 431 | memset(out_meta, 0, sizeof(*out_meta)); /* re-initialize to NULL */ |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 432 | out_meta->flags = cmd->flags; |
| 433 | if (cmd->flags & CMD_WANT_SKB) |
| 434 | out_meta->source = cmd; |
| 435 | if (cmd->flags & CMD_ASYNC) |
| 436 | out_meta->callback = cmd->callback; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 437 | |
| 438 | out_cmd->hdr.cmd = cmd->id; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 439 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 440 | |
| 441 | /* At this point, the out_cmd now has all of the incoming cmd |
| 442 | * information */ |
| 443 | |
| 444 | out_cmd->hdr.flags = 0; |
| 445 | out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) | |
| 446 | INDEX_TO_SEQ(q->write_ptr)); |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 447 | if (cmd->flags & CMD_SIZE_HUGE) |
Tomas Winkler | 9734cb2 | 2008-09-03 11:26:52 +0800 | [diff] [blame] | 448 | out_cmd->hdr.sequence |= SEQ_HUGE_FRAME; |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 449 | len = sizeof(struct iwl_device_cmd); |
Abhijeet Kolekar | 8961212 | 2010-02-19 11:49:49 -0800 | [diff] [blame] | 450 | if (idx == TFD_CMD_SLOTS) |
| 451 | len = IWL_MAX_CMD_SIZE; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 452 | |
Esti Kummer | ded2ae7 | 2008-08-04 16:00:45 +0800 | [diff] [blame] | 453 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 454 | switch (out_cmd->hdr.cmd) { |
| 455 | case REPLY_TX_LINK_QUALITY_CMD: |
| 456 | case SENSITIVITY_CMD: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 457 | IWL_DEBUG_HC_DUMP(priv, "Sending command %s (#%x), seq: 0x%04X, " |
Esti Kummer | ded2ae7 | 2008-08-04 16:00:45 +0800 | [diff] [blame] | 458 | "%d bytes at %d[%d]:%d\n", |
| 459 | get_cmd_string(out_cmd->hdr.cmd), |
| 460 | out_cmd->hdr.cmd, |
| 461 | le16_to_cpu(out_cmd->hdr.sequence), fix_size, |
| 462 | q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
| 463 | break; |
| 464 | default: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 465 | IWL_DEBUG_HC(priv, "Sending command %s (#%x), seq: 0x%04X, " |
Esti Kummer | ded2ae7 | 2008-08-04 16:00:45 +0800 | [diff] [blame] | 466 | "%d bytes at %d[%d]:%d\n", |
| 467 | get_cmd_string(out_cmd->hdr.cmd), |
| 468 | out_cmd->hdr.cmd, |
| 469 | le16_to_cpu(out_cmd->hdr.sequence), fix_size, |
| 470 | q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
| 471 | } |
| 472 | #endif |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 473 | txq->need_update = 1; |
| 474 | |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 475 | if (priv->cfg->ops->lib->txq_update_byte_cnt_tbl) |
| 476 | /* Set up entry in queue's byte count circular buffer */ |
| 477 | priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0); |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 478 | |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 479 | phys_addr = pci_map_single(priv->pci_dev, &out_cmd->hdr, |
| 480 | fix_size, PCI_DMA_BIDIRECTIONAL); |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 481 | pci_unmap_addr_set(out_meta, mapping, phys_addr); |
| 482 | pci_unmap_len_set(out_meta, len, fix_size); |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 483 | |
Johannes Berg | be1a71a | 2009-10-02 13:44:02 -0700 | [diff] [blame] | 484 | trace_iwlwifi_dev_hcmd(priv, &out_cmd->hdr, fix_size, cmd->flags); |
| 485 | |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 486 | priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq, |
| 487 | phys_addr, fix_size, 1, |
| 488 | U32_PAD(cmd->len)); |
| 489 | |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 490 | /* Increment and update queue's write index */ |
| 491 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 492 | iwl_txq_update_write_ptr(priv, txq); |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 493 | |
| 494 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 495 | return idx; |
Tomas Winkler | fd4abac | 2008-05-15 13:54:07 +0800 | [diff] [blame] | 496 | } |
| 497 | |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 498 | /** |
| 499 | * iwl_hcmd_queue_reclaim - Reclaim TX command queue entries already Tx'd |
| 500 | * |
| 501 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 502 | * need to be reclaimed. As result, some free space forms. If there is |
| 503 | * enough free space (> low mark), wake the stack that feeds us. |
| 504 | */ |
Tomas Winkler | 499b188 | 2008-10-14 12:32:48 -0700 | [diff] [blame] | 505 | static void iwl_hcmd_queue_reclaim(struct iwl_priv *priv, int txq_id, |
| 506 | int idx, int cmd_idx) |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 507 | { |
| 508 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
| 509 | struct iwl_queue *q = &txq->q; |
| 510 | int nfreed = 0; |
| 511 | |
Tomas Winkler | 499b188 | 2008-10-14 12:32:48 -0700 | [diff] [blame] | 512 | if ((idx >= q->n_bd) || (iwl_queue_used(q, idx) == 0)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 513 | IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, " |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 514 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | 499b188 | 2008-10-14 12:32:48 -0700 | [diff] [blame] | 515 | idx, q->n_bd, q->write_ptr, q->read_ptr); |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 516 | return; |
| 517 | } |
| 518 | |
Tomas Winkler | 499b188 | 2008-10-14 12:32:48 -0700 | [diff] [blame] | 519 | for (idx = iwl_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx; |
| 520 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
| 521 | |
| 522 | if (nfreed++ > 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 523 | IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", idx, |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 524 | q->write_ptr, q->read_ptr); |
| 525 | queue_work(priv->workqueue, &priv->restart); |
| 526 | } |
Gregory Greenman | da99c4b | 2008-08-04 16:00:40 +0800 | [diff] [blame] | 527 | |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them |
| 533 | * @rxb: Rx buffer to reclaim |
| 534 | * |
| 535 | * If an Rx buffer has an async callback associated with it the callback |
| 536 | * will be executed. The attached skb (if present) will only be freed |
| 537 | * if the callback returns 1 |
| 538 | */ |
| 539 | void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) |
| 540 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 541 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 542 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 543 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 544 | int index = SEQ_TO_INDEX(sequence); |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 545 | int cmd_index; |
Tomas Winkler | 9734cb2 | 2008-09-03 11:26:52 +0800 | [diff] [blame] | 546 | bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME); |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 547 | struct iwl_device_cmd *cmd; |
| 548 | struct iwl_cmd_meta *meta; |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 549 | |
| 550 | /* If a Tx command is being handled and it isn't in the actual |
| 551 | * command queue then there a command routing bug has been introduced |
| 552 | * in the queue management code. */ |
Johannes Berg | 55d6a3c | 2008-09-23 19:18:43 +0200 | [diff] [blame] | 553 | if (WARN(txq_id != IWL_CMD_QUEUE_NUM, |
Winkler, Tomas | 01ef9323 | 2008-11-07 09:58:45 -0800 | [diff] [blame] | 554 | "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n", |
| 555 | txq_id, sequence, |
| 556 | priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr, |
| 557 | priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) { |
Reinette Chatre | ec74116 | 2009-07-24 11:13:08 -0700 | [diff] [blame] | 558 | iwl_print_hex_error(priv, pkt, 32); |
Johannes Berg | 55d6a3c | 2008-09-23 19:18:43 +0200 | [diff] [blame] | 559 | return; |
Winkler, Tomas | 01ef9323 | 2008-11-07 09:58:45 -0800 | [diff] [blame] | 560 | } |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 561 | |
| 562 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
Gregory Greenman | da99c4b | 2008-08-04 16:00:40 +0800 | [diff] [blame] | 563 | cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 564 | meta = &priv->txq[IWL_CMD_QUEUE_NUM].meta[cmd_index]; |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 565 | |
Reinette Chatre | c33de62 | 2009-10-30 14:36:10 -0700 | [diff] [blame] | 566 | pci_unmap_single(priv->pci_dev, |
| 567 | pci_unmap_addr(meta, mapping), |
| 568 | pci_unmap_len(meta, len), |
| 569 | PCI_DMA_BIDIRECTIONAL); |
| 570 | |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 571 | /* Input error checking is done when commands are added to queue. */ |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 572 | if (meta->flags & CMD_WANT_SKB) { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 573 | meta->source->reply_page = (unsigned long)rxb_addr(rxb); |
| 574 | rxb->page = NULL; |
Johannes Berg | 5696aea | 2009-07-24 11:13:06 -0700 | [diff] [blame] | 575 | } else if (meta->callback) |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 576 | meta->callback(priv, cmd, pkt); |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 577 | |
Tomas Winkler | 499b188 | 2008-10-14 12:32:48 -0700 | [diff] [blame] | 578 | iwl_hcmd_queue_reclaim(priv, txq_id, index, cmd_index); |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 579 | |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 580 | if (!(meta->flags & CMD_ASYNC)) { |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 581 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
Reinette Chatre | d2dfe6d | 2010-02-18 22:03:04 -0800 | [diff] [blame] | 582 | IWL_DEBUG_INFO(priv, "Clearing HCMD_ACTIVE for command %s \n", |
| 583 | get_cmd_string(cmd->hdr.cmd)); |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 584 | wake_up_interruptible(&priv->wait_command_queue); |
| 585 | } |
| 586 | } |
| 587 | EXPORT_SYMBOL(iwl_tx_cmd_complete); |
| 588 | |
Helmut Schaa | 994d31f | 2008-07-02 12:17:06 +0200 | [diff] [blame] | 589 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | a332f8d6 | 2008-05-29 16:35:08 +0800 | [diff] [blame] | 590 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 591 | |
| 592 | const char *iwl_get_tx_fail_reason(u32 status) |
| 593 | { |
| 594 | switch (status & TX_STATUS_MSK) { |
| 595 | case TX_STATUS_SUCCESS: |
| 596 | return "SUCCESS"; |
| 597 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 598 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 599 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 600 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 601 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 602 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 603 | TX_STATUS_ENTRY(DEST_PS); |
| 604 | TX_STATUS_ENTRY(ABORTED); |
| 605 | TX_STATUS_ENTRY(BT_RETRY); |
| 606 | TX_STATUS_ENTRY(STA_INVALID); |
| 607 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 608 | TX_STATUS_ENTRY(TID_DISABLE); |
| 609 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 610 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 611 | TX_STATUS_ENTRY(TX_LOCKED); |
| 612 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 613 | } |
| 614 | |
| 615 | return "UNKNOWN"; |
| 616 | } |
| 617 | EXPORT_SYMBOL(iwl_get_tx_fail_reason); |
| 618 | #endif /* CONFIG_IWLWIFI_DEBUG */ |