Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1516019imm; Wed, 8 Aug 2018 19:34:14 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzFLCaZMPKSlmpH9tOCVGxPvwBpPHpZYqw6TWy9tA1UEbv+qYoE0pEnBqTm1uM94ZvnjHdc X-Received: by 2002:a17:902:6684:: with SMTP id e4-v6mr246994plk.35.1533782054032; Wed, 08 Aug 2018 19:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533782054; cv=none; d=google.com; s=arc-20160816; b=wGwIdR6z1MF73pb4ZKl+NoljsIxjGORYfFg6wTduU3j4UUPlIXjI+E/eF4uZe7bR2Y iO8/iA1tgiwowaOYbksZu4qaEG4MnjXC7gJoAe6F7xNUNmHc2T/KFqxh8XSDFMwNZnhP m0lrTqM5nccmhwNnwlCv2w75PTqiBRcfJmM7T//WZKPgc4fM0yIJjpiPKluJ/139/laR 1QO59kgohiU4flVJLA3mOmkkDSM8ds2Wy6lV1iBcb5DmwyntOOdbDXzd2DUslt+EKUZm QkF7hIRR/jxriFqNptYX+NgXb5zWEZSOZHqlJwYev5ORJoni/g0OFdAnKJpFNmc6MBgt X1pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=x2jA0t9/6ni8qxyg+P+vgZ6M6yTisdf1NTk6d8xkhWs=; b=dSN3OcLbH2gaLrVqF+/XFEUWFFlBGDmwlEpxhI4hn4wRL7ZuZSlgX6UWik3o9ttLZQ 9HzJqEA4pMeoRL2ACSGfMcbYlWqJ03w8NKAJVBfveBWv2vWcKjRIYXeho0XRq2PYhIjY nF/9e1Pc04UWVkfyO+PWk7Idk+cMkfevwODjAHqkxrZrGpWKywU3NdrSiSSiDR7zCUtI yz39UZq0uxuGR1j4Gaxj7iQ5f6gBBbtPmQu4uiqPExgHVDV47QKPmD0RS61jXlciM1bH gRiLenV4GWXVFSWpeq6ZnuIQ5HtYDmiQkmxkvvcWO/c1ifeCWUejVVAZHqmfpRxY9R2n TgDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="pYeu/RF2"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b13-v6si5561566pgh.255.2018.08.08.19.33.59; Wed, 08 Aug 2018 19:34:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="pYeu/RF2"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727557AbeHIEyx (ORCPT + 99 others); Thu, 9 Aug 2018 00:54:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:54210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbeHIEyx (ORCPT ); Thu, 9 Aug 2018 00:54:53 -0400 Received: from localhost (unknown [122.167.122.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 656B821C16; Thu, 9 Aug 2018 02:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1533781944; bh=Kh9QLmQCs+iqX5c7pmkk4iAxFS/9BJ7iOaQbIrYikR8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pYeu/RF2Z1cJr4k8/gwy4ZSyr8xiXdIYQXU99RBeoYrbieXzcukij33otW0vzumXY vgkJVHmOPqJbVaV+ctWDxPyIiCAqPkAcN5MT67qhaKz13y/W65h9lAUvem1b01Ifyg REnAvavoekvmZR8d7MNBA+VXSA4c+MB+IL7V3/G0= Date: Thu, 9 Aug 2018 08:02:15 +0530 From: Vinod To: Baolin Wang Cc: dan.j.williams@intel.com, eric.long@spreadtrum.com, broonie@kernel.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] dmaengine: sprd: Support DMA link-list mode Message-ID: <20180809023215.GO2395@vkoul-mobl> References: <78730daa2eaa66fa8089f196a52b51ce62579d1f.1532591566.git.baolin.wang@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <78730daa2eaa66fa8089f196a52b51ce62579d1f.1532591566.git.baolin.wang@linaro.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26-07-18, 16:00, Baolin Wang wrote: > From: Eric Long > > The Spreadtrum DMA can support the link-list transaction mode, which means > DMA controller can do transaction one by one automatically once we linked > these transaction by link-list register. > > Signed-off-by: Eric Long > Signed-off-by: Baolin Wang > --- > drivers/dma/sprd-dma.c | 82 ++++++++++++++++++++++++++++++++++++++---- > include/linux/dma/sprd-dma.h | 69 +++++++++++++++++++++++++++++++++++ > 2 files changed, 144 insertions(+), 7 deletions(-) > > diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c > index 55df0d4..649bd2c 100644 > --- a/drivers/dma/sprd-dma.c > +++ b/drivers/dma/sprd-dma.c > @@ -68,6 +68,7 @@ > > /* SPRD_DMA_CHN_CFG register definition */ > #define SPRD_DMA_CHN_EN BIT(0) > +#define SPRD_DMA_LINKLIST_EN BIT(4) > #define SPRD_DMA_WAIT_BDONE_OFFSET 24 > #define SPRD_DMA_DONOT_WAIT_BDONE 1 > > @@ -103,7 +104,7 @@ > #define SPRD_DMA_REQ_MODE_MASK GENMASK(1, 0) > #define SPRD_DMA_FIX_SEL_OFFSET 21 > #define SPRD_DMA_FIX_EN_OFFSET 20 > -#define SPRD_DMA_LLIST_END_OFFSET 19 > +#define SPRD_DMA_LLIST_END BIT(19) > #define SPRD_DMA_FRG_LEN_MASK GENMASK(16, 0) > > /* SPRD_DMA_CHN_BLK_LEN register definition */ > @@ -164,6 +165,7 @@ struct sprd_dma_desc { > struct sprd_dma_chn { > struct virt_dma_chan vc; > void __iomem *chn_base; > + struct sprd_dma_linklist linklist; > struct dma_slave_config slave_cfg; > u32 chn_num; > u32 dev_id; > @@ -582,7 +584,8 @@ static int sprd_dma_get_step(enum dma_slave_buswidth buswidth) > } > > static int sprd_dma_fill_desc(struct dma_chan *chan, > - struct sprd_dma_desc *sdesc, > + struct sprd_dma_chn_hw *hw, > + unsigned int sglen, int sg_index, > dma_addr_t src, dma_addr_t dst, u32 len, > enum dma_transfer_direction dir, > unsigned long flags, > @@ -590,7 +593,6 @@ static int sprd_dma_fill_desc(struct dma_chan *chan, > { > struct sprd_dma_dev *sdev = to_sprd_dma_dev(chan); > struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); > - struct sprd_dma_chn_hw *hw = &sdesc->chn_hw; > u32 req_mode = (flags >> SPRD_DMA_REQ_SHIFT) & SPRD_DMA_REQ_MODE_MASK; > u32 int_mode = flags & SPRD_DMA_INT_MASK; > int src_datawidth, dst_datawidth, src_step, dst_step; > @@ -670,12 +672,58 @@ static int sprd_dma_fill_desc(struct dma_chan *chan, > temp |= (src_step & SPRD_DMA_TRSF_STEP_MASK) << SPRD_DMA_SRC_TRSF_STEP_OFFSET; > hw->trsf_step = temp; > > + /* link-list configuration */ > + if (schan->linklist.phy_addr) { > + if (sg_index == sglen - 1) > + hw->frg_len |= SPRD_DMA_LLIST_END; > + > + hw->cfg |= SPRD_DMA_LINKLIST_EN; > + hw->llist_ptr = schan->linklist.phy_addr + > + ((sg_index + 1) % sglen) * sizeof(*hw) + > + SPRD_DMA_CHN_SRC_ADDR; > + } else { > + hw->llist_ptr = 0; > + } > + > hw->frg_step = 0; > hw->src_blk_step = 0; > hw->des_blk_step = 0; > return 0; > } > > +static int sprd_dma_fill_linklist_desc(struct dma_chan *chan, > + unsigned int sglen, int sg_index, > + dma_addr_t src, dma_addr_t dst, u32 len, > + enum dma_transfer_direction dir, > + unsigned long flags, > + struct dma_slave_config *slave_cfg) > +{ > + struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); > + struct sprd_dma_chn_hw *hw; > + > + if (sglen < 2 || !schan->linklist.virt_addr) > + return -EINVAL; why the limitation of 2 here? > + > + hw = (struct sprd_dma_chn_hw *)(schan->linklist.virt_addr + > + sg_index * sizeof(*hw)); > + > + return sprd_dma_fill_desc(chan, hw, sglen, sg_index, src, dst, len, dir, > + flags, slave_cfg); > +} > + > +static int sprd_dma_fill_chn_desc(struct dma_chan *chan, > + struct sprd_dma_desc *sdesc, > + dma_addr_t src, dma_addr_t dst, u32 len, > + enum dma_transfer_direction dir, > + unsigned long flags, > + struct dma_slave_config *slave_cfg) > +{ > + struct sprd_dma_chn_hw *hw = &sdesc->chn_hw; > + > + return sprd_dma_fill_desc(chan, hw, 0, 0, src, dst, len, dir, > + flags, slave_cfg); > +} this fn does not do much, so why not call sprd_dma_fill_desc() instead from caller! > + > static struct dma_async_tx_descriptor * > sprd_dma_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, > size_t len, unsigned long flags) > @@ -744,10 +792,20 @@ static int sprd_dma_fill_desc(struct dma_chan *chan, > u32 len = 0; > int ret, i; > > - /* TODO: now we only support one sg for each DMA configuration. */ > - if (!is_slave_direction(dir) || sglen > 1) > + if (!is_slave_direction(dir)) > return NULL; > > + if (context) { > + struct sprd_dma_linklist *ll_cfg = > + (struct sprd_dma_linklist *)context; > + > + schan->linklist.phy_addr = ll_cfg->phy_addr; > + schan->linklist.virt_addr = ll_cfg->virt_addr; > + } else { > + schan->linklist.phy_addr = 0; > + schan->linklist.virt_addr = 0; > + } > + > sdesc = kzalloc(sizeof(*sdesc), GFP_NOWAIT); > if (!sdesc) > return NULL; > @@ -762,10 +820,20 @@ static int sprd_dma_fill_desc(struct dma_chan *chan, > src = slave_cfg->src_addr; > dst = sg_dma_address(sg); > } > + > + if (sglen < 2) > + break; ? > + > + ret = sprd_dma_fill_linklist_desc(chan, sglen, i, src, dst, len, > + dir, flags, slave_cfg); > + if (ret) { > + kfree(sdesc); > + return NULL; > + } > } > > - ret = sprd_dma_fill_desc(chan, sdesc, src, dst, len, dir, flags, > - slave_cfg); > + ret = sprd_dma_fill_chn_desc(chan, sdesc, src, dst, len, dir, flags, > + slave_cfg); > if (ret) { > kfree(sdesc); > return NULL; > diff --git a/include/linux/dma/sprd-dma.h b/include/linux/dma/sprd-dma.h > index b0115e3..c51c705 100644 > --- a/include/linux/dma/sprd-dma.h > +++ b/include/linux/dma/sprd-dma.h > @@ -58,4 +58,73 @@ enum sprd_dma_int_type { > SPRD_DMA_CFGERR_INT, > }; > > +/* > + * struct sprd_dma_linklist - DMA link-list address structure > + * @virt_addr: link-list virtual address to configure link-list node > + * @phy_addr: link-list physical address to link DMA transfer > + * > + * The Spreadtrum DMA controller supports the link-list mode, that means slaves > + * can supply several groups configurations (each configuration represents one > + * DMA transfer) saved in memory, and DMA controller will link these groups > + * configurations by writing the physical address of each configuration into the > + * link-list register. > + * > + * Just as shown below, the link-list pointer register will be pointed to the > + * phycial address of 'configuration 1', and the 'configuration 1' link-list /s/phycial/physical > + * pointer will be pointed to 'configuration 2', and so on. > + * Once trigger the DMA transfer, the DMA controller will load 'configureation /s/configureation/configuration > + * 1' to its registers automatically, after 'configuration 1' transation is /s/transation/transaction > + * done, DMA controller will load 'configuration 2' automatically, until all > + * DMA transactions are done. > + * > + * Note: The last link-list pointer should point to the physical address > + * of 'configuration 1', which can avoid DMA controller loads incorrect > + * configuration when the last configuration transaction is done. > + * > + * DMA controller linklist memory > + * ====================== ----------------------- > + *| | | configuration 1 |<--- > + *| DMA controller | ------->| | | > + *| | | | | | > + *| | | | | | > + *| | | | | | > + *| linklist pointer reg |---- ----| linklist pointer | | > + * ====================== | ----------------------- | > + * | | > + * | ----------------------- | > + * | | configuration 2 | | > + * --->| | | > + * | | | > + * | | | > + * | | | > + * ----| linklist pointer | | > + * | ----------------------- | > + * | | > + * | ----------------------- | > + * | | configuration 3 | | > + * --->| | | > + * | | | > + * | . | | > + * . | > + * . | > + * . | > + * | . | > + * | ----------------------- | > + * | | configuration n | | > + * --->| | | > + * | | | > + * | | | > + * | | | > + * | linklist pointer |---- > + * ----------------------- > + * > + * To support the link-list mode, DMA slaves should allocate one segment memory > + * from always-on IRAM or dma coherent memory to store these groups of DMA > + * configuration, and pass the virtual and physical addess to DMA controller. /s/addess/address > + */ > +struct sprd_dma_linklist { > + unsigned long virt_addr; > + phys_addr_t phy_addr; > +}; > + > #endif > -- > 1.7.9.5 -- ~Vinod