Skip to contentSkip to conversation

mtd: nand: omap_gpmc: Fix NAND in SPL for AM335x

PATCH Superseded Roger Quadros 5 participants 14 messages Nov 25, 2023 – Dec 9, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: nand: omap_gpmc: Fix NAND in SPL for AM335x

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
drivers/mtd/nand/raw/omap_gpmc.c +29 -66
index 1a5ed0de31..2d2d2c2b6d 100644
@@ -293,7 +293,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 		break;
 	case OMAP_ECC_BCH8_CODE_HW:
 		bch_type = 1;
-		nsectors = chip->ecc.steps;
+		nsectors = 1;
 		if (mode == NAND_ECC_READ) {
 			wr_mode   = BCH_WRAPMODE_1;
 			ecc_size0 = BCH8R_ECC_SIZE0;
@@ -306,7 +306,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 		break;
 	case OMAP_ECC_BCH16_CODE_HW:
 		bch_type = 0x2;
-		nsectors = chip->ecc.steps;
+		nsectors = 1;
 		if (mode == NAND_ECC_READ) {
 			wr_mode   = 0x01;
 			ecc_size0 = 52; /* ECC bits in nibbles per sector */
@@ -345,17 +345,16 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 }
 
 /**
- * _omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
+ * omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
  * @mtd:        MTD device structure
  * @dat:        The pointer to data on which ecc is computed
  * @ecc_code:   The ecc_code buffer
- * @sector:     The sector number (for a multi sector page)
  *
  * Support calculating of BCH4/8/16 ECC vectors for one sector
  * within a page. Sector number is in @sector.
  */
-static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
-				   u8 *ecc_code, int sector)
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+				  u8 *ecc_code)
 {
 	struct nand_chip *chip = mtd_to_nand(mtd);
 	struct omap_nand_info *info = nand_get_controller_data(chip);
@@ -368,7 +367,7 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 	case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
 #endif
 	case OMAP_ECC_BCH8_CODE_HW:
-		ptr = &gpmc_cfg->bch_result_0_3[sector].bch_result_x[3];
+		ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
 		val = readl(ptr);
 		ecc_code[i++] = (val >>  0) & 0xFF;
 		ptr--;
@@ -383,21 +382,21 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 
 		break;
 	case OMAP_ECC_BCH16_CODE_HW:
-		val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[2]);
+		val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[2]);
 		ecc_code[i++] = (val >>  8) & 0xFF;
 		ecc_code[i++] = (val >>  0) & 0xFF;
-		val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[1]);
+		val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[1]);
 		ecc_code[i++] = (val >> 24) & 0xFF;
 		ecc_code[i++] = (val >> 16) & 0xFF;
 		ecc_code[i++] = (val >>  8) & 0xFF;
 		ecc_code[i++] = (val >>  0) & 0xFF;
-		val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[0]);
+		val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[0]);
 		ecc_code[i++] = (val >> 24) & 0xFF;
 		ecc_code[i++] = (val >> 16) & 0xFF;
 		ecc_code[i++] = (val >>  8) & 0xFF;
 		ecc_code[i++] = (val >>  0) & 0xFF;
 		for (j = 3; j >= 0; j--) {
-			val = readl(&gpmc_cfg->bch_result_0_3[sector].bch_result_x[j]
+			val = readl(&gpmc_cfg->bch_result_0_3[0].bch_result_x[j]
 									);
 			ecc_code[i++] = (val >> 24) & 0xFF;
 			ecc_code[i++] = (val >> 16) & 0xFF;
@@ -431,22 +430,6 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 	return 0;
 }
 
-/**
- * omap_calculate_ecc_bch - ECC generator for 1 sector
- * @mtd:        MTD device structure
- * @dat:	The pointer to data on which ecc is computed
- * @ecc_code:	The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
- * when SW based correction is required as ECC is required for one sector
- * at a time.
- */
-static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
-				  const u_char *dat, u_char *ecc_calc)
-{
-	return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
-}
-
 static inline void omap_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
 	struct nand_chip *chip = mtd_to_nand(mtd);
@@ -572,34 +555,6 @@ static void omap_nand_read_prefetch(struct mtd_info *mtd, uint8_t *buf, int len)
 
 #ifdef CONFIG_NAND_OMAP_ELM
 
-/**
- * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors
- * @mtd:	MTD device structure
- * @dat:	The pointer to data on which ecc is computed
- * @ecc_code:	The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ecc vectors for the entire page in one go.
- */
-static int omap_calculate_ecc_bch_multi(struct mtd_info *mtd,
-					const u_char *dat, u_char *ecc_calc)
-{
-	struct nand_chip *chip = mtd_to_nand(mtd);
-	int eccbytes = chip->ecc.bytes;
-	unsigned long nsectors;
-	int i, ret;
-
-	nsectors = ((readl(&gpmc_cfg->ecc_config) >> 4) & 0x7) + 1;
-	for (i = 0; i < nsectors; i++) {
-		ret = _omap_calculate_ecc_bch(mtd, dat, ecc_calc, i);
-		if (ret)
-			return ret;
-
-		ecc_calc += eccbytes;
-	}
-
-	return 0;
-}
-
 /*
  * omap_reverse_list - re-orders list elements in reverse order [internal]
  * @list:	pointer to start of list
@@ -752,7 +707,6 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 {
 	int i, eccsize = chip->ecc.size;
 	int eccbytes = chip->ecc.bytes;
-	int ecctotal = chip->ecc.total;
 	int eccsteps = chip->ecc.steps;
 	uint8_t *p = buf;
 	uint8_t *ecc_calc = chip->buffers->ecccalc;
@@ -760,24 +714,30 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 	uint32_t *eccpos = chip->ecc.layout->eccpos;
 	uint8_t *oob = chip->oob_poi;
 	uint32_t oob_pos;
+	u32 data_pos = 0;
 
 	/* oob area start */
 	oob_pos = (eccsize * eccsteps) + chip->ecc.layout->eccpos[0];
 	oob += chip->ecc.layout->eccpos[0];
 
-	/* Enable ECC engine */
-	chip->ecc.hwctl(mtd, NAND_ECC_READ);
+	for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize,
+	     oob += eccbytes) {
+		/* Enable ECC engine */
+		chip->ecc.hwctl(mtd, NAND_ECC_READ);
 
-	/* read entire page */
-	chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 0, -1);
-	chip->read_buf(mtd, buf, mtd->writesize);
+		/* read data */
+		chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);
+		chip->read_buf(mtd, p, eccsize);
 
-	/* read all ecc bytes from oob area */
-	chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-	chip->read_buf(mtd, oob, ecctotal);
+		/* read respective ecc from oob area */
+		chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+		chip->read_buf(mtd, oob, eccbytes);
+		/* read syndrome */
+		chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-	/* Calculate ecc bytes */
-	omap_calculate_ecc_bch_multi(mtd, buf, ecc_calc);
+		data_pos += eccsize;
+		oob_pos += eccbytes;
+	}
 
 	for (i = 0; i < chip->ecc.total; i++)
 		ecc_code[i] = chip->oob_poi[eccpos[i]];
@@ -945,6 +905,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
 		nand->ecc.hwctl		= omap_enable_hwecc_bch;
 		nand->ecc.correct	= omap_correct_data_bch_sw;
 		nand->ecc.calculate	= omap_calculate_ecc_bch;
+		nand->ecc.steps		= eccsteps;
 		/* define ecc-layout */
 		ecclayout->eccbytes	= nand->ecc.bytes * eccsteps;
 		ecclayout->eccpos[0]	= BADBLOCK_MARKER_LENGTH;
@@ -987,6 +948,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
 		nand->ecc.correct	= omap_correct_data_bch;
 		nand->ecc.calculate	= omap_calculate_ecc_bch;
 		nand->ecc.read_page	= omap_read_page_bch;
+		nand->ecc.steps		= eccsteps;
 		/* define ecc-layout */
 		ecclayout->eccbytes	= nand->ecc.bytes * eccsteps;
 		for (i = 0; i < ecclayout->eccbytes; i++)
@@ -1020,6 +982,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
 		nand->ecc.correct	= omap_correct_data_bch;
 		nand->ecc.calculate	= omap_calculate_ecc_bch;
 		nand->ecc.read_page	= omap_read_page_bch;
+		nand->ecc.steps		= eccsteps;
 		/* define ecc-layout */
 		ecclayout->eccbytes	= nand->ecc.bytes * eccsteps;
 		for (i = 0; i < ecclayout->eccbytes; i++)

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7

Signature · 1 line
2.34.1
#1 lore raw

Hi Roger

Quoted 224 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
drivers/mtd/nand/raw/omap_gpmc.c +29 -66
index 1a5ed0de31..2d2d2c2b6d 100644
@@ -293,7 +293,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
                break;
        case OMAP_ECC_BCH8_CODE_HW:
                bch_type = 1;
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = BCH_WRAPMODE_1;
                        ecc_size0 = BCH8R_ECC_SIZE0;
@@ -306,7 +306,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
                break;
        case OMAP_ECC_BCH16_CODE_HW:
                bch_type = 0x2;
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = 0x01;
                        ecc_size0 = 52; /* ECC bits in nibbles per sector */
@@ -345,17 +345,16 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 }
 
 /**
- * _omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
+ * omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
  * @mtd:        MTD device structure
  * @dat:        The pointer to data on which ecc is computed
  * @ecc_code:   The ecc_code buffer
- * @sector:     The sector number (for a multi sector page)
  *
  * Support calculating of BCH4/8/16 ECC vectors for one sector
  * within a page. Sector number is in @sector.
  */
-static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
-                                  u8 *ecc_code, int sector)
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+                                 u8 *ecc_code)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct omap_nand_info *info = nand_get_controller_data(chip);
@@ -368,7 +367,7 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
        case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
 #endif
        case OMAP_ECC_BCH8_CODE_HW:
-               ptr = &gpmc_cfg->bch_result_0_3[sector].bch_result_x[3];
+               ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
                val = readl(ptr);
                ecc_code[i++] = (val >>  0) & 0xFF;
                ptr--;
@@ -383,21 +382,21 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 
                break;
        case OMAP_ECC_BCH16_CODE_HW:
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[2]);
+               val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[2]);
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[1]);
+               val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[1]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[0]);
+               val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[0]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
                for (j = 3; j >= 0; j--) {
-                       val = readl(&gpmc_cfg->bch_result_0_3[sector].bch_result_x[j]
+                       val = readl(&gpmc_cfg->bch_result_0_3[0].bch_result_x[j]
                                                                        );
                        ecc_code[i++] = (val >> 24) & 0xFF;
                        ecc_code[i++] = (val >> 16) & 0xFF;
@@ -431,22 +430,6 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
        return 0;
 }
 
-/**
- * omap_calculate_ecc_bch - ECC generator for 1 sector
- * @mtd:        MTD device structure
- * @dat:       The pointer to data on which ecc is computed
- * @ecc_code:  The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
- * when SW based correction is required as ECC is required for one sector
- * at a time.
- */
-static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
-                                 const u_char *dat, u_char *ecc_calc)
-{
-       return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
-}
-
 static inline void omap_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
@@ -572,34 +555,6 @@ static void omap_nand_read_prefetch(struct mtd_info *mtd, uint8_t *buf, int len)
 
 #ifdef CONFIG_NAND_OMAP_ELM
 
-/**
- * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors
- * @mtd:       MTD device structure
- * @dat:       The pointer to data on which ecc is computed
- * @ecc_code:  The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ecc vectors for the entire page in one go.
- */
-static int omap_calculate_ecc_bch_multi(struct mtd_info *mtd,
-                                       const u_char *dat, u_char *ecc_calc)
-{
-       struct nand_chip *chip = mtd_to_nand(mtd);
-       int eccbytes = chip->ecc.bytes;
-       unsigned long nsectors;
-       int i, ret;
-
-       nsectors = ((readl(&gpmc_cfg->ecc_config) >> 4) & 0x7) + 1;
-       for (i = 0; i < nsectors; i++) {
-               ret = _omap_calculate_ecc_bch(mtd, dat, ecc_calc, i);
-               if (ret)
-                       return ret;
-
-               ecc_calc += eccbytes;
-       }
-
-       return 0;
-}
-
 /*
  * omap_reverse_list - re-orders list elements in reverse order [internal]
  * @list:      pointer to start of list
@@ -752,7 +707,6 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 {
        int i, eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
-       int ecctotal = chip->ecc.total;
        int eccsteps = chip->ecc.steps;
        uint8_t *p = buf;
        uint8_t *ecc_calc = chip->buffers->ecccalc;
@@ -760,24 +714,30 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
        uint32_t *eccpos = chip->ecc.layout->eccpos;
        uint8_t *oob = chip->oob_poi;
        uint32_t oob_pos;
+       u32 data_pos = 0;
 
        /* oob area start */
        oob_pos = (eccsize * eccsteps) + chip->ecc.layout->eccpos[0];
        oob += chip->ecc.layout->eccpos[0];
 
-       /* Enable ECC engine */
-       chip->ecc.hwctl(mtd, NAND_ECC_READ);
+       for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize,
+            oob += eccbytes) {
+               /* Enable ECC engine */
+               chip->ecc.hwctl(mtd, NAND_ECC_READ);
 
-       /* read entire page */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 0, -1);
-       chip->read_buf(mtd, buf, mtd->writesize);
+               /* read data */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);
+               chip->read_buf(mtd, p, eccsize);
 
-       /* read all ecc bytes from oob area */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-       chip->read_buf(mtd, oob, ecctotal);
+               /* read respective ecc from oob area */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+               chip->read_buf(mtd, oob, eccbytes);
+               /* read syndrome */
+               chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-       /* Calculate ecc bytes */
-       omap_calculate_ecc_bch_multi(mtd, buf, ecc_calc);
+               data_pos += eccsize;
+               oob_pos += eccbytes;
+       }
 
        for (i = 0; i < chip->ecc.total; i++)
                ecc_code[i] = chip->oob_poi[eccpos[i]];
@@ -945,6 +905,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.hwctl         = omap_enable_hwecc_bch;
                nand->ecc.correct       = omap_correct_data_bch_sw;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                ecclayout->eccpos[0]    = BADBLOCK_MARKER_LENGTH;
@@ -987,6 +948,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++)
@@ -1020,6 +982,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++)
Quoted 4 lines

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7 --
2.34.1

Let's wait on some tested-by

Michael

#5 lore raw
In reply to Roger Quadros
Quoted 5 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Quoted 7 lines

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)

I'm glad to see this fixed. My question is, can we abstract this slightly as I assume there's a performance hit on the newer SoCs that support more than one sector at a time for ECC and I assume it's just am335x and related that don't support the feature. Thanks.

Signature · 1 line
Tom
Tested-by on v1 1/1
#8 lore raw
In reply to Roger Quadros

Hello Roger,

Quoted 12 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)

[...]

Quoted 2 lines

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7

Based on this commit and with the (rebased) patchset from Enrico:

https://lists.denx.de/pipermail/u-boot/2023-November/536793.html

I can confirm, that the draco thuban board now boots again from NAND.

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
Tested-by
#2 lore raw
In reply to Michael Nazzareno Trimarchi

Hi,

Works on my draco thuban AM335x based boards booting from NAND with ECC BCH8 code.

Thanks

Quoted 264 lines

-----Original Message-----
From: Michael Nazzareno Trimarchi <[email protected]>
Sent: Saturday, November 25, 2023 2:07 PM
To: Roger Quadros <[email protected]>
Cc: [email protected]; Schocher, Heiko (EXT) (DENX Software Engineering GmbH) <[email protected]>; Leto, Enrico (SI BP R&D ZG FW CCP) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mtd: nand: omap_gpmc: Fix NAND in SPL for AM335x

Hi Roger

drivers/mtd/nand/raw/omap_gpmc.c static void __maybe_unused

Quoted 22 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL NAND loader. This driver expects 1 sector at a time ECC and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd:
rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based

correction")

---
 drivers/mtd/nand/raw/omap_gpmc.c | 95
++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
drivers/mtd/nand/raw/omap_gpmc.c +0 -0
index 1a5ed0de31..2d2d2c2b6d 100644
@@ -293,7 +293,7 @@ static void __maybe_unused

omap_enable_hwecc_bch(struct mtd_info *mtd,

Quoted 9 lines
drivers/mtd/nand/raw/omap_gpmc.c +1 -1
                break;
        case OMAP_ECC_BCH8_CODE_HW:
                bch_type = 1;
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = BCH_WRAPMODE_1;
                        ecc_size0 = BCH8R_ECC_SIZE0; @@ -306,7 +306,7

@@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info

*mtd,

drivers/mtd/nand/raw/omap_gpmc.c static int _omap_calculate_ecc_bch(struct mtd_info

Quoted 30 lines
                break;
        case OMAP_ECC_BCH16_CODE_HW:
                bch_type = 0x2;
drivers/mtd/nand/raw/omap_gpmc.c +1 -1
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = 0x01;
                        ecc_size0 = 52; /* ECC bits in nibbles per

sector */ @@ -345,17 +345,16 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, }

/**
- * _omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
+ * omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector

  * @mtd:        MTD device structure
  * @dat:        The pointer to data on which ecc is computed
  * @ecc_code:   The ecc_code buffer
- * @sector:     The sector number (for a multi sector page)

*
* Support calculating of BCH4/8/16 ECC vectors for one sector
* within a page. Sector number is in @sector.
*/

drivers/mtd/nand/raw/omap_gpmc.c +2 -2
-static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
-                                  u8 *ecc_code, int sector)
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+                                 u8 *ecc_code)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct omap_nand_info *info = nand_get_controller_data(chip);
@@ -368,7 +367,7 @@ static int _omap_calculate_ecc_bch(struct mtd_info

*mtd, const u8 *dat,

Quoted 30 lines
drivers/mtd/nand/raw/omap_gpmc.c +7 -4
        case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
 #endif
        case OMAP_ECC_BCH8_CODE_HW:
-               ptr = &gpmc_cfg->bch_result_0_3[sector].bch_result_x[3];
+               ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
                val = readl(ptr);
                ecc_code[i++] = (val >>  0) & 0xFF;
                ptr--;
@@ -383,21 +382,21 @@ static int _omap_calculate_ecc_bch(struct
 mtd_info *mtd, const u8 *dat,
 
                break;
        case OMAP_ECC_BCH16_CODE_HW:
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[2]);
+               val =
+ readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[2]);
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[1]);
+               val =
+ readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[1]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[0]);
+               val =
+ readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[0]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;

