From patchwork Fri May 4 08:01:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 134965 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp537712lji; Fri, 4 May 2018 01:02:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZryyoOrlsW51ONr24L/cwS2/8Y1LJeWiGaYKJGgt2h7vGqzcf7vq3WfqUch3i8VoLkhRr+g X-Received: by 2002:a65:6498:: with SMTP id e24-v6mr2847124pgv.360.1525420971445; Fri, 04 May 2018 01:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525420971; cv=none; d=google.com; s=arc-20160816; b=ekOfd3L6KANCWRmj8zrDuk6ndbAKWFp0vHUVOWXRuMo37RQy3iHHSviFBsO2dcy/qe Yea8pMOWKadgoaDRTVYgw4LIYRrM9H4r7Ibwcy+E2wUMnkt0U3EcVgICidJcQp+wCuFX g6pQfY2Kgyv3O5JTSZtrATqVtj1MNmq2gw6MrIRdzPeHmQVFxbGmySo7n36x3ttUElJA 6bXxue3/xT4QYje0XU5L+pFODHQQ3L3VufvPoyamDm249TJ5ZUiUlwGlvL4s/VGo0pzy WMDqR8QQf9nC4rpwuHCP1xGIfDZpAqd2U8hDygakn3jcp3EaqmtzpHeiXn4O1xc52EUi iD2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=UvoSatsphDb+Y8NRrqiGXuOONs9H7KhWxgdgqeXA9tw=; b=0J1Nu2D1Rry5mHbJv7OxLVxyuIwAFMT3F/sbY2H8igvhHPGtJHvu6Nh9yyyZxnTJmg mrVTqADqrxkOHU8mnA2ZMeoXwtMJ/5tDxxI6ZnVvVQzNc9UxeFgR0mhhQKxOSr9wgBCg 9MbvuRKEcCp+a+ug4E4AicmI/JFJXYb5OHq01lVkPvo4IaCCSzk0F5eD7ZKRQzBQx3bC YrsfU0MV4EYo8vWxTklwm+rPzIkt8foSUzMYHldVITEbzzf/m47qDlMzJ43OGeQPhQIZ 0uNyWZDbmZkxOAmKl27/O+7YDl+Z4k7QxxqjWU2NI9pBAGwzn2ulPTtziWKqJFYCqz4D UKRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KsA6upZo; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2-v6si15547553plz.27.2018.05.04.01.02.51; Fri, 04 May 2018 01:02:51 -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=@linaro.org header.s=google header.b=KsA6upZo; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751570AbeEDICr (ORCPT + 29 others); Fri, 4 May 2018 04:02:47 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:45500 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751507AbeEDICl (ORCPT ); Fri, 4 May 2018 04:02:41 -0400 Received: by mail-pg0-f66.google.com with SMTP id i29-v6so14928356pgn.12 for ; Fri, 04 May 2018 01:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=UvoSatsphDb+Y8NRrqiGXuOONs9H7KhWxgdgqeXA9tw=; b=KsA6upZo2y25dMjseE+LKfTvm/4Xy46wz8F5zjUYOOjkUMDdUxAwjT1E8kgnPh8GSq qTdxYNFyA8+WwRIcg2J9v8oGqxxsEH1nPioW3K2f72N2T7Sw4SSip2jxC9mT4jhkfhxR cOi2MUy8Kt3Tp+LriILHuAE9K5TetKMQ3i1f4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UvoSatsphDb+Y8NRrqiGXuOONs9H7KhWxgdgqeXA9tw=; b=U5DcdaPdmpqOXsYEvzMa5ibrgZldo0sbRfOrinRuEU7N1VuatRIEyYQlywwzYS2je7 yfjQf/uvTRdY/mgXz5fh6KbYEoIhWlPBIARJVHmmKDruSvkzYK9USNpzOtHFn/YCnUAM WcQw0SuCqF4j+et5c7WqSjtR3VAcC9JWgecKC50etTrickpxhBBb/qdPR0b2ArOHIvYB Mb6A9fo+Hsh0fPgtUsZjgDXcBYUS+LKxOT1lkxM/DIeMc4Ws2ktgbLL1KNF0MjrugYxc sQnYfB19Sbn0A9h9fux1AMf5+pbiWshsDewST6zB6BrDwI/gYH7G0vPD//eaxaeXSGFQ xHVg== X-Gm-Message-State: ALQs6tDGIxudnUt6jvk/yqMggqTbnqSh4eTxUAq8IjyXb6hnarY3IxY4 NLtv9kyp3kDgIIRvf8uSeKBtYg== X-Received: by 10.98.141.81 with SMTP id z78mr11858937pfd.69.1525420961380; Fri, 04 May 2018 01:02:41 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 131sm29337519pfa.103.2018.05.04.01.02.38 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 May 2018 01:02:40 -0700 (PDT) From: Baolin Wang To: dan.j.williams@intel.com, vinod.koul@intel.com Cc: eric.long@spreadtrum.com, broonie@kernel.org, baolin.wang@linaro.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] dmaengine: sprd: Optimize the sprd_dma_prep_dma_memcpy() Date: Fri, 4 May 2018 16:01:36 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Long This is one preparation patch, we can use default DMA configuration to implement the device_prep_dma_memcpy() interface instead of issuing sprd_dma_config(). We will implement one new sprd_dma_config() function with introducing device_prep_slave_sg() interface in following patch. So we can remove the obsolete sprd_dma_config() firstly. Signed-off-by: Eric Long Signed-off-by: Baolin Wang --- drivers/dma/sprd-dma.c | 154 ++++++++++-------------------------------------- 1 file changed, 32 insertions(+), 122 deletions(-) -- 1.7.9.5 diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c index ccdeb8f..a7a89fd 100644 --- a/drivers/dma/sprd-dma.c +++ b/drivers/dma/sprd-dma.c @@ -552,147 +552,57 @@ static void sprd_dma_issue_pending(struct dma_chan *chan) spin_unlock_irqrestore(&schan->vc.lock, flags); } -static int sprd_dma_config(struct dma_chan *chan, struct sprd_dma_desc *sdesc, - dma_addr_t dest, dma_addr_t src, size_t len) +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) { - struct sprd_dma_dev *sdev = to_sprd_dma_dev(chan); - struct sprd_dma_chn_hw *hw = &sdesc->chn_hw; - u32 datawidth, src_step, des_step, fragment_len; - u32 block_len, req_mode, irq_mode, transcation_len; - u32 fix_mode = 0, fix_en = 0; + struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); + struct sprd_dma_desc *sdesc; + struct sprd_dma_chn_hw *hw; + enum sprd_dma_datawidth datawidth; + u32 step; - if (IS_ALIGNED(len, 4)) { - datawidth = SPRD_DMA_DATAWIDTH_4_BYTES; - src_step = SPRD_DMA_WORD_STEP; - des_step = SPRD_DMA_WORD_STEP; - } else if (IS_ALIGNED(len, 2)) { - datawidth = SPRD_DMA_DATAWIDTH_2_BYTES; - src_step = SPRD_DMA_SHORT_STEP; - des_step = SPRD_DMA_SHORT_STEP; - } else { - datawidth = SPRD_DMA_DATAWIDTH_1_BYTE; - src_step = SPRD_DMA_BYTE_STEP; - des_step = SPRD_DMA_BYTE_STEP; - } + sdesc = kzalloc(sizeof(*sdesc), GFP_NOWAIT); + if (!sdesc) + return NULL; - fragment_len = SPRD_DMA_MEMCPY_MIN_SIZE; - if (len <= SPRD_DMA_BLK_LEN_MASK) { - block_len = len; - transcation_len = 0; - req_mode = SPRD_DMA_BLK_REQ; - irq_mode = SPRD_DMA_BLK_INT; - } else { - block_len = SPRD_DMA_MEMCPY_MIN_SIZE; - transcation_len = len; - req_mode = SPRD_DMA_TRANS_REQ; - irq_mode = SPRD_DMA_TRANS_INT; - } + hw = &sdesc->chn_hw; hw->cfg = SPRD_DMA_DONOT_WAIT_BDONE << SPRD_DMA_WAIT_BDONE_OFFSET; + hw->intc = SPRD_DMA_TRANS_INT | SPRD_DMA_CFG_ERR_INT_EN; + hw->src_addr = (u32)(src & SPRD_DMA_LOW_ADDR_MASK); + hw->des_addr = (u32)(dest & SPRD_DMA_LOW_ADDR_MASK); hw->wrap_ptr = (u32)((src >> SPRD_DMA_HIGH_ADDR_OFFSET) & SPRD_DMA_HIGH_ADDR_MASK); hw->wrap_to = (u32)((dest >> SPRD_DMA_HIGH_ADDR_OFFSET) & SPRD_DMA_HIGH_ADDR_MASK); - hw->src_addr = (u32)(src & SPRD_DMA_LOW_ADDR_MASK); - hw->des_addr = (u32)(dest & SPRD_DMA_LOW_ADDR_MASK); - - if ((src_step != 0 && des_step != 0) || (src_step | des_step) == 0) { - fix_en = 0; + if (IS_ALIGNED(len, 8)) { + datawidth = SPRD_DMA_DATAWIDTH_8_BYTES; + step = SPRD_DMA_DWORD_STEP; + } else if (IS_ALIGNED(len, 4)) { + datawidth = SPRD_DMA_DATAWIDTH_4_BYTES; + step = SPRD_DMA_WORD_STEP; + } else if (IS_ALIGNED(len, 2)) { + datawidth = SPRD_DMA_DATAWIDTH_2_BYTES; + step = SPRD_DMA_SHORT_STEP; } else { - fix_en = 1; - if (src_step) - fix_mode = 1; - else - fix_mode = 0; + datawidth = SPRD_DMA_DATAWIDTH_1_BYTE; + step = SPRD_DMA_BYTE_STEP; } hw->frg_len = datawidth << SPRD_DMA_SRC_DATAWIDTH_OFFSET | datawidth << SPRD_DMA_DES_DATAWIDTH_OFFSET | - req_mode << SPRD_DMA_REQ_MODE_OFFSET | - fix_mode << SPRD_DMA_FIX_SEL_OFFSET | - fix_en << SPRD_DMA_FIX_EN_OFFSET | - (fragment_len & SPRD_DMA_FRG_LEN_MASK); - hw->blk_len = block_len & SPRD_DMA_BLK_LEN_MASK; - - hw->intc = SPRD_DMA_CFG_ERR_INT_EN; - - switch (irq_mode) { - case SPRD_DMA_NO_INT: - break; - - case SPRD_DMA_FRAG_INT: - hw->intc |= SPRD_DMA_FRAG_INT_EN; - break; - - case SPRD_DMA_BLK_INT: - hw->intc |= SPRD_DMA_BLK_INT_EN; - break; + SPRD_DMA_TRANS_REQ << SPRD_DMA_REQ_MODE_OFFSET | + (len & SPRD_DMA_FRG_LEN_MASK); + hw->blk_len = len & SPRD_DMA_BLK_LEN_MASK; + hw->trsc_len = len & SPRD_DMA_TRSC_LEN_MASK; - case SPRD_DMA_BLK_FRAG_INT: - hw->intc |= SPRD_DMA_BLK_INT_EN | SPRD_DMA_FRAG_INT_EN; - break; - - case SPRD_DMA_TRANS_INT: - hw->intc |= SPRD_DMA_TRANS_INT_EN; - break; - - case SPRD_DMA_TRANS_FRAG_INT: - hw->intc |= SPRD_DMA_TRANS_INT_EN | SPRD_DMA_FRAG_INT_EN; - break; - - case SPRD_DMA_TRANS_BLK_INT: - hw->intc |= SPRD_DMA_TRANS_INT_EN | SPRD_DMA_BLK_INT_EN; - break; - - case SPRD_DMA_LIST_INT: - hw->intc |= SPRD_DMA_LIST_INT_EN; - break; - - case SPRD_DMA_CFGERR_INT: - hw->intc |= SPRD_DMA_CFG_ERR_INT_EN; - break; - - default: - dev_err(sdev->dma_dev.dev, "invalid irq mode\n"); - return -EINVAL; - } - - if (transcation_len == 0) - hw->trsc_len = block_len & SPRD_DMA_TRSC_LEN_MASK; - else - hw->trsc_len = transcation_len & SPRD_DMA_TRSC_LEN_MASK; - - hw->trsf_step = (des_step & SPRD_DMA_TRSF_STEP_MASK) << + hw->trsf_step = (step & SPRD_DMA_TRSF_STEP_MASK) << SPRD_DMA_DEST_TRSF_STEP_OFFSET | - (src_step & SPRD_DMA_TRSF_STEP_MASK) << + (step & SPRD_DMA_TRSF_STEP_MASK) << SPRD_DMA_SRC_TRSF_STEP_OFFSET; - hw->frg_step = 0; - hw->src_blk_step = 0; - hw->des_blk_step = 0; - hw->src_blk_step = 0; - return 0; -} - -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) -{ - struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); - struct sprd_dma_desc *sdesc; - int ret; - - sdesc = kzalloc(sizeof(*sdesc), GFP_NOWAIT); - if (!sdesc) - return NULL; - - ret = sprd_dma_config(chan, sdesc, dest, src, len); - if (ret) { - kfree(sdesc); - return NULL; - } - return vchan_tx_prep(&schan->vc, &sdesc->vd, flags); }