drivers/mtd/nand/ecc.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nand/ecc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nand/ecc.c- Extension
.c- Size
- 20713 bytes
- Lines
- 736
- Domain
- Driver Families
- Bucket
- drivers/mtd
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/mtd/nand.hlinux/platform_device.hlinux/slab.hlinux/of.hlinux/of_platform.h
Detected Declarations
function nand_ecc_init_ctxfunction nand_ecc_cleanup_ctxfunction nand_ecc_prepare_io_reqfunction nand_ecc_finish_io_reqfunction nand_ooblayout_ecc_spfunction nand_ooblayout_free_spfunction nand_ooblayout_ecc_lpfunction nand_ooblayout_free_lpfunction nand_ooblayout_ecc_lp_hammingfunction nand_ooblayout_free_lp_hammingfunction of_get_nand_ecc_engine_typefunction of_get_nand_ecc_placementfunction of_get_nand_ecc_algofunction of_get_nand_ecc_step_sizefunction of_get_nand_ecc_strengthfunction of_get_nand_ecc_user_configfunction Requirementfunction nand_ecc_init_req_tweakingfunction nand_ecc_cleanup_req_tweakingfunction nand_ecc_tweak_reqfunction nand_ecc_restore_reqfunction nand_ecc_register_on_host_hw_enginefunction nand_ecc_unregister_on_host_hw_enginefunction nand_ecc_put_on_host_hw_engineexport nand_ecc_init_ctxexport nand_ecc_cleanup_ctxexport nand_ecc_prepare_io_reqexport nand_ecc_finish_io_reqexport nand_get_small_page_ooblayoutexport nand_get_large_page_ooblayoutexport nand_get_large_page_hamming_ooblayoutexport of_get_nand_ecc_user_configexport nand_ecc_is_strong_enoughexport nand_ecc_init_req_tweakingexport nand_ecc_cleanup_req_tweakingexport nand_ecc_tweak_reqexport nand_ecc_restore_reqexport nand_ecc_get_sw_engineexport nand_ecc_get_on_die_hw_engineexport nand_ecc_register_on_host_hw_engineexport nand_ecc_unregister_on_host_hw_engineexport nand_ecc_get_on_host_hw_engineexport nand_ecc_put_on_host_hw_engine
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/*
* Generic Error-Correcting Code (ECC) engine
*
* Copyright (C) 2019 Macronix
* Author:
* Miquèl RAYNAL <miquel.raynal@bootlin.com>
*
*
* This file describes the abstraction of any NAND ECC engine. It has been
* designed to fit most cases, including parallel NANDs and SPI-NANDs.
*
* There are three main situations where instantiating this ECC engine makes
* sense:
* - external: The ECC engine is outside the NAND pipeline, typically this
* is a software ECC engine, or an hardware engine that is
* outside the NAND controller pipeline.
* - pipelined: The ECC engine is inside the NAND pipeline, ie. on the
* controller's side. This is the case of most of the raw NAND
* controllers. In the pipeline case, the ECC bytes are
* generated/data corrected on the fly when a page is
* written/read.
* - ondie: The ECC engine is inside the NAND pipeline, on the chip's side.
* Some NAND chips can correct themselves the data.
*
* Besides the initial setup and final cleanups, the interfaces are rather
* simple:
* - prepare: Prepare an I/O request. Enable/disable the ECC engine based on
* the I/O request type. In case of software correction or external
* engine, this step may involve to derive the ECC bytes and place
* them in the OOB area before a write.
* - finish: Finish an I/O request. Correct the data in case of a read
* request and report the number of corrected bits/uncorrectable
* errors. Most likely empty for write operations, unless you have
* hardware specific stuff to do, like shutting down the engine to
* save power.
*
* The I/O request should be enclosed in a prepare()/finish() pair of calls
* and will behave differently depending on the requested I/O type:
* - raw: Correction disabled
* - ecc: Correction enabled
*
* The request direction is impacting the logic as well:
* - read: Load data from the NAND chip
* - write: Store data in the NAND chip
*
* Mixing all this combinations together gives the following behavior.
* Those are just examples, drivers are free to add custom steps in their
* prepare/finish hook.
*
* [external ECC engine]
* - external + prepare + raw + read: do nothing
* - external + finish + raw + read: do nothing
* - external + prepare + raw + write: do nothing
* - external + finish + raw + write: do nothing
* - external + prepare + ecc + read: do nothing
* - external + finish + ecc + read: calculate expected ECC bytes, extract
* ECC bytes from OOB buffer, correct
* and report any bitflip/error
* - external + prepare + ecc + write: calculate ECC bytes and store them at
* the right place in the OOB buffer based
* on the OOB layout
* - external + finish + ecc + write: do nothing
*
* [pipelined ECC engine]
* - pipelined + prepare + raw + read: disable the controller's ECC engine if
* activated
* - pipelined + finish + raw + read: do nothing
* - pipelined + prepare + raw + write: disable the controller's ECC engine if
* activated
* - pipelined + finish + raw + write: do nothing
* - pipelined + prepare + ecc + read: enable the controller's ECC engine if
* deactivated
* - pipelined + finish + ecc + read: check the status, report any
* error/bitflip
* - pipelined + prepare + ecc + write: enable the controller's ECC engine if
* deactivated
* - pipelined + finish + ecc + write: do nothing
*
* [ondie ECC engine]
* - ondie + prepare + raw + read: send commands to disable the on-chip ECC
* engine if activated
* - ondie + finish + raw + read: do nothing
* - ondie + prepare + raw + write: send commands to disable the on-chip ECC
* engine if activated
* - ondie + finish + raw + write: do nothing
* - ondie + prepare + ecc + read: send commands to enable the on-chip ECC
* engine if deactivated
* - ondie + finish + ecc + read: send commands to check the status, report
* any error/bitflip
Annotation
- Immediate include surface: `linux/module.h`, `linux/mtd/nand.h`, `linux/platform_device.h`, `linux/slab.h`, `linux/of.h`, `linux/of_platform.h`.
- Detected declarations: `function nand_ecc_init_ctx`, `function nand_ecc_cleanup_ctx`, `function nand_ecc_prepare_io_req`, `function nand_ecc_finish_io_req`, `function nand_ooblayout_ecc_sp`, `function nand_ooblayout_free_sp`, `function nand_ooblayout_ecc_lp`, `function nand_ooblayout_free_lp`, `function nand_ooblayout_ecc_lp_hamming`, `function nand_ooblayout_free_lp_hamming`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.