Skip to contentSkip to conversation

mtd: nand: add per partition ECC config

RFC PATCH In review Boris BREZILLON 2 participants 11 messages Feb 11, 2014 – Feb 13, 2014

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

v2 cover mtd: nand: add per partition ECC config

Hello,

This patch series is a proposal to add per partition ECC config.

It defines a new partition type called nand_part which stores a pointer to a nand_ecc_ctrl struct.
This specific nand_ecc_ctrl struct is used in place of the base NAND chip nand_ecc_ctrl struct when accessing NAND chip from nand_part MTD device.

If the partition does not define any ECC config, the NAND chip ECC config is used instead.

This patch series also provides an helper function to parse DT defined NAND partitions (ofnandpart_parse).

If you want to test it you'll have to replace calls to mtd_device_parse_register with ofnandpart_parse within your NAND controller driver and implement a driver specific parser function that will provide the ECC config (see ofnandpart_data struct).

The 4th patch of this series is here as an example on how to move from MTD partitions to NAND partitions.

Best Regards,

Boris

Changes since v1:
- almost everything :-)

Boris BREZILLON (4):
mtd: nand: take nand_ecc_ctrl initialization out of nand_scan_tail
mtd: nand: add support for NAND partitions
mtd: nand: add DT NAND partition parser
mtd: nand: add NAND partition support to the sunxi driver

 drivers/mtd/nand/Kconfig      |    4 +
 drivers/mtd/nand/Makefile     |    2 +
 drivers/mtd/nand/nand_base.c  |  763 ++++++++++++++++++++++++++++++++---------
 drivers/mtd/nand/ofnandpart.c |  104 ++++++
 drivers/mtd/nand/sunxi_nand.c |   69 +++-
 include/linux/mtd/nand.h      |   54 +++
 6 files changed, 835 insertions(+), 161 deletions(-)
 create mode 100644 drivers/mtd/nand/ofnandpart.c
Signature · 1 line
1.7.9.5
#1 lore raw

RFC PATCH v2 1/4 mtd: nand: take nand_ecc_ctrl initialization out of nand_scan_tail

Take ECC initialization code portion out of nand_scan_tail so that we can re-use this implementation.

---
 drivers/mtd/nand/nand_base.c |   72 +++++++++++++++++++++++++++---------------
 1 file changed, 46 insertions(+), 26 deletions(-)
drivers/mtd/nand/nand_base.c +46 -26
index f59a465..f2e9312 100644
@@ -3582,32 +3582,14 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
 }
 EXPORT_SYMBOL(nand_scan_ident);
 
-
-/**
- * nand_scan_tail - [NAND Interface] Scan for the NAND device
- * @mtd: MTD device structure
- *
- * This is the second phase of the normal nand_scan() function. It fills out
- * all the uninitialized function pointers with the defaults and scans for a
- * bad block table if appropriate.
+/*
+ * Initialize ECC struct:
+ *  - fill ECC struct with default function/values when these ones are undefined
+ *  - fill ECC infos based on MTD device
  */
