Skip to contentSkip to conversation

mtd: Add __nand_calculate_ecc() to NAND ECC functions

PATCH In review Akinobu Mita 4 participants 9 messages Oct 19, 2009 – Oct 21, 2009

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

PATCH 1/2 mtd: Add __nand_calculate_ecc() to NAND ECC functions

Add __nand_calculate_ecc() which does not take struct mtd_info. The built-in 256/512 software ECC calculation and correction tester will use it.

Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>
---
 drivers/mtd/nand/nand_ecc.c  |   25 ++++++++++++++++++++-----
 include/linux/mtd/nand_ecc.h |    6 ++++++
 2 files changed, 26 insertions(+), 5 deletions(-)
drivers/mtd/nand/nand_ecc.c +20 -5
index db7ae9d..809fb53 100644
@@ -150,20 +150,19 @@ static const char addressbits[256] = {
 };
 
 /**
- * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
+ * __nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
  *			 block
- * @mtd:	MTD block structure
  * @buf:	input buffer with raw data
+ * @eccsize:	data bytes per ecc step (256 or 512)
  * @code:	output buffer with ECC
  */
-int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
+void __nand_calculate_ecc(const unsigned char *buf, unsigned int eccsize,
 		       unsigned char *code)
 {
 	int i;
 	const uint32_t *bp = (uint32_t *)buf;
 	/* 256 or 512 bytes/ecc  */
-	const uint32_t eccsize_mult =
-			(((struct nand_chip *)mtd->priv)->ecc.size) >> 8;
+	const uint32_t eccsize_mult = eccsize >> 8;
 	uint32_t cur;		/* current value in buffer */
 	/* rp0..rp15..rp17 are the various accumulated parities (per byte) */
 	uint32_t rp0, rp1, rp2, rp3, rp4, rp5, rp6, rp7;
@@ -412,6 +411,22 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
 		    (invparity[par & 0x55] << 2) |
 		    (invparity[rp17] << 1) |
 		    (invparity[rp16] << 0);
+}
+EXPORT_SYMBOL(__nand_calculate_ecc);
+
+/**
+ * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
+ *			 block
+ * @mtd:	MTD block structure
+ * @buf:	input buffer with raw data
+ * @code:	output buffer with ECC
+ */
+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);
+
 	return 0;
 }
 EXPORT_SYMBOL(nand_calculate_ecc);
include/linux/mtd/nand_ecc.h +6 -0
index 052ea8c..9cb10ff 100644
@@ -16,6 +16,12 @@
 struct mtd_info;
 
 /*
+ * Calculate 3 byte ECC code for eccsize byte block
+ */
+void __nand_calculate_ecc(const u_char *dat, unsigned int eccsize,
+				u_char *ecc_code);
+
+/*
  * Calculate 3 byte ECC code for 256 byte block
  */
 int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code);
Signature · 1 line
1.5.4.3
#1 lore raw

PATCH 2/2 MTD: Add nand_ecc test module

This module tests NAND ECC functions.

The test is simple.

1. Create a 256 or 512 bytes block of data filled with random bytes (data)
2. Duplicate the data block and inject single bit error (error_data)
3. Try to correct error_data
4. Compare data and error_data

This test is added into new MTD test group called MTD NAND test which requires MTD NAND device support.

Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>
---
 drivers/mtd/Kconfig               |    6 +++
 drivers/mtd/tests/Makefile        |    1 +
 drivers/mtd/tests/nand_ecc-test.c |   88 +++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/tests/nand_ecc-test.c
drivers/mtd/Kconfig +6 -0
index ecf90f5..abe5c7f 100644
@@ -33,6 +33,12 @@ config MTD_TESTS
 	  should normally be compiled as kernel modules. The modules perform
 	  various checks and verifications when loaded.
 
+config MTD_NAND_TESTS
+	tristate "MTD NAND tests support"
+	depends on MTD_TESTS && MTD_NAND
+	help
+	  This option enables MTD tests which require NAND Device support.
+
 config MTD_CONCAT
 	tristate "MTD concatenating support"
 	help
