pci_event.c 3.5 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
2 3 4 5 6 7 8
/*
 *  Copyright IBM Corp. 2012
 *
 *  Author(s):
 *    Jan Glauber <jang@linux.vnet.ibm.com>
 */

G
Gerald Schaefer 已提交
9 10
#define KMSG_COMPONENT "zpci"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 12 13

#include <linux/kernel.h>
#include <linux/pci.h>
S
Sebastian Ott 已提交
14
#include <asm/pci_debug.h>
15
#include <asm/sclp.h>
16

P
Pierre Morel 已提交
17 18
#include "pci_bus.h"

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
/* Content Code Description for PCI Function Error */
struct zpci_ccdf_err {
	u32 reserved1;
	u32 fh;				/* function handle */
	u32 fid;			/* function id */
	u32 ett		:  4;		/* expected table type */
	u32 mvn		: 12;		/* MSI vector number */
	u32 dmaas	:  8;		/* DMA address space */
	u32		:  6;
	u32 q		:  1;		/* event qualifier */
	u32 rw		:  1;		/* read/write */
	u64 faddr;			/* failing address */
	u32 reserved3;
	u16 reserved4;
	u16 pec;			/* PCI event code */
} __packed;

/* Content Code Description for PCI Function Availability */
struct zpci_ccdf_avail {
	u32 reserved1;
	u32 fh;				/* function handle */
	u32 fid;			/* function id */
	u32 reserved2;
	u32 reserved3;
	u32 reserved4;
	u32 reserved5;
	u16 reserved6;
	u16 pec;			/* PCI event code */
} __packed;

49
static void __zpci_event_error(struct zpci_ccdf_err *ccdf)
50
{
51
	struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
52
	struct pci_dev *pdev = NULL;
53 54 55 56

	zpci_err("error CCDF:\n");
	zpci_err_hex(ccdf, sizeof(*ccdf));

57
	if (zdev)
P
Pierre Morel 已提交
58
		pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn);
59

60
	pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
61
	       pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
62 63 64 65 66

	if (!pdev)
		return;

	pdev->error_state = pci_channel_io_perm_failure;
67
	pci_dev_put(pdev);
68 69
}

70 71 72 73 74 75 76
void zpci_event_error(void *data)
{
	if (zpci_is_enabled())
		__zpci_event_error(data);
}

static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
77
{
78
	struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
79
	struct pci_dev *pdev = NULL;
S
Sebastian Ott 已提交
80
	enum zpci_state state;
81
	int ret;
82

P
Pierre Morel 已提交
83
	if (zdev && zdev->zbus && zdev->zbus->bus)
P
Pierre Morel 已提交
84
		pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn);
85

S
Sebastian Ott 已提交
86 87
	zpci_err("avail CCDF:\n");
	zpci_err_hex(ccdf, sizeof(*ccdf));
88 89

	switch (ccdf->pec) {
90 91
	case 0x0301: /* Reserved|Standby -> Configured */
		if (!zdev) {
P
Pierre Morel 已提交
92
			ret = clp_add_pci_device(ccdf->fid, ccdf->fh, 1);
93
			break;
P
Pierre Morel 已提交
94
		}
95
		zdev->fh = ccdf->fh;
P
Pierre Morel 已提交
96 97
		zdev->state = ZPCI_FN_STATE_CONFIGURED;
		zpci_create_device(zdev);
98
		break;
99
	case 0x0302: /* Reserved -> Standby */
P
Pierre Morel 已提交
100
		if (!zdev) {
101
			clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
P
Pierre Morel 已提交
102 103 104
			break;
		}
		zdev->fh = ccdf->fh;
105
		break;
106
	case 0x0303: /* Deconfiguration requested */
S
Sebastian Ott 已提交
107 108
		if (!zdev)
			break;
109
		if (pdev)
110
			pci_stop_and_remove_bus_device_locked(pdev);
111 112 113 114 115 116 117 118 119 120 121

		ret = zpci_disable_device(zdev);
		if (ret)
			break;

		ret = sclp_pci_deconfigure(zdev->fid);
		zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
		if (!ret)
			zdev->state = ZPCI_FN_STATE_STANDBY;

		break;
S
Sebastian Ott 已提交
122 123 124
	case 0x0304: /* Configured -> Standby|Reserved */
		if (!zdev)
			break;
125 126 127 128
		if (pdev) {
			/* Give the driver a hint that the function is
			 * already unusable. */
			pdev->error_state = pci_channel_io_perm_failure;
129
			pci_stop_and_remove_bus_device_locked(pdev);
130
		}
131 132

		zdev->state = ZPCI_FN_STATE_STANDBY;
S
Sebastian Ott 已提交
133 134
		if (!clp_get_state(ccdf->fid, &state) &&
		    state == ZPCI_FN_STATE_RESERVED) {
P
Pierre Morel 已提交
135
			zpci_zdev_put(zdev);
S
Sebastian Ott 已提交
136
		}
137 138
		break;
	case 0x0306: /* 0x308 or 0x302 for multiple devices */
S
Sebastian Ott 已提交
139
		clp_rescan_pci_devices();
140
		break;
141
	case 0x0308: /* Standby -> Reserved */
142 143
		if (!zdev)
			break;
P
Pierre Morel 已提交
144
		zpci_zdev_put(zdev);
145
		break;
146 147 148 149
	default:
		break;
	}
}
150 151 152 153 154 155

void zpci_event_availability(void *data)
{
	if (zpci_is_enabled())
		__zpci_event_availability(data);
}