pci_sysfs.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 = get_zdev(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 = get_zdev(pdev);
  37. int ret;
  38. if (!device_remove_file_self(dev, attr))
  39. return count;
  40. pci_stop_and_remove_bus_device(pdev);
  41. ret = zpci_disable_device(zdev);
  42. if (ret)
  43. return ret;
  44. ret = zpci_enable_device(zdev);
  45. if (ret)
  46. return ret;
  47. pci_rescan_bus(zdev->bus);
  48. return count;
  49. }
  50. static DEVICE_ATTR_WO(recover);
  51. static ssize_t util_string_read(struct file *filp, struct kobject *kobj,
  52. struct bin_attribute *attr, char *buf,
  53. loff_t off, size_t count)
  54. {
  55. struct device *dev = kobj_to_dev(kobj);
  56. struct pci_dev *pdev = to_pci_dev(dev);
  57. struct zpci_dev *zdev = get_zdev(pdev);
  58. return memory_read_from_buffer(buf, count, &off, zdev->util_str,
  59. sizeof(zdev->util_str));
  60. }
  61. static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN);
  62. static struct bin_attribute *zpci_bin_attrs[] = {
  63. &bin_attr_util_string,
  64. NULL,
  65. };
  66. static struct attribute *zpci_dev_attrs[] = {
  67. &dev_attr_function_id.attr,
  68. &dev_attr_function_handle.attr,
  69. &dev_attr_pchid.attr,
  70. &dev_attr_pfgid.attr,
  71. &dev_attr_pft.attr,
  72. &dev_attr_vfn.attr,
  73. &dev_attr_uid.attr,
  74. &dev_attr_recover.attr,
  75. NULL,
  76. };
  77. static struct attribute_group zpci_attr_group = {
  78. .attrs = zpci_dev_attrs,
  79. .bin_attrs = zpci_bin_attrs,
  80. };
  81. static struct attribute *pfip_attrs[] = {
  82. &dev_attr_segment0.attr,
  83. &dev_attr_segment1.attr,
  84. &dev_attr_segment2.attr,
  85. &dev_attr_segment3.attr,
  86. NULL,
  87. };
  88. static struct attribute_group pfip_attr_group = {
  89. .name = "pfip",
  90. .attrs = pfip_attrs,
  91. };
  92. const struct attribute_group *zpci_attr_groups[] = {
  93. &zpci_attr_group,
  94. &pfip_attr_group,
  95. NULL,
  96. };