]> err.no Git - linux-2.6/blobdiff - drivers/pci/hotplug/shpchp_hpc.c
shpchp: remove unnecessary cmd_busy member from struct controller
[linux-2.6] / drivers / pci / hotplug / shpchp_hpc.c
index 45facaad39bddc4ecec7135c0651408a31d0ac73..bbe450f098e6eaa9447cc722e1df769e9d628b43 100644 (file)
@@ -218,7 +218,7 @@ static spinlock_t list_lock;
 
 static atomic_t shpchp_num_controllers = ATOMIC_INIT(0);
 
-static irqreturn_t shpc_isr(int irq, void *dev_id, struct pt_regs *regs);
+static irqreturn_t shpc_isr(int irq, void *dev_id);
 static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec);
 static int hpc_check_cmd_status(struct controller *ctrl);
 
@@ -276,7 +276,7 @@ static void int_poll_timeout(unsigned long lphp_ctlr)
        DBG_ENTER_ROUTINE
 
        /* Poll for interrupt events.  regs == NULL => polling */
-       shpc_isr(0, php_ctlr->callback_instance_id, NULL);
+       shpc_isr(0, php_ctlr->callback_instance_id);
 
        init_timer(&php_ctlr->int_poll_timer);
        if (!shpchp_poll_time)
@@ -302,21 +302,51 @@ static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec)
        add_timer(&php_ctlr->int_poll_timer);
 }
 
+static inline int is_ctrl_busy(struct controller *ctrl)
+{
+       u16 cmd_status = shpc_readw(ctrl, CMD_STATUS);
+       return cmd_status & 0x1;
+}
+
+/*
+ * Returns 1 if SHPC finishes executing a command within 1 sec,
+ * otherwise returns 0.
+ */
+static inline int shpc_poll_ctrl_busy(struct controller *ctrl)
+{
+       int i;
+
+       if (!is_ctrl_busy(ctrl))
+               return 1;
+
+       /* Check every 0.1 sec for a total of 1 sec */
+       for (i = 0; i < 10; i++) {
+               msleep(100);
+               if (!is_ctrl_busy(ctrl))
+                       return 1;
+       }
+
+       return 0;
+}
+
 static inline int shpc_wait_cmd(struct controller *ctrl)
 {
        int retval = 0;
-       unsigned int timeout_msec = shpchp_poll_mode ? 2000 : 1000;
-       unsigned long timeout = msecs_to_jiffies(timeout_msec);
-       int rc = wait_event_interruptible_timeout(ctrl->queue,
-                                                 !ctrl->cmd_busy, timeout);
-       if (!rc) {
+       unsigned long timeout = msecs_to_jiffies(1000);
+       int rc;
+
+       if (shpchp_poll_mode)
+               rc = shpc_poll_ctrl_busy(ctrl);
+       else
+               rc = wait_event_interruptible_timeout(ctrl->queue,
+                                               !is_ctrl_busy(ctrl), timeout);
+       if (!rc && is_ctrl_busy(ctrl)) {
                retval = -EIO;
-               err("Command not completed in %d msec\n", timeout_msec);
+               err("Command not completed in 1000 msec\n");
        } else if (rc < 0) {
                retval = -EINTR;
                info("Command was interrupted by a signal\n");
        }
-       ctrl->cmd_busy = 0;
 
        return retval;
 }
@@ -327,26 +357,15 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
        u16 cmd_status;
        int retval = 0;
        u16 temp_word;
-       int i;
 
        DBG_ENTER_ROUTINE 
 
        mutex_lock(&slot->ctrl->cmd_lock);
 
-       for (i = 0; i < 10; i++) {
-               cmd_status = shpc_readw(ctrl, CMD_STATUS);
-               
-               if (!(cmd_status & 0x1))
-                       break;
-               /*  Check every 0.1 sec for a total of 1 sec*/
-               msleep(100);
-       }
-
-       cmd_status = shpc_readw(ctrl, CMD_STATUS);
-       
-       if (cmd_status & 0x1) { 
+       if (!shpc_poll_ctrl_busy(ctrl)) {
                /* After 1 sec and and the controller is still busy */
-               err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__);
+               err("%s : Controller is still busy after 1 sec.\n",
+                   __FUNCTION__);
                retval = -EBUSY;
                goto out;
        }
@@ -358,7 +377,6 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
        /* To make sure the Controller Busy bit is 0 before we send out the
         * command. 
         */
-       slot->ctrl->cmd_busy = 1;
        shpc_writew(ctrl, CMD, temp_word);
 
        /*
@@ -870,7 +888,7 @@ static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
        return retval;
 }
 
-static irqreturn_t shpc_isr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t shpc_isr(int irq, void *dev_id)
 {
        struct controller *ctrl = (struct controller *)dev_id;
        struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
@@ -908,7 +926,6 @@ static irqreturn_t shpc_isr(int irq, void *dev_id, struct pt_regs *regs)
                serr_int &= ~SERR_INTR_RSVDZ_MASK;
                shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
 
-               ctrl->cmd_busy = 0;
                wake_up_interruptible(&ctrl->queue);
        }
 
@@ -1246,7 +1263,7 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
                } else
                        php_ctlr->irq = pdev->irq;
                
-               rc = request_irq(php_ctlr->irq, shpc_isr, SA_SHIRQ, MY_NAME, (void *) ctrl);
+               rc = request_irq(php_ctlr->irq, shpc_isr, IRQF_SHARED, MY_NAME, (void *) ctrl);
                dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc);
                if (rc) {
                        err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);