aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2008-06-13 12:12:32 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2008-07-09 12:09:23 -0400
commite7d39069e387a12d4c57f4067d9f48c1d29ea900 (patch)
tree5c22fa8d08bc0ed90af16b4c8c1044e6da15bbac /fs/nfs
parent396cee977f79590673ad51b04f1853e58bc30e7b (diff)
NFS: Clean up nfs_update_request()
Simplify the loop in nfs_update_request by moving into a separate function the code that attempts to update an existing cached NFS write. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/write.c201
1 files changed, 103 insertions, 98 deletions
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 21d8a48b624b..04f51e52e184 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -34,9 +34,6 @@
34/* 34/*
35 * Local function declarations 35 * Local function declarations
36 */ 36 */
37static struct nfs_page * nfs_update_request(struct nfs_open_context*,
38 struct page *,
39 unsigned int, unsigned int);
40static void nfs_pageio_init_write(struct nfs_pageio_descriptor *desc, 37static void nfs_pageio_init_write(struct nfs_pageio_descriptor *desc,
41 struct inode *inode, int ioflags); 38 struct inode *inode, int ioflags);
42static void nfs_redirty_request(struct nfs_page *req); 39static void nfs_redirty_request(struct nfs_page *req);
@@ -169,30 +166,6 @@ static void nfs_mark_uptodate(struct page *page, unsigned int base, unsigned int
169 SetPageUptodate(page); 166 SetPageUptodate(page);
170} 167}
171 168
172static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
173 unsigned int offset, unsigned int count)
174{
175 struct nfs_page *req;
176 int ret;
177
178 for (;;) {
179 req = nfs_update_request(ctx, page, offset, count);
180 if (!IS_ERR(req))
181 break;
182 ret = PTR_ERR(req);
183 if (ret != -EBUSY)
184 return ret;
185 ret = nfs_wb_page(page->mapping->host, page);
186 if (ret != 0)
187 return ret;
188 }
189 /* Update file length */
190 nfs_grow_file(page, offset, count);
191 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
192 nfs_clear_page_tag_locked(req);
193 return 0;
194}
195
196static int wb_priority(struct writeback_control *wbc) 169static int wb_priority(struct writeback_control *wbc)
197{ 170{
198 if (wbc->for_reclaim) 171 if (wbc->for_reclaim)
@@ -356,11 +329,19 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
356/* 329/*
357 * Insert a write request into an inode 330 * Insert a write request into an inode
358 */ 331 */
359static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req) 332static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
360{ 333{
361 struct nfs_inode *nfsi = NFS_I(inode); 334 struct nfs_inode *nfsi = NFS_I(inode);
362 int error; 335 int error;
363 336
337 error = radix_tree_preload(GFP_NOFS);
338 if (error != 0)
339 goto out;
340
341 /* Lock the request! */
342 nfs_lock_request_dontget(req);
343
344 spin_lock(&inode->i_lock);
364 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req); 345 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req);
365 BUG_ON(error); 346 BUG_ON(error);
366 if (!nfsi->npages) { 347 if (!nfsi->npages) {
@@ -374,6 +355,10 @@ static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
374 kref_get(&req->wb_kref); 355 kref_get(&req->wb_kref);
375 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index, 356 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
376 NFS_PAGE_TAG_LOCKED); 357 NFS_PAGE_TAG_LOCKED);
358 spin_unlock(&inode->i_lock);
359 radix_tree_preload_end();
360out:
361 return error;
377} 362}
378 363
379/* 364/*
@@ -565,101 +550,121 @@ static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, pg
565#endif 550#endif
566 551
567/* 552/*
568 * Try to update any existing write request, or create one if there is none. 553 * Search for an existing write request, and attempt to update
569 * In order to match, the request's credentials must match those of 554 * it to reflect a new dirty region on a given page.
570 * the calling process.
571 * 555 *
572 * Note: Should always be called with the Page Lock held! 556 * If the attempt fails, then the existing request is flushed out
557 * to disk.
573 */ 558 */
574static struct nfs_page * nfs_update_request(struct nfs_open_context* ctx, 559static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
575 struct page *page, unsigned int offset, unsigned int bytes) 560 struct page *page,
561 unsigned int offset,
562 unsigned int bytes)
576{ 563{
577 struct address_space *mapping = page->mapping; 564 struct nfs_page *req;
578 struct inode *inode = mapping->host; 565 unsigned int rqend;
579 struct nfs_page *req, *new = NULL; 566 unsigned int end;
580 pgoff_t rqend, end; 567 int error;
568
569 if (!PagePrivate(page))
570 return NULL;
581 571
582 end = offset + bytes; 572 end = offset + bytes;
573 spin_lock(&inode->i_lock);
583 574
584 for (;;) { 575 for (;;) {
585 /* Loop over all inode entries and see if we find
586 * A request for the page we wish to update
587 */
588 spin_lock(&inode->i_lock);
589 req = nfs_page_find_request_locked(page); 576 req = nfs_page_find_request_locked(page);
590 if (req) { 577 if (req == NULL)
591 if (!nfs_set_page_tag_locked(req)) { 578 goto out_unlock;
592 int error; 579
593 580 rqend = req->wb_offset + req->wb_bytes;
594 spin_unlock(&inode->i_lock); 581 /*
595 error = nfs_wait_on_request(req); 582 * Tell the caller to flush out the request if
596 nfs_release_request(req); 583 * the offsets are non-contiguous.
597 if (error < 0) { 584 * Note: nfs_flush_incompatible() will already
598 if (new) { 585 * have flushed out requests having wrong owners.
599 radix_tree_preload_end(); 586 */
600 nfs_release_request(new); 587 if (!nfs_dirty_request(req)
601 } 588 || offset > rqend
602 return ERR_PTR(error); 589 || end < req->wb_offset)
603 } 590 goto out_flushme;
604 continue; 591
605 } 592 if (nfs_set_page_tag_locked(req))
606 spin_unlock(&inode->i_lock);
607 if (new) {
608 radix_tree_preload_end();
609 nfs_release_request(new);
610 }
611 break; 593 break;
612 }
613 594
614 if (new) { 595 /* The request is locked, so wait and then retry */
615 nfs_lock_request_dontget(new);
616 nfs_inode_add_request(inode, new);
617 spin_unlock(&inode->i_lock);
618 radix_tree_preload_end();
619 req = new;
620 goto out;
621 }
622 spin_unlock(&inode->i_lock); 596 spin_unlock(&inode->i_lock);
623 597 error = nfs_wait_on_request(req);
624 new = nfs_create_request(ctx, inode, page, offset, bytes); 598 nfs_release_request(req);
625 if (IS_ERR(new)) 599 if (error != 0)
626 return new; 600 goto out_err;
627 if (radix_tree_preload(GFP_NOFS)) { 601 spin_lock(&inode->i_lock);
628 nfs_release_request(new);
629 return ERR_PTR(-ENOMEM);
630 }
631 }
632
633 /* We have a request for our page.
634 * If the creds don't match, or the
635 * page addresses don't match,
636 * tell the caller to wait on the conflicting
637 * request.
638 */
639 rqend = req->wb_offset + req->wb_bytes;
640 if (req->wb_context != ctx
641 || req->wb_page != page
642 || !nfs_dirty_request(req)
643 || offset > rqend || end < req->wb_offset) {
644 nfs_clear_page_tag_locked(req);
645 return ERR_PTR(-EBUSY);
646 } 602 }
647 603
648 /* Okay, the request matches. Update the region */ 604 /* Okay, the request matches. Update the region */
649 if (offset < req->wb_offset) { 605 if (offset < req->wb_offset) {
650 req->wb_offset = offset; 606 req->wb_offset = offset;
651 req->wb_pgbase = offset; 607 req->wb_pgbase = offset;
652 req->wb_bytes = max(end, rqend) - req->wb_offset;
653 goto out;
654 } 608 }
655
656 if (end > rqend) 609 if (end > rqend)
657 req->wb_bytes = end - req->wb_offset; 610 req->wb_bytes = end - req->wb_offset;
611 else
612 req->wb_bytes = rqend - req->wb_offset;
613out_unlock:
614 spin_unlock(&inode->i_lock);
615 return req;
616out_flushme:
617 spin_unlock(&inode->i_lock);
618 nfs_release_request(req);
619 error = nfs_wb_page(inode, page);
620out_err:
621 return ERR_PTR(error);
622}
658 623
624/*
625 * Try to update an existing write request, or create one if there is none.
626 *
627 * Note: Should always be called with the Page Lock held to prevent races
628 * if we have to add a new request. Also assumes that the caller has
629 * already called nfs_flush_incompatible() if necessary.
630 */
631static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx,
632 struct page *page, unsigned int offset, unsigned int bytes)
633{
634 struct inode *inode = page->mapping->host;
635 struct nfs_page *req;
636 int error;
637
638 req = nfs_try_to_update_request(inode, page, offset, bytes);
639 if (req != NULL)
640 goto out;
641 req = nfs_create_request(ctx, inode, page, offset, bytes);
642 if (IS_ERR(req))
643 goto out;
644 error = nfs_inode_add_request(inode, req);
645 if (error != 0) {
646 nfs_release_request(req);
647 req = ERR_PTR(error);
648 }
659out: 649out:
660 return req; 650 return req;
661} 651}
662 652
653static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
654 unsigned int offset, unsigned int count)
655{
656 struct nfs_page *req;
657
658 req = nfs_setup_write_request(ctx, page, offset, count);
659 if (IS_ERR(req))
660 return PTR_ERR(req);
661 /* Update file length */
662 nfs_grow_file(page, offset, count);
663 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
664 nfs_clear_page_tag_locked(req);
665 return 0;
666}
667
663int nfs_flush_incompatible(struct file *file, struct page *page) 668int nfs_flush_incompatible(struct file *file, struct page *page)
664{ 669{
665 struct nfs_open_context *ctx = nfs_file_open_context(file); 670 struct nfs_open_context *ctx = nfs_file_open_context(file);
-mapping.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/scatterlist.h> #include "txx9dmac.h" static struct txx9dmac_chan *to_txx9dmac_chan(struct dma_chan *chan) { return container_of(chan, struct txx9dmac_chan, chan); } static struct txx9dmac_cregs __iomem *__dma_regs(const struct txx9dmac_chan *dc) { return dc->ch_regs; } static struct txx9dmac_cregs32 __iomem *__dma_regs32( const struct txx9dmac_chan *dc) { return dc->ch_regs; } #define channel64_readq(dc, name) \ __raw_readq(&(__dma_regs(dc)->name)) #define channel64_writeq(dc, name, val) \ __raw_writeq((val), &(__dma_regs(dc)->name)) #define channel64_readl(dc, name) \ __raw_readl(&(__dma_regs(dc)->name)) #define channel64_writel(dc, name, val) \ __raw_writel((val), &(__dma_regs(dc)->name)) #define channel32_readl(dc, name) \ __raw_readl(&(__dma_regs32(dc)->name)) #define channel32_writel(dc, name, val) \ __raw_writel((val), &(__dma_regs32(dc)->name)) #define channel_readq(dc, name) channel64_readq(dc, name) #define channel_writeq(dc, name, val) channel64_writeq(dc, name, val) #define channel_readl(dc, name) \ (is_dmac64(dc) ? \ channel64_readl(dc, name) : channel32_readl(dc, name)) #define channel_writel(dc, name, val) \ (is_dmac64(dc) ? \ channel64_writel(dc, name, val) : channel32_writel(dc, name, val)) static dma_addr_t channel64_read_CHAR(const struct txx9dmac_chan *dc) { if (sizeof(__dma_regs(dc)->CHAR) == sizeof(u64)) return channel64_readq(dc, CHAR); else return channel64_readl(dc, CHAR); } static void channel64_write_CHAR(const struct txx9dmac_chan *dc, dma_addr_t val) { if (sizeof(__dma_regs(dc)->CHAR) == sizeof(u64)) channel64_writeq(dc, CHAR, val); else channel64_writel(dc, CHAR, val); } static void channel64_clear_CHAR(const struct txx9dmac_chan *dc) { #if defined(CONFIG_32BIT) && !defined(CONFIG_64BIT_PHYS_ADDR) channel64_writel(dc, CHAR, 0); channel64_writel(dc, __pad_CHAR, 0); #else channel64_writeq(dc, CHAR, 0); #endif } static dma_addr_t channel_read_CHAR(const struct txx9dmac_chan *dc) { if (is_dmac64(dc)) return channel64_read_CHAR(dc); else return channel32_readl(dc, CHAR); } static void channel_write_CHAR(const struct txx9dmac_chan *dc, dma_addr_t val) { if (is_dmac64(dc)) channel64_write_CHAR(dc, val); else channel32_writel(dc, CHAR, val); } static struct txx9dmac_regs __iomem *__txx9dmac_regs( const struct txx9dmac_dev *ddev) { return ddev->regs; } static struct txx9dmac_regs32 __iomem *__txx9dmac_regs32( const struct txx9dmac_dev *ddev) { return ddev->regs; } #define dma64_readl(ddev, name) \ __raw_readl(&(__txx9dmac_regs(ddev)->name)) #define dma64_writel(ddev, name, val) \ __raw_writel((val), &(__txx9dmac_regs(ddev)->name)) #define dma32_readl(ddev, name) \ __raw_readl(&(__txx9dmac_regs32(ddev)->name)) #define dma32_writel(ddev, name, val) \ __raw_writel((val), &(__txx9dmac_regs32(ddev)->name)) #define dma_readl(ddev, name) \ (__is_dmac64(ddev) ? \ dma64_readl(ddev, name) : dma32_readl(ddev, name)) #define dma_writel(ddev, name, val) \ (__is_dmac64(ddev) ? \ dma64_writel(ddev, name, val) : dma32_writel(ddev, name, val)) static struct device *chan2dev(struct dma_chan *chan) { return &chan->dev->device; } static struct device *chan2parent(struct dma_chan *chan) { return chan->dev->device.parent; } static struct txx9dmac_desc * txd_to_txx9dmac_desc(struct dma_async_tx_descriptor *txd) { return container_of(txd, struct txx9dmac_desc, txd); } static dma_addr_t desc_read_CHAR(const struct txx9dmac_chan *dc, const struct txx9dmac_desc *desc) { return is_dmac64(dc) ? desc->hwdesc.CHAR : desc->hwdesc32.CHAR; } static void desc_write_CHAR(const struct txx9dmac_chan *dc, struct txx9dmac_desc *desc, dma_addr_t val) { if (is_dmac64(dc)) desc->hwdesc.CHAR = val; else desc->hwdesc32.CHAR = val; } #define TXX9_DMA_MAX_COUNT 0x04000000 #define TXX9_DMA_INITIAL_DESC_COUNT 64 static struct txx9dmac_desc *txx9dmac_first_active(struct txx9dmac_chan *dc) { return list_entry(dc->active_list.next, struct txx9dmac_desc, desc_node); } static struct txx9dmac_desc *txx9dmac_last_active(struct txx9dmac_chan *dc) { return list_entry(dc->active_list.prev, struct txx9dmac_desc, desc_node); } static struct txx9dmac_desc *txx9dmac_first_queued(struct txx9dmac_chan *dc) { return list_entry(dc->queue.next, struct txx9dmac_desc, desc_node); } static struct txx9dmac_desc *txx9dmac_last_child(struct txx9dmac_desc *desc) { if (!list_empty(&desc->tx_list)) desc = list_entry(desc->tx_list.prev, typeof(*desc), desc_node); return desc; } static dma_cookie_t txx9dmac_tx_submit(struct dma_async_tx_descriptor *tx); static struct txx9dmac_desc *txx9dmac_desc_alloc(struct txx9dmac_chan *dc, gfp_t flags) { struct txx9dmac_dev *ddev = dc->ddev; struct txx9dmac_desc *desc; desc = kzalloc(sizeof(*desc), flags); if (!desc) return NULL; INIT_LIST_HEAD(&desc->tx_list); dma_async_tx_descriptor_init(&desc->txd, &dc->chan); desc->txd.tx_submit = txx9dmac_tx_submit; /* txd.flags will be overwritten in prep funcs */ desc->txd.flags = DMA_CTRL_ACK; desc->txd.phys = dma_map_single(chan2parent(&dc->chan), &desc->hwdesc, ddev->descsize, DMA_TO_DEVICE); return desc; } static struct txx9dmac_desc *txx9dmac_desc_get(struct txx9dmac_chan *dc) { struct txx9dmac_desc *desc, *_desc; struct txx9dmac_desc *ret = NULL; unsigned int i = 0; spin_lock_bh(&dc->lock); list_for_each_entry_safe(desc, _desc, &dc->free_list, desc_node) { if (async_tx_test_ack(&desc->txd)) { list_del(&desc->desc_node); ret = desc; break; } dev_dbg(chan2dev(&dc->chan), "desc %p not ACKed\n", desc); i++; } spin_unlock_bh(&dc->lock); dev_vdbg(chan2dev(&dc->chan), "scanned %u descriptors on freelist\n", i); if (!ret) { ret = txx9dmac_desc_alloc(dc, GFP_ATOMIC); if (ret) { spin_lock_bh(&dc->lock); dc->descs_allocated++; spin_unlock_bh(&dc->lock); } else dev_err(chan2dev(&dc->chan), "not enough descriptors available\n"); } return ret; } static void txx9dmac_sync_desc_for_cpu(struct txx9dmac_chan *dc, struct txx9dmac_desc *desc) { struct txx9dmac_dev *ddev = dc->ddev; struct txx9dmac_desc *child; list_for_each_entry(child, &desc->tx_list, desc_node) dma_sync_single_for_cpu(chan2parent(&dc->chan), child->txd.phys, ddev->descsize, DMA_TO_DEVICE); dma_sync_single_for_cpu(chan2parent(&dc->chan), desc->txd.phys, ddev->descsize, DMA_TO_DEVICE); } /* * Move a descriptor, including any children, to the free list. * `desc' must not be on any lists. */ static void txx9dmac_desc_put(struct txx9dmac_chan *dc, struct txx9dmac_desc *desc) { if (desc) { struct txx9dmac_desc *child; txx9dmac_sync_desc_for_cpu(dc, desc); spin_lock_bh(&dc->lock); list_for_each_entry(child, &desc->tx_list, desc_node) dev_vdbg(chan2dev(&dc->chan), "moving child desc %p to freelist\n", child); list_splice_init(&desc->tx_list, &dc->free_list); dev_vdbg(chan2dev(&dc->chan), "moving desc %p to freelist\n", desc); list_add(&desc->desc_node, &dc->free_list); spin_unlock_bh(&dc->lock); } } /* Called with dc->lock held and bh disabled */ static dma_cookie_t txx9dmac_assign_cookie(struct txx9dmac_chan *dc, struct txx9dmac_desc *desc) { dma_cookie_t cookie = dc->chan.cookie; if (++cookie < 0) cookie = 1; dc->chan.cookie = cookie; desc->txd.cookie = cookie; return cookie; } /*----------------------------------------------------------------------*/ static void txx9dmac_dump_regs(struct txx9dmac_chan *dc) { if (is_dmac64(dc)) dev_err(chan2dev(&dc->chan), " CHAR: %#llx SAR: %#llx DAR: %#llx CNTR: %#x" " SAIR: %#x DAIR: %#x CCR: %#x CSR: %#x\n", (u64)channel64_read_CHAR(dc), channel64_readq(dc, SAR), channel64_readq(dc, DAR), channel64_readl(dc, CNTR), channel64_readl(dc, SAIR), channel64_readl(dc, DAIR), channel64_readl(dc, CCR), channel64_readl(dc, CSR)); else dev_err(chan2dev(&dc->chan), " CHAR: %#x SAR: %#x DAR: %#x CNTR: %#x" " SAIR: %#x DAIR: %#x CCR: %#x CSR: %#x\n", channel32_readl(dc, CHAR), channel32_readl(dc, SAR), channel32_readl(dc, DAR), channel32_readl(dc, CNTR), channel32_readl(dc, SAIR), channel32_readl(dc, DAIR), channel32_readl(dc, CCR), channel32_readl(dc, CSR)); } static void txx9dmac_reset_chan(struct txx9dmac_chan *dc) { channel_writel(dc, CCR, TXX9_DMA_CCR_CHRST); if (is_dmac64(dc)) { channel64_clear_CHAR(dc); channel_writeq(dc, SAR, 0); channel_writeq(dc, DAR, 0); } else { channel_writel(dc, CHAR, 0); channel_writel(dc, SAR, 0); channel_writel(dc, DAR, 0); } channel_writel(dc, CNTR, 0); channel_writel(dc, SAIR, 0); channel_writel(dc, DAIR, 0); channel_writel(dc, CCR, 0); mmiowb(); } /* Called with dc->lock held and bh disabled */ static void txx9dmac_dostart(struct txx9dmac_chan *dc, struct txx9dmac_desc *first) { struct txx9dmac_slave *ds = dc->chan.private; u32 sai, dai; dev_vdbg(chan2dev(&dc->chan), "dostart %u %p\n", first->txd.cookie, first); /* ASSERT: channel is idle */ if (channel_readl(dc, CSR) & TXX9_DMA_CSR_XFACT) { dev_err(chan2dev(&dc->chan), "BUG: Attempted to start non-idle channel\n"); txx9dmac_dump_regs(dc); /* The tasklet will hopefully advance the queue... */ return; } if (is_dmac64(dc)) { channel64_writel(dc, CNTR, 0); channel64_writel(dc, CSR, 0xffffffff); if (ds) { if (ds->tx_reg) { sai = ds->reg_width; dai = 0; } else { sai = 0; dai = ds->reg_width; } } else { sai = 8; dai = 8; } channel64_writel(dc, SAIR, sai); channel64_writel(dc, DAIR, dai); /* All 64-bit DMAC supports SMPCHN */ channel64_writel(dc, CCR, dc->ccr); /* Writing a non zero value to CHAR will assert XFACT */ channel64_write_CHAR(dc, first->txd.phys); } else { channel32_writel(dc, CNTR, 0); channel32_writel(dc, CSR, 0xffffffff); if (ds) { if (ds->tx_reg) { sai = ds->reg_width; dai = 0; } else { sai = 0; dai = ds->reg_width; } } else { sai = 4; dai = 4; } channel32_writel(dc, SAIR, sai); channel32_writel(dc, DAIR, dai); if (txx9_dma_have_SMPCHN()) { channel32_writel(dc, CCR, dc->ccr); /* Writing a non zero value to CHAR will assert XFACT */ channel32_writel(dc, CHAR, first->txd.phys); } else { channel32_writel(dc, CHAR, first->txd.phys); channel32_writel(dc, CCR, dc->ccr); } } } /*----------------------------------------------------------------------*/ static void txx9dmac_descriptor_complete(struct txx9dmac_chan *dc, struct txx9dmac_desc *desc) { dma_async_tx_callback callback; void *param; struct dma_async_tx_descriptor *txd = &desc->txd; struct txx9dmac_slave *ds = dc->chan.private; dev_vdbg(chan2dev(&dc->chan), "descriptor %u %p complete\n", txd->cookie, desc); dc->completed = txd->cookie; callback = txd->callback; param = txd->callback_param; txx9dmac_sync_desc_for_cpu(dc, desc); list_splice_init(&desc->tx_list, &dc->free_list); list_move(&desc->desc_node, &dc->free_list); if (!ds) { dma_addr_t dmaaddr; if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) { dmaaddr = is_dmac64(dc) ? desc->hwdesc.DAR : desc->hwdesc32.DAR; if (txd->flags & DMA_COMPL_DEST_UNMAP_SINGLE) dma_unmap_single(chan2parent(&dc->chan), dmaaddr, desc->len, DMA_FROM_DEVICE); else dma_unmap_page(chan2parent(&dc->chan), dmaaddr, desc->len, DMA_FROM_DEVICE); } if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP)) { dmaaddr = is_dmac64(dc) ? desc->hwdesc.SAR : desc->hwdesc32.SAR; if (txd->flags & DMA_COMPL_SRC_UNMAP_SINGLE) dma_unmap_single(chan2parent(&dc->chan), dmaaddr, desc->len, DMA_TO_DEVICE); else dma_unmap_page(chan2parent(&dc->chan), dmaaddr, desc->len, DMA_TO_DEVICE); } } /* * The API requires that no submissions are done from a * callback, so we don't need to drop the lock here */ if (callback) callback(param); dma_run_dependencies(txd); } static void txx9dmac_dequeue(struct txx9dmac_chan *dc, struct list_head *list) { struct txx9dmac_dev *ddev = dc->ddev; struct txx9dmac_desc *desc; struct txx9dmac_desc *prev = NULL; BUG_ON(!list_empty(list)); do { desc = txx9dmac_first_queued(dc); if (prev) { desc_write_CHAR(dc, prev, desc->txd.phys); dma_sync_single_for_device(chan2parent(&dc->chan), prev->txd.phys, ddev->descsize, DMA_TO_DEVICE); } prev = txx9dmac_last_child(desc); list_move_tail(&desc->desc_node, list); /* Make chain-completion interrupt happen */ if ((desc->txd.flags & DMA_PREP_INTERRUPT) && !txx9dmac_chan_INTENT(dc)) break; } while (!list_empty(&dc->queue)); } static void txx9dmac_complete_all(struct txx9dmac_chan *dc) { struct txx9dmac_desc *desc, *_desc; LIST_HEAD(list); /* * Submit queued descriptors ASAP, i.e. before we go through * the completed ones. */ list_splice_init(&dc->active_list, &list); if (!list_empty(&dc->queue)) { txx9dmac_dequeue(dc, &dc->active_list); txx9dmac_dostart(dc, txx9dmac_first_active(dc)); } list_for_each_entry_safe(desc, _desc, &list, desc_node) txx9dmac_descriptor_complete(dc, desc); } static void txx9dmac_dump_desc(struct txx9dmac_chan *dc, struct txx9dmac_hwdesc *desc) { if (is_dmac64(dc)) { #ifdef TXX9_DMA_USE_SIMPLE_CHAIN dev_crit(chan2dev(&dc->chan), " desc: ch%#llx s%#llx d%#llx c%#x\n", (u64)desc->CHAR, desc->SAR, desc->DAR, desc->CNTR); #else dev_crit(chan2dev(&dc->chan), " desc: ch%#llx s%#llx d%#llx c%#x" " si%#x di%#x cc%#x cs%#x\n", (u64)desc->CHAR, desc->SAR, desc->DAR, desc->CNTR, desc->SAIR, desc->DAIR, desc->CCR, desc->CSR); #endif } else { struct txx9dmac_hwdesc32 *d = (struct txx9dmac_hwdesc32 *)desc; #ifdef TXX9_DMA_USE_SIMPLE_CHAIN dev_crit(chan2dev(&dc->chan), " desc: ch%#x s%#x d%#x c%#x\n", d->CHAR, d->SAR, d->DAR, d->CNTR); #else dev_crit(chan2dev(&dc->chan), " desc: ch%#x s%#x d%#x c%#x" " si%#x di%#x cc%#x cs%#x\n", d->CHAR, d->SAR, d->DAR, d->CNTR, d->SAIR, d->DAIR, d->CCR, d->CSR); #endif } } static void txx9dmac_handle_error(struct txx9dmac_chan *dc, u32 csr) { struct txx9dmac_desc *bad_desc; struct txx9dmac_desc *child; u32 errors; /* * The descriptor currently at the head of the active list is * borked. Since we don't have any way to report errors, we'll * just have to scream loudly and try to carry on. */ dev_crit(chan2dev(&dc->chan), "Abnormal Chain Completion\n"); txx9dmac_dump_regs(dc); bad_desc = txx9dmac_first_active(dc); list_del_init(&bad_desc->desc_node); /* Clear all error flags and try to restart the controller */ errors = csr & (TXX9_DMA_CSR_ABCHC | TXX9_DMA_CSR_CFERR | TXX9_DMA_CSR_CHERR | TXX9_DMA_CSR_DESERR | TXX9_DMA_CSR_SORERR); channel_writel(dc, CSR, errors); if (list_empty(&dc->active_list) && !list_empty(&dc->queue)) txx9dmac_dequeue(dc, &dc->active_list); if (!list_empty(&dc->active_list)) txx9dmac_dostart(dc, txx9dmac_first_active(dc)); dev_crit(chan2dev(&dc->chan), "Bad descriptor submitted for DMA! (cookie: %d)\n", bad_desc->txd.cookie); txx9dmac_dump_desc(dc, &bad_desc->hwdesc); list_for_each_entry(child, &bad_desc->tx_list, desc_node) txx9dmac_dump_desc(dc, &child->hwdesc); /* Pretend the descriptor completed successfully */ txx9dmac_descriptor_complete(dc, bad_desc); } static void txx9dmac_scan_descriptors(struct txx9dmac_chan *dc) { dma_addr_t chain; struct txx9dmac_desc *desc, *_desc; struct txx9dmac_desc *child; u32 csr; if (is_dmac64(dc)) { chain = channel64_read_CHAR(dc); csr = channel64_readl(dc, CSR); channel64_writel(dc, CSR, csr); } else { chain = channel32_readl(dc, CHAR); csr = channel32_readl(dc, CSR); channel32_writel(dc, CSR, csr); } /* For dynamic chain, we should look at XFACT instead of NCHNC */ if (!(csr & (TXX9_DMA_CSR_XFACT | TXX9_DMA_CSR_ABCHC))) { /* Everything we've submitted is done */ txx9dmac_complete_all(dc); return; } if (!(csr & TXX9_DMA_CSR_CHNEN)) chain = 0; /* last descriptor of this chain */ dev_vdbg(chan2dev(&dc->chan), "scan_descriptors: char=%#llx\n", (u64)chain); list_for_each_entry_safe(desc, _desc, &dc->active_list, desc_node) { if (desc_read_CHAR(dc, desc) == chain) { /* This one is currently in progress */ if (csr & TXX9_DMA_CSR_ABCHC) goto scan_done; return; } list_for_each_entry(child, &desc->tx_list, desc_node) if (desc_read_CHAR(dc, child) == chain) { /* Currently in progress */ if (csr & TXX9_DMA_CSR_ABCHC) goto scan_done; return; } /* * No descriptors so far seem to be in progress, i.e. * this one must be done.