From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8976D33F5AB for ; Sat, 11 Apr 2026 11:43:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907793; cv=none; b=uC07syFjGLJ6cShbMXWUOF4up2wvwxY+tr9i3vG1Fsg5pQbqQkqZ4UciOTixHH90pjz8E+lOmppucYdLNtWMsleHQEQJG5rR7VBJTsL8v+JaJpWAIsC8lWa9KHChnueVLPXd5sQ4VieMVQnPXvqZGmWbtrFJMl5Jw8hkNgHq4Qs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907793; c=relaxed/simple; bh=SIisgWIq7iz0fEX6zbuC2vzUQFNOenfE175SXgsqSCI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gjLNW4jcI8iLZgTsYI4THoB3/cfE4chMWr8m6v8k/cz8rdebePd8yREnaayayTTzrVHjrf9KQfgvLET/ffhaMt5QooUBlSHT1JN9M03ITUkIY9CDFRD23BbAyv+9Mc2989jaB7isnxngEtqOCFvSaIcm6iDS19btnBCotWBnIcc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=AlTA3i+/; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="AlTA3i+/" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-48374014a77so40484715e9.3 for ; Sat, 11 Apr 2026 04:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907790; x=1776512590; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2xnheHvaNltUuBI9CjLhmlXKJ1g2zxubkvsSzZotxIQ=; b=AlTA3i+/aEmGGqWaBB/kIenOvnULZwPvTCVjI0P+kS15UAYBEzTk4h4GhouQd55ocE LAgQ03YVZ0Iqqhif14f/F1dM7IT4GAVEXJwcCBkQ2KMgYea9wVaDgLvRctwtcF9q+oAe vGFL1k305VFnGQbB8cRSO1PW7ybMsQOW33tZHAFTztQhz3VbLLH81jq66YqJCmI85Aif R2d+kISc8scZXfIvU0nPu2W1f7rIspQ1V7bYtijgohYBgA/nfr4NjLu8bcYSNDM4hbVC OcKCweXLKSE9Z3HCLqSlBDjiO5dlJgLkwV4Wb8xCidGG5N6YSVY74+B2rD8HxxgTl4Ct U3nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907790; x=1776512590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2xnheHvaNltUuBI9CjLhmlXKJ1g2zxubkvsSzZotxIQ=; b=reniPfebT2C9zl/KZmshrADuocVoIvBjMWhVbpSiTtWLIR9ZLy83ppdRqerQXe2TXk PXhnwJKazxhG79Yr5RSxHLfpnn2b9KxBNhBzT+dLO0xo1sxm2Pvj1ikFlEqPDFkXA1nN +sc9xWxQjeD9ME3Uh+ZN8KJHVA01h/plEy45DmdHPubSvd5jZ97UBDB56uIBSoy2xAG4 wfFZpOkJqtEPiT90q6h/fUBU5o+JtIU/QslIjsSaXeuoWwDwDOA22X/B45Dz9jNGUsCq ePlxlCfyUTUoqH3ee3H/6zB760rWRi605eyINUfnX5x7pnz0ZWwVfN8ZraHk0xFeiXgU 70RQ== X-Forwarded-Encrypted: i=1; AJvYcCV103Q/38jlzknXAUyU7U10dOXav1FT5ypIKtYHOXHtGjhXFFtX3vb93ZJlqinVitMXuQT8/76ffJaHJnc=@vger.kernel.org X-Gm-Message-State: AOJu0YznJsWEHHQu7B15Eedrp9r/SICMj+h+dxVOnSsMT7hGvwX8SAil OUpbvTQheU0e/fPEFvuDOZG+JoayCsM1iiatv4fleM/0fBa+yBGFBwRWWkPbBPX8SuY= X-Gm-Gg: AeBDietwsL8mvAcJmWFXK2F0C6vphgHVILqAxAoglIoiInHLbbAT9sEHIlfBgy+oNEd NaBwEVPee8MTubFPPNJGcX/OoiPqwPWBMJepHGCJ/LzNjLRXlCTtwebjGePXb0af42SvlTkFasf 6Sr7BPpaoHF/NFVRrAbQsx5aRmIlFtGECtVQ+3aA8Ro+3ItXt5qs/3+OksFk56dQWLdslLSjnDl 6W8taJz6jpW6DqV2w1+UAvgYDY+7HscnrZfze3MDxzo/2CG9hLfdKnTI8Hy6CRKDz38KzyUs4uA 2IkyJMezbGbTY6OGQPCcKkvVaxDnSDdBgjJfUDj2ukwuJGo16kMVMD66+UCVsTWaOcDXq8ZmQVi AhbVAl+E0Lb01nWa70xYLTQXzFAEArsejg028a1tt0v57uPuge0Iw2Kiz1l5+CeDkSxULufKiLh Xkm24viPBkFOFUHToHY35LjpZOejFVwNh6L4kCYnbKMV17tA+UiyhXWYoamfsulSQ= X-Received: by 2002:a05:600c:c171:b0:488:a894:b27a with SMTP id 5b1f17b1804b1-488d67f0105mr91856815e9.8.1775907789889; Sat, 11 Apr 2026 04:43:09 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:09 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH v4 01/17] dmaengine: sh: rz-dmac: Move interrupt request after everything is set up Date: Sat, 11 Apr 2026 14:42:47 +0300 Message-ID: <20260411114303.2814115-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Once the interrupt is requested, the interrupt handler may run immediately. Since the IRQ handler can access channel->ch_base, which is initialized only after requesting the IRQ, this may lead to invalid memory access. Likewise, the IRQ thread may access uninitialized data (the ld_free, ld_queue, and ld_active lists), which may also lead to issues. Request the interrupts only after everything is set up. To keep the error path simpler, use dmam_alloc_coherent() instead of dma_alloc_coherent(). Fixes: 5000d37042a6 ("dmaengine: sh: Add DMAC driver for RZ/G2L SoC") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- Changes in v4: - none, this patch is new drivers/dma/sh/rz-dmac.c | 88 +++++++++++++++------------------------- 1 file changed, 33 insertions(+), 55 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 625ff29024de..9f206a33dcc6 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -981,25 +981,6 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, channel->index =3D index; channel->mid_rid =3D -EINVAL; =20 - /* Request the channel interrupt. */ - scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index); - irq =3D platform_get_irq_byname(pdev, pdev_irqname); - if (irq < 0) - return irq; - - irqname =3D devm_kasprintf(dmac->dev, GFP_KERNEL, "%s:%u", - dev_name(dmac->dev), index); - if (!irqname) - return -ENOMEM; - - ret =3D devm_request_threaded_irq(dmac->dev, irq, rz_dmac_irq_handler, - rz_dmac_irq_handler_thread, 0, - irqname, channel); - if (ret) { - dev_err(dmac->dev, "failed to request IRQ %u (%d)\n", irq, ret); - return ret; - } - /* Set io base address for each channel */ if (index < 8) { channel->ch_base =3D dmac->base + CHANNEL_0_7_OFFSET + @@ -1012,9 +993,9 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, } =20 /* Allocate descriptors */ - lmdesc =3D dma_alloc_coherent(&pdev->dev, - sizeof(struct rz_lmdesc) * DMAC_NR_LMDESC, - &channel->lmdesc.base_dma, GFP_KERNEL); + lmdesc =3D dmam_alloc_coherent(&pdev->dev, + sizeof(struct rz_lmdesc) * DMAC_NR_LMDESC, + &channel->lmdesc.base_dma, GFP_KERNEL); if (!lmdesc) { dev_err(&pdev->dev, "Can't allocate memory (lmdesc)\n"); return -ENOMEM; @@ -1030,7 +1011,24 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, INIT_LIST_HEAD(&channel->ld_free); INIT_LIST_HEAD(&channel->ld_active); =20 - return 0; + /* Request the channel interrupt. */ + scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index); + irq =3D platform_get_irq_byname(pdev, pdev_irqname); + if (irq < 0) + return irq; + + irqname =3D devm_kasprintf(dmac->dev, GFP_KERNEL, "%s:%u", + dev_name(dmac->dev), index); + if (!irqname) + return -ENOMEM; + + ret =3D devm_request_threaded_irq(dmac->dev, irq, rz_dmac_irq_handler, + rz_dmac_irq_handler_thread, 0, + irqname, channel); + if (ret) + dev_err(dmac->dev, "failed to request IRQ %u (%d)\n", irq, ret); + + return ret; } =20 static void rz_dmac_put_device(void *_dev) @@ -1099,7 +1097,6 @@ static int rz_dmac_probe(struct platform_device *pdev) const char *irqname =3D "error"; struct dma_device *engine; struct rz_dmac *dmac; - int channel_num; int ret; int irq; u8 i; @@ -1132,18 +1129,6 @@ static int rz_dmac_probe(struct platform_device *pde= v) return PTR_ERR(dmac->ext_base); } =20 - /* Register interrupt handler for error */ - irq =3D platform_get_irq_byname_optional(pdev, irqname); - if (irq > 0) { - ret =3D devm_request_irq(&pdev->dev, irq, rz_dmac_irq_handler, 0, - irqname, NULL); - if (ret) { - dev_err(&pdev->dev, "failed to request IRQ %u (%d)\n", - irq, ret); - return ret; - } - } - /* Initialize the channels. */ INIT_LIST_HEAD(&dmac->engine.channels); =20 @@ -1169,6 +1154,18 @@ static int rz_dmac_probe(struct platform_device *pde= v) goto err; } =20 + /* Register interrupt handler for error */ + irq =3D platform_get_irq_byname_optional(pdev, irqname); + if (irq > 0) { + ret =3D devm_request_irq(&pdev->dev, irq, rz_dmac_irq_handler, 0, + irqname, NULL); + if (ret) { + dev_err(&pdev->dev, "failed to request IRQ %u (%d)\n", + irq, ret); + goto err; + } + } + /* Register the DMAC as a DMA provider for DT. */ ret =3D of_dma_controller_register(pdev->dev.of_node, rz_dmac_of_xlate, NULL); @@ -1210,16 +1207,6 @@ static int rz_dmac_probe(struct platform_device *pde= v) dma_register_err: of_dma_controller_free(pdev->dev.of_node); err: - channel_num =3D i ? i - 1 : 0; - for (i =3D 0; i < channel_num; i++) { - struct rz_dmac_chan *channel =3D &dmac->channels[i]; - - dma_free_coherent(&pdev->dev, - sizeof(struct rz_lmdesc) * DMAC_NR_LMDESC, - channel->lmdesc.base, - channel->lmdesc.base_dma); - } - reset_control_assert(dmac->rstc); err_pm_runtime_put: pm_runtime_put(&pdev->dev); @@ -1232,18 +1219,9 @@ static int rz_dmac_probe(struct platform_device *pde= v) static void rz_dmac_remove(struct platform_device *pdev) { struct rz_dmac *dmac =3D platform_get_drvdata(pdev); - unsigned int i; =20 dma_async_device_unregister(&dmac->engine); of_dma_controller_free(pdev->dev.of_node); - for (i =3D 0; i < dmac->n_channels; i++) { - struct rz_dmac_chan *channel =3D &dmac->channels[i]; - - dma_free_coherent(&pdev->dev, - sizeof(struct rz_lmdesc) * DMAC_NR_LMDESC, - channel->lmdesc.base, - channel->lmdesc.base_dma); - } reset_control_assert(dmac->rstc); pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CD59343D91 for ; Sat, 11 Apr 2026 11:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907794; cv=none; b=XCvmw0t2gBy5nPBYxfqfaL+6efQvnR7d9RwOkzC0jsosCjP30lCN8h0LJyjIA8Ovii/kASCe8gDGjx7bJhSGRwt2ZBt/0CNp7G1kZ6AGKkLm2J6OJOjKAeBPIYFkl+qaUQBzDYU09v4mHkufVo8IpXouMqaZM+OOI3cWDYKJXK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907794; c=relaxed/simple; bh=QGre1JnMJ7EtNooAlP++jw+4gePWfV/O1V/jrTmI22o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Td0Y+zobn+ZYFcVFPkytnY6mGKyYqK3zKyko+bybTA8oAYeo76Cv/pEjfa2roWcxvUJZUySOkB4L8QW8nFwRvtQ8SoCCPQIqcPC9DwCEwhR8Ql9hoJytPdQ6S3MCilkLgEx2GZkKKgArDpI4ay96rgCfMsKVHb9ep21jLjtclcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=j7fp2xD1; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="j7fp2xD1" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-43cfb723793so1966218f8f.2 for ; Sat, 11 Apr 2026 04:43:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907791; x=1776512591; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R7WML25G5xFq4y3e3IxD4yNlbeDhj8/OemWvzra0+LM=; b=j7fp2xD1T53W9ogUMGE9CsyEh2Wvxa5BEDuORsSFSZdijZ4g9e3Y6tM9UpNwqdRhXc wb8pUBCjZ+W1hRnsc5iPYBifIdr4uQd5oI5e2qsE48QDHcbBF9ppmv9P77RBPogGpCtC ePqFmRpxHR1Om+dU0XS90aBGf0MU17PQ4V1FuGoNtYud1FiVDaPt2A368+OnEvkILUe6 WhTQrRV5zSNNq6N0QWIe3ulOttp3miqRRsSodLqvQn2O5Wbzt0qPJDq55Qf2bnOZhz1E D/kaeS4bcssqYB/l1lpJFlhY+iI3+ca+EPPfY2XLgukpciKYKTmHfigIZXSRFu6qBY/9 7FAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907791; x=1776512591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=R7WML25G5xFq4y3e3IxD4yNlbeDhj8/OemWvzra0+LM=; b=kt+Ky1glFiVObWvRxb2Dpilm4EjpYbz+sluTmXDFqqHsrTsiPXToSTahCtvg5v54xH 4UMpCM5SxClrX3sA5BIX5+5QP9mbOeIi/CdF85NuLqkiV0apnBOTu+GKwp/xyy2z7PmN 6dy7a3OaNtPKMmjhEeYy8Xe48zM3QUzY3ajuTlVS+TRuUX6MmO9lm+Lbc7XqzBHFo0XS +SfNQwHAS1Sjq+C99HXNG9KBqeRr9vGIWULbW13IwrTrpQgq6+XLenIOy03rjfV62WtV fzkEfybzxYGngdKvf2rM2hiUkahU1G4vkLuJqeRD632CxAT0PtlRnZCg4MP+MgI6Nszn 7cJA== X-Forwarded-Encrypted: i=1; AJvYcCX9YYkFapR8IukQxNwpWu8Bzqhfq195AzJL4q4bBa6mwMw0PyuXoXy7HH8BQTT/HjxWvWNXrvS+BPPMwx0=@vger.kernel.org X-Gm-Message-State: AOJu0YwgqTtsGvtqiwPPTCUKyGnwbKxxqEzzKM9IRx82jU1CTHaGCN2n k5AVq71atJQVMk/yNdpK8D5r45rRONvRjg7aDg3TG/FNVm5rg5QkLLz7uB9nzTrxpsM= X-Gm-Gg: AeBDieuHKluQhRavCS7dwgjUTn5PuuZyMqT6TqREEaksYBt88prL+sVJVysM+LtxmWA 5g0zmVp9a14s/ynCRl7PaOlCMUYEnawLBI/I1ksxTTMQOiwdqJqyRTtI3nU1mNyres1/eLTEfsx 3W021HytScCICcfZ7QWf3OA7JpmEN3hJPn07Z7z5tYPcjnLty5XI3gAT+tDe+OFc/XZ/5GVsdsK 6Ay2wvzZAyOqsjDCdY7vTorP1HWfRsrrI43MbEA8Ao0MiB0ti6gALX8tMgW3uz1SMo9wPQt1oX6 bizgYkg/CgwsNPtQU5ixnHqT+HAHp6jHSil1CHGohgl6z1I9MvXkk1NmfrGUEnpdXxWmMNfVV4b NgIfRSpgXJTspb5d5OmluSx0nRvm2E9iK4Y46JGjdB20kNdaxy2jk6fH6Oagy1ITfDm2rqXd543 s3cDEHcF4AxSmlSHSnR/g/G28ZRCE6gamImXZc5nhuWgb78FiNxZGR X-Received: by 2002:a05:6000:2886:b0:43b:4982:fc73 with SMTP id ffacd0b85a97d-43d642c77cemr9629206f8f.25.1775907791508; Sat, 11 Apr 2026 04:43:11 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:11 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH v4 02/17] dmaengine: sh: rz-dmac: Fix incorrect NULL check on list_first_entry() Date: Sat, 11 Apr 2026 14:42:48 +0300 Message-ID: <20260411114303.2814115-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The list passed as argument to list_first_entry() is expected to be not empty. Use list_first_entry_or_null() to avoid dereferencing invalid memory. Fixes: 21323b118c16 ("dmaengine: sh: rz-dmac: Add device_tx_status() callba= ck") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- Changes in v4: - none, this patch is new drivers/dma/sh/rz-dmac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 9f206a33dcc6..6d80cb668957 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -723,8 +723,8 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan= *channel, u32 crla, crtb, i; =20 /* Get current processing virtual descriptor */ - current_desc =3D list_first_entry(&channel->ld_active, - struct rz_dmac_desc, node); + current_desc =3D list_first_entry_or_null(&channel->ld_active, + struct rz_dmac_desc, node); if (!current_desc) return 0; =20 --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A21E3451B3 for ; Sat, 11 Apr 2026 11:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907795; cv=none; b=coPMa0szH92SF6fOe48BACPlO2DDawObnEah6QyHn66n7DT3UMe5wpOVY/pd2bWjhLS/q71Id8sUOd3xgvZq51TVm22UMiGN/gKVrGXBmLShJ/eZuEeoCAnRy/uaAWa1Z4D0VNasJcBAZuj46heDSDScxM3o3j5/0DrOH0q2iHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907795; c=relaxed/simple; bh=ZB6OzeV1iuOY4cphwcy1NTv7nOJuOcS76pQLBa2mvQo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WMVX2DMwafepHAJq5YVnuP16ioa8HLng1czIrPykDPNfLv8+rwGEM3qjAQRep96bvRcPyWvfmtpfn8FopAXxI5Wk95ulHI92l5SLSv0uk+83ZYOmV2qiKPMqvw0f1GQ9OQlnw6NwsDs7rr7qq7EVD4AhNebscXJhoqSFiTxr1hA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=UaQ8JVKm; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="UaQ8JVKm" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-43d01d6b50cso2887373f8f.1 for ; Sat, 11 Apr 2026 04:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907793; x=1776512593; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7j+XdlT3aD7tJGwl9xLTbJEKXv1OztcK3gKQoyq2CgQ=; b=UaQ8JVKmly6Bd6KpAeT0HIxw89p8cBqDvUR3YQYkHE/dboPgPUIt5zz/3sQ9WRaykp WjWbWfeL4ZrflH41LxHJTDeWLNW9qevlHTs32AF5taRIYUe6gRsBhKuhWvFEL6mm29Zd IgkuzXYeNtW6KE8Zcfsh44WGDVqoTaudNdQGB5CxAXlOuj2Au7k918yjvU2FivDomPS+ IXP5rcA6ADrXnJrGE9C5324eOo+B1XnRaUiiwU2n3ZgNSfdN0f9wEmA7ObbC+UelynZF BbOmyfEcjSgMWf3WfAs6+T53SvB2A/TmPFdILdbUwdNoIrnifDlezgzkVBUk1TZDbycQ fa8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907793; x=1776512593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7j+XdlT3aD7tJGwl9xLTbJEKXv1OztcK3gKQoyq2CgQ=; b=aB5CGQ9Cb6YA16rxQId7WQop7YVFfraS9EI75Lh+IsfYEPXsUtKdPU4ZjZ7O0tBHlz tpBChwE4BRJD9ZK6pEiD7qIlmTuiNYViUTg6CfAagRVjOVnE/pv4hEzhjLfNHl35Stfi HK74DrA+CS91oUXiSeZxIAfAp7LdWGKehmH8StiP64DtXwRkFODL+quEZ/AzAm4V6xL2 XN6FHoIzlBdCo3cFsl4yOD7Dy2eG3K9GqDcUJ94c6kZ0elP6KnXVf0C4PBGxf7bzLmpV +n1XcEzCxXZ4Jkw3jvJrjq1ApbcsbsthRfxYIY6q/EKN3gQ63hQrr6IA2vjHEGOYeYE9 QBKw== X-Forwarded-Encrypted: i=1; AJvYcCWZ96+eNc16ikHugMIBvrbOrPOwzVctd+tJfCC15nDbahFB9hhMxOnv5Z5yf21ABLxW44oMS79WvAL7Vd8=@vger.kernel.org X-Gm-Message-State: AOJu0YyE2K50fv0+4Q7HdhYhy0LEnS/QcMb1G/onJB4UUWi9S/uo5fNX HdbrN5iIJDIBYtrQEEjZdQZSTF/AD1KUZrj9lVkIBazZ/DkcMhY1q7iKgbia1HMVw0g= X-Gm-Gg: AeBDievlnqZhwFxlle1ycSug3aTnHfLT9ty8CdUCCk/65J9SYYCcEhXD01jG4IZa5Nz Dn1mQkvFSwNEpD157ErACPGpzOy5R+248fCEBlCJV3j1NWsnhbNKn2xY269LGoowvpWUVgG+o4z KKfqbqQv92D7IuAX1lvQpVlX0uZsXoHWx3HiPN53whKhGVUveyIR/vN7N1bczUzd/Be8y59DkzO B/KjBW+Z+uN/8OkKLjyuYHD8kSWZ9KrCTasyLleTnMXrMR2gGJyjdKrguUTbpXB/M5IzUjSvKKh 5M/PtiW6tn3FyWBmYGqbDdeo1x65MT4/AaJyXoPdzKtzerWIoW/FO3X3G3Nu1EhgFix90oxuEzm tLl/Vo5sVXmMM7v3xgBcekFCImEPmbDRmQIyBZdtrvFoOgUggQSg5GndnwreRsKQ1lZvjuKEDv5 bSsRXw0DPUwsHHcH3o3yPXXrCDexXi4MQELqWVyVHLyl9Bk9vm+S6B X-Received: by 2002:adf:e80d:0:b0:43d:69ff:6898 with SMTP id ffacd0b85a97d-43d69ff69c4mr3162191f8f.9.1775907792998; Sat, 11 Apr 2026 04:43:12 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:12 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 03/17] dmaengine: sh: rz-dmac: Use list_first_entry_or_null() Date: Sat, 11 Apr 2026 14:42:49 +0300 Message-ID: <20260411114303.2814115-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Use list_first_entry_or_null() instead of open-coding it with a list_empty() check and list_first_entry(). This simplifies the code. Signed-off-by: Claudiu Beznea --- Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 6d80cb668957..1717b407ab9e 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -503,11 +503,10 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_ad= dr_t dest, dma_addr_t src, __func__, channel->index, &src, &dest, len); =20 scoped_guard(spinlock_irqsave, &channel->vc.lock) { - if (list_empty(&channel->ld_free)) + desc =3D list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc= , node); + if (!desc) return NULL; =20 - desc =3D list_first_entry(&channel->ld_free, struct rz_dmac_desc, node); - desc->type =3D RZ_DMAC_DESC_MEMCPY; desc->src =3D src; desc->dest =3D dest; @@ -533,11 +532,10 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct s= catterlist *sgl, int i =3D 0; =20 scoped_guard(spinlock_irqsave, &channel->vc.lock) { - if (list_empty(&channel->ld_free)) + desc =3D list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc= , node); + if (!desc) return NULL; =20 - desc =3D list_first_entry(&channel->ld_free, struct rz_dmac_desc, node); - for_each_sg(sgl, sg, sg_len, i) dma_length +=3D sg_dma_len(sg); =20 --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FB96340293 for ; Sat, 11 Apr 2026 11:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907797; cv=none; b=tt0hG0oA6tnUpvo94tcmij5XTnOYSm+7+/emDoBlL4bp3hGbqpuVSwIVh8ZhAXXn/Wuw29dtl0jMSSH06GVhJirQAvS4Ymhr+ESt+aCiMRznAasbxCW96sIG3SxY+AidyFp07k1fGfBs7M6AqwFTLgqmZ3aQQu1hE25aqEx7Bfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907797; c=relaxed/simple; bh=gmR2MVgWRVwxG2GLS1GQZ1Ib/I0giv+IntwWqRZ8pCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lXpf8z9YIDoBf1faF/OFHz/E3Vw2Tx9HPkr/M5A2oFe3pyBtxyBEvpaWS2v1KHCLeecpyXnWd2r7vEsY3iucZyNQ9KE+Q6WtcVS0c5AqzcdSpqa4i5k9KTMksI8GHWRV/gXrZRljo21WYnSSBHfAuVgDoye0tAh7MrEB/9C6UZk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=LWK5zAMA; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="LWK5zAMA" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-43d17bb1c65so1906425f8f.0 for ; Sat, 11 Apr 2026 04:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907795; x=1776512595; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uEklTJzShDhVfSMVqbktdCdKI5vT2XbfZJslRpJnIVQ=; b=LWK5zAMAs5Qrl1Q/JOXtiW2AyxCvqFKJHYeCsBZ2SPR/cN2cMKxQ80H+jKARE6Cx3F Ni8HLEOvVriHKK7lCRP7CXIEFtHD17VPnuQvGYajQOtRgtwVDtU6m4af8ffmRt8EyjRk FMFYNFNM3WYUAm7fFe4rEJQS/P9s7KAI4bjfzxXriAhK5EZhtUvzwXY5rZFUzfo3MQkG 7255XWamcLGLD/ykQFcaQ5dS29M2cnkhFpRjjedzK7l0Y6LElbZDFDt762qZrVLf54oL R4GTYMKVsH7W6qtxwx8OlxjzjVD7umaqLRgRICDgNqGIg/VGdTUDb9YEsEyZdwpAnSM+ RbyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907795; x=1776512595; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uEklTJzShDhVfSMVqbktdCdKI5vT2XbfZJslRpJnIVQ=; b=cJbi3ZzgrKCc2dMoMZf2hDiDfLdpOG2gWaivUIQqiVwgTMAvLYstsGMxGAwuSd4Axy ZdRZcZL639VXtjtukNpS3EsA/8ZrL8JzhtjfLRhToQqC0ahUrnwI5aa9onUv+Lo8Kzvk bpttOLnE6WNbSEZZosb3LIWE8WjvI+rc1a28V5Lwq+Dpv6pwDrrOXhxH55cE8+4gRSQH 2hdYcsHo24El0hAWUTVN41hQu1FrvVAzK+vRQPvLnozjcP2tOi9erjbUPmKpvqS4Ww7g sYsuoXj2mn9cFpPKxfcMaHCgu8d/ts3nx2mDxcmFw5xbBJ6J223RuCnRngFWMV6cduxu Anuw== X-Forwarded-Encrypted: i=1; AJvYcCU81afsKX7DOgflYhIqCis1siWXLQz3GYh31oWdLGeWrf0NqtzQDiXTVFA4E6clxLARXment7ygEeHGu+c=@vger.kernel.org X-Gm-Message-State: AOJu0YzO/yiuOOvlPdh+5wncbym4FddM3StEJfVncKFsdJmmO8qun7Fv xebIlBtvTd416ZxtP/ehRgiJNPURLgGT0MSaMi7cp2XcBHnFIqbKRbZ+k0YCZ/ydy/A= X-Gm-Gg: AeBDiev1pWza6mk10C1ZYkBHVAqllxDl0cPO9OY6bB2vJNXgK1dinyyB5rthHZX0e+D m3srpdetUW3EXlS0c9SyP7asZbZKkT5Jp4r+97HIW8zR+4u8wU7YHTQ3eNFmOdpQVeoab7GcQd+ oxtYS73/pmL+6AMdds52AQ1CpqtSh8/sh0ar0NmCdjcD1o4657qH/KSw+Iw8kfjk0LMD+PsCj7E GebB443AEEeGfgl/bNdh6fPFDF9OA4Tf2w59hNoUbGOvA8St4BYhwetPqGYADC+z0LzsqtCeeFH UBqME5GscsKoBPikNZpuYZUrAqgJZBwdJMnVmPQJpV9oc48Eg8Xjmzcq/b5mC47vl7pI5TE8Qmv N5CCoN9M/JcF2s7IJ9UjFAccv3l5AT++YVk4scV6r3VjUg6Wqk66QmgeoJj39OU30SVx229iBMs G88hfkGg2RoI+pHpL2/PQHKPfK3imfJvcFy8H1HCze2OKELLGR9Z+r X-Received: by 2002:a05:6000:208a:b0:43d:1df6:ea9 with SMTP id ffacd0b85a97d-43d642c0938mr8925884f8f.40.1775907794662; Sat, 11 Apr 2026 04:43:14 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:14 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 04/17] dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw() Date: Sat, 11 Apr 2026 14:42:50 +0300 Message-ID: <20260411114303.2814115-5-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Use rz_dmac_disable_hw() instead of open codding it. This unifies the code and prepares it for the addition of suspend to RAM and cyclic DMA. The rz_dmac_disable_hw() from rz_dmac_chan_probe() was moved after vchan_init() as it initializes the channel->vc.chan.device used in rz_dmac_disable_hw(). Signed-off-by: Claudiu Beznea --- Changes in v4: - in rz_dmac_chan_probe(): moved rz_dmac_disable_hw() after the vchan_init(&channel->vc, &dmac->engine) call as this is the one which initializes data structures used by the debug code from rz_dmac_disable_hw(); updated the patch description to reflect this =20 Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 1717b407ab9e..40ddf534c094 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -873,7 +873,7 @@ static void rz_dmac_irq_handle_channel(struct rz_dmac_c= han *channel) channel->index, chstat); =20 scoped_guard(spinlock_irqsave, &channel->vc.lock) - rz_dmac_ch_writel(channel, CHCTRL_DEFAULT, CHCTRL, 1); + rz_dmac_disable_hw(channel); return; } =20 @@ -1000,15 +1000,15 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, } rz_lmdesc_setup(channel, lmdesc); =20 - /* Initialize register for each channel */ - rz_dmac_ch_writel(channel, CHCTRL_DEFAULT, CHCTRL, 1); - channel->vc.desc_free =3D rz_dmac_virt_desc_free; vchan_init(&channel->vc, &dmac->engine); INIT_LIST_HEAD(&channel->ld_queue); INIT_LIST_HEAD(&channel->ld_free); INIT_LIST_HEAD(&channel->ld_active); =20 + /* Initialize register for each channel */ + rz_dmac_disable_hw(channel); + /* Request the channel interrupt. */ scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index); irq =3D platform_get_irq_byname(pdev, pdev_irqname); --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6FF2348453 for ; Sat, 11 Apr 2026 11:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907800; cv=none; b=g5XQqzHR38NNG75Pe6wPCS4hL0Qu9xxJXLfP5USI80bJGFUSgZ9GwXxO8MHLvHbHYVuBjmGpzSGyRBH609H8fWwZ1WXA76bJzoju393576uWQsCTdL0xPTMWMj6/u79ZsKlM2MKDLUfZTQ1sShZgMcbqzwGaurcs+Oi3JODMjW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907800; c=relaxed/simple; bh=FswV1zMeTY8mzOC5mjgtkEA10SnivHgCzyn5u3OdJMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V1Uo3Fcqqf4Z5ekxV2RTCI2gegzE1emt4v1Jt829/2V5CPKv6N4ppFmQxy9tvyehmZkAktI0HjC54d2yz70DaISHctIHfD38ie+4sYWr+zCEsA72pysDlnHrIet3VPa7owaKntskUmEwAVf4VZiMqHomFCsdfn1anP1ctFd2844= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=ld2ZFpE4; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="ld2ZFpE4" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-43d02a71526so1785276f8f.3 for ; Sat, 11 Apr 2026 04:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907796; x=1776512596; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LCFzuE61zyUmhYiJf5OgZu1cO7csJ6djKP2u11HWSmA=; b=ld2ZFpE4uncheIVERSHKOhXIRdBq4yjwrpLJj2XQt8Ji5hZDw0Zr83nHwaGArpiIfy jFy4kRt+36wjatPI4mYL6u0NBWa9vCCw64BI7T3cpZxQp5mWbsB8U4wmdHT1PRgNCEfd b3Gg5Wgm0QzBRnoygAQeNJanEuByJO1EyywBC/o0vAuE0MDhGLxYL3KJUp+9TIKCNwcY mU0ycjpu9fwBgW2PCV/OhM5bU31usxQ3a1qYiYbnc//wEf3rl1Iz/vMiCqSow/8/D/8E 9xQ2fWACX4lH59mSB/SjljTOs2/Aw5olXhbAkr7sz0U9kFF8kgtTwaqA9F4ippFfukcW cJ5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907796; x=1776512596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LCFzuE61zyUmhYiJf5OgZu1cO7csJ6djKP2u11HWSmA=; b=mnXZ3hvtQWccXxUTo8FwBSYaNGp4iAga5ZSwepeWkGRY8YE0ecGk++T+lp4RoBoiMZ roM43XI4ITobwPsKH8f0/8uAIS8q2D5nLM3yz4qrfD1qEik8lWEy+nw5Jc8ep34RlPYl ayGX0SqC/AMrr9R14F1t3vIVA4h3AolXuGBHTypi6obT4zXUwvVeEp+Kjb4U/fCCd/E3 NthxKGeoMj1G1HIQI9Ftpt4LDQj4FqrfgypnEuT7l/tiii2dYTzEfIHpjN5c4jvOUtgw Did490WT3Q0sh6lYDlUzLqJnNJ3hxCiMBpgrvUK5pXdnIoJ5x0aCVXvIEfD9IyZIqBI6 hcGQ== X-Forwarded-Encrypted: i=1; AJvYcCXlOtPxYzf5uxEXWx9srA5jf0I84Aex6GTdZTgGLLXJHOOi325RoEuK9sQAx+/dpBa5Kl4TrSw1ekshRgA=@vger.kernel.org X-Gm-Message-State: AOJu0YyR8iEoJiBxtPCv/npRPO8EM3I7zui7lMibkLeNNVviR9sfIecI 25fqpmWO2vyekulGmgn+Bebxm4QnK6MXxhmKhcLuQO0DMosw3xZOmjt1WSMl2NkQTuc= X-Gm-Gg: AeBDietiXqyLw+LkSUur/4/6r6DMD/rufRSAcJhzn9Iglt8yCVvbpxL/JfulWUe47pl ESh4vC1NlcKKJ3WDpGcq/i+bawPpJ1arg+Njr6TgXuTGgJtwtwjrFmcCqCzCf+YDwNJMWc9IuiD Up+M3Z8SaaslmLpjomHA9MWdDoPYI3PJRlnMiqbS2trmLWMvxJ2c3bVDHuNUwyiJ5hmsuX2DRR9 q6McRX9tb8nuic6GKqPfwoa60AllvFXMzRXUIRInOrM8eYitvIoSz1dHZRtXS1Xydpbyw750KDG r1szpnEeA5de/oVnNOPLVXCRJdOpTIPNtnHLjO7Xh7OqjG4osXPFDyBNHyyKap/NPWe/9k67fPw IUy6wea6xLqRuT9iH3VMazOfdQCBaBD3m0cfF5QzxvxYM4sgbGi2KNFhBghxPWT+2EoXT8cTQ+k 03GMXNnm0yMIRQ8XnJG/Kdt9aw+spSdHLRGfvdY8jufPT+vzcSV+L7 X-Received: by 2002:a05:6000:26c4:b0:439:ac6b:dd38 with SMTP id ffacd0b85a97d-43d642ab99bmr9178051f8f.31.1775907796358; Sat, 11 Apr 2026 04:43:16 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:15 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 05/17] dmaengine: sh: rz-dmac: Do not disable the channel on error Date: Sat, 11 Apr 2026 14:42:51 +0300 Message-ID: <20260411114303.2814115-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Disabling the channel on error is pointless, as if other transfers are queued, the IRQ thread will be woken up and will execute them anyway by calling rz_dmac_xfer_desc(). rz_dmac_xfer_desc() re-enables the transfer. Before doing so, it sets CHCTRL.SWRST, which clears CHSTAT.DER and CHSTAT.END anyway. Skip disabling the DMA channel and just log the error instead. Signed-off-by: Claudiu Beznea --- Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 40ddf534c094..943c005f52bd 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -871,10 +871,6 @@ static void rz_dmac_irq_handle_channel(struct rz_dmac_= chan *channel) if (chstat & CHSTAT_ER) { dev_err(dmac->dev, "DMAC err CHSTAT_%d =3D %08X\n", channel->index, chstat); - - scoped_guard(spinlock_irqsave, &channel->vc.lock) - rz_dmac_disable_hw(channel); - return; } =20 /* --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E80734B438 for ; Sat, 11 Apr 2026 11:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907802; cv=none; b=jipenlDIxzWnBfYzlRMinj8kFlxZWmJavSxF9Y4mpMQ2wJidqR0geAHpcbN6OYaLbz1cYjEnbYxP0DMEytpvRBYkPXhW6D6zk57+bk3xHXMHC5auKcpTzLoxGoHO8iZVmhypJ3OweBHY/2UKcWKgMTFUCu8kW4VbmQK2RLfTTN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907802; c=relaxed/simple; bh=hCcTy5ooGYC8iDVpkjkx2X0iImn3Ks2K6Vfc4FCM9QE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rLGu9g01pFXPPfPcZTVbPA7tw/tRCedqQNU3/tPcHrrqcwJ2X9I5eQYGRvR1v8L4Voz05Ba3wL5hsmM64WRLQPOH5+U8nAahJps6aF0w3IK71yfWVRarcaC//vfl+Tyrfj++O5hY5vKvmEcEpbwFI34ll3eXA/Ponfu6svXW69s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=a7wzxxxa; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="a7wzxxxa" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-43cf3ee0fc1so1796788f8f.1 for ; Sat, 11 Apr 2026 04:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907798; x=1776512598; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BBAh3mtPfHrVsqP6yv8NM6dVTsui6/Je8uMjHCO4v28=; b=a7wzxxxaxIsoxYcmbeQZSVnkQjA4ADezdYt53TXIP1lFzE/qzyes2Ta6gq/RoPuEy9 zu0gJ9NpVekVwKfj5CB6fGCaGrtz+OPFXQ7f6mNqcbxsfZEWx1Z7LQBlfLCHfv77dKxu ZwAUhXNsbo70OfLuRbvObfUSyXrS1PqJP30iMDJbiIp8r8PAjmqL84jJSyhkC/8NNOE9 Wc0s4nl4kjSNaiSwCksWnxa+8pIF0A/i/TUQ/vZEpT5woEL/yErfZryZrMgetW61BjY2 HNwPtIPN8dgc+bpdXgrE3kMxoCT/roCA0TD8b4oQvED+ZzYUKoK6AdHADiK5Xn9c4nEF HP3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907798; x=1776512598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BBAh3mtPfHrVsqP6yv8NM6dVTsui6/Je8uMjHCO4v28=; b=XAV5BvffdTe46E5mKV9M2xkzHP8E02+ixs9jo00KCZF4ymQrVGewkndtPfRAoifX0h RgpOPJSQfWCrTJrSfZ2xCjHHLHrcdBoUh+IqHi5v42Ca+b2KoJCBwz0IcGpu1kVNmX2Y 97vf6uELIGx721++d507mw3KNskAMisALZX8AMRRONRxb75z1rd+hNgTtNe8vHvI1FjM AO/NnCcHpovoviWeb+yZbtgbrjYGas+zrVdQFmLK7xWbMHG1s6IOAnAdt72CBDUduKlT KdEE4XBXKrf8BSXcy3Y6TxnT09VRX61i7SfhMqaOM7oJ6Cx7C0kTEPoz0F6w3q6lXwdx YYHQ== X-Forwarded-Encrypted: i=1; AJvYcCVqpa/C6s+wSsVtGyexp8Tp+1hQLQWihCF+pPI0qIVwiHeY5FflFMfYgYAQI+wk+CgxeeFpsUVX2vR6y9M=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2lkpBqf2TYIxmTZDCdSp1cu+E3X5bMVRMIS3ljt+7r9Ihzurv 7H4iRx6O5cX32r+Iau/sqcv6VhNgiJjxLQE+6N59d5ItD6/i717epFxVRmji4cpxmYI= X-Gm-Gg: AeBDieuBKJRUgGiF72CN8fWy+gfXHZ4ev6faqkexn46rtT18ljJZ3HBBd01v9MC2aE6 DoWa04k75P/VDcLo73Jp/uf+EWK5TPce+tkk6xuPCEXt0V5IGhn9vstib/b5ri4j/9nu5kNFmP9 88MXUZQVwY0WlLrP4G6mjaAkdiruqrIlRm/o+KpRNRybtsqKSiMzcUM/zdcIWEXBGWe8HhjWrmU kuBHILN5b16PU0BcLF3prnz3UNWk87qywmoQYQrysL6l6csGETL16NFERxno7SiFFFuqgfaTA+R LDWJAxOkdCxHuc/iPu/hCt9qnM6xMy38p70THtSZOXHe4QmdZXQFQMYs9P/xmHvD7khTFA/9aOp tlo/I+/Xt8B9aAqR0jOmO+L/ZAN1AM4KhANLFDTR4Tr8wq8ojJV+4XSDF/vdnIAuk6tHP9hqa3h kMhMq0vGjek3Vf5ChqRBuPiD6zD/0MCdqc+uk+ceqfZ1lSntLpZZ+W X-Received: by 2002:a05:6000:2804:b0:43b:9d69:43a with SMTP id ffacd0b85a97d-43d5957372dmr10511283f8f.8.1775907797979; Sat, 11 Apr 2026 04:43:17 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:17 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 06/17] dmaengine: sh: rz-dmac: Add helper to compute the lmdesc address Date: Sat, 11 Apr 2026 14:42:52 +0300 Message-ID: <20260411114303.2814115-7-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add a helper function to compute the lmdesc address. This makes the code easier to understand, and the helper will be used in subsequent patches. Signed-off-by: Claudiu Beznea --- Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 943c005f52bd..6bea7c8c7053 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -259,6 +259,12 @@ static void rz_lmdesc_setup(struct rz_dmac_chan *chann= el, * Descriptors preparation */ =20 +static u32 rz_dmac_lmdesc_addr(struct rz_dmac_chan *channel, struct rz_lmd= esc *lmdesc) +{ + return channel->lmdesc.base_dma + + (sizeof(struct rz_lmdesc) * (lmdesc - channel->lmdesc.base)); +} + static void rz_dmac_lmdesc_recycle(struct rz_dmac_chan *channel) { struct rz_lmdesc *lmdesc =3D channel->lmdesc.head; @@ -284,9 +290,7 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *chan= nel) =20 rz_dmac_lmdesc_recycle(channel); =20 - nxla =3D channel->lmdesc.base_dma + - (sizeof(struct rz_lmdesc) * (channel->lmdesc.head - - channel->lmdesc.base)); + nxla =3D rz_dmac_lmdesc_addr(channel, channel->lmdesc.head); =20 chstat =3D rz_dmac_ch_readl(channel, CHSTAT, 1); if (!(chstat & CHSTAT_EN)) { --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 661A934C989 for ; Sat, 11 Apr 2026 11:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907804; cv=none; b=tNSAqqSkpzw/H2K3Pf7VoN3x6VKVMVxkhMFNnCdEzyLlNQQfC1Whr1Z7JetX/398eb1jtlVO9ksB/DOwVvdAJjvhw1z72vOv5eWaLTwBIhZl4O/H4hbVtzoV7DhVa35vmf0FkSYwU09krT7ojZ0ZnUROP4gSfWGagRoRGzTnCl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907804; c=relaxed/simple; bh=HYbQIS34NFlLeT+Ow3XXD+QsBaX+UteI12v9t0ej3d8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VC8iCyJYf2DIidOPSCQ6es52QORcWo4qUmhC/PrixOSC5hajEyBLZUfS+f5q9FnwWYo8WZPUqo2yr9Piwbn115VoA8nWIMyZw3Wz1YtfXGTItR7K+vxD7tl77sGfFPs+eDPEiyoN0OqKDAlejZA8xeYLSuS3d5CazfOZ3yOGmE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=lheJ0/6G; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="lheJ0/6G" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-43cfd1f9fd1so1848495f8f.3 for ; Sat, 11 Apr 2026 04:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907800; x=1776512600; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BpIDGi3F2+bKdB1eNAASENpLimdw7rfW2AbsZjsrSxU=; b=lheJ0/6GzGGNT5oXXikI2VArSjVzV7mPgXvXzlHPilsIP8a7v/hbJMtevxVDccN0Oc cj2txzl2z2slrH268e+9HxxlHQLcWr5TngTeVHbaeqZZpirdaWu5+sE3hB9mUDAFG/xu 1CoT8kAss3lFPexXlMM6Q4q7TkIpBGmhBAasDs+teldxd31geUSFxiMp5F+iSv3xaP8E Tt1YGE7oZE0B8B4tGMwkPqHtOUS9vzTx2dzHgtq8JCKG9AknYx0RsvOvA2bmvh0dW+Z3 cEuk7LOaIN1KywxMR6ZOehq6Szf4/4tMVsw0waFDJtB/CjRqa9M2YT632AfS0OVheUEC ydmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907800; x=1776512600; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BpIDGi3F2+bKdB1eNAASENpLimdw7rfW2AbsZjsrSxU=; b=VwQ0wgAUGLQlqXWLq/CKEguItjH+TzflavoL/THO1L6FGWNERHYhLwT34kJRcdAkJQ L47Q7Ctcpkhry5QEdfupq34xQKJ11w360RZc4K257cVIKGo+RCS+T+zWGsO5YitTUdo1 OWOSXi5XKxPlgczDNIKwRoG8uMIzoWEUN8iCvI5DeUMKSlyox4XcoqeOprI528wzOJGz MZF30R2UQbuwfJ82Gtx2HHaVAj8QXiPQUHsrjNeXuulJCX+gSjSAxHrgllK7Q2gy1v8b wrnMsMSONfH5qNZ0r/oadA707IHTturRKTXH1hgt8ti7M2KW5ZoAJJT4EEe/JVKk5U05 jgbA== X-Forwarded-Encrypted: i=1; AJvYcCXSM/u8xlxUik9STbg4NfEqCTQ+kqjG36TLZUjVVl0Yq2dBcIZel9+ZnRmYtES9C2qo7RnnN1BCp5afiLU=@vger.kernel.org X-Gm-Message-State: AOJu0YwPcZbcCRpbBIshe60MFeFEbro681df20jLEDXvftngyf+DEUxO z9lSG9kfeqvWFvj6Lb6nD0Jf+rwqgUQsdx3kBsyoHdkr6jYf8xp/etahCUvWfFjVAa0= X-Gm-Gg: AeBDiesFXyn4KKK9kIe062tmik2sVezZNb7UK0D5L+ks0qa/A6ANe/qnb/V7SO7sOrz RU9SfxhZJqmJX3tVjWth/32OpGs9gff2PSL231fBbrpSwNEpccaWg+oGnyjM+lm/Tyn9IMcPoZQ jUWmuwC3f/QdC5yJbVqnhdH9Dtmu8Sb/LFT3f2du5TkcRqo+tMZNzJdW53qkddaqPb+sEgnPE8i AUWAMwWK0dxaTvgpLQ3KfJAXJwhzKRcAtSXRmjBO6rcad87hZ1Bu2r4RIVeisw+NLYwe3UyNKlu 4AFsgtpnx0I89kPjzrfKQXx0jCQPvHvDW0tLE6g8Tn+R4nKFQUeB5IgTjwoLxAdZmmM/IQvQZB8 7AYLV8RFrWU0qgfZyAMaTjOhGpnf2c7VzFRBVi0r7CT14qo6AoHxnEkPNVPc3DBZKuy0NOiBezP aTDUkHqIbMeawoh4LmAOBpzWQZAxsNRDO3YHtVU0I65Yv8F5qnnd9Q X-Received: by 2002:a05:6000:2885:b0:439:c661:3245 with SMTP id ffacd0b85a97d-43d642d1968mr9382553f8f.34.1775907799752; Sat, 11 Apr 2026 04:43:19 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:19 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 07/17] dmaengine: sh: rz-dmac: Save the start LM descriptor Date: Sat, 11 Apr 2026 14:42:53 +0300 Message-ID: <20260411114303.2814115-8-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Save the start LM descriptor to avoid looping through the entire channel's LM descriptor list when computing the residue. This avoids unnecessary iterations. Signed-off-by: Claudiu Beznea --- Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 6bea7c8c7053..0f871c0a28bd 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -58,6 +58,7 @@ struct rz_dmac_desc { /* For slave sg */ struct scatterlist *sg; unsigned int sgcount; + struct rz_lmdesc *start_lmdesc; }; =20 #define to_rz_dmac_desc(d) container_of(d, struct rz_dmac_desc, vd) @@ -343,6 +344,8 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_d= mac_chan *channel) struct rz_dmac_desc *d =3D channel->desc; u32 chcfg =3D CHCFG_MEM_COPY; =20 + d->start_lmdesc =3D lmdesc; + /* prepare descriptor */ lmdesc->sa =3D d->src; lmdesc->da =3D d->dest; @@ -377,6 +380,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct r= z_dmac_chan *channel) } =20 lmdesc =3D channel->lmdesc.tail; + d->start_lmdesc =3D lmdesc; =20 for (i =3D 0, sg =3D sgl; i < sg_len; i++, sg =3D sg_next(sg)) { if (d->direction =3D=3D DMA_DEV_TO_MEM) { @@ -693,9 +697,10 @@ rz_dmac_get_next_lmdesc(struct rz_lmdesc *base, struct= rz_lmdesc *lmdesc) return next; } =20 -static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *chan= nel, u32 crla) +static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *chan= nel, + struct rz_dmac_desc *desc, u32 crla) { - struct rz_lmdesc *lmdesc =3D channel->lmdesc.head; + struct rz_lmdesc *lmdesc =3D desc->start_lmdesc; struct dma_chan *chan =3D &channel->vc.chan; struct rz_dmac *dmac =3D to_rz_dmac(chan->device); u32 residue =3D 0, i =3D 0; @@ -794,7 +799,7 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan= *channel, * Calculate number of bytes transferred in processing virtual descriptor. * One virtual descriptor can have many lmdesc. */ - return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, crla); + return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, current_desc= , crla); } =20 static enum dma_status rz_dmac_tx_status(struct dma_chan *chan, --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0005E34D3BE for ; Sat, 11 Apr 2026 11:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907805; cv=none; b=XpDlxo7eibAQQoORt+0NMqbvPI8RroLwtG1sBvsO8DiWyK1+yyH2+7L0OF9ic7uZdZ+S/4nEMUp/+rWnr/l2ChkAxidTmrmYylnixeglyvfmdOdF8TU82iNu/LJoYi84kck5jHwQbF4h8q9WUZVozeyhOHF/ZPZollFAzrJW+gI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907805; c=relaxed/simple; bh=G3TmLj2FVJVqKtKvmLk2oUEY0r77TRMnpm3HstyV+7c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kfSbmadCjiA00FkNm/Du/6aBXWXJ2rBcrtpuJW222HYH9ZJorq+cPTDCow8SOxMFtYKQ4dZlsqECqj8GLt0GYVqcDiXiKpcCn59Iz1bGVNdjNH8KK3VnrwkyqNr/UzAYX+6LLE/DxKfzDu5JE3ySjpTUhw+mRpSVTAoTxsFbw7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=LhxKW00h; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="LhxKW00h" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-488af9fdaa7so19742245e9.1 for ; Sat, 11 Apr 2026 04:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907801; x=1776512601; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2Ofhw21hwQOsSk68dsZGLNvbmOD1TuowEEUPnaN2gTE=; b=LhxKW00hbKBJorlbA10anBSFzNH/waBeFm6dI10TfVYnMW1ccTDc4u3+fayFdCMP7a Iw5qHMXP14sSDK9fO3Oc20X9C7TK1MEfaPgscsiZKSeBMYsadvCCS+cFIoCPH78UDED7 7GWh2EdFACDnJCJnS7RXVkjiXUjP020BziHMr79vr1vK4/b7u8yoaMzui15Wbt1BvLjZ 3Js5z3b19EhkFZzNaJ5cgzYNywQYyRmPH6Z7Gjxn2z5FUKgJe3JcmkWUFf/YqmU2xhgL 4fb9wnbOeBDbmbJSupubrqiVqxBWp3ULZ3pIws4gdra6CCBwCWbQU0KJKS1XuLtFO3Ml jRZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907801; x=1776512601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2Ofhw21hwQOsSk68dsZGLNvbmOD1TuowEEUPnaN2gTE=; b=NfrvUtPEu0zng1YQ3cZnRz3cCJxDuEMcDw/55prtn0HyGE3qkREvi6eQ6Fp9/bemTX Wp5rUEhgrxtfnkx5ydIIXCwVExNoO0c4zsNxaJpI3qRMAmk+6Re2Gu+Cfkaqy6UJjYPR LhT2XPH9A7PijHFFUxmWvkLTnKe+yKiW9lbf0kDNXNJURVd/dF7PNXytiAAKidajGkDD 9DD548hYI7je7qfBEQJGC1PxICz1aLW1joR3v4A81uzgTVkD/3AJ/odwKwSjeIwDR/PW 2LP/u/7OLMxecF6pkw/mhed3teA8Td17PSmaLJ2E17+gVzz3qfH4HLXw3hkvnoTP3L2I YdUQ== X-Forwarded-Encrypted: i=1; AJvYcCWgTWQz/Ns26EYUxljD2Ldxp7ySQFddRMjdxtqZ1ysKvkChDkKj0Uk/COdfDvIfiLe+3Ey7VIPkzVnTYzs=@vger.kernel.org X-Gm-Message-State: AOJu0YyBdpzjqy6pSlHxc8Pivj22lvZcoDvygsFyhl8aYUXacCn/obpx bjjcoZqNHJ7wTp4vCFUFeTSfOeWSjXBt0Z+zG1aWXsQKdF7zYC9gKAGAz/Sxbg9QXAI= X-Gm-Gg: AeBDiescNBVnCbms4JecJrv8Qkevyx6Mwnfwz9PSumTpcj/CnJ5LOmRxbhOX3v3qesY WxciLgVM9XuSgCjXhnAB/F/JPdE5sJP23FrBUSovoA615vw15UK74N8pAcsYGynAQ968QoZZ84E lUj7c4Y1h4RJu9rkWvkBzc68ZyrY0MU8k3oxbXe70kKAsQWiv6Yhv41GNTRUF8eKKMHcvz3VIcf KTM9VU7HB7IOZCCnImwFW6dZftwDhILV/ACB63xWgvAj/6DgGD4VwF0dUrQYxjACU1hceAPxxIZ EhgoNk8eHZye/n7SsnUbcnRkj4RWnCnaLM9ma0GtDC4TBvu/RnevrmXvnEhPudVVrntT/Br07/Z eoEcuuZpSCkx2fL7KjBZOz+i4vijBzSeAu1Fblyz8YeT46YbD9eCuCb4vRlxVoftY6lvhsERGng Gxn09oaUjLoQ4pGi9NCLXKEr1f4AHuVpxSlvuPdg1/hS9khf2XZ5MQ X-Received: by 2002:a05:600c:c0cc:b0:480:1c69:9d36 with SMTP id 5b1f17b1804b1-488d68af13dmr58285165e9.17.1775907801492; Sat, 11 Apr 2026 04:43:21 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:20 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 08/17] dmaengine: sh: rz-dmac: Add helper to check if the channel is enabled Date: Sat, 11 Apr 2026 14:42:54 +0300 Message-ID: <20260411114303.2814115-9-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add a helper to check if the channel is enabled. This will be reused in subsequent patches. Signed-off-by: Claudiu Beznea --- Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 0f871c0a28bd..1a3c33d28c6c 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -279,6 +279,13 @@ static void rz_dmac_lmdesc_recycle(struct rz_dmac_chan= *channel) channel->lmdesc.head =3D lmdesc; } =20 +static bool rz_dmac_chan_is_enabled(struct rz_dmac_chan *chan) +{ + u32 val =3D rz_dmac_ch_readl(chan, CHSTAT, 1); + + return !!(val & CHSTAT_EN); +} + static void rz_dmac_enable_hw(struct rz_dmac_chan *channel) { struct dma_chan *chan =3D &channel->vc.chan; @@ -840,8 +847,7 @@ static int rz_dmac_device_pause(struct dma_chan *chan) =20 guard(spinlock_irqsave)(&channel->vc.lock); =20 - val =3D rz_dmac_ch_readl(channel, CHSTAT, 1); - if (!(val & CHSTAT_EN)) + if (!rz_dmac_chan_is_enabled(channel)) return 0; =20 rz_dmac_ch_writel(channel, CHCTRL_SETSUS, CHCTRL, 1); --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D587F345CAA for ; Sat, 11 Apr 2026 11:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907806; cv=none; b=CL9h3gyD2HzZ4nTaJjGLP17lpgR+SEs+fmlKBKYGGLcGmtZWeeALnbopemYMT3dQ1ung4PIPvIel2+jYPNFTZavyuxsNBPtu9qrlDe0LbXuRy/zcv1EKN6+0jITYw3VnyqtQbYO66f6eKNF7WbHaKMuZQpNesmG3+rwrfzyZq3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907806; c=relaxed/simple; bh=kYxxf7UrOo/ylG412SxsscyOsq5s+9b6o32cDo3KE50=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c5Pghitvkd//anKeV/SwnhRmt9ErslLa8Vd/QEfYm/NAC/V/J4r8eFEJ7OPGH4b5RdauP7hQOavvI2+TO2tbFBfFA5aECLAFtUFbiZZUo2l+Sp1qGlg/uWDuUV0UOc4i9OfLJ094ppQfI1zzWXwm0KrPsNyxf+d/blzq/3TK0y4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=d3kytsCz; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="d3kytsCz" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-43d43e09de5so1587484f8f.1 for ; Sat, 11 Apr 2026 04:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907803; x=1776512603; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y6HUr1gtJuXFA7idjOAe9L67Llkodm8s1OURzQhPdNQ=; b=d3kytsCzByQoV1C+S3h7V6B7XxGwePoepa3dKpEVrSoRCA3vWhJ1IcCcWaVBOP1gcL jlD0Oe9LoaCBkBx+HOuFGmRNq1aRs7hJSE3cfYH5do0R7xXpqpbf2zzquHkT3ruFJFMn onxfw0WXIMrmyXgVTK93gmKAUlUC+JUzjNIEa3Mkfkt+I1brd+adcSD1UHaBaH7rCChi toseYi5Vvex7AcqtXCGXEr/a/UbFf1gTytobSXHOFkb1GDs9jRI/UsfnPB1YSt5zE7Eq 92sdt9OCcgmqovZXfFTFZ7+heN6CbS7HAS59vKtnHeCgQfwoqCY7JrudVUSyH8tDQuLx Q/2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907803; x=1776512603; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=y6HUr1gtJuXFA7idjOAe9L67Llkodm8s1OURzQhPdNQ=; b=cS1I9hblxY131QNY2Xj8ejOP8ZUbGztq4fg1IbPggDyavcxeava6PdkJVKUxOxqehA mw3yVOI2HRoDrWdmKkGluF7QKvdx7jZxC26lvXpiq1Fwh719cfZSx/q4M8qEVDLAi+U7 74jIdks4MgSlNEIEuiZXef70OPMbS+74LjOPKzaJVdENWKREISYGH/5/+FWyTJ9f0gQh EN4HV4DZVROA792sgFcE5ro+jeofWTQXZBnqllONkbnGHYDqDi73EWz5cH43bBi9DH2c pcV6Xl7UE0YH8X/+E/Z36u42ZjwUOf0jycVUwPwktMl8PXymKqlB43WX79QQHDWW1MEY XtEg== X-Forwarded-Encrypted: i=1; AJvYcCVZWHru0tbZH/Hi/hBhqygoQrzjs7BAKOJDwwDyS0g8aEbV4vGte1w/GH9/7ubdUugpLnmN4Jx24+VdTU8=@vger.kernel.org X-Gm-Message-State: AOJu0YxrmINp62F2uce5ax1Q4nivtp7w1BmBXLPYJkziK4URi0ToBxul kHhOH1Hj0iBYkYAf18kRuCZkhW2EedfG1Tip2Y25dGKBUvkgoHX711chEDI0AV9+1KE= X-Gm-Gg: AeBDieupo21vlvwfSPkGEMeJc7+MPRn8pjvWUZ72OHSO9fjrknvm81llfYMxSzkGb8D oj/IfGgRu1OQ4oRNHXrnxYzXLoQddDz0TtsXnCkGT3gIhW+N3e2b+EZRBk3owaqjhgRMw9CPHaK RNKlmQUCidWzrikiVSMl0xh+YtdPP0tqGCWMynTf5qJti1PW9/RfG4p69ETWN1/0SDz6ttyMird dRoIGb8YhvW/PlRQpqdif1WkqXV18LhbjVPtfh7KJphylRbR7yJaSjang6evM2K8RlP8Us3Z6eL 8R+zzYYEXnm44LTTyx/3YJ9n0yQ01JLAI/4vjimYYqLvxeKDy2yR1mQ2jb+TQMOZDkzA1cMvPhN SKrGVEqnbkOPEupKOpv5EboAmSOd4in36v733ey0pO3C+/q2FQl1toKTi/s/aRlOLzGKtHwgX7a 6f1pxUcghdRTaRrDPt7QKVvdtt27Lf+78CaLj3+Vao31XP2KpHRV97 X-Received: by 2002:a05:6000:3108:b0:43d:1c7a:8b5e with SMTP id ffacd0b85a97d-43d642c13e0mr9680005f8f.35.1775907803295; Sat, 11 Apr 2026 04:43:23 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:22 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 09/17] dmaengine: sh: rz-dmac: Add helper to check if the channel is paused Date: Sat, 11 Apr 2026 14:42:55 +0300 Message-ID: <20260411114303.2814115-10-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add a helper to check if the channel is paused. This will be reused in subsequent patches. Signed-off-by: Claudiu Beznea --- Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 1a3c33d28c6c..f35ff5739718 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -286,6 +286,13 @@ static bool rz_dmac_chan_is_enabled(struct rz_dmac_cha= n *chan) return !!(val & CHSTAT_EN); } =20 +static bool rz_dmac_chan_is_paused(struct rz_dmac_chan *chan) +{ + u32 val =3D rz_dmac_ch_readl(chan, CHSTAT, 1); + + return !!(val & CHSTAT_SUS); +} + static void rz_dmac_enable_hw(struct rz_dmac_chan *channel) { struct dma_chan *chan =3D &channel->vc.chan; @@ -822,12 +829,9 @@ static enum dma_status rz_dmac_tx_status(struct dma_ch= an *chan, return status; =20 scoped_guard(spinlock_irqsave, &channel->vc.lock) { - u32 val; - residue =3D rz_dmac_chan_get_residue(channel, cookie); =20 - val =3D rz_dmac_ch_readl(channel, CHSTAT, 1); - if (val & CHSTAT_SUS) + if (rz_dmac_chan_is_paused(channel)) status =3D DMA_PAUSED; } =20 --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0E243537F4 for ; Sat, 11 Apr 2026 11:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907808; cv=none; b=RpWT1+0zD+/diZDQ68GoNhqcd9QVtf4nXLBqbiIuJiCezmtxMCEnvKWLslOvFCbuk8KwTRufutRMByy9y0t0CpddbdaHjT5uFfqR0JdThI7uf3qMN4jjivvgymQnrferh4KA9CI9wpD4+nrFG1a/xwgl1g1RrCZO2wSm2sit9d0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907808; c=relaxed/simple; bh=9Fw7Tt7H8WNuXzw6Osa9Uin0V8vH5bKwDH1u+GTNvHQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tzg+acyOkh7zNhu+DJmA/ayNHXhr7TCGag6C1GFJRFCea7WjxWBtXvrQhoBg1BzacmWUhqWEJ1qWJiyyAx9OfnsdvCcxcfONeSO4DfQYwgsAON0nNzUEB3h6vTWCA4AhhfSu50V//32jb1EnzF3JMOrPNYXW2X4YIqSkeSPhhSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=iWWew4uY; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="iWWew4uY" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-43cff5dafc3so2175354f8f.1 for ; Sat, 11 Apr 2026 04:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907805; x=1776512605; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vJ3Nq2ZkZYO/hqWv6zWLV5vD2kiHATghc+wNwAJN61w=; b=iWWew4uYyb5By/hLqVdYcihNg/UvL1H05TjYtmZd82ciqi0deJDqLA1vchCRU2Nb89 2Pic0ogT+TlUkyxxj1XLGHk9BwHCBAOYmNkgke9SImJSCK78KT4qdO6kDh4tp7lb0AUq QRovMogHeEa/wHiMCuDSBkQbBN+onIQydyfjIuRVrgutSMoYQeQSf1SW+B2d0CRHN3lz 0S9EadFtIyo8wmKhRjJCUb6XPNpyHl59Y8xuqWjjDnbUQatyrcdNptHurR5BWpWAhdHM QmjDVhvcZm4e1ACvGPMtaJYh1X853eJGiQY+8BTT65hIJaafRotWNxvdUmxyFSuvymCa zmeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907805; x=1776512605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vJ3Nq2ZkZYO/hqWv6zWLV5vD2kiHATghc+wNwAJN61w=; b=J8SzKHlBl12CbWKvAvX4ZPH4nNJDg0WN8f3jHAy+aMtxDArhJcbTbDXfYlYTVJ1NCN 8rz6oPOvCLNpZ4l/OwvkXVL/cpzIudzhcgq7jLm+w1bGzxQEzPgD79G8ndwH/Diq/apO M+MWi1+vuIyLywrvvPMbySxs1zFxi+ejDz2ElLf5HEbuKaia9y1LlzEtcupM82z6oajL xz9hlGb81i+zK/dWjovrgjbURklAXhjzeKVG5Zlpiv4nq2y/nyh/SuYR/W3N8c2tOFxS UnXGj1qniqCI4Oh2cdyY3CgChit2y0eqICfp0AVTSMSJUskgothjK4nQ1JCb6dQwoh2o rkgw== X-Forwarded-Encrypted: i=1; AJvYcCV5rd9fYcf/fXCtBc/l22V0HxBqorQBpq/zpHrJBPvznHRZbOHETATgvVeDIqwbOji7HNxbfbELrvrSO4s=@vger.kernel.org X-Gm-Message-State: AOJu0Yzmxx+qH6RiUBVutBTAeJKP/co4Gk1mQWykrnQ+8LSIQ13Q4n2/ p4Ss7d/xkorkikpAM4jJWX8O4Kkhq5mjHQNBkME216TjTXSXqvTUBmf3h+OBfvgshjg= X-Gm-Gg: AeBDiesTiXN0Qz6RHL0mFogk5UXv0Yk9kWlvpZLGuVumPp98Lt2K2U8dyLeCmpLXYem +FiupHXHIskZhALqocxc0ks6qkDu5Tn/vKnzzsu2AKmDS6Hkzv9rV6S1laQYsYkq0fd92G5UYc9 EDnQfnrFj/1Au5/+Fmtc3ysA/j2r5seHPyyG+9BwBXTT+pFH3fi6FdHwt1NT+j64g8Xj0FWGD9j wYFzTcboFvtlSeAtHA+/OCzy9GLA1CzJjklkgLCZ7hT6IUjtIZTeN5s6Tuoi8kVunlLl2MAor+Z yPQgFuqG9tc14ZLkDEXh20aPU8Jq4o50q3t0o0k5vnwAGjIyw0UpKLyPCXq6x/kwN7WkwNyvkXr 5KT7SRECxsIXHdK/MUY36RuWZ72NaoDhWyA/DZDikIjWm4GLKGyaTwA88N/9u89NvsV9hyekbed WRCqxxCe+D0TmrAQJwBEVSXW6I97tZLotzGhAeXA19CkYOsQmVMcKCF6uFIAHi1n8= X-Received: by 2002:a05:6000:2508:b0:43a:580:f60d with SMTP id ffacd0b85a97d-43d642e7118mr11097647f8f.35.1775907804988; Sat, 11 Apr 2026 04:43:24 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:24 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 10/17] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing Date: Sat, 11 Apr 2026 14:42:56 +0300 Message-ID: <20260411114303.2814115-11-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The driver used a mix of virt-dma APIs and driver specific logic to process descriptors. It maintained three internal queues: ld_free, ld_queue, and ld_active as follows: - ld_free: stores the descriptors pre-allocated at probe time - ld_queue: stores descriptors after they are taken from ld_free and prepared. At the same time, vchan_tx_prep() queues them to vc->desc_allocated. The vc->desc_allocated list is then checked in rz_dmac_issue_pending() and rz_dmac_irq_handler_thread() before starting a new transfer via rz_dmac_xfer_desc(). In turn, rz_dmac_xfer_desc() grabs the next descriptor from vc->desc_issued and submits it for transfer - ld_active: stores the descriptors currently being transferred The interrupt handler moved a completed descriptor to ld_free before invoking its completion callback. Once returned to ld_free, the descriptor can be reused to prepare a new transfer. In theory, this means the descriptor could be re-prepared before its completion callback is called. Commit fully back the driver by the virt-dma APIs. With this, only ld_free need to be kept to track how many free descriptors are available. This is now done as follows: - the prepare stage removes the first descriptor from the ld_free and prepares it - the completion calls for it vc->desc_free() (rz_dmac_virt_desc_free()) which re-adds the descriptor at the end of ld_free With this, the critical areas in prepare callbacks were minimized to only getting the descriptor from the ld_free list. This change introduces struct rz_dmac_chan::desc to keep track of the currently transferred descriptor. It is cleared in rz_dmac_terminate_all(), referenced from rz_dmac_issue_pending() to determine whether a new transfer can be started, and from rz_dmac_irq_handler_thread() once a descriptor has completed. Finally, the rz_dmac_device_synchronize() was updated with vchan_synchronize() call to ensure the terminated descriptor is freed and the tasklet is killed. With this, residue computation is also simplified, as it can now be handled entirely through the virt-dma APIs. The spin_lock/unlock operations from rz_dmac_irq_handler_thread() were replaced by guard as the final code after rework is simpler this way. As subsequent commits will set the Link End bit on the last descriptor of a transfer, rz_dmac_enable_hw() is also adjusted as part of the full conversion to virt-dma APIs. It no longer checks the channel enable status itself; instead, its callers verify whether the channel is enabled and whether the previous transfer has completed before starting a new one. Signed-off-by: Claudiu Beznea --- Changes in v4: - in rz_dmac_tx_status(): return DMA_PAUSED if the channel is paused; call rz_dmac_chan_get_residue() only if status is not complete Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 233 +++++++++++++++------------------------ 1 file changed, 86 insertions(+), 147 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index f35ff5739718..04eb1a7f1e62 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -79,8 +79,6 @@ struct rz_dmac_chan { int mid_rid; =20 struct list_head ld_free; - struct list_head ld_queue; - struct list_head ld_active; =20 struct { struct rz_lmdesc *base; @@ -299,7 +297,6 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *chan= nel) struct rz_dmac *dmac =3D to_rz_dmac(chan->device); u32 nxla; u32 chctrl; - u32 chstat; =20 dev_dbg(dmac->dev, "%s channel %d\n", __func__, channel->index); =20 @@ -307,14 +304,11 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *ch= annel) =20 nxla =3D rz_dmac_lmdesc_addr(channel, channel->lmdesc.head); =20 - chstat =3D rz_dmac_ch_readl(channel, CHSTAT, 1); - if (!(chstat & CHSTAT_EN)) { - chctrl =3D (channel->chctrl | CHCTRL_SETEN); - rz_dmac_ch_writel(channel, nxla, NXLA, 1); - rz_dmac_ch_writel(channel, channel->chcfg, CHCFG, 1); - rz_dmac_ch_writel(channel, CHCTRL_SWRST, CHCTRL, 1); - rz_dmac_ch_writel(channel, chctrl, CHCTRL, 1); - } + chctrl =3D (channel->chctrl | CHCTRL_SETEN); + rz_dmac_ch_writel(channel, nxla, NXLA, 1); + rz_dmac_ch_writel(channel, channel->chcfg, CHCFG, 1); + rz_dmac_ch_writel(channel, CHCTRL_SWRST, CHCTRL, 1); + rz_dmac_ch_writel(channel, chctrl, CHCTRL, 1); } =20 static void rz_dmac_disable_hw(struct rz_dmac_chan *channel) @@ -426,18 +420,20 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct= rz_dmac_chan *channel) channel->chctrl =3D CHCTRL_SETEN; } =20 -static int rz_dmac_xfer_desc(struct rz_dmac_chan *chan) +static void rz_dmac_xfer_desc(struct rz_dmac_chan *chan) { - struct rz_dmac_desc *d =3D chan->desc; struct virt_dma_desc *vd; =20 vd =3D vchan_next_desc(&chan->vc); - if (!vd) - return 0; + if (!vd) { + chan->desc =3D NULL; + return; + } =20 list_del(&vd->node); + chan->desc =3D to_rz_dmac_desc(vd); =20 - switch (d->type) { + switch (chan->desc->type) { case RZ_DMAC_DESC_MEMCPY: rz_dmac_prepare_desc_for_memcpy(chan); break; @@ -445,14 +441,9 @@ static int rz_dmac_xfer_desc(struct rz_dmac_chan *chan) case RZ_DMAC_DESC_SLAVE_SG: rz_dmac_prepare_descs_for_slave_sg(chan); break; - - default: - return -EINVAL; } =20 rz_dmac_enable_hw(chan); - - return 0; } =20 /* @@ -494,8 +485,6 @@ static void rz_dmac_free_chan_resources(struct dma_chan= *chan) rz_lmdesc_setup(channel, channel->lmdesc.base); =20 rz_dmac_disable_hw(channel); - list_splice_tail_init(&channel->ld_active, &channel->ld_free); - list_splice_tail_init(&channel->ld_queue, &channel->ld_free); =20 if (channel->mid_rid >=3D 0) { clear_bit(channel->mid_rid, dmac->modules); @@ -504,13 +493,19 @@ static void rz_dmac_free_chan_resources(struct dma_ch= an *chan) =20 spin_unlock_irqrestore(&channel->vc.lock, flags); =20 + vchan_free_chan_resources(&channel->vc); + + spin_lock_irqsave(&channel->vc.lock, flags); + list_for_each_entry_safe(desc, _desc, &channel->ld_free, node) { + list_del(&desc->node); kfree(desc); channel->descs_allocated--; } =20 INIT_LIST_HEAD(&channel->ld_free); - vchan_free_chan_resources(&channel->vc); + + spin_unlock_irqrestore(&channel->vc.lock, flags); } =20 static struct dma_async_tx_descriptor * @@ -529,15 +524,15 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_ad= dr_t dest, dma_addr_t src, if (!desc) return NULL; =20 - desc->type =3D RZ_DMAC_DESC_MEMCPY; - desc->src =3D src; - desc->dest =3D dest; - desc->len =3D len; - desc->direction =3D DMA_MEM_TO_MEM; - - list_move_tail(channel->ld_free.next, &channel->ld_queue); + list_del(&desc->node); } =20 + desc->type =3D RZ_DMAC_DESC_MEMCPY; + desc->src =3D src; + desc->dest =3D dest; + desc->len =3D len; + desc->direction =3D DMA_MEM_TO_MEM; + return vchan_tx_prep(&channel->vc, &desc->vd, flags); } =20 @@ -558,22 +553,22 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct s= catterlist *sgl, if (!desc) return NULL; =20 - for_each_sg(sgl, sg, sg_len, i) - dma_length +=3D sg_dma_len(sg); + list_del(&desc->node); + } =20 - desc->type =3D RZ_DMAC_DESC_SLAVE_SG; - desc->sg =3D sgl; - desc->sgcount =3D sg_len; - desc->len =3D dma_length; - desc->direction =3D direction; + for_each_sg(sgl, sg, sg_len, i) + dma_length +=3D sg_dma_len(sg); =20 - if (direction =3D=3D DMA_DEV_TO_MEM) - desc->src =3D channel->src_per_address; - else - desc->dest =3D channel->dst_per_address; + desc->type =3D RZ_DMAC_DESC_SLAVE_SG; + desc->sg =3D sgl; + desc->sgcount =3D sg_len; + desc->len =3D dma_length; + desc->direction =3D direction; =20 - list_move_tail(channel->ld_free.next, &channel->ld_queue); - } + if (direction =3D=3D DMA_DEV_TO_MEM) + desc->src =3D channel->src_per_address; + else + desc->dest =3D channel->dst_per_address; =20 return vchan_tx_prep(&channel->vc, &desc->vd, flags); } @@ -588,8 +583,11 @@ static int rz_dmac_terminate_all(struct dma_chan *chan) rz_dmac_disable_hw(channel); rz_lmdesc_setup(channel, channel->lmdesc.base); =20 - list_splice_tail_init(&channel->ld_active, &channel->ld_free); - list_splice_tail_init(&channel->ld_queue, &channel->ld_free); + if (channel->desc) { + vchan_terminate_vdesc(&channel->desc->vd); + channel->desc =3D NULL; + } + vchan_get_all_descriptors(&channel->vc, &head); spin_unlock_irqrestore(&channel->vc.lock, flags); vchan_dma_desc_free_list(&channel->vc, &head); @@ -600,25 +598,16 @@ static int rz_dmac_terminate_all(struct dma_chan *cha= n) static void rz_dmac_issue_pending(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); - struct rz_dmac *dmac =3D to_rz_dmac(chan->device); - struct rz_dmac_desc *desc; unsigned long flags; =20 spin_lock_irqsave(&channel->vc.lock, flags); =20 - if (!list_empty(&channel->ld_queue)) { - desc =3D list_first_entry(&channel->ld_queue, - struct rz_dmac_desc, node); - channel->desc =3D desc; - if (vchan_issue_pending(&channel->vc)) { - if (rz_dmac_xfer_desc(channel) < 0) - dev_warn(dmac->dev, "ch: %d couldn't issue DMA xfer\n", - channel->index); - else - list_move_tail(channel->ld_queue.next, - &channel->ld_active); - } - } + /* + * Issue the descriptor. If another transfer is already in progress, the + * issued descriptor will be handled after the current transfer finishes. + */ + if (vchan_issue_pending(&channel->vc) && !channel->desc) + rz_dmac_xfer_desc(channel); =20 spin_unlock_irqrestore(&channel->vc.lock, flags); } @@ -676,13 +665,13 @@ static int rz_dmac_config(struct dma_chan *chan, =20 static void rz_dmac_virt_desc_free(struct virt_dma_desc *vd) { - /* - * Place holder - * Descriptor allocation is done during alloc_chan_resources and - * get freed during free_chan_resources. - * list is used to manage the descriptors and avoid any memory - * allocation/free during DMA read/write. - */ + struct rz_dmac_chan *channel =3D to_rz_dmac_chan(vd->tx.chan); + struct virt_dma_chan *vc =3D to_virt_chan(vd->tx.chan); + struct rz_dmac_desc *desc =3D to_rz_dmac_desc(vd); + + guard(spinlock_irqsave)(&vc->lock); + + list_add_tail(&desc->node, &channel->ld_free); } =20 static void rz_dmac_device_synchronize(struct dma_chan *chan) @@ -692,6 +681,8 @@ static void rz_dmac_device_synchronize(struct dma_chan = *chan) u32 chstat; int ret; =20 + vchan_synchronize(&channel->vc); + ret =3D read_poll_timeout(rz_dmac_ch_readl, chstat, !(chstat & CHSTAT_EN), 100, 100000, false, channel, CHSTAT, 1); if (ret < 0) @@ -739,58 +730,22 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(stru= ct rz_dmac_chan *channel, static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel, dma_cookie_t cookie) { - struct rz_dmac_desc *current_desc, *desc; - enum dma_status status; + struct rz_dmac_desc *desc =3D NULL; + struct virt_dma_desc *vd; u32 crla, crtb, i; =20 - /* Get current processing virtual descriptor */ - current_desc =3D list_first_entry_or_null(&channel->ld_active, - struct rz_dmac_desc, node); - if (!current_desc) - return 0; - - /* - * If the cookie corresponds to a descriptor that has been completed - * there is no residue. The same check has already been performed by the - * caller but without holding the channel lock, so the descriptor could - * now be complete. - */ - status =3D dma_cookie_status(&channel->vc.chan, cookie, NULL); - if (status =3D=3D DMA_COMPLETE) - return 0; - - /* - * If the cookie doesn't correspond to the currently processing virtual - * descriptor then the descriptor hasn't been processed yet, and the - * residue is equal to the full descriptor size. Also, a client driver - * is possible to call this function before rz_dmac_irq_handler_thread() - * runs. In this case, the running descriptor will be the next - * descriptor, and will appear in the done list. So, if the argument - * cookie matches the done list's cookie, we can assume the residue is - * zero. - */ - if (cookie !=3D current_desc->vd.tx.cookie) { - list_for_each_entry(desc, &channel->ld_free, node) { - if (cookie =3D=3D desc->vd.tx.cookie) - return 0; - } - - list_for_each_entry(desc, &channel->ld_queue, node) { - if (cookie =3D=3D desc->vd.tx.cookie) - return desc->len; - } - - list_for_each_entry(desc, &channel->ld_active, node) { - if (cookie =3D=3D desc->vd.tx.cookie) - return desc->len; - } + vd =3D vchan_find_desc(&channel->vc, cookie); + if (vd) { + /* Descriptor has been issued but not yet processed. */ + desc =3D to_rz_dmac_desc(vd); + return desc->len; + } else if (channel->desc && channel->desc->vd.tx.cookie =3D=3D cookie) { + /* Descriptor is currently processed. */ + desc =3D channel->desc; + } =20 - /* - * No descriptor found for the cookie, there's thus no residue. - * This shouldn't happen if the calling driver passes a correct - * cookie value. - */ - WARN(1, "No descriptor for cookie!"); + if (!desc) { + /* Descriptor was not found. May be already completed by now. */ return 0; } =20 @@ -813,7 +768,7 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan= *channel, * Calculate number of bytes transferred in processing virtual descriptor. * One virtual descriptor can have many lmdesc. */ - return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, current_desc= , crla); + return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, desc, crla); } =20 static enum dma_status rz_dmac_tx_status(struct dma_chan *chan, @@ -824,21 +779,17 @@ static enum dma_status rz_dmac_tx_status(struct dma_c= han *chan, enum dma_status status; u32 residue; =20 - status =3D dma_cookie_status(chan, cookie, txstate); - if (status =3D=3D DMA_COMPLETE || !txstate) - return status; - scoped_guard(spinlock_irqsave, &channel->vc.lock) { + status =3D dma_cookie_status(chan, cookie, txstate); + if (status =3D=3D DMA_COMPLETE || !txstate) + return status; + residue =3D rz_dmac_chan_get_residue(channel, cookie); =20 - if (rz_dmac_chan_is_paused(channel)) + if (status =3D=3D DMA_IN_PROGRESS && rz_dmac_chan_is_paused(channel)) status =3D DMA_PAUSED; } =20 - /* if there's no residue and no paused, the cookie is complete */ - if (!residue && status !=3D DMA_PAUSED) - return DMA_COMPLETE; - dma_set_residue(txstate, residue); =20 return status; @@ -914,28 +865,18 @@ static irqreturn_t rz_dmac_irq_handler(int irq, void = *dev_id) static irqreturn_t rz_dmac_irq_handler_thread(int irq, void *dev_id) { struct rz_dmac_chan *channel =3D dev_id; - struct rz_dmac_desc *desc =3D NULL; - unsigned long flags; + struct rz_dmac_desc *desc; =20 - spin_lock_irqsave(&channel->vc.lock, flags); + guard(spinlock_irqsave)(&channel->vc.lock); =20 - if (list_empty(&channel->ld_active)) { - /* Someone might have called terminate all */ - goto out; - } + desc =3D channel->desc; + if (!desc) + return IRQ_HANDLED; =20 - desc =3D list_first_entry(&channel->ld_active, struct rz_dmac_desc, node); vchan_cookie_complete(&desc->vd); - list_move_tail(channel->ld_active.next, &channel->ld_free); - if (!list_empty(&channel->ld_queue)) { - desc =3D list_first_entry(&channel->ld_queue, struct rz_dmac_desc, - node); - channel->desc =3D desc; - if (rz_dmac_xfer_desc(channel) =3D=3D 0) - list_move_tail(channel->ld_queue.next, &channel->ld_active); - } -out: - spin_unlock_irqrestore(&channel->vc.lock, flags); + channel->desc =3D NULL; + + rz_dmac_xfer_desc(channel); =20 return IRQ_HANDLED; } @@ -1017,9 +958,7 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, =20 channel->vc.desc_free =3D rz_dmac_virt_desc_free; vchan_init(&channel->vc, &dmac->engine); - INIT_LIST_HEAD(&channel->ld_queue); INIT_LIST_HEAD(&channel->ld_free); - INIT_LIST_HEAD(&channel->ld_active); =20 /* Initialize register for each channel */ rz_dmac_disable_hw(channel); --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62DA1358369 for ; Sat, 11 Apr 2026 11:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907811; cv=none; b=IcIar2i1IgTybFve1zLjHKlA84bgzpiktYrx28TRTtvVcxYTMJE4MJzmCSfPSv+oG6VecTur+oLgJN6Wef2+EhljTb37pzEIpTApvf7VpzSLjDy8v5eA9fhFpxPYSPeFINSeE1BSq5W/9ybwqJturJjvQJIzwgZq7jNjWe/82po= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907811; c=relaxed/simple; bh=iQawvjhzIGXmzEbrFF8bHIYm/8QPf/NESexbbH0n3Ow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=muzW/5f5Usv2Vlbj968cNBzZ5Is90fsncAjaZAFXgbxm3LpFpvECDIU5DnJdqxlLNfuILY5IlwXVbrDrHo88ri5hhBdlD+4+zAB6fz/uGE9ErIgdJIkx60wUJZeXuvn90ZpolWCLn2cPp/h84cZl5M+lw/OC4fCvsjp48MHnNQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=LRqrgw8o; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="LRqrgw8o" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-488a8ca4aadso33200645e9.3 for ; Sat, 11 Apr 2026 04:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907807; x=1776512607; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IUGFjnyw33YmgBsDPw6KMQ7GHcl3buE/kN68Vb3dY6k=; b=LRqrgw8ouf09WxyIcw8weWyhkZ2lqt34blgmZmyUXukcWMGTcn8tgwcIYiZUkia1q4 NFrKy6IhbTY1m17AykVE2+1edcVdU+JOCwi9mO3u4o8mAIN5f8UZ/Dp2bx+ZsNOA1eYu 36pApcDvNhRn0ekxQzGNvxZEwmhFnXkjQCPGsXdQ1NLsrNbikjoCOtUSTQ2bD1UJ/G4P /1bcrHU1IhCQb2n2OCauhbQxN5MVS9Qe8kJPXaSw7mAIkvdONtExMw+o3q/ug87nMN55 tW6xJCSTwlTIwsvqiZdPIpmIRT969ApU96Ti7dyz10NlTspqsbFU/ijeFKRelyDAXQwS /Ixw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907807; x=1776512607; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IUGFjnyw33YmgBsDPw6KMQ7GHcl3buE/kN68Vb3dY6k=; b=af4X0lU5kulWaUiMfz/vju8xMcdM0jvGAXDiDlac6c33fxTDT4LwetDNEKBaCjl4bH SGTCLOvnNtAQ5mLFyNQtluAbbU9hO0Y7CD2Qy95cUELorVmo/fuG5lxZwXTMZHapVDaf Bbvm6xBWuqtmWwH8zA11WMJutpRSG6XiwBGzR6Gm+DZtVUOk3UL+EVKfdlHZk+24qm/w Ys+5WwmGOImFjQ4KAVyK2RYB9vyZh0koDeYOOX21w68HpohtO8+2Drl64ZhX5jZTl1k1 a6BC9e+bveWCDiREpXXgqfOAy/e//HD6U6WzlY4lH6ZbLV6P8MmgZybuGIVsbVQMobYH P0Iw== X-Forwarded-Encrypted: i=1; AJvYcCUBWE/KYQPgUp0WzWlLp9Yhw2iRWfdVpXEMNUJshjFIWRe89Y2rc/6CLcig8dhFUQLt/n2bWJgVhQBDto4=@vger.kernel.org X-Gm-Message-State: AOJu0Ywp1AH3j9MJnnHlB4UI9nnkKCeaC/s+Mi6SGtL5wz9qBdvj0HoU MR2aLQfA1L6rjA7vqaZ2KOxNLgc4cYafDckhWrQqt5hLH41wJt2+FcR0X2GAQv4MMXA= X-Gm-Gg: AeBDieuvsdoZqogM9mzpoiteXrMWYfz7HsNm0z8sIeznrsNTUTAqUHKvS8TjKD1iV31 xocyhQofAWs4rq7gYOaKWafpyHwJKu4PK2k/AJJXanbV7AikFLQ1iM/NnVKVEwXCK35LkB48wHr vmZZbwWhWhldReRKYI7zbuNTR2UO8FHgOS1ad53/eKD1aKKuJCdSXNtT/XkmjyawkEkyIJCCZxX 0Z6cqj3bz9+0sjewvjhBdtDDz2mPyMPc+1Zu9GxveKZ1g8ZB/lqZ6MIjGBUaDimqoGlA3Eb+rRM ylKWTDvABDJPCvpF670faFRVx/RCoco/Fb/woUv/xnY2XoizXzSPZdyONaPWTRScH6C0XLqY4sH Teq1Dg4zr1EHLHuHiV5LeNc85b/dqqIrDMh3BHpsheoo+c+Po9EEY8op3AwArdIvSvarCcN8a6g pk6IOcna/e+IFNp3kELW3VfftZ/fOkLwP9rhckBSiNVX8k82oboRc9 X-Received: by 2002:a05:6000:24c2:b0:43c:f90b:5668 with SMTP id ffacd0b85a97d-43d642a7a6dmr9677284f8f.23.1775907806737; Sat, 11 Apr 2026 04:43:26 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:26 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 11/17] dmaengine: sh: rz-dmac: Refactor pause/resume code Date: Sat, 11 Apr 2026 14:42:57 +0300 Message-ID: <20260411114303.2814115-12-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Subsequent patches will add suspend/resume and cyclic DMA support to the rz-dmac driver. This support needs to work on SoCs where power to most components (including DMA) is turned off during system suspend. For this, some channels (for example cyclic ones) may need to be paused and resumed manually by the DMA driver during system suspend/resume. Refactor the pause/resume support so the same code can be reused in the system suspend/resume path. Signed-off-by: Claudiu Beznea --- Changes in v4: - reset channel->status in rz_dmac_free_chan_resources() and rz_dmac_terminate_all() Changes in v3: - none, this patch new new drivers/dma/sh/rz-dmac.c | 73 ++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 04eb1a7f1e62..d009b7607d44 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,14 @@ struct rz_dmac_desc { =20 #define to_rz_dmac_desc(d) container_of(d, struct rz_dmac_desc, vd) =20 +/** + * enum rz_dmac_chan_status: RZ DMAC channel status + * @RZ_DMAC_CHAN_STATUS_PAUSED: Channel is paused though DMA engine callba= cks + */ +enum rz_dmac_chan_status { + RZ_DMAC_CHAN_STATUS_PAUSED, +}; + struct rz_dmac_chan { struct virt_dma_chan vc; void __iomem *ch_base; @@ -74,6 +83,8 @@ struct rz_dmac_chan { dma_addr_t src_per_address; dma_addr_t dst_per_address; =20 + unsigned long status; + u32 chcfg; u32 chctrl; int mid_rid; @@ -491,6 +502,8 @@ static void rz_dmac_free_chan_resources(struct dma_chan= *chan) channel->mid_rid =3D -EINVAL; } =20 + channel->status =3D 0; + spin_unlock_irqrestore(&channel->vc.lock, flags); =20 vchan_free_chan_resources(&channel->vc); @@ -589,6 +602,9 @@ static int rz_dmac_terminate_all(struct dma_chan *chan) } =20 vchan_get_all_descriptors(&channel->vc, &head); + + channel->status =3D 0; + spin_unlock_irqrestore(&channel->vc.lock, flags); vchan_dma_desc_free_list(&channel->vc, &head); =20 @@ -795,35 +811,70 @@ static enum dma_status rz_dmac_tx_status(struct dma_c= han *chan, return status; } =20 -static int rz_dmac_device_pause(struct dma_chan *chan) +static int rz_dmac_device_pause_set(struct rz_dmac_chan *channel, + unsigned long set_bitmask) { - struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + int ret =3D 0; u32 val; =20 - guard(spinlock_irqsave)(&channel->vc.lock); + lockdep_assert_held(&channel->vc.lock); =20 if (!rz_dmac_chan_is_enabled(channel)) return 0; =20 + if (rz_dmac_chan_is_paused(channel)) + goto set_bit; + rz_dmac_ch_writel(channel, CHCTRL_SETSUS, CHCTRL, 1); - return read_poll_timeout_atomic(rz_dmac_ch_readl, val, - (val & CHSTAT_SUS), 1, 1024, - false, channel, CHSTAT, 1); + ret =3D read_poll_timeout_atomic(rz_dmac_ch_readl, val, + (val & CHSTAT_SUS), 1, 1024, false, + channel, CHSTAT, 1); + +set_bit: + channel->status |=3D set_bitmask; + + return ret; } =20 -static int rz_dmac_device_resume(struct dma_chan *chan) +static int rz_dmac_device_pause(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); - u32 val; =20 guard(spinlock_irqsave)(&channel->vc.lock); =20 + return rz_dmac_device_pause_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED)); +} + +static int rz_dmac_device_resume_set(struct rz_dmac_chan *channel, + unsigned long clear_bitmask) +{ + int ret =3D 0; + u32 val; + + lockdep_assert_held(&channel->vc.lock); + /* Do not check CHSTAT_SUS but rely on HW capabilities. */ =20 rz_dmac_ch_writel(channel, CHCTRL_CLRSUS, CHCTRL, 1); - return read_poll_timeout_atomic(rz_dmac_ch_readl, val, - !(val & CHSTAT_SUS), 1, 1024, - false, channel, CHSTAT, 1); + ret =3D read_poll_timeout_atomic(rz_dmac_ch_readl, val, + !(val & CHSTAT_SUS), 1, 1024, false, + channel, CHSTAT, 1); + + channel->status &=3D ~clear_bitmask; + + return ret; +} + +static int rz_dmac_device_resume(struct dma_chan *chan) +{ + struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + + guard(spinlock_irqsave)(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED))) + return 0; + + return rz_dmac_device_resume_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED)= ); } =20 /* --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11E2E359A66 for ; Sat, 11 Apr 2026 11:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907811; cv=none; b=d0y/x5dmC8/i6oYAFzD3ibBp+1z5wGqrpBC6o679rtuqQPloYAoWykQpIhg2goUBzXMWzq/jFrqe1Pk585GT8QOIfCdLp7CHFM60NVluBD+bMefE3GtU/XA3RiwwsXU+5EM+rZ7BMBg5TSKkIToxiSQy8Puz5EPQO7kOwNQKgwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907811; c=relaxed/simple; bh=IW52sWUaqMFEY6BbWKKClK/wbgEBkQeALR5hdqMA95U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mtdsanf3T4mX6AtLKPlWIhD6SCtfzkwHsUjr/EzfoAxmofHDiz+shRPMbtaWae5DiQu7keMGmmszYuHjQvymWORh/eIwwPylgzOlsocribcZtTEjc35Y8zLlchvljXsuCmDzW7D36SLdlC7tEbmqcdSmpoBl9HkQP4Ml9pv1k1w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=MLKtE0J4; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="MLKtE0J4" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-43d04fc3bf2so1683660f8f.3 for ; Sat, 11 Apr 2026 04:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907808; x=1776512608; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3zdkb0CAXfpSevM/ivqXKAKRICDyAzezyAIbw20Wd9A=; b=MLKtE0J4OBmPZxXaz9RiZvRq2+nnNzXMbYGy2n/ectLDEhjHo+XxPM0s0XkB3bgoxl i7N5QlSfHqxhen27HErppclZvCimwOzUem7Y2LcVjnq/185sRvBR/vaeucKJmz6bI/pI IlFb/uBzOJQkaeR0MUy7rHiJoKYOjqtQOl4e/RmbL5sIFRIBpnY5R5hZeVp/Rc75TdE+ HbXItGGWO72c+P5Tc8RnXaJUb+6uaZhQntmBBlXhTjw9+ya+r76Tr6PbpDRq7YBWLgE9 T5uXW66wI9fKsMgiWfXtFf+AwhZlTMEfZD+gRfOzl/4CuM7Q/MhrpbYdmjzaqV269onT BVlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907808; x=1776512608; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=3zdkb0CAXfpSevM/ivqXKAKRICDyAzezyAIbw20Wd9A=; b=s6DaKmHDmppK3XdCzT1iFopmk9TLGpxi971fewcHeJ6G9ZY9j3yyxMI6bC/N6Smv4m Lc/2fIwWMHN7uAtnxClLNB/W4KzS+joUoz160e7R0VsJPJA5tgyNvWv0tLyNYsZIdcik Muwje+iuUhp9VfDzN1TXGE215y/Cs4iFYB9sNH59YIFqyLHZu9lLoH+v/Gwls5fdN3JQ S1WkZwM8Ef9QPstwxhuXcPXADJv5cfEscWBGbp6M2ZRBZ4X45ftGlNIU04Nq9qMzX+jd XzK1IxlNezBwcSwR3eowMQHAbg+vMrJP6gv8PbL2BSBqxgVN30qA7YAJV1BdUwRuGX9D yAvA== X-Forwarded-Encrypted: i=1; AJvYcCUctAJpp+EFx0hbNW9bMZyQx5GBDPz6stf3ximAje5XNSPJFlNj2/eqex0LiOEl9xAMbGgeQpitbFnrRac=@vger.kernel.org X-Gm-Message-State: AOJu0YwKMlQhM0fEXtgqXMBDHizZcyVs+7rbCYZ1RaLPzDiKySU5KIlz vzieCrWfDpJmNiw016UhFnkcRWjVfI5Y3eExyqmj7BGgnOS7mjViYg9D+ANZ3Q8eq6E= X-Gm-Gg: AeBDietjC2oykRUpWEmbkMkAmyhrnyeX9b/eukoENmNf7n4jXsX/5P+xdnJrzT0idyt N5kgTWOTYRnwkgENb7hjxGbSk009CzTQCbNmjur83xpb9PcTwezHNDG6s5/YG+NBzc8DJ9YxR9M Kg+jVINJmlutLhBAil7Sd02t8OX8aiyFA9jTjV9mSGyUxqejJLd877O1+K9K9Evutntujv45oZ8 SzDuSdY3uopWaxUr3Tds18sBRmpkshhKWN6fzqO+NL62dwSVpQzq9/E/OinFTNJX1RAf8IU/kmr cGI8piSOkSmGqrZnlf6oqOE+p+dzwY4CmWWCgyQLO8Oc+V+wDFhzBCTwPmDv0cn/aoyTImYu+Ct lRo/61B6wnFsOkBzWuHaZwOtg6HwDP0maTaiZI7gAE2f+4mSlg4qI+OcQ7qyEa3yh8+OnFUQUb9 X59+mYMSwyayKTK5BAQRQ7hShNu04pRa/mmOX8C8dCY3/vKeg+dY+g X-Received: by 2002:a05:6000:2304:b0:43d:1c3b:2dae with SMTP id ffacd0b85a97d-43d64255160mr9442521f8f.9.1775907808486; Sat, 11 Apr 2026 04:43:28 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:27 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 12/17] dmaengine: sh: rz-dmac: Drop the update of channel->chctrl with CHCTRL_SETEN Date: Sat, 11 Apr 2026 14:42:58 +0300 Message-ID: <20260411114303.2814115-13-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The CHCTRL_SETEN bit is explicitly set in rz_dmac_enable_hw(). Updating struct rz_dmac_chan::chctrl with this bit in rz_dmac_prepare_desc_for_memcpy() and rz_dmac_prepare_descs_for_slave_sg() is unnecessary in the current code base. Moreover, it conflicts with the configuration sequence that will be used for cyclic DMA channels during suspend to RAM. Cyclic DMA support will be introduced in subsequent commits. This is a preparatory commit for cyclic DMA suspend to RAM support. Signed-off-by: Claudiu Beznea --- Changes in v4: - set channel->chctrl =3D 0 in rz_dmac_prepare_descs_for_slave_sg() Changes in v3: - none Changes in v2: - fixed typos in patch title and patch description drivers/dma/sh/rz-dmac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index d009b7607d44..958ee45abc70 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -377,7 +377,7 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_d= mac_chan *channel) rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_= no); =20 channel->chcfg =3D chcfg; - channel->chctrl =3D CHCTRL_STG | CHCTRL_SETEN; + channel->chctrl =3D CHCTRL_STG; } =20 static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channe= l) @@ -428,7 +428,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct r= z_dmac_chan *channel) =20 rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid); =20 - channel->chctrl =3D CHCTRL_SETEN; + channel->chctrl =3D 0; } =20 static void rz_dmac_xfer_desc(struct rz_dmac_chan *chan) --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC70035A3A9 for ; Sat, 11 Apr 2026 11:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907813; cv=none; b=p4RuC0D+j3z2hC21s1s/iCltNMES5z1iw8y7M9/syWrEbu+NgEjZdejrrwKx5d735+SZq6QUOl9wldS9I9AFOMqFSa41nz+UA/yfe/p979rVLvuBedbWolYz2tgFb1yJFxZy0fF6QtBtjiWDAqX8UF1v830LupvgypA9V1Ejeh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907813; c=relaxed/simple; bh=G5ZrxdDz6SrJRh5gILn+jY8SjkPfRoyYynwfeT8cu7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZnBIjSL0QRy/ud43z2DDbcVCNRhrD0Xz9caVFizreCUvaXYcLd3yZDMKqQJhFn+F6AOtSqjb55LE6DKGORv5sIBI0F6uJcE7W7n6cc0MdB4kE/jsgoS8+HQeX0aWwcug0eChqgtJfXYdlgKWQUc6HZViJmw0qoRlsalJRrR3fh8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=cLBNfpcS; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="cLBNfpcS" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-43b95e5b3afso1851823f8f.3 for ; Sat, 11 Apr 2026 04:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907810; x=1776512610; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e1vnLRbFLHGljDC8DA+DpcpC7Ymwdn6jDCXLtiDCAnA=; b=cLBNfpcSVK9HGMiaoknKHEkySooReh/4Vx2xP0KasiXixX9OufkHjPijEn9SXuIg5J 8pwOo7X+NG7A72hsPq6bRvfWBf4LM/zjVDUn58a8HOwdkf/8hlwz1pwt4J8Ws3GtvVWK k6hO8Oq18uWuZIsUTP+2Ukxjegb1JnLAcAL3pxB14iQeraKf6YjgIsM1/hx9ZIQ0z0/E DR4EQep5AaDtWs9ho8l8NuCcIJiEY8Vfwwyx+qxjQ21HD0zRLWQo9F2+9k7qXs6bfuRC Iq8l4kaIroDFK4fUMuYb/zRW8tP6xeO7E8CJGczN7UXLZLrLYZuUWZAjJdrOvMkdWdrG WjOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907810; x=1776512610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=e1vnLRbFLHGljDC8DA+DpcpC7Ymwdn6jDCXLtiDCAnA=; b=P+Sa2nqQP0qkAAqB3rzdxs7LeUpn+e16b12cGSqezY+/4eoiIhKDy9CtBOJSy6AnON 9sFsPrupp+eRL6fwpcqYtxh5x5ARfrS6mjE2VH5wBW03a1qUMOfQiW6Zztl/F8VejsEG FIe8CT1i6rI9rna7hkIcebv5AkU1wpMniPDARzLZq4bpW6rELlI+SbG34Beskj21rhwg FtkA4GP5XPLddQCUZBbnNsgmu2oQvLCd5EcpMUkakHSOC94nYxly1qTn7CKyOT21Cg6B rVEooRFmNeLg7zsjlz4vs6EdXF6E2MfRePF+2iqZnONCFRxZEUzDkILYKRDt96TG22KM hSpQ== X-Forwarded-Encrypted: i=1; AJvYcCXM9gZ5h2X9ISs4t/db6lo2US24JS/VgrpwhdsQTk50oHRvcSM8yDlVQfVaWi5umeCR41tTMLOYwU5Yhy4=@vger.kernel.org X-Gm-Message-State: AOJu0YxKxc1CczeK0D3jWiMEilWagu1jmtCNBQlfzgoECMY+XTROgJGD bOCvVExbbkUBfUtCR42/Ei/FD2AJNiCUqRBhkFQ0v3sUwXLk+eEkNNcdAx5xJVzQEVs= X-Gm-Gg: AeBDievROdcUXq/SaNIRi17fy7e4JpH/ooEoXBErvQFfDI9AdCpVtWjc7Ks5nDt9NcK nwhqy8D70fyYovxzUx1c4mSCBrAUQssokXQU2CxwiIMOrY9lXh4fuX1Xgqs3dRJVMpw/zb0TkJm IdcwZqptOw2e7KnNHTTHjzeF80G1y+kDmS8/3DYw/98ZAdjwsBlWwbjArNLXV84wRVpVY/B4vCu uWQbqvrDYi/Ym6TdIgG2/WvIgQZwsHqWHZmt5o2LXDaxOms7zi/oTM19TrLuRhk5SuxEb5fvIzV dwEGDXgIH8Rm+skJ+Ste1dPepF66c6yyXtFy9wS6J7RHrHEtMDLbzQ2q/x2AvvlR7RgnjO9BIDh n5dYWiCK0PEH4qX8x26bTUKiXN84h1TNdAUs9Pzv8YUZGqdRZMA7XYCUbzSACk+piAXL4pHmpuT uW7Vr7zjqLgx/7Pkr1e90D4JLAZN4y2xfcEREISSNzrBoXyjn8s4GK X-Received: by 2002:a5d:5847:0:b0:43d:4fca:a973 with SMTP id ffacd0b85a97d-43d642c1a9dmr9196491f8f.40.1775907810115; Sat, 11 Apr 2026 04:43:30 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:29 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 13/17] dmaengine: sh: rz-dmac: Add cyclic DMA support Date: Sat, 11 Apr 2026 14:42:59 +0300 Message-ID: <20260411114303.2814115-14-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add cyclic DMA support to the RZ DMAC driver. A per-channel status bit is introduced to mark cyclic channels and is set during the DMA prepare callback. The IRQ handler checks this status bit and calls vchan_cyclic_callback() accordingly. Signed-off-by: Claudiu Beznea --- Changes in v4: - drop the nxla update logic in rz_dmac_lmdesc_recycle() as this is not needed for any kind of transfers - drop the update of channel->status =3D 0 from rz_dmac_free_chan_resources= () and rz_dmac_terminate_all() as this was moved in patch 09/17 Changes in v3: - updated rz_dmac_lmdesc_recycle() to restore the lmdesc->nxla - in rz_dmac_prepare_descs_for_cyclic() update directly the desc->start_lmdesc with the descriptor pointer insted of the descriptor address - used rz_dmac_lmdesc_addr() to compute the descritor address - set channel->status =3D 0 in rz_dmac_free_chan_resources() - in rz_dmac_prep_dma_cyclic() check for invalid periods or buffer len and limit the critical area protected by spinlock - set channel->status =3D 0 in rz_dmac_terminate_all() - updated rz_dmac_calculate_residue_bytes_in_vd() to use=20 rz_dmac_lmdesc_addr() - dropped goto in rz_dmac_irq_handler_thread() as it is not needed anymore; dropped also the local variable desc Changes in v2: - none drivers/dma/sh/rz-dmac.c | 136 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 6 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 958ee45abc70..9a10430109e5 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -35,6 +35,7 @@ enum rz_dmac_prep_type { RZ_DMAC_DESC_MEMCPY, RZ_DMAC_DESC_SLAVE_SG, + RZ_DMAC_DESC_CYCLIC, }; =20 struct rz_lmdesc { @@ -67,9 +68,11 @@ struct rz_dmac_desc { /** * enum rz_dmac_chan_status: RZ DMAC channel status * @RZ_DMAC_CHAN_STATUS_PAUSED: Channel is paused though DMA engine callba= cks + * @RZ_DMAC_CHAN_STATUS_CYCLIC: Channel is cyclic */ enum rz_dmac_chan_status { RZ_DMAC_CHAN_STATUS_PAUSED, + RZ_DMAC_CHAN_STATUS_CYCLIC, }; =20 struct rz_dmac_chan { @@ -191,6 +194,7 @@ struct rz_dmac { =20 /* LINK MODE DESCRIPTOR */ #define HEADER_LV BIT(0) +#define HEADER_WBD BIT(2) =20 #define RZ_DMAC_MAX_CHAN_DESCRIPTORS 16 #define RZ_DMAC_MAX_CHANNELS 16 @@ -431,6 +435,57 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct = rz_dmac_chan *channel) channel->chctrl =3D 0; } =20 +static void rz_dmac_prepare_descs_for_cyclic(struct rz_dmac_chan *channel) +{ + struct dma_chan *chan =3D &channel->vc.chan; + struct rz_dmac *dmac =3D to_rz_dmac(chan->device); + struct rz_dmac_desc *d =3D channel->desc; + size_t period_len =3D d->sgcount; + struct rz_lmdesc *lmdesc; + size_t buf_len =3D d->len; + size_t periods =3D buf_len / period_len; + + lockdep_assert_held(&channel->vc.lock); + + channel->chcfg |=3D CHCFG_SEL(channel->index) | CHCFG_DMS; + + if (d->direction =3D=3D DMA_DEV_TO_MEM) { + channel->chcfg |=3D CHCFG_SAD; + channel->chcfg &=3D ~CHCFG_REQD; + } else { + channel->chcfg |=3D CHCFG_DAD | CHCFG_REQD; + } + + lmdesc =3D channel->lmdesc.tail; + d->start_lmdesc =3D lmdesc; + + for (size_t i =3D 0; i < periods; i++) { + if (d->direction =3D=3D DMA_DEV_TO_MEM) { + lmdesc->sa =3D d->src; + lmdesc->da =3D d->dest + (i * period_len); + } else { + lmdesc->sa =3D d->src + (i * period_len); + lmdesc->da =3D d->dest; + } + + lmdesc->tb =3D period_len; + lmdesc->chitvl =3D 0; + lmdesc->chext =3D 0; + lmdesc->chcfg =3D channel->chcfg; + lmdesc->header =3D HEADER_LV | HEADER_WBD; + + if (i =3D=3D periods - 1) + lmdesc->nxla =3D rz_dmac_lmdesc_addr(channel, d->start_lmdesc); + + if (++lmdesc >=3D (channel->lmdesc.base + DMAC_NR_LMDESC)) + lmdesc =3D channel->lmdesc.base; + } + + channel->lmdesc.tail =3D lmdesc; + + rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid); +} + static void rz_dmac_xfer_desc(struct rz_dmac_chan *chan) { struct virt_dma_desc *vd; @@ -452,6 +507,10 @@ static void rz_dmac_xfer_desc(struct rz_dmac_chan *cha= n) case RZ_DMAC_DESC_SLAVE_SG: rz_dmac_prepare_descs_for_slave_sg(chan); break; + + case RZ_DMAC_DESC_CYCLIC: + rz_dmac_prepare_descs_for_cyclic(chan); + break; } =20 rz_dmac_enable_hw(chan); @@ -586,6 +645,55 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct sc= atterlist *sgl, return vchan_tx_prep(&channel->vc, &desc->vd, flags); } =20 +static struct dma_async_tx_descriptor * +rz_dmac_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, + size_t buf_len, size_t period_len, + enum dma_transfer_direction direction, + unsigned long flags) +{ + struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + struct rz_dmac_desc *desc; + size_t periods; + + if (!is_slave_direction(direction)) + return NULL; + + if (!period_len || !buf_len) + return NULL; + + periods =3D buf_len / period_len; + if (!periods || periods > DMAC_NR_LMDESC) + return NULL; + + scoped_guard(spinlock_irqsave, &channel->vc.lock) { + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) + return NULL; + + desc =3D list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc= , node); + if (!desc) + return NULL; + + list_del(&desc->node); + + channel->status |=3D BIT(RZ_DMAC_CHAN_STATUS_CYCLIC); + } + + desc->type =3D RZ_DMAC_DESC_CYCLIC; + desc->sgcount =3D period_len; + desc->len =3D buf_len; + desc->direction =3D direction; + + if (direction =3D=3D DMA_DEV_TO_MEM) { + desc->src =3D channel->src_per_address; + desc->dest =3D buf_addr; + } else { + desc->src =3D buf_addr; + desc->dest =3D channel->dst_per_address; + } + + return vchan_tx_prep(&channel->vc, &desc->vd, flags); +} + static int rz_dmac_terminate_all(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); @@ -733,9 +841,18 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struc= t rz_dmac_chan *channel, } =20 /* Calculate residue from next lmdesc to end of virtual desc */ - while (lmdesc->chcfg & CHCFG_DEM) { - residue +=3D lmdesc->tb; - lmdesc =3D rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) { + u32 start_lmdesc_addr =3D rz_dmac_lmdesc_addr(channel, desc->start_lmdes= c); + + while (lmdesc->nxla !=3D start_lmdesc_addr) { + residue +=3D lmdesc->tb; + lmdesc =3D rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); + } + } else { + while (lmdesc->chcfg & CHCFG_DEM) { + residue +=3D lmdesc->tb; + lmdesc =3D rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); + } } =20 dev_dbg(dmac->dev, "%s: VD residue is %u\n", __func__, residue); @@ -924,10 +1041,14 @@ static irqreturn_t rz_dmac_irq_handler_thread(int ir= q, void *dev_id) if (!desc) return IRQ_HANDLED; =20 - vchan_cookie_complete(&desc->vd); - channel->desc =3D NULL; + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) { + vchan_cyclic_callback(&desc->vd); + } else { + vchan_cookie_complete(&desc->vd); + channel->desc =3D NULL; =20 - rz_dmac_xfer_desc(channel); + rz_dmac_xfer_desc(channel); + } =20 return IRQ_HANDLED; } @@ -1179,6 +1300,8 @@ static int rz_dmac_probe(struct platform_device *pdev) engine =3D &dmac->engine; dma_cap_set(DMA_SLAVE, engine->cap_mask); dma_cap_set(DMA_MEMCPY, engine->cap_mask); + dma_cap_set(DMA_CYCLIC, engine->cap_mask); + engine->directions =3D BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); engine->residue_granularity =3D DMA_RESIDUE_GRANULARITY_BURST; rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_0_7_COMMON_BASE + DCTRL); rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_8_15_COMMON_BASE + DCTRL); @@ -1190,6 +1313,7 @@ static int rz_dmac_probe(struct platform_device *pdev) engine->device_tx_status =3D rz_dmac_tx_status; engine->device_prep_slave_sg =3D rz_dmac_prep_slave_sg; engine->device_prep_dma_memcpy =3D rz_dmac_prep_dma_memcpy; + engine->device_prep_dma_cyclic =3D rz_dmac_prep_dma_cyclic; engine->device_config =3D rz_dmac_config; engine->device_terminate_all =3D rz_dmac_terminate_all; engine->device_issue_pending =3D rz_dmac_issue_pending; --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCA5135B659 for ; Sat, 11 Apr 2026 11:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907816; cv=none; b=bVtAv6zxejYL/+sR7V9bHYqKXhxIGORGHMCCf7R76UfIC58aFUwgm9k/fMNrBOgFEi2Iyd9JrU5idpxgTei2uN6wgQ4qFAwfl9TlxWlg3XGgAUaz9cMr1l80iDIYsCosSBIgEsrNcUmoo/W4qWES3ArFlizQZFZBAt7FGE8o7ZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907816; c=relaxed/simple; bh=gfdfvET+/ytu3LqE5vMvaJqB2mOAaDG7bZaE2zA+kYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hFs9EQ6EnQ8aSaeud52BDwr8fCqA6Z4xgPnFpP4C8jeaRMlYAweCfLlZc0X/mo0pd8KzBZhUZ2wlMgUoRqMkEBZv2sBiil9ZkRM6MnFreKw1yTLkc8ZZeoCnScpR6ZRRNaTQNfPN1rgT1wDSxiplSMIzDibH965Q0mzGOat2JnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=ce1oBavX; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="ce1oBavX" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-43b983bb07eso1851684f8f.0 for ; Sat, 11 Apr 2026 04:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907812; x=1776512612; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zlj+q2kP9Cu8qVdUYl4BQTSd5aVqUZiR4xxofBEVNKY=; b=ce1oBavX78g5I5DDFvStqAdrE8XK2Ox/AAH46GnlEkNAGltzF1Zd177RBvbxMdSlG4 94NtOHlPxe/jhLHR0gg6vUj4/0DwUV9qG8bX/H67hK7kqwaERrdMk3b4cte6ElTEiVHs CGo9Nx2533Ye8GMxb7UhGFRM4vQbvU89AGMV58FRhbLWRj1QfKbkUBR0wVmjNxb0+UBa d2qRby9haUhL4rpmmxivpn37I0IHBIK0LVcufZLKnuX0m6rsH+ezN+6S01QvgHCEqDBU jb6BC8OIb3VCkU1ZB6raRVOpxzQiPMZQot0e/egrZZ8AeY9qC5B2zLKS/VT/LfpCpV3m wGUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907812; x=1776512612; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zlj+q2kP9Cu8qVdUYl4BQTSd5aVqUZiR4xxofBEVNKY=; b=SNTemeHF1/RKmlA1fmv+wsAkQRTD8O43Uv93L85F8BpQydXPdXBuc2ytUzDKDeaQWE JXz7Mb15DPddPfsL+PdiTOZa4QpQPvFHjuzp7DXgsY+02i+BNhGtYMqx3RSh13vsUy6Q xyPq7i9f7KybExiPQQgBUdQtTbkjQhmnuNZplriqHcuxpa4gXtKbMPJWUjhXuUnvp3/l oaC0TjyxWC924O+NtJoqC9cP3V34aPFHS0MBwAU7Lxfjaef+oVBmX6sJJQiZadRcxN4I vTfDnB0j4vVXuMDCnUSx2g2Epp1Qd3b/3twhNU1Mt0KJofVSPI+UR1BEH3+FTHEbagLy TvXA== X-Forwarded-Encrypted: i=1; AJvYcCXfZhqSy9DHvXFcJe+rkOgqsF6oVMQKFRbjAYIALcJfoowaQjmDL4hmF1IIbvRq5SRq5wvF3WcuX/NDwus=@vger.kernel.org X-Gm-Message-State: AOJu0YxdsTHJd7kbembpeeMnms0MkkOyObc01sUIFoLop8xewre6bdbS AFJLpDfLCr5unZV3HH/+1BdIq0Q+htWXqUX7Vn6q1DjdLRd8ye7aJb23rzYUGS3FCiA= X-Gm-Gg: AeBDiesnstoI3hb03pWqZki2K/wFVz8JlPd8X4E0f2Cu/hzg3wcbgukeFI9PGya0w/d dgYS+i+7W/BG8vgIbuLmlCjfeLmAAx7n6K1nwkJLG6gwyW54rCtQ6UQrpK9ANOWa0kFdpkKKqml zN9l2A9Cxdz1pbE2rvd9/Jg579mlhLbLwjdt8r5rMbCQV/krl2soCmaSL4NQwBxoAUQD//Sb53B uL66J186G5UqCb+r957gbi5NbP/dU+C8U26nby50veTUBR8YxALXw7ArU5tcCA/NOx2NiS/BGe2 fliXo1eg5RDdiKMUHWGx4/Nr3fB2mSRqD+R2lLvhAkF17miM6EvupdFpf6Vs5S9KW0CS0ZMi4Wd pXb7Qh4+8n4/7Sl4gMvNsXPxVkzXZITv5PV/tpLoubNe+L+1m6xdaSJ4ANnfzy1NyNoBzt+VVhv LKp7uHTMrOJkw7FobY6GvDRojAbljY7hHpNQrjlESynlj4e6M4Y+nLwIjZHKtd0R4= X-Received: by 2002:a05:6000:200f:b0:43d:2f94:3b40 with SMTP id ffacd0b85a97d-43d64255019mr9745909f8f.6.1775907812110; Sat, 11 Apr 2026 04:43:32 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:31 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 14/17] dmaengine: sh: rz-dmac: Add suspend to RAM support Date: Sat, 11 Apr 2026 14:43:00 +0300 Message-ID: <20260411114303.2814115-15-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The Renesas RZ/G3S SoC supports a power saving mode in which power to most of the SoC components is turned off, including the DMA IP. Add suspend to RAM support to save and restore the DMA IP registers. Cyclic DMA channels require special handling. Since they can be paused and resumed during system suspend/resume, the driver restores additional registers for these channels during the system resume phase. If a channel was not explicitly paused during suspend, the driver ensures that it is paused and resumed as part of the system suspend/resume flow. This might be the case of a serial device being used with no_console_suspend. For non-cyclic channels, the dev_pm_ops::prepare callback waits for all the ongoing transfers to complete before allowing suspend-to-RAM to proceed. Signed-off-by: Claudiu Beznea --- Changes in v4: - in rz_dmac_device_synchronize() kept the read_poll_timeout() as this doesn't fail anymore with the proper status return from ->device_tx_status() API in case the channel is paused; with it the patch description was updated - keep the cleanup path in rz_dmac_suspend() simpler to avoid confusion when using guard() - used SYSTEM_SLEEP_PM_OPS() as there is no need for having the suspend/resume callbacks being called in NOIRQ phase Changes in v3: - dropped RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED - dropped read_poll_timeout() from rz_dmac_device_synchronze() as with audio drivers this times out all the time on suspend because the audio DMA is already paused when the rz_dmac_device_synchronize() is called; updated the commit description to describe this change - call rz_dmac_device_pause_internal() only if RZ_DMAC_CHAN_STATUS_PAUSED bit is not set or the device is enabled in HW - updated rz_dmac_device_resume_set() to have it simpler and cover the cases when it is called with the channel enabled or paused; updated the comment describing the covered use cases - call rz_dmac_device_resume_internal() only if RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL bit is set - in rz_dmac_chan_is_enabled() return -EAGAIN only if the channel is enabled in HW - in rz_dmac_suspend_recover() drop the update of RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED as this is not available anymore - in rz_dmac_suspend() call rz_dmac_device_pause_internal() unconditionally as the logic is now handled inside the called function; also, do not ignore anymore the failure of internal suspend and abort the suspend instead - report channel internal resume failures in rz_dmac_resume() - use rz_dmac_disable_hw() instead of open coding it in rz_dmac_resume() - call rz_dmac_device_resume_internal() uncoditionally as the skip logic is now handled in the function itself - use NOIRQ_SYSTEM_SLEEP_PM_OPS() - didn't collect Tommaso's Tb tag as the series was changed a lot since v2 Changes in v2: - fixed typos in patch description - in rz_dmac_suspend_prepare(): return -EAGAIN based on the value returned by vchan_issue_pending() - in rz_dmac_suspend_recover(): clear RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED for non cyclic channels - in rz_dmac_resume(): call rz_dmac_set_dma_req_no() only for cyclic channe= ls drivers/dma/sh/rz-dmac.c | 188 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 183 insertions(+), 5 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 9a10430109e5..00e18d8213ca 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -69,10 +69,12 @@ struct rz_dmac_desc { * enum rz_dmac_chan_status: RZ DMAC channel status * @RZ_DMAC_CHAN_STATUS_PAUSED: Channel is paused though DMA engine callba= cks * @RZ_DMAC_CHAN_STATUS_CYCLIC: Channel is cyclic + * @RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL: Channel is paused through driver = internal logic */ enum rz_dmac_chan_status { RZ_DMAC_CHAN_STATUS_PAUSED, RZ_DMAC_CHAN_STATUS_CYCLIC, + RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL, }; =20 struct rz_dmac_chan { @@ -92,6 +94,10 @@ struct rz_dmac_chan { u32 chctrl; int mid_rid; =20 + struct { + u32 nxla; + } pm_state; + struct list_head ld_free; =20 struct { @@ -962,20 +968,57 @@ static int rz_dmac_device_pause(struct dma_chan *chan) return rz_dmac_device_pause_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED)); } =20 +static int rz_dmac_device_pause_internal(struct rz_dmac_chan *channel) +{ + lockdep_assert_held(&channel->vc.lock); + + /* Skip channels explicitly paused by consummers or disabled. */ + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED) || + !rz_dmac_chan_is_enabled(channel)) + return 0; + + return rz_dmac_device_pause_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED_I= NTERNAL)); +} + static int rz_dmac_device_resume_set(struct rz_dmac_chan *channel, unsigned long clear_bitmask) { - int ret =3D 0; u32 val; + int ret; =20 lockdep_assert_held(&channel->vc.lock); =20 - /* Do not check CHSTAT_SUS but rely on HW capabilities. */ + /* + * We can be: + * + * 1/ after the channel was paused by a consummer and now it + * needs to be resummed + * 2/ after the channel was paused internally (as a result of + * a system suspend with power loss or not) + * 3/ after the channel was paused by a consummer, the system + * went through a system suspend (with power loss or not) + * and the consummer wants to resume the channel + * + * To cover all the above cases we set both CLRSUS and SETEN. + * + * In case 1/ setting SETEN while the channel is still enabled + * is harmless for the controller. + * + * In case 2/ the channel is disabled when calling this function + * and setting CLRSUS is harmless for the controller as the + * channel is disabled anyway. + * + * In case 3/ the channel is disabled/enabled if the system + * went though a suspend with power loss/or not and setting + * CLRSUS/SETEN is harmless for the controller as the channel + * is enabled/disabled anyway. + */ + + rz_dmac_ch_writel(channel, CHCTRL_CLRSUS | CHCTRL_SETEN, CHCTRL, 1); =20 - rz_dmac_ch_writel(channel, CHCTRL_CLRSUS, CHCTRL, 1); ret =3D read_poll_timeout_atomic(rz_dmac_ch_readl, val, - !(val & CHSTAT_SUS), 1, 1024, false, - channel, CHSTAT, 1); + ((val & (CHSTAT_SUS | CHSTAT_EN)) =3D=3D CHSTAT_EN), + 1, 1024, false, channel, CHSTAT, 1); =20 channel->status &=3D ~clear_bitmask; =20 @@ -994,6 +1037,16 @@ static int rz_dmac_device_resume(struct dma_chan *cha= n) return rz_dmac_device_resume_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED)= ); } =20 +static int rz_dmac_device_resume_internal(struct rz_dmac_chan *channel) +{ + lockdep_assert_held(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL))) + return 0; + + return rz_dmac_device_resume_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED_= INTERNAL)); +} + /* * -----------------------------------------------------------------------= ------ * IRQ handling @@ -1354,6 +1407,130 @@ static void rz_dmac_remove(struct platform_device *= pdev) pm_runtime_disable(&pdev->dev); } =20 +static int rz_dmac_suspend_prepare(struct device *dev) +{ + struct rz_dmac *dmac =3D dev_get_drvdata(dev); + + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + /* Wait for transfer completion, except in cyclic case. */ + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) + continue; + + if (rz_dmac_chan_is_enabled(channel)) + return -EAGAIN; + } + + return 0; +} + +static void rz_dmac_suspend_recover(struct rz_dmac *dmac) +{ + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) + continue; + + rz_dmac_device_resume_internal(channel); + } +} + +static int rz_dmac_suspend(struct device *dev) +{ + struct rz_dmac *dmac =3D dev_get_drvdata(dev); + int ret; + + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) + continue; + + ret =3D rz_dmac_device_pause_internal(channel); + if (ret) { + dev_err(dev, "Failed to suspend channel %s\n", + dma_chan_name(&channel->vc.chan)); + break; + } + + channel->pm_state.nxla =3D rz_dmac_ch_readl(channel, NXLA, 1); + } + + if (ret) { + rz_dmac_suspend_recover(dmac); + return ret; + } + + pm_runtime_put_sync(dmac->dev); + + ret =3D reset_control_assert(dmac->rstc); + if (ret) { + pm_runtime_resume_and_get(dmac->dev); + rz_dmac_suspend_recover(dmac); + } + + return ret; +} + +static int rz_dmac_resume(struct device *dev) +{ + struct rz_dmac *dmac =3D dev_get_drvdata(dev); + int errors =3D 0, ret; + + ret =3D reset_control_deassert(dmac->rstc); + if (ret) + return ret; + + ret =3D pm_runtime_resume_and_get(dmac->dev); + if (ret) { + reset_control_assert(dmac->rstc); + return ret; + } + + rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_0_7_COMMON_BASE + DCTRL); + rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_8_15_COMMON_BASE + DCTRL); + + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + rz_dmac_disable_hw(&dmac->channels[i]); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) + continue; + + rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid); + + rz_dmac_ch_writel(channel, channel->pm_state.nxla, NXLA, 1); + rz_dmac_ch_writel(channel, channel->chcfg, CHCFG, 1); + rz_dmac_ch_writel(channel, CHCTRL_SWRST, CHCTRL, 1); + rz_dmac_ch_writel(channel, channel->chctrl, CHCTRL, 1); + + ret =3D rz_dmac_device_resume_internal(channel); + if (ret) { + errors =3D ret; + dev_err(dev, "Failed to resume channel %s\n", + dma_chan_name(&channel->vc.chan)); + } + } + + return errors ? : ret; +} + +static const struct dev_pm_ops rz_dmac_pm_ops =3D { + .prepare =3D rz_dmac_suspend_prepare, + SYSTEM_SLEEP_PM_OPS(rz_dmac_suspend, rz_dmac_resume) +}; + static const struct rz_dmac_info rz_dmac_v2h_info =3D { .icu_register_dma_req =3D rzv2h_icu_register_dma_req, .default_dma_req_no =3D RZV2H_ICU_DMAC_REQ_NO_DEFAULT, @@ -1380,6 +1557,7 @@ static struct platform_driver rz_dmac_driver =3D { .driver =3D { .name =3D "rz-dmac", .of_match_table =3D of_rz_dmac_match, + .pm =3D pm_sleep_ptr(&rz_dmac_pm_ops), }, .probe =3D rz_dmac_probe, .remove =3D rz_dmac_remove, --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C98B35C19B for ; Sat, 11 Apr 2026 11:43:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907817; cv=none; b=eoyGSTihJw7XZus22QGImtoZC0Jt/CPCK1/BBD4xkut3ly2iqQpFB7txbmHNmA1KZ8eD7eSDeSIX7KbaXTSaXdLCvHAZYLvq7z/peGi83QCO3q+UxZiFc8ljwkcPjr2sJYrNIZZkTgqqKxSP7YF2VwErUsvWPx0kF8TZD4iGVio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907817; c=relaxed/simple; bh=FpCWJ1/MY4BN1v1ry6eYA3qXFhCvUdewz0pHLK1RDgE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K11NdSHlGgaAVaRUmeYZfMpvTqmODfVQQMM+Y7Y56j32hPQn40SfkGDLz6BeU7J/EOSbRjtUwHFrvMP43qNPv+HEFMe0c+ZYrqyY3FEtvHpfk+R9k6w1K4hbQcu4W/1QeqCq1aqSm1p36VCluLVdXALYzprXYGDnq1Z79XztCoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=FMT5r8zZ; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="FMT5r8zZ" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-43d04fc3bf2so1683682f8f.3 for ; Sat, 11 Apr 2026 04:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907815; x=1776512615; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=278h+cjHuGOS99RHJ8gfM7jOA+QjEIxjWNs1as6pY7E=; b=FMT5r8zZ0GqmJhNImWqWntYRSQ08KRs/R1J8N5YJFZTjn+Gxnrg1hZihd6x35QHH6/ SHkVjUPupmo8meiRrsdzhGQbx7eSk91bUKdJyjmb/lh+jO3j+SumlwN/KU0DyE9+/j8i lKligzr6mZWbk9UdW9f/ggQA+lLwq/tMpxH5PMR480uXF3OLwfFgNHkjKAZ2FkKhr6Oy AhO8vWrz5qPOrQ/+y1m2bxEhm7z/SK+eTvwq0siJGjkrskbgtGSKs67u9E/H31NxAHvw LIZfREL5VtlXnYigoxcekg5KLayyvO6CiF506yVKv7ukjbngUMun2q2xDUQ/+wPM8hiM J6UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907815; x=1776512615; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=278h+cjHuGOS99RHJ8gfM7jOA+QjEIxjWNs1as6pY7E=; b=MlyigR8U96jnoXiAk9wCRVeQlogjrooSSJQKgKd0gp7EcBedakqJYkGM3IzlJ/Yxt8 VBnb/X9klTAj7CKzTYmLAe3v9NYyJ4K29SjcXUPNVcDTpUdn4O70uCQv29wEguYWKaR+ G36ibLD1+UgI/9iHb5VgGph7B6NbgLuG3KfBWsy4TQdg5iraFo80CDvQ6+dTkvp02jkb JVLUoq+JNxCRYhmvMvRAa+5I60vY4DGYaE38UyiS9ciEBtReZl0HrGWtt8FCu1NhR8Mh bGL3UwyqfdFNo+Q3/28v+PurjO0L1Ws0WBeuPQv9bKodEEXlXWV4uH7QY50HQ0C5q6+p irBw== X-Forwarded-Encrypted: i=1; AJvYcCW/bHK5t5pMbcE8BG0pRurYa/Q7XZ37Lv0MjDXpexptLQgBYkccxG6thsj+Fe5uR35d3oPcHKKKpCaia8A=@vger.kernel.org X-Gm-Message-State: AOJu0YzRM7BIgC6PpBnRMckLCqRFjFGVOoIHFwEnwX8idfbBb+c2fgem Hcx0PHd0mJN0wf1S15AVJ6CFqozaqWRAZvF8wuYzhS059Wm/bvyEfmNW03ecYaiDyx4= X-Gm-Gg: AeBDieus8w7G19VT7cs/eJ9fsqmhHZQDV9xKeWiemkxlgpoNKrAOaiss0Va2ULjZ+tL GN9axvViLEdPDbqm9OskI9vl12AKrPHcWCq++jat7oopBDrgYR3IBPeoAnmn4l8Hmp+7I/9howB yyKKQriOebRhsQQZA8+eTyPy6MYpl5Kggd3vLeqZTo5H4a8aMfSrpfuohtiuYGGKXpULH9nL0Xw cI6zVN/8DpC0tHtgY5yyUkavFdHQxAaX6lSbAAsLbaSVHOE+vab7MBO3GAl2l55pHi8wNuFxPQ7 mV/CwZUqzqvlt+WLwpmjnYEnAS80GsmngShYB33/CwxyxM/FzfwuCGzcI4llaU98enoUDALpfLk 3qsWpI1bKKnc5/jeeGiMgp9RzyceqFnbHSnYJHDREaPXG4cZQyOuItgZDbLMT4kBTuKKgwesYut ojxOQuSd5+6NLOtszK26x55+kn9KtXOGgbn1wpfwL9WB6eBIBRscsR X-Received: by 2002:a05:6000:18a9:b0:43c:fde6:212e with SMTP id ffacd0b85a97d-43d642b8ebemr10073612f8f.24.1775907814878; Sat, 11 Apr 2026 04:43:34 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:33 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 15/17] ASoC: renesas: rz-ssi: Add pause support Date: Sat, 11 Apr 2026 14:43:01 +0300 Message-ID: <20260411114303.2814115-16-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add pause support as a preparatory step to switch to PCM dmaengine APIs. Acked-by: Mark Brown Signed-off-by: Claudiu Beznea --- Changes in v4: - collected tags Changes in v3: - none, this patch is new sound/soc/renesas/rz-ssi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sound/soc/renesas/rz-ssi.c b/sound/soc/renesas/rz-ssi.c index 71e434cfe07b..d4e1dded3a9c 100644 --- a/sound/soc/renesas/rz-ssi.c +++ b/sound/soc/renesas/rz-ssi.c @@ -847,6 +847,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream = *substream, int cmd, =20 switch (cmd) { case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: ret =3D rz_ssi_trigger_resume(ssi, strm); if (ret) return ret; @@ -888,6 +889,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream = *substream, int cmd, break; =20 case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: rz_ssi_stop(ssi, strm); break; =20 @@ -1054,7 +1056,8 @@ static const struct snd_pcm_hardware rz_ssi_pcm_hardw= are =3D { .info =3D SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | - SNDRV_PCM_INFO_RESUME, + SNDRV_PCM_INFO_RESUME | + SNDRV_PCM_INFO_PAUSE, .buffer_bytes_max =3D PREALLOC_BUFFER, .period_bytes_min =3D 32, .period_bytes_max =3D 8192, --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E398735E92D for ; Sat, 11 Apr 2026 11:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907821; cv=none; b=Xubk5qEIAnS4b88ilsWsUug3dq7nAzjEyvccJ60wnCITMMGNDOoqq1Vtn5/Qn6zb+MUxZ+sO9YSZcTH871vlLisNEPUJC+7LFKpcRpijB4NWFE7j7RL3KqiC7+TE+c9PE6gYsWGOJs9LYjNQpyTZVtc11gHHRpkCyzhJMUXE5Aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907821; c=relaxed/simple; bh=+h6VU5FYecBxv6kxKYM8BY6CpPANPNinM2oEi+/qg9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j+imqSDyO9FIXFpBUXp65wImFJ+aT7xulDvQpkHKYniGDgXBC4aXu/16ekVfe3Kz4NOEX7VX243HPw/tb7WtCNgVUnP70eGNbyb2rOPtwb4LRzCmKHFbt7hZyrbECX1rHkH69s4Oo2u/F5P/tjLNrqEDxZgI5H8jCeYz7HIoklQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=QkEKQQtL; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="QkEKQQtL" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-43cfce3a195so1795475f8f.2 for ; Sat, 11 Apr 2026 04:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907817; x=1776512617; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z/q7km/7zwC/5p0KrYii2cWv5WSy78Ho7mmg7M4ADTA=; b=QkEKQQtLWsTnR7lvhsbVZKfiasYfrla7keKVXy6UKHW/M3ScBMEemqFiXu8JCvJw3m aNsXUavl2a9ez/mlQgFmTX70z4YAGw+oJ1Hap7gt9/gw6csa7JFwXbmB/viX3LPhMGV/ +t2rxRBB5MQw3Aoi3l5Jc572RrMurGleF5z02NbZ1WdSZXcIY+jKqHnNZH4BknA7yLUv No5mX5vpB1zmQxS9WaaZfTaBNMfe3rDa6Q/Aq+vmon1J1UlGoTSPeYXaFIzO8UU3q1st V13nGwI8nf1J0Xmxoq+P9IxBSKOoJf3o1d3N8CAkj64WFR16LwRpAnBL9s9Z5VwWxyz+ NHyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907817; x=1776512617; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Z/q7km/7zwC/5p0KrYii2cWv5WSy78Ho7mmg7M4ADTA=; b=k+UWQ3gHNA8fnX2uDYMSyWVxYtO35P+AvklHm0Iw0d/mqlQ4UNhkmZzWl/57F8cXFt iDqvYYzkfGYUhEYrcgI+mNgZlLBLpQIeIm2PhnqJYVxKy79EEBYdji4GgVKsGKFEDCPB Ee0GqyHsmn+g9drqKS3HSGfaJvasP7PLUL00cpz9CgZBxJ65HHk3zuQ1wEc1bzGBRe+e b7eYqEfNYWeT/Oa48+gXogIJHtrQ3OKstXfTU5POYOAHCqFsejEPixumqkYJZpvncJZc BqArIAuoDZswTGFEJNkHRo7c0nvJgCzh/cq5ZlnXPUycPBJ4LAuiFTgQzA3FHxqWqcyo dDAw== X-Forwarded-Encrypted: i=1; AJvYcCUMRPMTukO5iUFLLlqvdu78Xe12/EBNXq/ONtoBb7XJnKpbCfjXkPFAYtPMX6jKO8V+ha3xcTfrMomSdlo=@vger.kernel.org X-Gm-Message-State: AOJu0YxeApvkwNbSMLKcJtk6UTqA4De4Tyq7Td3ZfoGlgLN9+txODLmG wlh0uWMg7OBaVW0fFb1NfsbWqYQifbpvLgTAPcdLVL/dKsOqXDfZel/dK9bIxKbDHzA= X-Gm-Gg: AeBDietoOVSpr5djrP9GLsercLaIH9msISD/1J05lX7p2Pg5J5ori/jEwTKAXKhh3N2 g8X3IqAnkvLYUwo1ASenDNJp8msIJ6lek5Gfbq3mB/eQ4LLjupAhZdtf1VREYbi+LhywsEehLV3 ZuIKAh7bBR0n98tnxg41YXbQdyN4Dcp6dHHA0N1MUxevGa2P0IA3j/WIHV0yQ0Trd/kVBwyEa0n eRlT4PXdvqF+cuLpLwyb1cwS8uySV1rvZDFAxffo6XKmweMciyR7umzX74H0FJ9hoj0H/JnJ0Yd dHjv6hqapZweEzun9ECjVE0rw1Q9UDPsNB9NS/RvqiVfnjOeT39fJh/04ADJ8hAFYqcq4U4arHo ehNvvjGiY0/lcsoxeFkMLU3CHtlIdVq7dNnCzqCxnkQHPM78nEu4GIWnOgcKn7P/wwN2Ekq3SnX DgosY3YNEDzhTqxezDO5ORMZa2i3BsEVcZVEOS/BkzVuz9aEJF2tnj X-Received: by 2002:adf:f7d0:0:b0:43d:6a20:117c with SMTP id ffacd0b85a97d-43d6a2011abmr2640219f8f.17.1775907817068; Sat, 11 Apr 2026 04:43:37 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:36 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 16/17] ASoC: renesas: rz-ssi: Use generic PCM dmaengine APIs Date: Sat, 11 Apr 2026 14:43:02 +0300 Message-ID: <20260411114303.2814115-17-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea On Renesas RZ/G2L and RZ/G3S SoCs (where this was tested), captured audio files occasionally contained random spikes when viewed with a tool such as Audacity. These spikes were also audible as popping noises. Using cyclic DMA resolves this issue. The driver was reworked to use the existing support provided by the generic PCM dmaengine APIs. In addition to eliminating the random spikes, the following issues were addressed: - blank periods at the beginning of recorded files, which occurred intermittently, are no longer present - no overruns or underruns were observed when continuously recording short audio files (e.g. 5 seconds long) in a loop - concurrency issues in the SSI driver when enqueuing DMA requests were eliminated; previously, DMA requests could be prepared and submitted both from the DMA completion callback and the interrupt handler, which led to crashes after several hours of testing - the SSI driver logic is simplified - the number of generated interrupts is reduced by approximately 250% In the SSI platform driver probe function, the following changes were made: - the driver-specific DMA configuration was removed in favor of the generic PCM dmaengine APIs. As a result, explicit cleanup goto labels are no longer required and the driver remove callback was dropped, since resource management is now handled via devres helpers - special handling was added for IP variants operating in half-duplex mode, where the DMA channel name in the device tree is "rt"; this DMA channel name is taken into account and passed to the generic PCM dmaengine configuration data All code previously responsible for preparing and completing DMA transfers was removed, as this functionality is now handled entirely by the generic PCM dmaengine APIs. Since DMA channels must be paused and resumed during recovery paths (overruns and underruns reported by the hardware), the DMA channel references are stored in rz_ssi_hw_params(). The logic in rz_ssi_is_dma_enabled() was updated to reflect that the driver no longer manages DMA transfers directly. To avoid software reported underruns (e.g. when running aplay during consecutive suspend/resume cycles, or when the CPU is nearly 100% loaded), rz_ssi_pcm_hardware.buffer_bytes_max was increased to 192K. At the same time, rz_ssi_pcm_hardware.period_bytes_max was set to 48K to reduce interrupt overhead. Finally, rz_ssi_stream_is_play() was removed, as it had only a single remaining user after this rework, and its logic was inlined at the call site. Acked-by: Mark Brown Signed-off-by: Claudiu Beznea --- Changes in v4: - collected tags - in rz_ssi_interrupt() checked the dma channel is valid before calling dmaengine_pause(); at the same time initialized the rz_ssi->dmas[] with NULL in case the DMA is not available in rz_ssi_dai_hw_params() - set rz_ssi_dmaengine_pcm_conf.prealloc_buffer_size - dinamically allocate the object of type snd_dmaengine_pcm_config passed to devm_snd_dmaengine_pcm_register() to avoid issues when the driver is instantiated for more than one HW instance - I considered keeping the ack was still OK; Mark, please let me know if you consider otherwise Changes in v3: - s/CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM/SND_SOC_GENERIC_DMAENGINE_PCM in Kconfig - in rz_ssi_clk_setup(): drop the update of dma_dai->maxburst - in rz_ssi_interrupt(): pause the DMA channels in case of HW over/underruns - add different open APIs for rz_ssi_soc_component_pio and rz_ssi_soc_component_dma=20 - set rz_ssi_pcm_hardware to rz_ssi_dmaengine_pcm_conf.pcm_hardware and updated the buffer_bytes_max to avoid underruns detected by applications just before suspending; along with it updated period_bytes_max for lower interrupt overhead; updated the patch description for this; with it updated the snd_pcm_set_managed_buffer_all() arguments to use the rz_ssi_pcm_hardware - added back rz_ssi_soc_component_pio.pcm_new instantiation as the PIO mode was broken w/o it - use specific rz_ssi_soc_component_dma.open implementation for DMA - updated rz_ssi_dmaengine_pcm_conf.chan_names[].{tx, rx} either if there is about full or half duplex instantiation and move the flags variable local to the code block that uses it - check devm_snd_dmaengine_pcm_register() for defer errors Changes in v2: - fixed typos in patch description - select CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM for rz-ssi driver - in rz_ssi_dai_hw_params() check if DMA is enabled before calling snd_dmaengine_pcm_get_chan() to avoid failures for PIO mode - do not drop rz_ssi_pcm_pointer() and rz_ssi_pcm_new() as these are necessary for PIO mode - added 2 struct snd_soc_component_driver, one for PIO mode, one for DMA and updated probe() to register the proper snd_soc_component_driver based on the working mode sound/soc/renesas/Kconfig | 1 + sound/soc/renesas/rz-ssi.c | 383 ++++++++++++------------------------- 2 files changed, 125 insertions(+), 259 deletions(-) diff --git a/sound/soc/renesas/Kconfig b/sound/soc/renesas/Kconfig index 11c2027c88a7..6520217e7407 100644 --- a/sound/soc/renesas/Kconfig +++ b/sound/soc/renesas/Kconfig @@ -56,6 +56,7 @@ config SND_SOC_MSIOF config SND_SOC_RZ tristate "RZ/G2L series SSIF-2 support" depends on ARCH_RZG2L || COMPILE_TEST + select SND_SOC_GENERIC_DMAENGINE_PCM help This option enables RZ/G2L SSIF-2 sound support. =20 diff --git a/sound/soc/renesas/rz-ssi.c b/sound/soc/renesas/rz-ssi.c index d4e1dded3a9c..b1d016bcca86 100644 --- a/sound/soc/renesas/rz-ssi.c +++ b/sound/soc/renesas/rz-ssi.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include =20 @@ -87,8 +89,6 @@ struct rz_ssi_stream { struct rz_ssi_priv *priv; struct snd_pcm_substream *substream; int fifo_sample_size; /* sample capacity of SSI FIFO */ - int dma_buffer_pos; /* The address for the next DMA descriptor */ - int completed_dma_buf_pos; /* The address of the last completed DMA descr= iptor. */ int period_counter; /* for keeping track of periods transferred */ int buffer_pos; /* current frame position in the buffer */ int running; /* 0=3Dstopped, 1=3Drunning */ @@ -96,8 +96,6 @@ struct rz_ssi_stream { int uerr_num; int oerr_num; =20 - struct dma_chan *dma_ch; - int (*transfer)(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm); }; =20 @@ -108,7 +106,6 @@ struct rz_ssi_priv { struct clk *sfr_clk; struct clk *clk; =20 - phys_addr_t phys; int irq_int; int irq_tx; int irq_rx; @@ -148,9 +145,10 @@ struct rz_ssi_priv { unsigned int sample_width; unsigned int sample_bits; } hw_params_cache; -}; =20 -static void rz_ssi_dma_complete(void *data); + struct snd_dmaengine_dai_dma_data dma_dais[SNDRV_PCM_STREAM_LAST + 1]; + struct dma_chan *dmas[SNDRV_PCM_STREAM_LAST + 1]; +}; =20 static void rz_ssi_reg_writel(struct rz_ssi_priv *priv, uint reg, u32 data) { @@ -172,11 +170,6 @@ static void rz_ssi_reg_mask_setl(struct rz_ssi_priv *p= riv, uint reg, writel(val, (priv->base + reg)); } =20 -static inline bool rz_ssi_stream_is_play(struct snd_pcm_substream *substre= am) -{ - return substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK; -} - static inline struct rz_ssi_stream * rz_ssi_stream_get(struct rz_ssi_priv *ssi, struct snd_pcm_substream *subst= ream) { @@ -185,7 +178,7 @@ rz_ssi_stream_get(struct rz_ssi_priv *ssi, struct snd_p= cm_substream *substream) =20 static inline bool rz_ssi_is_dma_enabled(struct rz_ssi_priv *ssi) { - return (ssi->playback.dma_ch && (ssi->dma_rt || ssi->capture.dma_ch)); + return !ssi->playback.transfer && !ssi->capture.transfer; } =20 static void rz_ssi_set_substream(struct rz_ssi_stream *strm, @@ -215,8 +208,6 @@ static void rz_ssi_stream_init(struct rz_ssi_stream *st= rm, struct snd_pcm_substream *substream) { rz_ssi_set_substream(strm, substream); - strm->dma_buffer_pos =3D 0; - strm->completed_dma_buf_pos =3D 0; strm->period_counter =3D 0; strm->buffer_pos =3D 0; =20 @@ -242,12 +233,13 @@ static void rz_ssi_stream_quit(struct rz_ssi_priv *ss= i, dev_info(dev, "underrun =3D %d\n", strm->uerr_num); } =20 -static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, unsigned int rate, - unsigned int channels) +static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, struct snd_pcm_substr= eam *substream, + unsigned int rate, unsigned int channels) { static u8 ckdv[] =3D { 1, 2, 4, 8, 16, 32, 64, 128, 6, 12, 24, 48, 96 = }; unsigned int channel_bits =3D 32; /* System Word Length */ unsigned long bclk_rate =3D rate * channels * channel_bits; + struct snd_dmaengine_dai_dma_data *dma_dai; unsigned int div; unsigned int i; u32 ssicr =3D 0; @@ -290,6 +282,8 @@ static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, un= signed int rate, return -EINVAL; } =20 + dma_dai =3D &ssi->dma_dais[substream->stream]; + /* * DWL: Data Word Length =3D {16, 24, 32} bits * SWL: System Word Length =3D 32 bits @@ -298,12 +292,15 @@ static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, = unsigned int rate, switch (ssi->hw_params_cache.sample_width) { case 16: ssicr |=3D SSICR_DWL(1); + dma_dai->addr_width =3D DMA_SLAVE_BUSWIDTH_2_BYTES; break; case 24: ssicr |=3D SSICR_DWL(5) | SSICR_PDTA; + dma_dai->addr_width =3D DMA_SLAVE_BUSWIDTH_4_BYTES; break; case 32: ssicr |=3D SSICR_DWL(6); + dma_dai->addr_width =3D DMA_SLAVE_BUSWIDTH_4_BYTES; break; default: dev_err(ssi->dev, "Not support %u data width", @@ -344,7 +341,7 @@ static void rz_ssi_set_idle(struct rz_ssi_priv *ssi) =20 static int rz_ssi_start(struct rz_ssi_priv *ssi, struct rz_ssi_stream *str= m) { - bool is_play =3D rz_ssi_stream_is_play(strm->substream); + bool is_play =3D strm->substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK; bool is_full_duplex; u32 ssicr, ssifcr; =20 @@ -423,14 +420,6 @@ static int rz_ssi_stop(struct rz_ssi_priv *ssi, struct= rz_ssi_stream *strm) /* Disable TX/RX */ rz_ssi_reg_mask_setl(ssi, SSICR, SSICR_TEN | SSICR_REN, 0); =20 - /* Cancel all remaining DMA transactions */ - if (rz_ssi_is_dma_enabled(ssi)) { - if (ssi->playback.dma_ch) - dmaengine_terminate_async(ssi->playback.dma_ch); - if (ssi->capture.dma_ch) - dmaengine_terminate_async(ssi->capture.dma_ch); - } - rz_ssi_set_idle(ssi); =20 return 0; @@ -458,10 +447,6 @@ static void rz_ssi_pointer_update(struct rz_ssi_stream= *strm, int frames) snd_pcm_period_elapsed(strm->substream); strm->period_counter =3D current_period; } - - strm->completed_dma_buf_pos +=3D runtime->period_size; - if (strm->completed_dma_buf_pos >=3D runtime->buffer_size) - strm->completed_dma_buf_pos =3D 0; } =20 static int rz_ssi_pio_recv(struct rz_ssi_priv *ssi, struct rz_ssi_stream *= strm) @@ -606,12 +591,6 @@ static irqreturn_t rz_ssi_interrupt(int irq, void *dat= a) if (irq =3D=3D ssi->irq_int) { /* error or idle */ bool is_stopped =3D !!(ssisr & (SSISR_RUIRQ | SSISR_ROIRQ | SSISR_TUIRQ | SSISR_TOIRQ)); - int i, count; - - if (rz_ssi_is_dma_enabled(ssi)) - count =3D 4; - else - count =3D 1; =20 if (ssi->capture.substream && is_stopped) { if (ssisr & SSISR_RUIRQ) @@ -631,18 +610,31 @@ static irqreturn_t rz_ssi_interrupt(int irq, void *da= ta) rz_ssi_stop(ssi, strm_playback); } =20 + if (!rz_ssi_is_stream_running(&ssi->playback) && + !rz_ssi_is_stream_running(&ssi->capture) && + rz_ssi_is_dma_enabled(ssi)) { + if (ssi->dmas[SNDRV_PCM_STREAM_PLAYBACK]) + dmaengine_pause(ssi->dmas[SNDRV_PCM_STREAM_PLAYBACK]); + if (ssi->dmas[SNDRV_PCM_STREAM_CAPTURE]) + dmaengine_pause(ssi->dmas[SNDRV_PCM_STREAM_CAPTURE]); + } + /* Clear all flags */ rz_ssi_reg_mask_setl(ssi, SSISR, SSISR_TOIRQ | SSISR_TUIRQ | SSISR_ROIRQ | SSISR_RUIRQ, 0); =20 /* Add/remove more data */ if (ssi->capture.substream && is_stopped) { - for (i =3D 0; i < count; i++) + if (rz_ssi_is_dma_enabled(ssi)) + dmaengine_resume(ssi->dmas[SNDRV_PCM_STREAM_CAPTURE]); + else strm_capture->transfer(ssi, strm_capture); } =20 if (ssi->playback.substream && is_stopped) { - for (i =3D 0; i < count; i++) + if (rz_ssi_is_dma_enabled(ssi)) + dmaengine_resume(ssi->dmas[SNDRV_PCM_STREAM_PLAYBACK]); + else strm_playback->transfer(ssi, strm_playback); } =20 @@ -679,153 +671,11 @@ static irqreturn_t rz_ssi_interrupt(int irq, void *d= ata) return IRQ_HANDLED; } =20 -static int rz_ssi_dma_slave_config(struct rz_ssi_priv *ssi, - struct dma_chan *dma_ch, bool is_play) -{ - struct dma_slave_config cfg; - - memset(&cfg, 0, sizeof(cfg)); - - cfg.direction =3D is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; - cfg.dst_addr =3D ssi->phys + SSIFTDR; - cfg.src_addr =3D ssi->phys + SSIFRDR; - if (ssi->hw_params_cache.sample_width =3D=3D 16) { - cfg.src_addr_width =3D DMA_SLAVE_BUSWIDTH_2_BYTES; - cfg.dst_addr_width =3D DMA_SLAVE_BUSWIDTH_2_BYTES; - } else { - cfg.src_addr_width =3D DMA_SLAVE_BUSWIDTH_4_BYTES; - cfg.dst_addr_width =3D DMA_SLAVE_BUSWIDTH_4_BYTES; - } - - return dmaengine_slave_config(dma_ch, &cfg); -} - -static int rz_ssi_dma_transfer(struct rz_ssi_priv *ssi, - struct rz_ssi_stream *strm) -{ - struct snd_pcm_substream *substream =3D strm->substream; - struct dma_async_tx_descriptor *desc; - struct snd_pcm_runtime *runtime; - enum dma_transfer_direction dir; - u32 dma_paddr, dma_size; - int amount; - - if (!rz_ssi_stream_is_valid(ssi, strm)) - return -EINVAL; - - runtime =3D substream->runtime; - if (runtime->state =3D=3D SNDRV_PCM_STATE_DRAINING) - /* - * Stream is ending, so do not queue up any more DMA - * transfers otherwise we play partial sound clips - * because we can't shut off the DMA quick enough. - */ - return 0; - - dir =3D rz_ssi_stream_is_play(substream) ? DMA_MEM_TO_DEV : DMA_DEV_TO_ME= M; - - /* Always transfer 1 period */ - amount =3D runtime->period_size; - - /* DMA physical address and size */ - dma_paddr =3D runtime->dma_addr + frames_to_bytes(runtime, - strm->dma_buffer_pos); - dma_size =3D frames_to_bytes(runtime, amount); - desc =3D dmaengine_prep_slave_single(strm->dma_ch, dma_paddr, dma_size, - dir, - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); - if (!desc) { - dev_err(ssi->dev, "dmaengine_prep_slave_single() fail\n"); - return -ENOMEM; - } - - desc->callback =3D rz_ssi_dma_complete; - desc->callback_param =3D strm; - - if (dmaengine_submit(desc) < 0) { - dev_err(ssi->dev, "dmaengine_submit() fail\n"); - return -EIO; - } - - /* Update DMA pointer */ - strm->dma_buffer_pos +=3D amount; - if (strm->dma_buffer_pos >=3D runtime->buffer_size) - strm->dma_buffer_pos =3D 0; - - /* Start DMA */ - dma_async_issue_pending(strm->dma_ch); - - return 0; -} - -static void rz_ssi_dma_complete(void *data) -{ - struct rz_ssi_stream *strm =3D (struct rz_ssi_stream *)data; - - if (!strm->running || !strm->substream || !strm->substream->runtime) - return; - - /* Note that next DMA transaction has probably already started */ - rz_ssi_pointer_update(strm, strm->substream->runtime->period_size); - - /* Queue up another DMA transaction */ - rz_ssi_dma_transfer(strm->priv, strm); -} - -static void rz_ssi_release_dma_channels(struct rz_ssi_priv *ssi) -{ - if (ssi->playback.dma_ch) { - dma_release_channel(ssi->playback.dma_ch); - ssi->playback.dma_ch =3D NULL; - if (ssi->dma_rt) - ssi->dma_rt =3D false; - } - - if (ssi->capture.dma_ch) { - dma_release_channel(ssi->capture.dma_ch); - ssi->capture.dma_ch =3D NULL; - } -} - -static int rz_ssi_dma_request(struct rz_ssi_priv *ssi, struct device *dev) -{ - ssi->playback.dma_ch =3D dma_request_chan(dev, "tx"); - if (IS_ERR(ssi->playback.dma_ch)) - ssi->playback.dma_ch =3D NULL; - - ssi->capture.dma_ch =3D dma_request_chan(dev, "rx"); - if (IS_ERR(ssi->capture.dma_ch)) - ssi->capture.dma_ch =3D NULL; - - if (!ssi->playback.dma_ch && !ssi->capture.dma_ch) { - ssi->playback.dma_ch =3D dma_request_chan(dev, "rt"); - if (IS_ERR(ssi->playback.dma_ch)) { - ssi->playback.dma_ch =3D NULL; - goto no_dma; - } - - ssi->dma_rt =3D true; - } - - if (!rz_ssi_is_dma_enabled(ssi)) - goto no_dma; - - return 0; - -no_dma: - rz_ssi_release_dma_channels(ssi); - - return -ENODEV; -} - static int rz_ssi_trigger_resume(struct rz_ssi_priv *ssi, struct rz_ssi_st= ream *strm) { struct snd_pcm_substream *substream =3D strm->substream; - struct snd_pcm_runtime *runtime =3D substream->runtime; int ret; =20 - strm->dma_buffer_pos =3D strm->completed_dma_buf_pos + runtime->period_si= ze; - if (rz_ssi_is_stream_running(&ssi->playback) || rz_ssi_is_stream_running(&ssi->capture)) return 0; @@ -834,7 +684,7 @@ static int rz_ssi_trigger_resume(struct rz_ssi_priv *ss= i, struct rz_ssi_stream * if (ret) return ret; =20 - return rz_ssi_clk_setup(ssi, ssi->hw_params_cache.rate, + return rz_ssi_clk_setup(ssi, substream, ssi->hw_params_cache.rate, ssi->hw_params_cache.channels); } =20 @@ -843,7 +693,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream = *substream, int cmd, { struct rz_ssi_priv *ssi =3D snd_soc_dai_get_drvdata(dai); struct rz_ssi_stream *strm =3D rz_ssi_stream_get(ssi, substream); - int ret =3D 0, i, num_transfer =3D 1; + int ret =3D 0; =20 switch (cmd) { case SNDRV_PCM_TRIGGER_RESUME: @@ -858,28 +708,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream= *substream, int cmd, if (cmd =3D=3D SNDRV_PCM_TRIGGER_START) rz_ssi_stream_init(strm, substream); =20 - if (rz_ssi_is_dma_enabled(ssi)) { - bool is_playback =3D rz_ssi_stream_is_play(substream); - - if (ssi->dma_rt) - ret =3D rz_ssi_dma_slave_config(ssi, ssi->playback.dma_ch, - is_playback); - else - ret =3D rz_ssi_dma_slave_config(ssi, strm->dma_ch, - is_playback); - - /* Fallback to pio */ - if (ret < 0) { - ssi->playback.transfer =3D rz_ssi_pio_send; - ssi->capture.transfer =3D rz_ssi_pio_recv; - rz_ssi_release_dma_channels(ssi); - } else { - /* For DMA, queue up multiple DMA descriptors */ - num_transfer =3D 4; - } - } - - for (i =3D 0; i < num_transfer; i++) { + if (!rz_ssi_is_dma_enabled(ssi)) { ret =3D strm->transfer(ssi, strm); if (ret) return ret; @@ -1026,6 +855,12 @@ static int rz_ssi_dai_hw_params(struct snd_pcm_substr= eam *substream, return -EINVAL; } =20 + /* Save the DMA channels for recovery. */ + if (rz_ssi_is_dma_enabled(ssi)) + ssi->dmas[substream->stream] =3D snd_dmaengine_pcm_get_chan(substream); + else + ssi->dmas[substream->stream] =3D NULL; + if (rz_ssi_is_stream_running(&ssi->playback) || rz_ssi_is_stream_running(&ssi->capture)) { if (rz_ssi_is_valid_hw_params(ssi, rate, channels, sample_width, sample_= bits)) @@ -1041,10 +876,21 @@ static int rz_ssi_dai_hw_params(struct snd_pcm_subst= ream *substream, if (ret) return ret; =20 - return rz_ssi_clk_setup(ssi, rate, channels); + return rz_ssi_clk_setup(ssi, substream, rate, channels); +} + +static int rz_ssi_dai_probe(struct snd_soc_dai *dai) +{ + struct rz_ssi_priv *ssi =3D snd_soc_dai_get_drvdata(dai); + + snd_soc_dai_init_dma_data(dai, &ssi->dma_dais[SNDRV_PCM_STREAM_PLAYBACK], + &ssi->dma_dais[SNDRV_PCM_STREAM_CAPTURE]); + + return 0; } =20 static const struct snd_soc_dai_ops rz_ssi_dai_ops =3D { + .probe =3D rz_ssi_dai_probe, .startup =3D rz_ssi_startup, .shutdown =3D rz_ssi_shutdown, .trigger =3D rz_ssi_dai_trigger, @@ -1058,9 +904,9 @@ static const struct snd_pcm_hardware rz_ssi_pcm_hardwa= re =3D { SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_PAUSE, - .buffer_bytes_max =3D PREALLOC_BUFFER, + .buffer_bytes_max =3D 192 * 1024, .period_bytes_min =3D 32, - .period_bytes_max =3D 8192, + .period_bytes_max =3D 48 * 1024, .channels_min =3D SSI_CHAN_MIN, .channels_max =3D SSI_CHAN_MAX, .periods_min =3D 1, @@ -1068,8 +914,8 @@ static const struct snd_pcm_hardware rz_ssi_pcm_hardwa= re =3D { .fifo_size =3D 32 * 2, }; =20 -static int rz_ssi_pcm_open(struct snd_soc_component *component, - struct snd_pcm_substream *substream) +static int rz_ssi_pcm_open_pio(struct snd_soc_component *component, + struct snd_pcm_substream *substream) { snd_soc_set_runtime_hwparams(substream, &rz_ssi_pcm_hardware); =20 @@ -1077,6 +923,13 @@ static int rz_ssi_pcm_open(struct snd_soc_component *= component, SNDRV_PCM_HW_PARAM_PERIODS); } =20 +static int rz_ssi_pcm_open_dma(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + return snd_pcm_hw_constraint_integer(substream->runtime, + SNDRV_PCM_HW_PARAM_PERIODS); +} + static snd_pcm_uframes_t rz_ssi_pcm_pointer(struct snd_soc_component *comp= onent, struct snd_pcm_substream *substream) { @@ -1093,7 +946,8 @@ static int rz_ssi_pcm_new(struct snd_soc_component *co= mponent, { snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV, rtd->card->snd_card->dev, - PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); + rz_ssi_pcm_hardware.buffer_bytes_max, + rz_ssi_pcm_hardware.buffer_bytes_max); return 0; } =20 @@ -1116,16 +970,30 @@ static struct snd_soc_dai_driver rz_ssi_soc_dai[] = =3D { }, }; =20 -static const struct snd_soc_component_driver rz_ssi_soc_component =3D { +static const struct snd_soc_component_driver rz_ssi_soc_component_pio =3D { .name =3D "rz-ssi", - .open =3D rz_ssi_pcm_open, + .open =3D rz_ssi_pcm_open_pio, .pointer =3D rz_ssi_pcm_pointer, .pcm_new =3D rz_ssi_pcm_new, .legacy_dai_naming =3D 1, }; =20 +static const struct snd_soc_component_driver rz_ssi_soc_component_dma =3D { + .name =3D "rz-ssi", + .open =3D rz_ssi_pcm_open_dma, + .legacy_dai_naming =3D 1, +}; + +static const struct snd_dmaengine_pcm_config rz_ssi_dmaengine_pcm_conf =3D= { + .pcm_hardware =3D &rz_ssi_pcm_hardware, + .prealloc_buffer_size =3D 192 * 1024, + .prepare_slave_config =3D snd_dmaengine_pcm_prepare_slave_config, +}; + static int rz_ssi_probe(struct platform_device *pdev) { + const struct snd_soc_component_driver *component_driver; + struct device_node *np =3D pdev->dev.of_node; struct device *dev =3D &pdev->dev; struct rz_ssi_priv *ssi; struct clk *audio_clk; @@ -1141,7 +1009,6 @@ static int rz_ssi_probe(struct platform_device *pdev) if (IS_ERR(ssi->base)) return PTR_ERR(ssi->base); =20 - ssi->phys =3D res->start; ssi->clk =3D devm_clk_get(dev, "ssi"); if (IS_ERR(ssi->clk)) return PTR_ERR(ssi->clk); @@ -1165,16 +1032,43 @@ static int rz_ssi_probe(struct platform_device *pde= v) =20 ssi->audio_mck =3D ssi->audio_clk_1 ? ssi->audio_clk_1 : ssi->audio_clk_2; =20 - /* Detect DMA support */ - ret =3D rz_ssi_dma_request(ssi, dev); - if (ret < 0) { + ssi->dma_dais[SNDRV_PCM_STREAM_PLAYBACK].addr =3D (dma_addr_t)res->start = + SSIFTDR; + ssi->dma_dais[SNDRV_PCM_STREAM_CAPTURE].addr =3D (dma_addr_t)res->start = + SSIFRDR; + + if (of_property_present(np, "dma-names")) { + struct snd_dmaengine_pcm_config *config; + unsigned int flags =3D 0; + + config =3D devm_kzalloc(dev, sizeof(*config), GFP_KERNEL); + if (!config) + return -ENOMEM; + + config->pcm_hardware =3D rz_ssi_dmaengine_pcm_conf.pcm_hardware; + config->prealloc_buffer_size =3D rz_ssi_dmaengine_pcm_conf.prealloc_buff= er_size; + config->prepare_slave_config =3D rz_ssi_dmaengine_pcm_conf.prepare_slave= _config; + + if (of_property_match_string(np, "dma-names", "rt") =3D=3D 0) { + flags =3D SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX; + config->chan_names[SNDRV_PCM_STREAM_PLAYBACK] =3D "rt"; + } else { + config->chan_names[SNDRV_PCM_STREAM_PLAYBACK] =3D "tx"; + config->chan_names[SNDRV_PCM_STREAM_CAPTURE] =3D "rx"; + } + ret =3D devm_snd_dmaengine_pcm_register(&pdev->dev, config, flags); + } else { + ret =3D -ENODEV; + } + + if (ret =3D=3D -EPROBE_DEFER) { + return ret; + } else if (ret) { dev_warn(dev, "DMA not available, using PIO\n"); ssi->playback.transfer =3D rz_ssi_pio_send; ssi->capture.transfer =3D rz_ssi_pio_recv; + component_driver =3D &rz_ssi_soc_component_pio; } else { - dev_info(dev, "DMA enabled"); - ssi->playback.transfer =3D rz_ssi_dma_transfer; - ssi->capture.transfer =3D rz_ssi_dma_transfer; + dev_info(dev, "DMA enabled\n"); + component_driver =3D &rz_ssi_soc_component_dma; } =20 ssi->playback.priv =3D ssi; @@ -1185,17 +1079,13 @@ static int rz_ssi_probe(struct platform_device *pde= v) =20 /* Error Interrupt */ ssi->irq_int =3D platform_get_irq_byname(pdev, "int_req"); - if (ssi->irq_int < 0) { - ret =3D ssi->irq_int; - goto err_release_dma_chs; - } + if (ssi->irq_int < 0) + return ssi->irq_int; =20 ret =3D devm_request_irq(dev, ssi->irq_int, rz_ssi_interrupt, 0, dev_name(dev), ssi); - if (ret < 0) { - dev_err_probe(dev, ret, "irq request error (int_req)\n"); - goto err_release_dma_chs; - } + if (ret < 0) + return dev_err_probe(dev, ret, "irq request error (int_req)\n"); =20 if (!rz_ssi_is_dma_enabled(ssi)) { /* Tx and Rx interrupts (pio only) */ @@ -1236,43 +1126,19 @@ static int rz_ssi_probe(struct platform_device *pde= v) } =20 ssi->rstc =3D devm_reset_control_get_exclusive(dev, NULL); - if (IS_ERR(ssi->rstc)) { - ret =3D PTR_ERR(ssi->rstc); - goto err_release_dma_chs; - } + if (IS_ERR(ssi->rstc)) + return dev_err_probe(dev, PTR_ERR(ssi->rstc), "Failed to get reset\n"); =20 /* Default 0 for power saving. Can be overridden via sysfs. */ pm_runtime_set_autosuspend_delay(dev, 0); pm_runtime_use_autosuspend(dev); ret =3D devm_pm_runtime_enable(dev); - if (ret < 0) { - dev_err(dev, "Failed to enable runtime PM!\n"); - goto err_release_dma_chs; - } - - ret =3D devm_snd_soc_register_component(dev, &rz_ssi_soc_component, - rz_ssi_soc_dai, - ARRAY_SIZE(rz_ssi_soc_dai)); - if (ret < 0) { - dev_err(dev, "failed to register snd component\n"); - goto err_release_dma_chs; - } - - return 0; - -err_release_dma_chs: - rz_ssi_release_dma_channels(ssi); - - return ret; -} - -static void rz_ssi_remove(struct platform_device *pdev) -{ - struct rz_ssi_priv *ssi =3D dev_get_drvdata(&pdev->dev); - - rz_ssi_release_dma_channels(ssi); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to enable runtime PM!\n"); =20 - reset_control_assert(ssi->rstc); + return devm_snd_soc_register_component(dev, component_driver, + rz_ssi_soc_dai, + ARRAY_SIZE(rz_ssi_soc_dai)); } =20 static const struct of_device_id rz_ssi_of_match[] =3D { @@ -1307,7 +1173,6 @@ static struct platform_driver rz_ssi_driver =3D { .pm =3D pm_ptr(&rz_ssi_pm_ops), }, .probe =3D rz_ssi_probe, - .remove =3D rz_ssi_remove, }; =20 module_platform_driver(rz_ssi_driver); --=20 2.43.0 From nobody Mon Jun 15 15:13:30 2026 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6886035DA4F for ; Sat, 11 Apr 2026 11:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907822; cv=none; b=PFZpVLNKC7ycqKCrNolqhkQ0fXb2mO9NAXcnPa1I6BELCwdw389pzrBY/vO9ixYdUz4OqY4gwiYOY7d4wEL6SE73dRFvdUBOZgW0KTxcFNTj5N3049IIWF058WvITTHYrDfhT8P8B2vqm9+FRItzQjRi1SbyqPap5hoRQFbh31c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775907822; c=relaxed/simple; bh=00agU9G8WCwFdL8wNmeE5/RI+LQevLHKH0zoSbPnvhI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MftBpO+kOIQdw3wV0pxiCbjAbQ5ZQ3y1viIHLTNCPyusWoVSr5TPpNAYZcyQhr5Oj+q74AB12c+J/YjNMAIyrkbCfRXbheCxIUSuE35I1U1MoSA6kF6x3D1EI3ox8xoRMKMohTTYf7HMjCBcjF5gTJs1Z49FN6y4ESkHeQcR+xk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=aR2uSJiy; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="aR2uSJiy" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-43b9d3ebed5so2319386f8f.1 for ; Sat, 11 Apr 2026 04:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1775907820; x=1776512620; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=woi0lrK3i2kpcKywf5o3X0tfp9llXfvPOtNyhrNBRjY=; b=aR2uSJiyLT6jmwBC3UH6WcfEo4IK6ecwdENClhaWAE8OcMX2Qiug9EqrsvgpYVJGVc zjdpK19ssdSr/KKwrSrTYiHPIBJzL59S1aNHGw5vS1XlY1y0PD2c0BdBkXpS/gC/8PLM XfRB6JC6lK3hlu5S+72CT6foKn880JNNQXQ6lqjIhzMvpnavRgiyqup/ZZURyM8P5xOz DuWEU0irOKUhCuNd+lneHGGGICr8iqau0A73S9s2/bKwTJvTMbjKMk7U9UK9gXxFGoPK g6fDAvDW7Zz3gCCY9JWgKD7YVr+ADGCwDXFTP4AM2hSR/I9vCv78xsFCZaqbw/Y7csqE 3C+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775907820; x=1776512620; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=woi0lrK3i2kpcKywf5o3X0tfp9llXfvPOtNyhrNBRjY=; b=j+CtwTbFZpgxYAftqRX5Ky5Stgy+4+ZDokiwF6/X0vnvmJUKHiqI3aVAducvl2SiPo lFcQ7R4cq1RTUMu6Z6tsYP5YZaUw5Pts1GOqB47gT+MJJ/vJkllNenbDr3xthBetGMZa /1YnWRoaWChGzAbrjp0+s2jNLNyIC2BTUtxSeOu1lDDcxJB5K7DjRI0FYiezgNCM3UV8 DqYz5FU5RSctIp4R9WPalJAwd2HZU0EmpMqlLwUpXqaDqsmZSEdUBaviAiq6jKgAHU/F +qeAFT+Et9EAQS2VQAfopusFVOzXavIchxuTke6Q6y4iawqmtne9FXeifFgPLWCnqKiV QxEg== X-Forwarded-Encrypted: i=1; AJvYcCXLdjKr4SSYUwn7pJBfQbn7e38cuHN98TZiwXmd8h0oWRBLVjoNmBaJzHagcIdzoj4bNGTo5RPQXaJ1tFs=@vger.kernel.org X-Gm-Message-State: AOJu0Yzgs++yQnxSp/HPJXL5uaCf1ltBlbpcoBqAR0kTdVWzk3qVM1vE UOTv6fwz767tOJGC6tfGqu5WYYlGRKOwLaDji8WB/M9fUdikAU4Za9Cx+cw13MyKftc= X-Gm-Gg: AeBDietY44lsp9+ERCPaLuNC+9XrYfaeYyG2lj35zovtu4YnioQ5wfr9xE/xGnH1jSl meSPvAPUeZlnySRjYCnnghwe3Dv+RPrOdhR63TA9qzO7r1CmyoId8d3yTBU2VIbVN2diiSQJiTh 2lJFX25+XfCfAhkKHgmB1E1fZL7GAgUnuYBL39lmMGid5T6DROgOFSzO4CY/7OMwsQYzM4/JRE6 efAguRN90tEZdDQ7uMCisFI2546QkKyH/xO8zZtDAZocnpwhsyGSqdviPl5Dw6g6yV00XvvjhoY DEUfcQkr4v+hqsebXCSGrl806Kw+vxOF4b4BRVE+38cyufjXQgg+gaNyJcKeOmfiJ4BfXH/H7e5 lu0cR+0k2Myq05DDdUf4aeYXOUMfLWSkoihGMm6Ns/75StzlSGdkvWDmP4ql1t8LOiQiyGyO4l/ W4OpPadgFqj7Hr3pmpChUmq6uqBNT5nGE2UMLm55oIkozi9C/FrwlVL1eUYAz1Ets= X-Received: by 2002:a05:6000:420b:b0:43c:ff3f:c635 with SMTP id ffacd0b85a97d-43d642b188amr9465975f8f.34.1775907819734; Sat, 11 Apr 2026 04:43:39 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.248]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c981sm15776447f8f.33.2026.04.11.04.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 04:43:38 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v4 17/17] dmaengine: sh: rz-dmac: Set the Link End (LE) bit on the last descriptor Date: Sat, 11 Apr 2026 14:43:03 +0300 Message-ID: <20260411114303.2814115-18-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> References: <20260411114303.2814115-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea On an RZ/G2L-based system, it has been observed that when the DMA channels for all enabled IPs are active (TX and RX for one serial IP, TX and RX for one audio IP, and TX and RX for one SPI IP), shortly after all of them are started, the system can become irrecoverably blocked. In one debug session the system did not block, and the DMA HW registers were inspected. It was found that the DER (Descriptor Error) bit in the CHSTAT register for one of the SPI DMA channels was set. According to the RZ/G2L HW Manual, Rev. 1.30, chapter 14.4.7 Channel Status Register n/nS (CHSTAT_n/nS), description of the DER bit, the DER bit is set when the LV (Link Valid) value loaded with a descriptor in link mode is 0. This means that the DMA engine has loaded an invalid descriptor (as defined in Table 14.14, Header Area, of the same manual). The same chapter states that when a descriptor error occurs, the transfer is stopped, but no DMA error interrupt is generated. Set the LE bit on the last descriptor of a transfer. This informs the DMA engine that this is the final descriptor for the transfer. Signed-off-by: Claudiu Beznea --- Changes in v4: - none Changes in v3: - none Changes in v2: - none drivers/dma/sh/rz-dmac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 00e18d8213ca..f5d2e206f4bb 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -200,6 +200,7 @@ struct rz_dmac { =20 /* LINK MODE DESCRIPTOR */ #define HEADER_LV BIT(0) +#define HEADER_LE BIT(1) #define HEADER_WBD BIT(2) =20 #define RZ_DMAC_MAX_CHAN_DESCRIPTORS 16 @@ -382,7 +383,7 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_d= mac_chan *channel) lmdesc->chcfg =3D chcfg; lmdesc->chitvl =3D 0; lmdesc->chext =3D 0; - lmdesc->header =3D HEADER_LV; + lmdesc->header =3D HEADER_LV | HEADER_LE; =20 rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_= no); =20 @@ -425,7 +426,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct r= z_dmac_chan *channel) lmdesc->chext =3D 0; if (i =3D=3D (sg_len - 1)) { lmdesc->chcfg =3D (channel->chcfg & ~CHCFG_DEM); - lmdesc->header =3D HEADER_LV; + lmdesc->header =3D HEADER_LV | HEADER_LE; } else { lmdesc->chcfg =3D channel->chcfg; lmdesc->header =3D HEADER_LV; --=20 2.43.0