Skip to contentSkip to conversation

mtd: bcm47xxsflash: use uncached MMIO access for BCM53573

PATCH Applied Rafał Miłecki 3 participants 4 messages Aug 15, 2016 – Nov 8, 2016 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: bcm47xxsflash: use uncached MMIO access for BCM53573

From: Rafał Miłecki <[email protected]>

BCM53573 is a new series of Broadcom's SoCs. It's based on ARM and uses this old ChipCommon-based flash access. Early tests resulted in flash corruptions that were tracked down to using cached MMIO for flash read access. Switch to ioremap_nocache conditionally to support BCM53573 and don't break performance on old MIPS devices.

---
 drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/mtd/devices/bcm47xxsflash.c +19 -5
index 1c65c15..514be04 100644
@@ -296,16 +296,30 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
 		dev_err(dev, "can't request region for resource %pR\n", res);
 		return -EBUSY;
 	}
-	b47s->window = ioremap_cache(res->start, resource_size(res));
-	if (!b47s->window) {
-		dev_err(dev, "ioremap failed for resource %pR\n", res);
-		return -ENOMEM;
-	}
 
 	b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
 	b47s->cc_read = bcm47xxsflash_bcma_cc_read;
 	b47s->cc_write = bcm47xxsflash_bcma_cc_write;
 
+	/*
+	 * On old MIPS devices cache was magically invalidated when needed,
+	 * allowing us to use cached access and gain some performance. Trying
+	 * the same on ARM based BCM53573 results in flash corruptions, we need
+	 * to use uncached access for it.
+	 *
+	 * It may be arch specific, but right now there is only 1 ARM SoC using
+	 * this driver, so let's follow Broadcom's reference code and check
+	 * ChipCommon revision.
+	 */
+	if (b47s->bcma_cc->core->id.rev == 54)
+		b47s->window = ioremap_nocache(res->start, resource_size(res));
+	else
+		b47s->window = ioremap_cache(res->start, resource_size(res));
+	if (!b47s->window) {
+		dev_err(dev, "ioremap failed for resource %pR\n", res);
+		return -ENOMEM;
+	}
+
 	switch (b47s->bcma_cc->capabilities & BCMA_CC_CAP_FLASHT) {
 	case BCMA_CC_FLASHT_STSER:
 		b47s->type = BCM47XXSFLASH_TYPE_ST;
Signature · 1 line
1.8.4.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Mon, 15 Aug 2016 14:21:28 +0200 Rafał Miłecki <[email protected]> wrote:

From: Rafał Miłecki <[email protected]>

BCM53573 is a new series of Broadcom's SoCs. It's based on ARM and uses this old ChipCommon-based flash access. Early tests resulted in flash corruptions that were tracked down to using cached MMIO for flash read access. Switch to ioremap_nocache conditionally to support BCM53573 and don't break performance on old MIPS devices.

Quoted 44 lines
---
 drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/mtd/devices/bcm47xxsflash.c +19 -5
index 1c65c15..514be04 100644
@@ -296,16 +296,30 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
 		dev_err(dev, "can't request region for resource %pR\n", res);
 		return -EBUSY;
 	}
-	b47s->window = ioremap_cache(res->start, resource_size(res));
-	if (!b47s->window) {
-		dev_err(dev, "ioremap failed for resource %pR\n", res);
-		return -ENOMEM;
-	}
 
 	b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
 	b47s->cc_read = bcm47xxsflash_bcma_cc_read;
 	b47s->cc_write = bcm47xxsflash_bcma_cc_write;
 
+	/*
+	 * On old MIPS devices cache was magically invalidated when needed,
+	 * allowing us to use cached access and gain some performance. Trying
+	 * the same on ARM based BCM53573 results in flash corruptions, we need
+	 * to use uncached access for it.
+	 *
+	 * It may be arch specific, but right now there is only 1 ARM SoC using
+	 * this driver, so let's follow Broadcom's reference code and check
+	 * ChipCommon revision.
+	 */
+	if (b47s->bcma_cc->core->id.rev == 54)
+		b47s->window = ioremap_nocache(res->start, resource_size(res));
+	else
+		b47s->window = ioremap_cache(res->start, resource_size(res));
+	if (!b47s->window) {
+		dev_err(dev, "ioremap failed for resource %pR\n", res);
+		return -ENOMEM;
+	}
+
 	switch (b47s->bcma_cc->capabilities & BCMA_CC_CAP_FLASHT) {
 	case BCMA_CC_FLASHT_STSER:
 		b47s->type = BCM47XXSFLASH_TYPE_ST;
Applied
#2 lore raw
In reply to Rafał Miłecki

Hi,

Quoted 26 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

BCM53573 is a new series of Broadcom's SoCs. It's based on ARM and uses this old ChipCommon-based flash access. Early tests resulted in flash corruptions that were tracked down to using cached MMIO for flash read access. Switch to ioremap_nocache conditionally to support BCM53573 and don't break performance on old MIPS devices.

---
 drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/mtd/devices/bcm47xxsflash.c +0 -5
index 1c65c15..514be04 100644
@@ -296,16 +296,30 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
 		dev_err(dev, "can't request region for resource %pR\n", res);
 		return -EBUSY;
 	}
