Jan Glauber | cbc0dd1 | 2012-11-29 14:34:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright IBM Corp. 2012 |
| 3 | * |
| 4 | * Author(s): |
| 5 | * Jan Glauber <jang@linux.vnet.ibm.com> |
| 6 | */ |
| 7 | |
Gerald Schaefer | 896cb7e | 2014-07-16 17:21:01 +0200 | [diff] [blame] | 8 | #define KMSG_COMPONENT "zpci" |
| 9 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
Jan Glauber | cbc0dd1 | 2012-11-29 14:34:48 +0100 | [diff] [blame] | 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/pci.h> |
Sebastian Ott | 1f1dcbd | 2013-10-22 15:17:19 +0200 | [diff] [blame] | 13 | #include <asm/pci_debug.h> |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 14 | #include <asm/sclp.h> |
Jan Glauber | cbc0dd1 | 2012-11-29 14:34:48 +0100 | [diff] [blame] | 15 | |
| 16 | /* Content Code Description for PCI Function Error */ |
| 17 | struct zpci_ccdf_err { |
| 18 | u32 reserved1; |
| 19 | u32 fh; /* function handle */ |
| 20 | u32 fid; /* function id */ |
| 21 | u32 ett : 4; /* expected table type */ |
| 22 | u32 mvn : 12; /* MSI vector number */ |
| 23 | u32 dmaas : 8; /* DMA address space */ |
| 24 | u32 : 6; |
| 25 | u32 q : 1; /* event qualifier */ |
| 26 | u32 rw : 1; /* read/write */ |
| 27 | u64 faddr; /* failing address */ |
| 28 | u32 reserved3; |
| 29 | u16 reserved4; |
| 30 | u16 pec; /* PCI event code */ |
| 31 | } __packed; |
| 32 | |
| 33 | /* Content Code Description for PCI Function Availability */ |
| 34 | struct zpci_ccdf_avail { |
| 35 | u32 reserved1; |
| 36 | u32 fh; /* function handle */ |
| 37 | u32 fid; /* function id */ |
| 38 | u32 reserved2; |
| 39 | u32 reserved3; |
| 40 | u32 reserved4; |
| 41 | u32 reserved5; |
| 42 | u16 reserved6; |
| 43 | u16 pec; /* PCI event code */ |
| 44 | } __packed; |
| 45 | |
Sebastian Ott | aa3b7c2 | 2013-12-12 17:48:32 +0100 | [diff] [blame] | 46 | static void __zpci_event_error(struct zpci_ccdf_err *ccdf) |
Jan Glauber | cbc0dd1 | 2012-11-29 14:34:48 +0100 | [diff] [blame] | 47 | { |
Sebastian Ott | 1f1dcbd | 2013-10-22 15:17:19 +0200 | [diff] [blame] | 48 | struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid); |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 49 | struct pci_dev *pdev = NULL; |
Jan Glauber | cbc0dd1 | 2012-11-29 14:34:48 +0100 | [diff] [blame] | 50 | |
Sebastian Ott | 1f1dcbd | 2013-10-22 15:17:19 +0200 | [diff] [blame] | 51 | zpci_err("error CCDF:\n"); |
| 52 | zpci_err_hex(ccdf, sizeof(*ccdf)); |
| 53 | |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 54 | if (zdev) |
| 55 | pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN); |
| 56 | |
Sebastian Ott | 1f1dcbd | 2013-10-22 15:17:19 +0200 | [diff] [blame] | 57 | pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n", |
Sebastian Ott | 515f022 | 2015-07-28 19:11:40 +0200 | [diff] [blame] | 58 | pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid); |
Sebastian Ott | 8ead7ef | 2016-01-22 14:04:18 +0100 | [diff] [blame] | 59 | |
| 60 | if (!pdev) |
| 61 | return; |
| 62 | |
| 63 | pdev->error_state = pci_channel_io_perm_failure; |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 64 | pci_dev_put(pdev); |
Jan Glauber | cbc0dd1 | 2012-11-29 14:34:48 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Sebastian Ott | aa3b7c2 | 2013-12-12 17:48:32 +0100 | [diff] [blame] | 67 | void zpci_event_error(void *data) |
Jan Glauber | cbc0dd1 | 2012-11-29 14:34:48 +0100 | [diff] [blame] | 68 | { |
Sebastian Ott | aa3b7c2 | 2013-12-12 17:48:32 +0100 | [diff] [blame] | 69 | if (zpci_is_enabled()) |
| 70 | __zpci_event_error(data); |
| 71 | } |
| 72 | |
| 73 | static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf) |
| 74 | { |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 75 | struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid); |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 76 | struct pci_dev *pdev = NULL; |
Sebastian Ott | 623bd44 | 2017-05-09 12:27:30 +0200 | [diff] [blame] | 77 | enum zpci_state state; |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 78 | int ret; |
| 79 | |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 80 | if (zdev) |
| 81 | pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN); |
| 82 | |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 83 | pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n", |
| 84 | pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid); |
| 85 | zpci_err("avail CCDF:\n"); |
| 86 | zpci_err_hex(ccdf, sizeof(*ccdf)); |
| 87 | |
| 88 | switch (ccdf->pec) { |
Sebastian Ott | 7fc611f | 2015-06-16 18:58:37 +0200 | [diff] [blame] | 89 | case 0x0301: /* Reserved|Standby -> Configured */ |
| 90 | if (!zdev) { |
| 91 | ret = clp_add_pci_device(ccdf->fid, ccdf->fh, 0); |
| 92 | if (ret) |
| 93 | break; |
| 94 | zdev = get_zdev_by_fid(ccdf->fid); |
| 95 | } |
Sebastian Ott | ca25f56 | 2014-04-16 16:09:23 +0200 | [diff] [blame] | 96 | if (!zdev || zdev->state != ZPCI_FN_STATE_STANDBY) |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 97 | break; |
| 98 | zdev->state = ZPCI_FN_STATE_CONFIGURED; |
Sebastian Ott | fcf2f40 | 2013-12-18 16:46:02 +0100 | [diff] [blame] | 99 | zdev->fh = ccdf->fh; |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 100 | ret = zpci_enable_device(zdev); |
| 101 | if (ret) |
| 102 | break; |
Sebastian Ott | 2a01bd1 | 2015-07-28 19:14:51 +0200 | [diff] [blame] | 103 | pci_lock_rescan_remove(); |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 104 | pci_rescan_bus(zdev->bus); |
Sebastian Ott | 2a01bd1 | 2015-07-28 19:14:51 +0200 | [diff] [blame] | 105 | pci_unlock_rescan_remove(); |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 106 | break; |
| 107 | case 0x0302: /* Reserved -> Standby */ |
Sebastian Ott | ca25f56 | 2014-04-16 16:09:23 +0200 | [diff] [blame] | 108 | if (!zdev) |
| 109 | clp_add_pci_device(ccdf->fid, ccdf->fh, 0); |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 110 | break; |
| 111 | case 0x0303: /* Deconfiguration requested */ |
Sebastian Ott | 623bd44 | 2017-05-09 12:27:30 +0200 | [diff] [blame] | 112 | if (!zdev) |
| 113 | break; |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 114 | if (pdev) |
Sebastian Ott | 2a01bd1 | 2015-07-28 19:14:51 +0200 | [diff] [blame] | 115 | pci_stop_and_remove_bus_device_locked(pdev); |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 116 | |
| 117 | ret = zpci_disable_device(zdev); |
| 118 | if (ret) |
| 119 | break; |
| 120 | |
| 121 | ret = sclp_pci_deconfigure(zdev->fid); |
| 122 | zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret); |
| 123 | if (!ret) |
| 124 | zdev->state = ZPCI_FN_STATE_STANDBY; |
| 125 | |
| 126 | break; |
Sebastian Ott | 623bd44 | 2017-05-09 12:27:30 +0200 | [diff] [blame] | 127 | case 0x0304: /* Configured -> Standby|Reserved */ |
| 128 | if (!zdev) |
| 129 | break; |
Sebastian Ott | 0c0c277 | 2013-12-12 17:53:11 +0100 | [diff] [blame] | 130 | if (pdev) { |
| 131 | /* Give the driver a hint that the function is |
| 132 | * already unusable. */ |
| 133 | pdev->error_state = pci_channel_io_perm_failure; |
Sebastian Ott | 2a01bd1 | 2015-07-28 19:14:51 +0200 | [diff] [blame] | 134 | pci_stop_and_remove_bus_device_locked(pdev); |
Sebastian Ott | 0c0c277 | 2013-12-12 17:53:11 +0100 | [diff] [blame] | 135 | } |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 136 | |
Sebastian Ott | fcf2f40 | 2013-12-18 16:46:02 +0100 | [diff] [blame] | 137 | zdev->fh = ccdf->fh; |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 138 | zpci_disable_device(zdev); |
| 139 | zdev->state = ZPCI_FN_STATE_STANDBY; |
Sebastian Ott | 623bd44 | 2017-05-09 12:27:30 +0200 | [diff] [blame] | 140 | if (!clp_get_state(ccdf->fid, &state) && |
| 141 | state == ZPCI_FN_STATE_RESERVED) { |
| 142 | zpci_remove_device(zdev); |
| 143 | } |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 144 | break; |
| 145 | case 0x0306: /* 0x308 or 0x302 for multiple devices */ |
| 146 | clp_rescan_pci_devices(); |
| 147 | break; |
| 148 | case 0x0308: /* Standby -> Reserved */ |
Sebastian Ott | 7042689 | 2013-12-12 17:50:53 +0100 | [diff] [blame] | 149 | if (!zdev) |
| 150 | break; |
Sebastian Ott | 623bd44 | 2017-05-09 12:27:30 +0200 | [diff] [blame] | 151 | zpci_remove_device(zdev); |
Sebastian Ott | d795dda | 2013-11-15 13:56:08 +0100 | [diff] [blame] | 152 | break; |
| 153 | default: |
| 154 | break; |
| 155 | } |
Markus Elfring | 64a40c8 | 2016-07-18 09:00:00 +0200 | [diff] [blame] | 156 | pci_dev_put(pdev); |
Jan Glauber | cbc0dd1 | 2012-11-29 14:34:48 +0100 | [diff] [blame] | 157 | } |
Sebastian Ott | aa3b7c2 | 2013-12-12 17:48:32 +0100 | [diff] [blame] | 158 | |
| 159 | void zpci_event_availability(void *data) |
| 160 | { |
| 161 | if (zpci_is_enabled()) |
| 162 | __zpci_event_availability(data); |
| 163 | } |