Skip to contentSkip to conversation

dma: cppi41: some trivial fixes and support for suspend/resume

PATCH Applied Daniel Mack 6 participants 21 messages Sep 22, 2013 – Oct 2, 2013 6 messages not in the archive dmaengine

lore
Share & tools
lore
#0 lore raw

v3 cover dma: cppi41: some trivial fixes and support for suspend/resume

Here are some patches to teach the cppi41 DMA driver support for suspend and resume. Patches 1-3 are simply cosmetic things that emerged during my debugging sessions.

Patch #4 is actually a real bugfix which I would like Sebastian Andrzej Siewior to have a look at. Quite frankly, the allocation scheme in this driver and the logic to determine a descriptor's index number seems quite complicated to me, but that's probably a different story. Allocating and freeing the exact same pointer more than once is certainly a bug.

Patch #5 adds support for suspend and resume. As the commit log says, the code needed to achive this is the result of a trial-and-error session. This is the minimum that's I'm left with now and which works for me.

On a different note, I'm also working on patches for the musb core to make it suspend and resume. Currently, I still have to rmmod/insmod musb_dsps before/after the resume cycle, but I'm hoping to make progress here soon.

Thanks,
Daniel

v2 -> v3:
* Patch #5: kill DEV_PM_OPS macro hack and fix a typo (Reported by Sergei Shtylyov)

v1 -> v2:
* Patch #5: depend on CONFIG_PM_SLEEP rather than on CONFIG_PM and use SIMPLE_DEV_PM_OPS (Reported by Sergei Shtylyov)

Daniel Mack (5):
dma: cppi41: pass around device instead of platform_device
dma: cppi41: s/deinit_cpii41/deinit_cppi41/
dma: cppi41: add shortcut to &pdev->dev in cppi41_dma_probe()
dma: cppi41: only allocate descriptor memory once
dma: cppi41: add support for suspend and resume

 drivers/dma/cppi41.c | 115 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 70 insertions(+), 45 deletions(-)
Signature · 1 line
1.8.3.1

A message that is not in the archive (sent off-list or not yet received): 1379861404-8250-1-git-send-email-zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH v3 1/5 dma: cppi41: pass around device instead of platform_device

Instead of passing around struct plafform_device, use struct device and save one level of dereferencing. This affects the following functions:

* cppi41_add_chans
* purge_descs
* deinit_cpii41
* init_descs
* init_cppi41
* cppi_glue_infos

It's just a cosmetic cleanup that makes the code more readable.

---
 drivers/dma/cppi41.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/dma/cppi41.c +20 -20
index 7c82b92..53d1d31 100644
@@ -674,14 +674,14 @@ static void cleanup_chans(struct cppi41_dd *cdd)
 	}
 }
 
-static int cppi41_add_chans(struct platform_device *pdev, struct cppi41_dd *cdd)
+static int cppi41_add_chans(struct device *dev, struct cppi41_dd *cdd)
 {
 	struct cppi41_channel *cchan;
 	int i;
 	int ret;
 	u32 n_chans;
 
-	ret = of_property_read_u32(pdev->dev.of_node, "#dma-channels",
+	ret = of_property_read_u32(dev->of_node, "#dma-channels",
 			&n_chans);
 	if (ret)
 		return ret;
@@ -719,7 +719,7 @@ err:
 	return -ENOMEM;
 }
 
-static void purge_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
+static void purge_descs(struct device *dev, struct cppi41_dd *cdd)
 {
 	unsigned int mem_decs;
 	int i;
@@ -731,7 +731,7 @@ static void purge_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
 		cppi_writel(0, cdd->qmgr_mem + QMGR_MEMBASE(i));
 		cppi_writel(0, cdd->qmgr_mem + QMGR_MEMCTRL(i));
 
-		dma_free_coherent(&pdev->dev, mem_decs, cdd->cd,
+		dma_free_coherent(dev, mem_decs, cdd->cd,
 				cdd->descs_phys);
 	}
 }
@@ -741,19 +741,19 @@ static void disable_sched(struct cppi41_dd *cdd)
 	cppi_writel(0, cdd->sched_mem + DMA_SCHED_CTRL);
 }
 
-static void deinit_cpii41(struct platform_device *pdev, struct cppi41_dd *cdd)
+static void deinit_cpii41(struct device *dev, struct cppi41_dd *cdd)
 {
 	disable_sched(cdd);
 
-	purge_descs(pdev, cdd);
+	purge_descs(dev, cdd);
 
 	cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM0_BASE);
 	cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM0_BASE);
-	dma_free_coherent(&pdev->dev, QMGR_SCRATCH_SIZE, cdd->qmgr_scratch,
+	dma_free_coherent(dev, QMGR_SCRATCH_SIZE, cdd->qmgr_scratch,
 			cdd->scratch_phys);
 }
 
-static int init_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
+static int init_descs(struct device *dev, struct cppi41_dd *cdd)
 {
 	unsigned int desc_size;
 	unsigned int mem_decs;
@@ -777,7 +777,7 @@ static int init_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
 		reg |= ilog2(ALLOC_DECS_NUM) - 5;
 
 		BUILD_BUG_ON(DESCS_AREAS != 1);
-		cdd->cd = dma_alloc_coherent(&pdev->dev, mem_decs,
+		cdd->cd = dma_alloc_coherent(dev, mem_decs,
 				&cdd->descs_phys, GFP_KERNEL);
 		if (!cdd->cd)
 			return -ENOMEM;
@@ -813,12 +813,12 @@ static void init_sched(struct cppi41_dd *cdd)
 	cppi_writel(reg, cdd->sched_mem + DMA_SCHED_CTRL);
 }
 
-static int init_cppi41(struct platform_device *pdev, struct cppi41_dd *cdd)
+static int init_cppi41(struct device *dev, struct cppi41_dd *cdd)
 {
 	int ret;
 
 	BUILD_BUG_ON(QMGR_SCRATCH_SIZE > ((1 << 14) - 1));
-	cdd->qmgr_scratch = dma_alloc_coherent(&pdev->dev, QMGR_SCRATCH_SIZE,
+	cdd->qmgr_scratch = dma_alloc_coherent(dev, QMGR_SCRATCH_SIZE,
 			&cdd->scratch_phys, GFP_KERNEL);
 	if (!cdd->qmgr_scratch)
 		return -ENOMEM;
@@ -827,7 +827,7 @@ static int init_cppi41(struct platform_device *pdev, struct cppi41_dd *cdd)
 	cppi_writel(QMGR_SCRATCH_SIZE, cdd->qmgr_mem + QMGR_LRAM_SIZE);
 	cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM1_BASE);
 
-	ret = init_descs(pdev, cdd);
+	ret = init_descs(dev, cdd);
 	if (ret)
 		goto err_td;
 
@@ -835,7 +835,7 @@ static int init_cppi41(struct platform_device *pdev, struct cppi41_dd *cdd)
 	init_sched(cdd);
 	return 0;
 err_td:
-	deinit_cpii41(pdev, cdd);
+	deinit_cpii41(dev, cdd);
 	return ret;
 }
 
@@ -914,11 +914,11 @@ static const struct of_device_id cppi41_dma_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, cppi41_dma_ids);
 
-static const struct cppi_glue_infos *get_glue_info(struct platform_device *pdev)
+static const struct cppi_glue_infos *get_glue_info(struct device *dev)
 {
 	const struct of_device_id *of_id;
 
-	of_id = of_match_node(cppi41_dma_ids, pdev->dev.of_node);
+	of_id = of_match_node(cppi41_dma_ids, dev->of_node);
 	if (!of_id)
 		return NULL;
 	return of_id->data;
@@ -931,7 +931,7 @@ static int cppi41_dma_probe(struct platform_device *pdev)
 	int irq;
 	int ret;
 
-	glue_info = get_glue_info(pdev);
+	glue_info = get_glue_info(&pdev->dev);
 	if (!glue_info)
 		return -EINVAL;
 
@@ -970,11 +970,11 @@ static int cppi41_dma_probe(struct platform_device *pdev)
 	cdd->queues_tx = glue_info->queues_tx;
 	cdd->td_queue = glue_info->td_queue;
 
-	ret = init_cppi41(pdev, cdd);
+	ret = init_cppi41(&pdev->dev, cdd);
 	if (ret)
 		goto err_init_cppi;
 
-	ret = cppi41_add_chans(pdev, cdd);
+	ret = cppi41_add_chans(&pdev->dev, cdd);
 	if (ret)
 		goto err_chans;
 
@@ -1009,7 +1009,7 @@ err_irq:
 	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
 	cleanup_chans(cdd);
 err_chans:
-	deinit_cpii41(pdev, cdd);
+	deinit_cpii41(&pdev->dev, cdd);
 err_init_cppi:
 	pm_runtime_put(&pdev->dev);
 err_get_sync:
@@ -1033,7 +1033,7 @@ static int cppi41_dma_remove(struct platform_device *pdev)
 	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
 	free_irq(cdd->irq, cdd);
 	cleanup_chans(cdd);
-	deinit_cpii41(pdev, cdd);
+	deinit_cpii41(&pdev->dev, cdd);
 	iounmap(cdd->usbss_mem);
 	iounmap(cdd->ctrl_mem);
 	iounmap(cdd->sched_mem);
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Applied
#3 lore raw

Re: [PATCH v3 1/5] dma: cppi41: pass around device instead of platform_device

Quoted 11 lines · Daniel Mack

Instead of passing around struct plafform_device, use struct device and save one level of dereferencing. This affects the following functions:

* cppi41_add_chans
* purge_descs
* deinit_cpii41
* init_descs
* init_cppi41
* cppi_glue_infos

It's just a cosmetic cleanup that makes the code more readable.

Applied, thanks

~Vinod

#4 lore raw

PATCH v3 2/5 dma: cppi41: s/deinit_cpii41/deinit_cppi41/

In reply to Daniel Mack

Fix a misspelled function name.

---
 drivers/dma/cppi41.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/dma/cppi41.c +4 -4
index 53d1d31..5469a15 100644
@@ -741,7 +741,7 @@ static void disable_sched(struct cppi41_dd *cdd)
 	cppi_writel(0, cdd->sched_mem + DMA_SCHED_CTRL);
 }
 
-static void deinit_cpii41(struct device *dev, struct cppi41_dd *cdd)
+static void deinit_cppi41(struct device *dev, struct cppi41_dd *cdd)
 {
 	disable_sched(cdd);
 
@@ -835,7 +835,7 @@ static int init_cppi41(struct device *dev, struct cppi41_dd *cdd)
 	init_sched(cdd);
 	return 0;
 err_td:
-	deinit_cpii41(dev, cdd);
+	deinit_cppi41(dev, cdd);
 	return ret;
 }
 
@@ -1009,7 +1009,7 @@ err_irq:
 	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
 	cleanup_chans(cdd);
 err_chans:
-	deinit_cpii41(&pdev->dev, cdd);
+	deinit_cppi41(&pdev->dev, cdd);
 err_init_cppi:
 	pm_runtime_put(&pdev->dev);
 err_get_sync:
@@ -1033,7 +1033,7 @@ static int cppi41_dma_remove(struct platform_device *pdev)
 	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
 	free_irq(cdd->irq, cdd);
 	cleanup_chans(cdd);
-	deinit_cpii41(&pdev->dev, cdd);
+	deinit_cppi41(&pdev->dev, cdd);
 	iounmap(cdd->usbss_mem);
 	iounmap(cdd->ctrl_mem);
 	iounmap(cdd->sched_mem);
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v3 3/5 dma: cppi41: add shortcut to &pdev->dev in cppi41_dma_probe()

In reply to Daniel Mack

Makes the code more readable and compact. No functional change.

---
 drivers/dma/cppi41.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
drivers/dma/cppi41.c +17 -16
index 5469a15..d689706 100644
@@ -927,11 +927,12 @@ static const struct cppi_glue_infos *get_glue_info(struct device *dev)
 static int cppi41_dma_probe(struct platform_device *pdev)
 {
 	struct cppi41_dd *cdd;
+	struct device *dev = &pdev->dev;
 	const struct cppi_glue_infos *glue_info;
 	int irq;
 	int ret;
 
-	glue_info = get_glue_info(&pdev->dev);
+	glue_info = get_glue_info(dev);
 	if (!glue_info)
 		return -EINVAL;
 
@@ -946,14 +947,14 @@ static int cppi41_dma_probe(struct platform_device *pdev)
 	cdd->ddev.device_issue_pending = cppi41_dma_issue_pending;
 	cdd->ddev.device_prep_slave_sg = cppi41_dma_prep_slave_sg;
 	cdd->ddev.device_control = cppi41_dma_control;
-	cdd->ddev.dev = &pdev->dev;
+	cdd->ddev.dev = dev;
 	INIT_LIST_HEAD(&cdd->ddev.channels);
 	cpp41_dma_info.dma_cap = cdd->ddev.cap_mask;
 
-	cdd->usbss_mem = of_iomap(pdev->dev.of_node, 0);
-	cdd->ctrl_mem = of_iomap(pdev->dev.of_node, 1);
-	cdd->sched_mem = of_iomap(pdev->dev.of_node, 2);
-	cdd->qmgr_mem = of_iomap(pdev->dev.of_node, 3);
+	cdd->usbss_mem = of_iomap(dev->of_node, 0);
+	cdd->ctrl_mem = of_iomap(dev->of_node, 1);
+	cdd->sched_mem = of_iomap(dev->of_node, 2);
+	cdd->qmgr_mem = of_iomap(dev->of_node, 3);
 
 	if (!cdd->usbss_mem || !cdd->ctrl_mem || !cdd->sched_mem ||
 			!cdd->qmgr_mem) {
@@ -961,8 +962,8 @@ static int cppi41_dma_probe(struct platform_device *pdev)
 		goto err_remap;
 	}
 
-	pm_runtime_enable(&pdev->dev);
-	ret = pm_runtime_get_sync(&pdev->dev);
+	pm_runtime_enable(dev);
+	ret = pm_runtime_get_sync(dev);
 	if (ret)
 		goto err_get_sync;
 
@@ -970,22 +971,22 @@ static int cppi41_dma_probe(struct platform_device *pdev)
 	cdd->queues_tx = glue_info->queues_tx;
 	cdd->td_queue = glue_info->td_queue;
 
-	ret = init_cppi41(&pdev->dev, cdd);
+	ret = init_cppi41(dev, cdd);
 	if (ret)
 		goto err_init_cppi;
 
-	ret = cppi41_add_chans(&pdev->dev, cdd);
+	ret = cppi41_add_chans(dev, cdd);
 	if (ret)
 		goto err_chans;
 
-	irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
+	irq = irq_of_parse_and_map(dev->of_node, 0);
 	if (!irq)
 		goto err_irq;
 
 	cppi_writel(USBSS_IRQ_PD_COMP, cdd->usbss_mem + USBSS_IRQ_ENABLER);
 
 	ret = request_irq(irq, glue_info->isr, IRQF_SHARED,
-			dev_name(&pdev->dev), cdd);
+			dev_name(dev), cdd);
 	if (ret)
 		goto err_irq;
 	cdd->irq = irq;
@@ -994,7 +995,7 @@ static int cppi41_dma_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_dma_reg;
 
-	ret = of_dma_controller_register(pdev->dev.of_node,
+	ret = of_dma_controller_register(dev->of_node,
 			cppi41_dma_xlate, &cpp41_dma_info);
 	if (ret)
 		goto err_of;
@@ -1009,11 +1010,11 @@ err_irq:
 	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
 	cleanup_chans(cdd);
 err_chans:
-	deinit_cppi41(&pdev->dev, cdd);
+	deinit_cppi41(dev, cdd);
 err_init_cppi:
-	pm_runtime_put(&pdev->dev);
+	pm_runtime_put(dev);
 err_get_sync:
-	pm_runtime_disable(&pdev->dev);
+	pm_runtime_disable(dev);
 	iounmap(cdd->usbss_mem);
 	iounmap(cdd->ctrl_mem);
 	iounmap(cdd->sched_mem);
Signature · 1 line
1.8.3.1

A message that is not in the archive (sent off-list or not yet received): 1379861404-8250-4-git-send-email-zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

Applied
#8 lore raw

Re: [PATCH v3 3/5] dma: cppi41: add shortcut to &pdev->dev in cppi41_dma_probe()

Quoted 3 lines · Daniel Mack

Makes the code more readable and compact. No functional change.

Applied, thanks

~Vinod

Signature · 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

PATCH v3 4/5 dma: cppi41: only allocate descriptor memory once

In reply to Daniel Mack

cdd->cd and cdd->descs_phys are allocated DESCS_AREAS times from init_descs() and freed as often from purge_descs(). This leads to both memory leaks and double-frees.

Fix this by pulling the calls to dma_{alloc,free}_coherent() out of the loops.

While at it, remove the intermediate variable mem_decs (I guess it was only there to make the code comply to the 80-chars CodingSytle rule).

---
 drivers/dma/cppi41.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/dma/cppi41.c +10 -15
index d689706..3347321 100644
@@ -727,13 +727,12 @@ static void purge_descs(struct device *dev, struct cppi41_dd *cdd)
 	mem_decs = ALLOC_DECS_NUM * sizeof(struct cppi41_desc);
 
 	for (i = 0; i < DESCS_AREAS; i++) {
-
 		cppi_writel(0, cdd->qmgr_mem + QMGR_MEMBASE(i));
 		cppi_writel(0, cdd->qmgr_mem + QMGR_MEMCTRL(i));
-
-		dma_free_coherent(dev, mem_decs, cdd->cd,
-				cdd->descs_phys);
 	}
+
+	dma_free_coherent(dev, ALLOC_DECS_NUM * sizeof(struct cppi41_desc),
+			  cdd->cd, cdd->descs_phys);
 }
 
 static void disable_sched(struct cppi41_dd *cdd)
@@ -755,8 +754,7 @@ static void deinit_cppi41(struct device *dev, struct cppi41_dd *cdd)
 
 static int init_descs(struct device *dev, struct cppi41_dd *cdd)
 {
-	unsigned int desc_size;
-	unsigned int mem_decs;
+	unsigned int desc_size = sizeof(struct cppi41_desc);
 	int i;
 	u32 reg;
 	u32 idx;
@@ -765,28 +763,25 @@ static int init_descs(struct device *dev, struct cppi41_dd *cdd)
 			(sizeof(struct cppi41_desc) - 1));
 	BUILD_BUG_ON(sizeof(struct cppi41_desc) < 32);
 	BUILD_BUG_ON(ALLOC_DECS_NUM < 32);
