Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2065267ybk; Mon, 11 May 2020 11:04:47 -0700 (PDT) X-Google-Smtp-Source: APiQypL7kPSFGMc9l/p8TzvLup8XavvgtjJjhneOAe4+E5+W4zEKSs5jXreLqRGMM6pL8kpQUOc9 X-Received: by 2002:a17:906:855a:: with SMTP id h26mr15000194ejy.56.1589220287340; Mon, 11 May 2020 11:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589220287; cv=none; d=google.com; s=arc-20160816; b=pv1wDJRpUxifQgWBAAIZAOwri8rIVsM1r/bpqopEcBm/51iLmCf4tAkMqNYDjbpbSo MYywJufxbC82TPUgCKW3AUKPEuyrah/6l8ofJjKyY5VJm8L+84GbUFJvKCDqE8zgm6Ys HKJPijAZgtFia4A8V2Dp5N3/d5MkHNHwcqbSMWqt80kAO+zzpU9N+FHYpWLmZeu0rwxo auKmuQmmgoZjZnpevo8eRtk+iCyfcG5tlV7zpbVPYgGAdst4aZrMpVJLgWZEj/BjWhtX 5VMiPDzK0YYegwF4IMUmj92gVRSIOOOA7H+Z25S7kono1rybVPB6mi0ipjOpyV0TPeU7 W+Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=KN4Bw4jdoDlNbb2x0GKSiOiWfddLAMYHfygVxNpIf6g=; b=mXhlnJsMfffSRKEbgl8CpdDHv/dgZgB0fSgOuURJSS9+LF6V9rOYVaGpqIz4aTrSGv pIIQtG+3LTsVLYKlxr9aqblMcvnKYHhsYXeyd3R1llkQSzQox67oKcUCbnwPw+UHtWmV CwhjdUgoopJEFDTEoNWK23RqpzNVeIJZqnww53qmADt4hCvwnlKjMdWApYqxfm/+tRCA wpKXfoI1r/PFn72vZcKyI97nLsilIhin4KPVLV+BfuTrhpW04UGZSwfO2gooQR4WKd9t fBp4aOXWEnWprMt/m6KVKno7s3vPeM3aQ/msbaahxaTz5s6O3t7UsZEa2GBVTClbGVPT CLiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=SvZpKz7y; 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 co24si6000317edb.24.2020.05.11.11.04.19; Mon, 11 May 2020 11:04:47 -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=SvZpKz7y; 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 S1730952AbgEKSCh (ORCPT + 99 others); Mon, 11 May 2020 14:02:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726891AbgEKSCh (ORCPT ); Mon, 11 May 2020 14:02:37 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD042C061A0C for ; Mon, 11 May 2020 11:02:36 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id e25so10561122ljg.5 for ; Mon, 11 May 2020 11:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KN4Bw4jdoDlNbb2x0GKSiOiWfddLAMYHfygVxNpIf6g=; b=SvZpKz7yYJU/v4SDDIo5TOzIj+jwoV/TpTBN3rKCL602OojQJglY2dw5xOeiunPOFi DyzhSP/Fy5UBdfge/am/cx04rOkqTbKWuxOjxqsp+K/Okzus3lAn3dbBKJ/ZCJ6HxuVq h39u7djqdlksyB3tKveo/W8quLa8tPXg7veTON0HABVQg+M+e7pjqhtcNTCkt/TMbnSd pN3CVJwzAKb5Ge7s+venQ9Nw4IxBg2uM87+P3w0lHhVzCAZjiNOP0HW0I/ovgLPoNSb8 nXG3b+J9z5POi+mxIRKklmwiOkmQ4nrSM4G66SUjogC5jXd4xS5Qd0ky++iU4xkLdE/O nPhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KN4Bw4jdoDlNbb2x0GKSiOiWfddLAMYHfygVxNpIf6g=; b=ctNyG6BXQTnwD7ixARY8hJhn40Zs2le3hBOiqgsxjjnpedHZRjRQsFcIt7y4jc9nmG kvFniMelmurZVvPZQjKfSi1K78aUXrMrG0EvHsW8ZPgfhruNNDs07cekFd2BSQ1oTleu Oq2kGhtH9yJmRFZWAQyP6+mY6QyEgBoyZWxVdFau75kr06dyrlYUfraReBphVf0AHIRx /+1+YXlh6nkm3HbpUS9aEHeOs4piIihxHqXetCclVaYnjGn9Y9Mc8oD/RX4IohsJh84i s5aD7lPJWB8vFVZu8sVCoKrvBzAcHQmfaSK00TMrPpCTMiw/kW1dBCYD9ymV7Lq9ybsS YYJw== X-Gm-Message-State: AOAM532S+e+dDbkuKVjtnDmB3tBjB+o0zsX/paKl5rKjGH3npuoGUSyw 8m1SoFF1tvUvuc4d5GPGCY+Q3k+FU5ECq5tnUsiaDw== X-Received: by 2002:a2e:b52a:: with SMTP id z10mr322629ljm.200.1589220154131; Mon, 11 May 2020 11:02:34 -0700 (PDT) MIME-Version: 1.0 References: <1588379352-22550-1-git-send-email-alan.mikhak@sifive.com> <20200507214418.GA22159@bogus> In-Reply-To: <20200507214418.GA22159@bogus> From: Alan Mikhak Date: Mon, 11 May 2020 11:02:23 -0700 Message-ID: Subject: Re: [PATCH] PCI: endpoint: functions/pci-epf-test: Support slave DMA transfer To: Rob Herring Cc: linux-pci , linux-kernel@vger.kernel.org, Kishon Vijay Abraham I , lorenzo.pieralisi@arm.com, Bjorn Helgaas , efremov@linux.com, b.zolnierkie@samsung.com, vidyas@nvidia.com, Paul Walmsley Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 7, 2020 at 2:44 PM Rob Herring wrote: > > On Fri, May 01, 2020 at 05:29:12PM -0700, Alan Mikhak wrote: > > 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. > > Looks fine, but also needs a user. The last sentence sounds like a > separate change. Thanks Rob for your comment. I will address your concern in a future v2 patch. Regards, Alan > > > > > 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 > >