| .. | .. |
|---|
| 9 | 9 | #include "ufs.h" |
|---|
| 10 | 10 | #include "ufs-sysfs.h" |
|---|
| 11 | 11 | |
|---|
| 12 | +#include <trace/hooks/ufshcd.h> |
|---|
| 13 | + |
|---|
| 12 | 14 | static const char *ufschd_uic_link_state_to_string( |
|---|
| 13 | 15 | enum uic_link_state state) |
|---|
| 14 | 16 | { |
|---|
| .. | .. |
|---|
| 16 | 18 | case UIC_LINK_OFF_STATE: return "OFF"; |
|---|
| 17 | 19 | case UIC_LINK_ACTIVE_STATE: return "ACTIVE"; |
|---|
| 18 | 20 | case UIC_LINK_HIBERN8_STATE: return "HIBERN8"; |
|---|
| 21 | + case UIC_LINK_BROKEN_STATE: return "BROKEN"; |
|---|
| 19 | 22 | default: return "UNKNOWN"; |
|---|
| 20 | 23 | } |
|---|
| 21 | 24 | } |
|---|
| .. | .. |
|---|
| 59 | 62 | { |
|---|
| 60 | 63 | struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 61 | 64 | |
|---|
| 62 | | - return sprintf(buf, "%d\n", hba->rpm_lvl); |
|---|
| 65 | + return sysfs_emit(buf, "%d\n", hba->rpm_lvl); |
|---|
| 63 | 66 | } |
|---|
| 64 | 67 | |
|---|
| 65 | 68 | static ssize_t rpm_lvl_store(struct device *dev, |
|---|
| .. | .. |
|---|
| 73 | 76 | { |
|---|
| 74 | 77 | struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 75 | 78 | |
|---|
| 76 | | - return sprintf(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( |
|---|
| 79 | + return sysfs_emit(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( |
|---|
| 77 | 80 | ufs_pm_lvl_states[hba->rpm_lvl].dev_state)); |
|---|
| 78 | 81 | } |
|---|
| 79 | 82 | |
|---|
| .. | .. |
|---|
| 82 | 85 | { |
|---|
| 83 | 86 | struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 84 | 87 | |
|---|
| 85 | | - return sprintf(buf, "%s\n", ufschd_uic_link_state_to_string( |
|---|
| 88 | + return sysfs_emit(buf, "%s\n", ufschd_uic_link_state_to_string( |
|---|
| 86 | 89 | ufs_pm_lvl_states[hba->rpm_lvl].link_state)); |
|---|
| 87 | 90 | } |
|---|
| 88 | 91 | |
|---|
| .. | .. |
|---|
| 91 | 94 | { |
|---|
| 92 | 95 | struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 93 | 96 | |
|---|
| 94 | | - return sprintf(buf, "%d\n", hba->spm_lvl); |
|---|
| 97 | + return sysfs_emit(buf, "%d\n", hba->spm_lvl); |
|---|
| 95 | 98 | } |
|---|
| 96 | 99 | |
|---|
| 97 | 100 | static ssize_t spm_lvl_store(struct device *dev, |
|---|
| .. | .. |
|---|
| 105 | 108 | { |
|---|
| 106 | 109 | struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 107 | 110 | |
|---|
| 108 | | - return sprintf(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( |
|---|
| 111 | + return sysfs_emit(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( |
|---|
| 109 | 112 | ufs_pm_lvl_states[hba->spm_lvl].dev_state)); |
|---|
| 110 | 113 | } |
|---|
| 111 | 114 | |
|---|
| .. | .. |
|---|
| 114 | 117 | { |
|---|
| 115 | 118 | struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 116 | 119 | |
|---|
| 117 | | - return sprintf(buf, "%s\n", ufschd_uic_link_state_to_string( |
|---|
| 120 | + return sysfs_emit(buf, "%s\n", ufschd_uic_link_state_to_string( |
|---|
| 118 | 121 | ufs_pm_lvl_states[hba->spm_lvl].link_state)); |
|---|
| 119 | | -} |
|---|
| 120 | | - |
|---|
| 121 | | -static void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) |
|---|
| 122 | | -{ |
|---|
| 123 | | - unsigned long flags; |
|---|
| 124 | | - |
|---|
| 125 | | - if (!(hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT)) |
|---|
| 126 | | - return; |
|---|
| 127 | | - |
|---|
| 128 | | - spin_lock_irqsave(hba->host->host_lock, flags); |
|---|
| 129 | | - if (hba->ahit == ahit) |
|---|
| 130 | | - goto out_unlock; |
|---|
| 131 | | - hba->ahit = ahit; |
|---|
| 132 | | - if (!pm_runtime_suspended(hba->dev)) |
|---|
| 133 | | - ufshcd_writel(hba, hba->ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); |
|---|
| 134 | | -out_unlock: |
|---|
| 135 | | - spin_unlock_irqrestore(hba->host->host_lock, flags); |
|---|
| 136 | 122 | } |
|---|
| 137 | 123 | |
|---|
| 138 | 124 | /* Convert Auto-Hibernate Idle Timer register value to microseconds */ |
|---|
| .. | .. |
|---|
| 162 | 148 | static ssize_t auto_hibern8_show(struct device *dev, |
|---|
| 163 | 149 | struct device_attribute *attr, char *buf) |
|---|
| 164 | 150 | { |
|---|
| 151 | + u32 ahit; |
|---|
| 165 | 152 | struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 166 | 153 | |
|---|
| 167 | | - if (!(hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT)) |
|---|
| 154 | + if (!ufshcd_is_auto_hibern8_supported(hba)) |
|---|
| 168 | 155 | return -EOPNOTSUPP; |
|---|
| 169 | 156 | |
|---|
| 170 | | - return snprintf(buf, PAGE_SIZE, "%d\n", ufshcd_ahit_to_us(hba->ahit)); |
|---|
| 157 | + pm_runtime_get_sync(hba->dev); |
|---|
| 158 | + ufshcd_hold(hba, false); |
|---|
| 159 | + ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER); |
|---|
| 160 | + ufshcd_release(hba); |
|---|
| 161 | + pm_runtime_put_sync(hba->dev); |
|---|
| 162 | + |
|---|
| 163 | + return sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit)); |
|---|
| 171 | 164 | } |
|---|
| 172 | 165 | |
|---|
| 173 | 166 | static ssize_t auto_hibern8_store(struct device *dev, |
|---|
| .. | .. |
|---|
| 177 | 170 | struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 178 | 171 | unsigned int timer; |
|---|
| 179 | 172 | |
|---|
| 180 | | - if (!(hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT)) |
|---|
| 173 | + if (!ufshcd_is_auto_hibern8_supported(hba)) |
|---|
| 181 | 174 | return -EOPNOTSUPP; |
|---|
| 182 | 175 | |
|---|
| 183 | 176 | if (kstrtouint(buf, 0, &timer)) |
|---|
| .. | .. |
|---|
| 214 | 207 | .attrs = ufs_sysfs_ufshcd_attrs, |
|---|
| 215 | 208 | }; |
|---|
| 216 | 209 | |
|---|
| 210 | +static ssize_t monitor_enable_show(struct device *dev, |
|---|
| 211 | + struct device_attribute *attr, char *buf) |
|---|
| 212 | +{ |
|---|
| 213 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 214 | + |
|---|
| 215 | + return sysfs_emit(buf, "%d\n", hba->monitor.enabled); |
|---|
| 216 | +} |
|---|
| 217 | + |
|---|
| 218 | +static ssize_t monitor_enable_store(struct device *dev, |
|---|
| 219 | + struct device_attribute *attr, |
|---|
| 220 | + const char *buf, size_t count) |
|---|
| 221 | +{ |
|---|
| 222 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 223 | + unsigned long value, flags; |
|---|
| 224 | + |
|---|
| 225 | + if (kstrtoul(buf, 0, &value)) |
|---|
| 226 | + return -EINVAL; |
|---|
| 227 | + |
|---|
| 228 | + value = !!value; |
|---|
| 229 | + spin_lock_irqsave(hba->host->host_lock, flags); |
|---|
| 230 | + if (value == hba->monitor.enabled) |
|---|
| 231 | + goto out_unlock; |
|---|
| 232 | + |
|---|
| 233 | + if (!value) { |
|---|
| 234 | + memset(&hba->monitor, 0, sizeof(hba->monitor)); |
|---|
| 235 | + } else { |
|---|
| 236 | + hba->monitor.enabled = true; |
|---|
| 237 | + hba->monitor.enabled_ts = ktime_get(); |
|---|
| 238 | + } |
|---|
| 239 | + |
|---|
| 240 | +out_unlock: |
|---|
| 241 | + spin_unlock_irqrestore(hba->host->host_lock, flags); |
|---|
| 242 | + return count; |
|---|
| 243 | +} |
|---|
| 244 | + |
|---|
| 245 | +static ssize_t monitor_chunk_size_show(struct device *dev, |
|---|
| 246 | + struct device_attribute *attr, char *buf) |
|---|
| 247 | +{ |
|---|
| 248 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 249 | + |
|---|
| 250 | + return sysfs_emit(buf, "%lu\n", hba->monitor.chunk_size); |
|---|
| 251 | +} |
|---|
| 252 | + |
|---|
| 253 | +static ssize_t monitor_chunk_size_store(struct device *dev, |
|---|
| 254 | + struct device_attribute *attr, |
|---|
| 255 | + const char *buf, size_t count) |
|---|
| 256 | +{ |
|---|
| 257 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 258 | + unsigned long value, flags; |
|---|
| 259 | + |
|---|
| 260 | + if (kstrtoul(buf, 0, &value)) |
|---|
| 261 | + return -EINVAL; |
|---|
| 262 | + |
|---|
| 263 | + spin_lock_irqsave(hba->host->host_lock, flags); |
|---|
| 264 | + /* Only allow chunk size change when monitor is disabled */ |
|---|
| 265 | + if (!hba->monitor.enabled) |
|---|
| 266 | + hba->monitor.chunk_size = value; |
|---|
| 267 | + spin_unlock_irqrestore(hba->host->host_lock, flags); |
|---|
| 268 | + return count; |
|---|
| 269 | +} |
|---|
| 270 | + |
|---|
| 271 | +static ssize_t read_total_sectors_show(struct device *dev, |
|---|
| 272 | + struct device_attribute *attr, char *buf) |
|---|
| 273 | +{ |
|---|
| 274 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 275 | + |
|---|
| 276 | + return sysfs_emit(buf, "%lu\n", hba->monitor.nr_sec_rw[READ]); |
|---|
| 277 | +} |
|---|
| 278 | + |
|---|
| 279 | +static ssize_t read_total_busy_show(struct device *dev, |
|---|
| 280 | + struct device_attribute *attr, char *buf) |
|---|
| 281 | +{ |
|---|
| 282 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 283 | + |
|---|
| 284 | + return sysfs_emit(buf, "%llu\n", |
|---|
| 285 | + ktime_to_us(hba->monitor.total_busy[READ])); |
|---|
| 286 | +} |
|---|
| 287 | + |
|---|
| 288 | +static ssize_t read_nr_requests_show(struct device *dev, |
|---|
| 289 | + struct device_attribute *attr, char *buf) |
|---|
| 290 | +{ |
|---|
| 291 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 292 | + |
|---|
| 293 | + return sysfs_emit(buf, "%lu\n", hba->monitor.nr_req[READ]); |
|---|
| 294 | +} |
|---|
| 295 | + |
|---|
| 296 | +static ssize_t read_req_latency_avg_show(struct device *dev, |
|---|
| 297 | + struct device_attribute *attr, |
|---|
| 298 | + char *buf) |
|---|
| 299 | +{ |
|---|
| 300 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 301 | + struct ufs_hba_monitor *m = &hba->monitor; |
|---|
| 302 | + |
|---|
| 303 | + return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[READ]), |
|---|
| 304 | + m->nr_req[READ])); |
|---|
| 305 | +} |
|---|
| 306 | + |
|---|
| 307 | +static ssize_t read_req_latency_max_show(struct device *dev, |
|---|
| 308 | + struct device_attribute *attr, |
|---|
| 309 | + char *buf) |
|---|
| 310 | +{ |
|---|
| 311 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 312 | + |
|---|
| 313 | + return sysfs_emit(buf, "%llu\n", |
|---|
| 314 | + ktime_to_us(hba->monitor.lat_max[READ])); |
|---|
| 315 | +} |
|---|
| 316 | + |
|---|
| 317 | +static ssize_t read_req_latency_min_show(struct device *dev, |
|---|
| 318 | + struct device_attribute *attr, |
|---|
| 319 | + char *buf) |
|---|
| 320 | +{ |
|---|
| 321 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 322 | + |
|---|
| 323 | + return sysfs_emit(buf, "%llu\n", |
|---|
| 324 | + ktime_to_us(hba->monitor.lat_min[READ])); |
|---|
| 325 | +} |
|---|
| 326 | + |
|---|
| 327 | +static ssize_t read_req_latency_sum_show(struct device *dev, |
|---|
| 328 | + struct device_attribute *attr, |
|---|
| 329 | + char *buf) |
|---|
| 330 | +{ |
|---|
| 331 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 332 | + |
|---|
| 333 | + return sysfs_emit(buf, "%llu\n", |
|---|
| 334 | + ktime_to_us(hba->monitor.lat_sum[READ])); |
|---|
| 335 | +} |
|---|
| 336 | + |
|---|
| 337 | +static ssize_t write_total_sectors_show(struct device *dev, |
|---|
| 338 | + struct device_attribute *attr, |
|---|
| 339 | + char *buf) |
|---|
| 340 | +{ |
|---|
| 341 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 342 | + |
|---|
| 343 | + return sysfs_emit(buf, "%lu\n", hba->monitor.nr_sec_rw[WRITE]); |
|---|
| 344 | +} |
|---|
| 345 | + |
|---|
| 346 | +static ssize_t write_total_busy_show(struct device *dev, |
|---|
| 347 | + struct device_attribute *attr, char *buf) |
|---|
| 348 | +{ |
|---|
| 349 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 350 | + |
|---|
| 351 | + return sysfs_emit(buf, "%llu\n", |
|---|
| 352 | + ktime_to_us(hba->monitor.total_busy[WRITE])); |
|---|
| 353 | +} |
|---|
| 354 | + |
|---|
| 355 | +static ssize_t write_nr_requests_show(struct device *dev, |
|---|
| 356 | + struct device_attribute *attr, char *buf) |
|---|
| 357 | +{ |
|---|
| 358 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 359 | + |
|---|
| 360 | + return sysfs_emit(buf, "%lu\n", hba->monitor.nr_req[WRITE]); |
|---|
| 361 | +} |
|---|
| 362 | + |
|---|
| 363 | +static ssize_t write_req_latency_avg_show(struct device *dev, |
|---|
| 364 | + struct device_attribute *attr, |
|---|
| 365 | + char *buf) |
|---|
| 366 | +{ |
|---|
| 367 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 368 | + struct ufs_hba_monitor *m = &hba->monitor; |
|---|
| 369 | + |
|---|
| 370 | + return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[WRITE]), |
|---|
| 371 | + m->nr_req[WRITE])); |
|---|
| 372 | +} |
|---|
| 373 | + |
|---|
| 374 | +static ssize_t write_req_latency_max_show(struct device *dev, |
|---|
| 375 | + struct device_attribute *attr, |
|---|
| 376 | + char *buf) |
|---|
| 377 | +{ |
|---|
| 378 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 379 | + |
|---|
| 380 | + return sysfs_emit(buf, "%llu\n", |
|---|
| 381 | + ktime_to_us(hba->monitor.lat_max[WRITE])); |
|---|
| 382 | +} |
|---|
| 383 | + |
|---|
| 384 | +static ssize_t write_req_latency_min_show(struct device *dev, |
|---|
| 385 | + struct device_attribute *attr, |
|---|
| 386 | + char *buf) |
|---|
| 387 | +{ |
|---|
| 388 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 389 | + |
|---|
| 390 | + return sysfs_emit(buf, "%llu\n", |
|---|
| 391 | + ktime_to_us(hba->monitor.lat_min[WRITE])); |
|---|
| 392 | +} |
|---|
| 393 | + |
|---|
| 394 | +static ssize_t write_req_latency_sum_show(struct device *dev, |
|---|
| 395 | + struct device_attribute *attr, |
|---|
| 396 | + char *buf) |
|---|
| 397 | +{ |
|---|
| 398 | + struct ufs_hba *hba = dev_get_drvdata(dev); |
|---|
| 399 | + |
|---|
| 400 | + return sysfs_emit(buf, "%llu\n", |
|---|
| 401 | + ktime_to_us(hba->monitor.lat_sum[WRITE])); |
|---|
| 402 | +} |
|---|
| 403 | + |
|---|
| 404 | +static DEVICE_ATTR_RW(monitor_enable); |
|---|
| 405 | +static DEVICE_ATTR_RW(monitor_chunk_size); |
|---|
| 406 | +static DEVICE_ATTR_RO(read_total_sectors); |
|---|
| 407 | +static DEVICE_ATTR_RO(read_total_busy); |
|---|
| 408 | +static DEVICE_ATTR_RO(read_nr_requests); |
|---|
| 409 | +static DEVICE_ATTR_RO(read_req_latency_avg); |
|---|
| 410 | +static DEVICE_ATTR_RO(read_req_latency_max); |
|---|
| 411 | +static DEVICE_ATTR_RO(read_req_latency_min); |
|---|
| 412 | +static DEVICE_ATTR_RO(read_req_latency_sum); |
|---|
| 413 | +static DEVICE_ATTR_RO(write_total_sectors); |
|---|
| 414 | +static DEVICE_ATTR_RO(write_total_busy); |
|---|
| 415 | +static DEVICE_ATTR_RO(write_nr_requests); |
|---|
| 416 | +static DEVICE_ATTR_RO(write_req_latency_avg); |
|---|
| 417 | +static DEVICE_ATTR_RO(write_req_latency_max); |
|---|
| 418 | +static DEVICE_ATTR_RO(write_req_latency_min); |
|---|
| 419 | +static DEVICE_ATTR_RO(write_req_latency_sum); |
|---|
| 420 | + |
|---|
| 421 | +static struct attribute *ufs_sysfs_monitor_attrs[] = { |
|---|
| 422 | + &dev_attr_monitor_enable.attr, |
|---|
| 423 | + &dev_attr_monitor_chunk_size.attr, |
|---|
| 424 | + &dev_attr_read_total_sectors.attr, |
|---|
| 425 | + &dev_attr_read_total_busy.attr, |
|---|
| 426 | + &dev_attr_read_nr_requests.attr, |
|---|
| 427 | + &dev_attr_read_req_latency_avg.attr, |
|---|
| 428 | + &dev_attr_read_req_latency_max.attr, |
|---|
| 429 | + &dev_attr_read_req_latency_min.attr, |
|---|
| 430 | + &dev_attr_read_req_latency_sum.attr, |
|---|
| 431 | + &dev_attr_write_total_sectors.attr, |
|---|
| 432 | + &dev_attr_write_total_busy.attr, |
|---|
| 433 | + &dev_attr_write_nr_requests.attr, |
|---|
| 434 | + &dev_attr_write_req_latency_avg.attr, |
|---|
| 435 | + &dev_attr_write_req_latency_max.attr, |
|---|
| 436 | + &dev_attr_write_req_latency_min.attr, |
|---|
| 437 | + &dev_attr_write_req_latency_sum.attr, |
|---|
| 438 | + NULL |
|---|
| 439 | +}; |
|---|
| 440 | + |
|---|
| 441 | +static const struct attribute_group ufs_sysfs_monitor_group = { |
|---|
| 442 | + .name = "monitor", |
|---|
| 443 | + .attrs = ufs_sysfs_monitor_attrs, |
|---|
| 444 | +}; |
|---|
| 445 | + |
|---|
| 217 | 446 | static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba, |
|---|
| 218 | 447 | enum desc_idn desc_id, |
|---|
| 219 | 448 | u8 desc_index, |
|---|
| .. | .. |
|---|
| 227 | 456 | if (param_size > 8) |
|---|
| 228 | 457 | return -EINVAL; |
|---|
| 229 | 458 | |
|---|
| 459 | + pm_runtime_get_sync(hba->dev); |
|---|
| 230 | 460 | ret = ufshcd_read_desc_param(hba, desc_id, desc_index, |
|---|
| 231 | 461 | param_offset, desc_buf, param_size); |
|---|
| 462 | + pm_runtime_put_sync(hba->dev); |
|---|
| 232 | 463 | if (ret) |
|---|
| 233 | 464 | return -EINVAL; |
|---|
| 234 | 465 | switch (param_size) { |
|---|
| 235 | 466 | case 1: |
|---|
| 236 | | - ret = sprintf(sysfs_buf, "0x%02X\n", *desc_buf); |
|---|
| 467 | + ret = sysfs_emit(sysfs_buf, "0x%02X\n", *desc_buf); |
|---|
| 237 | 468 | break; |
|---|
| 238 | 469 | case 2: |
|---|
| 239 | | - ret = sprintf(sysfs_buf, "0x%04X\n", |
|---|
| 470 | + ret = sysfs_emit(sysfs_buf, "0x%04X\n", |
|---|
| 240 | 471 | get_unaligned_be16(desc_buf)); |
|---|
| 241 | 472 | break; |
|---|
| 242 | 473 | case 4: |
|---|
| 243 | | - ret = sprintf(sysfs_buf, "0x%08X\n", |
|---|
| 474 | + ret = sysfs_emit(sysfs_buf, "0x%08X\n", |
|---|
| 244 | 475 | get_unaligned_be32(desc_buf)); |
|---|
| 245 | 476 | break; |
|---|
| 246 | 477 | case 8: |
|---|
| 247 | | - ret = sprintf(sysfs_buf, "0x%016llX\n", |
|---|
| 478 | + ret = sysfs_emit(sysfs_buf, "0x%016llX\n", |
|---|
| 248 | 479 | get_unaligned_be64(desc_buf)); |
|---|
| 249 | 480 | break; |
|---|
| 250 | 481 | } |
|---|
| .. | .. |
|---|
| 291 | 522 | UFS_DEVICE_DESC_PARAM(number_of_secure_wpa, _NUM_SEC_WPA, 1); |
|---|
| 292 | 523 | UFS_DEVICE_DESC_PARAM(psa_max_data_size, _PSA_MAX_DATA, 4); |
|---|
| 293 | 524 | UFS_DEVICE_DESC_PARAM(psa_state_timeout, _PSA_TMT, 1); |
|---|
| 525 | +UFS_DEVICE_DESC_PARAM(hpb_version, _HPB_VER, 2); |
|---|
| 526 | +UFS_DEVICE_DESC_PARAM(hpb_control, _HPB_CONTROL, 1); |
|---|
| 527 | +UFS_DEVICE_DESC_PARAM(ext_feature_sup, _EXT_UFS_FEATURE_SUP, 4); |
|---|
| 528 | +UFS_DEVICE_DESC_PARAM(wb_presv_us_en, _WB_PRESRV_USRSPC_EN, 1); |
|---|
| 529 | +UFS_DEVICE_DESC_PARAM(wb_type, _WB_TYPE, 1); |
|---|
| 530 | +UFS_DEVICE_DESC_PARAM(wb_shared_alloc_units, _WB_SHARED_ALLOC_UNITS, 4); |
|---|
| 294 | 531 | |
|---|
| 295 | 532 | static struct attribute *ufs_sysfs_device_descriptor[] = { |
|---|
| 296 | 533 | &dev_attr_device_type.attr, |
|---|
| .. | .. |
|---|
| 319 | 556 | &dev_attr_number_of_secure_wpa.attr, |
|---|
| 320 | 557 | &dev_attr_psa_max_data_size.attr, |
|---|
| 321 | 558 | &dev_attr_psa_state_timeout.attr, |
|---|
| 559 | + &dev_attr_hpb_version.attr, |
|---|
| 560 | + &dev_attr_hpb_control.attr, |
|---|
| 561 | + &dev_attr_ext_feature_sup.attr, |
|---|
| 562 | + &dev_attr_wb_presv_us_en.attr, |
|---|
| 563 | + &dev_attr_wb_type.attr, |
|---|
| 564 | + &dev_attr_wb_shared_alloc_units.attr, |
|---|
| 322 | 565 | NULL, |
|---|
| 323 | 566 | }; |
|---|
| 324 | 567 | |
|---|
| .. | .. |
|---|
| 388 | 631 | _ENM4_MAX_NUM_UNITS, 4); |
|---|
| 389 | 632 | UFS_GEOMETRY_DESC_PARAM(enh4_memory_capacity_adjustment_factor, |
|---|
| 390 | 633 | _ENM4_CAP_ADJ_FCTR, 2); |
|---|
| 634 | +UFS_GEOMETRY_DESC_PARAM(hpb_region_size, _HPB_REGION_SIZE, 1); |
|---|
| 635 | +UFS_GEOMETRY_DESC_PARAM(hpb_number_lu, _HPB_NUMBER_LU, 1); |
|---|
| 636 | +UFS_GEOMETRY_DESC_PARAM(hpb_subregion_size, _HPB_SUBREGION_SIZE, 1); |
|---|
| 637 | +UFS_GEOMETRY_DESC_PARAM(hpb_max_active_regions, _HPB_MAX_ACTIVE_REGS, 2); |
|---|
| 638 | +UFS_GEOMETRY_DESC_PARAM(wb_max_alloc_units, _WB_MAX_ALLOC_UNITS, 4); |
|---|
| 639 | +UFS_GEOMETRY_DESC_PARAM(wb_max_wb_luns, _WB_MAX_WB_LUNS, 1); |
|---|
| 640 | +UFS_GEOMETRY_DESC_PARAM(wb_buff_cap_adj, _WB_BUFF_CAP_ADJ, 1); |
|---|
| 641 | +UFS_GEOMETRY_DESC_PARAM(wb_sup_red_type, _WB_SUP_RED_TYPE, 1); |
|---|
| 642 | +UFS_GEOMETRY_DESC_PARAM(wb_sup_wb_type, _WB_SUP_WB_TYPE, 1); |
|---|
| 643 | + |
|---|
| 391 | 644 | |
|---|
| 392 | 645 | static struct attribute *ufs_sysfs_geometry_descriptor[] = { |
|---|
| 393 | 646 | &dev_attr_raw_device_capacity.attr, |
|---|
| .. | .. |
|---|
| 419 | 672 | &dev_attr_enh3_memory_capacity_adjustment_factor.attr, |
|---|
| 420 | 673 | &dev_attr_enh4_memory_max_alloc_units.attr, |
|---|
| 421 | 674 | &dev_attr_enh4_memory_capacity_adjustment_factor.attr, |
|---|
| 675 | + &dev_attr_hpb_region_size.attr, |
|---|
| 676 | + &dev_attr_hpb_number_lu.attr, |
|---|
| 677 | + &dev_attr_hpb_subregion_size.attr, |
|---|
| 678 | + &dev_attr_hpb_max_active_regions.attr, |
|---|
| 679 | + &dev_attr_wb_max_alloc_units.attr, |
|---|
| 680 | + &dev_attr_wb_max_wb_luns.attr, |
|---|
| 681 | + &dev_attr_wb_buff_cap_adj.attr, |
|---|
| 682 | + &dev_attr_wb_sup_red_type.attr, |
|---|
| 683 | + &dev_attr_wb_sup_wb_type.attr, |
|---|
| 422 | 684 | NULL, |
|---|
| 423 | 685 | }; |
|---|
| 424 | 686 | |
|---|
| .. | .. |
|---|
| 571 | 833 | int ret; \ |
|---|
| 572 | 834 | int desc_len = QUERY_DESC_MAX_SIZE; \ |
|---|
| 573 | 835 | u8 *desc_buf; \ |
|---|
| 836 | + \ |
|---|
| 574 | 837 | desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_ATOMIC); \ |
|---|
| 575 | | - if (!desc_buf) \ |
|---|
| 576 | | - return -ENOMEM; \ |
|---|
| 838 | + if (!desc_buf) \ |
|---|
| 839 | + return -ENOMEM; \ |
|---|
| 840 | + pm_runtime_get_sync(hba->dev); \ |
|---|
| 577 | 841 | ret = ufshcd_query_descriptor_retry(hba, \ |
|---|
| 578 | 842 | UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_DEVICE, \ |
|---|
| 579 | 843 | 0, 0, desc_buf, &desc_len); \ |
|---|
| .. | .. |
|---|
| 582 | 846 | goto out; \ |
|---|
| 583 | 847 | } \ |
|---|
| 584 | 848 | index = desc_buf[DEVICE_DESC_PARAM##_pname]; \ |
|---|
| 585 | | - memset(desc_buf, 0, QUERY_DESC_MAX_SIZE); \ |
|---|
| 586 | | - if (ufshcd_read_string_desc(hba, index, desc_buf, \ |
|---|
| 587 | | - QUERY_DESC_MAX_SIZE, true)) { \ |
|---|
| 588 | | - ret = -EINVAL; \ |
|---|
| 849 | + kfree(desc_buf); \ |
|---|
| 850 | + desc_buf = NULL; \ |
|---|
| 851 | + ret = ufshcd_read_string_desc(hba, index, &desc_buf, \ |
|---|
| 852 | + SD_ASCII_STD); \ |
|---|
| 853 | + if (ret < 0) \ |
|---|
| 589 | 854 | goto out; \ |
|---|
| 590 | | - } \ |
|---|
| 591 | | - ret = snprintf(buf, PAGE_SIZE, "%s\n", \ |
|---|
| 592 | | - desc_buf + QUERY_DESC_HDR_SIZE); \ |
|---|
| 855 | + ret = sysfs_emit(buf, "%s\n", desc_buf); \ |
|---|
| 593 | 856 | out: \ |
|---|
| 857 | + pm_runtime_put_sync(hba->dev); \ |
|---|
| 594 | 858 | kfree(desc_buf); \ |
|---|
| 595 | 859 | return ret; \ |
|---|
| 596 | 860 | } \ |
|---|
| .. | .. |
|---|
| 616 | 880 | .attrs = ufs_sysfs_string_descriptors, |
|---|
| 617 | 881 | }; |
|---|
| 618 | 882 | |
|---|
| 883 | +static inline bool ufshcd_is_wb_flags(enum flag_idn idn) |
|---|
| 884 | +{ |
|---|
| 885 | + return ((idn >= QUERY_FLAG_IDN_WB_EN) && |
|---|
| 886 | + (idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8)); |
|---|
| 887 | +} |
|---|
| 888 | + |
|---|
| 619 | 889 | #define UFS_FLAG(_name, _uname) \ |
|---|
| 620 | 890 | static ssize_t _name##_show(struct device *dev, \ |
|---|
| 621 | 891 | struct device_attribute *attr, char *buf) \ |
|---|
| 622 | 892 | { \ |
|---|
| 623 | 893 | bool flag; \ |
|---|
| 894 | + u8 index = 0; \ |
|---|
| 895 | + int ret; \ |
|---|
| 624 | 896 | struct ufs_hba *hba = dev_get_drvdata(dev); \ |
|---|
| 625 | | - if (ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \ |
|---|
| 626 | | - QUERY_FLAG_IDN##_uname, &flag)) \ |
|---|
| 897 | + if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname)) \ |
|---|
| 898 | + index = ufshcd_wb_get_query_index(hba); \ |
|---|
| 899 | + pm_runtime_get_sync(hba->dev); \ |
|---|
| 900 | + ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \ |
|---|
| 901 | + QUERY_FLAG_IDN##_uname, index, &flag); \ |
|---|
| 902 | + pm_runtime_put_sync(hba->dev); \ |
|---|
| 903 | + if (ret) \ |
|---|
| 627 | 904 | return -EINVAL; \ |
|---|
| 628 | | - return sprintf(buf, "%s\n", flag ? "true" : "false"); \ |
|---|
| 905 | + return sysfs_emit(buf, "%s\n", flag ? "true" : "false"); \ |
|---|
| 629 | 906 | } \ |
|---|
| 630 | 907 | static DEVICE_ATTR_RO(_name) |
|---|
| 631 | 908 | |
|---|
| .. | .. |
|---|
| 637 | 914 | UFS_FLAG(phy_resource_removal, _FPHYRESOURCEREMOVAL); |
|---|
| 638 | 915 | UFS_FLAG(busy_rtc, _BUSY_RTC); |
|---|
| 639 | 916 | UFS_FLAG(disable_fw_update, _PERMANENTLY_DISABLE_FW_UPDATE); |
|---|
| 917 | +UFS_FLAG(wb_enable, _WB_EN); |
|---|
| 918 | +UFS_FLAG(wb_flush_en, _WB_BUFF_FLUSH_EN); |
|---|
| 919 | +UFS_FLAG(wb_flush_during_h8, _WB_BUFF_FLUSH_DURING_HIBERN8); |
|---|
| 920 | +UFS_FLAG(hpb_enable, _HPB_EN); |
|---|
| 640 | 921 | |
|---|
| 641 | 922 | static struct attribute *ufs_sysfs_device_flags[] = { |
|---|
| 642 | 923 | &dev_attr_device_init.attr, |
|---|
| .. | .. |
|---|
| 647 | 928 | &dev_attr_phy_resource_removal.attr, |
|---|
| 648 | 929 | &dev_attr_busy_rtc.attr, |
|---|
| 649 | 930 | &dev_attr_disable_fw_update.attr, |
|---|
| 931 | + &dev_attr_wb_enable.attr, |
|---|
| 932 | + &dev_attr_wb_flush_en.attr, |
|---|
| 933 | + &dev_attr_wb_flush_during_h8.attr, |
|---|
| 934 | + &dev_attr_hpb_enable.attr, |
|---|
| 650 | 935 | NULL, |
|---|
| 651 | 936 | }; |
|---|
| 652 | 937 | |
|---|
| .. | .. |
|---|
| 655 | 940 | .attrs = ufs_sysfs_device_flags, |
|---|
| 656 | 941 | }; |
|---|
| 657 | 942 | |
|---|
| 943 | +static inline bool ufshcd_is_wb_attrs(enum attr_idn idn) |
|---|
| 944 | +{ |
|---|
| 945 | + return ((idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS) && |
|---|
| 946 | + (idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE)); |
|---|
| 947 | +} |
|---|
| 948 | + |
|---|
| 658 | 949 | #define UFS_ATTRIBUTE(_name, _uname) \ |
|---|
| 659 | 950 | static ssize_t _name##_show(struct device *dev, \ |
|---|
| 660 | 951 | struct device_attribute *attr, char *buf) \ |
|---|
| 661 | 952 | { \ |
|---|
| 662 | 953 | struct ufs_hba *hba = dev_get_drvdata(dev); \ |
|---|
| 663 | 954 | u32 value; \ |
|---|
| 664 | | - if (ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, \ |
|---|
| 665 | | - QUERY_ATTR_IDN##_uname, 0, 0, &value)) \ |
|---|
| 955 | + int ret; \ |
|---|
| 956 | + u8 index = 0; \ |
|---|
| 957 | + if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname)) \ |
|---|
| 958 | + index = ufshcd_wb_get_query_index(hba); \ |
|---|
| 959 | + pm_runtime_get_sync(hba->dev); \ |
|---|
| 960 | + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, \ |
|---|
| 961 | + QUERY_ATTR_IDN##_uname, index, 0, &value); \ |
|---|
| 962 | + pm_runtime_put_sync(hba->dev); \ |
|---|
| 963 | + if (ret) \ |
|---|
| 666 | 964 | return -EINVAL; \ |
|---|
| 667 | | - return sprintf(buf, "0x%08X\n", value); \ |
|---|
| 965 | + return sysfs_emit(buf, "0x%08X\n", value); \ |
|---|
| 668 | 966 | } \ |
|---|
| 669 | 967 | static DEVICE_ATTR_RO(_name) |
|---|
| 670 | 968 | |
|---|
| 671 | 969 | UFS_ATTRIBUTE(boot_lun_enabled, _BOOT_LU_EN); |
|---|
| 970 | +UFS_ATTRIBUTE(max_data_size_hpb_single_cmd, _MAX_HPB_SINGLE_CMD); |
|---|
| 672 | 971 | UFS_ATTRIBUTE(current_power_mode, _POWER_MODE); |
|---|
| 673 | 972 | UFS_ATTRIBUTE(active_icc_level, _ACTIVE_ICC_LVL); |
|---|
| 674 | 973 | UFS_ATTRIBUTE(ooo_data_enabled, _OOO_DATA_EN); |
|---|
| .. | .. |
|---|
| 684 | 983 | UFS_ATTRIBUTE(ffu_status, _FFU_STATUS); |
|---|
| 685 | 984 | UFS_ATTRIBUTE(psa_state, _PSA_STATE); |
|---|
| 686 | 985 | UFS_ATTRIBUTE(psa_data_size, _PSA_DATA_SIZE); |
|---|
| 986 | +UFS_ATTRIBUTE(wb_flush_status, _WB_FLUSH_STATUS); |
|---|
| 987 | +UFS_ATTRIBUTE(wb_avail_buf, _AVAIL_WB_BUFF_SIZE); |
|---|
| 988 | +UFS_ATTRIBUTE(wb_life_time_est, _WB_BUFF_LIFE_TIME_EST); |
|---|
| 989 | +UFS_ATTRIBUTE(wb_cur_buf, _CURR_WB_BUFF_SIZE); |
|---|
| 990 | + |
|---|
| 687 | 991 | |
|---|
| 688 | 992 | static struct attribute *ufs_sysfs_attributes[] = { |
|---|
| 689 | 993 | &dev_attr_boot_lun_enabled.attr, |
|---|
| 994 | + &dev_attr_max_data_size_hpb_single_cmd.attr, |
|---|
| 690 | 995 | &dev_attr_current_power_mode.attr, |
|---|
| 691 | 996 | &dev_attr_active_icc_level.attr, |
|---|
| 692 | 997 | &dev_attr_ooo_data_enabled.attr, |
|---|
| .. | .. |
|---|
| 702 | 1007 | &dev_attr_ffu_status.attr, |
|---|
| 703 | 1008 | &dev_attr_psa_state.attr, |
|---|
| 704 | 1009 | &dev_attr_psa_data_size.attr, |
|---|
| 1010 | + &dev_attr_wb_flush_status.attr, |
|---|
| 1011 | + &dev_attr_wb_avail_buf.attr, |
|---|
| 1012 | + &dev_attr_wb_life_time_est.attr, |
|---|
| 1013 | + &dev_attr_wb_cur_buf.attr, |
|---|
| 705 | 1014 | NULL, |
|---|
| 706 | 1015 | }; |
|---|
| 707 | 1016 | |
|---|
| .. | .. |
|---|
| 712 | 1021 | |
|---|
| 713 | 1022 | static const struct attribute_group *ufs_sysfs_groups[] = { |
|---|
| 714 | 1023 | &ufs_sysfs_default_group, |
|---|
| 1024 | + &ufs_sysfs_monitor_group, |
|---|
| 715 | 1025 | &ufs_sysfs_device_descriptor_group, |
|---|
| 716 | 1026 | &ufs_sysfs_interconnect_descriptor_group, |
|---|
| 717 | 1027 | &ufs_sysfs_geometry_descriptor_group, |
|---|
| .. | .. |
|---|
| 730 | 1040 | struct scsi_device *sdev = to_scsi_device(dev); \ |
|---|
| 731 | 1041 | struct ufs_hba *hba = shost_priv(sdev->host); \ |
|---|
| 732 | 1042 | u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun); \ |
|---|
| 733 | | - if (!ufs_is_valid_unit_desc_lun(lun)) \ |
|---|
| 1043 | + if (!ufs_is_valid_unit_desc_lun(&hba->dev_info, lun, \ |
|---|
| 1044 | + _duname##_DESC_PARAM##_puname)) \ |
|---|
| 734 | 1045 | return -EINVAL; \ |
|---|
| 735 | 1046 | return ufs_sysfs_read_desc_param(hba, QUERY_DESC_IDN_##_duname, \ |
|---|
| 736 | 1047 | lun, _duname##_DESC_PARAM##_puname, buf, _size); \ |
|---|
| .. | .. |
|---|
| 753 | 1064 | UFS_UNIT_DESC_PARAM(physical_memory_resourse_count, _PHY_MEM_RSRC_CNT, 8); |
|---|
| 754 | 1065 | UFS_UNIT_DESC_PARAM(context_capabilities, _CTX_CAPABILITIES, 2); |
|---|
| 755 | 1066 | UFS_UNIT_DESC_PARAM(large_unit_granularity, _LARGE_UNIT_SIZE_M1, 1); |
|---|
| 1067 | +UFS_UNIT_DESC_PARAM(hpb_lu_max_active_regions, _HPB_LU_MAX_ACTIVE_RGNS, 2); |
|---|
| 1068 | +UFS_UNIT_DESC_PARAM(hpb_pinned_region_start_offset, _HPB_PIN_RGN_START_OFF, 2); |
|---|
| 1069 | +UFS_UNIT_DESC_PARAM(hpb_number_pinned_regions, _HPB_NUM_PIN_RGNS, 2); |
|---|
| 1070 | +UFS_UNIT_DESC_PARAM(wb_buf_alloc_units, _WB_BUF_ALLOC_UNITS, 4); |
|---|
| 1071 | + |
|---|
| 756 | 1072 | |
|---|
| 757 | 1073 | static struct attribute *ufs_sysfs_unit_descriptor[] = { |
|---|
| 758 | 1074 | &dev_attr_boot_lun_id.attr, |
|---|
| .. | .. |
|---|
| 768 | 1084 | &dev_attr_physical_memory_resourse_count.attr, |
|---|
| 769 | 1085 | &dev_attr_context_capabilities.attr, |
|---|
| 770 | 1086 | &dev_attr_large_unit_granularity.attr, |
|---|
| 1087 | + &dev_attr_hpb_lu_max_active_regions.attr, |
|---|
| 1088 | + &dev_attr_hpb_pinned_region_start_offset.attr, |
|---|
| 1089 | + &dev_attr_hpb_number_pinned_regions.attr, |
|---|
| 1090 | + &dev_attr_wb_buf_alloc_units.attr, |
|---|
| 771 | 1091 | NULL, |
|---|
| 772 | 1092 | }; |
|---|
| 773 | 1093 | |
|---|
| .. | .. |
|---|
| 783 | 1103 | struct scsi_device *sdev = to_scsi_device(dev); |
|---|
| 784 | 1104 | struct ufs_hba *hba = shost_priv(sdev->host); |
|---|
| 785 | 1105 | u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun); |
|---|
| 1106 | + int ret; |
|---|
| 786 | 1107 | |
|---|
| 787 | | - if (ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, |
|---|
| 788 | | - QUERY_ATTR_IDN_DYN_CAP_NEEDED, lun, 0, &value)) |
|---|
| 1108 | + pm_runtime_get_sync(hba->dev); |
|---|
| 1109 | + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, |
|---|
| 1110 | + QUERY_ATTR_IDN_DYN_CAP_NEEDED, lun, 0, &value); |
|---|
| 1111 | + pm_runtime_put_sync(hba->dev); |
|---|
| 1112 | + if (ret) |
|---|
| 789 | 1113 | return -EINVAL; |
|---|
| 790 | | - return sprintf(buf, "0x%08X\n", value); |
|---|
| 1114 | + return sysfs_emit(buf, "0x%08X\n", value); |
|---|
| 791 | 1115 | } |
|---|
| 792 | 1116 | static DEVICE_ATTR_RO(dyn_cap_needed_attribute); |
|---|
| 793 | 1117 | |
|---|
| .. | .. |
|---|
| 800 | 1124 | .attrs = ufs_sysfs_lun_attributes, |
|---|
| 801 | 1125 | }; |
|---|
| 802 | 1126 | |
|---|
| 803 | | -void ufs_sysfs_add_nodes(struct device *dev) |
|---|
| 1127 | +void ufs_sysfs_add_nodes(struct ufs_hba *hba) |
|---|
| 804 | 1128 | { |
|---|
| 805 | 1129 | int ret; |
|---|
| 806 | 1130 | |
|---|
| 807 | | - ret = sysfs_create_groups(&dev->kobj, ufs_sysfs_groups); |
|---|
| 808 | | - if (ret) |
|---|
| 809 | | - dev_err(dev, |
|---|
| 1131 | + ret = sysfs_create_groups(&hba->dev->kobj, ufs_sysfs_groups); |
|---|
| 1132 | + if (ret) { |
|---|
| 1133 | + dev_err(hba->dev, |
|---|
| 810 | 1134 | "%s: sysfs groups creation failed (err = %d)\n", |
|---|
| 811 | 1135 | __func__, ret); |
|---|
| 1136 | + return; |
|---|
| 1137 | + } |
|---|
| 1138 | + |
|---|
| 1139 | + trace_android_vh_ufs_update_sysfs(hba); |
|---|
| 812 | 1140 | } |
|---|
| 813 | 1141 | |
|---|
| 814 | 1142 | void ufs_sysfs_remove_nodes(struct device *dev) |
|---|