[PATCH 18/27] powerpc/eeh: PowerNV EEH backends

2013-06-15 Thread Gavin Shan
The patch adds EEH backends for PowerNV platform. It's notable that
part of those EEH backends call to the I/O chip dependent backends.

Signed-off-by: Gavin Shan sha...@linux.vnet.ibm.com
---
 arch/powerpc/platforms/powernv/Makefile  |2 +-
 arch/powerpc/platforms/powernv/eeh-powernv.c |  396 ++
 2 files changed, 397 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/platforms/powernv/eeh-powernv.c

diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index 09bd0cb..7fe5951 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -3,4 +3,4 @@ obj-y   += opal-rtc.o opal-nvram.o
 
 obj-$(CONFIG_SMP)  += smp.o
 obj-$(CONFIG_PCI)  += pci.o pci-p5ioc2.o pci-ioda.o
-obj-$(CONFIG_EEH)  += eeh-ioda.o
+obj-$(CONFIG_EEH)  += eeh-ioda.o eeh-powernv.o
diff --git a/arch/powerpc/platforms/powernv/eeh-powernv.c 
b/arch/powerpc/platforms/powernv/eeh-powernv.c
new file mode 100644
index 000..decb317
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/eeh-powernv.c
@@ -0,0 +1,396 @@
+/*
+ * The file intends to implement the platform dependent EEH operations on
+ * powernv platform. Actually, the powernv was created in order to fully
+ * hypervisor support.
+ *
+ * Copyright Benjamin Herrenschmidt  Gavin Shan, IBM Corporation 2013.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include linux/atomic.h
+#include linux/delay.h
+#include linux/export.h
+#include linux/init.h
+#include linux/list.h
+#include linux/msi.h
+#include linux/of.h
+#include linux/pci.h
+#include linux/proc_fs.h
+#include linux/rbtree.h
+#include linux/sched.h
+#include linux/seq_file.h
+#include linux/spinlock.h
+
+#include asm/eeh.h
+#include asm/eeh_event.h
+#include asm/firmware.h
+#include asm/io.h
+#include asm/iommu.h
+#include asm/machdep.h
+#include asm/msi_bitmap.h
+#include asm/opal.h
+#include asm/ppc-pci.h
+
+#include powernv.h
+#include pci.h
+
+/**
+ * powernv_eeh_init - EEH platform dependent initialization
+ *
+ * EEH platform dependent initialization on powernv
+ */
+static int powernv_eeh_init(void)
+{
+   /* We require OPALv3 */
+   if (!firmware_has_feature(FW_FEATURE_OPALv3)) {
+   pr_warning(%s: OPALv3 is required !\n, __func__);
+   return -EINVAL;
+   }
+
+   /* Set EEH probe mode */
+   eeh_probe_mode_set(EEH_PROBE_MODE_DEV);
+
+   return 0;
+}
+
+/**
+ * powernv_eeh_post_init - EEH platform dependent post initialization
+ *
+ * EEH platform dependent post initialization on powernv. When
+ * the function is called, the EEH PEs and devices should have
+ * been built. If the I/O cache staff has been built, EEH is
+ * ready to supply service.
+ */
+static int powernv_eeh_post_init(void)
+{
+   struct pci_controller *hose;
+   struct pnv_phb *phb;
+   int ret = 0;
+
+   list_for_each_entry(hose, hose_list, list_node) {
+   phb = hose-private_data;
+
+   if (phb-eeh_ops  phb-eeh_ops-post_init) {
+   ret = phb-eeh_ops-post_init(hose);
+   if (ret)
+   break;
+   }
+   }
+
+   return ret;
+}
+
+/**
+ * powernv_eeh_dev_probe - Do probe on PCI device
+ * @dev: PCI device
+ * @flag: unused
+ *
+ * When EEH module is installed during system boot, all PCI devices
+ * are checked one by one to see if it supports EEH. The function
+ * is introduced for the purpose. By default, EEH has been enabled
+ * on all PCI devices. That's to say, we only need do necessary
+ * initialization on the corresponding eeh device and create PE
+ * accordingly.
+ *
+ * It's notable that's unsafe to retrieve the EEH device through
+ * the corresponding PCI device. During the PCI device hotplug, which
+ * was possiblly triggered by EEH core, the binding between EEH device
+ * and the PCI device isn't built yet.
+ */
+static int powernv_eeh_dev_probe(struct pci_dev *dev, void *flag)
+{
+   struct pci_controller *hose = pci_bus_to_host(dev-bus);
+   struct pnv_phb *phb = hose-private_data;
+   struct device_node *dn = pci_device_to_OF_node(dev);
+   struct eeh_dev *edev = of_node_to_eeh_dev(dn);
+
+   /*
+* When probing the root bridge, which doesn't have any
+* subordinate PCI devices. We don't have OF node for
+* the root bridge. So it's not reasonable to continue
+* the probing.
+*/
+   if (!dn || !edev)
+   return 0;
+
+   /* Skip for PCI-ISA bridge */
+   if ((dev-class  8) == PCI_CLASS_BRIDGE_ISA)
+   return 0;
+
+   /* Initialize eeh device */
+   edev-class_code= dev-class;
+   edev-mode   

[PATCH 18/27] powerpc/eeh: PowerNV EEH backends

2013-06-05 Thread Gavin Shan
The patch adds EEH backends for PowerNV platform. It's notable that
part of those EEH backends call to the I/O chip dependent backends.

Signed-off-by: Gavin Shan sha...@linux.vnet.ibm.com
---
 arch/powerpc/platforms/powernv/Makefile  |2 +-
 arch/powerpc/platforms/powernv/eeh-powernv.c |  387 ++
 2 files changed, 388 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/platforms/powernv/eeh-powernv.c

diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index 09bd0cb..7fe5951 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -3,4 +3,4 @@ obj-y   += opal-rtc.o opal-nvram.o
 
 obj-$(CONFIG_SMP)  += smp.o
 obj-$(CONFIG_PCI)  += pci.o pci-p5ioc2.o pci-ioda.o
-obj-$(CONFIG_EEH)  += eeh-ioda.o
+obj-$(CONFIG_EEH)  += eeh-ioda.o eeh-powernv.o
diff --git a/arch/powerpc/platforms/powernv/eeh-powernv.c 
b/arch/powerpc/platforms/powernv/eeh-powernv.c
new file mode 100644
index 000..1530264
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/eeh-powernv.c
@@ -0,0 +1,387 @@
+/*
+ * The file intends to implement the platform dependent EEH operations on
+ * powernv platform. Actually, the powernv was created in order to fully
+ * hypervisor support.
+ *
+ * Copyright Benjamin Herrenschmidt  Gavin Shan, IBM Corporation 2013.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include linux/atomic.h
+#include linux/delay.h
+#include linux/export.h
+#include linux/init.h
+#include linux/list.h
+#include linux/msi.h
+#include linux/of.h
+#include linux/pci.h
+#include linux/proc_fs.h
+#include linux/rbtree.h
+#include linux/sched.h
+#include linux/seq_file.h
+#include linux/spinlock.h
+
+#include asm/eeh.h
+#include asm/eeh_event.h
+#include asm/firmware.h
+#include asm/io.h
+#include asm/iommu.h
+#include asm/machdep.h
+#include asm/msi_bitmap.h
+#include asm/opal.h
+#include asm/ppc-pci.h
+
+#include powernv.h
+#include pci.h
+
+/**
+ * powernv_eeh_init - EEH platform dependent initialization
+ *
+ * EEH platform dependent initialization on powernv
+ */
+static int powernv_eeh_init(void)
+{
+   /* We require OPALv3 */
+   if (!firmware_has_feature(FW_FEATURE_OPALv3)) {
+   pr_warning(%s: OPALv3 is required !\n, __func__);
+   return -EINVAL;
+   }
+
+   /* Set EEH probe mode */
+   eeh_probe_mode_set(EEH_PROBE_MODE_DEV);
+
+   return 0;
+}
+
+/**
+ * powernv_eeh_post_init - EEH platform dependent post initialization
+ *
+ * EEH platform dependent post initialization on powernv. When
+ * the function is called, the EEH PEs and devices should have
+ * been built. If the I/O cache staff has been built, EEH is
+ * ready to supply service.
+ */
+static int powernv_eeh_post_init(void)
+{
+   struct pci_controller *hose;
+   struct pnv_phb *phb;
+   int ret = 0;
+
+   list_for_each_entry(hose, hose_list, list_node) {
+   phb = hose-private_data;
+
+   if (phb-eeh_ops  phb-eeh_ops-post_init) {
+   ret = phb-eeh_ops-post_init(hose);
+   if (ret)
+   break;
+   }
+   }
+
+   return ret;
+}
+
+/**
+ * powernv_eeh_dev_probe - Do probe on PCI device
+ * @dev: PCI device
+ * @flag: unused
+ *
+ * When EEH module is installed during system boot, all PCI devices
+ * are checked one by one to see if it supports EEH. The function
+ * is introduced for the purpose. By default, EEH has been enabled
+ * on all PCI devices. That's to say, we only need do necessary
+ * initialization on the corresponding eeh device and create PE
+ * accordingly.
+ *
+ * It's notable that's unsafe to retrieve the EEH device through
+ * the corresponding PCI device. During the PCI device hotplug, which
+ * was possiblly triggered by EEH core, the binding between EEH device
+ * and the PCI device isn't built yet.
+ */
+static int powernv_eeh_dev_probe(struct pci_dev *dev, void *flag)
+{
+   struct pci_controller *hose = pci_bus_to_host(dev-bus);
+   struct pnv_phb *phb = hose-private_data;
+   struct device_node *dn = pci_device_to_OF_node(dev);
+   struct eeh_dev *edev = of_node_to_eeh_dev(dn);
+
+   /*
+* When probing the