Skip to contentSkip to conversation

mmc: renesas_sdhi_internal_dmac: set scatter/gather max segment size

PATCH Superseded Niklas Söderlund 3 participants 4 messages Aug 30, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: renesas_sdhi_internal_dmac: set scatter/gather max segment size

Fix warning when running with CONFIG_DMA_API_DEBUG_SG=y by allocating a device_dma_parameters structure and filling in the max segment size. The size used is the result of a discussion with Renesas hardware engineers and unfortunately not found in the datasheet.

renesas_sdhi_internal_dmac ee140000.sd: DMA-API: mapping sg segment longer than device claims to support [len=126976] [max=65536A]

---
 drivers/mmc/host/renesas_sdhi_internal_dmac.c | 25 ++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/mmc/host/renesas_sdhi_internal_dmac.c +24 -1
index 225af5389599108a..13a286e2a247042d 100644
@@ -292,15 +292,38 @@ static const struct soc_device_attribute gen3_soc_whitelist[] = {
 static int renesas_sdhi_internal_dmac_probe(struct platform_device *pdev)
 {
 	const struct soc_device_attribute *soc = soc_device_match(gen3_soc_whitelist);
+	struct device *dev = &pdev->dev;
 
 	if (!soc)
 		return -ENODEV;
 
 	global_flags |= (unsigned long)soc->data;
 
+	if (!dev->dma_parms) {
+		dev->dma_parms = kzalloc(sizeof(*dev->dma_parms), GFP_KERNEL);
+		if (!dev->dma_parms)
+			return -ENOMEM;
+	}
+
+	if (dma_set_max_seg_size(dev, 0xffffffff))
+		dev_warn(dev, "Unable to set seg size\n");
+
 	return renesas_sdhi_probe(pdev, &renesas_sdhi_internal_dmac_dma_ops);
 }
 
+static int renesas_sdhi_internal_dmac_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	int ret;
+
+	ret = renesas_sdhi_remove(pdev);
+
+	kfree(dev->dma_parms);
+	dev->dma_parms = NULL;
+
+	return ret;
+}
+
 static const struct dev_pm_ops renesas_sdhi_internal_dmac_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
 				pm_runtime_force_resume)
@@ -316,7 +339,7 @@ static struct platform_driver renesas_internal_dmac_sdhi_driver = {
 		.of_match_table = renesas_sdhi_internal_dmac_of_match,
 	},
 	.probe		= renesas_sdhi_internal_dmac_probe,
-	.remove		= renesas_sdhi_remove,
+	.remove		= renesas_sdhi_internal_dmac_remove,
 };
 
 module_platform_driver(renesas_internal_dmac_sdhi_driver);
Signature · 1 line
2.18.0
#1 lore raw

Hi Niklas,

drivers/mmc/host/renesas_sdhi_internal_dmac.c static const struct soc_device_attribute gen3_soc_whitelist[] = { · line 303

Quoted 2 lines
drivers/mmc/host/renesas_sdhi_internal_dmac.c +2 -0
+	if (!dev->dma_parms) {
+		dev->dma_parms = kzalloc(sizeof(*dev->dma_parms), GFP_KERNEL);

Can't we use devm_kzalloc and skip the custom remove function?

Thanks,

Wolfram

#2 lore raw

Hi Wolfram,

Thanks for your feedback.

Quoted 6 lines · Wolfram Sang

Hi Niklas,

drivers/mmc/host/renesas_sdhi_internal_dmac.c static const struct soc_device_attribute gen3_soc_whitelist[] = { · line 303

Quoted 2 lines
drivers/mmc/host/renesas_sdhi_internal_dmac.c +2 -0
+	if (!dev->dma_parms) {
+		dev->dma_parms = kzalloc(sizeof(*dev->dma_parms), GFP_KERNEL);

Can't we use devm_kzalloc and skip the custom remove function?

We could do that but then we can't reset the struct device dma_parms member to NULL.

    kfree(dev->dma_parms);
    dev->dma_parms = NULL;

This might not be a problem but I chose to opt for the more safer approach at first. If you or someone else thinks this is not an issue I'm more then happy to switch to devm_kcalloc().

Signature · 2 lines
Regards,
Niklas S�derlund
#3 lore raw
Quoted 3 lines

We could do that but then we can't reset the struct device dma_parms member to NULL.

I think it is fine to skip this. From the device_add docs:

* Do not call this routine or device_register() more than once for
* any device structure. The driver model core is not designed to work
* with devices that get unregistered and then spring back to life.
* (Among other things, it's very hard to guarantee that all references
* to the previous incarnation of @dev have been dropped.) Allocate
* and register a fresh new struct device instead.

I also don't see any other dma_params user doing this (which is only an indication, not a proof).