mtd: rawnand: denali_dt: Add support for configuring SPARE_AREA_SKIP_BYTES
Subsystems (3)
PATCH 1/1 mtd: rawnand: denali_dt: Add support for configuring SPARE_AREA_SKIP_BYTES
The SPARE_AREA_SKIP_BYTES register is reset when the controller reset signal is toggled. Yet, this register must be configured to match the content of the NAND OOB area. The current default value is always set to 8 and is programmed into the hardware in case the hardware was not programmed before (e.g. in a bootloader) with a different value. This however does not work when the block is reset properly by Linux.
On Altera SoCFPGA CycloneV, ArriaV and Arria10, which are the SoCFPGA platforms which support booting from NAND, the SPARE_AREA_SKIP_BYTES value must be set to 2. On Socionext Uniphier, the value is 8. This patch adds support for preconfiguring the default value and handles the special SoCFPGA case by setting the default to 2 on all SoCFPGA platforms, while retaining the original behavior and default value of 8 on all the other platforms.
--- drivers/mtd/nand/raw/denali.c | 13 ++++++++++--- drivers/mtd/nand/raw/denali_dt.c | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/denali.c +10 -3
@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali)/* * Set how many bytes should be skipped before writing data in OOB. +* If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes =ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); -if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +if (denali->oob_skip_bytes) {iowrite32 (denali->oob_skip_bytes, denali->reg +SPARE_AREA_SKIP_BYTES ); + }else { + denali->oob_skip_bytes = +ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); +if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +iowrite32 (denali->oob_skip_bytes, + denali->reg +SPARE_AREA_SKIP_BYTES ); + } }iowrite32 (0 , denali->reg +TRANSFER_SPARE_REG );
drivers/mtd/nand/raw/denali_dt.c +6 -0
@@ -27,6 +27,7 @@ struct denali_dt {struct denali_dt_data {unsigned int revision;unsigned int caps; +unsigned int oob_skip_bytes;const struct nand_ecc_caps *ecc_caps; };
@@ -34,6 +35,7 @@ NAND_ECC_CAPS_SINGLE(denali_socfpga_ecc_caps, denali_calc_ecc_bytes, 512, 8, 15);static const struct denali_dt_data denali_socfpga_data = { .caps =DENALI_CAP_HW_ECC_FIXUP , + .oob_skip_bytes =2 , .ecc_caps = &denali_socfpga_ecc_caps, };
@@ -42,6 +44,7 @@ NAND_ECC_CAPS_SINGLE(denali_uniphier_v5a_ecc_caps, denali_calc_ecc_bytes,static const struct denali_dt_data denali_uniphier_v5a_data = { .caps =DENALI_CAP_HW_ECC_FIXUP |DENALI_CAP_DMA_64BIT , + .oob_skip_bytes =8 , .ecc_caps = &denali_uniphier_v5a_ecc_caps, };
@@ -51,6 +54,7 @@ static const struct denali_dt_data denali_uniphier_v5b_data = { .revision = 0x0501, .caps = DENALI_CAP_HW_ECC_FIXUP | DENALI_CAP_DMA_64BIT, + .oob_skip_bytes = 8, .ecc_caps = &denali_uniphier_v5b_ecc_caps, };
@@ -209,6 +213,8 @@ static int denali_dt_probe(struct platform_device *pdev) denali->clk_rate =clk_get_rate (dt->clk); denali->clk_x_rate =clk_get_rate (dt->clk_x); + denali->oob_skip_bytes = data->oob_skip_bytes; + ret =denali_init (denali);if (ret) goto out_disable_clk_ecc;
Signature · 6 lines
2.24.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 43 lines · Marek Vasut
The
SPARE_AREA_SKIP_BYTESregister is reset when the controller reset signal is toggled. Yet, this register must be configured to match the content of the NAND OOB area. The current default value is always set to 8 and is programmed into the hardware in case the hardware was not programmed before (e.g. in a bootloader) with a different value. This however does not work when the block is reset properly by Linux.On Altera SoCFPGA CycloneV, ArriaV and Arria10, which are the SoCFPGA platforms which support booting from NAND, the
SPARE_AREA_SKIP_BYTESvalue must be set to 2. On Socionext Uniphier, the value is 8. This patch adds support for preconfiguring the default value and handles the special SoCFPGA case by setting the default to 2 on all SoCFPGA platforms, while retaining the original behavior and default value of 8 on all the other platforms.Signed-off-by Marek Vasut <[email protected]>Cc Ley Foon Tan <[email protected]>Cc Masahiro Yamada <[email protected]>Cc Miquel Raynal <[email protected]>Cc Richard Weinberger <[email protected]>Cc Vignesh Raghavendra <[email protected]>--- drivers/mtd/nand/raw/denali.c | 13 ++++++++++--- drivers/mtd/nand/raw/denali_dt.c | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-)drivers/mtd/nand/raw/denali.c +1
-3@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali)/* * Set how many bytes should be skipped before writing data in OOB. +* If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes =ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); -if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ;
drivers/mtd/nand/raw/denali.c int denali_init(struct denali_controller *denali) · line 1318
Quoted 10 lines
drivers/mtd/nand/raw/denali.c +8
-0+if (denali->oob_skip_bytes) {iowrite32 (denali->oob_skip_bytes, denali->reg +SPARE_AREA_SKIP_BYTES ); + }else { + denali->oob_skip_bytes = +ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); +if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +iowrite32 (denali->oob_skip_bytes, + denali->reg +SPARE_AREA_SKIP_BYTES );
This fallback is ugly, and should be removed, I think. It is only reachable by PCI platform (Intel MRST), where DENALI_DEFAULT_OOB_SKIP_BYTES is probably useless.
drivers/mtd/nand/raw/denali.c static int denali_dt_probe(struct platform_device *pdev) · line 217
Quoted 6 lines
drivers/mtd/nand/raw/denali.c +2
-0@@ -209,6 +213,8 @@ static int denali_dt_probe(struct platform_device *pdev) denali->clk_rate =clk_get_rate (dt->clk); denali->clk_x_rate =clk_get_rate (dt->clk_x); + denali->oob_skip_bytes = data->oob_skip_bytes; +
Please move this to the relevant hunk.
Preferably, based on this:
http://patchwork.ozlabs.org/patch/1205912/
Quoted 10 lines
drivers/mtd/nand/raw/denali.c +0
-1ret =denali_init (denali);if (ret) goto out_disable_clk_ecc; --2.24.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
--
Best Regards
Masahiro Yamada
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
On 12/9/19 6:38 AM, Masahiro Yamada wrote:
[...]
Quoted 21 lines
Quoted 21 lines
drivers/mtd/nand/raw/denali.c +5
-3@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali)/* * Set how many bytes should be skipped before writing data in OOB. +* If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes =ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); -if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +if (denali->oob_skip_bytes) {iowrite32 (denali->oob_skip_bytes, denali->reg +SPARE_AREA_SKIP_BYTES ); + }else { + denali->oob_skip_bytes = +ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES );
Quoted 8 lines
drivers/mtd/nand/raw/denali.c int denali_init(struct denali_controller *denali) · line 1318
Quoted 4 lines
drivers/mtd/nand/raw/denali.c +4
-0+if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +iowrite32 (denali->oob_skip_bytes, + denali->reg +SPARE_AREA_SKIP_BYTES );This fallback is ugly, and should be removed, I think. It is only reachable by PCI platform (Intel MRST), where
DENALI_DEFAULT_OOB_SKIP_BYTESis probably useless.
This fallback retains the original behavior on all platforms. It might not be to your liking, but it does not break other platforms while fixing SoCFPGA. We don't know what other platforms might be depending on this behavior, do we ?
Quoted 10 lines
drivers/mtd/nand/raw/denali.c static int denali_dt_probe(struct platform_device *pdev) · line 217
Quoted 6 lines
drivers/mtd/nand/raw/denali.c +2
-0@@ -209,6 +213,8 @@ static int denali_dt_probe(struct platform_device *pdev) denali->clk_rate =clk_get_rate (dt->clk); denali->clk_x_rate =clk_get_rate (dt->clk_x); + denali->oob_skip_bytes = data->oob_skip_bytes; +Please move this to the relevant hunk.
Preferably, based on this:
http://patchwork.ozlabs.org/patch/1205912/
I don't understand what you want me to change ? Shall I rebase this on top of your patch from today and repost ?
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 34 lines · Marek Vasut
On 12/9/19 6:38 AM, Masahiro Yamada wrote:
[...]Quoted 21 lines
Quoted 21 lines
drivers/mtd/nand/raw/denali.c +5
-3@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali)/* * Set how many bytes should be skipped before writing data in OOB. +* If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes =ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); -if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +if (denali->oob_skip_bytes) {iowrite32 (denali->oob_skip_bytes, denali->reg +SPARE_AREA_SKIP_BYTES ); + }else { + denali->oob_skip_bytes = +ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES );Quoted 8 lines
drivers/mtd/nand/raw/denali.c int denali_init(struct denali_controller *denali) · line 1318
Quoted 4 lines
drivers/mtd/nand/raw/denali.c +4
-0+if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +iowrite32 (denali->oob_skip_bytes, + denali->reg +SPARE_AREA_SKIP_BYTES );This fallback is ugly, and should be removed, I think. It is only reachable by PCI platform (Intel MRST), where
DENALI_DEFAULT_OOB_SKIP_BYTESis probably useless.
Quoted 4 lines
This fallback retains the original behavior on all platforms. It might not be to your liking, but it does not break other platforms while fixing SoCFPGA. We don't know what other platforms might be depending on this behavior, do we ?
if (denali->oob_skip_bytes) {
iowrite32(denali->oob_skip_bytes,
denali->reg + SPARE_AREA_SKIP_BYTES);
else
denali->oob_skip_bytes =
ioread32(denali->reg + SPARE_AREA_SKIP_BYTES);... retains the original behavior.
For denali_dt.c, it now explicitly sets SPARE_AREA_SKIP_BYTES to the well-defined value.
denali_pci.c is the only platform that can read back the register value.
See, how Intel originally wrote the code.
https://github.com/torvalds/linux/blob/v3.0/drivers/mtd/nand/denali.c#L1345
Please notice the part "if this value is 0, just let it be." The Intel MRST platform happily accepts SPARE_AREA_SKIP_BYTES being set to 0.
I am not sure how many people are using this platform, but anyway it is how it has worked for a long time.
Quoted 11 lines
Quoted 10 lines
drivers/mtd/nand/raw/denali.c static int denali_dt_probe(struct platform_device *pdev) · line 217
Quoted 6 lines
drivers/mtd/nand/raw/denali.c +2
-0@@ -209,6 +213,8 @@ static int denali_dt_probe(struct platform_device *pdev) denali->clk_rate =clk_get_rate (dt->clk); denali->clk_x_rate =clk_get_rate (dt->clk_x); + denali->oob_skip_bytes = data->oob_skip_bytes; +Please move this to the relevant hunk.
Preferably, based on this:
http://patchwork.ozlabs.org/patch/1205912/
Quoted 2 lines
I don't understand what you want me to change ? Shall I rebase this on top of your patch from today and repost ?
Yes.
I do not want to scatter the relevant code
(coping struct fields) to random places.
I want the code to look like this:
denali->revision = data->revision;
denali->caps = data->caps;
+ denali->oob_skip_bytes = data->oob_skip_bytes;
denali->ecc_caps = data->ecc_caps;Signature · 6 lines
Best Regards Masahiro Yamada ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 48 lines · Masahiro Yamada
Quoted 34 lines · Marek Vasut
On 12/9/19 6:38 AM, Masahiro Yamada wrote:
[...]Quoted 21 lines
Quoted 21 lines
drivers/mtd/nand/raw/denali.c +5
-3@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali)/* * Set how many bytes should be skipped before writing data in OOB. +* If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes =ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); -if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +if (denali->oob_skip_bytes) {iowrite32 (denali->oob_skip_bytes, denali->reg +SPARE_AREA_SKIP_BYTES ); + }else { + denali->oob_skip_bytes = +ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES );Quoted 8 lines
drivers/mtd/nand/raw/denali.c int denali_init(struct denali_controller *denali) · line 1318
Quoted 4 lines
drivers/mtd/nand/raw/denali.c +4
-0+if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +iowrite32 (denali->oob_skip_bytes, + denali->reg +SPARE_AREA_SKIP_BYTES );This fallback is ugly, and should be removed, I think. It is only reachable by PCI platform (Intel MRST), where
DENALI_DEFAULT_OOB_SKIP_BYTESis probably useless.Quoted 4 lines
This fallback retains the original behavior on all platforms. It might not be to your liking, but it does not break other platforms while fixing SoCFPGA. We don't know what other platforms might be depending on this behavior, do we ?
if (denali->oob_skip_bytes) { iowrite32(denali->oob_skip_bytes, denali->reg + SPARE_AREA_SKIP_BYTES); else denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES);
Quoted 1 line
... retains the original behavior.
It does not, because if the readback in the else branch sets oob_skip_bytes to 0, the controller is not updated with the default value.
Quoted 11 lines
For
denali_dt.c, it now explicitly setsSPARE_AREA_SKIP_BYTESto the well-defined value.
denali_pci.cis the only platform that can read back the register value.See, how Intel originally wrote the code.
https://github.com/torvalds/linux/blob/v3.0/drivers/mtd/nand/denali.c#L1345
Quoted 6 lines
Please notice the part "if this value is 0, just let it be." The Intel MRST platform happily accepts
SPARE_AREA_SKIP_BYTESbeing set to 0.I am not sure how many people are using this platform, but anyway it is how it has worked for a long time.
The intel platform might accept 0 happily, but that's not how the controller was configured for a long time. So if I were to change the code as you suggest, it would likely break some setups.
Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
drivers/mtd/nand/raw/denali.c static int denali_dt_probe(struct platform_device *pdev) · line 217
Quoted 6 lines
drivers/mtd/nand/raw/denali.c +2
-0@@ -209,6 +213,8 @@ static int denali_dt_probe(struct platform_device *pdev) denali->clk_rate =clk_get_rate (dt->clk); denali->clk_x_rate =clk_get_rate (dt->clk_x); + denali->oob_skip_bytes = data->oob_skip_bytes; +Please move this to the relevant hunk.
Preferably, based on this:
http://patchwork.ozlabs.org/patch/1205912/Quoted 2 lines
I don't understand what you want me to change ? Shall I rebase this on top of your patch from today and repost ?
Yes.
I do not want to scatter the relevant code
(coping struct fields) to random places.
Quoted 6 lines
I want the code to look like this:
denali->revision = data->revision; denali->caps = data->caps; + denali->oob_skip_bytes = data->oob_skip_bytes; denali->ecc_caps = data->ecc_caps;
Maybe you can rebase your patch on top of this one then ? It was posted later after all.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 70 lines · Marek Vasut
Quoted 48 lines · Masahiro Yamada
Quoted 34 lines · Marek Vasut
On 12/9/19 6:38 AM, Masahiro Yamada wrote:
[...]Quoted 21 lines
Quoted 21 lines
drivers/mtd/nand/raw/denali.c +5
-3@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali)/* * Set how many bytes should be skipped before writing data in OOB. +* If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes =ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); -if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +if (denali->oob_skip_bytes) {iowrite32 (denali->oob_skip_bytes, denali->reg +SPARE_AREA_SKIP_BYTES ); + }else { + denali->oob_skip_bytes = +ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES );Quoted 8 lines
drivers/mtd/nand/raw/denali.c int denali_init(struct denali_controller *denali) · line 1318
Quoted 4 lines
drivers/mtd/nand/raw/denali.c +4
-0+if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +iowrite32 (denali->oob_skip_bytes, + denali->reg +SPARE_AREA_SKIP_BYTES );This fallback is ugly, and should be removed, I think. It is only reachable by PCI platform (Intel MRST), where
DENALI_DEFAULT_OOB_SKIP_BYTESis probably useless.Quoted 4 lines
This fallback retains the original behavior on all platforms. It might not be to your liking, but it does not break other platforms while fixing SoCFPGA. We don't know what other platforms might be depending on this behavior, do we ?
if (denali->oob_skip_bytes) { iowrite32(denali->oob_skip_bytes, denali->reg + SPARE_AREA_SKIP_BYTES); else denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES);Quoted 1 line
... retains the original behavior.
It does not, because if the readback in the else branch sets
oob_skip_bytesto 0, the controller is not updated with the default value.Quoted 15 lines
For
denali_dt.c, it now explicitly setsSPARE_AREA_SKIP_BYTESto the well-defined value.
denali_pci.cis the only platform that can read back the register value.See, how Intel originally wrote the code.
https://github.com/torvalds/linux/blob/v3.0/drivers/mtd/nand/denali.c#L1345
Please notice the part "if this value is 0, just let it be." The Intel MRST platform happily accepts
SPARE_AREA_SKIP_BYTESbeing set to 0.
Quoted 5 lines
Quoted 2 lines
I am not sure how many people are using this platform, but anyway it is how it has worked for a long time.
The intel platform might accept 0 happily, but that's not how the controller was configured for a long time.
It is.
It worked like that for 9 years. (i.e. v2.6.35 - v4.19)
Quoted 2 lines
So if I were to change the
code as you suggest, it would likely break some setups.
There is no perfect solution here
when SPARE_AREA_SKIP_BYTES was set to 0
before booting the kernel.
[A] Keep SPARE_AREA_SKIP_BYTES as it is.
This might affect the factory-recorded BBM,
but it should at least work if the firmware or the boot-loader has set up the controller this way.
[B] Override SPARE_AREA_SKIP_BYTES with
a different value (8).
This can keep the factory-based BBM, but
this is very unlikely to work across software stages if the NAND device was formatted by the firmware or the boot-loader.
We need to give up something.
[A] was the original, 9 years' default, and cleaner.
Quoted 21 lines
Quoted 21 lines
Quoted 11 lines
Quoted 10 lines
drivers/mtd/nand/raw/denali.c static int denali_dt_probe(struct platform_device *pdev) · line 217
Quoted 6 lines
drivers/mtd/nand/raw/denali.c +2
-0@@ -209,6 +213,8 @@ static int denali_dt_probe(struct platform_device *pdev) denali->clk_rate =clk_get_rate (dt->clk); denali->clk_x_rate =clk_get_rate (dt->clk_x); + denali->oob_skip_bytes = data->oob_skip_bytes; +Please move this to the relevant hunk.
Preferably, based on this:
http://patchwork.ozlabs.org/patch/1205912/Quoted 2 lines
I don't understand what you want me to change ? Shall I rebase this on top of your patch from today and repost ?
Yes.
I do not want to scatter the relevant code
(coping struct fields) to random places.I want the code to look like this:
Quoted 7 lines
Quoted 4 lines
denali->revision = data->revision; denali->caps = data->caps; + denali->oob_skip_bytes = data->oob_skip_bytes; denali->ecc_caps = data->ecc_caps;Maybe you can rebase your patch on top of this one then ? It was posted later after all.
Neither is applied yet.
If you have a chance for v2,
it would not be so annoying to move the code
to the relevant place.
If you really do not like rebase,
the second best would be:
if (data) {
denali->revision = data->revision;
denali->caps = data->caps;
+ denali->oob_skip_bytes = data->oob_skip_bytes;
denali->ecc_caps = data->ecc_caps;
}--
Best Regards
Masahiro Yamada
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 71 lines · Masahiro Yamada
Quoted 70 lines · Marek Vasut
Quoted 48 lines · Masahiro Yamada
Quoted 34 lines · Marek Vasut
On 12/9/19 6:38 AM, Masahiro Yamada wrote:
[...]Quoted 21 lines
Quoted 21 lines
drivers/mtd/nand/raw/denali.c +5
-3@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali)/* * Set how many bytes should be skipped before writing data in OOB. +* If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes =ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); -if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +if (denali->oob_skip_bytes) {iowrite32 (denali->oob_skip_bytes, denali->reg +SPARE_AREA_SKIP_BYTES ); + }else { + denali->oob_skip_bytes = +ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES );Quoted 8 lines
drivers/mtd/nand/raw/denali.c int denali_init(struct denali_controller *denali) · line 1318
Quoted 4 lines
drivers/mtd/nand/raw/denali.c +4
-0+if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +iowrite32 (denali->oob_skip_bytes, + denali->reg +SPARE_AREA_SKIP_BYTES );This fallback is ugly, and should be removed, I think. It is only reachable by PCI platform (Intel MRST), where
DENALI_DEFAULT_OOB_SKIP_BYTESis probably useless.Quoted 4 lines
This fallback retains the original behavior on all platforms. It might not be to your liking, but it does not break other platforms while fixing SoCFPGA. We don't know what other platforms might be depending on this behavior, do we ?
if (denali->oob_skip_bytes) { iowrite32(denali->oob_skip_bytes, denali->reg + SPARE_AREA_SKIP_BYTES); else denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES);Quoted 1 line
... retains the original behavior.
It does not, because if the readback in the else branch sets
oob_skip_bytesto 0, the controller is not updated with the default value.Quoted 15 lines
For
denali_dt.c, it now explicitly setsSPARE_AREA_SKIP_BYTESto the well-defined value.
denali_pci.cis the only platform that can read back the register value.See, how Intel originally wrote the code.
https://github.com/torvalds/linux/blob/v3.0/drivers/mtd/nand/denali.c#L1345
Please notice the part "if this value is 0, just let it be." The Intel MRST platform happily accepts
SPARE_AREA_SKIP_BYTESbeing set to 0.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I am not sure how many people are using this platform, but anyway it is how it has worked for a long time.
The intel platform might accept 0 happily, but that's not how the controller was configured for a long time.
It is.
It worked like that for 9 years. (i.e. v2.6.35 - v4.19)
So it is broken now ?
If so, then that fix is for another patch.
Quoted 20 lines
Quoted 2 lines
So if I were to change the
code as you suggest, it would likely break some setups.There is no perfect solution here when
SPARE_AREA_SKIP_BYTESwas set to 0 before booting the kernel.[A] Keep
SPARE_AREA_SKIP_BYTESas it is.
This might affect the factory-recorded BBM,
but it should at least work if the firmware or the boot-loader has set up the controller this way.[B] Override
SPARE_AREA_SKIP_BYTESwith
a different value (8).
This can keep the factory-based BBM, but
this is very unlikely to work across software stages if the NAND device was formatted by the firmware or the boot-loader.
Quoted 2 lines
We need to give up something.
[A] was the original, 9 years' default, and cleaner.
Or maybe
commit 0d55c668b218a1db68b5044bce4de74e1bd0f0c8
mtd: rawnand: denali: set SPARE_AREA_SKIP_BYTES register to 8 if unset
should be reverted, since it changed the behavior ?
[...]
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 76 lines · Marek Vasut
Quoted 74 lines · Masahiro Yamada
Quoted 73 lines · Marek Vasut
Quoted 48 lines · Masahiro Yamada
Quoted 34 lines · Marek Vasut
On 12/9/19 6:38 AM, Masahiro Yamada wrote:
[...]Quoted 21 lines
Quoted 21 lines
drivers/mtd/nand/raw/denali.c +5
-3@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali)/* * Set how many bytes should be skipped before writing data in OOB. +* If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes =ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); -if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +if (denali->oob_skip_bytes) {iowrite32 (denali->oob_skip_bytes, denali->reg +SPARE_AREA_SKIP_BYTES ); + }else { + denali->oob_skip_bytes = +ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES );Quoted 8 lines
drivers/mtd/nand/raw/denali.c int denali_init(struct denali_controller *denali) · line 1318
Quoted 4 lines
drivers/mtd/nand/raw/denali.c +4
-0+if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +iowrite32 (denali->oob_skip_bytes, + denali->reg +SPARE_AREA_SKIP_BYTES );This fallback is ugly, and should be removed, I think. It is only reachable by PCI platform (Intel MRST), where
DENALI_DEFAULT_OOB_SKIP_BYTESis probably useless.Quoted 4 lines
This fallback retains the original behavior on all platforms. It might not be to your liking, but it does not break other platforms while fixing SoCFPGA. We don't know what other platforms might be depending on this behavior, do we ?
if (denali->oob_skip_bytes) { iowrite32(denali->oob_skip_bytes, denali->reg + SPARE_AREA_SKIP_BYTES); else denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES);Quoted 1 line
... retains the original behavior.
It does not, because if the readback in the else branch sets
oob_skip_bytesto 0, the controller is not updated with the default value.Quoted 17 lines
For
denali_dt.c, it now explicitly setsSPARE_AREA_SKIP_BYTESto the well-defined value.
denali_pci.cis the only platform that can read back the register value.See, how Intel originally wrote the code.
https://github.com/torvalds/linux/blob/v3.0/drivers/mtd/nand/denali.c#L1345
Please notice the part "if this value is 0, just let it be." The Intel MRST platform happily accepts
SPARE_AREA_SKIP_BYTESbeing set to 0.I am not sure how many people are using this platform, but anyway it is how it has worked for a long time.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
The intel platform might accept 0 happily, but that's not how the controller was configured for a long time.
It is.
It worked like that for 9 years. (i.e. v2.6.35 - v4.19)So it is broken now ?
I do not know.
As I already said, there is no perfect solution about what to do when SPARE_AREA_SKIP_BYTES is zero.
I received various feedback from SOCFPGA board users about this driver, but nothing from denali_pci platfrom users. Absolutely zero question/complaint.
I suspect there is no user of that platform, but who knows.
Quoted 1 line
If so, then that fix is for another patch.
So, do you want me to get back the original behavior, then you want to send a new patch based on that?
I think it is a waste of time, but
it would be less worse than continuing this thread.
Quoted 31 lines
Quoted 20 lines
Quoted 2 lines
So if I were to change the
code as you suggest, it would likely break some setups.There is no perfect solution here when
SPARE_AREA_SKIP_BYTESwas set to 0 before booting the kernel.[A] Keep
SPARE_AREA_SKIP_BYTESas it is.
This might affect the factory-recorded BBM,
but it should at least work if the firmware or the boot-loader has set up the controller this way.[B] Override
SPARE_AREA_SKIP_BYTESwith
a different value (8).
This can keep the factory-based BBM, but
this is very unlikely to work across software stages if the NAND device was formatted by the firmware or the boot-loader.Quoted 2 lines
We need to give up something.
[A] was the original, 9 years' default, and cleaner.Or maybe
commit
0d55c668b218a1db68b5044bce4de74e1bd0f0c8
mtd: rawnand: denali: setSPARE_AREA_SKIP_BYTESregister to 8 if unsetshould be reverted, since it changed the behavior ?
[...]
Signature · 6 lines
Best Regards Masahiro Yamada ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
On 12/12/19 5:12 AM, Masahiro Yamada wrote:
[...]
Quoted 78 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 39 lines
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
(quoted diff) +5
-3@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali) /* * Set how many bytes should be skipped before writing data in OOB. + * If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES); - if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes = DENALI_DEFAULT_OOB_SKIP_BYTES; + if (denali->oob_skip_bytes) { iowrite32(denali->oob_skip_bytes, denali->reg + SPARE_AREA_SKIP_BYTES); + } else { + denali->oob_skip_bytes = + ioread32(denali->reg + SPARE_AREA_SKIP_BYTES);Quoted 8 lines
Review int denali_init(struct denali_controller *denali) · line 1318
Quoted 4 lines
(quoted diff) +4
-0+ if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes = DENALI_DEFAULT_OOB_SKIP_BYTES; + iowrite32(denali->oob_skip_bytes, + denali->reg + SPARE_AREA_SKIP_BYTES);This fallback is ugly, and should be removed, I think. It is only reachable by PCI platform (Intel MRST), where
DENALI_DEFAULT_OOB_SKIP_BYTESis probably useless.Quoted 4 lines
This fallback retains the original behavior on all platforms. It might not be to your liking, but it does not break other platforms while fixing SoCFPGA. We don't know what other platforms might be depending on this behavior, do we ?
if (denali->oob_skip_bytes) { iowrite32(denali->oob_skip_bytes, denali->reg + SPARE_AREA_SKIP_BYTES); else denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES);Quoted 1 line
... retains the original behavior.
It does not, because if the readback in the else branch sets
oob_skip_bytesto 0, the controller is not updated with the default value.Quoted 17 lines
For
denali_dt.c, it now explicitly setsSPARE_AREA_SKIP_BYTESto the well-defined value.
denali_pci.cis the only platform that can read back the register value.See, how Intel originally wrote the code.
https://github.com/torvalds/linux/blob/v3.0/drivers/mtd/nand/denali.c#L1345
Please notice the part "if this value is 0, just let it be." The Intel MRST platform happily accepts
SPARE_AREA_SKIP_BYTESbeing set to 0.I am not sure how many people are using this platform, but anyway it is how it has worked for a long time.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
The intel platform might accept 0 happily, but that's not how the controller was configured for a long time.
It is.
It worked like that for 9 years. (i.e. v2.6.35 - v4.19)So it is broken now ?
I do not know.
As I already said, there is no perfect solution about what to do whenSPARE_AREA_SKIP_BYTESis zero.I received various feedback from SOCFPGA board users about this driver, but nothing from
denali_pciplatfrom users. Absolutely zero question/complaint.
Quoted 7 lines
I suspect there is no user of that platform, but who knows.
Quoted 1 line
If so, then that fix is for another patch.
So, do you want me to get back the original behavior, then you want to send a new patch based on that?
I think it's definitely two separate issues.
Quoted 2 lines
I think it is a waste of time, but
it would be less worse than continuing this thread.
This patch at least retains the current behavior, so if someone wants to restore the original behavior before 4.19, it can be even done on top of this patch.
[...]
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Hi, Marek, Masahiro,
Quoted 95 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
The
SPARE_AREA_SKIP_BYTESregister is reset when the controller reset signal is toggled. Yet, this register must be configured to match the content of the NAND OOB area. The current default value is always set to 8 and is programmed into the hardware in case the hardware was not programmed before (e.g. in a bootloader) with a different value. This however does not work when the block is reset properly by Linux.On Altera SoCFPGA CycloneV, ArriaV and Arria10, which are the SoCFPGA platforms which support booting from NAND, the
SPARE_AREA_SKIP_BYTESvalue must be set to 2. On Socionext Uniphier, the value is 8. This patch adds support for preconfiguring the default value and handles the special SoCFPGA case by setting the default to 2 on all SoCFPGA platforms, while retaining the original behavior and default value of 8 on all the other platforms.Signed-off-by Marek Vasut <[email protected]>Cc Ley Foon Tan <[email protected]>Cc Masahiro Yamada <[email protected]>Cc Miquel Raynal <[email protected]>Cc Richard Weinberger <[email protected]>Cc Vignesh Raghavendra <[email protected]>--- drivers/mtd/nand/raw/denali.c | 13 ++++++++++--- drivers/mtd/nand/raw/denali_dt.c | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-)drivers/mtd/nand/raw/denali.c +10
-3@@ -1302,14 +1302,21 @@ int denali_init(struct denali_controller *denali)/* * Set how many bytes should be skipped before writing data in OOB. +* If a non-zero value has already been configured, update it in HW. * If a non-zero value has already been set (by firmware or something), * just use it. Otherwise, set the driver's default. */ - denali->oob_skip_bytes =ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); -if (!denali->oob_skip_bytes) { - denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +if (denali->oob_skip_bytes) {iowrite32 (denali->oob_skip_bytes, denali->reg +SPARE_AREA_SKIP_BYTES ); + }else { + denali->oob_skip_bytes = +ioread32 (denali->reg +SPARE_AREA_SKIP_BYTES ); +if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes =DENALI_DEFAULT_OOB_SKIP_BYTES ; +iowrite32 (denali->oob_skip_bytes, + denali->reg +SPARE_AREA_SKIP_BYTES ); + } }iowrite32 (0 , denali->reg +TRANSFER_SPARE_REG );drivers/mtd/nand/raw/denali_dt.c +4
-0@@ -27,6 +27,7 @@ struct denali_dt {struct denali_dt_data {unsigned int revision;unsigned int caps; +unsigned int oob_skip_bytes;const struct nand_ecc_caps *ecc_caps; };@@ -34,6 +35,7 @@ NAND_ECC_CAPS_SINGLE(denali_socfpga_ecc_caps, denali_calc_ecc_bytes, 512, 8, 15);static const struct denali_dt_data denali_socfpga_data = { .caps =DENALI_CAP_HW_ECC_FIXUP , + .oob_skip_bytes =2 , .ecc_caps = &denali_socfpga_ecc_caps, };@@ -42,6 +44,7 @@ NAND_ECC_CAPS_SINGLE(denali_uniphier_v5a_ecc_caps, denali_calc_ecc_bytes,static const struct denali_dt_data denali_uniphier_v5a_data = { .caps =DENALI_CAP_HW_ECC_FIXUP |DENALI_CAP_DMA_64BIT , + .oob_skip_bytes =8 , .ecc_caps = &denali_uniphier_v5a_ecc_caps, };@@ -51,6 +54,7 @@ static const struct denali_dt_data denali_uniphier_v5b_data = { .revision = 0x0501, .caps = DENALI_CAP_HW_ECC_FIXUP | DENALI_CAP_DMA_64BIT, + .oob_skip_bytes = 8, .ecc_caps = &denali_uniphier_v5b_ecc_caps, };
drivers/mtd/nand/raw/denali_dt.c static int denali_dt_probe(struct platform_device *pdev) · line 217
Quoted 5 lines
drivers/mtd/nand/raw/denali_dt.c +2
-0@@ -209,6 +213,8 @@ static int denali_dt_probe(struct platform_device *pdev) denali->clk_rate =clk_get_rate (dt->clk); denali->clk_x_rate =clk_get_rate (dt->clk_x); + denali->oob_skip_bytes = data->oob_skip_bytes; +
This indeed should be moved immediately after getting of_device_get_match_data. I share Marek's opinion that what Masahiro have identified worths a separate patch. Ideally we should fix one thing per patch. With this moved immediately after of_device_get_match_data() one can add:
Cheers,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/