Lines Matching +full:nand +full:- +full:ecc +full:- +full:mode

1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright 2017 - Free Electrons
6 * Boris Brezillon <boris.brezillon@free-electrons.com>
18 * struct nand_memory_organization - Memory organization structure
19 * @bits_per_cell: number of bits per NAND cell
27 * @ntargets: total number of targets exposed by the NAND device
55 * struct nand_row_converter - Information needed to convert an absolute offset
67 * struct nand_pos - NAND position object
68 * @target: the NAND target/die
74 * These information are usually used by specific sub-layers to select the
86 * enum nand_page_io_req_type - Direction of an I/O request
96 * struct nand_page_io_req - NAND I/O request object
105 * @mode: one of the %MTD_OPS_XXX mode
107 * NAND device will automatically prepare the next one
109 * This object is used to pass per-page I/O requests to NAND sub-layers. This
111 * specific NAND layers can focus on translating these information into
129 int mode; member
138 * enum nand_ecc_engine_type - NAND ECC engine type
140 * @NAND_ECC_ENGINE_TYPE_NONE: No ECC correction
141 * @NAND_ECC_ENGINE_TYPE_SOFT: Software ECC correction
142 * @NAND_ECC_ENGINE_TYPE_ON_HOST: On host hardware ECC correction
143 * @NAND_ECC_ENGINE_TYPE_ON_DIE: On chip hardware ECC correction
154 * enum nand_ecc_placement - NAND ECC bytes placement
155 * @NAND_ECC_PLACEMENT_UNKNOWN: The actual position of the ECC bytes is unknown
156 * @NAND_ECC_PLACEMENT_OOB: The ECC bytes are located in the OOB area
157 * @NAND_ECC_PLACEMENT_INTERLEAVED: Syndrome layout, there are ECC bytes
168 * enum nand_ecc_algo - NAND ECC algorithm
171 * @NAND_ECC_ALGO_BCH: Bose-Chaudhuri-Hocquenghem algorithm
172 * @NAND_ECC_ALGO_RS: Reed-Solomon algorithm
182 * struct nand_ecc_props - NAND ECC properties
183 * @engine_type: ECC engine type
185 * @algo: ECC algorithm (if relevant)
186 * @strength: ECC strength
201 /* NAND ECC misc flags */
205 * struct nand_bbt - bad block table object
213 * struct nand_ops - NAND operations
215 * erasing, this has been taken care of by the generic NAND layer
218 * NAND layer. This method should just write the BBM (Bad Block
219 * Marker) so that future call to struct_nand_ops->isbad() return
226 * NAND layers (SPI NAND, raw NAND, ...).
229 int (*erase)(struct nand_device *nand, const struct nand_pos *pos);
230 int (*markbad)(struct nand_device *nand, const struct nand_pos *pos);
231 bool (*isbad)(struct nand_device *nand, const struct nand_pos *pos);
235 * struct nand_ecc_context - Context for the ECC engine
236 * @conf: basic ECC engine parameters
237 * @nsteps: number of ECC steps
238 * @total: total number of bytes used for storing ECC codes, this is used by
240 * @priv: ECC engine driver private data
250 * struct nand_ecc_engine_ops - ECC engine operations
251 * @init_ctx: given a desired user configuration for the pointed NAND device,
252 * requests the ECC engine driver to setup a configuration with
256 * request to be performed with ECC correction.
258 * request and ensure proper ECC correction.
261 int (*init_ctx)(struct nand_device *nand);
262 void (*cleanup_ctx)(struct nand_device *nand);
263 int (*prepare_io_req)(struct nand_device *nand,
265 int (*finish_io_req)(struct nand_device *nand,
270 * enum nand_ecc_engine_integration - How the NAND ECC engine is integrated
272 * @NAND_ECC_ENGINE_INTEGRATION_PIPELINED: Pipelined engine, performs on-the-fly
285 * struct nand_ecc_engine - ECC engine abstraction for NAND devices
288 * @ops: ECC engine operations
301 void of_get_nand_ecc_user_config(struct nand_device *nand);
302 int nand_ecc_init_ctx(struct nand_device *nand);
303 void nand_ecc_cleanup_ctx(struct nand_device *nand);
304 int nand_ecc_prepare_io_req(struct nand_device *nand,
306 int nand_ecc_finish_io_req(struct nand_device *nand,
308 bool nand_ecc_is_strong_enough(struct nand_device *nand);
317 return -ENOTSUPP; in nand_ecc_register_on_host_hw_engine()
322 return -ENOTSUPP; in nand_ecc_unregister_on_host_hw_engine()
326 struct nand_ecc_engine *nand_ecc_get_sw_engine(struct nand_device *nand);
327 struct nand_ecc_engine *nand_ecc_get_on_die_hw_engine(struct nand_device *nand);
328 struct nand_ecc_engine *nand_ecc_get_on_host_hw_engine(struct nand_device *nand);
329 void nand_ecc_put_on_host_hw_engine(struct nand_device *nand);
351 * struct nand_ecc_req_tweak_ctx - Help for automatically tweaking requests
353 * @nand: Related NAND device, to have access to its memory organization
365 struct nand_device *nand; member
375 struct nand_device *nand);
383 * struct nand_ecc - Information relative to the ECC
385 * @requirements: ECC requirements from the NAND chip perspective
386 * @user_conf: User desires in terms of ECC parameters
387 * @ctx: ECC context for the ECC engine, derived from the device @requirements
389 * @ondie_engine: On-die ECC engine reference, if any
390 * @engine: ECC engine actually bound
402 * struct nand_device - NAND device
403 * @mtd: MTD instance attached to the NAND device
405 * @ecc: NAND ECC object attached to the NAND device
408 * @ops: NAND operations attached to the NAND device
410 * Generic NAND object. Specialized NAND layers (raw NAND, SPI NAND, OneNAND)
411 * should declare their own NAND object embedding a nand_device struct (that's
413 * struct_nand_device->memorg and struct_nand_device->ecc.requirements should
414 * be filled at device detection time to reflect the NAND device
416 * It will take care of converting NAND information into MTD ones, which means
417 * the specialized NAND layers should never manually tweak
418 * struct_nand_device->mtd except for the ->_read/write() hooks.
423 struct nand_ecc ecc; member
430 * struct nand_io_iter - NAND I/O iterator
436 * Can be used by specialized NAND layers to iterate over all pages covered
437 * by an MTD I/O request, which should greatly simplifies the boiler-plate
438 * code needed to read/write data from/to a NAND device.
448 * mtd_to_nanddev() - Get the NAND device attached to the MTD instance
451 * Return: the NAND device embedding @mtd.
459 * nanddev_to_mtd() - Get the MTD device attached to a NAND device
460 * @nand: NAND device
462 * Return: the MTD device embedded in @nand.
464 static inline struct mtd_info *nanddev_to_mtd(struct nand_device *nand) in nanddev_to_mtd() argument
466 return &nand->mtd; in nanddev_to_mtd()
470 * nanddev_bits_per_cell() - Get the number of bits per cell
471 * @nand: NAND device
475 static inline unsigned int nanddev_bits_per_cell(const struct nand_device *nand) in nanddev_bits_per_cell() argument
477 return nand->memorg.bits_per_cell; in nanddev_bits_per_cell()
481 * nanddev_page_size() - Get NAND page size
482 * @nand: NAND device
486 static inline size_t nanddev_page_size(const struct nand_device *nand) in nanddev_page_size() argument
488 return nand->memorg.pagesize; in nanddev_page_size()
492 * nanddev_per_page_oobsize() - Get NAND OOB size
493 * @nand: NAND device
498 nanddev_per_page_oobsize(const struct nand_device *nand) in nanddev_per_page_oobsize() argument
500 return nand->memorg.oobsize; in nanddev_per_page_oobsize()
504 * nanddev_pages_per_eraseblock() - Get the number of pages per eraseblock
505 * @nand: NAND device
510 nanddev_pages_per_eraseblock(const struct nand_device *nand) in nanddev_pages_per_eraseblock() argument
512 return nand->memorg.pages_per_eraseblock; in nanddev_pages_per_eraseblock()
516 * nanddev_pages_per_target() - Get the number of pages per target
517 * @nand: NAND device
522 nanddev_pages_per_target(const struct nand_device *nand) in nanddev_pages_per_target() argument
524 return nand->memorg.pages_per_eraseblock * in nanddev_pages_per_target()
525 nand->memorg.eraseblocks_per_lun * in nanddev_pages_per_target()
526 nand->memorg.luns_per_target; in nanddev_pages_per_target()
530 * nanddev_per_page_oobsize() - Get NAND erase block size
531 * @nand: NAND device
535 static inline size_t nanddev_eraseblock_size(const struct nand_device *nand) in nanddev_eraseblock_size() argument
537 return nand->memorg.pagesize * nand->memorg.pages_per_eraseblock; in nanddev_eraseblock_size()
541 * nanddev_eraseblocks_per_lun() - Get the number of eraseblocks per LUN
542 * @nand: NAND device
547 nanddev_eraseblocks_per_lun(const struct nand_device *nand) in nanddev_eraseblocks_per_lun() argument
549 return nand->memorg.eraseblocks_per_lun; in nanddev_eraseblocks_per_lun()
553 * nanddev_eraseblocks_per_target() - Get the number of eraseblocks per target
554 * @nand: NAND device
559 nanddev_eraseblocks_per_target(const struct nand_device *nand) in nanddev_eraseblocks_per_target() argument
561 return nand->memorg.eraseblocks_per_lun * nand->memorg.luns_per_target; in nanddev_eraseblocks_per_target()
565 * nanddev_target_size() - Get the total size provided by a single target/die
566 * @nand: NAND device
570 static inline u64 nanddev_target_size(const struct nand_device *nand) in nanddev_target_size() argument
572 return (u64)nand->memorg.luns_per_target * in nanddev_target_size()
573 nand->memorg.eraseblocks_per_lun * in nanddev_target_size()
574 nand->memorg.pages_per_eraseblock * in nanddev_target_size()
575 nand->memorg.pagesize; in nanddev_target_size()
579 * nanddev_ntarget() - Get the total of targets
580 * @nand: NAND device
582 * Return: the number of targets/dies exposed by @nand.
584 static inline unsigned int nanddev_ntargets(const struct nand_device *nand) in nanddev_ntargets() argument
586 return nand->memorg.ntargets; in nanddev_ntargets()
590 * nanddev_neraseblocks() - Get the total number of eraseblocks
591 * @nand: NAND device
593 * Return: the total number of eraseblocks exposed by @nand.
595 static inline unsigned int nanddev_neraseblocks(const struct nand_device *nand) in nanddev_neraseblocks() argument
597 return nand->memorg.ntargets * nand->memorg.luns_per_target * in nanddev_neraseblocks()
598 nand->memorg.eraseblocks_per_lun; in nanddev_neraseblocks()
602 * nanddev_size() - Get NAND size
603 * @nand: NAND device
605 * Return: the total size (in bytes) exposed by @nand.
607 static inline u64 nanddev_size(const struct nand_device *nand) in nanddev_size() argument
609 return nanddev_target_size(nand) * nanddev_ntargets(nand); in nanddev_size()
613 * nanddev_get_memorg() - Extract memory organization info from a NAND device
614 * @nand: NAND device
619 * Return: the memorg object embedded in the NAND device.
622 nanddev_get_memorg(struct nand_device *nand) in nanddev_get_memorg() argument
624 return &nand->memorg; in nanddev_get_memorg()
628 * nanddev_get_ecc_conf() - Extract the ECC configuration from a NAND device
629 * @nand: NAND device
632 nanddev_get_ecc_conf(struct nand_device *nand) in nanddev_get_ecc_conf() argument
634 return &nand->ecc.ctx.conf; in nanddev_get_ecc_conf()
638 * nanddev_get_ecc_nsteps() - Extract the number of ECC steps
639 * @nand: NAND device
642 nanddev_get_ecc_nsteps(struct nand_device *nand) in nanddev_get_ecc_nsteps() argument
644 return nand->ecc.ctx.nsteps; in nanddev_get_ecc_nsteps()
648 * nanddev_get_ecc_bytes_per_step() - Extract the number of ECC bytes per step
649 * @nand: NAND device
652 nanddev_get_ecc_bytes_per_step(struct nand_device *nand) in nanddev_get_ecc_bytes_per_step() argument
654 return nand->ecc.ctx.total / nand->ecc.ctx.nsteps; in nanddev_get_ecc_bytes_per_step()
658 * nanddev_get_ecc_requirements() - Extract the ECC requirements from a NAND
660 * @nand: NAND device
663 nanddev_get_ecc_requirements(struct nand_device *nand) in nanddev_get_ecc_requirements() argument
665 return &nand->ecc.requirements; in nanddev_get_ecc_requirements()
669 * nanddev_set_ecc_requirements() - Assign the ECC requirements of a NAND
671 * @nand: NAND device
675 nanddev_set_ecc_requirements(struct nand_device *nand, in nanddev_set_ecc_requirements() argument
678 nand->ecc.requirements = *reqs; in nanddev_set_ecc_requirements()
681 int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
683 void nanddev_cleanup(struct nand_device *nand);
686 * nanddev_register() - Register a NAND device
687 * @nand: NAND device
689 * Register a NAND device.
691 * registering the MTD device embedded in @nand.
695 static inline int nanddev_register(struct nand_device *nand) in nanddev_register() argument
697 return mtd_device_register(&nand->mtd, NULL, 0); in nanddev_register()
701 * nanddev_unregister() - Unregister a NAND device
702 * @nand: NAND device
704 * Unregister a NAND device.
706 * unregistering the MTD device embedded in @nand.
710 static inline int nanddev_unregister(struct nand_device *nand) in nanddev_unregister() argument
712 return mtd_device_unregister(&nand->mtd); in nanddev_unregister()
716 * nanddev_set_of_node() - Attach a DT node to a NAND device
717 * @nand: NAND device
720 * Attach a DT node to a NAND device.
722 static inline void nanddev_set_of_node(struct nand_device *nand, in nanddev_set_of_node() argument
725 mtd_set_of_node(&nand->mtd, np); in nanddev_set_of_node()
729 * nanddev_get_of_node() - Retrieve the DT node attached to a NAND device
730 * @nand: NAND device
732 * Return: the DT node attached to @nand.
734 static inline struct device_node *nanddev_get_of_node(struct nand_device *nand) in nanddev_get_of_node() argument
736 return mtd_get_of_node(&nand->mtd); in nanddev_get_of_node()
740 * nanddev_offs_to_pos() - Convert an absolute NAND offset into a NAND position
741 * @nand: NAND device
742 * @offs: absolute NAND offset (usually passed by the MTD layer)
743 * @pos: a NAND position object to fill in
747 * Return: the offset within the NAND page pointed by @pos.
749 static inline unsigned int nanddev_offs_to_pos(struct nand_device *nand, in nanddev_offs_to_pos() argument
756 pageoffs = do_div(tmp, nand->memorg.pagesize); in nanddev_offs_to_pos()
757 pos->page = do_div(tmp, nand->memorg.pages_per_eraseblock); in nanddev_offs_to_pos()
758 pos->eraseblock = do_div(tmp, nand->memorg.eraseblocks_per_lun); in nanddev_offs_to_pos()
759 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun; in nanddev_offs_to_pos()
760 pos->lun = do_div(tmp, nand->memorg.luns_per_target); in nanddev_offs_to_pos()
761 pos->target = tmp; in nanddev_offs_to_pos()
767 * nanddev_pos_cmp() - Compare two NAND positions
768 * @a: First NAND position
769 * @b: Second NAND position
771 * Compares two NAND positions.
773 * Return: -1 if @a < @b, 0 if @a == @b and 1 if @a > @b.
778 if (a->target != b->target) in nanddev_pos_cmp()
779 return a->target < b->target ? -1 : 1; in nanddev_pos_cmp()
781 if (a->lun != b->lun) in nanddev_pos_cmp()
782 return a->lun < b->lun ? -1 : 1; in nanddev_pos_cmp()
784 if (a->eraseblock != b->eraseblock) in nanddev_pos_cmp()
785 return a->eraseblock < b->eraseblock ? -1 : 1; in nanddev_pos_cmp()
787 if (a->page != b->page) in nanddev_pos_cmp()
788 return a->page < b->page ? -1 : 1; in nanddev_pos_cmp()
794 * nanddev_pos_to_offs() - Convert a NAND position into an absolute offset
795 * @nand: NAND device
796 * @pos: the NAND position to convert
798 * Converts @pos NAND position into an absolute offset.
804 static inline loff_t nanddev_pos_to_offs(struct nand_device *nand, in nanddev_pos_to_offs() argument
809 npages = pos->page + in nanddev_pos_to_offs()
810 ((pos->eraseblock + in nanddev_pos_to_offs()
811 (pos->lun + in nanddev_pos_to_offs()
812 (pos->target * nand->memorg.luns_per_target)) * in nanddev_pos_to_offs()
813 nand->memorg.eraseblocks_per_lun) * in nanddev_pos_to_offs()
814 nand->memorg.pages_per_eraseblock); in nanddev_pos_to_offs()
816 return (loff_t)npages * nand->memorg.pagesize; in nanddev_pos_to_offs()
820 * nanddev_pos_to_row() - Extract a row address from a NAND position
821 * @nand: NAND device
824 * Converts a NAND position into a row address that can then be passed to the
829 static inline unsigned int nanddev_pos_to_row(struct nand_device *nand, in nanddev_pos_to_row() argument
832 return (pos->lun << nand->rowconv.lun_addr_shift) | in nanddev_pos_to_row()
833 (pos->eraseblock << nand->rowconv.eraseblock_addr_shift) | in nanddev_pos_to_row()
834 pos->page; in nanddev_pos_to_row()
838 * nanddev_pos_next_target() - Move a position to the next target/die
839 * @nand: NAND device
843 * want to iterate over all targets/dies of a NAND device.
845 static inline void nanddev_pos_next_target(struct nand_device *nand, in nanddev_pos_next_target() argument
848 pos->page = 0; in nanddev_pos_next_target()
849 pos->plane = 0; in nanddev_pos_next_target()
850 pos->eraseblock = 0; in nanddev_pos_next_target()
851 pos->lun = 0; in nanddev_pos_next_target()
852 pos->target++; in nanddev_pos_next_target()
856 * nanddev_pos_next_lun() - Move a position to the next LUN
857 * @nand: NAND device
861 * iterate over all LUNs of a NAND device.
863 static inline void nanddev_pos_next_lun(struct nand_device *nand, in nanddev_pos_next_lun() argument
866 if (pos->lun >= nand->memorg.luns_per_target - 1) in nanddev_pos_next_lun()
867 return nanddev_pos_next_target(nand, pos); in nanddev_pos_next_lun()
869 pos->lun++; in nanddev_pos_next_lun()
870 pos->page = 0; in nanddev_pos_next_lun()
871 pos->plane = 0; in nanddev_pos_next_lun()
872 pos->eraseblock = 0; in nanddev_pos_next_lun()
876 * nanddev_pos_next_eraseblock() - Move a position to the next eraseblock
877 * @nand: NAND device
881 * want to iterate over all eraseblocks of a NAND device.
883 static inline void nanddev_pos_next_eraseblock(struct nand_device *nand, in nanddev_pos_next_eraseblock() argument
886 if (pos->eraseblock >= nand->memorg.eraseblocks_per_lun - 1) in nanddev_pos_next_eraseblock()
887 return nanddev_pos_next_lun(nand, pos); in nanddev_pos_next_eraseblock()
889 pos->eraseblock++; in nanddev_pos_next_eraseblock()
890 pos->page = 0; in nanddev_pos_next_eraseblock()
891 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun; in nanddev_pos_next_eraseblock()
895 * nanddev_pos_next_page() - Move a position to the next page
896 * @nand: NAND device
900 * iterate over all pages of a NAND device.
902 static inline void nanddev_pos_next_page(struct nand_device *nand, in nanddev_pos_next_page() argument
905 if (pos->page >= nand->memorg.pages_per_eraseblock - 1) in nanddev_pos_next_page()
906 return nanddev_pos_next_eraseblock(nand, pos); in nanddev_pos_next_page()
908 pos->page++; in nanddev_pos_next_page()
912 * nand_io_page_iter_init - Initialize a NAND I/O iterator
913 * @nand: NAND device
916 * @iter: NAND I/O iterator
918 * Initializes a NAND iterator based on the information passed by the MTD
921 static inline void nanddev_io_page_iter_init(struct nand_device *nand, in nanddev_io_page_iter_init() argument
926 struct mtd_info *mtd = nanddev_to_mtd(nand); in nanddev_io_page_iter_init()
928 iter->req.type = reqtype; in nanddev_io_page_iter_init()
929 iter->req.mode = req->mode; in nanddev_io_page_iter_init()
930 iter->req.dataoffs = nanddev_offs_to_pos(nand, offs, &iter->req.pos); in nanddev_io_page_iter_init()
931 iter->req.ooboffs = req->ooboffs; in nanddev_io_page_iter_init()
932 iter->oobbytes_per_page = mtd_oobavail(mtd, req); in nanddev_io_page_iter_init()
933 iter->dataleft = req->len; in nanddev_io_page_iter_init()
934 iter->oobleft = req->ooblen; in nanddev_io_page_iter_init()
935 iter->req.databuf.in = req->datbuf; in nanddev_io_page_iter_init()
936 iter->req.datalen = min_t(unsigned int, in nanddev_io_page_iter_init()
937 nand->memorg.pagesize - iter->req.dataoffs, in nanddev_io_page_iter_init()
938 iter->dataleft); in nanddev_io_page_iter_init()
939 iter->req.oobbuf.in = req->oobbuf; in nanddev_io_page_iter_init()
940 iter->req.ooblen = min_t(unsigned int, in nanddev_io_page_iter_init()
941 iter->oobbytes_per_page - iter->req.ooboffs, in nanddev_io_page_iter_init()
942 iter->oobleft); in nanddev_io_page_iter_init()
943 iter->req.continuous = false; in nanddev_io_page_iter_init()
947 * nand_io_block_iter_init - Initialize a NAND I/O iterator
948 * @nand: NAND device
951 * @iter: NAND I/O iterator
953 * Initializes a NAND iterator based on the information passed by the MTD
958 static inline void nanddev_io_block_iter_init(struct nand_device *nand, in nanddev_io_block_iter_init() argument
965 iter->req.type = reqtype; in nanddev_io_block_iter_init()
966 iter->req.mode = req->mode; in nanddev_io_block_iter_init()
967 iter->req.dataoffs = nanddev_offs_to_pos(nand, offs, &iter->req.pos); in nanddev_io_block_iter_init()
968 iter->req.ooboffs = 0; in nanddev_io_block_iter_init()
969 iter->oobbytes_per_page = 0; in nanddev_io_block_iter_init()
970 iter->dataleft = req->len; in nanddev_io_block_iter_init()
971 iter->oobleft = 0; in nanddev_io_block_iter_init()
972 iter->req.databuf.in = req->datbuf; in nanddev_io_block_iter_init()
973 offs_in_eb = (nand->memorg.pagesize * iter->req.pos.page) + iter->req.dataoffs; in nanddev_io_block_iter_init()
974 iter->req.datalen = min_t(unsigned int, in nanddev_io_block_iter_init()
975 nanddev_eraseblock_size(nand) - offs_in_eb, in nanddev_io_block_iter_init()
976 iter->dataleft); in nanddev_io_block_iter_init()
977 iter->req.oobbuf.in = NULL; in nanddev_io_block_iter_init()
978 iter->req.ooblen = 0; in nanddev_io_block_iter_init()
979 iter->req.continuous = true; in nanddev_io_block_iter_init()
983 * nand_io_iter_next_page - Move to the next page
984 * @nand: NAND device
985 * @iter: NAND I/O iterator
989 static inline void nanddev_io_iter_next_page(struct nand_device *nand, in nanddev_io_iter_next_page() argument
992 nanddev_pos_next_page(nand, &iter->req.pos); in nanddev_io_iter_next_page()
993 iter->dataleft -= iter->req.datalen; in nanddev_io_iter_next_page()
994 iter->req.databuf.in += iter->req.datalen; in nanddev_io_iter_next_page()
995 iter->oobleft -= iter->req.ooblen; in nanddev_io_iter_next_page()
996 iter->req.oobbuf.in += iter->req.ooblen; in nanddev_io_iter_next_page()
997 iter->req.dataoffs = 0; in nanddev_io_iter_next_page()
998 iter->req.ooboffs = 0; in nanddev_io_iter_next_page()
999 iter->req.datalen = min_t(unsigned int, nand->memorg.pagesize, in nanddev_io_iter_next_page()
1000 iter->dataleft); in nanddev_io_iter_next_page()
1001 iter->req.ooblen = min_t(unsigned int, iter->oobbytes_per_page, in nanddev_io_iter_next_page()
1002 iter->oobleft); in nanddev_io_iter_next_page()
1006 * nand_io_iter_next_block - Move to the next block
1007 * @nand: NAND device
1008 * @iter: NAND I/O iterator
1013 static inline void nanddev_io_iter_next_block(struct nand_device *nand, in nanddev_io_iter_next_block() argument
1016 nanddev_pos_next_eraseblock(nand, &iter->req.pos); in nanddev_io_iter_next_block()
1017 iter->dataleft -= iter->req.datalen; in nanddev_io_iter_next_block()
1018 iter->req.databuf.in += iter->req.datalen; in nanddev_io_iter_next_block()
1019 iter->req.dataoffs = 0; in nanddev_io_iter_next_block()
1020 iter->req.datalen = min_t(unsigned int, nanddev_eraseblock_size(nand), in nanddev_io_iter_next_block()
1021 iter->dataleft); in nanddev_io_iter_next_block()
1025 * nand_io_iter_end - Should end iteration or not
1026 * @nand: NAND device
1027 * @iter: NAND I/O iterator
1029 * Check whether @iter has reached the end of the NAND portion it was asked to
1035 static inline bool nanddev_io_iter_end(struct nand_device *nand, in nanddev_io_iter_end() argument
1038 if (iter->dataleft || iter->oobleft) in nanddev_io_iter_end()
1045 * nand_io_for_each_page - Iterate over all NAND pages contained in an MTD I/O
1047 * @nand: NAND device
1050 * @iter: NAND I/O iterator
1054 #define nanddev_io_for_each_page(nand, type, start, req, iter) \ argument
1055 for (nanddev_io_page_iter_init(nand, type, start, req, iter); \
1056 !nanddev_io_iter_end(nand, iter); \
1057 nanddev_io_iter_next_page(nand, iter))
1060 * nand_io_for_each_block - Iterate over all NAND pages contained in an MTD I/O
1062 * @nand: NAND device
1065 * @iter: NAND I/O iterator
1069 #define nanddev_io_for_each_block(nand, type, start, req, iter) \ argument
1070 for (nanddev_io_block_iter_init(nand, type, start, req, iter); \
1071 !nanddev_io_iter_end(nand, iter); \
1072 nanddev_io_iter_next_block(nand, iter))
1074 bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos);
1075 bool nanddev_isreserved(struct nand_device *nand, const struct nand_pos *pos);
1076 int nanddev_markbad(struct nand_device *nand, const struct nand_pos *pos);
1078 /* ECC related functions */
1079 int nanddev_ecc_engine_init(struct nand_device *nand);
1080 void nanddev_ecc_engine_cleanup(struct nand_device *nand);
1082 static inline void *nand_to_ecc_ctx(struct nand_device *nand) in nand_to_ecc_ctx() argument
1084 return nand->ecc.ctx.priv; in nand_to_ecc_ctx()
1097 int nanddev_bbt_init(struct nand_device *nand);
1098 void nanddev_bbt_cleanup(struct nand_device *nand);
1099 int nanddev_bbt_update(struct nand_device *nand);
1100 int nanddev_bbt_get_block_status(const struct nand_device *nand,
1102 int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
1104 int nanddev_bbt_markbad(struct nand_device *nand, unsigned int block);
1107 * nanddev_bbt_pos_to_entry() - Convert a NAND position into a BBT entry
1108 * @nand: NAND device
1109 * @pos: the NAND position we want to get BBT entry for
1116 static inline unsigned int nanddev_bbt_pos_to_entry(struct nand_device *nand, in nanddev_bbt_pos_to_entry() argument
1119 return pos->eraseblock + in nanddev_bbt_pos_to_entry()
1120 ((pos->lun + (pos->target * nand->memorg.luns_per_target)) * in nanddev_bbt_pos_to_entry()
1121 nand->memorg.eraseblocks_per_lun); in nanddev_bbt_pos_to_entry()
1125 * nanddev_bbt_is_initialized() - Check if the BBT has been initialized
1126 * @nand: NAND device
1130 static inline bool nanddev_bbt_is_initialized(struct nand_device *nand) in nanddev_bbt_is_initialized() argument
1132 return !!nand->bbt.cache; in nanddev_bbt_is_initialized()
1135 /* MTD -> NAND helper functions. */