linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] mtd: nand: allow force erasing of bad blocks through debugfs entry
@ 2017-05-20 15:24 Mario J. Rugiero
  2017-05-20 15:24 ` [PATCH 1/3] mtd: create per-device and module-scope debugfs entries Mario J. Rugiero
  0 siblings, 1 reply; 11+ messages in thread
From: Mario J. Rugiero @ 2017-05-20 15:24 UTC (permalink / raw)
  To: linux-mtd
  Cc: computersforpeace, boris.brezillon, marek.vasut, richard,
	cyrille.pitchen, Mario J. Rugiero

Some manufacturers use different layouts than MTD for the NAND, creating
incompatibilities when going from a vendor-specific kernel to mainline.
In particular, NAND devices for AllWinner boards write non-FF values to
the bad block marker, and thus false positives arise when detecting bad
blocks with the MTD driver. Sometimes there are enough false positives
to make the device unusable.
A proposed solution is NAND scrubbing, something a user who knows what
she's doing (TM) could do to avoid this. It consists in erasing blocks
disregarding the BBM. Since the user must know what she's doing, the
only way to enable this feature is through a per-chip debugfs entry.

Mario J. Rugiero (3):
  mtd: create per-device and module-scope debugfs entries
  mtd: nand: create a wrapper for mtd_device_register for NAND specific
    initialization.
  mtd: nand: add option to ignore bad blocks when erasing, opt-in
    through debugfs

 drivers/mtd/mtdcore.c                    | 17 ++++++++++++
 drivers/mtd/mtdcore.h                    |  2 ++
 drivers/mtd/nand/ams-delta.c             |  2 +-
 drivers/mtd/nand/atmel/nand-controller.c |  2 +-
 drivers/mtd/nand/au1550nd.c              |  2 +-
 drivers/mtd/nand/bf5xx_nand.c            |  2 +-
 drivers/mtd/nand/brcmnand/brcmnand.c     |  2 +-
 drivers/mtd/nand/davinci_nand.c          |  2 +-
 drivers/mtd/nand/denali.c                |  2 +-
 drivers/mtd/nand/diskonchip.c            |  4 +--
 drivers/mtd/nand/fsl_upm.c               |  2 +-
 drivers/mtd/nand/fsmc_nand.c             |  2 +-
 drivers/mtd/nand/gpio.c                  |  2 +-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c   |  2 +-
 drivers/mtd/nand/hisi504_nand.c          |  2 +-
 drivers/mtd/nand/jz4780_nand.c           |  2 +-
 drivers/mtd/nand/lpc32xx_mlc.c           |  2 +-
 drivers/mtd/nand/lpc32xx_slc.c           |  2 +-
 drivers/mtd/nand/mpc5121_nfc.c           |  2 +-
 drivers/mtd/nand/nand_base.c             | 45 +++++++++++++++++++++++++++++---
 drivers/mtd/nand/nandsim.c               |  2 +-
 drivers/mtd/nand/ndfc.c                  |  2 +-
 drivers/mtd/nand/nuc900_nand.c           |  2 +-
 drivers/mtd/nand/omap2.c                 |  4 +--
 drivers/mtd/nand/orion_nand.c            |  2 +-
 drivers/mtd/nand/oxnas_nand.c            |  2 +-
 drivers/mtd/nand/pasemi_nand.c           |  2 +-
 drivers/mtd/nand/pxa3xx_nand.c           |  2 +-
 drivers/mtd/nand/qcom_nandc.c            |  2 +-
 drivers/mtd/nand/sh_flctl.c              |  2 +-
 drivers/mtd/nand/sm_common.c             |  2 +-
 drivers/mtd/nand/socrates_nand.c         |  2 +-
 drivers/mtd/nand/sunxi_nand.c            |  2 +-
 drivers/mtd/nand/tango_nand.c            |  2 +-
 drivers/mtd/nand/vf610_nfc.c             |  2 +-
 drivers/mtd/nand/xway_nand.c             |  2 +-
 include/linux/mtd/mtd.h                  | 10 +++++++
 include/linux/mtd/nand.h                 | 17 ++++++++++++
 38 files changed, 122 insertions(+), 39 deletions(-)

-- 
2.13.0

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/3] mtd: create per-device and module-scope debugfs entries
  2017-05-20 15:24 [PATCH 0/3] mtd: nand: allow force erasing of bad blocks through debugfs entry Mario J. Rugiero
@ 2017-05-20 15:24 ` Mario J. Rugiero
  2017-05-20 15:24   ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Mario J. Rugiero
  2017-05-20 16:21   ` [PATCH 1/3] mtd: create per-device and module-scope debugfs entries Boris Brezillon
  0 siblings, 2 replies; 11+ messages in thread
From: Mario J. Rugiero @ 2017-05-20 15:24 UTC (permalink / raw)
  To: linux-mtd
  Cc: computersforpeace, boris.brezillon, marek.vasut, richard,
	cyrille.pitchen, Mario J. Rugiero

Signed-off-by: Mario J. Rugiero <mrugiero@gmail.com>
---
 drivers/mtd/mtdcore.c   | 17 +++++++++++++++++
 drivers/mtd/mtdcore.h   |  2 ++
 include/linux/mtd/mtd.h | 10 ++++++++++
 3 files changed, 29 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 1517da3ddd7d..461e8139ac2d 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -40,6 +40,7 @@
 #include <linux/slab.h>
 #include <linux/reboot.h>
 #include <linux/leds.h>
+#include <linux/debugfs.h>
 
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
@@ -662,6 +663,8 @@ static void mtd_set_dev_defaults(struct mtd_info *mtd)
 	}
 }
 
+static struct dentry *dfs_dir_mtd;
+
 /**
  * mtd_device_parse_register - parse partitions and register an MTD device.
  *
@@ -701,6 +704,10 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 
 	mtd_set_dev_defaults(mtd);
 
+	mtd->dbg.dfs_dir = debugfs_create_dir(mtd->name, dfs_dir_mtd);
+	if (IS_ERR(mtd->dbg.dfs_dir))
+		mtd->dbg.dfs_dir = NULL;
+
 	memset(&parsed, 0, sizeof(parsed));
 
 	ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
@@ -740,6 +747,8 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 out:
 	/* Cleanup any parsed partitions */
 	mtd_part_parser_cleanup(&parsed);
+	if (ret)
+		debugfs_remove_recursive(mtd->dbg.dfs_dir);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(mtd_device_parse_register);
@@ -754,6 +763,8 @@ int mtd_device_unregister(struct mtd_info *master)
 {
 	int err;
 
+	debugfs_remove_recursive(master->dbg.dfs_dir);
+
 	if (master->_reboot)
 		unregister_reboot_notifier(&master->reboot_notifier);
 
@@ -1807,6 +1818,10 @@ static int __init init_mtd(void)
 
 	proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
 
+	dfs_dir_mtd = debugfs_create_dir("mtd", NULL);
+	if (IS_ERR(dfs_dir_mtd))
+		dfs_dir_mtd = NULL;
+
 	ret = init_mtdchar();
 	if (ret)
 		goto out_procfs;
@@ -1816,6 +1831,7 @@ static int __init init_mtd(void)
 out_procfs:
 	if (proc_mtd)
 		remove_proc_entry("mtd", NULL);
+	debugfs_remove(dfs_dir_mtd);
 	bdi_put(mtd_bdi);
 err_bdi:
 	class_unregister(&mtd_class);
@@ -1826,6 +1842,7 @@ static int __init init_mtd(void)
 
 static void __exit cleanup_mtd(void)
 {
+	debugfs_remove_recursive(dfs_dir_mtd);
 	cleanup_mtdchar();
 	if (proc_mtd)
 		remove_proc_entry("mtd", NULL);
diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h
index 55fdb8e1fd2a..b5d095d24087 100644
--- a/drivers/mtd/mtdcore.h
+++ b/drivers/mtd/mtdcore.h
@@ -19,6 +19,8 @@ int parse_mtd_partitions(struct mtd_info *master, const char * const *types,
 
 void mtd_part_parser_cleanup(struct mtd_partitions *parts);
 
+extern struct dentry *debug_mtd;
+
 int __init init_mtdchar(void);
 void __exit cleanup_mtdchar(void);
 
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index f8a2ef239c60..6cd0f6b7658b 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -206,6 +206,15 @@ struct mtd_pairing_scheme {
 
 struct module;	/* only needed for owner field in mtd_info */
 
+/**
+ * struct mtd_debug_info - debugging information for an MTD device.
+ *
+ * @dfs_dir: direntry object of the MTD device debugfs directory
+ */
+struct mtd_debug_info {
+	struct dentry *dfs_dir;
+};
+
 struct mtd_info {
 	u_char type;
 	uint32_t flags;
@@ -346,6 +355,7 @@ struct mtd_info {
 	struct module *owner;
 	struct device dev;
 	int usecount;
+	struct mtd_debug_info dbg;
 };
 
 int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
  2017-05-20 15:24 ` [PATCH 1/3] mtd: create per-device and module-scope debugfs entries Mario J. Rugiero
