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