2 * Intel I/OAT DMA Linux driver
3 * Copyright(c) 2004 - 2009 Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
24 * This driver supports an Intel I/OAT DMA engine, which does asynchronous
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>
34 #include <linux/dma-mapping.h>
35 #include <linux/workqueue.h>
36 #include <linux/i7300_idle.h>
38 #include "registers.h"
41 static int ioat_pending_level = 4;
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)");
46 static void ioat_dma_chan_reset_part2(struct work_struct *work);
47 static void ioat_dma_chan_watchdog(struct work_struct *work);
49 /* internal functions */
50 static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat);
51 static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat);
53 static struct ioat_desc_sw *
54 ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat);
55 static struct ioat_desc_sw *
56 ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat);
58 static inline struct ioat_chan_common *
59 ioat_chan_by_index(struct ioatdma_device *device, int index)
61 return device->idx[index];
65 * ioat_dma_do_interrupt - handler used for single vector interrupt mode
67 * @data: interrupt data
69 static irqreturn_t ioat_dma_do_interrupt(int irq, void *data)
71 struct ioatdma_device *instance = data;
72 struct ioat_chan_common *chan;
73 unsigned long attnstatus;
77 intrctrl = readb(instance->reg_base + IOAT_INTRCTRL_OFFSET);
79 if (!(intrctrl & IOAT_INTRCTRL_MASTER_INT_EN))
82 if (!(intrctrl & IOAT_INTRCTRL_INT_STATUS)) {
83 writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
87 attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET);
88 for_each_bit(bit, &attnstatus, BITS_PER_LONG) {
89 chan = ioat_chan_by_index(instance, bit);
90 tasklet_schedule(&chan->cleanup_task);
93 writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
98 * ioat_dma_do_interrupt_msix - handler used for vector-per-channel interrupt mode
100 * @data: interrupt data
102 static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)
104 struct ioat_chan_common *chan = data;
106 tasklet_schedule(&chan->cleanup_task);
111 static void ioat_dma_cleanup_tasklet(unsigned long data);
114 * ioat_dma_enumerate_channels - find and initialize the device's channels
115 * @device: the device to be enumerated
117 static int ioat_dma_enumerate_channels(struct ioatdma_device *device)
122 struct ioat_chan_common *chan;
123 struct ioat_dma_chan *ioat;
124 struct device *dev = &device->pdev->dev;
125 struct dma_device *dma = &device->common;
127 INIT_LIST_HEAD(&dma->channels);
128 dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET);
129 xfercap_scale = readb(device->reg_base + IOAT_XFERCAP_OFFSET);
130 xfercap = (xfercap_scale == 0 ? -1 : (1UL << xfercap_scale));
132 #ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL
133 if (i7300_idle_platform_probe(NULL, NULL, 1) == 0)
136 for (i = 0; i < dma->chancnt; i++) {
137 ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL);
144 chan->device = device;
145 chan->reg_base = device->reg_base + (0x80 * (i + 1));
146 ioat->xfercap = xfercap;
148 INIT_DELAYED_WORK(&chan->work, ioat_dma_chan_reset_part2);
149 spin_lock_init(&chan->cleanup_lock);
150 spin_lock_init(&ioat->desc_lock);
151 INIT_LIST_HEAD(&ioat->free_desc);
152 INIT_LIST_HEAD(&ioat->used_desc);
153 /* This should be made common somewhere in dmaengine.c */
154 chan->common.device = &device->common;
155 list_add_tail(&chan->common.device_node, &dma->channels);
156 device->idx[i] = chan;
157 tasklet_init(&chan->cleanup_task,
158 ioat_dma_cleanup_tasklet,
159 (unsigned long) ioat);
160 tasklet_disable(&chan->cleanup_task);
166 * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended
168 * @chan: DMA channel handle
171 __ioat1_dma_memcpy_issue_pending(struct ioat_dma_chan *ioat)
173 void __iomem *reg_base = ioat->base.reg_base;
176 writeb(IOAT_CHANCMD_APPEND, reg_base + IOAT1_CHANCMD_OFFSET);
179 static void ioat1_dma_memcpy_issue_pending(struct dma_chan *chan)
181 struct ioat_dma_chan *ioat = to_ioat_chan(chan);
183 if (ioat->pending > 0) {
184 spin_lock_bh(&ioat->desc_lock);
185 __ioat1_dma_memcpy_issue_pending(ioat);
186 spin_unlock_bh(&ioat->desc_lock);
191 __ioat2_dma_memcpy_issue_pending(struct ioat_dma_chan *ioat)
193 void __iomem *reg_base = ioat->base.reg_base;
196 writew(ioat->dmacount, reg_base + IOAT_CHAN_DMACOUNT_OFFSET);
199 static void ioat2_dma_memcpy_issue_pending(struct dma_chan *chan)
201 struct ioat_dma_chan *ioat = to_ioat_chan(chan);
203 if (ioat->pending > 0) {
204 spin_lock_bh(&ioat->desc_lock);
205 __ioat2_dma_memcpy_issue_pending(ioat);
206 spin_unlock_bh(&ioat->desc_lock);
212 * ioat_dma_chan_reset_part2 - reinit the channel after a reset
214 static void ioat_dma_chan_reset_part2(struct work_struct *work)
216 struct ioat_chan_common *chan;
217 struct ioat_dma_chan *ioat;
218 struct ioat_desc_sw *desc;
220 chan = container_of(work, struct ioat_chan_common, work.work);
221 ioat = container_of(chan, struct ioat_dma_chan, base);
222 spin_lock_bh(&chan->cleanup_lock);
223 spin_lock_bh(&ioat->desc_lock);
225 chan->completion_virt->low = 0;
226 chan->completion_virt->high = 0;
230 * count the descriptors waiting, and be sure to do it
231 * right for both the CB1 line and the CB2 ring
234 if (ioat->used_desc.prev) {
235 desc = to_ioat_desc(ioat->used_desc.prev);
238 desc = to_ioat_desc(desc->node.next);
239 } while (&desc->node != ioat->used_desc.next);
243 * write the new starting descriptor address
244 * this puts channel engine into ARMED state
246 desc = to_ioat_desc(ioat->used_desc.prev);
247 switch (chan->device->version) {
249 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF,
250 chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW);
251 writel(((u64) desc->txd.phys) >> 32,
252 chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH);
254 writeb(IOAT_CHANCMD_START, chan->reg_base
255 + IOAT_CHANCMD_OFFSET(chan->device->version));
258 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF,
259 chan->reg_base + IOAT2_CHAINADDR_OFFSET_LOW);
260 writel(((u64) desc->txd.phys) >> 32,
261 chan->reg_base + IOAT2_CHAINADDR_OFFSET_HIGH);
263 /* tell the engine to go with what's left to be done */
264 writew(ioat->dmacount,
265 chan->reg_base + IOAT_CHAN_DMACOUNT_OFFSET);
269 dev_err(to_dev(chan),
270 "chan%d reset - %d descs waiting, %d total desc\n",
271 chan_num(chan), ioat->dmacount, ioat->desccount);
273 spin_unlock_bh(&ioat->desc_lock);
274 spin_unlock_bh(&chan->cleanup_lock);
278 * ioat_dma_reset_channel - restart a channel
279 * @ioat: IOAT DMA channel handle
281 static void ioat_dma_reset_channel(struct ioat_dma_chan *ioat)
283 struct ioat_chan_common *chan = &ioat->base;
284 void __iomem *reg_base = chan->reg_base;
285 u32 chansts, chanerr;
287 if (!ioat->used_desc.prev)
290 chanerr = readl(reg_base + IOAT_CHANERR_OFFSET);
291 chansts = (chan->completion_virt->low
292 & IOAT_CHANSTS_DMA_TRANSFER_STATUS);
294 dev_err(to_dev(chan),
295 "chan%d, CHANSTS = 0x%08x CHANERR = 0x%04x, clearing\n",
296 chan_num(chan), chansts, chanerr);
297 writel(chanerr, reg_base + IOAT_CHANERR_OFFSET);
301 * whack it upside the head with a reset
302 * and wait for things to settle out.
303 * force the pending count to a really big negative
304 * to make sure no one forces an issue_pending
305 * while we're waiting.
308 spin_lock_bh(&ioat->desc_lock);
309 ioat->pending = INT_MIN;
310 writeb(IOAT_CHANCMD_RESET,
311 reg_base + IOAT_CHANCMD_OFFSET(chan->device->version));
312 spin_unlock_bh(&ioat->desc_lock);
314 /* schedule the 2nd half instead of sleeping a long time */
315 schedule_delayed_work(&chan->work, RESET_DELAY);
319 * ioat_dma_chan_watchdog - watch for stuck channels
321 static void ioat_dma_chan_watchdog(struct work_struct *work)
323 struct ioatdma_device *device =
324 container_of(work, struct ioatdma_device, work.work);
325 struct ioat_dma_chan *ioat;
326 struct ioat_chan_common *chan;
336 unsigned long compl_desc_addr_hw;
338 for (i = 0; i < device->common.chancnt; i++) {
339 chan = ioat_chan_by_index(device, i);
340 ioat = container_of(chan, struct ioat_dma_chan, base);
342 if (chan->device->version == IOAT_VER_1_2
343 /* have we started processing anything yet */
344 && chan->last_completion
345 /* have we completed any since last watchdog cycle? */
346 && (chan->last_completion == chan->watchdog_completion)
347 /* has TCP stuck on one cookie since last watchdog? */
348 && (chan->watchdog_tcp_cookie == chan->watchdog_last_tcp_cookie)
349 && (chan->watchdog_tcp_cookie != chan->completed_cookie)
350 /* is there something in the chain to be processed? */
351 /* CB1 chain always has at least the last one processed */
352 && (ioat->used_desc.prev != ioat->used_desc.next)
353 && ioat->pending == 0) {
356 * check CHANSTS register for completed
357 * descriptor address.
358 * if it is different than completion writeback,
360 * and it has changed since the last watchdog
361 * we can assume that channel
362 * is still working correctly
363 * and the problem is in completion writeback.
364 * update completion writeback
365 * with actual CHANSTS value
367 * try resetting the channel
370 completion_hw.low = readl(chan->reg_base +
371 IOAT_CHANSTS_OFFSET_LOW(chan->device->version));
372 completion_hw.high = readl(chan->reg_base +
373 IOAT_CHANSTS_OFFSET_HIGH(chan->device->version));
374 #if (BITS_PER_LONG == 64)
377 & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
380 completion_hw.low & IOAT_LOW_COMPLETION_MASK;
383 if ((compl_desc_addr_hw != 0)
384 && (compl_desc_addr_hw != chan->watchdog_completion)
385 && (compl_desc_addr_hw != chan->last_compl_desc_addr_hw)) {
386 chan->last_compl_desc_addr_hw = compl_desc_addr_hw;
387 chan->completion_virt->low = completion_hw.low;
388 chan->completion_virt->high = completion_hw.high;
390 ioat_dma_reset_channel(ioat);
391 chan->watchdog_completion = 0;
392 chan->last_compl_desc_addr_hw = 0;
396 * for version 2.0 if there are descriptors yet to be processed
397 * and the last completed hasn't changed since the last watchdog
398 * if they haven't hit the pending level
399 * issue the pending to push them through
401 * try resetting the channel
403 } else if (chan->device->version == IOAT_VER_2_0
404 && ioat->used_desc.prev
405 && chan->last_completion
406 && chan->last_completion == chan->watchdog_completion) {
408 if (ioat->pending < ioat_pending_level)
409 ioat2_dma_memcpy_issue_pending(&chan->common);
411 ioat_dma_reset_channel(ioat);
412 chan->watchdog_completion = 0;
415 chan->last_compl_desc_addr_hw = 0;
416 chan->watchdog_completion = chan->last_completion;
418 chan->watchdog_last_tcp_cookie = chan->watchdog_tcp_cookie;
421 schedule_delayed_work(&device->work, WATCHDOG_DELAY);
424 static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
426 struct dma_chan *c = tx->chan;
427 struct ioat_dma_chan *ioat = to_ioat_chan(c);
428 struct ioat_desc_sw *desc = tx_to_ioat_desc(tx);
429 struct ioat_desc_sw *first;
430 struct ioat_desc_sw *chain_tail;
433 spin_lock_bh(&ioat->desc_lock);
434 /* cookie incr and addition to used_list must be atomic */
442 /* write address into NextDescriptor field of last desc in chain */
443 first = to_ioat_desc(tx->tx_list.next);
444 chain_tail = to_ioat_desc(ioat->used_desc.prev);
445 /* make descriptor updates globally visible before chaining */
447 chain_tail->hw->next = first->txd.phys;
448 list_splice_tail_init(&tx->tx_list, &ioat->used_desc);
450 ioat->dmacount += desc->tx_cnt;
451 ioat->pending += desc->tx_cnt;
452 if (ioat->pending >= ioat_pending_level)
453 __ioat1_dma_memcpy_issue_pending(ioat);
454 spin_unlock_bh(&ioat->desc_lock);
459 static dma_cookie_t ioat2_tx_submit(struct dma_async_tx_descriptor *tx)
461 struct ioat_dma_chan *ioat = to_ioat_chan(tx->chan);
462 struct ioat_desc_sw *first = tx_to_ioat_desc(tx);
463 struct ioat_desc_sw *new;
464 struct ioat_dma_descriptor *hw;
469 unsigned long orig_flags;
470 unsigned int desc_count = 0;
472 /* src and dest and len are stored in the initial descriptor */
476 orig_flags = first->txd.flags;
480 * ioat->desc_lock is still in force in version 2 path
481 * it gets unlocked at end of this function
484 copy = min_t(size_t, len, ioat->xfercap);
486 async_tx_ack(&new->txd);
498 } while (len && (new = ioat2_dma_get_next_descriptor(ioat)));
501 dev_err(to_dev(&ioat->base), "tx submit failed\n");
502 spin_unlock_bh(&ioat->desc_lock);
506 hw->ctl_f.compl_write = 1;
507 if (first->txd.callback) {
508 hw->ctl_f.int_en = 1;
510 /* move callback into to last desc */
511 new->txd.callback = first->txd.callback;
512 new->txd.callback_param
513 = first->txd.callback_param;
514 first->txd.callback = NULL;
515 first->txd.callback_param = NULL;
519 new->tx_cnt = desc_count;
520 new->txd.flags = orig_flags; /* client is in control of this ack */
522 /* store the original values for use in later cleanup */
524 new->src = first->src;
525 new->dst = first->dst;
526 new->len = first->len;
529 /* cookie incr and addition to used_list must be atomic */
530 cookie = ioat->base.common.cookie;
534 ioat->base.common.cookie = new->txd.cookie = cookie;
536 ioat->dmacount += desc_count;
537 ioat->pending += desc_count;
538 if (ioat->pending >= ioat_pending_level)
539 __ioat2_dma_memcpy_issue_pending(ioat);
540 spin_unlock_bh(&ioat->desc_lock);
546 * ioat_dma_alloc_descriptor - allocate and return a sw and hw descriptor pair
547 * @ioat: the channel supplying the memory pool for the descriptors
548 * @flags: allocation flags
550 static struct ioat_desc_sw *
551 ioat_dma_alloc_descriptor(struct ioat_dma_chan *ioat, gfp_t flags)
553 struct ioat_dma_descriptor *desc;
554 struct ioat_desc_sw *desc_sw;
555 struct ioatdma_device *ioatdma_device;
558 ioatdma_device = ioat->base.device;
559 desc = pci_pool_alloc(ioatdma_device->dma_pool, flags, &phys);
563 desc_sw = kzalloc(sizeof(*desc_sw), flags);
564 if (unlikely(!desc_sw)) {
565 pci_pool_free(ioatdma_device->dma_pool, desc, phys);
569 memset(desc, 0, sizeof(*desc));
570 dma_async_tx_descriptor_init(&desc_sw->txd, &ioat->base.common);
571 switch (ioatdma_device->version) {
573 desc_sw->txd.tx_submit = ioat1_tx_submit;
577 desc_sw->txd.tx_submit = ioat2_tx_submit;
582 desc_sw->txd.phys = phys;
587 static int ioat_initial_desc_count = 256;
588 module_param(ioat_initial_desc_count, int, 0644);
589 MODULE_PARM_DESC(ioat_initial_desc_count,
590 "initial descriptors per channel (default: 256)");
593 * ioat2_dma_massage_chan_desc - link the descriptors into a circle
594 * @ioat: the channel to be massaged
596 static void ioat2_dma_massage_chan_desc(struct ioat_dma_chan *ioat)
598 struct ioat_desc_sw *desc, *_desc;
600 /* setup used_desc */
601 ioat->used_desc.next = ioat->free_desc.next;
602 ioat->used_desc.prev = NULL;
604 /* pull free_desc out of the circle so that every node is a hw
605 * descriptor, but leave it pointing to the list
607 ioat->free_desc.prev->next = ioat->free_desc.next;
608 ioat->free_desc.next->prev = ioat->free_desc.prev;
610 /* circle link the hw descriptors */
611 desc = to_ioat_desc(ioat->free_desc.next);
612 desc->hw->next = to_ioat_desc(desc->node.next)->txd.phys;
613 list_for_each_entry_safe(desc, _desc, ioat->free_desc.next, node) {
614 desc->hw->next = to_ioat_desc(desc->node.next)->txd.phys;
619 * ioat_dma_alloc_chan_resources - returns the number of allocated descriptors
620 * @chan: the channel to be filled out
622 static int ioat_dma_alloc_chan_resources(struct dma_chan *c)
624 struct ioat_dma_chan *ioat = to_ioat_chan(c);
625 struct ioat_chan_common *chan = &ioat->base;
626 struct ioat_desc_sw *desc;
632 /* have we already been set up? */
633 if (!list_empty(&ioat->free_desc))
634 return ioat->desccount;
636 /* Setup register to interrupt and write completion status on error */
637 chanctrl = IOAT_CHANCTRL_ERR_INT_EN |
638 IOAT_CHANCTRL_ANY_ERR_ABORT_EN |
639 IOAT_CHANCTRL_ERR_COMPLETION_EN;
640 writew(chanctrl, chan->reg_base + IOAT_CHANCTRL_OFFSET);
642 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
644 dev_err(to_dev(chan), "CHANERR = %x, clearing\n", chanerr);
645 writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
648 /* Allocate descriptors */
649 for (i = 0; i < ioat_initial_desc_count; i++) {
650 desc = ioat_dma_alloc_descriptor(ioat, GFP_KERNEL);
652 dev_err(to_dev(chan), "Only %d initial descriptors\n", i);
655 list_add_tail(&desc->node, &tmp_list);
657 spin_lock_bh(&ioat->desc_lock);
659 list_splice(&tmp_list, &ioat->free_desc);
660 if (chan->device->version != IOAT_VER_1_2)
661 ioat2_dma_massage_chan_desc(ioat);
662 spin_unlock_bh(&ioat->desc_lock);
664 /* allocate a completion writeback area */
665 /* doing 2 32bit writes to mmio since 1 64b write doesn't work */
666 chan->completion_virt = pci_pool_alloc(chan->device->completion_pool,
668 &chan->completion_addr);
669 memset(chan->completion_virt, 0,
670 sizeof(*chan->completion_virt));
671 writel(((u64) chan->completion_addr) & 0x00000000FFFFFFFF,
672 chan->reg_base + IOAT_CHANCMP_OFFSET_LOW);
673 writel(((u64) chan->completion_addr) >> 32,
674 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
676 tasklet_enable(&chan->cleanup_task);
677 ioat_dma_start_null_desc(ioat); /* give chain to dma device */
678 return ioat->desccount;
682 * ioat_dma_free_chan_resources - release all the descriptors
683 * @chan: the channel to be cleaned
685 static void ioat_dma_free_chan_resources(struct dma_chan *c)
687 struct ioat_dma_chan *ioat = to_ioat_chan(c);
688 struct ioat_chan_common *chan = &ioat->base;
689 struct ioatdma_device *ioatdma_device = chan->device;
690 struct ioat_desc_sw *desc, *_desc;
691 int in_use_descs = 0;
693 /* Before freeing channel resources first check
694 * if they have been previously allocated for this channel.
696 if (ioat->desccount == 0)
699 tasklet_disable(&chan->cleanup_task);
700 ioat_dma_memcpy_cleanup(ioat);
702 /* Delay 100ms after reset to allow internal DMA logic to quiesce
703 * before removing DMA descriptor resources.
705 writeb(IOAT_CHANCMD_RESET,
706 chan->reg_base + IOAT_CHANCMD_OFFSET(chan->device->version));
709 spin_lock_bh(&ioat->desc_lock);
710 switch (chan->device->version) {
712 list_for_each_entry_safe(desc, _desc,
713 &ioat->used_desc, node) {
715 list_del(&desc->node);
716 pci_pool_free(ioatdma_device->dma_pool, desc->hw,
720 list_for_each_entry_safe(desc, _desc,
721 &ioat->free_desc, node) {
722 list_del(&desc->node);
723 pci_pool_free(ioatdma_device->dma_pool, desc->hw,
730 list_for_each_entry_safe(desc, _desc,
731 ioat->free_desc.next, node) {
732 list_del(&desc->node);
733 pci_pool_free(ioatdma_device->dma_pool, desc->hw,
737 desc = to_ioat_desc(ioat->free_desc.next);
738 pci_pool_free(ioatdma_device->dma_pool, desc->hw,
741 INIT_LIST_HEAD(&ioat->free_desc);
742 INIT_LIST_HEAD(&ioat->used_desc);
745 spin_unlock_bh(&ioat->desc_lock);
747 pci_pool_free(ioatdma_device->completion_pool,
748 chan->completion_virt,
749 chan->completion_addr);
751 /* one is ok since we left it on there on purpose */
752 if (in_use_descs > 1)
753 dev_err(to_dev(chan), "Freeing %d in use descriptors!\n",
756 chan->last_completion = chan->completion_addr = 0;
757 chan->watchdog_completion = 0;
758 chan->last_compl_desc_addr_hw = 0;
759 chan->watchdog_tcp_cookie = chan->watchdog_last_tcp_cookie = 0;
766 * ioat1_dma_get_next_descriptor - return the next available descriptor
767 * @ioat: IOAT DMA channel handle
769 * Gets the next descriptor from the chain, and must be called with the
770 * channel's desc_lock held. Allocates more descriptors if the channel
773 static struct ioat_desc_sw *
774 ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat)
776 struct ioat_desc_sw *new;
778 if (!list_empty(&ioat->free_desc)) {
779 new = to_ioat_desc(ioat->free_desc.next);
780 list_del(&new->node);
782 /* try to get another desc */
783 new = ioat_dma_alloc_descriptor(ioat, GFP_ATOMIC);
785 dev_err(to_dev(&ioat->base), "alloc failed\n");
794 static struct ioat_desc_sw *
795 ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat)
797 struct ioat_desc_sw *new;
800 * used.prev points to where to start processing
801 * used.next points to next free descriptor
802 * if used.prev == NULL, there are none waiting to be processed
803 * if used.next == used.prev.prev, there is only one free descriptor,
804 * and we need to use it to as a noop descriptor before
805 * linking in a new set of descriptors, since the device
806 * has probably already read the pointer to it
808 if (ioat->used_desc.prev &&
809 ioat->used_desc.next == ioat->used_desc.prev->prev) {
811 struct ioat_desc_sw *desc;
812 struct ioat_desc_sw *noop_desc;
815 /* set up the noop descriptor */
816 noop_desc = to_ioat_desc(ioat->used_desc.next);
817 /* set size to non-zero value (channel returns error when size is 0) */
818 noop_desc->hw->size = NULL_DESC_BUFFER_SIZE;
819 noop_desc->hw->ctl = 0;
820 noop_desc->hw->ctl_f.null = 1;
821 noop_desc->hw->src_addr = 0;
822 noop_desc->hw->dst_addr = 0;
824 ioat->used_desc.next = ioat->used_desc.next->next;
828 /* try to get a few more descriptors */
829 for (i = 16; i; i--) {
830 desc = ioat_dma_alloc_descriptor(ioat, GFP_ATOMIC);
832 dev_err(to_dev(&ioat->base),
836 list_add_tail(&desc->node, ioat->used_desc.next);
839 = to_ioat_desc(desc->node.next)->txd.phys;
840 to_ioat_desc(desc->node.prev)->hw->next
845 ioat->used_desc.next = noop_desc->node.next;
847 new = to_ioat_desc(ioat->used_desc.next);
849 ioat->used_desc.next = new->node.next;
851 if (ioat->used_desc.prev == NULL)
852 ioat->used_desc.prev = &new->node;
858 static struct ioat_desc_sw *
859 ioat_dma_get_next_descriptor(struct ioat_dma_chan *ioat)
864 switch (ioat->base.device->version) {
866 return ioat1_dma_get_next_descriptor(ioat);
869 return ioat2_dma_get_next_descriptor(ioat);
874 static struct dma_async_tx_descriptor *
875 ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
876 dma_addr_t dma_src, size_t len, unsigned long flags)
878 struct ioat_dma_chan *ioat = to_ioat_chan(c);
879 struct ioat_desc_sw *desc;
882 dma_addr_t src = dma_src;
883 dma_addr_t dest = dma_dest;
884 size_t total_len = len;
885 struct ioat_dma_descriptor *hw = NULL;
888 spin_lock_bh(&ioat->desc_lock);
889 desc = ioat_dma_get_next_descriptor(ioat);
895 copy = min_t(size_t, len, ioat->xfercap);
903 list_add_tail(&desc->node, &chain);
909 struct ioat_desc_sw *next;
911 async_tx_ack(&desc->txd);
912 next = ioat_dma_get_next_descriptor(ioat);
913 hw->next = next ? next->txd.phys : 0;
920 struct ioat_chan_common *chan = &ioat->base;
922 dev_err(to_dev(chan),
923 "chan%d - get_next_desc failed: %d descs waiting, %d total desc\n",
924 chan_num(chan), ioat->dmacount, ioat->desccount);
925 list_splice(&chain, &ioat->free_desc);
926 spin_unlock_bh(&ioat->desc_lock);
929 spin_unlock_bh(&ioat->desc_lock);
931 desc->txd.flags = flags;
932 desc->tx_cnt = tx_cnt;
934 desc->dst = dma_dest;
935 desc->len = total_len;
936 list_splice(&chain, &desc->txd.tx_list);
937 hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
938 hw->ctl_f.compl_write = 1;
943 static struct dma_async_tx_descriptor *
944 ioat2_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
945 dma_addr_t dma_src, size_t len, unsigned long flags)
947 struct ioat_dma_chan *ioat = to_ioat_chan(c);
948 struct ioat_desc_sw *new;
950 spin_lock_bh(&ioat->desc_lock);
951 new = ioat2_dma_get_next_descriptor(ioat);
954 * leave ioat->desc_lock set in ioat 2 path
955 * it will get unlocked at end of tx_submit
962 new->txd.flags = flags;
965 struct ioat_chan_common *chan = &ioat->base;
967 spin_unlock_bh(&ioat->desc_lock);
968 dev_err(to_dev(chan),
969 "chan%d - get_next_desc failed: %d descs waiting, %d total desc\n",
970 chan_num(chan), ioat->dmacount, ioat->desccount);
975 static void ioat_dma_cleanup_tasklet(unsigned long data)
977 struct ioat_dma_chan *chan = (void *)data;
978 ioat_dma_memcpy_cleanup(chan);
979 writew(IOAT_CHANCTRL_INT_DISABLE,
980 chan->base.reg_base + IOAT_CHANCTRL_OFFSET);
984 ioat_dma_unmap(struct ioat_chan_common *chan, struct ioat_desc_sw *desc)
986 if (!(desc->txd.flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
987 if (desc->txd.flags & DMA_COMPL_DEST_UNMAP_SINGLE)
988 pci_unmap_single(chan->device->pdev,
989 pci_unmap_addr(desc, dst),
990 pci_unmap_len(desc, len),
993 pci_unmap_page(chan->device->pdev,
994 pci_unmap_addr(desc, dst),
995 pci_unmap_len(desc, len),
999 if (!(desc->txd.flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
1000 if (desc->txd.flags & DMA_COMPL_SRC_UNMAP_SINGLE)
1001 pci_unmap_single(chan->device->pdev,
1002 pci_unmap_addr(desc, src),
1003 pci_unmap_len(desc, len),
1006 pci_unmap_page(chan->device->pdev,
1007 pci_unmap_addr(desc, src),
1008 pci_unmap_len(desc, len),
1014 * ioat_dma_memcpy_cleanup - cleanup up finished descriptors
1015 * @chan: ioat channel to be cleaned up
1017 static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat)
1019 struct ioat_chan_common *chan = &ioat->base;
1020 unsigned long phys_complete;
1021 struct ioat_desc_sw *desc, *_desc;
1022 dma_cookie_t cookie = 0;
1023 unsigned long desc_phys;
1024 struct ioat_desc_sw *latest_desc;
1025 struct dma_async_tx_descriptor *tx;
1027 prefetch(chan->completion_virt);
1029 if (!spin_trylock_bh(&chan->cleanup_lock))
1032 /* The completion writeback can happen at any time,
1033 so reads by the driver need to be atomic operations
1034 The descriptor physical addresses are limited to 32-bits
1035 when the CPU can only do a 32-bit mov */
1037 #if (BITS_PER_LONG == 64)
1039 chan->completion_virt->full
1040 & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
1042 phys_complete = chan->completion_virt->low & IOAT_LOW_COMPLETION_MASK;
1045 if ((chan->completion_virt->full
1046 & IOAT_CHANSTS_DMA_TRANSFER_STATUS) ==
1047 IOAT_CHANSTS_DMA_TRANSFER_STATUS_HALTED) {
1048 dev_err(to_dev(chan), "Channel halted, chanerr = %x\n",
1049 readl(chan->reg_base + IOAT_CHANERR_OFFSET));
1051 /* TODO do something to salvage the situation */
1054 if (phys_complete == chan->last_completion) {
1055 spin_unlock_bh(&chan->cleanup_lock);
1057 * perhaps we're stuck so hard that the watchdog can't go off?
1058 * try to catch it after 2 seconds
1060 if (chan->device->version != IOAT_VER_3_0) {
1061 if (time_after(jiffies,
1062 chan->last_completion_time + HZ*WATCHDOG_DELAY)) {
1063 ioat_dma_chan_watchdog(&(chan->device->work.work));
1064 chan->last_completion_time = jiffies;
1069 chan->last_completion_time = jiffies;
1072 if (!spin_trylock_bh(&ioat->desc_lock)) {
1073 spin_unlock_bh(&chan->cleanup_lock);
1077 switch (chan->device->version) {
1079 list_for_each_entry_safe(desc, _desc, &ioat->used_desc, node) {
1082 * Incoming DMA requests may use multiple descriptors,
1083 * due to exceeding xfercap, perhaps. If so, only the
1084 * last one will have a cookie, and require unmapping.
1087 cookie = tx->cookie;
1088 ioat_dma_unmap(chan, desc);
1090 tx->callback(tx->callback_param);
1091 tx->callback = NULL;
1095 if (tx->phys != phys_complete) {
1097 * a completed entry, but not the last, so clean
1098 * up if the client is done with the descriptor
1100 if (async_tx_test_ack(tx)) {
1101 list_move_tail(&desc->node,
1107 * last used desc. Do not remove, so we can
1108 * append from it, but don't look at it next
1113 /* TODO check status bits? */
1120 /* has some other thread has already cleaned up? */
1121 if (ioat->used_desc.prev == NULL)
1124 /* work backwards to find latest finished desc */
1125 desc = to_ioat_desc(ioat->used_desc.next);
1129 desc = to_ioat_desc(desc->node.prev);
1130 desc_phys = (unsigned long)tx->phys
1131 & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
1132 if (desc_phys == phys_complete) {
1136 } while (&desc->node != ioat->used_desc.prev);
1138 if (latest_desc != NULL) {
1139 /* work forwards to clear finished descriptors */
1140 for (desc = to_ioat_desc(ioat->used_desc.prev);
1141 &desc->node != latest_desc->node.next &&
1142 &desc->node != ioat->used_desc.next;
1143 desc = to_ioat_desc(desc->node.next)) {
1145 cookie = tx->cookie;
1147 ioat_dma_unmap(chan, desc);
1149 tx->callback(tx->callback_param);
1150 tx->callback = NULL;
1155 /* move used.prev up beyond those that are finished */
1156 if (&desc->node == ioat->used_desc.next)
1157 ioat->used_desc.prev = NULL;
1159 ioat->used_desc.prev = &desc->node;
1164 spin_unlock_bh(&ioat->desc_lock);
1166 chan->last_completion = phys_complete;
1168 chan->completed_cookie = cookie;
1170 spin_unlock_bh(&chan->cleanup_lock);
1174 * ioat_dma_is_complete - poll the status of a IOAT DMA transaction
1175 * @chan: IOAT DMA channel handle
1176 * @cookie: DMA transaction identifier
1177 * @done: if not %NULL, updated with last completed transaction
1178 * @used: if not %NULL, updated with last used transaction
1180 static enum dma_status
1181 ioat_dma_is_complete(struct dma_chan *c, dma_cookie_t cookie,
1182 dma_cookie_t *done, dma_cookie_t *used)
1184 struct ioat_dma_chan *ioat = to_ioat_chan(c);
1185 struct ioat_chan_common *chan = &ioat->base;
1186 dma_cookie_t last_used;
1187 dma_cookie_t last_complete;
1188 enum dma_status ret;
1190 last_used = c->cookie;
1191 last_complete = chan->completed_cookie;
1192 chan->watchdog_tcp_cookie = cookie;
1195 *done = last_complete;
1199 ret = dma_async_is_complete(cookie, last_complete, last_used);
1200 if (ret == DMA_SUCCESS)
1203 ioat_dma_memcpy_cleanup(ioat);
1205 last_used = c->cookie;
1206 last_complete = chan->completed_cookie;
1209 *done = last_complete;
1213 return dma_async_is_complete(cookie, last_complete, last_used);
1216 static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat)
1218 struct ioat_chan_common *chan = &ioat->base;
1219 struct ioat_desc_sw *desc;
1220 struct ioat_dma_descriptor *hw;
1222 spin_lock_bh(&ioat->desc_lock);
1224 desc = ioat_dma_get_next_descriptor(ioat);
1227 dev_err(to_dev(chan),
1228 "Unable to start null desc - get next desc failed\n");
1229 spin_unlock_bh(&ioat->desc_lock);
1236 hw->ctl_f.int_en = 1;
1237 hw->ctl_f.compl_write = 1;
1238 /* set size to non-zero value (channel returns error when size is 0) */
1239 hw->size = NULL_DESC_BUFFER_SIZE;
1242 async_tx_ack(&desc->txd);
1243 switch (chan->device->version) {
1246 list_add_tail(&desc->node, &ioat->used_desc);
1248 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF,
1249 chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW);
1250 writel(((u64) desc->txd.phys) >> 32,
1251 chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH);
1253 writeb(IOAT_CHANCMD_START, chan->reg_base
1254 + IOAT_CHANCMD_OFFSET(chan->device->version));
1258 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF,
1259 chan->reg_base + IOAT2_CHAINADDR_OFFSET_LOW);
1260 writel(((u64) desc->txd.phys) >> 32,
1261 chan->reg_base + IOAT2_CHAINADDR_OFFSET_HIGH);
1264 __ioat2_dma_memcpy_issue_pending(ioat);
1267 spin_unlock_bh(&ioat->desc_lock);
1271 * Perform a IOAT transaction to verify the HW works.
1273 #define IOAT_TEST_SIZE 2000
1275 static void ioat_dma_test_callback(void *dma_async_param)
1277 struct completion *cmp = dma_async_param;
1283 * ioat_dma_self_test - Perform a IOAT transaction to verify the HW works.
1284 * @device: device to be tested
1286 static int ioat_dma_self_test(struct ioatdma_device *device)
1291 struct dma_device *dma = &device->common;
1292 struct device *dev = &device->pdev->dev;
1293 struct dma_chan *dma_chan;
1294 struct dma_async_tx_descriptor *tx;
1295 dma_addr_t dma_dest, dma_src;
1296 dma_cookie_t cookie;
1298 struct completion cmp;
1300 unsigned long flags;
1302 src = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
1305 dest = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
1311 /* Fill in src buffer */
1312 for (i = 0; i < IOAT_TEST_SIZE; i++)
1315 /* Start copy, using first DMA channel */
1316 dma_chan = container_of(dma->channels.next, struct dma_chan,
1318 if (dma->device_alloc_chan_resources(dma_chan) < 1) {
1319 dev_err(dev, "selftest cannot allocate chan resource\n");
1324 dma_src = dma_map_single(dev, src, IOAT_TEST_SIZE, DMA_TO_DEVICE);
1325 dma_dest = dma_map_single(dev, dest, IOAT_TEST_SIZE, DMA_FROM_DEVICE);
1326 flags = DMA_COMPL_SRC_UNMAP_SINGLE | DMA_COMPL_DEST_UNMAP_SINGLE |
1328 tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src,
1329 IOAT_TEST_SIZE, flags);
1331 dev_err(dev, "Self-test prep failed, disabling\n");
1333 goto free_resources;
1337 init_completion(&cmp);
1338 tx->callback = ioat_dma_test_callback;
1339 tx->callback_param = &cmp;
1340 cookie = tx->tx_submit(tx);
1342 dev_err(dev, "Self-test setup failed, disabling\n");
1344 goto free_resources;
1346 dma->device_issue_pending(dma_chan);
1348 tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
1351 dma->device_is_tx_complete(dma_chan, cookie, NULL, NULL)
1353 dev_err(dev, "Self-test copy timed out, disabling\n");
1355 goto free_resources;
1357 if (memcmp(src, dest, IOAT_TEST_SIZE)) {
1358 dev_err(dev, "Self-test copy failed compare, disabling\n");
1360 goto free_resources;
1364 dma->device_free_chan_resources(dma_chan);
1371 static char ioat_interrupt_style[32] = "msix";
1372 module_param_string(ioat_interrupt_style, ioat_interrupt_style,
1373 sizeof(ioat_interrupt_style), 0644);
1374 MODULE_PARM_DESC(ioat_interrupt_style,
1375 "set ioat interrupt style: msix (default), "
1376 "msix-single-vector, msi, intx)");
1379 * ioat_dma_setup_interrupts - setup interrupt handler
1380 * @device: ioat device
1382 static int ioat_dma_setup_interrupts(struct ioatdma_device *device)
1384 struct ioat_chan_common *chan;
1385 struct pci_dev *pdev = device->pdev;
1386 struct device *dev = &pdev->dev;
1387 struct msix_entry *msix;
1392 if (!strcmp(ioat_interrupt_style, "msix"))
1394 if (!strcmp(ioat_interrupt_style, "msix-single-vector"))
1395 goto msix_single_vector;
1396 if (!strcmp(ioat_interrupt_style, "msi"))
1398 if (!strcmp(ioat_interrupt_style, "intx"))
1400 dev_err(dev, "invalid ioat_interrupt_style %s\n", ioat_interrupt_style);
1404 /* The number of MSI-X vectors should equal the number of channels */
1405 msixcnt = device->common.chancnt;
1406 for (i = 0; i < msixcnt; i++)
1407 device->msix_entries[i].entry = i;
1409 err = pci_enable_msix(pdev, device->msix_entries, msixcnt);
1413 goto msix_single_vector;
1415 for (i = 0; i < msixcnt; i++) {
1416 msix = &device->msix_entries[i];
1417 chan = ioat_chan_by_index(device, i);
1418 err = devm_request_irq(dev, msix->vector,
1419 ioat_dma_do_interrupt_msix, 0,
1422 for (j = 0; j < i; j++) {
1423 msix = &device->msix_entries[j];
1424 chan = ioat_chan_by_index(device, j);
1425 devm_free_irq(dev, msix->vector, chan);
1427 goto msix_single_vector;
1430 intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL;
1434 msix = &device->msix_entries[0];
1436 err = pci_enable_msix(pdev, device->msix_entries, 1);
1440 err = devm_request_irq(dev, msix->vector, ioat_dma_do_interrupt, 0,
1441 "ioat-msix", device);
1443 pci_disable_msix(pdev);
1449 err = pci_enable_msi(pdev);
1453 err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt, 0,
1454 "ioat-msi", device);
1456 pci_disable_msi(pdev);
1462 err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt,
1463 IRQF_SHARED, "ioat-intx", device);
1468 if (device->intr_quirk)
1469 device->intr_quirk(device);
1470 intrctrl |= IOAT_INTRCTRL_MASTER_INT_EN;
1471 writeb(intrctrl, device->reg_base + IOAT_INTRCTRL_OFFSET);
1475 /* Disable all interrupt generation */
1476 writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
1477 dev_err(dev, "no usable interrupts\n");
1481 static void ioat_disable_interrupts(struct ioatdma_device *device)
1483 /* Disable all interrupt generation */
1484 writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
1487 static int ioat_probe(struct ioatdma_device *device)
1490 struct dma_device *dma = &device->common;
1491 struct pci_dev *pdev = device->pdev;
1492 struct device *dev = &pdev->dev;
1494 /* DMA coherent memory pool for DMA descriptor allocations */
1495 device->dma_pool = pci_pool_create("dma_desc_pool", pdev,
1496 sizeof(struct ioat_dma_descriptor),
1498 if (!device->dma_pool) {
1503 device->completion_pool = pci_pool_create("completion_pool", pdev,
1504 sizeof(u64), SMP_CACHE_BYTES,
1506 if (!device->completion_pool) {
1508 goto err_completion_pool;
1511 ioat_dma_enumerate_channels(device);
1513 dma_cap_set(DMA_MEMCPY, dma->cap_mask);
1514 dma->device_alloc_chan_resources = ioat_dma_alloc_chan_resources;
1515 dma->device_free_chan_resources = ioat_dma_free_chan_resources;
1516 dma->device_is_tx_complete = ioat_dma_is_complete;
1517 dma->dev = &pdev->dev;
1519 dev_err(dev, "Intel(R) I/OAT DMA Engine found,"
1520 " %d channels, device version 0x%02x, driver version %s\n",
1521 dma->chancnt, device->version, IOAT_DMA_VERSION);
1523 if (!dma->chancnt) {
1524 dev_err(dev, "Intel(R) I/OAT DMA Engine problem found: "
1525 "zero channels detected\n");
1526 goto err_setup_interrupts;
1529 err = ioat_dma_setup_interrupts(device);
1531 goto err_setup_interrupts;
1533 err = ioat_dma_self_test(device);
1540 ioat_disable_interrupts(device);
1541 err_setup_interrupts:
1542 pci_pool_destroy(device->completion_pool);
1543 err_completion_pool:
1544 pci_pool_destroy(device->dma_pool);
1549 static int ioat_register(struct ioatdma_device *device)
1551 int err = dma_async_device_register(&device->common);
1554 ioat_disable_interrupts(device);
1555 pci_pool_destroy(device->completion_pool);
1556 pci_pool_destroy(device->dma_pool);
1562 /* ioat1_intr_quirk - fix up dma ctrl register to enable / disable msi */
1563 static void ioat1_intr_quirk(struct ioatdma_device *device)
1565 struct pci_dev *pdev = device->pdev;
1568 pci_read_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, &dmactrl);
1569 if (pdev->msi_enabled)
1570 dmactrl |= IOAT_PCI_DMACTRL_MSI_EN;
1572 dmactrl &= ~IOAT_PCI_DMACTRL_MSI_EN;
1573 pci_write_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, dmactrl);
1576 int ioat1_dma_probe(struct ioatdma_device *device, int dca)
1578 struct pci_dev *pdev = device->pdev;
1579 struct dma_device *dma;
1582 device->intr_quirk = ioat1_intr_quirk;
1583 dma = &device->common;
1584 dma->device_prep_dma_memcpy = ioat1_dma_prep_memcpy;
1585 dma->device_issue_pending = ioat1_dma_memcpy_issue_pending;
1587 err = ioat_probe(device);
1590 ioat_set_tcp_copy_break(4096);
1591 err = ioat_register(device);
1595 device->dca = ioat_dca_init(pdev, device->reg_base);
1597 INIT_DELAYED_WORK(&device->work, ioat_dma_chan_watchdog);
1598 schedule_delayed_work(&device->work, WATCHDOG_DELAY);
1603 int ioat2_dma_probe(struct ioatdma_device *device, int dca)
1605 struct pci_dev *pdev = device->pdev;
1606 struct dma_device *dma;
1608 struct ioat_chan_common *chan;
1611 dma = &device->common;
1612 dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy;
1613 dma->device_issue_pending = ioat2_dma_memcpy_issue_pending;
1615 err = ioat_probe(device);
1618 ioat_set_tcp_copy_break(2048);
1620 list_for_each_entry(c, &dma->channels, device_node) {
1621 chan = to_chan_common(c);
1622 writel(IOAT_DCACTRL_CMPL_WRITE_ENABLE | IOAT_DMA_DCA_ANY_CPU,
1623 chan->reg_base + IOAT_DCACTRL_OFFSET);
1626 err = ioat_register(device);
1630 device->dca = ioat2_dca_init(pdev, device->reg_base);
1632 INIT_DELAYED_WORK(&device->work, ioat_dma_chan_watchdog);
1633 schedule_delayed_work(&device->work, WATCHDOG_DELAY);
1638 int ioat3_dma_probe(struct ioatdma_device *device, int dca)
1640 struct pci_dev *pdev = device->pdev;
1641 struct dma_device *dma;
1643 struct ioat_chan_common *chan;
1647 dma = &device->common;
1648 dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy;
1649 dma->device_issue_pending = ioat2_dma_memcpy_issue_pending;
1651 /* -= IOAT ver.3 workarounds =- */
1652 /* Write CHANERRMSK_INT with 3E07h to mask out the errors
1653 * that can cause stability issues for IOAT ver.3
1655 pci_write_config_dword(pdev, IOAT_PCI_CHANERRMASK_INT_OFFSET, 0x3e07);
1657 /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit
1658 * (workaround for spurious config parity error after restart)
1660 pci_read_config_word(pdev, IOAT_PCI_DEVICE_ID_OFFSET, &dev_id);
1661 if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0)
1662 pci_write_config_dword(pdev, IOAT_PCI_DMAUNCERRSTS_OFFSET, 0x10);
1664 err = ioat_probe(device);
1667 ioat_set_tcp_copy_break(262144);
1669 list_for_each_entry(c, &dma->channels, device_node) {
1670 chan = to_chan_common(c);
1671 writel(IOAT_DMA_DCA_ANY_CPU,
1672 chan->reg_base + IOAT_DCACTRL_OFFSET);
1675 err = ioat_register(device);
1679 device->dca = ioat3_dca_init(pdev, device->reg_base);
1684 void ioat_dma_remove(struct ioatdma_device *device)
1686 struct dma_device *dma = &device->common;
1688 if (device->version != IOAT_VER_3_0)
1689 cancel_delayed_work(&device->work);
1691 ioat_disable_interrupts(device);
1693 dma_async_device_unregister(dma);
1695 pci_pool_destroy(device->dma_pool);
1696 pci_pool_destroy(device->completion_pool);
1698 INIT_LIST_HEAD(&dma->channels);