drivers/mtd/nand/raw/omap_gpmc.c static int _omap_calculate_ecc_bch(struct

Quoted 10 lines
drivers/mtd/nand/raw/omap_gpmc.c +3 -1
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
                for (j = 3; j >= 0; j--) {
-                       val = readl(&gpmc_cfg->bch_result_0_3[sector].bch_result_x[j]
+                       val =
+ readl(&gpmc_cfg->bch_result_0_3[0].bch_result_x[j]
                                                                        );
                        ecc_code[i++] = (val >> 24) & 0xFF;
                        ecc_code[i++] = (val >> 16) & 0xFF; @@ -431,22
+430,6 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const

u8 *dat,

Quoted 29 lines
        return 0;

}

-/**
- * omap_calculate_ecc_bch - ECC generator for 1 sector
- * @mtd: MTD device structure
- * @dat: The pointer to data on which ecc is computed
- * @ecc_code: The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
- * when SW based correction is required as ECC is required for one sector
- * at a time.
- */

drivers/mtd/nand/raw/omap_gpmc.c +0 -6
-static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
-                                 const u_char *dat, u_char *ecc_calc)
-{
-       return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
-}
-
 static inline void omap_nand_read_buf(struct mtd_info *mtd, uint8_t
*buf, int len)  {
        struct nand_chip *chip = mtd_to_nand(mtd); @@ -572,34 +555,6

@@ static void omap_nand_read_prefetch(struct mtd_info *mtd, uint8_t *buf, int len)

#ifdef CONFIG_NAND_OMAP_ELM

Quoted 7 lines

-/**
- * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors

- * @mtd:       MTD device structure
- * @dat:       The pointer to data on which ecc is computed
- * @ecc_code:  The ecc_code buffer

- *
- * Support calculating of BCH4/8/16 ecc vectors for the entire page in one

go.

Quoted 32 lines

- */

drivers/mtd/nand/raw/omap_gpmc.c +0 -21
-static int omap_calculate_ecc_bch_multi(struct mtd_info *mtd,
-                                       const u_char *dat, u_char *ecc_calc)
-{
-       struct nand_chip *chip = mtd_to_nand(mtd);
-       int eccbytes = chip->ecc.bytes;
-       unsigned long nsectors;
-       int i, ret;
-
-       nsectors = ((readl(&gpmc_cfg->ecc_config) >> 4) & 0x7) + 1;
-       for (i = 0; i < nsectors; i++) {
-               ret = _omap_calculate_ecc_bch(mtd, dat, ecc_calc, i);
-               if (ret)
-                       return ret;
-
-               ecc_calc += eccbytes;
-       }
-
-       return 0;
-}
-
 /*
  * omap_reverse_list - re-orders list elements in reverse order [internal]
  * @list:      pointer to start of list
@@ -752,7 +707,6 @@ static int omap_read_page_bch(struct mtd_info
 *mtd, struct nand_chip *chip,  {
        int i, eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
-       int ecctotal = chip->ecc.total;
        int eccsteps = chip->ecc.steps;
        uint8_t *p = buf;
        uint8_t *ecc_calc = chip->buffers->ecccalc; @@ -760,24 +714,30
Quoted 1 line

@@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip

*chip,

drivers/mtd/nand/raw/omap_gpmc.c static int omap_select_ecc_scheme(struct

Quoted 49 lines
        uint32_t *eccpos = chip->ecc.layout->eccpos;
        uint8_t *oob = chip->oob_poi;
        uint32_t oob_pos;
drivers/mtd/nand/raw/omap_gpmc.c +18 -10
+       u32 data_pos = 0;
 
        /* oob area start */
        oob_pos = (eccsize * eccsteps) + chip->ecc.layout->eccpos[0];
        oob += chip->ecc.layout->eccpos[0];
 
-       /* Enable ECC engine */
-       chip->ecc.hwctl(mtd, NAND_ECC_READ);
+       for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize,
+            oob += eccbytes) {
+               /* Enable ECC engine */
+               chip->ecc.hwctl(mtd, NAND_ECC_READ);
 
-       /* read entire page */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 0, -1);
-       chip->read_buf(mtd, buf, mtd->writesize);
+               /* read data */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);
+               chip->read_buf(mtd, p, eccsize);
 
-       /* read all ecc bytes from oob area */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-       chip->read_buf(mtd, oob, ecctotal);
+               /* read respective ecc from oob area */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+               chip->read_buf(mtd, oob, eccbytes);
+               /* read syndrome */
+               chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-       /* Calculate ecc bytes */
-       omap_calculate_ecc_bch_multi(mtd, buf, ecc_calc);
+               data_pos += eccsize;
+               oob_pos += eccbytes;
+       }
 
        for (i = 0; i < chip->ecc.total; i++)
                ecc_code[i] = chip->oob_poi[eccpos[i]]; @@ -945,6
+905,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.hwctl         = omap_enable_hwecc_bch;
                nand->ecc.correct       = omap_correct_data_bch_sw;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                ecclayout->eccpos[0]    = BADBLOCK_MARKER_LENGTH;
@@ -987,6 +948,7 @@ static int omap_select_ecc_scheme(struct

nand_chip *nand,

Quoted 16 lines
drivers/mtd/nand/raw/omap_gpmc.c +3 -0
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++) @@ -1020,6
+982,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++)
Quoted 4 lines

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7 --
2.34.1

Let's wait on some tested-by

Michael

#3 lore raw

Hi dario

Quoted 273 lines · Enrico

Hi,

Works on my draco thuban AM335x based boards booting from NAND with ECC BCH8 code.

Thanks

Quoted 263 lines

-----Original Message-----
From: Michael Nazzareno Trimarchi <[email protected]>
Sent: Saturday, November 25, 2023 2:07 PM
To: Roger Quadros <[email protected]>
Cc: [email protected]; Schocher, Heiko (EXT) (DENX Software Engineering GmbH) <[email protected]>; Leto, Enrico (SI BP R&D ZG FW CCP) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mtd: nand: omap_gpmc: Fix NAND in SPL for AM335x

Hi Roger

drivers/mtd/nand/raw/omap_gpmc.c static void __maybe_unused

Quoted 22 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL NAND loader. This driver expects 1 sector at a time ECC and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd:
rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based

correction")

---
 drivers/mtd/nand/raw/omap_gpmc.c | 95
++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
drivers/mtd/nand/raw/omap_gpmc.c +0 -0
index 1a5ed0de31..2d2d2c2b6d 100644
@@ -293,7 +293,7 @@ static void __maybe_unused

omap_enable_hwecc_bch(struct mtd_info *mtd,

Quoted 9 lines
drivers/mtd/nand/raw/omap_gpmc.c +1 -1
                break;
        case OMAP_ECC_BCH8_CODE_HW:
                bch_type = 1;
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = BCH_WRAPMODE_1;
                        ecc_size0 = BCH8R_ECC_SIZE0; @@ -306,7 +306,7

@@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info

*mtd,

drivers/mtd/nand/raw/omap_gpmc.c static int _omap_calculate_ecc_bch(struct mtd_info

Quoted 30 lines
                break;
        case OMAP_ECC_BCH16_CODE_HW:
                bch_type = 0x2;
drivers/mtd/nand/raw/omap_gpmc.c +1 -1
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = 0x01;
                        ecc_size0 = 52; /* ECC bits in nibbles per

sector */ @@ -345,17 +345,16 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, }

/**
- * _omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
+ * omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector

  * @mtd:        MTD device structure
  * @dat:        The pointer to data on which ecc is computed
  * @ecc_code:   The ecc_code buffer
- * @sector:     The sector number (for a multi sector page)

*
* Support calculating of BCH4/8/16 ECC vectors for one sector
* within a page. Sector number is in @sector.
*/

drivers/mtd/nand/raw/omap_gpmc.c +2 -2
-static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
-                                  u8 *ecc_code, int sector)
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+                                 u8 *ecc_code)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct omap_nand_info *info = nand_get_controller_data(chip);
@@ -368,7 +367,7 @@ static int _omap_calculate_ecc_bch(struct mtd_info

*mtd, const u8 *dat,

Quoted 30 lines
drivers/mtd/nand/raw/omap_gpmc.c +7 -4
        case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
 #endif
        case OMAP_ECC_BCH8_CODE_HW:
-               ptr = &gpmc_cfg->bch_result_0_3[sector].bch_result_x[3];
+               ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
                val = readl(ptr);
                ecc_code[i++] = (val >>  0) & 0xFF;
                ptr--;
@@ -383,21 +382,21 @@ static int _omap_calculate_ecc_bch(struct
 mtd_info *mtd, const u8 *dat,
 
                break;
        case OMAP_ECC_BCH16_CODE_HW:
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[2]);
+               val =
+ readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[2]);
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[1]);
+               val =
+ readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[1]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[0]);
+               val =
+ readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[0]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;

drivers/mtd/nand/raw/omap_gpmc.c static int _omap_calculate_ecc_bch(struct

Quoted 10 lines
drivers/mtd/nand/raw/omap_gpmc.c +3 -1
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
                for (j = 3; j >= 0; j--) {
-                       val = readl(&gpmc_cfg->bch_result_0_3[sector].bch_result_x[j]
+                       val =
+ readl(&gpmc_cfg->bch_result_0_3[0].bch_result_x[j]
                                                                        );
                        ecc_code[i++] = (val >> 24) & 0xFF;
                        ecc_code[i++] = (val >> 16) & 0xFF; @@ -431,22
+430,6 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const

u8 *dat,

Quoted 29 lines
        return 0;

}

-/**
- * omap_calculate_ecc_bch - ECC generator for 1 sector
- * @mtd: MTD device structure
- * @dat: The pointer to data on which ecc is computed
- * @ecc_code: The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
- * when SW based correction is required as ECC is required for one sector
- * at a time.
- */

drivers/mtd/nand/raw/omap_gpmc.c +0 -6
-static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
-                                 const u_char *dat, u_char *ecc_calc)
-{
-       return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
-}
-
 static inline void omap_nand_read_buf(struct mtd_info *mtd, uint8_t
*buf, int len)  {
        struct nand_chip *chip = mtd_to_nand(mtd); @@ -572,34 +555,6

@@ static void omap_nand_read_prefetch(struct mtd_info *mtd, uint8_t *buf, int len)

#ifdef CONFIG_NAND_OMAP_ELM

Quoted 7 lines

-/**
- * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors

- * @mtd:       MTD device structure
- * @dat:       The pointer to data on which ecc is computed
- * @ecc_code:  The ecc_code buffer

- *
- * Support calculating of BCH4/8/16 ecc vectors for the entire page in one

go.

Quoted 32 lines

- */

drivers/mtd/nand/raw/omap_gpmc.c +0 -21
-static int omap_calculate_ecc_bch_multi(struct mtd_info *mtd,
-                                       const u_char *dat, u_char *ecc_calc)
-{
-       struct nand_chip *chip = mtd_to_nand(mtd);
-       int eccbytes = chip->ecc.bytes;
-       unsigned long nsectors;
-       int i, ret;
-
-       nsectors = ((readl(&gpmc_cfg->ecc_config) >> 4) & 0x7) + 1;
-       for (i = 0; i < nsectors; i++) {
-               ret = _omap_calculate_ecc_bch(mtd, dat, ecc_calc, i);
-               if (ret)
-                       return ret;
-
-               ecc_calc += eccbytes;
-       }
-
-       return 0;
-}
-
 /*
  * omap_reverse_list - re-orders list elements in reverse order [internal]
  * @list:      pointer to start of list
@@ -752,7 +707,6 @@ static int omap_read_page_bch(struct mtd_info
 *mtd, struct nand_chip *chip,  {
        int i, eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
-       int ecctotal = chip->ecc.total;
        int eccsteps = chip->ecc.steps;
        uint8_t *p = buf;
        uint8_t *ecc_calc = chip->buffers->ecccalc; @@ -760,24 +714,30
Quoted 1 line

@@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip

*chip,

drivers/mtd/nand/raw/omap_gpmc.c static int omap_select_ecc_scheme(struct

Quoted 49 lines
        uint32_t *eccpos = chip->ecc.layout->eccpos;
        uint8_t *oob = chip->oob_poi;
        uint32_t oob_pos;
drivers/mtd/nand/raw/omap_gpmc.c +18 -10
+       u32 data_pos = 0;
 
        /* oob area start */
        oob_pos = (eccsize * eccsteps) + chip->ecc.layout->eccpos[0];
        oob += chip->ecc.layout->eccpos[0];
 
-       /* Enable ECC engine */
-       chip->ecc.hwctl(mtd, NAND_ECC_READ);
+       for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize,
+            oob += eccbytes) {
+               /* Enable ECC engine */
+               chip->ecc.hwctl(mtd, NAND_ECC_READ);
 
-       /* read entire page */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 0, -1);
-       chip->read_buf(mtd, buf, mtd->writesize);
+               /* read data */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);
+               chip->read_buf(mtd, p, eccsize);
 
