Merge branch 'master' into gfs2
[pandora-kernel.git] / drivers / pci / hotplug / pciehp_ctrl.c
index 5e582ec..41290a1 100644 (file)
@@ -207,7 +207,6 @@ u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
                 * power fault Cleared
                 */
                info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot);
-               p_slot->status = 0x00;
                taskInfo->event_type = INT_POWER_FAULT_CLEAR;
        } else {
                /*
@@ -215,8 +214,6 @@ u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
                 */
                info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot);
                taskInfo->event_type = INT_POWER_FAULT;
-               /* set power fault status for this board */
-               p_slot->status = 0xFF;
                info("power fault bit %x set\n", hp_slot);
        }
        if (rc)
@@ -232,13 +229,13 @@ u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
 static void set_slot_off(struct controller *ctrl, struct slot * pslot)
 {
        /* Wait for exclusive access to hardware */
-       down(&ctrl->crit_sect);
+       mutex_lock(&ctrl->crit_sect);
 
        /* turn off slot, turn on Amber LED, turn off Green LED if supported*/
        if (POWER_CTRL(ctrl->ctrlcap)) {
                if (pslot->hpc_ops->power_off_slot(pslot)) {   
                        err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
-                       up(&ctrl->crit_sect);
+                       mutex_unlock(&ctrl->crit_sect);
                        return;
                }
                wait_for_ctrl_irq (ctrl);
@@ -252,14 +249,14 @@ static void set_slot_off(struct controller *ctrl, struct slot * pslot)
        if (ATTN_LED(ctrl->ctrlcap)) { 
                if (pslot->hpc_ops->set_attention_status(pslot, 1)) {   
                        err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
-                       up(&ctrl->crit_sect);
+                       mutex_unlock(&ctrl->crit_sect);
                        return;
                }
                wait_for_ctrl_irq (ctrl);
        }
 
        /* Done with exclusive hardware access */
-       up(&ctrl->crit_sect);
+       mutex_unlock(&ctrl->crit_sect);
 }
 
 /**
@@ -282,13 +279,13 @@ static int board_added(struct slot *p_slot)
                        ctrl->slot_device_offset, hp_slot);
 
        /* Wait for exclusive access to hardware */
-       down(&ctrl->crit_sect);
+       mutex_lock(&ctrl->crit_sect);
 
        if (POWER_CTRL(ctrl->ctrlcap)) {
                /* Power on slot */
                rc = p_slot->hpc_ops->power_on_slot(p_slot);
                if (rc) {
-                       up(&ctrl->crit_sect);
+                       mutex_unlock(&ctrl->crit_sect);
                        return -1;
                }
 
@@ -304,7 +301,7 @@ static int board_added(struct slot *p_slot)
        }
 
        /* Done with exclusive hardware access */
-       up(&ctrl->crit_sect);
+       mutex_unlock(&ctrl->crit_sect);
 
        /* Wait for ~1 second */
        wait_for_ctrl_irq (ctrl);
@@ -317,13 +314,10 @@ static int board_added(struct slot *p_slot)
                return rc;
        }
 
-       dbg("%s: slot status = %x\n", __FUNCTION__, p_slot->status);
-
        /* Check for a power fault */
-       if (p_slot->status == 0xFF) {
-               /* power fault occurred, but it was benign */
+       if (p_slot->hpc_ops->query_power_fault(p_slot)) {
+               dbg("%s: power fault detected\n", __FUNCTION__);
                rc = POWER_FAILURE;
-               p_slot->status = 0;
                goto err_exit;
        }
 
@@ -334,8 +328,6 @@ static int board_added(struct slot *p_slot)
                goto err_exit;
        }
 
-       p_slot->status = 0;
-
        /*
         * Some PCI Express root ports require fixup after hot-plug operation.
         */
@@ -343,7 +335,7 @@ static int board_added(struct slot *p_slot)
                pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
        if (PWR_LED(ctrl->ctrlcap)) {
                /* Wait for exclusive access to hardware */
-               down(&ctrl->crit_sect);
+               mutex_lock(&ctrl->crit_sect);
 
                p_slot->hpc_ops->green_led_on(p_slot);
   
@@ -351,7 +343,7 @@ static int board_added(struct slot *p_slot)
                wait_for_ctrl_irq (ctrl);
        
                /* Done with exclusive hardware access */
-               up(&ctrl->crit_sect);
+               mutex_unlock(&ctrl->crit_sect);
        }
        return 0;
 
@@ -382,18 +374,15 @@ static int remove_board(struct slot *p_slot)
 
        dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
 
-       /* Change status to shutdown */
-       p_slot->status = 0x01;
-
        /* Wait for exclusive access to hardware */
-       down(&ctrl->crit_sect);
+       mutex_lock(&ctrl->crit_sect);
 
        if (POWER_CTRL(ctrl->ctrlcap)) {
                /* power off slot */
                rc = p_slot->hpc_ops->power_off_slot(p_slot);
                if (rc) {
                        err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
-                       up(&ctrl->crit_sect);
+                       mutex_unlock(&ctrl->crit_sect);
                        return rc;
                }
                /* Wait for the command to complete */
@@ -409,7 +398,7 @@ static int remove_board(struct slot *p_slot)
        }
 
        /* Done with exclusive hardware access */
-       up(&ctrl->crit_sect);
+       mutex_unlock(&ctrl->crit_sect);
 
        return 0;
 }
@@ -456,7 +445,7 @@ static void pciehp_pushbutton_thread(unsigned long slot)
 
                if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
                        /* Wait for exclusive access to hardware */
-                       down(&p_slot->ctrl->crit_sect);
+                       mutex_lock(&p_slot->ctrl->crit_sect);
 
                        p_slot->hpc_ops->green_led_off(p_slot);
 
@@ -464,7 +453,7 @@ static void pciehp_pushbutton_thread(unsigned long slot)
                        wait_for_ctrl_irq (p_slot->ctrl);
 
                        /* Done with exclusive hardware access */
-                       up(&p_slot->ctrl->crit_sect);
+                       mutex_unlock(&p_slot->ctrl->crit_sect);
                }
                p_slot->state = STATIC_STATE;
        }
@@ -506,7 +495,7 @@ static void pciehp_surprise_rm_thread(unsigned long slot)
 
                if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
                        /* Wait for exclusive access to hardware */
-                       down(&p_slot->ctrl->crit_sect);
+                       mutex_lock(&p_slot->ctrl->crit_sect);
 
                        p_slot->hpc_ops->green_led_off(p_slot);
 
@@ -514,7 +503,7 @@ static void pciehp_surprise_rm_thread(unsigned long slot)
                        wait_for_ctrl_irq (p_slot->ctrl);
 
                        /* Done with exclusive hardware access */
-                       up(&p_slot->ctrl->crit_sect);
+                       mutex_unlock(&p_slot->ctrl->crit_sect);
                }
                p_slot->state = STATIC_STATE;
        }
@@ -627,7 +616,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                        switch (p_slot->state) {
                                        case BLINKINGOFF_STATE:
                                                /* Wait for exclusive access to hardware */
-                                               down(&ctrl->crit_sect);
+                                               mutex_lock(&ctrl->crit_sect);
                                                
                                                if (PWR_LED(ctrl->ctrlcap)) {
                                                        p_slot->hpc_ops->green_led_on(p_slot);
@@ -641,11 +630,11 @@ static void interrupt_event_handler(struct controller *ctrl)
                                                        wait_for_ctrl_irq (ctrl);
                                                }
                                                /* Done with exclusive hardware access */
-                                               up(&ctrl->crit_sect);
+                                               mutex_unlock(&ctrl->crit_sect);
                                                break;
                                        case BLINKINGON_STATE:
                                                /* Wait for exclusive access to hardware */
-                                               down(&ctrl->crit_sect);
+                                               mutex_lock(&ctrl->crit_sect);
 
                                                if (PWR_LED(ctrl->ctrlcap)) {
                                                        p_slot->hpc_ops->green_led_off(p_slot);
@@ -658,7 +647,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                                        wait_for_ctrl_irq (ctrl);
                                                }
                                                /* Done with exclusive hardware access */
-                                               up(&ctrl->crit_sect);
+                                               mutex_unlock(&ctrl->crit_sect);
 
                                                break;
                                        default:
@@ -687,7 +676,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                                }
 
                                                /* Wait for exclusive access to hardware */
