Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3259566rwb; Mon, 15 Aug 2022 22:33:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR4mjzScHd6YNMo1de9dHlTtu/oAq1eh0oIpW9ZllTlhKRQDXQ4wGzIkGSn3HgihO5clccCl X-Received: by 2002:a17:906:98c8:b0:730:7ada:87a7 with SMTP id zd8-20020a17090698c800b007307ada87a7mr12430316ejb.748.1660628005215; Mon, 15 Aug 2022 22:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660628005; cv=none; d=google.com; s=arc-20160816; b=fj4g1rB3I/rcbVttLmRQ63vdioCtqWYuyQmNORekCecWbI3ha32nplrucO4Yl/rQs0 5F1Ht2YOPeN4mM104Jlld908KO0D+FOmeg/s9EHHqRQVREjYOfM2BHy9V03diVcmZHlk U+sIQ/muO4Y4gJJX5Y5gfYogOcp6V4h/MX27Jc1rxQEGavPo4aXBWKiFST+uw7Zuto5X MGkzipBSuHllZszFkxX4cQQGWyg/vH1sUzH494dX+hMZ2wyRGbqB34gXB2xOUhtKMBys NO67fmB3ae/nkkmPMrmSWhTU1hQ278U5sEYnChAcMrXWKFbE2OhJpttU1budo3lb6w0e ov2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=68fAR7jAAbYOxvG3x5eR10cJE/FZrc8rxrGEM3wf6F8=; b=HFr4lJ1yBHXvL0IDlxsKbIp6uSKafkstVx8SeGaf4MarsGSAatDPYM5TbCzR7xqsXL WhW2QFOh64Gv64zFmDL21oo6sf9ZzaUEfLlZryh1YvM1hO+C5SMvC7cGB4i8vtaz1dsR XZrjJS/84WrpTXoqpRqvR+/0o/d2Vv99j3udJjn0RLttdESnPhiB2hje3N0Qcw7SgDRm VejDpFDNv/o3rQPNffz+/B9jkQOaFvUg9OfyvVHe9nSM0QzN4+RtqIzgVTNvL3cSyo/P Rxu//WkvdDT2hGGgDjbSxwD9nu9F+lVOunHHSsU4MrtyzLQpVUd2wBVPWwi9SDl82ZQk TTpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xFEd0hCH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg26-20020a170907971a00b0072b57c1f238si8845313ejc.291.2022.08.15.22.32.59; Mon, 15 Aug 2022 22:33:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xFEd0hCH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbiHPEjf (ORCPT + 99 others); Tue, 16 Aug 2022 00:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbiHPEiy (ORCPT ); Tue, 16 Aug 2022 00:38:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6469172C37; Mon, 15 Aug 2022 13:29:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DE69261184; Mon, 15 Aug 2022 20:29:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C90B3C433D6; Mon, 15 Aug 2022 20:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595349; bh=OWPSdIFm61z5E2K4vT0EJcS4iLQ5Z8SLJgsG9Gpzgiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xFEd0hCH3REvG/Xysggq3RQAgc3IPG8c1HxzaFEDhXP8HkNJP6+quEM0R+iRZd0uY r3khrqmBgoyaUR5AycpP8aSYmBDHD5GDbbs8LitA5lWisjOh87w6CGXg+HKEI/7Dqh 6/0XZ3JskzLHOVkF1DCg12ceWoh+s8yLGm/6ELHk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Manivannan Sadhasivam , Serge Semin , Frank Li , Bjorn Helgaas , Vinod Koul , Sasha Levin Subject: [PATCH 5.19 0737/1157] dmaengine: dw-edma: Fix eDMA Rd/Wr-channels and DMA-direction semantics Date: Mon, 15 Aug 2022 20:01:33 +0200 Message-Id: <20220815180508.962660797@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Serge Semin [ Upstream commit c1e33979171da63cf47e56243ccb8ba82363c7d3 ] In accordance with [1, 2] the DW eDMA controller has been created to be part of the DW PCIe Root Port and DW PCIe End-point controllers and to offload the transferring of large blocks of data between application and remote PCIe domains leaving the system CPU free for other tasks. In the first case (eDMA being part of DW PCIe Root Port) the eDMA controller is always accessible via the CPU DBI interface and never over the PCIe wire. The latter case is more complex. Depending on the DW PCIe End-Point IP-core synthesize parameters it's possible to have the eDMA registers accessible not only from the application CPU side, but also via mapping the eDMA CSRs over a dedicated endpoint BAR. So based on the specifics denoted above the eDMA driver is supposed to support two types of the DMA controller setups: 1) eDMA embedded into the DW PCIe Root Port/End-point and accessible over the local CPU from the application side. 2) eDMA embedded into the DW PCIe End-point and accessible via the PCIe wire with MWr/MRd TLPs generated by the CPU PCIe host controller. Since the CPU memory resides different sides in these cases the semantics of the MEM_TO_DEV and DEV_TO_MEM operations is flipped with respect to the Tx and Rx DMA channels. So MEM_TO_DEV/DEV_TO_MEM corresponds to the Tx/Rx channels in setup 1) and to the Rx/Tx channels in case of setup 2). The DW eDMA driver has supported the case 2) since e63d79d1ffcd ("dmaengine: Add Synopsys eDMA IP core driver") in the framework of the drivers/dma/dw-edma/dw-edma-pcie.c driver. The case 1) support was added later by bd96f1b2f43a ("dmaengine: dw-edma: support local dma device transfer semantics"). Afterwards the driver was supposed to cover the both possible eDMA setups, but the latter commit turned out to be not fully correct. The problem was that the commit together with the new functionality support also changed the channel direction semantics so the eDMA Read-channel (corresponding to the DMA_DEV_TO_MEM direction for case 1) now uses the sgl/cyclic base addresses as the Source addresses of the DMA transfers and dma_slave_config.dst_addr as the Destination address of the DMA transfers. Similarly the eDMA Write-channel (corresponding to the DMA_MEM_TO_DEV direction for case 1) now uses dma_slave_config.src_addr as a source address of the DMA transfers and sgl/cyclic base address as the Destination address of the DMA transfers. This contradicts the logic of the DMA-interface, which implies that DEV side is supposed to belong to the PCIe device memory and MEM - to the CPU/Application memory. Indeed it seems irrational to have the SG-list defined in the PCIe bus space, while expecting a contiguous buffer allocated in the CPU memory. Moreover the passed SG-list and cyclic DMA buffers are supposed to be mapped in a way so to be seen by the DW eDMA Application (CPU) interface. So in order to have the correct DW eDMA interface we need to invert the eDMA Rd/Wr-channels and DMA-slave directions semantics by selecting the src/dst addresses based on the DMA transfer direction instead of using the channel direction capability. [1] DesignWare Cores PCI Express Controller Databook - DWC PCIe Root Port, v.5.40a, March 2019, p.1092 [2] DesignWare Cores PCI Express Controller Databook - DWC PCIe Endpoint, v.5.40a, March 2019, p.1189 Co-developed-by: Manivannan Sadhasivam Fixes: bd96f1b2f43a ("dmaengine: dw-edma: support local dma device transfer semantics") Link: https://lore.kernel.org/r/20220524152159.2370739-7-Frank.Li@nxp.com Tested-by: Manivannan Sadhasivam Signed-off-by: Manivannan Sadhasivam Signed-off-by: Serge Semin Signed-off-by: Frank Li Signed-off-by: Bjorn Helgaas Acked-By: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/dw-edma/dw-edma-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index 468d1097a1ec..f23569e4b0bd 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -423,7 +423,7 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer) chunk->ll_region.sz += burst->sz; desc->alloc_sz += burst->sz; - if (chan->dir == EDMA_DIR_WRITE) { + if (dir == DMA_DEV_TO_MEM) { burst->sar = src_addr; if (xfer->type == EDMA_XFER_CYCLIC) { burst->dar = xfer->xfer.cyclic.paddr; -- 2.35.1