Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp99529yba; Mon, 20 May 2019 05:41:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqyp1Po9vP6MuMVbUCumaq1Iri91Lu7GC++hE3FiEmu+9gtBG/erHoc9jHP1ya+JYpj5n04p X-Received: by 2002:a63:c50c:: with SMTP id f12mr74422743pgd.71.1558356107843; Mon, 20 May 2019 05:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558356107; cv=none; d=google.com; s=arc-20160816; b=EiVyH4M1jJHVGOVcx0+ZyND0HgLBDX4QXYV4XQ6i3t2fGcwk0xd1edAkKSvqsrpBKx U9gzaNI1fk/eT3UGyviHDKmrQV99Iq6lOcYByPf88Ii5KMxRNaobKhSlRN7c/8Tv0M9t Y5rEsZ1d20mDZtblXmG0ePfnOi9/sJ+xgEGYuwRKpqQVKAcFS4I7Lbb+Wzp88hllOI1g LxiDuxxImRwtUAChJzCuFGLI3njBdbOU25wBaRcOtXvDQJoDIIDLKictxcwFc1JhcO44 +iRY4cFrj3i8nNir61tPHmT+wmQtWdXXAlsrmdonGPX/+ouNXYEaLEk6JLy1LXmIs+CQ GiVA== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=0gtIRKGgE1Hs+0vCawywd7MxGsO0SgXAMLt9uKKZr+c=; b=XkIliV6PLD9FjRembo1qZQ1ncxFegeTW1es9+0OrdgY4r3bVUoREBMpF2s/ZjzeGKV nqBtQ2oVs01KUIFOPkfH9L6x2my3hrsGO+jfXWVoHh/AhQuGaoeOnBc/I7k11ncFXi6c unuU2b8kKioE9+kNi4E7O6nvNsi9MI+Y7oAy1Tfp772vfwAJtY2q+eXl5CqHeueJGrgq AfmSiskxKF2Tl69l+MnWQW9JbSFpgnp66V22wUMhYA6rFHhc21aEcrNBfinfzlYjsIpX /1a435iCVjeTB95L87REdkE1DYZ+IKi+hz8s6L/KfoqDo/k88y7GmczWndG73ES15vxW +CQQ== 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 q11si17847100pgf.519.2019.05.20.05.41.33; Mon, 20 May 2019 05:41:47 -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 S2391322AbfETMip convert rfc822-to-8bit (ORCPT + 99 others); Mon, 20 May 2019 08:38:45 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:33753 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390971AbfETMen (ORCPT ); Mon, 20 May 2019 08:34:43 -0400 X-Originating-IP: 90.88.22.185 Received: from xps13 (aaubervilliers-681-1-80-185.w90-88.abo.wanadoo.fr [90.88.22.185]) (Authenticated sender: miquel.raynal@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 3C106FF811; Mon, 20 May 2019 12:34:38 +0000 (UTC) Date: Mon, 20 May 2019 14:34:38 +0200 From: Miquel Raynal To: Mason Yang Cc: bbrezillon@kernel.org, marek.vasut@gmail.com, linux-kernel@vger.kernel.org, richard@nod.at, dwmw2@infradead.org, computersforpeace@gmail.com, linux-mtd@lists.infradead.org, vigneshr@ti.com, frieder.schrempf@kontron.de, juliensu@mxic.com.tw, zhengxunli@mxic.com.tw Subject: Re: [PATCH v2] mtd: rawnand: Add Macronix NAND read retry support Message-ID: <20190520143438.46248bfc@xps13> In-Reply-To: <1558076001-29579-1-git-send-email-masonccyang@mxic.com.tw> References: <1558076001-29579-1-git-send-email-masonccyang@mxic.com.tw> Organization: Bootlin X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mason, Mason Yang wrote on Fri, 17 May 2019 14:53:21 +0800: > Add support for Macronix NAND read retry. > > Macronix NANDs support specific read operation for data recovery, > which can be enabled/disabled with a SET/GET_FEATURE. > Driver checks byte 167 of Vendor Blocks in ONFI parameter page table > to see if this high-reliability function is supported. > > Signed-off-by: Mason Yang > --- > drivers/mtd/nand/raw/nand_macronix.c | 57 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) > > diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c > index e287e71..1a4dc92 100644 > --- a/drivers/mtd/nand/raw/nand_macronix.c > +++ b/drivers/mtd/nand/raw/nand_macronix.c > @@ -17,6 +17,62 @@ > > #include "internals.h" > > +#define MACRONIX_READ_RETRY_BIT BIT(0) > +#define MACRONIX_READ_RETRY_MODE 6 Can you name this define MACRONIX_NUM_READ_RETRY_MODES? > + > +struct nand_onfi_vendor_macronix { > + u8 reserved[1]; Do you need this "[1]" ? > + u8 reliability_func; > +} __packed; > + > +/* > + * Macronix NANDs support using SET/GET_FEATURES to enter/exit read retry mode > + */ > +static int macronix_nand_setup_read_retry(struct nand_chip *chip, int mode) > +{ > + u8 feature[ONFI_SUBFEATURE_PARAM_LEN]; > + int ret, feature_addr = ONFI_FEATURE_ADDR_READ_RETRY; > + > + if (chip->parameters.supports_set_get_features && > + test_bit(feature_addr, chip->parameters.set_feature_list) && > + test_bit(feature_addr, chip->parameters.get_feature_list)) { > + feature[0] = mode; > + ret = nand_set_features(chip, feature_addr, feature); > + if (ret) > + pr_err("Failed to set read retry moded:%d\n", mode); Do you have to call nand_get_features() on error? > + > + ret = nand_get_features(chip, feature_addr, feature); > + if (ret || feature[0] != mode) > + pr_err("Failed to verify read retry moded:%d(%d)\n", > + mode, feature[0]); if ret == 0 but feature[0] != mode, shouldn't you return an error? > + } > + > + return ret; This will produce a Warning at compile time (ret may be used uninitialized). Have you tested it? > +} > + > +static void macronix_nand_onfi_init(struct nand_chip *chip) > +{ > + struct nand_parameters *p = &chip->parameters; > + struct nand_onfi_vendor_macronix *mxic; > + > + if (!p->onfi) > + return; > + > + mxic = (struct nand_onfi_vendor_macronix *)p->onfi->vendor; > + if ((mxic->reliability_func & MACRONIX_READ_RETRY_BIT) == 0) > + return; > + > + chip->read_retries = MACRONIX_READ_RETRY_MODE; > + chip->setup_read_retry = macronix_nand_setup_read_retry; > + > + if (p->supports_set_get_features) { > + bitmap_set(p->set_feature_list, > + ONFI_FEATURE_ADDR_READ_RETRY, 1); > + bitmap_set(p->get_feature_list, > + ONFI_FEATURE_ADDR_READ_RETRY, 1); > + } > +} > + > /* > * Macronix AC series does not support using SET/GET_FEATURES to change > * the timings unlike what is declared in the parameter page. Unflag > @@ -65,6 +121,7 @@ static int macronix_nand_init(struct nand_chip *chip) > chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE; > > macronix_nand_fix_broken_get_timings(chip); > + macronix_nand_onfi_init(chip); > > return 0; > } Thanks, Miquèl