mbox series

[v3,0/5] mtd: spi-nor: introduce die erase

Message ID 20231125123529.55686-1-tudor.ambarus@linaro.org
Headers show
Series mtd: spi-nor: introduce die erase | expand

Message

Tudor Ambarus Nov. 25, 2023, 12:35 p.m. UTC
changes in v3:
- fix code, thanks to Fabio's testing
- found a n25q00 and tested on my side too
- fixed micron's die erase support

Add support for die erase.
JESD216 mentions die erase, but does not provide an opcode for it.
Check BFPT dword 11, bits 30:24, "Chip Erase, Typical time", it says:

"Typical time to erase one chip (die). User must poll device busy to
determine if the operation has completed. For a device consisting of
multiple dies, that are individually accessed, the time is for each die
to which a chip erase command is applied."

So when a flash consists of a single die, this is the erase time for the
full chip (die) erase, and when it consists of multiple dies, it's the
die erase time. Chip and die are the same thing.

For what concerns the Micron flashes, unfortunately Micron does not
provide a 4-byte opcode equivalent for the die erase. The SFDP 4BAIT
table fails to consider the die erase too, the standard can be improved.
Thus we're forced to enter in the 4 byte address mode in order to benefit
of the die erase. This comes with some changes into the core.
    
Tested on n25q00. This flash defines the 4BAIT SFDP table, thus it will
use the 4BAIT opcodes for reads, page programs or erases, with the
exception that it will use the die erase command in the 4 byte address
mode. 

Fabio Estevam (1):
  mtd: spi-nor: micron-st: Add support for mt25qu01g

Tudor Ambarus (4):
  mtd: spi-nor: add erase die (chip) capability
  mtd: spi-nor: spansion: enable die erase for multi die flashes
  mtd: spi-nor: micron-st: enable die erase for multi die flashes
  mtd: spi-nor: remove NO_CHIP_ERASE flag

 drivers/mtd/spi-nor/core.c      | 143 ++++++++++++++++++++------------
 drivers/mtd/spi-nor/core.h      |  16 ++--
 drivers/mtd/spi-nor/debugfs.c   |   2 +-
 drivers/mtd/spi-nor/micron-st.c |  59 ++++++++++++-
 drivers/mtd/spi-nor/spansion.c  |   4 +-
 5 files changed, 158 insertions(+), 66 deletions(-)

Comments

Tudor Ambarus Nov. 25, 2023, 12:37 p.m. UTC | #1
I made a typo on Fabio's email address. Now added correctly.
Fabio Estevam Nov. 25, 2023, 5:29 p.m. UTC | #2
Hi Tudor,

On 25/11/2023 09:37, Tudor Ambarus wrote:
> I made a typo on Fabio's email address. Now added correctly.

It looks like the Subject of patch 3/5 is not complete:

[PATCH v3 3/5] mtd: spi-nor: micron-st: "

Feel free to add to this series:

Tested-by: Fabio Estevam <festevam@denx.de>
Tudor Ambarus Nov. 30, 2023, 10:42 a.m. UTC | #3
On 11/25/23 17:29, Fabio Estevam wrote:
> Hi Tudor,

Hi!

> 
> On 25/11/2023 09:37, Tudor Ambarus wrote:
>> I made a typo on Fabio's email address. Now added correctly.
> 
> It looks like the Subject of patch 3/5 is not complete:
> 
> [PATCH v3 3/5] mtd: spi-nor: micron-st: "
> 
> Feel free to add to this series:
> 
> Tested-by: Fabio Estevam <festevam@denx.de>


Thanks, will do. Would you please replicate the tests that I did in
patch 3/5 for mt25qu01q? You'll have to modify a bit the offsets for the
die and cross die tests.

Cheers,
ta
Fabio Estevam Dec. 4, 2023, 8:59 p.m. UTC | #4
On 30/11/2023 07:42, Tudor Ambarus wrote:

> Thanks, will do. Would you please replicate the tests that I did in
> patch 3/5 for mt25qu01q? You'll have to modify a bit the offsets for 
> the
> die and cross die tests.


Here it goes.

Can this series be applied now?

:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/partname
mt25qu01g

:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/jedec_id
20bb21104400

:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/manufacturer
st

:~# xxd -p  
/sys/devices/platform/soc@0/30800000.bus/30bb0000.spi/spi_master/spi0/spi0.0/spi-nor/sfdp
53464450060101ff00060110300000ff84000102800000ffffffffffffff
ffffffffffffffffffffffffffffffffffffe520fbffffffff3f29eb276b
273b27bbffffffffffff27bbffff29eb0c2010d80f520000244a99008b8e
03e1ac0127387a757a75fbbdd55c4a0f82ff81bd3d36ffffffffffffffff
ffffffffffffffffffe7ffff21dcffff

