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

scsi: ufs: Prepare to add HCI capabilities sysfs

Prepare so we'll be able to read various other HCI registers. While at it,
fix the HCPID & HCMID register names to stand for what they really are.
Also replace the pm_runtime_{get/put}_sync() calls in auto_hibern8_show to
ufshcd_rpm_{get/put}_sync() as any host controller register reads should.

Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20240811143757.2538212-2-avri.altman@wdc.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Avri Altman and committed by
Martin K. Petersen
b9d10446 992f9884

+25 -18
+22 -16
drivers/ufs/core/ufs-sysfs.c
··· 198 198 FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, scale); 199 199 } 200 200 201 + static int ufshcd_read_hci_reg(struct ufs_hba *hba, u32 *val, unsigned int reg) 202 + { 203 + down(&hba->host_sem); 204 + if (!ufshcd_is_user_access_allowed(hba)) { 205 + up(&hba->host_sem); 206 + return -EBUSY; 207 + } 208 + 209 + ufshcd_rpm_get_sync(hba); 210 + ufshcd_hold(hba); 211 + *val = ufshcd_readl(hba, reg); 212 + ufshcd_release(hba); 213 + ufshcd_rpm_put_sync(hba); 214 + 215 + up(&hba->host_sem); 216 + return 0; 217 + } 218 + 201 219 static ssize_t auto_hibern8_show(struct device *dev, 202 220 struct device_attribute *attr, char *buf) 203 221 { ··· 226 208 if (!ufshcd_is_auto_hibern8_supported(hba)) 227 209 return -EOPNOTSUPP; 228 210 229 - down(&hba->host_sem); 230 - if (!ufshcd_is_user_access_allowed(hba)) { 231 - ret = -EBUSY; 232 - goto out; 233 - } 211 + ret = ufshcd_read_hci_reg(hba, &ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); 212 + if (ret) 213 + return ret; 234 214 235 - pm_runtime_get_sync(hba->dev); 236 - ufshcd_hold(hba); 237 - ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER); 238 - ufshcd_release(hba); 239 - pm_runtime_put_sync(hba->dev); 240 - 241 - ret = sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit)); 242 - 243 - out: 244 - up(&hba->host_sem); 245 - return ret; 215 + return sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit)); 246 216 } 247 217 248 218 static ssize_t auto_hibern8_store(struct device *dev,
+3 -2
include/ufs/ufshci.h
··· 25 25 REG_CONTROLLER_CAPABILITIES = 0x00, 26 26 REG_MCQCAP = 0x04, 27 27 REG_UFS_VERSION = 0x08, 28 - REG_CONTROLLER_DEV_ID = 0x10, 29 - REG_CONTROLLER_PROD_ID = 0x14, 28 + REG_EXT_CONTROLLER_CAPABILITIES = 0x0C, 29 + REG_CONTROLLER_PID = 0x10, 30 + REG_CONTROLLER_MID = 0x14, 30 31 REG_AUTO_HIBERNATE_IDLE_TIMER = 0x18, 31 32 REG_INTERRUPT_STATUS = 0x20, 32 33 REG_INTERRUPT_ENABLE = 0x24,