^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Copyright (C) 2018 Western Digital Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/bitfield.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "ufs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "ufs-sysfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <trace/hooks/ufshcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static const char *ufschd_uic_link_state_to_string(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) enum uic_link_state state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) case UIC_LINK_OFF_STATE: return "OFF";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) case UIC_LINK_ACTIVE_STATE: return "ACTIVE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) case UIC_LINK_HIBERN8_STATE: return "HIBERN8";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) case UIC_LINK_BROKEN_STATE: return "BROKEN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) default: return "UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static const char *ufschd_ufs_dev_pwr_mode_to_string(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) enum ufs_dev_pwr_mode state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) case UFS_ACTIVE_PWR_MODE: return "ACTIVE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) case UFS_SLEEP_PWR_MODE: return "SLEEP";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) case UFS_POWERDOWN_PWR_MODE: return "POWERDOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) default: return "UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static inline ssize_t ufs_sysfs_pm_lvl_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) const char *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) bool rpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned long flags, value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (kstrtoul(buf, 0, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (value >= UFS_PM_LVL_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) spin_lock_irqsave(hba->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (rpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) hba->rpm_lvl = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) hba->spm_lvl = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) spin_unlock_irqrestore(hba->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static ssize_t rpm_lvl_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return sysfs_emit(buf, "%d\n", hba->rpm_lvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static ssize_t rpm_lvl_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return ufs_sysfs_pm_lvl_store(dev, attr, buf, count, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static ssize_t rpm_target_dev_state_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return sysfs_emit(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ufs_pm_lvl_states[hba->rpm_lvl].dev_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static ssize_t rpm_target_link_state_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return sysfs_emit(buf, "%s\n", ufschd_uic_link_state_to_string(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ufs_pm_lvl_states[hba->rpm_lvl].link_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static ssize_t spm_lvl_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return sysfs_emit(buf, "%d\n", hba->spm_lvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static ssize_t spm_lvl_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return ufs_sysfs_pm_lvl_store(dev, attr, buf, count, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static ssize_t spm_target_dev_state_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return sysfs_emit(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ufs_pm_lvl_states[hba->spm_lvl].dev_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static ssize_t spm_target_link_state_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return sysfs_emit(buf, "%s\n", ufschd_uic_link_state_to_string(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ufs_pm_lvl_states[hba->spm_lvl].link_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* Convert Auto-Hibernate Idle Timer register value to microseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int ufshcd_ahit_to_us(u32 ahit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int timer = FIELD_GET(UFSHCI_AHIBERN8_TIMER_MASK, ahit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int scale = FIELD_GET(UFSHCI_AHIBERN8_SCALE_MASK, ahit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) for (; scale > 0; --scale)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) timer *= UFSHCI_AHIBERN8_SCALE_FACTOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* Convert microseconds to Auto-Hibernate Idle Timer register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static u32 ufshcd_us_to_ahit(unsigned int timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned int scale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) for (scale = 0; timer > UFSHCI_AHIBERN8_TIMER_MASK; ++scale)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) timer /= UFSHCI_AHIBERN8_SCALE_FACTOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, timer) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, scale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static ssize_t auto_hibern8_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) u32 ahit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (!ufshcd_is_auto_hibern8_supported(hba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) pm_runtime_get_sync(hba->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ufshcd_hold(hba, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ufshcd_release(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pm_runtime_put_sync(hba->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static ssize_t auto_hibern8_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) unsigned int timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!ufshcd_is_auto_hibern8_supported(hba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (kstrtouint(buf, 0, &timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (timer > UFSHCI_AHIBERN8_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ufshcd_auto_hibern8_update(hba, ufshcd_us_to_ahit(timer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static DEVICE_ATTR_RW(rpm_lvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static DEVICE_ATTR_RO(rpm_target_dev_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static DEVICE_ATTR_RO(rpm_target_link_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static DEVICE_ATTR_RW(spm_lvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static DEVICE_ATTR_RO(spm_target_dev_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static DEVICE_ATTR_RO(spm_target_link_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static DEVICE_ATTR_RW(auto_hibern8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) &dev_attr_rpm_lvl.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) &dev_attr_rpm_target_dev_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) &dev_attr_rpm_target_link_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) &dev_attr_spm_lvl.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) &dev_attr_spm_target_dev_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) &dev_attr_spm_target_link_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) &dev_attr_auto_hibern8.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static const struct attribute_group ufs_sysfs_default_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) .attrs = ufs_sysfs_ufshcd_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static ssize_t monitor_enable_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return sysfs_emit(buf, "%d\n", hba->monitor.enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static ssize_t monitor_enable_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unsigned long value, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (kstrtoul(buf, 0, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) value = !!value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) spin_lock_irqsave(hba->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (value == hba->monitor.enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (!value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) memset(&hba->monitor, 0, sizeof(hba->monitor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) hba->monitor.enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) hba->monitor.enabled_ts = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) spin_unlock_irqrestore(hba->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static ssize_t monitor_chunk_size_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return sysfs_emit(buf, "%lu\n", hba->monitor.chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static ssize_t monitor_chunk_size_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) unsigned long value, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (kstrtoul(buf, 0, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) spin_lock_irqsave(hba->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /* Only allow chunk size change when monitor is disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (!hba->monitor.enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) hba->monitor.chunk_size = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) spin_unlock_irqrestore(hba->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static ssize_t read_total_sectors_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return sysfs_emit(buf, "%lu\n", hba->monitor.nr_sec_rw[READ]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static ssize_t read_total_busy_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return sysfs_emit(buf, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) ktime_to_us(hba->monitor.total_busy[READ]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static ssize_t read_nr_requests_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return sysfs_emit(buf, "%lu\n", hba->monitor.nr_req[READ]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static ssize_t read_req_latency_avg_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct ufs_hba_monitor *m = &hba->monitor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[READ]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) m->nr_req[READ]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static ssize_t read_req_latency_max_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return sysfs_emit(buf, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ktime_to_us(hba->monitor.lat_max[READ]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static ssize_t read_req_latency_min_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return sysfs_emit(buf, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) ktime_to_us(hba->monitor.lat_min[READ]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static ssize_t read_req_latency_sum_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return sysfs_emit(buf, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) ktime_to_us(hba->monitor.lat_sum[READ]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static ssize_t write_total_sectors_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return sysfs_emit(buf, "%lu\n", hba->monitor.nr_sec_rw[WRITE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static ssize_t write_total_busy_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) return sysfs_emit(buf, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) ktime_to_us(hba->monitor.total_busy[WRITE]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static ssize_t write_nr_requests_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return sysfs_emit(buf, "%lu\n", hba->monitor.nr_req[WRITE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static ssize_t write_req_latency_avg_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct ufs_hba_monitor *m = &hba->monitor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[WRITE]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) m->nr_req[WRITE]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static ssize_t write_req_latency_max_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return sysfs_emit(buf, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ktime_to_us(hba->monitor.lat_max[WRITE]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static ssize_t write_req_latency_min_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return sysfs_emit(buf, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) ktime_to_us(hba->monitor.lat_min[WRITE]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static ssize_t write_req_latency_sum_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) struct ufs_hba *hba = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return sysfs_emit(buf, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) ktime_to_us(hba->monitor.lat_sum[WRITE]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static DEVICE_ATTR_RW(monitor_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static DEVICE_ATTR_RW(monitor_chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static DEVICE_ATTR_RO(read_total_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static DEVICE_ATTR_RO(read_total_busy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static DEVICE_ATTR_RO(read_nr_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static DEVICE_ATTR_RO(read_req_latency_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static DEVICE_ATTR_RO(read_req_latency_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static DEVICE_ATTR_RO(read_req_latency_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static DEVICE_ATTR_RO(read_req_latency_sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static DEVICE_ATTR_RO(write_total_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static DEVICE_ATTR_RO(write_total_busy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static DEVICE_ATTR_RO(write_nr_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static DEVICE_ATTR_RO(write_req_latency_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static DEVICE_ATTR_RO(write_req_latency_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static DEVICE_ATTR_RO(write_req_latency_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static DEVICE_ATTR_RO(write_req_latency_sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static struct attribute *ufs_sysfs_monitor_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) &dev_attr_monitor_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) &dev_attr_monitor_chunk_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) &dev_attr_read_total_sectors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) &dev_attr_read_total_busy.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) &dev_attr_read_nr_requests.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) &dev_attr_read_req_latency_avg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) &dev_attr_read_req_latency_max.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) &dev_attr_read_req_latency_min.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) &dev_attr_read_req_latency_sum.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) &dev_attr_write_total_sectors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) &dev_attr_write_total_busy.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) &dev_attr_write_nr_requests.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) &dev_attr_write_req_latency_avg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) &dev_attr_write_req_latency_max.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) &dev_attr_write_req_latency_min.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) &dev_attr_write_req_latency_sum.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static const struct attribute_group ufs_sysfs_monitor_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) .name = "monitor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) .attrs = ufs_sysfs_monitor_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) enum desc_idn desc_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) u8 desc_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) u8 param_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) u8 *sysfs_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) u8 param_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) u8 desc_buf[8] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (param_size > 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) pm_runtime_get_sync(hba->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) ret = ufshcd_read_desc_param(hba, desc_id, desc_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) param_offset, desc_buf, param_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) pm_runtime_put_sync(hba->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) switch (param_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) ret = sysfs_emit(sysfs_buf, "0x%02X\n", *desc_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) ret = sysfs_emit(sysfs_buf, "0x%04X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) get_unaligned_be16(desc_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) ret = sysfs_emit(sysfs_buf, "0x%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) get_unaligned_be32(desc_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) ret = sysfs_emit(sysfs_buf, "0x%016llX\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) get_unaligned_be64(desc_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) #define UFS_DESC_PARAM(_name, _puname, _duname, _size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static ssize_t _name##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) struct ufs_hba *hba = dev_get_drvdata(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return ufs_sysfs_read_desc_param(hba, QUERY_DESC_IDN_##_duname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 0, _duname##_DESC_PARAM##_puname, buf, _size); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static DEVICE_ATTR_RO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) #define UFS_DEVICE_DESC_PARAM(_name, _uname, _size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) UFS_DESC_PARAM(_name, _uname, DEVICE, _size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) UFS_DEVICE_DESC_PARAM(device_type, _DEVICE_TYPE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) UFS_DEVICE_DESC_PARAM(device_class, _DEVICE_CLASS, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) UFS_DEVICE_DESC_PARAM(device_sub_class, _DEVICE_SUB_CLASS, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) UFS_DEVICE_DESC_PARAM(protocol, _PRTCL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) UFS_DEVICE_DESC_PARAM(number_of_luns, _NUM_LU, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) UFS_DEVICE_DESC_PARAM(number_of_wluns, _NUM_WLU, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) UFS_DEVICE_DESC_PARAM(boot_enable, _BOOT_ENBL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) UFS_DEVICE_DESC_PARAM(descriptor_access_enable, _DESC_ACCSS_ENBL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) UFS_DEVICE_DESC_PARAM(initial_power_mode, _INIT_PWR_MODE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) UFS_DEVICE_DESC_PARAM(high_priority_lun, _HIGH_PR_LUN, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) UFS_DEVICE_DESC_PARAM(secure_removal_type, _SEC_RMV_TYPE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) UFS_DEVICE_DESC_PARAM(support_security_lun, _SEC_LU, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) UFS_DEVICE_DESC_PARAM(bkops_termination_latency, _BKOP_TERM_LT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) UFS_DEVICE_DESC_PARAM(initial_active_icc_level, _ACTVE_ICC_LVL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) UFS_DEVICE_DESC_PARAM(specification_version, _SPEC_VER, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) UFS_DEVICE_DESC_PARAM(manufacturing_date, _MANF_DATE, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) UFS_DEVICE_DESC_PARAM(manufacturer_id, _MANF_ID, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) UFS_DEVICE_DESC_PARAM(rtt_capability, _RTT_CAP, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) UFS_DEVICE_DESC_PARAM(rtc_update, _FRQ_RTC, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) UFS_DEVICE_DESC_PARAM(ufs_features, _UFS_FEAT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) UFS_DEVICE_DESC_PARAM(ffu_timeout, _FFU_TMT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) UFS_DEVICE_DESC_PARAM(queue_depth, _Q_DPTH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) UFS_DEVICE_DESC_PARAM(device_version, _DEV_VER, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) UFS_DEVICE_DESC_PARAM(number_of_secure_wpa, _NUM_SEC_WPA, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) UFS_DEVICE_DESC_PARAM(psa_max_data_size, _PSA_MAX_DATA, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) UFS_DEVICE_DESC_PARAM(psa_state_timeout, _PSA_TMT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) UFS_DEVICE_DESC_PARAM(hpb_version, _HPB_VER, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) UFS_DEVICE_DESC_PARAM(hpb_control, _HPB_CONTROL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) UFS_DEVICE_DESC_PARAM(ext_feature_sup, _EXT_UFS_FEATURE_SUP, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) UFS_DEVICE_DESC_PARAM(wb_presv_us_en, _WB_PRESRV_USRSPC_EN, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) UFS_DEVICE_DESC_PARAM(wb_type, _WB_TYPE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) UFS_DEVICE_DESC_PARAM(wb_shared_alloc_units, _WB_SHARED_ALLOC_UNITS, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static struct attribute *ufs_sysfs_device_descriptor[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) &dev_attr_device_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) &dev_attr_device_class.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) &dev_attr_device_sub_class.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) &dev_attr_protocol.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) &dev_attr_number_of_luns.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) &dev_attr_number_of_wluns.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) &dev_attr_boot_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) &dev_attr_descriptor_access_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) &dev_attr_initial_power_mode.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) &dev_attr_high_priority_lun.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) &dev_attr_secure_removal_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) &dev_attr_support_security_lun.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) &dev_attr_bkops_termination_latency.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) &dev_attr_initial_active_icc_level.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) &dev_attr_specification_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) &dev_attr_manufacturing_date.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) &dev_attr_manufacturer_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) &dev_attr_rtt_capability.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) &dev_attr_rtc_update.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) &dev_attr_ufs_features.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) &dev_attr_ffu_timeout.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) &dev_attr_queue_depth.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) &dev_attr_device_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) &dev_attr_number_of_secure_wpa.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) &dev_attr_psa_max_data_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) &dev_attr_psa_state_timeout.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) &dev_attr_hpb_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) &dev_attr_hpb_control.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) &dev_attr_ext_feature_sup.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) &dev_attr_wb_presv_us_en.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) &dev_attr_wb_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) &dev_attr_wb_shared_alloc_units.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static const struct attribute_group ufs_sysfs_device_descriptor_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) .name = "device_descriptor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) .attrs = ufs_sysfs_device_descriptor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) #define UFS_INTERCONNECT_DESC_PARAM(_name, _uname, _size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) UFS_DESC_PARAM(_name, _uname, INTERCONNECT, _size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) UFS_INTERCONNECT_DESC_PARAM(unipro_version, _UNIPRO_VER, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) UFS_INTERCONNECT_DESC_PARAM(mphy_version, _MPHY_VER, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static struct attribute *ufs_sysfs_interconnect_descriptor[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) &dev_attr_unipro_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) &dev_attr_mphy_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static const struct attribute_group ufs_sysfs_interconnect_descriptor_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) .name = "interconnect_descriptor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) .attrs = ufs_sysfs_interconnect_descriptor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) #define UFS_GEOMETRY_DESC_PARAM(_name, _uname, _size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) UFS_DESC_PARAM(_name, _uname, GEOMETRY, _size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) UFS_GEOMETRY_DESC_PARAM(raw_device_capacity, _DEV_CAP, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) UFS_GEOMETRY_DESC_PARAM(max_number_of_luns, _MAX_NUM_LUN, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) UFS_GEOMETRY_DESC_PARAM(segment_size, _SEG_SIZE, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) UFS_GEOMETRY_DESC_PARAM(allocation_unit_size, _ALLOC_UNIT_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) UFS_GEOMETRY_DESC_PARAM(min_addressable_block_size, _MIN_BLK_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) UFS_GEOMETRY_DESC_PARAM(optimal_read_block_size, _OPT_RD_BLK_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) UFS_GEOMETRY_DESC_PARAM(optimal_write_block_size, _OPT_WR_BLK_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) UFS_GEOMETRY_DESC_PARAM(max_in_buffer_size, _MAX_IN_BUF_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) UFS_GEOMETRY_DESC_PARAM(max_out_buffer_size, _MAX_OUT_BUF_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) UFS_GEOMETRY_DESC_PARAM(rpmb_rw_size, _RPMB_RW_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) UFS_GEOMETRY_DESC_PARAM(dyn_capacity_resource_policy, _DYN_CAP_RSRC_PLC, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) UFS_GEOMETRY_DESC_PARAM(data_ordering, _DATA_ORDER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) UFS_GEOMETRY_DESC_PARAM(max_number_of_contexts, _MAX_NUM_CTX, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) UFS_GEOMETRY_DESC_PARAM(sys_data_tag_unit_size, _TAG_UNIT_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) UFS_GEOMETRY_DESC_PARAM(sys_data_tag_resource_size, _TAG_RSRC_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) UFS_GEOMETRY_DESC_PARAM(secure_removal_types, _SEC_RM_TYPES, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) UFS_GEOMETRY_DESC_PARAM(memory_types, _MEM_TYPES, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) UFS_GEOMETRY_DESC_PARAM(sys_code_memory_max_alloc_units,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) _SCM_MAX_NUM_UNITS, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) UFS_GEOMETRY_DESC_PARAM(sys_code_memory_capacity_adjustment_factor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) _SCM_CAP_ADJ_FCTR, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) UFS_GEOMETRY_DESC_PARAM(non_persist_memory_max_alloc_units,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) _NPM_MAX_NUM_UNITS, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) UFS_GEOMETRY_DESC_PARAM(non_persist_memory_capacity_adjustment_factor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) _NPM_CAP_ADJ_FCTR, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) UFS_GEOMETRY_DESC_PARAM(enh1_memory_max_alloc_units,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) _ENM1_MAX_NUM_UNITS, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) UFS_GEOMETRY_DESC_PARAM(enh1_memory_capacity_adjustment_factor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) _ENM1_CAP_ADJ_FCTR, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) UFS_GEOMETRY_DESC_PARAM(enh2_memory_max_alloc_units,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) _ENM2_MAX_NUM_UNITS, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) UFS_GEOMETRY_DESC_PARAM(enh2_memory_capacity_adjustment_factor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) _ENM2_CAP_ADJ_FCTR, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) UFS_GEOMETRY_DESC_PARAM(enh3_memory_max_alloc_units,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) _ENM3_MAX_NUM_UNITS, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) UFS_GEOMETRY_DESC_PARAM(enh3_memory_capacity_adjustment_factor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) _ENM3_CAP_ADJ_FCTR, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) UFS_GEOMETRY_DESC_PARAM(enh4_memory_max_alloc_units,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) _ENM4_MAX_NUM_UNITS, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) UFS_GEOMETRY_DESC_PARAM(enh4_memory_capacity_adjustment_factor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) _ENM4_CAP_ADJ_FCTR, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) UFS_GEOMETRY_DESC_PARAM(hpb_region_size, _HPB_REGION_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) UFS_GEOMETRY_DESC_PARAM(hpb_number_lu, _HPB_NUMBER_LU, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) UFS_GEOMETRY_DESC_PARAM(hpb_subregion_size, _HPB_SUBREGION_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) UFS_GEOMETRY_DESC_PARAM(hpb_max_active_regions, _HPB_MAX_ACTIVE_REGS, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) UFS_GEOMETRY_DESC_PARAM(wb_max_alloc_units, _WB_MAX_ALLOC_UNITS, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) UFS_GEOMETRY_DESC_PARAM(wb_max_wb_luns, _WB_MAX_WB_LUNS, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) UFS_GEOMETRY_DESC_PARAM(wb_buff_cap_adj, _WB_BUFF_CAP_ADJ, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) UFS_GEOMETRY_DESC_PARAM(wb_sup_red_type, _WB_SUP_RED_TYPE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) UFS_GEOMETRY_DESC_PARAM(wb_sup_wb_type, _WB_SUP_WB_TYPE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) static struct attribute *ufs_sysfs_geometry_descriptor[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) &dev_attr_raw_device_capacity.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) &dev_attr_max_number_of_luns.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) &dev_attr_segment_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) &dev_attr_allocation_unit_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) &dev_attr_min_addressable_block_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) &dev_attr_optimal_read_block_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) &dev_attr_optimal_write_block_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) &dev_attr_max_in_buffer_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) &dev_attr_max_out_buffer_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) &dev_attr_rpmb_rw_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) &dev_attr_dyn_capacity_resource_policy.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) &dev_attr_data_ordering.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) &dev_attr_max_number_of_contexts.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) &dev_attr_sys_data_tag_unit_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) &dev_attr_sys_data_tag_resource_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) &dev_attr_secure_removal_types.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) &dev_attr_memory_types.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) &dev_attr_sys_code_memory_max_alloc_units.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) &dev_attr_sys_code_memory_capacity_adjustment_factor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) &dev_attr_non_persist_memory_max_alloc_units.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) &dev_attr_non_persist_memory_capacity_adjustment_factor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) &dev_attr_enh1_memory_max_alloc_units.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) &dev_attr_enh1_memory_capacity_adjustment_factor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) &dev_attr_enh2_memory_max_alloc_units.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) &dev_attr_enh2_memory_capacity_adjustment_factor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) &dev_attr_enh3_memory_max_alloc_units.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) &dev_attr_enh3_memory_capacity_adjustment_factor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) &dev_attr_enh4_memory_max_alloc_units.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) &dev_attr_enh4_memory_capacity_adjustment_factor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) &dev_attr_hpb_region_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) &dev_attr_hpb_number_lu.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) &dev_attr_hpb_subregion_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) &dev_attr_hpb_max_active_regions.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) &dev_attr_wb_max_alloc_units.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) &dev_attr_wb_max_wb_luns.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) &dev_attr_wb_buff_cap_adj.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) &dev_attr_wb_sup_red_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) &dev_attr_wb_sup_wb_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) static const struct attribute_group ufs_sysfs_geometry_descriptor_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) .name = "geometry_descriptor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) .attrs = ufs_sysfs_geometry_descriptor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) #define UFS_HEALTH_DESC_PARAM(_name, _uname, _size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) UFS_DESC_PARAM(_name, _uname, HEALTH, _size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) UFS_HEALTH_DESC_PARAM(eol_info, _EOL_INFO, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) UFS_HEALTH_DESC_PARAM(life_time_estimation_a, _LIFE_TIME_EST_A, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) UFS_HEALTH_DESC_PARAM(life_time_estimation_b, _LIFE_TIME_EST_B, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static struct attribute *ufs_sysfs_health_descriptor[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) &dev_attr_eol_info.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) &dev_attr_life_time_estimation_a.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) &dev_attr_life_time_estimation_b.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static const struct attribute_group ufs_sysfs_health_descriptor_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) .name = "health_descriptor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) .attrs = ufs_sysfs_health_descriptor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) #define UFS_POWER_DESC_PARAM(_name, _uname, _index) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static ssize_t _name##_index##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) struct ufs_hba *hba = dev_get_drvdata(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return ufs_sysfs_read_desc_param(hba, QUERY_DESC_IDN_POWER, 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) PWR_DESC##_uname##_0 + _index * 2, buf, 2); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) static DEVICE_ATTR_RO(_name##_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) UFS_POWER_DESC_PARAM(active_icc_levels_vcc, _ACTIVE_LVLS_VCC, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) UFS_POWER_DESC_PARAM(active_icc_levels_vccq, _ACTIVE_LVLS_VCCQ, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) UFS_POWER_DESC_PARAM(active_icc_levels_vccq2, _ACTIVE_LVLS_VCCQ2, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) static struct attribute *ufs_sysfs_power_descriptor[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) &dev_attr_active_icc_levels_vcc0.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) &dev_attr_active_icc_levels_vcc1.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) &dev_attr_active_icc_levels_vcc2.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) &dev_attr_active_icc_levels_vcc3.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) &dev_attr_active_icc_levels_vcc4.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) &dev_attr_active_icc_levels_vcc5.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) &dev_attr_active_icc_levels_vcc6.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) &dev_attr_active_icc_levels_vcc7.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) &dev_attr_active_icc_levels_vcc8.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) &dev_attr_active_icc_levels_vcc9.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) &dev_attr_active_icc_levels_vcc10.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) &dev_attr_active_icc_levels_vcc11.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) &dev_attr_active_icc_levels_vcc12.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) &dev_attr_active_icc_levels_vcc13.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) &dev_attr_active_icc_levels_vcc14.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) &dev_attr_active_icc_levels_vcc15.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) &dev_attr_active_icc_levels_vccq0.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) &dev_attr_active_icc_levels_vccq1.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) &dev_attr_active_icc_levels_vccq2.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) &dev_attr_active_icc_levels_vccq3.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) &dev_attr_active_icc_levels_vccq4.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) &dev_attr_active_icc_levels_vccq5.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) &dev_attr_active_icc_levels_vccq6.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) &dev_attr_active_icc_levels_vccq7.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) &dev_attr_active_icc_levels_vccq8.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) &dev_attr_active_icc_levels_vccq9.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) &dev_attr_active_icc_levels_vccq10.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) &dev_attr_active_icc_levels_vccq11.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) &dev_attr_active_icc_levels_vccq12.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) &dev_attr_active_icc_levels_vccq13.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) &dev_attr_active_icc_levels_vccq14.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) &dev_attr_active_icc_levels_vccq15.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) &dev_attr_active_icc_levels_vccq20.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) &dev_attr_active_icc_levels_vccq21.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) &dev_attr_active_icc_levels_vccq22.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) &dev_attr_active_icc_levels_vccq23.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) &dev_attr_active_icc_levels_vccq24.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) &dev_attr_active_icc_levels_vccq25.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) &dev_attr_active_icc_levels_vccq26.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) &dev_attr_active_icc_levels_vccq27.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) &dev_attr_active_icc_levels_vccq28.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) &dev_attr_active_icc_levels_vccq29.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) &dev_attr_active_icc_levels_vccq210.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) &dev_attr_active_icc_levels_vccq211.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) &dev_attr_active_icc_levels_vccq212.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) &dev_attr_active_icc_levels_vccq213.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) &dev_attr_active_icc_levels_vccq214.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) &dev_attr_active_icc_levels_vccq215.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) static const struct attribute_group ufs_sysfs_power_descriptor_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) .name = "power_descriptor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) .attrs = ufs_sysfs_power_descriptor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) #define UFS_STRING_DESCRIPTOR(_name, _pname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) static ssize_t _name##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) u8 index; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) struct ufs_hba *hba = dev_get_drvdata(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) int ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) int desc_len = QUERY_DESC_MAX_SIZE; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) u8 *desc_buf; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_ATOMIC); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (!desc_buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) return -ENOMEM; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) pm_runtime_get_sync(hba->dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) ret = ufshcd_query_descriptor_retry(hba, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_DEVICE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 0, 0, desc_buf, &desc_len); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (ret) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) ret = -EINVAL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) goto out; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) index = desc_buf[DEVICE_DESC_PARAM##_pname]; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) kfree(desc_buf); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) desc_buf = NULL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) ret = ufshcd_read_string_desc(hba, index, &desc_buf, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) SD_ASCII_STD); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) if (ret < 0) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) goto out; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) ret = sysfs_emit(buf, "%s\n", desc_buf); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) out: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) pm_runtime_put_sync(hba->dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) kfree(desc_buf); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) static DEVICE_ATTR_RO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) UFS_STRING_DESCRIPTOR(manufacturer_name, _MANF_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) UFS_STRING_DESCRIPTOR(product_name, _PRDCT_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) UFS_STRING_DESCRIPTOR(oem_id, _OEM_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) UFS_STRING_DESCRIPTOR(serial_number, _SN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) UFS_STRING_DESCRIPTOR(product_revision, _PRDCT_REV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) static struct attribute *ufs_sysfs_string_descriptors[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) &dev_attr_manufacturer_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) &dev_attr_product_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) &dev_attr_oem_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) &dev_attr_serial_number.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) &dev_attr_product_revision.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) static const struct attribute_group ufs_sysfs_string_descriptors_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) .name = "string_descriptors",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) .attrs = ufs_sysfs_string_descriptors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) static inline bool ufshcd_is_wb_flags(enum flag_idn idn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return ((idn >= QUERY_FLAG_IDN_WB_EN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) (idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) #define UFS_FLAG(_name, _uname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) static ssize_t _name##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) bool flag; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) u8 index = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) int ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) struct ufs_hba *hba = dev_get_drvdata(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) index = ufshcd_wb_get_query_index(hba); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) pm_runtime_get_sync(hba->dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) QUERY_FLAG_IDN##_uname, index, &flag); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) pm_runtime_put_sync(hba->dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) if (ret) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) return -EINVAL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) return sysfs_emit(buf, "%s\n", flag ? "true" : "false"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) static DEVICE_ATTR_RO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) UFS_FLAG(device_init, _FDEVICEINIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) UFS_FLAG(permanent_wpe, _PERMANENT_WPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) UFS_FLAG(power_on_wpe, _PWR_ON_WPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) UFS_FLAG(bkops_enable, _BKOPS_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) UFS_FLAG(life_span_mode_enable, _LIFE_SPAN_MODE_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) UFS_FLAG(phy_resource_removal, _FPHYRESOURCEREMOVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) UFS_FLAG(busy_rtc, _BUSY_RTC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) UFS_FLAG(disable_fw_update, _PERMANENTLY_DISABLE_FW_UPDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) UFS_FLAG(wb_enable, _WB_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) UFS_FLAG(wb_flush_en, _WB_BUFF_FLUSH_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) UFS_FLAG(wb_flush_during_h8, _WB_BUFF_FLUSH_DURING_HIBERN8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) UFS_FLAG(hpb_enable, _HPB_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) static struct attribute *ufs_sysfs_device_flags[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) &dev_attr_device_init.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) &dev_attr_permanent_wpe.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) &dev_attr_power_on_wpe.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) &dev_attr_bkops_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) &dev_attr_life_span_mode_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) &dev_attr_phy_resource_removal.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) &dev_attr_busy_rtc.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) &dev_attr_disable_fw_update.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) &dev_attr_wb_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) &dev_attr_wb_flush_en.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) &dev_attr_wb_flush_during_h8.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) &dev_attr_hpb_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) static const struct attribute_group ufs_sysfs_flags_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) .name = "flags",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) .attrs = ufs_sysfs_device_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) static inline bool ufshcd_is_wb_attrs(enum attr_idn idn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) return ((idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) (idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) #define UFS_ATTRIBUTE(_name, _uname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) static ssize_t _name##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) struct ufs_hba *hba = dev_get_drvdata(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) u32 value; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) int ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) u8 index = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) index = ufshcd_wb_get_query_index(hba); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) pm_runtime_get_sync(hba->dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) QUERY_ATTR_IDN##_uname, index, 0, &value); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) pm_runtime_put_sync(hba->dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) if (ret) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) return -EINVAL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) return sysfs_emit(buf, "0x%08X\n", value); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) static DEVICE_ATTR_RO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) UFS_ATTRIBUTE(boot_lun_enabled, _BOOT_LU_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) UFS_ATTRIBUTE(max_data_size_hpb_single_cmd, _MAX_HPB_SINGLE_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) UFS_ATTRIBUTE(current_power_mode, _POWER_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) UFS_ATTRIBUTE(active_icc_level, _ACTIVE_ICC_LVL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) UFS_ATTRIBUTE(ooo_data_enabled, _OOO_DATA_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) UFS_ATTRIBUTE(bkops_status, _BKOPS_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) UFS_ATTRIBUTE(purge_status, _PURGE_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) UFS_ATTRIBUTE(max_data_in_size, _MAX_DATA_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) UFS_ATTRIBUTE(max_data_out_size, _MAX_DATA_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) UFS_ATTRIBUTE(reference_clock_frequency, _REF_CLK_FREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) UFS_ATTRIBUTE(configuration_descriptor_lock, _CONF_DESC_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) UFS_ATTRIBUTE(max_number_of_rtt, _MAX_NUM_OF_RTT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) UFS_ATTRIBUTE(exception_event_control, _EE_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) UFS_ATTRIBUTE(exception_event_status, _EE_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) UFS_ATTRIBUTE(ffu_status, _FFU_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) UFS_ATTRIBUTE(psa_state, _PSA_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) UFS_ATTRIBUTE(psa_data_size, _PSA_DATA_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) UFS_ATTRIBUTE(wb_flush_status, _WB_FLUSH_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) UFS_ATTRIBUTE(wb_avail_buf, _AVAIL_WB_BUFF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) UFS_ATTRIBUTE(wb_life_time_est, _WB_BUFF_LIFE_TIME_EST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) UFS_ATTRIBUTE(wb_cur_buf, _CURR_WB_BUFF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) static struct attribute *ufs_sysfs_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) &dev_attr_boot_lun_enabled.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) &dev_attr_max_data_size_hpb_single_cmd.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) &dev_attr_current_power_mode.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) &dev_attr_active_icc_level.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) &dev_attr_ooo_data_enabled.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) &dev_attr_bkops_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) &dev_attr_purge_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) &dev_attr_max_data_in_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) &dev_attr_max_data_out_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) &dev_attr_reference_clock_frequency.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) &dev_attr_configuration_descriptor_lock.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) &dev_attr_max_number_of_rtt.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) &dev_attr_exception_event_control.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) &dev_attr_exception_event_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) &dev_attr_ffu_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) &dev_attr_psa_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) &dev_attr_psa_data_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) &dev_attr_wb_flush_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) &dev_attr_wb_avail_buf.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) &dev_attr_wb_life_time_est.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) &dev_attr_wb_cur_buf.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) static const struct attribute_group ufs_sysfs_attributes_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) .name = "attributes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) .attrs = ufs_sysfs_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) static const struct attribute_group *ufs_sysfs_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) &ufs_sysfs_default_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) &ufs_sysfs_monitor_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) &ufs_sysfs_device_descriptor_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) &ufs_sysfs_interconnect_descriptor_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) &ufs_sysfs_geometry_descriptor_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) &ufs_sysfs_health_descriptor_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) &ufs_sysfs_power_descriptor_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) &ufs_sysfs_string_descriptors_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) &ufs_sysfs_flags_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) &ufs_sysfs_attributes_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) #define UFS_LUN_DESC_PARAM(_pname, _puname, _duname, _size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) static ssize_t _pname##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) struct scsi_device *sdev = to_scsi_device(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) struct ufs_hba *hba = shost_priv(sdev->host); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (!ufs_is_valid_unit_desc_lun(&hba->dev_info, lun, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) _duname##_DESC_PARAM##_puname)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return -EINVAL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) return ufs_sysfs_read_desc_param(hba, QUERY_DESC_IDN_##_duname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) lun, _duname##_DESC_PARAM##_puname, buf, _size); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) static DEVICE_ATTR_RO(_pname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) #define UFS_UNIT_DESC_PARAM(_name, _uname, _size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) UFS_LUN_DESC_PARAM(_name, _uname, UNIT, _size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) UFS_UNIT_DESC_PARAM(boot_lun_id, _BOOT_LUN_ID, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) UFS_UNIT_DESC_PARAM(lun_write_protect, _LU_WR_PROTECT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) UFS_UNIT_DESC_PARAM(lun_queue_depth, _LU_Q_DEPTH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) UFS_UNIT_DESC_PARAM(psa_sensitive, _PSA_SENSITIVE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) UFS_UNIT_DESC_PARAM(lun_memory_type, _MEM_TYPE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) UFS_UNIT_DESC_PARAM(data_reliability, _DATA_RELIABILITY, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) UFS_UNIT_DESC_PARAM(logical_block_size, _LOGICAL_BLK_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) UFS_UNIT_DESC_PARAM(logical_block_count, _LOGICAL_BLK_COUNT, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) UFS_UNIT_DESC_PARAM(erase_block_size, _ERASE_BLK_SIZE, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) UFS_UNIT_DESC_PARAM(provisioning_type, _PROVISIONING_TYPE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) UFS_UNIT_DESC_PARAM(physical_memory_resourse_count, _PHY_MEM_RSRC_CNT, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) UFS_UNIT_DESC_PARAM(context_capabilities, _CTX_CAPABILITIES, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) UFS_UNIT_DESC_PARAM(large_unit_granularity, _LARGE_UNIT_SIZE_M1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) UFS_UNIT_DESC_PARAM(hpb_lu_max_active_regions, _HPB_LU_MAX_ACTIVE_RGNS, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) UFS_UNIT_DESC_PARAM(hpb_pinned_region_start_offset, _HPB_PIN_RGN_START_OFF, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) UFS_UNIT_DESC_PARAM(hpb_number_pinned_regions, _HPB_NUM_PIN_RGNS, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) UFS_UNIT_DESC_PARAM(wb_buf_alloc_units, _WB_BUF_ALLOC_UNITS, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) static struct attribute *ufs_sysfs_unit_descriptor[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) &dev_attr_boot_lun_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) &dev_attr_lun_write_protect.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) &dev_attr_lun_queue_depth.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) &dev_attr_psa_sensitive.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) &dev_attr_lun_memory_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) &dev_attr_data_reliability.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) &dev_attr_logical_block_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) &dev_attr_logical_block_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) &dev_attr_erase_block_size.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) &dev_attr_provisioning_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) &dev_attr_physical_memory_resourse_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) &dev_attr_context_capabilities.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) &dev_attr_large_unit_granularity.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) &dev_attr_hpb_lu_max_active_regions.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) &dev_attr_hpb_pinned_region_start_offset.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) &dev_attr_hpb_number_pinned_regions.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) &dev_attr_wb_buf_alloc_units.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) const struct attribute_group ufs_sysfs_unit_descriptor_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) .name = "unit_descriptor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) .attrs = ufs_sysfs_unit_descriptor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) static ssize_t dyn_cap_needed_attribute_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) struct scsi_device *sdev = to_scsi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) struct ufs_hba *hba = shost_priv(sdev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) pm_runtime_get_sync(hba->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) QUERY_ATTR_IDN_DYN_CAP_NEEDED, lun, 0, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) pm_runtime_put_sync(hba->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) return sysfs_emit(buf, "0x%08X\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) static DEVICE_ATTR_RO(dyn_cap_needed_attribute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) static struct attribute *ufs_sysfs_lun_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) &dev_attr_dyn_cap_needed_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) const struct attribute_group ufs_sysfs_lun_attributes_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) .attrs = ufs_sysfs_lun_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) void ufs_sysfs_add_nodes(struct ufs_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) ret = sysfs_create_groups(&hba->dev->kobj, ufs_sysfs_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) dev_err(hba->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) "%s: sysfs groups creation failed (err = %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) trace_android_vh_ufs_update_sysfs(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) void ufs_sysfs_remove_nodes(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) sysfs_remove_groups(&dev->kobj, ufs_sysfs_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }