1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright 2017 - Free Electrons
6 * Boris Brezillon <boris.brezillon@free-electrons.com>
7 * Peter Pan <peterpandong@micron.com>
10 #ifndef __LINUX_MTD_NAND_H
11 #define __LINUX_MTD_NAND_H
13 #include <linux/mtd/mtd.h>
18 * struct nand_memory_organization - Memory organization structure
19 * @bits_per_cell: number of bits per NAND cell
20 * @pagesize: page size
21 * @oobsize: OOB area size
22 * @pages_per_eraseblock: number of pages per eraseblock
23 * @eraseblocks_per_lun: number of eraseblocks per LUN (Logical Unit Number)
24 * @max_bad_eraseblocks_per_lun: maximum number of eraseblocks per LUN
25 * @planes_per_lun: number of planes per LUN
26 * @luns_per_target: number of LUN per target (target is a synonym for die)
27 * @ntargets: total number of targets exposed by the NAND device
29 struct nand_memory_organization {
30 unsigned int bits_per_cell;
31 unsigned int pagesize;
33 unsigned int pages_per_eraseblock;
34 unsigned int eraseblocks_per_lun;
35 unsigned int max_bad_eraseblocks_per_lun;
36 unsigned int planes_per_lun;
37 unsigned int luns_per_target;
38 unsigned int ntargets;
41 #define NAND_MEMORG(bpc, ps, os, ppe, epl, mbb, ppl, lpt, nt) \
43 .bits_per_cell = (bpc), \
46 .pages_per_eraseblock = (ppe), \
47 .eraseblocks_per_lun = (epl), \
48 .max_bad_eraseblocks_per_lun = (mbb), \
49 .planes_per_lun = (ppl), \
50 .luns_per_target = (lpt), \
55 * struct nand_row_converter - Information needed to convert an absolute offset
57 * @lun_addr_shift: position of the LUN identifier in the row address
58 * @eraseblock_addr_shift: position of the eraseblock identifier in the row
61 struct nand_row_converter {
62 unsigned int lun_addr_shift;
63 unsigned int eraseblock_addr_shift;
67 * struct nand_pos - NAND position object
68 * @target: the NAND target/die
69 * @lun: the LUN identifier
70 * @plane: the plane within the LUN
71 * @eraseblock: the eraseblock within the LUN
72 * @page: the page within the LUN
74 * These information are usually used by specific sub-layers to select the
75 * appropriate target/die and generate a row address to pass to the device.
81 unsigned int eraseblock;
86 * enum nand_page_io_req_type - Direction of an I/O request
87 * @NAND_PAGE_READ: from the chip, to the controller
88 * @NAND_PAGE_WRITE: from the controller, to the chip
90 enum nand_page_io_req_type {
96 * struct nand_page_io_req - NAND I/O request object
97 * @type: the type of page I/O: read or write
98 * @pos: the position this I/O request is targeting
99 * @dataoffs: the offset within the page
100 * @datalen: number of data bytes to read from/write to this page
101 * @databuf: buffer to store data in or get data from
102 * @ooboffs: the OOB offset within the page
103 * @ooblen: the number of OOB bytes to read from/write to this page
104 * @oobbuf: buffer to store OOB data in or get OOB data from
105 * @mode: one of the %MTD_OPS_XXX mode
107 * This object is used to pass per-page I/O requests to NAND sub-layers. This
108 * way all useful information are already formatted in a useful way and
109 * specific NAND layers can focus on translating these information into
110 * specific commands/operations.
112 struct nand_page_io_req {
113 enum nand_page_io_req_type type;
115 unsigned int dataoffs;
116 unsigned int datalen;
121 unsigned int ooboffs;
130 const struct mtd_ooblayout_ops *nand_get_small_page_ooblayout(void);
131 const struct mtd_ooblayout_ops *nand_get_large_page_ooblayout(void);
132 const struct mtd_ooblayout_ops *nand_get_large_page_hamming_ooblayout(void);
135 * enum nand_ecc_engine_type - NAND ECC engine type
136 * @NAND_ECC_ENGINE_TYPE_INVALID: Invalid value
137 * @NAND_ECC_ENGINE_TYPE_NONE: No ECC correction
138 * @NAND_ECC_ENGINE_TYPE_SOFT: Software ECC correction
139 * @NAND_ECC_ENGINE_TYPE_ON_HOST: On host hardware ECC correction
140 * @NAND_ECC_ENGINE_TYPE_ON_DIE: On chip hardware ECC correction
142 enum nand_ecc_engine_type {
143 NAND_ECC_ENGINE_TYPE_INVALID,
144 NAND_ECC_ENGINE_TYPE_NONE,
145 NAND_ECC_ENGINE_TYPE_SOFT,
146 NAND_ECC_ENGINE_TYPE_ON_HOST,
147 NAND_ECC_ENGINE_TYPE_ON_DIE,
151 * enum nand_ecc_placement - NAND ECC bytes placement
152 * @NAND_ECC_PLACEMENT_UNKNOWN: The actual position of the ECC bytes is unknown
153 * @NAND_ECC_PLACEMENT_OOB: The ECC bytes are located in the OOB area
154 * @NAND_ECC_PLACEMENT_INTERLEAVED: Syndrome layout, there are ECC bytes
155 * interleaved with regular data in the main
158 enum nand_ecc_placement {
159 NAND_ECC_PLACEMENT_UNKNOWN,
160 NAND_ECC_PLACEMENT_OOB,
161 NAND_ECC_PLACEMENT_INTERLEAVED,
165 * enum nand_ecc_algo - NAND ECC algorithm
166 * @NAND_ECC_ALGO_UNKNOWN: Unknown algorithm
167 * @NAND_ECC_ALGO_HAMMING: Hamming algorithm
168 * @NAND_ECC_ALGO_BCH: Bose-Chaudhuri-Hocquenghem algorithm
169 * @NAND_ECC_ALGO_RS: Reed-Solomon algorithm
172 NAND_ECC_ALGO_UNKNOWN,
173 NAND_ECC_ALGO_HAMMING,
179 * struct nand_ecc_props - NAND ECC properties
180 * @engine_type: ECC engine type
181 * @placement: OOB placement (if relevant)
182 * @algo: ECC algorithm (if relevant)
183 * @strength: ECC strength
184 * @step_size: Number of bytes per step
185 * @flags: Misc properties
187 struct nand_ecc_props {
188 enum nand_ecc_engine_type engine_type;
189 enum nand_ecc_placement placement;
190 enum nand_ecc_algo algo;
191 unsigned int strength;
192 unsigned int step_size;
196 #define NAND_ECCREQ(str, stp) { .strength = (str), .step_size = (stp) }
198 /* NAND ECC misc flags */
199 #define NAND_ECC_MAXIMIZE_STRENGTH BIT(0)
202 * struct nand_bbt - bad block table object
203 * @cache: in memory BBT cache
206 unsigned long *cache;
210 * struct nand_ops - NAND operations
211 * @erase: erase a specific block. No need to check if the block is bad before
212 * erasing, this has been taken care of by the generic NAND layer
213 * @markbad: mark a specific block bad. No need to check if the block is
214 * already marked bad, this has been taken care of by the generic
215 * NAND layer. This method should just write the BBM (Bad Block
216 * Marker) so that future call to struct_nand_ops->isbad() return
218 * @isbad: check whether a block is bad or not. This method should just read
219 * the BBM and return whether the block is bad or not based on what it
222 * These are all low level operations that should be implemented by specialized
223 * NAND layers (SPI NAND, raw NAND, ...).
226 int (*erase)(struct nand_device *nand, const struct nand_pos *pos);
227 int (*markbad)(struct nand_device *nand, const struct nand_pos *pos);
228 bool (*isbad)(struct nand_device *nand, const struct nand_pos *pos);
232 * struct nand_ecc_context - Context for the ECC engine
233 * @conf: basic ECC engine parameters
234 * @total: total number of bytes used for storing ECC codes, this is used by
235 * generic OOB layouts
236 * @priv: ECC engine driver private data
238 struct nand_ecc_context {
239 struct nand_ecc_props conf;
245 * struct nand_ecc_engine_ops - ECC engine operations
246 * @init_ctx: given a desired user configuration for the pointed NAND device,
247 * requests the ECC engine driver to setup a configuration with
248 * values it supports.
249 * @cleanup_ctx: clean the context initialized by @init_ctx.
250 * @prepare_io_req: is called before reading/writing a page to prepare the I/O
251 * request to be performed with ECC correction.
252 * @finish_io_req: is called after reading/writing a page to terminate the I/O
253 * request and ensure proper ECC correction.
255 struct nand_ecc_engine_ops {
256 int (*init_ctx)(struct nand_device *nand);
257 void (*cleanup_ctx)(struct nand_device *nand);
258 int (*prepare_io_req)(struct nand_device *nand,
259 struct nand_page_io_req *req);
260 int (*finish_io_req)(struct nand_device *nand,
261 struct nand_page_io_req *req);
265 * struct nand_ecc_engine - ECC engine abstraction for NAND devices
266 * @ops: ECC engine operations
268 struct nand_ecc_engine {
269 struct nand_ecc_engine_ops *ops;
272 void of_get_nand_ecc_user_config(struct nand_device *nand);
273 int nand_ecc_init_ctx(struct nand_device *nand);
274 void nand_ecc_cleanup_ctx(struct nand_device *nand);
275 int nand_ecc_prepare_io_req(struct nand_device *nand,
276 struct nand_page_io_req *req);
277 int nand_ecc_finish_io_req(struct nand_device *nand,
278 struct nand_page_io_req *req);
279 bool nand_ecc_is_strong_enough(struct nand_device *nand);
282 * struct nand_ecc - Information relative to the ECC
283 * @defaults: Default values, depend on the underlying subsystem
284 * @requirements: ECC requirements from the NAND chip perspective
285 * @user_conf: User desires in terms of ECC parameters
286 * @ctx: ECC context for the ECC engine, derived from the device @requirements
287 * the @user_conf and the @defaults
288 * @ondie_engine: On-die ECC engine reference, if any
289 * @engine: ECC engine actually bound
292 struct nand_ecc_props defaults;
293 struct nand_ecc_props requirements;
294 struct nand_ecc_props user_conf;
295 struct nand_ecc_context ctx;
296 struct nand_ecc_engine *ondie_engine;
297 struct nand_ecc_engine *engine;
301 * struct nand_device - NAND device
302 * @mtd: MTD instance attached to the NAND device
303 * @memorg: memory layout
304 * @ecc: NAND ECC object attached to the NAND device
305 * @rowconv: position to row address converter
306 * @bbt: bad block table info
307 * @ops: NAND operations attached to the NAND device
309 * Generic NAND object. Specialized NAND layers (raw NAND, SPI NAND, OneNAND)
310 * should declare their own NAND object embedding a nand_device struct (that's
311 * how inheritance is done).
312 * struct_nand_device->memorg and struct_nand_device->ecc.requirements should
313 * be filled at device detection time to reflect the NAND device
314 * capabilities/requirements. Once this is done nanddev_init() can be called.
315 * It will take care of converting NAND information into MTD ones, which means
316 * the specialized NAND layers should never manually tweak
317 * struct_nand_device->mtd except for the ->_read/write() hooks.
321 struct nand_memory_organization memorg;
323 struct nand_row_converter rowconv;
325 const struct nand_ops *ops;
329 * struct nand_io_iter - NAND I/O iterator
330 * @req: current I/O request
331 * @oobbytes_per_page: maximum number of OOB bytes per page
332 * @dataleft: remaining number of data bytes to read/write
333 * @oobleft: remaining number of OOB bytes to read/write
335 * Can be used by specialized NAND layers to iterate over all pages covered
336 * by an MTD I/O request, which should greatly simplifies the boiler-plate
337 * code needed to read/write data from/to a NAND device.
339 struct nand_io_iter {
340 struct nand_page_io_req req;
341 unsigned int oobbytes_per_page;
342 unsigned int dataleft;
343 unsigned int oobleft;
347 * mtd_to_nanddev() - Get the NAND device attached to the MTD instance
350 * Return: the NAND device embedding @mtd.
352 static inline struct nand_device *mtd_to_nanddev(struct mtd_info *mtd)
354 return container_of(mtd, struct nand_device, mtd);
358 * nanddev_to_mtd() - Get the MTD device attached to a NAND device
361 * Return: the MTD device embedded in @nand.
363 static inline struct mtd_info *nanddev_to_mtd(struct nand_device *nand)
369 * nanddev_bits_per_cell() - Get the number of bits per cell
372 * Return: the number of bits per cell.
374 static inline unsigned int nanddev_bits_per_cell(const struct nand_device *nand)
376 return nand->memorg.bits_per_cell;
380 * nanddev_page_size() - Get NAND page size
383 * Return: the page size.
385 static inline size_t nanddev_page_size(const struct nand_device *nand)
387 return nand->memorg.pagesize;
391 * nanddev_per_page_oobsize() - Get NAND OOB size
394 * Return: the OOB size.
396 static inline unsigned int
397 nanddev_per_page_oobsize(const struct nand_device *nand)
399 return nand->memorg.oobsize;
403 * nanddev_pages_per_eraseblock() - Get the number of pages per eraseblock
406 * Return: the number of pages per eraseblock.
408 static inline unsigned int
409 nanddev_pages_per_eraseblock(const struct nand_device *nand)
411 return nand->memorg.pages_per_eraseblock;
415 * nanddev_pages_per_target() - Get the number of pages per target
418 * Return: the number of pages per target.
420 static inline unsigned int
421 nanddev_pages_per_target(const struct nand_device *nand)
423 return nand->memorg.pages_per_eraseblock *
424 nand->memorg.eraseblocks_per_lun *
425 nand->memorg.luns_per_target;
429 * nanddev_per_page_oobsize() - Get NAND erase block size
432 * Return: the eraseblock size.
434 static inline size_t nanddev_eraseblock_size(const struct nand_device *nand)
436 return nand->memorg.pagesize * nand->memorg.pages_per_eraseblock;
440 * nanddev_eraseblocks_per_lun() - Get the number of eraseblocks per LUN
443 * Return: the number of eraseblocks per LUN.
445 static inline unsigned int
446 nanddev_eraseblocks_per_lun(const struct nand_device *nand)
448 return nand->memorg.eraseblocks_per_lun;
452 * nanddev_eraseblocks_per_target() - Get the number of eraseblocks per target
455 * Return: the number of eraseblocks per target.
457 static inline unsigned int
458 nanddev_eraseblocks_per_target(const struct nand_device *nand)
460 return nand->memorg.eraseblocks_per_lun * nand->memorg.luns_per_target;
464 * nanddev_target_size() - Get the total size provided by a single target/die
467 * Return: the total size exposed by a single target/die in bytes.
469 static inline u64 nanddev_target_size(const struct nand_device *nand)
471 return (u64)nand->memorg.luns_per_target *
472 nand->memorg.eraseblocks_per_lun *
473 nand->memorg.pages_per_eraseblock *
474 nand->memorg.pagesize;
478 * nanddev_ntarget() - Get the total of targets
481 * Return: the number of targets/dies exposed by @nand.
483 static inline unsigned int nanddev_ntargets(const struct nand_device *nand)
485 return nand->memorg.ntargets;
489 * nanddev_neraseblocks() - Get the total number of eraseblocks
492 * Return: the total number of eraseblocks exposed by @nand.
494 static inline unsigned int nanddev_neraseblocks(const struct nand_device *nand)
496 return nand->memorg.ntargets * nand->memorg.luns_per_target *
497 nand->memorg.eraseblocks_per_lun;
501 * nanddev_size() - Get NAND size
504 * Return: the total size (in bytes) exposed by @nand.
506 static inline u64 nanddev_size(const struct nand_device *nand)
508 return nanddev_target_size(nand) * nanddev_ntargets(nand);
512 * nanddev_get_memorg() - Extract memory organization info from a NAND device
515 * This can be used by the upper layer to fill the memorg info before calling
518 * Return: the memorg object embedded in the NAND device.
520 static inline struct nand_memory_organization *
521 nanddev_get_memorg(struct nand_device *nand)
523 return &nand->memorg;
527 * nanddev_get_ecc_conf() - Extract the ECC configuration from a NAND device
530 static inline const struct nand_ecc_props *
531 nanddev_get_ecc_conf(struct nand_device *nand)
533 return &nand->ecc.ctx.conf;
537 * nanddev_get_ecc_requirements() - Extract the ECC requirements from a NAND
541 static inline const struct nand_ecc_props *
542 nanddev_get_ecc_requirements(struct nand_device *nand)
544 return &nand->ecc.requirements;
548 * nanddev_set_ecc_requirements() - Assign the ECC requirements of a NAND
551 * @reqs: Requirements
554 nanddev_set_ecc_requirements(struct nand_device *nand,
555 const struct nand_ecc_props *reqs)
557 nand->ecc.requirements = *reqs;
560 int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
561 struct module *owner);
562 void nanddev_cleanup(struct nand_device *nand);
565 * nanddev_register() - Register a NAND device
568 * Register a NAND device.
569 * This function is just a wrapper around mtd_device_register()
570 * registering the MTD device embedded in @nand.
572 * Return: 0 in case of success, a negative error code otherwise.
574 static inline int nanddev_register(struct nand_device *nand)
576 return mtd_device_register(&nand->mtd, NULL, 0);
580 * nanddev_unregister() - Unregister a NAND device
583 * Unregister a NAND device.
584 * This function is just a wrapper around mtd_device_unregister()
585 * unregistering the MTD device embedded in @nand.
587 * Return: 0 in case of success, a negative error code otherwise.
589 static inline int nanddev_unregister(struct nand_device *nand)
591 return mtd_device_unregister(&nand->mtd);
595 * nanddev_set_of_node() - Attach a DT node to a NAND device
599 * Attach a DT node to a NAND device.
601 static inline void nanddev_set_of_node(struct nand_device *nand,
602 struct device_node *np)
604 mtd_set_of_node(&nand->mtd, np);
608 * nanddev_get_of_node() - Retrieve the DT node attached to a NAND device
611 * Return: the DT node attached to @nand.
613 static inline struct device_node *nanddev_get_of_node(struct nand_device *nand)
615 return mtd_get_of_node(&nand->mtd);
619 * nanddev_offs_to_pos() - Convert an absolute NAND offset into a NAND position
621 * @offs: absolute NAND offset (usually passed by the MTD layer)
622 * @pos: a NAND position object to fill in
624 * Converts @offs into a nand_pos representation.
626 * Return: the offset within the NAND page pointed by @pos.
628 static inline unsigned int nanddev_offs_to_pos(struct nand_device *nand,
630 struct nand_pos *pos)
632 unsigned int pageoffs;
635 pageoffs = do_div(tmp, nand->memorg.pagesize);
636 pos->page = do_div(tmp, nand->memorg.pages_per_eraseblock);
637 pos->eraseblock = do_div(tmp, nand->memorg.eraseblocks_per_lun);
638 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun;
639 pos->lun = do_div(tmp, nand->memorg.luns_per_target);
646 * nanddev_pos_cmp() - Compare two NAND positions
647 * @a: First NAND position
648 * @b: Second NAND position
650 * Compares two NAND positions.
652 * Return: -1 if @a < @b, 0 if @a == @b and 1 if @a > @b.
654 static inline int nanddev_pos_cmp(const struct nand_pos *a,
655 const struct nand_pos *b)
657 if (a->target != b->target)
658 return a->target < b->target ? -1 : 1;
660 if (a->lun != b->lun)
661 return a->lun < b->lun ? -1 : 1;
663 if (a->eraseblock != b->eraseblock)
664 return a->eraseblock < b->eraseblock ? -1 : 1;
666 if (a->page != b->page)
667 return a->page < b->page ? -1 : 1;
673 * nanddev_pos_to_offs() - Convert a NAND position into an absolute offset
675 * @pos: the NAND position to convert
677 * Converts @pos NAND position into an absolute offset.
679 * Return: the absolute offset. Note that @pos points to the beginning of a
680 * page, if one wants to point to a specific offset within this page
681 * the returned offset has to be adjusted manually.
683 static inline loff_t nanddev_pos_to_offs(struct nand_device *nand,
684 const struct nand_pos *pos)
691 (pos->target * nand->memorg.luns_per_target)) *
692 nand->memorg.eraseblocks_per_lun) *
693 nand->memorg.pages_per_eraseblock);
695 return (loff_t)npages * nand->memorg.pagesize;
699 * nanddev_pos_to_row() - Extract a row address from a NAND position
701 * @pos: the position to convert
703 * Converts a NAND position into a row address that can then be passed to the
706 * Return: the row address extracted from @pos.
708 static inline unsigned int nanddev_pos_to_row(struct nand_device *nand,
709 const struct nand_pos *pos)
711 return (pos->lun << nand->rowconv.lun_addr_shift) |
712 (pos->eraseblock << nand->rowconv.eraseblock_addr_shift) |
717 * nanddev_pos_next_target() - Move a position to the next target/die
719 * @pos: the position to update
721 * Updates @pos to point to the start of the next target/die. Useful when you
722 * want to iterate over all targets/dies of a NAND device.
724 static inline void nanddev_pos_next_target(struct nand_device *nand,
725 struct nand_pos *pos)
735 * nanddev_pos_next_lun() - Move a position to the next LUN
737 * @pos: the position to update
739 * Updates @pos to point to the start of the next LUN. Useful when you want to
740 * iterate over all LUNs of a NAND device.
742 static inline void nanddev_pos_next_lun(struct nand_device *nand,
743 struct nand_pos *pos)
745 if (pos->lun >= nand->memorg.luns_per_target - 1)
746 return nanddev_pos_next_target(nand, pos);
755 * nanddev_pos_next_eraseblock() - Move a position to the next eraseblock
757 * @pos: the position to update
759 * Updates @pos to point to the start of the next eraseblock. Useful when you
760 * want to iterate over all eraseblocks of a NAND device.
762 static inline void nanddev_pos_next_eraseblock(struct nand_device *nand,
763 struct nand_pos *pos)
765 if (pos->eraseblock >= nand->memorg.eraseblocks_per_lun - 1)
766 return nanddev_pos_next_lun(nand, pos);
770 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun;
774 * nanddev_pos_next_page() - Move a position to the next page
776 * @pos: the position to update
778 * Updates @pos to point to the start of the next page. Useful when you want to
779 * iterate over all pages of a NAND device.
781 static inline void nanddev_pos_next_page(struct nand_device *nand,
782 struct nand_pos *pos)
784 if (pos->page >= nand->memorg.pages_per_eraseblock - 1)
785 return nanddev_pos_next_eraseblock(nand, pos);
791 * nand_io_iter_init - Initialize a NAND I/O iterator
793 * @offs: absolute offset
795 * @iter: NAND I/O iterator
797 * Initializes a NAND iterator based on the information passed by the MTD
800 static inline void nanddev_io_iter_init(struct nand_device *nand,
801 enum nand_page_io_req_type reqtype,
802 loff_t offs, struct mtd_oob_ops *req,
803 struct nand_io_iter *iter)
805 struct mtd_info *mtd = nanddev_to_mtd(nand);
807 iter->req.type = reqtype;
808 iter->req.mode = req->mode;
809 iter->req.dataoffs = nanddev_offs_to_pos(nand, offs, &iter->req.pos);
810 iter->req.ooboffs = req->ooboffs;
811 iter->oobbytes_per_page = mtd_oobavail(mtd, req);
812 iter->dataleft = req->len;
813 iter->oobleft = req->ooblen;
814 iter->req.databuf.in = req->datbuf;
815 iter->req.datalen = min_t(unsigned int,
816 nand->memorg.pagesize - iter->req.dataoffs,
818 iter->req.oobbuf.in = req->oobbuf;
819 iter->req.ooblen = min_t(unsigned int,
820 iter->oobbytes_per_page - iter->req.ooboffs,
825 * nand_io_iter_next_page - Move to the next page
827 * @iter: NAND I/O iterator
829 * Updates the @iter to point to the next page.
831 static inline void nanddev_io_iter_next_page(struct nand_device *nand,
832 struct nand_io_iter *iter)
834 nanddev_pos_next_page(nand, &iter->req.pos);
835 iter->dataleft -= iter->req.datalen;
836 iter->req.databuf.in += iter->req.datalen;
837 iter->oobleft -= iter->req.ooblen;
838 iter->req.oobbuf.in += iter->req.ooblen;
839 iter->req.dataoffs = 0;
840 iter->req.ooboffs = 0;
841 iter->req.datalen = min_t(unsigned int, nand->memorg.pagesize,
843 iter->req.ooblen = min_t(unsigned int, iter->oobbytes_per_page,
848 * nand_io_iter_end - Should end iteration or not
850 * @iter: NAND I/O iterator
852 * Check whether @iter has reached the end of the NAND portion it was asked to
855 * Return: true if @iter has reached the end of the iteration request, false
858 static inline bool nanddev_io_iter_end(struct nand_device *nand,
859 const struct nand_io_iter *iter)
861 if (iter->dataleft || iter->oobleft)
868 * nand_io_for_each_page - Iterate over all NAND pages contained in an MTD I/O
871 * @start: start address to read/write from
872 * @req: MTD I/O request
873 * @iter: NAND I/O iterator
875 * Should be used for iterate over pages that are contained in an MTD request.
877 #define nanddev_io_for_each_page(nand, type, start, req, iter) \
878 for (nanddev_io_iter_init(nand, type, start, req, iter); \
879 !nanddev_io_iter_end(nand, iter); \
880 nanddev_io_iter_next_page(nand, iter))
882 bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos);
883 bool nanddev_isreserved(struct nand_device *nand, const struct nand_pos *pos);
884 int nanddev_erase(struct nand_device *nand, const struct nand_pos *pos);
885 int nanddev_markbad(struct nand_device *nand, const struct nand_pos *pos);
887 /* BBT related functions */
888 enum nand_bbt_block_status {
889 NAND_BBT_BLOCK_STATUS_UNKNOWN,
892 NAND_BBT_BLOCK_RESERVED,
893 NAND_BBT_BLOCK_FACTORY_BAD,
894 NAND_BBT_BLOCK_NUM_STATUS,
897 int nanddev_bbt_init(struct nand_device *nand);
898 void nanddev_bbt_cleanup(struct nand_device *nand);
899 int nanddev_bbt_update(struct nand_device *nand);
900 int nanddev_bbt_get_block_status(const struct nand_device *nand,
902 int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
903 enum nand_bbt_block_status status);
904 int nanddev_bbt_markbad(struct nand_device *nand, unsigned int block);
907 * nanddev_bbt_pos_to_entry() - Convert a NAND position into a BBT entry
909 * @pos: the NAND position we want to get BBT entry for
911 * Return the BBT entry used to store information about the eraseblock pointed
914 * Return: the BBT entry storing information about eraseblock pointed by @pos.
916 static inline unsigned int nanddev_bbt_pos_to_entry(struct nand_device *nand,
917 const struct nand_pos *pos)
919 return pos->eraseblock +
920 ((pos->lun + (pos->target * nand->memorg.luns_per_target)) *
921 nand->memorg.eraseblocks_per_lun);
925 * nanddev_bbt_is_initialized() - Check if the BBT has been initialized
928 * Return: true if the BBT has been initialized, false otherwise.
930 static inline bool nanddev_bbt_is_initialized(struct nand_device *nand)
932 return !!nand->bbt.cache;
935 /* MTD -> NAND helper functions. */
936 int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo);
937 int nanddev_mtd_max_bad_blocks(struct mtd_info *mtd, loff_t offs, size_t len);
939 #endif /* __LINUX_MTD_NAND_H */