diff mbox

[3/3] mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs

Message ID 20170520152428.9184-4-mrugiero@gmail.com
State Changes Requested
Delegated to: Boris Brezillon
Headers show

Commit Message

Mario Rugiero May 20, 2017, 3:24 p.m. UTC
Signed-off-by: Mario J. Rugiero <mrugiero@gmail.com>
---
 drivers/mtd/nand/nand_base.c | 26 ++++++++++++++++++++++----
 include/linux/mtd/nand.h     | 12 ++++++++++++
 2 files changed, 34 insertions(+), 4 deletions(-)

Comments

Boris Brezillon May 20, 2017, 5:54 p.m. UTC | #1
Le Sat, 20 May 2017 12:24:28 -0300,
"Mario J. Rugiero" <mrugiero@gmail.com> a écrit :

And again, pleases add a commit message.

> Signed-off-by: Mario J. Rugiero <mrugiero@gmail.com>
> ---
>  drivers/mtd/nand/nand_base.c | 26 ++++++++++++++++++++++----
>  include/linux/mtd/nand.h     | 12 ++++++++++++
>  2 files changed, 34 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index 52a257e12026..8cffea38a642 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -47,6 +47,7 @@
>  #include <linux/io.h>
>  #include <linux/mtd/partitions.h>
>  #include <linux/of.h>
> +#include <linux/debugfs.h>
>  
>  static int nand_get_device(struct mtd_info *mtd, int new_state);
>  
> @@ -3209,10 +3210,15 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
>  		/* Check if we have a bad block, we do not erase bad blocks! */
>  		if (nand_block_checkbad(mtd, ((loff_t) page) <<
>  					chip->page_shift, allowbbt)) {
> -			pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
> -				    __func__, page);
> -			instr->state = MTD_ERASE_FAILED;
> -			goto erase_exit;
> +			if (!chip->dbg.scrub_enabled) {
> +				pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
> +				    	__func__, page);
> +				instr->state = MTD_ERASE_FAILED;
> +				goto erase_exit;
> +			} else {
> +				pr_warn("%s: erasing a bad block at page 0x%08x\n",
> +					__func__, page);
> +			}
>  		}
>  
>  		/*
> @@ -4931,6 +4937,18 @@ int nand_device_register(struct mtd_info *mtd,
>  			 int defnr_parts)
>  {
>  	int ret = nand_device_register(mtd, defparts, defnr_parts);
> +	struct nand_debug_info *dbg;
> +
> +	if (!ret) {
> +		dbg = &mtd_to_nand(mtd)->dbg;
> +		dbg->scrub_enabled = false;
> +		dbg->dfs_scrub_enabled = debugfs_create_bool("scrub_enabled",

Or just "scrub", the enable/disable status is reflected by the value
exposed by the file.
BTW, not sure scrub is clear enough, how about "allow-bad-block-erase"?

> +							     0600,
> +							     mtd->dbg.dfs_dir,
> +							     &dbg->scrub_enabled);
> +		if (IS_ERR(dbg->dfs_scrub_enabled))
> +			dbg->dfs_scrub_enabled = NULL;
> +	}

I prefer:

	struct nand_debug_info *dbg;
	int ret;

	ret = mtd_device_register(mtd, defparts, defnr_parts);
	if (ret)
		return ret;

	dbg = &chip->dbg;
	dbg->scrub_enabled = false;
	dbg->dfs_scrub_enabled = debugfs_create_bool("scrub", 0600, mtd->dbg.dfs_dir,
						     &dbg->scrub_enabled);
	if (IS_ERR(dbg->dfs_scrub_enabled))
		dbg->dfs_scrub_enabled = NULL;
  
  	return 0;


This way the error path is easily identified and you don't have to add
an indentation level for the normal path.

}
diff mbox

Patch

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 52a257e12026..8cffea38a642 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -47,6 +47,7 @@ 
 #include <linux/io.h>
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
+#include <linux/debugfs.h>
 
 static int nand_get_device(struct mtd_info *mtd, int new_state);
 
@@ -3209,10 +3210,15 @@  int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
 		/* Check if we have a bad block, we do not erase bad blocks! */
 		if (nand_block_checkbad(mtd, ((loff_t) page) <<
 					chip->page_shift, allowbbt)) {
-			pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
-				    __func__, page);
-			instr->state = MTD_ERASE_FAILED;
-			goto erase_exit;
+			if (!chip->dbg.scrub_enabled) {
+				pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
+				    	__func__, page);
+				instr->state = MTD_ERASE_FAILED;
+				goto erase_exit;
+			} else {
+				pr_warn("%s: erasing a bad block at page 0x%08x\n",
+					__func__, page);
+			}
 		}
 
 		/*
@@ -4931,6 +4937,18 @@  int nand_device_register(struct mtd_info *mtd,
 			 int defnr_parts)
 {
 	int ret = nand_device_register(mtd, defparts, defnr_parts);
+	struct nand_debug_info *dbg;
+
+	if (!ret) {
+		dbg = &mtd_to_nand(mtd)->dbg;
+		dbg->scrub_enabled = false;
+		dbg->dfs_scrub_enabled = debugfs_create_bool("scrub_enabled",
+							     0600,
+							     mtd->dbg.dfs_dir,
+							     &dbg->scrub_enabled);
+		if (IS_ERR(dbg->dfs_scrub_enabled))
+			dbg->dfs_scrub_enabled = NULL;
+	}
 
 	return ret;
 }
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 77fc60923fdd..24114b120d0f 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -731,6 +731,16 @@  struct nand_manufacturer_ops {
 };
 
 /**
+ * struct nand_debug_info - NAND specific debugfs
+ * @dfs_scrub_enabled:	dentry for setting force-erase of bad blocks
+ * @scrub_enabled:	if true, erase can erase blocks marked as bad
+ */
+struct nand_debug_info {
+	struct dentry *dfs_scrub_enabled;
+	bool scrub_enabled;
+};
+
+/**
  * struct nand_chip - NAND Private Flash Chip Data
  * @mtd:		MTD device registered to the MTD framework
  * @IO_ADDR_R:		[BOARDSPECIFIC] address to read the 8 I/O lines of the
@@ -835,6 +845,7 @@  struct nand_manufacturer_ops {
  *			additional error status checks (determine if errors are
  *			correctable).
  * @manufacturer:	[INTERN] Contains manufacturer information
+ * @dbg:		NAND debugfs data
  */
 
 struct nand_chip {
@@ -926,6 +937,7 @@  struct nand_chip {
 		const struct nand_manufacturer *desc;
 		void *priv;
 	} manufacturer;
+	struct nand_debug_info dbg;
 };
 
 extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops;