All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/9] mtd: spi-nor: read while write support
@ 2022-12-15  8:12 Miquel Raynal
  2022-12-15  8:12 ` [PATCH v3 1/9] mtd: spi-nor: Create macros to define chip IDs and geometries Miquel Raynal
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

Hello folks,

Here is the follow-up of the RFC trying to bring a little bit of
parallelism to support SPI-NOR Read While Write feature on parts
supporting it and featuring several banks.

I have received some hardware to make it work, so since the RFC, the
series has been updated to fix my mistakes, but the overall idea is the
same.

There is nothing Macronix specific in the implementation, the operations
and opcodes are exactly the same as before. The only difference being:
we may consider the chip usable when it is in the busy state during a
write or an erase. Any chip with an internal split allowing to perform
parallel operations might possibly leverage the benefits of this
implementation.

The first patches are just refactoring and preparation work, there is
almost no functional change, it's just a way to prepare the introduction
of the new locking mechanism and hopefully provide the cleanest and
simplest diff possible for this new feature. The actual change is all
contained in "mtd: spi-nor: Enhance locking to support reads while
writes". The logic is described in the commit log and copy/pasted here
for clarity:

"
    On devices featuring several banks, the Read While Write (RWW) feature
    is here to improve the overall performance when performing parallel
    reads and writes at different locations (different banks). The
    following constraints have to be taken into account:
    1#: A single operation can be performed in a given bank.
    2#: Only a single program or erase operation can happen on the entire
        chip (common hardware limitation to limit costs)
    3#: Reads must remain serialized even though reads on different banks
        might occur at the same time.
    4#: The I/O bus is unique and thus is the most constrained resource, all
        spi-nor operations requiring access to the spi bus (through the spi
        controller) must be serialized until the bus exchanges are over. So
        we must ensure a single operation can be "sent" at a time.
    5#: Any other operation that would not be either a read or a write or an
        erase is considered requiring access to the full chip and cannot be
        parallelized, we then need to ensure the full chip is in the idle
        state when this occurs.
    
    All these constraints can easily be managed with a proper locking model:
    1#: Is enforced by a bitfield of the in-use banks, so that only a single
        operation can happen in a specific bank at any time.
    2#: Is handled by the ongoing_pe boolean which is set before any write
        or erase, and is released only at the very end of the
        operation. This way, no other destructive operation on the chip can
        start during this time frame.
    3#: An ongoing_rd boolean allows to track the ongoing reads, so that
        only one can be performed at a time.
    4#: An ongoing_io boolean is introduced in order to capture and
        serialize bus accessed. This is the one being released "sooner"
        than before, because we only need to protect the chip against
        other SPI accesses during the I/O phase, which for the
        destructive operations is the beginning of the operation (when
        we send the command cycles and possibly the data), while the
        second part of the operation (the erase delay or the
        programmation delay) is when we can do something else in another
        bank.
    5#: Is handled by the three booleans presented above, if any of them is
        set, the chip is not yet ready for the operation and must wait.
    
    All these internal variables are protected by the existing lock, so that
    changes in this structure are atomic. The serialization is handled with
    a wait queue."

Here is now a benchmark with a Macronix MX25UW51245G with 4 banks and RWW
support:

     // Testing the two accesses in the same bank
     $ flash_speed -b0 -k0 -c10 -d /dev/mtd0
     [...]
     testing read while write latency
     read while write took 51ms, read ended after 51ms

     // Testing the two accesses within different banks
     $ flash_speed -b0 -k4096 -c10 -d /dev/mtd0
     [...]
     testing read while write latency
     read while write took 51ms, read ended after 20ms

Parallel accesses have been validated with io_paral. A slight increase
of the time spent on this test has however been noticed. With my
configuration, over a limited number of blocks, the overall operation
took 22 min without any RWW changes up to 27 min with these changes,
maybe due to the number of additional scheduling situations involved).

Here is a branch with the mtd-utils patch bringing support for this
additional "-k" parameter in flash_speed (for the second block to use
during RWW testing), used to get the above results:
https://github.com/miquelraynal/mtd-utils/compare/master...rww

Cheers,
Miquèl

Changes in v3:
* Fix the bank offsets calculations by providing the same values when
  locking and when unlocking (might be changed by the functions themselves
  without use noticing).
* I completely changed the way the locking works because there was a new
  constraint: reads cannot be interrupted and status reads cannot happen
  during a read. Hence, as the multi-locks design was starting to be too
  messy, I changed the implementation to use a bunch of variables to
  track the read while write state, protected by the main spi-nor
  lock. If the internal state does not allow the operation, a sleep
  starts in a queue, until the threads are woken up after a state
  update. I know it is very verbose, I am open to suggestions.

Miquel Raynal (9):
  mtd: spi-nor: Create macros to define chip IDs and geometries
  mtd: spi-nor: Introduce the concept of bank
  mtd: spi-nor: Add a macro to define more banks
  mtd: spi-nor: Reorder the preparation vs locking steps
  mtd: spi-nor: Separate preparation and locking
  mtd: spi-nor: Prepare the introduction of a new locking mechanism
  mtd: spi-nor: Add a RWW flag
  mtd: spi-nor: Enhance locking to support reads while writes
  mtd: spi-nor: macronix: Add support for mx25uw51245g with RWW

 drivers/mtd/spi-nor/core.c     | 396 +++++++++++++++++++++++++++++++--
 drivers/mtd/spi-nor/core.h     |  61 ++---
 drivers/mtd/spi-nor/macronix.c |   3 +
 include/linux/mtd/spi-nor.h    |  13 ++
 4 files changed, 424 insertions(+), 49 deletions(-)

-- 
2.34.1


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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 1/9] mtd: spi-nor: Create macros to define chip IDs and geometries
  2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
@ 2022-12-15  8:12 ` Miquel Raynal
  2023-01-31  8:58   ` Tudor Ambarus
  2022-12-15  8:12 ` [PATCH v3 2/9] mtd: spi-nor: Introduce the concept of bank Miquel Raynal
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

The INFO() macro defines an ID array and a couple of geometry
properties. Right now all its lines are duplicated twice because of the
INFO6() macro (for extended IDs) and soon as well we will need to add a
geometry parameter to include the number of banks.

In order to limit the code duplication, let's create a number of
intermediate macros which will facilitate defining high-level INFOX()
macros.

There is not functional change.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
---
 drivers/mtd/spi-nor/core.h | 43 ++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 85b0cf254e97..dc74c7be3e28 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -527,33 +527,30 @@ struct flash_info {
 	const struct spi_nor_fixups *fixups;
 };
 
+#define SPI_NOR_ID_2ITEMS(_id) ((_id) >> 8) & 0xff, (_id) & 0xff
+#define SPI_NOR_ID_3ITEMS(_id) ((_id) >> 16) & 0xff, SPI_NOR_ID_2ITEMS(_id)
+
+#define SPI_NOR_ID(_jedec_id, _ext_id)					\
+	.id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_2ITEMS(_ext_id) }, \
+	.id_len = !(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))
+
+#define SPI_NOR_ID6(_jedec_id, _ext_id)					\
+	.id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_3ITEMS(_ext_id) }, \
+	.id_len = 6
+
+#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors)			\
+	.sector_size = (_sector_size),					\
+	.n_sectors = (_n_sectors),					\
+	.page_size = 256
+
 /* Used when the "_ext_id" is two bytes at most */
 #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
-		.id = {							\
-			((_jedec_id) >> 16) & 0xff,			\
-			((_jedec_id) >> 8) & 0xff,			\
-			(_jedec_id) & 0xff,				\
-			((_ext_id) >> 8) & 0xff,			\
-			(_ext_id) & 0xff,				\
-			},						\
-		.id_len = (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))),	\
-		.sector_size = (_sector_size),				\
-		.n_sectors = (_n_sectors),				\
-		.page_size = 256,					\
+	SPI_NOR_ID((_jedec_id), (_ext_id)),				\
+	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
 
 #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
-		.id = {							\
-			((_jedec_id) >> 16) & 0xff,			\
-			((_jedec_id) >> 8) & 0xff,			\
-			(_jedec_id) & 0xff,				\
-			((_ext_id) >> 16) & 0xff,			\
-			((_ext_id) >> 8) & 0xff,			\
-			(_ext_id) & 0xff,				\
-			},						\
-		.id_len = 6,						\
-		.sector_size = (_sector_size),				\
-		.n_sectors = (_n_sectors),				\
-		.page_size = 256,					\
+	SPI_NOR_ID6((_jedec_id), (_ext_id)),				\
+	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
 
 #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_nbytes)	\
 		.sector_size = (_sector_size),				\
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 2/9] mtd: spi-nor: Introduce the concept of bank
  2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
  2022-12-15  8:12 ` [PATCH v3 1/9] mtd: spi-nor: Create macros to define chip IDs and geometries Miquel Raynal
@ 2022-12-15  8:12 ` Miquel Raynal
  2023-01-19 16:34   ` Tudor Ambarus
  2022-12-15  8:12 ` [PATCH v3 3/9] mtd: spi-nor: Add a macro to define more banks Miquel Raynal
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

SPI-NOR chips are made of pages, which gathered in small groups make
(erase) sectors. Sectors, gathered together, make banks inside the
chip. So far there was only one bank per device supported, but we are
about to introduce support for new chips featuring several banks (up to
4 so far) where different operations may happen in parallel.

Let's allow describing these additional bank parameters.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
---
 drivers/mtd/spi-nor/core.c |  3 ++-
 drivers/mtd/spi-nor/core.h | 16 +++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index f2c64006f8d7..38a57aac6754 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2539,7 +2539,8 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
 
 	/* Set SPI NOR sizes. */
 	params->writesize = 1;