-       /* read all ecc bytes from oob area */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-       chip->read_buf(mtd, oob, ecctotal);
+               /* read respective ecc from oob area */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+               chip->read_buf(mtd, oob, eccbytes);
+               /* read syndrome */
+               chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-       /* Calculate ecc bytes */
-       omap_calculate_ecc_bch_multi(mtd, buf, ecc_calc);
+               data_pos += eccsize;
+               oob_pos += eccbytes;
+       }
 
        for (i = 0; i < chip->ecc.total; i++)
                ecc_code[i] = chip->oob_poi[eccpos[i]]; @@ -945,6
+905,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.hwctl         = omap_enable_hwecc_bch;
                nand->ecc.correct       = omap_correct_data_bch_sw;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                ecclayout->eccpos[0]    = BADBLOCK_MARKER_LENGTH;
@@ -987,6 +948,7 @@ static int omap_select_ecc_scheme(struct

nand_chip *nand,

Quoted 16 lines
drivers/mtd/nand/raw/omap_gpmc.c +3 -0
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++) @@ -1020,6
+982,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++)
Quoted 4 lines

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7 --
2.34.1

Let's wait on some tested-by

I'm not a fan of this patch but we need to cover this regression

Michael

Quoted 1 line
Quoted 1 line

Michael

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#4 lore raw
Quoted 274 lines · Michael Nazzareno Trimarchi

Hi dario

Quoted 271 lines · Enrico

Hi,

Works on my draco thuban AM335x based boards booting from NAND with ECC BCH8 code.

Thanks

Quoted 261 lines

-----Original Message-----
From: Michael Nazzareno Trimarchi <[email protected]>
Sent: Saturday, November 25, 2023 2:07 PM
To: Roger Quadros <[email protected]>
Cc: [email protected]; Schocher, Heiko (EXT) (DENX Software Engineering GmbH) <[email protected]>; Leto, Enrico (SI BP R&D ZG FW CCP) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mtd: nand: omap_gpmc: Fix NAND in SPL for AM335x

Hi Roger

drivers/mtd/nand/raw/omap_gpmc.c static void __maybe_unused

Quoted 22 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL NAND loader. This driver expects 1 sector at a time ECC and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd:
rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based

correction")

---
 drivers/mtd/nand/raw/omap_gpmc.c | 95
++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
drivers/mtd/nand/raw/omap_gpmc.c +0 -0
index 1a5ed0de31..2d2d2c2b6d 100644
@@ -293,7 +293,7 @@ static void __maybe_unused

omap_enable_hwecc_bch(struct mtd_info *mtd,

Quoted 9 lines
drivers/mtd/nand/raw/omap_gpmc.c +1 -1
                break;
        case OMAP_ECC_BCH8_CODE_HW:
                bch_type = 1;
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = BCH_WRAPMODE_1;
                        ecc_size0 = BCH8R_ECC_SIZE0; @@ -306,7 +306,7

@@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info

*mtd,

drivers/mtd/nand/raw/omap_gpmc.c static int _omap_calculate_ecc_bch(struct mtd_info

Quoted 30 lines
                break;
        case OMAP_ECC_BCH16_CODE_HW:
                bch_type = 0x2;
drivers/mtd/nand/raw/omap_gpmc.c +1 -1
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = 0x01;
                        ecc_size0 = 52; /* ECC bits in nibbles per

sector */ @@ -345,17 +345,16 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, }

/**
- * _omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
+ * omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector

  * @mtd:        MTD device structure
  * @dat:        The pointer to data on which ecc is computed
  * @ecc_code:   The ecc_code buffer
- * @sector:     The sector number (for a multi sector page)

*
* Support calculating of BCH4/8/16 ECC vectors for one sector
* within a page. Sector number is in @sector.
*/

drivers/mtd/nand/raw/omap_gpmc.c +2 -2
-static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
-                                  u8 *ecc_code, int sector)
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+                                 u8 *ecc_code)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct omap_nand_info *info = nand_get_controller_data(chip);
@@ -368,7 +367,7 @@ static int _omap_calculate_ecc_bch(struct mtd_info

*mtd, const u8 *dat,

Quoted 30 lines
drivers/mtd/nand/raw/omap_gpmc.c +7 -4
        case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
 #endif
        case OMAP_ECC_BCH8_CODE_HW:
-               ptr = &gpmc_cfg->bch_result_0_3[sector].bch_result_x[3];
+               ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
                val = readl(ptr);
                ecc_code[i++] = (val >>  0) & 0xFF;
                ptr--;
@@ -383,21 +382,21 @@ static int _omap_calculate_ecc_bch(struct
 mtd_info *mtd, const u8 *dat,
 
                break;
        case OMAP_ECC_BCH16_CODE_HW:
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[2]);
+               val =
+ readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[2]);
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[1]);
+               val =
+ readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[1]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[0]);
+               val =
+ readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[0]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;

drivers/mtd/nand/raw/omap_gpmc.c static int _omap_calculate_ecc_bch(struct

Quoted 10 lines
drivers/mtd/nand/raw/omap_gpmc.c +3 -1
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
                for (j = 3; j >= 0; j--) {
-                       val = readl(&gpmc_cfg->bch_result_0_3[sector].bch_result_x[j]
+                       val =
+ readl(&gpmc_cfg->bch_result_0_3[0].bch_result_x[j]
                                                                        );
                        ecc_code[i++] = (val >> 24) & 0xFF;
                        ecc_code[i++] = (val >> 16) & 0xFF; @@ -431,22
+430,6 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const

u8 *dat,

Quoted 29 lines
        return 0;

}

-/**
- * omap_calculate_ecc_bch - ECC generator for 1 sector
- * @mtd: MTD device structure
- * @dat: The pointer to data on which ecc is computed
- * @ecc_code: The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
- * when SW based correction is required as ECC is required for one sector
- * at a time.
- */

drivers/mtd/nand/raw/omap_gpmc.c +0 -6
-static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
-                                 const u_char *dat, u_char *ecc_calc)
-{
-       return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
-}
-
 static inline void omap_nand_read_buf(struct mtd_info *mtd, uint8_t
*buf, int len)  {
        struct nand_chip *chip = mtd_to_nand(mtd); @@ -572,34 +555,6

@@ static void omap_nand_read_prefetch(struct mtd_info *mtd, uint8_t *buf, int len)

#ifdef CONFIG_NAND_OMAP_ELM

Quoted 7 lines

-/**
- * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors

- * @mtd:       MTD device structure
- * @dat:       The pointer to data on which ecc is computed
- * @ecc_code:  The ecc_code buffer

- *
- * Support calculating of BCH4/8/16 ecc vectors for the entire page in one

go.

Quoted 32 lines

- */

drivers/mtd/nand/raw/omap_gpmc.c +0 -21
-static int omap_calculate_ecc_bch_multi(struct mtd_info *mtd,
-                                       const u_char *dat, u_char *ecc_calc)
-{
-       struct nand_chip *chip = mtd_to_nand(mtd);
-       int eccbytes = chip->ecc.bytes;
-       unsigned long nsectors;
-       int i, ret;
-
-       nsectors = ((readl(&gpmc_cfg->ecc_config) >> 4) & 0x7) + 1;
-       for (i = 0; i < nsectors; i++) {
-               ret = _omap_calculate_ecc_bch(mtd, dat, ecc_calc, i);
-               if (ret)
-                       return ret;
-
-               ecc_calc += eccbytes;
-       }
-
-       return 0;
-}
-
 /*
  * omap_reverse_list - re-orders list elements in reverse order [internal]
  * @list:      pointer to start of list
@@ -752,7 +707,6 @@ static int omap_read_page_bch(struct mtd_info
 *mtd, struct nand_chip *chip,  {
        int i, eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
-       int ecctotal = chip->ecc.total;
        int eccsteps = chip->ecc.steps;
        uint8_t *p = buf;
        uint8_t *ecc_calc = chip->buffers->ecccalc; @@ -760,24 +714,30
Quoted 1 line

@@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip

*chip,

drivers/mtd/nand/raw/omap_gpmc.c static int omap_select_ecc_scheme(struct

Quoted 49 lines
        uint32_t *eccpos = chip->ecc.layout->eccpos;
        uint8_t *oob = chip->oob_poi;
        uint32_t oob_pos;
drivers/mtd/nand/raw/omap_gpmc.c +18 -10
+       u32 data_pos = 0;
 
        /* oob area start */
        oob_pos = (eccsize * eccsteps) + chip->ecc.layout->eccpos[0];
        oob += chip->ecc.layout->eccpos[0];
 
-       /* Enable ECC engine */
-       chip->ecc.hwctl(mtd, NAND_ECC_READ);
+       for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize,
+            oob += eccbytes) {
+               /* Enable ECC engine */
+               chip->ecc.hwctl(mtd, NAND_ECC_READ);
 
-       /* read entire page */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 0, -1);
-       chip->read_buf(mtd, buf, mtd->writesize);
+               /* read data */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);
+               chip->read_buf(mtd, p, eccsize);
 
-       /* read all ecc bytes from oob area */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-       chip->read_buf(mtd, oob, ecctotal);
+               /* read respective ecc from oob area */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+               chip->read_buf(mtd, oob, eccbytes);
+               /* read syndrome */
+               chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-       /* Calculate ecc bytes */
-       omap_calculate_ecc_bch_multi(mtd, buf, ecc_calc);
+               data_pos += eccsize;
+               oob_pos += eccbytes;
+       }
 
        for (i = 0; i < chip->ecc.total; i++)
                ecc_code[i] = chip->oob_poi[eccpos[i]]; @@ -945,6
+905,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.hwctl         = omap_enable_hwecc_bch;
                nand->ecc.correct       = omap_correct_data_bch_sw;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                ecclayout->eccpos[0]    = BADBLOCK_MARKER_LENGTH;
@@ -987,6 +948,7 @@ static int omap_select_ecc_scheme(struct

nand_chip *nand,

Quoted 20 lines
drivers/mtd/nand/raw/omap_gpmc.c +3 -0
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++) @@ -1020,6
+982,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++)

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7 --
2.34.1

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

Let's wait on some tested-by

I'm not a fan of this patch but we need to cover this regression

Is it because of the performance hit for non AM335x platforms? Any suggestions for improvement?

Signature · 2 lines
cheers,
-roger
#6 lore raw
In reply to Tom Rini

Hi Tom,

Quoted 15 lines · Tom Rini
Quoted 5 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Quoted 7 lines

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
Quoted 5 lines

I'm glad to see this fixed. My question is, can we abstract this slightly as I assume there's a performance hit on the newer SoCs that support more than one sector at a time for ECC and I assume it's just am335x and related that don't support the feature. Thanks.

It looks like that the ELM driver (omap_elm.c) is not yet ready for multi-sector setup yet. I will need more time to test the multi-sector implementation.

Signature · 2 lines
cheers,
-roger
#9 lore raw
In reply to Roger Quadros
Quoted 9 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Azure pipeline build fails. Not because of this patch though.
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=7479&view=logs&j=c6c7c3ee-a125-5e20-d856-38cb989f4743&t=d274418e-7320-5c59-39b7-156cfcddae0b

Quoted 215 lines
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
drivers/mtd/nand/raw/omap_gpmc.c +29 -66
index 1a5ed0de31..2d2d2c2b6d 100644
@@ -293,7 +293,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 		break;
 	case OMAP_ECC_BCH8_CODE_HW:
 		bch_type = 1;
-		nsectors = chip->ecc.steps;
+		nsectors = 1;
 		if (mode == NAND_ECC_READ) {
 			wr_mode   = BCH_WRAPMODE_1;
 			ecc_size0 = BCH8R_ECC_SIZE0;
@@ -306,7 +306,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 		break;
 	case OMAP_ECC_BCH16_CODE_HW:
 		bch_type = 0x2;
-		nsectors = chip->ecc.steps;
+		nsectors = 1;
 		if (mode == NAND_ECC_READ) {
 			wr_mode   = 0x01;
 			ecc_size0 = 52; /* ECC bits in nibbles per sector */
@@ -345,17 +345,16 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 }
 
 /**
- * _omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
+ * omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
  * @mtd:        MTD device structure
  * @dat:        The pointer to data on which ecc is computed
  * @ecc_code:   The ecc_code buffer
- * @sector:     The sector number (for a multi sector page)
  *
  * Support calculating of BCH4/8/16 ECC vectors for one sector
  * within a page. Sector number is in @sector.
  */
-static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
-				   u8 *ecc_code, int sector)
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+				  u8 *ecc_code)
 {
 	struct nand_chip *chip = mtd_to_nand(mtd);
 	struct omap_nand_info *info = nand_get_controller_data(chip);
@@ -368,7 +367,7 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 	case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
 #endif
 	case OMAP_ECC_BCH8_CODE_HW:
-		ptr = &gpmc_cfg->bch_result_0_3[sector].bch_result_x[3];
+		ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
 		val = readl(ptr);
 		ecc_code[i++] = (val >>  0) & 0xFF;
 		ptr--;
@@ -383,21 +382,21 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 
 		break;
 	case OMAP_ECC_BCH16_CODE_HW:
-		val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[2]);
+		val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[2]);
 		ecc_code[i++] = (val >>  8) & 0xFF;
 		ecc_code[i++] = (val >>  0) & 0xFF;
-		val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[1]);
+		val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[1]);
 		ecc_code[i++] = (val >> 24) & 0xFF;
 		ecc_code[i++] = (val >> 16) & 0xFF;
 		ecc_code[i++] = (val >>  8) & 0xFF;
 		ecc_code[i++] = (val >>  0) & 0xFF;
-		val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[0]);
+		val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[0]);
 		ecc_code[i++] = (val >> 24) & 0xFF;
 		ecc_code[i++] = (val >> 16) & 0xFF;
 		ecc_code[i++] = (val >>  8) & 0xFF;
 		ecc_code[i++] = (val >>  0) & 0xFF;
 		for (j = 3; j >= 0; j--) {
-			val = readl(&gpmc_cfg->bch_result_0_3[sector].bch_result_x[j]
+			val = readl(&gpmc_cfg->bch_result_0_3[0].bch_result_x[j]
 									);
 			ecc_code[i++] = (val >> 24) & 0xFF;
 			ecc_code[i++] = (val >> 16) & 0xFF;
@@ -431,22 +430,6 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 	return 0;
 }
 
-/**
- * omap_calculate_ecc_bch - ECC generator for 1 sector
- * @mtd:        MTD device structure
- * @dat:	The pointer to data on which ecc is computed
- * @ecc_code:	The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
- * when SW based correction is required as ECC is required for one sector
- * at a time.
- */
-static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
-				  const u_char *dat, u_char *ecc_calc)
-{
-	return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
-}
-
 static inline void omap_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
 	struct nand_chip *chip = mtd_to_nand(mtd);
@@ -572,34 +555,6 @@ static void omap_nand_read_prefetch(struct mtd_info *mtd, uint8_t *buf, int len)
 
 #ifdef CONFIG_NAND_OMAP_ELM
 
-/**
- * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors
- * @mtd:	MTD device structure
- * @dat:	The pointer to data on which ecc is computed
- * @ecc_code:	The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ecc vectors for the entire page in one go.
- */
-static int omap_calculate_ecc_bch_multi(struct mtd_info *mtd,
-					const u_char *dat, u_char *ecc_calc)
-{
-	struct nand_chip *chip = mtd_to_nand(mtd);
-	int eccbytes = chip->ecc.bytes;
-	unsigned long nsectors;
-	int i, ret;
-
-	nsectors = ((readl(&gpmc_cfg->ecc_config) >> 4) & 0x7) + 1;
-	for (i = 0; i < nsectors; i++) {
-		ret = _omap_calculate_ecc_bch(mtd, dat, ecc_calc, i);
-		if (ret)
-			return ret;
-
-		ecc_calc += eccbytes;
-	}
-
-	return 0;
-}
-
 /*
  * omap_reverse_list - re-orders list elements in reverse order [internal]
  * @list:	pointer to start of list
@@ -752,7 +707,6 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 {
 	int i, eccsize = chip->ecc.size;
 	int eccbytes = chip->ecc.bytes;
-	int ecctotal = chip->ecc.total;
 	int eccsteps = chip->ecc.steps;
 	uint8_t *p = buf;
 	uint8_t *ecc_calc = chip->buffers->ecccalc;
@@ -760,24 +714,30 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 	uint32_t *eccpos = chip->ecc.layout->eccpos;
 	uint8_t *oob = chip->oob_poi;
 	uint32_t oob_pos;
+	u32 data_pos = 0;
 
 	/* oob area start */
 	oob_pos = (eccsize * eccsteps) + chip->ecc.layout->eccpos[0];
 	oob += chip->ecc.layout->eccpos[0];
 
-	/* Enable ECC engine */
-	chip->ecc.hwctl(mtd, NAND_ECC_READ);
+	for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize,
+	     oob += eccbytes) {
+		/* Enable ECC engine */
+		chip->ecc.hwctl(mtd, NAND_ECC_READ);
 
-	/* read entire page */
-	chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 0, -1);
-	chip->read_buf(mtd, buf, mtd->writesize);
+		/* read data */
+		chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);
+		chip->read_buf(mtd, p, eccsize);
 
-	/* read all ecc bytes from oob area */
-	chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-	chip->read_buf(mtd, oob, ecctotal);
+		/* read respective ecc from oob area */
+		chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+		chip->read_buf(mtd, oob, eccbytes);
+		/* read syndrome */
+		chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-	/* Calculate ecc bytes */
-	omap_calculate_ecc_bch_multi(mtd, buf, ecc_calc);
+		data_pos += eccsize;
+		oob_pos += eccbytes;
+	}
 
 	for (i = 0; i < chip->ecc.total; i++)
 		ecc_code[i] = chip->oob_poi[eccpos[i]];
