From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Xiaolei Li <xiaolei.li@mediatek.com>
Cc: <richard@nod.at>,
linux-mediatek@lists.infradead.org,
linux-mtd@lists.infradead.org, srv_heupstream@mediatek.com
Subject: Re: [PATCH 5/8] mtd: rawnand: Modify ->calc_ecc_bytes() hook in nand_ecc_caps
Date: Wed, 11 Apr 2018 20:57:57 +0200 [thread overview]
Message-ID: <20180411205757.06495b7b@bbrezillon> (raw)
In-Reply-To: <1523418118-57686-6-git-send-email-xiaolei.li@mediatek.com>
On Wed, 11 Apr 2018 11:41:55 +0800
Xiaolei Li <xiaolei.li@mediatek.com> wrote:
> 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.
I'm not fond of this approach. Why don't you provide a different
function for the 2 cases you have (parity = 13 and parity = 14)?
>
> Signed-off-by: Xiaolei Li <xiaolei.li@mediatek.com>
> ---
> 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.
next prev parent reply other threads:[~2018-04-11 18:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-11 3:41 [PATCH 0/8] Improve MTK NAND driver and ->calc_ecc_bytes() hook Xiaolei Li
2018-04-11 3:41 ` [PATCH 1/8] dt-bindings: mtd: mtk-nand: Update properties description Xiaolei Li
2018-04-11 3:41 ` [PATCH 2/8] MAINTAINERS: Add entry for Mediatek NAND controller driver Xiaolei Li
2018-04-11 3:41 ` [PATCH 3/8] mtd: rawnand: mtk: Add DT property mtk,fdm-ecc-size Xiaolei Li
2018-04-11 19:13 ` Boris Brezillon
2018-04-12 5:36 ` xiaolei li
2018-04-11 3:41 ` [PATCH 4/8] mtd: rawnand: mtk: Remove max_sector_size from struct mtk_nfc_caps Xiaolei Li
2018-04-11 3:41 ` [PATCH 5/8] mtd: rawnand: Modify ->calc_ecc_bytes() hook in nand_ecc_caps Xiaolei Li
2018-04-11 18:57 ` Boris Brezillon [this message]
2018-04-12 5:44 ` xiaolei li
2018-04-11 3:41 ` [PATCH 6/8] mtd: rawnand: mtk: Introduce mtk_ecc_calc_parity_bytes() function Xiaolei Li
2018-04-11 3:41 ` [PATCH 7/8] mtd: rawnand: mtk: Introduce mtk_ecc_get_strength_num(), mtk_ecc_get_strength() Xiaolei Li
2018-04-11 3:41 ` [PATCH 8/8] mtd: rawnand: mtk: Use generic helpers to calculate ecc size and strength Xiaolei Li
2018-04-11 19:05 ` Boris Brezillon
2018-04-12 5:43 ` xiaolei li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180411205757.06495b7b@bbrezillon \
--to=boris.brezillon@bootlin.com \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=srv_heupstream@mediatek.com \
--cc=xiaolei.li@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox