Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1 | /* |
Shannon Nelson | 43d6e36 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 2 | * Intel I/OAT DMA Linux driver |
Maciej Sosnowski | 211a22c | 2009-02-26 11:05:43 +0100 | [diff] [blame] | 3 | * Copyright(c) 2004 - 2009 Intel Corporation. |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
Shannon Nelson | 43d6e36 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
Shannon Nelson | 43d6e36 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 17 | * |
Shannon Nelson | 43d6e36 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * This driver supports an Intel I/OAT DMA engine, which does asynchronous |
| 25 | * copy operations. |
| 26 | */ |
| 27 | |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/dmaengine.h> |
| 33 | #include <linux/delay.h> |
David S. Miller | 6b00c92 | 2006-05-23 17:37:58 -0700 | [diff] [blame] | 34 | #include <linux/dma-mapping.h> |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 35 | #include <linux/workqueue.h> |
Venki Pallipadi | 3ad0b02 | 2008-10-22 16:34:52 -0700 | [diff] [blame] | 36 | #include <linux/i7300_idle.h> |
Dan Williams | 584ec22 | 2009-07-28 14:32:12 -0700 | [diff] [blame] | 37 | #include "dma.h" |
| 38 | #include "registers.h" |
| 39 | #include "hw.h" |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 40 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 41 | int ioat_pending_level = 4; |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 42 | module_param(ioat_pending_level, int, 0644); |
| 43 | MODULE_PARM_DESC(ioat_pending_level, |
| 44 | "high-water mark for pushing ioat descriptors (default: 4)"); |
| 45 | |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 46 | /* internal functions */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 47 | static void ioat1_cleanup(struct ioat_dma_chan *ioat); |
| 48 | static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * ioat_dma_do_interrupt - handler used for single vector interrupt mode |
| 52 | * @irq: interrupt id |
| 53 | * @data: interrupt data |
| 54 | */ |
| 55 | static irqreturn_t ioat_dma_do_interrupt(int irq, void *data) |
| 56 | { |
| 57 | struct ioatdma_device *instance = data; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 58 | struct ioat_chan_common *chan; |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 59 | unsigned long attnstatus; |
| 60 | int bit; |
| 61 | u8 intrctrl; |
| 62 | |
| 63 | intrctrl = readb(instance->reg_base + IOAT_INTRCTRL_OFFSET); |
| 64 | |
| 65 | if (!(intrctrl & IOAT_INTRCTRL_MASTER_INT_EN)) |
| 66 | return IRQ_NONE; |
| 67 | |
| 68 | if (!(intrctrl & IOAT_INTRCTRL_INT_STATUS)) { |
| 69 | writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET); |
| 70 | return IRQ_NONE; |
| 71 | } |
| 72 | |
| 73 | attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET); |
| 74 | for_each_bit(bit, &attnstatus, BITS_PER_LONG) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 75 | chan = ioat_chan_by_index(instance, bit); |
| 76 | tasklet_schedule(&chan->cleanup_task); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET); |
| 80 | return IRQ_HANDLED; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * ioat_dma_do_interrupt_msix - handler used for vector-per-channel interrupt mode |
| 85 | * @irq: interrupt id |
| 86 | * @data: interrupt data |
| 87 | */ |
| 88 | static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data) |
| 89 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 90 | struct ioat_chan_common *chan = data; |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 91 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 92 | tasklet_schedule(&chan->cleanup_task); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 93 | |
| 94 | return IRQ_HANDLED; |
| 95 | } |
| 96 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 97 | static void ioat1_cleanup_tasklet(unsigned long data); |
| 98 | |
| 99 | /* common channel initialization */ |
| 100 | void ioat_init_channel(struct ioatdma_device *device, |
| 101 | struct ioat_chan_common *chan, int idx, |
| 102 | work_func_t work_fn, void (*tasklet)(unsigned long), |
| 103 | unsigned long tasklet_data) |
| 104 | { |
| 105 | struct dma_device *dma = &device->common; |
| 106 | |
| 107 | chan->device = device; |
| 108 | chan->reg_base = device->reg_base + (0x80 * (idx + 1)); |
| 109 | INIT_DELAYED_WORK(&chan->work, work_fn); |
| 110 | spin_lock_init(&chan->cleanup_lock); |
| 111 | chan->common.device = dma; |
| 112 | list_add_tail(&chan->common.device_node, &dma->channels); |
| 113 | device->idx[idx] = chan; |
| 114 | tasklet_init(&chan->cleanup_task, tasklet, tasklet_data); |
| 115 | tasklet_disable(&chan->cleanup_task); |
| 116 | } |
| 117 | |
| 118 | static void ioat1_reset_part2(struct work_struct *work); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 119 | |
| 120 | /** |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 121 | * ioat1_dma_enumerate_channels - find and initialize the device's channels |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 122 | * @device: the device to be enumerated |
| 123 | */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 124 | static int ioat1_enumerate_channels(struct ioatdma_device *device) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 125 | { |
| 126 | u8 xfercap_scale; |
| 127 | u32 xfercap; |
| 128 | int i; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 129 | struct ioat_dma_chan *ioat; |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 130 | struct device *dev = &device->pdev->dev; |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 131 | struct dma_device *dma = &device->common; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 132 | |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 133 | INIT_LIST_HEAD(&dma->channels); |
| 134 | dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET); |
Dan Williams | bb32078 | 2009-09-08 12:01:14 -0700 | [diff] [blame] | 135 | dma->chancnt &= 0x1f; /* bits [4:0] valid */ |
| 136 | if (dma->chancnt > ARRAY_SIZE(device->idx)) { |
| 137 | dev_warn(dev, "(%d) exceeds max supported channels (%zu)\n", |
| 138 | dma->chancnt, ARRAY_SIZE(device->idx)); |
| 139 | dma->chancnt = ARRAY_SIZE(device->idx); |
| 140 | } |
Chris Leech | e382881 | 2007-03-08 09:57:35 -0800 | [diff] [blame] | 141 | xfercap_scale = readb(device->reg_base + IOAT_XFERCAP_OFFSET); |
Dan Williams | bb32078 | 2009-09-08 12:01:14 -0700 | [diff] [blame] | 142 | xfercap_scale &= 0x1f; /* bits [4:0] valid */ |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 143 | xfercap = (xfercap_scale == 0 ? -1 : (1UL << xfercap_scale)); |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 144 | dev_dbg(dev, "%s: xfercap = %d\n", __func__, xfercap); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 145 | |
Venki Pallipadi | f371be6 | 2008-10-23 15:39:06 -0700 | [diff] [blame] | 146 | #ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 147 | if (i7300_idle_platform_probe(NULL, NULL, 1) == 0) |
| 148 | dma->chancnt--; |
Andy Henroid | 27471fd | 2008-10-09 11:45:22 -0700 | [diff] [blame] | 149 | #endif |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 150 | for (i = 0; i < dma->chancnt; i++) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 151 | ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 152 | if (!ioat) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 153 | break; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 154 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 155 | ioat_init_channel(device, &ioat->base, i, |
| 156 | ioat1_reset_part2, |
| 157 | ioat1_cleanup_tasklet, |
| 158 | (unsigned long) ioat); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 159 | ioat->xfercap = xfercap; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 160 | spin_lock_init(&ioat->desc_lock); |
| 161 | INIT_LIST_HEAD(&ioat->free_desc); |
| 162 | INIT_LIST_HEAD(&ioat->used_desc); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 163 | } |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 164 | dma->chancnt = i; |
| 165 | return i; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 168 | /** |
| 169 | * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended |
| 170 | * descriptors to hw |
| 171 | * @chan: DMA channel handle |
| 172 | */ |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 173 | static inline void |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 174 | __ioat1_dma_memcpy_issue_pending(struct ioat_dma_chan *ioat) |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 175 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 176 | void __iomem *reg_base = ioat->base.reg_base; |
| 177 | |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 178 | dev_dbg(to_dev(&ioat->base), "%s: pending: %d\n", |
| 179 | __func__, ioat->pending); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 180 | ioat->pending = 0; |
| 181 | writeb(IOAT_CHANCMD_APPEND, reg_base + IOAT1_CHANCMD_OFFSET); |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static void ioat1_dma_memcpy_issue_pending(struct dma_chan *chan) |
| 185 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 186 | struct ioat_dma_chan *ioat = to_ioat_chan(chan); |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 187 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 188 | if (ioat->pending > 0) { |
| 189 | spin_lock_bh(&ioat->desc_lock); |
| 190 | __ioat1_dma_memcpy_issue_pending(ioat); |
| 191 | spin_unlock_bh(&ioat->desc_lock); |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 195 | /** |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 196 | * ioat1_reset_part2 - reinit the channel after a reset |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 197 | */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 198 | static void ioat1_reset_part2(struct work_struct *work) |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 199 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 200 | struct ioat_chan_common *chan; |
| 201 | struct ioat_dma_chan *ioat; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 202 | struct ioat_desc_sw *desc; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 203 | int dmacount; |
| 204 | bool start_null = false; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 205 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 206 | chan = container_of(work, struct ioat_chan_common, work.work); |
| 207 | ioat = container_of(chan, struct ioat_dma_chan, base); |
| 208 | spin_lock_bh(&chan->cleanup_lock); |
| 209 | spin_lock_bh(&ioat->desc_lock); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 210 | |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 211 | *chan->completion = 0; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 212 | ioat->pending = 0; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 213 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 214 | /* count the descriptors waiting */ |
| 215 | dmacount = 0; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 216 | if (ioat->used_desc.prev) { |
| 217 | desc = to_ioat_desc(ioat->used_desc.prev); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 218 | do { |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 219 | dmacount++; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 220 | desc = to_ioat_desc(desc->node.next); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 221 | } while (&desc->node != ioat->used_desc.next); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 224 | if (dmacount) { |
| 225 | /* |
| 226 | * write the new starting descriptor address |
| 227 | * this puts channel engine into ARMED state |
| 228 | */ |
| 229 | desc = to_ioat_desc(ioat->used_desc.prev); |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 230 | writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF, |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 231 | chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW); |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 232 | writel(((u64) desc->txd.phys) >> 32, |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 233 | chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 234 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 235 | writeb(IOAT_CHANCMD_START, chan->reg_base |
| 236 | + IOAT_CHANCMD_OFFSET(chan->device->version)); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 237 | } else |
| 238 | start_null = true; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 239 | spin_unlock_bh(&ioat->desc_lock); |
| 240 | spin_unlock_bh(&chan->cleanup_lock); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 241 | |
| 242 | dev_err(to_dev(chan), |
| 243 | "chan%d reset - %d descs waiting, %d total desc\n", |
| 244 | chan_num(chan), dmacount, ioat->desccount); |
| 245 | |
| 246 | if (start_null) |
| 247 | ioat1_dma_start_null_desc(ioat); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /** |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 251 | * ioat1_reset_channel - restart a channel |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 252 | * @ioat: IOAT DMA channel handle |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 253 | */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 254 | static void ioat1_reset_channel(struct ioat_dma_chan *ioat) |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 255 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 256 | struct ioat_chan_common *chan = &ioat->base; |
| 257 | void __iomem *reg_base = chan->reg_base; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 258 | u32 chansts, chanerr; |
| 259 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 260 | if (!ioat->used_desc.prev) |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 261 | return; |
| 262 | |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 263 | dev_dbg(to_dev(chan), "%s\n", __func__); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 264 | chanerr = readl(reg_base + IOAT_CHANERR_OFFSET); |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 265 | chansts = *chan->completion & IOAT_CHANSTS_DMA_TRANSFER_STATUS; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 266 | if (chanerr) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 267 | dev_err(to_dev(chan), |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 268 | "chan%d, CHANSTS = 0x%08x CHANERR = 0x%04x, clearing\n", |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 269 | chan_num(chan), chansts, chanerr); |
| 270 | writel(chanerr, reg_base + IOAT_CHANERR_OFFSET); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /* |
| 274 | * whack it upside the head with a reset |
| 275 | * and wait for things to settle out. |
| 276 | * force the pending count to a really big negative |
| 277 | * to make sure no one forces an issue_pending |
| 278 | * while we're waiting. |
| 279 | */ |
| 280 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 281 | spin_lock_bh(&ioat->desc_lock); |
| 282 | ioat->pending = INT_MIN; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 283 | writeb(IOAT_CHANCMD_RESET, |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 284 | reg_base + IOAT_CHANCMD_OFFSET(chan->device->version)); |
| 285 | spin_unlock_bh(&ioat->desc_lock); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 286 | |
| 287 | /* schedule the 2nd half instead of sleeping a long time */ |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 288 | schedule_delayed_work(&chan->work, RESET_DELAY); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /** |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 292 | * ioat1_chan_watchdog - watch for stuck channels |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 293 | */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 294 | static void ioat1_chan_watchdog(struct work_struct *work) |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 295 | { |
| 296 | struct ioatdma_device *device = |
| 297 | container_of(work, struct ioatdma_device, work.work); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 298 | struct ioat_dma_chan *ioat; |
| 299 | struct ioat_chan_common *chan; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 300 | int i; |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 301 | u64 completion; |
| 302 | u32 completion_low; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 303 | unsigned long compl_desc_addr_hw; |
| 304 | |
| 305 | for (i = 0; i < device->common.chancnt; i++) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 306 | chan = ioat_chan_by_index(device, i); |
| 307 | ioat = container_of(chan, struct ioat_dma_chan, base); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 308 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 309 | if (/* have we started processing anything yet */ |
| 310 | chan->last_completion |
| 311 | /* have we completed any since last watchdog cycle? */ |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 312 | && (chan->last_completion == chan->watchdog_completion) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 313 | /* has TCP stuck on one cookie since last watchdog? */ |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 314 | && (chan->watchdog_tcp_cookie == chan->watchdog_last_tcp_cookie) |
| 315 | && (chan->watchdog_tcp_cookie != chan->completed_cookie) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 316 | /* is there something in the chain to be processed? */ |
| 317 | /* CB1 chain always has at least the last one processed */ |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 318 | && (ioat->used_desc.prev != ioat->used_desc.next) |
| 319 | && ioat->pending == 0) { |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 320 | |
| 321 | /* |
| 322 | * check CHANSTS register for completed |
| 323 | * descriptor address. |
| 324 | * if it is different than completion writeback, |
| 325 | * it is not zero |
| 326 | * and it has changed since the last watchdog |
| 327 | * we can assume that channel |
| 328 | * is still working correctly |
| 329 | * and the problem is in completion writeback. |
| 330 | * update completion writeback |
| 331 | * with actual CHANSTS value |
| 332 | * else |
| 333 | * try resetting the channel |
| 334 | */ |
| 335 | |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 336 | /* we need to read the low address first as this |
| 337 | * causes the chipset to latch the upper bits |
| 338 | * for the subsequent read |
| 339 | */ |
| 340 | completion_low = readl(chan->reg_base + |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 341 | IOAT_CHANSTS_OFFSET_LOW(chan->device->version)); |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 342 | completion = readl(chan->reg_base + |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 343 | IOAT_CHANSTS_OFFSET_HIGH(chan->device->version)); |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 344 | completion <<= 32; |
| 345 | completion |= completion_low; |
| 346 | compl_desc_addr_hw = completion & |
| 347 | IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 348 | |
| 349 | if ((compl_desc_addr_hw != 0) |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 350 | && (compl_desc_addr_hw != chan->watchdog_completion) |
| 351 | && (compl_desc_addr_hw != chan->last_compl_desc_addr_hw)) { |
| 352 | chan->last_compl_desc_addr_hw = compl_desc_addr_hw; |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 353 | *chan->completion = completion; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 354 | } else { |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 355 | ioat1_reset_channel(ioat); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 356 | chan->watchdog_completion = 0; |
| 357 | chan->last_compl_desc_addr_hw = 0; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 358 | } |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 359 | } else { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 360 | chan->last_compl_desc_addr_hw = 0; |
| 361 | chan->watchdog_completion = chan->last_completion; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 362 | } |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 363 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 364 | chan->watchdog_last_tcp_cookie = chan->watchdog_tcp_cookie; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | schedule_delayed_work(&device->work, WATCHDOG_DELAY); |
| 368 | } |
| 369 | |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 370 | static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx) |
Dan Williams | 7405f74 | 2007-01-02 11:10:43 -0700 | [diff] [blame] | 371 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 372 | struct dma_chan *c = tx->chan; |
| 373 | struct ioat_dma_chan *ioat = to_ioat_chan(c); |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 374 | struct ioat_desc_sw *desc = tx_to_ioat_desc(tx); |
| 375 | struct ioat_desc_sw *first; |
| 376 | struct ioat_desc_sw *chain_tail; |
Dan Williams | 7405f74 | 2007-01-02 11:10:43 -0700 | [diff] [blame] | 377 | dma_cookie_t cookie; |
Shannon Nelson | 7f2b291 | 2007-10-18 03:07:14 -0700 | [diff] [blame] | 378 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 379 | spin_lock_bh(&ioat->desc_lock); |
Dan Williams | 7405f74 | 2007-01-02 11:10:43 -0700 | [diff] [blame] | 380 | /* cookie incr and addition to used_list must be atomic */ |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 381 | cookie = c->cookie; |
Dan Williams | 7405f74 | 2007-01-02 11:10:43 -0700 | [diff] [blame] | 382 | cookie++; |
| 383 | if (cookie < 0) |
| 384 | cookie = 1; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 385 | c->cookie = cookie; |
| 386 | tx->cookie = cookie; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 387 | dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie); |
Dan Williams | 7405f74 | 2007-01-02 11:10:43 -0700 | [diff] [blame] | 388 | |
| 389 | /* write address into NextDescriptor field of last desc in chain */ |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 390 | first = to_ioat_desc(tx->tx_list.next); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 391 | chain_tail = to_ioat_desc(ioat->used_desc.prev); |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 392 | /* make descriptor updates globally visible before chaining */ |
| 393 | wmb(); |
| 394 | chain_tail->hw->next = first->txd.phys; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 395 | list_splice_tail_init(&tx->tx_list, &ioat->used_desc); |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 396 | dump_desc_dbg(ioat, chain_tail); |
| 397 | dump_desc_dbg(ioat, first); |
Dan Williams | 7405f74 | 2007-01-02 11:10:43 -0700 | [diff] [blame] | 398 | |
Dan Williams | ad643f5 | 2009-09-08 12:01:38 -0700 | [diff] [blame^] | 399 | ioat->pending += desc->hw->tx_cnt; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 400 | if (ioat->pending >= ioat_pending_level) |
| 401 | __ioat1_dma_memcpy_issue_pending(ioat); |
| 402 | spin_unlock_bh(&ioat->desc_lock); |
Dan Williams | 7405f74 | 2007-01-02 11:10:43 -0700 | [diff] [blame] | 403 | |
Dan Williams | 7405f74 | 2007-01-02 11:10:43 -0700 | [diff] [blame] | 404 | return cookie; |
| 405 | } |
| 406 | |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 407 | /** |
| 408 | * ioat_dma_alloc_descriptor - allocate and return a sw and hw descriptor pair |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 409 | * @ioat: the channel supplying the memory pool for the descriptors |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 410 | * @flags: allocation flags |
| 411 | */ |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 412 | static struct ioat_desc_sw * |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 413 | ioat_dma_alloc_descriptor(struct ioat_dma_chan *ioat, gfp_t flags) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 414 | { |
| 415 | struct ioat_dma_descriptor *desc; |
| 416 | struct ioat_desc_sw *desc_sw; |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 417 | struct ioatdma_device *ioatdma_device; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 418 | dma_addr_t phys; |
| 419 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 420 | ioatdma_device = ioat->base.device; |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 421 | desc = pci_pool_alloc(ioatdma_device->dma_pool, flags, &phys); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 422 | if (unlikely(!desc)) |
| 423 | return NULL; |
| 424 | |
| 425 | desc_sw = kzalloc(sizeof(*desc_sw), flags); |
| 426 | if (unlikely(!desc_sw)) { |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 427 | pci_pool_free(ioatdma_device->dma_pool, desc, phys); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 428 | return NULL; |
| 429 | } |
| 430 | |
| 431 | memset(desc, 0, sizeof(*desc)); |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 432 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 433 | dma_async_tx_descriptor_init(&desc_sw->txd, &ioat->base.common); |
| 434 | desc_sw->txd.tx_submit = ioat1_tx_submit; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 435 | desc_sw->hw = desc; |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 436 | desc_sw->txd.phys = phys; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 437 | set_desc_id(desc_sw, -1); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 438 | |
| 439 | return desc_sw; |
| 440 | } |
| 441 | |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 442 | static int ioat_initial_desc_count = 256; |
| 443 | module_param(ioat_initial_desc_count, int, 0644); |
| 444 | MODULE_PARM_DESC(ioat_initial_desc_count, |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 445 | "ioat1: initial descriptors per channel (default: 256)"); |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 446 | /** |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 447 | * ioat1_dma_alloc_chan_resources - returns the number of allocated descriptors |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 448 | * @chan: the channel to be filled out |
| 449 | */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 450 | static int ioat1_dma_alloc_chan_resources(struct dma_chan *c) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 451 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 452 | struct ioat_dma_chan *ioat = to_ioat_chan(c); |
| 453 | struct ioat_chan_common *chan = &ioat->base; |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 454 | struct ioat_desc_sw *desc; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 455 | u32 chanerr; |
| 456 | int i; |
| 457 | LIST_HEAD(tmp_list); |
| 458 | |
Shannon Nelson | e422397 | 2007-08-24 23:02:53 -0700 | [diff] [blame] | 459 | /* have we already been set up? */ |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 460 | if (!list_empty(&ioat->free_desc)) |
| 461 | return ioat->desccount; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 462 | |
Shannon Nelson | 43d6e36 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 463 | /* Setup register to interrupt and write completion status on error */ |
Dan Williams | f6ab95b | 2009-09-08 12:01:21 -0700 | [diff] [blame] | 464 | writew(IOAT_CHANCTRL_RUN, chan->reg_base + IOAT_CHANCTRL_OFFSET); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 465 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 466 | chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 467 | if (chanerr) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 468 | dev_err(to_dev(chan), "CHANERR = %x, clearing\n", chanerr); |
| 469 | writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /* Allocate descriptors */ |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 473 | for (i = 0; i < ioat_initial_desc_count; i++) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 474 | desc = ioat_dma_alloc_descriptor(ioat, GFP_KERNEL); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 475 | if (!desc) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 476 | dev_err(to_dev(chan), "Only %d initial descriptors\n", i); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 477 | break; |
| 478 | } |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 479 | set_desc_id(desc, i); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 480 | list_add_tail(&desc->node, &tmp_list); |
| 481 | } |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 482 | spin_lock_bh(&ioat->desc_lock); |
| 483 | ioat->desccount = i; |
| 484 | list_splice(&tmp_list, &ioat->free_desc); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 485 | spin_unlock_bh(&ioat->desc_lock); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 486 | |
| 487 | /* allocate a completion writeback area */ |
| 488 | /* doing 2 32bit writes to mmio since 1 64b write doesn't work */ |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 489 | chan->completion = pci_pool_alloc(chan->device->completion_pool, |
| 490 | GFP_KERNEL, &chan->completion_dma); |
| 491 | memset(chan->completion, 0, sizeof(*chan->completion)); |
| 492 | writel(((u64) chan->completion_dma) & 0x00000000FFFFFFFF, |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 493 | chan->reg_base + IOAT_CHANCMP_OFFSET_LOW); |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 494 | writel(((u64) chan->completion_dma) >> 32, |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 495 | chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 496 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 497 | tasklet_enable(&chan->cleanup_task); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 498 | ioat1_dma_start_null_desc(ioat); /* give chain to dma device */ |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 499 | dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n", |
| 500 | __func__, ioat->desccount); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 501 | return ioat->desccount; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 504 | /** |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 505 | * ioat1_dma_free_chan_resources - release all the descriptors |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 506 | * @chan: the channel to be cleaned |
| 507 | */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 508 | static void ioat1_dma_free_chan_resources(struct dma_chan *c) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 509 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 510 | struct ioat_dma_chan *ioat = to_ioat_chan(c); |
| 511 | struct ioat_chan_common *chan = &ioat->base; |
| 512 | struct ioatdma_device *ioatdma_device = chan->device; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 513 | struct ioat_desc_sw *desc, *_desc; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 514 | int in_use_descs = 0; |
| 515 | |
Maciej Sosnowski | c3d4f44 | 2008-11-07 01:45:52 +0000 | [diff] [blame] | 516 | /* Before freeing channel resources first check |
| 517 | * if they have been previously allocated for this channel. |
| 518 | */ |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 519 | if (ioat->desccount == 0) |
Maciej Sosnowski | c3d4f44 | 2008-11-07 01:45:52 +0000 | [diff] [blame] | 520 | return; |
| 521 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 522 | tasklet_disable(&chan->cleanup_task); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 523 | ioat1_cleanup(ioat); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 524 | |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 525 | /* Delay 100ms after reset to allow internal DMA logic to quiesce |
| 526 | * before removing DMA descriptor resources. |
| 527 | */ |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 528 | writeb(IOAT_CHANCMD_RESET, |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 529 | chan->reg_base + IOAT_CHANCMD_OFFSET(chan->device->version)); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 530 | mdelay(100); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 531 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 532 | spin_lock_bh(&ioat->desc_lock); |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 533 | list_for_each_entry_safe(desc, _desc, &ioat->used_desc, node) { |
| 534 | dev_dbg(to_dev(chan), "%s: freeing %d from used list\n", |
| 535 | __func__, desc_id(desc)); |
| 536 | dump_desc_dbg(ioat, desc); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 537 | in_use_descs++; |
| 538 | list_del(&desc->node); |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 539 | pci_pool_free(ioatdma_device->dma_pool, desc->hw, |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 540 | desc->txd.phys); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 541 | kfree(desc); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 542 | } |
| 543 | list_for_each_entry_safe(desc, _desc, |
| 544 | &ioat->free_desc, node) { |
| 545 | list_del(&desc->node); |
| 546 | pci_pool_free(ioatdma_device->dma_pool, desc->hw, |
| 547 | desc->txd.phys); |
| 548 | kfree(desc); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 549 | } |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 550 | spin_unlock_bh(&ioat->desc_lock); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 551 | |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 552 | pci_pool_free(ioatdma_device->completion_pool, |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 553 | chan->completion, |
| 554 | chan->completion_dma); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 555 | |
| 556 | /* one is ok since we left it on there on purpose */ |
| 557 | if (in_use_descs > 1) |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 558 | dev_err(to_dev(chan), "Freeing %d in use descriptors!\n", |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 559 | in_use_descs - 1); |
| 560 | |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 561 | chan->last_completion = 0; |
| 562 | chan->completion_dma = 0; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 563 | chan->watchdog_completion = 0; |
| 564 | chan->last_compl_desc_addr_hw = 0; |
| 565 | chan->watchdog_tcp_cookie = chan->watchdog_last_tcp_cookie = 0; |
| 566 | ioat->pending = 0; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 567 | ioat->desccount = 0; |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 568 | } |
Shannon Nelson | 7f2b291 | 2007-10-18 03:07:14 -0700 | [diff] [blame] | 569 | |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 570 | /** |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 571 | * ioat1_dma_get_next_descriptor - return the next available descriptor |
| 572 | * @ioat: IOAT DMA channel handle |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 573 | * |
| 574 | * Gets the next descriptor from the chain, and must be called with the |
| 575 | * channel's desc_lock held. Allocates more descriptors if the channel |
| 576 | * has run out. |
| 577 | */ |
Shannon Nelson | 7f2b291 | 2007-10-18 03:07:14 -0700 | [diff] [blame] | 578 | static struct ioat_desc_sw * |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 579 | ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat) |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 580 | { |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 581 | struct ioat_desc_sw *new; |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 582 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 583 | if (!list_empty(&ioat->free_desc)) { |
| 584 | new = to_ioat_desc(ioat->free_desc.next); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 585 | list_del(&new->node); |
| 586 | } else { |
| 587 | /* try to get another desc */ |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 588 | new = ioat_dma_alloc_descriptor(ioat, GFP_ATOMIC); |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 589 | if (!new) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 590 | dev_err(to_dev(&ioat->base), "alloc failed\n"); |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 591 | return NULL; |
| 592 | } |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 593 | } |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 594 | dev_dbg(to_dev(&ioat->base), "%s: allocated: %d\n", |
| 595 | __func__, desc_id(new)); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 596 | prefetch(new->hw); |
| 597 | return new; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 600 | static struct dma_async_tx_descriptor * |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 601 | ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest, |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 602 | dma_addr_t dma_src, size_t len, unsigned long flags) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 603 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 604 | struct ioat_dma_chan *ioat = to_ioat_chan(c); |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 605 | struct ioat_desc_sw *desc; |
| 606 | size_t copy; |
| 607 | LIST_HEAD(chain); |
| 608 | dma_addr_t src = dma_src; |
| 609 | dma_addr_t dest = dma_dest; |
| 610 | size_t total_len = len; |
| 611 | struct ioat_dma_descriptor *hw = NULL; |
| 612 | int tx_cnt = 0; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 613 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 614 | spin_lock_bh(&ioat->desc_lock); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 615 | desc = ioat1_dma_get_next_descriptor(ioat); |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 616 | do { |
| 617 | if (!desc) |
| 618 | break; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 619 | |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 620 | tx_cnt++; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 621 | copy = min_t(size_t, len, ioat->xfercap); |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 622 | |
| 623 | hw = desc->hw; |
| 624 | hw->size = copy; |
| 625 | hw->ctl = 0; |
| 626 | hw->src_addr = src; |
| 627 | hw->dst_addr = dest; |
| 628 | |
| 629 | list_add_tail(&desc->node, &chain); |
| 630 | |
| 631 | len -= copy; |
| 632 | dest += copy; |
| 633 | src += copy; |
| 634 | if (len) { |
| 635 | struct ioat_desc_sw *next; |
| 636 | |
| 637 | async_tx_ack(&desc->txd); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 638 | next = ioat1_dma_get_next_descriptor(ioat); |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 639 | hw->next = next ? next->txd.phys : 0; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 640 | dump_desc_dbg(ioat, desc); |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 641 | desc = next; |
| 642 | } else |
| 643 | hw->next = 0; |
| 644 | } while (len); |
| 645 | |
| 646 | if (!desc) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 647 | struct ioat_chan_common *chan = &ioat->base; |
| 648 | |
| 649 | dev_err(to_dev(chan), |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 650 | "chan%d - get_next_desc failed\n", chan_num(chan)); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 651 | list_splice(&chain, &ioat->free_desc); |
| 652 | spin_unlock_bh(&ioat->desc_lock); |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 653 | return NULL; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 654 | } |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 655 | spin_unlock_bh(&ioat->desc_lock); |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 656 | |
| 657 | desc->txd.flags = flags; |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 658 | desc->len = total_len; |
| 659 | list_splice(&chain, &desc->txd.tx_list); |
| 660 | hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT); |
| 661 | hw->ctl_f.compl_write = 1; |
Dan Williams | ad643f5 | 2009-09-08 12:01:38 -0700 | [diff] [blame^] | 662 | hw->tx_cnt = tx_cnt; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 663 | dump_desc_dbg(ioat, desc); |
Dan Williams | a0587bc | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 664 | |
| 665 | return &desc->txd; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 668 | static void ioat1_cleanup_tasklet(unsigned long data) |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 669 | { |
| 670 | struct ioat_dma_chan *chan = (void *)data; |
Dan Williams | f6ab95b | 2009-09-08 12:01:21 -0700 | [diff] [blame] | 671 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 672 | ioat1_cleanup(chan); |
Dan Williams | f6ab95b | 2009-09-08 12:01:21 -0700 | [diff] [blame] | 673 | writew(IOAT_CHANCTRL_RUN, chan->base.reg_base + IOAT_CHANCTRL_OFFSET); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 676 | static void ioat_unmap(struct pci_dev *pdev, dma_addr_t addr, size_t len, |
| 677 | int direction, enum dma_ctrl_flags flags, bool dst) |
Dan Williams | e1d181e | 2008-07-04 00:13:40 -0700 | [diff] [blame] | 678 | { |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 679 | if ((dst && (flags & DMA_COMPL_DEST_UNMAP_SINGLE)) || |
| 680 | (!dst && (flags & DMA_COMPL_SRC_UNMAP_SINGLE))) |
| 681 | pci_unmap_single(pdev, addr, len, direction); |
| 682 | else |
| 683 | pci_unmap_page(pdev, addr, len, direction); |
Dan Williams | e1d181e | 2008-07-04 00:13:40 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 686 | |
| 687 | void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags, |
| 688 | size_t len, struct ioat_dma_descriptor *hw) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 689 | { |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 690 | struct pci_dev *pdev = chan->device->pdev; |
| 691 | size_t offset = len - hw->size; |
| 692 | |
| 693 | if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) |
| 694 | ioat_unmap(pdev, hw->dst_addr - offset, len, |
| 695 | PCI_DMA_FROMDEVICE, flags, 1); |
| 696 | |
| 697 | if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) |
| 698 | ioat_unmap(pdev, hw->src_addr - offset, len, |
| 699 | PCI_DMA_TODEVICE, flags, 0); |
| 700 | } |
| 701 | |
| 702 | unsigned long ioat_get_current_completion(struct ioat_chan_common *chan) |
| 703 | { |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 704 | unsigned long phys_complete; |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 705 | u64 completion; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 706 | |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 707 | completion = *chan->completion; |
| 708 | phys_complete = completion & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 709 | |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 710 | dev_dbg(to_dev(chan), "%s: phys_complete: %#llx\n", __func__, |
| 711 | (unsigned long long) phys_complete); |
| 712 | |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 713 | if ((completion & IOAT_CHANSTS_DMA_TRANSFER_STATUS) == |
Shannon Nelson | 43d6e36 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 714 | IOAT_CHANSTS_DMA_TRANSFER_STATUS_HALTED) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 715 | dev_err(to_dev(chan), "Channel halted, chanerr = %x\n", |
| 716 | readl(chan->reg_base + IOAT_CHANERR_OFFSET)); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 717 | |
| 718 | /* TODO do something to salvage the situation */ |
| 719 | } |
| 720 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 721 | return phys_complete; |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | * ioat1_cleanup - cleanup up finished descriptors |
| 726 | * @chan: ioat channel to be cleaned up |
| 727 | */ |
| 728 | static void ioat1_cleanup(struct ioat_dma_chan *ioat) |
| 729 | { |
| 730 | struct ioat_chan_common *chan = &ioat->base; |
| 731 | unsigned long phys_complete; |
| 732 | struct ioat_desc_sw *desc, *_desc; |
| 733 | dma_cookie_t cookie = 0; |
| 734 | struct dma_async_tx_descriptor *tx; |
| 735 | |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 736 | prefetch(chan->completion); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 737 | |
| 738 | if (!spin_trylock_bh(&chan->cleanup_lock)) |
| 739 | return; |
| 740 | |
| 741 | phys_complete = ioat_get_current_completion(chan); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 742 | if (phys_complete == chan->last_completion) { |
| 743 | spin_unlock_bh(&chan->cleanup_lock); |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 744 | /* |
| 745 | * perhaps we're stuck so hard that the watchdog can't go off? |
| 746 | * try to catch it after 2 seconds |
| 747 | */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 748 | if (time_after(jiffies, |
| 749 | chan->last_completion_time + HZ*WATCHDOG_DELAY)) { |
| 750 | ioat1_chan_watchdog(&(chan->device->work.work)); |
| 751 | chan->last_completion_time = jiffies; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 752 | } |
| 753 | return; |
| 754 | } |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 755 | chan->last_completion_time = jiffies; |
Maciej Sosnowski | 09177e8 | 2008-07-22 10:07:33 -0700 | [diff] [blame] | 756 | |
| 757 | cookie = 0; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 758 | if (!spin_trylock_bh(&ioat->desc_lock)) { |
| 759 | spin_unlock_bh(&chan->cleanup_lock); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 760 | return; |
| 761 | } |
| 762 | |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 763 | dev_dbg(to_dev(chan), "%s: phys_complete: %lx\n", |
| 764 | __func__, phys_complete); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 765 | list_for_each_entry_safe(desc, _desc, &ioat->used_desc, node) { |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 766 | tx = &desc->txd; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 767 | /* |
| 768 | * Incoming DMA requests may use multiple descriptors, |
| 769 | * due to exceeding xfercap, perhaps. If so, only the |
| 770 | * last one will have a cookie, and require unmapping. |
| 771 | */ |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 772 | dump_desc_dbg(ioat, desc); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 773 | if (tx->cookie) { |
| 774 | cookie = tx->cookie; |
| 775 | ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw); |
| 776 | if (tx->callback) { |
| 777 | tx->callback(tx->callback_param); |
| 778 | tx->callback = NULL; |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 779 | } |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 780 | } |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 781 | |
| 782 | if (tx->phys != phys_complete) { |
| 783 | /* |
| 784 | * a completed entry, but not the last, so clean |
| 785 | * up if the client is done with the descriptor |
| 786 | */ |
| 787 | if (async_tx_test_ack(tx)) |
| 788 | list_move_tail(&desc->node, &ioat->free_desc); |
| 789 | else |
| 790 | tx->cookie = 0; |
| 791 | } else { |
| 792 | /* |
| 793 | * last used desc. Do not remove, so we can |
| 794 | * append from it, but don't look at it next |
| 795 | * time, either |
| 796 | */ |
| 797 | tx->cookie = 0; |
| 798 | |
| 799 | /* TODO check status bits? */ |
| 800 | break; |
| 801 | } |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 804 | spin_unlock_bh(&ioat->desc_lock); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 805 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 806 | chan->last_completion = phys_complete; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 807 | if (cookie != 0) |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 808 | chan->completed_cookie = cookie; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 809 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 810 | spin_unlock_bh(&chan->cleanup_lock); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 813 | static enum dma_status |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 814 | ioat1_dma_is_complete(struct dma_chan *c, dma_cookie_t cookie, |
| 815 | dma_cookie_t *done, dma_cookie_t *used) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 816 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 817 | struct ioat_dma_chan *ioat = to_ioat_chan(c); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 818 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 819 | if (ioat_is_complete(c, cookie, done, used) == DMA_SUCCESS) |
| 820 | return DMA_SUCCESS; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 821 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 822 | ioat1_cleanup(ioat); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 823 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 824 | return ioat_is_complete(c, cookie, done, used); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 827 | static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 828 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 829 | struct ioat_chan_common *chan = &ioat->base; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 830 | struct ioat_desc_sw *desc; |
Dan Williams | c7984f4 | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 831 | struct ioat_dma_descriptor *hw; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 832 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 833 | spin_lock_bh(&ioat->desc_lock); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 834 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 835 | desc = ioat1_dma_get_next_descriptor(ioat); |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 836 | |
| 837 | if (!desc) { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 838 | dev_err(to_dev(chan), |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 839 | "Unable to start null desc - get next desc failed\n"); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 840 | spin_unlock_bh(&ioat->desc_lock); |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 841 | return; |
| 842 | } |
| 843 | |
Dan Williams | c7984f4 | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 844 | hw = desc->hw; |
| 845 | hw->ctl = 0; |
| 846 | hw->ctl_f.null = 1; |
| 847 | hw->ctl_f.int_en = 1; |
| 848 | hw->ctl_f.compl_write = 1; |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 849 | /* set size to non-zero value (channel returns error when size is 0) */ |
Dan Williams | c7984f4 | 2009-07-28 14:44:04 -0700 | [diff] [blame] | 850 | hw->size = NULL_DESC_BUFFER_SIZE; |
| 851 | hw->src_addr = 0; |
| 852 | hw->dst_addr = 0; |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 853 | async_tx_ack(&desc->txd); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 854 | hw->next = 0; |
| 855 | list_add_tail(&desc->node, &ioat->used_desc); |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 856 | dump_desc_dbg(ioat, desc); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 857 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 858 | writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF, |
| 859 | chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW); |
| 860 | writel(((u64) desc->txd.phys) >> 32, |
| 861 | chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH); |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 862 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 863 | writeb(IOAT_CHANCMD_START, chan->reg_base |
| 864 | + IOAT_CHANCMD_OFFSET(chan->device->version)); |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 865 | spin_unlock_bh(&ioat->desc_lock); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /* |
| 869 | * Perform a IOAT transaction to verify the HW works. |
| 870 | */ |
| 871 | #define IOAT_TEST_SIZE 2000 |
| 872 | |
Dan Williams | 345d852 | 2009-09-08 12:01:30 -0700 | [diff] [blame] | 873 | static void __devinit ioat_dma_test_callback(void *dma_async_param) |
Shannon Nelson | 9521843 | 2007-10-18 03:07:15 -0700 | [diff] [blame] | 874 | { |
Dan Williams | b9bdcbb | 2009-01-06 11:38:22 -0700 | [diff] [blame] | 875 | struct completion *cmp = dma_async_param; |
| 876 | |
| 877 | complete(cmp); |
Shannon Nelson | 9521843 | 2007-10-18 03:07:15 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 880 | /** |
| 881 | * ioat_dma_self_test - Perform a IOAT transaction to verify the HW works. |
| 882 | * @device: device to be tested |
| 883 | */ |
Dan Williams | 345d852 | 2009-09-08 12:01:30 -0700 | [diff] [blame] | 884 | static int __devinit ioat_dma_self_test(struct ioatdma_device *device) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 885 | { |
| 886 | int i; |
| 887 | u8 *src; |
| 888 | u8 *dest; |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 889 | struct dma_device *dma = &device->common; |
| 890 | struct device *dev = &device->pdev->dev; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 891 | struct dma_chan *dma_chan; |
Shannon Nelson | 711924b | 2007-12-17 16:20:08 -0800 | [diff] [blame] | 892 | struct dma_async_tx_descriptor *tx; |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 893 | dma_addr_t dma_dest, dma_src; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 894 | dma_cookie_t cookie; |
| 895 | int err = 0; |
Dan Williams | b9bdcbb | 2009-01-06 11:38:22 -0700 | [diff] [blame] | 896 | struct completion cmp; |
Dan Williams | 0c33e1c | 2009-03-02 13:31:35 -0700 | [diff] [blame] | 897 | unsigned long tmo; |
Maciej Sosnowski | 4f005db | 2009-04-23 12:31:51 +0200 | [diff] [blame] | 898 | unsigned long flags; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 899 | |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 900 | src = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 901 | if (!src) |
| 902 | return -ENOMEM; |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 903 | dest = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 904 | if (!dest) { |
| 905 | kfree(src); |
| 906 | return -ENOMEM; |
| 907 | } |
| 908 | |
| 909 | /* Fill in src buffer */ |
| 910 | for (i = 0; i < IOAT_TEST_SIZE; i++) |
| 911 | src[i] = (u8)i; |
| 912 | |
| 913 | /* Start copy, using first DMA channel */ |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 914 | dma_chan = container_of(dma->channels.next, struct dma_chan, |
Shannon Nelson | 43d6e36 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 915 | device_node); |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 916 | if (dma->device_alloc_chan_resources(dma_chan) < 1) { |
| 917 | dev_err(dev, "selftest cannot allocate chan resource\n"); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 918 | err = -ENODEV; |
| 919 | goto out; |
| 920 | } |
| 921 | |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 922 | dma_src = dma_map_single(dev, src, IOAT_TEST_SIZE, DMA_TO_DEVICE); |
| 923 | dma_dest = dma_map_single(dev, dest, IOAT_TEST_SIZE, DMA_FROM_DEVICE); |
Dan Williams | a6a39ca | 2009-07-28 14:44:05 -0700 | [diff] [blame] | 924 | flags = DMA_COMPL_SRC_UNMAP_SINGLE | DMA_COMPL_DEST_UNMAP_SINGLE | |
| 925 | DMA_PREP_INTERRUPT; |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 926 | tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src, |
Maciej Sosnowski | 4f005db | 2009-04-23 12:31:51 +0200 | [diff] [blame] | 927 | IOAT_TEST_SIZE, flags); |
Shannon Nelson | 5149fd0 | 2007-10-18 03:07:13 -0700 | [diff] [blame] | 928 | if (!tx) { |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 929 | dev_err(dev, "Self-test prep failed, disabling\n"); |
Shannon Nelson | 5149fd0 | 2007-10-18 03:07:13 -0700 | [diff] [blame] | 930 | err = -ENODEV; |
| 931 | goto free_resources; |
| 932 | } |
| 933 | |
Dan Williams | 7405f74 | 2007-01-02 11:10:43 -0700 | [diff] [blame] | 934 | async_tx_ack(tx); |
Dan Williams | b9bdcbb | 2009-01-06 11:38:22 -0700 | [diff] [blame] | 935 | init_completion(&cmp); |
Shannon Nelson | 9521843 | 2007-10-18 03:07:15 -0700 | [diff] [blame] | 936 | tx->callback = ioat_dma_test_callback; |
Dan Williams | b9bdcbb | 2009-01-06 11:38:22 -0700 | [diff] [blame] | 937 | tx->callback_param = &cmp; |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 938 | cookie = tx->tx_submit(tx); |
Shannon Nelson | 7f2b291 | 2007-10-18 03:07:14 -0700 | [diff] [blame] | 939 | if (cookie < 0) { |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 940 | dev_err(dev, "Self-test setup failed, disabling\n"); |
Shannon Nelson | 7f2b291 | 2007-10-18 03:07:14 -0700 | [diff] [blame] | 941 | err = -ENODEV; |
| 942 | goto free_resources; |
| 943 | } |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 944 | dma->device_issue_pending(dma_chan); |
Dan Williams | 532d3b1 | 2008-12-03 17:16:55 -0700 | [diff] [blame] | 945 | |
Dan Williams | 0c33e1c | 2009-03-02 13:31:35 -0700 | [diff] [blame] | 946 | tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 947 | |
Dan Williams | 0c33e1c | 2009-03-02 13:31:35 -0700 | [diff] [blame] | 948 | if (tmo == 0 || |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 949 | dma->device_is_tx_complete(dma_chan, cookie, NULL, NULL) |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 950 | != DMA_SUCCESS) { |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 951 | dev_err(dev, "Self-test copy timed out, disabling\n"); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 952 | err = -ENODEV; |
| 953 | goto free_resources; |
| 954 | } |
| 955 | if (memcmp(src, dest, IOAT_TEST_SIZE)) { |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 956 | dev_err(dev, "Self-test copy failed compare, disabling\n"); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 957 | err = -ENODEV; |
| 958 | goto free_resources; |
| 959 | } |
| 960 | |
| 961 | free_resources: |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 962 | dma->device_free_chan_resources(dma_chan); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 963 | out: |
| 964 | kfree(src); |
| 965 | kfree(dest); |
| 966 | return err; |
| 967 | } |
| 968 | |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 969 | static char ioat_interrupt_style[32] = "msix"; |
| 970 | module_param_string(ioat_interrupt_style, ioat_interrupt_style, |
| 971 | sizeof(ioat_interrupt_style), 0644); |
| 972 | MODULE_PARM_DESC(ioat_interrupt_style, |
| 973 | "set ioat interrupt style: msix (default), " |
| 974 | "msix-single-vector, msi, intx)"); |
| 975 | |
| 976 | /** |
| 977 | * ioat_dma_setup_interrupts - setup interrupt handler |
| 978 | * @device: ioat device |
| 979 | */ |
| 980 | static int ioat_dma_setup_interrupts(struct ioatdma_device *device) |
| 981 | { |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 982 | struct ioat_chan_common *chan; |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 983 | struct pci_dev *pdev = device->pdev; |
| 984 | struct device *dev = &pdev->dev; |
| 985 | struct msix_entry *msix; |
| 986 | int i, j, msixcnt; |
| 987 | int err = -EINVAL; |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 988 | u8 intrctrl = 0; |
| 989 | |
| 990 | if (!strcmp(ioat_interrupt_style, "msix")) |
| 991 | goto msix; |
| 992 | if (!strcmp(ioat_interrupt_style, "msix-single-vector")) |
| 993 | goto msix_single_vector; |
| 994 | if (!strcmp(ioat_interrupt_style, "msi")) |
| 995 | goto msi; |
| 996 | if (!strcmp(ioat_interrupt_style, "intx")) |
| 997 | goto intx; |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 998 | dev_err(dev, "invalid ioat_interrupt_style %s\n", ioat_interrupt_style); |
Shannon Nelson | 5149fd0 | 2007-10-18 03:07:13 -0700 | [diff] [blame] | 999 | goto err_no_irq; |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1000 | |
| 1001 | msix: |
| 1002 | /* The number of MSI-X vectors should equal the number of channels */ |
| 1003 | msixcnt = device->common.chancnt; |
| 1004 | for (i = 0; i < msixcnt; i++) |
| 1005 | device->msix_entries[i].entry = i; |
| 1006 | |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1007 | err = pci_enable_msix(pdev, device->msix_entries, msixcnt); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1008 | if (err < 0) |
| 1009 | goto msi; |
| 1010 | if (err > 0) |
| 1011 | goto msix_single_vector; |
| 1012 | |
| 1013 | for (i = 0; i < msixcnt; i++) { |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1014 | msix = &device->msix_entries[i]; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 1015 | chan = ioat_chan_by_index(device, i); |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1016 | err = devm_request_irq(dev, msix->vector, |
| 1017 | ioat_dma_do_interrupt_msix, 0, |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 1018 | "ioat-msix", chan); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1019 | if (err) { |
| 1020 | for (j = 0; j < i; j++) { |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1021 | msix = &device->msix_entries[j]; |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 1022 | chan = ioat_chan_by_index(device, j); |
| 1023 | devm_free_irq(dev, msix->vector, chan); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1024 | } |
| 1025 | goto msix_single_vector; |
| 1026 | } |
| 1027 | } |
| 1028 | intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL; |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1029 | goto done; |
| 1030 | |
| 1031 | msix_single_vector: |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1032 | msix = &device->msix_entries[0]; |
| 1033 | msix->entry = 0; |
| 1034 | err = pci_enable_msix(pdev, device->msix_entries, 1); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1035 | if (err) |
| 1036 | goto msi; |
| 1037 | |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1038 | err = devm_request_irq(dev, msix->vector, ioat_dma_do_interrupt, 0, |
| 1039 | "ioat-msix", device); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1040 | if (err) { |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1041 | pci_disable_msix(pdev); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1042 | goto msi; |
| 1043 | } |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1044 | goto done; |
| 1045 | |
| 1046 | msi: |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1047 | err = pci_enable_msi(pdev); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1048 | if (err) |
| 1049 | goto intx; |
| 1050 | |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1051 | err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt, 0, |
| 1052 | "ioat-msi", device); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1053 | if (err) { |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1054 | pci_disable_msi(pdev); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1055 | goto intx; |
| 1056 | } |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1057 | goto done; |
| 1058 | |
| 1059 | intx: |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1060 | err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt, |
| 1061 | IRQF_SHARED, "ioat-intx", device); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1062 | if (err) |
| 1063 | goto err_no_irq; |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1064 | |
| 1065 | done: |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1066 | if (device->intr_quirk) |
| 1067 | device->intr_quirk(device); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1068 | intrctrl |= IOAT_INTRCTRL_MASTER_INT_EN; |
| 1069 | writeb(intrctrl, device->reg_base + IOAT_INTRCTRL_OFFSET); |
| 1070 | return 0; |
| 1071 | |
| 1072 | err_no_irq: |
| 1073 | /* Disable all interrupt generation */ |
| 1074 | writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET); |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1075 | dev_err(dev, "no usable interrupts\n"); |
| 1076 | return err; |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1079 | static void ioat_disable_interrupts(struct ioatdma_device *device) |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1080 | { |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1081 | /* Disable all interrupt generation */ |
| 1082 | writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
Dan Williams | 345d852 | 2009-09-08 12:01:30 -0700 | [diff] [blame] | 1085 | int __devinit ioat_probe(struct ioatdma_device *device) |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1086 | { |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1087 | int err = -ENODEV; |
| 1088 | struct dma_device *dma = &device->common; |
| 1089 | struct pci_dev *pdev = device->pdev; |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1090 | struct device *dev = &pdev->dev; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1091 | |
| 1092 | /* DMA coherent memory pool for DMA descriptor allocations */ |
| 1093 | device->dma_pool = pci_pool_create("dma_desc_pool", pdev, |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 1094 | sizeof(struct ioat_dma_descriptor), |
| 1095 | 64, 0); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1096 | if (!device->dma_pool) { |
| 1097 | err = -ENOMEM; |
| 1098 | goto err_dma_pool; |
| 1099 | } |
| 1100 | |
Shannon Nelson | 43d6e36 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 1101 | device->completion_pool = pci_pool_create("completion_pool", pdev, |
| 1102 | sizeof(u64), SMP_CACHE_BYTES, |
| 1103 | SMP_CACHE_BYTES); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 1104 | |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1105 | if (!device->completion_pool) { |
| 1106 | err = -ENOMEM; |
| 1107 | goto err_completion_pool; |
| 1108 | } |
| 1109 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 1110 | device->enumerate_channels(device); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1111 | |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1112 | dma_cap_set(DMA_MEMCPY, dma->cap_mask); |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1113 | dma->dev = &pdev->dev; |
Shannon Nelson | 7bb67c1 | 2007-11-14 16:59:51 -0800 | [diff] [blame] | 1114 | |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1115 | dev_err(dev, "Intel(R) I/OAT DMA Engine found," |
Shannon Nelson | 5149fd0 | 2007-10-18 03:07:13 -0700 | [diff] [blame] | 1116 | " %d channels, device version 0x%02x, driver version %s\n", |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 1117 | dma->chancnt, device->version, IOAT_DMA_VERSION); |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 1118 | |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 1119 | if (!dma->chancnt) { |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1120 | dev_err(dev, "Intel(R) I/OAT DMA Engine problem found: " |
Maciej Sosnowski | 8b794b1 | 2009-02-26 11:04:54 +0100 | [diff] [blame] | 1121 | "zero channels detected\n"); |
| 1122 | goto err_setup_interrupts; |
| 1123 | } |
| 1124 | |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1125 | err = ioat_dma_setup_interrupts(device); |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 1126 | if (err) |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1127 | goto err_setup_interrupts; |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 1128 | |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1129 | err = ioat_dma_self_test(device); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1130 | if (err) |
| 1131 | goto err_self_test; |
| 1132 | |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1133 | return 0; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1134 | |
| 1135 | err_self_test: |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1136 | ioat_disable_interrupts(device); |
Shannon Nelson | 3e03745 | 2007-10-16 01:27:40 -0700 | [diff] [blame] | 1137 | err_setup_interrupts: |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1138 | pci_pool_destroy(device->completion_pool); |
| 1139 | err_completion_pool: |
| 1140 | pci_pool_destroy(device->dma_pool); |
| 1141 | err_dma_pool: |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1142 | return err; |
| 1143 | } |
| 1144 | |
Dan Williams | 345d852 | 2009-09-08 12:01:30 -0700 | [diff] [blame] | 1145 | int __devinit ioat_register(struct ioatdma_device *device) |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1146 | { |
| 1147 | int err = dma_async_device_register(&device->common); |
| 1148 | |
| 1149 | if (err) { |
| 1150 | ioat_disable_interrupts(device); |
| 1151 | pci_pool_destroy(device->completion_pool); |
| 1152 | pci_pool_destroy(device->dma_pool); |
| 1153 | } |
| 1154 | |
| 1155 | return err; |
| 1156 | } |
| 1157 | |
| 1158 | /* ioat1_intr_quirk - fix up dma ctrl register to enable / disable msi */ |
| 1159 | static void ioat1_intr_quirk(struct ioatdma_device *device) |
| 1160 | { |
| 1161 | struct pci_dev *pdev = device->pdev; |
| 1162 | u32 dmactrl; |
| 1163 | |
| 1164 | pci_read_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, &dmactrl); |
| 1165 | if (pdev->msi_enabled) |
| 1166 | dmactrl |= IOAT_PCI_DMACTRL_MSI_EN; |
| 1167 | else |
| 1168 | dmactrl &= ~IOAT_PCI_DMACTRL_MSI_EN; |
| 1169 | pci_write_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, dmactrl); |
| 1170 | } |
| 1171 | |
Dan Williams | 345d852 | 2009-09-08 12:01:30 -0700 | [diff] [blame] | 1172 | int __devinit ioat1_dma_probe(struct ioatdma_device *device, int dca) |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1173 | { |
| 1174 | struct pci_dev *pdev = device->pdev; |
| 1175 | struct dma_device *dma; |
| 1176 | int err; |
| 1177 | |
| 1178 | device->intr_quirk = ioat1_intr_quirk; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 1179 | device->enumerate_channels = ioat1_enumerate_channels; |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1180 | dma = &device->common; |
| 1181 | dma->device_prep_dma_memcpy = ioat1_dma_prep_memcpy; |
| 1182 | dma->device_issue_pending = ioat1_dma_memcpy_issue_pending; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 1183 | dma->device_alloc_chan_resources = ioat1_dma_alloc_chan_resources; |
| 1184 | dma->device_free_chan_resources = ioat1_dma_free_chan_resources; |
| 1185 | dma->device_is_tx_complete = ioat1_dma_is_complete; |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1186 | |
| 1187 | err = ioat_probe(device); |
| 1188 | if (err) |
| 1189 | return err; |
| 1190 | ioat_set_tcp_copy_break(4096); |
| 1191 | err = ioat_register(device); |
| 1192 | if (err) |
| 1193 | return err; |
| 1194 | if (dca) |
| 1195 | device->dca = ioat_dca_init(pdev, device->reg_base); |
| 1196 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 1197 | INIT_DELAYED_WORK(&device->work, ioat1_chan_watchdog); |
Dan Williams | f2427e2 | 2009-07-28 14:42:38 -0700 | [diff] [blame] | 1198 | schedule_delayed_work(&device->work, WATCHDOG_DELAY); |
| 1199 | |
| 1200 | return err; |
| 1201 | } |
| 1202 | |
Dan Williams | 345d852 | 2009-09-08 12:01:30 -0700 | [diff] [blame] | 1203 | void __devexit ioat_dma_remove(struct ioatdma_device *device) |
Dan Aloni | 428ed60 | 2007-03-08 09:57:36 -0800 | [diff] [blame] | 1204 | { |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 1205 | struct dma_device *dma = &device->common; |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1206 | |
Maciej Sosnowski | 2b8a6bf | 2009-02-26 11:05:07 +0100 | [diff] [blame] | 1207 | if (device->version != IOAT_VER_3_0) |
| 1208 | cancel_delayed_work(&device->work); |
| 1209 | |
Dan Williams | e6c0b69 | 2009-09-08 17:29:44 -0700 | [diff] [blame] | 1210 | ioat_disable_interrupts(device); |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 1211 | |
Dan Williams | bc3c702 | 2009-07-28 14:33:42 -0700 | [diff] [blame] | 1212 | dma_async_device_unregister(dma); |
Shannon Nelson | dfe2299 | 2007-10-18 03:07:13 -0700 | [diff] [blame] | 1213 | |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1214 | pci_pool_destroy(device->dma_pool); |
| 1215 | pci_pool_destroy(device->completion_pool); |
Shannon Nelson | 8ab8956 | 2007-10-16 01:27:39 -0700 | [diff] [blame] | 1216 | |
Dan Williams | dcbc853 | 2009-07-28 14:44:50 -0700 | [diff] [blame] | 1217 | INIT_LIST_HEAD(&dma->channels); |
Chris Leech | 0bbd5f4 | 2006-05-23 17:35:34 -0700 | [diff] [blame] | 1218 | } |