Skip to contentSkip to conversation

] Merge m25p80 into spi-nor

PATCH Superseded Vignesh Raghavendra 3 participants 12 messages Jul 20, 2019 – Jul 31, 2019

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Vignesh Raghavendra

author maintainer
#0 lore raw

v2 cover ] Merge m25p80 into spi-nor

This is repost of patch 6 and 7 split from from Boris Brezillon's X-X-X mode support series[1]

Background from cover letter for RFC[1]:
m25p80 is just a simple SPI NOR controller driver (a wrapper around the SPI mem API). Not only it shouldn't be named after a specific SPI NOR chip, but it also doesn't deserve a specific driver IMO, especially if the end goal is to get rid of SPI NOR controller drivers found in drivers/mtd/spi-nor/ and replace them by SPI mem drivers (which would be placed in drivers/spi/). With this solution, we declare the SPI NOR driver as a spi_mem_driver, just like the SPI NAND layer is declared as a spi_mem driver (patch 1/2).
This solution also allows us to check at a fined-grain level (thanks to the spi_mem_supports_op() function) which operations are supported and which ones are not, while the original m25p80 logic was basing this decision on the SPI_{RX,TX}_{DUAL,QUAD,OCTO} flags only (patch 2/2).

[1] https://patchwork.ozlabs.org/cover/982926/

Tested on TI' DRA7xx EVM with TI QSPI controller (a spi-mem driver) with DMA (s25fl256) flash. I don't see any performance regression due to bounce buffer copy introduced by this series

Boris Brezillon (2):
mtd: spi-nor: Move m25p80 code in spi-nor.c
mtd: spi-nor: Rework hwcaps selection for the spi-mem case

 drivers/mtd/devices/Kconfig   |  18 -
 drivers/mtd/devices/Makefile  |   1 -
 drivers/mtd/devices/m25p80.c  | 347 --------------
 drivers/mtd/spi-nor/Kconfig   |   2 +
 drivers/mtd/spi-nor/spi-nor.c | 845 ++++++++++++++++++++++++++++++++--
 include/linux/mtd/spi-nor.h   |  22 +
 6 files changed, 830 insertions(+), 405 deletions(-)
 delete mode 100644 drivers/mtd/devices/m25p80.c
Signature · 1 line
2.22.0
author maintainer
#1 lore raw

PATCH v2 1/2 mtd: spi-nor: Move m25p80 code in spi-nor.c

From: Boris Brezillon <[email protected]>

The m25p80 driver is actually a generic wrapper around the spi-mem layer. Not only the driver name is misleading, but we'd expect such a common logic to be directly available in the core. Another reason for moving this code is that SPI NOR controller drivers should progressively be replaced by SPI controller drivers implementing the spi_mem_ops interface, and when the conversion is done, we should have a single spi-nor driver directly interfacing with the spi-mem layer.

While moving the code we also fix a longstanding issue when non-DMA-able buffers are passed by the MTD layer.

---
v2:
Add docs for new functions added
Add spi_nor_ prefix to new functions
Incorporate Andrey's patches https://lkml.org/lkml/2019/4/1/32
to avoid looping spi_nor_spimem_* APIs

 drivers/mtd/devices/Kconfig   |  18 -
 drivers/mtd/devices/Makefile  |   1 -
 drivers/mtd/devices/m25p80.c  | 347 -----------------
 drivers/mtd/spi-nor/Kconfig   |   2 +
 drivers/mtd/spi-nor/spi-nor.c | 714 ++++++++++++++++++++++++++++++++--
 include/linux/mtd/spi-nor.h   |   8 +
 6 files changed, 695 insertions(+), 395 deletions(-)
 delete mode 100644 drivers/mtd/devices/m25p80.c
drivers/mtd/devices/Kconfig +0 -18
index 49abbc52457d..f96287c4b789 100644
@@ -79,24 +79,6 @@ config MTD_DATAFLASH_OTP
 	  other key product data.  The second half is programmed with a
 	  unique-to-each-chip bit pattern at the factory.
 
-config MTD_M25P80
-	tristate "Support most SPI Flash chips (AT26DF, M25P, W25X, ...)"
-	depends on SPI_MASTER && MTD_SPI_NOR
-	select SPI_MEM
-	help
-	  This enables access to most modern SPI flash chips, used for
-	  program and data storage.   Series supported include Atmel AT26DF,
-	  Spansion S25SL, SST 25VF, ST M25P, and Winbond W25X.  Other chips
-	  are supported as well.  See the driver source for the current list,
-	  or to add other chips.
-
-	  Note that the original DataFlash chips (AT45 series, not AT26DF),
-	  need an entirely different driver.
-
-	  Set up your spi devices with the right board-specific platform data,
-	  if you want to specify device partitioning or to use a device which
-	  doesn't support the JEDEC ID instruction.
-
 config MTD_MCHP23K256
 	tristate "Microchip 23K256 SRAM"
 	depends on SPI_MASTER
drivers/mtd/devices/Makefile +0 -1
index 94895eab3066..991c8d12c016 100644
@@ -12,7 +12,6 @@ obj-$(CONFIG_MTD_MTDRAM)	+= mtdram.o
 obj-$(CONFIG_MTD_LART)		+= lart.o
 obj-$(CONFIG_MTD_BLOCK2MTD)	+= block2mtd.o
 obj-$(CONFIG_MTD_DATAFLASH)	+= mtd_dataflash.o
-obj-$(CONFIG_MTD_M25P80)	+= m25p80.o
 obj-$(CONFIG_MTD_MCHP23K256)	+= mchp23k256.o
 obj-$(CONFIG_MTD_SPEAR_SMI)	+= spear_smi.o
 obj-$(CONFIG_MTD_SST25L)	+= sst25l.o
drivers/mtd/devices/m25p80.c deleted +0 -347

347 lines not on this page · raw message

drivers/mtd/spi-nor/Kconfig +2 -0
index 6de83277ce8b..f237fcdf7f86 100644
@@ -2,6 +2,8 @@
 menuconfig MTD_SPI_NOR
 	tristate "SPI-NOR device support"
 	depends on MTD
+	depends on MTD && SPI_MASTER
+	select SPI_MEM
 	help
 	  This is the framework for the SPI NOR which can be used by the SPI
 	  device drivers and the SPI-NOR device driver.
drivers/mtd/spi-nor/spi-nor.c +685 -29

931 lines not on this page · raw message

include/linux/mtd/spi-nor.h +8 -0
index 9f57cdfcc93d..e18c03f72ded 100644
@@ -9,6 +9,7 @@
 #include <linux/bitops.h>
 #include <linux/mtd/cfi.h>
 #include <linux/mtd/mtd.h>
