Skip to contentSkip to conversation

mtd: spi-nor: core: Discard HW capabilities if no enable function

PATCH In review Jaime Liao 3 participants 12 messages Dec 19, 2023 – Dec 20, 2023

Subsystems (2)
lore
Share & tools
lore

Jaime Liao

author
#0 lore raw

PATCH v2 1/1 mtd: spi-nor: core: Discard HW capabilities if no enable function

From: JaimeLiao <[email protected]>

Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.

---
changes in v2
- Add SNOR_HWCAPS_8_8_8_DTR
- Restore the enable function judgement in spi_nor_set_octal_dtr()
- Restore the enable function judgement in spi_nor_quad_enable()

---
 drivers/mtd/spi-nor/core.c  | 7 +++++++
 include/linux/mtd/spi-nor.h | 6 ++++++
 2 files changed, 13 insertions(+)
drivers/mtd/spi-nor/core.c +7 -0
index 1c443fe568cf..14359101c6cf 100644
@@ -2621,6 +2621,13 @@ static int spi_nor_default_setup(struct spi_nor *nor,
 	 */
 	shared_mask = hwcaps->mask & params->hwcaps.mask;
 
+	/* Mask out Octal DTR if no enable function */
+	if (!params->set_octal_dtr)
+		shared_mask &= ~SNOR_HWCAPS_8_8_8_DTR;
+
+	if (!params->quad_enable)
+		shared_mask &= ~SNOR_HWCAPS_4_4_4;
+
 	if (nor->spimem) {
 		/*
 		 * When called from spi_nor_probe(), all caps are set and we
include/linux/mtd/spi-nor.h +6 -0
index cdcfe0fd2e7d..78a119192ee0 100644
@@ -266,6 +266,12 @@ struct spi_nor_hwcaps {
 #define SNOR_HWCAPS_PP_8_8_8		BIT(22)
 #define SNOR_HWCAPS_PP_8_8_8_DTR	BIT(23)
 
+#define SNOR_HWCAPS_4_4_4	(SNOR_HWCAPS_READ_4_4_4 |	\
+				 SNOR_HWCAPS_PP_4_4_4)
+
+#define SNOR_HWCAPS_8_8_8_DTR	(SNOR_HWCAPS_READ_8_8_8_DTR |	\
+				 SNOR_HWCAPS_PP_8_8_8_DTR)
+
 #define SNOR_HWCAPS_X_X_X	(SNOR_HWCAPS_READ_2_2_2 |	\
 				 SNOR_HWCAPS_READ_4_4_4 |	\
 				 SNOR_HWCAPS_READ_8_8_8 |	\
Signature · 6 lines
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author
#1 lore raw

PATCH v3 1/1 mtd: spi-nor: sfdp: Get the 1-1-8 and 1-8-8 protocol from SFDP

From: JaimeLiao <[email protected]>

BFPT 17th DWORD contains the information about 1-1-8 and 1-8-8, parse BFPT 17 DWORD instruction to determine whether flash support 1-1-8 and 1-8-8, and set its dummy cycles accordingly.

Protocols 1-1-8 and 1-8-8 support are not determined by a single bit, so that use 8 bits instruction to determine whether the protocol support or not.

Macronix spi-nor flash didn't support 1-8-8 read feature, this patch validated 1-1-8 feature only on Xilinx board zynq-picozed.

---
Changes in v3:
- Modify title of patch
- Parse 1-8-8 read as well
- Modify the typo descriptions in commit log

---
 drivers/mtd/spi-nor/sfdp.c | 29 +++++++++++++++++++++++++++++
 drivers/mtd/spi-nor/sfdp.h |  7 +++++++
 2 files changed, 36 insertions(+)
drivers/mtd/spi-nor/sfdp.c +29 -0
index b3b11dfed789..3f1eba83a7d8 100644
@@ -446,6 +446,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 	u32 dword;
 	u16 half;
 	u8 erase_mask;
+	u8 wait_states, mode_clocks, opcode;
 
 	/* JESD216 Basic Flash Parameter Table length is at least 9 DWORDs. */
 	if (bfpt_header->length < BFPT_DWORD_MAX_JESD216)
@@ -631,6 +632,32 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 	if (bfpt_header->length == BFPT_DWORD_MAX_JESD216B)
 		return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt);
 
+	/* Parse 1-1-8 read instruction */
+	opcode = FIELD_GET(BFPT_DWORD17_RD_1_1_8_CMD, bfpt.dwords[SFDP_DWORD(17)]);
+	if (opcode) {
+		mode_clocks = FIELD_GET(BFPT_DWORD17_RD_1_1_8_MODE_CLOCKS,
+					bfpt.dwords[SFDP_DWORD(17)]);
+		wait_states = FIELD_GET(BFPT_DWORD17_RD_1_1_8_WAIT_STATES,
+					bfpt.dwords[SFDP_DWORD(17)]);
+		nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_8;
+		spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_1_1_8],
+					  mode_clocks, wait_states, opcode,
+					  SNOR_PROTO_1_1_8);
+	}
+
+	/* Parse 1-8-8 read instruction */
+	opcode = FIELD_GET(BFPT_DWORD17_RD_1_8_8_CMD, bfpt.dwords[SFDP_DWORD(17)]);
+	if (opcode) {
+		mode_clocks = FIELD_GET(BFPT_DWORD17_RD_1_8_8_MODE_CLOCKS,
+					bfpt.dwords[SFDP_DWORD(17)]);
+		wait_states = FIELD_GET(BFPT_DWORD17_RD_1_8_8_WAIT_STATES,
+					bfpt.dwords[SFDP_DWORD(17)]);
+		nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_1_8_8;
+		spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_1_8_8],
+					  mode_clocks, wait_states, opcode,
+					  SNOR_PROTO_1_8_8);
+	}
+
 	/* 8D-8D-8D command extension. */
 	switch (bfpt.dwords[SFDP_DWORD(18)] & BFPT_DWORD18_CMD_EXT_MASK) {
 	case BFPT_DWORD18_CMD_EXT_REP:
@@ -968,6 +995,8 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,
 		{ SNOR_HWCAPS_READ_1_1_1_DTR,	BIT(13) },
 		{ SNOR_HWCAPS_READ_1_2_2_DTR,	BIT(14) },
 		{ SNOR_HWCAPS_READ_1_4_4_DTR,	BIT(15) },
+		{ SNOR_HWCAPS_READ_1_1_8,	BIT(20) },
+		{ SNOR_HWCAPS_READ_1_8_8,	BIT(21) },
 	};
 	static const struct sfdp_4bait programs[] = {
 		{ SNOR_HWCAPS_PP,		BIT(6) },
drivers/mtd/spi-nor/sfdp.h +7 -0
index 6eb99e1cdd61..da0fe5aa9bb0 100644
@@ -118,6 +118,13 @@ struct sfdp_bfpt {
 	(BFPT_DWORD16_EN4B_EN4B | BFPT_DWORD16_EX4B_EX4B)
 #define BFPT_DWORD16_SWRST_EN_RST		BIT(12)
 
+#define BFPT_DWORD17_RD_1_1_8_CMD		GENMASK(31, 24)
+#define BFPT_DWORD17_RD_1_1_8_MODE_CLOCKS	GENMASK(23, 21)
+#define BFPT_DWORD17_RD_1_1_8_WAIT_STATES	GENMASK(20, 16)
+#define BFPT_DWORD17_RD_1_8_8_CMD		GENMASK(15, 8)
+#define BFPT_DWORD17_RD_1_8_8_MODE_CLOCKS	GENMASK(7, 5)
+#define BFPT_DWORD17_RD_1_8_8_WAIT_STATES	GENMASK(4, 0)
+
 #define BFPT_DWORD18_CMD_EXT_MASK		GENMASK(30, 29)
 #define BFPT_DWORD18_CMD_EXT_REP		(0x0UL << 29) /* Repeat */
 #define BFPT_DWORD18_CMD_EXT_INV		(0x1UL << 29) /* Invert */
Signature · 6 lines
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#2 lore raw

Re: [PATCH v3] mtd: spi-nor: sfdp: Get the 1-1-8 and 1-8-8 protocol from SFDP

Hi,

For the future, please send separate patches as separate mails, not in one thread. This will break b4 and probably patchwork.

Quoted 11 lines

From: JaimeLiao <[email protected]>

BFPT 17th DWORD contains the information about 1-1-8 and 1-8-8, parse BFPT 17 DWORD instruction to determine whether flash support 1-1-8 and 1-8-8, and set its dummy cycles accordingly.

Protocols 1-1-8 and 1-8-8 support are not determined by a single bit, so that use 8 bits instruction to determine whether the protocol support or not.

Quoted 6 lines

Macronix spi-nor flash didn't support 1-8-8 read feature, this patch validated 1-1-8 feature only on Xilinx board zynq-picozed.

Also for the future, if you do significant changes or adding further features, you should drop the Rb tag.

Anyway, this looks good, so my Rb tag is ok.

-michael

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

#3 lore raw

Re: [PATCH v3] mtd: spi-nor: sfdp: Get the 1-1-8 and 1-8-8 protocol from SFDP

In reply to Jaime Liao
Quoted 58 lines · Jaime Liao

From: JaimeLiao <[email protected]>

BFPT 17th DWORD contains the information about 1-1-8 and 1-8-8, parse BFPT 17 DWORD instruction to determine whether flash support 1-1-8 and 1-8-8, and set its dummy cycles accordingly.

Protocols 1-1-8 and 1-8-8 support are not determined by a single bit, so that use 8 bits instruction to determine whether the protocol support or not.

Macronix spi-nor flash didn't support 1-8-8 read feature, this patch validated 1-1-8 feature only on Xilinx board zynq-picozed.

---
Changes in v3:
- Modify title of patch
- Parse 1-8-8 read as well
- Modify the typo descriptions in commit log

---
 drivers/mtd/spi-nor/sfdp.c | 29 +++++++++++++++++++++++++++++
 drivers/mtd/spi-nor/sfdp.h |  7 +++++++
 2 files changed, 36 insertions(+)
drivers/mtd/spi-nor/sfdp.c +16 -0
index b3b11dfed789..3f1eba83a7d8 100644
@@ -446,6 +446,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 	u32 dword;
 	u16 half;
 	u8 erase_mask;
+	u8 wait_states, mode_clocks, opcode;
 
 	/* JESD216 Basic Flash Parameter Table length is at least 9 DWORDs. */
 	if (bfpt_header->length < BFPT_DWORD_MAX_JESD216)
@@ -631,6 +632,32 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 	if (bfpt_header->length == BFPT_DWORD_MAX_JESD216B)
 		return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt);
 
+	/* Parse 1-1-8 read instruction */
+	opcode = FIELD_GET(BFPT_DWORD17_RD_1_1_8_CMD, bfpt.dwords[SFDP_DWORD(17)]);
+	if (opcode) {
+		mode_clocks = FIELD_GET(BFPT_DWORD17_RD_1_1_8_MODE_CLOCKS,
+					bfpt.dwords[SFDP_DWORD(17)]);
+		wait_states = FIELD_GET(BFPT_DWORD17_RD_1_1_8_WAIT_STATES,
+					bfpt.dwords[SFDP_DWORD(17)]);
+		nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_8;
+		spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_1_1_8],
+					  mode_clocks, wait_states, opcode,
+					  SNOR_PROTO_1_1_8);
+	}
+
+	/* Parse 1-8-8 read instruction */
+	opcode = FIELD_GET(BFPT_DWORD17_RD_1_8_8_CMD, bfpt.dwords[SFDP_DWORD(17)]);

drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_bfpt(struct spi_nor *nor, · line 659

Quoted 10 lines
drivers/mtd/spi-nor/sfdp.c +10 -0
+	if (opcode) {
+		mode_clocks = FIELD_GET(BFPT_DWORD17_RD_1_8_8_MODE_CLOCKS,
+					bfpt.dwords[SFDP_DWORD(17)]);
+		wait_states = FIELD_GET(BFPT_DWORD17_RD_1_8_8_WAIT_STATES,
+					bfpt.dwords[SFDP_DWORD(17)]);
+		nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_1_8_8;
+		spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_1_8_8],
+					  mode_clocks, wait_states, opcode,
+					  SNOR_PROTO_1_8_8);
+	}

you can use params directly instead of nor->params. And it could have been written in a generic way, considering the other read settings parsed from SFDP. I'll get rid of the extra dereference and queue it, you can address how settings are parsed later on if you care. Or I'll do it myself if I won't be able to bear it.

Quoted 21 lines
drivers/mtd/spi-nor/sfdp.c +3 -0
+
 	/* 8D-8D-8D command extension. */
 	switch (bfpt.dwords[SFDP_DWORD(18)] & BFPT_DWORD18_CMD_EXT_MASK) {
 	case BFPT_DWORD18_CMD_EXT_REP:
@@ -968,6 +995,8 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,
 		{ SNOR_HWCAPS_READ_1_1_1_DTR,	BIT(13) },
 		{ SNOR_HWCAPS_READ_1_2_2_DTR,	BIT(14) },
 		{ SNOR_HWCAPS_READ_1_4_4_DTR,	BIT(15) },
+		{ SNOR_HWCAPS_READ_1_1_8,	BIT(20) },
+		{ SNOR_HWCAPS_READ_1_8_8,	BIT(21) },
 	};
 	static const struct sfdp_4bait programs[] = {
 		{ SNOR_HWCAPS_PP,		BIT(6) },
drivers/mtd/spi-nor/sfdp.h +0 -0
index 6eb99e1cdd61..da0fe5aa9bb0 100644
@@ -118,6 +118,13 @@ struct sfdp_bfpt {
 	(BFPT_DWORD16_EN4B_EN4B | BFPT_DWORD16_EX4B_EX4B)
 #define BFPT_DWORD16_SWRST_EN_RST		BIT(12)
 

drivers/mtd/spi-nor/sfdp.h struct sfdp_bfpt { · line 130

Quoted 10 lines
drivers/mtd/spi-nor/sfdp.h +7 -0
+#define BFPT_DWORD17_RD_1_1_8_CMD		GENMASK(31, 24)
+#define BFPT_DWORD17_RD_1_1_8_MODE_CLOCKS	GENMASK(23, 21)
+#define BFPT_DWORD17_RD_1_1_8_WAIT_STATES	GENMASK(20, 16)
+#define BFPT_DWORD17_RD_1_8_8_CMD		GENMASK(15, 8)
+#define BFPT_DWORD17_RD_1_8_8_MODE_CLOCKS	GENMASK(7, 5)
+#define BFPT_DWORD17_RD_1_8_8_WAIT_STATES	GENMASK(4, 0)
+
 #define BFPT_DWORD18_CMD_EXT_MASK		GENMASK(30, 29)
 #define BFPT_DWORD18_CMD_EXT_REP		(0x0UL << 29) /* Repeat */
 #define BFPT_DWORD18_CMD_EXT_INV		(0x1UL << 29) /* Invert */

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

#4 lore raw

Re (subset): [PATCH v3] mtd: spi-nor: sfdp: Get the 1-1-8 and 1-8-8 protocol from SFDP

In reply to Jaime Liao
Quoted 10 lines · Jaime Liao

BFPT 17th DWORD contains the information about 1-1-8 and 1-8-8, parse BFPT 17 DWORD instruction to determine whether flash support 1-1-8 and 1-8-8, and set its dummy cycles accordingly.

Protocols 1-1-8 and 1-8-8 support are not determined by a single bit, so that use 8 bits instruction to determine whether the protocol support or not.

[...]

Made some changes, see commit mesage.
Applied to git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git,
spi-nor/next branch. Thanks!

[1/1] mtd: spi-nor: sfdp: Get the 1-1-8 and 1-8-8 protocol from SFDP

      https://git.kernel.org/mtd/c/af2792abd455

Cheers,

Signature · 5 lines
Tudor Ambarus <[email protected]>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer Reviewed-by on v2 1/1
#5 lore raw
In reply to Jaime Liao

Am 2023-12-19 11:21, schrieb Jaime Liao:

Quoted 6 lines

From: JaimeLiao <[email protected]>

Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.

-michael

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

#6 lore raw
In reply to Jaime Liao
Quoted 39 lines · Jaime Liao

From: JaimeLiao <[email protected]>

Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.

---
changes in v2
- Add SNOR_HWCAPS_8_8_8_DTR
- Restore the enable function judgement in spi_nor_set_octal_dtr()
- Restore the enable function judgement in spi_nor_quad_enable()

---
 drivers/mtd/spi-nor/core.c  | 7 +++++++
 include/linux/mtd/spi-nor.h | 6 ++++++
 2 files changed, 13 insertions(+)
drivers/mtd/spi-nor/core.c +7 -0
index 1c443fe568cf..14359101c6cf 100644
@@ -2621,6 +2621,13 @@ static int spi_nor_default_setup(struct spi_nor *nor,
 	 */
 	shared_mask = hwcaps->mask & params->hwcaps.mask;
 
+	/* Mask out Octal DTR if no enable function */
+	if (!params->set_octal_dtr)
+		shared_mask &= ~SNOR_HWCAPS_8_8_8_DTR;
+
+	if (!params->quad_enable)
+		shared_mask &= ~SNOR_HWCAPS_4_4_4;
+
 	if (nor->spimem) {
 		/*
 		 * When called from spi_nor_probe(), all caps are set and we
include/linux/mtd/spi-nor.h +0 -0
index cdcfe0fd2e7d..78a119192ee0 100644

include/linux/mtd/spi-nor.h struct spi_nor_hwcaps { · line 270

Quoted 5 lines
include/linux/mtd/spi-nor.h +2 -0
@@ -266,6 +266,12 @@ struct spi_nor_hwcaps {
 #define SNOR_HWCAPS_PP_8_8_8		BIT(22)
 #define SNOR_HWCAPS_PP_8_8_8_DTR	BIT(23)
 
+#define SNOR_HWCAPS_4_4_4	(SNOR_HWCAPS_READ_4_4_4 |	\
+				 SNOR_HWCAPS_PP_4_4_4)

quad enable applies for 1-1-4 and 1-4-4 as well. How about changing this to:

#define SNOR_HWCAPS_QUAD (SNOR_HWCAPS_READ_QUAD | \
SNOR_HWCAPS_PP_QUAD)

include/linux/mtd/spi-nor.h struct spi_nor_hwcaps { · line 277

Quoted 7 lines
include/linux/mtd/spi-nor.h +4 -0
+
+#define SNOR_HWCAPS_8_8_8_DTR	(SNOR_HWCAPS_READ_8_8_8_DTR |	\
+				 SNOR_HWCAPS_PP_8_8_8_DTR)
+
 #define SNOR_HWCAPS_X_X_X	(SNOR_HWCAPS_READ_2_2_2 |	\
 				 SNOR_HWCAPS_READ_4_4_4 |	\
 				 SNOR_HWCAPS_READ_8_8_8 |	\

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

maintainer
#7 lore raw

Am 2023-12-20 09:07, schrieb Tudor Ambarus:

Quoted 44 lines · Jaime Liao
Quoted 43 lines

From: JaimeLiao <[email protected]>

Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.

---
changes in v2
- Add SNOR_HWCAPS_8_8_8_DTR
- Restore the enable function judgement in spi_nor_set_octal_dtr()
- Restore the enable function judgement in spi_nor_quad_enable()

---
 drivers/mtd/spi-nor/core.c  | 7 +++++++
 include/linux/mtd/spi-nor.h | 6 ++++++
 2 files changed, 13 insertions(+)
drivers/mtd/spi-nor/core.c +7 -0
index 1c443fe568cf..14359101c6cf 100644
@@ -2621,6 +2621,13 @@ static int spi_nor_default_setup(struct spi_nor 
 *nor,
 	 */
 	shared_mask = hwcaps->mask & params->hwcaps.mask;
 
+	/* Mask out Octal DTR if no enable function */
+	if (!params->set_octal_dtr)
+		shared_mask &= ~SNOR_HWCAPS_8_8_8_DTR;
+
+	if (!params->quad_enable)
+		shared_mask &= ~SNOR_HWCAPS_4_4_4;
+
 	if (nor->spimem) {
 		/*
drivers/mtd/spi-nor/core.c +0 -0
 		 * When called from spi_nor_probe(), all caps are set and we
include/linux/mtd/spi-nor.h +0 -0
index cdcfe0fd2e7d..78a119192ee0 100644
@@ -266,6 +266,12 @@ struct spi_nor_hwcaps {
 #define SNOR_HWCAPS_PP_8_8_8		BIT(22)
 #define SNOR_HWCAPS_PP_8_8_8_DTR	BIT(23)
 
Quoted 4 lines

include/linux/mtd/spi-nor.h struct spi_nor_hwcaps { · line 270

Quoted 2 lines
include/linux/mtd/spi-nor.h +2 -0
+#define SNOR_HWCAPS_4_4_4	(SNOR_HWCAPS_READ_4_4_4 |	\
+				 SNOR_HWCAPS_PP_4_4_4)

quad enable applies for 1-1-4 and 1-4-4 as well. How about changing this to:

Of course. You are right. I'm not even sure 4_4_4 falls into the category for our quad_enable, because there's a special mode, sometimes called qpi, for opcodes transferred in quad mode.

-michael

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

#8 lore raw
In reply to Jaime Liao
Quoted 21 lines · Jaime Liao

From: JaimeLiao <[email protected]>

Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.

---
changes in v2
- Add SNOR_HWCAPS_8_8_8_DTR
- Restore the enable function judgement in spi_nor_set_octal_dtr()
- Restore the enable function judgement in spi_nor_quad_enable()

---
 drivers/mtd/spi-nor/core.c  | 7 +++++++
 include/linux/mtd/spi-nor.h | 6 ++++++
 2 files changed, 13 insertions(+)
drivers/mtd/spi-nor/core.c +0 -0
index 1c443fe568cf..14359101c6cf 100644

drivers/mtd/spi-nor/core.c static int spi_nor_default_setup(struct spi_nor *nor, · line 2629

Quoted 9 lines
drivers/mtd/spi-nor/core.c +6 -0
@@ -2621,6 +2621,13 @@ static int spi_nor_default_setup(struct spi_nor *nor,
 	 */
 	shared_mask = hwcaps->mask & params->hwcaps.mask;
 
+	/* Mask out Octal DTR if no enable function */
+	if (!params->set_octal_dtr)
+		shared_mask &= ~SNOR_HWCAPS_8_8_8_DTR;
+
+	if (!params->quad_enable)
+		shared_mask &= ~SNOR_HWCAPS_4_4_4;

and these should have been in the late init hook, and instead discard them from the params->hwcaps.mask.

And why is this extra check needed in the first place? For octal I assume it's needed by macronix, where the flash is octal capable, but there's no octal enable method defined yet. What about the quad mode? Is there any flash that has no quad enable method defined but still caries quad mode in its hwcaps?

Quoted 11 lines
drivers/mtd/spi-nor/core.c +1 -0
+
 	if (nor->spimem) {
 		/*
 		 * When called from spi_nor_probe(), all caps are set and we
include/linux/mtd/spi-nor.h +0 -0
index cdcfe0fd2e7d..78a119192ee0 100644
@@ -266,6 +266,12 @@ struct spi_nor_hwcaps {
 #define SNOR_HWCAPS_PP_8_8_8		BIT(22)
 #define SNOR_HWCAPS_PP_8_8_8_DTR	BIT(23)

include/linux/mtd/spi-nor.h struct spi_nor_hwcaps { · line 277

Quoted 10 lines
include/linux/mtd/spi-nor.h +6 -0
 
+#define SNOR_HWCAPS_4_4_4	(SNOR_HWCAPS_READ_4_4_4 |	\
+				 SNOR_HWCAPS_PP_4_4_4)
+
+#define SNOR_HWCAPS_8_8_8_DTR	(SNOR_HWCAPS_READ_8_8_8_DTR |	\
+				 SNOR_HWCAPS_PP_8_8_8_DTR)
+
 #define SNOR_HWCAPS_X_X_X	(SNOR_HWCAPS_READ_2_2_2 |	\
 				 SNOR_HWCAPS_READ_4_4_4 |	\
 				 SNOR_HWCAPS_READ_8_8_8 |	\

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

maintainer
#9 lore raw

Am 2023-12-20 09:20, schrieb Tudor Ambarus:

Quoted 26 lines · Jaime Liao
Quoted 25 lines

From: JaimeLiao <[email protected]>

Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.

---
changes in v2
- Add SNOR_HWCAPS_8_8_8_DTR
- Restore the enable function judgement in spi_nor_set_octal_dtr()
- Restore the enable function judgement in spi_nor_quad_enable()

---
 drivers/mtd/spi-nor/core.c  | 7 +++++++
 include/linux/mtd/spi-nor.h | 6 ++++++
 2 files changed, 13 insertions(+)
drivers/mtd/spi-nor/core.c +0 -0
index 1c443fe568cf..14359101c6cf 100644
@@ -2621,6 +2621,13 @@ static int spi_nor_default_setup(struct spi_nor 
 *nor,
 	 */
 	shared_mask = hwcaps->mask & params->hwcaps.mask;
 
Quoted 9 lines

drivers/mtd/spi-nor/core.c static int spi_nor_default_setup(struct spi_nor *nor, · line 2629

Quoted 6 lines
drivers/mtd/spi-nor/core.c +6 -0
+	/* Mask out Octal DTR if no enable function */
+	if (!params->set_octal_dtr)
+		shared_mask &= ~SNOR_HWCAPS_8_8_8_DTR;
+
+	if (!params->quad_enable)
+		shared_mask &= ~SNOR_HWCAPS_4_4_4;

and these should have been in the late init hook, and instead discard them from the params->hwcaps.mask.

Maybe there is a better place to mask these bits. But IMHO the core should do it on itself and we shouldn't need to provide an extra hook function for every driver ourselves. The core knows that there is no .octal_enable op and thus it shouldn't even try to enable this mode.

Quoted 3 lines

And why is this extra check needed in the first place? For octal I assume it's needed by macronix, where the flash is octal capable, but there's no octal enable method defined yet.

Because it is the generic spi nor flash driver, which doesn't provide any of these enable x-mode helpers.

Quoted 3 lines

What about the quad mode? Is
there any flash that has no quad enable method defined but still caries quad mode in its hwcaps?

No it is for completeness and correctness. At the moment we are always setting a (random) default quad enable op, due to legacy reasons.

-michael

Quoted 12 lines
Quoted 12 lines
drivers/mtd/spi-nor/core.c +1 -0
+
 	if (nor->spimem) {
 		/*
drivers/mtd/spi-nor/core.c +0 -0
 		 * When called from spi_nor_probe(), all caps are set and we
include/linux/mtd/spi-nor.h +0 -0
index cdcfe0fd2e7d..78a119192ee0 100644
@@ -266,6 +266,12 @@ struct spi_nor_hwcaps {
 #define SNOR_HWCAPS_PP_8_8_8		BIT(22)
 #define SNOR_HWCAPS_PP_8_8_8_DTR	BIT(23)
 
Quoted 9 lines

include/linux/mtd/spi-nor.h struct spi_nor_hwcaps { · line 277

Quoted 9 lines
include/linux/mtd/spi-nor.h +6 -0
+#define SNOR_HWCAPS_4_4_4	(SNOR_HWCAPS_READ_4_4_4 |	\
+				 SNOR_HWCAPS_PP_4_4_4)
+
+#define SNOR_HWCAPS_8_8_8_DTR	(SNOR_HWCAPS_READ_8_8_8_DTR |	\
+				 SNOR_HWCAPS_PP_8_8_8_DTR)
+
 #define SNOR_HWCAPS_X_X_X	(SNOR_HWCAPS_READ_2_2_2 |	\
 				 SNOR_HWCAPS_READ_4_4_4 |	\
 				 SNOR_HWCAPS_READ_8_8_8 |	\

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

#10 lore raw
Quoted 37 lines · Michael Walle

Am 2023-12-20 09:20, schrieb Tudor Ambarus:

Quoted 26 lines · Jaime Liao
Quoted 25 lines

From: JaimeLiao <[email protected]>

Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.

---
changes in v2
 - Add SNOR_HWCAPS_8_8_8_DTR
 - Restore the enable function judgement in spi_nor_set_octal_dtr()
 - Restore the enable function judgement in spi_nor_quad_enable()
---
 drivers/mtd/spi-nor/core.c  | 7 +++++++ include/linux/mtd/spi-nor.h | 6 ++++++

 2 files changed, 13 insertions(+)
drivers/mtd/spi-nor/core.c +0 -0
index 1c443fe568cf..14359101c6cf 100644
@@ -2621,6 +2621,13 @@ static int spi_nor_default_setup(struct
 spi_nor *nor,
       */
      shared_mask = hwcaps->mask & params->hwcaps.mask;
 
Quoted 9 lines

drivers/mtd/spi-nor/core.c static int spi_nor_default_setup(struct spi_nor *nor, · line 2629

Quoted 6 lines
drivers/mtd/spi-nor/core.c +6 -0
+    /* Mask out Octal DTR if no enable function */
+    if (!params->set_octal_dtr)
+        shared_mask &= ~SNOR_HWCAPS_8_8_8_DTR;
+
+    if (!params->quad_enable)
+        shared_mask &= ~SNOR_HWCAPS_4_4_4;

and these should have been in the late init hook, and instead discard them from the params->hwcaps.mask.

Quoted 5 lines

Maybe there is a better place to mask these bits. But IMHO the core should do it on itself and we shouldn't need to provide an extra hook function for every driver ourselves. The core knows that there is no .octal_enable op and thus it shouldn't even try to enable this mode.

I meant in the core, at the end of the late_init_params(). Here:
https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/tree/drivers/mtd/spi-nor/core.c?h=spi-nor/next#n2962

Quoted 7 lines
Quoted 4 lines

And why is this extra check needed in the first place? For octal I assume it's needed by macronix, where the flash is octal capable, but there's no octal enable method defined yet.

Because it is the generic spi nor flash driver, which doesn't provide any of these enable x-mode helpers.

right, that was my guess too. The commit message has to be updated.

Quoted 8 lines
Quoted 4 lines

What about the quad mode? Is
there any flash that has no quad enable method defined but still caries quad mode in its hwcaps?

No it is for completeness and correctness. At the moment we are always setting a (random) default quad enable op, due to legacy reasons.

Still, the commit message shall indicate this. Can't add extra checks out of the blue. Especially since nobody is affected.

Cheers,
ta

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

maintainer
#11 lore raw

Hi,

Quoted 11 lines
Quoted 8 lines
Quoted 2 lines

and these should have been in the late init hook, and instead discard them from the params->hwcaps.mask.

Maybe there is a better place to mask these bits. But IMHO the core should do it on itself and we shouldn't need to provide an extra hook function for every driver ourselves. The core knows that there is no .octal_enable op and thus it shouldn't even try to enable this mode.

I meant in the core, at the end of the late_init_params(). Here:
https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/tree/drivers/mtd/spi-nor/core.c?h=spi-nor/next#n2962

Sounds good.

Quoted 6 lines
Quoted 3 lines

No it is for completeness and correctness. At the moment we are always setting a (random) default quad enable op, due to legacy reasons.

Still, the commit message shall indicate this. Can't add extra checks out of the blue. Especially since nobody is affected.

Ok :)

-michael

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