-	params->size = (u64)info->sector_size * info->n_sectors;
+	params->bank_size = (u64)info->sector_size * info->n_sectors;
+	params->size = params->bank_size * info->n_banks;
 	params->page_size = info->page_size;
 
 	if (!(info->flags & SPI_NOR_NO_FR)) {
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index dc74c7be3e28..8a067d56c995 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -336,7 +336,8 @@ struct spi_nor_otp {
  * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216
  * Serial Flash Discoverable Parameters (SFDP) tables.
  *
- * @size:		the flash memory density in bytes.
+ * @bank_size:		the flash memory bank density in bytes.
+ * @size:		the total flash memory density in bytes.
  * @writesize		Minimal writable flash unit size. Defaults to 1. Set to
  *			ECC unit size for ECC-ed flashes.
  * @page_size:		the page size of the SPI NOR flash memory.
@@ -374,6 +375,7 @@ struct spi_nor_otp {
  * @locking_ops:	SPI NOR locking methods.
  */
 struct spi_nor_flash_parameter {
+	u64				bank_size;
 	u64				size;
 	u32				writesize;
 	u32				page_size;
@@ -434,7 +436,8 @@ struct spi_nor_fixups {
  * @id_len:         the number of bytes of ID.
  * @sector_size:    the size listed here is what works with SPINOR_OP_SE, which
  *                  isn't necessarily called a "sector" by the vendor.
- * @n_sectors:      the number of sectors.
+ * @n_sectors:      the number of sectors per bank.
+ * @n_banks:        the number of banks.
  * @page_size:      the flash's page size.
  * @addr_nbytes:    number of address bytes to send.
  *
@@ -493,6 +496,7 @@ struct flash_info {
 	u8 id_len;
 	unsigned sector_size;
 	u16 n_sectors;
+	u16 n_banks;
 	u16 page_size;
 	u8 addr_nbytes;
 
@@ -538,23 +542,25 @@ struct flash_info {
 	.id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_3ITEMS(_ext_id) }, \
 	.id_len = 6
 
-#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors)			\
+#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors, _n_banks)		\
 	.sector_size = (_sector_size),					\
 	.n_sectors = (_n_sectors),					\
+	.n_banks = (_n_banks),						\
 	.page_size = 256
 
 /* Used when the "_ext_id" is two bytes at most */
 #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
 	SPI_NOR_ID((_jedec_id), (_ext_id)),				\
-	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
+	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),
 
 #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
 	SPI_NOR_ID6((_jedec_id), (_ext_id)),				\
-	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
+	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),
 
 #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_nbytes)	\
 		.sector_size = (_sector_size),				\
 		.n_sectors = (_n_sectors),				\
+		.n_banks = 1,						\
 		.page_size = (_page_size),				\
 		.addr_nbytes = (_addr_nbytes),				\
 		.flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,		\
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 3/9] mtd: spi-nor: Add a macro to define more banks
  2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
  2022-12-15  8:12 ` [PATCH v3 1/9] mtd: spi-nor: Create macros to define chip IDs and geometries Miquel Raynal
  2022-12-15  8:12 ` [PATCH v3 2/9] mtd: spi-nor: Introduce the concept of bank Miquel Raynal
@ 2022-12-15  8:12 ` Miquel Raynal
  2022-12-15  8:12 ` [PATCH v3 4/9] mtd: spi-nor: Reorder the preparation vs locking steps Miquel Raynal
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

Most of the chips on the market only feature a single bank. However, new
chips may support more than a single bank, with the possibility to
parallelize some operations. Let's introduce an INFOB() macro which also
takes a n_bank parameter.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
---
 drivers/mtd/spi-nor/core.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 8a067d56c995..044d49d749e0 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -553,6 +553,10 @@ struct flash_info {
 	SPI_NOR_ID((_jedec_id), (_ext_id)),				\
 	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),
 
+#define INFOB(_jedec_id, _ext_id, _sector_size, _n_sectors, _n_banks)	\
+	SPI_NOR_ID((_jedec_id), (_ext_id)),				\
+	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), (_n_banks)),
+
 #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
 	SPI_NOR_ID6((_jedec_id), (_ext_id)),				\
 	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 4/9] mtd: spi-nor: Reorder the preparation vs locking steps
  2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
                   ` (2 preceding siblings ...)
  2022-12-15  8:12 ` [PATCH v3 3/9] mtd: spi-nor: Add a macro to define more banks Miquel Raynal
@ 2022-12-15  8:12 ` Miquel Raynal
  2023-01-31  5:11   ` Tudor Ambarus
  2022-12-15  8:12 ` [PATCH v3 5/9] mtd: spi-nor: Separate preparation and locking Miquel Raynal
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

The ->prepare()/->unprepare() hooks are now legacy, and there are only
two controllers left supporting them. In both cases, the implementation
acquires a mutex, which is somehow redundant with the spi-nor main lock
that we acquire as well in the spi_nor_[un]lock_and_[un]prep() helpers.

While the mutex taken in the core is necessary, the helper can be
reorganized to first do the preparation, then acquire the core
lock. This is necessary in order to be able to improve the locking
mechanism in the core and should have no side effect.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/spi-nor/core.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 38a57aac6754..de77ca55f74d 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1074,23 +1074,20 @@ int spi_nor_lock_and_prep(struct spi_nor *nor)
 {
 	int ret = 0;
 
-	mutex_lock(&nor->lock);
-
-	if (nor->controller_ops &&  nor->controller_ops->prepare) {
+	if (nor->controller_ops && nor->controller_ops->prepare)
 		ret = nor->controller_ops->prepare(nor);
-		if (ret) {
-			mutex_unlock(&nor->lock);
-			return ret;
-		}
-	}
+
+	mutex_lock(&nor->lock);
+
 	return ret;
 }
 
 void spi_nor_unlock_and_unprep(struct spi_nor *nor)
 {
+	mutex_unlock(&nor->lock);
+
 	if (nor->controller_ops && nor->controller_ops->unprepare)
 		nor->controller_ops->unprepare(nor);
-	mutex_unlock(&nor->lock);
 }
 
 static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr)
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 5/9] mtd: spi-nor: Separate preparation and locking
  2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
                   ` (3 preceding siblings ...)
  2022-12-15  8:12 ` [PATCH v3 4/9] mtd: spi-nor: Reorder the preparation vs locking steps Miquel Raynal
@ 2022-12-15  8:12 ` Miquel Raynal
  2022-12-15  8:12 ` [PATCH v3 6/9] mtd: spi-nor: Prepare the introduction of a new locking mechanism Miquel Raynal
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

While this operation will remain a single function call in the end,
let's extract the logic of the [un]prepare calls within their own static
helper. We will soon add new flavors of the *_[un]lock_and_[un]prepare()
helper, having the preparation logic outside will save us from duplicating
code over and over again.

There is no functional change.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/spi-nor/core.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index de77ca55f74d..f87e57d97692 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1070,24 +1070,40 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
 	}
 }
 
-int spi_nor_lock_and_prep(struct spi_nor *nor)
+static int spi_nor_prep(struct spi_nor *nor)
 {
 	int ret = 0;
 
 	if (nor->controller_ops && nor->controller_ops->prepare)
 		ret = nor->controller_ops->prepare(nor);
 
+	return ret;
+}
+
+static void spi_nor_unprep(struct spi_nor *nor)
+{
+	if (nor->controller_ops && nor->controller_ops->unprepare)
+		nor->controller_ops->unprepare(nor);
+}
+
+int spi_nor_lock_and_prep(struct spi_nor *nor)
+{
+	int ret;
+
+	ret = spi_nor_prep(nor);
+	if (ret)
+		return ret;
+
 	mutex_lock(&nor->lock);
 
-	return ret;
+	return 0;
 }
 
 void spi_nor_unlock_and_unprep(struct spi_nor *nor)
 {
 	mutex_unlock(&nor->lock);
 
-	if (nor->controller_ops && nor->controller_ops->unprepare)
-		nor->controller_ops->unprepare(nor);
+	spi_nor_unprep(nor);
 }
 
 static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr)
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 6/9] mtd: spi-nor: Prepare the introduction of a new locking mechanism
  2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
                   ` (4 preceding siblings ...)
  2022-12-15  8:12 ` [PATCH v3 5/9] mtd: spi-nor: Separate preparation and locking Miquel Raynal
@ 2022-12-15  8:12 ` Miquel Raynal
  2023-01-31  5:29   ` Tudor Ambarus
  2022-12-15  8:12 ` [PATCH v3 7/9] mtd: spi-nor: Add a RWW flag Miquel Raynal
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

This commit alone just introduces two new "lock and prepare" pairs of
helpers which do the exact same thing as before. They will soon be
improved in a followup commit which actually brings the logic, but I
figured out it was more readable to do it this way.

One new pair is suffixed _pe which stands for "program and erase" and
hence is being called by spi_nor_write() and spi_nor_erase().

The other pair is suffixed _rd which stands for "read" and hence is
being called by spi_nor_read().

One note however, these extra helpers will need to know the operation
range, so they come with two new parameters to define it. Otherwise
there is no functional change.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/spi-nor/core.c | 59 ++++++++++++++++++++++++++++++++++----
 1 file changed, 53 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index f87e57d97692..6c08114e4275 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1086,6 +1086,7 @@ static void spi_nor_unprep(struct spi_nor *nor)
 		nor->controller_ops->unprepare(nor);
 }
 
+/* Generic helpers for internal locking and serialization */
 int spi_nor_lock_and_prep(struct spi_nor *nor)
 {
 	int ret;
@@ -1106,6 +1107,48 @@ void spi_nor_unlock_and_unprep(struct spi_nor *nor)
 	spi_nor_unprep(nor);
 }
 
