Re: [PATCH v6 1/1] EDAC, mellanox: Add ECC support for BlueField DDR4

From: Joe Perches
Date: Mon Jun 24 2019 - 15:57:04 EST


On Mon, 2019-06-24 at 14:42 -0400, Shravan Kumar Ramani wrote:
> Add ECC support for Mellanox BlueField SoC DDR controller.
> This requires SMC to the running Arm Trusted Firmware to report
> what is the current memory configuration.
[]
> diff --git a/drivers/edac/bluefield_edac.c b/drivers/edac/bluefield_edac.c
[]
> @@ -0,0 +1,381 @@
[]
> +#define MLXBF_ECC_CNT__SERR_CNT_SHIFT 0
> +#define MLXBF_ECC_CNT__SERR_CNT_MASK 0xffff
> +#define MLXBF_ECC_CNT__DERR_CNT_SHIFT 16
> +#define MLXBF_ECC_CNT__DERR_CNT_MASK 0xffff

[multiple variants of #defines like the above]

[]

> + serr = (dram_syndrom >> MLXBF_SYNDROM__SERR_SHIFT) &
> + MLXBF_SYNDROM__SERR_MASK;
> + derr = (dram_syndrom >> MLXBF_SYNDROM__DERR_SHIFT) &
> + MLXBF_SYNDROM__DERR_MASK;
> + syndrom = (dram_syndrom >> MLXBF_SYNDROM__SYN_SHIFT) &
> + MLXBF_SYNDROM__SYN_MASK;

To improve readability and reduce possible copy/paste errors,
these would all benefit from a macro like

#define MLXBF_SM(val, type) \
(((val) >> (MLXBF_ ## type ## _SHIFT)) & (MLXBF_ ## type ## _MASK)))

So these uses could become:

serr = MLXBF_SM(dram_syndrom, SYNDROM__SERR);
derr = MLXBF_SM(dram_syndrom, SYNDROM__DERR);
syndrom =
MLXBF_SM(dram_syndrom, SYN);

etc...