mtd: nand: allow force erasing of bad blocks through debugfs entry
Subsystems (7)
cover mtd: nand: allow force erasing of bad blocks through debugfs entry
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(-)
Signature · 1 line
2.13.0
PATCH 1/3 mtd: create per-device and module-scope debugfs entries
--- drivers/mtd/mtdcore.c | 17 +++++++++++++++++ drivers/mtd/mtdcore.h | 2 ++ include/linux/mtd/mtd.h | 10 ++++++++++ 3 files changed, 29 insertions(+)
drivers/mtd/mtdcore.c +17 -0
@@ -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 );
drivers/mtd/mtdcore.h +2 -0
@@ -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);
include/linux/mtd/mtd.h +10 -0
@@ -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,
Signature · 1 line
2.13.0
PATCH 3/3 mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs
In reply to Mario J. Rugiero--- drivers/mtd/nand/nand_base.c | 26 ++++++++++++++++++++++---- include/linux/mtd/nand.h | 12 ++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-)
drivers/mtd/nand/nand_base.c +22 -4
@@ -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; }
include/linux/mtd/nand.h +12 -0
@@ -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;
Signature · 1 line
2.13.0
PATCH 2/3 mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
In reply to Mario J. RugieroDrivers are updated to use this wrapper.
--- 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(-)
drivers/mtd/nand/ams-delta.c +1 -1
@@ -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;
drivers/mtd/nand/atmel/nand-controller.c +1 -1
@@ -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);
drivers/mtd/nand/au1550nd.c +1 -1
@@ -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);
drivers/mtd/nand/bf5xx_nand.c +1 -1
@@ -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)
drivers/mtd/nand/brcmnand/brcmnand.c +1 -1
@@ -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,
drivers/mtd/nand/davinci_nand.c +1 -1
@@ -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;
drivers/mtd/nand/denali.c +1 -1
@@ -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;
drivers/mtd/nand/diskonchip.c +2 -2
@@ -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)
drivers/mtd/nand/fsl_upm.c +1 -1
@@ -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)
drivers/mtd/nand/fsmc_nand.c +1 -1
@@ -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;
drivers/mtd/nand/gpio.c +1 -1
@@ -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 ;
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1 -1
@@ -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 ;
drivers/mtd/nand/hisi504_nand.c +1 -1
@@ -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;
drivers/mtd/nand/jz4780_nand.c +1 -1
@@ -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;
drivers/mtd/nand/lpc32xx_mlc.c +1 -1
@@ -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;
drivers/mtd/nand/lpc32xx_slc.c +1 -1
@@ -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;
drivers/mtd/nand/mpc5121_nfc.c +1 -1
@@ -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;
drivers/mtd/nand/nand_base.c +19 -0
@@ -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
drivers/mtd/nand/nandsim.c +1 -1
@@ -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;
drivers/mtd/nand/ndfc.c +1 -1
@@ -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);
drivers/mtd/nand/nuc900_nand.c +1 -1
@@ -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);
drivers/mtd/nand/omap2.c +2 -2
@@ -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);
drivers/mtd/nand/orion_nand.c +1 -1
@@ -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;
drivers/mtd/nand/oxnas_nand.c +1 -1
@@ -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;
drivers/mtd/nand/pasemi_nand.c +1 -1
@@ -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;
drivers/mtd/nand/pxa3xx_nand.c +1 -1
@@ -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 ;
drivers/mtd/nand/qcom_nandc.c +1 -1
@@ -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 */
drivers/mtd/nand/sh_flctl.c +1 -1
@@ -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 ;
drivers/mtd/nand/sm_common.c +1 -1
@@ -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);
drivers/mtd/nand/socrates_nand.c +1 -1
@@ -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;
drivers/mtd/nand/sunxi_nand.c +1 -1
@@ -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);
drivers/mtd/nand/tango_nand.c +1 -1
@@ -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;
drivers/mtd/nand/vf610_nfc.c +1 -1
@@ -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));
drivers/mtd/nand/xway_nand.c +1 -1
@@ -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);
include/linux/mtd/nand.h +5 -0
@@ -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);
Signature · 1 line
2.13.0
Re: [PATCH 1/3] mtd: create per-device and module-scope debugfs entries
In reply to Mario J. RugieroLe Sat, 20 May 2017 12:24:26 -0300,
"Mario J. Rugiero" <[email protected]> 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.
"
Quoted 1 line
Signed-off-by Mario J. Rugiero <[email protected]>
You forgot to add my Ack here.
Quoted 1 line
---
There should be a changelog here, or in the cover letter describing the evolution of this patch.
Quoted 123 lines
drivers/mtd/mtdcore.c | 17 +++++++++++++++++ drivers/mtd/mtdcore.h | 2 ++ include/linux/mtd/mtd.h | 10 ++++++++++ 3 files changed, 29 insertions(+)drivers/mtd/mtdcore.c +17
-0@@ -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 );drivers/mtd/mtdcore.h +2
-0@@ -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);include/linux/mtd/mtd.h +10
-0@@ -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,
Re: [PATCH 1/3] mtd: create per-device and module-scope debugfs entries
2017-05-20 13:21 GMT-03:00 Boris Brezillon <[email protected]>:
Quoted 6 lines
Le Sat, 20 May 2017 12:24:26 -0300,
"Mario J. Rugiero" <[email protected]> a écrit :I'd like to have a bit more details explaining why you want to do that. Something like:
Quoted 7 lines
"
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?
Quoted 134 lines
Quoted 2 lines
Signed-off-by Mario J. Rugiero <[email protected]>You forgot to add my Ack here.
Quoted 1 line
---
There should be a changelog here, or in the cover letter describing the evolution of this patch.
Quoted 123 lines
drivers/mtd/mtdcore.c | 17 +++++++++++++++++ drivers/mtd/mtdcore.h | 2 ++ include/linux/mtd/mtd.h | 10 ++++++++++ 3 files changed, 29 insertions(+)drivers/mtd/mtdcore.c +17
-0@@ -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 );drivers/mtd/mtdcore.h +2
-0@@ -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);include/linux/mtd/mtd.h +10
-0@@ -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,
Re: [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
In reply to Mario J. RugieroQuoted 1 line · Mario J. Rugiero
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);
}Quoted 3 lines
Signed-off-by Mario J. Rugiero <[email protected]>---
[...]
include/linux/mtd/nand.h int nand_scan_ident(struct mtd_info *mtd, int max_chips, · line 45
Quoted 5 lines
include/linux/mtd/nand.h +5
-0+/* 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?
Quoted 3 lines
/* Unregister the MTD device and free resources held by the NAND device */ void
nand_release(struct mtd_info *mtd);
Re: [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
In reply to Mario J. RugieroQuoted 10 lines · Mario J. Rugiero
/**
+ *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
+ */
drivers/mtd/nand/nand_base.c void nand_cleanup(struct nand_chip *chip) · line 4933
Quoted 5 lines
drivers/mtd/nand/nand_base.c +5
-0+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);
Quoted 4 lines
drivers/mtd/nand/nand_base.c +4
-0+ +return ret; +} +EXPORT_SYMBOL_GPL (nand_device_register);
Re: [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
Quoted 4 lines · Boris Brezillon
Quoted 1 line · Mario J. Rugiero
Quoted 16 lines
Quoted 9 lines
/**
+ *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
+ */drivers/mtd/nand/nand_base.c void nand_cleanup(struct nand_chip *chip) · line 4933
Quoted 5 lines
drivers/mtd/nand/nand_base.c +5
-0+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);
Quoted 5 lines
Quoted 5 lines
drivers/mtd/nand/nand_base.c +4
-0+ +return ret; +} +EXPORT_SYMBOL_GPL (nand_device_register);
Re: [PATCH 3/3] mtd: nand: add option to ignore bad blocks when erasing, opt-in through debugfs
In reply to Mario J. RugieroLe Sat, 20 May 2017 12:24:28 -0300,
"Mario J. Rugiero" <[email protected]> a écrit :
And again, pleases add a commit message.
Quoted 39 lines
Signed-off-by Mario J. Rugiero <[email protected]>--- drivers/mtd/nand/nand_base.c | 26 ++++++++++++++++++++++---- include/linux/mtd/nand.h | 12 ++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-)drivers/mtd/nand/nand_base.c +10
-4@@ -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); + } }/*
drivers/mtd/nand/nand_base.c int nand_device_register(struct mtd_info *mtd, · line 4945
Quoted 9 lines
drivers/mtd/nand/nand_base.c +6
-0@@ -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"?
drivers/mtd/nand/nand_base.c int nand_device_register(struct mtd_info *mtd, · line 4951
Quoted 6 lines
drivers/mtd/nand/nand_base.c +6
-0+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.
}
Re: [PATCH 2/3] mtd: nand: create a wrapper for mtd_device_register for NAND specific initialization.
In reply to Mario J. Rugieroinclude/linux/mtd/nand.h int nand_scan_ident(struct mtd_info *mtd, int max_chips, · line 42
Quoted 8 lines · Mario J. Rugiero
include/linux/mtd/nand.h +2
-0@@ -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.
Quoted 6 lines
include/linux/mtd/nand.h +3
-0+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);