+#include <linux/spi/spi-mem.h>
 
 /*
  * Manufacturer IDs
@@ -344,6 +345,10 @@ struct flash_info;
  * @mtd:		point to a mtd_info structure
  * @lock:		the lock for the read/write/erase/lock/unlock operations
  * @dev:		point to a spi device, or a spi nor controller device.
+ * @spimem:		point to the spi mem device
+ * @bouncebuf:		bounce buffer used when the buffer passed by the MTD
+ *                      layer is not DMA-able
+ * @bouncebuf_size:	size of the bounce buffer
  * @info:		spi-nor part JDEC MFR id and other info
  * @page_size:		the page size of the SPI NOR
  * @addr_width:		number of address bytes
@@ -382,6 +387,9 @@ struct spi_nor {
 	struct mtd_info		mtd;
 	struct mutex		lock;
 	struct device		*dev;
+	struct spi_mem		*spimem;
+	void			*bouncebuf;
+	size_t			bouncebuf_size;
 	const struct flash_info	*info;
 	u32			page_size;
 	u8			addr_width;
Signature · 1 line
2.22.0
#2 lore raw

Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c

All,

I want this in 5.4, please review/test the soonest.

Quoted 13 lines · Vignesh Raghavendra
drivers/mtd/spi-nor/spi-nor.c +1 -0
index 03cc788511d5..f428a6d4022b 100644
@@ -19,6 +19,7 @@
 
 #include <linux/mtd/mtd.h>
 #include <linux/of_platform.h>
+#include <linux/sched/task_stack.h>
 #include <linux/spi/flash.h>
 #include <linux/mtd/spi-nor.h>
 

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 293

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +2 -0
@@ -288,6 +289,232 @@ struct flash_info {
 
 #define JEDEC_MFR(info)	((info)->id[0])
 
+/**
+ * spi_nor_exec_op() - helper function to read/write flash registers

the function name can easily get confused with spi_mem_exec_op(). How about renaming it to spi_nor_spimem_xfer_reg(), it will be in concordance with spi_nor_spimem_xfer_data().

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 298

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +5 -0
+ * @nor:        pointer to 'struct spi_nor'
+ * @op:         pointer to 'struct spi_mem_op' template for transfer
+ * @addr:       pointer to offset within flash
+ * @buf:        pointer to data buffer into which data is read/written
+ *              into

^ drop second into

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 301

Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +3 -0
+ * @len:        length of the transfer
+ *
+ * Return: 0 on success, non-zero otherwise
                            ^ s/non-zero/-errno?

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 307

Quoted 6 lines
drivers/mtd/spi-nor/spi-nor.c +6 -0
+ */
+static int spi_nor_exec_op(struct spi_nor *nor, struct spi_mem_op *op,
+			   u64 *addr, void *buf, size_t len)
+{
+	int ret;
+	bool usebouncebuf = false;

I don't think we need a bounce buffer for regs. What is the maximum size that we read/write regs, SPI_NOR_MAX_CMD_SIZE(8)?

In spi-nor.c the maximum length that we pass to nor->read_reg()/write_reg() is SPI_NOR_MAX_ID_LEN(6).

I can provide a patch to always use nor->cmd_buf when reading/writing regs so you respin the series on top of it, if you feel the same.

With nor->cmd_buf this function will be reduced to the following:

static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)

{
	if (!op || (op->data.nbytes && !nor->cmd_buf))
		return -EINVAL;

	return spi_mem_exec_op(nor->spimem, op);
}

spi_nor_exec_op() always received a NULL addr, let's get rid of it. We won't need buf anymore and you can retrieve the length from op->data.nbytes. Now that we trimmed the arguments, I think I would get rid of the spi_nor_data/nodata_op() wrappers and use spi_nor_spimem_xfer_reg() directly.

Quoted 34 lines
drivers/mtd/spi-nor/spi-nor.c +34 -0
+
+	if (!op || (len && !buf))
+		return -EINVAL;
+
+	if (op->addr.nbytes && addr)
+		op->addr.val = *addr;
+
+	op->data.nbytes = len;
+
+	if (object_is_on_stack(buf) || !virt_addr_valid(buf))
+		usebouncebuf = true;
+	if (len && usebouncebuf) {
+		if (len > nor->bouncebuf_size)
+			return -ENOTSUPP;
+
+		if (op->data.dir == SPI_MEM_DATA_IN) {
+			op->data.buf.in = nor->bouncebuf;
+		} else {
+			op->data.buf.out = nor->bouncebuf;
+			memcpy(nor->bouncebuf, buf, len);
+		}
+	} else {
+		op->data.buf.out = buf;
+	}
+
+	ret = spi_mem_exec_op(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	if (usebouncebuf && len && op->data.dir == SPI_MEM_DATA_IN)
+		memcpy(buf, nor->bouncebuf, len);
+
+	return 0;
+}

cut

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +5 -0
+
+/**
+ * spi_nor_spimem_xfer_data() - helper function to read/write data to
+ *                              flash's memory region
+ * @nor:        pointer to 'struct spi_nor'

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 384

Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +10 -0
+ * @op:         pointer to 'struct spi_mem_op' template for transfer
+ * @proto:      protocol to be used for transfer
+ *
+ * Return: number of bytes transferred on success, -errno otherwise
+ */
+static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
+					struct spi_mem_op *op,
+					enum spi_nor_protocol proto)
+{
+	bool usebouncebuf = false;

declare bool at the end to avoid stack padding.

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 386

Quoted 2 lines
drivers/mtd/spi-nor/spi-nor.c +2 -0
+	void *rdbuf = NULL;
+	const void *buf;

you can get rid of rdbuf and buf if you pass buf as argument.

Quoted 44 lines
drivers/mtd/spi-nor/spi-nor.c +44 -0
+	int ret;
+
+	/* get transfer protocols. */
+	op->cmd.buswidth = spi_nor_get_protocol_inst_nbits(proto);
+	op->addr.buswidth = spi_nor_get_protocol_addr_nbits(proto);
+	op->data.buswidth = spi_nor_get_protocol_data_nbits(proto);
+
+	if (op->data.dir == SPI_MEM_DATA_IN)
+		buf = op->data.buf.in;
+	else
+		buf = op->data.buf.out;
+
+	if (object_is_on_stack(buf) || !virt_addr_valid(buf))
+		usebouncebuf = true;
+
+	if (usebouncebuf) {
+		if (op->data.nbytes > nor->bouncebuf_size)
+			op->data.nbytes = nor->bouncebuf_size;
+
+		if (op->data.dir == SPI_MEM_DATA_IN) {
+			rdbuf = op->data.buf.in;
+			op->data.buf.in = nor->bouncebuf;
+		} else {
+			op->data.buf.out = nor->bouncebuf;
+			memcpy(nor->bouncebuf, buf,
+			       op->data.nbytes);
+		}
+	}
+
+	ret = spi_mem_adjust_op_size(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	ret = spi_mem_exec_op(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	if (usebouncebuf && op->data.dir == SPI_MEM_DATA_IN)
+		memcpy(rdbuf, nor->bouncebuf, op->data.nbytes);
+
+	return op->data.nbytes;
+}
+
+/**

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 440

Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +10 -0
+ * spi_nor_spimem_read_data() - read data from flash's memory region via
+ *                              spi-mem
+ * @nor:        pointer to 'struct spi_nor'
+ * @ofs:        offset to read from
+ * @len:        number of bytes to read
+ * @buf:        pointer to dst buffer
+ *
+ * Return: number of bytes read successfully, -errno otherwise
+ */
+static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t ofs,

s/ofs/from? both flash and buf may have offsets, "from" better indicates that the offset is associated with the flash.

Quoted 4 lines
drivers/mtd/spi-nor/spi-nor.c +4 -0
+					size_t len, u8 *buf)
+{
+	struct spi_mem_op op =
+		SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 1),

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 454

Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +10 -0
+			   SPI_MEM_OP_ADDR(nor->addr_width, ofs, 1),
+			   SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
+			   SPI_MEM_OP_DATA_IN(len, buf, 1));
+
+	op.dummy.buswidth = spi_nor_get_protocol_addr_nbits(nor->read_proto);
+
+	/* convert the dummy cycles to the number of bytes */
+	op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
+
+	return spi_nor_spimem_xfer_data(nor, &op, nor->read_proto);

stop passing nor->read_proto and do all buswidth initialization here. This way we'll keep the inits all gathered together, and will have the xfer() that will do just the transfer (with bouncebuffer if needed). Function that does a single thing.

Quoted 1 line

+}

cut

drivers/mtd/spi-nor/spi-nor.c static void spi_nor_set_4byte_opcodes(struct spi_nor *nor) · line 462

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +0 -1
@@ -459,7 +749,6 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
 		struct spi_nor_erase_map *map = &nor->erase_map;
 		struct spi_nor_erase_type *erase;
 		int i;
-

keep the blank line

cut

drivers/mtd/spi-nor/spi-nor.c static int write_sr_cr(struct spi_nor *nor, u8 *sr_cr) · line 1815

Quoted 11 lines
drivers/mtd/spi-nor/spi-nor.c +6 -1
@@ -1406,7 +1807,18 @@ static int write_sr_cr(struct spi_nor *nor, u8 *sr_cr)
 
 	write_enable(nor);
 
-	ret = nor->write_reg(nor, SPINOR_OP_WRSR, sr_cr, 2);
+	if (nor->spimem) {
+		struct spi_mem_op op =
+			SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRSR, 1),
+				   SPI_MEM_OP_NO_ADDR,
+				   SPI_MEM_OP_NO_DUMMY,
+				   SPI_MEM_OP_DATA_OUT(0, NULL, 1));