-int nand_scan_tail(struct mtd_info *mtd)
+static int nand_ecc_ctrl_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc)
 {
 	int i;
-	struct nand_chip *chip = mtd->priv;
-	struct nand_ecc_ctrl *ecc = &chip->ecc;
-
-	/* New bad blocks should be marked in OOB, flash-based BBT, or both */
-	BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
-			!(chip->bbt_options & NAND_BBT_USE_FLASH));
-
-	if (!(chip->options & NAND_OWN_BUFFERS))
-		chip->buffers = kmalloc(sizeof(*chip->buffers), GFP_KERNEL);
-	if (!chip->buffers)
-		return -ENOMEM;
-
-	/* Set the internal oob buffer location, just after the page data */
-	chip->oob_poi = chip->buffers->databuf + mtd->writesize;
 
 	/*
 	 * If no default placement scheme is given, select an appropriate one.
@@ -3633,9 +3615,6 @@ int nand_scan_tail(struct mtd_info *mtd)
 		}
 	}
 
-	if (!chip->write_page)
-		chip->write_page = nand_write_page;
-
 	/*
 	 * Check ECC mode, default to software if 3byte/512byte hardware ECC is
 	 * selected and we have 256 byte pagesize fallback to software ECC
@@ -3802,6 +3781,47 @@ int nand_scan_tail(struct mtd_info *mtd)
 	}
 	ecc->total = ecc->steps * ecc->bytes;
 
+	return 0;
+}
+
+/**
+ * nand_scan_tail - [NAND Interface] Scan for the NAND device
+ * @mtd: MTD device structure
+ *
+ * This is the second phase of the normal nand_scan() function. It fills out
+ * all the uninitialized function pointers with the defaults and scans for a
+ * bad block table if appropriate.
+ */
+int nand_scan_tail(struct mtd_info *mtd)
+{
+	int ret;
+	struct nand_chip *chip = mtd->priv;
+	struct nand_ecc_ctrl *ecc = &chip->ecc;
+
+	/* New bad blocks should be marked in OOB, flash-based BBT, or both */
+	BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
+			!(chip->bbt_options & NAND_BBT_USE_FLASH));
+
+	if (!(chip->options & NAND_OWN_BUFFERS))
+		chip->buffers = kmalloc(sizeof(*chip->buffers), GFP_KERNEL);
+	if (!chip->buffers)
+		return -ENOMEM;
+
+	/* Set the internal oob buffer location, just after the page data */
+	chip->oob_poi = chip->buffers->databuf + mtd->writesize;
+
+	if (!chip->write_page)
+		chip->write_page = nand_write_page;
+
+	/* Initialize ECC struct */
+	ret = nand_ecc_ctrl_init(mtd, ecc);
+	if (ret) {
+		if (!(chip->options & NAND_OWN_BUFFERS))
+			kfree(chip->buffers);
+
+		return ret;
+	}
+
 	/* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
 	if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && nand_is_slc(chip)) {
 		switch (ecc->steps) {
Signature · 1 line
1.7.9.5
#2 lore raw

RFC PATCH v2 2/4 mtd: nand: add support for NAND partitions

In reply to Boris BREZILLON

Add support for NAND partitions, and inderectly for per partition ECC config.
Provide helper functions to add/delete/allocate nand partitions. NAND core code now make use of the partition specific nand_ecc_ctrl struct (if available) when doing read/write operations.

---
 drivers/mtd/nand/Kconfig     |    4 +
 drivers/mtd/nand/Makefile    |    2 +
 drivers/mtd/nand/nand_base.c |  691 ++++++++++++++++++++++++++++++++++--------
 include/linux/mtd/nand.h     |   37 +++
 4 files changed, 602 insertions(+), 132 deletions(-)
drivers/mtd/nand/Kconfig +4 -0
index 784dd42..aa62ca3 100644
@@ -22,6 +22,10 @@ menuconfig MTD_NAND
 
 if MTD_NAND
 
+config MTD_OF_NAND_PARTS
+	tristate
+	default n
+
 config MTD_NAND_BCH
 	tristate
 	select BCH
drivers/mtd/nand/Makefile +2 -0
index e3b4a34..992de88 100644
@@ -51,4 +51,6 @@ obj-$(CONFIG_MTD_NAND_XWAY)		+= xway_nand.o
 obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH)	+= bcm47xxnflash/
 obj-$(CONFIG_MTD_NAND_SUNXI)		+= sunxi_nand.o
 
+obj-$(CONFIG_MTD_OF_NAND_PARTS)		+= ofnandpart.o
+
 nand-objs := nand_base.o nand_bbt.o
drivers/mtd/nand/nand_base.c +559 -132

1,071 lines not on this page · raw message

include/linux/mtd/nand.h +37 -0
index c70e0a3..c4d271a 100644
@@ -574,6 +574,7 @@ struct nand_chip {
 	struct nand_hw_control *controller;
 
 	struct nand_ecc_ctrl ecc;
+	struct nand_ecc_ctrl *cur_ecc;
 	struct nand_buffers *buffers;
 	struct nand_hw_control hwcontrol;
 
@@ -583,9 +584,40 @@ struct nand_chip {
 
 	struct nand_bbt_descr *badblock_pattern;
 
+	struct list_head partitions;
+	struct mutex part_lock;
+
 	void *priv;
 };
 
+/**
+ * struct nand_part - NAND partition structure
+ * @node:	list node used to attach the partition to its NAND dev
+ * @mtd:	MTD partiton info
+ * @master:	MTD device representing the NAND chip
+ * @offset:	partition offset
+ * @ecc:	partition specific ECC struct
+ * @release:	function used to release this nand_part struct
+ *
+ * NAND partitions work as standard MTD partitions except it can override
+ * NAND chip ECC handling.
+ * This is particularly useful for SoCs that need specific ECC configs to boot
+ * from NAND while these ECC configs do not fit the NAND chip ECC requirements.
+ */
+struct nand_part {
+	struct list_head node;
+	struct mtd_info mtd;
+	struct mtd_info *master;
+	uint64_t offset;
+	struct nand_ecc_ctrl *ecc;
+	void (*release)(struct nand_part *part);
+};
+
+static inline struct nand_part *to_nand_part(struct mtd_info *mtd)
+{
+	return container_of(mtd, struct nand_part, mtd);
+}
+
 /*
  * NAND Flash Manufacturer ID Codes
  */
@@ -806,6 +838,11 @@ static inline bool nand_is_slc(struct nand_chip *chip)
 	return chip->bits_per_cell == 1;
 }
 
