diff options
author | Ezequiel Garcia <ezequiel.garcia@free-electrons.com> | 2014-06-24 09:55:50 -0400 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2014-07-08 21:37:26 -0400 |
commit | 990a3af0c20590954be01a95c2c3fcef9360a836 (patch) | |
tree | fc993286f8726b9a413b4d79e21133f3157ec2e8 | |
parent | 89384f646287437ba18afb28ccb125d5866a7209 (diff) |
mtd: Add sysfs attributes to expose the ECC stats fields
These new sysfs device attributes allow us to retrieve the ECC and bad
block stats by poking a sysfs file, which is often more convenient than
using the ioctl.
Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Tested-by: Pekon Gupta <pekon@ti.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
-rw-r--r-- | Documentation/ABI/testing/sysfs-class-mtd | 38 | ||||
-rw-r--r-- | drivers/mtd/mtdcore.c | 45 |
2 files changed, 83 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-mtd b/Documentation/ABI/testing/sysfs-class-mtd index 1399bb2da3eb..76ee192f80a0 100644 --- a/Documentation/ABI/testing/sysfs-class-mtd +++ b/Documentation/ABI/testing/sysfs-class-mtd | |||
@@ -184,3 +184,41 @@ Description: | |||
184 | 184 | ||
185 | It will always be a non-negative integer. In the case of | 185 | It will always be a non-negative integer. In the case of |
186 | devices lacking any ECC capability, it is 0. | 186 | devices lacking any ECC capability, it is 0. |
187 | |||
188 | What: /sys/class/mtd/mtdX/ecc_failures | ||
189 | Date: June 2014 | ||
190 | KernelVersion: 3.17 | ||
191 | Contact: linux-mtd@lists.infradead.org | ||
192 | Description: | ||
193 | The number of failures reported by this device's ECC. Typically, | ||
194 | these failures are associated with failed read operations. | ||
195 | |||
196 | It will always be a non-negative integer. In the case of | ||
197 | devices lacking any ECC capability, it is 0. | ||
198 | |||
199 | What: /sys/class/mtd/mtdX/corrected_bits | ||
200 | Date: June 2014 | ||
201 | KernelVersion: 3.17 | ||
202 | Contact: linux-mtd@lists.infradead.org | ||
203 | Description: | ||
204 | The number of bits that have been corrected by means of the | ||
205 | device's ECC. | ||
206 | |||
207 | It will always be a non-negative integer. In the case of | ||
208 | devices lacking any ECC capability, it is 0. | ||
209 | |||
210 | What: /sys/class/mtd/mtdX/bad_blocks | ||
211 | Date: June 2014 | ||
212 | KernelVersion: 3.17 | ||
213 | Contact: linux-mtd@lists.infradead.org | ||
214 | Description: | ||
215 | The number of blocks marked as bad, if any, in this partition. | ||
216 | |||
217 | What: /sys/class/mtd/mtdX/bbt_blocks | ||
218 | Date: June 2014 | ||
219 | KernelVersion: 3.17 | ||
220 | Contact: linux-mtd@lists.infradead.org | ||
221 | Description: | ||
222 | The number of blocks that are marked as reserved, if any, in | ||
223 | this partition. These are typically used to store the in-flash | ||
224 | bad block table (BBT). | ||
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index d201feeb3ca6..11857faa0d96 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c | |||
@@ -298,6 +298,47 @@ static ssize_t mtd_ecc_step_size_show(struct device *dev, | |||
298 | } | 298 | } |
299 | static DEVICE_ATTR(ecc_step_size, S_IRUGO, mtd_ecc_step_size_show, NULL); | 299 | static DEVICE_ATTR(ecc_step_size, S_IRUGO, mtd_ecc_step_size_show, NULL); |
300 | 300 | ||
301 | static ssize_t mtd_ecc_stats_corrected_show(struct device *dev, | ||
302 | struct device_attribute *attr, char *buf) | ||
303 | { | ||
304 | struct mtd_info *mtd = dev_get_drvdata(dev); | ||
305 | struct mtd_ecc_stats *ecc_stats = &mtd->ecc_stats; | ||
306 | |||
307 | return snprintf(buf, PAGE_SIZE, "%u\n", ecc_stats->corrected); | ||
308 | } | ||
309 | static DEVICE_ATTR(corrected_bits, S_IRUGO, | ||
310 | mtd_ecc_stats_corrected_show, NULL); | ||
311 | |||
312 | static ssize_t mtd_ecc_stats_errors_show(struct device *dev, | ||
313 | struct device_attribute *attr, char *buf) | ||
314 | { | ||
315 | struct mtd_info *mtd = dev_get_drvdata(dev); | ||
316 | struct mtd_ecc_stats *ecc_stats = &mtd->ecc_stats; | ||
317 | |||
318 | return snprintf(buf, PAGE_SIZE, "%u\n", ecc_stats->failed); | ||
319 | } | ||
320 | static DEVICE_ATTR(ecc_failures, S_IRUGO, mtd_ecc_stats_errors_show, NULL); | ||
321 | |||
322 | static ssize_t mtd_badblocks_show(struct device *dev, | ||
323 | struct device_attribute *attr, char *buf) | ||
324 | { | ||
325 | struct mtd_info *mtd = dev_get_drvdata(dev); | ||
326 | struct mtd_ecc_stats *ecc_stats = &mtd->ecc_stats; | ||
327 | |||
328 | return snprintf(buf, PAGE_SIZE, "%u\n", ecc_stats->badblocks); | ||
329 | } | ||
330 | static DEVICE_ATTR(bad_blocks, S_IRUGO, mtd_badblocks_show, NULL); | ||
331 | |||
332 | static ssize_t mtd_bbtblocks_show(struct device *dev, | ||
333 | struct device_attribute *attr, char *buf) | ||
334 | { | ||
335 | struct mtd_info *mtd = dev_get_drvdata(dev); | ||
336 | struct mtd_ecc_stats *ecc_stats = &mtd->ecc_stats; | ||
337 | |||
338 | return snprintf(buf, PAGE_SIZE, "%u\n", ecc_stats->bbtblocks); | ||
339 | } | ||
340 | static DEVICE_ATTR(bbt_blocks, S_IRUGO, mtd_bbtblocks_show, NULL); | ||
341 | |||
301 | static struct attribute *mtd_attrs[] = { | 342 | static struct attribute *mtd_attrs[] = { |
302 | &dev_attr_type.attr, | 343 | &dev_attr_type.attr, |
303 | &dev_attr_flags.attr, | 344 | &dev_attr_flags.attr, |
@@ -310,6 +351,10 @@ static struct attribute *mtd_attrs[] = { | |||
310 | &dev_attr_name.attr, | 351 | &dev_attr_name.attr, |
311 | &dev_attr_ecc_strength.attr, | 352 | &dev_attr_ecc_strength.attr, |
312 | &dev_attr_ecc_step_size.attr, | 353 | &dev_attr_ecc_step_size.attr, |
354 | &dev_attr_corrected_bits.attr, | ||
355 | &dev_attr_ecc_failures.attr, | ||
356 | &dev_attr_bad_blocks.attr, | ||
357 | &dev_attr_bbt_blocks.attr, | ||
313 | &dev_attr_bitflip_threshold.attr, | 358 | &dev_attr_bitflip_threshold.attr, |
314 | NULL, | 359 | NULL, |
315 | }; | 360 | }; |