drivers/mtd/nand/ecc-mxic.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nand/ecc-mxic.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nand/ecc-mxic.c- Extension
.c- Size
- 23365 bytes
- Lines
- 879
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/dma-mapping.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/kernel.hlinux/module.hlinux/mtd/mtd.hlinux/mtd/nand.hlinux/mtd/nand-ecc-mxic.hlinux/mutex.hlinux/of.hlinux/of_platform.hlinux/platform_device.hlinux/slab.h
Detected Declarations
struct mxic_ecc_enginestruct mxic_ecc_ctxfunction mxic_ecc_ooblayout_eccfunction mxic_ecc_ooblayout_freefunction mxic_ecc_disable_enginefunction mxic_ecc_enable_enginefunction mxic_ecc_disable_intfunction mxic_ecc_enable_intfunction mxic_ecc_isrfunction mxic_ecc_init_ctxfunction mxic_ecc_init_ctx_externalfunction mxic_ecc_init_ctx_pipelinedfunction mxic_ecc_cleanup_ctxfunction mxic_ecc_data_xfer_wait_for_completionfunction mxic_ecc_process_datafunction mxic_ecc_process_data_pipelinedfunction mxic_ecc_extract_status_bytesfunction mxic_ecc_reconstruct_oobbuffunction mxic_ecc_add_room_in_oobbuffunction mxic_ecc_count_biterrsfunction mxic_ecc_prepare_io_req_externalfunction mxic_ecc_finish_io_req_externalfunction mxic_ecc_prepare_io_req_pipelinedfunction mxic_ecc_finish_io_req_pipelinedfunction mxic_ecc_get_pdevfunction mxic_ecc_put_pipelined_enginefunction mxic_ecc_get_pipelined_enginefunction mxic_ecc_probefunction mxic_ecc_removeexport mxic_ecc_process_data_pipelinedexport mxic_ecc_get_pipelined_opsexport mxic_ecc_put_pipelined_engineexport mxic_ecc_get_pipelined_engine
Annotated Snippet
struct mxic_ecc_engine {
struct device *dev;
void __iomem *regs;
int irq;
struct completion complete;
struct nand_ecc_engine external_engine;
struct nand_ecc_engine pipelined_engine;
struct mutex lock;
};
struct mxic_ecc_ctx {
/* ECC machinery */
unsigned int data_step_sz;
unsigned int oob_step_sz;
unsigned int parity_sz;
unsigned int meta_sz;
u8 *status;
int steps;
/* DMA boilerplate */
struct nand_ecc_req_tweak_ctx req_ctx;
u8 *oobwithstat;
struct scatterlist sg[2];
struct nand_page_io_req *req;
unsigned int pageoffs;
};
static struct mxic_ecc_engine *ext_ecc_eng_to_mxic(struct nand_ecc_engine *eng)
{
return container_of(eng, struct mxic_ecc_engine, external_engine);
}
static struct mxic_ecc_engine *pip_ecc_eng_to_mxic(struct nand_ecc_engine *eng)
{
return container_of(eng, struct mxic_ecc_engine, pipelined_engine);
}
static struct mxic_ecc_engine *nand_to_mxic(struct nand_device *nand)
{
struct nand_ecc_engine *eng = nand->ecc.engine;
if (eng->integration == NAND_ECC_ENGINE_INTEGRATION_EXTERNAL)
return ext_ecc_eng_to_mxic(eng);
else
return pip_ecc_eng_to_mxic(eng);
}
static int mxic_ecc_ooblayout_ecc(struct mtd_info *mtd, int section,
struct mtd_oob_region *oobregion)
{
struct nand_device *nand = mtd_to_nanddev(mtd);
struct mxic_ecc_ctx *ctx = nand_to_ecc_ctx(nand);
if (section < 0 || section >= ctx->steps)
return -ERANGE;
oobregion->offset = (section * ctx->oob_step_sz) + ctx->meta_sz;
oobregion->length = ctx->parity_sz;
return 0;
}
static int mxic_ecc_ooblayout_free(struct mtd_info *mtd, int section,
struct mtd_oob_region *oobregion)
{
struct nand_device *nand = mtd_to_nanddev(mtd);
struct mxic_ecc_ctx *ctx = nand_to_ecc_ctx(nand);
if (section < 0 || section >= ctx->steps)
return -ERANGE;
if (!section) {
oobregion->offset = 2;
oobregion->length = ctx->meta_sz - 2;
} else {
oobregion->offset = section * ctx->oob_step_sz;
oobregion->length = ctx->meta_sz;
}
return 0;
}
static const struct mtd_ooblayout_ops mxic_ecc_ooblayout_ops = {
.ecc = mxic_ecc_ooblayout_ecc,
.free = mxic_ecc_ooblayout_free,
};
static void mxic_ecc_disable_engine(struct mxic_ecc_engine *mxic)
{
u32 reg;
Annotation
- Immediate include surface: `linux/dma-mapping.h`, `linux/init.h`, `linux/interrupt.h`, `linux/io.h`, `linux/iopoll.h`, `linux/kernel.h`, `linux/module.h`, `linux/mtd/mtd.h`.
- Detected declarations: `struct mxic_ecc_engine`, `struct mxic_ecc_ctx`, `function mxic_ecc_ooblayout_ecc`, `function mxic_ecc_ooblayout_free`, `function mxic_ecc_disable_engine`, `function mxic_ecc_enable_engine`, `function mxic_ecc_disable_int`, `function mxic_ecc_enable_int`, `function mxic_ecc_isr`, `function mxic_ecc_init_ctx`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.