* [PATCH v2] dmaengine: qcom: bam_dma: Report the residue of packet
@ 2026-11-16 13:49 Nickolay Goppen
0 siblings, 0 replies; only message in thread
From: Nickolay Goppen @ 2026-11-16 13:49 UTC (permalink / raw)
To: Vinod Koul, Frank Li
Cc: linux-arm-msm, dmaengine, linux-kernel, 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>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-16 13:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 13:49 [PATCH v2] dmaengine: qcom: bam_dma: Report the residue of packet Nickolay Goppen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®