From: Nickolay Goppen <setotau@mainlining.org>
To: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] dmaengine: qcom: bam_dma: Report the residue of packet
Date: Thu, 3 Dec 2026 21:31:39 +0300 [thread overview]
Message-ID: <a8fb94db-69fe-41b1-a6d0-d85b23d47784@mainlining.org> (raw)
In-Reply-To: <20261116-qcom-bam-dma-metadata-v2-1-aade3a42fcb4@mainlining.org>
16.11.2026 16:49, Nickolay Goppen пишет:
> The BAM writes back the number of bytes actually received into the
> descriptor that ended an RX transfer. Report this through the standard
> dmaengine_result (residue = length - transferred) so clients get the
> packet length from callback_result().
>
> Assisted-by: LLM
> Signed-off-by: Nickolay Goppen <setotau@mainlining.org>
> ---
> IPA v2.x uses BAM to send and receive IP packets, to and from the AP.
> However, unlike its predecessor BAM-DMUX, it doesn't send information
> about the packet length, but ipa2 driver will need that. To find the
> length of the packet, one must instead read the difference between
> packet length and residue.
> ---
> Changes in v2:
> - Fixed residues of old patch (sashiko)
> - changed readl_relaxed to readl for offset reading in proccess_channel_irqs (sashiko)
> - Link to v1: https://patch.msgid.link/20261115-qcom-bam-dma-metadata-v1-1-52e4de54ffd3@mainlining.org
>
> To: Vinod Koul <vkoul@kernel.org>
> To: Frank Li <Frank.Li@kernel.org>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: dmaengine@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
> drivers/dma/qcom/bam_dma.c | 33 ++++++++++++++++++++++++++++++++-
> 1 file changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
> index e62e411dc8f8..bf0c25d7c111 100644
> --- a/drivers/dma/qcom/bam_dma.c
> +++ b/drivers/dma/qcom/bam_dma.c
> @@ -65,6 +65,7 @@ struct bam_async_desc {
>
> u32 num_desc;
> u32 xfer_len;
> + size_t transferred;
>
> /* transaction flags, EOT|EOB|NWD */
> u16 flags;
> @@ -447,6 +448,31 @@ static inline void __iomem *bam_addr(struct bam_device *bdev, u32 pipe,
> r.ee_mult * bdev->ee;
> }
>
> +/**
> + * bam_fifo_xfer_len - bytes transferred for a completed descriptor chunk
> + * @bchan: BAM channel the chunk was queued on
> + * @async_desc: BAM async descriptor owning the chunk
> + *
> + * For RX pipes the BAM overwrites the size field of the descriptor that
> + * ended the transfer with the number of bytes actually written to memory,
> + * which can be less than the buffer size (e.g. an IPA packet). Those
> + * values live in the FIFO copy, not in async_desc->desc[].
> + */
> +
> +static u32 bam_fifo_xfer_len(struct bam_chan *bchan,
> + const struct bam_async_desc *async_desc)
> +{
> + struct bam_desc_hw *fifo = PTR_ALIGN(bchan->fifo_virt,
> + sizeof(struct bam_desc_hw));
> + u32 len = 0;
> + unsigned int i;
> +
> + for (i = bchan->head; i < bchan->head + async_desc->xfer_len; i++)
> + len += le16_to_cpu(fifo[i % MAX_DESCRIPTORS].size);
> +
> + return len;
> +}
> +
> /**
> * bam_reset() - reset and initialize BAM registers
> * @bdev: bam device
> @@ -865,7 +891,7 @@ static u32 process_channel_irqs(struct bam_device *bdev)
>
> guard(spinlock_irqsave)(&bchan->vc.lock);
>
> - offset = readl_relaxed(bam_addr(bdev, i, BAM_P_SW_OFSTS)) &
> + offset = readl(bam_addr(bdev, i, BAM_P_SW_OFSTS)) &
> P_SW_OFSTS_MASK;
> offset /= sizeof(struct bam_desc_hw);
>
> @@ -881,6 +907,11 @@ static u32 process_channel_irqs(struct bam_device *bdev)
> if (avail < async_desc->xfer_len)
> break;
>
> + async_desc->transferred +=
> + bam_fifo_xfer_len(bchan, async_desc);
> + async_desc->vd.tx_result.residue =
> + async_desc->length - async_desc->transferred;
> +
> /* manage FIFO */
> bchan->head += async_desc->xfer_len;
> bchan->head %= MAX_DESCRIPTORS;
>
> ---
> base-commit: 2cc223d6ffadd48e25eff0c8a03108a5d7a61c41
> change-id: 20261115-qcom-bam-dma-metadata-f34e592d400c
>
> Best regards,
> --
> Nickolay Goppen <setotau@mainlining.org>
Can someone take a look at this?
--
Best regards,
Nickolay
next prev parent reply other threads:[~2026-12-03 18:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 13:49 [PATCH v2] dmaengine: qcom: bam_dma: Report the residue of packet Nickolay Goppen
2026-12-03 18:31 ` Nickolay Goppen [this message]
2026-12-03 20:49 ` Frank Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a8fb94db-69fe-41b1-a6d0-d85b23d47784@mainlining.org \
--to=setotau@mainlining.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.