phone-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] Add support for metadata in bam_dma
@ 2021-09-19 14:33 Sireesh Kodali
  2021-09-19 14:33 ` [PATCH 1/1] dmaengine: qcom: bam_dma: Add support for metadata Sireesh Kodali
  2021-09-19 15:52 ` [PATCH 0/1] Add support for metadata in bam_dma Sirsireesh
  0 siblings, 2 replies; 4+ messages in thread
From: Sireesh Kodali @ 2021-09-19 14:33 UTC (permalink / raw)
  To: phone-devel, ~postmarketos/upstreaming, dmaengine, linux-kernel,
	linux-arm-msm
  Cc: Sireesh Kodali

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. To find the length of the packet, one must
instead read the bam_desc metadata. This patch adds support for sending
the size metadata over the dmaengine metadata api. Currently only the
dma size is stored in the metadata. Only client-side metadata is
supported for now, because host-side metadata doesn't make sense for
IPA, where more than one DMA descriptors could be waiting to be acked
and processed.

Sireesh Kodali (1):
  dmaengine: qcom: bam_dma: Add support for metadata

 drivers/dma/qcom/bam_dma.c | 74 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] dmaengine: qcom: bam_dma: Add support for metadata
  2021-09-19 14:33 [PATCH 0/1] Add support for metadata in bam_dma Sireesh Kodali
@ 2021-09-19 14:33 ` Sireesh Kodali
  2021-09-19 15:52 ` [PATCH 0/1] Add support for metadata in bam_dma Sirsireesh
  1 sibling, 0 replies; 4+ messages in thread
From: Sireesh Kodali @ 2021-09-19 14:33 UTC (permalink / raw)
  To: phone-devel, ~postmarketos/upstreaming, dmaengine, linux-kernel,
	linux-arm-msm
  Cc: Sireesh Kodali, Andy Gross, Bjorn Andersson, Vinod Koul

Some devices (like the IPA block) do not send the size of the DMA
transaction in band. Instead, the IPA driver needs to get the size of
the DMA transaction from the size of the BAM driver. This commit adds
support for attaching a pointer using the dmaengine API, to which it
will write the size of the DMA transaction.

Signed-off-by: Sireesh Kodali <sireeshkodali1@gmail.com>
---
 drivers/dma/qcom/bam_dma.c | 74 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
index cebec638a994..911c0f2e88a2 100644
--- a/drivers/dma/qcom/bam_dma.c
+++ b/drivers/dma/qcom/bam_dma.c
@@ -71,6 +71,11 @@ struct bam_async_desc {
 
 	struct bam_desc_hw *curr_desc;
 
+	/* first descriptor position in fifo */
+	size_t fifo_index;
+	void *metadata;
+	size_t meta_len;
+
 	/* list node for the desc in the bam_chan list of descriptors */
 	struct list_head desc_node;
 	enum dma_transfer_direction dir;
@@ -593,6 +598,65 @@ static int bam_slave_config(struct dma_chan *chan,
 	return 0;
 }
 
+/**
+ * bam_update_metadata - update metadata buffer
+ * @async_desc: BAM async descriptior
+ * @fifo: BAM FIFO to read metadata from
+ *
+ * Updates metadata buffer (transfer size) based on values
+ * read from FIFO descriptors
+ */
+
+static void bam_update_metadata(struct bam_async_desc *async_desc,
+				struct bam_desc_hw *fifo)
+{
+	unsigned int len = 0, i;
+
+	if (!async_desc->metadata)
+		return;
+
+	for (i = 0; i < async_desc->xfer_len; ++i) {
+		unsigned int pos = (i + async_desc->fifo_index) % MAX_DESCRIPTORS;
+
+		len += fifo[pos].size;
+	}
+
+	switch (async_desc->meta_len)  {
+	case 4:
+		*((u32 *)async_desc->metadata) = len;
+		break;
+	case 8:
+		*((u64 *)async_desc->metadata) = len;
+		break;
+	}
+}
+
+/**
+ * bam_attach_metadata - attach metadata buffer to the async descriptor
+ * @desc: async descriptor
+ * @data: buffer pointer
+ * @len: length of passed buffer
+ */
+static int bam_attach_metadata(struct dma_async_tx_descriptor *desc, void *data,
+			       size_t len)
+{
+	struct bam_async_desc *async_desc;
+
+	if (!data || !(len == 2 || len == 4 || len == 8))
+		return -EINVAL;
+
+	async_desc = container_of(desc, struct bam_async_desc, vd.tx);
+
+	async_desc->metadata = data;
+	async_desc->meta_len = len;
+
+	return 0;
+}
+
+static struct dma_descriptor_metadata_ops metadata_ops = {
+	.attach = bam_attach_metadata,
+};
+
 /**
  * bam_prep_slave_sg - Prep slave sg transaction
  *
@@ -672,6 +736,8 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,
 		} while (remainder > 0);
 	}
 
+	async_desc->vd.tx.metadata_ops = &metadata_ops;
+
 	return vchan_tx_prep(&bchan->vc, &async_desc->vd, flags);
 }
 
@@ -839,6 +905,11 @@ static u32 process_channel_irqs(struct bam_device *bdev)
 			 * it gets restarted by the tasklet
 			 */
 			if (!async_desc->num_desc) {
+				struct bam_desc_hw *fifo = PTR_ALIGN(bchan->fifo_virt,
+						sizeof(struct bam_desc_hw));
+
+				bam_update_metadata(async_desc, fifo);
+
 				vchan_cookie_complete(&async_desc->vd);
 			} else {
 				list_add(&async_desc->vd.node,
@@ -1053,6 +1124,8 @@ static void bam_start_dma(struct bam_chan *bchan)
 			       sizeof(struct bam_desc_hw));
 		}
 
+		async_desc->fifo_index = bchan->tail;
+
 		bchan->tail += async_desc->xfer_len;
 		bchan->tail %= MAX_DESCRIPTORS;
 		list_add_tail(&async_desc->desc_node, &bchan->desc_list);
@@ -1331,6 +1404,7 @@ static int bam_dma_probe(struct platform_device *pdev)
 	bdev->common.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
 	bdev->common.src_addr_widths = DMA_SLAVE_BUSWIDTH_4_BYTES;
 	bdev->common.dst_addr_widths = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	bdev->common.desc_metadata_modes = DESC_METADATA_CLIENT;
 	bdev->common.device_alloc_chan_resources = bam_alloc_chan;
 	bdev->common.device_free_chan_resources = bam_free_chan;
 	bdev->common.device_prep_slave_sg = bam_prep_slave_sg;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/1] Add support for metadata in bam_dma
  2021-09-19 14:33 [PATCH 0/1] Add support for metadata in bam_dma Sireesh Kodali
  2021-09-19 14:33 ` [PATCH 1/1] dmaengine: qcom: bam_dma: Add support for metadata Sireesh Kodali
@ 2021-09-19 15:52 ` Sirsireesh
  1 sibling, 0 replies; 4+ messages in thread
