pci_event.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/pci.h>
  11. #include <asm/pci_debug.h>
  12. #include <asm/sclp.h>
  13. /* Content Code Description for PCI Function Error */
  14. struct zpci_ccdf_err {
  15. u32 reserved1;
  16. u32 fh; /* function handle */
  17. u32 fid; /* function id */
  18. u32 ett : 4; /* expected table type */
  19. u32 mvn : 12; /* MSI vector number */
  20. u32 dmaas : 8; /* DMA address space */
  21. u32 : 6;
  22. u32 q : 1; /* event qualifier */
  23. u32 rw : 1; /* read/write */
  24. u64 faddr; /* failing address */
  25. u32 reserved3;
  26. u16 reserved4;
  27. u16 pec; /* PCI event code */
  28. } __packed;
  29. /* Content Code Description for PCI Function Availability */
  30. struct zpci_ccdf_avail {
  31. u32 reserved1;
  32. u32 fh; /* function handle */
  33. u32 fid; /* function id */
  34. u32 reserved2;
  35. u32 reserved3;
  36. u32 reserved4;
  37. u32 reserved5;
  38. u16 reserved6;
  39. u16 pec; /* PCI event code */
  40. } __packed;
  41. static void __zpci_event_error(struct zpci_ccdf_err *ccdf)
  42. {
  43. struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
  44. struct pci_dev *pdev = zdev ? zdev->pdev : NULL;
  45. zpci_err("error CCDF:\n");
  46. zpci_err_hex(ccdf, sizeof(*ccdf));
  47. pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
  48. pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
  49. }
  50. void zpci_event_error(void *data)
  51. {
  52. if (zpci_is_enabled())
  53. __zpci_event_error(data);
  54. }
  55. static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
  56. {
  57. struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
  58. struct pci_dev *pdev = zdev ? zdev->pdev : NULL;
  59. int ret;
  60. pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n",
  61. pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
  62. zpci_err("avail CCDF:\n");
  63. zpci_err_hex(ccdf, sizeof(*ccdf));
  64. switch (ccdf->pec) {
  65. case 0x0301: /* Reserved|Standby -> Configured */
  66. if (!zdev) {
  67. ret = clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
  68. if (ret)
  69. break;
  70. zdev = get_zdev_by_fid(ccdf->fid);
  71. }
  72. if (!zdev || zdev->state != ZPCI_FN_STATE_STANDBY)
  73. break;
  74. zdev->state = ZPCI_FN_STATE_CONFIGURED;
  75. zdev->fh = ccdf->fh;
  76. ret = zpci_enable_device(zdev);
  77. if (ret)
  78. break;
  79. pci_lock_rescan_remove();
  80. pci_rescan_bus(zdev->bus);
  81. pci_unlock_rescan_remove();
  82. break;
  83. case 0x0302: /* Reserved -> Standby */
  84. if (!zdev)
  85. clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
  86. break;
  87. case 0x0303: /* Deconfiguration requested */
  88. if (pdev)
  89. pci_stop_and_remove_bus_device_locked(pdev);
  90. ret = zpci_disable_device(zdev);
  91. if (ret)
  92. break;
  93. ret = sclp_pci_deconfigure(zdev->fid);
  94. zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
  95. if (!ret)
  96. zdev->state = ZPCI_FN_STATE_STANDBY;
  97. break;
  98. case 0x0304: /* Configured -> Standby */
  99. if (pdev) {
  100. /* Give the driver a hint that the function is
  101. * already unusable. */
  102. pdev->error_state = pci_channel_io_perm_failure;
  103. pci_stop_and_remove_bus_device_locked(pdev);
  104. }
  105. zdev->fh = ccdf->fh;
  106. zpci_disable_device(zdev);
  107. zdev->state = ZPCI_FN_STATE_STANDBY;
  108. break;
  109. case 0x0306: /* 0x308 or 0x302 for multiple devices */
  110. clp_rescan_pci_devices();
  111. break;
  112. case 0x0308: /* Standby -> Reserved */
  113. if (!zdev)
  114. break;
  115. pci_stop_root_bus(zdev->bus);
  116. pci_remove_root_bus(zdev->bus);
  117. break;
  118. default:
  119. break;
  120. }
  121. }
  122. void zpci_event_availability(void *data)
  123. {
  124. if (zpci_is_enabled())
  125. __zpci_event_availability(data);
  126. }