Skip to contentSkip to conversation

spi-nor: Drop uniform erase

PATCH In review Sverdlin, Alexander (Nokia - DE/Ulm) 2 participants 12 messages Jan 24, 2019 – Jan 13, 2020

Subsystems (2)
lore
Share & tools
lore
#8 lore raw

PATCH 2/2 mtd: spi-nor: Always use biggest erase size

In reply to Sverdlin, Alexander (Nokia - DE/Ulm)

Optimize erase time by always using biggest erase size for given erase request. Do it by removing "sector"-at-a-time erase code. spi_nor_erase_multi_sectors() seems to be mature enough to handle all the cases better.

For the above to work backwards-compatible regarding 4-bytes commands spi_nor_set_4byte_opcodes() has to prepare them always, independent of spi_nor_has_uniform_erase() flag.

Remainder check in spi_nor_erase() becomes superfluous because spi_nor_erase_multi_sectors() performs it anyway.

The trigger for this change was n25q128a13: enabling SECT_4K increased erase time of 128k block from 1.763s to 11.335s.

Fixes 4607777c71 ("mtd: spi-nor: add subsector flag to n25q128a")
---
 drivers/mtd/spi-nor/spi-nor.c | 46 ++++++-----------------------------
 1 file changed, 7 insertions(+), 39 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +7 -39
