[PATCH v2] dmaengine: qcom: bam_dma: Avoid writing unavailable register

Md Sadre Alam posted 1 patch 1 year ago
There is a newer version of this series
drivers/dma/qcom/bam_dma.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
[PATCH v2] dmaengine: qcom: bam_dma: Avoid writing unavailable register
Posted by Md Sadre Alam 1 year ago
Avoid writing unavailable register in BAM-Lite mode.
BAM_DESC_CNT_TRSHLD register is unavailable in BAM-Lite
mode. Its only available in BAM-NDP mode. So avoid writing
this register for clients who is using BAM-Lite mode.

Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---

Change in [v2]

* Replace 0xff with REVISION_MASK in the statement
  bdev->bam_revision = val & REVISION_MASK

Change in [v1]

* Added initial patch

 drivers/dma/qcom/bam_dma.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
index d43a881e43b9..27c5b3b58f92 100644
--- a/drivers/dma/qcom/bam_dma.c
+++ b/drivers/dma/qcom/bam_dma.c
@@ -59,6 +59,9 @@ struct bam_desc_hw {
 #define DESC_FLAG_NWD BIT(12)
 #define DESC_FLAG_CMD BIT(11)
 
+#define BAM_LITE	0x13
+#define BAM_NDP		0x20
+
 struct bam_async_desc {
 	struct virt_dma_desc vd;
 
@@ -398,6 +401,7 @@ struct bam_device {
 
 	/* dma start transaction tasklet */
 	struct tasklet_struct task;
+	u32 bam_revision;
 };
 
 /**
@@ -441,8 +445,9 @@ static void bam_reset(struct bam_device *bdev)
 	writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
 
 	/* set descriptor threshold, start with 4 bytes */
-	writel_relaxed(DEFAULT_CNT_THRSHLD,
-			bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
+	if (bdev->bam_revision >= BAM_LITE && bdev->bam_revision < BAM_NDP)
+		writel_relaxed(DEFAULT_CNT_THRSHLD,
+			       bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
 
 	/* Enable default set of h/w workarounds, ie all except BAM_FULL_PIPE */
 	writel_relaxed(BAM_CNFG_BITS_DEFAULT, bam_addr(bdev, 0, BAM_CNFG_BITS));
@@ -1000,9 +1005,9 @@ static void bam_apply_new_config(struct bam_chan *bchan,
 			maxburst = bchan->slave.src_maxburst;
 		else
 			maxburst = bchan->slave.dst_maxburst;
-
-		writel_relaxed(maxburst,
-			       bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
+		if (bdev->bam_revision >= BAM_LITE && bdev->bam_revision < BAM_NDP)
+			writel_relaxed(maxburst,
+				       bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
 	}
 
 	bchan->reconfigure = 0;
@@ -1192,10 +1197,11 @@ static int bam_init(struct bam_device *bdev)
 	u32 val;
 
 	/* read revision and configuration information */
-	if (!bdev->num_ees) {
-		val = readl_relaxed(bam_addr(bdev, 0, BAM_REVISION));
+	val = readl_relaxed(bam_addr(bdev, 0, BAM_REVISION));
+	if (!bdev->num_ees)
 		bdev->num_ees = (val >> NUM_EES_SHIFT) & NUM_EES_MASK;
-	}
+
+	bdev->bam_revision = val & REVISION_MASK;
 
 	/* check that configured EE is within range */
 	if (bdev->ee >= bdev->num_ees)
-- 
2.34.1
Re: [PATCH v2] dmaengine: qcom: bam_dma: Avoid writing unavailable register
Posted by Bryan O'Donoghue 1 year ago
On 05/12/2024 12:00, Md Sadre Alam wrote:

The commit log:

> Avoid writing unavailable register in BAM-Lite mode.
> BAM_DESC_CNT_TRSHLD register is unavailable in BAM-Lite
> mode. Its only available in BAM-NDP mode. So avoid writing

and the action taken in the code:

> +	if (bdev->bam_revision >= BAM_LITE && bdev->bam_revision < BAM_NDP)
> +		writel_relaxed(DEFAULT_CNT_THRSHLD,

Really don't match up. You've said in your commit log 
BAM_DESC_CNT_TRSHLD is unavailable to the LITE module but, then you say 
if (bam_revision >= BAM_LITE...)

How can checking if the revision == BAM_LITE match up with the stated 
objective in your commit log => _not_ writing to DEFAULT_CNT_THRSHLD in 
lite mode ... ?

---
bod
Re: [PATCH v2] dmaengine: qcom: bam_dma: Avoid writing unavailable register
Posted by Md Sadre Alam 1 year ago

On 12/5/2024 5:58 PM, Bryan O'Donoghue wrote:
> On 05/12/2024 12:00, Md Sadre Alam wrote:
> 
> The commit log:
> 
>> Avoid writing unavailable register in BAM-Lite mode.
>> BAM_DESC_CNT_TRSHLD register is unavailable in BAM-Lite
>> mode. Its only available in BAM-NDP mode. So avoid writing
> 
> and the action taken in the code:
> 
>> +    if (bdev->bam_revision >= BAM_LITE && bdev->bam_revision < BAM_NDP)
>> +        writel_relaxed(DEFAULT_CNT_THRSHLD,
> 
> Really don't match up. You've said in your commit log 
> BAM_DESC_CNT_TRSHLD is unavailable to the LITE module but, then you say 
> if (bam_revision >= BAM_LITE...)
> 
> How can checking if the revision == BAM_LITE match up with the stated 
> objective in your commit log => _not_ writing to DEFAULT_CNT_THRSHLD in 
> lite mode ... ?
Thank you for pointing that out. I'll address this in the next revision.
> 
> ---
> bod