Skip to content

Commit 6e88127

Browse files
ambarusmiquelraynal
authored andcommitted
mtd: rawnand: Introduce nand_set_ecc_on_host_ops()
There were too many levels of indentation and the code was hard to read. Introduce a new function, similar to nand_set_ecc_soft_ops(). Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20200917075213.532161-3-tudor.ambarus@microchip.com
1 parent d27c985 commit 6e88127

1 file changed

Lines changed: 61 additions & 53 deletions

File tree

drivers/mtd/nand/raw/nand_base.c

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5139,6 +5139,65 @@ static void nand_scan_ident_cleanup(struct nand_chip *chip)
51395139
kfree(chip->parameters.onfi);
51405140
}
51415141

5142+
static int nand_set_ecc_on_host_ops(struct nand_chip *chip)
5143+
{
5144+
struct nand_ecc_ctrl *ecc = &chip->ecc;
5145+
5146+
switch (ecc->placement) {
5147+
case NAND_ECC_PLACEMENT_UNKNOWN:
5148+
case NAND_ECC_PLACEMENT_OOB:
5149+
/* Use standard hwecc read page function? */
5150+
if (!ecc->read_page)
5151+
ecc->read_page = nand_read_page_hwecc;
5152+
if (!ecc->write_page)
5153+
ecc->write_page = nand_write_page_hwecc;
5154+
if (!ecc->read_page_raw)
5155+
ecc->read_page_raw = nand_read_page_raw;
5156+
if (!ecc->write_page_raw)
5157+
ecc->write_page_raw = nand_write_page_raw;
5158+
if (!ecc->read_oob)
5159+
ecc->read_oob = nand_read_oob_std;
5160+
if (!ecc->write_oob)
5161+
ecc->write_oob = nand_write_oob_std;
5162+
if (!ecc->read_subpage)
5163+
ecc->read_subpage = nand_read_subpage;
5164+
if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
5165+
ecc->write_subpage = nand_write_subpage_hwecc;
5166+
fallthrough;
5167+
5168+
case NAND_ECC_PLACEMENT_INTERLEAVED:
5169+
if ((!ecc->calculate || !ecc->correct || !ecc->hwctl) &&
5170+
(!ecc->read_page ||
5171+
ecc->read_page == nand_read_page_hwecc ||
5172+
!ecc->write_page ||
5173+
ecc->write_page == nand_write_page_hwecc)) {
5174+
WARN(1, "No ECC functions supplied; hardware ECC not possible\n");
5175+
return -EINVAL;
5176+
}
5177+
/* Use standard syndrome read/write page function? */
5178+
if (!ecc->read_page)
5179+
ecc->read_page = nand_read_page_syndrome;
5180+
if (!ecc->write_page)
5181+
ecc->write_page = nand_write_page_syndrome;
5182+
if (!ecc->read_page_raw)
5183+
ecc->read_page_raw = nand_read_page_raw_syndrome;
5184+
if (!ecc->write_page_raw)
5185+
ecc->write_page_raw = nand_write_page_raw_syndrome;
5186+
if (!ecc->read_oob)
5187+
ecc->read_oob = nand_read_oob_syndrome;
5188+
if (!ecc->write_oob)
5189+
ecc->write_oob = nand_write_oob_syndrome;
5190+
break;
5191+
5192+
default:
5193+
pr_warn("Invalid NAND_ECC_PLACEMENT %d\n",
5194+
ecc->placement);
5195+
return -EINVAL;
5196+
}
5197+
5198+
return 0;
5199+
}
5200+
51425201
static int nand_set_ecc_soft_ops(struct nand_chip *chip)
51435202
{
51445203
struct mtd_info *mtd = nand_to_mtd(chip);
@@ -5619,60 +5678,9 @@ static int nand_scan_tail(struct nand_chip *chip)
56195678

56205679
switch (ecc->engine_type) {
56215680
case NAND_ECC_ENGINE_TYPE_ON_HOST:
5622-
5623-
switch (ecc->placement) {
5624-
case NAND_ECC_PLACEMENT_UNKNOWN:
5625-
case NAND_ECC_PLACEMENT_OOB:
5626-
/* Use standard hwecc read page function? */
5627-
if (!ecc->read_page)
5628-
ecc->read_page = nand_read_page_hwecc;
5629-
if (!ecc->write_page)
5630-
ecc->write_page = nand_write_page_hwecc;
5631-
if (!ecc->read_page_raw)
5632-
ecc->read_page_raw = nand_read_page_raw;
5633-
if (!ecc->write_page_raw)
5634-
ecc->write_page_raw = nand_write_page_raw;
5635-
if (!ecc->read_oob)
5636-
ecc->read_oob = nand_read_oob_std;
5637-
if (!ecc->write_oob)
5638-
ecc->write_oob = nand_write_oob_std;
5639-
if (!ecc->read_subpage)
5640-
ecc->read_subpage = nand_read_subpage;
5641-
if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
5642-
ecc->write_subpage = nand_write_subpage_hwecc;
5643-
fallthrough;
5644-
5645-
case NAND_ECC_PLACEMENT_INTERLEAVED:
5646-
if ((!ecc->calculate || !ecc->correct || !ecc->hwctl) &&
5647-
(!ecc->read_page ||
5648-
ecc->read_page == nand_read_page_hwecc ||
5649-
!ecc->write_page ||
5650-
ecc->write_page == nand_write_page_hwecc)) {
5651-
WARN(1, "No ECC functions supplied; hardware ECC not possible\n");
5652-
ret = -EINVAL;
5653-
goto err_nand_manuf_cleanup;
5654-
}
5655-
/* Use standard syndrome read/write page function? */
5656-
if (!ecc->read_page)
5657-
ecc->read_page = nand_read_page_syndrome;
5658-
if (!ecc->write_page)
5659-
ecc->write_page = nand_write_page_syndrome;
5660-
if (!ecc->read_page_raw)
5661-
ecc->read_page_raw = nand_read_page_raw_syndrome;
5662-
if (!ecc->write_page_raw)
5663-
ecc->write_page_raw = nand_write_page_raw_syndrome;
5664-
if (!ecc->read_oob)
5665-
ecc->read_oob = nand_read_oob_syndrome;
5666-
if (!ecc->write_oob)
5667-
ecc->write_oob = nand_write_oob_syndrome;
5668-
break;
5669-
5670-
default:
5671-
pr_warn("Invalid NAND_ECC_PLACEMENT %d\n",
5672-
ecc->placement);
5673-
ret = -EINVAL;
5681+
ret = nand_set_ecc_on_host_ops(chip);
5682+
if (ret)
56745683
goto err_nand_manuf_cleanup;
5675-
}
56765684

56775685
if (mtd->writesize >= ecc->size) {
56785686
if (!ecc->strength) {

0 commit comments

Comments
 (0)