Skip to contentSkip to conversation

mtd: nand: allow NAND_NO_SUBPAGE_WRITE to be set from driver

PATCH RESEND In review Brian Norris 5 participants 13 messages Jul 31, 2012 – Aug 2, 2012

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

PATCH RESEND 1/1 mtd: nand: allow NAND_NO_SUBPAGE_WRITE to be set from driver

The NAND_CHIPOPTIONS_MSK has limited utility and is causing real bugs. It silently masks off at least one flag that might be set by the driver (NAND_NO_SUBPAGE_WRITE). This breaks the GPMI NAND driver and possibly others.

Really, as long as driver writers exercise a small amount of care with NAND_* options, this mask is not necessary at all. Thus, kill it.

Quoted 1 line

From Huang Shijie:

"I tested this patch on imx6q-arm2 board with Micron MT29F32G08QAA. it works fine, thanks."

---
Hello Artem/David,

GPMI NAND has needed this patch for some time, and I think it was agreed on by a few. I'm resending to get acknowledgment from a maintainer.

 drivers/mtd/nand/nand_base.c | 7 ++-----
 include/linux/mtd/nand.h     | 3 ---
 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/mtd/nand/nand_base.c +2 -5
index ead301a..996cc48 100644
@@ -2909,8 +2909,6 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
 	if (le16_to_cpu(p->features) & 1)
 		*busw = NAND_BUSWIDTH_16;
 
-	chip->options &= ~NAND_CHIPOPTIONS_MSK;
-
 	pr_info("ONFI flash detected\n");
 	return 1;
 }
@@ -3074,9 +3072,8 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
 			mtd->erasesize <<= ((id_data[3] & 0x03) << 1);
 		}
 	}
-	/* Get chip options, preserve non chip based options */
-	chip->options &= ~NAND_CHIPOPTIONS_MSK;
-	chip->options |= type->options & NAND_CHIPOPTIONS_MSK;
+	/* Get chip options */
+	chip->options |= type->options;
 
 	/*
 	 * Check if chip is not a Samsung device. Do not clear the
include/linux/mtd/nand.h +0 -3
index 6dce5a7..eeb7015 100644
@@ -206,9 +206,6 @@ typedef enum {
 #define NAND_SUBPAGE_READ(chip) ((chip->ecc.mode == NAND_ECC_SOFT) \
 					&& (chip->page_shift > 9))
 
-/* Mask to zero out the chip options, which come from the id table */
-#define NAND_CHIPOPTIONS_MSK	0x0000ffff
-
 /* Non chip related options */
 /* This option skips the bbt scan during initialization. */
 #define NAND_SKIP_BBTSCAN	0x00010000
Signature · 1 line
1.7.11.3
Tested-by on v1 1/1
#1 lore raw

Dear Brian Norris,

Quoted 8 lines

The NAND_CHIPOPTIONS_MSK has limited utility and is causing real bugs. It silently masks off at least one flag that might be set by the driver (NAND_NO_SUBPAGE_WRITE). This breaks the GPMI NAND driver and possibly others.

Really, as long as driver writers exercise a small amount of care with NAND_* options, this mask is not necessary at all. Thus, kill it.

Quoted 7 lines

From Huang Shijie:

"I tested this patch on imx6q-arm2 board with Micron MT29F32G08QAA. it works fine, thanks."

Sorry for the slow reply. Tested it on denx m28evk board.

Quoted 6 lines
Cc Marek Vasut <[email protected]>

---
Hello Artem/David,

GPMI NAND has needed this patch for some time, and I think it was agreed on by a few. I'm resending to get acknowledgment from a maintainer.

[...]

Best regards,
Marek Vasut

#2 lore raw
In reply to Brian Norris

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

Does the gpmi driver set this flag because it do not support partial write ? In this case why it doesn't set chip->ecc.steps to 1 ?

Matthieu

Quoted 64 lines · Brian Norris

The NAND_CHIPOPTIONS_MSK has limited utility and is causing real bugs. It silently masks off at least one flag that might be set by the driver (NAND_NO_SUBPAGE_WRITE). This breaks the GPMI NAND driver and possibly others.

Really, as long as driver writers exercise a small amount of care with NAND_* options, this mask is not necessary at all. Thus, kill it.

Quoted 1 line

From Huang Shijie:

"I tested this patch on imx6q-arm2 board with Micron MT29F32G08QAA. it works fine, thanks."

---
Hello Artem/David,

