pciehp: fix improper info messages
[safe/jmp/linux-2.6] / drivers / pci / hotplug / shpchp_hpc.c
index f6b3bf3..446e9be 100644 (file)
 #define SLOT_EVENT_LATCH       0x2
 #define SLOT_SERR_INT_MASK     0x3
 
-static spinlock_t hpc_event_lock;
-
 DEFINE_DBG_BUFFER              /* Debug string buffer for entire HPC defined here */
 static struct php_ctlr_state_s *php_ctlr_list_head;    /* HPC state linked list */
 static int ctlr_seq_num = 0;   /* Controller sequenc # */
@@ -220,9 +218,8 @@ 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 void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds);
+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);
 
 static inline u8 shpc_readb(struct controller *ctrl, int reg)
@@ -268,59 +265,80 @@ static inline int shpc_indirect_read(struct controller *ctrl, int index,
        return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
 }
 
-/* This is the interrupt polling timeout function. */
+/*
+ * This is the interrupt polling timeout function.
+ */
 static void int_poll_timeout(unsigned long lphp_ctlr)
 {
-    struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *)lphp_ctlr;
-
-    DBG_ENTER_ROUTINE
+       struct php_ctlr_state_s *php_ctlr =
+               (struct php_ctlr_state_s *)lphp_ctlr;
 
-    if ( !php_ctlr ) {
-               err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
-               return;
-    }
+       DBG_ENTER_ROUTINE
 
-    /* Poll for interrupt events.  regs == NULL => polling */
-    shpc_isr(0, php_ctlr->callback_instance_id, NULL );
+       /* Poll for interrupt events.  regs == NULL => polling */
+       shpc_isr(0, php_ctlr->callback_instance_id);
 
-    init_timer(&php_ctlr->int_poll_timer);
+       init_timer(&php_ctlr->int_poll_timer);
        if (!shpchp_poll_time)
-               shpchp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/
+               shpchp_poll_time = 2; /* default polling interval is 2 sec */
 
-    start_int_poll_timer(php_ctlr, shpchp_poll_time);  
-       
-       return;
+       start_int_poll_timer(php_ctlr, shpchp_poll_time);
+
+       DBG_LEAVE_ROUTINE
 }
 
-/* This function starts the interrupt polling timer. */
-static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds)
+/*
+ * This function starts the interrupt polling timer.
+ */
+static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec)
 {
-    if (!php_ctlr) {
-               err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
-               return;
-       }
+       /* Clamp to sane value */
+       if ((sec <= 0) || (sec > 60))
+               sec = 2;
+
+       php_ctlr->int_poll_timer.function = &int_poll_timeout;
+       php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr;
+       php_ctlr->int_poll_timer.expires = jiffies + sec * HZ;
+       add_timer(&php_ctlr->int_poll_timer);
+}
 
-    if ( ( seconds <= 0 ) || ( seconds > 60 ) )
-        seconds = 2;            /* Clamp to sane value */
+/*
+ * 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;
+       u16 cmd_status = shpc_readw(ctrl, CMD_STATUS);
 
-    php_ctlr->int_poll_timer.function = &int_poll_timeout;
-    php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr;    /* Instance data */
-    php_ctlr->int_poll_timer.expires = jiffies + seconds * HZ;
-    add_timer(&php_ctlr->int_poll_timer);
+       if (!(cmd_status & 0x1))
+               return 1;
+
+       /* Check every 0.1 sec for a total of 1 sec */
+       for (i = 0; i < 10; i++) {
+               msleep(100);
+               cmd_status = shpc_readw(ctrl, CMD_STATUS);
+               if (!(cmd_status & 0x1))
+                       return 1;
+       }
 
-       return;
+       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);
+       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,
+                                               !ctrl->cmd_busy, timeout);
        if (!rc) {
                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");
@@ -336,26 +354,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;
        }
@@ -879,7 +886,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;
@@ -1112,7 +1119,6 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
        void *instance_id = ctrl;
        int rc, num_slots = 0;
        u8 hp_slot;
-       static int first = 1;
        u32 shpc_base_offset;
        u32 tempdword, slot_reg, slot_config;
        u8 i;
@@ -1174,11 +1180,6 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
                ctrl->mmio_size = 0x24 + 0x4 * num_slots;
        }
 
-       if (first) {
-               spin_lock_init(&hpc_event_lock);
-               first = 0;
-       }
-
        info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, 
                pdev->subsystem_device);
        
@@ -1261,7 +1262,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);