nbytes is 2.

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +5 -0
+
+		ret = spi_nor_data_op(nor, &op, sr_cr, 2);
+	} else {
+		ret = nor->write_reg(nor, SPINOR_OP_WRSR, sr_cr, 2);
+	}

cut

drivers/mtd/spi-nor/spi-nor.c static int sr2_bit7_quad_enable(struct spi_nor *nor) · line 1629

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +0 -1
@@ -1626,8 +2068,7 @@ static int sr2_bit7_quad_enable(struct spi_nor *nor)
 		return ret;
 	}
 
-	/* Read back and check it. */

don't drop the comment

Quoted 6 lines
drivers/mtd/spi-nor/spi-nor.c +1 -1
-	ret = nor->read_reg(nor, SPINOR_OP_RDSR2, &sr2, 1);
+	ret = spi_nor_read_sr2(nor, &sr2);
 	if (!(ret > 0 && (sr2 & SR2_QUAD_EN_BIT7))) {
 		dev_err(nor->dev, "SR2 Quad bit not set\n");
 		return -EINVAL;

drivers/mtd/spi-nor/spi-nor.c static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) · line 2629

Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +6 -1
@@ -2180,7 +2621,18 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
 	u8			id[SPI_NOR_MAX_ID_LEN];
 	const struct flash_info	*info;
 
-	tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN);
+	if (nor->spimem) {
+		struct spi_mem_op op =
+			SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 1),
+				   SPI_MEM_OP_NO_ADDR,
+				   SPI_MEM_OP_NO_DUMMY,
+				   SPI_MEM_OP_DATA_IN(0, NULL, 1));

nbytes is SPI_NOR_MAX_ID_LEN and not 1.

Cheers,
ta

#3 lore raw

Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c

Quoted 3 lines · On 07/25/2019 02:19 PM, [email protected] wrote:

static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)

{
	if (!op || (op->data.nbytes && !nor->cmd_buf))

!nor->cmd_buf can't be NULL, we can get rid of this check too, and use spi_mem_exec_op() directly when interacting with registers.

Quoted 4 lines
		return -EINVAL;

	return spi_mem_exec_op(nor->spimem, op);
}
#4 lore raw

Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c

In reply to [email protected]
Quoted 18 lines · On Thu, 25 Jul 2019 11:19:06 +0000 <[email protected]> wrote:

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 307

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static int spi_nor_exec_op(struct spi_nor *nor, struct spi_mem_op *op,
+			   u64 *addr, void *buf, size_t len)
+{
+	int ret;
+	bool usebouncebuf = false;  

I don't think we need a bounce buffer for regs. What is the maximum size that we read/write regs, SPI_NOR_MAX_CMD_SIZE(8)?

In spi-nor.c the maximum length that we pass to nor->read_reg()/write_reg() is SPI_NOR_MAX_ID_LEN(6).

I can provide a patch to always use nor->cmd_buf when reading/writing regs so you respin the series on top of it, if you feel the same.

With nor->cmd_buf this function will be reduced to the following:

Quoted 7 lines

static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)

{
	if (!op || (op->data.nbytes && !nor->cmd_buf))
		return -EINVAL;

	return spi_mem_exec_op(nor->spimem, op);
}

Well, I don't think that's a good idea. ->cmd_buf is an array in the middle of the spi_nor struct, which means it won't be aligned on a cache line and you'll have to be extra careful not to touch the spi_nor fields when calling spi_mem_exec_op(). Might work, but I wouldn't take the risk if I were you.

Another option would be to allocate ->cmd_buf with kmalloc() instead of having it defined as a static array.

Quoted 5 lines

spi_nor_exec_op() always received a NULL addr, let's get rid of it. We won't need buf anymore and you can retrieve the length from op->data.nbytes. Now that we trimmed the arguments, I think I would get rid of the spi_nor_data/nodata_op() wrappers and use spi_nor_spimem_xfer_reg() directly.

I think I added the addr param for a good reason (probably to support Octo mode cmds that take an address parameter). This being said, I agree with you, we should just pass everything through the op parameter (including the address if we ever need to add one).

Quoted 9 lines
Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c +9 -0
+
+/**
+ * spi_nor_spimem_xfer_data() - helper function to read/write data to
+ *                              flash's memory region
+ * @nor:        pointer to 'struct spi_nor'
+ * @op:         pointer to 'struct spi_mem_op' template for transfer
+ * @proto:      protocol to be used for transfer
+ *
+ * Return: number of bytes transferred on success, -errno otherwise
Quoted 8 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 384

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
+					struct spi_mem_op *op,
+					enum spi_nor_protocol proto)
+{
+	bool usebouncebuf = false;  

declare bool at the end to avoid stack padding.

But it breaks the reverse-xmas-tree formatting :-).

Quoted 5 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 386

Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +2 -0
+	void *rdbuf = NULL;
+	const void *buf;  

you can get rid of rdbuf and buf if you pass buf as argument.

Hm, passing the buffer to send data from/receive data into is already part of the spi_mem_op definition process (which is done in the caller of this func) so why bother passing an extra arg to the function. Note that you had the exact opposite argument for the spi_nor_spimem_xfer_reg() prototype you suggested above (which I agree with BTW) :P.

Quoted 50 lines
Quoted 50 lines
drivers/mtd/spi-nor/spi-nor.c +49 -0
+	int ret;
+
+	/* get transfer protocols. */
+	op->cmd.buswidth = spi_nor_get_protocol_inst_nbits(proto);
+	op->addr.buswidth = spi_nor_get_protocol_addr_nbits(proto);
+	op->data.buswidth = spi_nor_get_protocol_data_nbits(proto);
+
+	if (op->data.dir == SPI_MEM_DATA_IN)
+		buf = op->data.buf.in;
+	else
+		buf = op->data.buf.out;
+
+	if (object_is_on_stack(buf) || !virt_addr_valid(buf))
+		usebouncebuf = true;
+
+	if (usebouncebuf) {
+		if (op->data.nbytes > nor->bouncebuf_size)
+			op->data.nbytes = nor->bouncebuf_size;
+
+		if (op->data.dir == SPI_MEM_DATA_IN) {
+			rdbuf = op->data.buf.in;
+			op->data.buf.in = nor->bouncebuf;
+		} else {
+			op->data.buf.out = nor->bouncebuf;
+			memcpy(nor->bouncebuf, buf,
+			       op->data.nbytes);
+		}
+	}
+
+	ret = spi_mem_adjust_op_size(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	ret = spi_mem_exec_op(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	if (usebouncebuf && op->data.dir == SPI_MEM_DATA_IN)
+		memcpy(rdbuf, nor->bouncebuf, op->data.nbytes);
+
+	return op->data.nbytes;
+}
+
+/**
+ * spi_nor_spimem_read_data() - read data from flash's memory region via
+ *                              spi-mem
+ * @nor:        pointer to 'struct spi_nor'
+ * @ofs:        offset to read from
+ * @len:        number of bytes to read
Quoted 8 lines
Quoted 5 lines

+ * @buf: pointer to dst buffer
+ *
+ * Return: number of bytes read successfully, -errno otherwise
+ */
+static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t ofs,

s/ofs/from? both flash and buf may have offsets, "from" better indicates that the offset is associated with the flash.

The semantic is well documented in the doc just above the function, but I have the feeling that you're in 'nitpick' mode, so I'll just let you pick the one you prefer :).

Quoted 12 lines
Quoted 12 lines
drivers/mtd/spi-nor/spi-nor.c +11 -0
+					size_t len, u8 *buf)
+{
+	struct spi_mem_op op =
+		SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 1),
+			   SPI_MEM_OP_ADDR(nor->addr_width, ofs, 1),
+			   SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
+			   SPI_MEM_OP_DATA_IN(len, buf, 1));
+
+	op.dummy.buswidth = spi_nor_get_protocol_addr_nbits(nor->read_proto);
+
+	/* convert the dummy cycles to the number of bytes */
Quoted 8 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 454

Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +3 -0
+	op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
+
+	return spi_nor_spimem_xfer_data(nor, &op, nor->read_proto);  

stop passing nor->read_proto and do all buswidth initialization here. This way we'll keep the inits all gathered together, and will have the xfer() that will do just the transfer (with bouncebuffer if needed). Function that does a single thing.