+	BUILD_BUG_ON(DESCS_AREAS != 1);
 
-	desc_size = sizeof(struct cppi41_desc);
-	mem_decs = ALLOC_DECS_NUM * desc_size;
+	cdd->cd = dma_alloc_coherent(dev, ALLOC_DECS_NUM * desc_size,
+				     &cdd->descs_phys, GFP_KERNEL);
+	if (!cdd->cd)
+		return -ENOMEM;
 
 	idx = 0;
 	for (i = 0; i < DESCS_AREAS; i++) {
-
 		reg = idx << QMGR_MEMCTRL_IDX_SH;
 		reg |= (ilog2(desc_size) - 5) << QMGR_MEMCTRL_DESC_SH;
 		reg |= ilog2(ALLOC_DECS_NUM) - 5;
 
-		BUILD_BUG_ON(DESCS_AREAS != 1);
-		cdd->cd = dma_alloc_coherent(dev, mem_decs,
-				&cdd->descs_phys, GFP_KERNEL);
-		if (!cdd->cd)
-			return -ENOMEM;
-
 		cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
 		cppi_writel(reg, cdd->qmgr_mem + QMGR_MEMCTRL(i));
 
 		idx += ALLOC_DECS_NUM;
 	}
+
 	return 0;
 }
 
Signature · 1 line
1.8.3.1
#10 lore raw

Re: [PATCH v3 4/5] dma: cppi41: only allocate descriptor memory once

Quoted 10 lines · Daniel Mack

cdd->cd and cdd->descs_phys are allocated DESCS_AREAS times from init_descs() and freed as often from purge_descs(). This leads to both memory leaks and double-frees.

Fix this by pulling the calls to dma_{alloc,free}_coherent() out of the loops.

While at it, remove the intermediate variable mem_decs (I guess it was only there to make the code comply to the 80-chars CodingSytle rule).

Looks fine, Sebastian cna you test it pls

~Vinod

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

Re: [PATCH v3 4/5] dma: cppi41: only allocate descriptor memory once

Quoted 1 line · Vinod Koul

Looks fine, Sebastian cna you test it pls

Just noticed that you already applied some of them. I just got back after a few weeks of. Will review & test as soon as I get to it.

Quoted 3 lines

~Vinod

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Re: [PATCH v3 4/5] dma: cppi41: only allocate descriptor memory once

Quoted 5 lines · Sebastian Andrzej Siewior
Quoted 1 line · Vinod Koul

Looks fine, Sebastian cna you test it pls

Just noticed that you already applied some of them. I just got back after a few weeks of. Will review & test as soon as I get to it.

Yes, the first three were trvial, 5th one looked fine to me !

~Vinod

A message that is not in the archive (sent off-list or not yet received): 1379861404-8250-5-git-send-email-zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#15 lore raw

Re: [PATCH v3 4/5] dma: cppi41: only allocate descriptor memory once

Quoted 11 lines · * Daniel Mack | 2013-09-22 16:50:03 [+0200]:

cdd->cd and cdd->descs_phys are allocated DESCS_AREAS times from init_descs() and freed as often from purge_descs(). This leads to both memory leaks and double-frees.

Fix this by pulling the calls to dma_{alloc,free}_coherent() out of the loops.

While at it, remove the intermediate variable mem_decs (I guess it was only there to make the code comply to the 80-chars CodingSytle rule).

Please don't merge the memory descriptors. The idea was initially to allocate multiple small descriptors instead one big. The descrriptor turned out to be enough so it looks like the way it looks. If you want to clean this up, please either remove the for loop and allocate only one memory area or please prepare for multiple descripors (I think two is the upper limit).

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw

Re: [PATCH v3 4/5] dma: cppi41: only allocate descriptor memory once

Hi Sebastian,

sorry for the long delay, I got distracted by other things.

Quoted 12 lines · Sebastian Andrzej Siewior
Quoted 10 lines · * Daniel Mack | 2013-09-22 16:50:03 [+0200]:

cdd->cd and cdd->descs_phys are allocated DESCS_AREAS times from init_descs() and freed as often from purge_descs(). This leads to both memory leaks and double-frees.

Fix this by pulling the calls to dma_{alloc,free}_coherent() out of the loops.

While at it, remove the intermediate variable mem_decs (I guess it was only there to make the code comply to the 80-chars CodingSytle rule).

Quoted 8 lines
Quoted 1 line

