Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1423645rdb; Mon, 2 Oct 2023 09:05:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLKa2G8G9XNCq01f1fYyaj+npXYe+8SpJ/N3t1jxHPPlnQeLUpoZC+lty0dWlAyRRi++8z X-Received: by 2002:a17:90a:fd04:b0:276:7e50:a497 with SMTP id cv4-20020a17090afd0400b002767e50a497mr8418477pjb.42.1696262708889; Mon, 02 Oct 2023 09:05:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696262708; cv=none; d=google.com; s=arc-20160816; b=KvFus2ZnzgRRvOqOXBam+4cACMjTt15z3XI+L4OdST+B4ZTJ+A2SqBhyXqkf4jkwiN iU4EgFBwLb5lAv1ZuUlQtniild0fP9qbwMKT30BFfk8TgxyxEnNp2iR4Mhr4HwqY4ael 6BlvC/FKLiabdLaTXxkkEuOMwd/oagToBL59EEehAe3HLBJoyIWrm9uT67wLATyC+NVK nVZ2z51/bjnClPl8HGxuE4Z4zn30+4C4vx8FpRdK+cZAm7uchAFo9T9y3v+vOeZDW/+7 KBXaiLbobWDLanRBtBxE986bgufEx+I7j9m2ojEcWZRjNqxmG0NPlCjaGr7s5jQAc/7V mxxw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F+CSUvAMd1jybDq39rbPIkUIvZut6yZ4pfXMFOmMcHw=; fh=3Wij1Nyq0kk9iFJBGjsMqOGfirL0oXoeYA+XKMkEeWg=; b=bI/TX/dj8C4WMXCOMqtrdvCWSfrdhksbzgBushqrXA8tVCU2wKrZEzPwrlHqPyQsdB w4z0Etbx/N/gF4s8/Q0/1p5jKoxG+gvRz6beixwJVlcVslS4bV1AByPsS+tB2R7/+aoe bIEN/yD/VMrGEuUMnHdlWvompUT54uX1rIeI7QrImhPUHYZjxqfXRjaYP0EKgB5bLPtC U4L15+opCsk7kavCSLpuC0S9MVYKK3PnNYS+DZAGWmeH82Eyfmc+5EsiXaSjBvj54jT3 KnB+wruKTa7ADPwpe9XopBmb/x0F25usk/vf0YetlJhH9ARA9AjJkwE+04t3UgR4ja5i LUWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Bu7573Vh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id lp15-20020a17090b4a8f00b0027909685905si8675513pjb.149.2023.10.02.09.05.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 09:05:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Bu7573Vh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 47143802658A; Mon, 2 Oct 2023 06:18:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237432AbjJBNSP (ORCPT + 99 others); Mon, 2 Oct 2023 09:18:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237381AbjJBNSB (ORCPT ); Mon, 2 Oct 2023 09:18:01 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3EF3C6; Mon, 2 Oct 2023 06:17:57 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 81AED1BF205; Mon, 2 Oct 2023 13:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696252676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F+CSUvAMd1jybDq39rbPIkUIvZut6yZ4pfXMFOmMcHw=; b=Bu7573VhSa5erKsSfwK0iaEuh1VE0npy5odZq3iNi+YU0L+E6Tg69KeevCCXPqC0VXyT0a RZp//Qp3exSV75CU9MjD1plVw64IoBSBKPfq8+lVCOj7LfG3TPAAPh/aQiZ+tHCIbmce3x IFdbf3LBwq1ba/VIlrmUAIDMgJ8WJOPLvf9+v6ZZX/oOr9BKlYLaTpNUHktd7Dyq+lgWTj xzwh835qXlf65Ccnr+nmscYy5V4gVZb0cBcj90RF+c0KbU/r9K1dWAxSbA20feyzGcDzIs rj9+RKK49RBbwx2WPqWSgYgzkCgEV8EFgOoH1Gu7HABc0jo6qrkHAD+ofj8U2Q== From: =?UTF-8?q?K=C3=B6ry=20Maincent?= To: Cai Huoqing , Manivannan Sadhasivam , Serge Semin , Vinod Koul , Gustavo Pimentel , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Thomas Petazzoni , Gustavo Pimentel , Herve Codina , Kory Maincent Subject: [PATCH v2 4/5] dmaengine: dw-edma: HDMA: Add sync read before starting the DMA transfer in remote setup Date: Mon, 2 Oct 2023 15:17:48 +0200 Message-Id: <20231002131749.2977952-5-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231002131749.2977952-1-kory.maincent@bootlin.com> References: <20231002131749.2977952-1-kory.maincent@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Mon, 02 Oct 2023 06:18:44 -0700 (PDT) From: Kory Maincent 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 can appears. In remote setup we can only use a readl to the memory to assured the full write has occurred. Fixes: e74c39573d35 ("dmaengine: dw-edma: Add support for native HDMA") Signed-off-by: Kory Maincent --- Changes in v2: - Move the sync read in a function. - Add commments --- drivers/dma/dw-edma/dw-hdma-v0-core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/dma/dw-edma/dw-hdma-v0-core.c b/drivers/dma/dw-edma/dw-hdma-v0-core.c index 0cce1880cfdc..26b5020dcc2a 100644 --- a/drivers/dma/dw-edma/dw-hdma-v0-core.c +++ b/drivers/dma/dw-edma/dw-hdma-v0-core.c @@ -221,6 +221,25 @@ 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); } +/** + * dw_hdma_v0_sync_ll_data() - sync the ll data write + * @chunk: dma chunk + * + * In case of remote HDMA engine setup, the DW PCIe RP/EP internals + * configuration registers and Application memory are normally accesse + * over different buses. We need to insure ll data has been written before + * toggling the doorbell register. + */ +static void dw_hdma_v0_sync_ll_data(struct dw_edma_chunk *chunk) +{ + if (!(chunk->chan->dw->chip->flags & DW_EDMA_CHIP_LOCAL)) + /* Linux memory barriers don't cater for what's required here. + * What's required is what's here - a read of the linked + * list region. + */ + 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; @@ -251,6 +270,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); } -- 2.25.1