pci_event.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 = NULL;
  45. zpci_err("error CCDF:\n");
  46. zpci_err_hex(ccdf, sizeof(*ccdf));
  47. if (zdev)
  48. pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN);
  49. pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
  50. pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
  51. if (!pdev)
  52. return;
  53. pdev->error_state = pci_channel_io_perm_failure;
  54. pci_dev_put(pdev);
  55. }
  56. void zpci_event_error(void *data)
  57. {
  58. if (zpci_is_enabled())
  59. __zpci_event_error(data);
  60. }
  61. static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
  62. {
  63. struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
  64. struct pci_dev *pdev = NULL;
  65. int ret;
  66. if (zdev)
  67. pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN);
  68. pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n",
  69. pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
  70. zpci_err("avail CCDF:\n");
  71. zpci_err_hex(ccdf, sizeof(*ccdf));
  72. switch (ccdf->pec) {
  73. case 0x0301: /* Reserved|Standby -> Configured */
  74. if (!zdev) {
  75. ret = clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
  76. if (ret)
  77. break;
  78. zdev = get_zdev_by_fid(ccdf->fid);
  79. }
  80. if (!zdev || zdev->state != ZPCI_FN_STATE_STANDBY)
  81. break;
  82. zdev->state = ZPCI_FN_STATE_CONFIGURED;
  83. zdev->fh = ccdf->fh;
  84. ret = zpci_enable_device(zdev);
  85. if (ret)
  86. break;
  87. pci_lock_rescan_remove();
  88. pci_rescan_bus(zdev->bus);
  89. pci_unlock_rescan_remove();
  90. break;
  91. case 0x0302: /* Reserved -> Standby */
  92. if (!zdev)
  93. clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
  94. break;
  95. case 0x0303: /* Deconfiguration requested */
  96. if (pdev)
  97. pci_stop_and_remove_bus_device_locked(pdev);
  98. ret = zpci_disable_device(zdev);
  99. if (ret)
  100. break;
  101. ret = sclp_pci_deconfigure(zdev->fid);
  102. zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
  103. if (!ret)
  104. zdev->state = ZPCI_FN_STATE_STANDBY;
  105. break;
  106. case 0x0304: /* Configured -> Standby */
  107. if (pdev) {
  108. /* Give the driver a hint that the function is
  109. * already unusable. */
  110. pdev->error_state = pci_channel_io_perm_failure;
  111. pci_stop_and_remove_bus_device_locked(pdev);
  112. }
  113. zdev->fh = ccdf->fh;
  114. zpci_disable_device(zdev);
  115. zdev->state = ZPCI_FN_STATE_STANDBY;
  116. break;
  117. case 0x0306: /* 0x308 or 0x302 for multiple devices */
  118. clp_rescan_pci_devices();
  119. break;
  120. case 0x0308: /* Standby -> Reserved */
  121. if (!zdev)
  122. break;
  123. pci_stop_root_bus(zdev->bus);
  124. pci_remove_root_bus(zdev->bus);
  125. break;
  126. default:
  127. break;
  128. }
  129. pci_dev_put(pdev);
  130. }
  131. void zpci_event_availability(void *data)
  132. {
  133. if (zpci_is_enabled())
  134. __zpci_event_availability(data);
  135. }