From: Sirsireesh @ 2021-09-19 15:52 UTC (permalink / raw)
  To: phone-devel, ~postmarketos/upstreaming, dmaengine, open list,
	open list:ARM/QUALCOMM SUPPORT
  Cc: Andy Gross, Bjorn Andersson, Vinod Koul

Hi,

Sorry, I accidentally sent this patch twice. Please ignore the second one
(i.e. the one I'm replying to now)

lkml link to original: https://lkml.org/lkml/2021/9/19/126

Sorry for the inconvenience
Sireesh



On Sun, Sep 19, 2021 at 8:03 PM Sireesh Kodali <sireeshkodali1@gmail.com> wrote:
>
> 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. To find the length of the packet, one must
> instead read the bam_desc metadata. This patch adds support for sending
> the size metadata over the dmaengine metadata api. Currently only the
> dma size is stored in the metadata. Only client-side metadata is
> supported for now, because host-side metadata doesn't make sense for
> IPA, where more than one DMA descriptors could be waiting to be acked
> and processed.
>
> Sireesh Kodali (1):
>   dmaengine: qcom: bam_dma: Add support for metadata
>
>  drivers/dma/qcom/bam_dma.c | 74 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 74 insertions(+)
>
> --
> 2.33.0
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] dmaengine: qcom: bam_dma: Add support for metadata
  2021-09-19 14:42 Sireesh Kodali