Please don't merge the memory descriptors. The idea was initially to allocate multiple small descriptors instead one big. The descrriptor turned out to be enough so it looks like the way it looks. If you want to clean this up, please either remove the for loop and allocate only one memory area or please prepare for multiple descripors (I think two is the upper limit).

Well, I didn't merge the descriptors. Look again at my changes please.

A simplified version of the code as it stands is:

  for (i = 0; i < DESCS_AREAS; i++)
    cdd->cd = dma_alloc_coherent(dev, ..., &cdd->descs_phys, GFP_KERNEL);

  for (i = 0; i < DESCS_AREAS; i++)
    dma_free_coherent(dev, mem_decs, cdd->cd, cdd->descs_phys);

So you're effectively allocating and freeing the same pointer DESCS_AREAS times, which is certainly not what you wanted.

And this just doesn't hit you because DESCS_AREAS is always 1:

  BUILD_BUG_ON(DESCS_AREAS != 1);

So, after all, my patch doesn't really change any of the runtime behaviour. Consider it a cosmetic cleanup if you wish :)

Thanks,
Daniel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#18 lore raw

Re: [PATCH v3 4/5] dma: cppi41: only allocate descriptor memory once

Quoted 1 line · Daniel Mack

Hi Sebastian,

Hi Daniel,

Quoted 1 line

sorry for the long delay, I got distracted by other things.

No problem.

Quoted 4 lines

Well, I didn't merge the descriptors. Look again at my changes please.

A simplified version of the code as it stands is:

Quoted 8 lines
  for (i = 0; i < DESCS_AREAS; i++)
    cdd->cd = dma_alloc_coherent(dev, ..., &cdd->descs_phys, GFP_KERNEL);

  for (i = 0; i < DESCS_AREAS; i++)
    dma_free_coherent(dev, mem_decs, cdd->cd, cdd->descs_phys);

So you're effectively allocating and freeing the same pointer DESCS_AREAS times, which is certainly not what you wanted.

Well, no but since DESCS_AREAS is 1 it does not matter.

Quoted 2 lines

And this just doesn't hit you because DESCS_AREAS is always 1:

exactly.

Quoted 6 lines
  BUILD_BUG_ON(DESCS_AREAS != 1);

So, after all, my patch doesn't really change any of the runtime behaviour. Consider it a cosmetic cleanup if you wish :)

But it looks strange (in my opinion at least). But now, that I look again at it yes you moved the alloc out of the loop and replaced mem_decs with the computation. So nothing changed but you moved it outside.

Right I think one desc area should be enough so I would just remove the for loop and DESCS_AREAS as well. How does this sound to you?

Quoted 5 lines

Thanks,
Daniel

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#19 lore raw

Re: [PATCH v3 4/5] dma: cppi41: only allocate descriptor memory once

Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 7 lines · Daniel Mack

A simplified version of the code as it stands is:

  for (i = 0; i < DESCS_AREAS; i++)
    cdd->cd = dma_alloc_coherent(dev, ..., &cdd->descs_phys, GFP_KERNEL);

  for (i = 0; i < DESCS_AREAS; i++)
    dma_free_coherent(dev, mem_decs, cdd->cd, cdd->descs_phys);

...

Quoted 4 lines
Quoted 2 lines

So, after all, my patch doesn't really change any of the runtime behaviour. Consider it a cosmetic cleanup if you wish :)

But it looks strange (in my opinion at least).

I still disagree, but maybe that doesn't matter any more, because ...

Quoted 7 lines

But now, that I look
again at it yes you moved the alloc out of the loop and replaced mem_decs with the computation. So nothing changed but you moved it outside.

Right I think one desc area should be enough so I would just remove the for loop and DESCS_AREAS as well. How does this sound to you?

That sound's like a good idea. Everything that make the driver smaller and easier to understand is certainly a good thing :)

So we can drop this patch favor of your cleanup. However, I appreciate if you did it on top of the second round of patches I sent today please, because my resume() implementation uses DESCS_AREAS as well.

Thanks,
Daniel

#20 lore raw

Re: [PATCH v3 4/5] dma: cppi41: only allocate descriptor memory once

Quoted 6 lines · Daniel Mack

That sound's like a good idea. Everything that make the driver smaller and easier to understand is certainly a good thing :)

So we can drop this patch favor of your cleanup. However, I appreciate if you did it on top of the second round of patches I sent today please, because my resume() implementation uses DESCS_AREAS as well.

Okay, no problem. Let me look at those and once they are merged I do the cleanup.

Quoted 4 lines

Thanks,
Daniel

Sebastian

#21 lore raw

PATCH v3 5/5 dma: cppi41: add support for suspend and resume

In reply to Daniel Mack

