hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/s390/pci/pci_event.c
....@@ -14,6 +14,8 @@
1414 #include <asm/pci_debug.h>
1515 #include <asm/sclp.h>
1616
17
+#include "pci_bus.h"
18
+
1719 /* Content Code Description for PCI Function Error */
1820 struct zpci_ccdf_err {
1921 u32 reserved1;
....@@ -53,16 +55,18 @@
5355 zpci_err_hex(ccdf, sizeof(*ccdf));
5456
5557 if (zdev)
56
- pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN);
58
+ pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn);
5759
5860 pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
5961 pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
6062
6163 if (!pdev)
62
- return;
64
+ goto no_pdev;
6365
6466 pdev->error_state = pci_channel_io_perm_failure;
6567 pci_dev_put(pdev);
68
+no_pdev:
69
+ zpci_zdev_put(zdev);
6670 }
6771
6872 void zpci_event_error(void *data)
....@@ -74,46 +78,53 @@
7478 static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
7579 {
7680 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
77
- struct pci_dev *pdev = NULL;
81
+ bool existing_zdev = !!zdev;
7882 enum zpci_state state;
83
+ struct pci_dev *pdev;
7984 int ret;
8085
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);
8686 zpci_err("avail CCDF:\n");
8787 zpci_err_hex(ccdf, sizeof(*ccdf));
8888
8989 switch (ccdf->pec) {
9090 case 0x0301: /* Reserved|Standby -> Configured */
9191 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);
9893 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;
10098 zdev->fh = ccdf->fh;
99
+ zdev->state = ZPCI_FN_STATE_CONFIGURED;
101100 ret = zpci_enable_device(zdev);
102101 if (ret)
103102 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);
104113 pci_lock_rescan_remove();
105
- pci_rescan_bus(zdev->bus);
114
+ pci_bus_add_devices(zdev->zbus->bus);
106115 pci_unlock_rescan_remove();
107116 break;
108117 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;
111123 break;
112124 case 0x0303: /* Deconfiguration requested */
113125 if (!zdev)
114126 break;
115
- if (pdev)
116
- pci_stop_and_remove_bus_device_locked(pdev);
127
+ zpci_remove_device(zdev, false);
117128
118129 ret = zpci_disable_device(zdev);
119130 if (ret)
....@@ -128,33 +139,33 @@
128139 case 0x0304: /* Configured -> Standby|Reserved */
129140 if (!zdev)
130141 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);
137146
138147 zdev->fh = ccdf->fh;
139148 zpci_disable_device(zdev);
140149 zdev->state = ZPCI_FN_STATE_STANDBY;
141150 if (!clp_get_state(ccdf->fid, &state) &&
142151 state == ZPCI_FN_STATE_RESERVED) {
143
- zpci_remove_device(zdev);
152
+ zpci_device_reserved(zdev);
144153 }
145154 break;
146155 case 0x0306: /* 0x308 or 0x302 for multiple devices */
147
- clp_rescan_pci_devices();
156
+ zpci_remove_reserved_devices();
157
+ clp_scan_pci_devices();
148158 break;
149159 case 0x0308: /* Standby -> Reserved */
150160 if (!zdev)
151161 break;
152
- zpci_remove_device(zdev);
162
+ zpci_device_reserved(zdev);
153163 break;
154164 default:
155165 break;
156166 }
157
- pci_dev_put(pdev);
167
+ if (existing_zdev)
168
+ zpci_zdev_put(zdev);
158169 }
159170
160171 void zpci_event_availability(void *data)