Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4001181ybp; Mon, 7 Oct 2019 01:20:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTt/552avV3mUirf0cv8gEW9qUhTntuLmuH0bTCsH0ucWBHjcX1OOtO+QCxSyIzJ4wMey/ X-Received: by 2002:a05:6402:1699:: with SMTP id a25mr27746852edv.91.1570436402486; Mon, 07 Oct 2019 01:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570436402; cv=none; d=google.com; s=arc-20160816; b=biYwgjmTGPi+j66OjceSlXBAcp44Ksb8U5pr9c+tQE8vwoL3Mo4OMTKKeB4V5lmds7 Bg9e1HPubNcqfBNBRF1SfQKf/CyYnOep1u/aEHM1Oh0jjFEXn37GCOOaKCT3UKlaCZiU RQgTRgwSS/yP/gIufhccBBAH2tUcWOtAQwLEXAYsQnaO9Lp3TuexHLOJ1jobMOJwSOga mMWr0ny205cI99sSdeoTm8UvP+9iw384cMBqakZIdcj04A41kQOaGPaz1TZf2epGR5xC ypC1UpDSrW50fh5Zc/GqRKAmQ9R+dg8qKRIcl7fyaL77g2AszF+tYX+0ycfRJxotUBjG R+tw== 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=ijC2jBgingVVRMdujySTlvBThuAiwtZUkXdNkbGoK/c=; b=JlyYhFeVKI6+8FrZRBsiZ6m4JVdduw3Lah6IWWoGFKvzVgXqF0EXGBTqTVsmTQcQpZ qN7phgI7YTjhUWBNBHd+Dlr4QKwcKYczI2olLsYKay0+zJAvoj7FSPRjty2XGevk8RzF bWFWRiOsgC56QWwI9ho0653R/PbkJsqQe6WFzNA1xlHmLU81QTs4ZNaM+bCXN6gu8FFv hfYDoKe6v+dbuLBxNTCwilu5U//X0lvcrIiXMwllhWZT0WyZS/VxdWEga9A6bJ6v6pGP lY8owQ3M3nn8xLMaM7+nqLwdpLccjQ4MynfMGYQaNXjkXB4P8q1Hl8sE0EZpzhtAN92w 3fnw== 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 a36si8582898edf.123.2019.10.07.01.19.38; Mon, 07 Oct 2019 01:20:02 -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 S1727505AbfJGISx convert rfc822-to-8bit (ORCPT + 99 others); Mon, 7 Oct 2019 04:18:53 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:56637 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727103AbfJGISx (ORCPT ); Mon, 7 Oct 2019 04:18:53 -0400 Received: from xps13 (lfbn-1-17395-211.w86-250.abo.wanadoo.fr [86.250.200.211]) (Authenticated sender: miquel.raynal@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 6BD9C100010; Mon, 7 Oct 2019 08:18:48 +0000 (UTC) Date: Mon, 7 Oct 2019 10:18:47 +0200 From: Miquel Raynal To: Mason Yang Cc: richard@nod.at, marek.vasut@gmail.com, dwmw2@infradead.org, bbrezillon@kernel.org, computersforpeace@gmail.com, vigneshr@ti.com, juliensu@mxic.com.tw, linux-kernel@vger.kernel.org, frieder.schrempf@kontron.de, linux-mtd@lists.infradead.org, tglx@linutronix.de Subject: Re: [PATCH v3] mtd: rawnand: Add support for Macronix NAND randomizer Message-ID: <20191007101847.7fcfcfc7@xps13> In-Reply-To: <1567676229-23414-1-git-send-email-masonccyang@mxic.com.tw> References: <1567676229-23414-1-git-send-email-masonccyang@mxic.com.tw> Organization: Bootlin X-Mailer: Claws Mail 3.17.3 (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 Thu, 5 Sep 2019 17:37:09 +0800: > Macronix NANDs support randomizer operation for user data scrambled, > which can be enabled with a SET_FEATURE. > > User data written to the NAND device without randomizer is still readable > after randomizer function enabled. > The penalty of randomizer are subpage accesses prohibited and more time > period is needed in program operation and entering deep power-down mode. > i.e., tPROG 300us to 340us(randomizer enabled) > > For more high-reliability concern, if subpage write not available with > hardware ECC and then to enable randomizer is recommended by default. > Driver checks byte 167 of Vendor Blocks in ONFI parameter page table > to see if this high-reliability function is supported. By adding a new > specific DT property in children nodes to enable randomizer function. > i.e., > > nand: nand-controller@unit-address { > > nand@0 { > reg = <0>; > mxic,enable-randomizer-otp; > }; > }; > > -- > changelog > v3: > To enable randomizer by specific DT property in children nodes, > mxic,enable-randomizer-otp; > > v2: > To enable randomizer by checking chip options NAND_NO_SUBPAGE_WRITE > > v1: > To enable randomizer by sys-fs > > Signed-off-by: Mason Yang > --- > drivers/mtd/nand/raw/nand_macronix.c | 64 ++++++++++++++++++++++++++++++++++++ As long as you modify bindings, you should write a separate patch to update the documentation and get it acked by Rob Herring. > 1 file changed, 64 insertions(+) > > diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c > index 58511ae..d5df09a 100644 > --- a/drivers/mtd/nand/raw/nand_macronix.c > +++ b/drivers/mtd/nand/raw/nand_macronix.c > @@ -11,6 +11,13 @@ > #define MACRONIX_READ_RETRY_BIT BIT(0) > #define MACRONIX_NUM_READ_RETRY_MODES 6 > > +#define MACRONIX_RANDOMIZER_BIT BIT(1) > +#define ONFI_FEATURE_ADDR_MXIC_RANDOMIZER 0xB0 > +#define MACRONIX_RANDOMIZER_ENPGM BIT(0) > +#define MACRONIX_RANDOMIZER_RANDEN BIT(1) > +#define MACRONIX_RANDOMIZER_RANDOPT BIT(2) > +#define MACRONIX_RANDOMIZER_MODE_EXIT ~MACRONIX_RANDOMIZER_ENPGM I would rather prefer a #define ...RANDOMISER_MODE_ENTER (ENGPM | RANDEN | RANDOPT) #define ...RANDOMISER_MODE_EXIT (RANDEN | RANDOPT) > + > struct nand_onfi_vendor_macronix { > u8 reserved; > u8 reliability_func; > @@ -29,15 +36,72 @@ static int macronix_nand_setup_read_retry(struct nand_chip *chip, int mode) > return nand_set_features(chip, ONFI_FEATURE_ADDR_READ_RETRY, feature); > } > > +static void macronix_nand_randomizer_check_enable(struct nand_chip *chip) You should return something and check it from the calling function. > +{ > + u8 feature[ONFI_SUBFEATURE_PARAM_LEN]; > + int ret; > + > + ret = nand_get_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + if (feature[0]) { > + pr_info("Macronix NAND randomizer enabled:0x%x\n", feature[0]); > + return; > + } > + > + feature[0] = MACRONIX_RANDOMIZER_ENPGM | MACRONIX_RANDOMIZER_RANDEN | > + MACRONIX_RANDOMIZER_RANDOPT; > + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + if (ret) > + goto err; > + > + feature[0] = 0x0; > + ret = nand_prog_page_op(chip, 0, 0, feature, 1); What is this? A comment is needed. > + if (ret) > + goto err; > + > + ret = nand_get_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + if (ret) > + goto err; > + > + feature[0] &= MACRONIX_RANDOMIZER_MODE_EXIT; > + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + if (ret) > + goto err; > + > + pr_info("Macronix NAND randomizer enable ok\n"); The pr_info "ok" could be dropped, the "failed" one would go in nand_onfi_init() after a check on the return code. Then, no more goto's. > + return; > +err: > + pr_err("Macronix NAND randomizer enable failed\n"); > +} > + > static void macronix_nand_onfi_init(struct nand_chip *chip) > { > struct nand_parameters *p = &chip->parameters; > struct nand_onfi_vendor_macronix *mxic; > + struct device_node *dn = nand_get_flash_node(chip); > + int rand_otp = 0; > > if (!p->onfi) > return; > > + if (of_find_property(dn, "mxic,enable-randomizer-otp", NULL)) > + rand_otp = 1; > + > mxic = (struct nand_onfi_vendor_macronix *)p->onfi->vendor; > + if (rand_otp && chip->options & NAND_NO_SUBPAGE_WRITE && > + mxic->reliability_func & MACRONIX_RANDOMIZER_BIT) { > + if (p->supports_set_get_features) { > + bitmap_set(p->set_feature_list, > + ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, 1); > + bitmap_set(p->get_feature_list, > + ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, 1); > + macronix_nand_randomizer_check_enable(chip); > + } > + } > + > if ((mxic->reliability_func & MACRONIX_READ_RETRY_BIT) == 0) > return; > Thanks, Miquèl