fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / powerpc / platforms / pseries / eeh.c
index 2ab9dcd..da6e536 100644 (file)
@@ -225,6 +225,7 @@ static void __eeh_mark_slot (struct device_node *dn, int mode_flag)
 
 void eeh_mark_slot (struct device_node *dn, int mode_flag)
 {
+       struct pci_dev *dev;
        dn = find_device_pe (dn);
 
        /* Back up one, since config addrs might be shared */
@@ -232,6 +233,12 @@ void eeh_mark_slot (struct device_node *dn, int mode_flag)
                dn = dn->parent;
 
        PCI_DN(dn)->eeh_mode |= mode_flag;
+
+       /* Mark the pci device too */
+       dev = PCI_DN(dn)->pcidev;
+       if (dev)
+               dev->error_state = pci_channel_io_frozen;
+
        __eeh_mark_slot (dn->child, mode_flag);
 }
 
@@ -330,6 +337,7 @@ int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
                        printk (KERN_ERR "EEH: Device driver ignored %d bad reads, panicing\n",
                                pdn->eeh_check_count);
                        dump_stack();
+                       msleep(5000);
                        
                        /* re-read the slot reset state */
                        if (read_slot_reset_state(pdn, rets) != 0)
@@ -449,7 +457,11 @@ EXPORT_SYMBOL(eeh_check_failure);
 /* ------------------------------------------------------------- */
 /* The code below deals with error recovery */
 
-/** Return negative value if a permanent error, else return
+/**
+ * eeh_slot_availability - returns error status of slot
+ * @pdn pci device node
+ *
+ * Return negative value if a permanent error, else return
  * a number of milliseconds to wait until the PCI slot is
  * ready to be used.
  */
@@ -474,11 +486,42 @@ eeh_slot_availability(struct pci_dn *pdn)
 
        printk (KERN_ERR "EEH: Slot unavailable: rc=%d, rets=%d %d %d\n",
                rc, rets[0], rets[1], rets[2]);
-       return -1;
+       return -2;
+}
+
+/**
+ * rtas_pci_enable - enable MMIO or DMA transfers for this slot
+ * @pdn pci device node
+ */
+
+int
+rtas_pci_enable(struct pci_dn *pdn, int function)
+{
+       int config_addr;
+       int rc;
+
+       /* Use PE configuration address, if present */
+       config_addr = pdn->eeh_config_addr;
+       if (pdn->eeh_pe_config_addr)
+               config_addr = pdn->eeh_pe_config_addr;
+
+       rc = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
+                      config_addr,
+                      BUID_HI(pdn->phb->buid),
+                      BUID_LO(pdn->phb->buid),
+                           function);
+
+       if (rc)
+               printk(KERN_WARNING "EEH: Cannot enable function %d, err=%d dn=%s\n",
+                       function, rc, pdn->node->full_name);
+
+       return rc;
 }
 
-/** rtas_pci_slot_reset raises/lowers the pci #RST line
- *  state: 1/0 to raise/lower the #RST
+/**
+ * rtas_pci_slot_reset - raises/lowers the pci #RST line
+ * @pdn pci device node
+ * @state: 1/0 to raise/lower the #RST
  *
  * Clear the EEH-frozen condition on a slot.  This routine
  * asserts the PCI #RST line if the 'state' argument is '1',
@@ -511,24 +554,21 @@ rtas_pci_slot_reset(struct pci_dn *pdn, int state)
                       BUID_HI(pdn->phb->buid),
                       BUID_LO(pdn->phb->buid),
                       state);
-       if (rc) {
-               printk (KERN_WARNING "EEH: Unable to reset the failed slot, (%d) #RST=%d dn=%s\n", 
+       if (rc)
+               printk (KERN_WARNING "EEH: Unable to reset the failed slot,"
+                       " (%d) #RST=%d dn=%s\n",
                        rc, state, pdn->node->full_name);
-               return;
-       }
 }
 
-/** rtas_set_slot_reset -- assert the pci #RST line for 1/4 second
- *  dn -- device node to be reset.
+/**
+ * rtas_set_slot_reset -- assert the pci #RST line for 1/4 second
+ * @pdn: pci device node to be reset.
  *
  *  Return 0 if success, else a non-zero value.
  */
 