drivers/mtd/tests/Makefile +1 -0
index c1d5013..3994d5a 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_MTD_TESTS) += mtd_speedtest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o
+obj-$(CONFIG_MTD_NAND_TESTS) += nand_ecc-test.o
drivers/mtd/tests/nand_ecc-test.c new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
1.5.4.3
#2 lore raw

Re: [PATCH 2/2] MTD: Add nand_ecc test module

Quoted 12 lines · Akinobu Mita

This module tests NAND ECC functions.

The test is simple.

1. Create a 256 or 512 bytes block of data filled with random bytes (data)
2. Duplicate the data block and inject single bit error (error_data)
3. Try to correct error_data
4. Compare data and error_data

This test is added into new MTD test group called MTD NAND test which requires MTD NAND device support.

...

drivers/mtd/tests/nand_ecc-test.c line 18

Quoted 3 lines
drivers/mtd/tests/nand_ecc-test.c new file +3 -0
+
+#if defined(CONFIG_MTD_NAND) || defined(CONFIG_MTD_NAND_MODULE)
+

Oops. I forgot to remove this ifdefs.

#3 lore raw

PATCH 2/2 MTD: Add nand_ecc test module

* v2 changes
- remove ifdef
- make inject_single_bit_error static

This module tests NAND ECC functions.

The test is simple.

1. Create a 256 or 512 bytes block of data filled with random bytes (data)
2. Duplicate the data block and inject single bit error (error_data)
3. Try to correct error_data
4. Compare data and error_data

This test is added into new MTD test group called MTD NAND test which requires MTD NAND device support.

Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>
---
 drivers/mtd/Kconfig               |    6 +++
 drivers/mtd/tests/Makefile        |    1 +
 drivers/mtd/tests/nand_ecc-test.c |   76 +++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/tests/nand_ecc-test.c
drivers/mtd/Kconfig +6 -0
index ecf90f5..abe5c7f 100644
@@ -33,6 +33,12 @@ config MTD_TESTS
 	  should normally be compiled as kernel modules. The modules perform
 	  various checks and verifications when loaded.
 
+config MTD_NAND_TESTS
+	tristate "MTD NAND tests support"
+	depends on MTD_TESTS && MTD_NAND
+	help
+	  This option enables MTD tests which require NAND Device support.
+
 config MTD_CONCAT
 	tristate "MTD concatenating support"
 	help
drivers/mtd/tests/Makefile +1 -0
index c1d5013..3994d5a 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_MTD_TESTS) += mtd_speedtest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o
+obj-$(CONFIG_MTD_NAND_TESTS) += nand_ecc-test.o
drivers/mtd/tests/nand_ecc-test.c new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
1.5.4.3
#4 lore raw

Re: [PATCH 2/2] MTD: Add nand_ecc test module

In reply to Akinobu Mita
Quoted 30 lines · Akinobu Mita

This module tests NAND ECC functions.

The test is simple.

1. Create a 256 or 512 bytes block of data filled with random bytes (data)
2. Duplicate the data block and inject single bit error (error_data)
3. Try to correct error_data
4. Compare data and error_data

This test is added into new MTD test group called MTD NAND test which requires MTD NAND device support.

Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>
---
 drivers/mtd/Kconfig               |    6 +++
 drivers/mtd/tests/Makefile        |    1 +
 drivers/mtd/tests/nand_ecc-test.c |   88 +++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/tests/nand_ecc-test.c
drivers/mtd/Kconfig +0 -0
index ecf90f5..abe5c7f 100644
@@ -33,6 +33,12 @@ config MTD_TESTS
 	  should normally be compiled as kernel modules. The modules perform
 	  various checks and verifications when loaded.

drivers/mtd/Kconfig config MTD_TESTS · line 44

Quoted 10 lines
drivers/mtd/Kconfig +6 -0
 
+config MTD_NAND_TESTS
+	tristate "MTD NAND tests support"
+	depends on MTD_TESTS && MTD_NAND
+	help
+	  This option enables MTD tests which require NAND Device support.
+
 config MTD_CONCAT
 	tristate "MTD concatenating support"
 	help

Could this please be a separate patch? Also, some of the existing tests are NAND only as well, so could do corresponding Makefile changes in the same patch and move the to the MTD_NAND_TESTS set? The tests are:

