From mboxrd@z Thu Jan 1 00:00:00 1970 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 98294385539 for ; Mon, 2 Mar 2026 13:49:59 +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=1772459402; cv=none; b=FNGwQgfJmISFMzibAXA9fXRovYHQpXmMychFCZ0hFIjEqznZ8mB6/5QiviSknpNV1w1QByE7YBNU1X7c7orFNmkFtiHvP659ETkDD9qpCZuaMKKlqbxFbH/eM56uRbPeEMjh414if1E2EkN5sey/4OrskHMLX4sRRPuBI8jQRUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772459402; c=relaxed/simple; bh=6rxitJML5el8SD7x2bLQQ2FRCVMs9yxv6zhxa8ylm0s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rRLOieyKuBimIC/edNruI72yZekOXdBuBDa6xtznPh5zKn8OeKakeOCTu496zRkjrY23jCgCs6I8FNZLP+Olwid9hQ2s9WOt49LS/qGlxgetViAbuFw5NlY+p8R2wH1f4vF39v9fRu4UuLQlCYbnsL1TuaC/ByKqjap+ZihemVU= 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=W89NMauy; 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="W89NMauy" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4838c15e3cbso40257735e9.3 for ; Mon, 02 Mar 2026 05:49:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1772459398; x=1773064198; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=uOGfBSF1Yzv+515EEkVwpjnn8h91APdHFmvLcZC+dMw=; b=W89NMauy/1z7mF+rIJ9SjSnsgrMYuU+3C6Pt8Zy1sGw9B1UmJnGOOgR1GjiBZU1YYM XFQWaVTG5lgRg4xgkzWKEF3HKbmkjfuq5hM3ZspgGErQUI3232yoDG0LhP4E/zvz7IsS Pq4qT0b1nybdtvAK5gCy/JdJKqn/KrvIoKwTK+/MWJRNOPU7DMH3Hn8ndDPha+DZ2CH8 84qSOmbhR0++KBTpvqR+eQf4XTPBgO0bQtQfbWCITLEz4tG6eQ3/pbYTVkTcDqaifYHp rupRSQP9Jqi0j8KG4xHtZsF0ySYs7zY2IjYgaNXgVOBsFHQqrL/QBUDJgLaP9IG+LJXY DEwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772459398; x=1773064198; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uOGfBSF1Yzv+515EEkVwpjnn8h91APdHFmvLcZC+dMw=; b=oCn6MUQW4EY+wNkIrjuWIRjqwzNGfusLfBa4gZrJ1GUxpewhkDUjj7Vp1mnZfUn0Fp R0O51sxUbMTVNibIC9Vhs3FLvGdjk7KrN1aBafyLcF/FnBAFdSWTzfmzPmlC93JZ7Zsn Qh7jBP9Sa+Hp10Hvq/P8jksOWNsFZWLVfrdCW6rftxKAax4geEWQlnnLOHbpjg3tRyQ3 1GBO74Cgusb0vhMu0Ua+N6EGGYN18s2OBTHj++v/OO0mPwef22luAsQ9KP1i1fd97xHO qIkOBVXA3/9XSMiOGsovYLlnSqxAuP+Z+Ka/otTshISx/KNunMaNxZ8RPkkGnwE/W2Tl 4V+Q== X-Forwarded-Encrypted: i=1; AJvYcCWwgI7ng62DPQLVf98PXGC/osb3i9kw/svZieDLl1TJLKCrypWin9jpOvc8o+tj6QlGS5slQTGzoTCI2eg=@vger.kernel.org X-Gm-Message-State: AOJu0YwIX3nGtW/mUX0FCIGpDpAP7rZLEtcNapWrE4TQkhyW0DJHbJFP rzVhslkZdSWY9gjklMh/rqk8TnXnI/9EbSt5ImoC7FV3XVKOjR05bojWLFzIFDO+kb0= X-Gm-Gg: ATEYQzwOOM8qqneZQUTL3TwyQ3Ba0JamCSbzmb4fEiTp+b201ZveI8eQdWV+KBvMwmF Hixp0hdor7n/B+1Um2oOPCkg2KeEdLK50tyZlfIRgzKLYkGDmZuqrVng1CSve6FjhFoYISDUeP5 VZuRuOftrzLjgDMGkBdddZsiGo9gYYG1SLUlfMKT1IJdH6fFuSR8w2t7KXV2XPhI11WMbziiXtE BZFiT+D5SROPOM3phZ45rid3ObF8wWfgp33ixL0zlU2m1PifXfdZc/haTvSummggWW+Hp9UAqrw 9WkX4djxHnOMZ1APMlWWQgYZttZMlBazkYbkH/TQtqzscgBFyBw/Of2GLerSqf1pjt+gZbOpuy3 9zGt/qWd1at09/caO9Rm9eeN17Scld9Xliqd4SUVtoszgr2lTk5QmVB3vofJch2D5cJ02K4Ayx1 hKfkBmS96Zo07G/Xh5RMTH7furstZlCK8Y9A9g X-Received: by 2002:a05:600c:1c28:b0:471:14af:c715 with SMTP id 5b1f17b1804b1-483c9bc5643mr221946815e9.3.1772459397277; Mon, 02 Mar 2026 05:49:57 -0800 (PST) Received: from [172.19.170.194] ([213.233.104.147]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483bd6f3124sm414496905e9.1.2026.03.02.05.49.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Mar 2026 05:49:56 -0800 (PST) Message-ID: Date: Mon, 2 Mar 2026 15:49:54 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 7/8] dmaengine: sh: rz-dmac: Add device_tx_status() callback To: Frank Li Cc: vkoul@kernel.org, geert+renesas@glider.be, biju.das.jz@bp.renesas.com, fabrizio.castro.jz@renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, Claudiu Beznea References: <20260120133330.3738850-1-claudiu.beznea.uj@bp.renesas.com> <20260120133330.3738850-8-claudiu.beznea.uj@bp.renesas.com> Content-Language: en-US From: Claudiu Beznea In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Frank, On 2/25/26 18:43, Frank Li wrote: > On Tue, Jan 20, 2026 at 03:33:29PM +0200, Claudiu wrote: >> 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 . > > If you want to give credit to Long Luu, any public link? No public link as far as I'm aware. Anyway, I'll add his SoB + Co-developed-by. > >> >> 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 != crla' comparison instead of >> '!(lmdesc->nxla == crla)' in rz_dmac_calculate_residue_bytes_in_vd() >> - in rz_dmac_calculate_residue_bytes_in_vd() use '++i >= 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] > > Suppose needn't this section Just followed the process. I can drop it. > >> Signed-off-by: Claudiu Beznea >> --- >> >> Changes in v8: >> - populated engine->residue_granularity >> >> Changes in v7: >> - none >> >> 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 != crla' comparison instead of >> '!(lmdesc->nxla == crla)' in rz_dmac_calculate_residue_bytes_in_vd() >> - in rz_dmac_calculate_residue_bytes_in_vd() use '++i >= 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 | 145 ++++++++++++++++++++++++++++++++++++++- >> 1 file changed, 144 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c >> index 4602f8b7408a..27c963083e29 100644 >> --- a/drivers/dma/sh/rz-dmac.c >> +++ b/drivers/dma/sh/rz-dmac.c >> @@ -125,10 +125,12 @@ struct rz_dmac { >> * Registers >> */ >> >> +#define CRTB 0x0020 >> #define CHSTAT 0x0024 >> #define CHCTRL 0x0028 >> #define CHCFG 0x002c >> #define NXLA 0x0038 >> +#define CRLA 0x003c >> >> #define DCTRL 0x0000 >> >> @@ -684,6 +686,146 @@ static void rz_dmac_device_synchronize(struct dma_chan *chan) >> rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_no); >> } >> >> +static struct rz_lmdesc * >> +rz_dmac_get_next_lmdesc(struct rz_lmdesc *base, struct rz_lmdesc *lmdesc) >> +{ >> + struct rz_lmdesc *next = ++lmdesc; >> + >> + if (next >= base + DMAC_NR_LMDESC) >> + next = base; >> + >> + return next; >> +} >> + >> +static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel) >> +{ >> + struct rz_lmdesc *lmdesc = channel->lmdesc.head; >> + struct dma_chan *chan = &channel->vc.chan; >> + struct rz_dmac *dmac = to_rz_dmac(chan->device); >> + u32 residue = 0, crla, i = 0; >> + >> + crla = rz_dmac_ch_readl(channel, CRLA, 1); >> + while (lmdesc->nxla != crla) { >> + lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); >> + if (++i >= DMAC_NR_LMDESC) >> + return 0; >> + } >> + >> + /* Calculate residue from next lmdesc to end of virtual desc */ >> + while (lmdesc->chcfg & CHCFG_DEM) { >> + residue += lmdesc->tb; >> + lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); >> + } > > can use one loop > > for (int i=0; i if (lmdesc->nxla == crla) > residue = 0; //reset to 0; > > if (lmdesc->chcfg & CHCFG_DEM) > residue += lmdesc->tb; > > lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); I'm not sure this will work as the descriptors list is cyclic and resetting the residue to zero when lmdesc->nxla == crla and then start acumulating from there will not work if there are descriptors enqueued for the current transfers at the end and the beginning of the list, e.g: descriptors list: | d3 | d5 | d6 | ... | d0 | d1 | d2 | ^ ^ start end (index 0) (index DMAC_NR_LMDESC-1) > } > > return residue; > >> + >> + 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 = 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 = dma_cookie_status(&channel->vc.chan, cookie, NULL); >> + if (status == 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 != current_desc->vd.tx.cookie) { >> + list_for_each_entry(desc, &channel->ld_free, node) { >> + if (cookie == desc->vd.tx.cookie) >> + return 0; >> + } >> + >> + list_for_each_entry(desc, &channel->ld_queue, node) { >> + if (cookie == desc->vd.tx.cookie) >> + return desc->len; >> + } >> + >> + list_for_each_entry(desc, &channel->ld_active, node) { >> + if (cookie == 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 = 0; i < 3; i++) { >> + crla = rz_dmac_ch_readl(channel, CRLA, 1); >> + crtb = rz_dmac_ch_readl(channel, CRTB, 1); >> + /* Still the same? */ >> + if (crla == rz_dmac_ch_readl(channel, CRLA, 1)) >> + break; >> + } >> + >> + WARN_ONCE(i >= 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); > > you don't use varible 'ctra' here, so retry 3 become useless. suppose > rz_dmac_calculate_residue_bytes_in_vd(channel, ctra) > > and avoid rz_dmac_ch_readl(channel, CRLA, 1) in > rz_dmac_calculate_residue_bytes_in_vd() to keep ctra and ctrb reflect the > correct hardware state. Good point, I'll update it. Thank you for your review, Claudiu