blob: 369a3e05d468dbf1973df24c77e4ae07e580c3b6 [file] [log] [blame]
Jan Glaubercbc0dd12012-11-29 14:34:48 +01001/*
2 * Copyright IBM Corp. 2012
3 *
4 * Author(s):
5 * Jan Glauber <jang@linux.vnet.ibm.com>
6 */
7
Gerald Schaefer896cb7e2014-07-16 17:21:01 +02008#define KMSG_COMPONENT "zpci"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
Jan Glaubercbc0dd12012-11-29 14:34:48 +010010
11#include <linux/kernel.h>
12#include <linux/pci.h>
Sebastian Ott1f1dcbd2013-10-22 15:17:19 +020013#include <asm/pci_debug.h>
Sebastian Ottd795dda2013-11-15 13:56:08 +010014#include <asm/sclp.h>
Jan Glaubercbc0dd12012-11-29 14:34:48 +010015
16/* Content Code Description for PCI Function Error */
17struct zpci_ccdf_err {
18 u32 reserved1;
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 */
24 u32 : 6;
25 u32 q : 1; /* event qualifier */
26 u32 rw : 1; /* read/write */
27 u64 faddr; /* failing address */
28 u32 reserved3;
29 u16 reserved4;
30 u16 pec; /* PCI event code */
31} __packed;
32
33/* Content Code Description for PCI Function Availability */
34struct zpci_ccdf_avail {
35 u32 reserved1;
36 u32 fh; /* function handle */
37 u32 fid; /* function id */
38 u32 reserved2;
39 u32 reserved3;
40 u32 reserved4;
41 u32 reserved5;
42 u16 reserved6;
43 u16 pec; /* PCI event code */
44} __packed;
45
Sebastian Ottaa3b7c22013-12-12 17:48:32 +010046static void __zpci_event_error(struct zpci_ccdf_err *ccdf)
Jan Glaubercbc0dd12012-11-29 14:34:48 +010047{
Sebastian Ott1f1dcbd2013-10-22 15:17:19 +020048 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
Sebastian Ott515f0222015-07-28 19:11:40 +020049 struct pci_dev *pdev = zdev ? zdev->pdev : NULL;
Jan Glaubercbc0dd12012-11-29 14:34:48 +010050
Sebastian Ott1f1dcbd2013-10-22 15:17:19 +020051 zpci_err("error CCDF:\n");
52 zpci_err_hex(ccdf, sizeof(*ccdf));
53
Sebastian Ott1f1dcbd2013-10-22 15:17:19 +020054 pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
Sebastian Ott515f0222015-07-28 19:11:40 +020055 pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
Jan Glaubercbc0dd12012-11-29 14:34:48 +010056}
57
Sebastian Ottaa3b7c22013-12-12 17:48:32 +010058void zpci_event_error(void *data)
Jan Glaubercbc0dd12012-11-29 14:34:48 +010059{
Sebastian Ottaa3b7c22013-12-12 17:48:32 +010060 if (zpci_is_enabled())
61 __zpci_event_error(data);
62}
63
64static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
65{
Sebastian Ottd795dda2013-11-15 13:56:08 +010066 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
67 struct pci_dev *pdev = zdev ? zdev->pdev : NULL;
68 int ret;
69
70 pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n",
71 pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
72 zpci_err("avail CCDF:\n");
73 zpci_err_hex(ccdf, sizeof(*ccdf));
74
75 switch (ccdf->pec) {
Sebastian Ott7fc611f2015-06-16 18:58:37 +020076 case 0x0301: /* Reserved|Standby -> Configured */
77 if (!zdev) {
78 ret = clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
79 if (ret)
80 break;
81 zdev = get_zdev_by_fid(ccdf->fid);
82 }
Sebastian Ottca25f562014-04-16 16:09:23 +020083 if (!zdev || zdev->state != ZPCI_FN_STATE_STANDBY)
Sebastian Ottd795dda2013-11-15 13:56:08 +010084 break;
85 zdev->state = ZPCI_FN_STATE_CONFIGURED;
Sebastian Ottfcf2f402013-12-18 16:46:02 +010086 zdev->fh = ccdf->fh;
Sebastian Ottd795dda2013-11-15 13:56:08 +010087 ret = zpci_enable_device(zdev);
88 if (ret)
89 break;
Sebastian Ott2a01bd12015-07-28 19:14:51 +020090 pci_lock_rescan_remove();
Sebastian Ottd795dda2013-11-15 13:56:08 +010091 pci_rescan_bus(zdev->bus);
Sebastian Ott2a01bd12015-07-28 19:14:51 +020092 pci_unlock_rescan_remove();
Sebastian Ottd795dda2013-11-15 13:56:08 +010093 break;
94 case 0x0302: /* Reserved -> Standby */
Sebastian Ottca25f562014-04-16 16:09:23 +020095 if (!zdev)
96 clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
Sebastian Ottd795dda2013-11-15 13:56:08 +010097 break;
98 case 0x0303: /* Deconfiguration requested */
99 if (pdev)
Sebastian Ott2a01bd12015-07-28 19:14:51 +0200100 pci_stop_and_remove_bus_device_locked(pdev);
Sebastian Ottd795dda2013-11-15 13:56:08 +0100101
102 ret = zpci_disable_device(zdev);
103 if (ret)
104 break;
105
106 ret = sclp_pci_deconfigure(zdev->fid);
107 zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
108 if (!ret)
109 zdev->state = ZPCI_FN_STATE_STANDBY;
110
111 break;
112 case 0x0304: /* Configured -> Standby */
Sebastian Ott0c0c2772013-12-12 17:53:11 +0100113 if (pdev) {
114 /* Give the driver a hint that the function is
115 * already unusable. */
116 pdev->error_state = pci_channel_io_perm_failure;
Sebastian Ott2a01bd12015-07-28 19:14:51 +0200117 pci_stop_and_remove_bus_device_locked(pdev);
Sebastian Ott0c0c2772013-12-12 17:53:11 +0100118 }
Sebastian Ottd795dda2013-11-15 13:56:08 +0100119
Sebastian Ottfcf2f402013-12-18 16:46:02 +0100120 zdev->fh = ccdf->fh;
Sebastian Ottd795dda2013-11-15 13:56:08 +0100121 zpci_disable_device(zdev);
122 zdev->state = ZPCI_FN_STATE_STANDBY;
123 break;
124 case 0x0306: /* 0x308 or 0x302 for multiple devices */
125 clp_rescan_pci_devices();
126 break;
127 case 0x0308: /* Standby -> Reserved */
Sebastian Ott70426892013-12-12 17:50:53 +0100128 if (!zdev)
129 break;
Sebastian Ottd795dda2013-11-15 13:56:08 +0100130 pci_stop_root_bus(zdev->bus);
131 pci_remove_root_bus(zdev->bus);
132 break;
133 default:
134 break;
135 }
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100136}
Sebastian Ottaa3b7c22013-12-12 17:48:32 +0100137
138void zpci_event_availability(void *data)
139{
140 if (zpci_is_enabled())
141 __zpci_event_availability(data);
142}