Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1423825imm; Thu, 19 Jul 2018 01:07:55 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeQYR6ijzlab/Q/N+uEQ9yoRThyT3dDUUGuD2+cU9icJe6wegQ6Fr7b4Z4MWP51vnMSvVH1 X-Received: by 2002:a65:6104:: with SMTP id z4-v6mr8978057pgu.361.1531987675947; Thu, 19 Jul 2018 01:07:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531987675; cv=none; d=google.com; s=arc-20160816; b=Wx6coZzwoFrSlFj8U6hklT+rPv2L5nEt+byf71clofnT6qj3EyKkg/AQ0MIdVq0qf2 9iTZJ1NeafmW7n6EZ+H1iZv5dTUUzxjV02Fg45/8HYZ2jD7TwHOCBT8R3pfDEIndjCwx zbgdxpq6ze1RXsDZb/mrhckXEGRspNPVRaOBi5G7Yr04CqP4kcm5zyDKiwVXuP/+oEbu AUbKKfXaWCChct9j0K4to/85M4xrn1ycwBPD7oZzhJ5T26UGvCMANj2cwKTpf0po1lK8 xsz6bpzHq/mjXzbB7h7FJ/x7HwO+3gfTy2NPzPrDTUzUEo+VCQfQzL/r29TyvpHr4jYZ +bKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=qXq2XRLqVjjrNvLSzEWMriWDYadTQCDbD8KKW2z5CMM=; b=cKgJaHnPopxaGOQeLm8RjyjUyiUgLjSUCl2OlKpAVSj4P40KARWtXQkJdqoX6pBwY8 7ODXMmoB6dx/3OWNoqslh8+ohOh8qoRvUmhfBBvZn5QSBK2LQkyrXu31DfqPyaboaiG4 Oimpdbg4Z0F3cI/YhJ+MbC8PkBlrPt3FsA7BpmHi+mDNyhVu9AQ6USpmDfb6/TEosmnE SHsVvCKE/1KvcSf2p0YwOxToKbO6Z9D5jA26FuhCBHC5JgqMjwYohYsb+0lEnQjFGSoV rtWTlcdA9p9AgrXLkkuTdbj/7lsiHzoNTF3fXaqBW3ynG2QfPnl8VzxmJHdYEGosSYJH 3H3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9-v6si5229518plk.130.2018.07.19.01.07.41; Thu, 19 Jul 2018 01:07:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730821AbeGSIsp (ORCPT + 99 others); Thu, 19 Jul 2018 04:48:45 -0400 Received: from mail.bootlin.com ([62.4.15.54]:54035 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727528AbeGSIso (ORCPT ); Thu, 19 Jul 2018 04:48:44 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id B8F87207AD; Thu, 19 Jul 2018 10:06:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (AAubervilliers-681-1-27-161.w90-88.abo.wanadoo.fr [90.88.147.161]) by mail.bootlin.com (Postfix) with ESMTPSA id 736AA206EE; Thu, 19 Jul 2018 10:06:47 +0200 (CEST) Date: Thu, 19 Jul 2018 10:06:47 +0200 From: Boris Brezillon To: KOBAYASHI Yoshitake Cc: miquel.raynal@bootlin.com, richard@nod.at, dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5] mtd: nand: toshiba: Add support for Toshiba Memory BENAND (Built-in ECC NAND) Message-ID: <20180719100647.6c2d5851@bbrezillon> In-Reply-To: <1531986813-18701-1-git-send-email-yoshitake.kobayashi@toshiba.co.jp> References: <1531986813-18701-1-git-send-email-yoshitake.kobayashi@toshiba.co.jp> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 19 Jul 2018 16:53:33 +0900 KOBAYASHI Yoshitake wrote: > From: yoshitake.kobayashi@toshiba.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 > --- > 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 > > +/* 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; > } >