-	b47s->window = ioremap_cache(res->start, resource_size(res));
-	if (!b47s->window) {
-		dev_err(dev, "ioremap failed for resource %pR\n", res);
-		return -ENOMEM;
-	}

drivers/mtd/devices/bcm47xxsflash.c static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) · line 308

Quoted 10 lines
drivers/mtd/devices/bcm47xxsflash.c +5 -0
 
 	b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
 	b47s->cc_read = bcm47xxsflash_bcma_cc_read;
 	b47s->cc_write = bcm47xxsflash_bcma_cc_write;
 
+	/*
+	 * On old MIPS devices cache was magically invalidated when needed,
+	 * allowing us to use cached access and gain some performance. Trying
+	 * the same on ARM based BCM53573 results in flash corruptions, we need
+	 * to use uncached access for it.

Is the word "magically" really used in the Broadcom reference code? I wouldn't be too suprised actually :)

I'd prefer getting a better explanation on this point, but without that, I think it's fair to leave the caching for the old (working) MIPS SoCs and avoid caching on the new ARM one.

drivers/mtd/devices/bcm47xxsflash.c static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) · line 312

Quoted 3 lines
drivers/mtd/devices/bcm47xxsflash.c +3 -0
+	 * It may be arch specific, but right now there is only 1 ARM SoC using
+	 * this driver, so let's follow Broadcom's reference code and check
+	 * ChipCommon revision.

Yeah, if we get any more ARM chips that behave similarly, I think we'll just want to do 'if !MIPS'.

Applied to l2-mtd.git.

Brian

Quoted 16 lines
drivers/mtd/devices/bcm47xxsflash.c +10 -0
+	 */
+	if (b47s->bcma_cc->core->id.rev == 54)
+		b47s->window = ioremap_nocache(res->start, resource_size(res));
+	else
+		b47s->window = ioremap_cache(res->start, resource_size(res));
+	if (!b47s->window) {
+		dev_err(dev, "ioremap failed for resource %pR\n", res);
+		return -ENOMEM;
+	}
+
 	switch (b47s->bcma_cc->capabilities & BCMA_CC_CAP_FLASHT) {
 	case BCMA_CC_FLASHT_STSER:
 		b47s->type = BCM47XXSFLASH_TYPE_ST;
Signature · 1 line
1.8.4.5
#3 lore raw
Quoted 41 lines · Brian Norris
Quoted 26 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

BCM53573 is a new series of Broadcom's SoCs. It's based on ARM and uses this old ChipCommon-based flash access. Early tests resulted in flash corruptions that were tracked down to using cached MMIO for flash read access. Switch to ioremap_nocache conditionally to support BCM53573 and don't break performance on old MIPS devices.

---
 drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/mtd/devices/bcm47xxsflash.c +0 -5
index 1c65c15..514be04 100644
@@ -296,16 +296,30 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
              dev_err(dev, "can't request region for resource %pR\n", res);
              return -EBUSY;
      }
-     b47s->window = ioremap_cache(res->start, resource_size(res));
-     if (!b47s->window) {
-             dev_err(dev, "ioremap failed for resource %pR\n", res);
-             return -ENOMEM;
-     }

drivers/mtd/devices/bcm47xxsflash.c static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) · line 308

Quoted 10 lines
drivers/mtd/devices/bcm47xxsflash.c +5 -0
 
      b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
      b47s->cc_read = bcm47xxsflash_bcma_cc_read;
      b47s->cc_write = bcm47xxsflash_bcma_cc_write;
 
+     /*
+      * On old MIPS devices cache was magically invalidated when needed,
+      * allowing us to use cached access and gain some performance. Trying
+      * the same on ARM based BCM53573 results in flash corruptions, we need
+      * to use uncached access for it.

Is the word "magically" really used in the Broadcom reference code? I wouldn't be too suprised actually :)

Quoted 3 lines

I'd prefer getting a better explanation on this point, but without that, I think it's fair to leave the caching for the old (working) MIPS SoCs and avoid caching on the new ARM one.

I have to admit "magic" word was my choice ;) I guess Broadcom ppl know more about this, but they didn't release any datasheets/programming guide and they didn't document it well in the code.

Reference code can be found in Broadcom's SDK in the ccsflash.c.

1) ccsflash_init does:
ccsflash.base = (uint32)REG_MAP(ccsflash.phybase, ccsflash.size); (and REG_MAP is a macro for ioremap_nocache)

2) ccsflash_read does:

if (sih->ccrev == 12) {
        from = (uint8 *)OSL_UNCACHED((void *)SI_FLASH2 + offset);
} else if (sih->ccrev == 54) {
        from = (uint8 *)((void *)sfl->base + offset);
} else {
        from = (uint8 *)OSL_CACHED((void *)SI_FLASH2 + offset);
}

I'm not aware of any market-released device with ChipCommon rev 12, so I check for rev 54 only.

Quoted 8 lines

drivers/mtd/devices/bcm47xxsflash.c static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) · line 312

Quoted 3 lines
drivers/mtd/devices/bcm47xxsflash.c +3 -0
+      * It may be arch specific, but right now there is only 1 ARM SoC using
+      * this driver, so let's follow Broadcom's reference code and check
+      * ChipCommon revision.

Yeah, if we get any more ARM chips that behave similarly, I think we'll just want to do 'if !MIPS'.

Applied to l2-mtd.git.

Thank you!