+int nand_add_partition(struct mtd_info *master, struct nand_part *part);
+
+void nand_del_partition(struct nand_part *part);
+
+struct nand_part *nandpart_alloc(void);
 
 /**
  * struct nand_sdr_timings - SDR NAND chip timings
Signature · 1 line
1.7.9.5
#5 lore raw

RFC PATCH v2 4/4 mtd: nand: add NAND partition support to the sunxi driver

In reply to Boris BREZILLON
---
 drivers/mtd/nand/sunxi_nand.c |   69 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 66 insertions(+), 3 deletions(-)
drivers/mtd/nand/sunxi_nand.c +66 -3
index f24ad8b..4693d9f 100644
@@ -168,6 +168,17 @@ struct sunxi_nand_hw_ecc {
 	struct nand_ecclayout layout;
 };
 
+struct sunxi_nand_part {
+	struct nand_part part;
+	struct nand_ecc_ctrl ecc;
+};
+
+static inline struct sunxi_nand_part *
+to_sunxi_nand_part(struct nand_part *part)
+{
+	return container_of(part, struct sunxi_nand_part, part);
+}
+
 struct sunxi_nand_chip {
 	struct list_head node;
 	struct nand_chip nand;
@@ -780,12 +791,58 @@ static int sunxi_nand_chip_ecc_init(struct device *dev,
 	return 0;
 }
 
+static void sunxi_nand_part_release(struct nand_part *part)
+{
+	kfree(to_sunxi_nand_part(part));
+}
+
+struct nand_part *sunxi_ofnandpart_parse(void *priv, struct mtd_info *master,
+					 struct device_node *pp)
+{
+	int mode = of_get_nand_ecc_mode(pp);
+	struct sunxi_nand_part *part;
+	struct nand_chip *chip = master->priv;
+	u32 strength;
+	u32 blk_size;
+
+	if (mode < 0)
+		return nandpart_alloc();
+
+	part = kzalloc(sizeof(*part), GFP_KERNEL);
+	part->part.release = sunxi_nand_part_release;
+
+	part->ecc.size = chip->ecc_step_ds;
+	part->ecc.strength = chip->ecc_strength_ds;
+	if (!of_get_nand_ecc_level(pp, &strength, &blk_size)) {
+		part->ecc.size = blk_size;
+		part->ecc.strength = strength;
+	}
+
+	part->ecc.mode = mode;
+	switch (mode) {
+	case NAND_ECC_SOFT_BCH:
+		part->ecc.bytes = ((part->ecc.strength *
+				    fls(8 * part->ecc.size)) + 7) / 8;
+		break;
+	case NAND_ECC_HW:
+		break;
+	case NAND_ECC_NONE:
+		break;
+	default:
+		break;
+	}
+
+	part->part.ecc = &part->ecc;
+
+	return &part->part;
+}
+
 static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
 				struct device_node *np)
 {
 	const struct nand_sdr_timings *timings;
 	struct sunxi_nand_chip *chip;
-	struct mtd_part_parser_data ppdata;
+	struct ofnandpart_data ppdata;
 	struct mtd_info *mtd;
 	struct nand_chip *nand;
 	int nsels;
@@ -889,9 +946,15 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
 		mtd->name = chip->default_name;
 	}
 
-	ppdata.of_node = np;
-	ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+	ppdata.node = np;
+	ppdata.parse = sunxi_ofnandpart_parse;
+	ret = ofnandpart_parse(mtd, &ppdata);
 	if (!ret)
+		ret = mtd_device_register(mtd, NULL, 0);
+	else if (ret > 0)
+		ret = 0;
+
+	if (ret)
 		return ret;
 
 	list_add_tail(&chip->node, &nfc->chips);
Signature · 1 line
1.7.9.5
#4 lore raw

RFC PATCH v2 3/4 mtd: nand: add DT NAND partition parser

In reply to Boris BREZILLON

Add ofnandpart_parse function to help parsing NAND partitions from DT. This function should be called from NAND controller drivers just after the nand_scan_tail in place of mtd_device_parse_register.
The caller can specify a parser function to retrieve HW specific informations from the DT.

---
 drivers/mtd/nand/ofnandpart.c |  104 +++++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/nand.h      |   17 +++++++
 2 files changed, 121 insertions(+)
 create mode 100644 drivers/mtd/nand/ofnandpart.c
drivers/mtd/nand/ofnandpart.c new file +104 -0
new file mode 100644
index 0000000..293daee
@@ -0,0 +1,104 @@
+/*
+ * NAND Flash partitions described by the OF (or flattened) device tree
+ *
+ * Copyright © 2014 Boris BREZILLON <[email protected]>
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/of.h>
+#include <linux/mtd/mtd.h>
+#include <linux/slab.h>
+#include <linux/mtd/nand.h>
+
+static inline bool node_has_compatible(struct device_node *pp)
+{
+	return of_get_property(pp, "compatible", NULL);
+}
+
+int ofnandpart_parse(struct mtd_info *master,
+		     const struct ofnandpart_data *data)
+{
+	struct device_node *node;
+	const char *partname;
+	struct device_node *pp;
+	int i;
+
+	if (!data)
+		return 0;
+
+	node = data->node;
+	if (!node)
+		return 0;
+
+	i = 0;
+	for_each_child_of_node(node,  pp) {
+		const __be32 *reg;
+		int len;
+		int a_cells, s_cells;
+		uint64_t offset, size;
+		uint32_t mask_flags = 0;
+		struct nand_part *part;
+
+		if (node_has_compatible(pp))
+			continue;
+
+		reg = of_get_property(pp, "reg", &len);
+		if (!reg)
+			continue;
+
+		a_cells = of_n_addr_cells(pp);
+		s_cells = of_n_size_cells(pp);
+		offset = of_read_number(reg, a_cells);
+		size = of_read_number(reg + a_cells, s_cells);
+
+		partname = of_get_property(pp, "label", &len);
+		if (!partname)
+			partname = of_get_property(pp, "name", &len);
+
+		if (of_get_property(pp, "read-only", &len))
+			mask_flags |= MTD_WRITEABLE;
+
+		if (of_get_property(pp, "lock", &len))
+			mask_flags |= MTD_POWERUP_LOCK;
+
+		if (data->parse)
+			part = data->parse(data->priv, master, pp);
+		else
+			part = nandpart_alloc();
+
+		if (IS_ERR(part))
+			continue;
+
+		part->offset = offset;
+		part->master = master;
+		part->mtd.name = partname;
+		part->mtd.size = size;
+		part->mtd.flags = mask_flags;
+
+		if (nand_add_partition(master, part)) {
+			if (part->release)
+				part->release(part);
+			continue;
+		}
+
+		i++;
+	}
+
+	if (!i) {
+		of_node_put(pp);
+		pr_err("No valid partition found on %s\n", node->full_name);
+	}
+
+	return i;
+}
+EXPORT_SYMBOL(ofnandpart_parse);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Parser for NAND flash partitioning information in device tree");
+MODULE_AUTHOR("Boris BREZILLON");
include/linux/mtd/nand.h +17 -0
index c4d271a..0c5890b 100644
@@ -845,6 +845,23 @@ void nand_del_partition(struct nand_part *part);
 struct nand_part *nandpart_alloc(void);
 
 /**
+ * struct ofnandpart_data - struct used to retrieve NAND partitions from a DT
+ *			    node
+ * @parse:		driver specific parser function
+ * @priv:		driver private data
+ * @node:		OF node containing NAND partitions
+ */
+struct ofnandpart_data {
+	struct nand_part *(*parse)(void *priv, struct mtd_info *master,
+				   struct device_node *pp);
+	void *priv;
+	struct device_node *node;
+};
+
+int ofnandpart_parse(struct mtd_info *master,
+		     const struct ofnandpart_data *data);
+
+/**
  * struct nand_sdr_timings - SDR NAND chip timings
  *
  * This struct defines the timing requirements of a SDR NAND chip.
Signature · 1 line
1.7.9.5
#3 lore raw

RFC PATCH v2 2/4 mtd: nand: add support for NAND partitions

In reply to Boris BREZILLON

Add support for NAND partitions, and inderectly for per partition ECC config.
Provide helper functions to add/delete/allocate nand partitions. NAND core code now make use of the partition specific nand_ecc_ctrl struct (if available) when doing read/write operations.

---

Hello,

Sorry for the noise: this version adds mutex_lock and partition initialization code which somehow were missing from my commit but were present in my source tree :-).

It also fixes a bug when using software ECC on a given partition.

Best Regards,

Boris

Changes since v2:
- add missing mutex_lock in nand_add_partition
- add missing partition list and lock initilization
- make use of cur_ecc pointer instead of ecc in nand_ecc and nand_bch code

 drivers/mtd/nand/Kconfig     |    4 +
 drivers/mtd/nand/Makefile    |    2 +
 drivers/mtd/nand/nand_base.c |  698 ++++++++++++++++++++++++++++++++++--------
 drivers/mtd/nand/nand_bch.c  |   16 +-
 drivers/mtd/nand/nand_ecc.c  |    4 +-
 include/linux/mtd/nand.h     |   37 +++
 6 files changed, 619 insertions(+), 142 deletions(-)
drivers/mtd/nand/Kconfig +4 -0
index 784dd42..aa62ca3 100644
@@ -22,6 +22,10 @@ menuconfig MTD_NAND
 
 if MTD_NAND
 
+config MTD_OF_NAND_PARTS
+	tristate
+	default n
+
 config MTD_NAND_BCH
 	tristate
 	select BCH
drivers/mtd/nand/Makefile +2 -0
index e3b4a34..992de88 100644
@@ -51,4 +51,6 @@ obj-$(CONFIG_MTD_NAND_XWAY)		+= xway_nand.o
 obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH)	+= bcm47xxnflash/
 obj-$(CONFIG_MTD_NAND_SUNXI)		+= sunxi_nand.o
 
+obj-$(CONFIG_MTD_OF_NAND_PARTS)		+= ofnandpart.o
+
 nand-objs := nand_base.o nand_bbt.o
drivers/mtd/nand/nand_base.c +566 -132

1,078 lines not on this page · raw message

drivers/mtd/nand/nand_bch.c +8 -8
index 3803e0b..b82b976 100644
@@ -53,14 +53,14 @@ int nand_bch_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
 			   unsigned char *code)
 {
 	const struct nand_chip *chip = mtd->priv;
-	struct nand_bch_control *nbc = chip->ecc.priv;
+	struct nand_bch_control *nbc = chip->cur_ecc->priv;
 	unsigned int i;
 
-	memset(code, 0, chip->ecc.bytes);
-	encode_bch(nbc->bch, buf, chip->ecc.size, code);
+	memset(code, 0, chip->cur_ecc->bytes);
+	encode_bch(nbc->bch, buf, chip->cur_ecc->size, code);
 
 	/* apply mask so that an erased page is a valid codeword */
-	for (i = 0; i < chip->ecc.bytes; i++)
+	for (i = 0; i < chip->cur_ecc->bytes; i++)
 		code[i] ^= nbc->eccmask[i];
 
 	return 0;
@@ -80,15 +80,15 @@ int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
 			  unsigned char *read_ecc, unsigned char *calc_ecc)
 {
 	const struct nand_chip *chip = mtd->priv;
-	struct nand_bch_control *nbc = chip->ecc.priv;
+	struct nand_bch_control *nbc = chip->cur_ecc->priv;
 	unsigned int *errloc = nbc->errloc;
 	int i, count;
 
-	count = decode_bch(nbc->bch, NULL, chip->ecc.size, read_ecc, calc_ecc,
-			   NULL, errloc);
+	count = decode_bch(nbc->bch, NULL, chip->cur_ecc->size, read_ecc,
+			   calc_ecc, NULL, errloc);
 	if (count > 0) {
 		for (i = 0; i < count; i++) {
-			if (errloc[i] < (chip->ecc.size*8))
+			if (errloc[i] < (chip->cur_ecc->size*8))
 				/* error is located in data, correct it */
 				buf[errloc[i] >> 3] ^= (1 << (errloc[i] & 7));
 			/* else error in ecc, no action needed */
drivers/mtd/nand/nand_ecc.c +2 -2
index 053c9a2..520bef5 100644
@@ -424,7 +424,7 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
 		       unsigned char *code)
 {
 	__nand_calculate_ecc(buf,
-			((struct nand_chip *)mtd->priv)->ecc.size, code);
+			((struct nand_chip *)mtd->priv)->cur_ecc->size, code);
 
 	return 0;
 }
@@ -524,7 +524,7 @@ int nand_correct_data(struct mtd_info *mtd, unsigned char *buf,
 		      unsigned char *read_ecc, unsigned char *calc_ecc)
 {
 	return __nand_correct_data(buf, read_ecc, calc_ecc,
-				   ((struct nand_chip *)mtd->priv)->ecc.size);
+			((struct nand_chip *)mtd->priv)->cur_ecc->size);
 }
 EXPORT_SYMBOL(nand_correct_data);
 
