powerpc/eeh: Fix improper condition in eeh_pci_enable()
authorGavin Shan <gwshan@linux.vnet.ibm.com>
Tue, 30 Sep 2014 02:39:00 +0000 (12:39 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 30 Sep 2014 07:15:13 +0000 (17:15 +1000)
The function eeh_pci_enable() is called to apply various requests
to one particular PE: Enabling EEH, Disabling EEH, Enabling IO,
Enabling DMA, Freezing PE. When enabling IO or DMA on one specific
PE, we need check that IO or DMA isn't enabled previously. But
the condition used to do the check isn't completely correct because
one PE would be in DMA frozen state with workable IO path, or vice
versa.

The patch fixes the improper condition.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/kernel/eeh.c

index f5677684429e3cc0c84b52cf3d3918bd2c32dca9..b79a8331965f7e003c86ded4aaa9f6ddae1b7fde 100644 (file)
@@ -579,25 +579,51 @@ EXPORT_SYMBOL(eeh_check_failure);
  */
 int eeh_pci_enable(struct eeh_pe *pe, int function)
 {
-       int rc, flags = (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE);
+       int active_flag, rc;
 
        /*
         * pHyp doesn't allow to enable IO or DMA on unfrozen PE.
         * Also, it's pointless to enable them on unfrozen PE. So
-        * we have the check here.
+        * we have to check before enabling IO or DMA.
         */
-       if (function == EEH_OPT_THAW_MMIO ||
-           function == EEH_OPT_THAW_DMA) {
+       switch (function) {
+       case EEH_OPT_THAW_MMIO:
+               active_flag = EEH_STATE_MMIO_ACTIVE;
+               break;
+       case EEH_OPT_THAW_DMA:
+               active_flag = EEH_STATE_DMA_ACTIVE;
+               break;
+       case EEH_OPT_DISABLE:
+       case EEH_OPT_ENABLE:
+       case EEH_OPT_FREEZE_PE:
+               active_flag = 0;
+               break;
+       default:
+               pr_warn("%s: Invalid function %d\n",
+                       __func__, function);
+               return -EINVAL;
+       }
+
+       /*
+        * Check if IO or DMA has been enabled before
+        * enabling them.
+        */
+       if (active_flag) {
                rc = eeh_ops->get_state(pe, NULL);
                if (rc < 0)
                        return rc;
 
-               /* Needn't to enable or already enabled */
-               if ((rc == EEH_STATE_NOT_SUPPORT) ||
-                   ((rc & flags) == flags))
+               /* Needn't enable it at all */
+               if (rc == EEH_STATE_NOT_SUPPORT)
+                       return 0;
+
+               /* It's already enabled */
+               if (rc & active_flag)
                        return 0;
        }
 
+
+       /* Issue the request */
        rc = eeh_ops->set_option(pe, function);
        if (rc)
                pr_warn("%s: Unexpected state change %d on "
@@ -605,17 +631,17 @@ int eeh_pci_enable(struct eeh_pe *pe, int function)
                        __func__, function, pe->phb->global_number,
                        pe->addr, rc);
 
-       rc = eeh_ops->wait_state(pe, PCI_BUS_RESET_WAIT_MSEC);
-       if (rc <= 0)
-               return rc;
+       /* Check if the request is finished successfully */
+       if (active_flag) {
+               rc = eeh_ops->wait_state(pe, PCI_BUS_RESET_WAIT_MSEC);
+               if (rc <= 0)
+                       return rc;
 
-       if ((function == EEH_OPT_THAW_MMIO) &&
-           (rc & EEH_STATE_MMIO_ENABLED))
-               return 0;
+               if (rc & active_flag)
+                       return 0;
 
-       if ((function == EEH_OPT_THAW_DMA) &&
-           (rc & EEH_STATE_DMA_ENABLED))
-               return 0;
+               return -EIO;
+       }
 
        return rc;
 }
This page took 0.026947 seconds and 5 git commands to generate.