ee3a6d384f90c6774ab2938fe424c38d1f4fb6d2
[openwrt/openwrt.git] /
1 From eb4a2d282c3c5752211d69be6dff2674119e5583 Mon Sep 17 00:00:00 2001
2 From: Miquel Raynal <miquel.raynal@bootlin.com>
3 Date: Thu, 27 Jan 2022 10:18:03 +0100
4 Subject: [PATCH 09/15] mtd: spinand: Create direct mapping descriptors for ECC
5 operations
6
7 In order for pipelined ECC engines to be able to enable/disable the ECC
8 engine only when needed and avoid races when future parallel-operations
9 will be supported, we need to provide the information about the use of
10 the ECC engine in the direct mapping hooks. As direct mapping
11 configurations are meant to be static, it is best to create two new
12 mappings: one for regular 'raw' accesses and one for accesses involving
13 correction. It is up to the driver to use or not the new ECC enable
14 boolean contained in the spi-mem operation.
15
16 As dirmaps are not free (they consume a few pages of MMIO address space)
17 and because these extra entries are only meant to be used by pipelined
18 engines, let's limit their use to this specific type of engine and save
19 a bit of memory with all the other setups.
20
21 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
22 Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
23 Link: https://lore.kernel.org/linux-mtd/20220127091808.1043392-9-miquel.raynal@bootlin.com
24 (cherry picked from commit f9d7c7265bcff7d9a17425a8cddf702e8fe159c2)
25 ---
26 drivers/mtd/nand/spi/core.c | 35 +++++++++++++++++++++++++++++++++--
27 include/linux/mtd/spinand.h | 2 ++
28 2 files changed, 35 insertions(+), 2 deletions(-)
29
30 diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
31 index bb6b026b558b..ff8336870bc0 100644
32 --- a/drivers/mtd/nand/spi/core.c
33 +++ b/drivers/mtd/nand/spi/core.c
34 @@ -381,7 +381,10 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
35 }
36 }
37
38 - rdesc = spinand->dirmaps[req->pos.plane].rdesc;
39 + if (req->mode == MTD_OPS_RAW)
40 + rdesc = spinand->dirmaps[req->pos.plane].rdesc;
41 + else
42 + rdesc = spinand->dirmaps[req->pos.plane].rdesc_ecc;
43
44 while (nbytes) {
45 ret = spi_mem_dirmap_read(rdesc, column, nbytes, buf);
46 @@ -452,7 +455,10 @@ static int spinand_write_to_cache_op(struct spinand_device *spinand,
47 req->ooblen);
48 }
49
50 - wdesc = spinand->dirmaps[req->pos.plane].wdesc;
51 + if (req->mode == MTD_OPS_RAW)
52 + wdesc = spinand->dirmaps[req->pos.plane].wdesc;
53 + else
54 + wdesc = spinand->dirmaps[req->pos.plane].wdesc_ecc;
55
56 while (nbytes) {
57 ret = spi_mem_dirmap_write(wdesc, column, nbytes, buf);
58 @@ -865,6 +871,31 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
59
60 spinand->dirmaps[plane].rdesc = desc;
61
62 + if (nand->ecc.engine->integration != NAND_ECC_ENGINE_INTEGRATION_PIPELINED) {
63 + spinand->dirmaps[plane].wdesc_ecc = spinand->dirmaps[plane].wdesc;
64 + spinand->dirmaps[plane].rdesc_ecc = spinand->dirmaps[plane].rdesc;
65 +
66 + return 0;
67 + }
68 +
69 + info.op_tmpl = *spinand->op_templates.update_cache;
70 + info.op_tmpl.data.ecc = true;
71 + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
72 + spinand->spimem, &info);
73 + if (IS_ERR(desc))
74 + return PTR_ERR(desc);
75 +
76 + spinand->dirmaps[plane].wdesc_ecc = desc;
77 +
78 + info.op_tmpl = *spinand->op_templates.read_cache;
79 + info.op_tmpl.data.ecc = true;
80 + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
81 + spinand->spimem, &info);
82 + if (IS_ERR(desc))
83 + return PTR_ERR(desc);
84 +
85 + spinand->dirmaps[plane].rdesc_ecc = desc;
86 +
87 return 0;
88 }
89
90 diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h
91 index 6988956b8492..3aa28240a77f 100644
92 --- a/include/linux/mtd/spinand.h
93 +++ b/include/linux/mtd/spinand.h
94 @@ -389,6 +389,8 @@ struct spinand_info {
95 struct spinand_dirmap {
96 struct spi_mem_dirmap_desc *wdesc;
97 struct spi_mem_dirmap_desc *rdesc;
98 + struct spi_mem_dirmap_desc *wdesc_ecc;
99 + struct spi_mem_dirmap_desc *rdesc_ecc;
100 };
101
102 /**
103 --
104 2.35.1
105