Skip to content

Commit fdbad98

Browse files
JoshWuDavid Woodhouse
authored andcommitted
mtd: nand: teach write_page and write_page_raw return an error code
There is an implemention of hardware ECC write page function which may return an error indication. For instance, using Atmel HW PMECC to write one page into a nand flash, the hardware engine will compute the BCH ecc code for this page. so we need read a the status register to theck whether the ecc code is generated. But we cannot assume the status register always can be ready, for example, incorrect hardware configuration or hardware issue, in such case we need write_page() to return a error code. Since the definition of 'write_page' function in struct nand_ecc_ctrl is 'void'. So this patch will: 1. add return 'int' value for 'write_page' function. 2. to be consitent, add return 'int' value for 'write_page_raw' fuctions too. 3. add code to test the return value, and if negative, indicate an error happend when write page with ECC. 4. fix the compile warning in all impacted nand flash driver. Note: I couldn't compile-test all of these easily, as some had ARCH dependencies. Signed-off-by: Josh Wu <josh.wu@atmel.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 3dfe41a commit fdbad98

12 files changed

Lines changed: 64 additions & 31 deletions

File tree

‎drivers/mtd/nand/bcm_umi_bch.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/* ---- Private Function Prototypes -------------------------------------- */
2424
static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd,
2525
struct nand_chip *chip, uint8_t *buf, int oob_required, int page);
26-
static void bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd,
26+
static int bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd,
2727
struct nand_chip *chip, const uint8_t *buf, int oob_required);
2828

2929
/* ---- Private Variables ------------------------------------------------ */
@@ -194,7 +194,7 @@ static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd,
194194
* @oob_required: must write chip->oob_poi to OOB
195195
*
196196
***************************************************************************/
197-
static void bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd,
197+
static int bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd,
198198
struct nand_chip *chip, const uint8_t *buf, int oob_required)
199199
{
200200
int sectorIdx = 0;
@@ -214,4 +214,6 @@ static void bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd,
214214
}
215215

216216
bcm_umi_nand_write_buf(mtd, chip->oob_poi, mtd->oobsize);
217+
218+
return 0;
217219
}

‎drivers/mtd/nand/bf5xx_nand.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,13 @@ static int bf5xx_nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip
566566
return 0;
567567
}
568568

569-
static void bf5xx_nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
570-
const uint8_t *buf, int oob_required)
569+
static int bf5xx_nand_write_page_raw(struct mtd_info *mtd,
570+
struct nand_chip *chip, const uint8_t *buf, int oob_required)
571571
{
572572
bf5xx_nand_write_buf(mtd, buf, mtd->writesize);
573573
bf5xx_nand_write_buf(mtd, chip->oob_poi, mtd->oobsize);
574+
575+
return 0;
574576
}
575577

576578
/*

‎drivers/mtd/nand/cafe_nand.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static struct nand_bbt_descr cafe_bbt_mirror_descr_512 = {
520520
};
521521

522522

523-
static void cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
523+
static int cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
524524
struct nand_chip *chip,
525525
const uint8_t *buf, int oob_required)
526526
{
@@ -531,6 +531,8 @@ static void cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
531531

532532
/* Set up ECC autogeneration */
533533
cafe->ctl2 |= (1<<30);
534+
535+
return 0;
534536
}
535537

536538
static int cafe_nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
@@ -542,9 +544,12 @@ static int cafe_nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
542544
chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
543545

544546
if (unlikely(raw))
545-
chip->ecc.write_page_raw(mtd, chip, buf, oob_required);
547+
status = chip->ecc.write_page_raw(mtd, chip, buf, oob_required);
546548
else
547-
chip->ecc.write_page(mtd, chip, buf, oob_required);
549+
status = chip->ecc.write_page(mtd, chip, buf, oob_required);
550+
551+
if (status < 0)
552+
return status;
548553

549554
/*
550555
* Cached progamming disabled for now, Not sure if its worth the

‎drivers/mtd/nand/denali.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static void denali_setup_dma(struct denali_nand_info *denali, int op)
10281028

10291029
/* writes a page. user specifies type, and this function handles the
10301030
* configuration details. */
1031-
static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
1031+
static int write_page(struct mtd_info *mtd, struct nand_chip *chip,
10321032
const uint8_t *buf, bool raw_xfer)
10331033
{
10341034
struct denali_nand_info *denali = mtd_to_denali(mtd);
@@ -1078,6 +1078,8 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
10781078

10791079
denali_enable_dma(denali, false);
10801080
dma_sync_single_for_cpu(denali->dev, addr, size, DMA_TO_DEVICE);
1081+
1082+
return 0;
10811083
}
10821084

10831085
/* NAND core entry points */
@@ -1086,24 +1088,24 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
10861088
* writing a page with ECC or without is similar, all the work is done
10871089
* by write_page above.
10881090
* */
1089-
static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip,
1091+
static int denali_write_page(struct mtd_info *mtd, struct nand_chip *chip,
10901092
const uint8_t *buf, int oob_required)
10911093
{
10921094
/* for regular page writes, we let HW handle all the ECC
10931095
* data written to the device. */
1094-
write_page(mtd, chip, buf, false);
1096+
return write_page(mtd, chip, buf, false);
10951097
}
10961098

10971099
/* This is the callback that the NAND core calls to write a page without ECC.
10981100
* raw access is similar to ECC page writes, so all the work is done in the
10991101
* write_page() function above.
11001102
*/
1101-
static void denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1103+
static int denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
11021104
const uint8_t *buf, int oob_required)
11031105
{
11041106
/* for raw page writes, we want to disable ECC and simply write
11051107
whatever data is in the buffer. */
1106-
write_page(mtd, chip, buf, true);
1108+
return write_page(mtd, chip, buf, true);
11071109
}
11081110

11091111
static int denali_write_oob(struct mtd_info *mtd, struct nand_chip *chip,

‎drivers/mtd/nand/docg4.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ static void docg4_erase_block(struct mtd_info *mtd, int page)
898898
write_nop(docptr);
899899
}
900900

901-
static void write_page(struct mtd_info *mtd, struct nand_chip *nand,
901+
static int write_page(struct mtd_info *mtd, struct nand_chip *nand,
902902
const uint8_t *buf, bool use_ecc)
903903
{
904904
struct docg4_priv *doc = nand->priv;
@@ -950,15 +950,17 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *nand,
950950
write_nop(docptr);
951951
writew(0, docptr + DOC_DATAEND);
952952
write_nop(docptr);
953+
954+
return 0;
953955
}
954956

955-
static void docg4_write_page_raw(struct mtd_info *mtd, struct nand_chip *nand,
957+
static int docg4_write_page_raw(struct mtd_info *mtd, struct nand_chip *nand,
956958
const uint8_t *buf, int oob_required)
957959
{
958960
return write_page(mtd, nand, buf, false);
959961
}
960962

961-
static void docg4_write_page(struct mtd_info *mtd, struct nand_chip *nand,
963+
static int docg4_write_page(struct mtd_info *mtd, struct nand_chip *nand,
962964
const uint8_t *buf, int oob_required)
963965
{
964966
return write_page(mtd, nand, buf, true);

‎drivers/mtd/nand/fsl_elbc_nand.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,13 @@ static int fsl_elbc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
766766
/* ECC will be calculated automatically, and errors will be detected in
767767
* waitfunc.
768768
*/
769-
static void fsl_elbc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
769+
static int fsl_elbc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
770770
const uint8_t *buf, int oob_required)
771771
{
772772
fsl_elbc_write_buf(mtd, buf, mtd->writesize);
773773
fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
774+
775+
return 0;
774776
}
775777

776778
static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)

‎drivers/mtd/nand/fsl_ifc_nand.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,13 @@ static int fsl_ifc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
721721
/* ECC will be calculated automatically, and errors will be detected in
722722
* waitfunc.
723723
*/
724-
static void fsl_ifc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
724+
static int fsl_ifc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
725725
const uint8_t *buf, int oob_required)
726726
{
727727
fsl_ifc_write_buf(mtd, buf, mtd->writesize);
728728
fsl_ifc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
729+
730+
return 0;
729731
}
730732

731733
static int fsl_ifc_chip_init_tail(struct mtd_info *mtd)

‎drivers/mtd/nand/gpmi-nand/gpmi-nand.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
930930
return ret;
931931
}
932932

933-
static void gpmi_ecc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
933+
static int gpmi_ecc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
934934
const uint8_t *buf, int oob_required)
935935
{
936936
struct gpmi_nand_data *this = chip->priv;
@@ -972,7 +972,7 @@ static void gpmi_ecc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
972972
&payload_virt, &payload_phys);
973973
if (ret) {
974974
pr_err("Inadequate payload DMA buffer\n");
975-
return;
975+
return 0;
976976
}
977977

978978
ret = send_page_prepare(this,
@@ -1002,6 +1002,8 @@ static void gpmi_ecc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
10021002
nfc_geo->payload_size,
10031003
payload_virt, payload_phys);
10041004
}
1005+
1006+
return 0;
10051007
}
10061008

10071009
/*

‎drivers/mtd/nand/nand_base.c‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,12 +1911,14 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
19111911
*
19121912
* Not for syndrome calculating ECC controllers, which use a special oob layout.
19131913
*/
1914-
static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1914+
static int nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
19151915
const uint8_t *buf, int oob_required)
19161916
{
19171917
chip->write_buf(mtd, buf, mtd->writesize);
19181918
if (oob_required)
19191919
chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
1920+
1921+
return 0;
19201922
}
19211923

19221924
/**
@@ -1928,7 +1930,7 @@ static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
19281930
*
19291931
* We need a special oob layout and handling even when ECC isn't checked.
19301932
*/
1931-
static void nand_write_page_raw_syndrome(struct mtd_info *mtd,
1933+
static int nand_write_page_raw_syndrome(struct mtd_info *mtd,
19321934
struct nand_chip *chip,
19331935
const uint8_t *buf, int oob_required)
19341936
{
@@ -1958,6 +1960,8 @@ static void nand_write_page_raw_syndrome(struct mtd_info *mtd,
19581960
size = mtd->oobsize - (oob - chip->oob_poi);
19591961
if (size)
19601962
chip->write_buf(mtd, oob, size);
1963+
1964+
return 0;
19611965
}
19621966
/**
19631967
* nand_write_page_swecc - [REPLACEABLE] software ECC based page write function
@@ -1966,7 +1970,7 @@ static void nand_write_page_raw_syndrome(struct mtd_info *mtd,
19661970
* @buf: data buffer
19671971
* @oob_required: must write chip->oob_poi to OOB
19681972
*/
1969-
static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1973+
static int nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
19701974
const uint8_t *buf, int oob_required)
19711975
{
19721976
int i, eccsize = chip->ecc.size;
@@ -1983,7 +1987,7 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
19831987
for (i = 0; i < chip->ecc.total; i++)
19841988
chip->oob_poi[eccpos[i]] = ecc_calc[i];
19851989

1986-
chip->ecc.write_page_raw(mtd, chip, buf, 1);
1990+
return chip->ecc.write_page_raw(mtd, chip, buf, 1);
19871991
}
19881992

19891993
/**
@@ -1993,7 +1997,7 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
19931997
* @buf: data buffer
19941998
* @oob_required: must write chip->oob_poi to OOB
19951999
*/
1996-
static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
2000+
static int nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
19972001
const uint8_t *buf, int oob_required)
19982002
{
19992003
int i, eccsize = chip->ecc.size;
@@ -2013,6 +2017,8 @@ static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
20132017
chip->oob_poi[eccpos[i]] = ecc_calc[i];
20142018

20152019
chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
2020+
2021+
return 0;
20162022
}
20172023

20182024
/**
@@ -2025,7 +2031,7 @@ static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
20252031
* The hw generator calculates the error syndrome automatically. Therefore we
20262032
* need a special oob layout and handling.
20272033
*/
2028-
static void nand_write_page_syndrome(struct mtd_info *mtd,
2034+
static int nand_write_page_syndrome(struct mtd_info *mtd,
20292035
struct nand_chip *chip,
20302036
const uint8_t *buf, int oob_required)
20312037
{
@@ -2059,6 +2065,8 @@ static void nand_write_page_syndrome(struct mtd_info *mtd,
20592065
i = mtd->oobsize - (oob - chip->oob_poi);
20602066
if (i)
20612067
chip->write_buf(mtd, oob, i);
2068+
2069+
return 0;
20622070
}
20632071

20642072
/**
@@ -2080,9 +2088,12 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
20802088
chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
20812089

20822090
if (unlikely(raw))
2083-
chip->ecc.write_page_raw(mtd, chip, buf, oob_required);
2091+
status = chip->ecc.write_page_raw(mtd, chip, buf, oob_required);
20842092
else
2085-
chip->ecc.write_page(mtd, chip, buf, oob_required);
2093+
status = chip->ecc.write_page(mtd, chip, buf, oob_required);
2094+
2095+
if (status < 0)
2096+
return status;
20862097

20872098
/*
20882099
* Cached progamming disabled for now. Not sure if it's worth the

‎drivers/mtd/nand/pxa3xx_nand.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,13 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
681681
info->state = STATE_IDLE;
682682
}
683683

684-
static void pxa3xx_nand_write_page_hwecc(struct mtd_info *mtd,
684+
static int pxa3xx_nand_write_page_hwecc(struct mtd_info *mtd,
685685
struct nand_chip *chip, const uint8_t *buf, int oob_required)
686686
{
687687
chip->write_buf(mtd, buf, mtd->writesize);
688688
chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
689+
690+
return 0;
689691
}
690692

691693
static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,

0 commit comments

Comments
 (0)