mtd_oobtest.c
mtd_pagetest.c
mtd_subpagetest.c

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#5 lore raw

Re: [PATCH 2/2] MTD: Add nand_ecc test module

Quoted 46 lines · Artem Bityutskiy
Quoted 30 lines · Akinobu Mita

This module tests NAND ECC functions.

The test is simple.

1. Create a 256 or 512 bytes block of data filled with random bytes (data)
2. Duplicate the data block and inject single bit error (error_data)
3. Try to correct error_data
4. Compare data and error_data

This test is added into new MTD test group called MTD NAND test which requires MTD NAND device support.

Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>
---
 drivers/mtd/Kconfig               |    6 +++
 drivers/mtd/tests/Makefile        |    1 +
 drivers/mtd/tests/nand_ecc-test.c |   88 +++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/tests/nand_ecc-test.c
drivers/mtd/Kconfig +0 -0
index ecf90f5..abe5c7f 100644
@@ -33,6 +33,12 @@ config MTD_TESTS
 	  should normally be compiled as kernel modules. The modules perform
 	  various checks and verifications when loaded.

drivers/mtd/Kconfig config MTD_TESTS · line 44

Quoted 10 lines
drivers/mtd/Kconfig +6 -0
 
+config MTD_NAND_TESTS
+	tristate "MTD NAND tests support"
+	depends on MTD_TESTS && MTD_NAND
+	help
+	  This option enables MTD tests which require NAND Device support.
+
 config MTD_CONCAT
 	tristate "MTD concatenating support"
 	help

Could this please be a separate patch? Also, some of the existing tests are NAND only as well, so could do corresponding Makefile changes in the same patch and move the to the MTD_NAND_TESTS set? The tests are:

Quoted 3 lines

mtd_oobtest.c
mtd_pagetest.c
mtd_subpagetest.c

Err, and of course this patch has to be the _last_ in the series, to preserve bisectability.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#6 lore raw

Re: [PATCH 2/2] MTD: Add nand_ecc test module

In reply to Artem Bityutskiy
Quoted 22 lines · Artem Bityutskiy
Quoted 7 lines
drivers/mtd/Kconfig +0 -0
index ecf90f5..abe5c7f 100644
@@ -33,6 +33,12 @@ config MTD_TESTS
 	  should normally be compiled as kernel modules. The modules perform
 	  various checks and verifications when loaded.

drivers/mtd/Kconfig config MTD_TESTS · line 44

Quoted 10 lines
drivers/mtd/Kconfig +6 -0
 
+config MTD_NAND_TESTS
+	tristate "MTD NAND tests support"
+	depends on MTD_TESTS && MTD_NAND
+	help
+	  This option enables MTD tests which require NAND Device support.
+
 config MTD_CONCAT
 	tristate "MTD concatenating support"
 	help

Could this please be a separate patch? Also, some of the existing tests are NAND only as well, so could do corresponding Makefile changes in the same patch and move the to the MTD_NAND_TESTS set? The tests are:

Quoted 3 lines

mtd_oobtest.c
mtd_pagetest.c
mtd_subpagetest.c

Should these MTD NAND tests support OneNAND device, too?

If so, the config with !CONFIG_MTD_NAND && MTD_ONENAND=m cannot select this new MTD_NAND_TESTS. So Kconfig dependency should be:

config MTD_NAND_TESTS
tristate "MTD NAND tests support"
depends on MTD_TEST
depends on MTD_NAND || MTD_ONENAND

But nand_ecc-test obviously needs CONFIG_MTD_NAND and cannot exist in the same group.

#7 lore raw

Re: [PATCH 2/2] MTD: Add nand_ecc test module

Quoted 32 lines · ext Akinobu Mita
Quoted 22 lines · Artem Bityutskiy
Quoted 7 lines
drivers/mtd/Kconfig +0 -0
index ecf90f5..abe5c7f 100644
@@ -33,6 +33,12 @@ config MTD_TESTS
 	  should normally be compiled as kernel modules. The modules perform
 	  various checks and verifications when loaded.

drivers/mtd/Kconfig config MTD_TESTS · line 44

Quoted 10 lines
drivers/mtd/Kconfig +6 -0
 
