2 * Copyright IBM Corp. 2012
5 * Jan Glauber <jang@linux.vnet.ibm.com>
8 #define KMSG_COMPONENT "zpci"
9 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 #include <linux/kernel.h>
12 #include <linux/pci.h>
13 #include <asm/pci_debug.h>
16 /* Content Code Description for PCI Function Error */
17 struct zpci_ccdf_err
{
19 u32 fh
; /* function handle */
20 u32 fid
; /* function id */
21 u32 ett
: 4; /* expected table type */
22 u32 mvn
: 12; /* MSI vector number */
23 u32 dmaas
: 8; /* DMA address space */
25 u32 q
: 1; /* event qualifier */
26 u32 rw
: 1; /* read/write */
27 u64 faddr
; /* failing address */
30 u16 pec
; /* PCI event code */
33 /* Content Code Description for PCI Function Availability */
34 struct zpci_ccdf_avail
{
36 u32 fh
; /* function handle */
37 u32 fid
; /* function id */
43 u16 pec
; /* PCI event code */
46 static void __zpci_event_error(struct zpci_ccdf_err
*ccdf
)
48 struct zpci_dev
*zdev
= get_zdev_by_fid(ccdf
->fid
);
49 struct pci_dev
*pdev
= NULL
;
51 zpci_err("error CCDF:\n");
52 zpci_err_hex(ccdf
, sizeof(*ccdf
));
55 pdev
= pci_get_slot(zdev
->bus
, ZPCI_DEVFN
);
57 pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
58 pdev
? pci_name(pdev
) : "n/a", ccdf
->pec
, ccdf
->fid
);
63 pdev
->error_state
= pci_channel_io_perm_failure
;
67 void zpci_event_error(void *data
)
69 if (zpci_is_enabled())
70 __zpci_event_error(data
);
73 static void __zpci_event_availability(struct zpci_ccdf_avail
*ccdf
)
75 struct zpci_dev
*zdev
= get_zdev_by_fid(ccdf
->fid
);
76 struct pci_dev
*pdev
= NULL
;
80 pdev
= pci_get_slot(zdev
->bus
, ZPCI_DEVFN
);
82 pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n",
83 pdev
? pci_name(pdev
) : "n/a", ccdf
->pec
, ccdf
->fid
);
84 zpci_err("avail CCDF:\n");
85 zpci_err_hex(ccdf
, sizeof(*ccdf
));
88 case 0x0301: /* Reserved|Standby -> Configured */
90 ret
= clp_add_pci_device(ccdf
->fid
, ccdf
->fh
, 0);
93 zdev
= get_zdev_by_fid(ccdf
->fid
);
95 if (!zdev
|| zdev
->state
!= ZPCI_FN_STATE_STANDBY
)
97 zdev
->state
= ZPCI_FN_STATE_CONFIGURED
;
99 ret
= zpci_enable_device(zdev
);
102 pci_lock_rescan_remove();
103 pci_rescan_bus(zdev
->bus
);
104 pci_unlock_rescan_remove();
106 case 0x0302: /* Reserved -> Standby */
108 clp_add_pci_device(ccdf
->fid
, ccdf
->fh
, 0);
110 case 0x0303: /* Deconfiguration requested */
112 pci_stop_and_remove_bus_device_locked(pdev
);
114 ret
= zpci_disable_device(zdev
);
118 ret
= sclp_pci_deconfigure(zdev
->fid
);
119 zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev
->fid
, ret
);
121 zdev
->state
= ZPCI_FN_STATE_STANDBY
;
124 case 0x0304: /* Configured -> Standby */
126 /* Give the driver a hint that the function is
127 * already unusable. */
128 pdev
->error_state
= pci_channel_io_perm_failure
;
129 pci_stop_and_remove_bus_device_locked(pdev
);
133 zpci_disable_device(zdev
);
134 zdev
->state
= ZPCI_FN_STATE_STANDBY
;
136 case 0x0306: /* 0x308 or 0x302 for multiple devices */
137 clp_rescan_pci_devices();
139 case 0x0308: /* Standby -> Reserved */
142 pci_stop_root_bus(zdev
->bus
);
143 pci_remove_root_bus(zdev
->bus
);
152 void zpci_event_availability(void *data
)
154 if (zpci_is_enabled())
155 __zpci_event_availability(data
);