Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3589715yba; Tue, 9 Apr 2019 00:05:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8DV3ysZVuiWnPOpu4kWpvXSzwsPcO77viNugK9khSn0rf3Itt4GtyDt7zZ/xHDhsWWSaA X-Received: by 2002:a17:902:bb94:: with SMTP id m20mr9033318pls.29.1554793526027; Tue, 09 Apr 2019 00:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554793526; cv=none; d=google.com; s=arc-20160816; b=IinUzT19dUWFXyFmUXSM2eOvvf1pB5OLg5fFWHh86ln1blBoJWDZykmD83m66YYqJM o7PUaPv+lVEtHOAKmBZtBA7paH8s04nq9NHzzTwn2/qh00nNVVbki9NMnrfhF1fLb/3L 7lEq+TEsOnizYQUVNOz9TyMiVV1U5BZxjZ6DKXfTzsOtG1nl1QX0TfX0X50iyEu5WdLJ Yi6weNaEjWN1Zw3M/rSMjjOy7pPLzrMMCNkuI7kcjDbG1eRQrr20kwL58VPu5i+N5RLD XTxurIMVXJq/ri/ujgigx1n0YPrGF9sFeNoP5Z8UZtCGm2+h5Z3N4L1w0nfc95Le4+oZ PJhg== 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=O9ogFZJv55BB/+FiDQf+84kn/2/6fA4EcvLqbHzkZOs=; b=CvgpViVpz7bpXvcHyEElVY9UeD8zOwG/mTRG0M7v99tStzqz4W64DUesfjDyMSonbc ldNvnxEVwPfUsC6WcNXn3CPW89+NJxQdExs3ARlx8Y/TxVtllUIpZuMa+N2AI+rI+7Ti sKKH3UzGbG+mR/ch0G9ABnb5S9pwRTQMxPASQCF/BEBXZ+7tW635CPBgrGWtuA69QfEY fO3DXGw/eNJSTlxLOntHv13bv6NTqDfZw+rG2ZBUZGeV/4Tq0pE6+2KCAAt7wETDZWTM R3HKmnHYgjm3xK8XcVCCJ3I3BTSHnRWLtDAQUiKCCGs+8eYKaDH6ED4PFDpIQR0SKFbw tkOw== 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=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s83si28481724pgs.420.2019.04.09.00.05.09; Tue, 09 Apr 2019 00:05:26 -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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726415AbfDIHEd (ORCPT + 99 others); Tue, 9 Apr 2019 03:04:33 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:48582 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725781AbfDIHEd (ORCPT ); Tue, 9 Apr 2019 03:04:33 -0400 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 27A35280827; Tue, 9 Apr 2019 08:04:31 +0100 (BST) Date: Tue, 9 Apr 2019 09:04:27 +0200 From: Boris Brezillon To: Mason Yang Cc: bbrezillon@kernel.org, marek.vasut@gmail.com, linux-kernel@vger.kernel.org, miquel.raynal@bootlin.com, dwmw2@infradead.org, computersforpeace@gmail.com, richard@nod.at, linux-mtd@lists.infradead.org, juliensu@mxic.com.tw, zhengxunli@mxic.com.tw Subject: Re: [PATCH] mtd: rawnand: Add Macronix NAND read retry and randomizer support Message-ID: <20190409090427.22de9917@collabora.com> In-Reply-To: <1554780172-23111-1-git-send-email-masonccyang@mxic.com.tw> References: <1554780172-23111-1-git-send-email-masonccyang@mxic.com.tw> Organization: Collabora X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 9 Apr 2019 11:22:52 +0800 Mason Yang wrote: > Add a driver for Macronix NAND read retry and randomizer. These are 2 orthogonal changes, and should thus bit split in 2 patches. > > Signed-off-by: Mason Yang > --- > drivers/mtd/nand/raw/nand_macronix.c | 169 +++++++++++++++++++++++++++++++++++ > 1 file changed, 169 insertions(+) > > diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c > index 47d8cda..a19caa4 100644 > --- a/drivers/mtd/nand/raw/nand_macronix.c > +++ b/drivers/mtd/nand/raw/nand_macronix.c > @@ -17,6 +17,174 @@ > > #include "internals.h" > > +#define MACRONIX_READ_RETRY_BIT BIT(0) > +#define MACRONIX_RANDOMIZER_BIT BIT(1) > +#define MACRONIX_READ_RETRY_MODE 5 > + > +#define ONFI_FEATURE_ADDR_MXIC_RANDOMIZER 0xB0 > + > +struct nand_onfi_vendor_macronix { > + u8 reserved[1]; > + u8 reliability_func; > +} __packed; > + > +struct nand_chip *mxic_sysfs; > + > +static int macronix_nand_setup_read_retry(struct nand_chip *chip, int mode) > +{ > + u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = {0}; > + int ret; > + > + if (mode > MACRONIX_READ_RETRY_MODE) > + mode = MACRONIX_READ_RETRY_MODE; > + > + feature[0] = mode; > + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_READ_RETRY, feature); > + if (ret) > + pr_err("failed to enter read retry moded:%d\n", mode); > + > + if (mode == 0) > + ret = nand_get_features(chip, ONFI_FEATURE_ADDR_READ_RETRY, > + feature); > + if (ret) > + pr_err("failed to exits read retry moded:%d\n", mode); > + > + return ret; > +} > + > +static ssize_t mxic_nand_rand_type_show(struct kobject *kobj, > + struct kobj_attribute *attr, char *buf) > +{ > + struct nand_chip *chip = mxic_sysfs; > + u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = {0}; > + int ret; > + > + nand_select_target(chip, 0); > + ret = nand_get_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + nand_deselect_target(chip); > + if (ret) > + pr_err("failed to check mxic nand device randomizer\n"); > + > + return sprintf(buf, "MXIC NAND device randomizer %s(0x%x)\n", > + feature[0] & MACRONIX_RANDOMIZER_BIT ? > + "enable" : "disable", feature[0]); > +} > + > +static ssize_t mxic_nand_rand_type_store(struct kobject *kobj, > + struct kobj_attribute *attr, > + const char *buf, size_t count) > +{ > + struct nand_chip *chip = mxic_sysfs; > + u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = {0}; > + unsigned int rand_layout; > + int ret; > + > + nand_select_target(chip, 0); > + ret = nand_get_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + nand_deselect_target(chip); > + > + if (feature[0]) { > + pr_err("Randomizer is enabled 0x%x\n", feature[0]); > + goto err_out; > + } > + > + ret = kstrtouint(buf, 0, &rand_layout); > + if (ret) > + goto err_out; > + > + if (rand_layout > 7) { > + pr_err("Error parameter value:0x%x\n", rand_layout); > + goto err_out; > + } > + > + feature[0] = rand_layout & 0x07; > + nand_select_target(chip, 0); > + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + nand_deselect_target(chip); > + if (ret) { > + pr_err("device randomizer set feature failed\n"); > + goto err_out; > + } > + > + feature[0] = 0x0; > + nand_select_target(chip, 0); > + ret = nand_prog_page_op(chip, 0, 0, feature, 1); > + nand_deselect_target(chip); > + if (ret) { > + pr_err("Prog device randomizer failed\n"); > + goto err_out; > + } > + > + feature[0] = 0x0; > + nand_select_target(chip, 0); > + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + feature); > + nand_deselect_target(chip); > + if (ret) > + pr_err("failed to exits prog device randomizer\n"); > + > +err_out: > + return count; > +} > + > +static const struct kobj_attribute sysfs_mxic_nand = > + __ATTR(nand_random, S_IRUGO | S_IWUSR, > + mxic_nand_rand_type_show, > + mxic_nand_rand_type_store); No, we don't want to expose that through a sysfs file, especially since changing the randomizer config means making the NAND unreadable for those that have used it before the change. BTW, why would we want to disable the randomizer? If it's here I guess it's needed. The only use case I have in mind is when the controller also has a randomizer and you want to use this one instead of the on-die one. > + > +static void macronix_nand_onfi_init(struct nand_chip *chip) > +{ > + struct nand_parameters *p = &chip->parameters; > + struct kobject *kobj; > + int ret; > + > + mxic_sysfs = chip; > + if (p->onfi) { > + struct nand_onfi_vendor_macronix *mxic = > + (void *)p->onfi->vendor; > + > + if (mxic->reliability_func & MACRONIX_READ_RETRY_BIT) { > + chip->read_retries = MACRONIX_READ_RETRY_MODE + 1; > + chip->setup_read_retry = > + macronix_nand_setup_read_retry; > + if (p->supports_set_get_features) { > + set_bit(ONFI_FEATURE_ADDR_READ_RETRY, > + p->set_feature_list); > + set_bit(ONFI_FEATURE_ADDR_READ_RETRY, > + p->get_feature_list); > + } > + } > + > + if (mxic->reliability_func & MACRONIX_RANDOMIZER_BIT) { > + if (p->supports_set_get_features) { > + set_bit(ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + p->set_feature_list); > + set_bit(ONFI_FEATURE_ADDR_MXIC_RANDOMIZER, > + p->get_feature_list); > + /* > + * create syfs-fs for MXIC NAND device > + * randomizer status check & enable > + * operations. > + */ > + kobj = kobject_create_and_add("mxic_rand_nand", > + NULL); > + if (!kobj) > + return; > + > + ret = sysfs_create_file(kobj, > + &sysfs_mxic_nand.attr); > + if (ret) { > + pr_err("Err: mxic_rand_nand sysfs"); > + kobject_put(kobj); > + } > + } > + } > + } > +} > + > /* > * 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 +233,7 @@ static int macronix_nand_init(struct nand_chip *chip) > chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; > > macronix_nand_fix_broken_get_timings(chip); > + macronix_nand_onfi_init(chip); > > return 0; > }