Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp61408ybz; Tue, 28 Apr 2020 18:12:59 -0700 (PDT) X-Google-Smtp-Source: APiQypK1VayvBb3hViIAT0fbVxm67FcMbs1um1cj5i2dzcMVkVtOziSly5HGZ8QRbPAFwye57llG X-Received: by 2002:a17:906:2511:: with SMTP id i17mr460090ejb.165.1588122779458; Tue, 28 Apr 2020 18:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588122779; cv=none; d=google.com; s=arc-20160816; b=li6ht2hIB+Lgjzr3IKzB2e/bQ9BzKAceGaLU8GtOy7tnZ3DFRvzpV9Kr7oWb1wGsht VjKu0ovYZdY+jly7+KWsJVq1oHzMspxAzRa1b0pAef2Riw6O3qi1c28z5YZYLqSUfED/ Pu41SAyk77F/dG+/Eps7dIAQ7BXoIlpZ1/xi1CZmDKpUqM6A2vbXqMMKsuMkfo1X9hlB Ke0iyvjar23butSnu+jfin9gGWCNj74B/iIKwU6MHbHkkqHSdGfnSB45KezN3Z+in0Dv gfI98p6KiIkSaU4D3WbjEv6J9JKPHZkCidrq+y2M6AgwC0rqWLll4MtrVvK38Rr+CVPf GFPQ== 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=+tkvHJiORDuD9q2tyEU1ZAJYf1nqy44zTSwWoOUTzwY=; b=GBBHXYsGEQhwNo8oEN207H+zqPY7r4R1wNarGUmPyNbgpp91VM70zC70We7ExU3363 8PnN1UIcOn5rki/O8gISbfOFf5TTvnqvE8oJs2qSE0wgZDOQEidWu3H+o3j1ILLnW4lo p6LY0ttM2HQc9dTvt2W//TMWUEoSI00+5PTohoLdXVKYSibQXdIEq++v6tN/je1LvYg2 jHRupdCx3e0MboQ4XG0/E8/7gz/E/Eb0Mqk9BrG5/xSHMt5os1a9rxGEaPQm1oXCqzdC oDD6S79UoXcSIuahF8qcbt2LW7pwMFt7EuUbe6GbrRgtfSosPAJi5LQQt71d/1o/mFqv 4I3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="jp+A/PSm"; 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 lc1si2970687ejb.198.2020.04.28.18.12.35; Tue, 28 Apr 2020 18:12:59 -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="jp+A/PSm"; 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 S1726457AbgD2BKq (ORCPT + 99 others); Tue, 28 Apr 2020 21:10:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726363AbgD2BKp (ORCPT ); Tue, 28 Apr 2020 21:10:45 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C2EAC03C1AC for ; Tue, 28 Apr 2020 18:10:45 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id hi11so84099pjb.3 for ; Tue, 28 Apr 2020 18:10:45 -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=+tkvHJiORDuD9q2tyEU1ZAJYf1nqy44zTSwWoOUTzwY=; b=jp+A/PSmOqvf4Bh5HmmTLiDY59o40n1Ahz0ZBiYaDwWZ5nQbj3KdTnWLATLo7/0NRj 9c+YZqUtsJlNJKJLSOWrE4YPDqZ+VLIDjxyBXivW8B7QJZqp46ZdMNVm80la9RVXMyu/ z3QH8SYiqx+5gBgq9G6/bKF4BozsTevmm9eg1LLtUAKDeWm76lJiBTsjJA23kzbHMoW9 WkWUdCdxAF1XueXLOfY5D0nepmGdioddbBFLlIMJpXZndWIyS2pzpY/eQeRlvRnEeW1j uRJgfbpYyB3IwcCT6momC2fCe0jhQ0UE1jQZT1eTlLy3wiGyojY/hFd2qUXR16xINjcw sStA== 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=+tkvHJiORDuD9q2tyEU1ZAJYf1nqy44zTSwWoOUTzwY=; b=FhwcL0hj/0qnmXI75N2odjtXlk1RYq7HXRF/WWR7rkbokeWs3MmjDG7izFOPBmjEPB eTIz/x2EchQ0yfz5ut8Wbe+A/7TM4yLU+IfWhshYWjq5ttc0v6VKXTPFxiIZcPY6IDYS /FPnIuCVNJiapM0vfXALp30nGhSmt+N+mWqPV99FCgNn3LdUoSLoh2+WXQy3TTjKJ9Od kQH36HznPvhuaXc9t/RcYu/6p/ecNAqfXWsxcxskgNrPN8K6ymzfxEXLT8J/rKkT7agJ neRsYwjEVEkBSHajRx+PmQ+aFU38+HSGLwanpU16FwKb1Q7AOPYO60PAwPdvSa7vD5yA DAQA== X-Gm-Message-State: AGi0PuYCQBiHSTURezIV7ABeVkl+C4LE94Jfxzl7U4bDVCtvInqkS/qY wRkijdrGcESKPZsmvkrT568t/w== X-Received: by 2002:a17:902:bb82:: with SMTP id m2mr10064593pls.291.1588122644708; Tue, 28 Apr 2020 18:10:44 -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 b5sm16243391pfb.190.2020.04.28.18.10.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2020 18:10:43 -0700 (PDT) From: Alan Mikhak X-Google-Original-From: Alan Mikhak < alan.mikhak@sifive.com > To: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, gustavo.pimentel@synopsys.com, dan.j.williams@intel.com, vkoul@kernel.org, kishon@ti.com, paul.walmsley@sifive.com Cc: Alan Mikhak Subject: [PATCH][next] dmaengine: dw-edma: support local dma device transfer semantics Date: Tue, 28 Apr 2020 18:10:33 -0700 Message-Id: <1588122633-1552-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 dw_edma_device_transfer() to also support the semantics of dma device transfer for additional use cases involving pcitest utility as a local initiator. For its original use case, dw-edma supported the semantics of dma device transfer from the perspective of a remote initiator who is located across the PCIe bus from dma channel hardware. To a remote initiator, DMA_DEV_TO_MEM means using a remote dma WRITE channel to transfer from remote memory to local memory. A WRITE channel would be employed on the remote device in order to move the contents of remote memory to the bus destined for local memory. To a remote initiator, DMA_MEM_TO_DEV means using a remote dma READ channel to transfer from local memory to remote memory. A READ channel would be employed on the remote device in order to move the contents of local memory to the bus destined for remote memory. From the perspective of a local dma initiator who is co-located on the same side of the PCIe bus as the dma channel hardware, the semantics of dma device transfer are flipped. To a local initiator, DMA_DEV_TO_MEM means using a local dma READ channel to transfer from remote memory to local memory. A READ channel would be employed on the local device in order to move the contents of remote memory to the bus destined for local memory. To a local initiator, DMA_MEM_TO_DEV means using a local dma WRITE channel to transfer from local memory to remote memory. A WRITE channel would be employed on the local device in order to move the contents of local memory to the bus destined for remote memory. To support local dma initiators, dw_edma_device_transfer() is modified to now examine the direction field of struct dma_slave_config for the channel which initiators can configure by calling dmaengine_slave_config(). If direction is configured as either DMA_DEV_TO_MEM or DMA_MEM_TO_DEV, local initiator semantics are used. If direction is a value other than DMA_DEV_TO_MEM nor DMA_MEM_TO_DEV, then remote initiator semantics are used. This should maintain backward compatibility with the original use case of dw-edma. The dw-edma-test utility is an example of a remote initiator. From reading its patch, dw-edma-test does not specifically set the direction field of struct dma_slave_config. Since dw_edma_device_transfer() also does not check the direction field of struct dma_slave_config, it seems safe to use this convention in dw-edma to support both local and remote initiator semantics. Signed-off-by: Alan Mikhak This patch depends on the following patches: [PATCH v2] dmaengine: dw-edma: Decouple dw-edma-core.c from struct pci_dev https://patchwork.kernel.org/patch/11491757/ [PATCH v2,next] dmaengine: dw-edma: Check MSI descriptor before copying https://patchwork.kernel.org/patch/11504849/ Rebased on linux-next next-20200428 which has above patches applied. --- drivers/dma/dw-edma/dw-edma-core.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index 306ab50462be..ed430ad9b3dd 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -323,7 +323,7 @@ static struct dma_async_tx_descriptor * dw_edma_device_transfer(struct dw_edma_transfer *xfer) { struct dw_edma_chan *chan = dchan2dw_edma_chan(xfer->dchan); - enum dma_transfer_direction direction = xfer->direction; + enum dma_transfer_direction dir = xfer->direction; phys_addr_t src_addr, dst_addr; struct scatterlist *sg = NULL; struct dw_edma_chunk *chunk; @@ -332,10 +332,26 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer) u32 cnt; int i; - if ((direction == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) || - (direction == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ)) + if (!chan->configured) return NULL; + switch (chan->config.direction) { + case DMA_DEV_TO_MEM: /* local dma */ + if (dir == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ) + break; + return NULL; + case DMA_MEM_TO_DEV: /* local dma */ + if (dir == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) + break; + return NULL; + default: /* remote dma */ + if (dir == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_READ) + break; + if (dir == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_WRITE) + break; + return NULL; + } + if (xfer->cyclic) { if (!xfer->xfer.cyclic.len || !xfer->xfer.cyclic.cnt) return NULL; @@ -344,9 +360,6 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer) return NULL; } - if (!chan->configured) - return NULL; - desc = dw_edma_alloc_desc(chan); if (unlikely(!desc)) goto err_alloc; @@ -387,7 +400,7 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer) chunk->ll_region.sz += burst->sz; desc->alloc_sz += burst->sz; - if (direction == DMA_DEV_TO_MEM) { + if (chan->dir == EDMA_DIR_WRITE) { burst->sar = src_addr; if (xfer->cyclic) { burst->dar = xfer->xfer.cyclic.paddr; -- 2.7.4