+/* Internal locking helpers for program and erase operations */
+static int spi_nor_lock_and_prep_pe(struct spi_nor *nor, loff_t start, size_t len)
+{
+	int ret;
+
+	ret = spi_nor_prep(nor);
+	if (ret)
+		return ret;
+
+	mutex_lock(&nor->lock);
+
+	return 0;
+}
+
+static void spi_nor_unlock_and_unprep_pe(struct spi_nor *nor, loff_t start, size_t len)
+{
+	mutex_unlock(&nor->lock);
+
+	spi_nor_unprep(nor);
+}
+
+/* Internal locking helpers for read operations */
+static int spi_nor_lock_and_prep_rd(struct spi_nor *nor, loff_t start, size_t len)
+{
+	int ret;
+
+	ret = spi_nor_prep(nor);
+	if (ret)
+		return ret;
+
+	mutex_lock(&nor->lock);
+
+	return 0;
+}
+
+static void spi_nor_unlock_and_unprep_rd(struct spi_nor *nor, loff_t start, size_t len)
+{
+	mutex_unlock(&nor->lock);
+
+	spi_nor_unprep(nor);
+}
+
 static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr)
 {
 	if (!nor->params->convert_addr)
@@ -1457,7 +1500,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 	addr = instr->addr;
 	len = instr->len;
 
-	ret = spi_nor_lock_and_prep(nor);
+	ret = spi_nor_lock_and_prep_pe(nor, instr->addr, instr->len);
 	if (ret)
 		return ret;
 
@@ -1520,7 +1563,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 	ret = spi_nor_write_disable(nor);
 
 erase_err:
-	spi_nor_unlock_and_unprep(nor);
+	spi_nor_unlock_and_unprep_pe(nor, instr->addr, instr->len);
 
 	return ret;
 }
@@ -1690,11 +1733,13 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 			size_t *retlen, u_char *buf)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
+	loff_t from_lock = from;
+	size_t len_lock = len;
 	ssize_t ret;
 
 	dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len);
 
-	ret = spi_nor_lock_and_prep(nor);
+	ret = spi_nor_lock_and_prep_rd(nor, from_lock, len_lock);
 	if (ret)
 		return ret;
 
@@ -1721,7 +1766,8 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 	ret = 0;
 
 read_err:
-	spi_nor_unlock_and_unprep(nor);
+	spi_nor_unlock_and_unprep_rd(nor, from_lock, len_lock);
+
 	return ret;
 }
 
@@ -1740,7 +1786,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 
 	dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
 
-	ret = spi_nor_lock_and_prep(nor);
+	ret = spi_nor_lock_and_prep_pe(nor, to, len);
 	if (ret)
 		return ret;
 
@@ -1782,7 +1828,8 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	}
 
 write_err:
-	spi_nor_unlock_and_unprep(nor);
+	spi_nor_unlock_and_unprep_pe(nor, to, len);
+
 	return ret;
 }
 
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 7/9] mtd: spi-nor: Add a RWW flag
  2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
                   ` (5 preceding siblings ...)
  2022-12-15  8:12 ` [PATCH v3 6/9] mtd: spi-nor: Prepare the introduction of a new locking mechanism Miquel Raynal