@ 2017-05-20 15:24   ` Mario J. Rugiero
  2017-05-20 15:24     ` [PATCH 3/3] mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs Mario J. Rugiero
                       ` (3 more replies)
  2017-05-20 16:21   ` [PATCH 1/3] mtd: create per-device and module-scope debugfs entries Boris Brezillon
  1 sibling, 4 replies; 11+ messages in thread
From: Mario J. Rugiero @ 2017-05-20 15:24 UTC (permalink / raw)
  To: linux-mtd
  Cc: computersforpeace, boris.brezillon, marek.vasut, richard,
	cyrille.pitchen, Mario J. Rugiero

Drivers are updated to use this wrapper.

Signed-off-by: Mario J. Rugiero <mrugiero@gmail.com>
---
 drivers/mtd/nand/ams-delta.c             |  2 +-
 drivers/mtd/nand/atmel/nand-controller.c |  2 +-
 drivers/mtd/nand/au1550nd.c              |  2 +-
 drivers/mtd/nand/bf5xx_nand.c            |  2 +-
 drivers/mtd/nand/brcmnand/brcmnand.c     |  2 +-
 drivers/mtd/nand/davinci_nand.c          |  2 +-
 drivers/mtd/nand/denali.c                |  2 +-
 drivers/mtd/nand/diskonchip.c            |  4 ++--
 drivers/mtd/nand/fsl_upm.c               |  2 +-
 drivers/mtd/nand/fsmc_nand.c             |  2 +-
 drivers/mtd/nand/gpio.c                  |  2 +-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c   |  2 +-
 drivers/mtd/nand/hisi504_nand.c          |  2 +-
 drivers/mtd/nand/jz4780_nand.c           |  2 +-
 drivers/mtd/nand/lpc32xx_mlc.c           |  2 +-
 drivers/mtd/nand/lpc32xx_slc.c           |  2 +-
 drivers/mtd/nand/mpc5121_nfc.c           |  2 +-
 drivers/mtd/nand/nand_base.c             | 19 +++++++++++++++++++
 drivers/mtd/nand/nandsim.c               |  2 +-
 drivers/mtd/nand/ndfc.c                  |  2 +-
 drivers/mtd/nand/nuc900_nand.c           |  2 +-
 drivers/mtd/nand/omap2.c                 |  4 ++--
 drivers/mtd/nand/orion_nand.c            |  2 +-
 drivers/mtd/nand/oxnas_nand.c            |  2 +-
 drivers/mtd/nand/pasemi_nand.c           |  2 +-
 drivers/mtd/nand/pxa3xx_nand.c           |  2 +-
 drivers/mtd/nand/qcom_nandc.c            |  2 +-
 drivers/mtd/nand/sh_flctl.c              |  2 +-
 drivers/mtd/nand/sm_common.c             |  2 +-
 drivers/mtd/nand/socrates_nand.c         |  2 +-
 drivers/mtd/nand/sunxi_nand.c            |  2 +-
 drivers/mtd/nand/tango_nand.c            |  2 +-
 drivers/mtd/nand/vf610_nfc.c             |  2 +-
 drivers/mtd/nand/xway_nand.c             |  2 +-
 include/linux/mtd/nand.h                 |  5 +++++
 35 files changed, 59 insertions(+), 35 deletions(-)

diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index 5d6c26f3cf7f..fd97d8922eb5 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -239,7 +239,7 @@ static int ams_delta_init(struct platform_device *pdev)
 		goto out_mtd;
 
 	/* Register the partitions */
