The address of passed PCI devices (domain:bus:slot:func) might be
quite different from the perspective of host and guest. We have to
trace the address mapping so that we can emulate EEH RTAS requests
from guest. The patch introduces additional fields to eeh_pe and
eeh_dev for the purpose.
Also, the patch adds function eeh_vfio_pe_get() and eeh_vfio_dev_get()
to search EEH PE or device according to the given guest address. Both
of them will be used by subsequent patches.
Signed-off-by: Gavin Shan gws...@linux.vnet.ibm.com
---
arch/powerpc/include/asm/eeh.h | 52 +++
arch/powerpc/kernel/eeh_pe.c | 80 ++
2 files changed, 132 insertions(+)
diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
index 7782056..96dabfc 100644
--- a/arch/powerpc/include/asm/eeh.h
+++ b/arch/powerpc/include/asm/eeh.h
@@ -48,6 +48,14 @@ struct device_node;
#define EEH_PE_RST_HOLD_TIME 250
#define EEH_PE_RST_SETTLE_TIME 1800
+#ifdef CONFIG_VFIO_EEH
+struct eeh_vfio_pci_addr {
+ uint64_tbuid; /* PHB BUID */
+ uint16_tconfig_addr;/* Bus/Device/Function number */
+ uint32_tpe_addr;/* PE configuration address */
+};
+#endif /* CONFIG_VFIO_EEH */
+
/*
* The struct is used to trace PE related EEH functionality.
* In theory, there will have one instance of the struct to
@@ -72,6 +80,7 @@ struct device_node;
#define EEH_PE_RESET (1 2)/* PE reset in progress */
#define EEH_PE_KEEP(1 8)/* Keep PE on hotplug */
+#define EEH_PE_PASSTHROUGH (1 9)/* PE owned by guest*/
struct eeh_pe {
int type; /* PE type: PHB/Bus/Device */
@@ -85,6 +94,9 @@ struct eeh_pe {
struct timeval tstamp; /* Time on first-time freeze*/
int false_positives;/* Times of reported #ff's */
struct eeh_pe *parent; /* Parent PE*/
+#ifdef CONFIG_VFIO_EEH
+ struct eeh_vfio_pci_addr guest_addr;
+#endif
struct list_head child_list;/* Link PE to the child list*/
struct list_head edevs; /* Link list of EEH devices */
struct list_head child; /* Child PEs*/
@@ -93,6 +105,21 @@ struct eeh_pe {
#define eeh_pe_for_each_dev(pe, edev, tmp) \
list_for_each_entry_safe(edev, tmp, pe-edevs, list)
+static inline bool eeh_pe_passed(struct eeh_pe *pe)
+{
+ return pe ? !!(pe-state EEH_PE_PASSTHROUGH) : false;
+}
+
+static inline void eeh_pe_set_passed(struct eeh_pe *pe, bool passed)
+{
+ if (pe) {
+ if (passed)
+ pe-state |= EEH_PE_PASSTHROUGH;
+ else
+ pe-state = ~EEH_PE_PASSTHROUGH;
+ }
+}
+
/*
* The struct is used to trace EEH state for the associated
* PCI device node or PCI device. In future, it might
@@ -110,6 +137,7 @@ struct eeh_pe {
#define EEH_DEV_SYSFS (1 9)/* Sysfs created*/
#define EEH_DEV_REMOVED(1 10) /* Removed permanently
*/
#define EEH_DEV_FRESET (1 11) /* Fundamental reset*/
+#define EEH_DEV_PASSTHROUGH(1 12) /* Owned by guest */
struct eeh_dev {
int mode; /* EEH mode */
@@ -126,6 +154,9 @@ struct eeh_dev {
struct device_node *dn; /* Associated device node */
struct pci_dev *pdev; /* Associated PCI device*/
struct pci_bus *bus;/* PCI bus for partial hotplug */
+#ifdef CONFIG_VFIO_EEH
+ struct eeh_vfio_pci_addr guest_addr;
+#endif
};
static inline struct device_node *eeh_dev_to_of_node(struct eeh_dev *edev)
@@ -138,6 +169,21 @@ static inline struct pci_dev *eeh_dev_to_pci_dev(struct
eeh_dev *edev)
return edev ? edev-pdev : NULL;
}
+static inline bool eeh_dev_passed(struct eeh_dev *dev)
+{
+ return dev ? !!(dev-mode EEH_DEV_PASSTHROUGH) : false;
+}
+
+static inline void eeh_dev_set_passed(struct eeh_dev *dev, bool passed)
+{
+ if (dev) {
+ if (passed)
+ dev-mode |= EEH_DEV_PASSTHROUGH;
+ else
+ dev-mode = ~EEH_DEV_PASSTHROUGH;
+ }
+}
+
/* Return values from eeh_ops::next_error */
enum {
EEH_NEXT_ERR_NONE = 0,
@@ -335,6 +381,12 @@ static inline void eeh_remove_device(struct pci_dev *dev)
{ }
#define EEH_IO_ERROR_VALUE(size) (-1UL)
#endif /* CONFIG_EEH */
+
+#ifdef CONFIG_VFIO_EEH
+struct eeh_dev *eeh_vfio_dev_get(struct eeh_vfio_pci_addr *addr);
+struct eeh_pe *eeh_vfio_pe_get(struct eeh_vfio_pci_addr *addr);
+#endif /* CONFIG_VFIO_EEH */
+
#ifdef CONFIG_PPC64
/*
* MMIO read/write operations with EEH support.
diff --git a/arch/powerpc/kernel/eeh_pe.c