Skip to contentSkip to conversation

About the SLC/MLC

PATCH In review Huang Shijie 3 participants 20 messages Sep 25, 2013 – Oct 8, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover About the SLC/MLC

In current mtd code, the MTD_NANDFLASH is used to represent both the SLC nand MLC(including the TLC). But we already have the MTD_MLCNANDFLASH to stand for the MLC. What is worse is that the JFFS2 may run on the MLC nand with current code. For the reason of READ/WRITE disturbance, the JFFS2 should runs on the SLC only,

This patch set tries to make clear what is the SLC/MLC by adding the macros, adding helpers, adding the comments. ..

After this patch set, the gpmi can support the JFFS2 for some SLC NAND now (only when the left oob area is big enough).

v3 --> v4:
[0] rename the cellinfo after introducing the nand_is_slc().
[1] change the order of the patches.
[2] add more comment for patch:
"mtd: nand: fix the wrong mtd->type for nand chip"

v2 --> v3:
[0] fix the wrong patch for jffs2.
[1] add more comments to nand_get_bits_per_cell().
[2] others.

v1 --> v2:
[0] rename the @cellinfo to @bits_per_cell
[1] abandon the patch: "mtd: add more information for the MTD_NANDFLASH case"
[2] update the ABI for patch 8
[3] misc

Huang Shijie (12):
mtd: nand: add a helper to check the SLC/MLC nand chip
mtd: nand: rename the cellinfo to bits_per_cell
mtd: nand: add the "bits per cell" info for legacy ID NAND
mtd: nand: set the cell information for ONFI nand
mtd: nand: print out the cell information for nand chip
mtd: gpmi: rewrite the gpmi_ecc_write_oob() to support the jffs2
mtd: nand: add more comment for MTD_NANDFLASH/MTD_MLCNANDFLASH
mtd: nand: add a helper to detect the nand type
mtd: mtd-abi: add a helper to detect the nand type
mtd: add MTD_MLCNANDFLASH case for mtd_type_show()
jffs2: do not support the MLC nand
mtd: nand: fix the wrong mtd->type for nand chip

 Documentation/ABI/testing/sysfs-class-mtd |    2 +-
 drivers/mtd/inftlcore.c                   |    2 +-
 drivers/mtd/mtdcore.c                     |    3 ++
 drivers/mtd/nand/denali.c                 |    2 +-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c    |   31 ++++++++++++++------
 drivers/mtd/nand/nand_base.c              |   45 +++++++++++++++++++---------
 drivers/mtd/nftlcore.c                    |    2 +-
 drivers/mtd/ssfdc.c                       |    2 +-
 drivers/mtd/tests/nandbiterrs.c           |    2 +-
 drivers/mtd/tests/oobtest.c               |    2 +-
 drivers/mtd/tests/pagetest.c              |    2 +-
 drivers/mtd/tests/subpagetest.c           |    2 +-
 fs/jffs2/fs.c                             |    4 ++
 include/linux/mtd/mtd.h                   |    5 +++
 include/linux/mtd/nand.h                  |   14 ++++++++-
 include/uapi/mtd/mtd-abi.h                |    9 ++++-
 16 files changed, 92 insertions(+), 37 deletions(-)
#1 lore raw

PATCH v4 1/12 mtd: nand: add a helper to check the SLC/MLC nand chip

Add a helper to check if a nand chip is SLC or MLC. This helper makes the code more readable.

---
 drivers/mtd/nand/denali.c    |    2 +-
 drivers/mtd/nand/nand_base.c |   14 ++++++--------
 include/linux/mtd/nand.h     |    9 +++++++++
 3 files changed, 16 insertions(+), 9 deletions(-)
drivers/mtd/nand/denali.c +1 -1
index 154b033..370b9dd 100644
@@ -1520,7 +1520,7 @@ int denali_init(struct denali_nand_info *denali)
 	 * so just let controller do 15bit ECC for MLC and 8bit ECC for
 	 * SLC if possible.
 	 * */
-	if (denali->nand.cellinfo & NAND_CI_CELLTYPE_MSK &&
+	if (!nand_is_slc(&denali->nand) &&
 			(denali->mtd.oobsize > (denali->bbtskipbytes +
 			ECC_15BITS * (denali->mtd.writesize /
 			ECC_SECTOR_SIZE)))) {
drivers/mtd/nand/nand_base.c +6 -8
index 00022b4..f256385 100644
@@ -3107,8 +3107,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
 	 * ID to decide what to do.
 	 */
 	if (id_len == 6 && id_data[0] == NAND_MFR_SAMSUNG &&
-			(chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
-			id_data[5] != 0x00) {
+			!nand_is_slc(chip) && id_data[5] != 0x00) {
 		/* Calc pagesize */
 		mtd->writesize = 2048 << (extid & 0x03);
 		extid >>= 2;
@@ -3140,7 +3139,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
 			(((extid >> 1) & 0x04) | (extid & 0x03));
 		*busw = 0;
 	} else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX &&
-			(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
+			!nand_is_slc(chip)) {
 		unsigned int tmp;
 
 		/* Calc pagesize */
@@ -3203,7 +3202,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
 		 * - ID byte 5, bit[7]:    1 -> BENAND, 0 -> raw SLC
 		 */
 		if (id_len >= 6 && id_data[0] == NAND_MFR_TOSHIBA &&
-				!(chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
+				nand_is_slc(chip) &&
 				(id_data[5] & 0x7) == 0x6 /* 24nm */ &&
 				!(id_data[4] & 0x80) /* !BENAND */) {
 			mtd->oobsize = 32 * mtd->writesize >> 9;
@@ -3264,11 +3263,11 @@ static void nand_decode_bbm_options(struct mtd_info *mtd,
 	 * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba,
 	 * AMD/Spansion, and Macronix.  All others scan only the first page.
 	 */
-	if ((chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
+	if (!nand_is_slc(chip) &&
 			(maf_id == NAND_MFR_SAMSUNG ||
 			 maf_id == NAND_MFR_HYNIX))
 		chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
-	else if ((!(chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
+	else if ((nand_is_slc(chip) &&
 				(maf_id == NAND_MFR_SAMSUNG ||
 				 maf_id == NAND_MFR_HYNIX ||
 				 maf_id == NAND_MFR_TOSHIBA ||
@@ -3744,8 +3743,7 @@ int nand_scan_tail(struct mtd_info *mtd)
 	chip->ecc.total = chip->ecc.steps * chip->ecc.bytes;
 
 	/* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
-	if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
-	    !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
+	if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && nand_is_slc(chip)) {
 		switch (chip->ecc.steps) {
 		case 2:
 			mtd->subpage_sft = 1;
include/linux/mtd/nand.h +9 -0
index 1295481..5c05bab 100644
@@ -795,4 +795,13 @@ static inline int onfi_get_sync_timing_mode(struct nand_chip *chip)
 	return le16_to_cpu(chip->onfi_params.src_sync_timing_mode);
 }
 
+/*
+ * Check if it is a SLC nand.
+ * The !nand_is_slc() can be used to check the MLC/TLC nand chips.
+ * We do not distinguish the MLC and TLC now.
+ */
+static inline bool nand_is_slc(struct nand_chip *chip)
+{
+	return !(chip->cellinfo & NAND_CI_CELLTYPE_MSK);
+}
 #endif /* __LINUX_MTD_NAND_H */
Signature · 1 line
1.7.1
#2 lore raw

PATCH v4 2/12 mtd: nand: rename the cellinfo to bits_per_cell

In reply to Huang Shijie

The @cellinfo fields contains unused information, such as write caching, internal chip numbering, etc. But we only use it to check the SLC or MLC.

This patch tries to make it more clear and simple, renames the @cellinfo to @bits_per_cell.

In order to avoiding the bisect issue, this patch also does the following changes:
(0) add a macro NAND_CI_CELLTYPE_SHIFT to avoid the hardcode.

(1) add a helper to parse out the cell type : nand_get_bits_per_cell()

(2) parse out the cell type for extended-ID chips and the full-id nand chips.

---
 drivers/mtd/nand/nand_base.c |   14 ++++++++++++--
 include/linux/mtd/nand.h     |    7 ++++---
 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/mtd/nand/nand_base.c +12 -2
index f256385..c84c35f 100644
@@ -3081,6 +3081,16 @@ static int nand_id_len(u8 *id_data, int arrlen)
 	return arrlen;
 }
 
+/* Extract the bits of per cell from the 3rd byte of the extended ID */
+static int nand_get_bits_per_cell(u8 cellinfo)
+{
+	int bits;
+
+	bits = cellinfo & NAND_CI_CELLTYPE_MSK;
+	bits >>= NAND_CI_CELLTYPE_SHIFT;
+	return bits + 1;
+}
+
 /*
  * Many new NAND share similar device ID codes, which represent the size of the
  * chip. The rest of the parameters must be decoded according to generic or
@@ -3091,7 +3101,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
 {
 	int extid, id_len;
 	/* The 3rd id byte holds MLC / multichip data */
-	chip->cellinfo = id_data[2];
+	chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]);
 	/* The 4th id byte is the important one */
 	extid = id_data[3];
 
@@ -3291,7 +3301,7 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip,
 		mtd->erasesize = type->erasesize;
 		mtd->oobsize = type->oobsize;
 
-		chip->cellinfo = id_data[2];
+		chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]);
 		chip->chipsize = (uint64_t)type->chipsize << 20;
 		chip->options |= type->options;
 		chip->ecc_strength_ds = NAND_ECC_STRENGTH(type);
include/linux/mtd/nand.h +4 -3
index 5c05bab..0eb4a63 100644
@@ -198,6 +198,7 @@ typedef enum {
 /* Cell info constants */
 #define NAND_CI_CHIPNR_MSK	0x03
 #define NAND_CI_CELLTYPE_MSK	0x0C
+#define NAND_CI_CELLTYPE_SHIFT	2
 
 /* Keep gcc happy */
 struct nand_chip;
@@ -477,7 +478,7 @@ struct nand_buffers {
  * @badblockbits:	[INTERN] minimum number of set bits in a good block's
  *			bad block marker position; i.e., BBM == 11110111b is
  *			not bad when badblockbits == 7
- * @cellinfo:		[INTERN] MLC/multichip data from chip ident
+ * @bits_per_cell:	[INTERN] the bits of per cell. i.e., 1 means SLC.
  * @ecc_strength_ds:	[INTERN] ECC correctability from the datasheet.
  *			Minimum amount of bit errors per @ecc_step_ds guaranteed
  *			to be correctable. If unknown, set to zero.
@@ -558,7 +559,7 @@ struct nand_chip {
 	int pagebuf;
 	unsigned int pagebuf_bitflips;
 	int subpagesize;
-	uint8_t cellinfo;
+	uint8_t bits_per_cell;
 	uint16_t ecc_strength_ds;
 	uint16_t ecc_step_ds;
 	int badblockpos;
@@ -802,6 +803,6 @@ static inline int onfi_get_sync_timing_mode(struct nand_chip *chip)
  */
 static inline bool nand_is_slc(struct nand_chip *chip)
 {
-	return !(chip->cellinfo & NAND_CI_CELLTYPE_MSK);
+	return chip->bits_per_cell == 1;
 }
 #endif /* __LINUX_MTD_NAND_H */
Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH v4 02/12] mtd: nand: rename the cellinfo to bits_per_cell

Quoted 25 lines · Huang Shijie

The @cellinfo fields contains unused information, such as write caching, internal chip numbering, etc. But we only use it to check the SLC or MLC.

This patch tries to make it more clear and simple, renames the @cellinfo to @bits_per_cell.

In order to avoiding the bisect issue, this patch also does the following changes:
(0) add a macro NAND_CI_CELLTYPE_SHIFT to avoid the hardcode.

(1) add a helper to parse out the cell type : nand_get_bits_per_cell()

(2) parse out the cell type for extended-ID chips and the full-id nand chips.

---
 drivers/mtd/nand/nand_base.c |   14 ++++++++++++--
 include/linux/mtd/nand.h     |    7 ++++---
 2 files changed, 16 insertions(+), 5 deletions(-)
include/linux/mtd/nand.h +0 -0
index 5c05bab..0eb4a63 100644

include/linux/mtd/nand.h struct nand_buffers { · line 481

Quoted 5 lines
include/linux/mtd/nand.h +1 -1
@@ -477,7 +478,7 @@ struct nand_buffers {
  * @badblockbits:	[INTERN] minimum number of set bits in a good block's
  *			bad block marker position; i.e., BBM == 11110111b is
  *			not bad when badblockbits == 7
- * @cellinfo:		[INTERN] MLC/multichip data from chip ident
+ * @bits_per_cell:	[INTERN] the bits of per cell. i.e., 1 means SLC.

s/bits of/number of bits/

include/linux/mtd/nand.h struct nand_buffers { · line 484

Quoted 3 lines
include/linux/mtd/nand.h +0 -0
  * @ecc_strength_ds:	[INTERN] ECC correctability from the datasheet.
  *			Minimum amount of bit errors per @ecc_step_ds guaranteed
  *			to be correctable. If unknown, set to zero.

I'll squash that change into the patch myself if the rest looks good.

Brian

#4 lore raw

PATCH v4 3/12 mtd: nand: add the "bits per cell" info for legacy ID NAND

In reply to Huang Shijie

The legacy ID NAND are all SLC.
This patch sets 1 to the @bits_per_cell for the legacy ID NAND, which means they are all SLC.

---
 drivers/mtd/nand/nand_base.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/mtd/nand/nand_base.c +3 -0
index c84c35f..0dedf71 100644
@@ -3237,6 +3237,9 @@ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip,
 	mtd->oobsize = mtd->writesize / 32;
 	*busw = type->options & NAND_BUSWIDTH_16;
 
+	/* All legacy ID NAND are small-page, SLC */
+	chip->bits_per_cell = 1;
+
 	/*
 	 * Check for Spansion/AMD ID + repeating 5th, 6th byte since
 	 * some Spansion chips have erasesize that conflicts with size
Signature · 1 line
1.7.1
#5 lore raw

PATCH v4 4/12 mtd: nand: set the cell information for ONFI nand

In reply to Huang Shijie

The current code does not set the SLC/MLC information for onfi nand. (This makes that the kernel treats all the onfi nand as SLC nand.)

This patch fills the cell information for ONFI nands.

---
 drivers/mtd/nand/nand_base.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/mtd/nand/nand_base.c +1 -0
index 0dedf71..94d9084 100644
@@ -2991,6 +2991,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
 	mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page);
 	chip->chipsize = le32_to_cpu(p->blocks_per_lun);
 	chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count;
+	chip->bits_per_cell = p->bits_per_cell;
 
 	if (onfi_feature(chip) & ONFI_FEATURE_16_BIT_BUS)
 		*busw = NAND_BUSWIDTH_16;
Signature · 1 line
1.7.1
#6 lore raw

PATCH v4 5/12 mtd: nand: print out the cell information for nand chip

In reply to Huang Shijie

Print out the cell information for nand chip.

(Since the message is too long, this patch also splits the log with two separate pr_info())

---
 drivers/mtd/nand/nand_base.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/mtd/nand/nand_base.c +7 -4
index 94d9084..b94309b 100644
@@ -3460,11 +3460,14 @@ ident_done:
 	if (mtd->writesize > 512 && chip->cmdfunc == nand_command)
 		chip->cmdfunc = nand_command_lp;
 
-	pr_info("NAND device: Manufacturer ID: 0x%02x, Chip ID: 0x%02x (%s %s),"
-		" %dMiB, page size: %d, OOB size: %d\n",
+	pr_info("NAND device: Manufacturer ID: 0x%02x,"
+			"Chip ID: 0x%02x (%s %s) \n",
 		*maf_id, *dev_id, nand_manuf_ids[maf_idx].name,
-		chip->onfi_version ? chip->onfi_params.model : type->name,
-		(int)(chip->chipsize >> 20), mtd->writesize, mtd->oobsize);
+		chip->onfi_version ? chip->onfi_params.model : type->name);
+
+	pr_info("NAND device: %dMiB, %s, page size: %d, OOB size: %d\n",
+		(int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC",
+		mtd->writesize, mtd->oobsize);
 
 	return type;
 }
Signature · 1 line
1.7.1
#7 lore raw

Re: [PATCH v4 05/12] mtd: nand: print out the cell information for nand chip

Quoted 15 lines · Huang Shijie

Print out the cell information for nand chip.

(Since the message is too long, this patch also splits the log with two separate pr_info())

---
 drivers/mtd/nand/nand_base.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/mtd/nand/nand_base.c +0 -0
index 94d9084..b94309b 100644

drivers/mtd/nand/nand_base.c ident_done: · line 3464

Quoted 7 lines
drivers/mtd/nand/nand_base.c +2 -2
@@ -3460,11 +3460,14 @@ ident_done:
 	if (mtd->writesize > 512 && chip->cmdfunc == nand_command)
 		chip->cmdfunc = nand_command_lp;
 
-	pr_info("NAND device: Manufacturer ID: 0x%02x, Chip ID: 0x%02x (%s %s),"
-		" %dMiB, page size: %d, OOB size: %d\n",
+	pr_info("NAND device: Manufacturer ID: 0x%02x,"
+			"Chip ID: 0x%02x (%s %s) \n",

You're adding excess whitespace before the '\n'. I'll squash this myself.

drivers/mtd/nand/nand_base.c ident_done: · line 3473

Quoted 11 lines
drivers/mtd/nand/nand_base.c +5 -2
 		*maf_id, *dev_id, nand_manuf_ids[maf_idx].name,
-		chip->onfi_version ? chip->onfi_params.model : type->name,
-		(int)(chip->chipsize >> 20), mtd->writesize, mtd->oobsize);
+		chip->onfi_version ? chip->onfi_params.model : type->name);
+
+	pr_info("NAND device: %dMiB, %s, page size: %d, OOB size: %d\n",
+		(int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC",
+		mtd->writesize, mtd->oobsize);
 
 	return type;
 }

Brian

#8 lore raw

Re: [PATCH v4 05/12] mtd: nand: print out the cell information for nand chip

Quoted 19 lines · Brian Norris
Quoted 18 lines · Huang Shijie

Print out the cell information for nand chip.

(Since the message is too long, this patch also splits the log with two separate pr_info())

---
 drivers/mtd/nand/nand_base.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/mtd/nand/nand_base.c +0 -0
index 94d9084..b94309b 100644
@@ -3460,11 +3460,14 @@ ident_done:
 	if (mtd->writesize > 512 && chip->cmdfunc == nand_command)
 		chip->cmdfunc = nand_command_lp;
 
Quoted 7 lines

drivers/mtd/nand/nand_base.c ident_done: · line 3464

Quoted 4 lines
drivers/mtd/nand/nand_base.c +2 -2
-	pr_info("NAND device: Manufacturer ID: 0x%02x, Chip ID: 0x%02x (%s %s),"
-		" %dMiB, page size: %d, OOB size: %d\n",
+	pr_info("NAND device: Manufacturer ID: 0x%02x,"
+			"Chip ID: 0x%02x (%s %s) \n",

You're adding excess whitespace before the '\n'. I'll squash this myself.

Nowadays' fashion is to never split strings, Huang.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#9 lore raw

Re: [PATCH v4 05/12] mtd: nand: print out the cell information for nand chip

Quoted 28 lines · Artem Bityutskiy
Quoted 19 lines · Brian Norris
Quoted 18 lines · Huang Shijie

Print out the cell information for nand chip.

(Since the message is too long, this patch also splits the log with two separate pr_info())

---
  drivers/mtd/nand/nand_base.c |   11 +++++++----
  1 files changed, 7 insertions(+), 4 deletions(-)
drivers/mtd/nand/nand_base.c +0 -0
index 94d9084..b94309b 100644
@@ -3460,11 +3460,14 @@ ident_done:
  	if (mtd->writesize > 512 && chip->cmdfunc == nand_command)
  		chip->cmdfunc = nand_command_lp;
 
Quoted 7 lines

drivers/mtd/nand/nand_base.c ident_done: · line 3464

Quoted 4 lines
drivers/mtd/nand/nand_base.c +2 -2
-	pr_info("NAND device: Manufacturer ID: 0x%02x, Chip ID: 0x%02x (%s %s),"
-		" %dMiB, page size: %d, OOB size: %d\n",
+	pr_info("NAND device: Manufacturer ID: 0x%02x,"
+			"Chip ID: 0x%02x (%s %s) \n",

You're adding excess whitespace before the '\n'. I'll squash this myself.

Quoted 1 line

Nowadays' fashion is to never split strings, Huang.

checkpatch.pl actually warns about this now, so I already fixed it but didn't remember to mention it. Also, in splitting this string, Huang removed a space (fixed as well).

Brian

#10 lore raw

PATCH v4 6/12 mtd: gpmi: rewrite the gpmi_ecc_write_oob() to support the jffs2

In reply to Huang Shijie

When we use the ECC info which is get from the nand chip's datasheet, we may have some freed oob area now.

This patch rewrites the gpmi_ecc_write_oob() to implement the ecc.write_oob(). We also update the comment for gpmi_hw_ecclayout.

Yes! We can support the JFFS2 for the SLC nand now.

---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +22 -9
index b4306bc..eba7b79 100644
@@ -45,7 +45,10 @@ static struct nand_bbt_descr gpmi_bbt_descr = {
 	.pattern	= scan_ff_pattern
 };
 
-/*  We will use all the (page + OOB). */
+/*
+ * We may change the layout if we can get the ECC info from the datasheet,
+ * else we will use all the (page + OOB).
+ */
 static struct nand_ecclayout gpmi_hw_ecclayout = {
 	.eccbytes = 0,
 	.eccpos = { 0, },
@@ -1262,14 +1265,24 @@ static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
 static int
 gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page)
 {
-	/*
-	 * The BCH will use all the (page + oob).
-	 * Our gpmi_hw_ecclayout can only prohibit the JFFS2 to write the oob.
-	 * But it can not stop some ioctls such MEMWRITEOOB which uses
-	 * MTD_OPS_PLACE_OOB. So We have to implement this function to prohibit
-	 * these ioctls too.
-	 */
-	return -EPERM;
+	struct nand_oobfree *of = mtd->ecclayout->oobfree;
+	int status = 0;
+
+	/* Do we have available oob area? */
+	if (!of->length)
+		return -EPERM;
+
+	if (!nand_is_slc(chip))
+		return -EPERM;
+
+	pr_debug("page number is %d\n", page);
+
+	chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + of->offset, page);
+	chip->write_buf(mtd, chip->oob_poi + of->offset, of->length);
+	chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
+
+	status = chip->waitfunc(mtd, chip);
+	return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
 
 static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs)
Signature · 1 line
1.7.1
#11 lore raw

Re: [PATCH v4 06/12] mtd: gpmi: rewrite the gpmi_ecc_write_oob() to support the jffs2

Quoted 42 lines · Huang Shijie

When we use the ECC info which is get from the nand chip's datasheet, we may have some freed oob area now.

This patch rewrites the gpmi_ecc_write_oob() to implement the ecc.write_oob(). We also update the comment for gpmi_hw_ecclayout.

Yes! We can support the JFFS2 for the SLC nand now.

---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +5 -9
index b4306bc..eba7b79 100644
@@ -45,7 +45,10 @@ static struct nand_bbt_descr gpmi_bbt_descr = {
 	.pattern	= scan_ff_pattern
 };
 
-/*  We will use all the (page + OOB). */
+/*
+ * We may change the layout if we can get the ECC info from the datasheet,
+ * else we will use all the (page + OOB).
+ */
 static struct nand_ecclayout gpmi_hw_ecclayout = {
 	.eccbytes = 0,
 	.eccpos = { 0, },
@@ -1262,14 +1265,24 @@ static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
 static int
 gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page)
 {
-	/*
-	 * The BCH will use all the (page + oob).
-	 * Our gpmi_hw_ecclayout can only prohibit the JFFS2 to write the oob.
-	 * But it can not stop some ioctls such MEMWRITEOOB which uses
-	 * MTD_OPS_PLACE_OOB. So We have to implement this function to prohibit
-	 * these ioctls too.
-	 */
-	return -EPERM;
+	struct nand_oobfree *of = mtd->ecclayout->oobfree;

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip, · line 1278

Quoted 10 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +10 -0
+	int status = 0;
+
+	/* Do we have available oob area? */
+	if (!of->length)
+		return -EPERM;
+
+	if (!nand_is_slc(chip))
+		return -EPERM;
+
+	pr_debug("page number is %d\n", page);

I feel like I commented on this earlier, but I guess I never actually sent my comment? Anyway, I don't think we need this pr_debug(). That may be useful for certain kinds of debugging, but it's really not useful at all to most people. So I'll drop it when I push, or else if we have v5, please remove it there.

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip, · line 1288

Quoted 10 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +7 -0
+
+	chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + of->offset, page);
+	chip->write_buf(mtd, chip->oob_poi + of->offset, of->length);
+	chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
+
+	status = chip->waitfunc(mtd, chip);
+	return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
 
 static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs)

Brian

#12 lore raw

PATCH v4 7/12 mtd: nand: add more comment for MTD_NANDFLASH/MTD_MLCNANDFLASH

In reply to Huang Shijie

In current code, the MTD_NANDFLASH is used to represent both the SLC and MLC. It is confusing to us.

By adding an explicit comment about these two macros, this patch makes it clear that:
MTD_NANDFLASH : stands for SLC nand,
MTD_MLCNANDFLASH : stands for MLC nand(including TLC).

---
 include/uapi/mtd/mtd-abi.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
include/uapi/mtd/mtd-abi.h +2 -2
index 36eace0..16a9406 100644
@@ -94,10 +94,10 @@ struct mtd_write_req {
 #define MTD_RAM			1
 #define MTD_ROM			2
 #define MTD_NORFLASH		3
-#define MTD_NANDFLASH		4
+#define MTD_NANDFLASH		4	/* stand for SLC nand */
 #define MTD_DATAFLASH		6
 #define MTD_UBIVOLUME		7
-#define MTD_MLCNANDFLASH	8
+#define MTD_MLCNANDFLASH	8	/* stand for MLC nand(including TLC) */
 
 #define MTD_WRITEABLE		0x400	/* Device is writeable */
 #define MTD_BIT_WRITEABLE	0x800	/* Single bits can be flipped */
Signature · 1 line
1.7.1
#13 lore raw

PATCH v4 8/12 mtd: nand: add a helper to detect the nand type

In reply to Huang Shijie

This helper detects that whether the mtd's type is nand type.

Now, it's clear that the MTD_NANDFLASH stands for SLC nand only. So use the mtd_type_is_nand() to replace the old check method to do the nand type (include the SLC and MLC) check.

---
 drivers/mtd/inftlcore.c         |    2 +-
 drivers/mtd/nftlcore.c          |    2 +-
 drivers/mtd/ssfdc.c             |    2 +-
 drivers/mtd/tests/nandbiterrs.c |    2 +-
 drivers/mtd/tests/oobtest.c     |    2 +-
 drivers/mtd/tests/pagetest.c    |    2 +-
 drivers/mtd/tests/subpagetest.c |    2 +-
 include/linux/mtd/mtd.h         |    5 +++++
 8 files changed, 12 insertions(+), 7 deletions(-)
drivers/mtd/inftlcore.c +1 -1
index 3af3514..b66b541 100644
@@ -50,7 +50,7 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
 	struct INFTLrecord *inftl;
 	unsigned long temp;
 
-	if (mtd->type != MTD_NANDFLASH || mtd->size > UINT_MAX)
+	if (!mtd_type_is_nand(mtd) || mtd->size > UINT_MAX)
 		return;
 	/* OK, this is moderately ugly.  But probably safe.  Alternatives? */
 	if (memcmp(mtd->name, "DiskOnChip", 10))
drivers/mtd/nftlcore.c +1 -1
index c5f4ebf..46f27de 100644
@@ -50,7 +50,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
 	struct NFTLrecord *nftl;
 	unsigned long temp;
 
-	if (mtd->type != MTD_NANDFLASH || mtd->size > UINT_MAX)
+	if (!mtd_type_is_nand(mtd) || mtd->size > UINT_MAX)
 		return;
 	/* OK, this is moderately ugly.  But probably safe.  Alternatives? */
 	if (memcmp(mtd->name, "DiskOnChip", 10))
drivers/mtd/ssfdc.c +1 -1
index ab2a52a..daf82ba 100644
@@ -290,7 +290,7 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
 	int cis_sector;
 
 	/* Check for small page NAND flash */
-	if (mtd->type != MTD_NANDFLASH || mtd->oobsize != OOB_SIZE ||
+	if (!mtd_type_is_nand(mtd) || mtd->oobsize != OOB_SIZE ||
 	    mtd->size > UINT_MAX)
 		return;
 
drivers/mtd/tests/nandbiterrs.c +1 -1
index 3cd3aab..6f97615 100644
@@ -349,7 +349,7 @@ static int __init mtd_nandbiterrs_init(void)
 		goto exit_mtddev;
 	}
 
-	if (mtd->type != MTD_NANDFLASH) {
+	if (!mtd_type_is_nand(mtd)) {
 		pr_info("this test requires NAND flash\n");
 		err = -ENODEV;
 		goto exit_nand;
drivers/mtd/tests/oobtest.c +1 -1
index ff35c46..2e9e2d1 100644
@@ -289,7 +289,7 @@ static int __init mtd_oobtest_init(void)
 		return err;
 	}
 
-	if (mtd->type != MTD_NANDFLASH) {
+	if (!mtd_type_is_nand(mtd)) {
 		pr_info("this test requires NAND flash\n");
 		goto out;
 	}
drivers/mtd/tests/pagetest.c +1 -1
index 44b96e9..ed2d3f6 100644
@@ -353,7 +353,7 @@ static int __init mtd_pagetest_init(void)
 		return err;
 	}
 
-	if (mtd->type != MTD_NANDFLASH) {
+	if (!mtd_type_is_nand(mtd)) {
 		pr_info("this test requires NAND flash\n");
 		goto out;
 	}
drivers/mtd/tests/subpagetest.c +1 -1
index e2c0adf..a876371 100644
@@ -299,7 +299,7 @@ static int __init mtd_subpagetest_init(void)
 		return err;
 	}
 
-	if (mtd->type != MTD_NANDFLASH) {
+	if (!mtd_type_is_nand(mtd)) {
 		pr_info("this test requires NAND flash\n");
 		goto out;
 	}
include/linux/mtd/mtd.h +5 -0
index f9bfe52..88409b8 100644
@@ -354,6 +354,11 @@ static inline int mtd_has_oob(const struct mtd_info *mtd)
 	return mtd->_read_oob && mtd->_write_oob;
 }
 
+static inline int mtd_type_is_nand(const struct mtd_info *mtd)
+{
+	return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
+}
+
 static inline int mtd_can_have_bb(const struct mtd_info *mtd)
 {
 	return !!mtd->_block_isbad;
Signature · 1 line
1.7.1
#14 lore raw

PATCH v4 9/12 mtd: mtd-abi: add a helper to detect the nand type

In reply to Huang Shijie

The helper is for user applications, and it is just a copy of the kernel helper: mtd_type_is_nand();

---
 include/uapi/mtd/mtd-abi.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
include/uapi/mtd/mtd-abi.h +5 -0
index 16a9406..66c2b0c 100644
@@ -275,4 +275,9 @@ enum mtd_file_modes {
 	MTD_FILE_MODE_RAW,
 };
 
+static inline int mtd_type_is_nand_user(const struct mtd_info_user *mtd)
+{
+	return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
+}
+
 #endif /* __MTD_ABI_H__ */
Signature · 1 line
1.7.1
#15 lore raw

PATCH v4 10/12 mtd: add MTD_MLCNANDFLASH case for mtd_type_show()

In reply to Huang Shijie

The current mtd_type_show() misses the MTD_MLCNANDFLASH case. This patch adds the case for it, and also updates the ABI.

---
 Documentation/ABI/testing/sysfs-class-mtd |    2 +-
 drivers/mtd/mtdcore.c                     |    3 +++
 2 files changed, 4 insertions(+), 1 deletions(-)
Documentation/ABI/testing/sysfs-class-mtd +1 -1
index bfd119a..1399bb2 100644
@@ -104,7 +104,7 @@ Description:
 		One of the following ASCII strings, representing the device
 		type:
 
-		absent, ram, rom, nor, nand, dataflash, ubi, unknown
+		absent, ram, rom, nor, nand, mlc-nand, dataflash, ubi, unknown
 
 What:		/sys/class/mtd/mtdX/writesize
 Date:		April 2009
drivers/mtd/mtdcore.c +3 -0
index 5e14d54..92311a5 100644
@@ -157,6 +157,9 @@ static ssize_t mtd_type_show(struct device *dev,
 	case MTD_UBIVOLUME:
 		type = "ubi";
 		break;
+	case MTD_MLCNANDFLASH:
+		type = "mlc-nand";
+		break;
 	default:
 		type = "unknown";
 	}
Signature · 1 line
1.7.1
#16 lore raw

PATCH v4 11/12 jffs2: do not support the MLC nand

In reply to Huang Shijie

We should not support the MLC nand for jffs2. So if the nand type is MLC, we quit immediatly.

---
 fs/jffs2/fs.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
fs/jffs2/fs.c +4 -0
index fe3c052..09b3ed4 100644
@@ -515,6 +515,10 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
 
 	c = JFFS2_SB_INFO(sb);
 
+	/* Do not support the MLC nand */
+	if (c->mtd->type == MTD_MLCNANDFLASH)
+		return -EINVAL;
+
 #ifndef CONFIG_JFFS2_FS_WRITEBUFFER
 	if (c->mtd->type == MTD_NANDFLASH) {
 		pr_err("Cannot operate on NAND flash unless jffs2 NAND support is compiled in\n");
Signature · 1 line
1.7.1
#17 lore raw

PATCH v4 12/12 mtd: nand: fix the wrong mtd->type for nand chip

In reply to Huang Shijie

Current code sets the mtd->type with MTD_NANDFLASH for both SLC and MLC. So the jffs2 may supports the MLC nand, but in actually, the jffs2 should not support the MLC.

This patch uses the nand_is_slc() to check the nand cell type, and set the mtd->type with the right nand type.

After this patch, the jffs2 only supports the SLC nand.

The side-effect of this patch:
Before this patch, the ioctl(MEMGETINFO) can only return with the MTD_NANDFLASH; but after this patch, the ioctl(MEMGETINFO) will return with the MTD_NANDFLASH for SLC, and MTD_MLCNANDFLASH for MLC.

So the user applictions(such as mtd-utils) should also changes a little for this.

---
 drivers/mtd/nand/nand_base.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mtd/nand/nand_base.c +1 -1
index b94309b..2e5b50f 100644
@@ -3785,7 +3785,7 @@ int nand_scan_tail(struct mtd_info *mtd)
 		chip->options |= NAND_SUBPAGE_READ;
 
 	/* Fill in remaining MTD driver data */
-	mtd->type = MTD_NANDFLASH;
+	mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH;
 	mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM :
 						MTD_CAP_NANDFLASH;
 	mtd->_erase = nand_erase;
Signature · 1 line
1.7.1
#18 lore raw
In reply to Huang Shijie
Quoted 11 lines · Huang Shijie

In current mtd code, the MTD_NANDFLASH is used to represent both the SLC nand MLC(including the TLC). But we already have the MTD_MLCNANDFLASH to stand for the MLC. What is worse is that the JFFS2 may run on the MLC nand with current code. For the reason of READ/WRITE disturbance, the JFFS2 should runs on the SLC only,

This patch set tries to make clear what is the SLC/MLC by adding the macros, adding helpers, adding the comments. ..

After this patch set, the gpmi can support the JFFS2 for some SLC NAND now (only when the left oob area is big enough).

...

Quoted 5 lines

Huang Shijie (12):
mtd: nand: add a helper to check the SLC/MLC nand chip
mtd: nand: rename the cellinfo to bits_per_cell
mtd: nand: add the "bits per cell" info for legacy ID NAND
mtd: nand: set the cell information for ONFI nand

Quoted 8 lines

mtd: nand: print out the cell information for nand chip
mtd: gpmi: rewrite the gpmi_ecc_write_oob() to support the jffs2
mtd: nand: add more comment for MTD_NANDFLASH/MTD_MLCNANDFLASH
mtd: nand: add a helper to detect the nand type
mtd: mtd-abi: add a helper to detect the nand type
mtd: add MTD_MLCNANDFLASH case for mtd_type_show()
jffs2: do not support the MLC nand
mtd: nand: fix the wrong mtd->type for nand chip

Pushed the whole series to l2-mtd.git, with a few amendments of my own to fix trivial issues.

Are the mtd-utils fixes still applicable as-is? I'll review them next, since we should get mtd-utils updated before the kernel changes make it to mainline.

Brian

#19 lore raw
Quoted 3 lines · Brian Norris

Are the mtd-utils fixes still applicable as-is? I'll review them next, since we should get mtd-utils updated before the kernel changes make it to mainline.

yes, i think the mtd-utils fixes still works.

thanks
Huang Shijie