From patchwork Wed Apr 11 03:41:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaolei li X-Patchwork-Id: 10334823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 28DB36053C for ; Wed, 11 Apr 2018 03:47:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1375B2869D for ; Wed, 11 Apr 2018 03:47:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07DD0286A4; Wed, 11 Apr 2018 03:47:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 399912869D for ; Wed, 11 Apr 2018 03:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JuYcYa0K3W1GMdgLTEyRJI0Nhw9VplavLqZxC84vqWk=; b=ugqxv7y8K0v8+m Dqr5Q1XSGZD52sF6JrU+57E4TEsgf9NahfGLHs8ytDQsiUq/nf5WKo/vUM1bu3+sxcxFKO5yIZHVz HHW+prUs+avYhw+6chS3/N5vSsgmyJEfTdp+isyoPrS9bl6IYxs5RZECS6iAQFHJC51t0Mz4EdlhS pu+bAgfMYUbN5IDzPD/NAPpXGjLvecMg+22duvkRtRePg3uDU+naWxnaTmBfXh8+lxc7NC7JUNiIt LetlJDI6FEEwGjpzxawLUbX2CNb80BD7kfPbqZjjnAb9CuOWhWMqktlAjJtyjaZYQC+XANET4a3Tg ssZ9PcBnfmtisGvirc+A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f66jE-0005bb-7R; Wed, 11 Apr 2018 03:47:24 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f66eX-0001v7-Mc; Wed, 11 Apr 2018 03:42:36 +0000 X-UUID: ca3c1a5ba82b4955ada187a0d5ea9881-20180411 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1797335618; Wed, 11 Apr 2018 11:42:14 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 11 Apr 2018 11:42:13 +0800 Received: from mtkslt306.mediatek.inc (10.21.14.136) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Wed, 11 Apr 2018 11:42:12 +0800 From: Xiaolei Li To: , Subject: [PATCH 5/8] mtd: rawnand: Modify ->calc_ecc_bytes() hook in nand_ecc_caps Date: Wed, 11 Apr 2018 11:41:55 +0800 Message-ID: <1523418118-57686-6-git-send-email-xiaolei.li@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523418118-57686-1-git-send-email-xiaolei.li@mediatek.com> References: <1523418118-57686-1-git-send-email-xiaolei.li@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180410_204233_913974_89524DA2 X-CRM114-Status: GOOD ( 12.75 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mediatek@lists.infradead.org, xiaolei.li@mediatek.com, linux-mtd@lists.infradead.org, srv_heupstream@mediatek.com Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Maybe some controllers need more information besides step size and ecc strength to calculate ECC bytes. struct nand_ecc_ctrl provides lots of ECC control information include private ECC control data. So, add it into ->calc_ecc_bytes() interface, to make this hook be more flexible. Signed-off-by: Xiaolei Li --- drivers/mtd/nand/raw/denali.c | 3 +- drivers/mtd/nand/raw/denali.h | 2 +- drivers/mtd/nand/raw/nand_base.c | 11 ++++-- include/linux/mtd/rawnand.h | 77 ++++++++++++++++++++-------------------- 4 files changed, 50 insertions(+), 43 deletions(-) diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c index 2a302a1..907609c 100644 --- a/drivers/mtd/nand/raw/denali.c +++ b/drivers/mtd/nand/raw/denali.c @@ -1113,7 +1113,8 @@ static void denali_hw_init(struct denali_nand_info *denali) iowrite32(0xffff, denali->reg + SPARE_AREA_MARKER); } -int denali_calc_ecc_bytes(int step_size, int strength) +int denali_calc_ecc_bytes(struct nand_ecc_ctrl *ecc, int step_size, + int strength) { /* BCH code. Denali requires ecc.bytes to be multiple of 2 */ return DIV_ROUND_UP(strength * fls(step_size * 8), 16) * 2; diff --git a/drivers/mtd/nand/raw/denali.h b/drivers/mtd/nand/raw/denali.h index 9ad33d2..644dffd 100644 --- a/drivers/mtd/nand/raw/denali.h +++ b/drivers/mtd/nand/raw/denali.h @@ -328,7 +328,7 @@ struct denali_nand_info { #define DENALI_CAP_HW_ECC_FIXUP BIT(0) #define DENALI_CAP_DMA_64BIT BIT(1) -int denali_calc_ecc_bytes(int step_size, int strength); +int denali_calc_ecc_bytes(struct nand_ecc_ctrl *, int, int); int denali_init(struct denali_nand_info *denali); void denali_remove(struct denali_nand_info *denali); diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index d0b993f..e17abc8 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -6052,6 +6052,7 @@ int nand_check_ecc_caps(struct nand_chip *chip, const struct nand_ecc_caps *caps, int oobavail) { struct mtd_info *mtd = nand_to_mtd(chip); + struct nand_ecc_ctrl *ecc = &chip->ecc; const struct nand_ecc_step_info *stepinfo; int preset_step = chip->ecc.size; int preset_strength = chip->ecc.strength; @@ -6076,7 +6077,7 @@ int nand_check_ecc_caps(struct nand_chip *chip, if (stepinfo->strengths[j] != preset_strength) continue; - ecc_bytes = caps->calc_ecc_bytes(preset_step, + ecc_bytes = caps->calc_ecc_bytes(ecc, preset_step, preset_strength); if (WARN_ON_ONCE(ecc_bytes < 0)) return ecc_bytes; @@ -6114,6 +6115,7 @@ int nand_match_ecc_req(struct nand_chip *chip, const struct nand_ecc_caps *caps, int oobavail) { struct mtd_info *mtd = nand_to_mtd(chip); + struct nand_ecc_ctrl *ecc = &chip->ecc; const struct nand_ecc_step_info *stepinfo; int req_step = chip->ecc_step_ds; int req_strength = chip->ecc_strength_ds; @@ -6152,7 +6154,8 @@ int nand_match_ecc_req(struct nand_chip *chip, nsteps = mtd->writesize / step_size; - ecc_bytes = caps->calc_ecc_bytes(step_size, strength); + ecc_bytes = caps->calc_ecc_bytes(ecc, step_size, + strength); if (WARN_ON_ONCE(ecc_bytes < 0)) continue; ecc_bytes_total = ecc_bytes * nsteps; @@ -6198,6 +6201,7 @@ int nand_maximize_ecc(struct nand_chip *chip, const struct nand_ecc_caps *caps, int oobavail) { struct mtd_info *mtd = nand_to_mtd(chip); + struct nand_ecc_ctrl *ecc = &chip->ecc; const struct nand_ecc_step_info *stepinfo; int step_size, strength, nsteps, ecc_bytes, corr; int best_corr = 0; @@ -6224,7 +6228,8 @@ int nand_maximize_ecc(struct nand_chip *chip, nsteps = mtd->writesize / step_size; - ecc_bytes = caps->calc_ecc_bytes(step_size, strength); + ecc_bytes = caps->calc_ecc_bytes(ecc, step_size, + strength); if (WARN_ON_ONCE(ecc_bytes < 0)) continue; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 5dad59b..e7c7fdb 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -507,44 +507,6 @@ static inline void nand_hw_control_init(struct nand_hw_control *nfc) } /** - * struct nand_ecc_step_info - ECC step information of ECC engine - * @stepsize: data bytes per ECC step - * @strengths: array of supported strengths - * @nstrengths: number of supported strengths - */ -struct nand_ecc_step_info { - int stepsize; - const int *strengths; - int nstrengths; -}; - -/** - * struct nand_ecc_caps - capability of ECC engine - * @stepinfos: array of ECC step information - * @nstepinfos: number of ECC step information - * @calc_ecc_bytes: driver's hook to calculate ECC bytes per step - */ -struct nand_ecc_caps { - const struct nand_ecc_step_info *stepinfos; - int nstepinfos; - int (*calc_ecc_bytes)(int step_size, int strength); -}; - -/* a shorthand to generate struct nand_ecc_caps with only one ECC stepsize */ -#define NAND_ECC_CAPS_SINGLE(__name, __calc, __step, ...) \ -static const int __name##_strengths[] = { __VA_ARGS__ }; \ -static const struct nand_ecc_step_info __name##_stepinfo = { \ - .stepsize = __step, \ - .strengths = __name##_strengths, \ - .nstrengths = ARRAY_SIZE(__name##_strengths), \ -}; \ -static const struct nand_ecc_caps __name = { \ - .stepinfos = &__name##_stepinfo, \ - .nstepinfos = 1, \ - .calc_ecc_bytes = __calc, \ -} - -/** * struct nand_ecc_ctrl - Control structure for ECC * @mode: ECC mode * @algo: ECC algorithm @@ -639,6 +601,45 @@ struct nand_ecc_ctrl { }; /** + * struct nand_ecc_step_info - ECC step information of ECC engine + * @stepsize: data bytes per ECC step + * @strengths: array of supported strengths + * @nstrengths: number of supported strengths + */ +struct nand_ecc_step_info { + int stepsize; + const int *strengths; + int nstrengths; +}; + +/** + * struct nand_ecc_caps - capability of ECC engine + * @stepinfos: array of ECC step information + * @nstepinfos: number of ECC step information + * @calc_ecc_bytes: driver's hook to calculate ECC bytes per step + */ +struct nand_ecc_caps { + const struct nand_ecc_step_info *stepinfos; + int nstepinfos; + int (*calc_ecc_bytes)(struct nand_ecc_ctrl *ecc, int step_size, + int strength); +}; + +/* a shorthand to generate struct nand_ecc_caps with only one ECC stepsize */ +#define NAND_ECC_CAPS_SINGLE(__name, __calc, __step, ...) \ +static const int __name##_strengths[] = { __VA_ARGS__ }; \ +static const struct nand_ecc_step_info __name##_stepinfo = { \ + .stepsize = __step, \ + .strengths = __name##_strengths, \ + .nstrengths = ARRAY_SIZE(__name##_strengths), \ +}; \ +static const struct nand_ecc_caps __name = { \ + .stepinfos = &__name##_stepinfo, \ + .nstepinfos = 1, \ + .calc_ecc_bytes = __calc, \ +} + +/** * struct nand_sdr_timings - SDR NAND chip timings * * This struct defines the timing requirements of a SDR NAND chip.