-int
-rtas_set_slot_reset(struct pci_dn *pdn)
+static void __rtas_set_slot_reset(struct pci_dn *pdn)
 {
-       int i, rc;
-
        rtas_pci_slot_reset (pdn, 1);
 
        /* The PCI bus requires that the reset be held high for at least
@@ -549,17 +589,33 @@ rtas_set_slot_reset(struct pci_dn *pdn)
         * up traffic. */
 #define PCI_BUS_SETTLE_TIME_MSEC 1800
        msleep (PCI_BUS_SETTLE_TIME_MSEC);
+}
+
+int rtas_set_slot_reset(struct pci_dn *pdn)
+{
+       int i, rc;
+
+       __rtas_set_slot_reset(pdn);
 
        /* Now double check with the firmware to make sure the device is
         * ready to be used; if not, wait for recovery. */
        for (i=0; i<10; i++) {
                rc = eeh_slot_availability (pdn);
-               if (rc < 0)
-                       printk (KERN_ERR "EEH: failed (%d) to reset slot %s\n", rc, pdn->node->full_name);
                if (rc == 0)
                        return 0;
-               if (rc < 0)
+
+               if (rc == -2) {
+                       printk (KERN_ERR "EEH: failed (%d) to reset slot %s\n",
+                               i, pdn->node->full_name);
+                       __rtas_set_slot_reset(pdn);
+                       continue;
+               }
+
+               if (rc < 0) {
+                       printk (KERN_ERR "EEH: unrecoverable slot failure %s\n",
+                               pdn->node->full_name);
                        return -1;
+               }
 
                msleep (rc+100);
        }
@@ -582,6 +638,8 @@ rtas_set_slot_reset(struct pci_dn *pdn)
 
 /**
  * __restore_bars - Restore the Base Address Registers
+ * @pdn: pci device node
+ *
  * Loads the PCI configuration space base address registers,
  * the expansion ROM base address, the latency timer, and etc.
  * from the saved values in the device node.
@@ -691,11 +749,11 @@ static void *early_enable_eeh(struct device_node *dn, void *data)
 {
        struct eeh_early_enable_info *info = data;
        int ret;
-       char *status = get_property(dn, "status", NULL);
-       u32 *class_code = (u32 *)get_property(dn, "class-code", NULL);
-       u32 *vendor_id = (u32 *)get_property(dn, "vendor-id", NULL);
-       u32 *device_id = (u32 *)get_property(dn, "device-id", NULL);
-       u32 *regs;
+       const char *status = get_property(dn, "status", NULL);
+       const u32 *class_code = get_property(dn, "class-code", NULL);
+       const u32 *vendor_id = get_property(dn, "vendor-id", NULL);
+       const u32 *device_id = get_property(dn, "device-id", NULL);
+       const u32 *regs;
        int enable;
        struct pci_dn *pdn = PCI_DN(dn);
 
@@ -737,7 +795,7 @@ static void *early_enable_eeh(struct device_node *dn, void *data)
 
        /* Ok... see if this device supports EEH.  Some do, some don't,
         * and the only way to find out is to check each and every one. */
-       regs = (u32 *)get_property(dn, "reg", NULL);
+       regs = get_property(dn, "reg", NULL);
        if (regs) {
                /* First register entry is addr (00BBSS00)  */
                /* Try to enable eeh */
@@ -865,7 +923,7 @@ void __init eeh_init(void)
  * on the CEC architecture, type of the device, on earlier boot
  * command-line arguments & etc.
  */
-void eeh_add_device_early(struct device_node *dn)
+static void eeh_add_device_early(struct device_node *dn)
 {
        struct pci_controller *phb;
        struct eeh_early_enable_info info;
@@ -882,7 +940,6 @@ void eeh_add_device_early(struct device_node *dn)
        info.buid_lo = BUID_LO(phb->buid);
        early_enable_eeh(dn, &info);
 }
-EXPORT_SYMBOL_GPL(eeh_add_device_early);
 
 void eeh_add_device_tree_early(struct device_node *dn)
 {
@@ -893,20 +950,6 @@ void eeh_add_device_tree_early(struct device_node *dn)
 }
 EXPORT_SYMBOL_GPL(eeh_add_device_tree_early);
 
-void eeh_add_device_tree_late(struct pci_bus *bus)
-{
-       struct pci_dev *dev;
-
-       list_for_each_entry(dev, &bus->devices, bus_list) {
-               eeh_add_device_late(dev);
-               if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
-                       struct pci_bus *subbus = dev->subordinate;
-                       if (subbus)
-                               eeh_add_device_tree_late(subbus);
-               }
-       }
-}
-
 /**
  * eeh_add_device_late - perform EEH initialization for the indicated pci device
  * @dev: pci device for which to set up EEH
@@ -914,7 +957,7 @@ void eeh_add_device_tree_late(struct pci_bus *bus)
  * This routine must be used to complete EEH initialization for PCI
  * devices that were added after system boot (e.g. hotplug, dlpar).
  */
-void eeh_add_device_late(struct pci_dev *dev)
+static void eeh_add_device_late(struct pci_dev *dev)
 {
        struct device_node *dn;
        struct pci_dn *pdn;
@@ -933,16 +976,33 @@ void eeh_add_device_late(struct pci_dev *dev)
 
        pci_addr_cache_insert_device (dev);
 }
-EXPORT_SYMBOL_GPL(eeh_add_device_late);
+
+void eeh_add_device_tree_late(struct pci_bus *bus)
+{
+       struct pci_dev *dev;
+
+       list_for_each_entry(dev, &bus->devices, bus_list) {
+               eeh_add_device_late(dev);
+               if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
+                       struct pci_bus *subbus = dev->subordinate;
+                       if (subbus)
+                               eeh_add_device_tree_late(subbus);
+               }
+       }
+}
+EXPORT_SYMBOL_GPL(eeh_add_device_tree_late);
 
 /**
  * eeh_remove_device - undo EEH setup for the indicated pci device
  * @dev: pci device to be removed
  *
- * This routine should be when a device is removed from a running
- * system (e.g. by hotplug or dlpar).
+ * This routine should be called when a device is removed from
+ * a running system (e.g. by hotplug or dlpar).  It unregisters
+ * the PCI device from the EEH subsystem.  I/O errors affecting
+ * this device will no longer be detected after this call; thus,
+ * i/o errors affecting this slot may leave this device unusable.
  */
