* [PATCH] mtd: atmel_nand: NFC: fix mtd_nandbiterrs.ko test fail when using sram write
@ 2014-07-22 9:25 Josh Wu
2014-08-04 21:22 ` Brian Norris
0 siblings, 1 reply; 3+ messages in thread
From: Josh Wu @ 2014-07-22 9:25 UTC (permalink / raw)
To: linux-mtd; +Cc: Josh Wu, computersforpeace
When enable NFC sram write, it will failed the mtd_nandbiterrs.ko test.
As in driver's nfc_sram_write_page(), if ops->mode equal to MTD_OSP_RAW,
driver assumes the data buffer contains one page data and one oob data
followed. And driver will write the page data and oob data to nand.
But this is wrong implementation. Since the data buffer don't contains the
oob data to write. We should write the chip->oob_poi to nand's oob.
So this patch fix it by writing the oob data from chip->oob_poi.
Signed-off-by: Josh Wu <josh.wu@atmel.com>
---
drivers/mtd/nand/atmel_nand.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 33826a0..012d687 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -1913,15 +1913,13 @@ static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip,
if (offset || (data_len < mtd->writesize))
return -EINVAL;
- cfg = nfc_readl(host->nfc->hsmc_regs, CFG);
- len = mtd->writesize;
-
- if (unlikely(raw)) {
- len += mtd->oobsize;
- nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE);
- } else
- nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE);
+ if (data_len > mtd->writesize) {
+ dev_err(host->dev, "data_len: %d should not bigger than mtd->writesize: %d!\n",
+ data_len, mtd->writesize);
+ return -EINVAL;
+ }
+ len = mtd->writesize;
/* Copy page data to sram that will write to nand via NFC */
if (use_dma) {
if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) != 0)
@@ -1931,6 +1929,15 @@ static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip,
memcpy32_toio(sram, buf, len);
}
+ cfg = nfc_readl(host->nfc->hsmc_regs, CFG);
+ if (unlikely(raw) && oob_required) {
+ memcpy32_toio(sram + len, chip->oob_poi, mtd->oobsize);
+ len += mtd->oobsize;
+ nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE);
+ } else {
+ nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE);
+ }
+
if (chip->ecc.mode == NAND_ECC_HW && host->has_pmecc)
/*
* When use NFC sram, need set up PMECC before send
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: atmel_nand: NFC: fix mtd_nandbiterrs.ko test fail when using sram write
2014-07-22 9:25 [PATCH] mtd: atmel_nand: NFC: fix mtd_nandbiterrs.ko test fail when using sram write Josh Wu
@ 2014-08-04 21:22 ` Brian Norris
2014-08-05 10:41 ` Josh Wu
0 siblings, 1 reply; 3+ messages in thread
From: Brian Norris @ 2014-08-04 21:22 UTC (permalink / raw)
To: Josh Wu; +Cc: linux-mtd
On Tue, Jul 22, 2014 at 05:25:38PM +0800, Josh Wu wrote:
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index 33826a0..012d687 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -1913,15 +1913,13 @@ static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip,
> if (offset || (data_len < mtd->writesize))
> return -EINVAL;
>
> - cfg = nfc_readl(host->nfc->hsmc_regs, CFG);
> - len = mtd->writesize;
> -
> - if (unlikely(raw)) {
> - len += mtd->oobsize;
> - nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE);
> - } else
> - nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE);
> + if (data_len > mtd->writesize) {
> + dev_err(host->dev, "data_len: %d should not bigger than mtd->writesize: %d!\n",
"should not be"
> + data_len, mtd->writesize);
> + return -EINVAL;
> + }
The NAND layer guarantees that 'write_page' will never have to write
more than 1 page (mtd->writesize), so the above block seems unnecessary.
Drop it?
>
> + len = mtd->writesize;
> /* Copy page data to sram that will write to nand via NFC */
> if (use_dma) {
> if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) != 0)
> @@ -1931,6 +1929,15 @@ static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip,
> memcpy32_toio(sram, buf, len);
> }
>
> + cfg = nfc_readl(host->nfc->hsmc_regs, CFG);
> + if (unlikely(raw) && oob_required) {
> + memcpy32_toio(sram + len, chip->oob_poi, mtd->oobsize);
> + len += mtd->oobsize;
> + nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE);
> + } else {
> + nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE);
> + }
> +
> if (chip->ecc.mode == NAND_ECC_HW && host->has_pmecc)
> /*
> * When use NFC sram, need set up PMECC before send
Brian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: atmel_nand: NFC: fix mtd_nandbiterrs.ko test fail when using sram write
2014-08-04 21:22 ` Brian Norris
@ 2014-08-05 10:41 ` Josh Wu
0 siblings, 0 replies; 3+ messages in thread
From: Josh Wu @ 2014-08-05 10:41 UTC (permalink / raw)
To: Brian Norris; +Cc: linux-mtd
On 8/5/2014 5:22 AM, Brian Norris wrote:
> On Tue, Jul 22, 2014 at 05:25:38PM +0800, Josh Wu wrote:
>> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
>> index 33826a0..012d687 100644
>> --- a/drivers/mtd/nand/atmel_nand.c
>> +++ b/drivers/mtd/nand/atmel_nand.c
>> @@ -1913,15 +1913,13 @@ static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip,
>> if (offset || (data_len < mtd->writesize))
>> return -EINVAL;
>>
>> - cfg = nfc_readl(host->nfc->hsmc_regs, CFG);
>> - len = mtd->writesize;
>> -
>> - if (unlikely(raw)) {
>> - len += mtd->oobsize;
>> - nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE);
>> - } else
>> - nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE);
>> + if (data_len > mtd->writesize) {
>> + dev_err(host->dev, "data_len: %d should not bigger than mtd->writesize: %d!\n",
> "should not be"
>
>> + data_len, mtd->writesize);
>> + return -EINVAL;
>> + }
> The NAND layer guarantees that 'write_page' will never have to write
> more than 1 page (mtd->writesize), so the above block seems unnecessary.
> Drop it?
you are right. I sent a v2 version which drops this check. Thanks.
Best Regards,
Josh Wu
>
>>
>> + len = mtd->writesize;
>> /* Copy page data to sram that will write to nand via NFC */
>> if (use_dma) {
>> if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) != 0)
>> @@ -1931,6 +1929,15 @@ static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip,
>> memcpy32_toio(sram, buf, len);
>> }
>>
>> + cfg = nfc_readl(host->nfc->hsmc_regs, CFG);
>> + if (unlikely(raw) && oob_required) {
>> + memcpy32_toio(sram + len, chip->oob_poi, mtd->oobsize);
>> + len += mtd->oobsize;
>> + nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE);
>> + } else {
>> + nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE);
>> + }
>> +
>> if (chip->ecc.mode == NAND_ECC_HW && host->has_pmecc)
>> /*
>> * When use NFC sram, need set up PMECC before send
> Brian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-08-05 10:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-22 9:25 [PATCH] mtd: atmel_nand: NFC: fix mtd_nandbiterrs.ko test fail when using sram write Josh Wu
2014-08-04 21:22 ` Brian Norris
2014-08-05 10:41 ` Josh Wu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).