@ 2022-12-15  8:12 ` Miquel Raynal
  2022-12-15  8:12 ` [PATCH v3 8/9] mtd: spi-nor: Enhance locking to support reads while writes Miquel Raynal
  2022-12-15  8:12 ` [PATCH v3 9/9] mtd: spi-nor: macronix: Add support for mx25uw51245g with RWW Miquel Raynal
  8 siblings, 0 replies; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

Introduce a new (no SFDP) flag for the feature that we are about to
support: Read While Write. This means, if the chip has several banks and
supports RWW, once a page of data to write has been transferred into the
chip's internal SRAM, another read operation happening on a different
bank can be performed during the tPROG delay.

Adding this new flag involves enlarging the no_sfdp_flags variable to 16
bits.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/spi-nor/core.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 044d49d749e0..299b60788597 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -472,6 +472,7 @@ struct spi_nor_fixups {
  *   SPI_NOR_OCTAL_READ:      flash supports Octal Read.
  *   SPI_NOR_OCTAL_DTR_READ:  flash supports octal DTR Read.
  *   SPI_NOR_OCTAL_DTR_PP:    flash supports Octal DTR Page Program.
+ *   SPI_NOR_RWW:             flash supports reads while write.
  *
  * @fixup_flags:    flags that indicate support that can be discovered via SFDP
  *                  ideally, but can not be discovered for this particular flash
@@ -512,7 +513,7 @@ struct flash_info {
 #define NO_CHIP_ERASE			BIT(7)
 #define SPI_NOR_NO_FR			BIT(8)
 
-	u8 no_sfdp_flags;
+	u16 no_sfdp_flags;
 #define SPI_NOR_SKIP_SFDP		BIT(0)
 #define SECT_4K				BIT(1)
 #define SPI_NOR_DUAL_READ		BIT(3)
@@ -520,6 +521,7 @@ struct flash_info {
 #define SPI_NOR_OCTAL_READ		BIT(5)
 #define SPI_NOR_OCTAL_DTR_READ		BIT(6)
 #define SPI_NOR_OCTAL_DTR_PP		BIT(7)
+#define SPI_NOR_RWW			BIT(8)
 
 	u8 fixup_flags;
 #define SPI_NOR_4B_OPCODES		BIT(0)
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 8/9] mtd: spi-nor: Enhance locking to support reads while writes
  2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
                   ` (6 preceding siblings ...)
  2022-12-15  8:12 ` [PATCH v3 7/9] mtd: spi-nor: Add a RWW flag Miquel Raynal
@ 2022-12-15  8:12 ` Miquel Raynal
  2022-12-15  8:12 ` [PATCH v3 9/9] mtd: spi-nor: macronix: Add support for mx25uw51245g with RWW Miquel Raynal
  8 siblings, 0 replies; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

On devices featuring several banks, the Read While Write (RWW) feature
is here to improve the overall performance when performing parallel
reads and writes at different locations (different banks). The following
constraints have to be taken into account:
1#: A single operation can be performed in a given bank.
2#: Only a single program or erase operation can happen on the entire
    chip (common hardware limitation to limit costs)
3#: Reads must remain serialized even though reads on different banks
    might occur at the same time.
4#: The I/O bus is unique and thus is the most constrained resource, all
    spi-nor operations requiring access to the spi bus (through the spi
    controller) must be serialized until the bus exchanges are over. So
    we must ensure a single operation can be "sent" at a time.
5#: Any other operation that would not be either a read or a write or an
    erase is considered requiring access to the full chip and cannot be
    parallelized, we then need to ensure the full chip is in the idle
    state when this occurs.

All these constraints can easily be managed with a proper locking model:
1#: Is enforced by a bitfield of the in-use banks, so that only a single
    operation can happen in a specific bank at any time.
2#: Is handled by the ongoing_pe boolean which is set before any write
    or erase, and is released only at the very end of the
    operation. This way, no other destructive operation on the chip can
    start during this time frame.
3#: An ongoing_rd boolean allows to track the ongoing reads, so that
    only one can be performed at a time.
4#: An ongoing_io boolean is introduced in order to capture and serialize
    bus accessed. This is the one being released "sooner" than before,
    because we only need to protect the chip against other SPI accesses
    during the I/O phase, which for the destructive operations is the
    beginning of the operation (when we send the command cycles and
    possibly the data), while the second part of the operation (the
    erase delay or the programmation delay) is when we can do something
    else in another bank.
5#: Is handled by the three booleans presented above, if any of them is
    set, the chip is not yet ready for the operation and must wait.

All these internal variables are protected by the existing lock, so that
changes in this structure are atomic. The serialization is handled with
a wait queue.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/spi-nor/core.c  | 319 ++++++++++++++++++++++++++++++++++--
 include/linux/mtd/spi-nor.h |  13 ++
 2 files changed, 317 insertions(+), 15 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 6c08114e4275..5d9eb40dfb3f 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -588,6 +588,66 @@ int spi_nor_sr_ready(struct spi_nor *nor)
 	return !(nor->bouncebuf[0] & SR_WIP);
 }
 
+/**
+ * spi_nor_parallel_locking() - Checks if the RWW locking scheme shall be used
+ * @nor:	pointer to 'struct spi_nor'.
+ *
+ * Return: true if parallel locking is enabled, false otherwise.
+ */
+static bool spi_nor_parallel_locking(struct spi_nor *nor)
+{
+	if (nor->controller_ops &&
+	    (nor->controller_ops->prepare || nor->controller_ops->unprepare))
+		return false;
+
+	return nor->info->n_banks > 1 && nor->info->no_sfdp_flags & SPI_NOR_RWW;
+}
+
+/* Locking helpers for status read operations */
+static int spi_nor_rww_start_rdst(struct spi_nor *nor)
+{
+	int ret = -EAGAIN;
+
+	mutex_lock(&nor->lock);
+
+	if (nor->rww.ongoing_io || nor->rww.ongoing_rd)
+		goto busy;
+
+	nor->rww.ongoing_io = true;
+	nor->rww.ongoing_rd = true;
+	ret = 0;
+
+busy:
+	mutex_unlock(&nor->lock);
+	return ret;
+}
+
+static void spi_nor_rww_end_rdst(struct spi_nor *nor)
+{
+	mutex_lock(&nor->lock);
+
+	nor->rww.ongoing_io = false;
+	nor->rww.ongoing_rd = false;
+
+	mutex_unlock(&nor->lock);
+}
+
+static int spi_nor_lock_rdst(struct spi_nor *nor)
+{
+	if (spi_nor_parallel_locking(nor))
+		return spi_nor_rww_start_rdst(nor);
+
+	return 0;
+}
+
+static void spi_nor_unlock_rdst(struct spi_nor *nor)
+{
+	if (spi_nor_parallel_locking(nor)) {
+		spi_nor_rww_end_rdst(nor);
+		wake_up(&nor->rww.wait);
+	}
+}
+
 /**
  * spi_nor_ready() - Query the flash to see if it is ready for new commands.
  * @nor:	pointer to 'struct spi_nor'.
@@ -596,11 +656,21 @@ int spi_nor_sr_ready(struct spi_nor *nor)
  */
 static int spi_nor_ready(struct spi_nor *nor)
 {
+	int ret;
+
+	ret = spi_nor_lock_rdst(nor);
+	if (ret)
+		return 0;
+
 	/* Flashes might override the standard routine. */
 	if (nor->params->ready)
-		return nor->params->ready(nor);
+		ret = nor->params->ready(nor);
+	else
+		ret = spi_nor_sr_ready(nor);
 
-	return spi_nor_sr_ready(nor);
+	spi_nor_unlock_rdst(nor);
+
+	return ret;
 }
 
 /**
@@ -1086,7 +1156,81 @@ static void spi_nor_unprep(struct spi_nor *nor)
 		nor->controller_ops->unprepare(nor);
 }
 
+static void spi_nor_offset_to_banks(struct spi_nor *nor, loff_t start, size_t len,
+				    unsigned int *first, unsigned int *last)
+{
+	*first = DIV_ROUND_DOWN_ULL(start, nor->params->bank_size);
+	*last = DIV_ROUND_DOWN_ULL(start + len - 1, nor->params->bank_size);
+}
+
 /* Generic helpers for internal locking and serialization */
+static bool spi_nor_rww_start_io(struct spi_nor *nor)
+{
+	bool start = false;
+
+	mutex_lock(&nor->lock);
+
+	if (nor->rww.ongoing_io)
+		goto busy;
+
+	nor->rww.ongoing_io = true;
+	start = true;
+
+busy:
+	mutex_unlock(&nor->lock);
+	return start;
+}
+
+static void spi_nor_rww_end_io(struct spi_nor *nor)
+{
+	mutex_lock(&nor->lock);
+	nor->rww.ongoing_io = false;
+	mutex_unlock(&nor->lock);
+}
+
+static int spi_nor_lock_device(struct spi_nor *nor)
+{
+	if (!spi_nor_parallel_locking(nor))
+		return 0;
+
+	return wait_event_killable(nor->rww.wait, spi_nor_rww_start_io(nor));
+}
+
+static void spi_nor_unlock_device(struct spi_nor *nor)
+{
+	if (spi_nor_parallel_locking(nor))
+		spi_nor_rww_end_io(nor);
+}
+
+/* Generic helpers for internal locking and serialization */
+static bool spi_nor_rww_start_exclusive(struct spi_nor *nor)
+{
+	bool start = false;
+
+	mutex_lock(&nor->lock);
+
+	if (nor->rww.ongoing_io || nor->rww.ongoing_rd || nor->rww.ongoing_pe)
+		goto busy;
+
+	nor->rww.ongoing_io = true;
+	nor->rww.ongoing_rd = true;
+	nor->rww.ongoing_pe = true;
+	start = true;
+
+busy:
+	mutex_unlock(&nor->lock);
+	return start;
+}
+
+static void spi_nor_rww_end_exclusive(struct spi_nor *nor)
+{
+	mutex_lock(&nor->lock);
+	nor->rww.ongoing_io = false;
+	nor->rww.ongoing_rd = false;
+	nor->rww.ongoing_pe = false;
+	mutex_unlock(&nor->lock);
+}
+
 int spi_nor_lock_and_prep(struct spi_nor *nor)
 {
 	int ret;
@@ -1095,19 +1239,71 @@ int spi_nor_lock_and_prep(struct spi_nor *nor)
 	if (ret)
 		return ret;
 
-	mutex_lock(&nor->lock);
+	if (!spi_nor_parallel_locking(nor))
+		mutex_lock(&nor->lock);
+	else
+		ret = wait_event_killable(nor->rww.wait,
+					  spi_nor_rww_start_exclusive(nor));
 
-	return 0;
+	return ret;
 }
 
 void spi_nor_unlock_and_unprep(struct spi_nor *nor)
 {
-	mutex_unlock(&nor->lock);
+	if (!spi_nor_parallel_locking(nor)) {
+		mutex_unlock(&nor->lock);
+	} else {
+		spi_nor_rww_end_exclusive(nor);
+		wake_up(&nor->rww.wait);
+	}
 
 	spi_nor_unprep(nor);
 }
 
 /* Internal locking helpers for program and erase operations */
+static bool spi_nor_rww_start_pe(struct spi_nor *nor, loff_t start, size_t len)
+{
+	unsigned int first, last;
+	bool started = false;
+	int bank;
+
+	mutex_lock(&nor->lock);
+
+	if (nor->rww.ongoing_io || nor->rww.ongoing_rd || nor->rww.ongoing_pe)
+		goto busy;
+
+	spi_nor_offset_to_banks(nor, start, len, &first, &last);
+	for (bank = first; bank <= last; bank++)
+		if (nor->rww.used_banks & BIT(bank))
+			goto busy;
+
+	for (bank = first; bank <= last; bank++)
+		nor->rww.used_banks |= BIT(bank);
+
+	nor->rww.ongoing_pe = true;
+	started = true;
+
+busy:
+	mutex_unlock(&nor->lock);
+	return started;
+}
+
+static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len)
+{
+	unsigned int first, last;
+	int bank;
+
+	mutex_lock(&nor->lock);
+
+	spi_nor_offset_to_banks(nor, start, len, &first, &last);
+	for (bank = first; bank <= last; bank++)
+		nor->rww.used_banks &= ~BIT(bank);
+
+	nor->rww.ongoing_pe = false;
+
+	mutex_unlock(&nor->lock);
+}
+
 static int spi_nor_lock_and_prep_pe(struct spi_nor *nor, loff_t start, size_t len)
 {
 	int ret;
@@ -1116,19 +1312,73 @@ static int spi_nor_lock_and_prep_pe(struct spi_nor *nor, loff_t start, size_t le
 	if (ret)
 		return ret;
 
-	mutex_lock(&nor->lock);
+	if (!spi_nor_parallel_locking(nor))
+		mutex_lock(&nor->lock);
+	else
+		ret = wait_event_killable(nor->rww.wait,
+					  spi_nor_rww_start_pe(nor, start, len));
 
-	return 0;
+	return ret;
 }
 
 static void spi_nor_unlock_and_unprep_pe(struct spi_nor *nor, loff_t start, size_t len)
 {
-	mutex_unlock(&nor->lock);
+	if (!spi_nor_parallel_locking(nor)) {
+		mutex_unlock(&nor->lock);
+	} else {
+		spi_nor_rww_end_pe(nor, start, len);
+		wake_up(&nor->rww.wait);
+	}
 
 	spi_nor_unprep(nor);
 }
 
 /* Internal locking helpers for read operations */
+static bool spi_nor_rww_start_rd(struct spi_nor *nor, loff_t start, size_t len)
+{
+	unsigned int first, last;
+	bool started = false;
+	int bank;
+
+	mutex_lock(&nor->lock);
+
+	if (nor->rww.ongoing_io || nor->rww.ongoing_rd)
+		goto busy;
+
+	spi_nor_offset_to_banks(nor, start, len, &first, &last);
+	for (bank = first; bank <= last; bank++)
+		if (nor->rww.used_banks & BIT(bank))
+			goto busy;
+
+	for (bank = first; bank <= last; bank++)
+		nor->rww.used_banks |= BIT(bank);
+
+	nor->rww.ongoing_io = true;
+	nor->rww.ongoing_rd = true;
+	started = true;
+
+busy:
+	mutex_unlock(&nor->lock);
+	return started;
+}
+
+static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len)
+{
+	unsigned int first, last;
+	int bank;
+
+	mutex_lock(&nor->lock);
+
+	spi_nor_offset_to_banks(nor, start, len, &first, &last);
+	for (bank = first; bank <= last; bank++)
+		nor->rww.used_banks &= ~BIT(bank);
+
+	nor->rww.ongoing_io = false;
+	nor->rww.ongoing_rd = false;
+
+	mutex_unlock(&nor->lock);
+}
+
 static int spi_nor_lock_and_prep_rd(struct spi_nor *nor, loff_t start, size_t len)
 {
 	int ret;
@@ -1137,14 +1387,23 @@ static int spi_nor_lock_and_prep_rd(struct spi_nor *nor, loff_t start, size_t le
 	if (ret)
 		return ret;
 
-	mutex_lock(&nor->lock);
+	if (!spi_nor_parallel_locking(nor))
+		mutex_lock(&nor->lock);
+	else
+		ret = wait_event_killable(nor->rww.wait,
+					  spi_nor_rww_start_rd(nor, start, len));
 
-	return 0;
+	return ret;
 }
 
 static void spi_nor_unlock_and_unprep_rd(struct spi_nor *nor, loff_t start, size_t len)
 {
-	mutex_unlock(&nor->lock);
+	if (!spi_nor_parallel_locking(nor)) {
+		mutex_unlock(&nor->lock);
+	} else {
+		spi_nor_rww_end_rd(nor, start, len);
+		wake_up(&nor->rww.wait);
+	}
 
 	spi_nor_unprep(nor);
 }
@@ -1451,11 +1710,18 @@ static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len)
 			dev_vdbg(nor->dev, "erase_cmd->size = 0x%08x, erase_cmd->opcode = 0x%02x, erase_cmd->count = %u\n",
 				 cmd->size, cmd->opcode, cmd->count);
 
-			ret = spi_nor_write_enable(nor);
+			ret = spi_nor_lock_device(nor);
 			if (ret)
 				goto destroy_erase_cmd_list;
 
+			ret = spi_nor_write_enable(nor);
+			if (ret) {
+				spi_nor_unlock_device(nor);
+				goto destroy_erase_cmd_list;
+			}
+
 			ret = spi_nor_erase_sector(nor, addr);
+			spi_nor_unlock_device(nor);
 			if (ret)
 				goto destroy_erase_cmd_list;
 
@@ -1508,11 +1774,18 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 	if (len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) {
 		unsigned long timeout;
 
-		ret = spi_nor_write_enable(nor);
+		ret = spi_nor_lock_device(nor);
 		if (ret)
 			goto erase_err;
 
+		ret = spi_nor_write_enable(nor);
+		if (ret) {
+			spi_nor_unlock_device(nor);
+			goto erase_err;
+		}
+
 		ret = spi_nor_erase_chip(nor);
+		spi_nor_unlock_device(nor);
 		if (ret)
 			goto erase_err;
 
@@ -1537,11 +1810,18 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 	/* "sector"-at-a-time erase */
 	} else if (spi_nor_has_uniform_erase(nor)) {
 		while (len) {
-			ret = spi_nor_write_enable(nor);
+			ret = spi_nor_lock_device(nor);
 			if (ret)
 				goto erase_err;
 
+			ret = spi_nor_write_enable(nor);
+			if (ret) {
+				spi_nor_unlock_device(nor);
+				goto erase_err;
+			}
+
 			ret = spi_nor_erase_sector(nor, addr);
+			spi_nor_unlock_device(nor);
 			if (ret)
 				goto erase_err;
 
@@ -1811,11 +2091,18 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 
 		addr = spi_nor_convert_addr(nor, addr);
 
-		ret = spi_nor_write_enable(nor);
+		ret = spi_nor_lock_device(nor);
 		if (ret)
 			goto write_err;
 
+		ret = spi_nor_write_enable(nor);
+		if (ret) {
+			spi_nor_unlock_device(nor);
+			goto write_err;
+		}
+
 		ret = spi_nor_write_data(nor, addr, page_remain, buf + i);
+		spi_nor_unlock_device(nor);
 		if (ret < 0)
 			goto write_err;
 		written = ret;
@@ -3033,6 +3320,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	nor->info = info;
 
 	mutex_init(&nor->lock);
+	if (spi_nor_parallel_locking(nor))
+		init_waitqueue_head(&nor->rww.wait);
 
 	/* Init flash parameters based on flash_info struct and SFDP */
 	ret = spi_nor_init_params(nor);
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 42218a1164f6..51e247d854c4 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -344,6 +344,12 @@ struct spi_nor_flash_parameter;
  * struct spi_nor - Structure for defining the SPI NOR layer
  * @mtd:		an mtd_info structure
  * @lock:		the lock for the read/write/erase/lock/unlock operations
+ * @rww:		Read-While-Write (RWW) sync lock
+ * @rww.wait:		wait queue for the RWW sync
+ * @rww.ongoing_io:	the bus is busy
+ * @rww.ongoing_rd:	a read is ongoing on the chip
+ * @rww.ongoing_pe:	a program/erase is ongoing on the chip
+ * @rww.used_banks:	bitmap of the banks in use
  * @dev:		pointer to an SPI device or an SPI NOR controller device
  * @spimem:		pointer to the SPI memory device
  * @bouncebuf:		bounce buffer used when the buffer passed by the MTD
@@ -375,6 +381,13 @@ struct spi_nor_flash_parameter;
 struct spi_nor {
 	struct mtd_info		mtd;
 	struct mutex		lock;
+	struct {
+		wait_queue_head_t wait;
+		bool		ongoing_io;
+		bool		ongoing_rd;
+		bool		ongoing_pe;
+		unsigned int	used_banks;
+	} rww;
 	struct device		*dev;
 	struct spi_mem		*spimem;
 	u8			*bouncebuf;
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 9/9] mtd: spi-nor: macronix: Add support for mx25uw51245g with RWW
  2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
                   ` (7 preceding siblings ...)
  2022-12-15  8:12 ` [PATCH v3 8/9] mtd: spi-nor: Enhance locking to support reads while writes Miquel Raynal
@ 2022-12-15  8:12 ` Miquel Raynal
  8 siblings, 0 replies; 18+ messages in thread