GPMI NAND has needed this patch for some time, and I think it was agreed on by a few. I'm resending to get acknowledgment from a maintainer.

 drivers/mtd/nand/nand_base.c | 7 ++-----
 include/linux/mtd/nand.h     | 3 ---
 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/mtd/nand/nand_base.c +2 -5
index ead301a..996cc48 100644
@@ -2909,8 +2909,6 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
 	if (le16_to_cpu(p->features) & 1)
 		*busw = NAND_BUSWIDTH_16;
 
-	chip->options &= ~NAND_CHIPOPTIONS_MSK;
-
 	pr_info("ONFI flash detected\n");
 	return 1;
 }
@@ -3074,9 +3072,8 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
 			mtd->erasesize <<= ((id_data[3] & 0x03) << 1);
 		}
 	}
-	/* Get chip options, preserve non chip based options */
-	chip->options &= ~NAND_CHIPOPTIONS_MSK;
-	chip->options |= type->options & NAND_CHIPOPTIONS_MSK;
+	/* Get chip options */
+	chip->options |= type->options;
 
 	/*
 	 * Check if chip is not a Samsung device. Do not clear the
include/linux/mtd/nand.h +0 -3
index 6dce5a7..eeb7015 100644
@@ -206,9 +206,6 @@ typedef enum {
 #define NAND_SUBPAGE_READ(chip) ((chip->ecc.mode == NAND_ECC_SOFT) \
 					&& (chip->page_shift > 9))
 
-/* Mask to zero out the chip options, which come from the id table */
-#define NAND_CHIPOPTIONS_MSK	0x0000ffff
-
 /* Non chip related options */
 /* This option skips the bbt scan during initialization. */
 #define NAND_SKIP_BBTSCAN	0x00010000
#3 lore raw

Dear Matthieu CASTET,

Quoted 10 lines

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

Does the gpmi driver set this flag because it do not support partial write ?

Yes

Quoted 1 line

In this case why it doesn't set chip->ecc.steps to 1 ?

Can you elabore how exactly will that help please?

Quoted 76 lines

Matthieu

Quoted 73 lines · Brian Norris

The NAND_CHIPOPTIONS_MSK has limited utility and is causing real bugs. It silently masks off at least one flag that might be set by the driver (NAND_NO_SUBPAGE_WRITE). This breaks the GPMI NAND driver and possibly others.

Really, as long as driver writers exercise a small amount of care with NAND_* options, this mask is not necessary at all. Thus, kill it.

Quoted 1 line

From Huang Shijie:

"I tested this patch on imx6q-arm2 board with Micron MT29F32G08QAA. it works fine, thanks."

---
Hello Artem/David,

GPMI NAND has needed this patch for some time, and I think it was agreed on by a few. I'm resending to get acknowledgment from a maintainer.

 drivers/mtd/nand/nand_base.c | 7 ++-----
 include/linux/mtd/nand.h     | 3 ---
 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/mtd/nand/nand_base.c +0 -2
index ead301a..996cc48 100644
@@ -2909,8 +2909,6 @@ static int nand_flash_detect_onfi(struct mtd_info
 *mtd, struct nand_chip *chip,
 
 	if (le16_to_cpu(p->features) & 1)
 
 		*busw = NAND_BUSWIDTH_16;
 
-	chip->options &= ~NAND_CHIPOPTIONS_MSK;
-
drivers/mtd/nand/nand_base.c +2 -3
 	pr_info("ONFI flash detected\n");
 	return 1;
 
 }
@@ -3074,9 +3072,8 @@ static struct nand_flash_dev
 *nand_get_flash_type(struct mtd_info *mtd,
 
 			mtd->erasesize <<= ((id_data[3] & 0x03) << 1);
 
 		}
 
 	}
 
-	/* Get chip options, preserve non chip based options */
-	chip->options &= ~NAND_CHIPOPTIONS_MSK;
-	chip->options |= type->options & NAND_CHIPOPTIONS_MSK;
+	/* Get chip options */
+	chip->options |= type->options;
 
 	/*
 
 	 * Check if chip is not a Samsung device. Do not clear the
include/linux/mtd/nand.h +0 -0
index 6dce5a7..eeb7015 100644
@@ -206,9 +206,6 @@ typedef enum {
 
 #define NAND_SUBPAGE_READ(chip) ((chip->ecc.mode == NAND_ECC_SOFT) \
 
 					&& (chip->page_shift > 9))
 
Quoted 7 lines
Quoted 7 lines
include/linux/mtd/nand.h +0 -3
-/* Mask to zero out the chip options, which come from the id table */
-#define NAND_CHIPOPTIONS_MSK	0x0000ffff
-
 

