Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1224769ybz; Fri, 1 May 2020 17:31:25 -0700 (PDT) X-Google-Smtp-Source: APiQypIXBIGLX8Fhm/w9hTcFcseP+SwGzCKwmLIEpcBkJ6kz4j1ApL5BkrDUd8G3BL1vSmtEefhq X-Received: by 2002:a17:906:7f0d:: with SMTP id d13mr5826356ejr.312.1588379485102; Fri, 01 May 2020 17:31:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588379485; cv=none; d=google.com; s=arc-20160816; b=xo/TD5L5+Dp74OGNulpHCriMlbsYECcEBfUMVF7CLCMTrQ9Sw1n9PS8FSbBc0Pkm/4 nN59TA3BX1Z0Oxozm/2fyWv4zglSNlC2VqXZEeUuTGC00ZVdSeqMjqlEGLHwzaNiQsnT 6dBHI6SuIfLdkFE0HuZpIEbP5o7Yq+kSeP2uMl6fP2sp8wUVZGxtALhcw+iXG1AMe/0m GDJt6ukq4b4FDcjOuT/90N7prBnLODNc0eC2FjXY7jjCj29iLscHKg0dgZgERL1Ae/yB AKyz/Hjn4ddNfaVXtrKMO6mvsSqBd++Sm9KiXwIwiMbstNo+rcgioICKqYZhat2IV7II 8Blg== 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; bh=0gEckujgYO5yEgZCIWnLgeYgKfcc2TLCCkDUoH39Yyk=; b=WFYYlscNiuBUS6xPWjtZ5MY5B/JXD2c4QAsczS7mhBgMASO11G34VCzMomwZg/g/AU 6fENoolD6NFj7yrNvzurtLlr8OrX26/Ihn5y2o0M4KB9L7/ptK5hmhUfnO8JBFieMG3p WP33twhcbeiyNcMhFbNR3W90LFs0QpByHI3POBvcmpl/V+lnraVF9Z/wo+VByLfPjQhf TxndSbrEw4QLI2Yfitg7zj16NRCJcAiAWyzZS9OkYPAaH3quyseo4+rKXw/Z1oIKW2PP cYojJ3NUM+FvzURIv5AhHfjAiddpLrhn0oqtwxLceB6VFWnVZYXD7+D4oI5BLHIlO31K HlrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Iw9jkJxw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si2545585eji.41.2020.05.01.17.31.00; Fri, 01 May 2020 17:31:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Iw9jkJxw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726437AbgEBA3Z (ORCPT + 99 others); Fri, 1 May 2020 20:29:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726435AbgEBA3Y (ORCPT ); Fri, 1 May 2020 20:29:24 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6755FC061A0C for ; Fri, 1 May 2020 17:29:24 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id b6so931289plz.13 for ; Fri, 01 May 2020 17:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=0gEckujgYO5yEgZCIWnLgeYgKfcc2TLCCkDUoH39Yyk=; b=Iw9jkJxwdpW8o7T3GhJeC2RS98jno3xBpIyuVU3DTq5SZ4c2+A+pUpk+CdFvgjObZY igMkXyRu4Qg9jR3GpjcBJ+btxk93gBsLxwR6GQ0KkyYlvYFNY48hgrf5Pkmf7WHCrMp7 hLTXbnh/4wm/MjRlXsVBydzkswSdPZeSlkVP+j/aOZiUbRIWItaSk+/At8gd/ecWTd8x A3WuqYXYT9hsFTQ8nn7nI3vs1beW2NWk3w0nwTic98VhHK8Wz4I7hrav1Pi0gqvIYbHd IZagS9+Pd3+kEOi5WaevvGjnm6pJLgxR12NjKSfKnPwEefTtc3fLObiX4aDbCN6Pop73 H13A== 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=0gEckujgYO5yEgZCIWnLgeYgKfcc2TLCCkDUoH39Yyk=; b=mgCKMgtwv7OE+fqfMJfTORbHwXJwBEPIT5t0DnBI64it4aHPNvLNEN0Ddw3Pv3wGMQ YCdyadepCmWJ1dAxO7r4HJeqqkfAEZdwxqL2AiYvWpUnigl35IewPHsyAtsMmW64PFVw 4OskrcoskAe+w9TmsJxiuAu/pHBeny5D0t+ieZRM303ro7u8LC6HIIafmWNzUfC/YbGe rVReRzwHwvukwA0Vncli9uJoj8K59kMcKkSsIVOWNoxc+N9AwOEPkpp5MONB2vxtn4rU rirpYjVgrj6CjAGQ5ueucs6ErR1ZAdmr0W8RWP+ZXjND1EJ5HQsMPNW23R4vs08QaoQ+ HXCg== X-Gm-Message-State: AGi0PuY42rLN1vMROwaTOcO1zHcbqwL8APkYfkBKQge9EVbcwPvbY3pS vaZXSKDuz6tz9gwFH45eHRWYIg== X-Received: by 2002:a17:902:8b82:: with SMTP id ay2mr6829624plb.153.1588379363760; Fri, 01 May 2020 17:29:23 -0700 (PDT) Received: from nuc7.sifive.com (c-24-5-48-146.hsd1.ca.comcast.net. [24.5.48.146]) by smtp.gmail.com with ESMTPSA id u188sm3143644pfu.33.2020.05.01.17.29.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 May 2020 17:29:23 -0700 (PDT) From: Alan Mikhak X-Google-Original-From: Alan Mikhak < alan.mikhak@sifive.com > To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kishon@ti.com, lorenzo.pieralisi@arm.com, bhelgaas@google.com, efremov@linux.com, b.zolnierkie@samsung.com, vidyas@nvidia.com, paul.walmsley@sifive.com Cc: Alan Mikhak Subject: [PATCH] PCI: endpoint: functions/pci-epf-test: Support slave DMA transfer Date: Fri, 1 May 2020 17:29:12 -0700 Message-Id: <1588379352-22550-1-git-send-email-alan.mikhak@sifive.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Mikhak Modify pci_epf_test_data_transfer() to also support slave DMA transfers. Adds a direction parameter so caller can specify one of the supported DMA transfer directions: DMA_MEM_TO_MEM, DMA_MEM_TO_DEV, and DMA_DEV_TO_MEM. For DMA_MEM_TO_MEM, the function calls dmaengine_prep_dma_memcpy() as it did before. For DMA_MEM_TO_DEV or DMA_DEV_TO_MEM direction, the function calls dmaengine_slave_config() to configure the slave channel before it calls dmaengine_prep_slave_single(). Modify existing callers to specify DMA_MEM_TO_MEM since that is the only possible option so far. Rename the phys_addr local variable in some of the callers for more readability. Tighten some of the timing function calls to avoid counting error print time in case of error. Signed-off-by: Alan Mikhak --- drivers/pci/endpoint/functions/pci-epf-test.c | 67 ++++++++++++++++++--------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 60330f3e3751..1d026682febb 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -104,25 +104,41 @@ static void pci_epf_test_dma_callback(void *param) * The function returns '0' on success and negative value on failure. */ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, - dma_addr_t dma_dst, dma_addr_t dma_src, - size_t len) + dma_addr_t dma_dst, + dma_addr_t dma_src, + size_t len, + enum dma_transfer_direction dir) { enum dma_ctrl_flags flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT; struct dma_chan *chan = epf_test->dma_chan; struct pci_epf *epf = epf_test->epf; + struct dma_slave_config sconf; struct dma_async_tx_descriptor *tx; struct device *dev = &epf->dev; dma_cookie_t cookie; + dma_addr_t buf; int ret; if (IS_ERR_OR_NULL(chan)) { - dev_err(dev, "Invalid DMA memcpy channel\n"); + dev_err(dev, "Invalid DMA channel\n"); return -EINVAL; } - tx = dmaengine_prep_dma_memcpy(chan, dma_dst, dma_src, len, flags); + if (dir == DMA_MEM_TO_MEM) { + tx = dmaengine_prep_dma_memcpy(chan, dma_dst, dma_src, + len, flags); + } else { + memset(&sconf, 0, sizeof(sconf)); + sconf.direction = dir; + sconf.dst_addr = dma_dst; + sconf.src_addr = dma_src; + dmaengine_slave_config(chan, &sconf); + + buf = (dir == DMA_MEM_TO_DEV) ? dma_dst : dma_src; + tx = dmaengine_prep_slave_single(chan, buf, len, dir, flags); + } if (!tx) { - dev_err(dev, "Failed to prepare DMA memcpy\n"); + dev_err(dev, "Failed to prepare DMA transfer\n"); return -EIO; } @@ -268,7 +284,6 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) goto err_dst_addr; } - ktime_get_ts64(&start); use_dma = !!(reg->flags & FLAG_USE_DMA); if (use_dma) { if (!epf_test->dma_supported) { @@ -277,14 +292,18 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) goto err_map_addr; } + ktime_get_ts64(&start); ret = pci_epf_test_data_transfer(epf_test, dst_phys_addr, - src_phys_addr, reg->size); + src_phys_addr, reg->size, + DMA_MEM_TO_MEM); + ktime_get_ts64(&end); if (ret) dev_err(dev, "Data transfer failed\n"); } else { + ktime_get_ts64(&start); memcpy(dst_addr, src_addr, reg->size); + ktime_get_ts64(&end); } - ktime_get_ts64(&end); pci_epf_test_print_rate("COPY", reg->size, &start, &end, use_dma); err_map_addr: @@ -310,7 +329,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) void *buf; u32 crc32; bool use_dma; - phys_addr_t phys_addr; + phys_addr_t src_phys_addr; phys_addr_t dst_phys_addr; struct timespec64 start, end; struct pci_epf *epf = epf_test->epf; @@ -319,8 +338,9 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) struct device *dma_dev = epf->epc->dev.parent; enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + enum dma_transfer_direction dir = DMA_MEM_TO_MEM; - src_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); + src_addr = pci_epc_mem_alloc_addr(epc, &src_phys_addr, reg->size); if (!src_addr) { dev_err(dev, "Failed to allocate address\n"); reg->status = STATUS_SRC_ADDR_INVALID; @@ -328,7 +348,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) goto err; } - ret = pci_epc_map_addr(epc, epf->func_no, phys_addr, reg->src_addr, + ret = pci_epc_map_addr(epc, epf->func_no, src_phys_addr, reg->src_addr, reg->size); if (ret) { dev_err(dev, "Failed to map address\n"); @@ -360,10 +380,10 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) ktime_get_ts64(&start); ret = pci_epf_test_data_transfer(epf_test, dst_phys_addr, - phys_addr, reg->size); + src_phys_addr, reg->size, dir); + ktime_get_ts64(&end); if (ret) dev_err(dev, "Data transfer failed\n"); - ktime_get_ts64(&end); dma_unmap_single(dma_dev, dst_phys_addr, reg->size, DMA_FROM_DEVICE); @@ -383,10 +403,10 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) kfree(buf); err_map_addr: - pci_epc_unmap_addr(epc, epf->func_no, phys_addr); + pci_epc_unmap_addr(epc, epf->func_no, src_phys_addr); err_addr: - pci_epc_mem_free_addr(epc, phys_addr, src_addr, reg->size); + pci_epc_mem_free_addr(epc, src_phys_addr, src_addr, reg->size); err: return ret; @@ -398,7 +418,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) void __iomem *dst_addr; void *buf; bool use_dma; - phys_addr_t phys_addr; + phys_addr_t dst_phys_addr; phys_addr_t src_phys_addr; struct timespec64 start, end; struct pci_epf *epf = epf_test->epf; @@ -407,8 +427,9 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) struct device *dma_dev = epf->epc->dev.parent; enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + enum dma_transfer_direction dir = DMA_MEM_TO_MEM; - dst_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); + dst_addr = pci_epc_mem_alloc_addr(epc, &dst_phys_addr, reg->size); if (!dst_addr) { dev_err(dev, "Failed to allocate address\n"); reg->status = STATUS_DST_ADDR_INVALID; @@ -416,7 +437,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) goto err; } - ret = pci_epc_map_addr(epc, epf->func_no, phys_addr, reg->dst_addr, + ret = pci_epc_map_addr(epc, epf->func_no, dst_phys_addr, reg->dst_addr, reg->size); if (ret) { dev_err(dev, "Failed to map address\n"); @@ -450,11 +471,11 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) } ktime_get_ts64(&start); - ret = pci_epf_test_data_transfer(epf_test, phys_addr, - src_phys_addr, reg->size); + ret = pci_epf_test_data_transfer(epf_test, dst_phys_addr, + src_phys_addr, reg->size, dir); + ktime_get_ts64(&end); if (ret) dev_err(dev, "Data transfer failed\n"); - ktime_get_ts64(&end); dma_unmap_single(dma_dev, src_phys_addr, reg->size, DMA_TO_DEVICE); @@ -476,10 +497,10 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) kfree(buf); err_map_addr: - pci_epc_unmap_addr(epc, epf->func_no, phys_addr); + pci_epc_unmap_addr(epc, epf->func_no, dst_phys_addr); err_addr: - pci_epc_mem_free_addr(epc, phys_addr, dst_addr, reg->size); + pci_epc_mem_free_addr(epc, dst_phys_addr, dst_addr, reg->size); err: return ret; -- 2.7.4