1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2012
6 * Jan Glauber <jang@linux.vnet.ibm.com>
9 #define KMSG_COMPONENT "zpci"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/kernel.h>
13 #include <linux/pci.h>
14 #include <asm/pci_debug.h>
19 /* Content Code Description for PCI Function Error */
20 struct zpci_ccdf_err
{
22 u32 fh
; /* function handle */
23 u32 fid
; /* function id */
24 u32 ett
: 4; /* expected table type */
25 u32 mvn
: 12; /* MSI vector number */
26 u32 dmaas
: 8; /* DMA address space */
28 u32 q
: 1; /* event qualifier */
29 u32 rw
: 1; /* read/write */
30 u64 faddr
; /* failing address */
33 u16 pec
; /* PCI event code */
36 /* Content Code Description for PCI Function Availability */
37 struct zpci_ccdf_avail
{
39 u32 fh
; /* function handle */
40 u32 fid
; /* function id */
46 u16 pec
; /* PCI event code */
49 static void __zpci_event_error(struct zpci_ccdf_err
*ccdf
)
51 struct zpci_dev
*zdev
= get_zdev_by_fid(ccdf
->fid
);
52 struct pci_dev
*pdev
= NULL
;
54 zpci_err("error CCDF:\n");
55 zpci_err_hex(ccdf
, sizeof(*ccdf
));
58 pdev
= pci_get_slot(zdev
->zbus
->bus
, zdev
->devfn
);
60 pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
61 pdev
? pci_name(pdev
) : "n/a", ccdf
->pec
, ccdf
->fid
);
66 pdev
->error_state
= pci_channel_io_perm_failure
;
70 void zpci_event_error(void *data
)
72 if (zpci_is_enabled())
73 __zpci_event_error(data
);
76 static void __zpci_event_availability(struct zpci_ccdf_avail
*ccdf
)
78 struct zpci_dev
*zdev
= get_zdev_by_fid(ccdf
->fid
);
79 struct pci_dev
*pdev
= NULL
;
80 enum zpci_state state
;
83 if (zdev
&& zdev
->zbus
&& zdev
->zbus
->bus
)
84 pdev
= pci_get_slot(zdev
->zbus
->bus
, zdev
->devfn
);
86 zpci_err("avail CCDF:\n");
87 zpci_err_hex(ccdf
, sizeof(*ccdf
));
90 case 0x0301: /* Reserved|Standby -> Configured */
92 ret
= clp_add_pci_device(ccdf
->fid
, ccdf
->fh
, 1);
95 /* the configuration request may be stale */
96 if (zdev
->state
!= ZPCI_FN_STATE_STANDBY
)
99 zdev
->state
= ZPCI_FN_STATE_CONFIGURED
;
100 ret
= zpci_enable_device(zdev
);
104 /* the PCI function will be scanned once function 0 appears */
105 if (!zdev
->zbus
->bus
)
108 pdev
= pci_scan_single_device(zdev
->zbus
->bus
, zdev
->devfn
);
112 pci_bus_add_device(pdev
);
113 pci_lock_rescan_remove();
114 pci_bus_add_devices(zdev
->zbus
->bus
);
115 pci_unlock_rescan_remove();
117 case 0x0302: /* Reserved -> Standby */
119 clp_add_pci_device(ccdf
->fid
, ccdf
->fh
, 0);
124 case 0x0303: /* Deconfiguration requested */
128 zpci_remove_device(zdev
);
130 ret
= zpci_disable_device(zdev
);
134 ret
= sclp_pci_deconfigure(zdev
->fid
);
135 zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev
->fid
, ret
);
137 zdev
->state
= ZPCI_FN_STATE_STANDBY
;
140 case 0x0304: /* Configured -> Standby|Reserved */
144 /* Give the driver a hint that the function is
145 * already unusable. */
146 pdev
->error_state
= pci_channel_io_perm_failure
;
147 zpci_remove_device(zdev
);
151 zpci_disable_device(zdev
);
152 zdev
->state
= ZPCI_FN_STATE_STANDBY
;
153 if (!clp_get_state(ccdf
->fid
, &state
) &&
154 state
== ZPCI_FN_STATE_RESERVED
) {
158 case 0x0306: /* 0x308 or 0x302 for multiple devices */
159 zpci_remove_reserved_devices();
160 clp_scan_pci_devices();
162 case 0x0308: /* Standby -> Reserved */
172 void zpci_event_availability(void *data
)
174 if (zpci_is_enabled())
175 __zpci_event_availability(data
);