blob: 17a518d0386f2094be5416909a4e8702ad9ac36b [file] [log] [blame]
Chris Leech0bbd5f42006-05-23 17:35:34 -07001/*
Shannon Nelson43d6e362007-10-16 01:27:39 -07002 * Intel I/OAT DMA Linux driver
Maciej Sosnowski211a22c2009-02-26 11:05:43 +01003 * Copyright(c) 2004 - 2009 Intel Corporation.
Chris Leech0bbd5f42006-05-23 17:35:34 -07004 *
5 * This program is free software; you can redistribute it and/or modify it
Shannon Nelson43d6e362007-10-16 01:27:39 -07006 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
Chris Leech0bbd5f42006-05-23 17:35:34 -07008 *
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 Nelson43d6e362007-10-16 01:27:39 -070015 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
Chris Leech0bbd5f42006-05-23 17:35:34 -070017 *
Shannon Nelson43d6e362007-10-16 01:27:39 -070018 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
Chris Leech0bbd5f42006-05-23 17:35:34 -070021 */
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. Miller6b00c922006-05-23 17:37:58 -070034#include <linux/dma-mapping.h>
Maciej Sosnowski09177e82008-07-22 10:07:33 -070035#include <linux/workqueue.h>
Venki Pallipadi3ad0b022008-10-22 16:34:52 -070036#include <linux/i7300_idle.h>
Dan Williams584ec222009-07-28 14:32:12 -070037#include "dma.h"
38#include "registers.h"
39#include "hw.h"
Chris Leech0bbd5f42006-05-23 17:35:34 -070040
Dan Williams5cbafa62009-08-26 13:01:44 -070041int ioat_pending_level = 4;
Shannon Nelson7bb67c12007-11-14 16:59:51 -080042module_param(ioat_pending_level, int, 0644);
43MODULE_PARM_DESC(ioat_pending_level,
44 "high-water mark for pushing ioat descriptors (default: 4)");
45
Chris Leech0bbd5f42006-05-23 17:35:34 -070046/* internal functions */
Dan Williams5cbafa62009-08-26 13:01:44 -070047static void ioat1_cleanup(struct ioat_dma_chan *ioat);
48static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat);
Shannon Nelson3e037452007-10-16 01:27:40 -070049
50/**
51 * ioat_dma_do_interrupt - handler used for single vector interrupt mode
52 * @irq: interrupt id
53 * @data: interrupt data
54 */
55static irqreturn_t ioat_dma_do_interrupt(int irq, void *data)
56{
57 struct ioatdma_device *instance = data;
Dan Williamsdcbc8532009-07-28 14:44:50 -070058 struct ioat_chan_common *chan;
Shannon Nelson3e037452007-10-16 01:27:40 -070059 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 Williamsdcbc8532009-07-28 14:44:50 -070075 chan = ioat_chan_by_index(instance, bit);
76 tasklet_schedule(&chan->cleanup_task);
Shannon Nelson3e037452007-10-16 01:27:40 -070077 }
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 */
88static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)
89{
Dan Williamsdcbc8532009-07-28 14:44:50 -070090 struct ioat_chan_common *chan = data;
Shannon Nelson3e037452007-10-16 01:27:40 -070091
Dan Williamsdcbc8532009-07-28 14:44:50 -070092 tasklet_schedule(&chan->cleanup_task);
Shannon Nelson3e037452007-10-16 01:27:40 -070093
94 return IRQ_HANDLED;
95}
96
Dan Williams5cbafa62009-08-26 13:01:44 -070097static void ioat1_cleanup_tasklet(unsigned long data);
98
99/* common channel initialization */
100void ioat_init_channel(struct ioatdma_device *device,
101 struct ioat_chan_common *chan, int idx,
Dan Williams09c8a5b2009-09-08 12:01:49 -0700102 void (*timer_fn)(unsigned long),
103 void (*tasklet)(unsigned long),
104 unsigned long ioat)
Dan Williams5cbafa62009-08-26 13:01:44 -0700105{
106 struct dma_device *dma = &device->common;
107
108 chan->device = device;
109 chan->reg_base = device->reg_base + (0x80 * (idx + 1));
Dan Williams5cbafa62009-08-26 13:01:44 -0700110 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 Williams09c8a5b2009-09-08 12:01:49 -0700114 init_timer(&chan->timer);
115 chan->timer.function = timer_fn;
116 chan->timer.data = ioat;
117 tasklet_init(&chan->cleanup_task, tasklet, ioat);
Dan Williams5cbafa62009-08-26 13:01:44 -0700118 tasklet_disable(&chan->cleanup_task);
119}
120
Dan Williams09c8a5b2009-09-08 12:01:49 -0700121static void ioat1_timer_event(unsigned long data);
Shannon Nelson3e037452007-10-16 01:27:40 -0700122
123/**
Dan Williams5cbafa62009-08-26 13:01:44 -0700124 * ioat1_dma_enumerate_channels - find and initialize the device's channels
Shannon Nelson3e037452007-10-16 01:27:40 -0700125 * @device: the device to be enumerated
126 */
Dan Williams5cbafa62009-08-26 13:01:44 -0700127static int ioat1_enumerate_channels(struct ioatdma_device *device)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700128{
129 u8 xfercap_scale;
130 u32 xfercap;
131 int i;
Dan Williamsdcbc8532009-07-28 14:44:50 -0700132 struct ioat_dma_chan *ioat;
Dan Williamse6c0b692009-09-08 17:29:44 -0700133 struct device *dev = &device->pdev->dev;
Dan Williamsf2427e22009-07-28 14:42:38 -0700134 struct dma_device *dma = &device->common;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700135
Dan Williamsf2427e22009-07-28 14:42:38 -0700136 INIT_LIST_HEAD(&dma->channels);
137 dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET);
Dan Williamsbb320782009-09-08 12:01:14 -0700138 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 Leeche3828812007-03-08 09:57:35 -0800144 xfercap_scale = readb(device->reg_base + IOAT_XFERCAP_OFFSET);
Dan Williamsbb320782009-09-08 12:01:14 -0700145 xfercap_scale &= 0x1f; /* bits [4:0] valid */
Chris Leech0bbd5f42006-05-23 17:35:34 -0700146 xfercap = (xfercap_scale == 0 ? -1 : (1UL << xfercap_scale));
Dan Williams6df91832009-09-08 12:00:55 -0700147 dev_dbg(dev, "%s: xfercap = %d\n", __func__, xfercap);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700148
Venki Pallipadif371be62008-10-23 15:39:06 -0700149#ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL
Dan Williamsf2427e22009-07-28 14:42:38 -0700150 if (i7300_idle_platform_probe(NULL, NULL, 1) == 0)
151 dma->chancnt--;
Andy Henroid27471fd2008-10-09 11:45:22 -0700152#endif
Dan Williamsf2427e22009-07-28 14:42:38 -0700153 for (i = 0; i < dma->chancnt; i++) {
Dan Williamsdcbc8532009-07-28 14:44:50 -0700154 ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL);
Dan Williams5cbafa62009-08-26 13:01:44 -0700155 if (!ioat)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700156 break;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700157
Dan Williams5cbafa62009-08-26 13:01:44 -0700158 ioat_init_channel(device, &ioat->base, i,
Dan Williams09c8a5b2009-09-08 12:01:49 -0700159 ioat1_timer_event,
Dan Williams5cbafa62009-08-26 13:01:44 -0700160 ioat1_cleanup_tasklet,
161 (unsigned long) ioat);
Dan Williamsdcbc8532009-07-28 14:44:50 -0700162 ioat->xfercap = xfercap;
Dan Williamsdcbc8532009-07-28 14:44:50 -0700163 spin_lock_init(&ioat->desc_lock);
164 INIT_LIST_HEAD(&ioat->free_desc);
165 INIT_LIST_HEAD(&ioat->used_desc);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700166 }
Dan Williams5cbafa62009-08-26 13:01:44 -0700167 dma->chancnt = i;
168 return i;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700169}
170
Shannon Nelson711924b2007-12-17 16:20:08 -0800171/**
172 * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended
173 * descriptors to hw
174 * @chan: DMA channel handle
175 */
Dan Williamsbc3c7022009-07-28 14:33:42 -0700176static inline void
Dan Williamsdcbc8532009-07-28 14:44:50 -0700177__ioat1_dma_memcpy_issue_pending(struct ioat_dma_chan *ioat)
Shannon Nelson711924b2007-12-17 16:20:08 -0800178{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700179 void __iomem *reg_base = ioat->base.reg_base;
180
Dan Williams6df91832009-09-08 12:00:55 -0700181 dev_dbg(to_dev(&ioat->base), "%s: pending: %d\n",
182 __func__, ioat->pending);
Dan Williamsdcbc8532009-07-28 14:44:50 -0700183 ioat->pending = 0;
184 writeb(IOAT_CHANCMD_APPEND, reg_base + IOAT1_CHANCMD_OFFSET);
Shannon Nelson711924b2007-12-17 16:20:08 -0800185}
186
187static void ioat1_dma_memcpy_issue_pending(struct dma_chan *chan)
188{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700189 struct ioat_dma_chan *ioat = to_ioat_chan(chan);
Shannon Nelson711924b2007-12-17 16:20:08 -0800190
Dan Williamsdcbc8532009-07-28 14:44:50 -0700191 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 Nelson711924b2007-12-17 16:20:08 -0800195 }
196}
197
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700198/**
Dan Williams5cbafa62009-08-26 13:01:44 -0700199 * ioat1_reset_channel - restart a channel
Dan Williamsdcbc8532009-07-28 14:44:50 -0700200 * @ioat: IOAT DMA channel handle
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700201 */
Dan Williams5cbafa62009-08-26 13:01:44 -0700202static void ioat1_reset_channel(struct ioat_dma_chan *ioat)
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700203{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700204 struct ioat_chan_common *chan = &ioat->base;
205 void __iomem *reg_base = chan->reg_base;
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700206 u32 chansts, chanerr;
207
Dan Williams09c8a5b2009-09-08 12:01:49 -0700208 dev_warn(to_dev(chan), "reset\n");
Dan Williamsdcbc8532009-07-28 14:44:50 -0700209 chanerr = readl(reg_base + IOAT_CHANERR_OFFSET);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700210 chansts = *chan->completion & IOAT_CHANSTS_STATUS;
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700211 if (chanerr) {
Dan Williamsdcbc8532009-07-28 14:44:50 -0700212 dev_err(to_dev(chan),
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700213 "chan%d, CHANSTS = 0x%08x CHANERR = 0x%04x, clearing\n",
Dan Williamsdcbc8532009-07-28 14:44:50 -0700214 chan_num(chan), chansts, chanerr);
215 writel(chanerr, reg_base + IOAT_CHANERR_OFFSET);
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700216 }
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 Williamsdcbc8532009-07-28 14:44:50 -0700226 ioat->pending = INT_MIN;
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700227 writeb(IOAT_CHANCMD_RESET,
Dan Williamsdcbc8532009-07-28 14:44:50 -0700228 reg_base + IOAT_CHANCMD_OFFSET(chan->device->version));
Dan Williams09c8a5b2009-09-08 12:01:49 -0700229 set_bit(IOAT_RESET_PENDING, &chan->state);
230 mod_timer(&chan->timer, jiffies + RESET_DELAY);
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700231}
232
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800233static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
Dan Williams7405f742007-01-02 11:10:43 -0700234{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700235 struct dma_chan *c = tx->chan;
236 struct ioat_dma_chan *ioat = to_ioat_chan(c);
Dan Williamsa0587bc2009-07-28 14:44:04 -0700237 struct ioat_desc_sw *desc = tx_to_ioat_desc(tx);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700238 struct ioat_chan_common *chan = &ioat->base;
Dan Williamsa0587bc2009-07-28 14:44:04 -0700239 struct ioat_desc_sw *first;
240 struct ioat_desc_sw *chain_tail;
Dan Williams7405f742007-01-02 11:10:43 -0700241 dma_cookie_t cookie;
Shannon Nelson7f2b2912007-10-18 03:07:14 -0700242
Dan Williamsdcbc8532009-07-28 14:44:50 -0700243 spin_lock_bh(&ioat->desc_lock);
Dan Williams7405f742007-01-02 11:10:43 -0700244 /* cookie incr and addition to used_list must be atomic */
Dan Williamsdcbc8532009-07-28 14:44:50 -0700245 cookie = c->cookie;
Dan Williams7405f742007-01-02 11:10:43 -0700246 cookie++;
247 if (cookie < 0)
248 cookie = 1;
Dan Williamsdcbc8532009-07-28 14:44:50 -0700249 c->cookie = cookie;
250 tx->cookie = cookie;
Dan Williams6df91832009-09-08 12:00:55 -0700251 dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie);
Dan Williams7405f742007-01-02 11:10:43 -0700252
253 /* write address into NextDescriptor field of last desc in chain */
Dan Williamsa0587bc2009-07-28 14:44:04 -0700254 first = to_ioat_desc(tx->tx_list.next);
Dan Williamsdcbc8532009-07-28 14:44:50 -0700255 chain_tail = to_ioat_desc(ioat->used_desc.prev);
Dan Williamsa0587bc2009-07-28 14:44:04 -0700256 /* make descriptor updates globally visible before chaining */
257 wmb();
258 chain_tail->hw->next = first->txd.phys;
Dan Williamsdcbc8532009-07-28 14:44:50 -0700259 list_splice_tail_init(&tx->tx_list, &ioat->used_desc);
Dan Williams6df91832009-09-08 12:00:55 -0700260 dump_desc_dbg(ioat, chain_tail);
261 dump_desc_dbg(ioat, first);
Dan Williams7405f742007-01-02 11:10:43 -0700262
Dan Williams09c8a5b2009-09-08 12:01:49 -0700263 if (!test_and_set_bit(IOAT_COMPLETION_PENDING, &chan->state))
264 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
265
Dan Williamsad643f52009-09-08 12:01:38 -0700266 ioat->pending += desc->hw->tx_cnt;
Dan Williamsdcbc8532009-07-28 14:44:50 -0700267 if (ioat->pending >= ioat_pending_level)
268 __ioat1_dma_memcpy_issue_pending(ioat);
269 spin_unlock_bh(&ioat->desc_lock);
Dan Williams7405f742007-01-02 11:10:43 -0700270
Dan Williams7405f742007-01-02 11:10:43 -0700271 return cookie;
272}
273
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800274/**
275 * ioat_dma_alloc_descriptor - allocate and return a sw and hw descriptor pair
Dan Williamsdcbc8532009-07-28 14:44:50 -0700276 * @ioat: the channel supplying the memory pool for the descriptors
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800277 * @flags: allocation flags
278 */
Dan Williamsbc3c7022009-07-28 14:33:42 -0700279static struct ioat_desc_sw *
Dan Williamsdcbc8532009-07-28 14:44:50 -0700280ioat_dma_alloc_descriptor(struct ioat_dma_chan *ioat, gfp_t flags)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700281{
282 struct ioat_dma_descriptor *desc;
283 struct ioat_desc_sw *desc_sw;
Shannon Nelson8ab89562007-10-16 01:27:39 -0700284 struct ioatdma_device *ioatdma_device;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700285 dma_addr_t phys;
286
Dan Williamsdcbc8532009-07-28 14:44:50 -0700287 ioatdma_device = ioat->base.device;
Shannon Nelson8ab89562007-10-16 01:27:39 -0700288 desc = pci_pool_alloc(ioatdma_device->dma_pool, flags, &phys);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700289 if (unlikely(!desc))
290 return NULL;
291
292 desc_sw = kzalloc(sizeof(*desc_sw), flags);
293 if (unlikely(!desc_sw)) {
Shannon Nelson8ab89562007-10-16 01:27:39 -0700294 pci_pool_free(ioatdma_device->dma_pool, desc, phys);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700295 return NULL;
296 }
297
298 memset(desc, 0, sizeof(*desc));
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800299
Dan Williams5cbafa62009-08-26 13:01:44 -0700300 dma_async_tx_descriptor_init(&desc_sw->txd, &ioat->base.common);
301 desc_sw->txd.tx_submit = ioat1_tx_submit;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700302 desc_sw->hw = desc;
Dan Williamsbc3c7022009-07-28 14:33:42 -0700303 desc_sw->txd.phys = phys;
Dan Williams6df91832009-09-08 12:00:55 -0700304 set_desc_id(desc_sw, -1);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700305
306 return desc_sw;
307}
308
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800309static int ioat_initial_desc_count = 256;
310module_param(ioat_initial_desc_count, int, 0644);
311MODULE_PARM_DESC(ioat_initial_desc_count,
Dan Williams5cbafa62009-08-26 13:01:44 -0700312 "ioat1: initial descriptors per channel (default: 256)");
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800313/**
Dan Williams5cbafa62009-08-26 13:01:44 -0700314 * ioat1_dma_alloc_chan_resources - returns the number of allocated descriptors
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800315 * @chan: the channel to be filled out
316 */
Dan Williams5cbafa62009-08-26 13:01:44 -0700317static int ioat1_dma_alloc_chan_resources(struct dma_chan *c)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700318{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700319 struct ioat_dma_chan *ioat = to_ioat_chan(c);
320 struct ioat_chan_common *chan = &ioat->base;
Shannon Nelson711924b2007-12-17 16:20:08 -0800321 struct ioat_desc_sw *desc;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700322 u32 chanerr;
323 int i;
324 LIST_HEAD(tmp_list);
325
Shannon Nelsone4223972007-08-24 23:02:53 -0700326 /* have we already been set up? */
Dan Williamsdcbc8532009-07-28 14:44:50 -0700327 if (!list_empty(&ioat->free_desc))
328 return ioat->desccount;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700329
Shannon Nelson43d6e362007-10-16 01:27:39 -0700330 /* Setup register to interrupt and write completion status on error */
Dan Williamsf6ab95b2009-09-08 12:01:21 -0700331 writew(IOAT_CHANCTRL_RUN, chan->reg_base + IOAT_CHANCTRL_OFFSET);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700332
Dan Williamsdcbc8532009-07-28 14:44:50 -0700333 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700334 if (chanerr) {
Dan Williamsdcbc8532009-07-28 14:44:50 -0700335 dev_err(to_dev(chan), "CHANERR = %x, clearing\n", chanerr);
336 writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700337 }
338
339 /* Allocate descriptors */
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800340 for (i = 0; i < ioat_initial_desc_count; i++) {
Dan Williamsdcbc8532009-07-28 14:44:50 -0700341 desc = ioat_dma_alloc_descriptor(ioat, GFP_KERNEL);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700342 if (!desc) {
Dan Williamsdcbc8532009-07-28 14:44:50 -0700343 dev_err(to_dev(chan), "Only %d initial descriptors\n", i);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700344 break;
345 }
Dan Williams6df91832009-09-08 12:00:55 -0700346 set_desc_id(desc, i);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700347 list_add_tail(&desc->node, &tmp_list);
348 }
Dan Williamsdcbc8532009-07-28 14:44:50 -0700349 spin_lock_bh(&ioat->desc_lock);
350 ioat->desccount = i;
351 list_splice(&tmp_list, &ioat->free_desc);
Dan Williamsdcbc8532009-07-28 14:44:50 -0700352 spin_unlock_bh(&ioat->desc_lock);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700353
354 /* allocate a completion writeback area */
355 /* doing 2 32bit writes to mmio since 1 64b write doesn't work */
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700356 chan->completion = pci_pool_alloc(chan->device->completion_pool,
357 GFP_KERNEL, &chan->completion_dma);
358 memset(chan->completion, 0, sizeof(*chan->completion));
359 writel(((u64) chan->completion_dma) & 0x00000000FFFFFFFF,
Dan Williamsdcbc8532009-07-28 14:44:50 -0700360 chan->reg_base + IOAT_CHANCMP_OFFSET_LOW);
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700361 writel(((u64) chan->completion_dma) >> 32,
Dan Williamsdcbc8532009-07-28 14:44:50 -0700362 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700363
Dan Williamsdcbc8532009-07-28 14:44:50 -0700364 tasklet_enable(&chan->cleanup_task);
Dan Williams5cbafa62009-08-26 13:01:44 -0700365 ioat1_dma_start_null_desc(ioat); /* give chain to dma device */
Dan Williams6df91832009-09-08 12:00:55 -0700366 dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n",
367 __func__, ioat->desccount);
Dan Williamsdcbc8532009-07-28 14:44:50 -0700368 return ioat->desccount;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700369}
370
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800371/**
Dan Williams5cbafa62009-08-26 13:01:44 -0700372 * ioat1_dma_free_chan_resources - release all the descriptors
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800373 * @chan: the channel to be cleaned
374 */
Dan Williams5cbafa62009-08-26 13:01:44 -0700375static void ioat1_dma_free_chan_resources(struct dma_chan *c)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700376{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700377 struct ioat_dma_chan *ioat = to_ioat_chan(c);
378 struct ioat_chan_common *chan = &ioat->base;
379 struct ioatdma_device *ioatdma_device = chan->device;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700380 struct ioat_desc_sw *desc, *_desc;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700381 int in_use_descs = 0;
382
Maciej Sosnowskic3d4f442008-11-07 01:45:52 +0000383 /* Before freeing channel resources first check
384 * if they have been previously allocated for this channel.
385 */
Dan Williamsdcbc8532009-07-28 14:44:50 -0700386 if (ioat->desccount == 0)
Maciej Sosnowskic3d4f442008-11-07 01:45:52 +0000387 return;
388
Dan Williamsdcbc8532009-07-28 14:44:50 -0700389 tasklet_disable(&chan->cleanup_task);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700390 del_timer_sync(&chan->timer);
Dan Williams5cbafa62009-08-26 13:01:44 -0700391 ioat1_cleanup(ioat);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700392
Shannon Nelson3e037452007-10-16 01:27:40 -0700393 /* Delay 100ms after reset to allow internal DMA logic to quiesce
394 * before removing DMA descriptor resources.
395 */
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800396 writeb(IOAT_CHANCMD_RESET,
Dan Williamsdcbc8532009-07-28 14:44:50 -0700397 chan->reg_base + IOAT_CHANCMD_OFFSET(chan->device->version));
Shannon Nelson3e037452007-10-16 01:27:40 -0700398 mdelay(100);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700399
Dan Williamsdcbc8532009-07-28 14:44:50 -0700400 spin_lock_bh(&ioat->desc_lock);
Dan Williams6df91832009-09-08 12:00:55 -0700401 list_for_each_entry_safe(desc, _desc, &ioat->used_desc, node) {
402 dev_dbg(to_dev(chan), "%s: freeing %d from used list\n",
403 __func__, desc_id(desc));
404 dump_desc_dbg(ioat, desc);
Dan Williams5cbafa62009-08-26 13:01:44 -0700405 in_use_descs++;
406 list_del(&desc->node);
Shannon Nelson8ab89562007-10-16 01:27:39 -0700407 pci_pool_free(ioatdma_device->dma_pool, desc->hw,
Dan Williamsbc3c7022009-07-28 14:33:42 -0700408 desc->txd.phys);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700409 kfree(desc);
Dan Williams5cbafa62009-08-26 13:01:44 -0700410 }
411 list_for_each_entry_safe(desc, _desc,
412 &ioat->free_desc, node) {
413 list_del(&desc->node);
414 pci_pool_free(ioatdma_device->dma_pool, desc->hw,
415 desc->txd.phys);
416 kfree(desc);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700417 }
Dan Williamsdcbc8532009-07-28 14:44:50 -0700418 spin_unlock_bh(&ioat->desc_lock);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700419
Shannon Nelson8ab89562007-10-16 01:27:39 -0700420 pci_pool_free(ioatdma_device->completion_pool,
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700421 chan->completion,
422 chan->completion_dma);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700423
424 /* one is ok since we left it on there on purpose */
425 if (in_use_descs > 1)
Dan Williamsdcbc8532009-07-28 14:44:50 -0700426 dev_err(to_dev(chan), "Freeing %d in use descriptors!\n",
Chris Leech0bbd5f42006-05-23 17:35:34 -0700427 in_use_descs - 1);
428
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700429 chan->last_completion = 0;
430 chan->completion_dma = 0;
Dan Williamsdcbc8532009-07-28 14:44:50 -0700431 ioat->pending = 0;
Dan Williamsdcbc8532009-07-28 14:44:50 -0700432 ioat->desccount = 0;
Shannon Nelson3e037452007-10-16 01:27:40 -0700433}
Shannon Nelson7f2b2912007-10-18 03:07:14 -0700434
Shannon Nelson3e037452007-10-16 01:27:40 -0700435/**
Dan Williamsdcbc8532009-07-28 14:44:50 -0700436 * ioat1_dma_get_next_descriptor - return the next available descriptor
437 * @ioat: IOAT DMA channel handle
Shannon Nelson3e037452007-10-16 01:27:40 -0700438 *
439 * Gets the next descriptor from the chain, and must be called with the
440 * channel's desc_lock held. Allocates more descriptors if the channel
441 * has run out.
442 */
Shannon Nelson7f2b2912007-10-18 03:07:14 -0700443static struct ioat_desc_sw *
Dan Williamsdcbc8532009-07-28 14:44:50 -0700444ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat)
Shannon Nelson3e037452007-10-16 01:27:40 -0700445{
Shannon Nelson711924b2007-12-17 16:20:08 -0800446 struct ioat_desc_sw *new;
Shannon Nelson3e037452007-10-16 01:27:40 -0700447
Dan Williamsdcbc8532009-07-28 14:44:50 -0700448 if (!list_empty(&ioat->free_desc)) {
449 new = to_ioat_desc(ioat->free_desc.next);
Shannon Nelson3e037452007-10-16 01:27:40 -0700450 list_del(&new->node);
451 } else {
452 /* try to get another desc */
Dan Williamsdcbc8532009-07-28 14:44:50 -0700453 new = ioat_dma_alloc_descriptor(ioat, GFP_ATOMIC);
Shannon Nelson711924b2007-12-17 16:20:08 -0800454 if (!new) {
Dan Williamsdcbc8532009-07-28 14:44:50 -0700455 dev_err(to_dev(&ioat->base), "alloc failed\n");
Shannon Nelson711924b2007-12-17 16:20:08 -0800456 return NULL;
457 }
Shannon Nelson3e037452007-10-16 01:27:40 -0700458 }
Dan Williams6df91832009-09-08 12:00:55 -0700459 dev_dbg(to_dev(&ioat->base), "%s: allocated: %d\n",
460 __func__, desc_id(new));
Shannon Nelson3e037452007-10-16 01:27:40 -0700461 prefetch(new->hw);
462 return new;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700463}
464
Dan Williamsbc3c7022009-07-28 14:33:42 -0700465static struct dma_async_tx_descriptor *
Dan Williamsdcbc8532009-07-28 14:44:50 -0700466ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
Dan Williamsbc3c7022009-07-28 14:33:42 -0700467 dma_addr_t dma_src, size_t len, unsigned long flags)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700468{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700469 struct ioat_dma_chan *ioat = to_ioat_chan(c);
Dan Williamsa0587bc2009-07-28 14:44:04 -0700470 struct ioat_desc_sw *desc;
471 size_t copy;
472 LIST_HEAD(chain);
473 dma_addr_t src = dma_src;
474 dma_addr_t dest = dma_dest;
475 size_t total_len = len;
476 struct ioat_dma_descriptor *hw = NULL;
477 int tx_cnt = 0;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700478
Dan Williamsdcbc8532009-07-28 14:44:50 -0700479 spin_lock_bh(&ioat->desc_lock);
Dan Williams5cbafa62009-08-26 13:01:44 -0700480 desc = ioat1_dma_get_next_descriptor(ioat);
Dan Williamsa0587bc2009-07-28 14:44:04 -0700481 do {
482 if (!desc)
483 break;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700484
Dan Williamsa0587bc2009-07-28 14:44:04 -0700485 tx_cnt++;
Dan Williamsdcbc8532009-07-28 14:44:50 -0700486 copy = min_t(size_t, len, ioat->xfercap);
Dan Williamsa0587bc2009-07-28 14:44:04 -0700487
488 hw = desc->hw;
489 hw->size = copy;
490 hw->ctl = 0;
491 hw->src_addr = src;
492 hw->dst_addr = dest;
493
494 list_add_tail(&desc->node, &chain);
495
496 len -= copy;
497 dest += copy;
498 src += copy;
499 if (len) {
500 struct ioat_desc_sw *next;
501
502 async_tx_ack(&desc->txd);
Dan Williams5cbafa62009-08-26 13:01:44 -0700503 next = ioat1_dma_get_next_descriptor(ioat);
Dan Williamsa0587bc2009-07-28 14:44:04 -0700504 hw->next = next ? next->txd.phys : 0;
Dan Williams6df91832009-09-08 12:00:55 -0700505 dump_desc_dbg(ioat, desc);
Dan Williamsa0587bc2009-07-28 14:44:04 -0700506 desc = next;
507 } else
508 hw->next = 0;
509 } while (len);
510
511 if (!desc) {
Dan Williamsdcbc8532009-07-28 14:44:50 -0700512 struct ioat_chan_common *chan = &ioat->base;
513
514 dev_err(to_dev(chan),
Dan Williams5cbafa62009-08-26 13:01:44 -0700515 "chan%d - get_next_desc failed\n", chan_num(chan));
Dan Williamsdcbc8532009-07-28 14:44:50 -0700516 list_splice(&chain, &ioat->free_desc);
517 spin_unlock_bh(&ioat->desc_lock);
Shannon Nelson711924b2007-12-17 16:20:08 -0800518 return NULL;
Maciej Sosnowski09177e82008-07-22 10:07:33 -0700519 }
Dan Williamsdcbc8532009-07-28 14:44:50 -0700520 spin_unlock_bh(&ioat->desc_lock);
Dan Williamsa0587bc2009-07-28 14:44:04 -0700521
522 desc->txd.flags = flags;
Dan Williamsa0587bc2009-07-28 14:44:04 -0700523 desc->len = total_len;
524 list_splice(&chain, &desc->txd.tx_list);
525 hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
526 hw->ctl_f.compl_write = 1;
Dan Williamsad643f52009-09-08 12:01:38 -0700527 hw->tx_cnt = tx_cnt;
Dan Williams6df91832009-09-08 12:00:55 -0700528 dump_desc_dbg(ioat, desc);
Dan Williamsa0587bc2009-07-28 14:44:04 -0700529
530 return &desc->txd;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700531}
532
Dan Williams5cbafa62009-08-26 13:01:44 -0700533static void ioat1_cleanup_tasklet(unsigned long data)
Shannon Nelson3e037452007-10-16 01:27:40 -0700534{
535 struct ioat_dma_chan *chan = (void *)data;
Dan Williamsf6ab95b2009-09-08 12:01:21 -0700536
Dan Williams5cbafa62009-08-26 13:01:44 -0700537 ioat1_cleanup(chan);
Dan Williamsf6ab95b2009-09-08 12:01:21 -0700538 writew(IOAT_CHANCTRL_RUN, chan->base.reg_base + IOAT_CHANCTRL_OFFSET);
Shannon Nelson3e037452007-10-16 01:27:40 -0700539}
540
Dan Williams5cbafa62009-08-26 13:01:44 -0700541static void ioat_unmap(struct pci_dev *pdev, dma_addr_t addr, size_t len,
542 int direction, enum dma_ctrl_flags flags, bool dst)
Dan Williamse1d181e2008-07-04 00:13:40 -0700543{
Dan Williams5cbafa62009-08-26 13:01:44 -0700544 if ((dst && (flags & DMA_COMPL_DEST_UNMAP_SINGLE)) ||
545 (!dst && (flags & DMA_COMPL_SRC_UNMAP_SINGLE)))
546 pci_unmap_single(pdev, addr, len, direction);
547 else
548 pci_unmap_page(pdev, addr, len, direction);
Dan Williamse1d181e2008-07-04 00:13:40 -0700549}
550
Dan Williams5cbafa62009-08-26 13:01:44 -0700551
552void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
553 size_t len, struct ioat_dma_descriptor *hw)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700554{
Dan Williams5cbafa62009-08-26 13:01:44 -0700555 struct pci_dev *pdev = chan->device->pdev;
556 size_t offset = len - hw->size;
557
558 if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
559 ioat_unmap(pdev, hw->dst_addr - offset, len,
560 PCI_DMA_FROMDEVICE, flags, 1);
561
562 if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP))
563 ioat_unmap(pdev, hw->src_addr - offset, len,
564 PCI_DMA_TODEVICE, flags, 0);
565}
566
567unsigned long ioat_get_current_completion(struct ioat_chan_common *chan)
568{
Chris Leech0bbd5f42006-05-23 17:35:34 -0700569 unsigned long phys_complete;
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700570 u64 completion;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700571
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700572 completion = *chan->completion;
Dan Williams09c8a5b2009-09-08 12:01:49 -0700573 phys_complete = ioat_chansts_to_addr(completion);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700574
Dan Williams6df91832009-09-08 12:00:55 -0700575 dev_dbg(to_dev(chan), "%s: phys_complete: %#llx\n", __func__,
576 (unsigned long long) phys_complete);
577
Dan Williams09c8a5b2009-09-08 12:01:49 -0700578 if (is_ioat_halted(completion)) {
579 u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
Dan Williamsdcbc8532009-07-28 14:44:50 -0700580 dev_err(to_dev(chan), "Channel halted, chanerr = %x\n",
Dan Williams09c8a5b2009-09-08 12:01:49 -0700581 chanerr);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700582
583 /* TODO do something to salvage the situation */
584 }
585
Dan Williams5cbafa62009-08-26 13:01:44 -0700586 return phys_complete;
587}
588
Dan Williams09c8a5b2009-09-08 12:01:49 -0700589bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
590 unsigned long *phys_complete)
591{
592 *phys_complete = ioat_get_current_completion(chan);
593 if (*phys_complete == chan->last_completion)
594 return false;
595 clear_bit(IOAT_COMPLETION_ACK, &chan->state);
596 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
597
598 return true;
599}
600
601static void __cleanup(struct ioat_dma_chan *ioat, unsigned long phys_complete)
Dan Williams5cbafa62009-08-26 13:01:44 -0700602{
603 struct ioat_chan_common *chan = &ioat->base;
Dan Williams09c8a5b2009-09-08 12:01:49 -0700604 struct list_head *_desc, *n;
Dan Williams5cbafa62009-08-26 13:01:44 -0700605 struct dma_async_tx_descriptor *tx;
606
Dan Williams6df91832009-09-08 12:00:55 -0700607 dev_dbg(to_dev(chan), "%s: phys_complete: %lx\n",
608 __func__, phys_complete);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700609 list_for_each_safe(_desc, n, &ioat->used_desc) {
610 struct ioat_desc_sw *desc;
611
612 prefetch(n);
613 desc = list_entry(_desc, typeof(*desc), node);
Dan Williamsbc3c7022009-07-28 14:33:42 -0700614 tx = &desc->txd;
Dan Williams5cbafa62009-08-26 13:01:44 -0700615 /*
616 * Incoming DMA requests may use multiple descriptors,
617 * due to exceeding xfercap, perhaps. If so, only the
618 * last one will have a cookie, and require unmapping.
619 */
Dan Williams6df91832009-09-08 12:00:55 -0700620 dump_desc_dbg(ioat, desc);
Dan Williams5cbafa62009-08-26 13:01:44 -0700621 if (tx->cookie) {
Dan Williams09c8a5b2009-09-08 12:01:49 -0700622 chan->completed_cookie = tx->cookie;
623 tx->cookie = 0;
Dan Williams5cbafa62009-08-26 13:01:44 -0700624 ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
625 if (tx->callback) {
626 tx->callback(tx->callback_param);
627 tx->callback = NULL;
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800628 }
Chris Leech0bbd5f42006-05-23 17:35:34 -0700629 }
Dan Williams5cbafa62009-08-26 13:01:44 -0700630
631 if (tx->phys != phys_complete) {
632 /*
633 * a completed entry, but not the last, so clean
634 * up if the client is done with the descriptor
635 */
636 if (async_tx_test_ack(tx))
637 list_move_tail(&desc->node, &ioat->free_desc);
Dan Williams5cbafa62009-08-26 13:01:44 -0700638 } else {
639 /*
640 * last used desc. Do not remove, so we can
Dan Williams09c8a5b2009-09-08 12:01:49 -0700641 * append from it.
Dan Williams5cbafa62009-08-26 13:01:44 -0700642 */
Dan Williams09c8a5b2009-09-08 12:01:49 -0700643
644 /* if nothing else is pending, cancel the
645 * completion timeout
646 */
647 if (n == &ioat->used_desc) {
648 dev_dbg(to_dev(chan),
649 "%s cancel completion timeout\n",
650 __func__);
651 clear_bit(IOAT_COMPLETION_PENDING, &chan->state);
652 }
Dan Williams5cbafa62009-08-26 13:01:44 -0700653
654 /* TODO check status bits? */
655 break;
656 }
Chris Leech0bbd5f42006-05-23 17:35:34 -0700657 }
658
Dan Williamsdcbc8532009-07-28 14:44:50 -0700659 chan->last_completion = phys_complete;
Dan Williams09c8a5b2009-09-08 12:01:49 -0700660}
Chris Leech0bbd5f42006-05-23 17:35:34 -0700661
Dan Williams09c8a5b2009-09-08 12:01:49 -0700662/**
663 * ioat1_cleanup - cleanup up finished descriptors
664 * @chan: ioat channel to be cleaned up
665 *
666 * To prevent lock contention we defer cleanup when the locks are
667 * contended with a terminal timeout that forces cleanup and catches
668 * completion notification errors.
669 */
670static void ioat1_cleanup(struct ioat_dma_chan *ioat)
671{
672 struct ioat_chan_common *chan = &ioat->base;
673 unsigned long phys_complete;
674
675 prefetch(chan->completion);
676
677 if (!spin_trylock_bh(&chan->cleanup_lock))
678 return;
679
680 if (!ioat_cleanup_preamble(chan, &phys_complete)) {
681 spin_unlock_bh(&chan->cleanup_lock);
682 return;
683 }
684
685 if (!spin_trylock_bh(&ioat->desc_lock)) {
686 spin_unlock_bh(&chan->cleanup_lock);
687 return;
688 }
689
690 __cleanup(ioat, phys_complete);
691
692 spin_unlock_bh(&ioat->desc_lock);
693 spin_unlock_bh(&chan->cleanup_lock);
694}
695
696static void ioat1_timer_event(unsigned long data)
697{
698 struct ioat_dma_chan *ioat = (void *) data;
699 struct ioat_chan_common *chan = &ioat->base;
700
701 dev_dbg(to_dev(chan), "%s: state: %lx\n", __func__, chan->state);
702
703 spin_lock_bh(&chan->cleanup_lock);
704 if (test_and_clear_bit(IOAT_RESET_PENDING, &chan->state)) {
705 struct ioat_desc_sw *desc;
706
707 spin_lock_bh(&ioat->desc_lock);
708
709 /* restart active descriptors */
710 desc = to_ioat_desc(ioat->used_desc.prev);
711 ioat_set_chainaddr(ioat, desc->txd.phys);
712 ioat_start(chan);
713
714 ioat->pending = 0;
715 set_bit(IOAT_COMPLETION_PENDING, &chan->state);
716 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
717 spin_unlock_bh(&ioat->desc_lock);
718 } else if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
719 unsigned long phys_complete;
720
721 spin_lock_bh(&ioat->desc_lock);
722 /* if we haven't made progress and we have already
723 * acknowledged a pending completion once, then be more
724 * forceful with a restart
725 */
726 if (ioat_cleanup_preamble(chan, &phys_complete))
727 __cleanup(ioat, phys_complete);
728 else if (test_bit(IOAT_COMPLETION_ACK, &chan->state))
729 ioat1_reset_channel(ioat);
730 else {
731 u64 status = ioat_chansts(chan);
732
733 /* manually update the last completion address */
734 if (ioat_chansts_to_addr(status) != 0)
735 *chan->completion = status;
736
737 set_bit(IOAT_COMPLETION_ACK, &chan->state);
738 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
739 }
740 spin_unlock_bh(&ioat->desc_lock);
741 }
Dan Williamsdcbc8532009-07-28 14:44:50 -0700742 spin_unlock_bh(&chan->cleanup_lock);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700743}
744
Dan Williamsbc3c7022009-07-28 14:33:42 -0700745static enum dma_status
Dan Williams5cbafa62009-08-26 13:01:44 -0700746ioat1_dma_is_complete(struct dma_chan *c, dma_cookie_t cookie,
747 dma_cookie_t *done, dma_cookie_t *used)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700748{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700749 struct ioat_dma_chan *ioat = to_ioat_chan(c);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700750
Dan Williams5cbafa62009-08-26 13:01:44 -0700751 if (ioat_is_complete(c, cookie, done, used) == DMA_SUCCESS)
752 return DMA_SUCCESS;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700753
Dan Williams5cbafa62009-08-26 13:01:44 -0700754 ioat1_cleanup(ioat);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700755
Dan Williams5cbafa62009-08-26 13:01:44 -0700756 return ioat_is_complete(c, cookie, done, used);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700757}
758
Dan Williams5cbafa62009-08-26 13:01:44 -0700759static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700760{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700761 struct ioat_chan_common *chan = &ioat->base;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700762 struct ioat_desc_sw *desc;
Dan Williamsc7984f42009-07-28 14:44:04 -0700763 struct ioat_dma_descriptor *hw;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700764
Dan Williamsdcbc8532009-07-28 14:44:50 -0700765 spin_lock_bh(&ioat->desc_lock);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700766
Dan Williams5cbafa62009-08-26 13:01:44 -0700767 desc = ioat1_dma_get_next_descriptor(ioat);
Maciej Sosnowski7f1b3582008-07-22 17:30:57 -0700768
769 if (!desc) {
Dan Williamsdcbc8532009-07-28 14:44:50 -0700770 dev_err(to_dev(chan),
Maciej Sosnowski7f1b3582008-07-22 17:30:57 -0700771 "Unable to start null desc - get next desc failed\n");
Dan Williamsdcbc8532009-07-28 14:44:50 -0700772 spin_unlock_bh(&ioat->desc_lock);
Maciej Sosnowski7f1b3582008-07-22 17:30:57 -0700773 return;
774 }
775
Dan Williamsc7984f42009-07-28 14:44:04 -0700776 hw = desc->hw;
777 hw->ctl = 0;
778 hw->ctl_f.null = 1;
779 hw->ctl_f.int_en = 1;
780 hw->ctl_f.compl_write = 1;
Maciej Sosnowski7f1b3582008-07-22 17:30:57 -0700781 /* set size to non-zero value (channel returns error when size is 0) */
Dan Williamsc7984f42009-07-28 14:44:04 -0700782 hw->size = NULL_DESC_BUFFER_SIZE;
783 hw->src_addr = 0;
784 hw->dst_addr = 0;
Dan Williamsbc3c7022009-07-28 14:33:42 -0700785 async_tx_ack(&desc->txd);
Dan Williams5cbafa62009-08-26 13:01:44 -0700786 hw->next = 0;
787 list_add_tail(&desc->node, &ioat->used_desc);
Dan Williams6df91832009-09-08 12:00:55 -0700788 dump_desc_dbg(ioat, desc);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700789
Dan Williams09c8a5b2009-09-08 12:01:49 -0700790 ioat_set_chainaddr(ioat, desc->txd.phys);
791 ioat_start(chan);
Dan Williamsdcbc8532009-07-28 14:44:50 -0700792 spin_unlock_bh(&ioat->desc_lock);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700793}
794
795/*
796 * Perform a IOAT transaction to verify the HW works.
797 */
798#define IOAT_TEST_SIZE 2000
799
Dan Williams345d8522009-09-08 12:01:30 -0700800static void __devinit ioat_dma_test_callback(void *dma_async_param)
Shannon Nelson95218432007-10-18 03:07:15 -0700801{
Dan Williamsb9bdcbb2009-01-06 11:38:22 -0700802 struct completion *cmp = dma_async_param;
803
804 complete(cmp);
Shannon Nelson95218432007-10-18 03:07:15 -0700805}
806
Shannon Nelson3e037452007-10-16 01:27:40 -0700807/**
808 * ioat_dma_self_test - Perform a IOAT transaction to verify the HW works.
809 * @device: device to be tested
810 */
Dan Williams345d8522009-09-08 12:01:30 -0700811static int __devinit ioat_dma_self_test(struct ioatdma_device *device)
Chris Leech0bbd5f42006-05-23 17:35:34 -0700812{
813 int i;
814 u8 *src;
815 u8 *dest;
Dan Williamsbc3c7022009-07-28 14:33:42 -0700816 struct dma_device *dma = &device->common;
817 struct device *dev = &device->pdev->dev;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700818 struct dma_chan *dma_chan;
Shannon Nelson711924b2007-12-17 16:20:08 -0800819 struct dma_async_tx_descriptor *tx;
Dan Williams00367312008-02-02 19:49:57 -0700820 dma_addr_t dma_dest, dma_src;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700821 dma_cookie_t cookie;
822 int err = 0;
Dan Williamsb9bdcbb2009-01-06 11:38:22 -0700823 struct completion cmp;
Dan Williams0c33e1c2009-03-02 13:31:35 -0700824 unsigned long tmo;
Maciej Sosnowski4f005db2009-04-23 12:31:51 +0200825 unsigned long flags;
Chris Leech0bbd5f42006-05-23 17:35:34 -0700826
Christoph Lametere94b1762006-12-06 20:33:17 -0800827 src = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700828 if (!src)
829 return -ENOMEM;
Christoph Lametere94b1762006-12-06 20:33:17 -0800830 dest = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700831 if (!dest) {
832 kfree(src);
833 return -ENOMEM;
834 }
835
836 /* Fill in src buffer */
837 for (i = 0; i < IOAT_TEST_SIZE; i++)
838 src[i] = (u8)i;
839
840 /* Start copy, using first DMA channel */
Dan Williamsbc3c7022009-07-28 14:33:42 -0700841 dma_chan = container_of(dma->channels.next, struct dma_chan,
Shannon Nelson43d6e362007-10-16 01:27:39 -0700842 device_node);
Dan Williamsbc3c7022009-07-28 14:33:42 -0700843 if (dma->device_alloc_chan_resources(dma_chan) < 1) {
844 dev_err(dev, "selftest cannot allocate chan resource\n");
Chris Leech0bbd5f42006-05-23 17:35:34 -0700845 err = -ENODEV;
846 goto out;
847 }
848
Dan Williamsbc3c7022009-07-28 14:33:42 -0700849 dma_src = dma_map_single(dev, src, IOAT_TEST_SIZE, DMA_TO_DEVICE);
850 dma_dest = dma_map_single(dev, dest, IOAT_TEST_SIZE, DMA_FROM_DEVICE);
Dan Williamsa6a39ca2009-07-28 14:44:05 -0700851 flags = DMA_COMPL_SRC_UNMAP_SINGLE | DMA_COMPL_DEST_UNMAP_SINGLE |
852 DMA_PREP_INTERRUPT;
Dan Williams00367312008-02-02 19:49:57 -0700853 tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src,
Maciej Sosnowski4f005db2009-04-23 12:31:51 +0200854 IOAT_TEST_SIZE, flags);
Shannon Nelson5149fd02007-10-18 03:07:13 -0700855 if (!tx) {
Dan Williamsbc3c7022009-07-28 14:33:42 -0700856 dev_err(dev, "Self-test prep failed, disabling\n");
Shannon Nelson5149fd02007-10-18 03:07:13 -0700857 err = -ENODEV;
858 goto free_resources;
859 }
860
Dan Williams7405f742007-01-02 11:10:43 -0700861 async_tx_ack(tx);
Dan Williamsb9bdcbb2009-01-06 11:38:22 -0700862 init_completion(&cmp);
Shannon Nelson95218432007-10-18 03:07:15 -0700863 tx->callback = ioat_dma_test_callback;
Dan Williamsb9bdcbb2009-01-06 11:38:22 -0700864 tx->callback_param = &cmp;
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800865 cookie = tx->tx_submit(tx);
Shannon Nelson7f2b2912007-10-18 03:07:14 -0700866 if (cookie < 0) {
Dan Williamsbc3c7022009-07-28 14:33:42 -0700867 dev_err(dev, "Self-test setup failed, disabling\n");
Shannon Nelson7f2b2912007-10-18 03:07:14 -0700868 err = -ENODEV;
869 goto free_resources;
870 }
Dan Williamsbc3c7022009-07-28 14:33:42 -0700871 dma->device_issue_pending(dma_chan);
Dan Williams532d3b12008-12-03 17:16:55 -0700872
Dan Williams0c33e1c2009-03-02 13:31:35 -0700873 tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
Chris Leech0bbd5f42006-05-23 17:35:34 -0700874
Dan Williams0c33e1c2009-03-02 13:31:35 -0700875 if (tmo == 0 ||
Dan Williamsbc3c7022009-07-28 14:33:42 -0700876 dma->device_is_tx_complete(dma_chan, cookie, NULL, NULL)
Shannon Nelson7bb67c12007-11-14 16:59:51 -0800877 != DMA_SUCCESS) {
Dan Williamsbc3c7022009-07-28 14:33:42 -0700878 dev_err(dev, "Self-test copy timed out, disabling\n");
Chris Leech0bbd5f42006-05-23 17:35:34 -0700879 err = -ENODEV;
880 goto free_resources;
881 }
882 if (memcmp(src, dest, IOAT_TEST_SIZE)) {
Dan Williamsbc3c7022009-07-28 14:33:42 -0700883 dev_err(dev, "Self-test copy failed compare, disabling\n");
Chris Leech0bbd5f42006-05-23 17:35:34 -0700884 err = -ENODEV;
885 goto free_resources;
886 }
887
888free_resources:
Dan Williamsbc3c7022009-07-28 14:33:42 -0700889 dma->device_free_chan_resources(dma_chan);
Chris Leech0bbd5f42006-05-23 17:35:34 -0700890out:
891 kfree(src);
892 kfree(dest);
893 return err;
894}
895
Shannon Nelson3e037452007-10-16 01:27:40 -0700896static char ioat_interrupt_style[32] = "msix";
897module_param_string(ioat_interrupt_style, ioat_interrupt_style,
898 sizeof(ioat_interrupt_style), 0644);
899MODULE_PARM_DESC(ioat_interrupt_style,
900 "set ioat interrupt style: msix (default), "
901 "msix-single-vector, msi, intx)");
902
903/**
904 * ioat_dma_setup_interrupts - setup interrupt handler
905 * @device: ioat device
906 */
907static int ioat_dma_setup_interrupts(struct ioatdma_device *device)
908{
Dan Williamsdcbc8532009-07-28 14:44:50 -0700909 struct ioat_chan_common *chan;
Dan Williamse6c0b692009-09-08 17:29:44 -0700910 struct pci_dev *pdev = device->pdev;
911 struct device *dev = &pdev->dev;
912 struct msix_entry *msix;
913 int i, j, msixcnt;
914 int err = -EINVAL;
Shannon Nelson3e037452007-10-16 01:27:40 -0700915 u8 intrctrl = 0;
916
917 if (!strcmp(ioat_interrupt_style, "msix"))
918 goto msix;
919 if (!strcmp(ioat_interrupt_style, "msix-single-vector"))
920 goto msix_single_vector;
921 if (!strcmp(ioat_interrupt_style, "msi"))
922 goto msi;
923 if (!strcmp(ioat_interrupt_style, "intx"))
924 goto intx;
Dan Williamse6c0b692009-09-08 17:29:44 -0700925 dev_err(dev, "invalid ioat_interrupt_style %s\n", ioat_interrupt_style);
Shannon Nelson5149fd02007-10-18 03:07:13 -0700926 goto err_no_irq;
Shannon Nelson3e037452007-10-16 01:27:40 -0700927
928msix:
929 /* The number of MSI-X vectors should equal the number of channels */
930 msixcnt = device->common.chancnt;
931 for (i = 0; i < msixcnt; i++)
932 device->msix_entries[i].entry = i;
933
Dan Williamse6c0b692009-09-08 17:29:44 -0700934 err = pci_enable_msix(pdev, device->msix_entries, msixcnt);
Shannon Nelson3e037452007-10-16 01:27:40 -0700935 if (err < 0)
936 goto msi;
937 if (err > 0)
938 goto msix_single_vector;
939
940 for (i = 0; i < msixcnt; i++) {
Dan Williamse6c0b692009-09-08 17:29:44 -0700941 msix = &device->msix_entries[i];
Dan Williamsdcbc8532009-07-28 14:44:50 -0700942 chan = ioat_chan_by_index(device, i);
Dan Williamse6c0b692009-09-08 17:29:44 -0700943 err = devm_request_irq(dev, msix->vector,
944 ioat_dma_do_interrupt_msix, 0,
Dan Williamsdcbc8532009-07-28 14:44:50 -0700945 "ioat-msix", chan);
Shannon Nelson3e037452007-10-16 01:27:40 -0700946 if (err) {
947 for (j = 0; j < i; j++) {
Dan Williamse6c0b692009-09-08 17:29:44 -0700948 msix = &device->msix_entries[j];
Dan Williamsdcbc8532009-07-28 14:44:50 -0700949 chan = ioat_chan_by_index(device, j);
950 devm_free_irq(dev, msix->vector, chan);
Shannon Nelson3e037452007-10-16 01:27:40 -0700951 }
952 goto msix_single_vector;
953 }
954 }
955 intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL;
Shannon Nelson3e037452007-10-16 01:27:40 -0700956 goto done;
957
958msix_single_vector:
Dan Williamse6c0b692009-09-08 17:29:44 -0700959 msix = &device->msix_entries[0];
960 msix->entry = 0;
961 err = pci_enable_msix(pdev, device->msix_entries, 1);
Shannon Nelson3e037452007-10-16 01:27:40 -0700962 if (err)
963 goto msi;
964
Dan Williamse6c0b692009-09-08 17:29:44 -0700965 err = devm_request_irq(dev, msix->vector, ioat_dma_do_interrupt, 0,
966 "ioat-msix", device);
Shannon Nelson3e037452007-10-16 01:27:40 -0700967 if (err) {
Dan Williamse6c0b692009-09-08 17:29:44 -0700968 pci_disable_msix(pdev);
Shannon Nelson3e037452007-10-16 01:27:40 -0700969 goto msi;
970 }
Shannon Nelson3e037452007-10-16 01:27:40 -0700971 goto done;
972
973msi:
Dan Williamse6c0b692009-09-08 17:29:44 -0700974 err = pci_enable_msi(pdev);
Shannon Nelson3e037452007-10-16 01:27:40 -0700975 if (err)
976 goto intx;
977
Dan Williamse6c0b692009-09-08 17:29:44 -0700978 err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt, 0,
979 "ioat-msi", device);
Shannon Nelson3e037452007-10-16 01:27:40 -0700980 if (err) {
Dan Williamse6c0b692009-09-08 17:29:44 -0700981 pci_disable_msi(pdev);
Shannon Nelson3e037452007-10-16 01:27:40 -0700982 goto intx;
983 }
Shannon Nelson3e037452007-10-16 01:27:40 -0700984 goto done;
985
986intx:
Dan Williamse6c0b692009-09-08 17:29:44 -0700987 err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt,
988 IRQF_SHARED, "ioat-intx", device);
Shannon Nelson3e037452007-10-16 01:27:40 -0700989 if (err)
990 goto err_no_irq;
Shannon Nelson3e037452007-10-16 01:27:40 -0700991
992done:
Dan Williamsf2427e22009-07-28 14:42:38 -0700993 if (device->intr_quirk)
994 device->intr_quirk(device);
Shannon Nelson3e037452007-10-16 01:27:40 -0700995 intrctrl |= IOAT_INTRCTRL_MASTER_INT_EN;
996 writeb(intrctrl, device->reg_base + IOAT_INTRCTRL_OFFSET);
997 return 0;
998
999err_no_irq:
1000 /* Disable all interrupt generation */
1001 writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
Dan Williamse6c0b692009-09-08 17:29:44 -07001002 dev_err(dev, "no usable interrupts\n");
1003 return err;
Shannon Nelson3e037452007-10-16 01:27:40 -07001004}
1005
Dan Williamse6c0b692009-09-08 17:29:44 -07001006static void ioat_disable_interrupts(struct ioatdma_device *device)
Shannon Nelson3e037452007-10-16 01:27:40 -07001007{
Shannon Nelson3e037452007-10-16 01:27:40 -07001008 /* Disable all interrupt generation */
1009 writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
Shannon Nelson3e037452007-10-16 01:27:40 -07001010}
1011
Dan Williams345d8522009-09-08 12:01:30 -07001012int __devinit ioat_probe(struct ioatdma_device *device)
Chris Leech0bbd5f42006-05-23 17:35:34 -07001013{
Dan Williamsf2427e22009-07-28 14:42:38 -07001014 int err = -ENODEV;
1015 struct dma_device *dma = &device->common;
1016 struct pci_dev *pdev = device->pdev;
Dan Williamse6c0b692009-09-08 17:29:44 -07001017 struct device *dev = &pdev->dev;
Chris Leech0bbd5f42006-05-23 17:35:34 -07001018
1019 /* DMA coherent memory pool for DMA descriptor allocations */
1020 device->dma_pool = pci_pool_create("dma_desc_pool", pdev,
Shannon Nelson8ab89562007-10-16 01:27:39 -07001021 sizeof(struct ioat_dma_descriptor),
1022 64, 0);
Chris Leech0bbd5f42006-05-23 17:35:34 -07001023 if (!device->dma_pool) {
1024 err = -ENOMEM;
1025 goto err_dma_pool;
1026 }
1027
Shannon Nelson43d6e362007-10-16 01:27:39 -07001028 device->completion_pool = pci_pool_create("completion_pool", pdev,
1029 sizeof(u64), SMP_CACHE_BYTES,
1030 SMP_CACHE_BYTES);
Dan Williams5cbafa62009-08-26 13:01:44 -07001031
Chris Leech0bbd5f42006-05-23 17:35:34 -07001032 if (!device->completion_pool) {
1033 err = -ENOMEM;
1034 goto err_completion_pool;
1035 }
1036
Dan Williams5cbafa62009-08-26 13:01:44 -07001037 device->enumerate_channels(device);
Chris Leech0bbd5f42006-05-23 17:35:34 -07001038
Dan Williamsf2427e22009-07-28 14:42:38 -07001039 dma_cap_set(DMA_MEMCPY, dma->cap_mask);
Dan Williamsf2427e22009-07-28 14:42:38 -07001040 dma->dev = &pdev->dev;
Shannon Nelson7bb67c12007-11-14 16:59:51 -08001041
Dan Williamse6c0b692009-09-08 17:29:44 -07001042 dev_err(dev, "Intel(R) I/OAT DMA Engine found,"
Shannon Nelson5149fd02007-10-18 03:07:13 -07001043 " %d channels, device version 0x%02x, driver version %s\n",
Dan Williamsbc3c7022009-07-28 14:33:42 -07001044 dma->chancnt, device->version, IOAT_DMA_VERSION);
Shannon Nelson8ab89562007-10-16 01:27:39 -07001045
Dan Williamsbc3c7022009-07-28 14:33:42 -07001046 if (!dma->chancnt) {
Dan Williamse6c0b692009-09-08 17:29:44 -07001047 dev_err(dev, "Intel(R) I/OAT DMA Engine problem found: "
Maciej Sosnowski8b794b12009-02-26 11:04:54 +01001048 "zero channels detected\n");
1049 goto err_setup_interrupts;
1050 }
1051
Shannon Nelson3e037452007-10-16 01:27:40 -07001052 err = ioat_dma_setup_interrupts(device);
Shannon Nelson8ab89562007-10-16 01:27:39 -07001053 if (err)
Shannon Nelson3e037452007-10-16 01:27:40 -07001054 goto err_setup_interrupts;
Shannon Nelson8ab89562007-10-16 01:27:39 -07001055
Shannon Nelson3e037452007-10-16 01:27:40 -07001056 err = ioat_dma_self_test(device);
Chris Leech0bbd5f42006-05-23 17:35:34 -07001057 if (err)
1058 goto err_self_test;
1059
Dan Williamsf2427e22009-07-28 14:42:38 -07001060 return 0;
Chris Leech0bbd5f42006-05-23 17:35:34 -07001061
1062err_self_test:
Dan Williamse6c0b692009-09-08 17:29:44 -07001063 ioat_disable_interrupts(device);
Shannon Nelson3e037452007-10-16 01:27:40 -07001064err_setup_interrupts:
Chris Leech0bbd5f42006-05-23 17:35:34 -07001065 pci_pool_destroy(device->completion_pool);
1066err_completion_pool:
1067 pci_pool_destroy(device->dma_pool);
1068err_dma_pool:
Dan Williamsf2427e22009-07-28 14:42:38 -07001069 return err;
1070}
1071
Dan Williams345d8522009-09-08 12:01:30 -07001072int __devinit ioat_register(struct ioatdma_device *device)
Dan Williamsf2427e22009-07-28 14:42:38 -07001073{
1074 int err = dma_async_device_register(&device->common);
1075
1076 if (err) {
1077 ioat_disable_interrupts(device);
1078 pci_pool_destroy(device->completion_pool);
1079 pci_pool_destroy(device->dma_pool);
1080 }
1081
1082 return err;
1083}
1084
1085/* ioat1_intr_quirk - fix up dma ctrl register to enable / disable msi */
1086static void ioat1_intr_quirk(struct ioatdma_device *device)
1087{
1088 struct pci_dev *pdev = device->pdev;
1089 u32 dmactrl;
1090
1091 pci_read_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, &dmactrl);
1092 if (pdev->msi_enabled)
1093 dmactrl |= IOAT_PCI_DMACTRL_MSI_EN;
1094 else
1095 dmactrl &= ~IOAT_PCI_DMACTRL_MSI_EN;
1096 pci_write_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, dmactrl);
1097}
1098
Dan Williams345d8522009-09-08 12:01:30 -07001099int __devinit ioat1_dma_probe(struct ioatdma_device *device, int dca)
Dan Williamsf2427e22009-07-28 14:42:38 -07001100{
1101 struct pci_dev *pdev = device->pdev;
1102 struct dma_device *dma;
1103 int err;
1104
1105 device->intr_quirk = ioat1_intr_quirk;
Dan Williams5cbafa62009-08-26 13:01:44 -07001106 device->enumerate_channels = ioat1_enumerate_channels;
Dan Williamsf2427e22009-07-28 14:42:38 -07001107 dma = &device->common;
1108 dma->device_prep_dma_memcpy = ioat1_dma_prep_memcpy;
1109 dma->device_issue_pending = ioat1_dma_memcpy_issue_pending;
Dan Williams5cbafa62009-08-26 13:01:44 -07001110 dma->device_alloc_chan_resources = ioat1_dma_alloc_chan_resources;
1111 dma->device_free_chan_resources = ioat1_dma_free_chan_resources;
1112 dma->device_is_tx_complete = ioat1_dma_is_complete;
Dan Williamsf2427e22009-07-28 14:42:38 -07001113
1114 err = ioat_probe(device);
1115 if (err)
1116 return err;
1117 ioat_set_tcp_copy_break(4096);
1118 err = ioat_register(device);
1119 if (err)
1120 return err;
1121 if (dca)
1122 device->dca = ioat_dca_init(pdev, device->reg_base);
1123
Dan Williamsf2427e22009-07-28 14:42:38 -07001124 return err;
1125}
1126
Dan Williams345d8522009-09-08 12:01:30 -07001127void __devexit ioat_dma_remove(struct ioatdma_device *device)
Dan Aloni428ed602007-03-08 09:57:36 -08001128{
Dan Williamsbc3c7022009-07-28 14:33:42 -07001129 struct dma_device *dma = &device->common;
Chris Leech0bbd5f42006-05-23 17:35:34 -07001130
Dan Williamse6c0b692009-09-08 17:29:44 -07001131 ioat_disable_interrupts(device);
Shannon Nelson8ab89562007-10-16 01:27:39 -07001132
Dan Williamsbc3c7022009-07-28 14:33:42 -07001133 dma_async_device_unregister(dma);
Shannon Nelsondfe22992007-10-18 03:07:13 -07001134
Chris Leech0bbd5f42006-05-23 17:35:34 -07001135 pci_pool_destroy(device->dma_pool);
1136 pci_pool_destroy(device->completion_pool);
Shannon Nelson8ab89562007-10-16 01:27:39 -07001137
Dan Williamsdcbc8532009-07-28 14:44:50 -07001138 INIT_LIST_HEAD(&dma->channels);
Chris Leech0bbd5f42006-05-23 17:35:34 -07001139}