1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2012
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>
15 #include <asm/pci_dma.h>
20 /* Content Code Description for PCI Function Error */
21 struct zpci_ccdf_err {
23 u32 fh; /* function handle */
24 u32 fid; /* function id */
25 u32 ett : 4; /* expected table type */
26 u32 mvn : 12; /* MSI vector number */
27 u32 dmaas : 8; /* DMA address space */
29 u32 q : 1; /* event qualifier */
30 u32 rw : 1; /* read/write */
31 u64 faddr; /* failing address */
34 u16 pec; /* PCI event code */
37 /* Content Code Description for PCI Function Availability */
38 struct zpci_ccdf_avail {
40 u32 fh; /* function handle */
41 u32 fid; /* function id */
47 u16 pec; /* PCI event code */
50 static void __zpci_event_error(struct zpci_ccdf_err *ccdf)
52 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
53 struct pci_dev *pdev = NULL;
55 zpci_err("error CCDF:\n");
56 zpci_err_hex(ccdf, sizeof(*ccdf));
59 pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn);
61 pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
62 pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
67 pdev->error_state = pci_channel_io_perm_failure;
71 void zpci_event_error(void *data)
73 if (zpci_is_enabled())
74 __zpci_event_error(data);
77 static void zpci_event_hard_deconfigured(struct zpci_dev *zdev, u32 fh)
80 /* Give the driver a hint that the function is
83 zpci_bus_remove_device(zdev, true);
84 /* Even though the device is already gone we still
85 * need to free zPCI resources as part of the disable.
88 zpci_dma_exit_device(zdev);
89 if (zdev_enabled(zdev))
90 zpci_disable_device(zdev);
91 zdev->state = ZPCI_FN_STATE_STANDBY;
94 static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
96 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
97 enum zpci_state state;
99 zpci_err("avail CCDF:\n");
100 zpci_err_hex(ccdf, sizeof(*ccdf));
103 case 0x0301: /* Reserved|Standby -> Configured */
105 zdev = zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_CONFIGURED);
109 /* the configuration request may be stale */
110 if (zdev->state != ZPCI_FN_STATE_STANDBY)
112 zdev->state = ZPCI_FN_STATE_CONFIGURED;
114 zpci_scan_configured_device(zdev, ccdf->fh);
116 case 0x0302: /* Reserved -> Standby */
118 zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_STANDBY);
122 case 0x0303: /* Deconfiguration requested */
124 /* The event may have been queued before we confirgured
127 if (zdev->state != ZPCI_FN_STATE_CONFIGURED)
130 zpci_deconfigure_device(zdev);
133 case 0x0304: /* Configured -> Standby|Reserved */
135 /* The event may have been queued before we confirgured
138 if (zdev->state == ZPCI_FN_STATE_CONFIGURED)
139 zpci_event_hard_deconfigured(zdev, ccdf->fh);
140 /* The 0x0304 event may immediately reserve the device */
141 if (!clp_get_state(zdev->fid, &state) &&
142 state == ZPCI_FN_STATE_RESERVED) {
147 case 0x0306: /* 0x308 or 0x302 for multiple devices */
148 zpci_remove_reserved_devices();
149 clp_scan_pci_devices();
151 case 0x0308: /* Standby -> Reserved */
161 void zpci_event_availability(void *data)
163 if (zpci_is_enabled())
164 __zpci_event_availability(data);