Netdev List
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Vishnu Santhosh <vishnu.santhosh@oss.qualcomm.com>
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Stephan Gerhold <stephan@gerhold.net>,
	Loic Poulain <loic.poulain@oss.qualcomm.com>,
	Sergey Ryazanov <ryazanov.s.a@gmail.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Deepak Kumar Singh <deepak.singh@oss.qualcomm.com>
Subject: Re: [PATCH net-next 1/3] dmaengine: qcom: bam_dma: report residue for completed RX transfers
Date: Thu, 3 Dec 2026 10:19:00 -0600	[thread overview]
Message-ID: <axGWdAF-wBmvywQW@SMW015318> (raw)
In-Reply-To: <20261203-qcom-bam-dmux-qmap-v1-1-abc2e80a03af@oss.qualcomm.com>

On Thu, Dec 03, 2026 at 09:40:52PM +0530, Vishnu Santhosh wrote:
> For device-to-memory transfers, the BAM writes the number of bytes it
> transferred back into the size field of each completed descriptor in the
> FIFO. The driver ignores this and always reports a residue of zero, so
> clients cannot tell how much data was received.
>
> BAM-DMUX needs this, because the modem can send packets whose length is
> only given by the size of the transfer.
>
> Read the written-back sizes when a transfer completes, and report the
> unused part of the buffers as residue through callback_result. If the
> BAM reports more bytes than were queued, mark the transfer as
> DMA_TRANS_WRITE_FAILED. If a descriptor other than the last one is
> short, the received data is not contiguous and cannot be described by a
> residue, so mark the transfer as DMA_TRANS_ABORTED.
>
> All existing users set the plain callback, which does not receive the
> result, so they are not affected.
>
> Co-developed-by: Deepak Kumar Singh <deepak.singh@oss.qualcomm.com>
> Signed-off-by: Deepak Kumar Singh <deepak.singh@oss.qualcomm.com>
> Signed-off-by: Vishnu Santhosh <vishnu.santhosh@oss.qualcomm.com>
> ---
>  drivers/dma/qcom/bam_dma.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
>
> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
> index e62e411dc8f8b24ecb9443b0c7eafb73ecfe8f01..b5d661b9af3df05ebd1ef909dea66a98ba938915 100644
> --- a/drivers/dma/qcom/bam_dma.c
> +++ b/drivers/dma/qcom/bam_dma.c
> @@ -834,6 +834,57 @@ static int bam_resume(struct dma_chan *chan)
>  	return 0;
>  }
>
> +/**
> + * bam_update_rx_result - account for bytes received by completed descriptors
> + * @bchan: bam channel
> + * @async_desc: descriptor whose hardware descriptors have completed
> + *
> + * On a producer pipe the BAM writes the number of bytes it transferred back
> + * into the size field of each completed descriptor in the FIFO. Report the
> + * unused part of the buffers as residue, so that clients using
> + * callback_result know how much data was received. Only the last descriptor
> + * of a transfer may be short, otherwise the transfer is marked as aborted.
> + * Clients that rely on the residue should therefore use a single buffer of
> + * at most BAM_FIFO_SIZE bytes per transfer. The residue is undefined if the
> + * result is not DMA_TRANS_NOERROR.
> + */
> +static void bam_update_rx_result(struct bam_chan *bchan,
> +				 struct bam_async_desc *async_desc)
> +{
> +	struct bam_desc_hw *fifo = PTR_ALIGN(bchan->fifo_virt,
> +					    sizeof(struct bam_desc_hw));
> +	u32 i;
> +
> +	if (async_desc->dir != DMA_DEV_TO_MEM)
> +		return;
> +
> +	/* Read the written back sizes only after reading BAM_P_SW_OFSTS */
> +	dma_rmb();
> +
> +	for (i = 0; i < async_desc->xfer_len; i++) {
> +		u16 expected = le16_to_cpu(async_desc->curr_desc[i].size);
> +		u16 received = le16_to_cpu(fifo[(bchan->head + i) %
> +						 MAX_DESCRIPTORS].size);
> +
> +		if (received > expected) {
> +			async_desc->vd.tx_result.result = DMA_TRANS_WRITE_FAILED;
> +			async_desc->vd.tx_result.residue += expected;
> +			continue;
> +		}
> +
> +		/*
> +		 * The next descriptor writes from its own address, so a short
> +		 * write before the last one leaves a hole in the buffer that
> +		 * cannot be described by the residue.
> +		 */
> +		if (received < expected && i != async_desc->num_desc - 1 &&
> +		    async_desc->vd.tx_result.result == DMA_TRANS_NOERROR)
> +			async_desc->vd.tx_result.result = DMA_TRANS_ABORTED;

Suppose need break loop here. Need check following desc.

Frank

> +
> +		async_desc->vd.tx_result.residue += expected - received;
> +	}
> +}
> +
>  /**
>   * process_channel_irqs - processes the channel interrupts
>   * @bdev: bam controller
> @@ -881,6 +932,8 @@ static u32 process_channel_irqs(struct bam_device *bdev)
>  			if (avail < async_desc->xfer_len)
>  				break;
>
> +			bam_update_rx_result(bchan, async_desc);
> +
>  			/* manage FIFO */
>  			bchan->head += async_desc->xfer_len;
>  			bchan->head %= MAX_DESCRIPTORS;
>
> --
> 2.34.1
>

  reply	other threads:[~2026-12-03 16:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:10 [PATCH net-next 0/3] net: wwan: qcom_bam_dmux: Add QMAP support Vishnu Santhosh
2026-12-03 16:10 ` [PATCH net-next 1/3] dmaengine: qcom: bam_dma: report residue for completed RX transfers Vishnu Santhosh
2026-12-03 16:19   ` Frank Li [this message]
2026-12-03 16:10 ` [PATCH net-next 2/3] net: wwan: qcom_bam_dmux: use DMA transfer size for RX packets Vishnu Santhosh
2026-12-03 16:10 ` [PATCH net-next 3/3] net: wwan: qcom_bam_dmux: enable QMAP if supported by the modem Vishnu Santhosh

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=axGWdAF-wBmvywQW@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=deepak.singh@oss.qualcomm.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=stephan@gerhold.net \
    --cc=vishnu.santhosh@oss.qualcomm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox