lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20180719100647.6c2d5851@bbrezillon>
Date:   Thu, 19 Jul 2018 10:06:47 +0200
From:   Boris Brezillon <boris.brezillon@...tlin.com>
To:     KOBAYASHI Yoshitake <yoshitake.kobayashi@...hiba.co.jp>
Cc:     miquel.raynal@...tlin.com, richard@....at, dwmw2@...radead.org,
        computersforpeace@...il.com, marek.vasut@...il.com,
        linux-mtd@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5] mtd: nand: toshiba: Add support for Toshiba Memory
 BENAND (Built-in ECC NAND)

On Thu, 19 Jul 2018 16:53:33 +0900
KOBAYASHI Yoshitake <yoshitake.kobayashi@...hiba.co.jp> wrote:

> From: yoshitake.kobayashi@...hiba.co.jp
> 
> This patch is a patch to support TOSHIBA MEMORY CORPORATION BENAND
> memory devices.  Check the status of the built-in ECC with the Read
> Status command without using the vendor specific command.  The Read
> Status command only knows whether there was bitflips above the
> threshold and can not get accurate bitflips.  For now, I set
> max_bitflips mtd->bitflip_threshold.
> 
> Signed-off-by: KOBAYASHI Yoshitake <yoshitake.kobayashi@...hiba.co.jp>
> ---
>  drivers/mtd/nand/raw/nand_toshiba.c | 84 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 84 insertions(+)
> 
> diff --git a/drivers/mtd/nand/raw/nand_toshiba.c b/drivers/mtd/nand/raw/nand_toshiba.c
> index ab43f02..6cec923 100644
> --- a/drivers/mtd/nand/raw/nand_toshiba.c
> +++ b/drivers/mtd/nand/raw/nand_toshiba.c
> @@ -17,6 +17,86 @@
>  
>  #include <linux/mtd/rawnand.h>
>  
> +/* Recommended to rewrite for BENAND */
> +#define TOSHIBA_NAND_STATUS_REWRITE_RECOMMENDED	BIT(3)
> +
> +static int toshiba_nand_benand_eccstatus(struct mtd_info *mtd,
> +					 struct nand_chip *chip)
> +{
> +	int ret;
> +	unsigned int max_bitflips = 0;
> +	u8 status;
> +
> +	/* Check Status */
> +	ret = nand_status_op(chip, &status);
> +	if (ret)
> +		return ret;
> +
> +	if (status & NAND_STATUS_FAIL) {
> +		/* uncorrected */
> +		mtd->ecc_stats.failed++;
> +	} else if (status & TOSHIBA_NAND_STATUS_REWRITE_RECOMMENDED) {
> +		/* corrected */
> +		max_bitflips = mtd->bitflip_threshold;
> +		mtd->ecc_stats.corrected += max_bitflips;
> +	}
> +
> +	return max_bitflips;
> +}
> +
> +static int
> +toshiba_nand_read_page_benand(struct mtd_info *mtd,
> +			      struct nand_chip *chip, uint8_t *buf,
> +			      int oob_required, int page)
> +{
> +	int ret;
> +
> +	ret = nand_read_page_raw(mtd, chip, buf, oob_required, page);
> +	if (ret)
> +		return ret;
> +
> +	return toshiba_nand_benand_eccstatus(mtd, chip);
> +}
> +
> +static int
> +toshiba_nand_read_subpage_benand(struct mtd_info *mtd,
> +				 struct nand_chip *chip, uint32_t data_offs,
> +				 uint32_t readlen, uint8_t *bufpoi, int page)
> +{
> +	int ret;
> +
> +	ret = nand_read_page_op(chip, page, data_offs,
> +				bufpoi + data_offs, readlen);
> +	if (ret)
> +		return ret;
> +
> +	return toshiba_nand_benand_eccstatus(mtd, chip);
> +}
> +
> +static void toshiba_nand_benand_init(struct nand_chip *chip)
> +{
> +	struct mtd_info *mtd = nand_to_mtd(chip);
> +
> +	/*
> +	 * On BENAND, the entire OOB region can be used by the MTD user.
> +	 * The calculated ECC bytes are stored into other isolated
> +	 * area which is not accessible to users.
> +	 * This is why chip->ecc.bytes = 0.
> +	 */
> +	chip->ecc.bytes = 0;
> +	chip->ecc.size = 512;
> +	chip->ecc.strength = 8;
> +	chip->ecc.read_page = toshiba_nand_read_page_benand;
> +	chip->ecc.read_subpage = toshiba_nand_read_subpage_benand;
> +	chip->ecc.write_page = nand_write_page_raw;
> +	chip->ecc.read_page_raw = nand_read_page_raw;
> +	chip->ecc.write_page_raw = nand_write_page_raw;

Well, in this case raw accesses are not supported since you can't
disabled ECC. I just introduced nand_{read,write}_page_raw_notsupp(),
so you should probably use them.

> +
> +	chip->options |= NAND_SUBPAGE_READ;
> +
> +	mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
> +}
> +
>  static void toshiba_nand_decode_id(struct nand_chip *chip)
>  {
>  	struct mtd_info *mtd = nand_to_mtd(chip);
> @@ -68,6 +148,10 @@ static int toshiba_nand_init(struct nand_chip *chip)
>  	if (nand_is_slc(chip))
>  		chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
>  
> +	if (nand_is_slc(chip) && (chip->id.data[4] & 0x80) /* BENAND */ &&

Please put the /* BENAND */ comment above the if () block.
Maybe you should have a macro for the 0x80 value

#define TOSHIBA_NAND_ID4_IS_BENAND		BIT(7)

and then test

	chip->id.data[4] & TOSHIBA_NAND_ID4_IS_BENAND

> +	    (chip->ecc.mode == NAND_ECC_ON_DIE))

Unneeded parens around chip->ecc.mode == NAND_ECC_ON_DIE and
chip->id.data[4] & 0x80 tests.

> +		toshiba_nand_benand_init(chip);
> +
>  	return 0;
>  }
>  

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