/* Non chip related options */
/* This option skips the bbt scan during initialization. */
#define NAND_SKIP_BBTSCAN 0x00010000

Best regards,
Marek Vasut

#4 lore raw

Hi Marek,

Quoted 10 lines · Marek Vasut

Dear Matthieu CASTET,

Quoted 8 lines

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

Quoted 9 lines
Quoted 2 lines

Does the gpmi driver set this flag because it do not support partial write ?

Yes

Quoted 1 line

In this case why it doesn't set chip->ecc.steps to 1 ?

Can you elabore how exactly will that help please?

If you look at the nand_base.c, you will see that mtd->subpage_sft = 0 if NAND_NO_SUBPAGE_WRITE flags is set or chip->ecc.steps == 1 [1].

Matthieu

[1]

    /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
    if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
        !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
        switch (chip->ecc.steps) {
        case 2:
            mtd->subpage_sft = 1;
            break;
        case 4:
        case 8:
        case 16:
            mtd->subpage_sft = 2;
            break;
        }
    }
    chip->subpagesize = mtd->writesize >> mtd->subpage_sft;
#5 lore raw

Dear Matthieu CASTET,

Quoted 16 lines

Hi Marek,

Quoted 13 lines · Marek Vasut

Dear Matthieu CASTET,

Quoted 10 lines

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

Does the gpmi driver set this flag because it do not support partial write ?

Quoted 8 lines
Quoted 5 lines

Yes

Quoted 1 line

In this case why it doesn't set chip->ecc.steps to 1 ?

Can you elabore how exactly will that help please?

If you look at the nand_base.c, you will see that mtd->subpage_sft = 0 if NAND_NO_SUBPAGE_WRITE flags is set or chip->ecc.steps == 1 [1].

Ok, this is what I saw coming ... this is yet another hole in the design and I see only undefined behavior. So if default: branch started returning an error, this whole code will break again.

Quoted 16 lines

[1]

    /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
    if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
        !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
        switch (chip->ecc.steps) {
        case 2:
            mtd->subpage_sft = 1;
            break;
        case 4:
        case 8:
        case 16:
            mtd->subpage_sft = 2;
            break;
        }
    }
    chip->subpagesize = mtd->writesize >> mtd->subpage_sft;

Best regards,
Marek Vasut

#6 lore raw
Quoted 19 lines · Marek Vasut

Dear Matthieu CASTET,

Quoted 17 lines

Hi Marek,

Quoted 14 lines · Marek Vasut

Dear Matthieu CASTET,

Quoted 10 lines

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

Does the gpmi driver set this flag because it do not support partial write ?

Yes

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

In this case why it doesn't set chip->ecc.steps to 1 ?

Can you elabore how exactly will that help please?

If you look at the nand_base.c, you will see that mtd->subpage_sft = 0 if NAND_NO_SUBPAGE_WRITE flags is set or chip->ecc.steps == 1 [1].

Ok, this is what I saw coming ... this is yet another hole in the design and I see only undefined behavior. So if default: branch started returning an error, this whole code will break again.

Do you see any reason why chip->ecc.steps == 1 will return an error ? This will break drivers.

The behavior match the comment : "Allow subpage writes up to ecc.steps"

Matthieu

Quoted 18 lines
Quoted 18 lines

[1]

    /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
    if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
        !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
        switch (chip->ecc.steps) {
        case 2:
            mtd->subpage_sft = 1;
            break;
        case 4:
        case 8:
        case 16:
            mtd->subpage_sft = 2;
            break;
        }
    }
    chip->subpagesize = mtd->writesize >> mtd->subpage_sft;
#7 lore raw

Dear Matthieu CASTET,

Quoted 28 lines
Quoted 27 lines · Marek Vasut

Dear Matthieu CASTET,

Quoted 24 lines

Hi Marek,

Quoted 10 lines · Marek Vasut

Dear Matthieu CASTET,

Quoted 8 lines

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

Quoted 8 lines
Quoted 2 lines

Does the gpmi driver set this flag because it do not support partial write ?

Yes

Quoted 1 line

In this case why it doesn't set chip->ecc.steps to 1 ?

Can you elabore how exactly will that help please?

If you look at the nand_base.c, you will see that mtd->subpage_sft = 0 if NAND_NO_SUBPAGE_WRITE flags is set or chip->ecc.steps == 1 [1].

Quoted 6 lines
Quoted 3 lines

Ok, this is what I saw coming ... this is yet another hole in the design and I see only undefined behavior. So if default: branch started returning an error, this whole code will break again.

Do you see any reason why chip->ecc.steps == 1 will return an error ? This will break drivers.

