Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libata: Expose TRIM capability in sysfs

Create a sysfs "trim" attribute for each ata_device that displays
whether DSM TRIM is "unsupported", "unqueued", "forced_unqueued"
(blacklisted) or "queued".

Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Martin K. Petersen and committed by
Tejun Heo
f3030741 d7b16e4f

+33
+11
Documentation/ABI/testing/sysfs-ata
··· 90 90 130: SATA_PMP_GSCR_SII_GPIO 91 91 Only valid if the device is a PM. 92 92 93 + trim 94 + 95 + Shows the DSM TRIM mode currently used by the device. Valid 96 + values are: 97 + unsupported: Drive does not support DSM TRIM 98 + unqueued: Drive supports unqueued DSM TRIM only 99 + queued: Drive supports queued DSM TRIM 100 + forced_unqueued: Drive's unqueued DSM support is known to be 101 + buggy and only unqueued TRIM commands 102 + are sent 103 + 93 104 spdn_cnt 94 105 95 106 Number of time libata decided to lower the speed of link due to errors.
+22
drivers/ata/libata-transport.c
··· 560 560 561 561 static DEVICE_ATTR(gscr, S_IRUGO, show_ata_dev_gscr, NULL); 562 562 563 + static ssize_t 564 + show_ata_dev_trim(struct device *dev, 565 + struct device_attribute *attr, char *buf) 566 + { 567 + struct ata_device *ata_dev = transport_class_to_dev(dev); 568 + unsigned char *mode; 569 + 570 + if (!ata_id_has_trim(ata_dev->id)) 571 + mode = "unsupported"; 572 + else if (ata_dev->horkage & ATA_HORKAGE_NO_NCQ_TRIM) 573 + mode = "forced_unqueued"; 574 + else if (ata_fpdma_dsm_supported(ata_dev)) 575 + mode = "queued"; 576 + else 577 + mode = "unqueued"; 578 + 579 + return snprintf(buf, 20, "%s\n", mode); 580 + } 581 + 582 + static DEVICE_ATTR(trim, S_IRUGO, show_ata_dev_trim, NULL); 583 + 563 584 static DECLARE_TRANSPORT_CLASS(ata_dev_class, 564 585 "ata_device", NULL, NULL, NULL); 565 586 ··· 754 733 SETUP_DEV_ATTRIBUTE(ering); 755 734 SETUP_DEV_ATTRIBUTE(id); 756 735 SETUP_DEV_ATTRIBUTE(gscr); 736 + SETUP_DEV_ATTRIBUTE(trim); 757 737 BUG_ON(count > ATA_DEV_ATTRS); 758 738 i->dev_attrs[count] = NULL; 759 739