Indeed, doesn't make sense to pass this info since it could be passed through the op->data field.

#5 lore raw

Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c

Hi, Boris,

Quoted 29 lines · Boris Brezillon

External E-Mail

Quoted 23 lines · On Thu, 25 Jul 2019 11:19:06 +0000 <[email protected]> wrote:

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 307

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static int spi_nor_exec_op(struct spi_nor *nor, struct spi_mem_op *op,
+			   u64 *addr, void *buf, size_t len)
+{
+	int ret;
+	bool usebouncebuf = false;  

I don't think we need a bounce buffer for regs. What is the maximum size that we read/write regs, SPI_NOR_MAX_CMD_SIZE(8)?

In spi-nor.c the maximum length that we pass to nor->read_reg()/write_reg() is SPI_NOR_MAX_ID_LEN(6).

I can provide a patch to always use nor->cmd_buf when reading/writing regs so you respin the series on top of it, if you feel the same.

With nor->cmd_buf this function will be reduced to the following:

static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)

{
	if (!op || (op->data.nbytes && !nor->cmd_buf))
		return -EINVAL;
Quoted 9 lines
Quoted 2 lines
	return spi_mem_exec_op(nor->spimem, op);
}

Well, I don't think that's a good idea. ->cmd_buf is an array in the middle of the spi_nor struct, which means it won't be aligned on a cache line and you'll have to be extra careful not to touch the spi_nor fields when calling spi_mem_exec_op(). Might work, but I wouldn't take the risk if I were you.

u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE] ____cacheline_aligned;

Does this help?

Quoted 41 lines

Another option would be to allocate ->cmd_buf with kmalloc() instead of having it defined as a static array.

Quoted 5 lines

spi_nor_exec_op() always received a NULL addr, let's get rid of it. We won't need buf anymore and you can retrieve the length from op->data.nbytes. Now that we trimmed the arguments, I think I would get rid of the spi_nor_data/nodata_op() wrappers and use spi_nor_spimem_xfer_reg() directly.

I think I added the addr param for a good reason (probably to support Octo mode cmds that take an address parameter). This being said, I agree with you, we should just pass everything through the op parameter (including the address if we ever need to add one).

Quoted 9 lines
Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c +9 -0
+
+/**
+ * spi_nor_spimem_xfer_data() - helper function to read/write data to
+ *                              flash's memory region
+ * @nor:        pointer to 'struct spi_nor'
+ * @op:         pointer to 'struct spi_mem_op' template for transfer
+ * @proto:      protocol to be used for transfer
+ *
+ * Return: number of bytes transferred on success, -errno otherwise
Quoted 8 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 384

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
+					struct spi_mem_op *op,
+					enum spi_nor_protocol proto)
+{
+	bool usebouncebuf = false;  

declare bool at the end to avoid stack padding.

But it breaks the reverse-xmas-tree formatting :-).

Quoted 5 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 386

Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +2 -0
+	void *rdbuf = NULL;
+	const void *buf;  

you can get rid of rdbuf and buf if you pass buf as argument.

Quoted 6 lines

Hm, passing the buffer to send data from/receive data into is already part of the spi_mem_op definition process (which is done in the caller of this func) so why bother passing an extra arg to the function. Note that you had the exact opposite argument for the spi_nor_spimem_xfer_reg() prototype you suggested above (which I agree with BTW) :P.

In order to avoid if clauses like "if (op->data.dir == SPI_MEM_DATA_IN)". You can't use op->data.buf directly, the *out const qualifier can be discarded.

pointer to buf was not needed in spi_nor_spimem_xfer_reg(), we could use nor->cmd_buf.

Quoted 60 lines
Quoted 51 lines
Quoted 51 lines
drivers/mtd/spi-nor/spi-nor.c +49 -0
+	int ret;
+
+	/* get transfer protocols. */
+	op->cmd.buswidth = spi_nor_get_protocol_inst_nbits(proto);
+	op->addr.buswidth = spi_nor_get_protocol_addr_nbits(proto);
+	op->data.buswidth = spi_nor_get_protocol_data_nbits(proto);
+
+	if (op->data.dir == SPI_MEM_DATA_IN)
+		buf = op->data.buf.in;
+	else
+		buf = op->data.buf.out;
+
+	if (object_is_on_stack(buf) || !virt_addr_valid(buf))
+		usebouncebuf = true;
+
+	if (usebouncebuf) {
+		if (op->data.nbytes > nor->bouncebuf_size)
+			op->data.nbytes = nor->bouncebuf_size;
+
+		if (op->data.dir == SPI_MEM_DATA_IN) {
+			rdbuf = op->data.buf.in;
+			op->data.buf.in = nor->bouncebuf;
+		} else {
+			op->data.buf.out = nor->bouncebuf;
+			memcpy(nor->bouncebuf, buf,
+			       op->data.nbytes);
+		}
+	}
+
+	ret = spi_mem_adjust_op_size(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	ret = spi_mem_exec_op(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	if (usebouncebuf && op->data.dir == SPI_MEM_DATA_IN)
+		memcpy(rdbuf, nor->bouncebuf, op->data.nbytes);
+
+	return op->data.nbytes;
+}
+
+/**
+ * spi_nor_spimem_read_data() - read data from flash's memory region via
+ *                              spi-mem
+ * @nor:        pointer to 'struct spi_nor'
+ * @ofs:        offset to read from
+ * @len:        number of bytes to read
Quoted 8 lines
Quoted 5 lines

+ * @buf: pointer to dst buffer
+ *
+ * Return: number of bytes read successfully, -errno otherwise
+ */
+static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t ofs,

s/ofs/from? both flash and buf may have offsets, "from" better indicates that the offset is associated with the flash.

Quoted 3 lines

The semantic is well documented in the doc just above the function, but I have the feeling that you're in 'nitpick' mode, so I'll just let you pick the one you prefer :).

Not my intention. struct mtd_info and struct spi_nor use "from" when referring to the offset from where to read in the read() calls. Just consistency reasons.

Cheers,
ta

#6 lore raw

Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c

Quoted 11 lines · Tudor Ambarus
Quoted 11 lines
Quoted 6 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 384

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +5 -0
+static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
+					struct spi_mem_op *op,
+					enum spi_nor_protocol proto)
+{
+	bool usebouncebuf = false;  

declare bool at the end to avoid stack padding.

But it breaks the reverse-xmas-tree formatting :-).

Quoted 3 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 386

Quoted 2 lines
drivers/mtd/spi-nor/spi-nor.c +2 -0
+	void *rdbuf = NULL;
+	const void *buf;  

you can get rid of rdbuf and buf if you pass buf as argument.

Quoted 8 lines
Quoted 6 lines

Hm, passing the buffer to send data from/receive data into is already part of the spi_mem_op definition process (which is done in the caller of this func) so why bother passing an extra arg to the function. Note that you had the exact opposite argument for the spi_nor_spimem_xfer_reg() prototype you suggested above (which I agree with BTW) :P.

In order to avoid if clauses like "if (op->data.dir == SPI_MEM_DATA_IN)". You can't use op->data.buf directly, the *out const qualifier can be discarded.

I'm wrong, the const qualifier will be discarded when passing the buf argument. Please ignore.

#7 lore raw

Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c

In reply to [email protected]
Quoted 42 lines · On Thu, 25 Jul 2019 13:17:07 +0000 <[email protected]> wrote:

Hi, Boris,

Quoted 29 lines · Boris Brezillon

External E-Mail

Quoted 23 lines · On Thu, 25 Jul 2019 11:19:06 +0000 <[email protected]> wrote:

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 307

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static int spi_nor_exec_op(struct spi_nor *nor, struct spi_mem_op *op,
+			   u64 *addr, void *buf, size_t len)
+{
+	int ret;
+	bool usebouncebuf = false;    

I don't think we need a bounce buffer for regs. What is the maximum size that we read/write regs, SPI_NOR_MAX_CMD_SIZE(8)?

In spi-nor.c the maximum length that we pass to nor->read_reg()/write_reg() is SPI_NOR_MAX_ID_LEN(6).

I can provide a patch to always use nor->cmd_buf when reading/writing regs so you respin the series on top of it, if you feel the same.

With nor->cmd_buf this function will be reduced to the following:

static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)

