@@ -450,6 +450,26 @@ bool nand_ecc_correction_is_enough(struct nand_device *nand)
}
EXPORT_SYMBOL(nand_ecc_correction_is_enough);
+struct nand_ecc_engine *nand_ecc_get_sw_engine(struct nand_device *nand)
+{
+ unsigned int algo = nand->ecc.user_conf.algo;
+
+ if (algo == NAND_ECC_UNKNOWN)
+ algo = nand->ecc.defaults.algo;
+
+ switch (algo) {
+ case NAND_ECC_HAMMING:
+ return nand_ecc_sw_hamming_get_engine();
+ case NAND_ECC_BCH:
+ return nand_ecc_sw_bch_get_engine();
+ default:
+ break;
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL(nand_ecc_get_sw_engine);
+
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Miquel Raynal <miquel.raynal@bootlin.com>");
MODULE_DESCRIPTION("Generic ECC engine");
@@ -11,6 +11,9 @@
#include <linux/mtd/nand.h>
#include <linux/bch.h>
+/* Needed for cross inclusion with nand.h */
+struct nand_device;
+
/**
* struct nand_ecc_sw_bch_conf - private software BCH ECC engine structure
* @reqooblen: Save the actual user OOB length requested before overwriting it
@@ -12,6 +12,9 @@
#include <linux/mtd/nand.h>
+/* Needed for cross inclusion with nand.h */
+struct nand_device;
+
/**
* struct nand_ecc_sw_hamming_conf - private software Hamming ECC engine structure
* @reqooblen: Save the actual user OOB length requested before overwriting it
@@ -11,6 +11,8 @@
#define __LINUX_MTD_NAND_H
#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand-ecc-sw-hamming.h>
+#include <linux/mtd/nand-ecc-sw-bch.h>
struct nand_device;
@@ -245,6 +247,7 @@ int nand_ecc_prepare_io_req(struct nand_device *nand,
int nand_ecc_finish_io_req(struct nand_device *nand,
struct nand_page_io_req *req, void *oobbuf);
bool nand_ecc_correction_is_enough(struct nand_device *nand);
+struct nand_ecc_engine *nand_ecc_get_sw_engine(struct nand_device *nand);
/**
* struct nand_ecc - High-level ECC object
Before making use of the ECC engines, we must retrieve them. Add the boilerplate for the ones already available: software engines (Hamming and BCH). Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> --- drivers/mtd/nand/ecc/engine.c | 20 ++++++++++++++++++++ include/linux/mtd/nand-ecc-sw-bch.h | 3 +++ include/linux/mtd/nand-ecc-sw-hamming.h | 3 +++ include/linux/mtd/nand.h | 3 +++ 4 files changed, 29 insertions(+)