From patchwork Fri Nov 17 10:03:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 166080 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp419670vqn; Fri, 17 Nov 2023 02:04:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGV7HUoKAB5OihgIo9ry0Rv34jq1w0oJ04QDeMus+l1LrzKdm3ytgIYKVCdPVo0C5uWyxe X-Received: by 2002:a17:90b:3902:b0:27c:ecec:8854 with SMTP id ob2-20020a17090b390200b0027cecec8854mr6431279pjb.7.1700215482835; Fri, 17 Nov 2023 02:04:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700215482; cv=none; d=google.com; s=arc-20160816; b=PTzgNPdiNc7DE80F9EcjI4lc23JpOiIkZzx8t90+jyUgCyN/fWSHNxM5kA0Y6pNPuk 5nEHEsP/tgcncVCpgMfHMETY1usNTTkAHmrbRHYbLzbJfBgBJ9Rv8Rs0OzSvvZIbRdd+ tg4xYxTlLrYkUQ2r9Ko/QzICF7ym6nN2ckPSzOM7bDAkrRRByUrKd5+XJMe9Hz1FVt0I 1fi9XBMf1pn3e1XupaMryeWmHdjnZlpYkhURxfacuVhoyj+RLH+DN5Ov2/KhZ0khvxY7 N9EjbPfy2SKAUXgQS5sGVmS1KuJD22r2+y8DL0jzncCzyZx3JSzilH70NIx9B+yXAYDg Xrbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=ppALPMc1pFTIFQzwRMW+tmzwmtQj10e6/dO7SG+F1wI=; fh=Fko32OqwGgI5WpcqYpp5KigXgtelsKMiigtnZERCGL8=; b=c/+wXk9l45ZK7WQm7NrSMHbgYqbTo8mqXwbRR926Wl7DqpK8NNKbotnisBGM9r8gbu VNUUJgTf+ihaPLc5/ApkqVmdROGLq+6RGpaMtcZhvquP/yzNreBqjfO163YhnhmBWPsp NMnw4rEvb6mXfz5LkaHKtXBdQDGTyaKAPmKLAGFxd16fEAKkwmRFpen8Awak2sJISWtz 2fnH8uHPuQJkIxvHiH8cr2Chp5OygIZCo/DrVMsCFIX7Sb6nM1L0CNzgo3Ik/0uhWKtz C8fcyZ0GLk9gpK0NkBPKu3sj6fwP3JvYs9u9a/IXev/80FaS6N150d8SkXaaLeJv/DTd Vdcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Nk9QOBXX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id lr16-20020a17090b4b9000b0027b258f284esi4057673pjb.26.2023.11.17.02.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 02:04:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Nk9QOBXX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 07AA78270DFA; Fri, 17 Nov 2023 02:04:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345901AbjKQKEa (ORCPT + 30 others); Fri, 17 Nov 2023 05:04:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345812AbjKQKEO (ORCPT ); Fri, 17 Nov 2023 05:04:14 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 345C6C4; Fri, 17 Nov 2023 02:04:10 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 61BA3FF81F; Fri, 17 Nov 2023 10:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1700215448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ppALPMc1pFTIFQzwRMW+tmzwmtQj10e6/dO7SG+F1wI=; b=Nk9QOBXXkZe4llaGhdKMLdybPq2Ys+qCWgZHo0Pqu1T/I1N0M3dRksIcsoMHP7nr5dtfxf 6i/sa+juuDTM+sP6A8BzmOF5UvDxgis/3p0tNggqxlk6nvDiHiVJ66i3UxsbEGn8rNw8le 5QSFaLRjEDZpgXIBZRUlVjICboIiEyp7IA+8UjD841jsPLL6MpoTpOuoNIH34uBqZTRmFj l4xEwiaZ74ODB4KZez8YoSvsWpSBRdhOTYNxbFcYgl3vLOL+cLUrswuB+sEgOOBqptNK/y +R6DIe+sLhbC82Qkx6wZGL9NojMmTkyB1B8buzuZ85auJPJIEQsMJS//3YxCsA== From: Kory Maincent Date: Fri, 17 Nov 2023 11:03:53 +0100 Subject: [PATCH v6 5/6] dmaengine: dw-edma: HDMA: Add sync read before starting the DMA transfer in remote setup MIME-Version: 1.0 Message-Id: <20231117-b4-feature_hdma_mainline-v6-5-ebf7aa0e40d7@bootlin.com> References: <20231117-b4-feature_hdma_mainline-v6-0-ebf7aa0e40d7@bootlin.com> In-Reply-To: <20231117-b4-feature_hdma_mainline-v6-0-ebf7aa0e40d7@bootlin.com> To: Manivannan Sadhasivam , Gustavo Pimentel , Serge Semin , Vinod Koul , Cai Huoqing Cc: Thomas Petazzoni , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, Herve Codina , Kory Maincent , Manivannan Sadhasivam X-Mailer: b4 0.12.4 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 02:04:42 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782805149759328173 X-GMAIL-MSGID: 1782805149759328173 The Linked list element and pointer are not stored in the same memory as the HDMA controller register. If the doorbell register is toggled before the full write of the linked list a race condition error will occur. In remote setup we can only use a readl to the memory to assure the full write has occurred. Fixes: e74c39573d35 ("dmaengine: dw-edma: Add support for native HDMA") Reviewed-by: Serge Semin Reviewed-by: Manivannan Sadhasivam Signed-off-by: Kory Maincent --- Changes in v2: - Move the sync read in a function. - Add commments Changes in v4: - Update git commit message. Changes in v6: - Fix comment typos. --- drivers/dma/dw-edma/dw-hdma-v0-core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/dma/dw-edma/dw-hdma-v0-core.c b/drivers/dma/dw-edma/dw-hdma-v0-core.c index 04b0bcb6ded9..10e8f0715114 100644 --- a/drivers/dma/dw-edma/dw-hdma-v0-core.c +++ b/drivers/dma/dw-edma/dw-hdma-v0-core.c @@ -222,6 +222,20 @@ static void dw_hdma_v0_core_write_chunk(struct dw_edma_chunk *chunk) dw_hdma_v0_write_ll_link(chunk, i, control, chunk->ll_region.paddr); } +static void dw_hdma_v0_sync_ll_data(struct dw_edma_chunk *chunk) +{ + /* + * In case of remote HDMA engine setup, the DW PCIe RP/EP internal + * configuration registers and application memory are normally accessed + * over different buses. Ensure LL-data reaches the memory before the + * doorbell register is toggled by issuing the dummy-read from the remote + * LL memory in a hope that the MRd TLP will return only after the + * last MWr TLP is completed + */ + if (!(chunk->chan->dw->chip->flags & DW_EDMA_CHIP_LOCAL)) + readl(chunk->ll_region.vaddr.io); +} + static void dw_hdma_v0_core_start(struct dw_edma_chunk *chunk, bool first) { struct dw_edma_chan *chan = chunk->chan; @@ -252,6 +266,9 @@ static void dw_hdma_v0_core_start(struct dw_edma_chunk *chunk, bool first) /* Set consumer cycle */ SET_CH_32(dw, chan->dir, chan->id, cycle_sync, HDMA_V0_CONSUMER_CYCLE_STAT | HDMA_V0_CONSUMER_CYCLE_BIT); + + dw_hdma_v0_sync_ll_data(chunk); + /* Doorbell */ SET_CH_32(dw, chan->dir, chan->id, doorbell, HDMA_V0_DOORBELL_START); }