From nobody Tue Feb 10 13:18:12 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 EA6783FBA7 for ; Wed, 17 Dec 2025 13:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765979559; cv=none; b=AhlnTkCH0jTeIouD+TpywhKqQilThPq3olQ7uqru4asJQdng1o1RGbXhqdsAr2nUeq7farlppK8xmSyCZtPTprHeu6yfMup4h8wn0lYUmKpVs/MI/ujQpfsA6JFZ45W+2L06I1RQ5RmDeI9px5h2bu70hpZnVV83GV9sherQe08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765979559; c=relaxed/simple; bh=wdcFsKk64ZqLQoSy4lgRRP+OrwZbLshgOLdKPP5OhP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W5ZYhT+S0hnJ29FlJ8cqeSLYrUn5xuJbzXwcvPM6USuutixMlezdI4KJgCyXc36SBj378A1BcuTDx0HJFr+PcAddwL/yXnIxFdeRKbz/eeLdebxMTbt3MPp4THBzlbF9ZOJ6zAZLT9VranAVvG8ljcx8sXgQio+xb9GizYkLVOE= 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=fP8YWCct; arc=none smtp.client-ip=209.85.221.52 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="fP8YWCct" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-430f5ecaa08so1965705f8f.3 for ; Wed, 17 Dec 2025 05:52:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1765979552; x=1766584352; 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=DRRlcALx6KJfRO0PXviH91cZdJRUcSAZjbrCKicxs7Q=; b=fP8YWCctS3AIm5PV10EeBYI20bTvBEv5YD+UTt3fTh/3tpmClexPPRPlYmso8tThaw cOeHvCojtOIiOu5E9dHvLkoK6FBbT90hnmVUk4NohcmJ0oIluwO9mReVZ3x4ol/9ahel oSU9wgl2c/bpM+QlUB64WhniVMqpA1T9rHiIFyHnq3b1UBLhTz70sLINcONSILOgob3z 4DW7gHgjgoP6xBN1S+kyy8iXTC7mTka8bRItWlmgXXRwS4MBXRcFOxy6xk+/zVslExlB L6BGh2W3RKPUXyMSWShB+jv/eCqgL048vtbhPQX86AMzkTPl/Z7Bfr6akwUC9eosPeNL UuTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765979552; x=1766584352; 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=DRRlcALx6KJfRO0PXviH91cZdJRUcSAZjbrCKicxs7Q=; b=TSog0hAZrF+7dsmDBcyJu/N3mDnzqvPiUi5/k4FhR7BpP4n0XlT6B9u/Gv/zf6A2P+ 7hhpwnYBlqRghZlys+kmrps7RAWNUT15hwH5fEclGqhNFU9TvmXIcMAMU/v5Hjp2b27K u4hYIxfRAnl7SjjHIlC29Lm05n4KpkDF/VF0LxcLWMk4Dd6E5BAs/mU1Yegj4ixzwwjB OKTchIs2n9o4uKfrc4kkcegQ12Huks4M7sX7SMj6umty0QsEB/yGHrTw2acQmLhV8+YS +2yr0meljObhMqJN8eF8+U52L0s8GyZRIdeBMUyBR94AdwSdhGbj9Dh1F7T4U5ct6CWW KYAw== X-Forwarded-Encrypted: i=1; AJvYcCVdsRdf630FIPwtF/DVFBEWWGnFGcGZyF5BP9mj+emjTo6HL0iSYx/BBSf5S0f3+wWDbGH9Ahm5GgY84mQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzqxpvWauX1nF6Xn97wp5AEtXDwObkXb0Lvr5K2Vk6nm7pJNspW C9VG1Z5OFjo6i46GyPUQDccdlQnTHXgJVPK2RHdMrteMf4w30wQGUydmgsytwXYwfsg= X-Gm-Gg: AY/fxX683KOlPlTzghTgpsL1gERMPjawuYSUseDy7iZB0oYAcZWbhu6dKK2JEpAxTZu 9Ucvl0XgvDaEuca+PRE/7c3iqtpDmbf+LEvu68/5eV0VkdNCduunpJo0+xOJVJc2sP4EFC1TSHQ mJT3ZGvVKaAHoQCdKir+fOXLUPQC/JxpU1zhOHsjqo3eCHxaClowlSVCp0LflEftdZvKSgBzRXT WNT/By1Eaby15dudYK1CfThe/HC/q8Sl1K1ayuW9CfmMLBlaxd7v78TQF0BB82U8Qap6PBq3cS1 CYZau0vBRXmHsOmjzAK+fJwigct0mjL1TfsBiw9pzw4KtPuMzsq5J+plloCA4SVIL3bHvBBuJaH V9/hN7l/S2haSgXbS1xuUp99JscTnT7KpNdhgC8IvYWcRiqjwx/D1tLqaGWcVEMg+tLedFy9bvs R0OeoM6fA4A0oB+mGh+kvDo6BiRHlyuFP2ICtpB+An X-Google-Smtp-Source: AGHT+IHdujWlg8jdn+rKZhpuf2sBPdcm1xcJ2ZQ4xT/FfMCcNymrhpduRFzaqB97VLiWsatlboVbUA== X-Received: by 2002:adf:fe87:0:b0:42f:bc61:d1e5 with SMTP id ffacd0b85a97d-42fbc61d428mr15779119f8f.15.1765979552183; Wed, 17 Dec 2025 05:52:32 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.134]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4310adf701csm4508000f8f.42.2025.12.17.05.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 05:52:31 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, fabrizio.castro.jz@renesas.com, biju.das.jz@bp.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 v5 5/6] dmaengine: sh: rz-dmac: Add device_tx_status() callback Date: Wed, 17 Dec 2025 15:52:12 +0200 Message-ID: <20251217135213.400280-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251217135213.400280-1-claudiu.beznea.uj@bp.renesas.com> References: <20251217135213.400280-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 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 bb5677f5a318..c3035b94ef2c 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 byte 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 @@ -1015,7 +1157,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