From: Miquel Raynal @ 2022-12-15  8:12 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni, Miquel Raynal

Describe this new part and provide the RWW flag for it.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/spi-nor/macronix.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index d81a4cb2812b..e9b82afcd6c4 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -82,6 +82,9 @@ static const struct flash_info macronix_nor_parts[] = {
 	{ "mx25u51245g", INFO(0xc2253a, 0, 64 * 1024, 1024)
 		NO_SFDP_FLAGS(SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
 		FIXUP_FLAGS(SPI_NOR_4B_OPCODES) },
+	{ "mx25uw51245g", INFOB(0xc2813a, 0, 16 * 1024, 1024, 4)
+		NO_SFDP_FLAGS(SECT_4K | SPI_NOR_RWW)
+		FIXUP_FLAGS(SPI_NOR_4B_OPCODES) },
 	{ "mx25v8035f",  INFO(0xc22314, 0, 64 * 1024,  16)
 		NO_SFDP_FLAGS(SECT_4K | SPI_NOR_DUAL_READ |
 			      SPI_NOR_QUAD_READ) },
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/9] mtd: spi-nor: Introduce the concept of bank
  2022-12-15  8:12 ` [PATCH v3 2/9] mtd: spi-nor: Introduce the concept of bank Miquel Raynal
@ 2023-01-19 16:34   ` Tudor Ambarus
  2023-02-01 11:32     ` Miquel Raynal
  0 siblings, 1 reply; 18+ messages in thread
From: Tudor Ambarus @ 2023-01-19 16:34 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni

Hi, Miquel,

On 12/15/22 08:12, Miquel Raynal wrote:
> SPI-NOR chips are made of pages, which gathered in small groups make

nit: s/SPI-NOR/ SPI NOR

> (erase) sectors. Sectors, gathered together, make banks inside the
> chip. So far there was only one bank per device supported, but we are
> about to introduce support for new chips featuring several banks (up to
> 4 so far) where different operations may happen in parallel.
> 
> Let's allow describing these additional bank parameters.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
> ---
>   drivers/mtd/spi-nor/core.c |  3 ++-
>   drivers/mtd/spi-nor/core.h | 16 +++++++++++-----
>   2 files changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index f2c64006f8d7..38a57aac6754 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2539,7 +2539,8 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
>   
>   	/* Set SPI NOR sizes. */
>   	params->writesize = 1;
> -	params->size = (u64)info->sector_size * info->n_sectors;
> +	params->bank_size = (u64)info->sector_size * info->n_sectors;
> +	params->size = params->bank_size * info->n_banks;

Is the datasheet for these chips public? I see JESD216 says nothing
about flash banks.

I'm wondering whether we should keep the n_sectors as the total number 
of sectors per flash or not. Does this flash type support Software Block
Protection? How do they count the sectors on Block Protection, per flash
or per bank?

>   	params->page_size = info->page_size;
>   
>   	if (!(info->flags & SPI_NOR_NO_FR)) {
> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
> index dc74c7be3e28..8a067d56c995 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -336,7 +336,8 @@ struct spi_nor_otp {
>    * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216
>    * Serial Flash Discoverable Parameters (SFDP) tables.
>    *
> - * @size:		the flash memory density in bytes.
> + * @bank_size:		the flash memory bank density in bytes.
> + * @size:		the total flash memory density in bytes.
>    * @writesize		Minimal writable flash unit size. Defaults to 1. Set to
>    *			ECC unit size for ECC-ed flashes.
>    * @page_size:		the page size of the SPI NOR flash memory.
> @@ -374,6 +375,7 @@ struct spi_nor_otp {
>    * @locking_ops:	SPI NOR locking methods.
>    */
>   struct spi_nor_flash_parameter {
> +	u64				bank_size;
>   	u64				size;
>   	u32				writesize;
>   	u32				page_size;
> @@ -434,7 +436,8 @@ struct spi_nor_fixups {
>    * @id_len:         the number of bytes of ID.
>    * @sector_size:    the size listed here is what works with SPINOR_OP_SE, which
>    *                  isn't necessarily called a "sector" by the vendor.
> - * @n_sectors:      the number of sectors.
> + * @n_sectors:      the number of sectors per bank.
> + * @n_banks:        the number of banks.
>    * @page_size:      the flash's page size.
>    * @addr_nbytes:    number of address bytes to send.
>    *
> @@ -493,6 +496,7 @@ struct flash_info {
>   	u8 id_len;
>   	unsigned sector_size;
>   	u16 n_sectors;
> +	u16 n_banks;
>   	u16 page_size;

We can try u8 nbanks for now. And we would define it here, to avoid
struct padding.
>   	u8 addr_nbytes;
>   
> @@ -538,23 +542,25 @@ struct flash_info {
>   	.id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_3ITEMS(_ext_id) }, \
>   	.id_len = 6
>   
> -#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors)			\
> +#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors, _n_banks)		\
>   	.sector_size = (_sector_size),					\
>   	.n_sectors = (_n_sectors),					\
> +	.n_banks = (_n_banks),						\
>   	.page_size = 256
>   
>   /* Used when the "_ext_id" is two bytes at most */
>   #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
>   	SPI_NOR_ID((_jedec_id), (_ext_id)),				\
> -	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
> +	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),
>   
>   #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
>   	SPI_NOR_ID6((_jedec_id), (_ext_id)),				\
> -	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
> +	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),
>   
>   #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_nbytes)	\
>   		.sector_size = (_sector_size),				\
>   		.n_sectors = (_n_sectors),				\
> +		.n_banks = 1,						\
>   		.page_size = (_page_size),				\
>   		.addr_nbytes = (_addr_nbytes),				\
>   		.flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,		\

you need to update S3AN_INFO as well.

Cheers,
ta

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 4/9] mtd: spi-nor: Reorder the preparation vs locking steps
  2022-12-15  8:12 ` [PATCH v3 4/9] mtd: spi-nor: Reorder the preparation vs locking steps Miquel Raynal
@ 2023-01-31  5:11   ` Tudor Ambarus
  2023-02-01 11:36     ` Miquel Raynal
  0 siblings, 1 reply; 18+ messages in thread
From: Tudor Ambarus @ 2023-01-31  5:11 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni

Hi, Miquel,

On 12/15/22 08:12, Miquel Raynal wrote:
> The ->prepare()/->unprepare() hooks are now legacy, and there are only
> two controllers left supporting them. In both cases, the implementation

now there's only one, hisi-sfc.c.

> acquires a mutex, which is somehow redundant with the spi-nor main lock

I see a HIFMC_MAX_CHIP_NUM with value 2, the controller seems to be able
to operate 2 flashes in parallel and that's why the internal mutex.

> that we acquire as well in the spi_nor_[un]lock_and_[un]prep() helpers.
> 
> While the mutex taken in the core is necessary, the helper can be
> reorganized to first do the preparation, then acquire the core
> lock. This is necessary in order to be able to improve the locking
> mechanism in the core and should have no side effect.
> 

the change seems fine for hisi, and since we're no longer adding drivers
under spi-nor/controllers we should be good.

> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>   drivers/mtd/spi-nor/core.c | 15 ++++++---------
>   1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 38a57aac6754..de77ca55f74d 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1074,23 +1074,20 @@ int spi_nor_lock_and_prep(struct spi_nor *nor)

you'll have to rename it to spi_nor_prep_and_lock to reflect the order
of ops.

>   {
>   	int ret = 0;
>   
> -	mutex_lock(&nor->lock);
> -
> -	if (nor->controller_ops &&  nor->controller_ops->prepare) {
> +	if (nor->controller_ops && nor->controller_ops->prepare)
>   		ret = nor->controller_ops->prepare(nor);
> -		if (ret) {
> -			mutex_unlock(&nor->lock);
> -			return ret;
> -		}
> -	}
> +
> +	mutex_lock(&nor->lock);
> +
>   	return ret;
>   }
> 

Cheers,
ta

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 6/9] mtd: spi-nor: Prepare the introduction of a new locking mechanism
  2022-12-15  8:12 ` [PATCH v3 6/9] mtd: spi-nor: Prepare the introduction of a new locking mechanism Miquel Raynal
@ 2023-01-31  5:29   ` Tudor Ambarus
  0 siblings, 0 replies; 18+ messages in thread
