Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1446057imm; Thu, 19 Jul 2018 01:37:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdO7sPfx7kXqsJU77BXh2x23PD6EYis+ktctgAkp6CGedxtdqVDzjUmnhAmTGVwqsAE/7t9 X-Received: by 2002:a17:902:e093:: with SMTP id cb19-v6mr9267479plb.189.1531989460580; Thu, 19 Jul 2018 01:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531989460; cv=none; d=google.com; s=arc-20160816; b=LwYPKd8nMwZq3ApBHNqeCtyiRfEplSU51N7Udjvmxgvfbc6PzmP2KQEpeoKb3bu3sT PWZT6JZu6g9+RzCnZb4SNNC24yzgJmz7LV3W7RBls3TI3ZXLFKQ/fc+ueOOlK9gsZmZx GC3Yk4lzk2PzYcasTYLY5mMS9BxrRoHZSWmP9I4QZzTwthYYJr2RMG29ob3XbBW3cKe4 6MZpWM0sEBHGhs1e6cOr6R0mQXoFpax2rLCx8OO9v6g14VztTW7Fi4NpOzP/LK8wT/42 D8z4WMxprDYIBP+LdjiHxUd97s4LpMZJeAzosrYfVJJm0euKYUD6F/n2yDcKLGJNtnqJ d+Aw== 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 :content-transfer-encoding:arc-authentication-results; bh=u6mh2U7a8SJEgW1U056OPDgWSxEKhRPvU2JEjB64nuI=; b=RFtzkQJBQ/n3uAO5dHicmELI+cjm1ZMBhiRHijBbSilw7daYjVTz5M5taJVuIBGPH1 OAse4U8ZZD8F8+K7AZ/TgDXWgNgxxXlvUhtuPDQr9Y1x8BFm+OYXGohPKGs2N5GjCxaE qJgLG9M2qHnxaEPjhzJQ86thduLzb+jfog84OublxnQqiZjzoJ38uDO/hv3SjKgsx3RX ZEcoi+EvdBhSM+ulauAmERk9IDWAje3CKj9xY6BE+TdNLTwqVhOuOjuoer+xmtc3N7wo dH8eHcu/ubUai/ALDcKUDyH82ODIVjI/Z8hubpOYifM8se7wxnhN80AJGAylholQqQkv Br9w== 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 w5-v6si4788350plz.438.2018.07.19.01.37.24; Thu, 19 Jul 2018 01:37:40 -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 S1730782AbeGSJSw (ORCPT + 99 others); Thu, 19 Jul 2018 05:18:52 -0400 Received: from mo-csw-fb1115.securemx.jp ([210.130.202.174]:49514 "EHLO mo-csw-fb.securemx.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbeGSJSv (ORCPT ); Thu, 19 Jul 2018 05:18:51 -0400 Received: by mo-csw-fb.securemx.jp (mx-mo-csw-fb1115) id w6J7ssqT030202; Thu, 19 Jul 2018 16:54:54 +0900 Received: by mo-csw.securemx.jp (mx-mo-csw1114) id w6J7s1dh008596; Thu, 19 Jul 2018 16:54:01 +0900 X-Iguazu-Qid: 2wGr4XsOpocR8ov1OL X-Iguazu-QSIG: v=1; s=0; t=1531986841; q=2wGr4XsOpocR8ov1OL; m=/g3rU7TXdO+dfxS7wdS8GI7jugW0ermTbPf+dQMKbZw= Received: from imx2.toshiba.co.jp (imx2.toshiba.co.jp [106.186.93.51]) by relay.securemx.jp (mx-mr1112) id w6J7rx5X001124; Thu, 19 Jul 2018 16:53:59 +0900 Received: from hop001.toshiba.co.jp ([133.199.164.63]) by imx2.toshiba.co.jp with ESMTP id w6J7rx9v020903; Thu, 19 Jul 2018 16:53:59 +0900 (JST) Content-Transfer-Encoding: 7bit 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] mtd: nand: toshiba: Add support for ->exec_op() Date: Thu, 19 Jul 2018 16:53:47 +0900 X-TSB-HOP: ON Message-Id: <1531986827-18743-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 | 76 +++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_toshiba.c b/drivers/mtd/nand/raw/nand_toshiba.c index 6cec923..12218cd 100644 --- a/drivers/mtd/nand/raw/nand_toshiba.c +++ b/drivers/mtd/nand/raw/nand_toshiba.c @@ -17,28 +17,74 @@ #include +/* 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 + /* Recommended to rewrite for BENAND */ #define TOSHIBA_NAND_STATUS_REWRITE_RECOMMENDED BIT(3) +static int toshiba_nand_benand_read_eccstatus_op(struct nand_chip *chip, + u8 *buf) +{ + u8 *ecc_status = buf; + + 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); + + /* Drop the DATA_IN instruction if chip->ecc.steps is set to 0. */ + if (!chip->ecc.steps) + op.ninstrs--; + + return nand_exec_op(chip, &op); +} + static int toshiba_nand_benand_eccstatus(struct mtd_info *mtd, struct nand_chip *chip) { - int ret; + int ret, i; 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; + u8 status, bitflips, ecc_status[8]; + + if (chip->exec_op) { + /* Check ECC Status */ + ret = toshiba_nand_benand_read_eccstatus_op(chip, ecc_status); + if (ret) + return ret; + + for (i = 0; i < chip->ecc.steps; i++) { + bitflips = (ecc_status[i] & + TOSHIBA_NAND_ECC_STATUS_MASK); + if (bitflips == 0x0F) { + mtd->ecc_stats.failed++; + } else { + mtd->ecc_stats.corrected += bitflips; + max_bitflips = max_t(unsigned int, + max_bitflips, bitflips); + } + } + } else { + /* 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; -- 2.7.4