| .. | .. |
|---|
| 14 | 14 | #include <asm/pci_debug.h> |
|---|
| 15 | 15 | #include <asm/sclp.h> |
|---|
| 16 | 16 | |
|---|
| 17 | +#include "pci_bus.h" |
|---|
| 18 | + |
|---|
| 17 | 19 | /* Content Code Description for PCI Function Error */ |
|---|
| 18 | 20 | struct zpci_ccdf_err { |
|---|
| 19 | 21 | u32 reserved1; |
|---|
| .. | .. |
|---|
| 53 | 55 | zpci_err_hex(ccdf, sizeof(*ccdf)); |
|---|
| 54 | 56 | |
|---|
| 55 | 57 | if (zdev) |
|---|
| 56 | | - pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN); |
|---|
| 58 | + pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn); |
|---|
| 57 | 59 | |
|---|
| 58 | 60 | pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n", |
|---|
| 59 | 61 | pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid); |
|---|
| 60 | 62 | |
|---|
| 61 | 63 | if (!pdev) |
|---|
| 62 | | - return; |
|---|
| 64 | + goto no_pdev; |
|---|
| 63 | 65 | |
|---|
| 64 | 66 | pdev->error_state = pci_channel_io_perm_failure; |
|---|
| 65 | 67 | pci_dev_put(pdev); |
|---|
| 68 | +no_pdev: |
|---|
| 69 | + zpci_zdev_put(zdev); |
|---|
| 66 | 70 | } |
|---|
| 67 | 71 | |
|---|
| 68 | 72 | void zpci_event_error(void *data) |
|---|
| .. | .. |
|---|
| 74 | 78 | static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf) |
|---|
| 75 | 79 | { |
|---|
| 76 | 80 | struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid); |
|---|
| 77 | | - struct pci_dev *pdev = NULL; |
|---|
| 81 | + bool existing_zdev = !!zdev; |
|---|
| 78 | 82 | enum zpci_state state; |
|---|
| 83 | + struct pci_dev *pdev; |
|---|
| 79 | 84 | int ret; |
|---|
| 80 | 85 | |
|---|
| 81 | | - if (zdev) |
|---|
| 82 | | - pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN); |
|---|
| 83 | | - |
|---|
| 84 | | - pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n", |
|---|
| 85 | | - pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid); |
|---|
| 86 | 86 | zpci_err("avail CCDF:\n"); |
|---|
| 87 | 87 | zpci_err_hex(ccdf, sizeof(*ccdf)); |
|---|
| 88 | 88 | |
|---|
| 89 | 89 | switch (ccdf->pec) { |
|---|
| 90 | 90 | case 0x0301: /* Reserved|Standby -> Configured */ |
|---|
| 91 | 91 | if (!zdev) { |
|---|
| 92 | | - ret = clp_add_pci_device(ccdf->fid, ccdf->fh, 0); |
|---|
| 93 | | - if (ret) |
|---|
| 94 | | - break; |
|---|
| 95 | | - zdev = get_zdev_by_fid(ccdf->fid); |
|---|
| 96 | | - } |
|---|
| 97 | | - if (!zdev || zdev->state != ZPCI_FN_STATE_STANDBY) |
|---|
| 92 | + zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_CONFIGURED); |
|---|
| 98 | 93 | break; |
|---|
| 99 | | - zdev->state = ZPCI_FN_STATE_CONFIGURED; |
|---|
| 94 | + } |
|---|
| 95 | + /* the configuration request may be stale */ |
|---|
| 96 | + if (zdev->state != ZPCI_FN_STATE_STANDBY) |
|---|
| 97 | + break; |
|---|
| 100 | 98 | zdev->fh = ccdf->fh; |
|---|
| 99 | + zdev->state = ZPCI_FN_STATE_CONFIGURED; |
|---|
| 101 | 100 | ret = zpci_enable_device(zdev); |
|---|
| 102 | 101 | if (ret) |
|---|
| 103 | 102 | break; |
|---|
| 103 | + |
|---|
| 104 | + /* the PCI function will be scanned once function 0 appears */ |
|---|
| 105 | + if (!zdev->zbus->bus) |
|---|
| 106 | + break; |
|---|
| 107 | + |
|---|
| 108 | + pdev = pci_scan_single_device(zdev->zbus->bus, zdev->devfn); |
|---|
| 109 | + if (!pdev) |
|---|
| 110 | + break; |
|---|
| 111 | + |
|---|
| 112 | + pci_bus_add_device(pdev); |
|---|
| 104 | 113 | pci_lock_rescan_remove(); |
|---|
| 105 | | - pci_rescan_bus(zdev->bus); |
|---|
| 114 | + pci_bus_add_devices(zdev->zbus->bus); |
|---|
| 106 | 115 | pci_unlock_rescan_remove(); |
|---|
| 107 | 116 | break; |
|---|
| 108 | 117 | case 0x0302: /* Reserved -> Standby */ |
|---|
| 109 | | - if (!zdev) |
|---|
| 110 | | - clp_add_pci_device(ccdf->fid, ccdf->fh, 0); |
|---|
| 118 | + if (!zdev) { |
|---|
| 119 | + zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_STANDBY); |
|---|
| 120 | + break; |
|---|
| 121 | + } |
|---|
| 122 | + zdev->fh = ccdf->fh; |
|---|
| 111 | 123 | break; |
|---|
| 112 | 124 | case 0x0303: /* Deconfiguration requested */ |
|---|
| 113 | 125 | if (!zdev) |
|---|
| 114 | 126 | break; |
|---|
| 115 | | - if (pdev) |
|---|
| 116 | | - pci_stop_and_remove_bus_device_locked(pdev); |
|---|
| 127 | + zpci_remove_device(zdev, false); |
|---|
| 117 | 128 | |
|---|
| 118 | 129 | ret = zpci_disable_device(zdev); |
|---|
| 119 | 130 | if (ret) |
|---|
| .. | .. |
|---|
| 128 | 139 | case 0x0304: /* Configured -> Standby|Reserved */ |
|---|
| 129 | 140 | if (!zdev) |
|---|
| 130 | 141 | break; |
|---|
| 131 | | - if (pdev) { |
|---|
| 132 | | - /* Give the driver a hint that the function is |
|---|
| 133 | | - * already unusable. */ |
|---|
| 134 | | - pdev->error_state = pci_channel_io_perm_failure; |
|---|
| 135 | | - pci_stop_and_remove_bus_device_locked(pdev); |
|---|
| 136 | | - } |
|---|
| 142 | + /* Give the driver a hint that the function is |
|---|
| 143 | + * already unusable. |
|---|
| 144 | + */ |
|---|
| 145 | + zpci_remove_device(zdev, true); |
|---|
| 137 | 146 | |
|---|
| 138 | 147 | zdev->fh = ccdf->fh; |
|---|
| 139 | 148 | zpci_disable_device(zdev); |
|---|
| 140 | 149 | zdev->state = ZPCI_FN_STATE_STANDBY; |
|---|
| 141 | 150 | if (!clp_get_state(ccdf->fid, &state) && |
|---|
| 142 | 151 | state == ZPCI_FN_STATE_RESERVED) { |
|---|
| 143 | | - zpci_remove_device(zdev); |
|---|
| 152 | + zpci_device_reserved(zdev); |
|---|
| 144 | 153 | } |
|---|
| 145 | 154 | break; |
|---|
| 146 | 155 | case 0x0306: /* 0x308 or 0x302 for multiple devices */ |
|---|
| 147 | | - clp_rescan_pci_devices(); |
|---|
| 156 | + zpci_remove_reserved_devices(); |
|---|
| 157 | + clp_scan_pci_devices(); |
|---|
| 148 | 158 | break; |
|---|
| 149 | 159 | case 0x0308: /* Standby -> Reserved */ |
|---|
| 150 | 160 | if (!zdev) |
|---|
| 151 | 161 | break; |
|---|
| 152 | | - zpci_remove_device(zdev); |
|---|
| 162 | + zpci_device_reserved(zdev); |
|---|
| 153 | 163 | break; |
|---|
| 154 | 164 | default: |
|---|
| 155 | 165 | break; |
|---|
| 156 | 166 | } |
|---|
| 157 | | - pci_dev_put(pdev); |
|---|
| 167 | + if (existing_zdev) |
|---|
| 168 | + zpci_zdev_put(zdev); |
|---|
| 158 | 169 | } |
|---|
| 159 | 170 | |
|---|
| 160 | 171 | void zpci_event_availability(void *data) |
|---|