Skip to content

Commit 600edc6

Browse files
avri-altman-sndkmartinkpetersen
authored andcommitted
scsi: ufs: sysfs: Make max_number_of_rtt read-write
Given the importance of the RTT parameter, we want to be able to configure it via sysfs. This is because UFS users should be discouraged from change UFS device parameters without the UFSHCI driver being aware of these changes. Signed-off-by: Avri Altman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent e75ff63 commit 600edc6

File tree

2 files changed

+80
-7
lines changed

2 files changed

+80
-7
lines changed

Documentation/ABI/testing/sysfs-driver-ufs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,16 @@ Description: This file shows whether the configuration descriptor is locked.
920920

921921
What: /sys/bus/platform/drivers/ufshcd/*/attributes/max_number_of_rtt
922922
What: /sys/bus/platform/devices/*.ufs/attributes/max_number_of_rtt
923-
Date: February 2018
924-
Contact: Stanislav Nijnikov <stanislav.nijnikov@wdc.com>
923+
Date: May 2024
924+
Contact: Avri Altman <avri.altman@wdc.com>
925925
Description: This file provides the maximum current number of
926-
outstanding RTTs in device that is allowed. The full
927-
information about the attribute could be found at
928-
UFS specifications 2.1.
926+
outstanding RTTs in device that is allowed. bMaxNumOfRTT is a
927+
read-write persistent attribute and is equal to two after device
928+
manufacturing. It shall not be set to a value greater than
929+
bDeviceRTTCap value, and it may be set only when the hw queues are
930+
empty.
929931

930-
The file is read only.
932+
The file is read write.
931933

932934
What: /sys/bus/platform/drivers/ufshcd/*/attributes/exception_event_control
933935
What: /sys/bus/platform/devices/*.ufs/attributes/exception_event_control

drivers/ufs/core/ufs-sysfs.c

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,78 @@ static const struct attribute_group ufs_sysfs_flags_group = {
13401340
.attrs = ufs_sysfs_device_flags,
13411341
};
13421342

1343+
static ssize_t max_number_of_rtt_show(struct device *dev,
1344+
struct device_attribute *attr, char *buf)
1345+
{
1346+
struct ufs_hba *hba = dev_get_drvdata(dev);
1347+
u32 rtt;
1348+
int ret;
1349+
1350+
down(&hba->host_sem);
1351+
if (!ufshcd_is_user_access_allowed(hba)) {
1352+
up(&hba->host_sem);
1353+
return -EBUSY;
1354+
}
1355+
1356+
ufshcd_rpm_get_sync(hba);
1357+
ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
1358+
QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt);
1359+
ufshcd_rpm_put_sync(hba);
1360+
1361+
if (ret)
1362+
goto out;
1363+
1364+
ret = sysfs_emit(buf, "0x%08X\n", rtt);
1365+
1366+
out:
1367+
up(&hba->host_sem);
1368+
return ret;
1369+
}
1370+
1371+
static ssize_t max_number_of_rtt_store(struct device *dev,
1372+
struct device_attribute *attr,
1373+
const char *buf, size_t count)
1374+
{
1375+
struct ufs_hba *hba = dev_get_drvdata(dev);
1376+
struct ufs_dev_info *dev_info = &hba->dev_info;
1377+
struct scsi_device *sdev;
1378+
unsigned int rtt;
1379+
int ret;
1380+
1381+
if (kstrtouint(buf, 0, &rtt))
1382+
return -EINVAL;
1383+
1384+
if (rtt > dev_info->rtt_cap) {
1385+
dev_err(dev, "rtt can be at most bDeviceRTTCap\n");
1386+
return -EINVAL;
1387+
}
1388+
1389+
down(&hba->host_sem);
1390+
if (!ufshcd_is_user_access_allowed(hba)) {
1391+
ret = -EBUSY;
1392+
goto out;
1393+
}
1394+
1395+
ufshcd_rpm_get_sync(hba);
1396+
1397+
shost_for_each_device(sdev, hba->host)
1398+
blk_mq_freeze_queue(sdev->request_queue);
1399+
1400+
ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
1401+
QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt);
1402+
1403+
shost_for_each_device(sdev, hba->host)
1404+
blk_mq_unfreeze_queue(sdev->request_queue);
1405+
1406+
ufshcd_rpm_put_sync(hba);
1407+
1408+
out:
1409+
up(&hba->host_sem);
1410+
return ret < 0 ? ret : count;
1411+
}
1412+
1413+
static DEVICE_ATTR_RW(max_number_of_rtt);
1414+
13431415
static inline bool ufshcd_is_wb_attrs(enum attr_idn idn)
13441416
{
13451417
return idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS &&
@@ -1387,7 +1459,6 @@ UFS_ATTRIBUTE(max_data_in_size, _MAX_DATA_IN);
13871459
UFS_ATTRIBUTE(max_data_out_size, _MAX_DATA_OUT);
13881460
UFS_ATTRIBUTE(reference_clock_frequency, _REF_CLK_FREQ);
13891461
UFS_ATTRIBUTE(configuration_descriptor_lock, _CONF_DESC_LOCK);
1390-
UFS_ATTRIBUTE(max_number_of_rtt, _MAX_NUM_OF_RTT);
13911462
UFS_ATTRIBUTE(exception_event_control, _EE_CONTROL);
13921463
UFS_ATTRIBUTE(exception_event_status, _EE_STATUS);
13931464
UFS_ATTRIBUTE(ffu_status, _FFU_STATUS);

0 commit comments

Comments
 (0)