index c3598f0571cc..a25324a52eae 100644
@@ -434,6 +434,10 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode)
 
 static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
 {
+	struct spi_nor_erase_map *map = &nor->erase_map;
+	struct spi_nor_erase_type *erase;
+	int i;
+
 	/* Do some manufacturer fixups first */
 	switch (JEDEC_MFR(nor->info)) {
 	case SNOR_MFR_SPANSION:
@@ -450,16 +454,9 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
 	nor->program_opcode = spi_nor_convert_3to4_program(nor->program_opcode);
 	nor->erase_opcode = spi_nor_convert_3to4_erase(nor->erase_opcode);
 
-	if (!spi_nor_has_uniform_erase(nor)) {
-		struct spi_nor_erase_map *map = &nor->erase_map;
-		struct spi_nor_erase_type *erase;
-		int i;
-
-		for (i = 0; i < SNOR_ERASE_TYPE_MAX; i++) {
-			erase = &map->erase_type[i];
-			erase->opcode =
-				spi_nor_convert_3to4_erase(erase->opcode);
-		}
+	for (i = 0; i < SNOR_ERASE_TYPE_MAX; i++) {
+		erase = &map->erase_type[i];
+		erase->opcode = spi_nor_convert_3to4_erase(erase->opcode);
 	}
 }
 
@@ -978,18 +975,11 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	u32 addr, len;
-	uint32_t rem;
 	int ret;
 
 	dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr,
 			(long long)instr->len);
 
-	if (spi_nor_has_uniform_erase(nor)) {
-		div_u64_rem(instr->len, mtd->erasesize, &rem);
-		if (rem)
-			return -EINVAL;
-	}
-
 	addr = instr->addr;
 	len = instr->len;
 
@@ -1021,28 +1011,6 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 		if (ret)
 			goto erase_err;
 
-	/* REVISIT in some cases we could speed up erasing large regions
-	 * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K.  We may have set up
-	 * to use "small sector erase", but that's not always optimal.
-	 */
-
-	/* "sector"-at-a-time erase */
-	} else if (spi_nor_has_uniform_erase(nor)) {
-		while (len) {
-			write_enable(nor);
-
-			ret = spi_nor_erase_sector(nor, addr);
-			if (ret)
-				goto erase_err;
-
-			addr += mtd->erasesize;
-			len -= mtd->erasesize;
-
-			ret = spi_nor_wait_till_ready(nor);
-			if (ret)
-				goto erase_err;
-		}
-
 	/* erase multiple sectors */
 	} else {
 		ret = spi_nor_erase_multi_sectors(nor, addr, len);
Signature · 6 lines
2.19.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#0 lore raw

cover spi-nor: Drop uniform erase

A series which initially started as n25q128a13 erase time regression analysis but ended up in removing uniform erase completely.

It has been tested on the following name/ID combinations:

n25q128a13:
JEDEC ID 20 ba 18 10 00 00
JEDEC ID 20 ba 18 10 40 00
JEDEC ID 20 ba 18 10 44 00

n25q128a11:
JEDEC ID 20 bb 18 10 44 00

s25fl129p1:
JEDEC ID 01 20 18 4d 01 81

Alexander Sverdlin (2):
mtd: spi-nor: Fix comment of spi_nor_find_best_erase_type()
mtd: spi-nor: Always use biggest erase size

 drivers/mtd/spi-nor/spi-nor.c | 48 ++++++-----------------------------
 1 file changed, 8 insertions(+), 40 deletions(-)
Signature · 6 lines
2.19.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw

PATCH 1/2 mtd: spi-nor: Fix comment of spi_nor_find_best_erase_type()

Erase types are sorted *smallest* type first, refer to spi_nor_sort_erase_mask().

---
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/spi-nor.c +1 -1
index 6e13bbd1aaa5..c3598f0571cc 100644
@@ -739,7 +739,7 @@ spi_nor_find_best_erase_type(const struct spi_nor_erase_map *map,
 	u8 erase_mask = region->offset & SNOR_ERASE_TYPE_MASK;
 
 	/*
-	 * Erase types are ordered by size, with the biggest erase type at
+	 * Erase types are ordered by size, with the smallest erase type at
 	 * index 0.
 	 */
 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
Signature · 6 lines
2.19.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#9 lore raw

Re: [PATCH 2/2] mtd: spi-nor: Always use biggest erase size

In reply to Sverdlin, Alexander (Nokia - DE/Ulm)

Hi, Alexander,

Quoted 4 lines · Alexander (Nokia - DE/Ulm)

Optimize erase time by always using biggest erase size for given erase request. Do it by removing "sector"-at-a-time erase code. spi_nor_erase_multi_sectors() seems to be mature enough to handle all the cases better.

Did you check if the upper mtd layers are affected by this change?

Quoted 10 lines

For the above to work backwards-compatible regarding 4-bytes commands spi_nor_set_4byte_opcodes() has to prepare them always, independent of spi_nor_has_uniform_erase() flag.

Remainder check in spi_nor_erase() becomes superfluous because spi_nor_erase_multi_sectors() performs it anyway.

The trigger for this change was n25q128a13: enabling SECT_4K increased erase time of 128k block from 1.763s to 11.335s.

When needed, one can disable the 4K sectors with the MTD_SPI_NOR_USE_4K_SECTORS kconfig option. Does this help you?

Cheers,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#10 lore raw

Re: [PATCH 2/2] mtd: spi-nor: Always use biggest erase size

Hi Tudor,

Quoted 7 lines · On 28/02/2019 18:00, [email protected] wrote:
Quoted 4 lines · Alexander (Nokia - DE/Ulm)

Optimize erase time by always using biggest erase size for given erase request. Do it by removing "sector"-at-a-time erase code. spi_nor_erase_multi_sectors() seems to be mature enough to handle all the cases better.

Did you check if the upper mtd layers are affected by this change?

For now I just change static function, I didn't want to remote spi_nor_has_uniform_erase() infrastructure in the first step.

So I personally see no problems with my patch. It's also quite well tested up to now.

Quoted 4 lines
Quoted 4 lines

For the above to work backwards-compatible regarding 4-bytes commands spi_nor_set_4byte_opcodes() has to prepare them always, independent of spi_nor_has_uniform_erase() flag.

Quoted 8 lines
Quoted 5 lines

Remainder check in spi_nor_erase() becomes superfluous because spi_nor_erase_multi_sectors() performs it anyway.

The trigger for this change was n25q128a13: enabling SECT_4K increased erase time of 128k block from 1.763s to 11.335s.

When needed, one can disable the 4K sectors with the MTD_SPI_NOR_USE_4K_SECTORS kconfig option. Does this help you?

This very same kernel runs on different boards with different flashes. Seems that more modern flashes are not so slow when 4K sectors are used.

Moreover, I truly believe this was a dead code and want to be convinced otherwise before real problems start :)

Signature · 5 lines
Best regards,
Alexander Sverdlin.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#2 lore raw

Re: [PATCH 1/2] mtd: spi-nor: Fix comment of spi_nor_find_best_erase_type()

In reply to Sverdlin, Alexander (Nokia - DE/Ulm)
Quoted 4 lines · Alexander (Nokia - DE/Ulm)

Erase types are sorted *smallest* type first, refer to spi_nor_sort_erase_mask().

Please fix your author name to match your S-o-b tag. See
https://lkml.org/lkml/2019/2/8/556 for a workaround.

I'll add my R-b after this change.

I didn't forget about patch 2/2, I just want to check the upper mtd layers.

Thanks,
ta

Quoted 10 lines
---
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/spi-nor.c +0 -0
index 6e13bbd1aaa5..c3598f0571cc 100644

drivers/mtd/spi-nor/spi-nor.c spi_nor_find_best_erase_type(const struct spi_nor_erase_map *map, · line 745

Quoted 8 lines
drivers/mtd/spi-nor/spi-nor.c +1 -1
@@ -739,7 +739,7 @@ spi_nor_find_best_erase_type(const struct spi_nor_erase_map *map,
 	u8 erase_mask = region->offset & SNOR_ERASE_TYPE_MASK;
 
 	/*
-	 * Erase types are ordered by size, with the biggest erase type at
+	 * Erase types are ordered by size, with the smallest erase type at
 	 * index 0.
 	 */
 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#3 lore raw

cover spi-nor: Drop uniform erase

From: Alexander Sverdlin <[email protected]>

A series which initially started as n25q128a13 erase time regression analysis but ended up in removing uniform erase completely.

It has been tested on the following name/ID combinations:

n25q128a13:
JEDEC ID 20 ba 18 10 00 00
JEDEC ID 20 ba 18 10 40 00
JEDEC ID 20 ba 18 10 44 00

n25q128a11:
JEDEC ID 20 bb 18 10 44 00

s25fl129p1:
JEDEC ID 01 20 18 4d 01 81

Alexander Sverdlin (2):
mtd: spi-nor: Fix comment of spi_nor_find_best_erase_type()
mtd: spi-nor: Always use biggest erase size

 drivers/mtd/spi-nor/spi-nor.c | 48 ++++++-----------------------------
 1 file changed, 8 insertions(+), 40 deletions(-)
Signature · 6 lines
2.19.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#4 lore raw

PATCH 1/2 mtd: spi-nor: Fix comment of spi_nor_find_best_erase_type()

From: Alexander Sverdlin <[email protected]>

Erase types are sorted *smallest* type first, refer to spi_nor_sort_erase_mask().

---
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/spi-nor.c +1 -1
index 6e13bbd1aaa5..c3598f0571cc 100644
@@ -739,7 +739,7 @@ spi_nor_find_best_erase_type(const struct spi_nor_erase_map *map,
 	u8 erase_mask = region->offset & SNOR_ERASE_TYPE_MASK;
 
 	/*
-	 * Erase types are ordered by size, with the biggest erase type at
+	 * Erase types are ordered by size, with the smallest erase type at
 	 * index 0.
 	 */
 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
Signature · 6 lines
2.19.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#7 lore raw

PATCH 2/2 mtd: spi-nor: Always use biggest erase size

In reply to Sverdlin, Alexander (Nokia - DE/Ulm)

From: Alexander Sverdlin <[email protected]>

Optimize erase time by always using biggest erase size for given erase request. Do it by removing "sector"-at-a-time erase code. spi_nor_erase_multi_sectors() seems to be mature enough to handle all the cases better.

For the above to work backwards-compatible regarding 4-bytes commands spi_nor_set_4byte_opcodes() has to prepare them always, independent of spi_nor_has_uniform_erase() flag.

Remainder check in spi_nor_erase() becomes superfluous because spi_nor_erase_multi_sectors() performs it anyway.

The trigger for this change was n25q128a13: enabling SECT_4K increased erase time of 128k block from 1.763s to 11.335s.

Fixes 4607777c71 ("mtd: spi-nor: add subsector flag to n25q128a")
---
 drivers/mtd/spi-nor/spi-nor.c | 46 ++++++-----------------------------
 1 file changed, 7 insertions(+), 39 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +7 -39
index c3598f0571cc..a25324a52eae 100644
@@ -434,6 +434,10 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode)
 
 static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
 {
+	struct spi_nor_erase_map *map = &nor->erase_map;
+	struct spi_nor_erase_type *erase;
+	int i;
+
 	/* Do some manufacturer fixups first */
 	switch (JEDEC_MFR(nor->info)) {
 	case SNOR_MFR_SPANSION:
@@ -450,16 +454,9 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
 	nor->program_opcode = spi_nor_convert_3to4_program(nor->program_opcode);
 	nor->erase_opcode = spi_nor_convert_3to4_erase(nor->erase_opcode);
 
-	if (!spi_nor_has_uniform_erase(nor)) {
-		struct spi_nor_erase_map *map = &nor->erase_map;
-		struct spi_nor_erase_type *erase;
-		int i;
-
-		for (i = 0; i < SNOR_ERASE_TYPE_MAX; i++) {
-			erase = &map->erase_type[i];
-			erase->opcode =
-				spi_nor_convert_3to4_erase(erase->opcode);
-		}
+	for (i = 0; i < SNOR_ERASE_TYPE_MAX; i++) {
+		erase = &map->erase_type[i];
+		erase->opcode = spi_nor_convert_3to4_erase(erase->opcode);
 	}
 }
 
@@ -978,18 +975,11 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	u32 addr, len;
-	uint32_t rem;
 	int ret;
 
 	dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr,
 			(long long)instr->len);
 
-	if (spi_nor_has_uniform_erase(nor)) {
-		div_u64_rem(instr->len, mtd->erasesize, &rem);
-		if (rem)
-			return -EINVAL;
-	}
-
 	addr = instr->addr;
 	len = instr->len;
 
@@ -1021,28 +1011,6 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 		if (ret)
 			goto erase_err;
 
-	/* REVISIT in some cases we could speed up erasing large regions
-	 * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K.  We may have set up
-	 * to use "small sector erase", but that's not always optimal.
-	 */
-
-	/* "sector"-at-a-time erase */
-	} else if (spi_nor_has_uniform_erase(nor)) {
-		while (len) {
-			write_enable(nor);
-
-			ret = spi_nor_erase_sector(nor, addr);
-			if (ret)
-				goto erase_err;
-
-			addr += mtd->erasesize;
-			len -= mtd->erasesize;
-
-			ret = spi_nor_wait_till_ready(nor);
-			if (ret)
-				goto erase_err;
-		}
-
 	/* erase multiple sectors */
 	} else {
 		ret = spi_nor_erase_multi_sectors(nor, addr, len);
Signature · 6 lines
2.19.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Reviewed-by on v1 1/2
#5 lore raw

Re: [PATCH 1/2] mtd: spi-nor: Fix comment of spi_nor_find_best_erase_type()

In reply to Sverdlin, Alexander (Nokia - DE/Ulm)
Quoted 9 lines · Alexander (Nokia - DE/Ulm)

External E-Mail

From: Alexander Sverdlin <[email protected]>

Erase types are sorted *smallest* type first, refer to spi_nor_sort_erase_mask().

Quoted 10 lines
---
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/spi-nor.c +0 -0
index 6e13bbd1aaa5..c3598f0571cc 100644

drivers/mtd/spi-nor/spi-nor.c spi_nor_find_best_erase_type(const struct spi_nor_erase_map *map, · line 745

Quoted 8 lines
drivers/mtd/spi-nor/spi-nor.c +1 -1
@@ -739,7 +739,7 @@ spi_nor_find_best_erase_type(const struct spi_nor_erase_map *map,
 	u8 erase_mask = region->offset & SNOR_ERASE_TYPE_MASK;
 
 	/*
-	 * Erase types are ordered by size, with the biggest erase type at
+	 * Erase types are ordered by size, with the smallest erase type at
 	 * index 0.
 	 */
 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#6 lore raw

Re: [PATCH 1/2] mtd: spi-nor: Fix comment of spi_nor_find_best_erase_type()

In reply to Sverdlin, Alexander (Nokia - DE/Ulm)
Quoted 9 lines · Alexander (Nokia - DE/Ulm)

From: Alexander Sverdlin <[email protected]>

Erase types are sorted *smallest* type first, refer to spi_nor_sort_erase_mask().

---
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to http://git.infradead.org/linux-mtd.git, spi-nor/next. Thanks.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#11 lore raw

Re: [PATCH 2/2] mtd: spi-nor: Always use biggest erase size

In reply to Sverdlin, Alexander (Nokia - DE/Ulm)

Hello Tudor,

Quoted 20 lines · Alexander Sverdlin
Quoted 5 lines
Quoted 4 lines

Optimize erase time by always using biggest erase size for given erase request. Do it by removing "sector"-at-a-time erase code. spi_nor_erase_multi_sectors() seems to be mature enough to handle all the cases better.

Did you check if the upper mtd layers are affected by this change?

For now I just change static function, I didn't want to remote spi_nor_has_uniform_erase() infrastructure in the first step.

So I personally see no problems with my patch. It's also quite well tested up to now.

Quoted 9 lines
Quoted 9 lines

For the above to work backwards-compatible regarding 4-bytes commands spi_nor_set_4byte_opcodes() has to prepare them always, independent of spi_nor_has_uniform_erase() flag.

Remainder check in spi_nor_erase() becomes superfluous because spi_nor_erase_multi_sectors() performs it anyway.

The trigger for this change was n25q128a13: enabling SECT_4K increased erase time of 128k block from 1.763s to 11.335s.

Quoted 7 lines
Quoted 2 lines

When needed, one can disable the 4K sectors with the MTD_SPI_NOR_USE_4K_SECTORS kconfig option. Does this help you?

This very same kernel runs on different boards with different flashes. Seems that more modern flashes are not so slow when 4K sectors are used.

Moreover, I truly believe this was a dead code and want to be convinced otherwise before real problems start :)

in the past 10 months I didn't encounter any problems with this patch. Could you take another look on it?

Signature · 6 lines
Best regards,
Alexander Sverdlin.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/