aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mtd
diff options
context:
space:
mode:
authorBoris Brezillon <boris.brezillon@free-electrons.com>2016-02-03 13:01:31 -0500
committerBoris Brezillon <boris.brezillon@free-electrons.com>2016-04-19 16:05:55 -0400
commitadbbc3bc827eb1f43a932d783f09ba55c8ec8379 (patch)
treeab56a88178983e991113dc80d2350496627bcdea /include/linux/mtd
parent06af3b023c016bf97e39fbe22087b1d974f9e474 (diff)
mtd: create an mtd_ooblayout_ops struct to ease ECC layout definition
ECC layout definitions are currently exposed using the nand_ecclayout struct which embeds oobfree and eccpos arrays with predefined size. This approach was acceptable when NAND chips were providing relatively small OOB regions, but MLC and TLC now provide OOB regions of several hundreds of bytes, which implies a non negligible overhead for everybody even those who only need to support legacy NANDs. Create an mtd_ooblayout_ops interface providing the same functionality (expose the ECC and oobfree layout) without the need for this huge structure. The mtd->ecclayout is now deprecated and should be replaced by the equivalent mtd_ooblayout_ops. In the meantime we provide a wrapper around the ->ecclayout field to ease migration to this new model. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Diffstat (limited to 'include/linux/mtd')
-rw-r--r--include/linux/mtd/mtd.h32
1 files changed, 28 insertions, 4 deletions
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index e62da8462493..177bf314ad70 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -101,6 +101,9 @@ struct mtd_oob_ops {
101 * similar, smaller struct nand_ecclayout_user (in mtd-abi.h) that is retained 101 * similar, smaller struct nand_ecclayout_user (in mtd-abi.h) that is retained
102 * for export to user-space via the ECCGETLAYOUT ioctl. 102 * for export to user-space via the ECCGETLAYOUT ioctl.
103 * nand_ecclayout should be expandable in the future simply by the above macros. 103 * nand_ecclayout should be expandable in the future simply by the above macros.
104 *
105 * This structure is now deprecated, you should use struct nand_ecclayout_ops
106 * to describe your OOB layout.
104 */ 107 */
105struct nand_ecclayout { 108struct nand_ecclayout {
106 __u32 eccbytes; 109 __u32 eccbytes;
@@ -123,6 +126,22 @@ struct mtd_oob_region {
123 u32 length; 126 u32 length;
124}; 127};
125 128
129/*
130 * struct mtd_ooblayout_ops - NAND OOB layout operations
131 * @ecc: function returning an ECC region in the OOB area.
132 * Should return -ERANGE if %section exceeds the total number of
133 * ECC sections.
134 * @free: function returning a free region in the OOB area.
135 * Should return -ERANGE if %section exceeds the total number of
136 * free sections.
137 */
138struct mtd_ooblayout_ops {
139 int (*ecc)(struct mtd_info *mtd, int section,
140 struct mtd_oob_region *oobecc);
141 int (*free)(struct mtd_info *mtd, int section,
142 struct mtd_oob_region *oobfree);
143};
144
126struct module; /* only needed for owner field in mtd_info */ 145struct module; /* only needed for owner field in mtd_info */
127 146
128struct mtd_info { 147struct mtd_info {
@@ -181,9 +200,12 @@ struct mtd_info {
181 const char *name; 200 const char *name;
182 int index; 201 int index;
183 202
184 /* ECC layout structure pointer - read only! */ 203 /* [Deprecated] ECC layout structure pointer - read only! */
185 struct nand_ecclayout *ecclayout; 204 struct nand_ecclayout *ecclayout;
186 205
206 /* OOB layout description */
207 const struct mtd_ooblayout_ops *ooblayout;
208
187 /* the ecc step size. */ 209 /* the ecc step size. */
188 unsigned int ecc_step_size; 210 unsigned int ecc_step_size;
189 211
@@ -286,10 +308,12 @@ int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
286int mtd_ooblayout_count_freebytes(struct mtd_info *mtd); 308int mtd_ooblayout_count_freebytes(struct mtd_info *mtd);
287int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd); 309int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd);
288 310
289static inline void mtd_set_ecclayout(struct mtd_info *mtd, 311void mtd_set_ecclayout(struct mtd_info *mtd, struct nand_ecclayout *ecclayout);
290 struct nand_ecclayout *ecclayout) 312
313static inline void mtd_set_ooblayout(struct mtd_info *mtd,
314 const struct mtd_ooblayout_ops *ooblayout)
291{ 315{
292 mtd->ecclayout = ecclayout; 316 mtd->ooblayout = ooblayout;
293} 317}
294 318
295static inline void mtd_set_of_node(struct mtd_info *mtd, 319static inline void mtd_set_of_node(struct mtd_info *mtd,