:~# sha256sum /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
e49dfee6eeb73c55e94c07a8c7d352dd7d8774b830a64ed1059ef6e7bc833668  
/sys/bus/spi/devices/spi0.0/spi-nor/sfdp

:~# cat /sys/kernel/debug/spi-nor/spi0.0/capabilities
Supported read modes by the flash
  1S-1S-1S
   opcode	0x13
   mode cycles	0
   dummy cycles	0
  1S-1S-2S
   opcode	0x3c
   mode cycles	1
   dummy cycles	7
  1S-2S-2S
   opcode	0xbc
   mode cycles	1
   dummy cycles	7
  2S-2S-2S
   opcode	0xbc
   mode cycles	1
   dummy cycles	7
  1S-1S-4S
   opcode	0x6c
   mode cycles	1
   dummy cycles	7
  1S-4S-4S
   opcode	0xec
   mode cycles	1
   dummy cycles	9
  4S-4S-4S
   opcode	0xec
   mode cycles	1
   dummy cycles	9

Supported page program modes by the flash
  1S-1S-1S
   opcode	0x12
  1S-1S-4S
   opcode	0x34
  1S-4S-4S
   opcode	0x3e

:~# cat /sys/kernel/debug/spi-nor/spi0.0/params
name		mt25qu01g
id		20 bb 21 10 44 00
size		128 MiB
write size	1
page size	256
address nbytes	4
flags		4B_OPCODES | HAS_4BAIT | HAS_16BIT_SR | SOFT_RESET

opcodes
  read		0x6c
   dummy cycles	8
  erase		0x21
  program	0x12
  8D extension	none

protocols
  read		1S-1S-4S
  write		1S-1S-1S
  register	1S-1S-1S

erase commands
  21 (4.00 KiB) [1]
  dc (64.0 KiB) [3]
  c4 (128 MiB)

sector map
  region (in hex)   | erase mask | flags
  ------------------+------------+----------
  00000000-07ffffff |     [ 123] |
root@mcde3000a:~#

:~# dd if=/dev/urandom of=./spi_test bs=1M count=2
2+0 records in
2+0 records out
2097152 bytes (2.1 MB, 2.0 MiB) copied, 0.0303915 s, 69.0 MB/s

:~# mtd_debug erase /dev/mtd0 0 2097152
Erased 2097152 bytes from address 0x00000000 in flash
:~# mtd_debug read /dev/mtd0 0 2097152 spi_read
Copied 2097152 bytes from address 0x00000000 in flash to spi_read
:~# hexdump spi_read
0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0200000
:~# sha256sum spi_read
4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5  
spi_read
:~# mtd_debug write /dev/mtd0 0 2097152 spi_test
Copied 2097152 bytes from spi_test to address 0x00000000 in flash

:~# mtd_debug read /dev/mtd0 0 2097152 spi_read
Copied 2097152 bytes from address 0x00000000 in flash to spi_read
:~# sha256sum spi*
d5c15629e1fa019941cb820eff6ffd2a9008b5796bb23a67c351f42af48ce180  
spi_read
d5c15629e1fa019941cb820eff6ffd2a9008b5796bb23a67c351f42af48ce180  
spi_test
:~# mtd_debug erase /dev/mtd0 0 2097152
Erased 2097152 bytes from address 0x00000000 in flash

:~# mtd_debug read /dev/mtd0 0 2097152 spi_read
Copied 2097152 bytes from address 0x00000000 in flash to spi_read
:~# sha256sum spi*
4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5  
spi_read
d5c15629e1fa019941cb820eff6ffd2a9008b5796bb23a67c351f42af48ce180  
spi_test
:~# mtd_debug info /dev/mtd0
mtd.type = MTD_NORFLASH
mtd.flags = MTD_CAP_NORFLASH
mtd.size = 134217728 (128M)
mtd.erasesize = 4096 (4K)
mtd.writesize = 1
mtd.oobsize = 0
regions = 0


real	0m0.005s
user	0m0.001s
sys	0m0.005s
:~# time mtd_debug erase /dev/mtd0 0 134217728
Erased 134217728 bytes from address 0x00000000 in flash

real	0m1.768s
user	0m0.001s
sys	0m1.609s
:~# echo "ta writes something into the first die" > firstdie
:~# echo "ta writes something into the second die" > seconddie
:~# ls -al
total 4112
drwx------ 2 root root    4096 Dec  4 20:36 .
drwxr-xr-x 4 root root    4096 Mar  9  2018 ..
-rw-r--r-- 1 root root      39 Dec  4 20:36 firstdie
-rw-r--r-- 1 root root      40 Dec  4 20:36 seconddie
-rw-r--r-- 1 root root 2097152 Dec  4 20:35 spi_read
-rw-r--r-- 1 root root 2097152 Dec  4 20:32 spi_test
:~# mtd_debug write /dev/mtd0 0 39 firstdie
Copied 39 bytes from firstdie to address 0x00000000 in flash
:~# mtd_debug write /dev/mtd0 67108864 40 seconddie
Copied 40 bytes from seconddie to address 0x04000000 in flash
:~# mtd_debug read /dev/mtd0 0 134217728 read
Copied 134217728 bytes from address 0x00000000 in flash to read
:~# hexdump -C read
00000000  74 61 20 77 72 69 74 65  73 20 73 6f 6d 65 74 68  |ta writes 
someth|
00000010  69 6e 67 20 69 6e 74 6f  20 74 68 65 20 66 69 72  |ing into 
the fir|
00000020  73 74 20 64 69 65 0a ff  ff ff ff ff ff ff ff ff  |st 
die..........|
00000030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  
|................|
*
04000000  74 61 20 77 72 69 74 65  73 20 73 6f 6d 65 74 68  |ta writes 
someth|
04000010  69 6e 67 20 69 6e 74 6f  20 74 68 65 20 73 65 63  |ing into 
the sec|
04000020  6f 6e 64 20 64 69 65 0a  ff ff ff ff ff ff ff ff  |ond 
die.........|
04000030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  
|................|
*
08000000
:~# time mtd_debug erase /dev/mtd0 0 134217728
Erased 134217728 bytes from address 0x00000000 in flash

real	0m2.029s
user	0m0.001s
sys	0m1.853s

:~# echo "ta writes a something crossing the dice" > cross-dice
:~# mtd_debug write /dev/mtd0 67108857 40 cross-dice
Copied 40 bytes from cross-dice to address 0x03fffff9 in flash

:~# mtd_debug read /dev/mtd0 0 134217728 read
Copied 134217728 bytes from address 0x00000000 in flash to read
:~# hexdump -C read
00000000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  
|................|
*
03fffff0  ff ff ff ff ff ff ff ff  ff 74 61 20 77 72 69 74  |.........ta 
writ|
04000000  65 73 20 61 20 73 6f 6d  65 74 68 69 6e 67 20 63  |es a 
something c|
04000010  72 6f 73 73 69 6e 67 20  74 68 65 20 64 69 63 65  |rossing the 
dice|
04000020  0a ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  
|................|
04000030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  
|................|
*
08000000
:~# mtd_debug read /dev/mtd0 67108857 40 read
Copied 40 bytes from address 0x03fffff9 in flash to read
:~# hexdump -C read
00000000  74 61 20 77 72 69 74 65  73 20 61 20 73 6f 6d 65  |ta writes a 
some|
00000010  74 68 69 6e 67 20 63 72  6f 73 73 69 6e 67 20 74  |thing 
crossing t|
00000020  68 65 20 64 69 63 65 0a                           |he dice.|
00000028
:~#
Tudor Ambarus Dec. 5, 2023, 7:40 a.m. UTC | #5
On 04.12.2023 22:59, Fabio Estevam wrote:
> 
>> Thanks, will do. Would you please replicate the tests that I did in
>> patch 3/5 for mt25qu01q? You'll have to modify a bit the offsets for the
>> die and cross die tests.
> 
> 
> Here it goes.

Wonderful, thanks!

> 
> Can this series be applied now?

Yes. Michael, any objections?

Thanks,
ta
Tudor Ambarus Dec. 6, 2023, 9:32 a.m. UTC | #6
On Sat, 25 Nov 2023 14:35:24 +0200, Tudor Ambarus wrote:
> changes in v3:
> - fix code, thanks to Fabio's testing
> - found a n25q00 and tested on my side too
> - fixed micron's die erase support
> 
> Add support for die erase.
> JESD216 mentions die erase, but does not provide an opcode for it.
> Check BFPT dword 11, bits 30:24, "Chip Erase, Typical time", it says:
> 
> [...]

Applied to git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git,
spi-nor/next branch. Thanks!

[1/5] mtd: spi-nor: add erase die (chip) capability
      https://git.kernel.org/mtd/c/9641423174d0
[2/5] mtd: spi-nor: spansion: enable die erase for multi die flashes
      https://git.kernel.org/mtd/c/461d0babb544
[3/5] mtd: spi-nor: micron-st: enable die erase for multi die flashes
      https://git.kernel.org/mtd/c/53919a968b43
[4/5] mtd: spi-nor: remove NO_CHIP_ERASE flag
      https://git.kernel.org/mtd/c/06de1257aae7
[5/5] mtd: spi-nor: micron-st: Add support for mt25qu01g
      https://git.kernel.org/mtd/c/c692ba6de1c5

Cheers,