From: Tudor Ambarus @ 2023-01-31  5:29 UTC (permalink / raw)
  To: linux-mtd



On 12/15/22 08:12, Miquel Raynal wrote:
> This commit alone just introduces two new "lock and prepare" pairs of
> helpers which do the exact same thing as before. They will soon be
> improved in a followup commit which actually brings the logic, but I
> figured out it was more readable to do it this way.
> 

I'd like to not introduce new support for SPI NOR controller drivers
(those under drivers/mtd/spi-nor/controllers/) so that we motivate the
owners to move their drivers to SPI. So we may have to rewrite the
helpers a bit, but I won't stumble on this right now, let me get the
general idea of read while write support first.

Cheers,
ta

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 1/9] mtd: spi-nor: Create macros to define chip IDs and geometries
  2022-12-15  8:12 ` [PATCH v3 1/9] mtd: spi-nor: Create macros to define chip IDs and geometries Miquel Raynal
@ 2023-01-31  8:58   ` Tudor Ambarus
  0 siblings, 0 replies; 18+ messages in thread
From: Tudor Ambarus @ 2023-01-31  8:58 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Alvin Zhou, Thomas Petazzoni



On 15.12.2022 10:12, Miquel Raynal wrote:
> The INFO() macro defines an ID array and a couple of geometry
> properties. Right now all its lines are duplicated twice because of the
> INFO6() macro (for extended IDs) and soon as well we will need to add a
> geometry parameter to include the number of banks.
> 
> In order to limit the code duplication, let's create a number of
> intermediate macros which will facilitate defining high-level INFOX()
> macros.
> 
> There is not functional change.
s/not/no and applied to spi-nor/next.

Thanks!
> 
> Signed-off-by: Miquel Raynal<miquel.raynal@bootlin.com>
> Reviewed-by: Pratyush Yadav<pratyush@kernel.org>
> ---
>   drivers/mtd/spi-nor/core.h | 43 ++++++++++++++++++--------------------
>   1 file changed, 20 insertions(+), 23 deletions(-)

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/9] mtd: spi-nor: Introduce the concept of bank
  2023-01-19 16:34   ` Tudor Ambarus
@ 2023-02-01 11:32     ` Miquel Raynal
  2023-03-17  3:33       ` Tudor Ambarus
  0 siblings, 1 reply; 18+ messages in thread
From: Miquel Raynal @ 2023-02-01 11:32 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Jaime Liao,
	Alvin Zhou, Thomas Petazzoni

Hi Tudor,

Jaime, a few questions for you below.

tudor.ambarus@linaro.org wrote on Thu, 19 Jan 2023 16:34:28 +0000:

> Hi, Miquel,
> 
> On 12/15/22 08:12, Miquel Raynal wrote:
> > SPI-NOR chips are made of pages, which gathered in small groups make  
> 
> nit: s/SPI-NOR/ SPI NOR

Noted.

> 
> > (erase) sectors. Sectors, gathered together, make banks inside the
> > chip. So far there was only one bank per device supported, but we are
> > about to introduce support for new chips featuring several banks (up to
> > 4 so far) where different operations may happen in parallel.
> > 
> > Let's allow describing these additional bank parameters.
> > 
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
> > ---
> >   drivers/mtd/spi-nor/core.c |  3 ++-
> >   drivers/mtd/spi-nor/core.h | 16 +++++++++++-----
> >   2 files changed, 13 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> > index f2c64006f8d7..38a57aac6754 100644
> > --- a/drivers/mtd/spi-nor/core.c
> > +++ b/drivers/mtd/spi-nor/core.c
> > @@ -2539,7 +2539,8 @@ static void spi_nor_init_default_params(struct spi_nor *nor)  
> >   >   	/* Set SPI NOR sizes. */  
> >   	params->writesize = 1;
> > -	params->size = (u64)info->sector_size * info->n_sectors;
> > +	params->bank_size = (u64)info->sector_size * info->n_sectors;
> > +	params->size = params->bank_size * info->n_banks;  
> 
> Is the datasheet for these chips public? I see JESD216 says nothing
> about flash banks.

Jaime, do you have a public datasheet for the MX25UW51245G ?

> I'm wondering whether we should keep the n_sectors as the total number of sectors per flash or not.

This is indeed a good point and I did think about it when I wrote the
initial support. For me it looks like the banks are only relevant for
the RWW purpose (for now) so I decided I would keep the changes minimal
and not mess with the existing variables further. So I just added a
"bank" member, and if you want the number of sectors per bank, you can
divide nsectors by the number of banks. Another approach might be, as
you ask, to count the number of sectors based on the number of sectors
per bank and the number of banks. We can move to this approach later I
believe, if ever useful.

> Does this flash type support Software Block
> Protection? How do they count the sectors on Block Protection, per flash
> or per bank?

Yes it supports block protection, AFAICS it is a per-sector
configuration, which does not care about banks at all. It looks like
you can protect 2^n sectors (called "blocks" in the datasheet) from the
start or from the end of the device.

Jaime, do you confirm?

> >   	params->page_size = info->page_size;  
> >   >   	if (!(info->flags & SPI_NOR_NO_FR)) {  
> > diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
> > index dc74c7be3e28..8a067d56c995 100644
> > --- a/drivers/mtd/spi-nor/core.h
> > +++ b/drivers/mtd/spi-nor/core.h
> > @@ -336,7 +336,8 @@ struct spi_nor_otp {
> >    * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216
> >    * Serial Flash Discoverable Parameters (SFDP) tables.
> >    *
> > - * @size:		the flash memory density in bytes.
> > + * @bank_size:		the flash memory bank density in bytes.
> > + * @size:		the total flash memory density in bytes.
> >    * @writesize		Minimal writable flash unit size. Defaults to 1. Set to
> >    *			ECC unit size for ECC-ed flashes.
> >    * @page_size:		the page size of the SPI NOR flash memory.
> > @@ -374,6 +375,7 @@ struct spi_nor_otp {
> >    * @locking_ops:	SPI NOR locking methods.
> >    */
> >   struct spi_nor_flash_parameter {
> > +	u64				bank_size;
> >   	u64				size;
> >   	u32				writesize;
> >   	u32				page_size;
> > @@ -434,7 +436,8 @@ struct spi_nor_fixups {
> >    * @id_len:         the number of bytes of ID.
> >    * @sector_size:    the size listed here is what works with SPINOR_OP_SE, which
> >    *                  isn't necessarily called a "sector" by the vendor.
> > - * @n_sectors:      the number of sectors.
> > + * @n_sectors:      the number of sectors per bank.
> > + * @n_banks:        the number of banks.
> >    * @page_size:      the flash's page size.
> >    * @addr_nbytes:    number of address bytes to send.
> >    *
> > @@ -493,6 +496,7 @@ struct flash_info {
> >   	u8 id_len;
> >   	unsigned sector_size;
> >   	u16 n_sectors;
> > +	u16 n_banks;
> >   	u16 page_size;  
> 
> We can try u8 nbanks for now. And we would define it here, to avoid
> struct padding.

Ok.

> >   	u8 addr_nbytes;  
> >   > @@ -538,23 +542,25 @@ struct flash_info {  
> >   	.id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_3ITEMS(_ext_id) }, \
> >   	.id_len = 6  
> >   > -#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors)			\  
> > +#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors, _n_banks)		\
> >   	.sector_size = (_sector_size),					\
> >   	.n_sectors = (_n_sectors),					\
> > +	.n_banks = (_n_banks),						\
> >   	.page_size = 256  
> >   >   /* Used when the "_ext_id" is two bytes at most */  
> >   #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
> >   	SPI_NOR_ID((_jedec_id), (_ext_id)),				\
> > -	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
> > +	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),  
> >   >   #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors)		\  
> >   	SPI_NOR_ID6((_jedec_id), (_ext_id)),				\
> > -	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
> > +	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),  
> >   >   #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_nbytes)	\  
> >   		.sector_size = (_sector_size),				\
> >   		.n_sectors = (_n_sectors),				\
> > +		.n_banks = 1,						\
> >   		.page_size = (_page_size),				\
> >   		.addr_nbytes = (_addr_nbytes),				\
> >   		.flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,		\  
> 
> you need to update S3AN_INFO as well.

Completely missed that one, thanks!

Cheers,
Miquèl

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 4/9] mtd: spi-nor: Reorder the preparation vs locking steps
  2023-01-31  5:11   ` Tudor Ambarus