-                                               down(&ctrl->crit_sect);
+                                               mutex_lock(&ctrl->crit_sect);
 
                                                /* blink green LED and turn off amber */
                                                if (PWR_LED(ctrl->ctrlcap)) {
@@ -704,7 +693,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                                }
 
                                                /* Done with exclusive hardware access */
-                                               up(&ctrl->crit_sect);
+                                               mutex_unlock(&ctrl->crit_sect);
 
                                                init_timer(&p_slot->task_event);
                                                p_slot->task_event.expires = jiffies + 5 * HZ;   /* 5 second delay */
@@ -719,7 +708,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                        if (POWER_CTRL(ctrl->ctrlcap)) {
                                                dbg("power fault\n");
                                                /* Wait for exclusive access to hardware */
-                                               down(&ctrl->crit_sect);
+                                               mutex_lock(&ctrl->crit_sect);
 
                                                if (ATTN_LED(ctrl->ctrlcap)) {
                                                        p_slot->hpc_ops->set_attention_status(p_slot, 1);
@@ -732,7 +721,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                                }
 
                                                /* Done with exclusive hardware access */
-                                               up(&ctrl->crit_sect);
+                                               mutex_unlock(&ctrl->crit_sect);
                                        }
                                }
                                /***********SURPRISE REMOVAL********************/
@@ -767,20 +756,20 @@ int pciehp_enable_slot(struct slot *p_slot)
        int rc;
 
        /* Check to see if (latch closed, card present, power off) */
-       down(&p_slot->ctrl->crit_sect);
+       mutex_lock(&p_slot->ctrl->crit_sect);
 
        rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
        if (rc || !getstatus) {
                info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
-               up(&p_slot->ctrl->crit_sect);
-               return 1;
+               mutex_unlock(&p_slot->ctrl->crit_sect);
+               return -ENODEV;
        }
        if (MRL_SENS(p_slot->ctrl->ctrlcap)) {  
                rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
                if (rc || getstatus) {
                        info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
-                       up(&p_slot->ctrl->crit_sect);
-                       return 1;
+                       mutex_unlock(&p_slot->ctrl->crit_sect);
+                       return -ENODEV;
                }
        }
        
@@ -788,11 +777,11 @@ int pciehp_enable_slot(struct slot *p_slot)
                rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
                if (rc || getstatus) {
                        info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
-                       up(&p_slot->ctrl->crit_sect);
-                       return 1;
+                       mutex_unlock(&p_slot->ctrl->crit_sect);
+                       return -EINVAL;
                }
        }
-       up(&p_slot->ctrl->crit_sect);
+       mutex_unlock(&p_slot->ctrl->crit_sect);
 
        p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
 
@@ -817,14 +806,14 @@ int pciehp_disable_slot(struct slot *p_slot)
                return 1;
 
        /* Check to see if (latch closed, card present, power on) */
-       down(&p_slot->ctrl->crit_sect);
+       mutex_lock(&p_slot->ctrl->crit_sect);
 
        if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) {       
                ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
                if (ret || !getstatus) {
                        info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
-                       up(&p_slot->ctrl->crit_sect);
-                       return 1;
+                       mutex_unlock(&p_slot->ctrl->crit_sect);
+                       return -ENODEV;
                }
        }
 
@@ -832,8 +821,8 @@ int pciehp_disable_slot(struct slot *p_slot)
                ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
                if (ret || getstatus) {
                        info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
-                       up(&p_slot->ctrl->crit_sect);
-                       return 1;
+                       mutex_unlock(&p_slot->ctrl->crit_sect);
+                       return -ENODEV;
                }
        }
 
@@ -841,12 +830,12 @@ int pciehp_disable_slot(struct slot *p_slot)
                ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
                if (ret || !getstatus) {
                        info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
-                       up(&p_slot->ctrl->crit_sect);
-                       return 1;
+                       mutex_unlock(&p_slot->ctrl->crit_sect);
+                       return -EINVAL;
                }
        }
 
-       up(&p_slot->ctrl->crit_sect);
+       mutex_unlock(&p_slot->ctrl->crit_sect);
 
        ret = remove_board(p_slot);
        update_slot_info(p_slot);