This patch adds support for suspend/resume functionality to the cppi41 DMA driver. The steps necessary to make the system resume properly were figured out by trial-and-error. The code as it stands now is the minimum that has to be done to put the musb host system on an AM33xx system into an operable state after resume.

---
 drivers/dma/cppi41.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/dma/cppi41.c +29 -0
index 3347321..89decc9 100644
@@ -1040,12 +1040,41 @@ static int cppi41_dma_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int cppi41_suspend(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+
+	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
+	disable_sched(cdd);
+
+	return 0;
+}
+
+static int cppi41_resume(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+	int i;
+
+	for (i = 0; i < DESCS_AREAS; i++)
+		cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
+
+	init_sched(cdd);
+	cppi_writel(USBSS_IRQ_PD_COMP, cdd->usbss_mem + USBSS_IRQ_ENABLER);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(cppi41_pm_ops, cppi41_suspend, cppi41_resume);
+
 static struct platform_driver cpp41_dma_driver = {
 	.probe  = cppi41_dma_probe,
 	.remove = cppi41_dma_remove,
 	.driver = {
 		.name = "cppi41-dma-engine",
 		.owner = THIS_MODULE,
+		.pm = &cppi41_pm_ops,
 		.of_match_table = of_match_ptr(cppi41_dma_ids),
 	},
 };
Signature · 1 line
1.8.3.1

A message that is not in the archive (sent off-list or not yet received): 1379861404-8250-6-git-send-email-zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#23 lore raw

Re: [PATCH v3 5/5] dma: cppi41: add support for suspend and resume

Quoted 16 lines · Daniel Mack

This patch adds support for suspend/resume functionality to the cppi41 DMA driver. The steps necessary to make the system resume properly were figured out by trial-and-error. The code as it stands now is the minimum that has to be done to put the musb host system on an AM33xx system into an operable state after resume.

---
 drivers/dma/cppi41.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/dma/cppi41.c +0 -0
index 3347321..89decc9 100644

drivers/dma/cppi41.c static int cppi41_dma_remove(struct platform_device *pdev) · line 1043

Quoted 4 lines
drivers/dma/cppi41.c +1 -0
@@ -1040,12 +1040,41 @@ static int cppi41_dma_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP

ahhhh

Quoted 16 lines
drivers/dma/cppi41.c +16 -0
+static int cppi41_suspend(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+
+	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
+	disable_sched(cdd);
+
+	return 0;
+}
+
+static int cppi41_resume(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+	int i;
+
+	for (i = 0; i < DESCS_AREAS; i++)

drivers/dma/cppi41.c static int cppi41_dma_remove(struct platform_device *pdev) · line 1069

Quoted 10 lines
drivers/dma/cppi41.c +10 -0
+		cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
+
+	init_sched(cdd);
+	cppi_writel(USBSS_IRQ_PD_COMP, cdd->usbss_mem + USBSS_IRQ_ENABLER);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(cppi41_pm_ops, cppi41_suspend, cppi41_resume);

Here is the macro in pm.h

#ifdef CONFIG_PM_SLEEP

#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
        .suspend = suspend_fn, \
        .resume = resume_fn, \
        .freeze = suspend_fn, \
        .thaw = resume_fn, \
        .poweroff = suspend_fn, \
        .restore = resume_fn,

#else
#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) #endif

/*
* Use this if you want to use the same suspend and resume callbacks for suspend
* to RAM and hibernation.
*/
#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \

const struct dev_pm_ops name = { \
        SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \

Now since you are using the macro there should be no need to wrap ifdef around your code, the macro will take care of it.

~Vinod

Quoted 14 lines
drivers/dma/cppi41.c +2 -0
+
 static struct platform_driver cpp41_dma_driver = {
 	.probe  = cppi41_dma_probe,
 	.remove = cppi41_dma_remove,
 	.driver = {
 		.name = "cppi41-dma-engine",
 		.owner = THIS_MODULE,
+		.pm = &cppi41_pm_ops,
 		.of_match_table = of_match_ptr(cppi41_dma_ids),
 	},
 };
Signature · 1 line
1.8.3.1
Signature · 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#24 lore raw

Re: [PATCH v3 5/5] dma: cppi41: add support for suspend and resume

Quoted 32 lines · Vinod Koul
Quoted 1 line · Daniel Mack

+#ifdef CONFIG_PM_SLEEP

ahhhh

Quoted 16 lines
drivers/dma/cppi41.c +16 -0
+static int cppi41_suspend(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+
+	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
+	disable_sched(cdd);
+
+	return 0;
+}
+
+static int cppi41_resume(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+	int i;
+
+	for (i = 0; i < DESCS_AREAS; i++)

drivers/dma/cppi41.c static int cppi41_dma_remove(struct platform_device *pdev) · line 1069

Quoted 10 lines
drivers/dma/cppi41.c +10 -0
+		cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
+
+	init_sched(cdd);
+	cppi_writel(USBSS_IRQ_PD_COMP, cdd->usbss_mem + USBSS_IRQ_ENABLER);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(cppi41_pm_ops, cppi41_suspend, cppi41_resume);

Here is the macro in pm.h

[...]

Quoted 2 lines

Now since you are using the macro there should be no need to wrap ifdef around your code, the macro will take care of it.

Well yes, which is why I put the macro itself *outside* of the #ifdef block. Without that #ifdef, however, and with CONFIG_PM_SLEEP unset, I get:

drivers/dma/cppi41.c:1043:12: warning: ‘cppi41_suspend’ defined but not used [-Wunused-function]
static int cppi41_suspend(struct device *dev)

            ^
drivers/dma/cppi41.c:1053:12: warning: ‘cppi41_resume’ defined but not
used [-Wunused-function]
 static int cppi41_resume(struct device *dev)
            ^

... which doesn't surprise me much. Or do I still not get your point?

Thanks,
Daniel

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#25 lore raw

Re: [PATCH v3 5/5] dma: cppi41: add support for suspend and resume

Quoted 45 lines · Daniel Mack
Quoted 32 lines · Vinod Koul
Quoted 1 line · Daniel Mack

+#ifdef CONFIG_PM_SLEEP

ahhhh

Quoted 16 lines
drivers/dma/cppi41.c +16 -0
+static int cppi41_suspend(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+
+	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
+	disable_sched(cdd);
+
+	return 0;
+}
+
+static int cppi41_resume(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+	int i;
+
+	for (i = 0; i < DESCS_AREAS; i++)

drivers/dma/cppi41.c static int cppi41_dma_remove(struct platform_device *pdev) · line 1069

Quoted 10 lines
drivers/dma/cppi41.c +10 -0
+		cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
+
+	init_sched(cdd);
+	cppi_writel(USBSS_IRQ_PD_COMP, cdd->usbss_mem + USBSS_IRQ_ENABLER);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(cppi41_pm_ops, cppi41_suspend, cppi41_resume);

Here is the macro in pm.h

[...]

Quoted 2 lines

Now since you are using the macro there should be no need to wrap ifdef around your code, the macro will take care of it.

Well yes, which is why I put the macro itself *outside* of the #ifdef block. Without that #ifdef, however, and with CONFIG_PM_SLEEP unset, I get:

drivers/dma/cppi41.c:1043:12: warning: ‘cppi41_suspend’ defined but not used [-Wunused-function]
static int cppi41_suspend(struct device *dev)

Quoted 7 lines
            ^
drivers/dma/cppi41.c:1053:12: warning: ‘cppi41_resume’ defined but not
used [-Wunused-function]
 static int cppi41_resume(struct device *dev)
            ^

... which doesn't surprise me much. Or do I still not get your point?

And this is what i had expected... I was thinking we should ignore this, but this is better too, so I will try to apply this now

~Vinod

Signature · 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Applied
#26 lore raw

Re: [PATCH v3 5/5] dma: cppi41: add support for suspend and resume

In reply to Daniel Mack
Quoted 5 lines · Daniel Mack

This patch adds support for suspend/resume functionality to the cppi41 DMA driver. The steps necessary to make the system resume properly were figured out by trial-and-error. The code as it stands now is the minimum that has to be done to put the musb host system on an AM33xx system into an operable state after resume.

Applied, thanks

~Vinod

Quoted 55 lines
---
 drivers/dma/cppi41.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/dma/cppi41.c +29 -0
index 3347321..89decc9 100644
@@ -1040,12 +1040,41 @@ static int cppi41_dma_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int cppi41_suspend(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+
+	cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
+	disable_sched(cdd);
+
+	return 0;
+}
+
+static int cppi41_resume(struct device *dev)
+{
+	struct cppi41_dd *cdd = dev_get_drvdata(dev);
+	int i;
+
+	for (i = 0; i < DESCS_AREAS; i++)
+		cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
+
+	init_sched(cdd);
+	cppi_writel(USBSS_IRQ_PD_COMP, cdd->usbss_mem + USBSS_IRQ_ENABLER);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(cppi41_pm_ops, cppi41_suspend, cppi41_resume);
+
 static struct platform_driver cpp41_dma_driver = {
 	.probe  = cppi41_dma_probe,
 	.remove = cppi41_dma_remove,
 	.driver = {
 		.name = "cppi41-dma-engine",
 		.owner = THIS_MODULE,
+		.pm = &cppi41_pm_ops,
 		.of_match_table = of_match_ptr(cppi41_dma_ids),
 	},
 };
Signature · 1 line
1.8.3.1