@ 2021-09-19 14:42 ` Sireesh Kodali
  0 siblings, 0 replies; 4+ messages in thread
From: Sireesh Kodali @ 2021-09-19 14:42 UTC (permalink / raw)
  To: phone-devel, ~postmarketos/upstreaming, dmaengine, linux-kernel,
	linux-arm-msm
  Cc: Sireesh Kodali, Andy Gross, Bjorn Andersson, Vinod Koul

Some devices (like the IPA block) do not send the size of the DMA
transaction in band. Instead, the IPA driver needs to get the size of
the DMA transaction from the size of the BAM driver. This commit adds
support for attaching a pointer using the dmaengine API, to which it
will write the size of the DMA transaction.

Signed-off-by: Sireesh Kodali <sireeshkodali1@gmail.com>
---
 drivers/dma/qcom/bam_dma.c | 74 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
index cebec638a994..911c0f2e88a2 100644
--- a/drivers/dma/qcom/bam_dma.c
+++ b/drivers/dma/qcom/bam_dma.c
@@ -71,6 +71,11 @@ struct bam_async_desc {
 
 	struct bam_desc_hw *curr_desc;
 
+	/* first descriptor position in fifo */
+	size_t fifo_index;
+	void *metadata;
+	size_t meta_len;
+
 	/* list node for the desc in the bam_chan list of descriptors */
 	struct list_head desc_node;
 	enum dma_transfer_direction dir;
@@ -593,6 +598,65 @@ static int bam_slave_config(struct dma_chan *chan,
 	return 0;
 }
 
+/**
+ * bam_update_metadata - update metadata buffer
+ * @async_desc: BAM async descriptior
+ * @fifo: BAM FIFO to read metadata from
+ *
+ * Updates metadata buffer (transfer size) based on values
+ * read from FIFO descriptors
+ */
+
+static void bam_update_metadata(struct bam_async_desc *async_desc,
+				struct bam_desc_hw *fifo)
+{
+	unsigned int len = 0, i;
+
+	if (!async_desc->metadata)
+		return;
+
+	for (i = 0; i < async_desc->xfer_len; ++i) {
+		unsigned int pos = (i + async_desc->fifo_index) % MAX_DESCRIPTORS;
+
+		len += fifo[pos].size;
+	}
+
+	switch (async_desc->meta_len)  {
+	case 4:
+		*((u32 *)async_desc->metadata) = len;
+		break;
+	case 8:
+		*((u64 *)async_desc->metadata) = len;
+		break;
+	}
+}
+
+/**
+ * bam_attach_metadata - attach metadata buffer to the async descriptor
+ * @desc: async descriptor
+ * @data: buffer pointer
+ * @len: length of passed buffer
+ */
+static int bam_attach_metadata(struct dma_async_tx_descriptor *desc, void *data,
+			       size_t len)
+{
+	struct bam_async_desc *async_desc;
+
+	if (!data || !(len == 2 || len == 4 || len == 8))
+		return -EINVAL;
+
+	async_desc = container_of(desc, struct bam_async_desc, vd.tx);
+
+	async_desc->metadata = data;
+	async_desc->meta_len = len;
+
+	return 0;
+}
+
+static struct dma_descriptor_metadata_ops metadata_ops = {
+	.attach = bam_attach_metadata,
+};
+
 /**
  * bam_prep_slave_sg - Prep slave sg transaction
  *
@@ -672,6 +736,8 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,
 		} while (remainder > 0);
 	}
 
+	async_desc->vd.tx.metadata_ops = &metadata_ops;
+
 	return vchan_tx_prep(&bchan->vc, &async_desc->vd, flags);
 }
 
@@ -839,6 +905,11 @@ static u32 process_channel_irqs(struct bam_device *bdev)
 			 * it gets restarted by the tasklet
 			 */
 			if (!async_desc->num_desc) {
+				struct bam_desc_hw *fifo = PTR_ALIGN(bchan->fifo_virt,
+						sizeof(struct bam_desc_hw));
+
+				bam_update_metadata(async_desc, fifo);
+
 				vchan_cookie_complete(&async_desc->vd);
 			} else {
 				list_add(&async_desc->vd.node,
@@ -1053,6 +1124,8 @@ static void bam_start_dma(struct bam_chan *bchan)
 			       sizeof(struct bam_desc_hw));
 		}
 
+		async_desc->fifo_index = bchan->tail;
+
 		bchan->tail += async_desc->xfer_len;
 		bchan->tail %= MAX_DESCRIPTORS;
 		list_add_tail(&async_desc->desc_node, &bchan->desc_list);
@@ -1331,6 +1404,7 @@ static int bam_dma_probe(struct platform_device *pdev)
 	bdev->common.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
 	bdev->common.src_addr_widths = DMA_SLAVE_BUSWIDTH_4_BYTES;
 	bdev->common.dst_addr_widths = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	bdev->common.desc_metadata_modes = DESC_METADATA_CLIENT;
 	bdev->common.device_alloc_chan_resources = bam_alloc_chan;
 	bdev->common.device_free_chan_resources = bam_free_chan;
 	bdev->common.device_prep_slave_sg = bam_prep_slave_sg;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-19 15:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19 14:33 [PATCH 0/1] Add support for metadata in bam_dma Sireesh Kodali
2021-09-19 14:33 ` [PATCH 1/1] dmaengine: qcom: bam_dma: Add support for metadata Sireesh Kodali
2021-09-19 15:52 ` [PATCH 0/1] Add support for metadata in bam_dma Sirsireesh
2021-09-19 14:42 Sireesh Kodali
2021-09-19 14:42 ` [PATCH 1/1] dmaengine: qcom: bam_dma: Add support for metadata Sireesh Kodali

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).