@ 2023-02-01 11:36     ` Miquel Raynal
  0 siblings, 0 replies; 18+ messages in thread
From: Miquel Raynal @ 2023-02-01 11:36 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Jaime Liao,
	Alvin Zhou, Thomas Petazzoni

Hi Tudor,

tudor.ambarus@linaro.org wrote on Tue, 31 Jan 2023 05:11:33 +0000:

> Hi, Miquel,
> 
> On 12/15/22 08:12, Miquel Raynal wrote:
> > The ->prepare()/->unprepare() hooks are now legacy, and there are only
> > two controllers left supporting them. In both cases, the implementation  
> 
> now there's only one, hisi-sfc.c.

Indeed.

> 
> > acquires a mutex, which is somehow redundant with the spi-nor main lock  
> 
> I see a HIFMC_MAX_CHIP_NUM with value 2, the controller seems to be able
> to operate 2 flashes in parallel and that's why the internal mutex.
> 
> > that we acquire as well in the spi_nor_[un]lock_and_[un]prep() helpers.
> > 
> > While the mutex taken in the core is necessary, the helper can be
> > reorganized to first do the preparation, then acquire the core
> > lock. This is necessary in order to be able to improve the locking
> > mechanism in the core and should have no side effect.
> >   
> 
> the change seems fine for hisi, and since we're no longer adding drivers
> under spi-nor/controllers we should be good.
> 
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >   drivers/mtd/spi-nor/core.c | 15 ++++++---------
> >   1 file changed, 6 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> > index 38a57aac6754..de77ca55f74d 100644
> > --- a/drivers/mtd/spi-nor/core.c
> > +++ b/drivers/mtd/spi-nor/core.c
> > @@ -1074,23 +1074,20 @@ int spi_nor_lock_and_prep(struct spi_nor *nor)  
> 
> you'll have to rename it to spi_nor_prep_and_lock to reflect the order
> of ops.

Sure.

> 
> >   {
> >   	int ret = 0;  
> >   > -	mutex_lock(&nor->lock);  
> > -
> > -	if (nor->controller_ops &&  nor->controller_ops->prepare) {
> > +	if (nor->controller_ops && nor->controller_ops->prepare)
> >   		ret = nor->controller_ops->prepare(nor);
> > -		if (ret) {
> > -			mutex_unlock(&nor->lock);
> > -			return ret;
> > -		}
> > -	}
> > +
> > +	mutex_lock(&nor->lock);
> > +
> >   	return ret;
> >   }
> >   
> 
> Cheers,
> ta


Thanks,
Miquèl

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/9] mtd: spi-nor: Introduce the concept of bank
  2023-02-01 11:32     ` Miquel Raynal
@ 2023-03-17  3:33       ` Tudor Ambarus
  2023-03-24 15:13         ` Miquel Raynal
  0 siblings, 1 reply; 18+ messages in thread
From: Tudor Ambarus @ 2023-03-17  3:33 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Jaime Liao,
	Alvin Zhou, Thomas Petazzoni



On 2/1/23 11:32, Miquel Raynal wrote:
> Hi Tudor,
> 
> Jaime, a few questions for you below.
> 
> tudor.ambarus@linaro.org wrote on Thu, 19 Jan 2023 16:34:28 +0000:
> 
>> Hi, Miquel,
>>
>> On 12/15/22 08:12, Miquel Raynal wrote:
>>> SPI-NOR chips are made of pages, which gathered in small groups make  
>>
>> nit: s/SPI-NOR/ SPI NOR
> 
> Noted.
> 
>>
>>> (erase) sectors. Sectors, gathered together, make banks inside the
>>> chip. So far there was only one bank per device supported, but we are
>>> about to introduce support for new chips featuring several banks (up to
>>> 4 so far) where different operations may happen in parallel.
>>>
>>> Let's allow describing these additional bank parameters.
>>>
>>> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
>>> Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
>>> ---
>>>   drivers/mtd/spi-nor/core.c |  3 ++-
>>>   drivers/mtd/spi-nor/core.h | 16 +++++++++++-----
>>>   2 files changed, 13 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
>>> index f2c64006f8d7..38a57aac6754 100644
>>> --- a/drivers/mtd/spi-nor/core.c
>>> +++ b/drivers/mtd/spi-nor/core.c
>>> @@ -2539,7 +2539,8 @@ static void spi_nor_init_default_params(struct spi_nor *nor)  
>>>   >   	/* Set SPI NOR sizes. */  
>>>   	params->writesize = 1;
>>> -	params->size = (u64)info->sector_size * info->n_sectors;
>>> +	params->bank_size = (u64)info->sector_size * info->n_sectors;
>>> +	params->size = params->bank_size * info->n_banks;  
>>
>> Is the datasheet for these chips public? I see JESD216 says nothing
>> about flash banks.
> 
> Jaime, do you have a public datasheet for the MX25UW51245G ?
> 
>> I'm wondering whether we should keep the n_sectors as the total number of sectors per flash or not.
> 
> This is indeed a good point and I did think about it when I wrote the
> initial support. For me it looks like the banks are only relevant for
> the RWW purpose (for now) so I decided I would keep the changes minimal
> and not mess with the existing variables further. So I just added a
> "bank" member, and if you want the number of sectors per bank, you can
> divide nsectors by the number of banks. Another approach might be, as
> you ask, to count the number of sectors based on the number of sectors
> per bank and the number of banks. We can move to this approach later I
> believe, if ever useful.
> 
>> Does this flash type support Software Block
>> Protection? How do they count the sectors on Block Protection, per flash
>> or per bank?
> 
> Yes it supports block protection, AFAICS it is a per-sector
> configuration, which does not care about banks at all. It looks like
> you can protect 2^n sectors (called "blocks" in the datasheet) from the
> start or from the end of the device.

then you shouldn't change the n_sectors meaning, and keep it per flash,
and not per bank. Otherwise you break the block protection support for
these flashes. If you really need the number of sectors per bank, you
can divide n_sectors (per flash) by nbanks, can't you? So bank_size
should look like (n_sectors / nbanks) * sector_size.