{
	if (!op || (op->data.nbytes && !nor->cmd_buf))
		return -EINVAL;
Quoted 9 lines
Quoted 2 lines
	return spi_mem_exec_op(nor->spimem, op);
}  

Well, I don't think that's a good idea. ->cmd_buf is an array in the middle of the spi_nor struct, which means it won't be aligned on a cache line and you'll have to be extra careful not to touch the spi_nor fields when calling spi_mem_exec_op(). Might work, but I wouldn't take the risk if I were you.

Quoted 3 lines

u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE] ____cacheline_aligned;

Does this help?

I guess you'll also need one on the following field to guarantee that cmd_buf is covering the whole cache line. TBH, I really prefer the option of allocating ->cmd_buf.

Quoted 49 lines
Quoted 42 lines

Another option would be to allocate ->cmd_buf with kmalloc() instead of having it defined as a static array.

Quoted 5 lines

spi_nor_exec_op() always received a NULL addr, let's get rid of it. We won't need buf anymore and you can retrieve the length from op->data.nbytes. Now that we trimmed the arguments, I think I would get rid of the spi_nor_data/nodata_op() wrappers and use spi_nor_spimem_xfer_reg() directly.

I think I added the addr param for a good reason (probably to support Octo mode cmds that take an address parameter). This being said, I agree with you, we should just pass everything through the op parameter (including the address if we ever need to add one).

Quoted 9 lines
Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c +9 -0
+
+/**
+ * spi_nor_spimem_xfer_data() - helper function to read/write data to
+ *                              flash's memory region
+ * @nor:        pointer to 'struct spi_nor'
+ * @op:         pointer to 'struct spi_mem_op' template for transfer
+ * @proto:      protocol to be used for transfer
+ *
+ * Return: number of bytes transferred on success, -errno otherwise
Quoted 8 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 384

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
+					struct spi_mem_op *op,
+					enum spi_nor_protocol proto)
+{
+	bool usebouncebuf = false;    

declare bool at the end to avoid stack padding.

But it breaks the reverse-xmas-tree formatting :-).

Quoted 5 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 386

Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +2 -0
+	void *rdbuf = NULL;
+	const void *buf;    

you can get rid of rdbuf and buf if you pass buf as argument.

Quoted 6 lines

Hm, passing the buffer to send data from/receive data into is already part of the spi_mem_op definition process (which is done in the caller of this func) so why bother passing an extra arg to the function. Note that you had the exact opposite argument for the spi_nor_spimem_xfer_reg() prototype you suggested above (which I agree with BTW) :P.

Quoted 2 lines

In order to avoid if clauses like "if (op->data.dir == SPI_MEM_DATA_IN)". You can't use op->data.buf directly, the *out const qualifier can be discarded.

Not entirely sure why you think this is important to avoid that test (looks like a micro-optimization to me), but if you really want to have a non-const buffer, just use the one pointed by op->data.buf.in (buf is a union so both in and out point to the same thing). Note that we'd need a comment explaining why this is safe to do that, because bypassing constness constraints is usually a bad thing.

Quoted 3 lines

pointer to buf was not needed in spi_nor_spimem_xfer_reg(), we could use nor->cmd_buf.

Do you mean that callers of spi_nor_spimem_xfer_data() should put data into/read from ->cmd_buf and let spi_nor_spimem_xfer_data() assign op->data.buf.{in,out} to ->cmd_buf?

#8 lore raw

Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c

Quoted 48 lines · Boris Brezillon

External E-Mail

Quoted 42 lines · On Thu, 25 Jul 2019 13:17:07 +0000 <[email protected]> wrote:

Hi, Boris,

Quoted 38 lines · Boris Brezillon

External E-Mail

Quoted 18 lines · On Thu, 25 Jul 2019 11:19:06 +0000 <[email protected]> wrote:

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 307

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static int spi_nor_exec_op(struct spi_nor *nor, struct spi_mem_op *op,
+			   u64 *addr, void *buf, size_t len)
+{
+	int ret;
+	bool usebouncebuf = false;    

I don't think we need a bounce buffer for regs. What is the maximum size that we read/write regs, SPI_NOR_MAX_CMD_SIZE(8)?

In spi-nor.c the maximum length that we pass to nor->read_reg()/write_reg() is SPI_NOR_MAX_ID_LEN(6).

I can provide a patch to always use nor->cmd_buf when reading/writing regs so you respin the series on top of it, if you feel the same.

With nor->cmd_buf this function will be reduced to the following:

Quoted 7 lines

static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)

{
	if (!op || (op->data.nbytes && !nor->cmd_buf))
		return -EINVAL;

	return spi_mem_exec_op(nor->spimem, op);
}  

Well, I don't think that's a good idea. ->cmd_buf is an array in the middle of the spi_nor struct, which means it won't be aligned on a cache line and you'll have to be extra careful not to touch the spi_nor fields when calling spi_mem_exec_op(). Might work, but I wouldn't take the risk if I were you.

Quoted 7 lines
Quoted 3 lines

u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE] ____cacheline_aligned;

Does this help?

I guess you'll also need one on the following field to guarantee that cmd_buf is covering the whole cache line. TBH, I really prefer the option of allocating ->cmd_buf.

agreed.

Quoted 53 lines
Quoted 50 lines
Quoted 43 lines

Another option would be to allocate ->cmd_buf with kmalloc() instead of having it defined as a static array.

Quoted 5 lines

spi_nor_exec_op() always received a NULL addr, let's get rid of it. We won't need buf anymore and you can retrieve the length from op->data.nbytes. Now that we trimmed the arguments, I think I would get rid of the spi_nor_data/nodata_op() wrappers and use spi_nor_spimem_xfer_reg() directly.

I think I added the addr param for a good reason (probably to support Octo mode cmds that take an address parameter). This being said, I agree with you, we should just pass everything through the op parameter (including the address if we ever need to add one).

Quoted 9 lines
Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c +9 -0
+
+/**
+ * spi_nor_spimem_xfer_data() - helper function to read/write data to
+ *                              flash's memory region
+ * @nor:        pointer to 'struct spi_nor'
+ * @op:         pointer to 'struct spi_mem_op' template for transfer
+ * @proto:      protocol to be used for transfer
+ *
+ * Return: number of bytes transferred on success, -errno otherwise
Quoted 8 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 384

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
+					struct spi_mem_op *op,
+					enum spi_nor_protocol proto)
+{
+	bool usebouncebuf = false;    

declare bool at the end to avoid stack padding.

But it breaks the reverse-xmas-tree formatting :-).

Quoted 5 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 386

Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +2 -0
+	void *rdbuf = NULL;
+	const void *buf;    

you can get rid of rdbuf and buf if you pass buf as argument.

Quoted 6 lines

Hm, passing the buffer to send data from/receive data into is already part of the spi_mem_op definition process (which is done in the caller of this func) so why bother passing an extra arg to the function. Note that you had the exact opposite argument for the spi_nor_spimem_xfer_reg() prototype you suggested above (which I agree with BTW) :P.

Quoted 2 lines

In order to avoid if clauses like "if (op->data.dir == SPI_MEM_DATA_IN)". You can't use op->data.buf directly, the *out const qualifier can be discarded.

Quoted 6 lines

Not entirely sure why you think this is important to avoid that test (looks like a micro-optimization to me), but if you really want to have a non-const buffer, just use the one pointed by op->data.buf.in (buf is a union so both in and out point to the same thing). Note that we'd need a comment explaining why this is safe to do that, because bypassing constness constraints is usually a bad thing.

No need for a buf argument, I missed that the const qualifier will be discarded when passing the pointer. We'll keep the function as it is, with the amend that the "enum spi_nor_protocol proto" will be removed from the arguments.

Thanks for jumping in,
ta

author maintainer
#9 lore raw

Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c

In reply to [email protected]

Hi Tudor,

Quoted 56 lines · On 25-Jul-19 4:49 PM, [email protected] wrote:

All,

I want this in 5.4, please review/test the soonest.

Quoted 13 lines · Vignesh Raghavendra
drivers/mtd/spi-nor/spi-nor.c +1 -0
index 03cc788511d5..f428a6d4022b 100644
@@ -19,6 +19,7 @@
 
 #include <linux/mtd/mtd.h>
 #include <linux/of_platform.h>
+#include <linux/sched/task_stack.h>
 #include <linux/spi/flash.h>
 #include <linux/mtd/spi-nor.h>
 

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 293

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +2 -0
@@ -288,6 +289,232 @@ struct flash_info {
 
 #define JEDEC_MFR(info)	((info)->id[0])
 
+/**
+ * spi_nor_exec_op() - helper function to read/write flash registers

the function name can easily get confused with spi_mem_exec_op(). How about renaming it to spi_nor_spimem_xfer_reg(), it will be in concordance with spi_nor_spimem_xfer_data().

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 298

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +5 -0
+ * @nor:        pointer to 'struct spi_nor'
+ * @op:         pointer to 'struct spi_mem_op' template for transfer
+ * @addr:       pointer to offset within flash
+ * @buf:        pointer to data buffer into which data is read/written
+ *              into

^ drop second into

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 301

Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +3 -0
+ * @len:        length of the transfer
+ *
+ * Return: 0 on success, non-zero otherwise
                            ^ s/non-zero/-errno?

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 307

Quoted 6 lines
drivers/mtd/spi-nor/spi-nor.c +6 -0
+ */
+static int spi_nor_exec_op(struct spi_nor *nor, struct spi_mem_op *op,
+			   u64 *addr, void *buf, size_t len)
+{
+	int ret;
+	bool usebouncebuf = false;

I don't think we need a bounce buffer for regs. What is the maximum size that we read/write regs, SPI_NOR_MAX_CMD_SIZE(8)?

In spi-nor.c the maximum length that we pass to nor->read_reg()/write_reg() is SPI_NOR_MAX_ID_LEN(6).

Quoted 7 lines

I can provide a patch to always use nor->cmd_buf when reading/writing regs so you respin the series on top of it, if you feel the same.

With nor->cmd_buf this function will be reduced to the following:

I will move the code introducing bounce buffer into separate patch at the beginning of this series and switch over all read/write regs functions to use bounce buffer instead of cmd_buf. cmd_buf will be dropped. And then simplify this patch to spi_nor_spimem_xfer_reg() to you pointed out below. Does that sound good?

Quoted 59 lines

static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)