-void eeh_remove_device(struct pci_dev *dev)
+static void eeh_remove_device(struct pci_dev *dev)
 {
        struct device_node *dn;
        if (!dev || !eeh_subsystem_enabled)
@@ -955,24 +1015,22 @@ void eeh_remove_device(struct pci_dev *dev)
        pci_addr_cache_remove_device(dev);
 
        dn = pci_device_to_OF_node(dev);
-       PCI_DN(dn)->pcidev = NULL;
-       pci_dev_put (dev);
+       if (PCI_DN(dn)->pcidev) {
+               PCI_DN(dn)->pcidev = NULL;
+               pci_dev_put (dev);
+       }
 }
-EXPORT_SYMBOL_GPL(eeh_remove_device);
 
 void eeh_remove_bus_device(struct pci_dev *dev)
 {
+       struct pci_bus *bus = dev->subordinate;
+       struct pci_dev *child, *tmp;
+
        eeh_remove_device(dev);
-       if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
-               struct pci_bus *bus = dev->subordinate;
-               struct list_head *ln;
-               if (!bus)
-                       return; 
-               for (ln = bus->devices.next; ln != &bus->devices; ln = ln->next) {
-                       struct pci_dev *pdev = pci_dev_b(ln);
-                       if (pdev)
-                               eeh_remove_bus_device(pdev);
-               }
+
+       if (bus && dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
+               list_for_each_entry_safe(child, tmp, &bus->devices, bus_list)
+                        eeh_remove_bus_device(child);
        }
 }
 EXPORT_SYMBOL_GPL(eeh_remove_bus_device);
@@ -1018,7 +1076,7 @@ static int __init eeh_init_proc(void)
 {
        struct proc_dir_entry *e;
 
-       if (platform_is_pseries()) {
+       if (machine_is(pseries)) {
                e = create_proc_entry("ppc64/eeh", 0, NULL);
                if (e)
                        e->proc_fops = &proc_eeh_operations;