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