@@ -945,6 +905,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
 		nand->ecc.hwctl		= omap_enable_hwecc_bch;
 		nand->ecc.correct	= omap_correct_data_bch_sw;
 		nand->ecc.calculate	= omap_calculate_ecc_bch;
+		nand->ecc.steps		= eccsteps;
 		/* define ecc-layout */
 		ecclayout->eccbytes	= nand->ecc.bytes * eccsteps;
 		ecclayout->eccpos[0]	= BADBLOCK_MARKER_LENGTH;
@@ -987,6 +948,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
 		nand->ecc.correct	= omap_correct_data_bch;
 		nand->ecc.calculate	= omap_calculate_ecc_bch;
 		nand->ecc.read_page	= omap_read_page_bch;
+		nand->ecc.steps		= eccsteps;
 		/* define ecc-layout */
 		ecclayout->eccbytes	= nand->ecc.bytes * eccsteps;
 		for (i = 0; i < ecclayout->eccbytes; i++)
@@ -1020,6 +982,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
 		nand->ecc.correct	= omap_correct_data_bch;
 		nand->ecc.calculate	= omap_calculate_ecc_bch;
 		nand->ecc.read_page	= omap_read_page_bch;
+		nand->ecc.steps		= eccsteps;
 		/* define ecc-layout */
 		ecclayout->eccbytes	= nand->ecc.bytes * eccsteps;
 		for (i = 0; i < ecclayout->eccbytes; i++)

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7

Signature · 2 lines
cheers,
-roger
#10 lore raw

Hi

Quoted 7 lines · Roger Quadros
Quoted 5 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Quoted 8 lines
Quoted 4 lines

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Azure pipeline build fails. Not because of this patch though.
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=7479&view=logs&j=c6c7c3ee-a125-5e20-d856-38cb989f4743&t=d274418e-7320-5c59-39b7-156cfcddae0b

My comment below

Quoted 29 lines
Quoted 29 lines
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
drivers/mtd/nand/raw/omap_gpmc.c +2 -2
index 1a5ed0de31..2d2d2c2b6d 100644
@@ -293,7 +293,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
              break;
      case OMAP_ECC_BCH8_CODE_HW:
              bch_type = 1;
-             nsectors = chip->ecc.steps;
+             nsectors = 1;
              if (mode == NAND_ECC_READ) {
                      wr_mode   = BCH_WRAPMODE_1;
                      ecc_size0 = BCH8R_ECC_SIZE0;
@@ -306,7 +306,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
              break;
      case OMAP_ECC_BCH16_CODE_HW:
              bch_type = 0x2;
-             nsectors = chip->ecc.steps;
+             nsectors = 1;
              if (mode == NAND_ECC_READ) {
                      wr_mode   = 0x01;
                      ecc_size0 = 52; /* ECC bits in nibbles per sector */
@@ -345,17 +345,16 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 }
 
Quoted 16 lines
Quoted 6 lines
drivers/mtd/nand/raw/omap_gpmc.c +1 -1
 /**
- * _omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
+ * omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
  * @mtd:        MTD device structure
  * @dat:        The pointer to data on which ecc is computed
  * @ecc_code:   The ecc_code buffer

drivers/mtd/nand/raw/omap_gpmc.c static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, · line 358

Quoted 10 lines
drivers/mtd/nand/raw/omap_gpmc.c +2 -3
- * @sector:     The sector number (for a multi sector page)
  *
  * Support calculating of BCH4/8/16 ECC vectors for one sector
  * within a page. Sector number is in @sector.
  */
-static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
-                                u8 *ecc_code, int sector)
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+                               u8 *ecc_code)
 {

This should be as before
static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,

Quoted 41 lines
Quoted 41 lines
drivers/mtd/nand/raw/omap_gpmc.c +5 -5
      struct nand_chip *chip = mtd_to_nand(mtd);
      struct omap_nand_info *info = nand_get_controller_data(chip);
@@ -368,7 +367,7 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
      case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
 #endif
      case OMAP_ECC_BCH8_CODE_HW:
-             ptr = &gpmc_cfg->bch_result_0_3[sector].bch_result_x[3];
+             ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
              val = readl(ptr);
              ecc_code[i++] = (val >>  0) & 0xFF;
              ptr--;
@@ -383,21 +382,21 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 
              break;
      case OMAP_ECC_BCH16_CODE_HW:
-             val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[2]);
+             val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[2]);
              ecc_code[i++] = (val >>  8) & 0xFF;
              ecc_code[i++] = (val >>  0) & 0xFF;
-             val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[1]);
+             val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[1]);
              ecc_code[i++] = (val >> 24) & 0xFF;
              ecc_code[i++] = (val >> 16) & 0xFF;
              ecc_code[i++] = (val >>  8) & 0xFF;
              ecc_code[i++] = (val >>  0) & 0xFF;
-             val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[0]);
+             val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[0]);
              ecc_code[i++] = (val >> 24) & 0xFF;
              ecc_code[i++] = (val >> 16) & 0xFF;
              ecc_code[i++] = (val >>  8) & 0xFF;
              ecc_code[i++] = (val >>  0) & 0xFF;
              for (j = 3; j >= 0; j--) {
-                     val = readl(&gpmc_cfg->bch_result_0_3[sector].bch_result_x[j]
+                     val = readl(&gpmc_cfg->bch_result_0_3[0].bch_result_x[j]
                                                                      );
                      ecc_code[i++] = (val >> 24) & 0xFF;
                      ecc_code[i++] = (val >> 16) & 0xFF;
@@ -431,22 +430,6 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
      return 0;
 }
 
Quoted 13 lines

drivers/mtd/nand/raw/omap_gpmc.c static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat, · line 446

Quoted 13 lines
drivers/mtd/nand/raw/omap_gpmc.c +0 -13
-/**
- * omap_calculate_ecc_bch - ECC generator for 1 sector
- * @mtd:        MTD device structure
- * @dat:     The pointer to data on which ecc is computed
- * @ecc_code:        The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
- * when SW based correction is required as ECC is required for one sector
- * at a time.
- */
-static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
-                               const u_char *dat, u_char *ecc_calc)
-{

If you remove you should stay with it

Quoted 120 lines
Quoted 115 lines
drivers/mtd/nand/raw/omap_gpmc.c +19 -42
-     return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
-}
-
 static inline void omap_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
      struct nand_chip *chip = mtd_to_nand(mtd);
@@ -572,34 +555,6 @@ static void omap_nand_read_prefetch(struct mtd_info *mtd, uint8_t *buf, int len)
 
 #ifdef CONFIG_NAND_OMAP_ELM
 
-/**
- * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors
- * @mtd:     MTD device structure
- * @dat:     The pointer to data on which ecc is computed
- * @ecc_code:        The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ecc vectors for the entire page in one go.
- */
-static int omap_calculate_ecc_bch_multi(struct mtd_info *mtd,
-                                     const u_char *dat, u_char *ecc_calc)
-{
-     struct nand_chip *chip = mtd_to_nand(mtd);
-     int eccbytes = chip->ecc.bytes;
-     unsigned long nsectors;
-     int i, ret;
-
-     nsectors = ((readl(&gpmc_cfg->ecc_config) >> 4) & 0x7) + 1;
-     for (i = 0; i < nsectors; i++) {
-             ret = _omap_calculate_ecc_bch(mtd, dat, ecc_calc, i);
-             if (ret)
-                     return ret;
-
-             ecc_calc += eccbytes;
-     }
-
-     return 0;
-}
-
 /*
  * omap_reverse_list - re-orders list elements in reverse order [internal]
  * @list:    pointer to start of list
@@ -752,7 +707,6 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 {
      int i, eccsize = chip->ecc.size;
      int eccbytes = chip->ecc.bytes;
-     int ecctotal = chip->ecc.total;
      int eccsteps = chip->ecc.steps;
      uint8_t *p = buf;
      uint8_t *ecc_calc = chip->buffers->ecccalc;
@@ -760,24 +714,30 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
      uint32_t *eccpos = chip->ecc.layout->eccpos;
      uint8_t *oob = chip->oob_poi;
      uint32_t oob_pos;
+     u32 data_pos = 0;
 
      /* oob area start */
      oob_pos = (eccsize * eccsteps) + chip->ecc.layout->eccpos[0];
      oob += chip->ecc.layout->eccpos[0];
 
-     /* Enable ECC engine */
-     chip->ecc.hwctl(mtd, NAND_ECC_READ);
+     for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize,
+          oob += eccbytes) {
+             /* Enable ECC engine */
+             chip->ecc.hwctl(mtd, NAND_ECC_READ);
 
-     /* read entire page */
-     chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 0, -1);
-     chip->read_buf(mtd, buf, mtd->writesize);
+             /* read data */
+             chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);
+             chip->read_buf(mtd, p, eccsize);
 
-     /* read all ecc bytes from oob area */
-     chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-     chip->read_buf(mtd, oob, ecctotal);
+             /* read respective ecc from oob area */
+             chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+             chip->read_buf(mtd, oob, eccbytes);
+             /* read syndrome */
+             chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-     /* Calculate ecc bytes */
-     omap_calculate_ecc_bch_multi(mtd, buf, ecc_calc);
+             data_pos += eccsize;
+             oob_pos += eccbytes;
+     }
 
      for (i = 0; i < chip->ecc.total; i++)
              ecc_code[i] = chip->oob_poi[eccpos[i]];
@@ -945,6 +905,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
              nand->ecc.hwctl         = omap_enable_hwecc_bch;
              nand->ecc.correct       = omap_correct_data_bch_sw;
              nand->ecc.calculate     = omap_calculate_ecc_bch;
+             nand->ecc.steps         = eccsteps;
              /* define ecc-layout */
              ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
              ecclayout->eccpos[0]    = BADBLOCK_MARKER_LENGTH;
@@ -987,6 +948,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
              nand->ecc.correct       = omap_correct_data_bch;
              nand->ecc.calculate     = omap_calculate_ecc_bch;
              nand->ecc.read_page     = omap_read_page_bch;
