Re: [RFC PATCH] mtd: nand: add support for ts72xx

From: Nikita Shubin
Date: Sat Sep 30 2023 - 12:06:56 EST


Hello Miquèl!

On Wed, 2023-09-27 at 17:29 +0200, Miquel Raynal wrote:
> Hi Nikita,
>
> nikita.shubin@xxxxxxxxxxx wrote on Wed, 27 Sep 2023 17:15:25 +0300:
>
> > Technologic Systems has it's own nand controller implementation in
> > CPLD.
> >
> > Signed-off-by: Nikita Shubin <nikita.shubin@xxxxxxxxxxx>
> > ---
> > Hello Miquèl.
> >
> > Can you please take a look on it as RFC, so no need for the whole
> > series spinning ?
> >
> > I've got rid of all legacy stuff i think, however:
>
> I am glad you did, thanks a lot!
>
> > - look's like i me ts7250 is missing READCACHE and i couldn't find
> > any docs
> >   for this controller, so as legacy had no READCACHE, i mark it as
> > non-supported
>
> What NAND device do you use?
>
> The controller clearly supports it, as it just forwards whatever
> addrs/cmd/data cycle you input. However we are trying to fix the
> cache
> reads support which is unstable. If you use a NAND that is non-JEDEC
> and non-ONFI then please apply this and you will no longer be
> bothered
> by it:
> https://lore.kernel.org/linux-mtd/20230926132725.5d570e1b@xps-13/T/#md7e5e944a6a08e24f4f1e20068a49f94794ab945
>

You are totally right - controller and chip are different entities, i
somehow forgot about it:

```
# modprobe technologic-nand-controller
nand: device found, Manufacturer ID: 0xec, Chip ID: 0xf1
nand: Samsung NAND 128MiB 3,3V 8-bit
nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
Scanning device for bad blocks
Bad eraseblock 137 at 0x000001120000
Bad eraseblock 310 at 0x0000026c0000
3 fixed-partitions partitions found on MTD device 60000000.nand-
controller
Creating 3 MTD partitions on "60000000.nand-controller":
0x000000000000-0x000000020000 : "TS-BOOTROM"
0x000000020000-0x000007d20000 : "Linux"
0x000007d20000-0x000008000000 : "RedBoot"
```

This looks like Samsung K9F1G08U0D or K9F1G08U0B.

And the patch above totally solves my issues with READCACHE - thank
you!

> If you are using a Micron chip that specifies not supporting ECC
> correction together with sequential cache reads, then it's a problem
> that we will solve soon (you can hardcode
> chip->controller->supported_op.cont_read to 0);
>
> Otherwise we can discuss it.
>
> > - legacy wait implementation had no delays - only timeout and if i
> > set
> >   readb_poll_timeout() to something reasonable i experience speed
> > degradation
> >   on mtd_speedtest, can it be left as 0 ?
>
> Looks like the legacy implementation used cond_resched(). The delay
> needs to be observed before first checking for the status, it's a
> delay
> that is described in the spec, if you get the status before you might
> just not see a consistent value. I believe that is worth taking into
> account in your implementation below (don't wait then delay, it's
> not relevant). Can you share the values you've tried and the
> performances you've got?

The numbers are pretty stable, so indeed legacy is a bit faster,
followed up by new one with zero interval.

Legacy speedtest (old version of nand controller):

