From patchwork Mon Aug 21 21:11:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 9913819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DCEC7603FF for ; Mon, 21 Aug 2017 21:11:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEE1128799 for ; Mon, 21 Aug 2017 21:11:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3E53287C3; Mon, 21 Aug 2017 21:11:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8B83D287DE for ; Mon, 21 Aug 2017 21:11:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6E9D421E7903C; Mon, 21 Aug 2017 14:08:39 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2415C21E79010 for ; Mon, 21 Aug 2017 14:08:38 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Aug 2017 14:11:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,409,1498546800"; d="scan'208"; a="1186638208" Received: from djiang5-desk3.ch.intel.com ([143.182.137.38]) by fmsmga001.fm.intel.com with ESMTP; 21 Aug 2017 14:11:09 -0700 Subject: [PATCH v5 6/7] dmaengine: add SG support to dmaengine_unmap From: Dave Jiang To: vinod.koul@intel.com, dan.j.williams@intel.com Date: Mon, 21 Aug 2017 14:11:09 -0700 Message-ID: <150334986946.55214.3540641512473593212.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <150333903164.55214.3813479680626005389.stgit@djiang5-desk3.ch.intel.com> References: <150333903164.55214.3813479680626005389.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dmaengine@vger.kernel.org, hch@infradead.org, linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This provides support to unmap scatterlist with the dmaengine_unmap_data. We will support only 1 scatterlist per direction. Signed-off-by: Dave Jiang --- drivers/dma/dmaengine.c | 27 +++++++++++++++++++++++++++ include/linux/dmaengine.h | 13 ++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 40a035e..09ee03d 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -1124,12 +1124,39 @@ static struct dmaengine_unmap_pool *__get_unmap_pool(int nr) } } +static void dmaengine_unmap_sg(struct dmaengine_unmap_data *unmap) +{ + struct device *dev = unmap->dev; + + if (unmap->to_sg) { + dma_unmap_sg(dev, unmap->unmap_sg.sg, + unmap->sg_nents, DMA_TO_DEVICE); + + dma_unmap_page(dev, unmap->unmap_sg.buf_phys, unmap->len, + DMA_FROM_DEVICE); + } + + if (unmap->from_sg) { + dma_unmap_page(dev, unmap->unmap_sg.buf_phys, unmap->len, + DMA_TO_DEVICE); + dma_unmap_sg(dev, unmap->unmap_sg.sg, + unmap->sg_nents, DMA_FROM_DEVICE); + } + + mempool_free(unmap, __get_unmap_pool(unmap->map_cnt)->pool); +} + static void dmaengine_unmap(struct kref *kref) { struct dmaengine_unmap_data *unmap = container_of(kref, typeof(*unmap), kref); struct device *dev = unmap->dev; int cnt, i; + if (unmap->to_sg || unmap->from_sg) { + dmaengine_unmap_sg(unmap); + return; + } + cnt = unmap->to_cnt; for (i = 0; i < cnt; i++) dma_unmap_page(dev, unmap->addr[i], unmap->len, diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index 53356c4..fc53854 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -464,15 +464,26 @@ struct dmaengine_result { typedef void (*dma_async_tx_callback_result)(void *dma_async_param, const struct dmaengine_result *result); +struct dmaengine_unmap_sg { + struct scatterlist *sg; + dma_addr_t buf_phys; +}; + struct dmaengine_unmap_data { u8 map_cnt; u8 to_cnt; + u8 to_sg; u8 from_cnt; + u8 from_sg; u8 bidi_cnt; + int sg_nents; struct device *dev; struct kref kref; size_t len; - dma_addr_t addr[0]; + union { + struct dmaengine_unmap_sg unmap_sg; + dma_addr_t addr[0]; + }; }; /**