include/linux/mtd/nand.h +37 -0
index c70e0a3..c4d271a 100644
@@ -574,6 +574,7 @@ struct nand_chip {
 	struct nand_hw_control *controller;
 
 	struct nand_ecc_ctrl ecc;
+	struct nand_ecc_ctrl *cur_ecc;
 	struct nand_buffers *buffers;
 	struct nand_hw_control hwcontrol;
 
@@ -583,9 +584,40 @@ struct nand_chip {
 
 	struct nand_bbt_descr *badblock_pattern;
 
+	struct list_head partitions;
+	struct mutex part_lock;
+
 	void *priv;
 };
 
+/**
+ * struct nand_part - NAND partition structure
+ * @node:	list node used to attach the partition to its NAND dev
+ * @mtd:	MTD partiton info
+ * @master:	MTD device representing the NAND chip
+ * @offset:	partition offset
+ * @ecc:	partition specific ECC struct
+ * @release:	function used to release this nand_part struct
+ *
+ * NAND partitions work as standard MTD partitions except it can override
+ * NAND chip ECC handling.
+ * This is particularly useful for SoCs that need specific ECC configs to boot
+ * from NAND while these ECC configs do not fit the NAND chip ECC requirements.
+ */
+struct nand_part {
+	struct list_head node;
+	struct mtd_info mtd;
+	struct mtd_info *master;
+	uint64_t offset;
+	struct nand_ecc_ctrl *ecc;
+	void (*release)(struct nand_part *part);
+};
+
+static inline struct nand_part *to_nand_part(struct mtd_info *mtd)
+{
+	return container_of(mtd, struct nand_part, mtd);
+}
+
 /*
  * NAND Flash Manufacturer ID Codes
  */
@@ -806,6 +838,11 @@ static inline bool nand_is_slc(struct nand_chip *chip)
 	return chip->bits_per_cell == 1;
 }
 
