ata: ahci_platform: add 32-bit quirk for dwc-ahci
Subsystems (3)
PATCH 1/1 ata: ahci_platform: add 32-bit quirk for dwc-ahci
On TI Platforms using LPAE, SATA breaks with 64-bit DMA. Restrict it to 32-bit.
--- drivers/ata/ahci_platform.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/ata/ahci_platform.c +3 -0
@@ -62,6 +62,9 @@ static int ahci_probe(struct platform_device *pdev)if (of_device_is_compatible (dev->of_node,"hisilicon,hisi-ahci" )) hpriv->flags |=AHCI_HFLAG_NO_FBS |AHCI_HFLAG_NO_NCQ ; +if (of_device_is_compatible (dev->of_node,"snps,dwc-ahci" )) + hpriv->flags |=AHCI_HFLAG_32BIT_ONLY ; + port =acpi_device_get_match_data (dev);if (!port) port = &ahci_port_info;
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Hi,
Quoted 14 lines · Roger Quadros
On TI Platforms using LPAE, SATA breaks with 64-bit DMA. Restrict it to 32-bit.
Signed-off-by Roger Quadros <[email protected]>--- drivers/ata/ahci_platform.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ata/ahci_platform.c +0
-0
drivers/ata/ahci_platform.c static int ahci_probe(struct platform_device *pdev) · line 67
Quoted 6 lines
drivers/ata/ahci_platform.c +3
-0@@ -62,6 +62,9 @@ static int ahci_probe(struct platform_device *pdev)if (of_device_is_compatible (dev->of_node,"hisilicon,hisi-ahci" )) hpriv->flags |=AHCI_HFLAG_NO_FBS |AHCI_HFLAG_NO_NCQ ; +if (of_device_is_compatible (dev->of_node,"snps,dwc-ahci" )) + hpriv->flags |=AHCI_HFLAG_32BIT_ONLY ; +
The "snps,dwc-ahci" is a generic (non TI specific) compatible which is e.g. also used on some exynos devices. So using that to key the setting of the 32 bit flag seems wrong to me.
IMHO it would be better to introduce a TI specific compatible and use that to match on instead (and also adjust the dts files accordingly).
Regards,
Hans
Quoted 4 lines
drivers/ata/ahci_platform.c +0
-0port =acpi_device_get_match_data (dev);if (!port) port = &ahci_port_info;
Hans,
Quoted 12 lines · Hans de Goede
Hi,
Quoted 9 lines · Roger Quadros
On TI Platforms using LPAE, SATA breaks with 64-bit DMA. Restrict it to 32-bit.
Signed-off-by Roger Quadros <[email protected]>---
drivers/ata/ahci_platform.c| 3 +++1 file changed, 3 insertions(+)
Quoted 14 lines
drivers/ata/ahci_platform.c static int ahci_probe(struct platform_device *pdev) · line 66
Quoted 10 lines
drivers/ata/ahci_platform.c +3
-0@@ -62,6 +62,9 @@ static int ahci_probe(struct platform_device *pdev) if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci")) hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ; + if (of_device_is_compatible(dev->of_node, "snps,dwc-ahci")) + hpriv->flags |= AHCI_HFLAG_32BIT_ONLY; +The "snps,dwc-ahci" is a generic (non TI specific) compatible which is e.g. also used on some exynos devices. So using that to key the setting of the 32 bit flag seems wrong to me.
You are right, Vignesh also pointed this out to me offline.
snps,dwc-ahci does indeed support 64-bit addressing, so this patch is wrong.
Quoted 4 lines
IMHO it would be better to introduce a TI specific compatible and use that to match on instead (and also adjust the dts files accordingly).
The TI platform's TRM does say it has only 36-bits of the controller wired in the device. If that was the case and DDR address never goes beyond 36-bits, we don't understand why it fails in the first place.
80000000-afcfffff : System RAM
b0000000-feffffff : System RAM
200000000-27fffffff : System RAM
cheers,
-roger
Quoted 12 lines
Regards,
Hans
Quoted 4 lines
drivers/ata/ahci_platform.c +0
-0port = acpi_device_get_match_data(dev); if (!port) port = &ahci_port_info;
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Hi,
Quoted 27 lines · Hans de Goede
Hi,
Quoted 14 lines · Roger Quadros
On TI Platforms using LPAE, SATA breaks with 64-bit DMA. Restrict it to 32-bit.
Signed-off-by Roger Quadros <[email protected]>---
drivers/ata/ahci_platform.c| 3 +++1 file changed, 3 insertions(+)drivers/ata/ahci_platform.c +0
-0drivers/ata/ahci_platform.c static int ahci_probe(struct platform_device *pdev) · line 66
Quoted 5 lines
drivers/ata/ahci_platform.c +3
-0@@ -62,6 +62,9 @@ static int ahci_probe(struct platform_device *pdev) if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci")) hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ; + if (of_device_is_compatible(dev->of_node, "snps,dwc-ahci")) + hpriv->flags |= AHCI_HFLAG_32BIT_ONLY; +The "snps,dwc-ahci" is a generic (non TI specific) compatible which is e.g. also used on some exynos devices. So using that to key the setting of the 32 bit flag seems wrong to me.
Quoted 3 lines
IMHO it would be better to introduce a TI specific compatible and use that to match on instead (and also adjust the dts files accordingly).
Thinking further on this I think it is a bad idea to add a special binding because the IP is not different. It is just that it is wired differently on the TI SoC so DMA range is limited.
IMO the proper solution is to have the right dma-ranges property in the device tree. However, SATA platform driver is doing the wrong thing by overriding the dma masks.
i.e. in ahci_platform_init_host() in libahci_platform.c
if (hpriv->cap & HOST_CAP_64) {
rc = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64));
if (rc) {
rc = dma_coerce_mask_and_coherent(dev,
DMA_BIT_MASK(32));
if (rc) {
dev_err(dev, "Failed to enable 64-bit DMA.\n");
return rc;
}
dev_warn(dev, "Enable 32-bit DMA instead of 64-bit.\n");
}
}This should be removed. Do you agree?
You can also see a similar in ahci_configure_dma_masks() with the XXX disclaimer explaining that it is wrong.
static int ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac)
{
const int dma_bits = using_dac ? 64 : 32;
int rc;
/*
* If the device fixup already set the dma_mask to some non-standard
* value, don't extend it here. This happens on STA2X11, for example.
*
* XXX: manipulating the DMA mask from platform code is completely
* bogus, platform code should use dev->bus_dma_limit instead..
*/
if (pdev->dma_mask && pdev->dma_mask < DMA_BIT_MASK(32))
return 0;
rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(dma_bits));
if (rc)
dev_err(&pdev->dev, "DMA enable failed\n");
return rc;
}Quoted 12 lines
Regards,
Hans
Quoted 4 lines
drivers/ata/ahci_platform.c +0
-0port = acpi_device_get_match_data(dev); if (!port) port = &ahci_port_info;
Signature · 4 lines
cheers, -roger Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Hi,
Quoted 55 lines · Roger Quadros
Hi,
Quoted 27 lines · Hans de Goede
Hi,
Quoted 14 lines · Roger Quadros
On TI Platforms using LPAE, SATA breaks with 64-bit DMA. Restrict it to 32-bit.
Signed-off-by Roger Quadros <[email protected]>---
drivers/ata/ahci_platform.c| 3 +++1 file changed, 3 insertions(+)drivers/ata/ahci_platform.c +0
-0drivers/ata/ahci_platform.c static int ahci_probe(struct platform_device *pdev) · line 66
Quoted 5 lines
drivers/ata/ahci_platform.c +3
-0@@ -62,6 +62,9 @@ static int ahci_probe(struct platform_device *pdev) if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci")) hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ; + if (of_device_is_compatible(dev->of_node, "snps,dwc-ahci")) + hpriv->flags |= AHCI_HFLAG_32BIT_ONLY; +The "snps,dwc-ahci" is a generic (non TI specific) compatible which is e.g. also used on some exynos devices. So using that to key the setting of the 32 bit flag seems wrong to me.
Quoted 3 lines
IMHO it would be better to introduce a TI specific compatible and use that to match on instead (and also adjust the dts files accordingly).
Thinking further on this I think it is a bad idea to add a special binding because the IP is not different. It is just that it is wired differently on the TI SoC so DMA range is limited.
IMO the proper solution is to have the right dma-ranges property in the device tree. However, SATA platform driver is doing the wrong thing by overriding the dma masks.
i.e. inahci_platform_init_host()inlibahci_platform.c>
if (hpriv->cap&HOST_CAP_64) {
rc =dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64)); if (rc) {
rc =dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); if (rc) {
dev_err(dev, "Failed to enable 64-bit DMA.\n"); return rc;
}
dev_warn(dev, "Enable 32-bit DMA instead of 64-bit.\n"); }
}
Quoted 1 line
This should be removed. Do you agree?
I agree with you in principal, but I'm afraid this might cause regressions for existing hardware. We only do this if the host has set the CAP_64 flag, this code is quite old, it comes from the following commit:
###
From cc7a9e27562cd78a1dc885504086fab24addce40 Mon Sep 17 00:00:00 2001
From: Suravee Suthikulpanit <[email protected]>
Date: Thu, 12 Jun 2014 12:40:23 -0500
Subject: [PATCH v3] ahci: Check and set 64-bit DMA mask for platform AHCI driver
The current platform AHCI driver does not set the dma_mask correctly for 64-bit DMA capable AHCI controller. This patch checks the AHCI capability bit and set the dma_mask and coherent_dma_mask accordingly.
###
Presumably this was added for a reason, I'm guessing this might come from AMD's ARM server chips adventures, but I'm afraid that AHCI support on other (ARM) SoC's has become to rely on this behavior too.
Maybe we can add a check to see if the mask was not already set and skip setting the mask in that case ?
Regards,
Hans
Quoted 81 lines · Hans de Goede
Hi,
Quoted 56 lines · Roger Quadros
Hi,
Quoted 27 lines · Hans de Goede
Hi,
Quoted 14 lines · Roger Quadros
On TI Platforms using LPAE, SATA breaks with 64-bit DMA. Restrict it to 32-bit.
Signed-off-by Roger Quadros <[email protected]>---
drivers/ata/ahci_platform.c| 3 +++1 file changed, 3 insertions(+)drivers/ata/ahci_platform.c +0
-0drivers/ata/ahci_platform.c static int ahci_probe(struct platform_device *pdev) · line 66
Quoted 5 lines
drivers/ata/ahci_platform.c +3
-0@@ -62,6 +62,9 @@ static int ahci_probe(struct platform_device *pdev) if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci")) hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ; + if (of_device_is_compatible(dev->of_node, "snps,dwc-ahci")) + hpriv->flags |= AHCI_HFLAG_32BIT_ONLY; +The "snps,dwc-ahci" is a generic (non TI specific) compatible which is e.g. also used on some exynos devices. So using that to key the setting of the 32 bit flag seems wrong to me.
Quoted 3 lines
IMHO it would be better to introduce a TI specific compatible and use that to match on instead (and also adjust the dts files accordingly).
Thinking further on this I think it is a bad idea to add a special binding because the IP is not different. It is just that it is wired differently on the TI SoC so DMA range is limited.
IMO the proper solution is to have the right dma-ranges property in the device tree. However, SATA platform driver is doing the wrong thing by overriding the dma masks.
i.e. inahci_platform_init_host()inlibahci_platform.c>
if (hpriv->cap&HOST_CAP_64) {
rc =dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64)); if (rc) {
rc = dma_coerce_mask_and_coherent(dev,
DMA_BIT_MASK(32));
if (rc) {
dev_err(dev, "Failed to enable 64-bit DMA.\n"); return rc;
}
dev_warn(dev, "Enable 32-bit DMA instead of 64-bit.\n"); }
}Quoted 1 line
This should be removed. Do you agree?
I agree with you in principal, but I'm afraid this might cause regressions for existing hardware. We only do this if the host has set the
CAP_64flag, this code is quite old, it comes from the following commit:###
Fromcc7a9e27562cd78a1dc885504086fab24addce40Mon Sep 17 00:00:00 2001
From: Suravee Suthikulpanit <[email protected]>
Date: Thu, 12 Jun 2014 12:40:23 -0500
Subject: [PATCH v3] ahci: Check and set 64-bit DMA mask for platform AHCI driverThe current platform AHCI driver does not set the
dma_maskcorrectly for 64-bit DMA capable AHCI controller. This patch checks the AHCI capability bit and set thedma_maskandcoherent_dma_maskaccordingly.Signed-off-by Suravee Suthikulpanit <[email protected]>Reviewed-by Bartlomiej Zolnierkiewicz <[email protected]>Reviewed-by Hans de Goede <[email protected]>Tested-by Hans de Goede <[email protected]>Tested-by Suman Tripathi <[email protected]>Signed-off-by Tejun Heo <[email protected]>
Quoted 8 lines
###
Presumably this was added for a reason, I'm guessing this might come from AMD's ARM server chips adventures, but I'm afraid that AHCI support on other (ARM) SoC's has become to rely on this behavior too.
Maybe we can add a check to see if the mask was not already set and skip setting the mask in that case ?
If the device *is* inherently 64-bit capable, then setting 64-bit masks in the driver is correct - if a 64-bit IP block happens to have been integrated with only 32 address bits wired up, but the system has memory above the 32-bit boundary, then that should be described via "dma-ranges", which should then end up being used to further constrain the device masks internally to the DMA API.
Robin.
From: Robin Murphy
Quoted 1 line
Sent: 12 February 2020 11:43
...
Quoted 6 lines
If the device *is* inherently 64-bit capable, then setting 64-bit masks in the driver is correct - if a 64-bit IP block happens to have been integrated with only 32 address bits wired up, but the system has memory above the 32-bit boundary, then that should be described via "dma-ranges", which should then end up being used to further constrain the device masks internally to the DMA API.
Given how often this happens (please can I shoot some more hardware engineers - he says while compiling some VHDL) is it possible to allocate some memory pages that are aliases if the address bits over 31 are ignored?
Then (at least some) drivers could to a run-time probe reading to the high address and checking the data didn't appear in the low address.
Only one such set of pages is needed - access can be locked. But they'd need to be reserved early on.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 15 lines · David Laight
From: Robin Murphy
Quoted 1 line
Sent: 12 February 2020 11:43
...
Quoted 6 lines
If the device *is* inherently 64-bit capable, then setting 64-bit masks in the driver is correct - if a 64-bit IP block happens to have been integrated with only 32 address bits wired up, but the system has memory above the 32-bit boundary, then that should be described via "dma-ranges", which should then end up being used to further constrain the device masks internally to the DMA API.
Given how often this happens (please can I shoot some more hardware engineers - he says while compiling some VHDL) is it possible to allocate some memory pages that are aliases if the address bits over 31 are ignored?
Quoted 6 lines
Then (at least some) drivers could to a run-time probe reading to the high address and checking the data didn't appear in the low address.
Only one such set of pages is needed - access can be locked. But they'd need to be reserved early on.
(Oh, for that much control over page allocation!)
It's a fun idea, but there's no guarantee that the platform memory map is actually suitable (AMD Seattle is the go-to counterexample), and having an opt-in test that every driver has to implement individually sounds like a maintenance nightmare. I think it's far better all round to just expect the firmware-provided machine description - be it devicetree, ACPI, or whatever - to correctly describe the integration.
Robin.
Quoted 83 lines · Robin Murphy
Quoted 82 lines · Hans de Goede
Hi,
Quoted 55 lines · Roger Quadros
Hi,
Quoted 27 lines · Hans de Goede
Hi,
Quoted 14 lines · Roger Quadros
On TI Platforms using LPAE, SATA breaks with 64-bit DMA. Restrict it to 32-bit.
Signed-off-by Roger Quadros <[email protected]>---
drivers/ata/ahci_platform.c| 3 +++1 file changed, 3 insertions(+)drivers/ata/ahci_platform.c +0
-0drivers/ata/ahci_platform.c static int ahci_probe(struct platform_device *pdev) · line 66
Quoted 5 lines
drivers/ata/ahci_platform.c +3
-0@@ -62,6 +62,9 @@ static int ahci_probe(struct platform_device *pdev) if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci")) hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ; + if (of_device_is_compatible(dev->of_node, "snps,dwc-ahci")) + hpriv->flags |= AHCI_HFLAG_32BIT_ONLY; +The "snps,dwc-ahci" is a generic (non TI specific) compatible which is e.g. also used on some exynos devices. So using that to key the setting of the 32 bit flag seems wrong to me.
Quoted 3 lines
IMHO it would be better to introduce a TI specific compatible and use that to match on instead (and also adjust the dts files accordingly).
Thinking further on this I think it is a bad idea to add a special binding because the IP is not different. It is just that it is wired differently on the TI SoC so DMA range is limited.
IMO the proper solution is to have the right dma-ranges property in the device tree. However, SATA platform driver is doing the wrong thing by overriding the dma masks.
i.e. inahci_platform_init_host()inlibahci_platform.c>
if (hpriv->cap&HOST_CAP_64) {
rc =dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64)); if (rc) {
rc =dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
if (rc) {
dev_err(dev, "Failed to enable 64-bit DMA.\n"); return rc;
}
dev_warn(dev, "Enable 32-bit DMA instead of 64-bit.\n"); }
}Quoted 1 line
This should be removed. Do you agree?
I agree with you in principal, but I'm afraid this might cause regressions for existing hardware. We only do this if the host has set the
CAP_64flag, this code is quite old, it comes from the following commit:###
Fromcc7a9e27562cd78a1dc885504086fab24addce40Mon Sep 17 00:00:00 2001
From: Suravee Suthikulpanit <[email protected]>
Date: Thu, 12 Jun 2014 12:40:23 -0500
Subject: [PATCH v3] ahci: Check and set 64-bit DMA mask for platform AHCI driverThe current platform AHCI driver does not set the
dma_maskcorrectly for 64-bit DMA capable AHCI controller. This patch checks the AHCI capability bit and set thedma_maskandcoherent_dma_maskaccordingly.Signed-off-by Suravee Suthikulpanit <[email protected]>Reviewed-by Bartlomiej Zolnierkiewicz <[email protected]>Reviewed-by Hans de Goede <[email protected]>Tested-by Hans de Goede <[email protected]>Tested-by Suman Tripathi <[email protected]>Signed-off-by Tejun Heo <[email protected]>###
Quoted 8 lines
Quoted 6 lines
Presumably this was added for a reason, I'm guessing this might come from AMD's ARM server chips adventures, but I'm afraid that AHCI support on other (ARM) SoC's has become to rely on this behavior too.
Maybe we can add a check to see if the mask was not already set and skip setting the mask in that case ?
If the device *is* inherently 64-bit capable, then setting 64-bit masks in the driver is correct - if a 64-bit IP block happens to have been integrated with only 32 address bits wired up, but the system has memory above the 32-bit boundary, then that should be described via "dma-ranges", which should then end up being used to further constrain the device masks internally to the DMA API.
I agree. In this case, it looks like DMA API is allocating memory > 32-bits even if "dma-ranges" size and dma_bus_limit is < 32-bits so issue is with platform DMA code.
I will continue the discussion in the other thread
https://lkml.org/lkml/2020/2/12/907
Signature · 4 lines
cheers, -roger Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki