423-v6.1-0001-mtd-track-maximum-number-of-bitflips-for-each-read-r.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From e237285113963bd1dd2e925770aa8b3aa8a1894c Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= <[email protected]>
  3. Date: Wed, 29 Jun 2022 14:57:34 +0200
  4. Subject: [PATCH 1/4] mtd: track maximum number of bitflips for each read
  5. request
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. mtd_read_oob() callers are currently oblivious to the details of ECC
  10. errors detected during the read operation - they only learn (through the
  11. return value) whether any corrected bitflips or uncorrectable errors
  12. occurred. More detailed ECC information can be useful to user-space
  13. applications for making better-informed choices about moving data
  14. around.
  15. Extend struct mtd_oob_ops with a pointer to a newly-introduced struct
  16. mtd_req_stats and set its 'max_bitflips' field to the maximum number of
  17. bitflips found in a single ECC step during the read operation performed
  18. by mtd_read_oob(). This is a prerequisite for ultimately passing that
  19. value back to user space.
  20. Suggested-by: Boris Brezillon <[email protected]>
  21. Signed-off-by: Michał Kępień <[email protected]>
  22. Signed-off-by: Miquel Raynal <[email protected]>
  23. Link: https://lore.kernel.org/linux-mtd/[email protected]
  24. ---
  25. drivers/mtd/mtdcore.c | 5 +++++
  26. include/linux/mtd/mtd.h | 5 +++++
  27. 2 files changed, 10 insertions(+)
  28. --- a/drivers/mtd/mtdcore.c
  29. +++ b/drivers/mtd/mtdcore.c
  30. @@ -1676,6 +1676,9 @@ int mtd_read_oob(struct mtd_info *mtd, l
  31. if (!master->_read_oob && (!master->_read || ops->oobbuf))
  32. return -EOPNOTSUPP;
  33. + if (ops->stats)
  34. + memset(ops->stats, 0, sizeof(*ops->stats));
  35. +
  36. if (mtd->flags & MTD_SLC_ON_MLC_EMULATION)
  37. ret_code = mtd_io_emulated_slc(mtd, from, true, ops);
  38. else
  39. @@ -1693,6 +1696,8 @@ int mtd_read_oob(struct mtd_info *mtd, l
  40. return ret_code;
  41. if (mtd->ecc_strength == 0)
  42. return 0; /* device lacks ecc */
  43. + if (ops->stats)
  44. + ops->stats->max_bitflips = ret_code;
  45. return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0;
  46. }
  47. EXPORT_SYMBOL_GPL(mtd_read_oob);
  48. --- a/include/linux/mtd/mtd.h
  49. +++ b/include/linux/mtd/mtd.h
  50. @@ -40,6 +40,10 @@ struct mtd_erase_region_info {
  51. unsigned long *lockmap; /* If keeping bitmap of locks */
  52. };
  53. +struct mtd_req_stats {
  54. + unsigned int max_bitflips;
  55. +};
  56. +
  57. /**
  58. * struct mtd_oob_ops - oob operation operands
  59. * @mode: operation mode
  60. @@ -70,6 +74,7 @@ struct mtd_oob_ops {
  61. uint32_t ooboffs;
  62. uint8_t *datbuf;
  63. uint8_t *oobbuf;
  64. + struct mtd_req_stats *stats;
  65. };
  66. #define MTD_MAX_OOBFREE_ENTRIES_LARGE 32