{
	if (!op || (op->data.nbytes && !nor->cmd_buf))
		return -EINVAL;

	return spi_mem_exec_op(nor->spimem, op);
}

spi_nor_exec_op() always received a NULL addr, let's get rid of it. We won't need buf anymore and you can retrieve the length from op->data.nbytes. Now that we trimmed the arguments, I think I would get rid of the spi_nor_data/nodata_op() wrappers and use spi_nor_spimem_xfer_reg() directly.

Quoted 34 lines
drivers/mtd/spi-nor/spi-nor.c +34 -0
+
+	if (!op || (len && !buf))
+		return -EINVAL;
+
+	if (op->addr.nbytes && addr)
+		op->addr.val = *addr;
+
+	op->data.nbytes = len;
+
+	if (object_is_on_stack(buf) || !virt_addr_valid(buf))
+		usebouncebuf = true;
+	if (len && usebouncebuf) {
+		if (len > nor->bouncebuf_size)
+			return -ENOTSUPP;
+
+		if (op->data.dir == SPI_MEM_DATA_IN) {
+			op->data.buf.in = nor->bouncebuf;
+		} else {
+			op->data.buf.out = nor->bouncebuf;
+			memcpy(nor->bouncebuf, buf, len);
+		}
+	} else {
+		op->data.buf.out = buf;
+	}
+
+	ret = spi_mem_exec_op(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	if (usebouncebuf && len && op->data.dir == SPI_MEM_DATA_IN)
+		memcpy(buf, nor->bouncebuf, len);
+
+	return 0;
+}

cut

Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c +9 -0
+
+/**
+ * spi_nor_spimem_xfer_data() - helper function to read/write data to
+ *                              flash's memory region
+ * @nor:        pointer to 'struct spi_nor'
+ * @op:         pointer to 'struct spi_mem_op' template for transfer
+ * @proto:      protocol to be used for transfer
+ *
+ * Return: number of bytes transferred on success, -errno otherwise
Quoted 9 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 384

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
+					struct spi_mem_op *op,
+					enum spi_nor_protocol proto)
+{
+	bool usebouncebuf = false;

declare bool at the end to avoid stack padding.

I prefer reverse xmas and hope compilers are intelligent enough to reorder allocation to save padding :)

Quoted 54 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 386

Quoted 2 lines
drivers/mtd/spi-nor/spi-nor.c +2 -0
+	void *rdbuf = NULL;
+	const void *buf;

you can get rid of rdbuf and buf if you pass buf as argument.

Quoted 49 lines
drivers/mtd/spi-nor/spi-nor.c +49 -0
+	int ret;
+
+	/* get transfer protocols. */
+	op->cmd.buswidth = spi_nor_get_protocol_inst_nbits(proto);
+	op->addr.buswidth = spi_nor_get_protocol_addr_nbits(proto);
+	op->data.buswidth = spi_nor_get_protocol_data_nbits(proto);
+
+	if (op->data.dir == SPI_MEM_DATA_IN)
+		buf = op->data.buf.in;
+	else
+		buf = op->data.buf.out;
+
+	if (object_is_on_stack(buf) || !virt_addr_valid(buf))
+		usebouncebuf = true;
+
+	if (usebouncebuf) {
+		if (op->data.nbytes > nor->bouncebuf_size)
+			op->data.nbytes = nor->bouncebuf_size;
+
+		if (op->data.dir == SPI_MEM_DATA_IN) {
+			rdbuf = op->data.buf.in;
+			op->data.buf.in = nor->bouncebuf;
+		} else {
+			op->data.buf.out = nor->bouncebuf;
+			memcpy(nor->bouncebuf, buf,
+			       op->data.nbytes);
+		}
+	}
+
+	ret = spi_mem_adjust_op_size(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	ret = spi_mem_exec_op(nor->spimem, op);
+	if (ret)
+		return ret;
+
+	if (usebouncebuf && op->data.dir == SPI_MEM_DATA_IN)
+		memcpy(rdbuf, nor->bouncebuf, op->data.nbytes);
+
+	return op->data.nbytes;
+}
+
+/**
+ * spi_nor_spimem_read_data() - read data from flash's memory region via
+ *                              spi-mem
+ * @nor:        pointer to 'struct spi_nor'
+ * @ofs:        offset to read from
+ * @len:        number of bytes to read
Quoted 8 lines
Quoted 5 lines

+ * @buf: pointer to dst buffer
+ *
+ * Return: number of bytes read successfully, -errno otherwise
+ */
+static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t ofs,

s/ofs/from? both flash and buf may have offsets, "from" better indicates that the offset is associated with the flash.

OK.

Quoted 12 lines
Quoted 12 lines
drivers/mtd/spi-nor/spi-nor.c +11 -0
+					size_t len, u8 *buf)
+{
+	struct spi_mem_op op =
+		SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 1),
+			   SPI_MEM_OP_ADDR(nor->addr_width, ofs, 1),
+			   SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
+			   SPI_MEM_OP_DATA_IN(len, buf, 1));
+
+	op.dummy.buswidth = spi_nor_get_protocol_addr_nbits(nor->read_proto);
+
+	/* convert the dummy cycles to the number of bytes */
Quoted 9 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 454

Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +3 -0
+	op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
+
+	return spi_nor_spimem_xfer_data(nor, &op, nor->read_proto);

stop passing nor->read_proto and do all buswidth initialization here. This way we'll keep the inits all gathered together, and will have the xfer() that will do just the transfer (with bouncebuffer if needed). Function that does a single thing.

Ok, my idea was to factor out all common code b/w spi_nor_spimem_read_data() and spi_nor_spimem_write_data() in spi_nor_spimem_xfer_data(). But, I am fine with your idea.

Quoted 4 lines
Quoted 1 line

+}

cut

Quoted 8 lines