-	mtd_device_register(ams_delta_mtd, partition_info,
+	nand_device_register(ams_delta_mtd, partition_info,
 			    ARRAY_SIZE(partition_info));
 
 	goto out;
diff --git a/drivers/mtd/nand/atmel/nand-controller.c b/drivers/mtd/nand/atmel/nand-controller.c
index 3b2446896147..734d1e9f15cd 100644
--- a/drivers/mtd/nand/atmel/nand-controller.c
+++ b/drivers/mtd/nand/atmel/nand-controller.c
@@ -1312,7 +1312,7 @@ static int atmel_nand_register(struct atmel_nand *nand)
 		return ret;
 	}
 
-	ret = mtd_device_register(mtd, NULL, 0);
+	ret = nand_device_register(mtd, NULL, 0);
 	if (ret) {
 		dev_err(nc->dev, "Failed to register mtd device: %d\n", ret);
 		nand_cleanup(chip);
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 9bf6d9915694..d44168fc4d00 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -476,7 +476,7 @@ static int au1550nd_probe(struct platform_device *pdev)
 		goto out3;
 	}
 
-	mtd_device_register(mtd, pd->parts, pd->num_parts);
+	nand_device_register(mtd, pd->parts, pd->num_parts);
 
 	platform_set_drvdata(pdev, ctx);
 
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index 3962f55bd034..cd1404c48331 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -677,7 +677,7 @@ static int bf5xx_nand_add_partition(struct bf5xx_nand_info *info)
 	struct mtd_partition *parts = info->platform->partitions;
 	int nr = info->platform->nr_partitions;
 
-	return mtd_device_register(mtd, parts, nr);
+	return nand_device_register(mtd, parts, nr);
 }
 
 static int bf5xx_nand_remove(struct platform_device *pdev)
diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
index 7419c5ce63f8..de4dcb1fc574 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -2294,7 +2294,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host, struct device_node *dn)
 	if (ret)
 		return ret;
 
-	return mtd_device_register(mtd, NULL, 0);
+	return nand_device_register(mtd, NULL, 0);
 }
 
 static void brcmnand_save_restore_cs_config(struct brcmnand_host *host,
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index 531c51991e57..0cb21afb29a4 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -821,7 +821,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
 		ret = mtd_device_parse_register(mtd, NULL, NULL,
 					pdata->parts, pdata->nr_parts);
 	else
-		ret = mtd_device_register(mtd, NULL, 0);
+		ret = nand_device_register(mtd, NULL, 0);
 	if (ret < 0)
 		goto err;
 
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 16634df2e39a..76d70e2dbab8 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -1630,7 +1630,7 @@ int denali_init(struct denali_nand_info *denali)
 	if (ret)
 		goto failed_req_irq;
 
-	ret = mtd_device_register(mtd, NULL, 0);
+	ret = nand_device_register(mtd, NULL, 0);
 	if (ret) {
 		dev_err(denali->dev, "Failed to register MTD: %d\n", ret);
 		goto failed_req_irq;
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index a023ab9e9cbf..d6356a781107 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -1298,7 +1298,7 @@ static int __init nftl_scan_bbt(struct mtd_info *mtd)
 	if (ret)
 		return ret;
 
-	return mtd_device_register(mtd, parts, no_autopart ? 0 : numparts);
+	return nand_device_register(mtd, parts, no_autopart ? 0 : numparts);
 }
 
 static int __init inftl_scan_bbt(struct mtd_info *mtd)
@@ -1352,7 +1352,7 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd)
 	   autopartitioning, but I want to give it more thought. */
 	if (!numparts)
 		return -EIO;
-	return mtd_device_register(mtd, parts, no_autopart ? 0 : numparts);
+	return nand_device_register(mtd, parts, no_autopart ? 0 : numparts);
 }
 
 static inline int __init doc2000_init(struct mtd_info *mtd)
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index d85fa2555b68..5c85139e6488 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -195,7 +195,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
 	if (ret)
 		goto err;
 
-	ret = mtd_device_register(mtd, NULL, 0);
+	ret = nand_device_register(mtd, NULL, 0);
 err:
 	of_node_put(flash_np);
 	if (ret)
diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index cea50d2f218c..c2970f9b729c 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -1019,7 +1019,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
 		goto err_probe;
 
 	mtd->name = "nand";
-	ret = mtd_device_register(mtd, NULL, 0);
+	ret = nand_device_register(mtd, NULL, 0);
 	if (ret)
 		goto err_probe;
 
diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c
index 85294f150f4f..4cdbb875ae53 100644
--- a/drivers/mtd/nand/gpio.c
+++ b/drivers/mtd/nand/gpio.c
@@ -299,7 +299,7 @@ static int gpio_nand_probe(struct platform_device *pdev)
 	if (gpiomtd->plat.adjust_parts)
 		gpiomtd->plat.adjust_parts(&gpiomtd->plat, mtd->size);
 
-	ret = mtd_device_register(mtd, gpiomtd->plat.parts,
+	ret = nand_device_register(mtd, gpiomtd->plat.parts,
 				  gpiomtd->plat.num_parts);
 	if (!ret)
 		return 0;
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index d52139635b67..dbb963423c6e 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -2053,7 +2053,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
 	if (ret)
 		goto err_out;
 
-	ret = mtd_device_register(mtd, NULL, 0);
+	ret = nand_device_register(mtd, NULL, 0);
 	if (ret)
 		goto err_out;
 	return 0;
diff --git a/drivers/mtd/nand/hisi504_nand.c b/drivers/mtd/nand/hisi504_nand.c
index e40364eeb556..af15b84ee349 100644
--- a/drivers/mtd/nand/hisi504_nand.c
+++ b/drivers/mtd/nand/hisi504_nand.c
@@ -812,7 +812,7 @@ static int hisi_nfc_probe(struct platform_device *pdev)
 		goto err_res;
 	}
 
