From nobody Tue Feb 10 14:32:21 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 6930A2D7DE1 for ; Tue, 23 Dec 2025 13:50:52 +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=1766497854; cv=none; b=S0k4Pl0s3rJC7Qd6aMobrJa852bjz64/XMk57UbGwFeJLnwSJcTJ63U06EgDLZcLZa07WsDMs4Fl/eOsi0hcJwKkG6bmWgd6RiRgfhuu8UBvD5Lyh0qhTn33OyOdhRY7Om9OZsiMnvSly2YfW9qBKxFwD4Nvn/pp3mKwqT2uzxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766497854; c=relaxed/simple; bh=V2j30uJzU9iGi0tcofb7kdtfANNgwgeTb2rJjoOkv6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KUkP7PDldP4SXUJeXD0SagqE2rdTnmX5TroIY7iQMj1GjIH34K1QgHitaqHaFFwDZl4zdWUcor6zlyDFrVFnm72OcIgyBZ/uj9HO3/rz7x+ORWUKVMfd3+PgO6feF2rcRIu140lJ6n0PwWTfYgLN2ETfWbGOplWJB68iJLAbiCI= 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=dj6l5f7A; 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="dj6l5f7A" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-47bdbc90dcaso33192195e9.1 for ; Tue, 23 Dec 2025 05:50:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1766497850; x=1767102650; 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=wwIfRwPlxJ4dUOA9CK0cEGyokIF+zsSw+S+9qTH5zlc=; b=dj6l5f7AFsff3vv3MaGhjDVU6md76azkNckHP4p9o3i7gUhdOGnbu9i73AvFmfpAi4 w1TcKiqAJ7V8AquS5GFH5aiRVfjQzYRgIfS9YR/he+2jVNzsfkYY7NgvOeCgKnVJz51X pXhN/Y9gyfApMGX3dlcnlW5bEk4fzie1bbu8QcGoTv2Y/MHAbNcgtvYStx6SzXWIXDTQ 8/EmZzWT0FFl8Be9RXKISFaUySDiw3e9kmigiY+6epTfvbi+YoNMkD3XE/b1VCpKGnTR axt5Ikzy3S76Tqsiip2oOAQzFqR2ETBcas/9B+NBDALhej+tx046pMnyssnMMygpduDJ C2GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766497850; x=1767102650; 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=wwIfRwPlxJ4dUOA9CK0cEGyokIF+zsSw+S+9qTH5zlc=; b=Trpvhq0n4VF6n+C8+GD7U/klGThh/SWfZ/4RurKftcj0gK1ldByO6sL34KB3sc4qBa GpVCSum8ThZqpmo3obPRheEJXVMpzUw+jMmvcDBtmMMJfB8YsJeM578gdeUc4BXPQxoR P7eKYaRrCxEeHya6DFSENDhTPdJMWV+K24KNxV+riIeqxJfvRoaE0hWp9w7v3+zyei2v QgPo1ZDqRdT59aVz4vOdOFKxwAV7mtAmTfr5qMhrVIFOXUHTOwissP8QPUsZlYI77Jc0 y4Ihbk/tkeK4nPnI1hU6cMlak9Eartf/LfQzgno63qG1L76MRcuMjmh6qkc4agbNOHMp t1jA== X-Forwarded-Encrypted: i=1; AJvYcCWSRHmL9ygYdymDsaKBaY/JZSmswOidZSr/ia+PcO7DCFJqmBJWVcRXwh5nEfxWfNmGFBsKBlXY5NQqRsU=@vger.kernel.org X-Gm-Message-State: AOJu0YyNCAvnXDO/xQ9Yc1usghQjWE+BAvUE9306zvOfTLgjXkfn3rTK fI6DHNJ12FzURJvnnmDDXIiU3skPwv27f0JnJeWbnqjH+B/NmJMrLk5uKlxikXHewVs= X-Gm-Gg: AY/fxX4pMKQ9q8+6KX9nJYHQ+BM9AzrGFo9hFCxSwxAxUhKnc21KHXsvEc+hrrBbCeG JycYASSSxzSN9/lm+FVxJMZK1CWaCZJLEGIBpX8JVVLnOKRct++HMaVk3luF6WxmEmZTYr0l6sU xtBYvRE+85TK0xzJEuRMP1lGjFkwUe1RPk+zrHrANJ/pt6O4eZFc8cWK2F3ztV0/9HrARChBeKa qwZmXk4GRuohzRZpQEypXhrbRQP6SL5OddYYAo46RT2LH43lz2/F9WiGTG/OnMRhtwTjWI2fN2Q C65SZmWBCoQ/SvSeNv2IJz7e01Z4lXkXatdwZk5mER1BYLBfQL/TcOP1rLQWdnKWNZ/z3sruPY1 yxLaVp/+QLYyTgJDFVD/24rRxmSuIk6r62zoo7LSOozEf+/yc8Wn0bKjFZR0YHjG1MLU0SLqqdQ MEBtPQ01ry+GEXUX3D7ROqx1t7s03IoPpbyWKK0VyZ++MMNZvG/iH4mFFqWzkToPwE9GrPTWtph aEZpWfP9g== X-Google-Smtp-Source: AGHT+IGpYksT8judEEY1zEyXam/PhoR55JNkEaNhLWS8xcqxEg/9LOK2xzEcnGWU/7o70HLlvIufAQ== X-Received: by 2002:a05:600c:4595:b0:477:a1a2:d829 with SMTP id 5b1f17b1804b1-47d1953ead3mr144045255e9.13.1766497850257; Tue, 23 Dec 2025 05:50:50 -0800 (PST) Received: from claudiu-TUXEDO-InfinityBook-Pro-AMD-Gen9.. ([2a02:2f04:620a:8300:4258:c40f:5faf:7af5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d192e88f5sm237921025e9.0.2025.12.23.05.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Dec 2025 05:50:49 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, biju.das.jz@bp.renesas.com, fabrizio.castro.jz@renesas.com, geert+renesas@glider.be, prabhakar.mahadev-lad.rj@bp.renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, Claudiu Beznea Subject: [PATCH v6 7/8] dmaengine: sh: rz-dmac: Add device_tx_status() callback Date: Tue, 23 Dec 2025 15:49:51 +0200 Message-ID: <20251223134952.460284-8-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251223134952.460284-1-claudiu.beznea.uj@bp.renesas.com> References: <20251223134952.460284-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: Biju Das Add support for device_tx_status() callback as it is needed for RZ/G2L SCIFA driver. Based on a patch in the BSP similar to rcar-dmac by Long Luu . Signed-off-by: Biju Das [claudiu.beznea: - post-increment lmdesc in rz_dmac_get_next_lmdesc() to allow the next pointer to advance - use 'lmdesc->nxla !=3D crla' comparison instead of '!(lmdesc->nxla =3D=3D crla)' in rz_dmac_calculate_residue_bytes_in_vd() - in rz_dmac_calculate_residue_bytes_in_vd() use '++i >=3D DMAC_NR_LMDESC' to verify if the full lmdesc list was checked - drop rz_dmac_calculate_total_bytes_in_vd() and use desc->len instead - re-arranged comments so they span fewer lines and are wrapped to ~80 characters - use u32 for the residue value and the functions returning it - use u32 for the variables storing register values - fixed typos] Signed-off-by: Claudiu Beznea --- Changes in v6: - s/byte/bytes in comment from rz_dmac_chan_get_residue() Changes in v5: - post-increment lmdesc in rz_dmac_get_next_lmdesc() to allow the next pointer to advance - use 'lmdesc->nxla !=3D crla' comparison instead of '!(lmdesc->nxla =3D=3D crla)' in rz_dmac_calculate_residue_bytes_in_vd() - in rz_dmac_calculate_residue_bytes_in_vd() use '++i >=3D DMAC_NR_LMDESC' to verify if the full lmdesc list was checked - drop rz_dmac_calculate_total_bytes_in_vd() and use desc->len instead - re-arranged comments so they span fewer lines and are wrapped to ~80 characters - use u32 for the residue value and the functions returning it - use u32 for the variables storing register values - fixed typos drivers/dma/sh/rz-dmac.c | 144 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 1 deletion(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 45c45053e9df..44f0f72cbcf1 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -119,10 +119,12 @@ struct rz_dmac { * Registers */ =20 +#define CRTB 0x0020 #define CHSTAT 0x0024 #define CHCTRL 0x0028 #define CHCFG 0x002c #define NXLA 0x0038 +#define CRLA 0x003c =20 #define DCTRL 0x0000 =20 @@ -685,6 +687,146 @@ static void rz_dmac_device_synchronize(struct dma_cha= n *chan) } } =20 +static struct rz_lmdesc * +rz_dmac_get_next_lmdesc(struct rz_lmdesc *base, struct rz_lmdesc *lmdesc) +{ + struct rz_lmdesc *next =3D ++lmdesc; + + if (next >=3D base + DMAC_NR_LMDESC) + next =3D base; + + return next; +} + +static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *chan= nel) +{ + struct rz_lmdesc *lmdesc =3D channel->lmdesc.head; + struct dma_chan *chan =3D &channel->vc.chan; + struct rz_dmac *dmac =3D to_rz_dmac(chan->device); + u32 residue =3D 0, crla, i =3D 0; + + crla =3D rz_dmac_ch_readl(channel, CRLA, 1); + while (lmdesc->nxla !=3D crla) { + lmdesc =3D rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); + if (++i >=3D DMAC_NR_LMDESC) + return 0; + } + + /* 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); + } + + dev_dbg(dmac->dev, "%s: VD residue is %u\n", __func__, residue); + + return residue; +} + +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; + u32 crla, crtb, i; + + /* Get current processing virtual descriptor */ + current_desc =3D list_first_entry(&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; + } + + /* + * 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!"); + return 0; + } + + /* + * We need to read two registers. Make sure the hardware does not move + * to next lmdesc while reading the current lmdesc. Trying it 3 times + * should be enough: initial read, retry, retry for the paranoid. + */ + for (i =3D 0; i < 3; i++) { + crla =3D rz_dmac_ch_readl(channel, CRLA, 1); + crtb =3D rz_dmac_ch_readl(channel, CRTB, 1); + /* Still the same? */ + if (crla =3D=3D rz_dmac_ch_readl(channel, CRLA, 1)) + break; + } + + WARN_ONCE(i >=3D 3, "residue might not be continuous!"); + + /* + * 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); +} + +static enum dma_status rz_dmac_tx_status(struct dma_chan *chan, + dma_cookie_t cookie, + struct dma_tx_state *txstate) +{ + struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + enum dma_status status; + u32 residue; + + status =3D dma_cookie_status(chan, cookie, txstate); + if (status =3D=3D DMA_COMPLETE || !txstate) + return status; + + scoped_guard(spinlock_irqsave, &channel->vc.lock) + residue =3D rz_dmac_chan_get_residue(channel, cookie); + + /* if there's no residue, the cookie is complete */ + if (!residue) + return DMA_COMPLETE; + + dma_set_residue(txstate, residue); + + return status; +} + /* * -----------------------------------------------------------------------= ------ * IRQ handling @@ -1016,7 +1158,7 @@ static int rz_dmac_probe(struct platform_device *pdev) =20 engine->device_alloc_chan_resources =3D rz_dmac_alloc_chan_resources; engine->device_free_chan_resources =3D rz_dmac_free_chan_resources; - engine->device_tx_status =3D dma_cookie_status; + 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_config =3D rz_dmac_config; --=20 2.43.0