Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/pci-2.6
[sfrench/cifs-2.6.git] / drivers / pci / hotplug / cpqphp_ctrl.c
index 10a5a7674a8acb8d3a0bc602a5ce2789a349538e..37d72f123a80f65d05c703446b7f353aa55d8844 100644 (file)
@@ -26,7 +26,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
@@ -37,6 +36,7 @@
 #include <linux/wait.h>
 #include <linux/smp_lock.h>
 #include <linux/pci.h>
+#include <linux/pci_hotplug.h>
 #include "cpqphp.h"
 
 static u32 configure_new_device(struct controller* ctrl, struct pci_func *func,
@@ -890,7 +890,7 @@ int cpqhp_resource_sort_and_combine(struct pci_resource **head)
 }
 
 
-irqreturn_t cpqhp_ctrl_intr(int IRQ, void *data, struct pt_regs *regs)
+irqreturn_t cpqhp_ctrl_intr(int IRQ, void *data)
 {
        struct controller *ctrl = data;
        u8 schedule_flag = 0;
@@ -1282,9 +1282,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
        u8 hp_slot;
        u8 temp_byte;
        u8 adapter_speed;
-       u32 index;
        u32 rc = 0;
-       u32 src = 8;
 
        hp_slot = func->device - ctrl->slot_device_offset;
 
@@ -1299,7 +1297,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
                 **********************************/
                rc = CARD_FUNCTIONING;
        } else {
-               down(&ctrl->crit_sect);
+               mutex_lock(&ctrl->crit_sect);
 
                /* turn on board without attaching to the bus */
                enable_slot_power (ctrl, hp_slot);
@@ -1333,12 +1331,12 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
                /* Wait for SOBS to be unset */
                wait_for_ctrl_irq (ctrl);
 
-               up(&ctrl->crit_sect);
+               mutex_unlock(&ctrl->crit_sect);
 
                if (rc)
                        return rc;
 
-               down(&ctrl->crit_sect);
+               mutex_lock(&ctrl->crit_sect);
 
                slot_enable (ctrl, hp_slot);
                green_LED_blink (ctrl, hp_slot);
@@ -1350,7 +1348,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
                /* Wait for SOBS to be unset */
                wait_for_ctrl_irq (ctrl);
 
-               up(&ctrl->crit_sect);
+               mutex_unlock(&ctrl->crit_sect);
 
                /* Wait for ~1 second because of hot plug spec */
                long_delay(1*HZ);
@@ -1368,76 +1366,30 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
 
                        rc = cpqhp_configure_board(ctrl, func);
 
-                       if (rc || src) {
-                               /* If configuration fails, turn it off
-                                * Get slot won't work for devices behind
-                                * bridges, but in this case it will always be
-                                * called for the "base" bus/dev/func of an
-                                * adapter. */
+                       /* If configuration fails, turn it off
+                        * Get slot won't work for devices behind
+                        * bridges, but in this case it will always be
+                        * called for the "base" bus/dev/func of an
+                        * adapter. */
 
-                               down(&ctrl->crit_sect);
+                       mutex_lock(&ctrl->crit_sect);
 
-                               amber_LED_on (ctrl, hp_slot);
-                               green_LED_off (ctrl, hp_slot);
-                               slot_disable (ctrl, hp_slot);
-
-                               set_SOGO(ctrl);
-
-                               /* Wait for SOBS to be unset */
-                               wait_for_ctrl_irq (ctrl);
-
-                               up(&ctrl->crit_sect);
-
-                               if (rc)
-                                       return rc;
-                               else
-                                       return 1;
-                       }
-
-                       func->status = 0;
-                       func->switch_save = 0x10;
-
-                       index = 1;
-                       while (((func = cpqhp_slot_find(func->bus, func->device, index)) != NULL) && !rc) {
-                               rc |= cpqhp_configure_board(ctrl, func);
-                               index++;
-                       }
-
-                       if (rc) {
-                               /* If configuration fails, turn it off
-                                * Get slot won't work for devices behind
-                                * bridges, but in this case it will always be
-                                * called for the "base" bus/dev/func of an
-                                * adapter. */
-
-                               down(&ctrl->crit_sect);
-
-                               amber_LED_on (ctrl, hp_slot);
-                               green_LED_off (ctrl, hp_slot);
-                               slot_disable (ctrl, hp_slot);
-
-                               set_SOGO(ctrl);
-
-                               /* Wait for SOBS to be unset */
-                               wait_for_ctrl_irq (ctrl);
-
-                               up(&ctrl->crit_sect);
-
-                               return rc;
-                       }
-                       /* Done configuring so turn LED on full time */
-
-                       down(&ctrl->crit_sect);
-
-                       green_LED_on (ctrl, hp_slot);
+                       amber_LED_on (ctrl, hp_slot);
+                       green_LED_off (ctrl, hp_slot);
+                       slot_disable (ctrl, hp_slot);
 
                        set_SOGO(ctrl);
 
                        /* Wait for SOBS to be unset */
                        wait_for_ctrl_irq (ctrl);
 
-                       up(&ctrl->crit_sect);
-                       rc = 0;
+                       mutex_unlock(&ctrl->crit_sect);
+
+                       if (rc)
+                               return rc;
+                       else
+                               return 1;
+
                } else {
                        /* Something is wrong
 
@@ -1445,7 +1397,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
                         * in this case it will always be called for the "base"
                         * bus/dev/func of an adapter. */
 
-                       down(&ctrl->crit_sect);
+                       mutex_lock(&ctrl->crit_sect);
 
                        amber_LED_on (ctrl, hp_slot);
                        green_LED_off (ctrl, hp_slot);
@@ -1456,7 +1408,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
                        /* Wait for SOBS to be unset */
                        wait_for_ctrl_irq (ctrl);
 
-                       up(&ctrl->crit_sect);
+                       mutex_unlock(&ctrl->crit_sect);
                }
 
        }
