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

scsi: libsas: Define NCQ Priority sysfs attributes for SATA devices

libata sysfs attributes cannot be used for libsas-managed SATA devices
because the ata_port location is different for libsas.

Defined sysfs attributes (visible for SATA devices only):

- /sys/block/sda/device/ncq_prio_enable
- /sys/block/sda/device/ncq_prio_supported

The newly defined attributes will pass the correct ata_port to libata
helper functions.

Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Jason Yan <yanaijie@huawei.com>
Signed-off-by: Igor Pylypiv <ipylypiv@google.com>
Link: https://lore.kernel.org/r/20240307214418.3812290-3-ipylypiv@google.com
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Igor Pylypiv and committed by
Martin K. Petersen
b4d3ddd2 abeded46

+88
+82
drivers/scsi/libsas/sas_ata.c
··· 964 964 force_phy_id, &tmf_task); 965 965 } 966 966 EXPORT_SYMBOL_GPL(sas_execute_ata_cmd); 967 + 968 + static ssize_t sas_ncq_prio_supported_show(struct device *device, 969 + struct device_attribute *attr, 970 + char *buf) 971 + { 972 + struct scsi_device *sdev = to_scsi_device(device); 973 + struct domain_device *ddev = sdev_to_domain_dev(sdev); 974 + bool supported; 975 + int rc; 976 + 977 + rc = ata_ncq_prio_supported(ddev->sata_dev.ap, sdev, &supported); 978 + if (rc) 979 + return rc; 980 + 981 + return sysfs_emit(buf, "%d\n", supported); 982 + } 983 + 984 + DEVICE_ATTR(ncq_prio_supported, S_IRUGO, sas_ncq_prio_supported_show, NULL); 985 + 986 + static ssize_t sas_ncq_prio_enable_show(struct device *device, 987 + struct device_attribute *attr, 988 + char *buf) 989 + { 990 + struct scsi_device *sdev = to_scsi_device(device); 991 + struct domain_device *ddev = sdev_to_domain_dev(sdev); 992 + bool enabled; 993 + int rc; 994 + 995 + rc = ata_ncq_prio_enabled(ddev->sata_dev.ap, sdev, &enabled); 996 + if (rc) 997 + return rc; 998 + 999 + return sysfs_emit(buf, "%d\n", enabled); 1000 + } 1001 + 1002 + static ssize_t sas_ncq_prio_enable_store(struct device *device, 1003 + struct device_attribute *attr, 1004 + const char *buf, size_t len) 1005 + { 1006 + struct scsi_device *sdev = to_scsi_device(device); 1007 + struct domain_device *ddev = sdev_to_domain_dev(sdev); 1008 + bool enable; 1009 + int rc; 1010 + 1011 + rc = kstrtobool(buf, &enable); 1012 + if (rc) 1013 + return rc; 1014 + 1015 + rc = ata_ncq_prio_enable(ddev->sata_dev.ap, sdev, enable); 1016 + if (rc) 1017 + return rc; 1018 + 1019 + return len; 1020 + } 1021 + 1022 + DEVICE_ATTR(ncq_prio_enable, S_IRUGO | S_IWUSR, 1023 + sas_ncq_prio_enable_show, sas_ncq_prio_enable_store); 1024 + 1025 + static struct attribute *sas_ata_sdev_attrs[] = { 1026 + &dev_attr_ncq_prio_supported.attr, 1027 + &dev_attr_ncq_prio_enable.attr, 1028 + NULL 1029 + }; 1030 + 1031 + static umode_t sas_ata_attr_is_visible(struct kobject *kobj, 1032 + struct attribute *attr, int i) 1033 + { 1034 + struct device *dev = kobj_to_dev(kobj); 1035 + struct scsi_device *sdev = to_scsi_device(dev); 1036 + struct domain_device *ddev = sdev_to_domain_dev(sdev); 1037 + 1038 + if (!dev_is_sata(ddev)) 1039 + return 0; 1040 + 1041 + return attr->mode; 1042 + } 1043 + 1044 + const struct attribute_group sas_ata_sdev_attr_group = { 1045 + .attrs = sas_ata_sdev_attrs, 1046 + .is_visible = sas_ata_attr_is_visible, 1047 + }; 1048 + EXPORT_SYMBOL_GPL(sas_ata_sdev_attr_group);
+6
include/scsi/sas_ata.h
··· 39 39 int sas_discover_sata(struct domain_device *dev); 40 40 int sas_ata_add_dev(struct domain_device *parent, struct ex_phy *phy, 41 41 struct domain_device *child, int phy_id); 42 + 43 + extern const struct attribute_group sas_ata_sdev_attr_group; 44 + 42 45 #else 43 46 44 47 static inline void sas_ata_disabled_notice(void) ··· 126 123 sas_ata_disabled_notice(); 127 124 return -ENODEV; 128 125 } 126 + 127 + #define sas_ata_sdev_attr_group ((struct attribute_group) {}) 128 + 129 129 #endif 130 130 131 131 #endif /* _SAS_ATA_H_ */