Received: by 10.192.165.148 with SMTP id m20csp2631646imm; Sun, 6 May 2018 20:42:10 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqtL4boooNawJsBwBYBIamnA8gRs/iIURViei6i0HRsIVC554T8rcFINlA+y2ATwcG6czsE X-Received: by 2002:a63:7c14:: with SMTP id x20-v6mr29239493pgc.161.1525664530193; Sun, 06 May 2018 20:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525664530; cv=none; d=google.com; s=arc-20160816; b=n6UXjDolTnndeWxpcZKtz2E+ChubMcXXOFw/D26060hwy4rp5pxamXQ8+dohwXKD6f n/jd8b9YHcWXnbD5HhNfZAVT+78K4scfJ4euQE8KbHakTNIrC1/ylnlKFT7uWihKF9c7 DMEBK6yxk3zhwVlxxGORi+GZCPnR9EXJAJfHNF0tHwPIydKSSFDgQOajU8E6psIxL+Lj TiBYb6GWqviok/fqnlj9a93e7181t1ZlniQ1glqIAnxp8KmOc7Ght79W9D5jnIPr2PQi L16GLjfQns96HBiZuCI1oXod5ikh/5CwIvlcJp6t9wd4rFxgPNogJ/QZxAca98k7gUzQ 2nXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=Qp0kfB5//iqhq7XbWe4TaN0fPKLkX7599mv2+TEPtGc=; b=FTSYLjKnhMCBSZlsFpcHTEHac9011Kob4ycYdXZQuGpfl/63hOIR4Ccy3b0zkPGUvH mKBbD0fDGr3uWvOPrinl2O9t05yJqpK176dVuGDxcKJ4q/99sOBIzcy3pIQV3teyH0q1 WqUnfiMfOpIYsge2UsANGMGPpuM7uTXEg70MhkA2hklko191cGGNk4H/k00JM5zijcx5 5gaiLvbIXTukSmHxlLUiIdTbjUdQPCPB1COaXx3Il9fDUJcZplu3lE7JcK5kNGwsd6/u mxbUMrqoXZTvLI/POnsKjj35Hvl0ZTTVSACaK34jSmB/7EaW5FG8/rEFuQ2oqVQpr3Wo XaTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=PH/0Q8E+; 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 m7si20692179pfh.92.2018.05.06.20.41.54; Sun, 06 May 2018 20:42:10 -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; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=PH/0Q8E+; 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 S1751903AbeEGDln (ORCPT + 99 others); Sun, 6 May 2018 23:41:43 -0400 Received: from conssluserg-03.nifty.com ([210.131.2.82]:47233 "EHLO conssluserg-03.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751800AbeEGDlk (ORCPT ); Sun, 6 May 2018 23:41:40 -0400 Received: from mail-ua0-f170.google.com (mail-ua0-f170.google.com [209.85.217.170]) (authenticated) by conssluserg-03.nifty.com with ESMTP id w473fKiW029600; Mon, 7 May 2018 12:41:21 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com w473fKiW029600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1525664481; bh=Qp0kfB5//iqhq7XbWe4TaN0fPKLkX7599mv2+TEPtGc=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=PH/0Q8E+YNyspYaUPNTnrwlpPBlNZOuPuXuJojazT/Lqm4yyVgCOo+6lvdkbJOBYA rNheM1SAOGSTCHcV6HzDsQhIXQoEeYq3jzauaCxLL+4mmf9GKzn3nlMeuBmZLIESuO twfji236tKW2oZMv07fjdlXVm1GYkXJKgY8Vt1LVqX155fnQNLRHdUnT2nLr8FtMJw ji1HNAAxLo11LMXvBbzq+W1uMBxH9IpiBjY6ldGDJ+laUQP3KzxQLdhweVr9kDh0ir LBjLdGUNbqJQIpJOj7zY1307o/0LfD0giyG6nUuPXhenEReF5brv+b4cKuRsWxAvt5 8xiNxkkBCSzIw== X-Nifty-SrcIP: [209.85.217.170] Received: by mail-ua0-f170.google.com with SMTP id i3so17477024uad.4; Sun, 06 May 2018 20:41:21 -0700 (PDT) X-Gm-Message-State: ALQs6tAd6nTkDzn/LaJmMThLot1G54XVadxqjNeTaZ0nIJl78XCrvsn0 6tjVcVPIuIKWYRnnAYphhcH0DpH26UUc7FxazEc= X-Received: by 10.176.6.170 with SMTP id g39mr30396446uag.82.1525664479944; Sun, 06 May 2018 20:41:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.85.216 with HTTP; Sun, 6 May 2018 20:40:39 -0700 (PDT) In-Reply-To: <1525350041-22995-2-git-send-email-absahu@codeaurora.org> References: <1525350041-22995-1-git-send-email-absahu@codeaurora.org> <1525350041-22995-2-git-send-email-absahu@codeaurora.org> From: Masahiro Yamada Date: Mon, 7 May 2018 12:40:39 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 01/14] mtd: rawnand: helper function for setting up ECC parameters To: Abhishek Sahu Cc: Boris Brezillon , Archit Taneja , Richard Weinberger , linux-arm-msm , Linux Kernel Mailing List , Marek Vasut , linux-mtd , Miquel Raynal , Andy Gross , Brian Norris , David Woodhouse Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-05-03 21:20 GMT+09:00 Abhishek Sahu : > commit 2c8f8afa7f92 ("mtd: nand: add generic helpers to check, > match, maximize ECC settings") provides generic helpers which > drivers can use for setting up ECC parameters. > > Since same board can have different ECC strength nand chips so > following is the logic for setting up ECC strength and ECC step > size, which can be used by most of the drivers. > > 1. If both ECC step size and ECC strength are already set > (usually by DT) then just check whether this setting > is supported by NAND controller. > 2. If NAND_ECC_MAXIMIZE is set, then select maximum ECC strength > supported by NAND controller. > 3. Otherwise, try to match the ECC step size and ECC strength closest > to the chip's requirement. If available OOB size can't fit the chip > requirement then select maximum ECC strength which can be fit with > available OOB size with warning. > > This patch introduces nand_ecc_param_setup function which calls the > required helper functions for the above logic. The drivers can use > this single function instead of calling the 3 helper functions > individually. > > CC: Masahiro Yamada > Signed-off-by: Abhishek Sahu > --- > * Changes from v1: > > NEW PATCH > > drivers/mtd/nand/raw/nand_base.c | 42 ++++++++++++++++++++++++++++++++++++++++ > include/linux/mtd/rawnand.h | 3 +++ > 2 files changed, 45 insertions(+) > > diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c > index 72f3a89..dd7a984 100644 > --- a/drivers/mtd/nand/raw/nand_base.c > +++ b/drivers/mtd/nand/raw/nand_base.c > @@ -6249,6 +6249,48 @@ int nand_maximize_ecc(struct nand_chip *chip, > } > EXPORT_SYMBOL_GPL(nand_maximize_ecc); > > +/** > + * nand_ecc_param_setup - Set the ECC strength and ECC step size > + * @chip: nand chip info structure > + * @caps: ECC engine caps info structure > + * @oobavail: OOB size that the ECC engine can use > + * > + * Choose the ECC strength according to following logic > + * > + * 1. If both ECC step size and ECC strength are already set (usually by DT) > + * then check if it is supported by this controller. > + * 2. If NAND_ECC_MAXIMIZE is set, then select maximum ECC strength. > + * 3. Otherwise, try to match the ECC step size and ECC strength closest > + * to the chip's requirement. If available OOB size can't fit the chip > + * requirement then fallback to the maximum ECC step size and ECC strength > + * and print the warning. > + * > + * On success, the chosen ECC settings are set. > + */ > +int nand_ecc_param_setup(struct nand_chip *chip, > + const struct nand_ecc_caps *caps, int oobavail) > +{ > + int ret; > + > + if (chip->ecc.size && chip->ecc.strength) > + return nand_check_ecc_caps(chip, caps, oobavail); > + > + if (chip->ecc.options & NAND_ECC_MAXIMIZE) > + return nand_maximize_ecc(chip, caps, oobavail); > + > + if (!nand_match_ecc_req(chip, caps, oobavail)) > + return 0; > + > + ret = nand_maximize_ecc(chip, caps, oobavail); Why two calls for nand_maximize_ecc()? My code is simpler, and does not display false-positive warning. > + if (!ret) > + pr_warn("ECC (step, strength) = (%d, %d) not supported on this controller. Fallback to (%d, %d)\n", > + chip->ecc_step_ds, chip->ecc_strength_ds, > + chip->ecc.size, chip->ecc.strength); This is annoying. {ecc_step_ds, ecc_strength_ds} are not provided by Non-ONFi devices. So, ECC (step, strength) = (0, 0) not supported on this controller. will be always displayed. The strength will be checked by nand_ecc_strength_good() anyway. > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(nand_ecc_param_setup); -- Best Regards Masahiro Yamada