pci_event.c 3.2 KB

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