+             nand->ecc.steps         = eccsteps;
              /* define ecc-layout */
              ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
              for (i = 0; i < ecclayout->eccbytes; i++)
@@ -1020,6 +982,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
              nand->ecc.correct       = omap_correct_data_bch;
              nand->ecc.calculate     = omap_calculate_ecc_bch;
              nand->ecc.read_page     = omap_read_page_bch;
+             nand->ecc.steps         = eccsteps;
              /* define ecc-layout */
              ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
              for (i = 0; i < ecclayout->eccbytes; i++)
Quoted 1 line

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7

--
cheers,
-roger

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#11 lore raw
Quoted 111 lines · Michael Nazzareno Trimarchi

Hi

Quoted 7 lines · Roger Quadros
Quoted 5 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Quoted 8 lines
Quoted 4 lines

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Azure pipeline build fails. Not because of this patch though.
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=7479&view=logs&j=c6c7c3ee-a125-5e20-d856-38cb989f4743&t=d274418e-7320-5c59-39b7-156cfcddae0b

My comment below

Quoted 29 lines
Quoted 29 lines
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
drivers/mtd/nand/raw/omap_gpmc.c +2 -2
index 1a5ed0de31..2d2d2c2b6d 100644
@@ -293,7 +293,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
              break;
      case OMAP_ECC_BCH8_CODE_HW:
              bch_type = 1;
-             nsectors = chip->ecc.steps;
+             nsectors = 1;
              if (mode == NAND_ECC_READ) {
                      wr_mode   = BCH_WRAPMODE_1;
                      ecc_size0 = BCH8R_ECC_SIZE0;
@@ -306,7 +306,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
              break;
      case OMAP_ECC_BCH16_CODE_HW:
              bch_type = 0x2;
-             nsectors = chip->ecc.steps;
+             nsectors = 1;
              if (mode == NAND_ECC_READ) {
                      wr_mode   = 0x01;
                      ecc_size0 = 52; /* ECC bits in nibbles per sector */
@@ -345,17 +345,16 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 }
 
Quoted 16 lines
Quoted 6 lines
drivers/mtd/nand/raw/omap_gpmc.c +1 -1
 /**
- * _omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
+ * omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
  * @mtd:        MTD device structure
  * @dat:        The pointer to data on which ecc is computed
  * @ecc_code:   The ecc_code buffer

drivers/mtd/nand/raw/omap_gpmc.c static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, · line 358

Quoted 10 lines
drivers/mtd/nand/raw/omap_gpmc.c +2 -3
- * @sector:     The sector number (for a multi sector page)
  *
  * Support calculating of BCH4/8/16 ECC vectors for one sector
  * within a page. Sector number is in @sector.
  */
-static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
-                                u8 *ecc_code, int sector)
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+                               u8 *ecc_code)
 {

This should be as before
static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,

Quoted 41 lines
Quoted 41 lines
drivers/mtd/nand/raw/omap_gpmc.c +5 -5
      struct nand_chip *chip = mtd_to_nand(mtd);
      struct omap_nand_info *info = nand_get_controller_data(chip);
@@ -368,7 +367,7 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
      case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
 #endif
      case OMAP_ECC_BCH8_CODE_HW:
-             ptr = &gpmc_cfg->bch_result_0_3[sector].bch_result_x[3];
+             ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
              val = readl(ptr);
              ecc_code[i++] = (val >>  0) & 0xFF;
              ptr--;
@@ -383,21 +382,21 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 
              break;
      case OMAP_ECC_BCH16_CODE_HW:
-             val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[2]);
+             val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[2]);
              ecc_code[i++] = (val >>  8) & 0xFF;
              ecc_code[i++] = (val >>  0) & 0xFF;
-             val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[1]);
+             val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[1]);
              ecc_code[i++] = (val >> 24) & 0xFF;
              ecc_code[i++] = (val >> 16) & 0xFF;
              ecc_code[i++] = (val >>  8) & 0xFF;
              ecc_code[i++] = (val >>  0) & 0xFF;
-             val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[0]);
+             val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[0]);
              ecc_code[i++] = (val >> 24) & 0xFF;
              ecc_code[i++] = (val >> 16) & 0xFF;
              ecc_code[i++] = (val >>  8) & 0xFF;
              ecc_code[i++] = (val >>  0) & 0xFF;
              for (j = 3; j >= 0; j--) {
-                     val = readl(&gpmc_cfg->bch_result_0_3[sector].bch_result_x[j]
+                     val = readl(&gpmc_cfg->bch_result_0_3[0].bch_result_x[j]
                                                                      );
                      ecc_code[i++] = (val >> 24) & 0xFF;
                      ecc_code[i++] = (val >> 16) & 0xFF;
@@ -431,22 +430,6 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
      return 0;
 }
 
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
drivers/mtd/nand/raw/omap_gpmc.c +0 -5
-/**
- * omap_calculate_ecc_bch - ECC generator for 1 sector
- * @mtd:        MTD device structure
- * @dat:     The pointer to data on which ecc is computed
- * @ecc_code:        The ecc_code buffer
Quoted 8 lines

drivers/mtd/nand/raw/omap_gpmc.c static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat, · line 446

Quoted 8 lines
drivers/mtd/nand/raw/omap_gpmc.c +0 -8
- *
- * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
- * when SW based correction is required as ECC is required for one sector
- * at a time.
- */
-static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
-                               const u_char *dat, u_char *ecc_calc)
-{

If you remove you should stay with it

Thanks. So the issue was indeed introduced by this patch.

I see a lot of #ifdeffery in this driver.
Is it recommended in general to move to if defined(IS_ENABLED(CONFIG_*)) instead and get rid of __maybe_unused?

Quoted 124 lines
Quoted 121 lines
Quoted 116 lines
drivers/mtd/nand/raw/omap_gpmc.c +19 -42
-     return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
-}
-
 static inline void omap_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
      struct nand_chip *chip = mtd_to_nand(mtd);
@@ -572,34 +555,6 @@ static void omap_nand_read_prefetch(struct mtd_info *mtd, uint8_t *buf, int len)
 
 #ifdef CONFIG_NAND_OMAP_ELM
 
-/**
- * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors
- * @mtd:     MTD device structure
- * @dat:     The pointer to data on which ecc is computed
- * @ecc_code:        The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ecc vectors for the entire page in one go.
- */
-static int omap_calculate_ecc_bch_multi(struct mtd_info *mtd,
-                                     const u_char *dat, u_char *ecc_calc)
-{
-     struct nand_chip *chip = mtd_to_nand(mtd);
-     int eccbytes = chip->ecc.bytes;
-     unsigned long nsectors;
-     int i, ret;
-
-     nsectors = ((readl(&gpmc_cfg->ecc_config) >> 4) & 0x7) + 1;
-     for (i = 0; i < nsectors; i++) {
-             ret = _omap_calculate_ecc_bch(mtd, dat, ecc_calc, i);
-             if (ret)
-                     return ret;
-
-             ecc_calc += eccbytes;
-     }
-
-     return 0;
-}
-
 /*
  * omap_reverse_list - re-orders list elements in reverse order [internal]
  * @list:    pointer to start of list
@@ -752,7 +707,6 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 {
      int i, eccsize = chip->ecc.size;
      int eccbytes = chip->ecc.bytes;
-     int ecctotal = chip->ecc.total;
      int eccsteps = chip->ecc.steps;
      uint8_t *p = buf;
      uint8_t *ecc_calc = chip->buffers->ecccalc;
@@ -760,24 +714,30 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
      uint32_t *eccpos = chip->ecc.layout->eccpos;
      uint8_t *oob = chip->oob_poi;
      uint32_t oob_pos;
+     u32 data_pos = 0;
 
      /* oob area start */
      oob_pos = (eccsize * eccsteps) + chip->ecc.layout->eccpos[0];
      oob += chip->ecc.layout->eccpos[0];
 
-     /* Enable ECC engine */
-     chip->ecc.hwctl(mtd, NAND_ECC_READ);
+     for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize,
+          oob += eccbytes) {
+             /* Enable ECC engine */
+             chip->ecc.hwctl(mtd, NAND_ECC_READ);
 
-     /* read entire page */
-     chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 0, -1);
-     chip->read_buf(mtd, buf, mtd->writesize);
+             /* read data */
+             chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);
+             chip->read_buf(mtd, p, eccsize);
 
-     /* read all ecc bytes from oob area */
-     chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-     chip->read_buf(mtd, oob, ecctotal);
+             /* read respective ecc from oob area */
+             chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+             chip->read_buf(mtd, oob, eccbytes);
+             /* read syndrome */
+             chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-     /* Calculate ecc bytes */
-     omap_calculate_ecc_bch_multi(mtd, buf, ecc_calc);
+             data_pos += eccsize;
+             oob_pos += eccbytes;
+     }
 
      for (i = 0; i < chip->ecc.total; i++)
              ecc_code[i] = chip->oob_poi[eccpos[i]];
@@ -945,6 +905,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
              nand->ecc.hwctl         = omap_enable_hwecc_bch;
              nand->ecc.correct       = omap_correct_data_bch_sw;
              nand->ecc.calculate     = omap_calculate_ecc_bch;
+             nand->ecc.steps         = eccsteps;
              /* define ecc-layout */
              ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
              ecclayout->eccpos[0]    = BADBLOCK_MARKER_LENGTH;
@@ -987,6 +948,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
              nand->ecc.correct       = omap_correct_data_bch;
              nand->ecc.calculate     = omap_calculate_ecc_bch;
              nand->ecc.read_page     = omap_read_page_bch;
+             nand->ecc.steps         = eccsteps;
              /* define ecc-layout */
              ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
              for (i = 0; i < ecclayout->eccbytes; i++)
@@ -1020,6 +982,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
              nand->ecc.correct       = omap_correct_data_bch;
              nand->ecc.calculate     = omap_calculate_ecc_bch;
              nand->ecc.read_page     = omap_read_page_bch;
