35912cd2cd6b81d6bea1e7b5d78703bfba782e04
[openwrt/staging/ldir.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 --- a/drivers/mtd/nand/spi/core.c
31 +++ b/drivers/mtd/nand/spi/core.c
32 @@ -381,7 +381,10 @@ static int spinand_read_from_cache_op(st
33 }
34 }
35
36 - rdesc = spinand->dirmaps[req->pos.plane].rdesc;
37 + if (req->mode == MTD_OPS_RAW)
38 + rdesc = spinand->dirmaps[req->pos.plane].rdesc;
39 + else
40 + rdesc = spinand->dirmaps[req->pos.plane].rdesc_ecc;
41
42 while (nbytes) {
43 ret = spi_mem_dirmap_read(rdesc, column, nbytes, buf);
44 @@ -452,7 +455,10 @@ static int spinand_write_to_cache_op(str
45 req->ooblen);
46 }
47
48 - wdesc = spinand->dirmaps[req->pos.plane].wdesc;
49 + if (req->mode == MTD_OPS_RAW)
50 + wdesc = spinand->dirmaps[req->pos.plane].wdesc;
51 + else
52 + wdesc = spinand->dirmaps[req->pos.plane].wdesc_ecc;
53
54 while (nbytes) {
55 ret = spi_mem_dirmap_write(wdesc, column, nbytes, buf);
56 @@ -875,6 +881,31 @@ static int spinand_create_dirmap(struct
57
58 spinand->dirmaps[plane].rdesc = desc;
59
60 + if (nand->ecc.engine->integration != NAND_ECC_ENGINE_INTEGRATION_PIPELINED) {
61 + spinand->dirmaps[plane].wdesc_ecc = spinand->dirmaps[plane].wdesc;
62 + spinand->dirmaps[plane].rdesc_ecc = spinand->dirmaps[plane].rdesc;
63 +
64 + return 0;
65 + }
66 +
67 + info.op_tmpl = *spinand->op_templates.update_cache;
68 + info.op_tmpl.data.ecc = true;
69 + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
70 + spinand->spimem, &info);
71 + if (IS_ERR(desc))
72 + return PTR_ERR(desc);
73 +
74 + spinand->dirmaps[plane].wdesc_ecc = desc;
75 +
76 + info.op_tmpl = *spinand->op_templates.read_cache;
77 + info.op_tmpl.data.ecc = true;
78 + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
79 + spinand->spimem, &info);
80 + if (IS_ERR(desc))
81 + return PTR_ERR(desc);
82 +
83 + spinand->dirmaps[plane].rdesc_ecc = desc;
84 +
85 return 0;
86 }
87
88 --- a/include/linux/mtd/spinand.h
89 +++ b/include/linux/mtd/spinand.h
90 @@ -392,6 +392,8 @@ struct spinand_info {
91 struct spinand_dirmap {
92 struct spi_mem_dirmap_desc *wdesc;
93 struct spi_mem_dirmap_desc *rdesc;
94 + struct spi_mem_dirmap_desc *wdesc_ecc;
95 + struct spi_mem_dirmap_desc *rdesc_ecc;
96 };
97
98 /**