> 
> Jaime, do you confirm?
> 
>>>   	params->page_size = info->page_size;  
>>>   >   	if (!(info->flags & SPI_NOR_NO_FR)) {  
>>> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
>>> index dc74c7be3e28..8a067d56c995 100644
>>> --- a/drivers/mtd/spi-nor/core.h
>>> +++ b/drivers/mtd/spi-nor/core.h
>>> @@ -336,7 +336,8 @@ struct spi_nor_otp {
>>>    * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216
>>>    * Serial Flash Discoverable Parameters (SFDP) tables.
>>>    *
>>> - * @size:		the flash memory density in bytes.
>>> + * @bank_size:		the flash memory bank density in bytes.
>>> + * @size:		the total flash memory density in bytes.
>>>    * @writesize		Minimal writable flash unit size. Defaults to 1. Set to
>>>    *			ECC unit size for ECC-ed flashes.
>>>    * @page_size:		the page size of the SPI NOR flash memory.
>>> @@ -374,6 +375,7 @@ struct spi_nor_otp {
>>>    * @locking_ops:	SPI NOR locking methods.
>>>    */
>>>   struct spi_nor_flash_parameter {
>>> +	u64				bank_size;
>>>   	u64				size;
>>>   	u32				writesize;
>>>   	u32				page_size;
>>> @@ -434,7 +436,8 @@ struct spi_nor_fixups {
>>>    * @id_len:         the number of bytes of ID.
>>>    * @sector_size:    the size listed here is what works with SPINOR_OP_SE, which
>>>    *                  isn't necessarily called a "sector" by the vendor.
>>> - * @n_sectors:      the number of sectors.
>>> + * @n_sectors:      the number of sectors per bank.
>>> + * @n_banks:        the number of banks.
>>>    * @page_size:      the flash's page size.
>>>    * @addr_nbytes:    number of address bytes to send.
>>>    *
>>> @@ -493,6 +496,7 @@ struct flash_info {
>>>   	u8 id_len;
>>>   	unsigned sector_size;
>>>   	u16 n_sectors;
>>> +	u16 n_banks;
>>>   	u16 page_size;  
>>
>> We can try u8 nbanks for now. And we would define it here, to avoid
>> struct padding.
> 
> Ok.
> 
>>>   	u8 addr_nbytes;  
>>>   > @@ -538,23 +542,25 @@ struct flash_info {  
>>>   	.id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_3ITEMS(_ext_id) }, \
>>>   	.id_len = 6  
>>>   > -#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors)			\  
>>> +#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors, _n_banks)		\
>>>   	.sector_size = (_sector_size),					\
>>>   	.n_sectors = (_n_sectors),					\
>>> +	.n_banks = (_n_banks),						\
>>>   	.page_size = 256  
>>>   >   /* Used when the "_ext_id" is two bytes at most */  
>>>   #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
>>>   	SPI_NOR_ID((_jedec_id), (_ext_id)),				\
>>> -	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
>>> +	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),  
>>>   >   #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors)		\  
>>>   	SPI_NOR_ID6((_jedec_id), (_ext_id)),				\
>>> -	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
>>> +	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),  
>>>   >   #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_nbytes)	\  
>>>   		.sector_size = (_sector_size),				\
>>>   		.n_sectors = (_n_sectors),				\
>>> +		.n_banks = 1,						\
>>>   		.page_size = (_page_size),				\
>>>   		.addr_nbytes = (_addr_nbytes),				\
>>>   		.flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,		\  
>>
>> you need to update S3AN_INFO as well.
> 
> Completely missed that one, thanks!
> 
> Cheers,
> Miquèl

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/9] mtd: spi-nor: Introduce the concept of bank
  2023-03-17  3:33       ` Tudor Ambarus
@ 2023-03-24 15:13         ` Miquel Raynal
  0 siblings, 0 replies; 18+ messages in thread
From: Miquel Raynal @ 2023-03-24 15:13 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Jaime Liao,
	Alvin Zhou, Thomas Petazzoni

Hi Tudor,

tudor.ambarus@linaro.org wrote on Fri, 17 Mar 2023 03:33:02 +0000:

> On 2/1/23 11:32, Miquel Raynal wrote:
> > Hi Tudor,
> > 
> > Jaime, a few questions for you below.
> > 
> > tudor.ambarus@linaro.org wrote on Thu, 19 Jan 2023 16:34:28 +0000:
> >   
> >> Hi, Miquel,
> >>
> >> On 12/15/22 08:12, Miquel Raynal wrote:  
> >>> SPI-NOR chips are made of pages, which gathered in small groups make    
> >>
> >> nit: s/SPI-NOR/ SPI NOR  
> > 
> > Noted.
> >   
> >>  
> >>> (erase) sectors. Sectors, gathered together, make banks inside the
> >>> chip. So far there was only one bank per device supported, but we are
> >>> about to introduce support for new chips featuring several banks (up to
> >>> 4 so far) where different operations may happen in parallel.
> >>>
> >>> Let's allow describing these additional bank parameters.
> >>>
> >>> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> >>> Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
> >>> ---
> >>>   drivers/mtd/spi-nor/core.c |  3 ++-
> >>>   drivers/mtd/spi-nor/core.h | 16 +++++++++++-----
> >>>   2 files changed, 13 insertions(+), 6 deletions(-)
> >>>
> >>> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> >>> index f2c64006f8d7..38a57aac6754 100644
> >>> --- a/drivers/mtd/spi-nor/core.c
> >>> +++ b/drivers/mtd/spi-nor/core.c
> >>> @@ -2539,7 +2539,8 @@ static void spi_nor_init_default_params(struct spi_nor *nor)    
> >>>   >   	/* Set SPI NOR sizes. */    
> >>>   	params->writesize = 1;
> >>> -	params->size = (u64)info->sector_size * info->n_sectors;
> >>> +	params->bank_size = (u64)info->sector_size * info->n_sectors;
> >>> +	params->size = params->bank_size * info->n_banks;    
> >>
> >> Is the datasheet for these chips public? I see JESD216 says nothing
> >> about flash banks.  
> > 
> > Jaime, do you have a public datasheet for the MX25UW51245G ?
> >   
> >> I'm wondering whether we should keep the n_sectors as the total number of sectors per flash or not.  
> > 
> > This is indeed a good point and I did think about it when I wrote the
> > initial support. For me it looks like the banks are only relevant for
> > the RWW purpose (for now) so I decided I would keep the changes minimal
> > and not mess with the existing variables further. So I just added a
> > "bank" member, and if you want the number of sectors per bank, you can
> > divide nsectors by the number of banks. Another approach might be, as
> > you ask, to count the number of sectors based on the number of sectors
> > per bank and the number of banks. We can move to this approach later I
> > believe, if ever useful.
> >   
> >> Does this flash type support Software Block
> >> Protection? How do they count the sectors on Block Protection, per flash
> >> or per bank?  
> > 
> > Yes it supports block protection, AFAICS it is a per-sector
> > configuration, which does not care about banks at all. It looks like
> > you can protect 2^n sectors (called "blocks" in the datasheet) from the
> > start or from the end of the device.  
> 
> then you shouldn't change the n_sectors meaning, and keep it per flash,
> and not per bank. Otherwise you break the block protection support for
> these flashes.

That's totally right, good point. I'll update. Actually that was my
initial intention and the commit log reflected this idea, instead of
what I actually implemented in a second time.

> If you really need the number of sectors per bank, you
> can divide n_sectors (per flash) by nbanks, can't you? So bank_size
> should look like (n_sectors / nbanks) * sector_size.
> 
> > 
> > Jaime, do you confirm?
> >   
> >>>   	params->page_size = info->page_size;    
> >>>   >   	if (!(info->flags & SPI_NOR_NO_FR)) {    
> >>> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
> >>> index dc74c7be3e28..8a067d56c995 100644
> >>> --- a/drivers/mtd/spi-nor/core.h
> >>> +++ b/drivers/mtd/spi-nor/core.h
> >>> @@ -336,7 +336,8 @@ struct spi_nor_otp {
> >>>    * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216
> >>>    * Serial Flash Discoverable Parameters (SFDP) tables.
> >>>    *
> >>> - * @size:		the flash memory density in bytes.
> >>> + * @bank_size:		the flash memory bank density in bytes.
> >>> + * @size:		the total flash memory density in bytes.
> >>>    * @writesize		Minimal writable flash unit size. Defaults to 1. Set to
> >>>    *			ECC unit size for ECC-ed flashes.
> >>>    * @page_size:		the page size of the SPI NOR flash memory.
> >>> @@ -374,6 +375,7 @@ struct spi_nor_otp {
> >>>    * @locking_ops:	SPI NOR locking methods.
> >>>    */
> >>>   struct spi_nor_flash_parameter {
> >>> +	u64				bank_size;
> >>>   	u64				size;
> >>>   	u32				writesize;
> >>>   	u32				page_size;
> >>> @@ -434,7 +436,8 @@ struct spi_nor_fixups {
> >>>    * @id_len:         the number of bytes of ID.
> >>>    * @sector_size:    the size listed here is what works with SPINOR_OP_SE, which
> >>>    *                  isn't necessarily called a "sector" by the vendor.
> >>> - * @n_sectors:      the number of sectors.
> >>> + * @n_sectors:      the number of sectors per bank.
> >>> + * @n_banks:        the number of banks.
> >>>    * @page_size:      the flash's page size.
> >>>    * @addr_nbytes:    number of address bytes to send.
> >>>    *
> >>> @@ -493,6 +496,7 @@ struct flash_info {
> >>>   	u8 id_len;
> >>>   	unsigned sector_size;
> >>>   	u16 n_sectors;
> >>> +	u16 n_banks;
> >>>   	u16 page_size;    
> >>
> >> We can try u8 nbanks for now. And we would define it here, to avoid
> >> struct padding.  
> > 
> > Ok.
> >   
> >>>   	u8 addr_nbytes;    
> >>>   > @@ -538,23 +542,25 @@ struct flash_info {    
> >>>   	.id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_3ITEMS(_ext_id) }, \
> >>>   	.id_len = 6    
> >>>   > -#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors)			\    
> >>> +#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors, _n_banks)		\
> >>>   	.sector_size = (_sector_size),					\
> >>>   	.n_sectors = (_n_sectors),					\
> >>> +	.n_banks = (_n_banks),						\
> >>>   	.page_size = 256    
> >>>   >   /* Used when the "_ext_id" is two bytes at most */    
> >>>   #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors)		\
> >>>   	SPI_NOR_ID((_jedec_id), (_ext_id)),				\
> >>> -	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
> >>> +	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),    
> >>>   >   #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors)		\    
> >>>   	SPI_NOR_ID6((_jedec_id), (_ext_id)),				\
> >>> -	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
> >>> +	SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),    
> >>>   >   #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_nbytes)	\    
> >>>   		.sector_size = (_sector_size),				\
> >>>   		.n_sectors = (_n_sectors),				\
> >>> +		.n_banks = 1,						\
> >>>   		.page_size = (_page_size),				\
> >>>   		.addr_nbytes = (_addr_nbytes),				\
> >>>   		.flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,		\    
> >>
> >> you need to update S3AN_INFO as well.  
> > 
> > Completely missed that one, thanks!
> > 
> > Cheers,
> > Miquèl  


Thanks,
Miquèl

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2023-03-24 15:19 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-15  8:12 [PATCH v3 0/9] mtd: spi-nor: read while write support Miquel Raynal
2022-12-15  8:12 ` [PATCH v3 1/9] mtd: spi-nor: Create macros to define chip IDs and geometries Miquel Raynal
2023-01-31  8:58   ` Tudor Ambarus
2022-12-15  8:12 ` [PATCH v3 2/9] mtd: spi-nor: Introduce the concept of bank Miquel Raynal
2023-01-19 16:34   ` Tudor Ambarus
2023-02-01 11:32     ` Miquel Raynal
2023-03-17  3:33       ` Tudor Ambarus
2023-03-24 15:13         ` Miquel Raynal
2022-12-15  8:12 ` [PATCH v3 3/9] mtd: spi-nor: Add a macro to define more banks Miquel Raynal
2022-12-15  8:12 ` [PATCH v3 4/9] mtd: spi-nor: Reorder the preparation vs locking steps Miquel Raynal
2023-01-31  5:11   ` Tudor Ambarus
2023-02-01 11:36     ` Miquel Raynal
2022-12-15  8:12 ` [PATCH v3 5/9] mtd: spi-nor: Separate preparation and locking Miquel Raynal
2022-12-15  8:12 ` [PATCH v3 6/9] mtd: spi-nor: Prepare the introduction of a new locking mechanism Miquel Raynal
2023-01-31  5:29   ` Tudor Ambarus
2022-12-15  8:12 ` [PATCH v3 7/9] mtd: spi-nor: Add a RWW flag Miquel Raynal
2022-12-15  8:12 ` [PATCH v3 8/9] mtd: spi-nor: Enhance locking to support reads while writes Miquel Raynal
2022-12-15  8:12 ` [PATCH v3 9/9] mtd: spi-nor: macronix: Add support for mx25uw51245g with RWW Miquel Raynal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.