@@ -1488,7 +1440,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
        dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n",
            __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot);
 
-       down(&ctrl->crit_sect);
+       mutex_lock(&ctrl->crit_sect);
 
        /* turn on board without attaching to the bus */
        enable_slot_power(ctrl, hp_slot);
@@ -1522,7 +1474,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
        /* Wait for SOBS to be unset */
        wait_for_ctrl_irq(ctrl);
 
-       up(&ctrl->crit_sect);
+       mutex_unlock(&ctrl->crit_sect);
 
        if (rc)
                return rc;
@@ -1532,7 +1484,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
        /* turn on board and blink green LED */
 
        dbg("%s: before down\n", __FUNCTION__);
-       down(&ctrl->crit_sect);
+       mutex_lock(&ctrl->crit_sect);
        dbg("%s: after down\n", __FUNCTION__);
 
        dbg("%s: before slot_enable\n", __FUNCTION__);
@@ -1553,7 +1505,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
        dbg("%s: after wait_for_ctrl_irq\n", __FUNCTION__);
 
        dbg("%s: before up\n", __FUNCTION__);
-       up(&ctrl->crit_sect);
+       mutex_unlock(&ctrl->crit_sect);
        dbg("%s: after up\n", __FUNCTION__);
 
        /* Wait for ~1 second because of hot plug spec */
@@ -1607,7 +1559,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
                cpqhp_resource_sort_and_combine(&(ctrl->bus_head));
 
                if (rc) {
-                       down(&ctrl->crit_sect);
+                       mutex_lock(&ctrl->crit_sect);
 
                        amber_LED_on (ctrl, hp_slot);
                        green_LED_off (ctrl, hp_slot);
@@ -1618,7 +1570,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
                        /* Wait for SOBS to be unset */
                        wait_for_ctrl_irq (ctrl);
 
-                       up(&ctrl->crit_sect);
+                       mutex_unlock(&ctrl->crit_sect);
                        return rc;
                } else {
                        cpqhp_save_slot_config(ctrl, func);
@@ -1640,7 +1592,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
                        }
                } while (new_slot);
 
-               down(&ctrl->crit_sect);
+               mutex_lock(&ctrl->crit_sect);
 
                green_LED_on (ctrl, hp_slot);
 
@@ -1649,9 +1601,9 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
                /* Wait for SOBS to be unset */
                wait_for_ctrl_irq (ctrl);
 
-               up(&ctrl->crit_sect);
+               mutex_unlock(&ctrl->crit_sect);
        } else {
-               down(&ctrl->crit_sect);
+               mutex_lock(&ctrl->crit_sect);
 
                amber_LED_on (ctrl, hp_slot);
                green_LED_off (ctrl, hp_slot);
@@ -1662,7 +1614,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
                /* Wait for SOBS to be unset */
                wait_for_ctrl_irq (ctrl);
 
-               up(&ctrl->crit_sect);
+               mutex_unlock(&ctrl->crit_sect);
 
                return rc;
        }