+             nand->ecc.steps         = eccsteps;
              /* define ecc-layout */
              ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
              for (i = 0; i < ecclayout->eccbytes; i++)
Quoted 1 line

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7

--
cheers,
-roger

Signature · 2 lines
cheers,
-roger
#13 lore raw
In reply to Roger Quadros

Hi Roger

Quoted 37 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
drivers/mtd/nand/raw/omap_gpmc.c +2 -2
index 1a5ed0de31..2d2d2c2b6d 100644
@@ -293,7 +293,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
                break;
        case OMAP_ECC_BCH8_CODE_HW:
                bch_type = 1;
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = BCH_WRAPMODE_1;
                        ecc_size0 = BCH8R_ECC_SIZE0;
@@ -306,7 +306,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
                break;
        case OMAP_ECC_BCH16_CODE_HW:
                bch_type = 0x2;
-               nsectors = chip->ecc.steps;
+               nsectors = 1;
                if (mode == NAND_ECC_READ) {
                        wr_mode   = 0x01;
                        ecc_size0 = 52; /* ECC bits in nibbles per sector */

drivers/mtd/nand/raw/omap_gpmc.c static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, · line 346

Quoted 2 lines
drivers/mtd/nand/raw/omap_gpmc.c +0 -0
@@ -345,17 +345,16 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd,
 }
 

If the changes impact only one family can you just restrict it to those family?

Michael

Quoted 189 lines
drivers/mtd/nand/raw/omap_gpmc.c +27 -64
 /**
- * _omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
+ * omap_calculate_ecc_bch - Generate BCH ECC bytes for one sector
  * @mtd:        MTD device structure
  * @dat:        The pointer to data on which ecc is computed
  * @ecc_code:   The ecc_code buffer
- * @sector:     The sector number (for a multi sector page)
  *
  * Support calculating of BCH4/8/16 ECC vectors for one sector
  * within a page. Sector number is in @sector.
  */
-static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
-                                  u8 *ecc_code, int sector)
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+                                 u8 *ecc_code)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct omap_nand_info *info = nand_get_controller_data(chip);
@@ -368,7 +367,7 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
        case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
 #endif
        case OMAP_ECC_BCH8_CODE_HW:
-               ptr = &gpmc_cfg->bch_result_0_3[sector].bch_result_x[3];
+               ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
                val = readl(ptr);
                ecc_code[i++] = (val >>  0) & 0xFF;
                ptr--;
@@ -383,21 +382,21 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
 
                break;
        case OMAP_ECC_BCH16_CODE_HW:
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[2]);
+               val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[2]);
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[1]);
+               val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[1]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
-               val = readl(&gpmc_cfg->bch_result_4_6[sector].bch_result_x[0]);
+               val = readl(&gpmc_cfg->bch_result_4_6[0].bch_result_x[0]);
                ecc_code[i++] = (val >> 24) & 0xFF;
                ecc_code[i++] = (val >> 16) & 0xFF;
                ecc_code[i++] = (val >>  8) & 0xFF;
                ecc_code[i++] = (val >>  0) & 0xFF;
                for (j = 3; j >= 0; j--) {
-                       val = readl(&gpmc_cfg->bch_result_0_3[sector].bch_result_x[j]
+                       val = readl(&gpmc_cfg->bch_result_0_3[0].bch_result_x[j]
                                                                        );
                        ecc_code[i++] = (val >> 24) & 0xFF;
                        ecc_code[i++] = (val >> 16) & 0xFF;
@@ -431,22 +430,6 @@ static int _omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
        return 0;
 }
 
-/**
- * omap_calculate_ecc_bch - ECC generator for 1 sector
- * @mtd:        MTD device structure
- * @dat:       The pointer to data on which ecc is computed
- * @ecc_code:  The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
- * when SW based correction is required as ECC is required for one sector
- * at a time.
- */
-static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
-                                 const u_char *dat, u_char *ecc_calc)
-{
-       return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
-}
-
 static inline void omap_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
@@ -572,34 +555,6 @@ static void omap_nand_read_prefetch(struct mtd_info *mtd, uint8_t *buf, int len)
 
 #ifdef CONFIG_NAND_OMAP_ELM
 
-/**
- * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors
- * @mtd:       MTD device structure
- * @dat:       The pointer to data on which ecc is computed
- * @ecc_code:  The ecc_code buffer
- *
- * Support calculating of BCH4/8/16 ecc vectors for the entire page in one go.
- */
-static int omap_calculate_ecc_bch_multi(struct mtd_info *mtd,
-                                       const u_char *dat, u_char *ecc_calc)
-{
-       struct nand_chip *chip = mtd_to_nand(mtd);
-       int eccbytes = chip->ecc.bytes;
-       unsigned long nsectors;
-       int i, ret;
-
-       nsectors = ((readl(&gpmc_cfg->ecc_config) >> 4) & 0x7) + 1;
-       for (i = 0; i < nsectors; i++) {
-               ret = _omap_calculate_ecc_bch(mtd, dat, ecc_calc, i);
-               if (ret)
-                       return ret;
-
-               ecc_calc += eccbytes;
-       }
-
-       return 0;
-}
-
 /*
  * omap_reverse_list - re-orders list elements in reverse order [internal]
  * @list:      pointer to start of list
@@ -752,7 +707,6 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 {
        int i, eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
-       int ecctotal = chip->ecc.total;
        int eccsteps = chip->ecc.steps;
        uint8_t *p = buf;
        uint8_t *ecc_calc = chip->buffers->ecccalc;
@@ -760,24 +714,30 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
        uint32_t *eccpos = chip->ecc.layout->eccpos;
        uint8_t *oob = chip->oob_poi;
        uint32_t oob_pos;
+       u32 data_pos = 0;
 
        /* oob area start */
        oob_pos = (eccsize * eccsteps) + chip->ecc.layout->eccpos[0];
        oob += chip->ecc.layout->eccpos[0];
 
-       /* Enable ECC engine */
-       chip->ecc.hwctl(mtd, NAND_ECC_READ);
+       for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize,
+            oob += eccbytes) {
+               /* Enable ECC engine */
+               chip->ecc.hwctl(mtd, NAND_ECC_READ);
 
-       /* read entire page */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 0, -1);
-       chip->read_buf(mtd, buf, mtd->writesize);
+               /* read data */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);
+               chip->read_buf(mtd, p, eccsize);
 
-       /* read all ecc bytes from oob area */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-       chip->read_buf(mtd, oob, ecctotal);
+               /* read respective ecc from oob area */
+               chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+               chip->read_buf(mtd, oob, eccbytes);
+               /* read syndrome */
+               chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-       /* Calculate ecc bytes */
-       omap_calculate_ecc_bch_multi(mtd, buf, ecc_calc);
+               data_pos += eccsize;
+               oob_pos += eccbytes;
+       }
 
        for (i = 0; i < chip->ecc.total; i++)
                ecc_code[i] = chip->oob_poi[eccpos[i]];
@@ -945,6 +905,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.hwctl         = omap_enable_hwecc_bch;
                nand->ecc.correct       = omap_correct_data_bch_sw;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                ecclayout->eccpos[0]    = BADBLOCK_MARKER_LENGTH;
@@ -987,6 +948,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++)
@@ -1020,6 +982,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
                nand->ecc.correct       = omap_correct_data_bch;
                nand->ecc.calculate     = omap_calculate_ecc_bch;
                nand->ecc.read_page     = omap_read_page_bch;
+               nand->ecc.steps         = eccsteps;
                /* define ecc-layout */
                ecclayout->eccbytes     = nand->ecc.bytes * eccsteps;
                for (i = 0; i < ecclayout->eccbytes; i++)

base-commit: 9e53e45292ee2f1d9d2ccc59914b161bef9b10d7 --
2.34.1

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#12 lore raw
In reply to Roger Quadros
Quoted 6 lines · Roger Quadros
Quoted 5 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Quoted 7 lines
Quoted 4 lines

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Azure pipeline build fails. Not because of this patch though.
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=7479&view=logs&j=c6c7c3ee-a125-5e20-d856-38cb989f4743&t=d274418e-7320-5c59-39b7-156cfcddae0b

Er? The failure is just above the end of the page (which the link opens
to for me) and is:
+drivers/mtd/nand/raw/omap_gpmc.c:356:12: error: 'omap_calculate_ecc_bch' defined but not used [-Werror=unused-function]
+ 356 | static int omap_calculate_ecc_bch(struct mtd_info *mtd, const u8 *dat,
+ | ^~~~~~~~~~~~~~~~~~~~~~
+cc1: all warnings being treated as errors

And is this patch :)

Signature · 1 line
Tom
#7 lore raw
In reply to Roger Quadros
Quoted 18 lines · Roger Quadros

Hi Tom,

Quoted 15 lines · Tom Rini
Quoted 12 lines · Roger Quadros

AM335x uses a special driver "am335x_spl_bch.c" as SPL
NAND loader. This driver expects 1 sector at a time ECC
and doesn't work well with multi-sector ECC that was implemented in commit 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")

Switch back to 1 sector at a time read/ECC.

Fixes 04fcd2587321 ("mtd: rawnand: omap_gpmc: Fix BCH6/16 HW based correction")
---
 drivers/mtd/nand/raw/omap_gpmc.c | 95 ++++++++++----------------------
 1 file changed, 29 insertions(+), 66 deletions(-)
Quoted 8 lines
Quoted 5 lines

I'm glad to see this fixed. My question is, can we abstract this slightly as I assume there's a performance hit on the newer SoCs that support more than one sector at a time for ECC and I assume it's just am335x and related that don't support the feature. Thanks.

It looks like that the ELM driver (omap_elm.c) is not yet ready for multi-sector setup yet. I will need more time to test the multi-sector implementation.

Ah, thanks. Lets make that clearer in the commit message of the next spin please.

Signature · 1 line
Tom