mtd: spi-nor: Always use biggest erase size
Subsystems (2)
PATCH v2 1/1 mtd: spi-nor: Always use biggest erase size
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 superflous 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.
---
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
Changelog:
v2: Rebased
drivers/mtd/spi-nor/spi-nor.c | 48 +++++++------------------------------------ 1 file changed, 7 insertions(+), 41 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +7 -41
@@ -1318,20 +1318,17 @@ 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->params.erase_map; +struct spi_nor_erase_type *erase; +int i; + nor->read_opcode =spi_nor_convert_3to4_read (nor->read_opcode); 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->params.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); } }
@@ -1701,18 +1698,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;
@@ -1745,30 +1735,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) { - ret =spi_nor_write_enable (nor); -if (ret) - goto erase_err; - - 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.4.6 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 1/1 mtd: spi-nor: Fixup page size for S25FS-S
From: Alexander Sverdlin <[email protected]>
Spansion S25FS-S family has an issue in Basic Flash Parameter Table:
DWORD-11 bits 7-4 specify write page size 512 bytes. In reality this is configurable in the non-volatile CR3NV register and even factory default configuration is "wrap at 256 bytes". So blind relying on BFPT breaks write operation on these Flashes.
All this story is vendor-specific, so add the corresponding fixup hook which first restores the safe page size of 256 bytes from struct flash_info but checks is more performant 512 bytes configuration is active and adjusts the page_size accordingly.
---
Changelog:
v3: Use spi_nor_read_data()
v2: Thankfully rebased on the hint from John Garry
drivers/mtd/spi-nor/spi-nor.c | 39 +++++++++++++++++++++++++++++++++++++-- include/linux/mtd/spi-nor.h | 5 +++++ 2 files changed, 42 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +37 -2
@@ -2326,6 +2326,39 @@ static struct spi_nor_fixups gd25q256_fixups = { .default_init = gd25q256_default_init, }; +/* Spansion S25FS-S SFDP workarounds */ +static int s25fs_s_post_bfpt_fixups (struct spi_nor *nor, +const struct sfdp_parameter_header *bfpt_header, +const struct sfdp_bfpt *bfpt, +struct spi_nor_flash_parameter *params) +{ +const struct flash_info *info = nor->info; +u8 read_opcode, buf; +int ret; + +/* Default is safe */ + params->page_size = info->page_size; + +/* +* But is the chip configured for more performant 512 bytes write page +* size? +*/ + read_opcode = nor->read_opcode; + + nor->read_opcode =SPINOR_OP_RDAR ; + ret =spi_nor_read_data (nor,SPINOR_REG_CR3V ,1 , &buf); +if (!ret && (buf &CR3V_02H_V )) + params->page_size =512 ; + + nor->read_opcode = read_opcode; + +return ret; +} + +static const struct spi_nor_fixups s25fs_s_fixups = { + .post_bfpt = s25fs_s_post_bfpt_fixups, +}; +/* NOTE: double check command sets and memory organization when you add * more nor chips. This current list focusses on newer chips, which * have been converging on command sets which including JEDEC ID.
@@ -2560,7 +2593,8 @@ static const struct flash_info spi_nor_ids[] = { SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) }, {"s25fl128s1" ,INFO6 (0x012018 ,0x4d0180 ,64 *1024 ,256 , SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) }, - { "s25fl256s0", INFO(0x010219, 0x4d00, 256 * 1024, 128, USE_CLSR) }, + { "s25fl256s0", INFO(0x010219, 0x4d00, 256 * 1024, 128, USE_CLSR) + .fixups = &s25fs_s_fixups, }, { "s25fl256s1", INFO(0x010219, 0x4d01, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) }, { "s25fl512s", INFO6(0x010220, 0x4d0080, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
@@ -2570,7 +2604,8 @@ static const struct flash_info spi_nor_ids[] = { { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) }, { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) }, { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) }, - { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) }, + { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) + .fixups = &s25fs_s_fixups, }, { "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) }, { "s25sl008a", INFO(0x010213, 0, 64 * 1024, 16, 0) }, { "s25sl016a", INFO(0x010214, 0, 64 * 1024, 32, 0) },
include/linux/mtd/spi-nor.h +5 -0
@@ -116,6 +116,7 @@/* Used for Spansion flashes only. */ #define SPINOR_OP_BRWR 0x17/* Bank register write */ #define SPINOR_OP_CLSR 0x30/* Clear status register 1 */ +#define SPINOR_OP_RDAR 0x65/* Read Any Register */ /* Used for Micron flashes only. */ #define SPINOR_OP_RD_EVCR 0x65/* Read EVCR register */
@@ -152,6 +153,10 @@#define SR2_QUAD_EN_BIT1 BIT(1)#define SR2_QUAD_EN_BIT7 BIT(7) +/* Used for Spansion flashes RDAR command only. */ +#define SPINOR_REG_CR3V 0x800004 +#define CR3V_02H_V BIT(4)/* Page Buffer Wrap */ +/* Supported SPI protocols */ #define SNOR_PROTO_INST_MASK GENMASK(23, 16)#define SNOR_PROTO_INST_SHIFT 16
Signature · 6 lines
2.4.6 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3] mtd: spi-nor: Fixup page size for S25FS-S
Hello all,
Quoted 14 lines · Alexander A Sverdlin
Spansion S25FS-S family has an issue in Basic Flash Parameter Table:
DWORD-11 bits 7-4 specify write page size 512 bytes. In reality this is configurable in the non-volatile CR3NV register and even factory default configuration is "wrap at 256 bytes". So blind relying on BFPT breaks write operation on these Flashes.All this story is vendor-specific, so add the corresponding fixup hook which first restores the safe page size of 256 bytes from struct
flash_infobut checks is more performant 512 bytes configuration is active and adjusts thepage_sizeaccordingly.Fixes f384b352c ("mtd: spi-nor: parse Serial Flash Discoverable Parameters (SFDP) tables")Signed-off-by Alexander Sverdlin <[email protected]>Change-Id I998829dfe43a6778ac439a693f5f41670acd20f1
[...]
drivers/mtd/spi-nor/spi-nor.c static struct spi_nor_fixups gd25q256_fixups = { · line 2350
Quoted 2 lines
drivers/mtd/spi-nor/spi-nor.c +2
-0+ ret =spi_nor_read_data (nor,SPINOR_REG_CR3V ,1 , &buf); +if (!ret && (buf &CR3V_02H_V ))
please ignore this patch! Besides forgotten Change-Id it has a a faulty error-handling above...
Signature · 6 lines
Best regards, Alexander Sverdlin. ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/