blob: 65ea105f68a196790b7be4c03b70a32d3c4e1a51 [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
8#define COMPONENT "zPCI"
9#define pr_fmt(fmt) COMPONENT ": " fmt
10
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);
Jan Glaubercbc0dd12012-11-29 14:34:48 +010049
Sebastian Ott1f1dcbd2013-10-22 15:17:19 +020050 zpci_err("error CCDF:\n");
51 zpci_err_hex(ccdf, sizeof(*ccdf));
52
53 if (!zdev)
Jan Glaubercbc0dd12012-11-29 14:34:48 +010054 return;
Sebastian Ott1f1dcbd2013-10-22 15:17:19 +020055
56 pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
57 pci_name(zdev->pdev), ccdf->pec, ccdf->fid);
Jan Glaubercbc0dd12012-11-29 14:34:48 +010058}
59
Sebastian Ottaa3b7c22013-12-12 17:48:32 +010060void zpci_event_error(void *data)
Jan Glaubercbc0dd12012-11-29 14:34:48 +010061{
Sebastian Ottaa3b7c22013-12-12 17:48:32 +010062 if (zpci_is_enabled())
63 __zpci_event_error(data);
64}
65
66static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
67{
Sebastian Ottd795dda2013-11-15 13:56:08 +010068 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
69 struct pci_dev *pdev = zdev ? zdev->pdev : NULL;
70 int ret;
71
72 pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n",
73 pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
74 zpci_err("avail CCDF:\n");
75 zpci_err_hex(ccdf, sizeof(*ccdf));
76
77 switch (ccdf->pec) {
78 case 0x0301: /* Standby -> Configured */
79 if (!zdev || zdev->state == ZPCI_FN_STATE_CONFIGURED)
80 break;
81 zdev->state = ZPCI_FN_STATE_CONFIGURED;
82 ret = zpci_enable_device(zdev);
83 if (ret)
84 break;
85 pci_rescan_bus(zdev->bus);
86 break;
87 case 0x0302: /* Reserved -> Standby */
88 clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
89 break;
90 case 0x0303: /* Deconfiguration requested */
91 if (pdev)
92 pci_stop_and_remove_bus_device(pdev);
93
94 ret = zpci_disable_device(zdev);
95 if (ret)
96 break;
97
98 ret = sclp_pci_deconfigure(zdev->fid);
99 zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
100 if (!ret)
101 zdev->state = ZPCI_FN_STATE_STANDBY;
102
103 break;
104 case 0x0304: /* Configured -> Standby */
105 if (pdev)
106 pci_stop_and_remove_bus_device(pdev);
107
108 zpci_disable_device(zdev);
109 zdev->state = ZPCI_FN_STATE_STANDBY;
110 break;
111 case 0x0306: /* 0x308 or 0x302 for multiple devices */
112 clp_rescan_pci_devices();
113 break;
114 case 0x0308: /* Standby -> Reserved */
Sebastian Ott70426892013-12-12 17:50:53 +0100115 if (!zdev)
116 break;
Sebastian Ottd795dda2013-11-15 13:56:08 +0100117 pci_stop_root_bus(zdev->bus);
118 pci_remove_root_bus(zdev->bus);
119 break;
120 default:
121 break;
122 }
Jan Glaubercbc0dd12012-11-29 14:34:48 +0100123}
Sebastian Ottaa3b7c22013-12-12 17:48:32 +0100124
125void zpci_event_availability(void *data)
126{
127 if (zpci_is_enabled())
128 __zpci_event_availability(data);
129}