Introduce generic ONFI support
Subsystems (2)
cover Introduce generic ONFI support
From: Shivamurthy Shastri <[email protected]>
Current support to ONFI parameter page is only for raw NAND, this patch series turn ONFI support into generic. So that, other NAND devices like SPI NAND can use this.
The series has five parts.
1. Prepare for tunrning ONFI into generic
2. Turn ONFI into generic
3. Turn SPI NAND core to use parameter page
4. Redesign Micron SPI NAND driver implementation
5. Support for new Micron SPI NAND devices
Changes in V4
-------------
* Turn ONFI support into generic.
Re-designed as per the Boris's comment. Common functions are moved to nand/onfi.c. Function to prase ONFI table is defined in nand/onfi.c
* Enable parameter page support in SPI NAND core. Re-designed as per changes in ONFI generic support. Function defined to read parameter page. Function defined to detect parameter page.
Changes in V3
-------------
* Split the patches as per suggestion
* Addressed the comments
* Some fixes which I missed in last version
Shivamurthy Shastri (8):
mtd: nand: move ONFI related functions to onfi.h
mtd: nand: move support functions for ONFI to nand/onfi.c
mtd: nand: create ONFI table parsing instance
mtd: spinand: enabled parameter page support
mtd: spinand: micron: prepare for generalizing driver
mtd: spinand: micron: Turn driver implementation generic
mtd: spinand: micron: Fix read failure in Micron M70A flashes
mtd: spinand: micron: Enable micron flashes with multi-die
drivers/mtd/nand/Makefile | 2 +- drivers/mtd/nand/onfi.c | 121 +++++++++++++++++++++++++++ drivers/mtd/nand/raw/internals.h | 1 - drivers/mtd/nand/raw/nand_base.c | 18 ---- drivers/mtd/nand/raw/nand_onfi.c | 65 +-------------- drivers/mtd/nand/spi/core.c | 136 ++++++++++++++++++++++++++++++- drivers/mtd/nand/spi/micron.c | 107 +++++++++++++++++------- include/linux/mtd/onfi.h | 11 +++ include/linux/mtd/spinand.h | 7 ++ 9 files changed, 356 insertions(+), 112 deletions(-) create mode 100644 drivers/mtd/nand/onfi.c
Signature · 1 line
2.17.1
PATCH 1/8 mtd: nand: move ONFI related functions to onfi.h
From: Shivamurthy Shastri <[email protected]>
These functions will be used by both raw NAND and SPI NAND, which supports ONFI like standards.
--- drivers/mtd/nand/raw/internals.h | 1 - include/linux/mtd/onfi.h | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/internals.h +0 -1
@@ -140,7 +140,6 @@ void nand_legacy_adjust_cmdfunc(struct nand_chip *chip);int nand_legacy_check_hooks (struct nand_chip *chip);/* ONFI functions */ -u16 onfi_crc16 (u16 crc,u8 const *p,size_t len);int nand_onfi_detect (struct nand_chip *chip);/* JEDEC functions */
include/linux/mtd/onfi.h +9 -0
@@ -10,6 +10,7 @@#ifndef __LINUX_MTD_ONFI_H#define __LINUX_MTD_ONFI_H +#include <linux/mtd/nand.h> #include <linux/types.h> /* ONFI version bits */
@@ -175,4 +176,12 @@ struct onfi_params { u8 vendor[88]; }; +/* ONFI functions */ +u16 onfi_crc16 (u16 crc,u8 const *p,size_t len); +void nand_bit_wise_majority (const void **srcbufs, +unsigned int nsrcbufs, +void *dstbuf, +unsigned int bufsize); +void sanitize_string (u8 *s,size_t len); +#endif /* __LINUX_MTD_ONFI_H */
Signature · 1 line
2.17.1
Miquel Raynal
maintainerRe: [PATCH 1/8] mtd: nand: move ONFI related functions to onfi.h
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:14 +0200:
Quoted 4 lines
From: Shivamurthy Shastri <[email protected]>
These functions will be used by both raw NAND and SPI NAND, which supports ONFI like standards.
This is not exactly what you do. Why not:
mtd: nand: export ONFI related functions to onfi.h
These functions can be used by all flavors of NAND chips (raw, SPI) which may all follow ONFI standards. Export the related functions in the onfi.h generic file.
Quoted 24 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/raw/internals.h | 1 - include/linux/mtd/onfi.h | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)drivers/mtd/nand/raw/internals.h +0
-1@@ -140,7 +140,6 @@ void nand_legacy_adjust_cmdfunc(struct nand_chip *chip);int nand_legacy_check_hooks (struct nand_chip *chip);/* ONFI functions */ -u16 onfi_crc16 (u16 crc,u8 const *p,size_t len);int nand_onfi_detect (struct nand_chip *chip);/* JEDEC functions */ include/linux/mtd/onfi.h +0
-0
include/linux/mtd/onfi.h line 13
Quoted 4 lines
include/linux/mtd/onfi.h +1
-0@@ -10,6 +10,7 @@#ifndef __LINUX_MTD_ONFI_H#define __LINUX_MTD_ONFI_H +#include <linux/mtd/nand.h>
This should be removed, or at least not added at this moment.
include/linux/mtd/onfi.h struct onfi_params { · line 184
Quoted 13 lines
include/linux/mtd/onfi.h +6
-0#include <linux/types.h> /* ONFI version bits */ @@ -175,4 +176,12 @@ struct onfi_params {u8 vendor[88 ]; }; +/* ONFI functions */ +u16 onfi_crc16 (u16 crc,u8 const *p,size_t len); +void nand_bit_wise_majority (const void **srcbufs, +unsigned int nsrcbufs, +void *dstbuf, +unsigned int bufsize);
Don't export this function while you don't use it from elsewhere.
include/linux/mtd/onfi.h struct onfi_params { · line 185
Quoted 1 line
include/linux/mtd/onfi.h +1
-0+void sanitize_string (u8 *s,size_t len);
This one is used by jedec code and has no onfi-related logic, so you may want to export it (only when you will use it) in another header like linux/mtd/nand.h
include/linux/mtd/onfi.h struct onfi_params { · line 187
Quoted 2 lines
include/linux/mtd/onfi.h +1
-0+#endif /* __LINUX_MTD_ONFI_H */
Thanks,
Miquèl
RE: [EXT] Re: [PATCH 1/8] mtd: nand: move ONFI related functions to onfi.h
Hi Miquel,
Thanks for reviewing.
Quoted 10 lines
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:14 +0200:
Quoted 4 lines
From: Shivamurthy Shastri <[email protected]>
These functions will be used by both raw NAND and SPI NAND, which supports ONFI like standards.
Quoted 8 lines
This is not exactly what you do. Why not:
mtd: nand: export ONFI related functions to
onfi.hThese functions can be used by all flavors of NAND chips (raw, SPI) which may all follow ONFI standards. Export the related functions in the
onfi.hgeneric file.
Looks good. I will use this.
Quoted 29 lines
Review
Quoted 8 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/raw/internals.h | 1 - include/linux/mtd/onfi.h | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/mtd/nand/raw/internals.hdrivers/mtd/nand/raw/internals.h void nand_legacy_adjust_cmdfunc(struct
Quoted 4 lines
index
cba6fe7dd8c4..ed323087d884100644drivers/mtd/nand/raw/internals.h +0
-0@@ -140,7 +140,6 @@ void nand_legacy_adjust_cmdfunc(struct
nand_chip*chip);Quoted 15 lines
drivers/mtd/nand/raw/internals.h +0
-1int nand_legacy_check_hooks (struct nand_chip *chip);/* ONFI functions */ -u16 onfi_crc16 (u16 crc,u8 const *p,size_t len);int nand_onfi_detect (struct nand_chip *chip);/* JEDEC functions */ include/linux/mtd/onfi.h +0
-0@@ -10,6 +10,7 @@#ifndef __LINUX_MTD_ONFI_H#define __LINUX_MTD_ONFI_H
Quoted 4 lines
include/linux/mtd/onfi.h line 13
Quoted 1 line
include/linux/mtd/onfi.h +1
-0+#include <linux/mtd/nand.h> This should be removed, or at least not added at this moment.
okay.
Quoted 7 lines
Quoted 7 lines
include/linux/mtd/onfi.h +0
-0#include <linux/types.h> /* ONFI version bits */ @@ -175,4 +176,12 @@ struct onfi_params {u8 vendor[88 ]; };
Quoted 9 lines
include/linux/mtd/onfi.h struct onfi_params { · line 184
Quoted 6 lines
include/linux/mtd/onfi.h +6
-0+/* ONFI functions */ +u16 onfi_crc16 (u16 crc,u8 const *p,size_t len); +void nand_bit_wise_majority (const void **srcbufs, +unsigned int nsrcbufs, +void *dstbuf, +unsigned int bufsize);Don't export this function while you don't use it from elsewhere.
The function will be moved to nand/onfi.c in next patch and will be used by both raw and SPI NAND.
Quoted 5 lines
include/linux/mtd/onfi.h struct onfi_params { · line 185
Quoted 1 line
include/linux/mtd/onfi.h +1
-0+void sanitize_string (u8 *s,size_t len);This one is used by jedec code and has no onfi-related logic, so you may want to export it (only when you will use it) in another header like
linux/mtd/nand.h
okay, I will keep this as it is.
Quoted 6 lines
include/linux/mtd/onfi.h struct onfi_params { · line 187
Quoted 3 lines
include/linux/mtd/onfi.h +1
-0+#endif /* __LINUX_MTD_ONFI_H */ Thanks,
Miquèl
Thanks,
Shiva
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 2/8 mtd: nand: move support functions for ONFI to nand/onfi.c
In reply to [email protected]From: Shivamurthy Shastri <[email protected]>
These functions are support functions for enabling ONFI standard and common between raw NAND and SPI NAND.
--- drivers/mtd/nand/Makefile | 2 +- drivers/mtd/nand/onfi.c | 89 ++++++++++++++++++++++++++++++++ drivers/mtd/nand/raw/nand_base.c | 18 ------- drivers/mtd/nand/raw/nand_onfi.c | 43 --------------- 4 files changed, 90 insertions(+), 62 deletions(-) create mode 100644 drivers/mtd/nand/onfi.c
drivers/mtd/nand/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -nandcore-objs := core.o bbt.o +nandcore-objs := core.o bbt.o onfi.o obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o obj-y += onenand/
drivers/mtd/nand/onfi.c new file +89 -0
89 lines not on this page · raw message
drivers/mtd/nand/raw/nand_base.c +0 -18
@@ -4375,24 +4375,6 @@ static void nand_set_defaults(struct nand_chip *chip) chip->buf_align =1 ; } -/* Sanitize ONFI strings so we can safely print them */ -void sanitize_string (uint8_t *s,size_t len) -{ -ssize_t i; - -/* Null terminate */ - s[len -1 ] =0 ; - -/* Remove non printable chars */ -for (i =0 ; i < len -1 ; i++) { -if (s[i] <' ' || s[i] >127 ) - s[i] ='?' ; - } - -/* Remove trailing spaces */ -strim (s); -} -/* * nand_id_has_period - Check if an ID string has a given wraparound period * @id_data: the ID string
drivers/mtd/nand/raw/nand_onfi.c +0 -43
55 lines not on this page · raw message
Signature · 1 line
2.17.1
Miquel Raynal
maintainerRe: [PATCH 2/8] mtd: nand: move support functions for ONFI to nand/onfi.c
[email protected] wrote on Mon, 22 Jul 2019 07:56:15 +0200:
Quoted 1 line
From: Shivamurthy Shastri <[email protected]>
"mtd: nand: move ONFI specific helpers to nand/onfi.c"?
Quoted 3 lines
These functions are support functions for enabling ONFI standard and common between raw NAND and SPI NAND.
"
These are ONFI specific helpers that might be shared between raw and SPI NAND logics, move them to a generic place.
While at it, add kernel doc on the function parameters. "
Quoted 28 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/Makefile | 2 +- drivers/mtd/nand/onfi.c | 89 ++++++++++++++++++++++++++++++++ drivers/mtd/nand/raw/nand_base.c | 18 ------- drivers/mtd/nand/raw/nand_onfi.c | 43 --------------- 4 files changed, 90 insertions(+), 62 deletions(-) create mode 100644 drivers/mtd/nand/onfi.cdrivers/mtd/nand/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -nandcore-objs := core.o bbt.o +nandcore-objs := core.o bbt.o onfi.o obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o obj-y += onenand/drivers/mtd/nand/onfi.c new file +0
-0
drivers/mtd/nand/onfi.c line 9
Quoted 9 lines
drivers/mtd/nand/onfi.c new file +9
-0@@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define pr_fmt (fmt) "nand-onfi: " fmt + +#include <linux/mtd/onfi.h> +#include <linux/mtd/nand.h> + +/** +* onfi_crc16() - Check CRC of ONFI table
There is no check in this function.
Derive the CRC of an ONFI table
drivers/mtd/nand/onfi.c line 11
Quoted 2 lines
drivers/mtd/nand/onfi.c new file +2
-0+* @crc: base CRC +* @p: buffer pointing to ONFI table
^ the
drivers/mtd/nand/onfi.c line 12
Quoted 1 line
drivers/mtd/nand/onfi.c new file +1
-0+* @len: length of ONFI table
^the
drivers/mtd/nand/onfi.c line 14
Quoted 2 lines
drivers/mtd/nand/onfi.c new file +2
-0+* +* Return: CRC of the ONFI table
@return: the CRC of the given ONFI table
Quoted 9 lines
drivers/mtd/nand/onfi.c new file +9
-0+*/ +u16 onfi_crc16 (u16 crc,u8 const *p,size_t len) +{ +int i; + +while (len--) { + crc ^= *p++ <<8 ; +for (i =0 ; i <8 ; i++) + crc = (crc <<1 ) ^ ((crc &0x8000 ) ?0x8005 :0 );
drivers/mtd/nand/onfi.c line 33
Quoted 10 lines
drivers/mtd/nand/onfi.c new file +10
-0+ } + +return crc; +} +EXPORT_SYMBOL_GPL (onfi_crc16); + +/** +* nand_bit_wise_majority() - Recover data with bit-wise majority +* @srcbufs: buffer pointing to ONFI table +* @nsrcbufs: length of ONFI table
^the
drivers/mtd/nand/onfi.c line 35
Quoted 2 lines
drivers/mtd/nand/onfi.c new file +2
-0+* @dstbuf: valid ONFI table to be returned +* @bufsize: length og valid ONFI table
of the valid...
drivers/mtd/nand/onfi.c line 36
Quoted 1 line
drivers/mtd/nand/onfi.c new file +1
-0+*
Extra line
Quoted 22 lines
drivers/mtd/nand/onfi.c new file +22
-0+*/ +void nand_bit_wise_majority (const void **srcbufs, +unsigned int nsrcbufs, +void *dstbuf, +unsigned int bufsize) +{ +int i, j, k; + +for (i =0 ; i < bufsize; i++) { +u8 val =0 ; + +for (j =0 ; j <8 ; j++) { +unsigned int cnt =0 ; + +for (k =0 ; k < nsrcbufs; k++) { +const u8 *srcbuf = srcbufs[k]; + +if (srcbuf[i] &BIT (j)) + cnt++; + } + +if (cnt > nsrcbufs /2 )
drivers/mtd/nand/onfi.c line 68
Quoted 10 lines
drivers/mtd/nand/onfi.c new file +10
-0+ val |=BIT (j); + } + + ((u8 *)dstbuf)[i] = val; + } +} +EXPORT_SYMBOL_GPL (nand_bit_wise_majority); + +/** +* sanitize_string() - Sanitize ONFI strings so we can safely print them
It is used by JEDEC logic so this should be moved elsewhere and not refer to any ONFI naming.
Quoted 101 lines
drivers/mtd/nand/onfi.c new file +21
-0+* @s: string to be sanitized +* @len: length of the string +* +*/ +void sanitize_string (u8 *s,size_t len) +{ +ssize_t i; + +/* Null terminate */ + s[len -1 ] =0 ; + +/* Remove non printable chars */ +for (i =0 ; i < len -1 ; i++) { +if (s[i] <' ' || s[i] >127 ) + s[i] ='?' ; + } + +/* Remove trailing spaces */ +strim (s); +} +EXPORT_SYMBOL_GPL (sanitize_string);drivers/mtd/nand/raw/nand_base.c +0
-18@@ -4375,24 +4375,6 @@ static void nand_set_defaults(struct nand_chip *chip) chip->buf_align =1 ; } -/* Sanitize ONFI strings so we can safely print them */ -void sanitize_string (uint8_t *s,size_t len) -{ -ssize_t i; - -/* Null terminate */ - s[len -1 ] =0 ; - -/* Remove non printable chars */ -for (i =0 ; i < len -1 ; i++) { -if (s[i] <' ' || s[i] >127 ) - s[i] ='?' ; - } - -/* Remove trailing spaces */ -strim (s); -} -/* * nand_id_has_period - Check if an ID string has a given wraparound period * @id_data: the ID string drivers/mtd/nand/raw/nand_onfi.c +0
-36@@ -16,18 +16,6 @@#include "internals.h" -u16 onfi_crc16 (u16 crc,u8 const *p,size_t len) -{ -int i; -while (len--) { - crc ^= *p++ <<8 ; -for (i =0 ; i <8 ; i++) - crc = (crc <<1 ) ^ ((crc &0x8000 ) ?0x8005 :0 ); - } - -return crc; -} -/* Parse the Extended Parameter Page. */ static int nand_flash_detect_ext_param_page (struct nand_chip *chip,struct nand_onfi_params *p)@@ -103,37 +91,6 @@ static int nand_flash_detect_ext_param_page(struct nand_chip *chip,return ret; } -/* -* Recover data with bit-wise majority -*/ -static void nand_bit_wise_majority (const void **srcbufs, -unsigned int nsrcbufs, -void *dstbuf, -unsigned int bufsize) -{ -int i, j, k; - -for (i =0 ; i < bufsize; i++) { -u8 val =0 ; - -for (j =0 ; j <8 ; j++) { -unsigned int cnt =0 ; - -for (k =0 ; k < nsrcbufs; k++) { -const u8 *srcbuf = srcbufs[k]; - -if (srcbuf[i] &BIT (j)) - cnt++; - } - -if (cnt > nsrcbufs /2 )
drivers/mtd/nand/raw/nand_onfi.c static int nand_flash_detect_ext_param_page(struct nand_chip *chip, · line 96
Quoted 10 lines
drivers/mtd/nand/raw/nand_onfi.c +0
-7- val |=BIT (j); - } - - ((u8 *)dstbuf)[i] = val; - } -} -/* * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. */
Thanks,
Miquèl
RE: [EXT] Re: [PATCH 2/8] mtd: nand: move support functions for ONFI to nand/onfi.c
Hi Miquel,
Quoted 8 lines
[email protected] wrote on Mon, 22 Jul 2019 07:56:15 +0200:
Quoted 1 line
From: Shivamurthy Shastri <[email protected]>
"mtd: nand: move ONFI specific helpers to
nand/onfi.c"?
I will use this.
Quoted 5 lines
Quoted 4 lines
These functions are support functions for enabling ONFI standard and common between raw NAND and SPI NAND.
Quoted 7 lines
"
These are ONFI specific helpers that might be shared between raw and SPI NAND logics, move them to a generic place.While at it, add kernel doc on the function parameters. "
I will use this.
Quoted 41 lines
Quoted 5 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/Makefile | 2 +- drivers/mtd/nand/onfi.c | 89++++++++++++++++++++++++++++++++
Quoted 23 lines
drivers/mtd/nand/raw/nand_base.c | 18 ------- drivers/mtd/nand/raw/nand_onfi.c | 43 --------------- 4 files changed, 90 insertions(+), 62 deletions(-) create mode 100644 drivers/mtd/nand/onfi.cdrivers/mtd/nand/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -nandcore-objs := core.o bbt.o +nandcore-objs := core.o bbt.o onfi.o obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o obj-y += onenand/drivers/mtd/nand/onfi.c new file +0
-0drivers/mtd/nand/onfi.c line 9
Quoted 9 lines
drivers/mtd/nand/onfi.c new file +9
-0@@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define pr_fmt (fmt) "nand-onfi: " fmt + +#include <linux/mtd/onfi.h> +#include <linux/mtd/nand.h> + +/** +* onfi_crc16() - Check CRC of ONFI table There is no check in this function.
Quoted 1 line
Derive the CRC of an ONFI table
okay.
Quoted 64 lines
drivers/mtd/nand/onfi.c line 11
Quoted 3 lines
drivers/mtd/nand/onfi.c new file +2
-0+* @crc: base CRC +* @p: buffer pointing to ONFI table ^ the
drivers/mtd/nand/onfi.c line 12
Quoted 1 line
drivers/mtd/nand/onfi.c new file +1
-0+* @len: length of ONFI table ^the
drivers/mtd/nand/onfi.c line 14
Quoted 2 lines
drivers/mtd/nand/onfi.c new file +2
-0+* +* Return: CRC of the ONFI table @return: the CRC of the given ONFI table
Quoted 9 lines
drivers/mtd/nand/onfi.c new file +9
-0+*/ +u16 onfi_crc16 (u16 crc,u8 const *p,size_t len) +{ +int i; + +while (len--) { + crc ^= *p++ <<8 ; +for (i =0 ; i <8 ; i++) + crc = (crc <<1 ) ^ ((crc &0x8000 ) ?0x8005 :0 );drivers/mtd/nand/onfi.c line 33
Quoted 10 lines
drivers/mtd/nand/onfi.c new file +10
-0+ } + +return crc; +} +EXPORT_SYMBOL_GPL (onfi_crc16); + +/** +* nand_bit_wise_majority() - Recover data with bit-wise majority +* @srcbufs: buffer pointing to ONFI table +* @nsrcbufs: length of ONFI table ^the
drivers/mtd/nand/onfi.c line 35
Quoted 2 lines
drivers/mtd/nand/onfi.c new file +2
-0+* @dstbuf: valid ONFI table to be returned +* @bufsize: length og valid ONFI table of the valid...
drivers/mtd/nand/onfi.c line 36
Quoted 1 line
drivers/mtd/nand/onfi.c new file +1
-0+* Extra line
Quoted 27 lines
drivers/mtd/nand/onfi.c new file +27
-0+*/ +void nand_bit_wise_majority (const void **srcbufs, +unsigned int nsrcbufs, +void *dstbuf, +unsigned int bufsize) +{ +int i, j, k; + +for (i =0 ; i < bufsize; i++) { +u8 val =0 ; + +for (j =0 ; j <8 ; j++) { +unsigned int cnt =0 ; + +for (k =0 ; k < nsrcbufs; k++) { +const u8 *srcbuf = srcbufs[k]; + +if (srcbuf[i] &BIT (j)) + cnt++; + } + +if (cnt > nsrcbufs /2 ) + val |=BIT (j); + } + + ((u8 *)dstbuf)[i] = val; + }
Quoted 8 lines
drivers/mtd/nand/onfi.c line 68
Quoted 5 lines
drivers/mtd/nand/onfi.c new file +5
-0+} +EXPORT_SYMBOL_GPL (nand_bit_wise_majority); + +/** +* sanitize_string() - Sanitize ONFI strings so we can safely print them It is used by JEDEC logic so this should be moved elsewhere and not refer to any ONFI naming.
okay, I will move this.
Quoted 112 lines
Review
Quoted 23 lines
drivers/mtd/nand/onfi.c new file +21
-0+* @s: string to be sanitized +* @len: length of the string +* +*/ +void sanitize_string (u8 *s,size_t len) +{ +ssize_t i; + +/* Null terminate */ + s[len -1 ] =0 ; + +/* Remove non printable chars */ +for (i =0 ; i < len -1 ; i++) { +if (s[i] <' ' || s[i] >127 ) + s[i] ='?' ; + } + +/* Remove trailing spaces */ +strim (s); +} +EXPORT_SYMBOL_GPL (sanitize_string);(quoted diff) +0
-0
b/drivers/mtd/nand/raw/nand_base.cdrivers/mtd/nand/raw/nand_base.c static void nand_set_defaults(struct nand_chip
Quoted 4 lines
index
6ecd1c496ce3..c198829bcd79100644drivers/mtd/nand/raw/nand_base.c +0
-0@@ -4375,24 +4375,6 @@ static void nand_set_defaults(struct nand_chip*chip)
Quoted 13 lines
drivers/mtd/nand/raw/nand_base.c +0
-10chip->buf_align =1 ; } -/* Sanitize ONFI strings so we can safely print them */ -void sanitize_string (uint8_t *s,size_t len) -{ -ssize_t i; - -/* Null terminate */ - s[len -1 ] =0 ; - -/* Remove non printable chars */ -for (i =0 ; i < len -1 ; i++) {drivers/mtd/nand/raw/nand_base.c static void nand_set_defaults(struct nand_chip *chip)
Quoted 10 lines
drivers/mtd/nand/raw/nand_base.c +0
-8-if (s[i] <' ' || s[i] >127 ) - s[i] ='?' ; - } - -/* Remove trailing spaces */ -strim (s); -} -/* * nand_id_has_period - Check if an ID string has a given wraparound period
Review
Quoted 2 lines
drivers/mtd/nand/raw/nand_base.c +0
-0* @id_data: the ID string (quoted diff) +0
-0
b/drivers/mtd/nand/raw/nand_onfi.cdrivers/mtd/nand/raw/nand_onfi.c static int
Quoted 23 lines
index
0b879bd0a68c..2e8edfa636ef100644drivers/mtd/nand/raw/nand_onfi.c +0
-12@@ -16,18 +16,6 @@#include "internals.h" -u16 onfi_crc16 (u16 crc,u8 const *p,size_t len) -{ -int i; -while (len--) { - crc ^= *p++ <<8 ; -for (i =0 ; i <8 ; i++) - crc = (crc <<1 ) ^ ((crc &0x8000 ) ?0x8005 :0 ); - } - -return crc; -} -/* Parse the Extended Parameter Page. */ static int nand_flash_detect_ext_param_page (struct nand_chip *chip,struct nand_onfi_params *p)@@ -103,37 +91,6 @@ static intnand_flash_detect_ext_param_page(struct
nand_chip*chip,Quoted 32 lines
drivers/mtd/nand/raw/nand_onfi.c +0
-29return ret; } -/* -* Recover data with bit-wise majority -*/ -static void nand_bit_wise_majority (const void **srcbufs, -unsigned int nsrcbufs, -void *dstbuf, -unsigned int bufsize) -{ -int i, j, k; - -for (i =0 ; i < bufsize; i++) { -u8 val =0 ; - -for (j =0 ; j <8 ; j++) { -unsigned int cnt =0 ; - -for (k =0 ; k < nsrcbufs; k++) { -const u8 *srcbuf = srcbufs[k]; - -if (srcbuf[i] &BIT (j)) - cnt++; - } - -if (cnt > nsrcbufs /2 ) - val |=BIT (j); - } - - ((u8 *)dstbuf)[i] = val; - }
Quoted 8 lines
drivers/mtd/nand/raw/nand_onfi.c static int nand_flash_detect_ext_param_page(struct nand_chip *chip, · line 96
Quoted 5 lines
drivers/mtd/nand/raw/nand_onfi.c +0
-2-} -/* * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. */ Thanks,
Miquèl
Thanks,
Shiva
PATCH 3/8 mtd: nand: create ONFI table parsing instance
In reply to [email protected]From: Shivamurthy Shastri <[email protected]>
ONFI table parsing is common, as most of the variables are common between raw and SPI NAND. The parsing function is instantiated in onfi.c, which fills ONFI parameters into nand_memory_organization.
--- drivers/mtd/nand/onfi.c | 32 ++++++++++++++++++++++++++++++++ drivers/mtd/nand/raw/nand_onfi.c | 22 ++-------------------- include/linux/mtd/onfi.h | 2 ++ 3 files changed, 36 insertions(+), 20 deletions(-)
drivers/mtd/nand/onfi.c +32 -0
@@ -87,3 +87,35 @@ void sanitize_string(u8 *s, size_t len)strim (s); }EXPORT_SYMBOL_GPL (sanitize_string); + +/** +* fill_nand_memorg() - Parse ONFI table and fill memorg +* @memorg: NAND memorg to be filled +* @p: ONFI table to be parsed +* +*/ +void parse_onfi_params (struct nand_memory_organization *memorg, +struct nand_onfi_params *p) +{ + memorg->pagesize =le32_to_cpu (p->byte_per_page); + +/* +* pages_per_block and blocks_per_lun may not be a power-of-2 size +* (don't ask me who thought of this...). MTD assumes that these +* dimensions will be power-of-2, so just truncate the remaining area. +*/ + memorg->pages_per_eraseblock = +1 << (fls (le32_to_cpu (p->pages_per_block)) -1 ); + + memorg->oobsize =le16_to_cpu (p->spare_bytes_per_page); + + memorg->luns_per_target = p->lun_count; + memorg->planes_per_lun =1 << p->interleaved_bits; + +/* See erasesize comment */ + memorg->eraseblocks_per_lun = +1 << (fls (le32_to_cpu (p->blocks_per_lun)) -1 ); + memorg->max_bad_eraseblocks_per_lun =le32_to_cpu (p->blocks_per_lun); + memorg->bits_per_cell = p->bits_per_cell; +} +EXPORT_SYMBOL_GPL (parse_onfi_params);
drivers/mtd/nand/raw/nand_onfi.c +2 -20
@@ -181,30 +181,12 @@ int nand_onfi_detect(struct nand_chip *chip) goto free_onfi_param_page; } - memorg->pagesize =le32_to_cpu (p->byte_per_page); - mtd->writesize = memorg->pagesize; +parse_onfi_params (memorg, p); -/* -* pages_per_block and blocks_per_lun may not be a power-of-2 size -* (don't ask me who thought of this...). MTD assumes that these -* dimensions will be power-of-2, so just truncate the remaining area. -*/ - memorg->pages_per_eraseblock = -1 << (fls (le32_to_cpu (p->pages_per_block)) -1 ); + mtd->writesize = memorg->pagesize; mtd->erasesize = memorg->pages_per_eraseblock * memorg->pagesize; - - memorg->oobsize =le16_to_cpu (p->spare_bytes_per_page); mtd->oobsize = memorg->oobsize; - memorg->luns_per_target = p->lun_count; - memorg->planes_per_lun =1 << p->interleaved_bits; - -/* See erasesize comment */ - memorg->eraseblocks_per_lun = -1 << (fls (le32_to_cpu (p->blocks_per_lun)) -1 ); - memorg->max_bad_eraseblocks_per_lun =le32_to_cpu (p->blocks_per_lun); - memorg->bits_per_cell = p->bits_per_cell; -if (le16_to_cpu (p->features) &ONFI_FEATURE_16_BIT_BUS ) chip->options |=NAND_BUSWIDTH_16 ;
include/linux/mtd/onfi.h +2 -0
@@ -183,5 +183,7 @@ void nand_bit_wise_majority(const void **srcbufs,void *dstbuf, unsigned int bufsize);void sanitize_string (u8 *s,size_t len); +void parse_onfi_params (struct nand_memory_organization *memorg, +struct nand_onfi_params *p);#endif /* __LINUX_MTD_ONFI_H */
Signature · 1 line
2.17.1
Miquel Raynal
maintainerRe: [PATCH 3/8] mtd: nand: create ONFI table parsing instance
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:16 +0200:
Quoted 1 line
From: Shivamurthy Shastri <[email protected]>
"Create one generic ONFI table parsing instance"
Quoted 4 lines
ONFI table parsing is common, as most of the variables are common between raw and SPI NAND. The parsing function is instantiated in
onfi.c, which fills ONFI parameters intonand_memory_organization.
... into nand_memory_organization just as before.
Quoted 13 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/onfi.c | 32 ++++++++++++++++++++++++++++++++ drivers/mtd/nand/raw/nand_onfi.c | 22 ++-------------------- include/linux/mtd/onfi.h | 2 ++ 3 files changed, 36 insertions(+), 20 deletions(-)drivers/mtd/nand/onfi.c +0
-0
drivers/mtd/nand/onfi.c void sanitize_string(u8 *s, size_t len) · line 92
Quoted 6 lines
drivers/mtd/nand/onfi.c +3
-0@@ -87,3 +87,35 @@ void sanitize_string(u8 *s, size_t len)strim (s); }EXPORT_SYMBOL_GPL (sanitize_string); + +/** +* fill_nand_memorg() - Parse ONFI table and fill memorg
^ parse_onfi_params() - Parse an ONFI table and fill a memory organization structure
drivers/mtd/nand/onfi.c void sanitize_string(u8 *s, size_t len) · line 93
Quoted 1 line
drivers/mtd/nand/onfi.c +1
-0+* @memorg: NAND memorg to be filled
memory organization core structure to be filled
Quoted 70 lines
drivers/mtd/nand/onfi.c +28
-0+* @p: ONFI table to be parsed +* +*/ +void parse_onfi_params (struct nand_memory_organization *memorg, +struct nand_onfi_params *p) +{ + memorg->pagesize =le32_to_cpu (p->byte_per_page); + +/* +* pages_per_block and blocks_per_lun may not be a power-of-2 size +* (don't ask me who thought of this...). MTD assumes that these +* dimensions will be power-of-2, so just truncate the remaining area. +*/ + memorg->pages_per_eraseblock = +1 << (fls (le32_to_cpu (p->pages_per_block)) -1 ); + + memorg->oobsize =le16_to_cpu (p->spare_bytes_per_page); + + memorg->luns_per_target = p->lun_count; + memorg->planes_per_lun =1 << p->interleaved_bits; + +/* See erasesize comment */ + memorg->eraseblocks_per_lun = +1 << (fls (le32_to_cpu (p->blocks_per_lun)) -1 ); + memorg->max_bad_eraseblocks_per_lun =le32_to_cpu (p->blocks_per_lun); + memorg->bits_per_cell = p->bits_per_cell; +} +EXPORT_SYMBOL_GPL (parse_onfi_params);drivers/mtd/nand/raw/nand_onfi.c +2
-20@@ -181,30 +181,12 @@ int nand_onfi_detect(struct nand_chip *chip) goto free_onfi_param_page; } - memorg->pagesize =le32_to_cpu (p->byte_per_page); - mtd->writesize = memorg->pagesize; +parse_onfi_params (memorg, p); -/* -* pages_per_block and blocks_per_lun may not be a power-of-2 size -* (don't ask me who thought of this...). MTD assumes that these -* dimensions will be power-of-2, so just truncate the remaining area. -*/ - memorg->pages_per_eraseblock = -1 << (fls (le32_to_cpu (p->pages_per_block)) -1 ); + mtd->writesize = memorg->pagesize; mtd->erasesize = memorg->pages_per_eraseblock * memorg->pagesize; - - memorg->oobsize =le16_to_cpu (p->spare_bytes_per_page); mtd->oobsize = memorg->oobsize; - memorg->luns_per_target = p->lun_count; - memorg->planes_per_lun =1 << p->interleaved_bits; - -/* See erasesize comment */ - memorg->eraseblocks_per_lun = -1 << (fls (le32_to_cpu (p->blocks_per_lun)) -1 ); - memorg->max_bad_eraseblocks_per_lun =le32_to_cpu (p->blocks_per_lun); - memorg->bits_per_cell = p->bits_per_cell; -if (le16_to_cpu (p->features) &ONFI_FEATURE_16_BIT_BUS ) chip->options |=NAND_BUSWIDTH_16 ;include/linux/mtd/onfi.h +0
-0
include/linux/mtd/onfi.h void nand_bit_wise_majority(const void **srcbufs, · line 189
Quoted 7 lines
include/linux/mtd/onfi.h +2
-0@@ -183,5 +183,7 @@ void nand_bit_wise_majority(const void **srcbufs,void *dstbuf, unsigned int bufsize);void sanitize_string (u8 *s,size_t len); +void parse_onfi_params (struct nand_memory_organization *memorg, +struct nand_onfi_params *p);#endif /* __LINUX_MTD_ONFI_H */
Thanks,
Miquèl
PATCH 4/8 mtd: spinand: enabled parameter page support
In reply to [email protected]From: Shivamurthy Shastri <[email protected]>
Some of the SPI NAND devices has parameter page, which is similar to ONFI table.
But, it may not be self sufficient to propagate all the required parameters. Fixup function has been added in struct manufacturer to accommodate this.
--- drivers/mtd/nand/spi/core.c | 134 ++++++++++++++++++++++++++++++++++++ include/linux/mtd/spinand.h | 3 + 2 files changed, 137 insertions(+)
drivers/mtd/nand/spi/core.c +134 -0
@@ -400,6 +400,131 @@ static int spinand_lock_block(struct spinand_device *spinand, u8 lock)return spinand_write_reg_op (spinand,REG_BLOCK_LOCK , lock); } +/** +* spinand_read_param_page_op - Read parameter page operation +* @spinand: the spinand +* @page: page number where parameter page tables can be found +* @buf: buffer used to store the parameter page +* @len: length of the buffer +* +* Read parameter page +* +* Returns 0 on success, a negative error code otherwise. +*/ +static int spinand_parameter_page_read (struct spinand_device *spinand, +u8 page,void *buf,unsigned int len) +{ +struct spi_mem_op pread_op =SPINAND_PAGE_READ_OP (page); +struct spi_mem_op pread_cache_op = +SPINAND_PAGE_READ_FROM_CACHE_OP (false, +0 , +1 , + buf, + len); +u8 feature; +u8 status; +int ret; + +if (len && !buf) +return -EINVAL ; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature); +if (ret) +return ret; + +/* CFG_OTP_ENABLE is used to enable parameter page access */ + feature |=CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + + ret =spi_mem_exec_op (spinand->spimem, &pread_op); +if (ret) +return ret; + + ret =spinand_wait (spinand, &status); +if (ret <0 ) +return ret; + + ret =spi_mem_exec_op (spinand->spimem, &pread_cache_op); +if (ret) +return ret; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature); +if (ret) +return ret; + + feature &= ~CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + +return 0 ; +} + +static int spinand_param_page_detect (struct spinand_device *spinand) +{ +struct mtd_info *mtd =spinand_to_mtd (spinand); +struct nand_memory_organization *memorg; +struct nand_onfi_params *p; +struct nand_device *base =spinand_to_nand (spinand); +int i, ret; + + memorg =nanddev_get_memorg (base); + +/* Allocate buffer to hold parameter page */ + p =kzalloc ((sizeof (*p) *3 ),GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + ret =spinand_parameter_page_read (spinand,0x01 , p,sizeof (*p) *3 ); +if (ret) { + ret =0 ; + goto free_param_page; + } + +for (i =0 ; i <3 ; i++) { +if (onfi_crc16 (ONFI_CRC_BASE , (u8 *)&p[i],254 ) == +le16_to_cpu (p->crc)) { +if (i) +memcpy (p, &p[i],sizeof (*p)); +break ; + } + } + +if (i ==3 ) { +const void *srcbufs[3 ] = {p, p +1 , p +2 }; + +pr_warn ("Could not find a valid ONFI parameter page, trying bit-wise majority to recover it\n" ); +nand_bit_wise_majority (srcbufs,ARRAY_SIZE (srcbufs), p, +sizeof (*p)); + +if (onfi_crc16 (ONFI_CRC_BASE , (u8 *)p,254 ) != +le16_to_cpu (p->crc)) { +pr_err ("ONFI parameter recovery failed, aborting\n" ); + goto free_param_page; + } + } + +parse_onfi_params (memorg, p); + + mtd->writesize = memorg->pagesize; + mtd->erasesize = memorg->pages_per_eraseblock * memorg->pagesize; + mtd->oobsize = memorg->oobsize; + +/* Manufacturers may interpret the parameter page differently */ +if (spinand->manufacturer->ops->fixup_param_page) + spinand->manufacturer->ops->fixup_param_page (spinand, p); + +/* Identification done, free the full parameter page and exit */ + ret =1 ; + +free_param_page: +kfree (p); + +return ret; +} +static int spinand_check_ecc_status (struct spinand_device *spinand,u8 status) {struct nand_device *nand =spinand_to_nand (spinand);
@@ -911,6 +1036,15 @@ static int spinand_detect(struct spinand_device *spinand)return ret; } +if (!spinand->base.memorg.pagesize) { + ret =spinand_param_page_detect (spinand); +if (ret <=0 ) { +dev_err (dev,"no parameter page for %*phN\n" , +SPINAND_MAX_ID_LEN , spinand->id.data); +return -ENODEV ; + } + } +if (nand->memorg.ntargets >1 && !spinand->select_target) {dev_err (dev,"SPI NANDs with more than one die must implement ->select_target()\n" );
include/linux/mtd/spinand.h +3 -0
@@ -15,6 +15,7 @@#include <linux/mtd/nand.h> #include <linux/spi/spi.h> #include <linux/spi/spi-mem.h> +#include <linux/mtd/onfi.h> /** * Standard SPI NAND flash operations
@@ -209,6 +210,8 @@ struct spinand_manufacturer_ops {int (*detect)(struct spinand_device *spinand);int (*init)(struct spinand_device *spinand);void (*cleanup)(struct spinand_device *spinand); +void (*fixup_param_page)(struct spinand_device *spinand, +struct nand_onfi_params *p); };/**
Signature · 1 line
2.17.1
Miquel Raynal
maintainerRe: [PATCH 4/8] mtd: spinand: enabled parameter page support
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:17 +0200:
"mtd: spinand: enable parameter page support"
Quoted 3 lines
From: Shivamurthy Shastri <[email protected]>
Some of the SPI NAND devices has parameter page, which is similar to
- have a
Quoted 1 line
ONFI table.
regular raw NAND ONFI tables.
Quoted 2 lines
But, it may not be self sufficient to propagate all the required
As it may not be
Quoted 1 line
parameters. Fixup function has been added in struct manufacturer to
, a fixup is being added in the manufacturer structure
Quoted 1 line
accommodate this.
The fixup function sentence should be dropped from the commit message, see below.
Quoted 12 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/core.c | 134 ++++++++++++++++++++++++++++++++++++ include/linux/mtd/spinand.h | 3 + 2 files changed, 137 insertions(+)drivers/mtd/nand/spi/core.c +0
-0
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 404
Quoted 5 lines
drivers/mtd/nand/spi/core.c +2
-0@@ -400,6 +400,131 @@ static int spinand_lock_block(struct spinand_device *spinand, u8 lock)return spinand_write_reg_op (spinand,REG_BLOCK_LOCK , lock); } +/** +* spinand_read_param_page_op - Read parameter page operation
Again, the name in the doc does not fit the function you describe
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 405
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @spinand: the spinand
SPI-NAND chip
Shiva, there are way too much typos and shortcuts in your series. Please be more careful otherwise we can't focus on the technical aspects. I am not a native English speaker at all but please, plain English is not C code. We talk SPI-NAND and not spinand, we say structure and not struct, acronyms are uppercase, etc.
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 406
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @page: page number where parameter page tables can be found
^ the
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 410
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+* @buf: buffer used to store the parameter page +* @len: length of the buffer +* +* Read parameter page
the
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 423
Quoted 13 lines
drivers/mtd/nand/spi/core.c +13
-0+* +* Returns 0 on success, a negative error code otherwise. +*/ +static int spinand_parameter_page_read (struct spinand_device *spinand, +u8 page,void *buf,unsigned int len) +{ +struct spi_mem_op pread_op =SPINAND_PAGE_READ_OP (page); +struct spi_mem_op pread_cache_op = +SPINAND_PAGE_READ_FROM_CACHE_OP (false, +0 , +1 , + buf, + len);
That's ok if you cross the 80 characters boundary here. You may put "0, 1," on the first line and "buf, len);" on the second.
Quoted 31 lines
drivers/mtd/nand/spi/core.c +31
-0+u8 feature; +u8 status; +int ret; + +if (len && !buf) +return -EINVAL ; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature); +if (ret) +return ret; + +/* CFG_OTP_ENABLE is used to enable parameter page access */ + feature |=CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + + ret =spi_mem_exec_op (spinand->spimem, &pread_op); +if (ret) +return ret; + + ret =spinand_wait (spinand, &status); +if (ret <0 ) +return ret; + + ret =spi_mem_exec_op (spinand->spimem, &pread_cache_op); +if (ret) +return ret; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature);
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 464
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+if (ret) +return ret; + + feature &= ~CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + +return 0 ; +} +
Add the kernel doc please
Change the below function so that it returns 1 if the page was detected, 0 if it did not, an negative error code otherwise.
Quoted 8 lines
drivers/mtd/nand/spi/core.c +8
-0+static int spinand_param_page_detect (struct spinand_device *spinand) +{ +struct mtd_info *mtd =spinand_to_mtd (spinand); +struct nand_memory_organization *memorg; +struct nand_onfi_params *p; +struct nand_device *base =spinand_to_nand (spinand); +int i, ret; +
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 482
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+ memorg =nanddev_get_memorg (base); + +/* Allocate buffer to hold parameter page */ + p =kzalloc ((sizeof (*p) *3 ),GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + ret =spinand_parameter_page_read (spinand,0x01 , p,sizeof (*p) *3 ); +if (ret) { + ret =0 ;
No, you should return the error in case of error. You will later handle the fact that there is no parameter page.
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 487
Quoted 5 lines
drivers/mtd/nand/spi/core.c +5
-0+ goto free_param_page; + } + +for (i =0 ; i <3 ; i++) { + if (onfi_crc16(ONFI_CRC_BASE, (u8 *)&p[i], 254) ==
^
If you force the parameter page to be 254 bytes long it means you limit yourself to ONFI standard. That's not a problem, but then you should mention it in the function name.
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+ le16_to_cpu(p->crc)) { +if (i) +memcpy (p, &p[i],sizeof (*p)); +break ; + } + } + +if (i ==3 ) { +const void *srcbufs[3 ] = {p, p +1 , p +2 }; +
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 507
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+pr_warn ("Could not find a valid ONFI parameter page, trying bit-wise majority to recover it\n" ); +nand_bit_wise_majority (srcbufs,ARRAY_SIZE (srcbufs), p, +sizeof (*p)); + +if (onfi_crc16 (ONFI_CRC_BASE , (u8 *)p,254 ) != +le16_to_cpu (p->crc)) { +pr_err ("ONFI parameter recovery failed, aborting\n" ); + goto free_param_page; + } + }
The whole for-loop and the if (i==3) condition is exactly the same as for raw NANDs and must be extracted in a generic function:
1/ extract the function from nand/raw/nand_onfi.c and put it in nand/onfi.c.
2/ then use it in this patch.
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 513
Quoted 6 lines
drivers/mtd/nand/spi/core.c +6
-0+ +parse_onfi_params (memorg, p); + + mtd->writesize = memorg->pagesize; + mtd->erasesize = memorg->pages_per_eraseblock * memorg->pagesize; + mtd->oobsize = memorg->oobsize;
This will be handled by nanddev_init, should be removed.
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 517
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+ +/* Manufacturers may interpret the parameter page differently */ +if (spinand->manufacturer->ops->fixup_param_page) + spinand->manufacturer->ops->fixup_param_page (spinand, p);
The whole "manufacturer fixup" should be done separately.
Quoted 14 lines
drivers/mtd/nand/spi/core.c +10
-0+ +/* Identification done, free the full parameter page and exit */ + ret =1 ; + +free_param_page: +kfree (p); + +return ret; +} +static int spinand_check_ecc_status (struct spinand_device *spinand,u8 status) {struct nand_device *nand =spinand_to_nand (spinand);
drivers/mtd/nand/spi/core.c static int spinand_detect(struct spinand_device *spinand) · line 1042
Quoted 7 lines
drivers/mtd/nand/spi/core.c +4
-0@@ -911,6 +1036,15 @@ static int spinand_detect(struct spinand_device *spinand)return ret; } +if (!spinand->base.memorg.pagesize) { + ret =spinand_param_page_detect (spinand); +if (ret <=0 ) { + dev_err(dev, "no parameter page for %*phN\n",
Not sure at this stage dev will give something meaningful. Anyway I don't think we should scream at the user if his NAND is not an ONFI one so please return an error only if ret < 0. If ret == 0 or ret == 1, don't warn the user.
Quoted 21 lines
drivers/mtd/nand/spi/core.c +5
-0+ SPINAND_MAX_ID_LEN, spinand->id.data); +return -ENODEV ; + } + } +if (nand->memorg.ntargets >1 && !spinand->select_target) {dev_err (dev,"SPI NANDs with more than one die must implement ->select_target()\n" );include/linux/mtd/spinand.h +1
-0@@ -15,6 +15,7 @@#include <linux/mtd/nand.h> #include <linux/spi/spi.h> #include <linux/spi/spi-mem.h> +#include <linux/mtd/onfi.h> /** * Standard SPI NAND flash operations
include/linux/mtd/spinand.h struct spinand_manufacturer_ops { · line 214
Quoted 5 lines
include/linux/mtd/spinand.h +2
-0@@ -209,6 +210,8 @@ struct spinand_manufacturer_ops {int (*detect)(struct spinand_device *spinand);int (*init)(struct spinand_device *spinand);void (*cleanup)(struct spinand_device *spinand); +void (*fixup_param_page)(struct spinand_device *spinand, +struct nand_onfi_params *p);
Please do this in a separate patch.
include/linux/mtd/spinand.h struct spinand_manufacturer_ops { · line 217
Quoted 3 lines
include/linux/mtd/spinand.h +0
-0};/**
Thanks,
Miquèl
RE: [EXT] Re: [PATCH 4/8] mtd: spinand: enabled parameter page support
Hi Miquel,
Quoted 15 lines
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:17 +0200:
"mtd: spinand: enable parameter page support"
Quoted 3 lines
From: Shivamurthy Shastri <[email protected]>
Some of the SPI NAND devices has parameter page, which is similar to
- have a
Quoted 1 line
ONFI table.
regular raw NAND ONFI tables.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
But, it may not be self sufficient to propagate all the required
As it may not be
Quoted 1 line
parameters. Fixup function has been added in struct manufacturer to
, a fixup is being added in the manufacturer structure
Quoted 1 line
accommodate this.
The fixup function sentence should be dropped from the commit message, see below.
Okay, I will create separate patch for fixup function.
Quoted 23 lines
Quoted 5 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/core.c | 134++++++++++++++++++++++++++++++++++++
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct
Quoted 8 lines
include/linux/mtd/spinand.h | 3 + 2 files changed, 137 insertions(+)drivers/mtd/nand/spi/core.c +0
-0@@ -400,6 +400,131 @@ static int spinand_lock_block(struct
spinand_device*spinand, u8 lock)drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 404
Quoted 5 lines
drivers/mtd/nand/spi/core.c +2
-0return spinand_write_reg_op (spinand,REG_BLOCK_LOCK , lock); } +/** +* spinand_read_param_page_op - Read parameter page operation Again, the name in the doc does not fit the function you describe
Quoted 9 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 405
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @spinand: the spinand SPI-NAND chip
Shiva, there are way too much typos and shortcuts in your series. Please be more careful otherwise we can't focus on the technical aspects. I am not a native English speaker at all but please, plain English is not C code. We talk SPI-NAND and not spinand, we say structure and not struct, acronyms are uppercase, etc.
Sorry for the inconvenience caused, I will take care from next time.
Quoted 88 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 406
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @page: page number where parameter page tables can be found ^ the
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 410
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+* @buf: buffer used to store the parameter page +* @len: length of the buffer +* +* Read parameter page the
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 427
Quoted 9 lines
drivers/mtd/nand/spi/core.c +9
-0+* +* Returns 0 on success, a negative error code otherwise. +*/ +static int spinand_parameter_page_read (struct spinand_device *spinand, +u8 page,void *buf,unsigned int len) +{ +struct spi_mem_op pread_op =SPINAND_PAGE_READ_OP (page); + struct spi_mem_op pread_cache_op = +SPINAND_PAGE_READ_FROM_CACHE_OP(false,
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 423
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+0 , +1 , + buf, + len);That's ok if you cross the 80 characters boundary here. You may put "0, 1," on the first line and "buf, len);" on the second.
Quoted 31 lines
drivers/mtd/nand/spi/core.c +31
-0+u8 feature; +u8 status; +int ret; + +if (len && !buf) +return -EINVAL ; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature); +if (ret) +return ret; + +/* CFG_OTP_ENABLE is used to enable parameter page access */ + feature |=CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + + ret =spi_mem_exec_op (spinand->spimem, &pread_op); +if (ret) +return ret; + + ret =spinand_wait (spinand, &status); +if (ret <0 ) +return ret; + + ret =spi_mem_exec_op (spinand->spimem, &pread_cache_op); +if (ret) +return ret; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature);drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 464
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+if (ret) +return ret; + + feature &= ~CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + +return 0 ; +} +Add the kernel doc please
Change the below function so that it returns 1 if the page was detected, 0 if it did not, an negative error code otherwise.
Quoted 6 lines
drivers/mtd/nand/spi/core.c +6
-0+static int spinand_param_page_detect (struct spinand_device *spinand) +{ +struct mtd_info *mtd =spinand_to_mtd (spinand); +struct nand_memory_organization *memorg; +struct nand_onfi_params *p; +struct nand_device *base =spinand_to_nand (spinand);drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+int i, ret; + + memorg =nanddev_get_memorg (base); + +/* Allocate buffer to hold parameter page */ + p =kzalloc ((sizeof (*p) *3 ),GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + ret = spinand_parameter_page_read(spinand, 0x01, p, sizeof(*p) *3);
Quoted 5 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 482
Quoted 2 lines
drivers/mtd/nand/spi/core.c +2
-0+if (ret) { + ret =0 ;No, you should return the error in case of error. You will later handle the fact that there is no parameter page.
okay.
Quoted 10 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 487
Quoted 6 lines
drivers/mtd/nand/spi/core.c +5
-0+ goto free_param_page; + } + +for (i =0 ; i <3 ; i++) { + if (onfi_crc16(ONFI_CRC_BASE, (u8 *)&p[i], 254) ==^If you force the parameter page to be 254 bytes long it means you limit yourself to ONFI standard. That's not a problem, but then you should mention it in the function name.
okay, I will mention in kernel doc.
Quoted 20 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 12 lines
drivers/mtd/nand/spi/core.c +11
-0+ le16_to_cpu(p->crc)) { +if (i) +memcpy (p, &p[i],sizeof (*p)); +break ; + } + } + +if (i ==3 ) { +const void *srcbufs[3 ] = {p, p +1 , p +2 }; + + pr_warn("Could not find a valid ONFI parameter page, tryingbit-wise majority to recover it\n");
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 6 lines
drivers/mtd/nand/spi/core.c +6
-0+nand_bit_wise_majority (srcbufs,ARRAY_SIZE (srcbufs), p, +sizeof (*p)); + +if (onfi_crc16 (ONFI_CRC_BASE , (u8 *)p,254 ) != +le16_to_cpu (p->crc)) { + pr_err("ONFI parameter recovery failed,aborting\n");
Quoted 9 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 492
Quoted 3 lines
drivers/mtd/nand/spi/core.c +3
-0+ goto free_param_page; + } + }The whole for-loop and the if (i==3) condition is exactly the same as for raw NANDs and must be extracted in a generic function:
1/ extract the function fromnand/raw/nand_onfi.cand put it innand/onfi.c.
2/ then use it in this patch.
I have done this intentionally, because in raw NAND case there is function "nand_read_data_op" called inside for-loop. I don't think just for if (i == 3) it is necessary to create new function.
Let me know if you have different opinion.
Quoted 38 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 513
Quoted 8 lines
drivers/mtd/nand/spi/core.c +6
-0+ +parse_onfi_params (memorg, p); + + mtd->writesize = memorg->pagesize; + mtd->erasesize = memorg->pages_per_eraseblock * memorg- pagesize; + mtd->oobsize = memorg->oobsize;This will be handled by
nanddev_init, should be removed.drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+ +/* Manufacturers may interpret the parameter page differently */ +if (spinand->manufacturer->ops->fixup_param_page) + spinand->manufacturer->ops->fixup_param_page(spinand,p);
The whole "manufacturer fixup" should be done separately.
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 11 lines
drivers/mtd/nand/spi/core.c +10
-0+ +/* Identification done, free the full parameter page and exit */ + ret =1 ; + +free_param_page: +kfree (p); + +return ret; +} + static int spinand_check_ecc_status(struct spinand_device *spinand, u8status)
drivers/mtd/nand/spi/core.c static int spinand_detect(struct spinand_device
Quoted 3 lines
drivers/mtd/nand/spi/core.c +0
-0{drivers/mtd/nand/spi/core.c +0
-0struct nand_device *nand =spinand_to_nand (spinand);@@ -911,6 +1036,15 @@ static int spinand_detect(struct spinand_device*spinand)
Quoted 3 lines
drivers/mtd/nand/spi/core.c +0
-0return ret; }
Quoted 9 lines
drivers/mtd/nand/spi/core.c static int spinand_detect(struct spinand_device *spinand) · line 1042
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+if (!spinand->base.memorg.pagesize) { + ret =spinand_param_page_detect (spinand); +if (ret <=0 ) { + dev_err(dev, "no parameter page for %*phN\n",Not sure at this stage dev will give something meaningful. Anyway I don't think we should scream at the user if his NAND is not an ONFI one so please return an error only if ret < 0. If ret == 0 or ret == 1, don't warn the user.
I will do it as per your suggestion.
Quoted 37 lines
drivers/mtd/nand/spi/core.c static int spinand_detect(struct spinand_device *spinand)
Quoted 9 lines
drivers/mtd/nand/spi/core.c +5
-0+ SPINAND_MAX_ID_LEN, spinand->id.data); +return -ENODEV ; + } + } +if (nand->memorg.ntargets >1 && !spinand->select_target) { dev_err(dev, "SPI NANDs with more than one die must implement->select_target()\n");
Quoted 13 lines
include/linux/mtd/spinand.h +1
-0@@ -15,6 +15,7 @@#include <linux/mtd/nand.h> #include <linux/spi/spi.h> #include <linux/spi/spi-mem.h> +#include <linux/mtd/onfi.h> /** * Standard SPI NAND flash operations include/linux/mtd/spinand.h struct spinand_manufacturer_ops { · line 214
Quoted 5 lines
include/linux/mtd/spinand.h +2
-0@@ -209,6 +210,8 @@ struct spinand_manufacturer_ops {int (*detect)(struct spinand_device *spinand);int (*init)(struct spinand_device *spinand);void (*cleanup)(struct spinand_device *spinand); +void (*fixup_param_page)(struct spinand_device *spinand, +struct nand_onfi_params *p);Please do this in a separate patch.
include/linux/mtd/spinand.h struct spinand_manufacturer_ops { · line 217
Quoted 3 lines
include/linux/mtd/spinand.h +0
-0};/** Thanks,
Miquèl
Miquel Raynal
maintainerRe: [EXT] Re: [PATCH 4/8] mtd: spinand: enabled parameter page support
Hi Boris,
Another question for you :)
"Shivamurthy Shastri (sshivamurthy)" <[email protected]> wrote on Mon, 19 Aug 2019 08:51:52 +0000:
Quoted 202 lines
Hi Miquel,
Quoted 15 lines
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:17 +0200:
"mtd: spinand: enable parameter page support"
Quoted 3 lines
From: Shivamurthy Shastri <[email protected]>
Some of the SPI NAND devices has parameter page, which is similar to
- have a
Quoted 1 line
ONFI table.
regular raw NAND ONFI tables.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
But, it may not be self sufficient to propagate all the required
As it may not be
Quoted 1 line
parameters. Fixup function has been added in struct manufacturer to
, a fixup is being added in the manufacturer structure
Quoted 1 line
accommodate this.
The fixup function sentence should be dropped from the commit message, see below.
Okay, I will create separate patch for fixup function.
Quoted 23 lines
Quoted 5 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/core.c | 134++++++++++++++++++++++++++++++++++++
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct
Quoted 8 lines
include/linux/mtd/spinand.h | 3 + 2 files changed, 137 insertions(+)drivers/mtd/nand/spi/core.c +0
-0@@ -400,6 +400,131 @@ static int spinand_lock_block(struct
spinand_device*spinand, u8 lock)drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 404
Quoted 5 lines
drivers/mtd/nand/spi/core.c +2
-0return spinand_write_reg_op (spinand,REG_BLOCK_LOCK , lock); } +/** +* spinand_read_param_page_op - Read parameter page operation Again, the name in the doc does not fit the function you describe
Quoted 9 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 405
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @spinand: the spinand SPI-NAND chip
Shiva, there are way too much typos and shortcuts in your series. Please be more careful otherwise we can't focus on the technical aspects. I am not a native English speaker at all but please, plain English is not C code. We talk SPI-NAND and not spinand, we say structure and not struct, acronyms are uppercase, etc.
Sorry for the inconvenience caused, I will take care from next time.
Quoted 88 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 406
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @page: page number where parameter page tables can be found ^ the
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 410
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+* @buf: buffer used to store the parameter page +* @len: length of the buffer +* +* Read parameter page the
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 427
Quoted 9 lines
drivers/mtd/nand/spi/core.c +9
-0+* +* Returns 0 on success, a negative error code otherwise. +*/ +static int spinand_parameter_page_read (struct spinand_device *spinand, +u8 page,void *buf,unsigned int len) +{ +struct spi_mem_op pread_op =SPINAND_PAGE_READ_OP (page); + struct spi_mem_op pread_cache_op = +SPINAND_PAGE_READ_FROM_CACHE_OP(false,
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 423
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+0 , +1 , + buf, + len);That's ok if you cross the 80 characters boundary here. You may put "0, 1," on the first line and "buf, len);" on the second.
Quoted 31 lines
drivers/mtd/nand/spi/core.c +31
-0+u8 feature; +u8 status; +int ret; + +if (len && !buf) +return -EINVAL ; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature); +if (ret) +return ret; + +/* CFG_OTP_ENABLE is used to enable parameter page access */ + feature |=CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + + ret =spi_mem_exec_op (spinand->spimem, &pread_op); +if (ret) +return ret; + + ret =spinand_wait (spinand, &status); +if (ret <0 ) +return ret; + + ret =spi_mem_exec_op (spinand->spimem, &pread_cache_op); +if (ret) +return ret; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature);drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 464
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+if (ret) +return ret; + + feature &= ~CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + +return 0 ; +} +Add the kernel doc please
Change the below function so that it returns 1 if the page was detected, 0 if it did not, an negative error code otherwise.
Quoted 6 lines
drivers/mtd/nand/spi/core.c +6
-0+static int spinand_param_page_detect (struct spinand_device *spinand) +{ +struct mtd_info *mtd =spinand_to_mtd (spinand); +struct nand_memory_organization *memorg; +struct nand_onfi_params *p; +struct nand_device *base =spinand_to_nand (spinand);drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+int i, ret; + + memorg =nanddev_get_memorg (base); + +/* Allocate buffer to hold parameter page */ + p =kzalloc ((sizeof (*p) *3 ),GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + ret = spinand_parameter_page_read(spinand, 0x01, p, sizeof(*p) *3);
Quoted 5 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 482
Quoted 2 lines
drivers/mtd/nand/spi/core.c +2
-0+if (ret) { + ret =0 ;No, you should return the error in case of error. You will later handle the fact that there is no parameter page.
okay.
Quoted 10 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 487
Quoted 6 lines
drivers/mtd/nand/spi/core.c +5
-0+ goto free_param_page; + } + +for (i =0 ; i <3 ; i++) { + if (onfi_crc16(ONFI_CRC_BASE, (u8 *)&p[i], 254) ==^If you force the parameter page to be 254 bytes long it means you limit yourself to ONFI standard. That's not a problem, but then you should mention it in the function name.
okay, I will mention in kernel doc.
Quoted 20 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 12 lines
drivers/mtd/nand/spi/core.c +11
-0+ le16_to_cpu(p->crc)) { +if (i) +memcpy (p, &p[i],sizeof (*p)); +break ; + } + } + +if (i ==3 ) { +const void *srcbufs[3 ] = {p, p +1 , p +2 }; + + pr_warn("Could not find a valid ONFI parameter page, tryingbit-wise majority to recover it\n");
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 6 lines
drivers/mtd/nand/spi/core.c +6
-0+nand_bit_wise_majority (srcbufs,ARRAY_SIZE (srcbufs), p, +sizeof (*p)); + +if (onfi_crc16 (ONFI_CRC_BASE , (u8 *)p,254 ) != +le16_to_cpu (p->crc)) { + pr_err("ONFI parameter recovery failed,aborting\n");
Quoted 9 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 492
Quoted 3 lines
drivers/mtd/nand/spi/core.c +3
-0+ goto free_param_page; + } + }The whole for-loop and the if (i==3) condition is exactly the same as for raw NANDs and must be extracted in a generic function:
1/ extract the function fromnand/raw/nand_onfi.cand put it innand/onfi.c.
2/ then use it in this patch.
Quoted 5 lines
I have done this intentionally, because in raw NAND case there is function "
nand_read_data_op" called inside for-loop. I don't think just for if (i == 3) it is necessary to create new function.Let me know if you have different opinion.
I don't have a strong opinion on that. Boris what do you think? Shall we duplicate the code? It's not just about the if condition, it's the whole for loop which is very similar.
Thanks,
Miquèl
RE: [EXT] Re: [PATCH 4/8] mtd: spinand: enabled parameter page support
Hello Miquel & Boris,
Just a gentle reminder that I'd like some feedback.
Thanks,
Shiva
Quoted 227 lines
Hi Boris,
Another question for you :)
"Shivamurthy Shastri (sshivamurthy)" <[email protected]> wrote on
Mon, 19 Aug 2019 08:51:52 +0000:Quoted 24 lines
Hi Miquel,
Quoted 22 lines
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:17 +0200:
"mtd: spinand: enable parameter page support"
Quoted 3 lines
From: Shivamurthy Shastri <[email protected]>
Some of the SPI NAND devices has parameter page, which is similar to
- have a
Quoted 1 line
ONFI table.
regular raw NAND ONFI tables.
Quoted 2 lines
But, it may not be self sufficient to propagate all the required
As it may not be
Quoted 1 line
parameters. Fixup function has been added in struct manufacturer to
, a fixup is being added in the manufacturer structure
Quoted 1 line
accommodate this.
The fixup function sentence should be dropped from the commit
message,
Quoted 30 lines
Quoted 1 line
see below.
Okay, I will create separate patch for fixup function.
Quoted 26 lines
Quoted 5 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/core.c | 134++++++++++++++++++++++++++++++++++++
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct
Quoted 8 lines
include/linux/mtd/spinand.h | 3 + 2 files changed, 137 insertions(+)drivers/mtd/nand/spi/core.c +0
-0@@ -400,6 +400,131 @@ static int spinand_lock_block(struct
spinand_device*spinand, u8 lock)drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 404
Quoted 5 lines
drivers/mtd/nand/spi/core.c +2
-0return spinand_write_reg_op (spinand,REG_BLOCK_LOCK , lock); } +/** +* spinand_read_param_page_op - Read parameter page operation Again, the name in the doc does not fit the function you describe
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 405
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @spinand: the spinand SPI-NAND chip
Quoted 20 lines
Quoted 6 lines
Shiva, there are way too much typos and shortcuts in your series. Please be more careful otherwise we can't focus on the technical aspects. I am not a native English speaker at all but please, plain English is not C code. We talk SPI-NAND and not spinand, we say structure and not struct, acronyms are uppercase, etc.
Sorry for the inconvenience caused, I will take care from next time.
Quoted 11 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 406
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @page: page number where parameter page tables can be found ^ the
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 410
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+* @buf: buffer used to store the parameter page +* @len: length of the buffer +* +* Read parameter page the
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+* +* Returns 0 on success, a negative error code otherwise. +*/ +static int spinand_parameter_page_read(struct spinand_device*spinand,
Quoted 57 lines
Quoted 57 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 427
Quoted 5 lines
drivers/mtd/nand/spi/core.c +5
-0+ u8 page, void *buf, unsigned int len) +{ + struct spi_mem_op pread_op = SPINAND_PAGE_READ_OP(page); + struct spi_mem_op pread_cache_op = +SPINAND_PAGE_READ_FROM_CACHE_OP(false,
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 423
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+0 , +1 , + buf, + len);That's ok if you cross the 80 characters boundary here. You may put "0, 1," on the first line and "buf, len);" on the second.
Quoted 31 lines
drivers/mtd/nand/spi/core.c +31
-0+u8 feature; +u8 status; +int ret; + +if (len && !buf) +return -EINVAL ; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature); +if (ret) +return ret; + +/* CFG_OTP_ENABLE is used to enable parameter page access */ + feature |=CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + + ret =spi_mem_exec_op (spinand->spimem, &pread_op); +if (ret) +return ret; + + ret =spinand_wait (spinand, &status); +if (ret <0 ) +return ret; + + ret =spi_mem_exec_op (spinand->spimem, &pread_cache_op); +if (ret) +return ret; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature);drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 464
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+if (ret) +return ret; + + feature &= ~CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + +return 0 ; +} +Add the kernel doc please
Quoted 4 lines
Quoted 4 lines
Change the below function so that it returns 1 if the page was detected, 0 if it did not, an negative error code otherwise.
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+static int spinand_param_page_detect(struct spinand_device*spinand)
Quoted 67 lines
Quoted 16 lines
Quoted 5 lines
drivers/mtd/nand/spi/core.c +5
-0+{ +struct mtd_info *mtd =spinand_to_mtd (spinand); +struct nand_memory_organization *memorg; +struct nand_onfi_params *p; +struct nand_device *base =spinand_to_nand (spinand);drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+int i, ret; + + memorg =nanddev_get_memorg (base); + +/* Allocate buffer to hold parameter page */ + p =kzalloc ((sizeof (*p) *3 ),GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + ret = spinand_parameter_page_read(spinand, 0x01, p, sizeof(*p) *3);
Quoted 5 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 482
Quoted 2 lines
drivers/mtd/nand/spi/core.c +2
-0+if (ret) { + ret =0 ;No, you should return the error in case of error. You will later handle the fact that there is no parameter page.
okay.
Quoted 10 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 487
Quoted 6 lines
drivers/mtd/nand/spi/core.c +5
-0+ goto free_param_page; + } + +for (i =0 ; i <3 ; i++) { + if (onfi_crc16(ONFI_CRC_BASE, (u8 *)&p[i], 254) ==^If you force the parameter page to be 254 bytes long it means you limit yourself to ONFI standard. That's not a problem, but then you should mention it in the function name.
okay, I will mention in kernel doc.
Quoted 20 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 12 lines
drivers/mtd/nand/spi/core.c +11
-0+ le16_to_cpu(p->crc)) { +if (i) +memcpy (p, &p[i],sizeof (*p)); +break ; + } + } + +if (i ==3 ) { +const void *srcbufs[3 ] = {p, p +1 , p +2 }; + + pr_warn("Could not find a valid ONFI parameter page, tryingbit-wise majority to recover it\n");
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 6 lines
drivers/mtd/nand/spi/core.c +6
-0+nand_bit_wise_majority (srcbufs,ARRAY_SIZE (srcbufs), p, +sizeof (*p)); + +if (onfi_crc16 (ONFI_CRC_BASE , (u8 *)p,254 ) != +le16_to_cpu (p->crc)) { + pr_err("ONFI parameter recovery failed,aborting\n");
Quoted 9 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 492
Quoted 3 lines
drivers/mtd/nand/spi/core.c +3
-0+ goto free_param_page; + } + }The whole for-loop and the if (i==3) condition is exactly the same as for raw NANDs and must be extracted in a generic function:
1/ extract the function fromnand/raw/nand_onfi.cand put it innand/onfi.c.
2/ then use it in this patch.Quoted 5 lines
I have done this intentionally, because in raw NAND case there is function "
nand_read_data_op" called inside for-loop. I don't think just for if (i == 3) it is necessary to create new function.Let me know if you have different opinion.
I don't have a strong opinion on that. Boris what do you think? Shall we duplicate the code? It's not just about the if condition, it's the whole for loop which is very similar.
Thanks,
Miquèl
Re: [EXT] Re: [PATCH 4/8] mtd: spinand: enabled parameter page support
In reply to Miquel RaynalQuoted 208 lines · On Mon, 19 Aug 2019 11:21:18 +0200 Miquel Raynal <[email protected]>…
Hi Boris,
Another question for you :)
"Shivamurthy Shastri (sshivamurthy)" <[email protected]> wrote on Mon, 19 Aug 2019 08:51:52 +0000:
Quoted 201 lines
Hi Miquel,
Quoted 15 lines
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:17 +0200:
"mtd: spinand: enable parameter page support"
Quoted 3 lines
From: Shivamurthy Shastri <[email protected]>
Some of the SPI NAND devices has parameter page, which is similar to
- have a
Quoted 1 line
ONFI table.
regular raw NAND ONFI tables.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
But, it may not be self sufficient to propagate all the required
As it may not be
Quoted 1 line
parameters. Fixup function has been added in struct manufacturer to
, a fixup is being added in the manufacturer structure
Quoted 1 line
accommodate this.
The fixup function sentence should be dropped from the commit message, see below.
Okay, I will create separate patch for fixup function.
Quoted 23 lines
Quoted 5 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/core.c | 134++++++++++++++++++++++++++++++++++++
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct
Quoted 8 lines
include/linux/mtd/spinand.h | 3 + 2 files changed, 137 insertions(+)drivers/mtd/nand/spi/core.c +0
-0@@ -400,6 +400,131 @@ static int spinand_lock_block(struct
spinand_device*spinand, u8 lock)drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 404
Quoted 5 lines
drivers/mtd/nand/spi/core.c +2
-0return spinand_write_reg_op (spinand,REG_BLOCK_LOCK , lock); } +/** +* spinand_read_param_page_op - Read parameter page operation Again, the name in the doc does not fit the function you describe
Quoted 9 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 405
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @spinand: the spinand SPI-NAND chip
Shiva, there are way too much typos and shortcuts in your series. Please be more careful otherwise we can't focus on the technical aspects. I am not a native English speaker at all but please, plain English is not C code. We talk SPI-NAND and not spinand, we say structure and not struct, acronyms are uppercase, etc.
Sorry for the inconvenience caused, I will take care from next time.
Quoted 88 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 406
Quoted 1 line
drivers/mtd/nand/spi/core.c +1
-0+* @page: page number where parameter page tables can be found ^ the
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 410
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+* @buf: buffer used to store the parameter page +* @len: length of the buffer +* +* Read parameter page the
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 427
Quoted 9 lines
drivers/mtd/nand/spi/core.c +9
-0+* +* Returns 0 on success, a negative error code otherwise. +*/ +static int spinand_parameter_page_read (struct spinand_device *spinand, +u8 page,void *buf,unsigned int len) +{ +struct spi_mem_op pread_op =SPINAND_PAGE_READ_OP (page); + struct spi_mem_op pread_cache_op = +SPINAND_PAGE_READ_FROM_CACHE_OP(false,
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 423
Quoted 4 lines
drivers/mtd/nand/spi/core.c +4
-0+0 , +1 , + buf, + len);That's ok if you cross the 80 characters boundary here. You may put "0, 1," on the first line and "buf, len);" on the second.
Quoted 31 lines
drivers/mtd/nand/spi/core.c +31
-0+u8 feature; +u8 status; +int ret; + +if (len && !buf) +return -EINVAL ; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature); +if (ret) +return ret; + +/* CFG_OTP_ENABLE is used to enable parameter page access */ + feature |=CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + + ret =spi_mem_exec_op (spinand->spimem, &pread_op); +if (ret) +return ret; + + ret =spinand_wait (spinand, &status); +if (ret <0 ) +return ret; + + ret =spi_mem_exec_op (spinand->spimem, &pread_cache_op); +if (ret) +return ret; + + ret =spinand_read_reg_op (spinand,REG_CFG , + &feature);drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 464
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+if (ret) +return ret; + + feature &= ~CFG_OTP_ENABLE ; + +spinand_write_reg_op (spinand,REG_CFG , feature); + +return 0 ; +} +Add the kernel doc please
Change the below function so that it returns 1 if the page was detected, 0 if it did not, an negative error code otherwise.
Quoted 6 lines
drivers/mtd/nand/spi/core.c +6
-0+static int spinand_param_page_detect (struct spinand_device *spinand) +{ +struct mtd_info *mtd =spinand_to_mtd (spinand); +struct nand_memory_organization *memorg; +struct nand_onfi_params *p; +struct nand_device *base =spinand_to_nand (spinand);drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+int i, ret; + + memorg =nanddev_get_memorg (base); + +/* Allocate buffer to hold parameter page */ + p =kzalloc ((sizeof (*p) *3 ),GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + ret = spinand_parameter_page_read(spinand, 0x01, p, sizeof(*p) *3);
Quoted 5 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 482
Quoted 2 lines
drivers/mtd/nand/spi/core.c +2
-0+if (ret) { + ret =0 ;No, you should return the error in case of error. You will later handle the fact that there is no parameter page.
okay.
Quoted 10 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 487
Quoted 6 lines
drivers/mtd/nand/spi/core.c +5
-0+ goto free_param_page; + } + +for (i =0 ; i <3 ; i++) { + if (onfi_crc16(ONFI_CRC_BASE, (u8 *)&p[i], 254) ==^If you force the parameter page to be 254 bytes long it means you limit yourself to ONFI standard. That's not a problem, but then you should mention it in the function name.
okay, I will mention in kernel doc.
Quoted 29 lines
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 12 lines
drivers/mtd/nand/spi/core.c +11
-0+ le16_to_cpu(p->crc)) { +if (i) +memcpy (p, &p[i],sizeof (*p)); +break ; + } + } + +if (i ==3 ) { +const void *srcbufs[3 ] = {p, p +1 , p +2 }; + + pr_warn("Could not find a valid ONFI parameter page, tryingbit-wise majority to recover it\n");
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
Quoted 6 lines
drivers/mtd/nand/spi/core.c +6
-0+nand_bit_wise_majority (srcbufs,ARRAY_SIZE (srcbufs), p, +sizeof (*p)); + +if (onfi_crc16 (ONFI_CRC_BASE , (u8 *)p,254 ) != +le16_to_cpu (p->crc)) { + pr_err("ONFI parameter recovery failed,aborting\n");
drivers/mtd/nand/spi/core.c static int spinand_lock_block(struct spinand_device *spinand, u8 lock) · line 492
Quoted 3 lines
drivers/mtd/nand/spi/core.c +3
-0+ goto free_param_page; + } + }The whole for-loop and the if (i==3) condition is exactly the same as for raw NANDs and must be extracted in a generic function:
1/ extract the function fromnand/raw/nand_onfi.cand put it innand/onfi.c.
2/ then use it in this patch.
Sounds like a good idea indeed.
Quoted 4 lines
Quoted 4 lines
I have done this intentionally, because in raw NAND case there is function "
nand_read_data_op" called inside for-loop. I don't think just for if (i == 3) it is necessary to create new function.
Well, reading more than just a single param page in a single step shouldn't hurt. You can let the caller choose the number of page it wants to read (can be more than 3) and pass this information to the helper function. You should probably call nand_bit_wise_majority() from this helper too.
Quoted 6 lines
Quoted 2 lines
Let me know if you have different opinion.
I don't have a strong opinion on that. Boris what do you think? Shall we duplicate the code? It's not just about the if condition, it's the whole for loop which is very similar.
I think Miquel is right, we shouldn't duplicate this logic.
PATCH 5/8 mtd: spinand: micron: prepare for generalizing driver
In reply to [email protected]From: Shivamurthy Shastri <[email protected]>
Generalize OOB layout structure and function names.
--- drivers/mtd/nand/spi/micron.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/mtd/nand/spi/micron.c +14 -14
@@ -34,38 +34,38 @@ static SPINAND_OP_VARIANTS(update_cache_variants,SPINAND_PROG_LOAD_X4 (false,0 ,NULL ,0 ), SPINAND_PROG_LOAD(false, 0, NULL, 0)); -static int mt29f2g01abagd_ooblayout_ecc (struct mtd_info *mtd,int section, -struct mtd_oob_region *region) +static int micron_ooblayout_ecc (struct mtd_info *mtd,int section, +struct mtd_oob_region *region) {if (section)return -ERANGE ; - region->offset =64 ; - region->length =64 ; + region->offset = mtd->oobsize /2 ; + region->length = mtd->oobsize /2 ;return 0 ; } -static int mt29f2g01abagd_ooblayout_free (struct mtd_info *mtd,int section, -struct mtd_oob_region *region) +static int micron_ooblayout_free (struct mtd_info *mtd,int section, +struct mtd_oob_region *region) {if (section)return -ERANGE ;/* Reserve 2 bytes for the BBM. */ region->offset =2 ; - region->length =62 ; + region->length = (mtd->oobsize /2 ) -2 ;return 0 ; } -static const struct mtd_ooblayout_ops mt29f2g01abagd_ooblayout = { - .ecc = mt29f2g01abagd_ooblayout_ecc, - .free = mt29f2g01abagd_ooblayout_free, +static const struct mtd_ooblayout_ops micron_ooblayout_ops = { + .ecc = micron_ooblayout_ecc, + .free = micron_ooblayout_free, }; -static int mt29f2g01abagd_ecc_get_status (struct spinand_device *spinand, -u8 status) +static int micron_ecc_get_status (struct spinand_device *spinand, +u8 status) {switch (status &MICRON_STATUS_ECC_MASK ) {case STATUS_ECC_NO_BITFLIPS :
@@ -98,8 +98,8 @@ static const struct spinand_info micron_spinand_table[] = { &write_cache_variants, &update_cache_variants), 0, - SPINAND_ECCINFO(&mt29f2g01abagd_ooblayout, - mt29f2g01abagd_ecc_get_status)), + SPINAND_ECCINFO(µn_ooblayout_ops, + micron_ecc_get_status)), };static int micron_spinand_detect (struct spinand_device *spinand)
Signature · 1 line
2.17.1
Miquel Raynal
maintainerRe: [PATCH 5/8] mtd: spinand: micron: prepare for generalizing driver
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:18 +0200:
Quoted 2 lines
From: Shivamurthy Shastri <[email protected]>
"mtd: spinand: micron: Rename helpers and structures to be more generic"
Quoted 1 line
Generalize OOB layout structure and function names.
Change the prefix of Micron driver's functions and structures before supporting more chips: s/mt29f2g01abagd/micron/
Quoted 62 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/micron.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)drivers/mtd/nand/spi/micron.c +12
-12@@ -34,38 +34,38 @@ static SPINAND_OP_VARIANTS(update_cache_variants,SPINAND_PROG_LOAD_X4 (false,0 ,NULL ,0 ), SPINAND_PROG_LOAD(false, 0, NULL, 0)); -static int mt29f2g01abagd_ooblayout_ecc (struct mtd_info *mtd,int section, -struct mtd_oob_region *region) +static int micron_ooblayout_ecc (struct mtd_info *mtd,int section, +struct mtd_oob_region *region) {if (section)return -ERANGE ; - region->offset =64 ; - region->length =64 ; + region->offset = mtd->oobsize /2 ; + region->length = mtd->oobsize /2 ;return 0 ; } -static int mt29f2g01abagd_ooblayout_free (struct mtd_info *mtd,int section, -struct mtd_oob_region *region) +static int micron_ooblayout_free (struct mtd_info *mtd,int section, +struct mtd_oob_region *region) {if (section)return -ERANGE ;/* Reserve 2 bytes for the BBM. */ region->offset =2 ; - region->length =62 ; + region->length = (mtd->oobsize /2 ) -2 ;return 0 ; } -static const struct mtd_ooblayout_ops mt29f2g01abagd_ooblayout = { - .ecc = mt29f2g01abagd_ooblayout_ecc, - .free = mt29f2g01abagd_ooblayout_free, +static const struct mtd_ooblayout_ops micron_ooblayout_ops = { + .ecc = micron_ooblayout_ecc, + .free = micron_ooblayout_free, }; -static int mt29f2g01abagd_ecc_get_status (struct spinand_device *spinand, -u8 status) +static int micron_ecc_get_status (struct spinand_device *spinand, +u8 status) {switch (status &MICRON_STATUS_ECC_MASK ) {case STATUS_ECC_NO_BITFLIPS :
drivers/mtd/nand/spi/micron.c static const struct spinand_info micron_spinand_table[] = { · line 105
Quoted 10 lines
drivers/mtd/nand/spi/micron.c +2
-2@@ -98,8 +98,8 @@ static const struct spinand_info micron_spinand_table[] = { &write_cache_variants, &update_cache_variants), 0, - SPINAND_ECCINFO(&mt29f2g01abagd_ooblayout, - mt29f2g01abagd_ecc_get_status)), + SPINAND_ECCINFO(µn_ooblayout_ops, + micron_ecc_get_status)), };static int micron_spinand_detect (struct spinand_device *spinand)
Thanks,
Miquèl
PATCH 6/8 mtd: spinand: micron: Turn driver implementation generic
In reply to [email protected]From: Shivamurthy Shastri <[email protected]>
Driver is redesigned using parameter page to support Micron SPI NAND flashes.
The reason why spinand_select_op_variant globalized is that the Micron driver no longer calling spinand_match_and_init.
--- drivers/mtd/nand/spi/core.c | 2 +- drivers/mtd/nand/spi/micron.c | 61 +++++++++++++++++++++++++---------- include/linux/mtd/spinand.h | 4 +++ 3 files changed, 49 insertions(+), 18 deletions(-)
drivers/mtd/nand/spi/core.c +1 -1
@@ -920,7 +920,7 @@ static void spinand_manufacturer_cleanup(struct spinand_device *spinand)return spinand->manufacturer->ops->cleanup (spinand); } -static const struct spi_mem_op * +const struct spi_mem_op *spinand_select_op_variant (struct spinand_device *spinand,const struct spinand_op_variants *variants) {
drivers/mtd/nand/spi/micron.c +44 -17
82 lines not on this page · raw message
include/linux/mtd/spinand.h +4 -0
@@ -461,4 +461,8 @@ int spinand_match_and_init(struct spinand_device *dev,int spinand_upd_cfg (struct spinand_device *spinand,u8 mask,u8 val);int spinand_select_target (struct spinand_device *spinand,unsigned int target); +const struct spi_mem_op * +spinand_select_op_variant (struct spinand_device *spinand, +const struct spinand_op_variants *variants); +#endif /* __LINUX_MTD_SPINAND_H */
Signature · 1 line
2.17.1
Miquel Raynal
maintainerRe: [PATCH 6/8] mtd: spinand: micron: Turn driver implementation generic
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:19 +0200:
Quoted 2 lines
From: Shivamurthy Shastri <[email protected]>
I am not sure the "turn implemenatation generic" title describes what you do.
Quoted 2 lines
Driver is redesigned using parameter page to support Micron SPI NAND flashes.
Redesigned is perhaps a bit too much.
"
Quoted 33 lines
The reason why
spinand_select_op_variantglobalized is that the Micron driver no longer callingspinand_match_and_init.Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/core.c | 2 +- drivers/mtd/nand/spi/micron.c | 61 +++++++++++++++++++++++++---------- include/linux/mtd/spinand.h | 4 +++ 3 files changed, 49 insertions(+), 18 deletions(-)drivers/mtd/nand/spi/core.c +1
-1@@ -920,7 +920,7 @@ static void spinand_manufacturer_cleanup(struct spinand_device *spinand)return spinand->manufacturer->ops->cleanup (spinand); } -static const struct spi_mem_op * +const struct spi_mem_op *spinand_select_op_variant (struct spinand_device *spinand,const struct spinand_op_variants *variants) {drivers/mtd/nand/spi/micron.c +0
-2@@ -90,22 +90,10 @@ static int micron_ecc_get_status(struct spinand_device *spinand,return -EINVAL ; } -static const struct spinand_info micron_spinand_table[] = { - SPINAND_INFO("MT29F2G01ABAGD", 0x24,
drivers/mtd/nand/spi/micron.c static int micron_ecc_get_status(struct spinand_device *spinand, · line 104
Quoted 10 lines
drivers/mtd/nand/spi/micron.c +0
-10-NAND_MEMORG (1 ,2048 ,128 ,64 ,2048 ,40 ,2 ,1 ,1 ), -NAND_ECCREQ (8 ,512 ), -SPINAND_INFO_OP_VARIANTS (&read_cache_variants, - &write_cache_variants, - &update_cache_variants), -0 , -SPINAND_ECCINFO (µn_ooblayout_ops, - micron_ecc_get_status)), -}; -
I don't know if it is wise to drop this structure.
Quoted 9 lines
drivers/mtd/nand/spi/micron.c +1
-1static int micron_spinand_detect (struct spinand_device *spinand) { +const struct spi_mem_op *op;u8 *id = spinand->id.data; -int ret;/* * Micron SPI NAND read ID need a dummy byte,
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct spinand_device *spinand) · line 118
Quoted 5 lines
drivers/mtd/nand/spi/micron.c +0
-2@@ -114,16 +102,55 @@ static int micron_spinand_detect(struct spinand_device *spinand)if (id[1 ] !=SPINAND_MFR_MICRON )return 0 ; - ret =spinand_match_and_init (spinand, micron_spinand_table, -ARRAY_SIZE (micron_spinand_table), id[2 ]);
I am not sure this is the right solution. I would keep this call and overwrite what you need to overwrite with the fixup hook.
Quoted 59 lines
drivers/mtd/nand/spi/micron.c +43
-2-if (ret) -return ret; + spinand->flags =0 ; + spinand->eccinfo.get_status = micron_ecc_get_status; + spinand->eccinfo.ooblayout = µn_ooblayout_ops; + + op =spinand_select_op_variant (spinand, + &read_cache_variants); +if (!op) +return -ENOTSUPP ; + + spinand->op_templates.read_cache = op; + + op =spinand_select_op_variant (spinand, + &write_cache_variants); +if (!op) +return -ENOTSUPP ; + + spinand->op_templates.write_cache = op; + + op =spinand_select_op_variant (spinand, + &update_cache_variants); + spinand->op_templates.update_cache = op;return 1 ; } +static void micron_fixup_param_page (struct spinand_device *spinand, +struct nand_onfi_params *p) +{ +/* +* As per Micron datasheets vendor[83] is defined as +* die_select_feature +*/ +if (p->vendor[83 ] && !p->interleaved_bits) + spinand->base.memorg.planes_per_lun =1 << p->vendor[0 ]; + + spinand->base.memorg.ntargets = p->lun_count; + spinand->base.memorg.luns_per_target =1 ; + +/* +* As per Micron datasheets, +* vendor[82] is ECC maximum correctability +*/ + spinand->base.eccreq.strength = p->vendor[82 ]; + spinand->base.eccreq.step_size =512 ; +} +static const struct spinand_manufacturer_ops micron_spinand_manuf_ops = { .detect = micron_spinand_detect, + .fixup_param_page = micron_fixup_param_page, };const struct spinand_manufacturer micron_spinand_manufacturer = {include/linux/mtd/spinand.h +0
-0
include/linux/mtd/spinand.h int spinand_match_and_init(struct spinand_device *dev, · line 468
Quoted 8 lines
include/linux/mtd/spinand.h +4
-0@@ -461,4 +461,8 @@ int spinand_match_and_init(struct spinand_device *dev,int spinand_upd_cfg (struct spinand_device *spinand,u8 mask,u8 val);int spinand_select_target (struct spinand_device *spinand,unsigned int target); +const struct spi_mem_op * +spinand_select_op_variant (struct spinand_device *spinand, +const struct spinand_op_variants *variants); +#endif /* __LINUX_MTD_SPINAND_H */
Thanks,
Miquèl
RE: [EXT] Re: [PATCH 6/8] mtd: spinand: micron: Turn driver implementation generic
Hi Miquel,
Quoted 80 lines
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:19 +0200:
Quoted 2 lines
From: Shivamurthy Shastri <[email protected]>
I am not sure the "turn implemenatation generic" title describes what you do.
Quoted 2 lines
Driver is redesigned using parameter page to support Micron SPI NAND flashes.
Redesigned is perhaps a bit too much.
"
Quoted 7 lines
The reason why
spinand_select_op_variantglobalized is that the Micron driver no longer callingspinand_match_and_init.Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/core.c | 2 +- drivers/mtd/nand/spi/micron.c | 61 +++++++++++++++++++++++++----------
drivers/mtd/nand/spi/core.c static void spinand_manufacturer_cleanup(struct
Quoted 8 lines
include/linux/mtd/spinand.h | 4 +++ 3 files changed, 49 insertions(+), 18 deletions(-)drivers/mtd/nand/spi/core.c +0
-0@@ -920,7 +920,7 @@ static void spinand_manufacturer_cleanup(struct
spinand_device*spinand)Review
Quoted 9 lines
drivers/mtd/nand/spi/core.c +1
-1return spinand->manufacturer->ops->cleanup (spinand); } -static const struct spi_mem_op * +const struct spi_mem_op *spinand_select_op_variant (struct spinand_device *spinand,const struct spinand_op_variants *variants) {(quoted diff) +0
-0
b/drivers/mtd/nand/spi/micron.cdrivers/mtd/nand/spi/micron.c static int micron_ecc_get_status(struct
Quoted 4 lines
index
95bc5264ebc1..6fde93ec23a1100644drivers/mtd/nand/spi/micron.c +0
-0@@ -90,22 +90,10 @@ static int micron_ecc_get_status(struct
spinand_device*spinand,Quoted 5 lines
drivers/mtd/nand/spi/micron.c +0
-2return -EINVAL ; } -static const struct spinand_info micron_spinand_table[] = { - SPINAND_INFO("MT29F2G01ABAGD", 0x24,drivers/mtd/nand/spi/micron.c static int micron_ecc_get_status(struct spinand_device *spinand, · line 104
Quoted 10 lines
drivers/mtd/nand/spi/micron.c +0
-10-NAND_MEMORG (1 ,2048 ,128 ,64 ,2048 ,40 ,2 ,1 ,1 ), -NAND_ECCREQ (8 ,512 ), -SPINAND_INFO_OP_VARIANTS (&read_cache_variants, - &write_cache_variants, - &update_cache_variants), -0 , -SPINAND_ECCINFO (µn_ooblayout_ops, - micron_ecc_get_status)), -}; -I don't know if it is wise to drop this structure.
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct
Quoted 9 lines
drivers/mtd/nand/spi/micron.c +1
-1static int micron_spinand_detect (struct spinand_device *spinand) { +const struct spi_mem_op *op;u8 *id = spinand->id.data; -int ret;/* * Micron SPI NAND read ID need a dummy byte, @@ -114,16 +102,55 @@ static int micron_spinand_detect(struct
spinand_device*spinand)Quoted 3 lines
drivers/mtd/nand/spi/micron.c +0
-0if (id[1 ] !=SPINAND_MFR_MICRON )return 0 ;
Quoted 7 lines
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct · line 118
Quoted 2 lines
drivers/mtd/nand/spi/micron.c +0
-2- ret = spinand_match_and_init(spinand, micron_spinand_table, - ARRAY_SIZE(micron_spinand_table),id[2]);
I am not sure this is the right solution. I would keep this call and overwrite what you need to overwrite with the fixup hook.
Then, I will have dummy structure like below.
static const struct spinand_info micron_spinand_table[] = {
SPINAND_INFO(NULL, 0,
NAND_MEMORG(0, 0, 0, 0, 0, 0, 0, 0, 0),
NAND_ECCREQ(0, 0),
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
&write_cache_variants,
&update_cache_variants),
0,
SPINAND_ECCINFO(µn_ooblayout_ops,
micron_ecc_get_status)),
}; Let me know if you are thinking for different approach.
Quoted 77 lines
Quoted 40 lines
drivers/mtd/nand/spi/micron.c +33
-2-if (ret) -return ret; + spinand->flags =0 ; + spinand->eccinfo.get_status = micron_ecc_get_status; + spinand->eccinfo.ooblayout = µn_ooblayout_ops; + + op =spinand_select_op_variant (spinand, + &read_cache_variants); +if (!op) +return -ENOTSUPP ; + + spinand->op_templates.read_cache = op; + + op =spinand_select_op_variant (spinand, + &write_cache_variants); +if (!op) +return -ENOTSUPP ; + + spinand->op_templates.write_cache = op; + + op =spinand_select_op_variant (spinand, + &update_cache_variants); + spinand->op_templates.update_cache = op;return 1 ; } +static void micron_fixup_param_page (struct spinand_device *spinand, +struct nand_onfi_params *p) +{ +/* +* As per Micron datasheets vendor[83] is defined as +* die_select_feature +*/ +if (p->vendor[83 ] && !p->interleaved_bits) + spinand->base.memorg.planes_per_lun =1 << p- vendor[0 ]; + + spinand->base.memorg.ntargets = p->lun_count; + spinand->base.memorg.luns_per_target =1 ;drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct spinand_device *spinand)
Quoted 10 lines
drivers/mtd/nand/spi/micron.c +9
-0+ +/* +* As per Micron datasheets, +* vendor[82] is ECC maximum correctability +*/ + spinand->base.eccreq.strength = p->vendor[82 ]; + spinand->base.eccreq.step_size =512 ; +} + static const struct spinand_manufacturer_ops
micron_spinand_manuf_ops= {include/linux/mtd/spinand.h int spinand_match_and_init(struct spinand_device
Quoted 10 lines
drivers/mtd/nand/spi/micron.c +1
-0.detect = micron_spinand_detect, + .fixup_param_page = micron_fixup_param_page, };const struct
spinand_manufacturermicron_spinand_manufacturer= {include/linux/mtd/spinand.h +0
-0@@ -461,4 +461,8 @@ int spinand_match_and_init(struct spinand_device*dev,
include/linux/mtd/spinand.h int spinand_match_and_init(struct spinand_device · line 462
Quoted 2 lines
include/linux/mtd/spinand.h +0
-0int spinand_upd_cfg (struct spinand_device *spinand,u8 mask,u8 val); int spinand_select_target(struct spinand_device *spinand, unsigned inttarget);
include/linux/mtd/spinand.h int spinand_match_and_init(struct spinand_device *dev, · line 468
Quoted 6 lines
include/linux/mtd/spinand.h +4
-0+const struct spi_mem_op * +spinand_select_op_variant (struct spinand_device *spinand, +const struct spinand_op_variants *variants); +#endif /* __LINUX_MTD_SPINAND_H */ Thanks,
Miquèl
Miquel Raynal
maintainerRe: [EXT] Re: [PATCH 6/8] mtd: spinand: micron: Turn driver implementation generic
Hi Boris,
I need your opinion on the question below.
"Shivamurthy Shastri (sshivamurthy)" <[email protected]> wrote on Mon, 19 Aug 2019 09:03:38 +0000:
Quoted 104 lines
Hi Miquel,
Quoted 80 lines
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:19 +0200:
Quoted 2 lines
From: Shivamurthy Shastri <[email protected]>
I am not sure the "turn implemenatation generic" title describes what you do.
Quoted 2 lines
Driver is redesigned using parameter page to support Micron SPI NAND flashes.
Redesigned is perhaps a bit too much.
"
Quoted 7 lines
The reason why
spinand_select_op_variantglobalized is that the Micron driver no longer callingspinand_match_and_init.Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/core.c | 2 +- drivers/mtd/nand/spi/micron.c | 61 +++++++++++++++++++++++++----------
drivers/mtd/nand/spi/core.c static void spinand_manufacturer_cleanup(struct
Quoted 8 lines
include/linux/mtd/spinand.h | 4 +++ 3 files changed, 49 insertions(+), 18 deletions(-)drivers/mtd/nand/spi/core.c +0
-0@@ -920,7 +920,7 @@ static void spinand_manufacturer_cleanup(struct
spinand_device*spinand)Review
Quoted 9 lines
drivers/mtd/nand/spi/core.c +1
-1return spinand->manufacturer->ops->cleanup (spinand); } -static const struct spi_mem_op * +const struct spi_mem_op *spinand_select_op_variant (struct spinand_device *spinand,const struct spinand_op_variants *variants) {(quoted diff) +0
-0
b/drivers/mtd/nand/spi/micron.cdrivers/mtd/nand/spi/micron.c static int micron_ecc_get_status(struct
Quoted 4 lines
index
95bc5264ebc1..6fde93ec23a1100644drivers/mtd/nand/spi/micron.c +0
-0@@ -90,22 +90,10 @@ static int micron_ecc_get_status(struct
spinand_device*spinand,Quoted 5 lines
drivers/mtd/nand/spi/micron.c +0
-2return -EINVAL ; } -static const struct spinand_info micron_spinand_table[] = { - SPINAND_INFO("MT29F2G01ABAGD", 0x24,drivers/mtd/nand/spi/micron.c static int micron_ecc_get_status(struct spinand_device *spinand, · line 104
Quoted 10 lines
drivers/mtd/nand/spi/micron.c +0
-10-NAND_MEMORG (1 ,2048 ,128 ,64 ,2048 ,40 ,2 ,1 ,1 ), -NAND_ECCREQ (8 ,512 ), -SPINAND_INFO_OP_VARIANTS (&read_cache_variants, - &write_cache_variants, - &update_cache_variants), -0 , -SPINAND_ECCINFO (µn_ooblayout_ops, - micron_ecc_get_status)), -}; -I don't know if it is wise to drop this structure.
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct
Quoted 9 lines
drivers/mtd/nand/spi/micron.c +1
-1static int micron_spinand_detect (struct spinand_device *spinand) { +const struct spi_mem_op *op;u8 *id = spinand->id.data; -int ret;/* * Micron SPI NAND read ID need a dummy byte, @@ -114,16 +102,55 @@ static int micron_spinand_detect(struct
spinand_device*spinand)Quoted 3 lines
drivers/mtd/nand/spi/micron.c +0
-0if (id[1 ] !=SPINAND_MFR_MICRON )return 0 ;Quoted 7 lines
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct · line 118
Quoted 2 lines
drivers/mtd/nand/spi/micron.c +0
-2- ret = spinand_match_and_init(spinand, micron_spinand_table, - ARRAY_SIZE(micron_spinand_table),id[2]);
I am not sure this is the right solution. I would keep this call and overwrite what you need to overwrite with the fixup hook.
Then, I will have dummy structure like below.
static const struct spinand_info micron_spinand_table[] = { SPINAND_INFO(NULL, 0, NAND_MEMORG(0, 0, 0, 0, 0, 0, 0, 0, 0), NAND_ECCREQ(0, 0), SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), 0, SPINAND_ECCINFO(µn_ooblayout_ops, micron_ecc_get_status)), };
Quoted 2 lines
Let me know if you are thinking for different approach.
Thanks,
Miquèl
RE: [EXT] Re: [PATCH 6/8] mtd: spinand: micron: Turn driver implementation generic
Hello Miquel & Boris,
Just a gentle reminder that I'd like some feedback.
Thanks,
Shiva
Quoted 121 lines
Hi Boris,
I need your opinion on the question below.
"Shivamurthy Shastri (sshivamurthy)" <[email protected]> wrote on
Mon, 19 Aug 2019 09:03:38 +0000:Quoted 20 lines
Hi Miquel,
Quoted 18 lines
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:19 +0200:
Quoted 2 lines
From: Shivamurthy Shastri <[email protected]>
I am not sure the "turn implemenatation generic" title describes what you do.
Quoted 2 lines
Driver is redesigned using parameter page to support Micron SPI NAND flashes.
Redesigned is perhaps a bit too much.
"
Quoted 1 line
The reason why
spinand_select_op_variantglobalized is that theMicron
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
driver no longer calling
spinand_match_and_init.Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/core.c | 2 +- drivers/mtd/nand/spi/micron.c | 61 +++++++++++++++++++++++++-------
Quoted 9 lines
Quoted 9 lines
---
drivers/mtd/nand/spi/core.c static void
Quoted 8 lines
include/linux/mtd/spinand.h | 4 +++ 3 files changed, 49 insertions(+), 18 deletions(-)drivers/mtd/nand/spi/core.c +0
-0@@ -920,7 +920,7 @@ static voidspinand_manufacturer_cleanup(struct
Quoted 69 lines
Quoted 47 lines
spinand_device*spinand)Review
Quoted 9 lines
drivers/mtd/nand/spi/core.c +1
-1return spinand->manufacturer->ops->cleanup (spinand); } -static const struct spi_mem_op * +const struct spi_mem_op *spinand_select_op_variant (struct spinand_device *spinand,const struct spinand_op_variants *variants) {(quoted diff) +0
-0
b/drivers/mtd/nand/spi/micron.cdrivers/mtd/nand/spi/micron.c static int micron_ecc_get_status(struct
Quoted 4 lines
index
95bc5264ebc1..6fde93ec23a1100644drivers/mtd/nand/spi/micron.c +0
-0@@ -90,22 +90,10 @@ static int micron_ecc_get_status(struct
spinand_device*spinand,Quoted 5 lines
drivers/mtd/nand/spi/micron.c +0
-2return -EINVAL ; } -static const struct spinand_info micron_spinand_table[] = { - SPINAND_INFO("MT29F2G01ABAGD", 0x24,drivers/mtd/nand/spi/micron.c static int micron_ecc_get_status(struct spinand_device *spinand, · line 104
Quoted 10 lines
drivers/mtd/nand/spi/micron.c +0
-10-NAND_MEMORG (1 ,2048 ,128 ,64 ,2048 ,40 ,2 ,1 ,1 ), -NAND_ECCREQ (8 ,512 ), -SPINAND_INFO_OP_VARIANTS (&read_cache_variants, - &write_cache_variants, - &update_cache_variants), -0 , -SPINAND_ECCINFO (µn_ooblayout_ops, - micron_ecc_get_status)), -}; -I don't know if it is wise to drop this structure.
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct
Quoted 9 lines
drivers/mtd/nand/spi/micron.c +1
-1static int micron_spinand_detect (struct spinand_device *spinand) { +const struct spi_mem_op *op;u8 *id = spinand->id.data; -int ret;/* * Micron SPI NAND read ID need a dummy byte, @@ -114,16 +102,55 @@ static int micron_spinand_detect(struct
spinand_device*spinand)Quoted 3 lines
drivers/mtd/nand/spi/micron.c +0
-0if (id[1 ] !=SPINAND_MFR_MICRON )return 0 ;Quoted 7 lines
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct · line 118
Quoted 2 lines
drivers/mtd/nand/spi/micron.c +0
-2- ret = spinand_match_and_init(spinand, micron_spinand_table, - ARRAY_SIZE(micron_spinand_table),id[2]);
I am not sure this is the right solution. I would keep this call and overwrite what you need to overwrite with the fixup hook.
Then, I will have dummy structure like below.
static const struct spinand_info micron_spinand_table[] = { SPINAND_INFO(NULL, 0, NAND_MEMORG(0, 0, 0, 0, 0, 0, 0, 0, 0), NAND_ECCREQ(0, 0), SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), 0, SPINAND_ECCINFO(µn_ooblayout_ops, micron_ecc_get_status)), };Quoted 2 lines
Let me know if you are thinking for different approach.
Thanks,
Miquèl
Re: [EXT] Re: [PATCH 6/8] mtd: spinand: micron: Turn driver implementation generic
In reply to Shivamurthy Shastri (sshivamurthy)Quoted 14 lines · On Mon, 19 Aug 2019 09:03:38 +0000 "Shivamurthy Shastri (sshivamurthy)"…
Quoted 14 lines
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct
Quoted 10 lines
static int
micron_spinand_detect(struct spinand_device *spinand){drivers/mtd/nand/spi/micron.c +1
-1+const struct spi_mem_op *op;u8 *id = spinand->id.data; -int ret;/* * Micron SPI NAND read ID need a dummy byte, @@ -114,16 +102,55 @@ static int micron_spinand_detect(struct
spinand_device*spinand)Quoted 3 lines
drivers/mtd/nand/spi/micron.c +0
-0if (id[1 ] !=SPINAND_MFR_MICRON )return 0 ;
Quoted 7 lines
Quoted 7 lines
Review static int micron_spinand_detect(struct · line 118
Quoted 2 lines
(quoted diff) +0
-2- ret = spinand_match_and_init(spinand, micron_spinand_table, - ARRAY_SIZE(micron_spinand_table),id[2]);
I am not sure this is the right solution. I would keep this call and overwrite what you need to overwrite with the fixup hook.
I'm definitely not comfortable with this whole "rely on ONFi param-page" thing. Vendors have proven to get it wrong from time to time, so before we do that, I'd like to make sure all currently supported Micron NANDs (looks like we only support MT29F2G01ABAGD, so that shouldn't be hard) expose the right thing there. For instance, are we sure the ECC layout is always the same, and if not, do we have a reliable way to extract that?
Quoted 16 lines
Then, I will have dummy structure like below.
static const struct spinand_info micron_spinand_table[] = { SPINAND_INFO(NULL, 0, NAND_MEMORG(0, 0, 0, 0, 0, 0, 0, 0, 0), NAND_ECCREQ(0, 0), SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), 0, SPINAND_ECCINFO(µn_ooblayout_ops, micron_ecc_get_status)), };
Quoted 1 line
Let me know if you are thinking for different approach.
Exposing dummy entries is useless. If you're entirely sure all Micron SPI NANDs have a valid ONFi param page, then no need to use the ID-based detection. But as I said above, I feel param-page-based detection is going to be as messy as SFDP-based detection is for SPI NORs. Vendors tend to make mistakes which we have to fix to make things work. ID-based detection is much more reliable in this regard, as long as we don't have ID collisions :P.
Plus, it looks like only a few manufacturers decided to use ONFi param pages to expose SPI NAND info (AFAICT, only Micron and Macronix do that), which is not surprising since the ONFi param page has been created to describe parallel NANDs not SPI NANDs (if you look closely enough, you'll notice that some fields are meaningless for SPI NANDs).
RE: [EXT] Re: [PATCH 6/8] mtd: spinand: micron: Turn driver implementation generic
Hi Boris,
Thank you for the review.
Quoted 52 lines
Quoted 14 lines · On Mon, 19 Aug 2019 09:03:38 +0000 "Shivamurthy Shastri (sshivamurthy)"…
Quoted 14 lines
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct
Quoted 10 lines
static int
micron_spinand_detect(struct spinand_device *spinand){drivers/mtd/nand/spi/micron.c +1
-1+const struct spi_mem_op *op;u8 *id = spinand->id.data; -int ret;/* * Micron SPI NAND read ID need a dummy byte, @@ -114,16 +102,55 @@ static int micron_spinand_detect(struct
spinand_device*spinand)Quoted 3 lines
drivers/mtd/nand/spi/micron.c +0
-0if (id[1 ] !=SPINAND_MFR_MICRON )return 0 ;Quoted 7 lines
Quoted 7 lines
Review static int micron_spinand_detect(struct · line 118
Quoted 2 lines
(quoted diff) +0
-2- ret = spinand_match_and_init(spinand, micron_spinand_table, - ARRAY_SIZE(micron_spinand_table),id[2]);
I am not sure this is the right solution. I would keep this call and overwrite what you need to overwrite with the fixup hook.
I'm definitely not comfortable with this whole "rely on ONFi param-page" thing. Vendors have proven to get it wrong from time to time, so before we do that, I'd like to make sure all currently supported Micron NANDs (looks like we only support MT29F2G01ABAGD, so that shouldn't be hard) expose the right thing there. For instance, are we sure the ECC layout is always the same, and if not, do we have a reliable way to extract that?
Quoted 16 lines
Then, I will have dummy structure like below.
static const struct spinand_info micron_spinand_table[] = { SPINAND_INFO(NULL, 0, NAND_MEMORG(0, 0, 0, 0, 0, 0, 0, 0, 0), NAND_ECCREQ(0, 0), SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), 0, SPINAND_ECCINFO(µn_ooblayout_ops, micron_ecc_get_status)), };Quoted 1 line
Let me know if you are thinking for different approach.
Quoted 12 lines
Exposing dummy entries is useless. If you're entirely sure all Micron SPI NANDs have a valid ONFi param page, then no need to use the ID-based detection. But as I said above, I feel param-page-based detection is going to be as messy as SFDP-based detection is for SPI NORs. Vendors tend to make mistakes which we have to fix to make things work. ID-based detection is much more reliable in this regard, as long as we don't have ID collisions :P.
Plus, it looks like only a few manufacturers decided to use ONFi param pages to expose SPI NAND info (AFAICT, only Micron and Macronix do that), which is not surprising since the ONFi param page has been created to describe parallel NANDs not SPI NANDs (if you look closely enough, you'll notice that some fields are meaningless for SPI NANDs).
Okay, I will send new patches with ID-based detection for the new devices.
Thanks,
Shiva
PATCH 7/8 mtd: spinand: micron: Fix read failure in Micron M70A flashes
In reply to [email protected]From: Shivamurthy Shastri <[email protected]>
M70A series flashes by default enable continuous read feature (BIT0 in configuration register). This feature will not expose the ECC to host and causing read failure.
--- drivers/mtd/nand/spi/micron.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/mtd/nand/spi/micron.c +10 -0
@@ -127,6 +127,15 @@ static int micron_spinand_detect(struct spinand_device *spinand)return 1 ; } +static int micron_spinand_init (struct spinand_device *spinand) +{ +/* +* Some of the Micron flashes enable this BIT by default, +* and there is a chance of read failure due to this. +*/ +return spinand_upd_cfg (spinand,CFG_QUAD_ENABLE ,0 ); +} +static void micron_fixup_param_page (struct spinand_device *spinand,struct nand_onfi_params *p) {
@@ -150,6 +159,7 @@ static void micron_fixup_param_page(struct spinand_device *spinand,static const struct spinand_manufacturer_ops micron_spinand_manuf_ops = { .detect = micron_spinand_detect, + .init = micron_spinand_init, .fixup_param_page = micron_fixup_param_page, };
Signature · 1 line
2.17.1
Re: [PATCH 7/8] mtd: spinand: micron: Fix read failure in Micron M70A flashes
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:20 +0200:
Quoted 5 lines
From: Shivamurthy Shastri <[email protected]>
M70A series flashes by default enable continuous read feature (BIT0 in configuration register). This feature will not expose the ECC to host and causing read failure.
This is not readable enough, can you rephrase? Besides that you can add my
Quoted 27 lines
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/micron.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/mtd/nand/spi/micron.c +9
-0@@ -127,6 +127,15 @@ static int micron_spinand_detect(struct spinand_device *spinand)return 1 ; } +static int micron_spinand_init (struct spinand_device *spinand) +{ +/* +* Some of the Micron flashes enable this BIT by default, +* and there is a chance of read failure due to this. +*/ +return spinand_upd_cfg (spinand,CFG_QUAD_ENABLE ,0 ); +} +static void micron_fixup_param_page (struct spinand_device *spinand,struct nand_onfi_params *p) {
drivers/mtd/nand/spi/micron.c static void micron_fixup_param_page(struct spinand_device *spinand, · line 165
Quoted 7 lines
drivers/mtd/nand/spi/micron.c +1
-0@@ -150,6 +159,7 @@ static void micron_fixup_param_page(struct spinand_device *spinand,static const struct spinand_manufacturer_ops micron_spinand_manuf_ops = { .detect = micron_spinand_detect, + .init = micron_spinand_init, .fixup_param_page = micron_fixup_param_page, };
Thanks,
Miquèl
PATCH 8/8 mtd: spinand: micron: Enable micron flashes with multi-die
In reply to [email protected]From: Shivamurthy Shastri <[email protected]>
Some of the Micron flashes has multi-die, and need to select the die each time while accessing it.
--- drivers/mtd/nand/spi/micron.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/mtd/nand/spi/micron.c +14 -0
@@ -90,6 +90,19 @@ static int micron_ecc_get_status(struct spinand_device *spinand,return -EINVAL ; } +static int micron_select_target (struct spinand_device *spinand, +unsigned int target) +{ +struct spi_mem_op op =SPINAND_SET_FEATURE_OP (0xd0 , + spinand->scratchbuf); + +if (target ==1 ) + target =0x40 ; + + *spinand->scratchbuf = target; +return spi_mem_exec_op (spinand->spimem, &op); +} +static int micron_spinand_detect (struct spinand_device *spinand) {const struct spi_mem_op *op;
@@ -105,6 +118,7 @@ static int micron_spinand_detect(struct spinand_device *spinand) spinand->flags =0 ; spinand->eccinfo.get_status = micron_ecc_get_status; spinand->eccinfo.ooblayout = µn_ooblayout_ops; + spinand->select_target = micron_select_target; op =spinand_select_op_variant (spinand, &read_cache_variants);
Signature · 1 line
2.17.1
Miquel Raynal
maintainerRe: [PATCH 8/8] mtd: spinand: micron: Enable micron flashes with multi-die
Hi Shiva,
[email protected] wrote on Mon, 22 Jul 2019 07:56:21 +0200:
"with multiple dies" in the title
Quoted 3 lines
From: Shivamurthy Shastri <[email protected]>
Some of the Micron flashes has multi-die, and need to select the die
have multiple dies and
Quoted 12 lines
each time while accessing it.
Signed-off-by Shivamurthy Shastri <[email protected]>--- drivers/mtd/nand/spi/micron.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/mtd/nand/spi/micron.c +0
-0
drivers/mtd/nand/spi/micron.c static int micron_ecc_get_status(struct spinand_device *spinand, · line 92
Quoted 3 lines
drivers/mtd/nand/spi/micron.c +0
-0@@ -90,6 +90,19 @@ static int micron_ecc_get_status(struct spinand_device *spinand,return -EINVAL ; }
Please explain in a comment what you do here, like in the commit title.
drivers/mtd/nand/spi/micron.c static int micron_ecc_get_status(struct spinand_device *spinand, · line 102
Quoted 10 lines
drivers/mtd/nand/spi/micron.c +10
-0+static int micron_select_target (struct spinand_device *spinand, +unsigned int target) +{ +struct spi_mem_op op =SPINAND_SET_FEATURE_OP (0xd0 , + spinand->scratchbuf); + +if (target ==1 ) + target =0x40 ; + + *spinand->scratchbuf = target;
if (target == 1)
*spinand->scratchbuf = 0x40
space
Quoted 7 lines
drivers/mtd/nand/spi/micron.c +3
-0+return spi_mem_exec_op (spinand->spimem, &op); +} +static int micron_spinand_detect (struct spinand_device *spinand) {const struct spi_mem_op *op;
drivers/mtd/nand/spi/micron.c static int micron_spinand_detect(struct spinand_device *spinand) · line 124
Quoted 7 lines
drivers/mtd/nand/spi/micron.c +1
-0@@ -105,6 +118,7 @@ static int micron_spinand_detect(struct spinand_device *spinand) spinand->flags =0 ; spinand->eccinfo.get_status = micron_ecc_get_status; spinand->eccinfo.ooblayout = µn_ooblayout_ops; + spinand->select_target = micron_select_target; op =spinand_select_op_variant (spinand, &read_cache_variants);
Thanks,
Miquèl