It'd be enough if mtd->subpage_sft was inited to some other value. So either add "case 1: mtd->subpage_sft = 0; break;" or go with this patch. Either way is fine by me.

Quoted 27 lines

The behavior match the comment : "Allow subpage writes up to ecc.steps"

Matthieu

Quoted 23 lines
Quoted 23 lines

[1]

    /* Allow subpage writes up to ecc.steps. Not possible for MLC flash
    */ if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
    
        !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
        switch (chip->ecc.steps) {
        
        case 2:
            mtd->subpage_sft = 1;
            break;
        
        case 4:
        case 8:
        
        case 16:
            mtd->subpage_sft = 2;
            break;
        
        }
    
    }
    chip->subpagesize = mtd->writesize >> mtd->subpage_sft;

Best regards,
Marek Vasut

#8 lore raw
In reply to Matthieu CASTET
Quoted 6 lines · Matthieu CASTET

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

This is for cases where the constraint is the controller, not the chip.

Quoted 2 lines

Does the gpmi driver set this flag because it do not support partial write ? In this case why it doesn't set chip->ecc.steps to 1 ?

Why is it better to lie about ECC geometry than to just say "subpage writes aren't supported"? Does/will the ECC geometry get used by upper layers in evaluating the number of corrected bitflips?

-Scott

#9 lore raw
Quoted 2 lines · Scott Wood

Why is it better to lie about ECC geometry than to just say "subpage writes aren't supported"? Does/will the ECC geometry get used by upper

yes. I think it's better to provide an official method to let the driver say: " i do not support the subpage writes."

Huang Shijie

#10 lore raw
In reply to Scott Wood

Hi Scott,

Quoted 8 lines · Scott Wood
Quoted 6 lines · Matthieu CASTET

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

Quoted 8 lines

This is for cases where the constraint is the controller, not the chip.

Quoted 2 lines

Does the gpmi driver set this flag because it do not support partial write ? In this case why it doesn't set chip->ecc.steps to 1 ?

Why is it better to lie about ECC geometry than to just say "subpage writes aren't supported"? Does/will the ECC geometry get used by upper layers in evaluating the number of corrected bitflips?

If it is not because of ecc geometry, why the controller doesn't support subpage writes ?

Matthieu

#11 lore raw
Quoted 13 lines · Matthieu CASTET

Hi Scott,

Quoted 10 lines · Scott Wood
Quoted 6 lines · Matthieu CASTET

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

This is for cases where the constraint is the controller, not the chip.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Does the gpmi driver set this flag because it do not support partial write ? In this case why it doesn't set chip->ecc.steps to 1 ?

Why is it better to lie about ECC geometry than to just say "subpage writes aren't supported"? Does/will the ECC geometry get used by upper layers in evaluating the number of corrected bitflips?

If it is not because of ecc geometry, why the controller doesn't support subpage writes ?

I can't answer for GPMI, but in the case of Freescale eLBC/IFC, the controller only does ECC when you do a full page transaction -- but the ECC is still done in steps, which is relevant for bitflip thresholds.

-Scott

#12 lore raw
Quoted 18 lines · Scott Wood
Quoted 17 lines · Matthieu CASTET
Quoted 16 lines · Scott Wood
Quoted 6 lines · Matthieu CASTET

Hi,

for ONFI flash (like this micron one) the information should be extracted form the ONFI table (programs_per_page IIRC)

This should be better than relying on the SOC driver for setting this flags.

This is for cases where the constraint is the controller, not the chip.

Quoted 2 lines

Does the gpmi driver set this flag because it do not support partial write ? In this case why it doesn't set chip->ecc.steps to 1 ?

Why is it better to lie about ECC geometry than to just say "subpage writes aren't supported"? Does/will the ECC geometry get used by upper layers in evaluating the number of corrected bitflips?

Quoted 6 lines
Quoted 2 lines

If it is not because of ecc geometry, why the controller doesn't support subpage writes ?

I can't answer for GPMI, but in the case of Freescale eLBC/IFC, the controller only does ECC when you do a full page transaction -- but the ECC is still done in steps, which is relevant for bitflip thresholds.

My controller (out-of-tree driver) *can* support subpage writes, but disabling them gives performance benefits and allows stronger ECC modes. My driver already performs a kind of hack by enabling NAND_NO_SUBPAGE_WRITE in between nand_scan_ident() and nand_scan_tail().

I agree that removing the mask allows a direct way of stating that the controller does not support subpage writes, a property which is orthogonal to the concept of ECC step size.

Brian