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>
17 /* Content Code Description for PCI Function Error */
18 struct zpci_ccdf_err
{
20 u32 fh
; /* function handle */
21 u32 fid
; /* function id */
22 u32 ett
: 4; /* expected table type */
23 u32 mvn
: 12; /* MSI vector number */
24 u32 dmaas
: 8; /* DMA address space */
26 u32 q
: 1; /* event qualifier */
27 u32 rw
: 1; /* read/write */
28 u64 faddr
; /* failing address */
31 u16 pec
; /* PCI event code */
34 /* Content Code Description for PCI Function Availability */
35 struct zpci_ccdf_avail
{
37 u32 fh
; /* function handle */
38 u32 fid
; /* function id */
44 u16 pec
; /* PCI event code */
47 static void __zpci_event_error(struct zpci_ccdf_err
*ccdf
)
49 struct zpci_dev
*zdev
= get_zdev_by_fid(ccdf
->fid
);
50 struct pci_dev
*pdev
= NULL
;
52 zpci_err("error CCDF:\n");
53 zpci_err_hex(ccdf
, sizeof(*ccdf
));
56 pdev
= pci_get_slot(zdev
->bus
, ZPCI_DEVFN
);
58 pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
59 pdev
? pci_name(pdev
) : "n/a", ccdf
->pec
, ccdf
->fid
);
64 pdev
->error_state
= pci_channel_io_perm_failure
;
68 void zpci_event_error(void *data
)
70 if (zpci_is_enabled())
71 __zpci_event_error(data
);
74 static void __zpci_event_availability(struct zpci_ccdf_avail
*ccdf
)
76 struct zpci_dev
*zdev
= get_zdev_by_fid(ccdf
->fid
);
77 struct pci_dev
*pdev
= NULL
;
78 enum zpci_state state
;
82 pdev
= pci_get_slot(zdev
->bus
, ZPCI_DEVFN
);
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 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
, 0);
95 zdev
= get_zdev_by_fid(ccdf
->fid
);
97 if (!zdev
|| zdev
->state
!= ZPCI_FN_STATE_STANDBY
)
99 zdev
->state
= ZPCI_FN_STATE_CONFIGURED
;
101 ret
= zpci_enable_device(zdev
);
104 pci_lock_rescan_remove();
105 pci_rescan_bus(zdev
->bus
);
106 pci_unlock_rescan_remove();
108 case 0x0302: /* Reserved -> Standby */
110 clp_add_pci_device(ccdf
->fid
, ccdf
->fh
, 0);
112 case 0x0303: /* Deconfiguration requested */
116 pci_stop_and_remove_bus_device_locked(pdev
);
118 ret
= zpci_disable_device(zdev
);
122 ret
= sclp_pci_deconfigure(zdev
->fid
);
123 zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev
->fid
, ret
);
125 zdev
->state
= ZPCI_FN_STATE_STANDBY
;
128 case 0x0304: /* Configured -> Standby|Reserved */
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
);
139 zpci_disable_device(zdev
);
140 zdev
->state
= ZPCI_FN_STATE_STANDBY
;
141 if (!clp_get_state(ccdf
->fid
, &state
) &&
142 state
== ZPCI_FN_STATE_RESERVED
) {
143 zpci_remove_device(zdev
);
146 case 0x0306: /* 0x308 or 0x302 for multiple devices */
147 clp_rescan_pci_devices();
149 case 0x0308: /* Standby -> Reserved */
152 zpci_remove_device(zdev
);
160 void zpci_event_availability(void *data
)
162 if (zpci_is_enabled())
163 __zpci_event_availability(data
);