```
# insmod mtd_speedtest.ko dev=1

=================================================
mtd_speedtest: MTD device: 1
mtd_speedtest: MTD device size 131072000, eraseblock size 131072, page
size 2048, count of eraseblocks 1000, pages per eraseblock 64, OOB size
64
mtd_test: scanning for bad eraseblocks
mtd_test: block 136 is bad
mtd_test: block 309 is bad
mtd_test: scanned 1000 eraseblocks, 2 are bad
mtd_speedtest: testing eraseblock write speed
mtd_speedtest: eraseblock write speed is 3793 KiB/s
mtd_speedtest: testing eraseblock read speed
mtd_speedtest: eraseblock read speed is 3567 KiB/s
mtd_speedtest: testing page write speed
mtd_speedtest: page write speed is 3682 KiB/s
mtd_speedtest: testing page read speed
mtd_speedtest: page read speed is 3488 KiB/s
mtd_speedtest: testing 2 page write speed
mtd_speedtest: 2 page write speed is 3724 KiB/s
mtd_speedtest: testing 2 page read speed
mtd_speedtest: 2 page read speed is 3521 KiB/s
mtd_speedtest: Testing erase speed
mtd_speedtest: erase speed is 198709 KiB/s
mtd_speedtest: Testing 2x multi-block erase speed
mtd_speedtest: 2x multi-block erase speed is 200638 KiB/s
mtd_speedtest: Testing 4x multi-block erase speed
mtd_speedtest: 4x multi-block erase speed is 201545 KiB/s
mtd_speedtest: Testing 8x multi-block erase speed
mtd_speedtest: 8x multi-block erase speed is 202341 KiB/s
mtd_speedtest: Testing 16x multi-block erase speed
mtd_speedtest: 16x multi-block erase speed is 202909 KiB/s
mtd_speedtest: Testing 32x multi-block erase speed
mtd_speedtest: 32x multi-block erase speed is 203095 KiB/s
mtd_speedtest: Testing 64x multi-block erase speed
mtd_speedtest: 64x multi-block erase speed is 203482 KiB/s
mtd_speedtest: finished
=================================================
```

New version with interval zero:

```
# insmod mtd_speedtest.ko dev=1

=================================================
mtd_speedtest: MTD device: 1
mtd_speedtest: MTD device size 131072000, eraseblock size 131072, page
size 2048, count of eraseblocks 1000, pages per eraseblock 64, OOB size
64
mtd_test: scanning for bad eraseblocks
mtd_test: block 136 is bad
mtd_test: block 309 is bad
mtd_test: scanned 1000 eraseblocks, 2 are bad
mtd_speedtest: testing eraseblock write speed
mtd_speedtest: eraseblock write speed is 3685 KiB/s
mtd_speedtest: testing eraseblock read speed
mtd_speedtest: eraseblock read speed is 3517 KiB/s
mtd_speedtest: testing page write speed
mtd_speedtest: page write speed is 3592 KiB/s
mtd_speedtest: testing page read speed
mtd_speedtest: page read speed is 3444 KiB/s
mtd_speedtest: testing 2 page write speed
mtd_speedtest: 2 page write speed is 3608 KiB/s
mtd_speedtest: testing 2 page read speed
mtd_speedtest: 2 page read speed is 3475 KiB/s
mtd_speedtest: Testing erase speed
mtd_speedtest: erase speed is 194499 KiB/s
mtd_speedtest: Testing 2x multi-block erase speed
mtd_speedtest: 2x multi-block erase speed is 196316 KiB/s
mtd_speedtest: Testing 4x multi-block erase speed
mtd_speedtest: 4x multi-block erase speed is 198305 KiB/s
mtd_speedtest: Testing 8x multi-block erase speed
mtd_speedtest: 8x multi-block erase speed is 199263 KiB/s
mtd_speedtest: Testing 16x multi-block erase speed
mtd_speedtest: 16x multi-block erase speed is 199548 KiB/s
mtd_speedtest: Testing 32x multi-block erase speed
mtd_speedtest: 32x multi-block erase speed is 200221 KiB/s
mtd_speedtest: Testing 64x multi-block erase speed
mtd_speedtest: 64x multi-block erase speed is 200579 KiB/s
mtd_speedtest: finished
=================================================
```

New version with interval 100:

```
# insmod mtd_speedtest.ko dev=1

=================================================
mtd_speedtest: MTD device: 1
mtd_speedtest: MTD device size 131072000, eraseblock size 131072, page
size 2048, count of eraseblocks 1000, pages per eraseblock 64, OOB size
64
mtd_test: scanning for bad eraseblocks
mtd_test: block 136 is bad
mtd_test: block 309 is bad
mtd_test: scanned 1000 eraseblocks, 2 are bad
mtd_speedtest: testing eraseblock write speed
mtd_speedtest: eraseblock write speed is 2722 KiB/s
mtd_speedtest: testing eraseblock read speed
mtd_speedtest: eraseblock read speed is 2175 KiB/s
mtd_speedtest: testing page write speed
mtd_speedtest: page write speed is 2598 KiB/s
mtd_speedtest: testing page read speed
mtd_speedtest: page read speed is 2070 KiB/s
mtd_speedtest: testing 2 page write speed
mtd_speedtest: 2 page write speed is 2627 KiB/s
mtd_speedtest: testing 2 page read speed
mtd_speedtest: 2 page read speed is 2106 KiB/s
mtd_speedtest: Testing erase speed
mtd_speedtest: erase speed is 175851 KiB/s
mtd_speedtest: Testing 2x multi-block erase speed
mtd_speedtest: 2x multi-block erase speed is 181582 KiB/s
mtd_speedtest: Testing 4x multi-block erase speed
mtd_speedtest: 4x multi-block erase speed is 181579 KiB/s
mtd_speedtest: Testing 8x multi-block erase speed
mtd_speedtest: 8x multi-block erase speed is 182735 KiB/s
mtd_speedtest: Testing 16x multi-block erase speed
mtd_speedtest: 16x multi-block erase speed is 183589 KiB/s
mtd_speedtest: Testing 32x multi-block erase speed
mtd_speedtest: 32x multi-block erase speed is 183003 KiB/s
mtd_speedtest: Testing 64x multi-block erase speed
mtd_speedtest: 64x multi-block erase speed is 183460 KiB/s
mtd_speedtest: finished
=================================================
```

Also providing version with zero interval and "if (instr->delay_ns)"
dropped - it's optional as far i understood:

```
# insmod mtd_speedtest.ko dev=1

=================================================
mtd_speedtest: MTD device: 1
mtd_speedtest: MTD device size 131072000, eraseblock size 131072, page
size 2048, count of eraseblocks 1000, pages per eraseblock 64, OOB size
64
mtd_test: scanning for bad eraseblocks
mtd_test: block 136 is bad
mtd_test: block 309 is bad
mtd_test: scanned 1000 eraseblocks, 2 are bad
mtd_speedtest: testing eraseblock write speed
mtd_speedtest: eraseblock write speed is 3695 KiB/s
mtd_speedtest: testing eraseblock read speed
mtd_speedtest: eraseblock read speed is 3532 KiB/s
mtd_speedtest: testing page write speed
mtd_speedtest: page write speed is 3593 KiB/s
mtd_speedtest: testing page read speed
mtd_speedtest: page read speed is 3457 KiB/s
mtd_speedtest: testing 2 page write speed
mtd_speedtest: 2 page write speed is 3640 KiB/s
mtd_speedtest: testing 2 page read speed
mtd_speedtest: 2 page read speed is 3488 KiB/s
mtd_speedtest: Testing erase speed
mtd_speedtest: erase speed is 195451 KiB/s
mtd_speedtest: Testing 2x multi-block erase speed
mtd_speedtest: 2x multi-block erase speed is 198538 KiB/s
mtd_speedtest: Testing 4x multi-block erase speed
mtd_speedtest: 4x multi-block erase speed is 199509 KiB/s
mtd_speedtest: Testing 8x multi-block erase speed
mtd_speedtest: 8x multi-block erase speed is 199871 KiB/s
mtd_speedtest: Testing 16x multi-block erase speed
mtd_speedtest: 16x multi-block erase speed is 200075 KiB/s
mtd_speedtest: Testing 32x multi-block erase speed
mtd_speedtest: 32x multi-block erase speed is 200683 KiB/s
mtd_speedtest: Testing 64x multi-block erase speed
mtd_speedtest: 64x multi-block erase speed is 200850 KiB/s
mtd_speedtest: finished
=================================================

```


>
> Thanks,
> Miquèl
>