mtd: rawnand: Allow selection of ECC byte ordering at runtime
Subsystems (2)
PATCH 1/1 mtd: rawnand: Allow selection of ECC byte ordering at runtime
Currently, the selection of ECC byte ordering for software hamming is done at compilation time, which doesn't make sense when ECC byte calculation is done in hardware and byte ordering is forced by the hardware engine.
In this case, only the correction is done and software and we want to force the byte-ordering no matter the value of CONFIG_MTD_NAND_ECC_SMC.
This is typically the case for the FSMC (Smart Media ordering), TMIO and TXX9NDFMC (regular byte ordering) blocks.
For all other use cases (pure software implementation, SM FTL and nandecctest), we keep selecting the byte ordering based on the CONFIG_MTD_NAND_ECC_SMC value. It might not be ideal for SM FTL (I'd expect Smart Media ordering to be employed by the Smart Media FTL), but this option doesn't seem to be enabled in the existing _defconfig, so I can't tell setting sm_order to true is the right choice.
--- drivers/mtd/nand/raw/fsmc_nand.c | 1 + drivers/mtd/nand/raw/nand_base.c | 4 ++ drivers/mtd/nand/raw/nand_ecc.c | 93 ++++++++++++++++--------------------- drivers/mtd/nand/raw/tmio_nand.c | 5 +- drivers/mtd/nand/raw/txx9ndfmc.c | 3 +- drivers/mtd/sm_ftl.c | 20 +++++--- drivers/mtd/tests/mtd_nandecctest.c | 21 ++++++--- include/linux/mtd/nand_ecc.h | 4 +- include/linux/mtd/rawnand.h | 6 +++ 9 files changed, 86 insertions(+), 71 deletions(-)
drivers/mtd/nand/raw/fsmc_nand.c +1 -0
@@ -951,6 +951,7 @@ static int fsmc_nand_attach_chip(struct nand_chip *nand) nand->ecc.correct = nand_correct_data; nand->ecc.bytes =3 ; nand->ecc.strength =1 ; + nand->ecc.options |=NAND_ECC_SOFT_HAMMING_SM_ORDER ;break ;case NAND_ECC_SOFT :
drivers/mtd/nand/raw/nand_base.c +4 -0
@@ -6070,6 +6070,10 @@ static int nand_set_ecc_soft_ops(struct mtd_info *mtd) ecc->size =256 ; ecc->bytes =3 ; ecc->strength =1 ; + +if (IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC )) + ecc->options |=NAND_ECC_SOFT_HAMMING_SM_ORDER ; +return 0 ;case NAND_ECC_BCH :if (!mtd_nand_has_bch ()) {
drivers/mtd/nand/raw/nand_ecc.c +41 -52
136 lines not on this page · raw message
drivers/mtd/nand/raw/tmio_nand.c +3 -2
@@ -296,10 +296,11 @@ static int tmio_nand_correct_data(struct mtd_info *mtd, unsigned char *buf,int r0, r1;/* assume ecc.size = 512 and ecc.bytes = 6 */ - r0 =__nand_correct_data (buf, read_ecc, calc_ecc,256 ); + r0 =__nand_correct_data (buf, read_ecc, calc_ecc,256 , false);if (r0 <0 )return r0; - r1 =__nand_correct_data (buf +256 , read_ecc +3 , calc_ecc +3 ,256 ); + r1 =__nand_correct_data (buf +256 , read_ecc +3 , calc_ecc +3 ,256 , + false);if (r1 <0 )return r1;return r0 + r1;
drivers/mtd/nand/raw/txx9ndfmc.c +2 -1
@@ -200,7 +200,8 @@ static int txx9ndfmc_correct_data(struct mtd_info *mtd, unsigned char *buf,int stat;for (eccsize = chip->ecc.size; eccsize >0 ; eccsize -=256 ) { - stat =__nand_correct_data (buf, read_ecc, calc_ecc,256 ); + stat =__nand_correct_data (buf, read_ecc, calc_ecc,256 , + false);if (stat <0 )return stat; corrected += stat;
drivers/mtd/sm_ftl.c +13 -7
@@ -221,14 +221,18 @@ static int sm_correct_sector(uint8_t *buffer, struct sm_oob *oob) {uint8_t ecc[3 ]; -__nand_calculate_ecc (buffer,SM_SMALL_PAGE , ecc); -if (__nand_correct_data (buffer, ecc, oob->ecc1,SM_SMALL_PAGE ) <0 ) +__nand_calculate_ecc (buffer,SM_SMALL_PAGE , ecc, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC )); +if (__nand_correct_data (buffer, ecc, oob->ecc1,SM_SMALL_PAGE , +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC )) <0 )return -EIO ; buffer +=SM_SMALL_PAGE ; -__nand_calculate_ecc (buffer,SM_SMALL_PAGE , ecc); -if (__nand_correct_data (buffer, ecc, oob->ecc2,SM_SMALL_PAGE ) <0 ) +__nand_calculate_ecc (buffer,SM_SMALL_PAGE , ecc, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC )); +if (__nand_correct_data (buffer, ecc, oob->ecc2,SM_SMALL_PAGE , +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC )) <0 )return -EIO ;return 0 ; }
@@ -393,11 +397,13 @@ static int sm_write_block(struct sm_ftl *ftl, uint8_t *buf, }if (ftl->smallpagenand) { -__nand_calculate_ecc (buf + boffset, -SM_SMALL_PAGE , oob.ecc1); +__nand_calculate_ecc (buf + boffset,SM_SMALL_PAGE , + oob.ecc1, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC ));__nand_calculate_ecc (buf + boffset +SM_SMALL_PAGE , -SM_SMALL_PAGE , oob.ecc2); +SM_SMALL_PAGE , oob.ecc2, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC )); }if (!sm_write_sector (ftl, zone, block, boffset, buf + boffset, &oob))
drivers/mtd/tests/mtd_nandecctest.c +14 -7
@@ -121,8 +121,10 @@ static int no_bit_error_verify(void *error_data, void *error_ecc,unsigned char calc_ecc[3 ];int ret; -__nand_calculate_ecc (error_data, size, calc_ecc); - ret =__nand_correct_data (error_data, error_ecc, calc_ecc, size); +__nand_calculate_ecc (error_data, size, calc_ecc, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC )); + ret =__nand_correct_data (error_data, error_ecc, calc_ecc, size, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC ));if (ret ==0 && !memcmp (correct_data, error_data, size))return 0 ;
@@ -149,8 +151,10 @@ static int single_bit_error_correct(void *error_data, void *error_ecc,unsigned char calc_ecc[3 ];int ret; -__nand_calculate_ecc (error_data, size, calc_ecc); - ret =__nand_correct_data (error_data, error_ecc, calc_ecc, size); +__nand_calculate_ecc (error_data, size, calc_ecc, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC )); + ret =__nand_correct_data (error_data, error_ecc, calc_ecc, size, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC ));if (ret ==1 && !memcmp (correct_data, error_data, size))return 0 ;
@@ -184,8 +188,10 @@ static int double_bit_error_detect(void *error_data, void *error_ecc,unsigned char calc_ecc[3 ];int ret; -__nand_calculate_ecc (error_data, size, calc_ecc); - ret =__nand_correct_data (error_data, error_ecc, calc_ecc, size); +__nand_calculate_ecc (error_data, size, calc_ecc, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC )); + ret =__nand_correct_data (error_data, error_ecc, calc_ecc, size, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC ));return (ret == -EBADMSG ) ?0 : -EINVAL ; }
@@ -259,7 +265,8 @@ static int nand_ecc_test_run(const size_t size) }prandom_bytes (correct_data, size); -__nand_calculate_ecc (correct_data, size, correct_ecc); +__nand_calculate_ecc (correct_data, size, correct_ecc, +IS_ENABLED (CONFIG_MTD_NAND_ECC_SMC ));for (i =0 ; i <ARRAY_SIZE (nand_ecc_test); i++) { nand_ecc_test[i].prepare(error_data, error_ecc,
include/linux/mtd/nand_ecc.h +2 -2
@@ -19,7 +19,7 @@ struct mtd_info;* Calculate 3 byte ECC code for eccsize byte block */ void __nand_calculate_ecc (const u_char *dat,unsigned int eccsize, -u_char *ecc_code); +u_char *ecc_code,bool sm_order);/* * Calculate 3 byte ECC code for 256/512 byte block
@@ -30,7 +30,7 @@ int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code* Detect and correct a 1 bit error for eccsize byte block */ int __nand_correct_data (u_char *dat,u_char *read_ecc,u_char *calc_ecc, -unsigned int eccsize); +unsigned int eccsize,bool sm_order);/* * Detect and correct a 1 bit error for 256/512 byte block
include/linux/mtd/rawnand.h +6 -0
@@ -131,6 +131,12 @@ enum nand_ecc_algo {#define NAND_ECC_GENERIC_ERASED_CHECK BIT(0)#define NAND_ECC_MAXIMIZE BIT(1) +/* +* When using software implementation of Hamming, we can specify which byte +* ordering should be used. +*/ +#define NAND_ECC_SOFT_HAMMING_SM_ORDER BIT(2) +/* Bit mask for flags passed to do_nand_read_ecc */ #define NAND_GET_DEVICE 0x80
Signature · 1 line
2.14.1
Hi Boris,
Boris Brezillon <[email protected]> wrote on Tue, 4 Sep 2018 16:23:28 +0200:
Quoted 5 lines
Currently, the selection of ECC byte ordering for software hamming is done at compilation time, which doesn't make sense when ECC byte calculation is done in hardware and byte ordering is forced by the hardware engine.
In this case, only the correction is done and software and we want to
^ in
Quoted 12 lines
force the byte-ordering no matter the value of
CONFIG_MTD_NAND_ECC_SMC.This is typically the case for the FSMC (Smart Media ordering), TMIO and TXX9NDFMC (regular byte ordering) blocks.
For all other use cases (pure software implementation, SM FTL and nandecctest), we keep selecting the byte ordering based on the
CONFIG_MTD_NAND_ECC_SMCvalue. It might not be ideal for SM FTL (I'd expect Smart Media ordering to be employed by the Smart Media FTL), but this option doesn't seem to be enabled in the existing_defconfig, so I can't tell settingsm_orderto true is the right choice.
Quoted 2 lines
Signed-off-by Boris Brezillon <[email protected]>---
Applied to nand/next with the above typo corrected.
Thanks,
Miquèl