Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1235686imm; Fri, 3 Aug 2018 22:28:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfk/UKzT+/g3Xx9Kx72bHeDOVHEbo2RVEMVCi0qMbL0BhLDdoRBGleyfLoUMnONUmk2DYUD X-Received: by 2002:a62:e218:: with SMTP id a24-v6mr7709843pfi.75.1533360509821; Fri, 03 Aug 2018 22:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533360509; cv=none; d=google.com; s=arc-20160816; b=yH/8o4AFO1KVuvR/PDrSdjTlTcIh9BDjqVkiddL29bdRo0reCIWEUtN9q7EgUP3ckV 6oMnJXc4ZN0mERcHofwPxtr3XetyStvjSa1xK/xzK5TJjfhnYh67/rvC/Yf1TfGTPnJm S4vrUTRREe0ojT3OnfcG1WsefIiCWWLeNEz9cY0MH+T3lP+7gOwgsSw5xPwqhuQuJl1W b9HTnq+jL7ZKDly0tv8scqwBcBjb+90lQZal9d5ip3PA1Y3BKC74kDUvHOSqos3ZVHD0 NDOv1RKnHZ7JcuANTR5Yc2NJmMb312YHixsH4zaE3tfUu4GYcoSd1OnaTdpeOaNP/Bq8 U25Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=5DlrzBpvU4kZjp0IUIEAb+42cMr+QN4nLrXTK+9kXM4=; b=PvtVUBHpxpubLFHmcJEYiRV6fQ5FQDWiuOT6jNmh1c0CZ4ruWkiOPXWeIuLzv95Cx4 LbicFIrTG3qpyc9vxbYfmOR3KmFte6I4nQyI94Ky7xvEUJPAxpTkcIUJY1yrHgdkgeOi AVA4KrogWZnTqT/dz+7pTvEtT0vpXYOWJDi2I/s4saZRSk8Q/HrmJNkfvAnXSSbRSigD vg9bDzq6TXGxIPOjkM+AC2UO7P5RgfPhI7n/rneXb48er6ic0zhC3Wws/jg5N4Q3miaT 2kvPrYblFMtdVEOX+e2vQTcGg89eqr+6cu61VEndW9EpQ1rX2q63fTziWc2RDeemo1a1 ChIA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=toshiba.co.jp Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1-v6si4912547plt.264.2018.08.03.22.28.12; Fri, 03 Aug 2018 22:28:29 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=toshiba.co.jp Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727038AbeHDH0o (ORCPT + 99 others); Sat, 4 Aug 2018 03:26:44 -0400 Received: from mo-csw1115.securemx.jp ([210.130.202.157]:55764 "EHLO mo-csw.securemx.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbeHDH0n (ORCPT ); Sat, 4 Aug 2018 03:26:43 -0400 Received: by mo-csw.securemx.jp (mx-mo-csw1115) id w745QN67007035; Sat, 4 Aug 2018 14:26:23 +0900 X-Iguazu-Qid: 2wGqjZUhdEFGnqXwtk X-Iguazu-QSIG: v=1; s=0; t=1533360382; q=2wGqjZUhdEFGnqXwtk; m=efBU3koXaYlJ2dy8mid6XF+0OEJ8Iq4Kbvu3IMFJTfs= Received: from imx2.toshiba.co.jp (imx2.toshiba.co.jp [106.186.93.51]) by relay.securemx.jp (mx-mr1112) id w745QJ5g037574; Sat, 4 Aug 2018 14:26:19 +0900 Received: from hop001.toshiba.co.jp ([133.199.164.63]) by imx2.toshiba.co.jp with ESMTP id w745QJ1Z010620; Sat, 4 Aug 2018 14:26:19 +0900 (JST) From: KOBAYASHI Yoshitake To: boris.brezillon@bootlin.com, miquel.raynal@bootlin.com, richard@nod.at, dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, KOBAYASHI Yoshitake Subject: [PATCH v6] mtd: nand: toshiba: Add support for Toshiba Memory BENAND (Built-in ECC NAND) Date: Sat, 4 Aug 2018 14:25:52 +0900 X-TSB-HOP: ON Message-Id: <1533360352-2882-1-git-send-email-yoshitake.kobayashi@toshiba.co.jp> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_toshiba.c b/drivers/mtd/nand/raw/nand_toshiba.c index ab43f02..8aec3fa 100644 --- a/drivers/mtd/nand/raw/nand_toshiba.c +++ b/drivers/mtd/nand/raw/nand_toshiba.c @@ -17,6 +17,89 @@ #include +/* Bit for detecting BENAND */ +#define TOSHIBA_NAND_ID4_IS_BENAND BIT(7) + +/* 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_notsupp; + chip->ecc.write_page_raw = nand_write_page_raw_notsupp; + + 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 +151,11 @@ static int toshiba_nand_init(struct nand_chip *chip) if (nand_is_slc(chip)) chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + /* Check that chip is BENAND and ECC mode is on-die */ + if (nand_is_slc(chip) && chip->ecc.mode == NAND_ECC_ON_DIE && + chip->id.data[4] & TOSHIBA_NAND_ID4_IS_BENAND) + toshiba_nand_benand_init(chip); + return 0; } -- 2.7.4