drivers/mtd/spi-nor/spi-nor.c static void spi_nor_set_4byte_opcodes(struct spi_nor *nor) · line 462

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +0 -1
@@ -459,7 +749,6 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
 		struct spi_nor_erase_map *map = &nor->erase_map;
 		struct spi_nor_erase_type *erase;
 		int i;
-

keep the blank line

Will drop

Quoted 6 lines

cut

Quoted 4 lines
drivers/mtd/spi-nor/spi-nor.c +0 -0
@@ -1406,7 +1807,18 @@ static int write_sr_cr(struct spi_nor *nor, u8 *sr_cr)
 
 	write_enable(nor);
 
Quoted 10 lines

drivers/mtd/spi-nor/spi-nor.c static int write_sr_cr(struct spi_nor *nor, u8 *sr_cr) · line 1815

Quoted 7 lines
drivers/mtd/spi-nor/spi-nor.c +6 -1
-	ret = nor->write_reg(nor, SPINOR_OP_WRSR, sr_cr, 2);
+	if (nor->spimem) {
+		struct spi_mem_op op =
+			SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRSR, 1),
+				   SPI_MEM_OP_NO_ADDR,
+				   SPI_MEM_OP_NO_DUMMY,
+				   SPI_MEM_OP_DATA_OUT(0, NULL, 1));

nbytes is 2.

Will update when dropping spi_nor_data_op()

Quoted 8 lines
Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +5 -0
+
+		ret = spi_nor_data_op(nor, &op, sr_cr, 2);
+	} else {
+		ret = nor->write_reg(nor, SPINOR_OP_WRSR, sr_cr, 2);
+	}

cut

Quoted 7 lines

drivers/mtd/spi-nor/spi-nor.c static int sr2_bit7_quad_enable(struct spi_nor *nor) · line 1629

Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +0 -1
@@ -1626,8 +2068,7 @@ static int sr2_bit7_quad_enable(struct spi_nor *nor)
 		return ret;
 	}
 
-	/* Read back and check it. */

don't drop the comment

Agreed

Quoted 10 lines
Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +1 -1
-	ret = nor->read_reg(nor, SPINOR_OP_RDSR2, &sr2, 1);
+	ret = spi_nor_read_sr2(nor, &sr2);
 	if (!(ret > 0 && (sr2 & SR2_QUAD_EN_BIT7))) {
 		dev_err(nor->dev, "SR2 Quad bit not set\n");
 		return -EINVAL;
@@ -2180,7 +2621,18 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
 	u8			id[SPI_NOR_MAX_ID_LEN];
 	const struct flash_info	*info;
 
Quoted 10 lines

drivers/mtd/spi-nor/spi-nor.c static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) · line 2629

Quoted 7 lines
drivers/mtd/spi-nor/spi-nor.c +6 -1
-	tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN);
+	if (nor->spimem) {
+		struct spi_mem_op op =
+			SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 1),
+				   SPI_MEM_OP_NO_ADDR,
+				   SPI_MEM_OP_NO_DUMMY,
+				   SPI_MEM_OP_DATA_IN(0, NULL, 1));

nbytes is SPI_NOR_MAX_ID_LEN and not 1.

Will fix along with dropping spi_nor_data_op()

Quoted 3 lines

Cheers,
ta

Regards
Vignesh

#10 lore raw

Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c

Quoted 16 lines · Vignesh Raghavendra
Quoted 15 lines

drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 307

Quoted 6 lines

+ */

drivers/mtd/spi-nor/spi-nor.c +5 -0
+static int spi_nor_exec_op(struct spi_nor *nor, struct spi_mem_op *op,
+			   u64 *addr, void *buf, size_t len)
+{
+	int ret;
+	bool usebouncebuf = false;

I don't think we need a bounce buffer for regs. What is the maximum size that we read/write regs, SPI_NOR_MAX_CMD_SIZE(8)?

In spi-nor.c the maximum length that we pass to nor->read_reg()/write_reg() is SPI_NOR_MAX_ID_LEN(6).

I can provide a patch to always use nor->cmd_buf when reading/writing regs so you respin the series on top of it, if you feel the same.

Quoted 8 lines
Quoted 2 lines

With nor->cmd_buf this function will be reduced to the following:

I will move the code introducing bounce buffer into separate patch at the beginning of this series and switch over all read/write regs functions to use bounce buffer instead of cmd_buf. cmd_buf will be dropped. And then simplify this patch to spi_nor_spimem_xfer_reg() to you pointed out below. Does that sound good?

Please do. Probably we can get rid of spi_nor_spimem_xfer_reg entirely and use spi_mem_exec_op() directly when interacting with registers. I'll wait for your v3.

Cheers,
ta

Quoted 12 lines
Quoted 12 lines

static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)

{
	if (!op || (op->data.nbytes && !nor->cmd_buf))
		return -EINVAL;

	return spi_mem_exec_op(nor->spimem, op);
}

spi_nor_exec_op() always received a NULL addr, let's get rid of it. We won't need buf anymore and you can retrieve the length from op->data.nbytes. Now that we trimmed the arguments, I think I would get rid of the spi_nor_data/nodata_op() wrappers and use spi_nor_spimem_xfer_reg() directly.

author maintainer
#11 lore raw

PATCH v2 2/2 mtd: spi-nor: Rework hwcaps selection for the spi-mem case

In reply to Vignesh Raghavendra

From: Boris Brezillon <[email protected]>

The spi-mem layer provides a spi_mem_supports_op() function to check whether a specific operation is supported by the controller or not. This is much more accurate than the hwcaps selection logic based on SPI_{RX,TX}_ flags.

Rework the hwcaps selection logic to use spi_mem_supports_op() when nor->spimem != NULL.

---
v2:
Refractor spi_nor_spimem_adjust_hwcaps to avoid looping twice over WCAPS
Add docs to new functions
Rework spi_nor_spimem_check_op() logic

 drivers/mtd/spi-nor/spi-nor.c | 183 +++++++++++++++++++++++++++-------
 include/linux/mtd/spi-nor.h   |  14 +++
 2 files changed, 161 insertions(+), 36 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +147 -36
index f428a6d4022b..924dbaf3fa49 100644
@@ -3028,6 +3028,129 @@ static int spi_nor_read_sfdp(struct spi_nor *nor, u32 addr,
 	return ret;
 }
 
