| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for the Atmel AHB DMA Controller (aka HDMA or DMAC on AT91 systems) |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2008 Atmel Corporation |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | 6 | * |
|---|
| 12 | 7 | * This supports the Atmel AHB DMA Controller found in several Atmel SoCs. |
|---|
| 13 | 8 | * The only Atmel DMA Controller that is not covered by this driver is the one |
|---|
| .. | .. |
|---|
| 134 | 129 | struct at_desc *ret = NULL; |
|---|
| 135 | 130 | unsigned long flags; |
|---|
| 136 | 131 | unsigned int i = 0; |
|---|
| 137 | | - LIST_HEAD(tmp_list); |
|---|
| 138 | 132 | |
|---|
| 139 | 133 | spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 140 | 134 | list_for_each_entry_safe(desc, _desc, &atchan->free_list, desc_node) { |
|---|
| .. | .. |
|---|
| 152 | 146 | "scanned %u descriptors on freelist\n", i); |
|---|
| 153 | 147 | |
|---|
| 154 | 148 | /* no more descriptor available in initial pool: create one more */ |
|---|
| 155 | | - if (!ret) { |
|---|
| 156 | | - ret = atc_alloc_descriptor(&atchan->chan_common, GFP_ATOMIC); |
|---|
| 157 | | - if (ret) { |
|---|
| 158 | | - spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 159 | | - atchan->descs_allocated++; |
|---|
| 160 | | - spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 161 | | - } else { |
|---|
| 162 | | - dev_err(chan2dev(&atchan->chan_common), |
|---|
| 163 | | - "not enough descriptors available\n"); |
|---|
| 164 | | - } |
|---|
| 165 | | - } |
|---|
| 149 | + if (!ret) |
|---|
| 150 | + ret = atc_alloc_descriptor(&atchan->chan_common, GFP_NOWAIT); |
|---|
| 166 | 151 | |
|---|
| 167 | 152 | return ret; |
|---|
| 168 | 153 | } |
|---|
| .. | .. |
|---|
| 252 | 237 | ATC_SPIP_BOUNDARY(first->boundary)); |
|---|
| 253 | 238 | channel_writel(atchan, DPIP, ATC_DPIP_HOLE(first->dst_hole) | |
|---|
| 254 | 239 | ATC_DPIP_BOUNDARY(first->boundary)); |
|---|
| 240 | + /* Don't allow CPU to reorder channel enable. */ |
|---|
| 241 | + wmb(); |
|---|
| 255 | 242 | dma_writel(atdma, CHER, atchan->mask); |
|---|
| 256 | 243 | |
|---|
| 257 | 244 | vdbg_dump_regs(atchan); |
|---|
| .. | .. |
|---|
| 312 | 299 | struct at_desc *desc_first = atc_first_active(atchan); |
|---|
| 313 | 300 | struct at_desc *desc; |
|---|
| 314 | 301 | int ret; |
|---|
| 315 | | - u32 ctrla, dscr, trials; |
|---|
| 302 | + u32 ctrla, dscr; |
|---|
| 303 | + unsigned int i; |
|---|
| 316 | 304 | |
|---|
| 317 | 305 | /* |
|---|
| 318 | 306 | * If the cookie doesn't match to the currently running transfer then |
|---|
| .. | .. |
|---|
| 382 | 370 | dscr = channel_readl(atchan, DSCR); |
|---|
| 383 | 371 | rmb(); /* ensure DSCR is read before CTRLA */ |
|---|
| 384 | 372 | ctrla = channel_readl(atchan, CTRLA); |
|---|
| 385 | | - for (trials = 0; trials < ATC_MAX_DSCR_TRIALS; ++trials) { |
|---|
| 373 | + for (i = 0; i < ATC_MAX_DSCR_TRIALS; ++i) { |
|---|
| 386 | 374 | u32 new_dscr; |
|---|
| 387 | 375 | |
|---|
| 388 | 376 | rmb(); /* ensure DSCR is read after CTRLA */ |
|---|
| .. | .. |
|---|
| 408 | 396 | rmb(); /* ensure DSCR is read before CTRLA */ |
|---|
| 409 | 397 | ctrla = channel_readl(atchan, CTRLA); |
|---|
| 410 | 398 | } |
|---|
| 411 | | - if (unlikely(trials >= ATC_MAX_DSCR_TRIALS)) |
|---|
| 399 | + if (unlikely(i == ATC_MAX_DSCR_TRIALS)) |
|---|
| 412 | 400 | return -ETIMEDOUT; |
|---|
| 413 | 401 | |
|---|
| 414 | 402 | /* for the first descriptor we can be more accurate */ |
|---|
| .. | .. |
|---|
| 441 | 429 | * atc_chain_complete - finish work for one transaction chain |
|---|
| 442 | 430 | * @atchan: channel we work on |
|---|
| 443 | 431 | * @desc: descriptor at the head of the chain we want do complete |
|---|
| 444 | | - * |
|---|
| 445 | | - * Called with atchan->lock held and bh disabled */ |
|---|
| 432 | + */ |
|---|
| 446 | 433 | static void |
|---|
| 447 | 434 | atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc) |
|---|
| 448 | 435 | { |
|---|
| 449 | 436 | struct dma_async_tx_descriptor *txd = &desc->txd; |
|---|
| 450 | 437 | struct at_dma *atdma = to_at_dma(atchan->chan_common.device); |
|---|
| 438 | + unsigned long flags; |
|---|
| 451 | 439 | |
|---|
| 452 | 440 | dev_vdbg(chan2dev(&atchan->chan_common), |
|---|
| 453 | 441 | "descriptor %u complete\n", txd->cookie); |
|---|
| 454 | 442 | |
|---|
| 443 | + spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 444 | + |
|---|
| 455 | 445 | /* mark the descriptor as complete for non cyclic cases only */ |
|---|
| 456 | 446 | if (!atc_chan_is_cyclic(atchan)) |
|---|
| 457 | 447 | dma_cookie_complete(txd); |
|---|
| 448 | + |
|---|
| 449 | + spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 450 | + |
|---|
| 451 | + dma_descriptor_unmap(txd); |
|---|
| 452 | + /* for cyclic transfers, |
|---|
| 453 | + * no need to replay callback function while stopping */ |
|---|
| 454 | + if (!atc_chan_is_cyclic(atchan)) |
|---|
| 455 | + dmaengine_desc_get_callback_invoke(txd, NULL); |
|---|
| 456 | + |
|---|
| 457 | + dma_run_dependencies(txd); |
|---|
| 458 | + |
|---|
| 459 | + spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 460 | + /* move children to free_list */ |
|---|
| 461 | + list_splice_init(&desc->tx_list, &atchan->free_list); |
|---|
| 462 | + /* add myself to free_list */ |
|---|
| 463 | + list_add(&desc->desc_node, &atchan->free_list); |
|---|
| 464 | + spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 458 | 465 | |
|---|
| 459 | 466 | /* If the transfer was a memset, free our temporary buffer */ |
|---|
| 460 | 467 | if (desc->memset_buffer) { |
|---|
| .. | .. |
|---|
| 462 | 469 | desc->memset_paddr); |
|---|
| 463 | 470 | desc->memset_buffer = false; |
|---|
| 464 | 471 | } |
|---|
| 465 | | - |
|---|
| 466 | | - /* move children to free_list */ |
|---|
| 467 | | - list_splice_init(&desc->tx_list, &atchan->free_list); |
|---|
| 468 | | - /* move myself to free_list */ |
|---|
| 469 | | - list_move(&desc->desc_node, &atchan->free_list); |
|---|
| 470 | | - |
|---|
| 471 | | - dma_descriptor_unmap(txd); |
|---|
| 472 | | - /* for cyclic transfers, |
|---|
| 473 | | - * no need to replay callback function while stopping */ |
|---|
| 474 | | - if (!atc_chan_is_cyclic(atchan)) { |
|---|
| 475 | | - /* |
|---|
| 476 | | - * The API requires that no submissions are done from a |
|---|
| 477 | | - * callback, so we don't need to drop the lock here |
|---|
| 478 | | - */ |
|---|
| 479 | | - dmaengine_desc_get_callback_invoke(txd, NULL); |
|---|
| 480 | | - } |
|---|
| 481 | | - |
|---|
| 482 | | - dma_run_dependencies(txd); |
|---|
| 483 | | -} |
|---|
| 484 | | - |
|---|
| 485 | | -/** |
|---|
| 486 | | - * atc_complete_all - finish work for all transactions |
|---|
| 487 | | - * @atchan: channel to complete transactions for |
|---|
| 488 | | - * |
|---|
| 489 | | - * Eventually submit queued descriptors if any |
|---|
| 490 | | - * |
|---|
| 491 | | - * Assume channel is idle while calling this function |
|---|
| 492 | | - * Called with atchan->lock held and bh disabled |
|---|
| 493 | | - */ |
|---|
| 494 | | -static void atc_complete_all(struct at_dma_chan *atchan) |
|---|
| 495 | | -{ |
|---|
| 496 | | - struct at_desc *desc, *_desc; |
|---|
| 497 | | - LIST_HEAD(list); |
|---|
| 498 | | - |
|---|
| 499 | | - dev_vdbg(chan2dev(&atchan->chan_common), "complete all\n"); |
|---|
| 500 | | - |
|---|
| 501 | | - /* |
|---|
| 502 | | - * Submit queued descriptors ASAP, i.e. before we go through |
|---|
| 503 | | - * the completed ones. |
|---|
| 504 | | - */ |
|---|
| 505 | | - if (!list_empty(&atchan->queue)) |
|---|
| 506 | | - atc_dostart(atchan, atc_first_queued(atchan)); |
|---|
| 507 | | - /* empty active_list now it is completed */ |
|---|
| 508 | | - list_splice_init(&atchan->active_list, &list); |
|---|
| 509 | | - /* empty queue list by moving descriptors (if any) to active_list */ |
|---|
| 510 | | - list_splice_init(&atchan->queue, &atchan->active_list); |
|---|
| 511 | | - |
|---|
| 512 | | - list_for_each_entry_safe(desc, _desc, &list, desc_node) |
|---|
| 513 | | - atc_chain_complete(atchan, desc); |
|---|
| 514 | 472 | } |
|---|
| 515 | 473 | |
|---|
| 516 | 474 | /** |
|---|
| 517 | 475 | * atc_advance_work - at the end of a transaction, move forward |
|---|
| 518 | 476 | * @atchan: channel where the transaction ended |
|---|
| 519 | | - * |
|---|
| 520 | | - * Called with atchan->lock held and bh disabled |
|---|
| 521 | 477 | */ |
|---|
| 522 | 478 | static void atc_advance_work(struct at_dma_chan *atchan) |
|---|
| 523 | 479 | { |
|---|
| 480 | + struct at_desc *desc; |
|---|
| 481 | + unsigned long flags; |
|---|
| 482 | + |
|---|
| 524 | 483 | dev_vdbg(chan2dev(&atchan->chan_common), "advance_work\n"); |
|---|
| 525 | 484 | |
|---|
| 526 | | - if (atc_chan_is_enabled(atchan)) |
|---|
| 527 | | - return; |
|---|
| 485 | + spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 486 | + if (atc_chan_is_enabled(atchan) || list_empty(&atchan->active_list)) |
|---|
| 487 | + return spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 528 | 488 | |
|---|
| 529 | | - if (list_empty(&atchan->active_list) || |
|---|
| 530 | | - list_is_singular(&atchan->active_list)) { |
|---|
| 531 | | - atc_complete_all(atchan); |
|---|
| 532 | | - } else { |
|---|
| 533 | | - atc_chain_complete(atchan, atc_first_active(atchan)); |
|---|
| 534 | | - /* advance work */ |
|---|
| 535 | | - atc_dostart(atchan, atc_first_active(atchan)); |
|---|
| 489 | + desc = atc_first_active(atchan); |
|---|
| 490 | + /* Remove the transfer node from the active list. */ |
|---|
| 491 | + list_del_init(&desc->desc_node); |
|---|
| 492 | + spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 493 | + atc_chain_complete(atchan, desc); |
|---|
| 494 | + |
|---|
| 495 | + /* advance work */ |
|---|
| 496 | + spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 497 | + if (!list_empty(&atchan->active_list)) { |
|---|
| 498 | + desc = atc_first_queued(atchan); |
|---|
| 499 | + list_move_tail(&desc->desc_node, &atchan->active_list); |
|---|
| 500 | + atc_dostart(atchan, desc); |
|---|
| 536 | 501 | } |
|---|
| 502 | + spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 537 | 503 | } |
|---|
| 538 | 504 | |
|---|
| 539 | 505 | |
|---|
| 540 | 506 | /** |
|---|
| 541 | 507 | * atc_handle_error - handle errors reported by DMA controller |
|---|
| 542 | 508 | * @atchan: channel where error occurs |
|---|
| 543 | | - * |
|---|
| 544 | | - * Called with atchan->lock held and bh disabled |
|---|
| 545 | 509 | */ |
|---|
| 546 | 510 | static void atc_handle_error(struct at_dma_chan *atchan) |
|---|
| 547 | 511 | { |
|---|
| 548 | 512 | struct at_desc *bad_desc; |
|---|
| 513 | + struct at_desc *desc; |
|---|
| 549 | 514 | struct at_desc *child; |
|---|
| 515 | + unsigned long flags; |
|---|
| 550 | 516 | |
|---|
| 517 | + spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 551 | 518 | /* |
|---|
| 552 | 519 | * The descriptor currently at the head of the active list is |
|---|
| 553 | 520 | * broked. Since we don't have any way to report errors, we'll |
|---|
| .. | .. |
|---|
| 556 | 523 | bad_desc = atc_first_active(atchan); |
|---|
| 557 | 524 | list_del_init(&bad_desc->desc_node); |
|---|
| 558 | 525 | |
|---|
| 559 | | - /* As we are stopped, take advantage to push queued descriptors |
|---|
| 560 | | - * in active_list */ |
|---|
| 561 | | - list_splice_init(&atchan->queue, atchan->active_list.prev); |
|---|
| 562 | | - |
|---|
| 563 | 526 | /* Try to restart the controller */ |
|---|
| 564 | | - if (!list_empty(&atchan->active_list)) |
|---|
| 565 | | - atc_dostart(atchan, atc_first_active(atchan)); |
|---|
| 527 | + if (!list_empty(&atchan->active_list)) { |
|---|
| 528 | + desc = atc_first_queued(atchan); |
|---|
| 529 | + list_move_tail(&desc->desc_node, &atchan->active_list); |
|---|
| 530 | + atc_dostart(atchan, desc); |
|---|
| 531 | + } |
|---|
| 566 | 532 | |
|---|
| 567 | 533 | /* |
|---|
| 568 | 534 | * KERN_CRITICAL may seem harsh, but since this only happens |
|---|
| .. | .. |
|---|
| 579 | 545 | list_for_each_entry(child, &bad_desc->tx_list, desc_node) |
|---|
| 580 | 546 | atc_dump_lli(atchan, &child->lli); |
|---|
| 581 | 547 | |
|---|
| 548 | + spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 549 | + |
|---|
| 582 | 550 | /* Pretend the descriptor completed successfully */ |
|---|
| 583 | 551 | atc_chain_complete(atchan, bad_desc); |
|---|
| 584 | 552 | } |
|---|
| .. | .. |
|---|
| 586 | 554 | /** |
|---|
| 587 | 555 | * atc_handle_cyclic - at the end of a period, run callback function |
|---|
| 588 | 556 | * @atchan: channel used for cyclic operations |
|---|
| 589 | | - * |
|---|
| 590 | | - * Called with atchan->lock held and bh disabled |
|---|
| 591 | 557 | */ |
|---|
| 592 | 558 | static void atc_handle_cyclic(struct at_dma_chan *atchan) |
|---|
| 593 | 559 | { |
|---|
| .. | .. |
|---|
| 603 | 569 | |
|---|
| 604 | 570 | /*-- IRQ & Tasklet ---------------------------------------------------*/ |
|---|
| 605 | 571 | |
|---|
| 606 | | -static void atc_tasklet(unsigned long data) |
|---|
| 572 | +static void atc_tasklet(struct tasklet_struct *t) |
|---|
| 607 | 573 | { |
|---|
| 608 | | - struct at_dma_chan *atchan = (struct at_dma_chan *)data; |
|---|
| 609 | | - unsigned long flags; |
|---|
| 574 | + struct at_dma_chan *atchan = from_tasklet(atchan, t, tasklet); |
|---|
| 610 | 575 | |
|---|
| 611 | | - spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 612 | 576 | if (test_and_clear_bit(ATC_IS_ERROR, &atchan->status)) |
|---|
| 613 | | - atc_handle_error(atchan); |
|---|
| 614 | | - else if (atc_chan_is_cyclic(atchan)) |
|---|
| 615 | | - atc_handle_cyclic(atchan); |
|---|
| 616 | | - else |
|---|
| 617 | | - atc_advance_work(atchan); |
|---|
| 577 | + return atc_handle_error(atchan); |
|---|
| 618 | 578 | |
|---|
| 619 | | - spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 579 | + if (atc_chan_is_cyclic(atchan)) |
|---|
| 580 | + return atc_handle_cyclic(atchan); |
|---|
| 581 | + |
|---|
| 582 | + atc_advance_work(atchan); |
|---|
| 620 | 583 | } |
|---|
| 621 | 584 | |
|---|
| 622 | 585 | static irqreturn_t at_dma_interrupt(int irq, void *dev_id) |
|---|
| .. | .. |
|---|
| 664 | 627 | |
|---|
| 665 | 628 | /** |
|---|
| 666 | 629 | * atc_tx_submit - set the prepared descriptor(s) to be executed by the engine |
|---|
| 667 | | - * @desc: descriptor at the head of the transaction chain |
|---|
| 630 | + * @tx: descriptor at the head of the transaction chain |
|---|
| 668 | 631 | * |
|---|
| 669 | 632 | * Queue chain if DMA engine is working already |
|---|
| 670 | 633 | * |
|---|
| .. | .. |
|---|
| 680 | 643 | spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 681 | 644 | cookie = dma_cookie_assign(tx); |
|---|
| 682 | 645 | |
|---|
| 683 | | - if (list_empty(&atchan->active_list)) { |
|---|
| 684 | | - dev_vdbg(chan2dev(tx->chan), "tx_submit: started %u\n", |
|---|
| 685 | | - desc->txd.cookie); |
|---|
| 686 | | - atc_dostart(atchan, desc); |
|---|
| 687 | | - list_add_tail(&desc->desc_node, &atchan->active_list); |
|---|
| 688 | | - } else { |
|---|
| 689 | | - dev_vdbg(chan2dev(tx->chan), "tx_submit: queued %u\n", |
|---|
| 690 | | - desc->txd.cookie); |
|---|
| 691 | | - list_add_tail(&desc->desc_node, &atchan->queue); |
|---|
| 692 | | - } |
|---|
| 693 | | - |
|---|
| 646 | + list_add_tail(&desc->desc_node, &atchan->queue); |
|---|
| 694 | 647 | spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 695 | 648 | |
|---|
| 649 | + dev_vdbg(chan2dev(tx->chan), "tx_submit: queued %u\n", |
|---|
| 650 | + desc->txd.cookie); |
|---|
| 696 | 651 | return cookie; |
|---|
| 697 | 652 | } |
|---|
| 698 | 653 | |
|---|
| .. | .. |
|---|
| 946 | 901 | return NULL; |
|---|
| 947 | 902 | } |
|---|
| 948 | 903 | |
|---|
| 949 | | - vaddr = dma_pool_alloc(atdma->memset_pool, GFP_ATOMIC, &paddr); |
|---|
| 904 | + vaddr = dma_pool_alloc(atdma->memset_pool, GFP_NOWAIT, &paddr); |
|---|
| 950 | 905 | if (!vaddr) { |
|---|
| 951 | 906 | dev_err(chan2dev(chan), "%s: couldn't allocate buffer\n", |
|---|
| 952 | 907 | __func__); |
|---|
| .. | .. |
|---|
| 1004 | 959 | return NULL; |
|---|
| 1005 | 960 | } |
|---|
| 1006 | 961 | |
|---|
| 1007 | | - vaddr = dma_pool_alloc(atdma->memset_pool, GFP_ATOMIC, &paddr); |
|---|
| 962 | + vaddr = dma_pool_alloc(atdma->memset_pool, GFP_NOWAIT, &paddr); |
|---|
| 1008 | 963 | if (!vaddr) { |
|---|
| 1009 | 964 | dev_err(chan2dev(chan), "%s: couldn't allocate buffer\n", |
|---|
| 1010 | 965 | __func__); |
|---|
| .. | .. |
|---|
| 1204 | 1159 | return NULL; |
|---|
| 1205 | 1160 | } |
|---|
| 1206 | 1161 | |
|---|
| 1207 | | -/** |
|---|
| 1162 | +/* |
|---|
| 1208 | 1163 | * atc_dma_cyclic_check_values |
|---|
| 1209 | 1164 | * Check for too big/unaligned periods and unaligned DMA buffer |
|---|
| 1210 | 1165 | */ |
|---|
| .. | .. |
|---|
| 1225 | 1180 | return -EINVAL; |
|---|
| 1226 | 1181 | } |
|---|
| 1227 | 1182 | |
|---|
| 1228 | | -/** |
|---|
| 1183 | +/* |
|---|
| 1229 | 1184 | * atc_dma_cyclic_fill_desc - Fill one period descriptor |
|---|
| 1230 | 1185 | */ |
|---|
| 1231 | 1186 | static int |
|---|
| .. | .. |
|---|
| 1320 | 1275 | if (unlikely(!is_slave_direction(direction))) |
|---|
| 1321 | 1276 | goto err_out; |
|---|
| 1322 | 1277 | |
|---|
| 1323 | | - if (sconfig->direction == DMA_MEM_TO_DEV) |
|---|
| 1278 | + if (direction == DMA_MEM_TO_DEV) |
|---|
| 1324 | 1279 | reg_width = convert_buswidth(sconfig->dst_addr_width); |
|---|
| 1325 | 1280 | else |
|---|
| 1326 | 1281 | reg_width = convert_buswidth(sconfig->src_addr_width); |
|---|
| .. | .. |
|---|
| 1387 | 1342 | int chan_id = atchan->chan_common.chan_id; |
|---|
| 1388 | 1343 | unsigned long flags; |
|---|
| 1389 | 1344 | |
|---|
| 1390 | | - LIST_HEAD(list); |
|---|
| 1391 | | - |
|---|
| 1392 | 1345 | dev_vdbg(chan2dev(chan), "%s\n", __func__); |
|---|
| 1393 | 1346 | |
|---|
| 1394 | 1347 | spin_lock_irqsave(&atchan->lock, flags); |
|---|
| .. | .. |
|---|
| 1407 | 1360 | struct at_dma *atdma = to_at_dma(chan->device); |
|---|
| 1408 | 1361 | int chan_id = atchan->chan_common.chan_id; |
|---|
| 1409 | 1362 | unsigned long flags; |
|---|
| 1410 | | - |
|---|
| 1411 | | - LIST_HEAD(list); |
|---|
| 1412 | 1363 | |
|---|
| 1413 | 1364 | dev_vdbg(chan2dev(chan), "%s\n", __func__); |
|---|
| 1414 | 1365 | |
|---|
| .. | .. |
|---|
| 1430 | 1381 | struct at_dma_chan *atchan = to_at_dma_chan(chan); |
|---|
| 1431 | 1382 | struct at_dma *atdma = to_at_dma(chan->device); |
|---|
| 1432 | 1383 | int chan_id = atchan->chan_common.chan_id; |
|---|
| 1433 | | - struct at_desc *desc, *_desc; |
|---|
| 1434 | 1384 | unsigned long flags; |
|---|
| 1435 | | - |
|---|
| 1436 | | - LIST_HEAD(list); |
|---|
| 1437 | 1385 | |
|---|
| 1438 | 1386 | dev_vdbg(chan2dev(chan), "%s\n", __func__); |
|---|
| 1439 | 1387 | |
|---|
| .. | .. |
|---|
| 1453 | 1401 | cpu_relax(); |
|---|
| 1454 | 1402 | |
|---|
| 1455 | 1403 | /* active_list entries will end up before queued entries */ |
|---|
| 1456 | | - list_splice_init(&atchan->queue, &list); |
|---|
| 1457 | | - list_splice_init(&atchan->active_list, &list); |
|---|
| 1458 | | - |
|---|
| 1459 | | - /* Flush all pending and queued descriptors */ |
|---|
| 1460 | | - list_for_each_entry_safe(desc, _desc, &list, desc_node) |
|---|
| 1461 | | - atc_chain_complete(atchan, desc); |
|---|
| 1404 | + list_splice_tail_init(&atchan->queue, &atchan->free_list); |
|---|
| 1405 | + list_splice_tail_init(&atchan->active_list, &atchan->free_list); |
|---|
| 1462 | 1406 | |
|---|
| 1463 | 1407 | clear_bit(ATC_IS_PAUSED, &atchan->status); |
|---|
| 1464 | 1408 | /* if channel dedicated to cyclic operations, free it */ |
|---|
| .. | .. |
|---|
| 1520 | 1464 | } |
|---|
| 1521 | 1465 | |
|---|
| 1522 | 1466 | /** |
|---|
| 1523 | | - * atc_issue_pending - try to finish work |
|---|
| 1467 | + * atc_issue_pending - takes the first transaction descriptor in the pending |
|---|
| 1468 | + * queue and starts the transfer. |
|---|
| 1524 | 1469 | * @chan: target DMA channel |
|---|
| 1525 | 1470 | */ |
|---|
| 1526 | 1471 | static void atc_issue_pending(struct dma_chan *chan) |
|---|
| 1527 | 1472 | { |
|---|
| 1528 | | - struct at_dma_chan *atchan = to_at_dma_chan(chan); |
|---|
| 1529 | | - unsigned long flags; |
|---|
| 1473 | + struct at_dma_chan *atchan = to_at_dma_chan(chan); |
|---|
| 1474 | + struct at_desc *desc; |
|---|
| 1475 | + unsigned long flags; |
|---|
| 1530 | 1476 | |
|---|
| 1531 | 1477 | dev_vdbg(chan2dev(chan), "issue_pending\n"); |
|---|
| 1532 | 1478 | |
|---|
| 1533 | | - /* Not needed for cyclic transfers */ |
|---|
| 1534 | | - if (atc_chan_is_cyclic(atchan)) |
|---|
| 1535 | | - return; |
|---|
| 1536 | | - |
|---|
| 1537 | 1479 | spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 1538 | | - atc_advance_work(atchan); |
|---|
| 1480 | + if (atc_chan_is_enabled(atchan) || list_empty(&atchan->queue)) |
|---|
| 1481 | + return spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 1482 | + |
|---|
| 1483 | + desc = atc_first_queued(atchan); |
|---|
| 1484 | + list_move_tail(&desc->desc_node, &atchan->active_list); |
|---|
| 1485 | + atc_dostart(atchan, desc); |
|---|
| 1539 | 1486 | spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 1540 | 1487 | } |
|---|
| 1541 | 1488 | |
|---|
| 1542 | 1489 | /** |
|---|
| 1543 | 1490 | * atc_alloc_chan_resources - allocate resources for DMA channel |
|---|
| 1544 | 1491 | * @chan: allocate descriptor resources for this channel |
|---|
| 1545 | | - * @client: current client requesting the channel be ready for requests |
|---|
| 1546 | 1492 | * |
|---|
| 1547 | 1493 | * return - the number of allocated descriptors |
|---|
| 1548 | 1494 | */ |
|---|
| .. | .. |
|---|
| 1552 | 1498 | struct at_dma *atdma = to_at_dma(chan->device); |
|---|
| 1553 | 1499 | struct at_desc *desc; |
|---|
| 1554 | 1500 | struct at_dma_slave *atslave; |
|---|
| 1555 | | - unsigned long flags; |
|---|
| 1556 | 1501 | int i; |
|---|
| 1557 | 1502 | u32 cfg; |
|---|
| 1558 | | - LIST_HEAD(tmp_list); |
|---|
| 1559 | 1503 | |
|---|
| 1560 | 1504 | dev_vdbg(chan2dev(chan), "alloc_chan_resources\n"); |
|---|
| 1561 | 1505 | |
|---|
| 1562 | 1506 | /* ASSERT: channel is idle */ |
|---|
| 1563 | 1507 | if (atc_chan_is_enabled(atchan)) { |
|---|
| 1564 | 1508 | dev_dbg(chan2dev(chan), "DMA channel not idle ?\n"); |
|---|
| 1509 | + return -EIO; |
|---|
| 1510 | + } |
|---|
| 1511 | + |
|---|
| 1512 | + if (!list_empty(&atchan->free_list)) { |
|---|
| 1513 | + dev_dbg(chan2dev(chan), "can't allocate channel resources (channel not freed from a previous use)\n"); |
|---|
| 1565 | 1514 | return -EIO; |
|---|
| 1566 | 1515 | } |
|---|
| 1567 | 1516 | |
|---|
| .. | .. |
|---|
| 1580 | 1529 | cfg = atslave->cfg; |
|---|
| 1581 | 1530 | } |
|---|
| 1582 | 1531 | |
|---|
| 1583 | | - /* have we already been set up? |
|---|
| 1584 | | - * reconfigure channel but no need to reallocate descriptors */ |
|---|
| 1585 | | - if (!list_empty(&atchan->free_list)) |
|---|
| 1586 | | - return atchan->descs_allocated; |
|---|
| 1587 | | - |
|---|
| 1588 | 1532 | /* Allocate initial pool of descriptors */ |
|---|
| 1589 | 1533 | for (i = 0; i < init_nr_desc_per_channel; i++) { |
|---|
| 1590 | 1534 | desc = atc_alloc_descriptor(chan, GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 1593 | 1537 | "Only %d initial descriptors\n", i); |
|---|
| 1594 | 1538 | break; |
|---|
| 1595 | 1539 | } |
|---|
| 1596 | | - list_add_tail(&desc->desc_node, &tmp_list); |
|---|
| 1540 | + list_add_tail(&desc->desc_node, &atchan->free_list); |
|---|
| 1597 | 1541 | } |
|---|
| 1598 | 1542 | |
|---|
| 1599 | | - spin_lock_irqsave(&atchan->lock, flags); |
|---|
| 1600 | | - atchan->descs_allocated = i; |
|---|
| 1601 | | - list_splice(&tmp_list, &atchan->free_list); |
|---|
| 1602 | 1543 | dma_cookie_init(chan); |
|---|
| 1603 | | - spin_unlock_irqrestore(&atchan->lock, flags); |
|---|
| 1604 | 1544 | |
|---|
| 1605 | 1545 | /* channel parameters */ |
|---|
| 1606 | 1546 | channel_writel(atchan, CFG, cfg); |
|---|
| 1607 | 1547 | |
|---|
| 1608 | 1548 | dev_dbg(chan2dev(chan), |
|---|
| 1609 | | - "alloc_chan_resources: allocated %d descriptors\n", |
|---|
| 1610 | | - atchan->descs_allocated); |
|---|
| 1549 | + "alloc_chan_resources: allocated %d descriptors\n", i); |
|---|
| 1611 | 1550 | |
|---|
| 1612 | | - return atchan->descs_allocated; |
|---|
| 1551 | + return i; |
|---|
| 1613 | 1552 | } |
|---|
| 1614 | 1553 | |
|---|
| 1615 | 1554 | /** |
|---|
| .. | .. |
|---|
| 1623 | 1562 | struct at_desc *desc, *_desc; |
|---|
| 1624 | 1563 | LIST_HEAD(list); |
|---|
| 1625 | 1564 | |
|---|
| 1626 | | - dev_dbg(chan2dev(chan), "free_chan_resources: (descs allocated=%u)\n", |
|---|
| 1627 | | - atchan->descs_allocated); |
|---|
| 1628 | | - |
|---|
| 1629 | 1565 | /* ASSERT: channel is idle */ |
|---|
| 1630 | 1566 | BUG_ON(!list_empty(&atchan->active_list)); |
|---|
| 1631 | 1567 | BUG_ON(!list_empty(&atchan->queue)); |
|---|
| .. | .. |
|---|
| 1638 | 1574 | dma_pool_free(atdma->dma_desc_pool, desc, desc->txd.phys); |
|---|
| 1639 | 1575 | } |
|---|
| 1640 | 1576 | list_splice_init(&atchan->free_list, &list); |
|---|
| 1641 | | - atchan->descs_allocated = 0; |
|---|
| 1642 | 1577 | atchan->status = 0; |
|---|
| 1643 | 1578 | |
|---|
| 1644 | 1579 | /* |
|---|
| .. | .. |
|---|
| 1919 | 1854 | INIT_LIST_HEAD(&atchan->queue); |
|---|
| 1920 | 1855 | INIT_LIST_HEAD(&atchan->free_list); |
|---|
| 1921 | 1856 | |
|---|
| 1922 | | - tasklet_init(&atchan->tasklet, atc_tasklet, |
|---|
| 1923 | | - (unsigned long)atchan); |
|---|
| 1857 | + tasklet_setup(&atchan->tasklet, atc_tasklet); |
|---|
| 1924 | 1858 | atc_enable_chan_irq(atdma, i); |
|---|
| 1925 | 1859 | } |
|---|
| 1926 | 1860 | |
|---|
| .. | .. |
|---|
| 1967 | 1901 | dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask) ? "slave " : "", |
|---|
| 1968 | 1902 | plat_dat->nr_channels); |
|---|
| 1969 | 1903 | |
|---|
| 1970 | | - dma_async_device_register(&atdma->dma_common); |
|---|
| 1904 | + err = dma_async_device_register(&atdma->dma_common); |
|---|
| 1905 | + if (err) { |
|---|
| 1906 | + dev_err(&pdev->dev, "Unable to register: %d.\n", err); |
|---|
| 1907 | + goto err_dma_async_device_register; |
|---|
| 1908 | + } |
|---|
| 1971 | 1909 | |
|---|
| 1972 | 1910 | /* |
|---|
| 1973 | 1911 | * Do not return an error if the dmac node is not present in order to |
|---|
| .. | .. |
|---|
| 1987 | 1925 | |
|---|
| 1988 | 1926 | err_of_dma_controller_register: |
|---|
| 1989 | 1927 | dma_async_device_unregister(&atdma->dma_common); |
|---|
| 1928 | +err_dma_async_device_register: |
|---|
| 1990 | 1929 | dma_pool_destroy(atdma->memset_pool); |
|---|
| 1991 | 1930 | err_memset_pool_create: |
|---|
| 1992 | 1931 | dma_pool_destroy(atdma->dma_desc_pool); |
|---|