Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2422681ybl; Thu, 9 Jan 2020 12:28:54 -0800 (PST) X-Google-Smtp-Source: APXvYqyzvQDPE/EXJGdjldkhDNTj5S6LNXzIDZonDOb6rAurnEGp0k+SuQFoOGWqY34PdWJX2rvy X-Received: by 2002:a54:4e8d:: with SMTP id c13mr4684492oiy.27.1578601734130; Thu, 09 Jan 2020 12:28:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578601734; cv=none; d=google.com; s=arc-20160816; b=ilBiETEYK9SK8GItVxKcZBBtbEZ/tpWdMJcx4sklu/DROJudnPTaUAhMSd83pEeZo4 ADQhlQp+BLnBilOSBibEBtiUchlrZVkPbkKYjhBVecEVJWXSbWPTvelMSK0RLr+bdEMM FPQkjMjs33jgozMRoo0soEGoGapyRtsA+4Q/g2HBb84Kkgq3tdutn6fhiXWHdRAjIRAp LF1uGbnoQMwCRoeGxTs/LJ+VJ6V2sDOZy40X87k7jODzF8R5yKnzkHuW9PTm0yrvMkxa +qfDZN7zmxwcEojqS0iceVah5pQAwOubQS/90a1cTKJeW3wFCoQMhs5G1jPJxUYWlmiW NeOQ== 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=p7idKY4EknJvHqdGbYFB0myVXwymxEe3mlUcZjTR9hA=; b=rZMDW+c4HTAtIVWtj4mEEY2pcSm3KkJwXYYhzhF/woHOc1NeBMJ3ejaCO5MH+I2yMb gVZQNMQNv4ywf5x/LvKc16WCHIsUwwrC+Avuah9rAKYQDtUADfxYikVglnwTmdYmcyiX x2tNF1dOepNugksNerhw5PH9EriPGT2UmkSi7sJA+6di8mwokGAiR8a60iw9h1df5izb MJf0CwuUKHYbJk7FPJRdolu24eC86WrOK11yZH2BxD1M8mGIynxXEEvt8P3Y9l7ES5bH PoMOJMVxbzxTLtT8x0RZyGm6NQEEg7M1Y+/cW3VZflwk1f5btmY7kojiCMEwfnR8FSZV SIdw== 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 p8si5717009otc.118.2020.01.09.12.28.41; Thu, 09 Jan 2020 12:28:54 -0800 (PST) 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 S2387626AbgAIQ2X convert rfc822-to-8bit (ORCPT + 99 others); Thu, 9 Jan 2020 11:28:23 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:45169 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728840AbgAIQ2V (ORCPT ); Thu, 9 Jan 2020 11:28:21 -0500 X-Originating-IP: 91.224.148.103 Received: from xps13 (unknown [91.224.148.103]) (Authenticated sender: miquel.raynal@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 3718220011; Thu, 9 Jan 2020 16:28:17 +0000 (UTC) Date: Thu, 9 Jan 2020 17:28:16 +0100 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, robh+dt@kernel.org, mark.rutland@arm.com, devicetree@vger.kernel.org, juliensu@mxic.com.tw, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: Re: [PATCH v4 1/2] mtd: rawnand: Add support for Macronix NAND randomizer Message-ID: <20200109172816.6c1d7be7@xps13> In-Reply-To: <1571902807-10388-2-git-send-email-masonccyang@mxic.com.tw> References: <1571902807-10388-1-git-send-email-masonccyang@mxic.com.tw> <1571902807-10388-2-git-send-email-masonccyang@mxic.com.tw> Organization: Bootlin X-Mailer: Claws Mail 3.17.4 (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, 24 Oct 2019 15:40:06 +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. > > Signed-off-by: Mason Yang > --- > drivers/mtd/nand/raw/nand_macronix.c | 69 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 69 insertions(+) > > diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c > index 58511ae..89101fa 100644 > --- a/drivers/mtd/nand/raw/nand_macronix.c > +++ b/drivers/mtd/nand/raw/nand_macronix.c > @@ -11,6 +11,14 @@ > #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 ENPGM BIT(0) > +#define RANDEN BIT(1) > +#define RANDOPT BIT(2) > +#define MACRONIX_RANDOMIZER_MODE_ENTER (ENPGM | RANDEN | RANDOPT) > +#define MACRONIX_RANDOMIZER_MODE_EXIT (RANDEN | RANDOPT) > + > struct nand_onfi_vendor_macronix { > u8 reserved; > u8 reliability_func; > @@ -29,15 +37,76 @@ 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 int macronix_nand_randomizer_check_enable(struct nand_chip *chip) > +{ > + u8 feature[ONFI_SUBFEATURE_PARAM_LEN]; > + int ret; > + > + ret = nand_get_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + if (ret < 0) > + return ret; > + > + if (feature[0]) > + return feature[0]; > + > + feature[0] = MACRONIX_RANDOMIZER_MODE_ENTER; > + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + if (ret < 0) > + return ret; > + > + /* RANDEN and RANDOPT OTP bits are programmed */ > + feature[0] = 0x0; > + ret = nand_prog_page_op(chip, 0, 0, feature, 1); > + if (ret < 0) > + return ret; > + > + ret = nand_get_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + if (ret < 0) > + return ret; > + > + feature[0] &= MACRONIX_RANDOMIZER_MODE_EXIT; > + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + if (ret < 0) > + return ret; > + > + return feature[0]; Can feature[0] be != 0 ? I don't think so, in this case I prefer a: return 0; > +} > + > 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; > + int ret; > > 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; > + /* Subpage write is prohibited in randomizer operatoin */ with operation > + 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); > + ret = macronix_nand_randomizer_check_enable(chip); > + if (ret < 0) > + pr_info("Macronix NAND randomizer failed\n"); > + else > + pr_info("Macronix NAND randomizer enabled\n"); Maybe we should update the bitmaps only if it succeeds? > + } > + } > + > if ((mxic->reliability_func & MACRONIX_READ_RETRY_BIT) == 0) > return; > With the above fixed, Reviewed-by: Miquel Raynal Thanks, Miquèl