+config MTD_NAND_TESTS
+	tristate "MTD NAND tests support"
+	depends on MTD_TESTS && MTD_NAND
+	help
+	  This option enables MTD tests which require NAND Device support.
+
 config MTD_CONCAT
 	tristate "MTD concatenating support"
 	help

Could this please be a separate patch? Also, some of the existing tests are NAND only as well, so could do corresponding Makefile changes in the same patch and move the to the MTD_NAND_TESTS set? The tests are:

Quoted 3 lines

mtd_oobtest.c
mtd_pagetest.c
mtd_subpagetest.c

Should these MTD NAND tests support OneNAND device, too?

If so, the config with !CONFIG_MTD_NAND && MTD_ONENAND=m cannot select this new MTD_NAND_TESTS. So Kconfig dependency should be:

Quoted 7 lines

config MTD_NAND_TESTS
tristate "MTD NAND tests support"
depends on MTD_TEST
depends on MTD_NAND || MTD_ONENAND

But nand_ecc-test obviously needs CONFIG_MTD_NAND and cannot exist in the same group.

Oh, I see. May be your original idea with ifdefs in the code was not bad at all :-) ?

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#8 lore raw
In reply to Akinobu Mita
Quoted 71 lines · Akinobu Mita

Add __nand_calculate_ecc() which does not take struct mtd_info. The built-in 256/512 software ECC calculation and correction tester will use it.

Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>

---
 drivers/mtd/nand/nand_ecc.c  |   25 ++++++++++++++++++++----- include/linux/mtd/nand_ecc.h |    6 ++++++

 2 files changed, 26 insertions(+), 5 deletions(-)
drivers/mtd/nand/nand_ecc.c +4 -5
index db7ae9d..809fb53 100644
@@ -150,20 +150,19 @@ static const char addressbits[256] = {
  };
 
  /**
- * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
+ * __nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
  *                      block
- * @mtd:       MTD block structure
  * @buf:       input buffer with raw data
+ * @eccsize:   data bytes per ecc step (256 or 512)
  * @code:      output buffer with ECC
  */
-int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
+void __nand_calculate_ecc(const unsigned char *buf, unsigned int eccsize,
                       unsigned char *code)
  {
        int i;
        const uint32_t *bp = (uint32_t *)buf;
        /* 256 or 512 bytes/ecc  */
-       const uint32_t eccsize_mult =
-                       (((struct nand_chip *)mtd->priv)->ecc.size) >> 8;
+       const uint32_t eccsize_mult = eccsize >> 8;

       uint32_t cur;           /* current value in buffer */
       /* rp0..rp15..rp17 are the various accumulated parities (per byte) */ uint32_t rp0, rp1, rp2, rp3, rp4, rp5, rp6, rp7;

drivers/mtd/nand/nand_ecc.c +0 -0
@@ -412,6 +411,22 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,

                   (invparity[par & 0x55] << 2) |
                   (invparity[rp17] << 1) |
                   (invparity[rp16] << 0);

drivers/mtd/nand/nand_ecc.c +16 -0
+}
+EXPORT_SYMBOL(__nand_calculate_ecc);
+
+/**
+ * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
+ *                      block
+ * @mtd:       MTD block structure
+ * @buf:       input buffer with raw data
+ * @code:      output buffer with ECC
+ */
+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);
+

       return 0;
 }
 EXPORT_SYMBOL(nand_calculate_ecc);

include/linux/mtd/nand_ecc.h +0 -0
index 052ea8c..9cb10ff 100644
@@ -16,6 +16,12 @@
  struct mtd_info;

include/linux/mtd/nand_ecc.h line 26

Quoted 10 lines
include/linux/mtd/nand_ecc.h +6 -0
 
  /*
+ * Calculate 3 byte ECC code for eccsize byte block
+ */
+void __nand_calculate_ecc(const u_char *dat, unsigned int eccsize,
+                               u_char *ecc_code);
+
+/*
  * Calculate 3 byte ECC code for 256 byte block
  */

Could you please correct above comment too?

Signature · 2 lines
Regards,
Vimal Singh
Quoted 9 lines
include/linux/mtd/nand_ecc.h +0 -1
  int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code);
--

1.5.4.3

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