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 (versions >= 2), which
25 * does asynchronous data movement and checksumming operations.
28 #include <linux/init.h>
29 #include <linux/module.h>
30 #include <linux/slab.h>
31 #include <linux/pci.h>
32 #include <linux/interrupt.h>
33 #include <linux/dmaengine.h>
34 #include <linux/delay.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/workqueue.h>
37 #include <linux/prefetch.h>
38 #include <linux/i7300_idle.h>
41 #include "registers.h"
44 int ioat_ring_alloc_order = 8;
45 module_param(ioat_ring_alloc_order, int, 0644);
46 MODULE_PARM_DESC(ioat_ring_alloc_order,
47 "ioat2+: allocate 2^n descriptors per channel"
48 " (default: 8 max: 16)");
49 static int ioat_ring_max_alloc_order = IOAT_MAX_ORDER;
50 module_param(ioat_ring_max_alloc_order, int, 0644);
51 MODULE_PARM_DESC(ioat_ring_max_alloc_order,
52 "ioat2+: upper limit for ring size (default: 16)");
54 void __ioat2_issue_pending(struct ioat2_dma_chan *ioat)
56 struct ioat_chan_common *chan = &ioat->base;
58 ioat->dmacount += ioat2_ring_pending(ioat);
59 ioat->issued = ioat->head;
60 writew(ioat->dmacount, chan->reg_base + IOAT_CHAN_DMACOUNT_OFFSET);
62 "%s: head: %#x tail: %#x issued: %#x count: %#x\n",
63 __func__, ioat->head, ioat->tail, ioat->issued, ioat->dmacount);
66 void ioat2_issue_pending(struct dma_chan *c)
68 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
70 if (ioat2_ring_pending(ioat)) {
71 spin_lock_bh(&ioat->prep_lock);
72 __ioat2_issue_pending(ioat);
73 spin_unlock_bh(&ioat->prep_lock);
78 * ioat2_update_pending - log pending descriptors
79 * @ioat: ioat2+ channel
81 * Check if the number of unsubmitted descriptors has exceeded the
82 * watermark. Called with prep_lock held
84 static void ioat2_update_pending(struct ioat2_dma_chan *ioat)
86 if (ioat2_ring_pending(ioat) > ioat_pending_level)
87 __ioat2_issue_pending(ioat);
90 static void __ioat2_start_null_desc(struct ioat2_dma_chan *ioat)
92 struct ioat_ring_ent *desc;
93 struct ioat_dma_descriptor *hw;
95 if (ioat2_ring_space(ioat) < 1) {
96 dev_err(to_dev(&ioat->base),
97 "Unable to start null desc - ring full\n");
101 dev_dbg(to_dev(&ioat->base), "%s: head: %#x tail: %#x issued: %#x\n",
102 __func__, ioat->head, ioat->tail, ioat->issued);
103 desc = ioat2_get_ring_ent(ioat, ioat->head);
108 hw->ctl_f.int_en = 1;
109 hw->ctl_f.compl_write = 1;
110 /* set size to non-zero value (channel returns error when size is 0) */
111 hw->size = NULL_DESC_BUFFER_SIZE;
114 async_tx_ack(&desc->txd);
115 ioat2_set_chainaddr(ioat, desc->txd.phys);
116 dump_desc_dbg(ioat, desc);
119 __ioat2_issue_pending(ioat);
122 static void ioat2_start_null_desc(struct ioat2_dma_chan *ioat)
124 spin_lock_bh(&ioat->prep_lock);
125 __ioat2_start_null_desc(ioat);
126 spin_unlock_bh(&ioat->prep_lock);
129 static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
131 struct ioat_chan_common *chan = &ioat->base;
132 struct dma_async_tx_descriptor *tx;
133 struct ioat_ring_ent *desc;
134 bool seen_current = false;
136 int idx = ioat->tail, i;
138 dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n",
139 __func__, ioat->head, ioat->tail, ioat->issued);
141 active = ioat2_ring_active(ioat);
142 for (i = 0; i < active && !seen_current; i++) {
143 smp_read_barrier_depends();
144 prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
145 desc = ioat2_get_ring_ent(ioat, idx + i);
147 dump_desc_dbg(ioat, desc);
149 ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
150 chan->completed_cookie = tx->cookie;
153 tx->callback(tx->callback_param);
158 if (tx->phys == phys_complete)
161 smp_mb(); /* finish all descriptor reads before incrementing tail */
162 ioat->tail = idx + i;
163 BUG_ON(active && !seen_current); /* no active descs have written a completion? */
165 chan->last_completion = phys_complete;
166 if (active - i == 0) {
167 dev_dbg(to_dev(chan), "%s: cancel completion timeout\n",
169 clear_bit(IOAT_COMPLETION_PENDING, &chan->state);
170 mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
175 * ioat2_cleanup - clean finished descriptors (advance tail pointer)
176 * @chan: ioat channel to be cleaned up
178 static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
180 struct ioat_chan_common *chan = &ioat->base;
181 unsigned long phys_complete;
183 spin_lock_bh(&chan->cleanup_lock);
184 if (ioat_cleanup_preamble(chan, &phys_complete))
185 __cleanup(ioat, phys_complete);
186 spin_unlock_bh(&chan->cleanup_lock);
189 void ioat2_cleanup_event(unsigned long data)
191 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
194 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
197 void __ioat2_restart_chan(struct ioat2_dma_chan *ioat)
199 struct ioat_chan_common *chan = &ioat->base;
201 /* set the tail to be re-issued */
202 ioat->issued = ioat->tail;
204 set_bit(IOAT_COMPLETION_PENDING, &chan->state);
205 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
207 dev_dbg(to_dev(chan),
208 "%s: head: %#x tail: %#x issued: %#x count: %#x\n",
209 __func__, ioat->head, ioat->tail, ioat->issued, ioat->dmacount);
211 if (ioat2_ring_pending(ioat)) {
212 struct ioat_ring_ent *desc;
214 desc = ioat2_get_ring_ent(ioat, ioat->tail);
215 ioat2_set_chainaddr(ioat, desc->txd.phys);
216 __ioat2_issue_pending(ioat);
218 __ioat2_start_null_desc(ioat);
221 int ioat2_quiesce(struct ioat_chan_common *chan, unsigned long tmo)
223 unsigned long end = jiffies + tmo;
227 status = ioat_chansts(chan);
228 if (is_ioat_active(status) || is_ioat_idle(status))
230 while (is_ioat_active(status) || is_ioat_idle(status)) {
231 if (tmo && time_after(jiffies, end)) {
235 status = ioat_chansts(chan);
242 int ioat2_reset_sync(struct ioat_chan_common *chan, unsigned long tmo)
244 unsigned long end = jiffies + tmo;
248 while (ioat_reset_pending(chan)) {
249 if (end && time_after(jiffies, end)) {
259 static void ioat2_restart_channel(struct ioat2_dma_chan *ioat)
261 struct ioat_chan_common *chan = &ioat->base;
262 unsigned long phys_complete;
264 ioat2_quiesce(chan, 0);
265 if (ioat_cleanup_preamble(chan, &phys_complete))
266 __cleanup(ioat, phys_complete);
268 __ioat2_restart_chan(ioat);
271 void ioat2_timer_event(unsigned long data)
273 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
274 struct ioat_chan_common *chan = &ioat->base;
276 if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
277 unsigned long phys_complete;
280 status = ioat_chansts(chan);
282 /* when halted due to errors check for channel
283 * programming errors before advancing the completion state
285 if (is_ioat_halted(status)) {
288 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
289 dev_err(to_dev(chan), "%s: Channel halted (%x)\n",
291 if (test_bit(IOAT_RUN, &chan->state))
292 BUG_ON(is_ioat_bug(chanerr));
293 else /* we never got off the ground */
297 /* if we haven't made progress and we have already
298 * acknowledged a pending completion once, then be more
299 * forceful with a restart
301 spin_lock_bh(&chan->cleanup_lock);
302 if (ioat_cleanup_preamble(chan, &phys_complete)) {
303 __cleanup(ioat, phys_complete);
304 } else if (test_bit(IOAT_COMPLETION_ACK, &chan->state)) {
305 spin_lock_bh(&ioat->prep_lock);
306 ioat2_restart_channel(ioat);
307 spin_unlock_bh(&ioat->prep_lock);
309 set_bit(IOAT_COMPLETION_ACK, &chan->state);
310 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
312 spin_unlock_bh(&chan->cleanup_lock);
316 /* if the ring is idle, empty, and oversized try to step
319 spin_lock_bh(&chan->cleanup_lock);
320 spin_lock_bh(&ioat->prep_lock);
321 active = ioat2_ring_active(ioat);
322 if (active == 0 && ioat->alloc_order > ioat_get_alloc_order())
323 reshape_ring(ioat, ioat->alloc_order-1);
324 spin_unlock_bh(&ioat->prep_lock);
325 spin_unlock_bh(&chan->cleanup_lock);
327 /* keep shrinking until we get back to our minimum
330 if (ioat->alloc_order > ioat_get_alloc_order())
331 mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
335 static int ioat2_reset_hw(struct ioat_chan_common *chan)
337 /* throw away whatever the channel was doing and get it initialized */
340 ioat2_quiesce(chan, msecs_to_jiffies(100));
342 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
343 writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
345 return ioat2_reset_sync(chan, msecs_to_jiffies(200));
349 * ioat2_enumerate_channels - find and initialize the device's channels
350 * @device: the device to be enumerated
352 int ioat2_enumerate_channels(struct ioatdma_device *device)
354 struct ioat2_dma_chan *ioat;
355 struct device *dev = &device->pdev->dev;
356 struct dma_device *dma = &device->common;
360 INIT_LIST_HEAD(&dma->channels);
361 dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET);
362 dma->chancnt &= 0x1f; /* bits [4:0] valid */
363 if (dma->chancnt > ARRAY_SIZE(device->idx)) {
364 dev_warn(dev, "(%d) exceeds max supported channels (%zu)\n",
365 dma->chancnt, ARRAY_SIZE(device->idx));
366 dma->chancnt = ARRAY_SIZE(device->idx);
368 xfercap_log = readb(device->reg_base + IOAT_XFERCAP_OFFSET);
369 xfercap_log &= 0x1f; /* bits [4:0] valid */
370 if (xfercap_log == 0)
372 dev_dbg(dev, "%s: xfercap = %d\n", __func__, 1 << xfercap_log);
374 /* FIXME which i/oat version is i7300? */
375 #ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL
376 if (i7300_idle_platform_probe(NULL, NULL, 1) == 0)
379 for (i = 0; i < dma->chancnt; i++) {
380 ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL);
384 ioat_init_channel(device, &ioat->base, i);
385 ioat->xfercap_log = xfercap_log;
386 spin_lock_init(&ioat->prep_lock);
387 if (device->reset_hw(&ioat->base)) {
396 static dma_cookie_t ioat2_tx_submit_unlock(struct dma_async_tx_descriptor *tx)
398 struct dma_chan *c = tx->chan;
399 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
400 struct ioat_chan_common *chan = &ioat->base;
401 dma_cookie_t cookie = c->cookie;
408 dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie);
410 if (!test_and_set_bit(IOAT_COMPLETION_PENDING, &chan->state))
411 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
413 /* make descriptor updates visible before advancing ioat->head,
414 * this is purposefully not smp_wmb() since we are also
415 * publishing the descriptor updates to a dma device
419 ioat->head += ioat->produce;
421 ioat2_update_pending(ioat);
422 spin_unlock_bh(&ioat->prep_lock);
427 static struct ioat_ring_ent *ioat2_alloc_ring_ent(struct dma_chan *chan, gfp_t flags)
429 struct ioat_dma_descriptor *hw;
430 struct ioat_ring_ent *desc;
431 struct ioatdma_device *dma;
434 dma = to_ioatdma_device(chan->device);
435 hw = pci_pool_alloc(dma->dma_pool, flags, &phys);
438 memset(hw, 0, sizeof(*hw));
440 desc = kmem_cache_alloc(ioat2_cache, flags);
442 pci_pool_free(dma->dma_pool, hw, phys);
445 memset(desc, 0, sizeof(*desc));
447 dma_async_tx_descriptor_init(&desc->txd, chan);
448 desc->txd.tx_submit = ioat2_tx_submit_unlock;
450 desc->txd.phys = phys;
454 static void ioat2_free_ring_ent(struct ioat_ring_ent *desc, struct dma_chan *chan)
456 struct ioatdma_device *dma;
458 dma = to_ioatdma_device(chan->device);
459 pci_pool_free(dma->dma_pool, desc->hw, desc->txd.phys);
460 kmem_cache_free(ioat2_cache, desc);
463 static struct ioat_ring_ent **ioat2_alloc_ring(struct dma_chan *c, int order, gfp_t flags)
465 struct ioat_ring_ent **ring;
466 int descs = 1 << order;
469 if (order > ioat_get_max_alloc_order())
472 /* allocate the array to hold the software ring */
473 ring = kcalloc(descs, sizeof(*ring), flags);
476 for (i = 0; i < descs; i++) {
477 ring[i] = ioat2_alloc_ring_ent(c, flags);
480 ioat2_free_ring_ent(ring[i], c);
484 set_desc_id(ring[i], i);
488 for (i = 0; i < descs-1; i++) {
489 struct ioat_ring_ent *next = ring[i+1];
490 struct ioat_dma_descriptor *hw = ring[i]->hw;
492 hw->next = next->txd.phys;
494 ring[i]->hw->next = ring[0]->txd.phys;
499 void ioat2_free_chan_resources(struct dma_chan *c);
501 /* ioat2_alloc_chan_resources - allocate/initialize ioat2 descriptor ring
502 * @chan: channel to be initialized
504 int ioat2_alloc_chan_resources(struct dma_chan *c)
506 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
507 struct ioat_chan_common *chan = &ioat->base;
508 struct ioat_ring_ent **ring;
512 /* have we already been set up? */
514 return 1 << ioat->alloc_order;
516 /* Setup register to interrupt and write completion status on error */
517 writew(IOAT_CHANCTRL_RUN, chan->reg_base + IOAT_CHANCTRL_OFFSET);
519 /* allocate a completion writeback area */
520 /* doing 2 32bit writes to mmio since 1 64b write doesn't work */
521 chan->completion = pci_pool_alloc(chan->device->completion_pool,
522 GFP_KERNEL, &chan->completion_dma);
523 if (!chan->completion)
526 memset(chan->completion, 0, sizeof(*chan->completion));
527 writel(((u64) chan->completion_dma) & 0x00000000FFFFFFFF,
528 chan->reg_base + IOAT_CHANCMP_OFFSET_LOW);
529 writel(((u64) chan->completion_dma) >> 32,
530 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
532 order = ioat_get_alloc_order();
533 ring = ioat2_alloc_ring(c, order, GFP_KERNEL);
537 spin_lock_bh(&chan->cleanup_lock);
538 spin_lock_bh(&ioat->prep_lock);
543 ioat->alloc_order = order;
544 spin_unlock_bh(&ioat->prep_lock);
545 spin_unlock_bh(&chan->cleanup_lock);
547 tasklet_enable(&chan->cleanup_task);
548 ioat2_start_null_desc(ioat);
550 /* check that we got off the ground */
552 status = ioat_chansts(chan);
553 if (is_ioat_active(status) || is_ioat_idle(status)) {
554 set_bit(IOAT_RUN, &chan->state);
555 return 1 << ioat->alloc_order;
557 u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
559 dev_WARN(to_dev(chan),
560 "failed to start channel chanerr: %#x\n", chanerr);
561 ioat2_free_chan_resources(c);
566 bool reshape_ring(struct ioat2_dma_chan *ioat, int order)
568 /* reshape differs from normal ring allocation in that we want
569 * to allocate a new software ring while only
570 * extending/truncating the hardware ring
572 struct ioat_chan_common *chan = &ioat->base;
573 struct dma_chan *c = &chan->common;
574 const u16 curr_size = ioat2_ring_size(ioat);
575 const u16 active = ioat2_ring_active(ioat);
576 const u16 new_size = 1 << order;
577 struct ioat_ring_ent **ring;
580 if (order > ioat_get_max_alloc_order())
583 /* double check that we have at least 1 free descriptor */
584 if (active == curr_size)
587 /* when shrinking, verify that we can hold the current active
588 * set in the new ring
590 if (active >= new_size)
593 /* allocate the array to hold the software ring */
594 ring = kcalloc(new_size, sizeof(*ring), GFP_NOWAIT);
598 /* allocate/trim descriptors as needed */
599 if (new_size > curr_size) {
600 /* copy current descriptors to the new ring */
601 for (i = 0; i < curr_size; i++) {
602 u16 curr_idx = (ioat->tail+i) & (curr_size-1);
603 u16 new_idx = (ioat->tail+i) & (new_size-1);
605 ring[new_idx] = ioat->ring[curr_idx];
606 set_desc_id(ring[new_idx], new_idx);
609 /* add new descriptors to the ring */
610 for (i = curr_size; i < new_size; i++) {
611 u16 new_idx = (ioat->tail+i) & (new_size-1);
613 ring[new_idx] = ioat2_alloc_ring_ent(c, GFP_NOWAIT);
614 if (!ring[new_idx]) {
616 u16 new_idx = (ioat->tail+i) & (new_size-1);
618 ioat2_free_ring_ent(ring[new_idx], c);
623 set_desc_id(ring[new_idx], new_idx);
626 /* hw link new descriptors */
627 for (i = curr_size-1; i < new_size; i++) {
628 u16 new_idx = (ioat->tail+i) & (new_size-1);
629 struct ioat_ring_ent *next = ring[(new_idx+1) & (new_size-1)];
630 struct ioat_dma_descriptor *hw = ring[new_idx]->hw;
632 hw->next = next->txd.phys;
635 struct ioat_dma_descriptor *hw;
636 struct ioat_ring_ent *next;
638 /* copy current descriptors to the new ring, dropping the
639 * removed descriptors
641 for (i = 0; i < new_size; i++) {
642 u16 curr_idx = (ioat->tail+i) & (curr_size-1);
643 u16 new_idx = (ioat->tail+i) & (new_size-1);
645 ring[new_idx] = ioat->ring[curr_idx];
646 set_desc_id(ring[new_idx], new_idx);
649 /* free deleted descriptors */
650 for (i = new_size; i < curr_size; i++) {
651 struct ioat_ring_ent *ent;
653 ent = ioat2_get_ring_ent(ioat, ioat->tail+i);
654 ioat2_free_ring_ent(ent, c);
657 /* fix up hardware ring */
658 hw = ring[(ioat->tail+new_size-1) & (new_size-1)]->hw;
659 next = ring[(ioat->tail+new_size) & (new_size-1)];
660 hw->next = next->txd.phys;
663 dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n",
668 ioat->alloc_order = order;
674 * ioat2_check_space_lock - verify space and grab ring producer lock
675 * @ioat: ioat2,3 channel (ring) to operate on
676 * @num_descs: allocation length
678 int ioat2_check_space_lock(struct ioat2_dma_chan *ioat, int num_descs)
680 struct ioat_chan_common *chan = &ioat->base;
684 spin_lock_bh(&ioat->prep_lock);
685 /* never allow the last descriptor to be consumed, we need at
686 * least one free at all times to allow for on-the-fly ring
689 if (likely(ioat2_ring_space(ioat) > num_descs)) {
690 dev_dbg(to_dev(chan), "%s: num_descs: %d (%x:%x:%x)\n",
691 __func__, num_descs, ioat->head, ioat->tail, ioat->issued);
692 ioat->produce = num_descs;
693 return 0; /* with ioat->prep_lock held */
695 retry = test_and_set_bit(IOAT_RESHAPE_PENDING, &chan->state);
696 spin_unlock_bh(&ioat->prep_lock);
698 /* is another cpu already trying to expand the ring? */
702 spin_lock_bh(&chan->cleanup_lock);
703 spin_lock_bh(&ioat->prep_lock);
704 retry = reshape_ring(ioat, ioat->alloc_order + 1);
705 clear_bit(IOAT_RESHAPE_PENDING, &chan->state);
706 spin_unlock_bh(&ioat->prep_lock);
707 spin_unlock_bh(&chan->cleanup_lock);
709 /* if we were able to expand the ring retry the allocation */
713 if (printk_ratelimit())
714 dev_dbg(to_dev(chan), "%s: ring full! num_descs: %d (%x:%x:%x)\n",
715 __func__, num_descs, ioat->head, ioat->tail, ioat->issued);
717 /* progress reclaim in the allocation failure case we may be
718 * called under bh_disabled so we need to trigger the timer
721 if (jiffies > chan->timer.expires && timer_pending(&chan->timer)) {
722 struct ioatdma_device *device = chan->device;
724 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
725 device->timer_fn((unsigned long) &chan->common);
731 struct dma_async_tx_descriptor *
732 ioat2_dma_prep_memcpy_lock(struct dma_chan *c, dma_addr_t dma_dest,
733 dma_addr_t dma_src, size_t len, unsigned long flags)
735 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
736 struct ioat_dma_descriptor *hw;
737 struct ioat_ring_ent *desc;
738 dma_addr_t dst = dma_dest;
739 dma_addr_t src = dma_src;
740 size_t total_len = len;
741 int num_descs, idx, i;
743 num_descs = ioat2_xferlen_to_descs(ioat, len);
744 if (likely(num_descs) && ioat2_check_space_lock(ioat, num_descs) == 0)
750 size_t copy = min_t(size_t, len, 1 << ioat->xfercap_log);
752 desc = ioat2_get_ring_ent(ioat, idx + i);
763 dump_desc_dbg(ioat, desc);
764 } while (++i < num_descs);
766 desc->txd.flags = flags;
767 desc->len = total_len;
768 hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
769 hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
770 hw->ctl_f.compl_write = 1;
771 dump_desc_dbg(ioat, desc);
772 /* we leave the channel locked to ensure in order submission */
778 * ioat2_free_chan_resources - release all the descriptors
779 * @chan: the channel to be cleaned
781 void ioat2_free_chan_resources(struct dma_chan *c)
783 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
784 struct ioat_chan_common *chan = &ioat->base;
785 struct ioatdma_device *device = chan->device;
786 struct ioat_ring_ent *desc;
787 const u16 total_descs = 1 << ioat->alloc_order;
791 /* Before freeing channel resources first check
792 * if they have been previously allocated for this channel.
797 tasklet_disable(&chan->cleanup_task);
798 del_timer_sync(&chan->timer);
799 device->cleanup_fn((unsigned long) c);
800 device->reset_hw(chan);
801 clear_bit(IOAT_RUN, &chan->state);
803 spin_lock_bh(&chan->cleanup_lock);
804 spin_lock_bh(&ioat->prep_lock);
805 descs = ioat2_ring_space(ioat);
806 dev_dbg(to_dev(chan), "freeing %d idle descriptors\n", descs);
807 for (i = 0; i < descs; i++) {
808 desc = ioat2_get_ring_ent(ioat, ioat->head + i);
809 ioat2_free_ring_ent(desc, c);
812 if (descs < total_descs)
813 dev_err(to_dev(chan), "Freeing %d in use descriptors!\n",
814 total_descs - descs);
816 for (i = 0; i < total_descs - descs; i++) {
817 desc = ioat2_get_ring_ent(ioat, ioat->tail + i);
818 dump_desc_dbg(ioat, desc);
819 ioat2_free_ring_ent(desc, c);
824 ioat->alloc_order = 0;
825 pci_pool_free(device->completion_pool, chan->completion,
826 chan->completion_dma);
827 spin_unlock_bh(&ioat->prep_lock);
828 spin_unlock_bh(&chan->cleanup_lock);
830 chan->last_completion = 0;
831 chan->completion_dma = 0;
835 static ssize_t ring_size_show(struct dma_chan *c, char *page)
837 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
839 return sprintf(page, "%d\n", (1 << ioat->alloc_order) & ~1);
841 static struct ioat_sysfs_entry ring_size_attr = __ATTR_RO(ring_size);
843 static ssize_t ring_active_show(struct dma_chan *c, char *page)
845 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
847 /* ...taken outside the lock, no need to be precise */
848 return sprintf(page, "%d\n", ioat2_ring_active(ioat));
850 static struct ioat_sysfs_entry ring_active_attr = __ATTR_RO(ring_active);
852 static struct attribute *ioat2_attrs[] = {
853 &ring_size_attr.attr,
854 &ring_active_attr.attr,
856 &ioat_version_attr.attr,
860 struct kobj_type ioat2_ktype = {
861 .sysfs_ops = &ioat_sysfs_ops,
862 .default_attrs = ioat2_attrs,
865 int __devinit ioat2_dma_probe(struct ioatdma_device *device, int dca)
867 struct pci_dev *pdev = device->pdev;
868 struct dma_device *dma;
870 struct ioat_chan_common *chan;
873 device->enumerate_channels = ioat2_enumerate_channels;
874 device->reset_hw = ioat2_reset_hw;
875 device->cleanup_fn = ioat2_cleanup_event;
876 device->timer_fn = ioat2_timer_event;
877 device->self_test = ioat_dma_self_test;
878 dma = &device->common;
879 dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock;
880 dma->device_issue_pending = ioat2_issue_pending;
881 dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
882 dma->device_free_chan_resources = ioat2_free_chan_resources;
883 dma->device_tx_status = ioat_dma_tx_status;
885 err = ioat_probe(device);
888 ioat_set_tcp_copy_break(2048);
890 list_for_each_entry(c, &dma->channels, device_node) {
891 chan = to_chan_common(c);
892 writel(IOAT_DCACTRL_CMPL_WRITE_ENABLE | IOAT_DMA_DCA_ANY_CPU,
893 chan->reg_base + IOAT_DCACTRL_OFFSET);
896 err = ioat_register(device);
900 ioat_kobject_add(device, &ioat2_ktype);
903 device->dca = ioat2_dca_init(pdev, device->reg_base);