xref: /openbmc/linux/arch/s390/pci/pci_event.c (revision 930beb5a)
1 /*
2  *  Copyright IBM Corp. 2012
3  *
4  *  Author(s):
5  *    Jan Glauber <jang@linux.vnet.ibm.com>
6  */
7 
8 #define COMPONENT "zPCI"
9 #define pr_fmt(fmt) COMPONENT ": " fmt
10 
11 #include <linux/kernel.h>
12 #include <linux/pci.h>
13 #include <asm/pci_debug.h>
14 #include <asm/sclp.h>
15 
16 /* Content Code Description for PCI Function Error */
17 struct 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 */
34 struct 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 
46 void zpci_event_error(void *data)
47 {
48 	struct zpci_ccdf_err *ccdf = data;
49 	struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
50 
51 	zpci_err("error CCDF:\n");
52 	zpci_err_hex(ccdf, sizeof(*ccdf));
53 
54 	if (!zdev)
55 		return;
56 
57 	pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
58 	       pci_name(zdev->pdev), ccdf->pec, ccdf->fid);
59 }
60 
61 void zpci_event_availability(void *data)
62 {
63 	struct zpci_ccdf_avail *ccdf = data;
64 	struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
65 	struct pci_dev *pdev = zdev ? zdev->pdev : NULL;
66 	int ret;
67 
68 	pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n",
69 		pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
70 	zpci_err("avail CCDF:\n");
71 	zpci_err_hex(ccdf, sizeof(*ccdf));
72 
73 	switch (ccdf->pec) {
74 	case 0x0301: /* Standby -> Configured */
75 		if (!zdev || zdev->state == ZPCI_FN_STATE_CONFIGURED)
76 			break;
77 		zdev->state = ZPCI_FN_STATE_CONFIGURED;
78 		zdev->fh = ccdf->fh;
79 		ret = zpci_enable_device(zdev);
80 		if (ret)
81 			break;
82 		pci_rescan_bus(zdev->bus);
83 		break;
84 	case 0x0302: /* Reserved -> Standby */
85 		clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
86 		break;
87 	case 0x0303: /* Deconfiguration requested */
88 		if (pdev)
89 			pci_stop_and_remove_bus_device(pdev);
90 
91 		ret = zpci_disable_device(zdev);
92 		if (ret)
93 			break;
94 
95 		ret = sclp_pci_deconfigure(zdev->fid);
96 		zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
97 		if (!ret)
98 			zdev->state = ZPCI_FN_STATE_STANDBY;
99 
100 		break;
101 	case 0x0304: /* Configured -> Standby */
102 		if (pdev)
103 			pci_stop_and_remove_bus_device(pdev);
104 
105 		zdev->fh = ccdf->fh;
106 		zpci_disable_device(zdev);
107 		zdev->state = ZPCI_FN_STATE_STANDBY;
108 		break;
109 	case 0x0306: /* 0x308 or 0x302 for multiple devices */
110 		clp_rescan_pci_devices();
111 		break;
112 	case 0x0308: /* Standby -> Reserved */
113 		pci_stop_root_bus(zdev->bus);
114 		pci_remove_root_bus(zdev->bus);
115 		break;
116 	default:
117 		break;
118 	}
119 }
120