+/**
+ * spi_nor_spimem_check_op - check if the operation is supported
+ *                           by controller
+ *@nor:        pointer to a 'struct spi_nor'
+ *@op:         pointer to op template to be checked
+ *
+ * Returns 0 if operation is supported, -ENOTSUPP otherwise.
+ */
+static int spi_nor_spimem_check_op(struct spi_nor *nor,
+				   struct spi_mem_op *op)
+{
+	/*
+	 * First test with 4 address bytes. The opcode itself might
+	 * be a 3B addressing opcode but we don't care, because
+	 * SPI controller implementation should not check the opcode,
+	 * but just the sequence.
+	 */
+	op->addr.nbytes = 4;
+	if (!spi_mem_supports_op(nor->spimem, op)) {
+		/* If flash size <16MB, 3 address bytes are sufficient */
+		if (nor->mtd.size <= SZ_16M) {
+			op->addr.nbytes = 3;
+			if (!spi_mem_supports_op(nor->spimem, op))
+				return -ENOTSUPP;
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * spi_nor_spimem_check_readop - check if the read op is supported
+ *                               by controller
+ *@nor:         pointer to a 'struct spi_nor'
+ *@read:        pointer to op template to be checked
+ *
+ * Returns 0 if operation is supported, -ENOTSUPP otherwise.
+ */
+static int spi_nor_spimem_check_readop(struct spi_nor *nor,
+				       const struct spi_nor_read_command *read)
+{
+	struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(read->opcode, 1),
+					  SPI_MEM_OP_ADDR(3, 0, 1),
+					  SPI_MEM_OP_DUMMY(0, 1),
+					  SPI_MEM_OP_DATA_IN(0, NULL, 1));
+
+	op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(read->proto);
+	op.addr.buswidth = spi_nor_get_protocol_addr_nbits(read->proto);
+	op.data.buswidth = spi_nor_get_protocol_data_nbits(read->proto);
+	op.dummy.buswidth = op.addr.buswidth;
+	op.dummy.nbytes = (read->num_mode_clocks + read->num_wait_states) *
+			  op.dummy.buswidth / 8;
+
+	return spi_nor_spimem_check_op(nor, &op);
+}
+
+/**
+ * spi_nor_spimem_check_pp - check if the page program op is supported
+ *                           by controller
+ *@nor:         pointer to a 'struct spi_nor'
+ *@pp:          pointer to op template to be checked
+ *
+ * Returns 0 if operation is supported, -ENOTSUPP otherwise.
+ */
+static int spi_nor_spimem_check_pp(struct spi_nor *nor,
+				   const struct spi_nor_pp_command *pp)
+{
+	struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(pp->opcode, 1),
+					  SPI_MEM_OP_ADDR(3, 0, 1),
+					  SPI_MEM_OP_NO_DUMMY,
+					  SPI_MEM_OP_DATA_OUT(0, NULL, 1));
+
+	op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(pp->proto);
+	op.addr.buswidth = spi_nor_get_protocol_addr_nbits(pp->proto);
+	op.data.buswidth = spi_nor_get_protocol_data_nbits(pp->proto);
+
+	return spi_nor_spimem_check_op(nor, &op);
+}
+
+/**
+ * spi_nor_spimem_adjust_hwcaps - Find optimal Read/Write protocol
+ *                                based on SPI controller capabilities
+ * @nor:        pointer to a 'struct spi_nor'
+ * @params:     pointer to the 'struct spi_nor_flash_parameter'
+ *              representing SPI NOR flash capabilities
+ * @hwcaps:     pointer to resulting capabilities after adjusting
+ *              according to controller and flash's capability
+ */
+static void
+spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor,
+			     const struct spi_nor_flash_parameter *params,
+			     u32 *hwcaps)
+{
+	unsigned int cap;
+
+	/* DTR modes are not supported yet, mask them all. */
+	*hwcaps &= ~SNOR_HWCAPS_DTR;
+
+	/* X-X-X modes are not supported yet, mask them all. */
+	*hwcaps &= ~SNOR_HWCAPS_X_X_X;
+
+	/* Start with read commands. */
+	for (cap = 0; cap < sizeof(*hwcaps) * BITS_PER_BYTE; cap++) {
+		int rdidx, ppidx;
+
+		if (!(*hwcaps & BIT(cap)))
+			continue;
+
+		rdidx = spi_nor_hwcaps_read2cmd(BIT(cap));
+		if (rdidx >= 0 &&
+		    spi_nor_spimem_check_readop(nor, &params->reads[rdidx]))
+			*hwcaps &= ~BIT(cap);
+
+		ppidx = spi_nor_hwcaps_pp2cmd(BIT(cap));
+		if (ppidx < 0)
+			continue;
+
+		if (spi_nor_spimem_check_pp(nor,
+					    &params->page_programs[ppidx]))
+			*hwcaps &= ~BIT(cap);
+	}
+}
+
 /**
  * spi_nor_read_sfdp_dma_unsafe() - read Serial Flash Discoverable Parameters.
  * @nor:	pointer to a 'struct spi_nor'
@@ -4437,16 +4560,25 @@ static int spi_nor_setup(struct spi_nor *nor,
 	 */
 	shared_mask = hwcaps->mask & params->hwcaps.mask;
 
-	/* SPI n-n-n protocols are not supported yet. */
-	ignored_mask = (SNOR_HWCAPS_READ_2_2_2 |
-			SNOR_HWCAPS_READ_4_4_4 |
-			SNOR_HWCAPS_READ_8_8_8 |
-			SNOR_HWCAPS_PP_4_4_4 |
-			SNOR_HWCAPS_PP_8_8_8);
-	if (shared_mask & ignored_mask) {
-		dev_dbg(nor->dev,
-			"SPI n-n-n protocols are not supported yet.\n");
-		shared_mask &= ~ignored_mask;
+	if (nor->spimem) {
+		/*
+		 * When called from spi_nor_probe(), all caps are set and we
+		 * need to discard some of them based on what the SPI
+		 * controller actually supports (using spi_mem_supports_op()).
+		 */
+		spi_nor_spimem_adjust_hwcaps(nor, params, &shared_mask);
+	} else {
+		/*
+		 * SPI n-n-n protocols are not supported when the SPI
+		 * controller directly implements the spi_nor interface.
+		 * Yet another reason to switch to spi-mem.
+		 */
+		ignored_mask = SNOR_HWCAPS_X_X_X;
+		if (shared_mask & ignored_mask) {
+			dev_dbg(nor->dev,
+				"SPI n-n-n protocols are not supported.\n");
+			shared_mask &= ~ignored_mask;
+		}
 	}
 
 	/* Select the (Fast) Read command. */
@@ -4775,11 +4907,11 @@ static int spi_nor_probe(struct spi_mem *spimem)
 	struct spi_device *spi = spimem->spi;
 	struct flash_platform_data *data = dev_get_platdata(&spi->dev);
 	struct spi_nor *nor;
-	struct spi_nor_hwcaps hwcaps = {
-		.mask = SNOR_HWCAPS_READ |
-			SNOR_HWCAPS_READ_FAST |
-			SNOR_HWCAPS_PP,
-	};
+	/*
+	 * Enable all caps by default. The core will mask them after
+	 * checking what's really supported using spi_mem_supports_op().
+	 */
+	const struct spi_nor_hwcaps hwcaps = { .mask = SNOR_HWCAPS_ALL };
 	char *flash_name;
 	int ret;
 
@@ -4806,27 +4938,6 @@ static int spi_nor_probe(struct spi_mem *spimem)
 
 	spi_mem_set_drvdata(spimem, nor);
 
-	if (spi->mode & SPI_RX_OCTAL) {
-		hwcaps.mask |= SNOR_HWCAPS_READ_1_1_8;
-
-		if (spi->mode & SPI_TX_OCTAL)
-			hwcaps.mask |= (SNOR_HWCAPS_READ_1_8_8 |
-					SNOR_HWCAPS_PP_1_1_8 |
-					SNOR_HWCAPS_PP_1_8_8);
-	} else if (spi->mode & SPI_RX_QUAD) {
-		hwcaps.mask |= SNOR_HWCAPS_READ_1_1_4;
-
-		if (spi->mode & SPI_TX_QUAD)
-			hwcaps.mask |= (SNOR_HWCAPS_READ_1_4_4 |
-					SNOR_HWCAPS_PP_1_1_4 |
-					SNOR_HWCAPS_PP_1_4_4);
-	} else if (spi->mode & SPI_RX_DUAL) {
-		hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2;
-
-		if (spi->mode & SPI_TX_DUAL)
-			hwcaps.mask |= SNOR_HWCAPS_READ_1_2_2;
-	}
-
 	if (data && data->name)
 		nor->mtd.name = data->name;
 
include/linux/mtd/spi-nor.h +14 -0
index e18c03f72ded..4521a38452d6 100644
@@ -526,6 +526,20 @@ struct spi_nor_hwcaps {
 #define SNOR_HWCAPS_PP_1_8_8	BIT(21)
 #define SNOR_HWCAPS_PP_8_8_8	BIT(22)
 
+#define SNOR_HWCAPS_X_X_X	(SNOR_HWCAPS_READ_2_2_2 |	\
+				 SNOR_HWCAPS_READ_4_4_4 |	\
+				 SNOR_HWCAPS_READ_8_8_8 |	\
+				 SNOR_HWCAPS_PP_4_4_4 |		\
+				 SNOR_HWCAPS_PP_8_8_8)
+
+#define SNOR_HWCAPS_DTR		(SNOR_HWCAPS_READ_1_1_1_DTR |	\
+				 SNOR_HWCAPS_READ_1_2_2_DTR |	\
+				 SNOR_HWCAPS_READ_1_4_4_DTR |	\
+				 SNOR_HWCAPS_READ_1_8_8_DTR)
+
+#define SNOR_HWCAPS_ALL		(SNOR_HWCAPS_READ_MASK |	\
+				 SNOR_HWCAPS_PP_MASK)
+
 /**
  * spi_nor_scan() - scan the SPI NOR
  * @nor:	the spi_nor structure
Signature · 1 line
2.22.0