pci_sysfs.c 2.7 KB

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