pci_sysfs.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2012
  4. *
  5. * Author(s):
  6. * Jan Glauber <jang@linux.vnet.ibm.com>
  7. */
  8. #define KMSG_COMPONENT "zpci"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/kernel.h>
  11. #include <linux/stat.h>
  12. #include <linux/pci.h>
  13. #include <asm/sclp.h>
  14. #define zpci_attr(name, fmt, member) \
  15. static ssize_t name##_show(struct device *dev, \
  16. struct device_attribute *attr, char *buf) \
  17. { \
  18. struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); \
  19. \
  20. return sprintf(buf, fmt, zdev->member); \
  21. } \
  22. static DEVICE_ATTR_RO(name)
  23. zpci_attr(function_id, "0x%08x\n", fid);
  24. zpci_attr(function_handle, "0x%08x\n", fh);
  25. zpci_attr(pchid, "0x%04x\n", pchid);
  26. zpci_attr(pfgid, "0x%02x\n", pfgid);
  27. zpci_attr(vfn, "0x%04x\n", vfn);
  28. zpci_attr(pft, "0x%02x\n", pft);
  29. zpci_attr(uid, "0x%x\n", uid);
  30. zpci_attr(segment0, "0x%02x\n", pfip[0]);
  31. zpci_attr(segment1, "0x%02x\n", pfip[1]);
  32. zpci_attr(segment2, "0x%02x\n", pfip[2]);
  33. zpci_attr(segment3, "0x%02x\n", pfip[3]);
  34. static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
  35. const char *buf, size_t count)
  36. {
  37. struct pci_dev *pdev = to_pci_dev(dev);
  38. struct zpci_dev *zdev = to_zpci(pdev);
  39. int ret;
  40. if (!device_remove_file_self(dev, attr))
  41. return count;
  42. pci_lock_rescan_remove();
  43. pci_stop_and_remove_bus_device(pdev);
  44. ret = zpci_disable_device(zdev);
  45. if (ret)
  46. goto error;
  47. ret = zpci_enable_device(zdev);
  48. if (ret)
  49. goto error;
  50. pci_rescan_bus(zdev->bus);
  51. pci_unlock_rescan_remove();
  52. return count;
  53. error:
  54. pci_unlock_rescan_remove();
  55. return ret;
  56. }
  57. static DEVICE_ATTR_WO(recover);
  58. static ssize_t util_string_read(struct file *filp, struct kobject *kobj,
  59. struct bin_attribute *attr, char *buf,
  60. loff_t off, size_t count)
  61. {
  62. struct device *dev = kobj_to_dev(kobj);
  63. struct pci_dev *pdev = to_pci_dev(dev);
  64. struct zpci_dev *zdev = to_zpci(pdev);
  65. return memory_read_from_buffer(buf, count, &off, zdev->util_str,
  66. sizeof(zdev->util_str));
  67. }
  68. static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN);
  69. static ssize_t report_error_write(struct file *filp, struct kobject *kobj,
  70. struct bin_attribute *attr, char *buf,
  71. loff_t off, size_t count)
  72. {
  73. struct zpci_report_error_header *report = (void *) buf;
  74. struct device *dev = kobj_to_dev(kobj);
  75. struct pci_dev *pdev = to_pci_dev(dev);
  76. struct zpci_dev *zdev = to_zpci(pdev);
  77. int ret;
  78. if (off || (count < sizeof(*report)))
  79. return -EINVAL;
  80. ret = sclp_pci_report(report, zdev->fh, zdev->fid);
  81. return ret ? ret : count;
  82. }
  83. static BIN_ATTR(report_error, S_IWUSR, NULL, report_error_write, PAGE_SIZE);
  84. static struct bin_attribute *zpci_bin_attrs[] = {
  85. &bin_attr_util_string,
  86. &bin_attr_report_error,
  87. NULL,
  88. };
  89. static struct attribute *zpci_dev_attrs[] = {
  90. &dev_attr_function_id.attr,
  91. &dev_attr_function_handle.attr,
  92. &dev_attr_pchid.attr,
  93. &dev_attr_pfgid.attr,
  94. &dev_attr_pft.attr,
  95. &dev_attr_vfn.attr,
  96. &dev_attr_uid.attr,
  97. &dev_attr_recover.attr,
  98. NULL,
  99. };
  100. static struct attribute_group zpci_attr_group = {
  101. .attrs = zpci_dev_attrs,
  102. .bin_attrs = zpci_bin_attrs,
  103. };
  104. static struct attribute *pfip_attrs[] = {
  105. &dev_attr_segment0.attr,
  106. &dev_attr_segment1.attr,
  107. &dev_attr_segment2.attr,
  108. &dev_attr_segment3.attr,
  109. NULL,
  110. };
  111. static struct attribute_group pfip_attr_group = {
  112. .name = "pfip",
  113. .attrs = pfip_attrs,
  114. };
  115. const struct attribute_group *zpci_attr_groups[] = {
  116. &zpci_attr_group,
  117. &pfip_attr_group,
  118. NULL,
  119. };