Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1237526imm; Fri, 3 Aug 2018 22:31:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfLl/9IlgRAmxI+p3C8uHK/hg8wAeMmTBpDFxBq2B/M2v1hZfXBN9nFYrUeCD6EzlkW8msh X-Received: by 2002:a62:c218:: with SMTP id l24-v6mr7656287pfg.185.1533360679170; Fri, 03 Aug 2018 22:31:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533360679; cv=none; d=google.com; s=arc-20160816; b=n0EmHtwD7yoUhyxbAEVxeQk+/eW/bCMvu8TBoDFBrw7bSiOnElG/cl8tm6t0ITnGzS FWJ/QMCFKQQEWlAgmkwcGgfVfJ8wJ0wU29YQ6/Nyv0UYjeWEifNsvXhz5f7SfYEnBD6L VjQp1MbxZRivCHJ4dlMkmMmS8uZZOFTxgruYthhjCPJa+sBMGkBRNoVNP2MPYzGtRTem i0s2RbBl0GxJ3pj4lLuob7qsig4LWF9CbinsNIVYWXIUZsT+iF1a28GXk9IUgfzUn3is qFiSUaHwhD/SpqmCLFmm/VOrydaV193pKIkGmNfU1XkQEM/bq96wrWQjvk9+cs2tP5M3 lxOw== 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=Gh2VTEPSrWxNeInASYU4SHbTWvTCvMVi4YEErpWjwkU=; b=ev5AwbWuET9wmBmTnSctwGbITeW7OAiqa38YgMXI6CEJf4fhZSqDLWBK4ymbeMa4zT P2E3BakLW5GNSMFltsN9z6YkMwG7/KmVe1AzLoUXFrSb4+DWTOPT3bEbtVDxZggs1YXm ylg+7ARJ6Rm+J4ODbTJLCduRn5TqJyyZeFip3NITcd8XQDM+7UxHbL8AH7kdOVF1SQub yzAiZCOXy929nlNMuZhKXeguhGk+IRBijkWgQraTeyV56nlt+MXDz3VVggKOv5jbfuz5 gn+GxKD3W2HOSEYuAoBzM1BjTsjBVDYGfMQ+dGP+0V8Jmax51RClGvIUana0s40EtU0v 6n9Q== 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 e9-v6si6585409pgj.70.2018.08.03.22.31.04; Fri, 03 Aug 2018 22:31:19 -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 S1727038AbeHDH3k (ORCPT + 99 others); Sat, 4 Aug 2018 03:29:40 -0400 Received: from mo-csw1116.securemx.jp ([210.130.202.158]:41226 "EHLO mo-csw.securemx.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726055AbeHDH3k (ORCPT ); Sat, 4 Aug 2018 03:29:40 -0400 Received: by mo-csw.securemx.jp (mx-mo-csw1116) id w745TWLR000773; Sat, 4 Aug 2018 14:29:32 +0900 X-Iguazu-Qid: 2wGrT2hbsoZemxf7rc X-Iguazu-QSIG: v=1; s=0; t=1533360572; q=2wGrT2hbsoZemxf7rc; m=fWLoZMBK0fYugtY533PjSu4xCFSoTTJpttmiC/x+MmE= Received: from imx12.toshiba.co.jp (imx12.toshiba.co.jp [61.202.160.132]) by relay.securemx.jp (mx-mr1113) id w745TUHB032990; Sat, 4 Aug 2018 14:29:31 +0900 Received: from hop101.toshiba.co.jp ([133.199.85.107]) by imx12.toshiba.co.jp with ESMTP id w745TUhE007278; Sat, 4 Aug 2018 14:29:30 +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: [RFC PATCH v2] mtd: nand: toshiba: Add support for ->exec_op() Date: Sat, 4 Aug 2018 14:26:18 +0900 X-TSB-HOP: ON Message-Id: <1533360378-2925-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. This use vendor specific command (TOSHIBA_NAND_CMD_ECC_STATUS) to know the exact bitflips. However, I could not test this patch because I do not have a platform that supports chip-> exec_op. Therefore, I post this patch as RFC. As soon as I get a platform that supports chip-> exec_op, I would like to test and re-post. Signed-off-by: KOBAYASHI Yoshitake --- drivers/mtd/nand/raw/nand_toshiba.c | 53 ++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/nand_toshiba.c b/drivers/mtd/nand/raw/nand_toshiba.c index 8aec3fa..3f4683b 100644 --- a/drivers/mtd/nand/raw/nand_toshiba.c +++ b/drivers/mtd/nand/raw/nand_toshiba.c @@ -23,14 +23,65 @@ /* Recommended to rewrite for BENAND */ #define TOSHIBA_NAND_STATUS_REWRITE_RECOMMENDED BIT(3) +/* ECC Status Read Command for BENAND */ +#define TOSHIBA_NAND_CMD_ECC_STATUS_READ 0x7A + +/* ECC Status Mask for BENAND */ +#define TOSHIBA_NAND_ECC_STATUS_MASK 0x0F + +/* Uncorrectable Error for BENAND */ +#define TOSHIBA_NAND_ECC_STATUS_UNCORR 0x0F + +static int toshiba_nand_benand_read_eccstatus_op(struct nand_chip *chip, + u8 *buf) +{ + u8 *ecc_status = buf; + + if (chip->exec_op) { + const struct nand_sdr_timings *sdr = + nand_get_sdr_timings(&chip->data_interface); + struct nand_op_instr instrs[] = { + NAND_OP_CMD(TOSHIBA_NAND_CMD_ECC_STATUS_READ, + PSEC_TO_NSEC(sdr->tADL_min)), + NAND_OP_8BIT_DATA_IN(chip->ecc.steps, ecc_status, 0), + }; + struct nand_operation op = NAND_OPERATION(instrs); + + return nand_exec_op(chip, &op); + } + + return -ENOTSUPP; +} + static int toshiba_nand_benand_eccstatus(struct mtd_info *mtd, struct nand_chip *chip) { int ret; unsigned int max_bitflips = 0; - u8 status; + u8 status, ecc_status[8]; /* Check Status */ + ret = toshiba_nand_benand_read_eccstatus_op(chip, ecc_status); + if (!ret) { + unsigned int i, bitflips = 0; + + for (i = 0; i < chip->ecc.steps; i++) { + bitflips = ecc_status[i] & TOSHIBA_NAND_ECC_STATUS_MASK; + if (bitflips == TOSHIBA_NAND_ECC_STATUS_UNCORR) { + mtd->ecc_stats.failed++; + } else { + mtd->ecc_stats.corrected += bitflips; + max_bitflips = max(max_bitflips, bitflips); + } + } + + return max_bitflips; + } + + /* + * Fallback to regular status check if + * toshiba_nand_benand_read_eccstatus_op() failed. + */ ret = nand_status_op(chip, &status); if (ret) return ret; -- 2.7.4