aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma/ioat/dma.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2009-08-26 16:01:44 -0400
committerDan Williams <dan.j.williams@intel.com>2009-09-08 20:29:55 -0400
commit5cbafa65b92ee4f5b8ba915cddf94b91f186b989 (patch)
treef074c9dbcdedf05c5567a4e456a15120895363a6 /drivers/dma/ioat/dma.c
parentdcbc853af6f0c056088e4df0794d9bf36184809e (diff)
ioat2,3: convert to a true ring buffer
Replace the current linked list munged into a ring with a native ring buffer implementation. The benefit of this approach is reduced overhead as many parameters can be derived from ring position with simple pointer comparisons and descriptor allocation/freeing becomes just a manipulation of head/tail pointers. It requires a contiguous allocation for the software descriptor information. Since this arrangement is significantly different from the ioat1 chain, move ioat2,3 support into its own file and header. Common routines are exported from driver/dma/ioat/dma.[ch]. Signed-off-by: Maciej Sosnowski <maciej.sosnowski@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/dma/ioat/dma.c')
-rw-r--r--drivers/dma/ioat/dma.c874
1 files changed, 194 insertions, 680 deletions
diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
index 2e81e0c76e61..64b4d75059aa 100644
--- a/drivers/dma/ioat/dma.c
+++ b/drivers/dma/ioat/dma.c
@@ -38,28 +38,14 @@
38#include "registers.h" 38#include "registers.h"
39#include "hw.h" 39#include "hw.h"
40 40
41static int ioat_pending_level = 4; 41int ioat_pending_level = 4;
42module_param(ioat_pending_level, int, 0644); 42module_param(ioat_pending_level, int, 0644);
43MODULE_PARM_DESC(ioat_pending_level, 43MODULE_PARM_DESC(ioat_pending_level,
44 "high-water mark for pushing ioat descriptors (default: 4)"); 44 "high-water mark for pushing ioat descriptors (default: 4)");
45 45
46static void ioat_dma_chan_reset_part2(struct work_struct *work);
47static void ioat_dma_chan_watchdog(struct work_struct *work);
48
49/* internal functions */ 46/* internal functions */
50static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat); 47static void ioat1_cleanup(struct ioat_dma_chan *ioat);
51static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat); 48static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat);
52
53static struct ioat_desc_sw *
54ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat);
55static struct ioat_desc_sw *
56ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat);
57
58static inline struct ioat_chan_common *
59ioat_chan_by_index(struct ioatdma_device *device, int index)
60{
61 return device->idx[index];
62}
63 49
64/** 50/**
65 * ioat_dma_do_interrupt - handler used for single vector interrupt mode 51 * ioat_dma_do_interrupt - handler used for single vector interrupt mode
@@ -108,18 +94,38 @@ static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)
108 return IRQ_HANDLED; 94 return IRQ_HANDLED;
109} 95}
110 96
111static void ioat_dma_cleanup_tasklet(unsigned long data); 97static 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,
102 work_func_t work_fn, void (*tasklet)(unsigned long),
103 unsigned long tasklet_data)
104{
105 struct dma_device *dma = &device->common;
106
107 chan->device = device;
108 chan->reg_base = device->reg_base + (0x80 * (idx + 1));
109 INIT_DELAYED_WORK(&chan->work, work_fn);
110 spin_lock_init(&chan->cleanup_lock);
111 chan->common.device = dma;
112 list_add_tail(&chan->common.device_node, &dma->channels);
113 device->idx[idx] = chan;
114 tasklet_init(&chan->cleanup_task, tasklet, tasklet_data);
115 tasklet_disable(&chan->cleanup_task);
116}
117
118static void ioat1_reset_part2(struct work_struct *work);
112 119
113/** 120/**
114 * ioat_dma_enumerate_channels - find and initialize the device's channels 121 * ioat1_dma_enumerate_channels - find and initialize the device's channels
115 * @device: the device to be enumerated 122 * @device: the device to be enumerated
116 */ 123 */
117static int ioat_dma_enumerate_channels(struct ioatdma_device *device) 124static int ioat1_enumerate_channels(struct ioatdma_device *device)
118{ 125{
119 u8 xfercap_scale; 126 u8 xfercap_scale;
120 u32 xfercap; 127 u32 xfercap;
121 int i; 128 int i;
122 struct ioat_chan_common *chan;
123 struct ioat_dma_chan *ioat; 129 struct ioat_dma_chan *ioat;
124 struct device *dev = &device->pdev->dev; 130 struct device *dev = &device->pdev->dev;
125 struct dma_device *dma = &device->common; 131 struct dma_device *dma = &device->common;
@@ -135,31 +141,20 @@ static int ioat_dma_enumerate_channels(struct ioatdma_device *device)
135#endif 141#endif
136 for (i = 0; i < dma->chancnt; i++) { 142 for (i = 0; i < dma->chancnt; i++) {
137 ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL); 143 ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL);
138 if (!ioat) { 144 if (!ioat)
139 dma->chancnt = i;
140 break; 145 break;
141 }
142 146
143 chan = &ioat->base; 147 ioat_init_channel(device, &ioat->base, i,
144 chan->device = device; 148 ioat1_reset_part2,
145 chan->reg_base = device->reg_base + (0x80 * (i + 1)); 149 ioat1_cleanup_tasklet,
150 (unsigned long) ioat);
146 ioat->xfercap = xfercap; 151 ioat->xfercap = xfercap;
147 ioat->desccount = 0;
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); 152 spin_lock_init(&ioat->desc_lock);
151 INIT_LIST_HEAD(&ioat->free_desc); 153 INIT_LIST_HEAD(&ioat->free_desc);
152 INIT_LIST_HEAD(&ioat->used_desc); 154 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);
161 } 155 }
162 return dma->chancnt; 156 dma->chancnt = i;
157 return i;
163} 158}
164 159
165/** 160/**
@@ -187,35 +182,16 @@ static void ioat1_dma_memcpy_issue_pending(struct dma_chan *chan)
187 } 182 }
188} 183}
189 184
190static inline void
191__ioat2_dma_memcpy_issue_pending(struct ioat_dma_chan *ioat)
192{
193 void __iomem *reg_base = ioat->base.reg_base;
194
195 ioat->pending = 0;
196 writew(ioat->dmacount, reg_base + IOAT_CHAN_DMACOUNT_OFFSET);
197}
198
199static void ioat2_dma_memcpy_issue_pending(struct dma_chan *chan)
200{
201 struct ioat_dma_chan *ioat = to_ioat_chan(chan);
202
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);
207 }
208}
209
210
211/** 185/**
212 * ioat_dma_chan_reset_part2 - reinit the channel after a reset 186 * ioat1_reset_part2 - reinit the channel after a reset
213 */ 187 */
214static void ioat_dma_chan_reset_part2(struct work_struct *work) 188static void ioat1_reset_part2(struct work_struct *work)
215{ 189{
216 struct ioat_chan_common *chan; 190 struct ioat_chan_common *chan;
217 struct ioat_dma_chan *ioat; 191 struct ioat_dma_chan *ioat;
218 struct ioat_desc_sw *desc; 192 struct ioat_desc_sw *desc;
193 int dmacount;
194 bool start_null = false;
219 195
220 chan = container_of(work, struct ioat_chan_common, work.work); 196 chan = container_of(work, struct ioat_chan_common, work.work);
221 ioat = container_of(chan, struct ioat_dma_chan, base); 197 ioat = container_of(chan, struct ioat_dma_chan, base);
@@ -226,26 +202,22 @@ static void ioat_dma_chan_reset_part2(struct work_struct *work)
226 chan->completion_virt->high = 0; 202 chan->completion_virt->high = 0;
227 ioat->pending = 0; 203 ioat->pending = 0;
228 204
229 /* 205 /* count the descriptors waiting */
230 * count the descriptors waiting, and be sure to do it 206 dmacount = 0;
231 * right for both the CB1 line and the CB2 ring
232 */
233 ioat->dmacount = 0;
234 if (ioat->used_desc.prev) { 207 if (ioat->used_desc.prev) {
235 desc = to_ioat_desc(ioat->used_desc.prev); 208 desc = to_ioat_desc(ioat->used_desc.prev);
236 do { 209 do {
237 ioat->dmacount++; 210 dmacount++;
238 desc = to_ioat_desc(desc->node.next); 211 desc = to_ioat_desc(desc->node.next);
239 } while (&desc->node != ioat->used_desc.next); 212 } while (&desc->node != ioat->used_desc.next);
240 } 213 }
241 214
242 /* 215 if (dmacount) {
243 * write the new starting descriptor address 216 /*
244 * this puts channel engine into ARMED state 217 * write the new starting descriptor address
245 */ 218 * this puts channel engine into ARMED state
246 desc = to_ioat_desc(ioat->used_desc.prev); 219 */
247 switch (chan->device->version) { 220 desc = to_ioat_desc(ioat->used_desc.prev);
248 case IOAT_VER_1_2:
249 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF, 221 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF,
250 chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW); 222 chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW);
251 writel(((u64) desc->txd.phys) >> 32, 223 writel(((u64) desc->txd.phys) >> 32,
@@ -253,32 +225,24 @@ static void ioat_dma_chan_reset_part2(struct work_struct *work)
253 225
254 writeb(IOAT_CHANCMD_START, chan->reg_base 226 writeb(IOAT_CHANCMD_START, chan->reg_base
255 + IOAT_CHANCMD_OFFSET(chan->device->version)); 227 + IOAT_CHANCMD_OFFSET(chan->device->version));
256 break; 228 } else
257 case IOAT_VER_2_0: 229 start_null = true;
258 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF, 230 spin_unlock_bh(&ioat->desc_lock);
259 chan->reg_base + IOAT2_CHAINADDR_OFFSET_LOW); 231 spin_unlock_bh(&chan->cleanup_lock);
260 writel(((u64) desc->txd.phys) >> 32,
261 chan->reg_base + IOAT2_CHAINADDR_OFFSET_HIGH);
262
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);
266 232
267 break;
268 }
269 dev_err(to_dev(chan), 233 dev_err(to_dev(chan),
270 "chan%d reset - %d descs waiting, %d total desc\n", 234 "chan%d reset - %d descs waiting, %d total desc\n",
271 chan_num(chan), ioat->dmacount, ioat->desccount); 235 chan_num(chan), dmacount, ioat->desccount);
272 236
273 spin_unlock_bh(&ioat->desc_lock); 237 if (start_null)
274 spin_unlock_bh(&chan->cleanup_lock); 238 ioat1_dma_start_null_desc(ioat);
275} 239}
276 240
277/** 241/**
278 * ioat_dma_reset_channel - restart a channel 242 * ioat1_reset_channel - restart a channel
279 * @ioat: IOAT DMA channel handle 243 * @ioat: IOAT DMA channel handle
280 */ 244 */
281static void ioat_dma_reset_channel(struct ioat_dma_chan *ioat) 245static void ioat1_reset_channel(struct ioat_dma_chan *ioat)
282{ 246{
283 struct ioat_chan_common *chan = &ioat->base; 247 struct ioat_chan_common *chan = &ioat->base;
284 void __iomem *reg_base = chan->reg_base; 248 void __iomem *reg_base = chan->reg_base;
@@ -316,9 +280,9 @@ static void ioat_dma_reset_channel(struct ioat_dma_chan *ioat)
316} 280}
317 281
318/** 282/**
319 * ioat_dma_chan_watchdog - watch for stuck channels 283 * ioat1_chan_watchdog - watch for stuck channels
320 */ 284 */
321static void ioat_dma_chan_watchdog(struct work_struct *work) 285static void ioat1_chan_watchdog(struct work_struct *work)
322{ 286{
323 struct ioatdma_device *device = 287 struct ioatdma_device *device =
324 container_of(work, struct ioatdma_device, work.work); 288 container_of(work, struct ioatdma_device, work.work);
@@ -339,16 +303,15 @@ static void ioat_dma_chan_watchdog(struct work_struct *work)
339 chan = ioat_chan_by_index(device, i); 303 chan = ioat_chan_by_index(device, i);
340 ioat = container_of(chan, struct ioat_dma_chan, base); 304 ioat = container_of(chan, struct ioat_dma_chan, base);
341 305
342 if (chan->device->version == IOAT_VER_1_2 306 if (/* have we started processing anything yet */
343 /* have we started processing anything yet */ 307 chan->last_completion
344 && chan->last_completion 308 /* have we completed any since last watchdog cycle? */
345 /* have we completed any since last watchdog cycle? */
346 && (chan->last_completion == chan->watchdog_completion) 309 && (chan->last_completion == chan->watchdog_completion)
347 /* has TCP stuck on one cookie since last watchdog? */ 310 /* has TCP stuck on one cookie since last watchdog? */
348 && (chan->watchdog_tcp_cookie == chan->watchdog_last_tcp_cookie) 311 && (chan->watchdog_tcp_cookie == chan->watchdog_last_tcp_cookie)
349 && (chan->watchdog_tcp_cookie != chan->completed_cookie) 312 && (chan->watchdog_tcp_cookie != chan->completed_cookie)
350 /* is there something in the chain to be processed? */ 313 /* is there something in the chain to be processed? */
351 /* CB1 chain always has at least the last one processed */ 314 /* CB1 chain always has at least the last one processed */
352 && (ioat->used_desc.prev != ioat->used_desc.next) 315 && (ioat->used_desc.prev != ioat->used_desc.next)
353 && ioat->pending == 0) { 316 && ioat->pending == 0) {
354 317
@@ -387,34 +350,15 @@ static void ioat_dma_chan_watchdog(struct work_struct *work)
387 chan->completion_virt->low = completion_hw.low; 350 chan->completion_virt->low = completion_hw.low;
388 chan->completion_virt->high = completion_hw.high; 351 chan->completion_virt->high = completion_hw.high;
389 } else { 352 } else {
390 ioat_dma_reset_channel(ioat); 353 ioat1_reset_channel(ioat);
391 chan->watchdog_completion = 0; 354 chan->watchdog_completion = 0;
392 chan->last_compl_desc_addr_hw = 0; 355 chan->last_compl_desc_addr_hw = 0;
393 } 356 }
394
395 /*
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
400 * else
401 * try resetting the channel
402 */
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) {
407
408 if (ioat->pending < ioat_pending_level)
409 ioat2_dma_memcpy_issue_pending(&chan->common);
410 else {
411 ioat_dma_reset_channel(ioat);
412 chan->watchdog_completion = 0;
413 }
414 } else { 357 } else {
415 chan->last_compl_desc_addr_hw = 0; 358 chan->last_compl_desc_addr_hw = 0;
416 chan->watchdog_completion = chan->last_completion; 359 chan->watchdog_completion = chan->last_completion;
417 } 360 }
361
418 chan->watchdog_last_tcp_cookie = chan->watchdog_tcp_cookie; 362 chan->watchdog_last_tcp_cookie = chan->watchdog_tcp_cookie;
419 } 363 }
420 364
@@ -447,7 +391,6 @@ static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
447 chain_tail->hw->next = first->txd.phys; 391 chain_tail->hw->next = first->txd.phys;
448 list_splice_tail_init(&tx->tx_list, &ioat->used_desc); 392 list_splice_tail_init(&tx->tx_list, &ioat->used_desc);
449 393
450 ioat->dmacount += desc->tx_cnt;
451 ioat->pending += desc->tx_cnt; 394 ioat->pending += desc->tx_cnt;
452 if (ioat->pending >= ioat_pending_level) 395 if (ioat->pending >= ioat_pending_level)
453 __ioat1_dma_memcpy_issue_pending(ioat); 396 __ioat1_dma_memcpy_issue_pending(ioat);
@@ -456,92 +399,6 @@ static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
456 return cookie; 399 return cookie;
457} 400}
458 401
459static dma_cookie_t ioat2_tx_submit(struct dma_async_tx_descriptor *tx)
460{
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;
465 dma_cookie_t cookie;
466 u32 copy;
467 size_t len;
468 dma_addr_t src, dst;
469 unsigned long orig_flags;
470 unsigned int desc_count = 0;
471
472 /* src and dest and len are stored in the initial descriptor */
473 len = first->len;
474 src = first->src;
475 dst = first->dst;
476 orig_flags = first->txd.flags;
477 new = first;
478
479 /*
480 * ioat->desc_lock is still in force in version 2 path
481 * it gets unlocked at end of this function
482 */
483 do {
484 copy = min_t(size_t, len, ioat->xfercap);
485
486 async_tx_ack(&new->txd);
487
488 hw = new->hw;
489 hw->size = copy;
490 hw->ctl = 0;
491 hw->src_addr = src;
492 hw->dst_addr = dst;
493
494 len -= copy;
495 dst += copy;
496 src += copy;
497 desc_count++;
498 } while (len && (new = ioat2_dma_get_next_descriptor(ioat)));
499
500 if (!new) {
501 dev_err(to_dev(&ioat->base), "tx submit failed\n");
502 spin_unlock_bh(&ioat->desc_lock);
503 return -ENOMEM;
504 }
505
506 hw->ctl_f.compl_write = 1;
507 if (first->txd.callback) {
508 hw->ctl_f.int_en = 1;
509 if (first != new) {
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;
516 }
517 }
518
519 new->tx_cnt = desc_count;
520 new->txd.flags = orig_flags; /* client is in control of this ack */
521
522 /* store the original values for use in later cleanup */
523 if (new != first) {
524 new->src = first->src;
525 new->dst = first->dst;
526 new->len = first->len;
527 }
528
529 /* cookie incr and addition to used_list must be atomic */
530 cookie = ioat->base.common.cookie;
531 cookie++;
532 if (cookie < 0)
533 cookie = 1;
534 ioat->base.common.cookie = new->txd.cookie = cookie;
535
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);
541
542 return cookie;
543}
544
545/** 402/**
546 * ioat_dma_alloc_descriptor - allocate and return a sw and hw descriptor pair 403 * ioat_dma_alloc_descriptor - allocate and return a sw and hw descriptor pair
547 * @ioat: the channel supplying the memory pool for the descriptors 404 * @ioat: the channel supplying the memory pool for the descriptors
@@ -567,17 +424,9 @@ ioat_dma_alloc_descriptor(struct ioat_dma_chan *ioat, gfp_t flags)
567 } 424 }
568 425
569 memset(desc, 0, sizeof(*desc)); 426 memset(desc, 0, sizeof(*desc));
570 dma_async_tx_descriptor_init(&desc_sw->txd, &ioat->base.common);
571 switch (ioatdma_device->version) {
572 case IOAT_VER_1_2:
573 desc_sw->txd.tx_submit = ioat1_tx_submit;
574 break;
575 case IOAT_VER_2_0:
576 case IOAT_VER_3_0:
577 desc_sw->txd.tx_submit = ioat2_tx_submit;
578 break;
579 }
580 427
428 dma_async_tx_descriptor_init(&desc_sw->txd, &ioat->base.common);
429 desc_sw->txd.tx_submit = ioat1_tx_submit;
581 desc_sw->hw = desc; 430 desc_sw->hw = desc;
582 desc_sw->txd.phys = phys; 431 desc_sw->txd.phys = phys;
583 432
@@ -587,39 +436,12 @@ ioat_dma_alloc_descriptor(struct ioat_dma_chan *ioat, gfp_t flags)
587static int ioat_initial_desc_count = 256; 436static int ioat_initial_desc_count = 256;
588module_param(ioat_initial_desc_count, int, 0644); 437module_param(ioat_initial_desc_count, int, 0644);
589MODULE_PARM_DESC(ioat_initial_desc_count, 438MODULE_PARM_DESC(ioat_initial_desc_count,
590 "initial descriptors per channel (default: 256)"); 439 "ioat1: initial descriptors per channel (default: 256)");
591
592/**
593 * ioat2_dma_massage_chan_desc - link the descriptors into a circle
594 * @ioat: the channel to be massaged
595 */
596static void ioat2_dma_massage_chan_desc(struct ioat_dma_chan *ioat)
597{
598 struct ioat_desc_sw *desc, *_desc;
599
600 /* setup used_desc */
601 ioat->used_desc.next = ioat->free_desc.next;
602 ioat->used_desc.prev = NULL;
603
604 /* pull free_desc out of the circle so that every node is a hw
605 * descriptor, but leave it pointing to the list
606 */
607 ioat->free_desc.prev->next = ioat->free_desc.next;
608 ioat->free_desc.next->prev = ioat->free_desc.prev;
609
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;
615 }
616}
617
618/** 440/**
619 * ioat_dma_alloc_chan_resources - returns the number of allocated descriptors 441 * ioat1_dma_alloc_chan_resources - returns the number of allocated descriptors
620 * @chan: the channel to be filled out 442 * @chan: the channel to be filled out
621 */ 443 */
622static int ioat_dma_alloc_chan_resources(struct dma_chan *c) 444static int ioat1_dma_alloc_chan_resources(struct dma_chan *c)
623{ 445{
624 struct ioat_dma_chan *ioat = to_ioat_chan(c); 446 struct ioat_dma_chan *ioat = to_ioat_chan(c);
625 struct ioat_chan_common *chan = &ioat->base; 447 struct ioat_chan_common *chan = &ioat->base;
@@ -657,8 +479,6 @@ static int ioat_dma_alloc_chan_resources(struct dma_chan *c)
657 spin_lock_bh(&ioat->desc_lock); 479 spin_lock_bh(&ioat->desc_lock);
658 ioat->desccount = i; 480 ioat->desccount = i;
659 list_splice(&tmp_list, &ioat->free_desc); 481 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); 482 spin_unlock_bh(&ioat->desc_lock);
663 483
664 /* allocate a completion writeback area */ 484 /* allocate a completion writeback area */
@@ -674,15 +494,15 @@ static int ioat_dma_alloc_chan_resources(struct dma_chan *c)
674 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH); 494 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
675 495
676 tasklet_enable(&chan->cleanup_task); 496 tasklet_enable(&chan->cleanup_task);
677 ioat_dma_start_null_desc(ioat); /* give chain to dma device */ 497 ioat1_dma_start_null_desc(ioat); /* give chain to dma device */
678 return ioat->desccount; 498 return ioat->desccount;
679} 499}
680 500
681/** 501/**
682 * ioat_dma_free_chan_resources - release all the descriptors 502 * ioat1_dma_free_chan_resources - release all the descriptors
683 * @chan: the channel to be cleaned 503 * @chan: the channel to be cleaned
684 */ 504 */
685static void ioat_dma_free_chan_resources(struct dma_chan *c) 505static void ioat1_dma_free_chan_resources(struct dma_chan *c)
686{ 506{
687 struct ioat_dma_chan *ioat = to_ioat_chan(c); 507 struct ioat_dma_chan *ioat = to_ioat_chan(c);
688 struct ioat_chan_common *chan = &ioat->base; 508 struct ioat_chan_common *chan = &ioat->base;
@@ -697,7 +517,7 @@ static void ioat_dma_free_chan_resources(struct dma_chan *c)
697 return; 517 return;
698 518
699 tasklet_disable(&chan->cleanup_task); 519 tasklet_disable(&chan->cleanup_task);
700 ioat_dma_memcpy_cleanup(ioat); 520 ioat1_cleanup(ioat);
701 521
702 /* Delay 100ms after reset to allow internal DMA logic to quiesce 522 /* Delay 100ms after reset to allow internal DMA logic to quiesce
703 * before removing DMA descriptor resources. 523 * before removing DMA descriptor resources.
@@ -707,40 +527,20 @@ static void ioat_dma_free_chan_resources(struct dma_chan *c)
707 mdelay(100); 527 mdelay(100);
708 528
709 spin_lock_bh(&ioat->desc_lock); 529 spin_lock_bh(&ioat->desc_lock);
710 switch (chan->device->version) { 530 list_for_each_entry_safe(desc, _desc,
711 case IOAT_VER_1_2: 531 &ioat->used_desc, node) {
712 list_for_each_entry_safe(desc, _desc, 532 in_use_descs++;
713 &ioat->used_desc, node) { 533 list_del(&desc->node);
714 in_use_descs++; 534 pci_pool_free(ioatdma_device->dma_pool, desc->hw,
715 list_del(&desc->node); 535 desc->txd.phys);
716 pci_pool_free(ioatdma_device->dma_pool, desc->hw, 536 kfree(desc);
717 desc->txd.phys); 537 }
718 kfree(desc); 538 list_for_each_entry_safe(desc, _desc,
719 } 539 &ioat->free_desc, node) {
720 list_for_each_entry_safe(desc, _desc, 540 list_del(&desc->node);
721 &ioat->free_desc, node) {
722 list_del(&desc->node);
723 pci_pool_free(ioatdma_device->dma_pool, desc->hw,
724 desc->txd.phys);
725 kfree(desc);
726 }
727 break;
728 case IOAT_VER_2_0:
729 case IOAT_VER_3_0:
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,
734 desc->txd.phys);
735 kfree(desc);
736 }
737 desc = to_ioat_desc(ioat->free_desc.next);
738 pci_pool_free(ioatdma_device->dma_pool, desc->hw, 541 pci_pool_free(ioatdma_device->dma_pool, desc->hw,
739 desc->txd.phys); 542 desc->txd.phys);
740 kfree(desc); 543 kfree(desc);
741 INIT_LIST_HEAD(&ioat->free_desc);
742 INIT_LIST_HEAD(&ioat->used_desc);
743 break;
744 } 544 }
745 spin_unlock_bh(&ioat->desc_lock); 545 spin_unlock_bh(&ioat->desc_lock);
746 546
@@ -758,7 +558,6 @@ static void ioat_dma_free_chan_resources(struct dma_chan *c)
758 chan->last_compl_desc_addr_hw = 0; 558 chan->last_compl_desc_addr_hw = 0;
759 chan->watchdog_tcp_cookie = chan->watchdog_last_tcp_cookie = 0; 559 chan->watchdog_tcp_cookie = chan->watchdog_last_tcp_cookie = 0;
760 ioat->pending = 0; 560 ioat->pending = 0;
761 ioat->dmacount = 0;
762 ioat->desccount = 0; 561 ioat->desccount = 0;
763} 562}
764 563
@@ -791,86 +590,6 @@ ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat)
791 return new; 590 return new;
792} 591}
793 592
794static struct ioat_desc_sw *
795ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat)
796{
797 struct ioat_desc_sw *new;
798
799 /*
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
807 */
808 if (ioat->used_desc.prev &&
809 ioat->used_desc.next == ioat->used_desc.prev->prev) {
810
811 struct ioat_desc_sw *desc;
812 struct ioat_desc_sw *noop_desc;
813 int i;
814
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;
823
824 ioat->used_desc.next = ioat->used_desc.next->next;
825 ioat->pending++;
826 ioat->dmacount++;
827
828 /* try to get a few more descriptors */
829 for (i = 16; i; i--) {
830 desc = ioat_dma_alloc_descriptor(ioat, GFP_ATOMIC);
831 if (!desc) {
832 dev_err(to_dev(&ioat->base),
833 "alloc failed\n");
834 break;
835 }
836 list_add_tail(&desc->node, ioat->used_desc.next);
837
838 desc->hw->next
839 = to_ioat_desc(desc->node.next)->txd.phys;
840 to_ioat_desc(desc->node.prev)->hw->next
841 = desc->txd.phys;
842 ioat->desccount++;
843 }
844
845 ioat->used_desc.next = noop_desc->node.next;
846 }
847 new = to_ioat_desc(ioat->used_desc.next);
848 prefetch(new);
849 ioat->used_desc.next = new->node.next;
850
851 if (ioat->used_desc.prev == NULL)
852 ioat->used_desc.prev = &new->node;
853
854 prefetch(new->hw);
855 return new;
856}
857
858static struct ioat_desc_sw *
859ioat_dma_get_next_descriptor(struct ioat_dma_chan *ioat)
860{
861 if (!ioat)
862 return NULL;
863
864 switch (ioat->base.device->version) {
865 case IOAT_VER_1_2:
866 return ioat1_dma_get_next_descriptor(ioat);
867 case IOAT_VER_2_0:
868 case IOAT_VER_3_0:
869 return ioat2_dma_get_next_descriptor(ioat);
870 }
871 return NULL;
872}
873
874static struct dma_async_tx_descriptor * 593static struct dma_async_tx_descriptor *
875ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest, 594ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
876 dma_addr_t dma_src, size_t len, unsigned long flags) 595 dma_addr_t dma_src, size_t len, unsigned long flags)
@@ -886,7 +605,7 @@ ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
886 int tx_cnt = 0; 605 int tx_cnt = 0;
887 606
888 spin_lock_bh(&ioat->desc_lock); 607 spin_lock_bh(&ioat->desc_lock);
889 desc = ioat_dma_get_next_descriptor(ioat); 608 desc = ioat1_dma_get_next_descriptor(ioat);
890 do { 609 do {
891 if (!desc) 610 if (!desc)
892 break; 611 break;
@@ -909,7 +628,7 @@ ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
909 struct ioat_desc_sw *next; 628 struct ioat_desc_sw *next;
910 629
911 async_tx_ack(&desc->txd); 630 async_tx_ack(&desc->txd);
912 next = ioat_dma_get_next_descriptor(ioat); 631 next = ioat1_dma_get_next_descriptor(ioat);
913 hw->next = next ? next->txd.phys : 0; 632 hw->next = next ? next->txd.phys : 0;
914 desc = next; 633 desc = next;
915 } else 634 } else
@@ -920,8 +639,7 @@ ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
920 struct ioat_chan_common *chan = &ioat->base; 639 struct ioat_chan_common *chan = &ioat->base;
921 640
922 dev_err(to_dev(chan), 641 dev_err(to_dev(chan),
923 "chan%d - get_next_desc failed: %d descs waiting, %d total desc\n", 642 "chan%d - get_next_desc failed\n", chan_num(chan));
924 chan_num(chan), ioat->dmacount, ioat->desccount);
925 list_splice(&chain, &ioat->free_desc); 643 list_splice(&chain, &ioat->free_desc);
926 spin_unlock_bh(&ioat->desc_lock); 644 spin_unlock_bh(&ioat->desc_lock);
927 return NULL; 645 return NULL;
@@ -940,94 +658,43 @@ ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
940 return &desc->txd; 658 return &desc->txd;
941} 659}
942 660
943static struct dma_async_tx_descriptor * 661static void ioat1_cleanup_tasklet(unsigned long data)
944ioat2_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
945 dma_addr_t dma_src, size_t len, unsigned long flags)
946{
947 struct ioat_dma_chan *ioat = to_ioat_chan(c);
948 struct ioat_desc_sw *new;
949
950 spin_lock_bh(&ioat->desc_lock);
951 new = ioat2_dma_get_next_descriptor(ioat);
952
953 /*
954 * leave ioat->desc_lock set in ioat 2 path
955 * it will get unlocked at end of tx_submit
956 */
957
958 if (new) {
959 new->len = len;
960 new->dst = dma_dest;
961 new->src = dma_src;
962 new->txd.flags = flags;
963 return &new->txd;
964 } else {
965 struct ioat_chan_common *chan = &ioat->base;
966
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);
971 return NULL;
972 }
973}
974
975static void ioat_dma_cleanup_tasklet(unsigned long data)
976{ 662{
977 struct ioat_dma_chan *chan = (void *)data; 663 struct ioat_dma_chan *chan = (void *)data;
978 ioat_dma_memcpy_cleanup(chan); 664 ioat1_cleanup(chan);
979 writew(IOAT_CHANCTRL_INT_DISABLE, 665 writew(IOAT_CHANCTRL_INT_DISABLE,
980 chan->base.reg_base + IOAT_CHANCTRL_OFFSET); 666 chan->base.reg_base + IOAT_CHANCTRL_OFFSET);
981} 667}
982 668
983static void 669static void ioat_unmap(struct pci_dev *pdev, dma_addr_t addr, size_t len,
984ioat_dma_unmap(struct ioat_chan_common *chan, struct ioat_desc_sw *desc) 670 int direction, enum dma_ctrl_flags flags, bool dst)
985{ 671{
986 if (!(desc->txd.flags & DMA_COMPL_SKIP_DEST_UNMAP)) { 672 if ((dst && (flags & DMA_COMPL_DEST_UNMAP_SINGLE)) ||
987 if (desc->txd.flags & DMA_COMPL_DEST_UNMAP_SINGLE) 673 (!dst && (flags & DMA_COMPL_SRC_UNMAP_SINGLE)))
988 pci_unmap_single(chan->device->pdev, 674 pci_unmap_single(pdev, addr, len, direction);
989 pci_unmap_addr(desc, dst), 675 else
990 pci_unmap_len(desc, len), 676 pci_unmap_page(pdev, addr, len, direction);
991 PCI_DMA_FROMDEVICE);
992 else
993 pci_unmap_page(chan->device->pdev,
994 pci_unmap_addr(desc, dst),
995 pci_unmap_len(desc, len),
996 PCI_DMA_FROMDEVICE);
997 }
998
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),
1004 PCI_DMA_TODEVICE);
1005 else
1006 pci_unmap_page(chan->device->pdev,
1007 pci_unmap_addr(desc, src),
1008 pci_unmap_len(desc, len),
1009 PCI_DMA_TODEVICE);
1010 }
1011} 677}
1012 678
1013/** 679
1014 * ioat_dma_memcpy_cleanup - cleanup up finished descriptors 680void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
1015 * @chan: ioat channel to be cleaned up 681 size_t len, struct ioat_dma_descriptor *hw)
1016 */
1017static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat)
1018{ 682{
1019 struct ioat_chan_common *chan = &ioat->base; 683 struct pci_dev *pdev = chan->device->pdev;
1020 unsigned long phys_complete; 684 size_t offset = len - hw->size;
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;
1026 685
1027 prefetch(chan->completion_virt); 686 if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
687 ioat_unmap(pdev, hw->dst_addr - offset, len,
688 PCI_DMA_FROMDEVICE, flags, 1);
1028 689
1029 if (!spin_trylock_bh(&chan->cleanup_lock)) 690 if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP))
1030 return; 691 ioat_unmap(pdev, hw->src_addr - offset, len,
692 PCI_DMA_TODEVICE, flags, 0);
693}
694
695unsigned long ioat_get_current_completion(struct ioat_chan_common *chan)
696{
697 unsigned long phys_complete;
1031 698
1032 /* The completion writeback can happen at any time, 699 /* The completion writeback can happen at any time,
1033 so reads by the driver need to be atomic operations 700 so reads by the driver need to be atomic operations
@@ -1051,18 +718,37 @@ static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat)
1051 /* TODO do something to salvage the situation */ 718 /* TODO do something to salvage the situation */
1052 } 719 }
1053 720
721 return phys_complete;
722}
723
724/**
725 * ioat1_cleanup - cleanup up finished descriptors
726 * @chan: ioat channel to be cleaned up
727 */
728static void ioat1_cleanup(struct ioat_dma_chan *ioat)
729{
730 struct ioat_chan_common *chan = &ioat->base;
731 unsigned long phys_complete;
732 struct ioat_desc_sw *desc, *_desc;
733 dma_cookie_t cookie = 0;
734 struct dma_async_tx_descriptor *tx;
735
736 prefetch(chan->completion_virt);
737
738 if (!spin_trylock_bh(&chan->cleanup_lock))
739 return;
740
741 phys_complete = ioat_get_current_completion(chan);
1054 if (phys_complete == chan->last_completion) { 742 if (phys_complete == chan->last_completion) {
1055 spin_unlock_bh(&chan->cleanup_lock); 743 spin_unlock_bh(&chan->cleanup_lock);
1056 /* 744 /*
1057 * perhaps we're stuck so hard that the watchdog can't go off? 745 * perhaps we're stuck so hard that the watchdog can't go off?
1058 * try to catch it after 2 seconds 746 * try to catch it after 2 seconds
1059 */ 747 */
1060 if (chan->device->version != IOAT_VER_3_0) { 748 if (time_after(jiffies,
1061 if (time_after(jiffies, 749 chan->last_completion_time + HZ*WATCHDOG_DELAY)) {
1062 chan->last_completion_time + HZ*WATCHDOG_DELAY)) { 750 ioat1_chan_watchdog(&(chan->device->work.work));
1063 ioat_dma_chan_watchdog(&(chan->device->work.work)); 751 chan->last_completion_time = jiffies;
1064 chan->last_completion_time = jiffies;
1065 }
1066 } 752 }
1067 return; 753 return;
1068 } 754 }
@@ -1074,91 +760,42 @@ static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat)
1074 return; 760 return;
1075 } 761 }
1076 762
1077 switch (chan->device->version) { 763 list_for_each_entry_safe(desc, _desc, &ioat->used_desc, node) {
1078 case IOAT_VER_1_2: 764 tx = &desc->txd;
1079 list_for_each_entry_safe(desc, _desc, &ioat->used_desc, node) { 765 /*
1080 tx = &desc->txd; 766 * Incoming DMA requests may use multiple descriptors,
1081 /* 767 * due to exceeding xfercap, perhaps. If so, only the
1082 * Incoming DMA requests may use multiple descriptors, 768 * last one will have a cookie, and require unmapping.
1083 * due to exceeding xfercap, perhaps. If so, only the 769 */
1084 * last one will have a cookie, and require unmapping. 770 if (tx->cookie) {
1085 */ 771 cookie = tx->cookie;
1086 if (tx->cookie) { 772 ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
1087 cookie = tx->cookie; 773 if (tx->callback) {
1088 ioat_dma_unmap(chan, desc); 774 tx->callback(tx->callback_param);
1089 if (tx->callback) { 775 tx->callback = NULL;
1090 tx->callback(tx->callback_param);
1091 tx->callback = NULL;
1092 }
1093 } 776 }
777 }
1094 778
1095 if (tx->phys != phys_complete) { 779 if (tx->phys != phys_complete) {
1096 /* 780 /*
1097 * a completed entry, but not the last, so clean 781 * a completed entry, but not the last, so clean
1098 * up if the client is done with the descriptor 782 * up if the client is done with the descriptor
1099 */ 783 */
1100 if (async_tx_test_ack(tx)) { 784 if (async_tx_test_ack(tx))
1101 list_move_tail(&desc->node, 785 list_move_tail(&desc->node, &ioat->free_desc);
1102 &ioat->free_desc); 786 else
1103 } else
1104 tx->cookie = 0;
1105 } else {
1106 /*
1107 * last used desc. Do not remove, so we can
1108 * append from it, but don't look at it next
1109 * time, either
1110 */
1111 tx->cookie = 0; 787 tx->cookie = 0;
788 } else {
789 /*
790 * last used desc. Do not remove, so we can
791 * append from it, but don't look at it next
792 * time, either
793 */
794 tx->cookie = 0;
1112 795
1113 /* TODO check status bits? */ 796 /* TODO check status bits? */
1114 break;
1115 }
1116 }
1117 break;
1118 case IOAT_VER_2_0:
1119 case IOAT_VER_3_0:
1120 /* has some other thread has already cleaned up? */
1121 if (ioat->used_desc.prev == NULL)
1122 break; 797 break;
1123
1124 /* work backwards to find latest finished desc */
1125 desc = to_ioat_desc(ioat->used_desc.next);
1126 tx = &desc->txd;
1127 latest_desc = NULL;
1128 do {
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) {
1133 latest_desc = desc;
1134 break;
1135 }
1136 } while (&desc->node != ioat->used_desc.prev);
1137
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)) {
1144 if (tx->cookie) {
1145 cookie = tx->cookie;
1146 tx->cookie = 0;
1147 ioat_dma_unmap(chan, desc);
1148 if (tx->callback) {
1149 tx->callback(tx->callback_param);
1150 tx->callback = NULL;
1151 }
1152 }
1153 }
1154
1155 /* move used.prev up beyond those that are finished */
1156 if (&desc->node == ioat->used_desc.next)
1157 ioat->used_desc.prev = NULL;
1158 else
1159 ioat->used_desc.prev = &desc->node;
1160 } 798 }
1161 break;
1162 } 799 }
1163 800
1164 spin_unlock_bh(&ioat->desc_lock); 801 spin_unlock_bh(&ioat->desc_lock);
@@ -1170,50 +807,21 @@ static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat)
1170 spin_unlock_bh(&chan->cleanup_lock); 807 spin_unlock_bh(&chan->cleanup_lock);
1171} 808}
1172 809
1173/**
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
1179 */
1180static enum dma_status 810static enum dma_status
1181ioat_dma_is_complete(struct dma_chan *c, dma_cookie_t cookie, 811ioat1_dma_is_complete(struct dma_chan *c, dma_cookie_t cookie,
1182 dma_cookie_t *done, dma_cookie_t *used) 812 dma_cookie_t *done, dma_cookie_t *used)
1183{ 813{
1184 struct ioat_dma_chan *ioat = to_ioat_chan(c); 814 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;
1189
1190 last_used = c->cookie;
1191 last_complete = chan->completed_cookie;
1192 chan->watchdog_tcp_cookie = cookie;
1193
1194 if (done)
1195 *done = last_complete;
1196 if (used)
1197 *used = last_used;
1198
1199 ret = dma_async_is_complete(cookie, last_complete, last_used);
1200 if (ret == DMA_SUCCESS)
1201 return ret;
1202 815
1203 ioat_dma_memcpy_cleanup(ioat); 816 if (ioat_is_complete(c, cookie, done, used) == DMA_SUCCESS)
817 return DMA_SUCCESS;
1204 818
1205 last_used = c->cookie; 819 ioat1_cleanup(ioat);
1206 last_complete = chan->completed_cookie;
1207 820
1208 if (done) 821 return ioat_is_complete(c, cookie, done, used);
1209 *done = last_complete;
1210 if (used)
1211 *used = last_used;
1212
1213 return dma_async_is_complete(cookie, last_complete, last_used);
1214} 822}
1215 823
1216static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat) 824static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat)
1217{ 825{
1218 struct ioat_chan_common *chan = &ioat->base; 826 struct ioat_chan_common *chan = &ioat->base;
1219 struct ioat_desc_sw *desc; 827 struct ioat_desc_sw *desc;
@@ -1221,7 +829,7 @@ static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat)
1221 829
1222 spin_lock_bh(&ioat->desc_lock); 830 spin_lock_bh(&ioat->desc_lock);
1223 831
1224 desc = ioat_dma_get_next_descriptor(ioat); 832 desc = ioat1_dma_get_next_descriptor(ioat);
1225 833
1226 if (!desc) { 834 if (!desc) {
1227 dev_err(to_dev(chan), 835 dev_err(to_dev(chan),
@@ -1240,30 +848,16 @@ static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat)
1240 hw->src_addr = 0; 848 hw->src_addr = 0;
1241 hw->dst_addr = 0; 849 hw->dst_addr = 0;
1242 async_tx_ack(&desc->txd); 850 async_tx_ack(&desc->txd);
1243 switch (chan->device->version) { 851 hw->next = 0;
1244 case IOAT_VER_1_2: 852 list_add_tail(&desc->node, &ioat->used_desc);
1245 hw->next = 0;
1246 list_add_tail(&desc->node, &ioat->used_desc);
1247 853
1248 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF, 854 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF,
1249 chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW); 855 chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW);
1250 writel(((u64) desc->txd.phys) >> 32, 856 writel(((u64) desc->txd.phys) >> 32,
1251 chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH); 857 chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH);
1252
1253 writeb(IOAT_CHANCMD_START, chan->reg_base
1254 + IOAT_CHANCMD_OFFSET(chan->device->version));
1255 break;
1256 case IOAT_VER_2_0:
1257 case IOAT_VER_3_0:
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);
1262 858
1263 ioat->dmacount++; 859 writeb(IOAT_CHANCMD_START, chan->reg_base
1264 __ioat2_dma_memcpy_issue_pending(ioat); 860 + IOAT_CHANCMD_OFFSET(chan->device->version));
1265 break;
1266 }
1267 spin_unlock_bh(&ioat->desc_lock); 861 spin_unlock_bh(&ioat->desc_lock);
1268} 862}
1269 863
@@ -1484,7 +1078,7 @@ static void ioat_disable_interrupts(struct ioatdma_device *device)
1484 writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET); 1078 writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
1485} 1079}
1486 1080
1487static int ioat_probe(struct ioatdma_device *device) 1081int ioat_probe(struct ioatdma_device *device)
1488{ 1082{
1489 int err = -ENODEV; 1083 int err = -ENODEV;
1490 struct dma_device *dma = &device->common; 1084 struct dma_device *dma = &device->common;
@@ -1503,17 +1097,15 @@ static int ioat_probe(struct ioatdma_device *device)
1503 device->completion_pool = pci_pool_create("completion_pool", pdev, 1097 device->completion_pool = pci_pool_create("completion_pool", pdev,
1504 sizeof(u64), SMP_CACHE_BYTES, 1098 sizeof(u64), SMP_CACHE_BYTES,
1505 SMP_CACHE_BYTES); 1099 SMP_CACHE_BYTES);
1100
1506 if (!device->completion_pool) { 1101 if (!device->completion_pool) {
1507 err = -ENOMEM; 1102 err = -ENOMEM;
1508 goto err_completion_pool; 1103 goto err_completion_pool;
1509 } 1104 }
1510 1105
1511 ioat_dma_enumerate_channels(device); 1106 device->enumerate_channels(device);
1512 1107
1513 dma_cap_set(DMA_MEMCPY, dma->cap_mask); 1108 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; 1109 dma->dev = &pdev->dev;
1518 1110
1519 dev_err(dev, "Intel(R) I/OAT DMA Engine found," 1111 dev_err(dev, "Intel(R) I/OAT DMA Engine found,"
@@ -1546,7 +1138,7 @@ err_dma_pool:
1546 return err; 1138 return err;
1547} 1139}
1548 1140
1549static int ioat_register(struct ioatdma_device *device) 1141int ioat_register(struct ioatdma_device *device)
1550{ 1142{
1551 int err = dma_async_device_register(&device->common); 1143 int err = dma_async_device_register(&device->common);
1552 1144
@@ -1580,9 +1172,13 @@ int ioat1_dma_probe(struct ioatdma_device *device, int dca)
1580 int err; 1172 int err;
1581 1173
1582 device->intr_quirk = ioat1_intr_quirk; 1174 device->intr_quirk = ioat1_intr_quirk;
1175 device->enumerate_channels = ioat1_enumerate_channels;
1583 dma = &device->common; 1176 dma = &device->common;
1584 dma->device_prep_dma_memcpy = ioat1_dma_prep_memcpy; 1177 dma->device_prep_dma_memcpy = ioat1_dma_prep_memcpy;
1585 dma->device_issue_pending = ioat1_dma_memcpy_issue_pending; 1178 dma->device_issue_pending = ioat1_dma_memcpy_issue_pending;
1179 dma->device_alloc_chan_resources = ioat1_dma_alloc_chan_resources;
1180 dma->device_free_chan_resources = ioat1_dma_free_chan_resources;
1181 dma->device_is_tx_complete = ioat1_dma_is_complete;
1586 1182
1587 err = ioat_probe(device); 1183 err = ioat_probe(device);
1588 if (err) 1184 if (err)
@@ -1594,93 +1190,12 @@ int ioat1_dma_probe(struct ioatdma_device *device, int dca)
1594 if (dca) 1190 if (dca)
1595 device->dca = ioat_dca_init(pdev, device->reg_base); 1191 device->dca = ioat_dca_init(pdev, device->reg_base);
1596 1192
1597 INIT_DELAYED_WORK(&device->work, ioat_dma_chan_watchdog); 1193 INIT_DELAYED_WORK(&device->work, ioat1_chan_watchdog);
1598 schedule_delayed_work(&device->work, WATCHDOG_DELAY);
1599
1600 return err;
1601}
1602
1603int ioat2_dma_probe(struct ioatdma_device *device, int dca)
1604{
1605 struct pci_dev *pdev = device->pdev;
1606 struct dma_device *dma;
1607 struct dma_chan *c;
1608 struct ioat_chan_common *chan;
1609 int err;
1610
1611 dma = &device->common;
1612 dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy;
1613 dma->device_issue_pending = ioat2_dma_memcpy_issue_pending;
1614
1615 err = ioat_probe(device);
1616 if (err)
1617 return err;
1618 ioat_set_tcp_copy_break(2048);
1619
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);
1624 }
1625
1626 err = ioat_register(device);
1627 if (err)
1628 return err;
1629 if (dca)
1630 device->dca = ioat2_dca_init(pdev, device->reg_base);
1631
1632 INIT_DELAYED_WORK(&device->work, ioat_dma_chan_watchdog);
1633 schedule_delayed_work(&device->work, WATCHDOG_DELAY); 1194 schedule_delayed_work(&device->work, WATCHDOG_DELAY);
1634 1195
1635 return err; 1196 return err;
1636} 1197}
1637 1198
1638int ioat3_dma_probe(struct ioatdma_device *device, int dca)
1639{
1640 struct pci_dev *pdev = device->pdev;
1641 struct dma_device *dma;
1642 struct dma_chan *c;
1643 struct ioat_chan_common *chan;
1644 int err;
1645 u16 dev_id;
1646
1647 dma = &device->common;
1648 dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy;
1649 dma->device_issue_pending = ioat2_dma_memcpy_issue_pending;
1650
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
1654 */
1655 pci_write_config_dword(pdev, IOAT_PCI_CHANERRMASK_INT_OFFSET, 0x3e07);
1656
1657 /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit
1658 * (workaround for spurious config parity error after restart)
1659 */
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);
1663
1664 err = ioat_probe(device);
1665 if (err)
1666 return err;
1667 ioat_set_tcp_copy_break(262144);
1668
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);
1673 }
1674
1675 err = ioat_register(device);
1676 if (err)
1677 return err;
1678 if (dca)
1679 device->dca = ioat3_dca_init(pdev, device->reg_base);
1680
1681 return err;
1682}
1683
1684void ioat_dma_remove(struct ioatdma_device *device) 1199void ioat_dma_remove(struct ioatdma_device *device)
1685{ 1200{
1686 struct dma_device *dma = &device->common; 1201 struct dma_device *dma = &device->common;
@@ -1697,4 +1212,3 @@ void ioat_dma_remove(struct ioatdma_device *device)
1697 1212
1698 INIT_LIST_HEAD(&dma->channels); 1213 INIT_LIST_HEAD(&dma->channels);
1699} 1214}
1700