-	ret = mtd_device_register(mtd, NULL, 0);
+	ret = nand_device_register(mtd, NULL, 0);
 	if (ret) {
 		dev_err(dev, "Err MTD partition=%d\n", ret);
 		goto err_mtd;
diff --git a/drivers/mtd/nand/jz4780_nand.c b/drivers/mtd/nand/jz4780_nand.c
index a39bb70175ee..5ebe726eb9b9 100644
--- a/drivers/mtd/nand/jz4780_nand.c
+++ b/drivers/mtd/nand/jz4780_nand.c
@@ -291,7 +291,7 @@ static int jz4780_nand_init_chip(struct platform_device *pdev,
 	if (ret)
 		return ret;
 
-	ret = mtd_device_register(mtd, NULL, 0);
+	ret = nand_device_register(mtd, NULL, 0);
 	if (ret) {
 		nand_release(mtd);
 		return ret;
diff --git a/drivers/mtd/nand/lpc32xx_mlc.c b/drivers/mtd/nand/lpc32xx_mlc.c
index 846a66c1b133..2f22184fcc44 100644
--- a/drivers/mtd/nand/lpc32xx_mlc.c
+++ b/drivers/mtd/nand/lpc32xx_mlc.c
@@ -798,7 +798,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 
 	mtd->name = DRV_NAME;
 
-	res = mtd_device_register(mtd, host->ncfg->parts,
+	res = nand_device_register(mtd, host->ncfg->parts,
 				  host->ncfg->num_parts);
 	if (!res)
 		return res;
diff --git a/drivers/mtd/nand/lpc32xx_slc.c b/drivers/mtd/nand/lpc32xx_slc.c
index a0669a33f8fe..d7a4b9d437d8 100644
--- a/drivers/mtd/nand/lpc32xx_slc.c
+++ b/drivers/mtd/nand/lpc32xx_slc.c
@@ -928,7 +928,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 		goto err_exit3;
 
 	mtd->name = "nxp_lpc3220_slc";
-	res = mtd_device_register(mtd, host->ncfg->parts,
+	res = nand_device_register(mtd, host->ncfg->parts,
 				  host->ncfg->num_parts);
 	if (!res)
 		return res;
diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index 6d6eaed2d20c..62eda8644ca5 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -810,7 +810,7 @@ static int mpc5121_nfc_probe(struct platform_device *op)
 	dev_set_drvdata(dev, mtd);
 
 	/* Register device in MTD */
-	retval = mtd_device_register(mtd, NULL, 0);
+	retval = nand_device_register(mtd, NULL, 0);
 	if (retval) {
 		dev_err(dev, "Error adding MTD device!\n");
 		goto error;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index d474378ed810..52a257e12026 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -4918,6 +4918,25 @@ void nand_cleanup(struct nand_chip *chip)
 EXPORT_SYMBOL_GPL(nand_cleanup);
 
 /**
+ * nand_device_register - [NAND Interface] Register the MTD device and
+ *                        allocate resources for the NAND device
+ * @mtd: MTD device structure
+ * @defparts: default device partitions array, from C-based board files
+ * @defnr_parts: number of elements in defparts
+ *
+ * @return
+ */
+int nand_device_register(struct mtd_info *mtd,
+			 const struct mtd_partition *defparts,
+			 int defnr_parts)
+{
+	int ret = nand_device_register(mtd, defparts, defnr_parts);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(nand_device_register);
+
+/**
  * nand_release - [NAND Interface] Unregister the MTD device and free resources
  *		  held by the NAND device
  * @mtd: MTD device structure
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 03a0d057bf2f..037afc62f856 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -2365,7 +2365,7 @@ static int __init ns_init_module(void)
 		goto err_exit;
 
 	/* Register NAND partitions */
-	retval = mtd_device_register(nsmtd, &nand->partitions[0],
+	retval = nand_device_register(nsmtd, &nand->partitions[0],
 				     nand->nbparts);
 	if (retval != 0)
 		goto err_exit;
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index 28e6118362f7..8d1207f3e0cd 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -185,7 +185,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
 	if (ret)
 		goto err;
 
-	ret = mtd_device_register(mtd, NULL, 0);
+	ret = nand_device_register(mtd, NULL, 0);
 
 err:
 	of_node_put(flash_np);
diff --git a/drivers/mtd/nand/nuc900_nand.c b/drivers/mtd/nand/nuc900_nand.c
index 8f64011d32ef..54b962c472bb 100644
--- a/drivers/mtd/nand/nuc900_nand.c
+++ b/drivers/mtd/nand/nuc900_nand.c
@@ -273,7 +273,7 @@ static int nuc900_nand_probe(struct platform_device *pdev)
 	if (nand_scan(mtd, 1))
 		return -ENXIO;
 
-	mtd_device_register(mtd, partitions, ARRAY_SIZE(partitions));
+	nand_device_register(mtd, partitions, ARRAY_SIZE(partitions));
 
 	platform_set_drvdata(pdev, nuc900_nand);
 
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 084934a9f19c..31e2d9aa497e 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -2168,9 +2168,9 @@ static int omap_nand_probe(struct platform_device *pdev)
 		goto return_error;
 
 	if (dev->of_node)
-		mtd_device_register(mtd, NULL, 0);
+		nand_device_register(mtd, NULL, 0);
 	else
-		mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
+		nand_device_register(mtd, pdata->parts, pdata->nr_parts);
 
 	platform_set_drvdata(pdev, mtd);
 
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index f8e463a97b9e..34b26169734f 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -173,7 +173,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
 		goto no_dev;
 
 	mtd->name = "orion_nand";
-	ret = mtd_device_register(mtd, board->parts, board->nr_parts);
+	ret = nand_device_register(mtd, board->parts, board->nr_parts);
 	if (ret) {
 		nand_release(mtd);
 		goto no_dev;
diff --git a/drivers/mtd/nand/oxnas_nand.c b/drivers/mtd/nand/oxnas_nand.c
index 1b207aac840c..cbc52b68775a 100644
--- a/drivers/mtd/nand/oxnas_nand.c
+++ b/drivers/mtd/nand/oxnas_nand.c
@@ -141,7 +141,7 @@ static int oxnas_nand_probe(struct platform_device *pdev)
 		if (err)
 			return err;
 
-		err = mtd_device_register(mtd, NULL, 0);
+		err = nand_device_register(mtd, NULL, 0);
 		if (err) {
 			nand_release(mtd);
 			return err;
diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c
index 074b8b01289e..6ac3b7693205 100644
--- a/drivers/mtd/nand/pasemi_nand.c
+++ b/drivers/mtd/nand/pasemi_nand.c
@@ -160,7 +160,7 @@ static int pasemi_nand_probe(struct platform_device *ofdev)
 	if (err)
 		goto out_lpc;
 
-	if (mtd_device_register(pasemi_nand_mtd, NULL, 0)) {
+	if (nand_device_register(pasemi_nand_mtd, NULL, 0)) {
 		dev_err(dev, "Unable to register MTD device\n");
 		err = -ENODEV;
 		goto out_lpc;
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index 649ba8200832..86ca08b51b1c 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -1988,7 +1988,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
 			continue;
 		}
 
-		ret = mtd_device_register(mtd, pdata->parts[cs],
+		ret = nand_device_register(mtd, pdata->parts[cs],
 					  pdata->nr_parts[cs]);
 		if (!ret)
 			probe_success = 1;
diff --git a/drivers/mtd/nand/qcom_nandc.c b/drivers/mtd/nand/qcom_nandc.c
index 57d483ac5765..9e4038735e88 100644
--- a/drivers/mtd/nand/qcom_nandc.c
+++ b/drivers/mtd/nand/qcom_nandc.c
@@ -2039,7 +2039,7 @@ static int qcom_nand_host_init(struct qcom_nand_controller *nandc,
 	if (ret)
 		return ret;
 
-	return mtd_device_register(mtd, NULL, 0);
+	return nand_device_register(mtd, NULL, 0);
 }
 
 /* parse custom DT properties here */
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index 442ce619b3b6..6c4b7e4397e7 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -1214,7 +1214,7 @@ static int flctl_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_chip;
 
-	ret = mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
+	ret = nand_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
 
 	return 0;
 
diff --git a/drivers/mtd/nand/sm_common.c b/drivers/mtd/nand/sm_common.c
index 5939dff253c2..396a3916d300 100644
--- a/drivers/mtd/nand/sm_common.c
+++ b/drivers/mtd/nand/sm_common.c
@@ -193,7 +193,7 @@ int sm_register_device(struct mtd_info *mtd, int smartmedia)
 	if (ret)
 		return ret;
 
-	return mtd_device_register(mtd, NULL, 0);
+	return nand_device_register(mtd, NULL, 0);
 }
 EXPORT_SYMBOL_GPL(sm_register_device);
 
diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index 72369bd079af..5d9b40bd71b6 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -191,7 +191,7 @@ static int socrates_nand_probe(struct platform_device *ofdev)
 	if (res)
 		goto out;
 
-	res = mtd_device_register(mtd, NULL, 0);
+	res = nand_device_register(mtd, NULL, 0);
 	if (!res)
 		return res;
 
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index 118a26fff368..8c470743c5d9 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -2115,7 +2115,7 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
 		return ret;
 	}
 
-	ret = mtd_device_register(mtd, NULL, 0);
+	ret = nand_device_register(mtd, NULL, 0);
 	if (ret) {
 		dev_err(dev, "failed to register mtd device: %d\n", ret);
 		nand_release(mtd);
diff --git a/drivers/mtd/nand/tango_nand.c b/drivers/mtd/nand/tango_nand.c
index 05b6e1065203..96c80525d40b 100644
--- a/drivers/mtd/nand/tango_nand.c
+++ b/drivers/mtd/nand/tango_nand.c
@@ -583,7 +583,7 @@ static int chip_init(struct device *dev, struct device_node *np)
 	tchip->pkt_n_cfg = PKT_CFG(ecc->size, ecc->strength);
 	tchip->bb_cfg = BB_CFG(mtd->writesize, BBM_SIZE);
 
-	err = mtd_device_register(mtd, NULL, 0);
+	err = nand_device_register(mtd, NULL, 0);
 	if (err)
 		return err;
 
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 3ea4bb19e12d..f9ec94536390 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -781,7 +781,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, mtd);
 
 	/* Register device in MTD */
-	return mtd_device_register(mtd, NULL, 0);
+	return nand_device_register(mtd, NULL, 0);
 
 error:
 	of_node_put(nand_get_flash_node(chip));
diff --git a/drivers/mtd/nand/xway_nand.c b/drivers/mtd/nand/xway_nand.c
index ddee4005248c..abe59140b7b6 100644
--- a/drivers/mtd/nand/xway_nand.c
+++ b/drivers/mtd/nand/xway_nand.c
@@ -209,7 +209,7 @@ static int xway_nand_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 
-	err = mtd_device_register(mtd, NULL, 0);
+	err = nand_device_register(mtd, NULL, 0);
 	if (err)
 		nand_release(mtd);
 
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 8f67b1581683..77fc60923fdd 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -38,6 +38,11 @@ int nand_scan_ident(struct mtd_info *mtd, int max_chips,
 			   struct nand_flash_dev *table);
 int nand_scan_tail(struct mtd_info *mtd);
 
+/* Register the MTD device and allocate resources for the NAND device */
+int nand_device_register(struct mtd_info *mtd,
+			 const struct mtd_partition *defparts,
+			 int defnr_parts);
+
 /* Unregister the MTD device and free resources held by the NAND device */
 void nand_release(struct mtd_info *mtd);
 
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/3] mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs
  2017-05-20 15:24   ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Mario J. Rugiero
@ 2017-05-20 15:24     ` Mario J. Rugiero
  2017-05-20 17:54       ` Boris Brezillon
  2017-05-20 17:38     ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Boris Brezillon
                       ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Mario J. Rugiero @ 2017-05-20 15:24 UTC (permalink / raw)
  To: linux-mtd
  Cc: computersforpeace, boris.brezillon, marek.vasut, richard,
	cyrille.pitchen, Mario J. Rugiero

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",
+							     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;
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/3] mtd: create per-device and module-scope debugfs entries
  2017-05-20 15:24 ` [PATCH 1/3] mtd: create per-device and module-scope debugfs entries Mario J. Rugiero
  2017-05-20 15:24   ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Mario J. Rugiero
@ 2017-05-20 16:21   ` Boris Brezillon
  2017-05-20 16:41     ` Mario Rugiero
  1 sibling, 1 reply; 11+ messages in thread
From: Boris Brezillon @ 2017-05-20 16:21 UTC (permalink / raw)
  To: Mario J. Rugiero
  Cc: linux-mtd, computersforpeace, marek.vasut, richard,
	cyrille.pitchen

Le Sat, 20 May 2017 12:24:26 -0300,
"Mario J. Rugiero" <mrugiero@gmail.com> a écrit :

I'd like to have a bit more details explaining why you want to do that.
Something like:

"
Several MTD drivers are currently creating their own debugfs directory
at the root of the debugfs filesystem. Create an mtd directory and one
subdirectory per MTD device so that specific MTD drivers or sub-layers
(NAND, SPI-NOR, ...) can add their own debugfs files under a well known
directory instead of spreading them over the debugfs tree.
"

> Signed-off-by: Mario J. Rugiero <mrugiero@gmail.com>

You forgot to add my Ack here.

> ---

There should be a changelog here, or in the cover letter describing the
evolution of this patch.

>  drivers/mtd/mtdcore.c   | 17 +++++++++++++++++
>  drivers/mtd/mtdcore.h   |  2 ++
>  include/linux/mtd/mtd.h | 10 ++++++++++
>  3 files changed, 29 insertions(+)
> 
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index 1517da3ddd7d..461e8139ac2d 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -40,6 +40,7 @@
>  #include <linux/slab.h>
>  #include <linux/reboot.h>
>  #include <linux/leds.h>
> +#include <linux/debugfs.h>
>  
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/partitions.h>
> @@ -662,6 +663,8 @@ static void mtd_set_dev_defaults(struct mtd_info *mtd)
>  	}
>  }
>  
> +static struct dentry *dfs_dir_mtd;
> +
>  /**
>   * mtd_device_parse_register - parse partitions and register an MTD device.
>   *
> @@ -701,6 +704,10 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
>  
>  	mtd_set_dev_defaults(mtd);
>  
> +	mtd->dbg.dfs_dir = debugfs_create_dir(mtd->name, dfs_dir_mtd);
> +	if (IS_ERR(mtd->dbg.dfs_dir))
> +		mtd->dbg.dfs_dir = NULL;
> +
>  	memset(&parsed, 0, sizeof(parsed));
>  
>  	ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
> @@ -740,6 +747,8 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
>  out:
>  	/* Cleanup any parsed partitions */
>  	mtd_part_parser_cleanup(&parsed);
> +	if (ret)
> +		debugfs_remove_recursive(mtd->dbg.dfs_dir);
>  	return ret;
>  }
>  EXPORT_SYMBOL_GPL(mtd_device_parse_register);
> @@ -754,6 +763,8 @@ int mtd_device_unregister(struct mtd_info *master)
>  {
>  	int err;
>  
> +	debugfs_remove_recursive(master->dbg.dfs_dir);
> +
>  	if (master->_reboot)
>  		unregister_reboot_notifier(&master->reboot_notifier);
>  
> @@ -1807,6 +1818,10 @@ static int __init init_mtd(void)
>  
>  	proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
>  
> +	dfs_dir_mtd = debugfs_create_dir("mtd", NULL);
> +	if (IS_ERR(dfs_dir_mtd))
> +		dfs_dir_mtd = NULL;
> +
>  	ret = init_mtdchar();
>  	if (ret)
>  		goto out_procfs;
> @@ -1816,6 +1831,7 @@ static int __init init_mtd(void)
>  out_procfs:
>  	if (proc_mtd)
>  		remove_proc_entry("mtd", NULL);
> +	debugfs_remove(dfs_dir_mtd);
>  	bdi_put(mtd_bdi);
>  err_bdi:
>  	class_unregister(&mtd_class);
> @@ -1826,6 +1842,7 @@ static int __init init_mtd(void)
>  
>  static void __exit cleanup_mtd(void)
>  {
> +	debugfs_remove_recursive(dfs_dir_mtd);
>  	cleanup_mtdchar();
>  	if (proc_mtd)
>  		remove_proc_entry("mtd", NULL);
> diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h
> index 55fdb8e1fd2a..b5d095d24087 100644
> --- a/drivers/mtd/mtdcore.h
> +++ b/drivers/mtd/mtdcore.h
> @@ -19,6 +19,8 @@ int parse_mtd_partitions(struct mtd_info *master, const char * const *types,
>  
>  void mtd_part_parser_cleanup(struct mtd_partitions *parts);
>  
> +extern struct dentry *debug_mtd;
> +
>  int __init init_mtdchar(void);
>  void __exit cleanup_mtdchar(void);
>  
> diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
> index f8a2ef239c60..6cd0f6b7658b 100644
> --- a/include/linux/mtd/mtd.h
> +++ b/include/linux/mtd/mtd.h
> @@ -206,6 +206,15 @@ struct mtd_pairing_scheme {
>  
>  struct module;	/* only needed for owner field in mtd_info */
>  
> +/**
> + * struct mtd_debug_info - debugging information for an MTD device.
> + *
> + * @dfs_dir: direntry object of the MTD device debugfs directory
> + */
> +struct mtd_debug_info {
> +	struct dentry *dfs_dir;
> +};
> +
>  struct mtd_info {
>  	u_char type;
>  	uint32_t flags;
> @@ -346,6 +355,7 @@ struct mtd_info {
>  	struct module *owner;
>  	struct device dev;
>  	int usecount;
> +	struct mtd_debug_info dbg;
>  };
>  
>  int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/3] mtd: create per-device and module-scope debugfs entries
  2017-05-20 16:21   ` [PATCH 1/3] mtd: create per-device and module-scope debugfs entries Boris Brezillon
@ 2017-05-20 16:41     ` Mario Rugiero
  0 siblings, 0 replies; 11+ messages in thread
From: Mario Rugiero @ 2017-05-20 16:41 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: linux-mtd, Brian Norris, Marek Vašut, Richard Weinberger,
	cyrille.pitchen

2017-05-20 13:21 GMT-03:00 Boris Brezillon <boris.brezillon@free-electrons.com>:
> Le Sat, 20 May 2017 12:24:26 -0300,
> "Mario J. Rugiero" <mrugiero@gmail.com> a écrit :
>
> I'd like to have a bit more details explaining why you want to do that.
> Something like:
>
> "
> Several MTD drivers are currently creating their own debugfs directory
> at the root of the debugfs filesystem. Create an mtd directory and one
> subdirectory per MTD device so that specific MTD drivers or sub-layers
> (NAND, SPI-NOR, ...) can add their own debugfs files under a well known
> directory instead of spreading them over the debugfs tree.
> "
I'd probably use that text verbatim. Would that be right?
I hadn't realized some drivers did create their own entries at the
root, should a patch in this patch set update them to use the
per-device entry?
>
>> Signed-off-by: Mario J. Rugiero <mrugiero@gmail.com>
>
> You forgot to add my Ack here.
>
>> ---
>
> There should be a changelog here, or in the cover letter describing the
> evolution of this patch.
>
>>  drivers/mtd/mtdcore.c   | 17 +++++++++++++++++
>>  drivers/mtd/mtdcore.h   |  2 ++
>>  include/linux/mtd/mtd.h | 10 ++++++++++
>>  3 files changed, 29 insertions(+)
>>
>> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
>> index 1517da3ddd7d..461e8139ac2d 100644
>> --- a/drivers/mtd/mtdcore.c
>> +++ b/drivers/mtd/mtdcore.c
>> @@ -40,6 +40,7 @@
>>  #include <linux/slab.h>
>>  #include <linux/reboot.h>
>>  #include <linux/leds.h>
>> +#include <linux/debugfs.h>
>>
>>  #include <linux/mtd/mtd.h>
>>  #include <linux/mtd/partitions.h>
>> @@ -662,6 +663,8 @@ static void mtd_set_dev_defaults(struct mtd_info *mtd)
>>       }
>>  }
>>
>> +static struct dentry *dfs_dir_mtd;
>> +
>>  /**
>>   * mtd_device_parse_register - parse partitions and register an MTD device.
>>   *
>> @@ -701,6 +704,10 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
>>
>>       mtd_set_dev_defaults(mtd);
>>
>> +     mtd->dbg.dfs_dir = debugfs_create_dir(mtd->name, dfs_dir_mtd);
>> +     if (IS_ERR(mtd->dbg.dfs_dir))
>> +             mtd->dbg.dfs_dir = NULL;
>> +
>>       memset(&parsed, 0, sizeof(parsed));
>>
>>       ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
>> @@ -740,6 +747,8 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
>>  out:
>>       /* Cleanup any parsed partitions */
>>       mtd_part_parser_cleanup(&parsed);
>> +     if (ret)
>> +             debugfs_remove_recursive(mtd->dbg.dfs_dir);
>>       return ret;
>>  }
>>  EXPORT_SYMBOL_GPL(mtd_device_parse_register);
>> @@ -754,6 +763,8 @@ int mtd_device_unregister(struct mtd_info *master)
>>  {
>>       int err;
>>
>> +     debugfs_remove_recursive(master->dbg.dfs_dir);
>> +
>>       if (master->_reboot)
>>               unregister_reboot_notifier(&master->reboot_notifier);
>>
>> @@ -1807,6 +1818,10 @@ static int __init init_mtd(void)
>>
>>       proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
>>
>> +     dfs_dir_mtd = debugfs_create_dir("mtd", NULL);
>> +     if (IS_ERR(dfs_dir_mtd))
>> +             dfs_dir_mtd = NULL;
>> +
>>       ret = init_mtdchar();
>>       if (ret)
>>               goto out_procfs;
>> @@ -1816,6 +1831,7 @@ static int __init init_mtd(void)
>>  out_procfs:
>>       if (proc_mtd)
>>               remove_proc_entry("mtd", NULL);
>> +     debugfs_remove(dfs_dir_mtd);
>>       bdi_put(mtd_bdi);
>>  err_bdi:
>>       class_unregister(&mtd_class);
>> @@ -1826,6 +1842,7 @@ static int __init init_mtd(void)
>>
>>  static void __exit cleanup_mtd(void)
>>  {
>> +     debugfs_remove_recursive(dfs_dir_mtd);
>>       cleanup_mtdchar();
>>       if (proc_mtd)
>>               remove_proc_entry("mtd", NULL);
>> diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h
>> index 55fdb8e1fd2a..b5d095d24087 100644
>> --- a/drivers/mtd/mtdcore.h
>> +++ b/drivers/mtd/mtdcore.h
>> @@ -19,6 +19,8 @@ int parse_mtd_partitions(struct mtd_info *master, const char * const *types,
>>
>>  void mtd_part_parser_cleanup(struct mtd_partitions *parts);
>>
>> +extern struct dentry *debug_mtd;
>> +
>>  int __init init_mtdchar(void);
>>  void __exit cleanup_mtdchar(void);
>>
>> diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
>> index f8a2ef239c60..6cd0f6b7658b 100644
>> --- a/include/linux/mtd/mtd.h
>> +++ b/include/linux/mtd/mtd.h
>> @@ -206,6 +206,15 @@ struct mtd_pairing_scheme {
>>
>>  struct module;       /* only needed for owner field in mtd_info */
>>
>> +/**
>> + * struct mtd_debug_info - debugging information for an MTD device.
>> + *
>> + * @dfs_dir: direntry object of the MTD device debugfs directory
>> + */
>> +struct mtd_debug_info {
>> +     struct dentry *dfs_dir;
>> +};
>> +
>>  struct mtd_info {
>>       u_char type;
>>       uint32_t flags;
>> @@ -346,6 +355,7 @@ struct mtd_info {
>>       struct module *owner;
>>       struct device dev;
>>       int usecount;
>> +     struct mtd_debug_info dbg;
>>  };
>>
>>  int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
  2017-05-20 15:24   ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Mario J. Rugiero
  2017-05-20 15:24     ` [PATCH 3/3] mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs Mario J. Rugiero
@ 2017-05-20 17:38     ` Boris Brezillon
  2017-05-20 17:44     ` Boris Brezillon
  2017-05-20 17:56     ` Boris Brezillon
  3 siblings, 0 replies; 11+ messages in thread
From: Boris Brezillon @ 2017-05-20 17:38 UTC (permalink / raw)
  To: Mario J. Rugiero
  Cc: linux-mtd, computersforpeace, marek.vasut, richard,
	cyrille.pitchen

Le Sat, 20 May 2017 12:24:27 -0300,
"Mario J. Rugiero" <mrugiero@gmail.com> a écrit :

> Drivers are updated to use this wrapper.

Try to be a bit more verbose in your commit messages. Explain why you
want to add this wrapper.

BTW, you only update mtd_device_register() callers, not those who
call mtd_device_parse_register(), which is wrong.

This being said, I wonder if we shouldn't have extra helpers to
assign default parts and part_parser_types and parser_data to a
nand_chip, and then have a nand_chip_register() which just takes
a nand_chip object and extract parts info from there.

Something like:

struct nand_parts_info {
	const char * const *part_parsers;
	struct mtd_part_parser_data *part_parser_data;
	const struct mtd_partition *defparts;
	int ndefparts;
};

struct nand_chip {
	...

	struct nand_parts_info parts_info;
	...
};


void nand_chip_set_default_parts(struct nand_chip *chip,
				 const struct mtd_partition *parts,
				 int nparts)
{
	chip->parts_info.defparts = parts;
	chip->parts_info.ndefparts = nparts;
}

void nand_chip_set_part_parsers(struct nand_chip *chip,
			const char * const *part_parsers)
{
	chip->parts_info.part_parsers = part_parsers;
}

void nand_chip_set_part_parser_data(struct nand_chip *chip,
				    struct mtd_part_parser_data *data)
{
	chip->parts_info.part_parser_data = part_parser_data;
}

int nand_chip_register(struct nand_chip *chip)
{
	return mtd_device_parse_register(nand_to_mtd(chip),
					 chip->parts_info.part_parsers,
					 chip->parts_info.part_parser_data,
					 chip->parts_info.defparts,
					 chip->parts_info.ndefparts);
}


> 
> Signed-off-by: Mario J. Rugiero <mrugiero@gmail.com>
> ---

[...]

> +/* Register the MTD device and allocate resources for the NAND device */
> +int nand_device_register(struct mtd_info *mtd,
> +			 const struct mtd_partition *defparts,
> +			 int defnr_parts);
> +

I prefer nand_chip_register(), I reserve the nand_device_ prefix for
other reworks I'm planning to do ;-).

BTW, where is the nand_chip_unregister() I suggested to add to keep the
API symetric?

>  /* Unregister the MTD device and free resources held by the NAND device */
>  void nand_release(struct mtd_info *mtd);
>  

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
  2017-05-20 15:24   ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Mario J. Rugiero
  2017-05-20 15:24     ` [PATCH 3/3] mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs Mario J. Rugiero
  2017-05-20 17:38     ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Boris Brezillon
@ 2017-05-20 17:44     ` Boris Brezillon
  2017-05-20 17:46       ` Boris Brezillon
  2017-05-20 17:56     ` Boris Brezillon
  3 siblings, 1 reply; 11+ messages in thread
From: Boris Brezillon @ 2017-05-20 17:44 UTC (permalink / raw)
  To: Mario J. Rugiero
  Cc: linux-mtd, computersforpeace, marek.vasut, richard,
	cyrille.pitchen

Le Sat, 20 May 2017 12:24:27 -0300,
"Mario J. Rugiero" <mrugiero@gmail.com> a écrit :

>  
>  /**
> + * nand_device_register - [NAND Interface] Register the MTD device and
> + *                        allocate resources for the NAND device
> + * @mtd: MTD device structure
> + * @defparts: default device partitions array, from C-based board files
> + * @defnr_parts: number of elements in defparts
> + *
> + * @return
> + */
> +int nand_device_register(struct mtd_info *mtd,
> +			 const struct mtd_partition *defparts,
> +			 int defnr_parts)
> +{
> +	int ret = nand_device_register(mtd, defparts, defnr_parts);

	return nand_device_register(mtd, defparts, defnr_parts);

> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(nand_device_register);

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
  2017-05-20 17:44     ` Boris Brezillon
@ 2017-05-20 17:46       ` Boris Brezillon
  0 siblings, 0 replies; 11+ messages in thread
From: Boris Brezillon @ 2017-05-20 17:46 UTC (permalink / raw)
  To: Mario J. Rugiero
  Cc: linux-mtd, computersforpeace, marek.vasut, richard,
	cyrille.pitchen

Le Sat, 20 May 2017 19:44:30 +0200,
Boris Brezillon <boris.brezillon@free-electrons.com> a écrit :

> Le Sat, 20 May 2017 12:24:27 -0300,
> "Mario J. Rugiero" <mrugiero@gmail.com> a écrit :
> 
> >  
> >  /**
> > + * nand_device_register - [NAND Interface] Register the MTD device and
> > + *                        allocate resources for the NAND device
> > + * @mtd: MTD device structure
> > + * @defparts: default device partitions array, from C-based board files
> > + * @defnr_parts: number of elements in defparts
> > + *
> > + * @return
> > + */
> > +int nand_device_register(struct mtd_info *mtd,
> > +			 const struct mtd_partition *defparts,
> > +			 int defnr_parts)
> > +{
> > +	int ret = nand_device_register(mtd, defparts, defnr_parts);  
> 
> 	return nand_device_register(mtd, defparts, defnr_parts);

Duh, actually it's:

	return mtd_device_register(mtd, defparts, defnr_parts);

> 
> > +
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(nand_device_register);  

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/3] mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs
  2017-05-20 15:24     ` [PATCH 3/3] mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs Mario J. Rugiero
@ 2017-05-20 17:54       ` Boris Brezillon
  0 siblings, 0 replies; 11+ messages in thread
From: Boris Brezillon @ 2017-05-20 17:54 UTC (permalink / raw)
  To: Mario J. Rugiero
  Cc: linux-mtd, computersforpeace, marek.vasut, richard,
	cyrille.pitchen

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.

}

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
  2017-05-20 15:24   ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Mario J. Rugiero
                       ` (2 preceding siblings ...)
  2017-05-20 17:44     ` Boris Brezillon
@ 2017-05-20 17:56     ` Boris Brezillon
  3 siblings, 0 replies; 11+ messages in thread
From: Boris Brezillon @ 2017-05-20 17:56 UTC (permalink / raw)
  To: Mario J. Rugiero
  Cc: linux-mtd, computersforpeace, marek.vasut, richard,
	cyrille.pitchen

Le Sat, 20 May 2017 12:24:27 -0300,
"Mario J. Rugiero" <mrugiero@gmail.com> a écrit :

> --- a/include/linux/mtd/nand.h
> +++ b/include/linux/mtd/nand.h
> @@ -38,6 +38,11 @@ int nand_scan_ident(struct mtd_info *mtd, int max_chips,
>  			   struct nand_flash_dev *table);
>  int nand_scan_tail(struct mtd_info *mtd);
>  
> +/* Register the MTD device and allocate resources for the NAND device */
> +int nand_device_register(struct mtd_info *mtd,

Please pass a nand_chip object here, not mtd_info.

> +			 const struct mtd_partition *defparts,
> +			 int defnr_parts);
> +
>  /* Unregister the MTD device and free resources held by the NAND device */
>  void nand_release(struct mtd_info *mtd);
>  

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-05-20 17:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-20 15:24 [PATCH 0/3] mtd: nand: allow force erasing of bad blocks through debugfs entry Mario J. Rugiero
2017-05-20 15:24 ` [PATCH 1/3] mtd: create per-device and module-scope debugfs entries Mario J. Rugiero
2017-05-20 15:24   ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Mario J. Rugiero
2017-05-20 15:24     ` [PATCH 3/3] mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs Mario J. Rugiero
2017-05-20 17:54       ` Boris Brezillon
2017-05-20 17:38     ` [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization Boris Brezillon
2017-05-20 17:44     ` Boris Brezillon
2017-05-20 17:46       ` Boris Brezillon
2017-05-20 17:56     ` Boris Brezillon
2017-05-20 16:21   ` [PATCH 1/3] mtd: create per-device and module-scope debugfs entries Boris Brezillon
2017-05-20 16:41     ` Mario Rugiero

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).