From patchwork Mon Jul 31 22:24:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 9873203 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 355166038F for ; Mon, 31 Jul 2017 22:25:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24C1728599 for ; Mon, 31 Jul 2017 22:25:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18B96285FB; Mon, 31 Jul 2017 22:25:30 +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=ham 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 6BD7F28599 for ; Mon, 31 Jul 2017 22:25:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DC1C821D49C65; Mon, 31 Jul 2017 15:22:27 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 ED64A21D4919D for ; Mon, 31 Jul 2017 15:22:26 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP; 31 Jul 2017 15:24:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,304,1498546800"; d="scan'208";a="134238937" Received: from djiang5-desk3.ch.intel.com ([143.182.137.38]) by fmsmga006.fm.intel.com with ESMTP; 31 Jul 2017 15:24:35 -0700 Subject: [PATCH 3/5] dmaengine: add SG support to dmaengine_unmap From: Dave Jiang To: vinod.koul@intel.com, dan.j.williams@intel.com Date: Mon, 31 Jul 2017 15:24:35 -0700 Message-ID: <150153987513.49768.17123101509082248111.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <150153948477.49768.5767882242140065474.stgit@djiang5-desk3.ch.intel.com> References: <150153948477.49768.5767882242140065474.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, linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This should provide support to unmap scatterlist with the dmaengine_unmap_data. We will support only 1 scatterlist per direction. The DMA addresses array has been overloaded for the 2 or less entries DMA unmap data structure in order to store the SG pointer(s). Signed-off-by: Dave Jiang --- drivers/dma/dmaengine.c | 45 ++++++++++++++++++++++++++++++++++++--------- include/linux/dmaengine.h | 4 ++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index d9118ec..81d10c97 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -1126,16 +1126,35 @@ 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; + int cnt, i, sg_nents; + struct scatterlist *sg; + + sg_nents = dma_unmap_data_sg_to_nents(unmap, unmap->map_cnt); + if (sg_nents) { + i = 0; + cnt = 1; + sg = (struct scatterlist *)unmap->addr[i]; + dma_unmap_sg(dev, sg, sg_nents, DMA_TO_DEVICE); + } else { + cnt = unmap->to_cnt; + for (i = 0; i < cnt; i++) + dma_unmap_page(dev, unmap->addr[i], unmap->len, + DMA_TO_DEVICE); + } + + sg_nents = dma_unmap_data_sg_from_nents(unmap, unmap->map_cnt); + if (sg_nents) { + sg = (struct scatterlist *)unmap->addr[i]; + dma_unmap_sg(dev, sg, sg_nents, DMA_FROM_DEVICE); + cnt++; + i++; + } else { + cnt += unmap->from_cnt; + for (; i < cnt; i++) + dma_unmap_page(dev, unmap->addr[i], unmap->len, + DMA_FROM_DEVICE); + } - cnt = unmap->to_cnt; - for (i = 0; i < cnt; i++) - dma_unmap_page(dev, unmap->addr[i], unmap->len, - DMA_TO_DEVICE); - cnt += unmap->from_cnt; - for (; i < cnt; i++) - dma_unmap_page(dev, unmap->addr[i], unmap->len, - DMA_FROM_DEVICE); cnt += unmap->bidi_cnt; for (; i < cnt; i++) { if (unmap->addr[i] == 0) @@ -1179,6 +1198,10 @@ static int __init dmaengine_init_unmap_pool(void) size = sizeof(struct dmaengine_unmap_data) + sizeof(dma_addr_t) * p->size; + /* add 2 more entries for SG nents overload */ + if (i == 0) + size += sizeof(dma_addr_t) * 2; + p->cache = kmem_cache_create(p->name, size, 0, SLAB_HWCACHE_ALIGN, NULL); if (!p->cache) @@ -1205,6 +1228,10 @@ dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags) return NULL; memset(unmap, 0, sizeof(*unmap)); + /* clear the overloaded sg nents entries */ + if (nr < 3) + memset(&unmap->addr[nr], 0, + DMA_UNMAP_SG_ENTS * sizeof(dma_addr_t)); kref_init(&unmap->kref); unmap->dev = dev; unmap->map_cnt = nr; diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index 6202e7c..ec65b9b 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -475,6 +475,10 @@ struct dmaengine_unmap_data { dma_addr_t addr[0]; }; +#define DMA_UNMAP_SG_ENTS 2 +#define dma_unmap_data_sg_to_nents(x, n) x->addr[n] +#define dma_unmap_data_sg_from_nents(x, n) x->addr[n+1] + /** * struct dma_async_tx_descriptor - async transaction descriptor * ---dma generic offload fields---