+int nand_add_partition(struct mtd_info *master, struct nand_part *part);
+
+void nand_del_partition(struct nand_part *part);
+
+struct nand_part *nandpart_alloc(void);
 
 /**
  * struct nand_sdr_timings - SDR NAND chip timings
Signature · 1 line
1.7.9.5
#6 lore raw
In reply to Boris BREZILLON

Hi Boris,

2014-02-11 13:46 GMT-08:00 Boris BREZILLON <[email protected]>:

Quoted 11 lines

Hello,

This patch series is a proposal to add per partition ECC config.

It defines a new partition type called nand_part which stores a pointer to a nand_ecc_ctrl struct.
This specific nand_ecc_ctrl struct is used in place of the base NAND chip nand_ecc_ctrl struct when accessing NAND chip from nand_part MTD device.

If the partition does not define any ECC config, the NAND chip ECC config is used instead.

Although the idea does look nice on the paper, I wonder if it is really useful to have that much complexity in the kernel. Most likely what is happening is that your bootloader partition has a specific ECC scheme due to the CPU bootrom or whatever early bootagent is running on the system. When that is the case, this can be solved in user-space by preparing full pages (main+spare) along with their specific ECC requirements and use the MTD_FILE_MODE_RAW option on your specific MTD partition.

You do not describe what is the end goal of this patchset, which might help figuring out the potential other platforms requirements etc...

Quoted 41 lines

This patch series also provides an helper function to parse DT defined NAND partitions (ofnandpart_parse).

If you want to test it you'll have to replace calls to mtd_device_parse_register with ofnandpart_parse within your NAND controller driver and implement a driver specific parser function that will provide the ECC config (see ofnandpart_data struct).

The 4th patch of this series is here as an example on how to move from MTD partitions to NAND partitions.

Best Regards,

Boris

Changes since v1:
- almost everything :-)

Boris BREZILLON (4):
mtd: nand: take nand_ecc_ctrl initialization out of nand_scan_tail
mtd: nand: add support for NAND partitions
mtd: nand: add DT NAND partition parser
mtd: nand: add NAND partition support to the sunxi driver

 drivers/mtd/nand/Kconfig      |    4 +
 drivers/mtd/nand/Makefile     |    2 +
 drivers/mtd/nand/nand_base.c  |  763 ++++++++++++++++++++++++++++++++---------
 drivers/mtd/nand/ofnandpart.c |  104 ++++++
 drivers/mtd/nand/sunxi_nand.c |   69 +++-
 include/linux/mtd/nand.h      |   54 +++
 6 files changed, 835 insertions(+), 161 deletions(-)
 create mode 100644 drivers/mtd/nand/ofnandpart.c

--
1.7.9.5

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

Signature · 1 line
Florian
#7 lore raw

Hi Florian,

Quoted 14 lines · Florian Fainelli

Hi Boris,

2014-02-11 13:46 GMT-08:00 Boris BREZILLON <[email protected]>:

Quoted 11 lines

Hello,

This patch series is a proposal to add per partition ECC config.

It defines a new partition type called nand_part which stores a pointer to a nand_ecc_ctrl struct.
This specific nand_ecc_ctrl struct is used in place of the base NAND chip nand_ecc_ctrl struct when accessing NAND chip from nand_part MTD device.

If the partition does not define any ECC config, the NAND chip ECC config is used instead.

Quoted 8 lines

Although the idea does look nice on the paper, I wonder if it is really useful to have that much complexity in the kernel. Most likely what is happening is that your bootloader partition has a specific ECC scheme due to the CPU bootrom or whatever early bootagent is running on the system. When that is the case, this can be solved in user-space by preparing full pages (main+spare) along with their specific ECC requirements and use the MTD_FILE_MODE_RAW option on your specific MTD partition.

Okay, that should be possible, althought in the sunxi specific case I haven't figured out how to generate these ECC data yet (even if it's using BCH algorithms).

Quoted 2 lines

You do not describe what is the end goal of this patchset, which might help figuring out the potential other platforms requirements etc...

My goal is exactly the one you described above, I just thought this would be much easier to handle this within the kernel, without having to develop extra user space tools.
Moreover the user would be able to directly manipulate the data on the MTD partitions.

This implementation is not that complex and should not impact performances (it's just using cur_ecc pointer instead of intern ecc struct).

Most of the extra code introduced by this series come from the new partition type handling, which is quite straightforward BTW.

Anyway, I understand your concern. Could MTD maintainers (and NAND driver developpers) give there opinion too ?

BTW, I'm also working on a data randomization layer (needed by some MLC/TLC chips) within the NAND core framework and I'm using the same per partition approach (for the exact same reason: boot0 partition uses a randomizer seed that might not fit the NAND chip requirements).

Should I reconsider doing this too ?

Thanks for you comments.

Best Regards,

Boris

Quoted 43 lines
Quoted 41 lines

This patch series also provides an helper function to parse DT defined NAND partitions (ofnandpart_parse).

If you want to test it you'll have to replace calls to mtd_device_parse_register with ofnandpart_parse within your NAND controller driver and implement a driver specific parser function that will provide the ECC config (see ofnandpart_data struct).

The 4th patch of this series is here as an example on how to move from MTD partitions to NAND partitions.

Best Regards,

Boris

Changes since v1:
- almost everything :-)

Boris BREZILLON (4):
mtd: nand: take nand_ecc_ctrl initialization out of nand_scan_tail
mtd: nand: add support for NAND partitions
mtd: nand: add DT NAND partition parser
mtd: nand: add NAND partition support to the sunxi driver

  drivers/mtd/nand/Kconfig      |    4 +
  drivers/mtd/nand/Makefile     |    2 +
  drivers/mtd/nand/nand_base.c  |  763 ++++++++++++++++++++++++++++++++---------
  drivers/mtd/nand/ofnandpart.c |  104 ++++++
  drivers/mtd/nand/sunxi_nand.c |   69 +++-
  include/linux/mtd/nand.h      |   54 +++
  6 files changed, 835 insertions(+), 161 deletions(-)

create mode 100644 drivers/mtd/nand/ofnandpart.c

--
1.7.9.5

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

#8 lore raw
Quoted 26 lines · Boris BREZILLON

Hi Florian,

Quoted 14 lines · Florian Fainelli

Hi Boris,

2014-02-11 13:46 GMT-08:00 Boris BREZILLON <[email protected]>:

Quoted 11 lines

Hello,

This patch series is a proposal to add per partition ECC config.

It defines a new partition type called nand_part which stores a pointer to a nand_ecc_ctrl struct.
This specific nand_ecc_ctrl struct is used in place of the base NAND chip nand_ecc_ctrl struct when accessing NAND chip from nand_part MTD device.

If the partition does not define any ECC config, the NAND chip ECC config is used instead.

Quoted 8 lines

Although the idea does look nice on the paper, I wonder if it is really useful to have that much complexity in the kernel. Most likely what is happening is that your bootloader partition has a specific ECC scheme due to the CPU bootrom or whatever early bootagent is running on the system. When that is the case, this can be solved in user-space by preparing full pages (main+spare) along with their specific ECC requirements and use the MTD_FILE_MODE_RAW option on your specific MTD partition.

Quoted 6 lines

Okay, that should be possible, althought in the sunxi specific case I haven't figured out how to generate these ECC data yet (even if it's using BCH algorithms).

Quoted 2 lines

You do not describe what is the end goal of this patchset, which might help figuring out the potential other platforms requirements etc...

BTW, here is another case where per partition ECC would have been useful :-) :
http://comments.gmane.org/gmane.linux.ports.arm.omap/108083

Quoted 72 lines

My goal is exactly the one you described above, I just thought this would be much easier to handle this within the kernel, without having to develop extra user space tools.
Moreover the user would be able to directly manipulate the data on the MTD partitions.

This implementation is not that complex and should not impact performances (it's just using cur_ecc pointer instead of intern ecc struct).

Most of the extra code introduced by this series come from the new partition type handling, which is quite straightforward BTW.

Anyway, I understand your concern. Could MTD maintainers (and NAND driver developpers) give there opinion too ?

BTW, I'm also working on a data randomization layer (needed by some MLC/TLC chips) within the NAND core framework and I'm using the same per partition approach (for the exact same reason: boot0 partition uses a randomizer seed that might not fit the NAND chip requirements).

Should I reconsider doing this too ?

Thanks for you comments.

Best Regards,

Boris

Quoted 44 lines
Quoted 42 lines

This patch series also provides an helper function to parse DT defined NAND partitions (ofnandpart_parse).

If you want to test it you'll have to replace calls to mtd_device_parse_register with ofnandpart_parse within your NAND controller driver and implement a driver specific parser function that will provide the ECC config (see ofnandpart_data struct).

The 4th patch of this series is here as an example on how to move from MTD partitions to NAND partitions.

Best Regards,

Boris

Changes since v1:
- almost everything :-)

Boris BREZILLON (4):
mtd: nand: take nand_ecc_ctrl initialization out of nand_scan_tail
mtd: nand: add support for NAND partitions
mtd: nand: add DT NAND partition parser
mtd: nand: add NAND partition support to the sunxi driver

  drivers/mtd/nand/Kconfig      |    4 +
  drivers/mtd/nand/Makefile     |    2 +
  drivers/mtd/nand/nand_base.c  |  763 
++++++++++++++++++++++++++++++++---------
  drivers/mtd/nand/ofnandpart.c |  104 ++++++
  drivers/mtd/nand/sunxi_nand.c |   69 +++-
  include/linux/mtd/nand.h      |   54 +++
  6 files changed, 835 insertions(+), 161 deletions(-)

create mode 100644 drivers/mtd/nand/ofnandpart.c

Signature · 6 lines
1.7.9.5


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#9 lore raw
In reply to Boris BREZILLON

2014-02-12 13:20 GMT-08:00 Boris BREZILLON <[email protected]>:

Quoted 38 lines

Hi Florian,

Quoted 18 lines · Florian Fainelli

Hi Boris,

2014-02-11 13:46 GMT-08:00 Boris BREZILLON <[email protected]>:

Quoted 5 lines

Hello,

This patch series is a proposal to add per partition ECC config.

Quoted 8 lines

It defines a new partition type called nand_part which stores a pointer to
a nand_ecc_ctrl struct.
This specific nand_ecc_ctrl struct is used in place of the base NAND chip nand_ecc_ctrl struct when accessing NAND chip from nand_part MTD device.

If the partition does not define any ECC config, the NAND chip ECC config is used instead.

Quoted 8 lines

Although the idea does look nice on the paper, I wonder if it is really useful to have that much complexity in the kernel. Most likely what is happening is that your bootloader partition has a specific ECC scheme due to the CPU bootrom or whatever early bootagent is running on the system. When that is the case, this can be solved in user-space by preparing full pages (main+spare) along with their specific ECC requirements and use the MTD_FILE_MODE_RAW option on your specific MTD partition.

Okay, that should be possible, althought in the sunxi specific case I haven't
figured out how to generate these ECC data yet (even if it's using BCH algorithms).

Quoted 8 lines
Quoted 2 lines

You do not describe what is the end goal of this patchset, which might help figuring out the potential other platforms requirements etc...

My goal is exactly the one you described above, I just thought this would be much easier to handle this within the kernel, without having to develop extra
user space tools.

Each platform will have different requirements which are imho better solved at the user-space level (bad block marker placement, ECC scheme, number of times the bootloader must be replicated, cryptography, signing, proprietary OOBs and whatnot). The situation is probably made even worse with platforms implementing a trusted boot scheme where you may have to modify your boot program for whatever reason before writing it down again.

My point is that, an user-space solution already exists, and the bootloaders are significantly smaller and not read/written often enough to justify leveraging HW ECC for instance, which could be one advantage of the per-partition ECC scheme.

Quoted 3 lines

This implementation is not that complex and should not impact performances (it's just using cur_ecc pointer instead of intern ecc struct).

How about reading/erasing/writing concurrently (as in having two user-space applications), is not that going to incur some sort of "ECC context switching" cost? I am also not sure if all NAND controllers will behave (they should) correctly when you switch from one ECC scheme to another on the fly like this could be happening.

Quoted 72 lines

Most of the extra code introduced by this series come from the new partition type
handling, which is quite straightforward BTW.

Anyway, I understand your concern. Could MTD maintainers (and NAND driver developpers) give there opinion too ?

BTW, I'm also working on a data randomization layer (needed by some MLC/TLC chips)
within the NAND core framework and I'm using the same per partition approach (for the exact same reason: boot0 partition uses a randomizer seed that might not fit
the NAND chip requirements).

Should I reconsider doing this too ?

Thanks for you comments.

Best Regards,

Boris

Quoted 48 lines
Quoted 45 lines

This patch series also provides an helper function to parse DT defined NAND
partitions (ofnandpart_parse).

If you want to test it you'll have to replace calls to mtd_device_parse_register with ofnandpart_parse within your NAND controller
driver and implement a driver specific parser function that will provide the ECC config (see ofnandpart_data struct).

The 4th patch of this series is here as an example on how to move from MTD
partitions to NAND partitions.

Best Regards,

Boris

Changes since v1:
- almost everything :-)

Boris BREZILLON (4):
mtd: nand: take nand_ecc_ctrl initialization out of nand_scan_tail
mtd: nand: add support for NAND partitions
mtd: nand: add DT NAND partition parser
mtd: nand: add NAND partition support to the sunxi driver

  drivers/mtd/nand/Kconfig      |    4 +
  drivers/mtd/nand/Makefile     |    2 +
  drivers/mtd/nand/nand_base.c  |  763
++++++++++++++++++++++++++++++++---------
  drivers/mtd/nand/ofnandpart.c |  104 ++++++
  drivers/mtd/nand/sunxi_nand.c |   69 +++-
  include/linux/mtd/nand.h      |   54 +++
  6 files changed, 835 insertions(+), 161 deletions(-)

create mode 100644 drivers/mtd/nand/ofnandpart.c

--
1.7.9.5

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

Signature · 1 line
Florian
#10 lore raw
Quoted 42 lines · Florian Fainelli

2014-02-12 13:20 GMT-08:00 Boris BREZILLON <[email protected]>:

Quoted 34 lines

Hi Florian,

Quoted 15 lines · Florian Fainelli

Hi Boris,

2014-02-11 13:46 GMT-08:00 Boris BREZILLON <[email protected]>:

Quoted 4 lines

Hello,

This patch series is a proposal to add per partition ECC config.

Quoted 8 lines

It defines a new partition type called nand_part which stores a pointer to
a nand_ecc_ctrl struct.
This specific nand_ecc_ctrl struct is used in place of the base NAND chip nand_ecc_ctrl struct when accessing NAND chip from nand_part MTD device.

If the partition does not define any ECC config, the NAND chip ECC config is used instead.

Quoted 8 lines

Although the idea does look nice on the paper, I wonder if it is really useful to have that much complexity in the kernel. Most likely what is happening is that your bootloader partition has a specific ECC scheme due to the CPU bootrom or whatever early bootagent is running on the system. When that is the case, this can be solved in user-space by preparing full pages (main+spare) along with their specific ECC requirements and use the MTD_FILE_MODE_RAW option on your specific MTD partition.

Okay, that should be possible, althought in the sunxi specific case I haven't
figured out how to generate these ECC data yet (even if it's using BCH algorithms).

Quoted 7 lines
Quoted 2 lines

You do not describe what is the end goal of this patchset, which might help figuring out the potential other platforms requirements etc...

My goal is exactly the one you described above, I just thought this would be much easier to handle this within the kernel, without having to develop extra
user space tools.

Quoted 7 lines

Each platform will have different requirements which are imho better solved at the user-space level (bad block marker placement, ECC scheme, number of times the bootloader must be replicated, cryptography, signing, proprietary OOBs and whatnot). The situation is probably made even worse with platforms implementing a trusted boot scheme where you may have to modify your boot program for whatever reason before writing it down again.

On the other hand, most of the time the NAND controller drivers already support all these specific ECC algorithms and OOB layouts (I'm not talking about crypto, signing or trusted boot), and would be able to expose these "weird" partitions to user-space with almost no extra development cost.

Quoted 5 lines

My point is that, an user-space solution already exists, and the bootloaders are significantly smaller and not read/written often enough to justify leveraging HW ECC for instance, which could be one advantage of the per-partition ECC scheme.

AFAICT, there's no such tools for the sunxi platform (but I might be wrong).

Quoted 6 lines
Quoted 3 lines

This implementation is not that complex and should not impact performances (it's just using cur_ecc pointer instead of intern ecc struct).

How about reading/erasing/writing concurrently (as in having two user-space applications), is not that going to incur some sort of "ECC context switching" cost?

I can only talk for the sunxi NAND driver, and AFAIK, for this driver, switching from one ECC config to another shouldn't imply any performance cost.

I'll do some measurements to validate what I'm saying.

Quoted 3 lines

I am also not sure if all NAND controllers
will behave (they should) correctly when you switch from one ECC scheme to another on the fly like this could be happening.

The decision to use per-partition ECC config is left to the NAND controller driver, thus, if a driver does not support ECC config switching (or if this implies too much performance cost) it can just use the standard mtd_device_parse_register or assign part's ecc pointer to NULL.

I can even go further and take the nand_part code out of nand_base.c to make it optional (I would just need to export some NAND core functions). The same goes for the NAND partition list and list lock stored in the nand_chip
struct: we can make it optional depending on a NAND_PART Kconfig option.

As you can see, I'm not giving up on this feature :-), because this would help me (and hopefully other users too) a lot to have access to these specific partition without any user space converters.

Best Regards,

Boris

Quoted 70 lines
Quoted 68 lines

Most of the extra code introduced by this series come from the new partition type
handling, which is quite straightforward BTW.

Anyway, I understand your concern. Could MTD maintainers (and NAND driver developpers) give there opinion too ?

BTW, I'm also working on a data randomization layer (needed by some MLC/TLC chips)
within the NAND core framework and I'm using the same per partition approach (for the exact same reason: boot0 partition uses a randomizer seed that might not fit
the NAND chip requirements).

Should I reconsider doing this too ?

Thanks for you comments.

Best Regards,

Boris

Quoted 46 lines
Quoted 44 lines

This patch series also provides an helper function to parse DT defined NAND
partitions (ofnandpart_parse).

If you want to test it you'll have to replace calls to mtd_device_parse_register with ofnandpart_parse within your NAND controller
driver and implement a driver specific parser function that will provide the ECC config (see ofnandpart_data struct).

The 4th patch of this series is here as an example on how to move from MTD
partitions to NAND partitions.

Best Regards,

Boris

Changes since v1:
- almost everything :-)

Boris BREZILLON (4):
mtd: nand: take nand_ecc_ctrl initialization out of nand_scan_tail
mtd: nand: add support for NAND partitions
mtd: nand: add DT NAND partition parser
mtd: nand: add NAND partition support to the sunxi driver

   drivers/mtd/nand/Kconfig      |    4 +
   drivers/mtd/nand/Makefile     |    2 +
   drivers/mtd/nand/nand_base.c  |  763
++++++++++++++++++++++++++++++++---------
   drivers/mtd/nand/ofnandpart.c |  104 ++++++
   drivers/mtd/nand/sunxi_nand.c |   69 +++-
   include/linux/mtd/nand.h      |   54 +++
   6 files changed, 835 insertions(+), 161 deletions(-)

create mode 100644 drivers/mtd/nand/ofnandpart.c

--
1.7.9.5

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