@@ -1721,7 +1673,7 @@ static u32 remove_board(struct pci_func * func, u32 replace_flag, struct control
                func->status = 0x01;
        func->configured = 0;
 
-       down(&ctrl->crit_sect);
+       mutex_lock(&ctrl->crit_sect);
 
        green_LED_off (ctrl, hp_slot);
        slot_disable (ctrl, hp_slot);
@@ -1736,7 +1688,7 @@ static u32 remove_board(struct pci_func * func, u32 replace_flag, struct control
        /* Wait for SOBS to be unset */
        wait_for_ctrl_irq (ctrl);
 
-       up(&ctrl->crit_sect);
+       mutex_unlock(&ctrl->crit_sect);
 
        if (!replace_flag && ctrl->add_support) {
                while (func) {
@@ -1794,10 +1746,8 @@ static void pushbutton_helper_thread(unsigned long data)
 static int event_thread(void* data)
 {
        struct controller *ctrl;
-       lock_kernel();
+
        daemonize("phpd_event");
-       
-       unlock_kernel();
 
        while (1) {
                dbg("!!!!event_thread sleeping\n");
@@ -1899,7 +1849,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                        dbg("button cancel\n");
                                        del_timer(&p_slot->task_event);
 
-                                       down(&ctrl->crit_sect);
+                                       mutex_lock(&ctrl->crit_sect);
 
                                        if (p_slot->state == BLINKINGOFF_STATE) {
                                                /* slot is on */
@@ -1922,7 +1872,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                        /* Wait for SOBS to be unset */
                                        wait_for_ctrl_irq (ctrl);
 
-                                       up(&ctrl->crit_sect);
+                                       mutex_unlock(&ctrl->crit_sect);
                                }
                                /*** button Released (No action on press...) */
                                else if (ctrl->event_queue[loop].event_type == INT_BUTTON_RELEASE) {
@@ -1937,7 +1887,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                                p_slot->state = BLINKINGON_STATE;
                                                info(msg_button_on, p_slot->number);
                                        }
-                                       down(&ctrl->crit_sect);
+                                       mutex_lock(&ctrl->crit_sect);
                                        
                                        dbg("blink green LED and turn off amber\n");
                                        
@@ -1949,7 +1899,7 @@ static void interrupt_event_handler(struct controller *ctrl)
                                        /* Wait for SOBS to be unset */
                                        wait_for_ctrl_irq (ctrl);
 
-                                       up(&ctrl->crit_sect);
+                                       mutex_unlock(&ctrl->crit_sect);
                                        init_timer(&p_slot->task_event);
                                        p_slot->hp_slot = hp_slot;
                                        p_slot->ctrl = ctrl;
@@ -2630,29 +2580,15 @@ static int configure_new_function(struct controller *ctrl, struct pci_func *func
                        hold_mem_node = NULL;
                }
 
-               /* If we have prefetchable memory resources copy them and 
-                * fill in the bridge's memory range registers.  Otherwise,
-                * fill in the range registers with values that disable them. */
-               if (p_mem_node) {
-                       memcpy(hold_p_mem_node, p_mem_node, sizeof(struct pci_resource));
-                       p_mem_node->next = NULL;
-
-                       /* set Pre Mem base and Limit registers */
-                       temp_word = p_mem_node->base >> 16;
-                       rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
+               memcpy(hold_p_mem_node, p_mem_node, sizeof(struct pci_resource));
+               p_mem_node->next = NULL;
 
-                       temp_word = (p_mem_node->base + p_mem_node->length - 1) >> 16;
-                       rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
-               } else {
-                       temp_word = 0xFFFF;
-                       rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
-
-                       temp_word = 0x0000;
-                       rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
+               /* set Pre Mem base and Limit registers */
+               temp_word = p_mem_node->base >> 16;
+               rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
 
-                       kfree(hold_p_mem_node);
-                       hold_p_mem_node = NULL;
-               }
+               temp_word = (p_mem_node->base + p_mem_node->length - 1) >> 16;
+               rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
 
                /* Adjust this to compensate for extra adjustment in first loop */
                irqs.barber_pole--;