Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / drivers / pci / hotplug / pciehp_core.c
index c748a19..c248554 100644 (file)
@@ -126,8 +126,10 @@ static int set_lock_status(struct hotplug_slot *hotplug_slot, u8 status)
        mutex_lock(&slot->ctrl->crit_sect);
 
        /* has it been >1 sec since our last toggle? */
-       if ((get_seconds() - slot->last_emi_toggle) < 1)
+       if ((get_seconds() - slot->last_emi_toggle) < 1) {
+               mutex_unlock(&slot->ctrl->crit_sect);
                return -EINVAL;
+       }
 
        /* see what our current state is */
        retval = get_lock_status(hotplug_slot, &value);
@@ -184,8 +186,8 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
 {
        struct slot *slot = hotplug_slot->private;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                __func__, hotplug_slot_name(hotplug_slot));
 
        kfree(hotplug_slot->info);
        kfree(hotplug_slot);
@@ -196,7 +198,7 @@ static int init_slots(struct controller *ctrl)
        struct slot *slot;
        struct hotplug_slot *hotplug_slot;
        struct hotplug_slot_info *info;
-       int len, dup = 1;
+       char name[SLOT_NAME_SIZE];
        int retval = -ENOMEM;
 
        list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
@@ -210,48 +212,37 @@ static int init_slots(struct controller *ctrl)
 
                /* register this slot with the hotplug pci core */
                hotplug_slot->info = info;
-               hotplug_slot->name = slot->name;
                hotplug_slot->private = slot;
                hotplug_slot->release = &release_slot;
                hotplug_slot->ops = &pciehp_hotplug_slot_ops;
-               get_power_status(hotplug_slot, &info->power_status);
-               get_attention_status(hotplug_slot, &info->attention_status);
-               get_latch_status(hotplug_slot, &info->latch_status);
-               get_adapter_status(hotplug_slot, &info->adapter_status);
                slot->hotplug_slot = hotplug_slot;
+               snprintf(name, SLOT_NAME_SIZE, "%u", slot->number);
 
-               ctrl_dbg(ctrl, "Registering bus=%x dev=%x hp_slot=%x sun=%x "
-                        "slot_device_offset=%x\n", slot->bus, slot->device,
-                        slot->hp_slot, slot->number, ctrl->slot_device_offset);
-duplicate_name:
+               ctrl_dbg(ctrl, "Registering domain:bus:dev=%04x:%02x:%02x "
+                        "hp_slot=%x sun=%x slot_device_offset=%x\n",
+                        pci_domain_nr(ctrl->pci_dev->subordinate),
+                        slot->bus, slot->device, slot->hp_slot, slot->number,
+                        ctrl->slot_device_offset);
                retval = pci_hp_register(hotplug_slot,
                                         ctrl->pci_dev->subordinate,
-                                        slot->device);
+                                        slot->device,
+                                        name);
                if (retval) {
-                       /*
-                        * If slot N already exists, we'll try to create
-                        * slot N-1, N-2 ... N-M, until we overflow.
-                        */
-                       if (retval == -EEXIST) {
-                               len = snprintf(slot->name, SLOT_NAME_SIZE,
-                                              "%d-%d", slot->number, dup++);
-                               if (len < SLOT_NAME_SIZE)
-                                       goto duplicate_name;
-                               else
-                                       ctrl_err(ctrl, "duplicate slot name "
-                                                "overflow\n");
-                       }
                        ctrl_err(ctrl, "pci_hp_register failed with error %d\n",
                                 retval);
                        goto error_info;
                }
+               get_power_status(hotplug_slot, &info->power_status);
+               get_attention_status(hotplug_slot, &info->attention_status);
+               get_latch_status(hotplug_slot, &info->latch_status);
+               get_adapter_status(hotplug_slot, &info->adapter_status);
                /* create additional sysfs entries */
                if (EMI(ctrl)) {
                        retval = sysfs_create_file(&hotplug_slot->pci_slot->kobj,
                                &hotplug_slot_attr_lock.attr);
                        if (retval) {
                                pci_hp_deregister(hotplug_slot);
-                               ctrl_err(ctrl, "cannot create additional sysfs "
+                               ctrl_err(ctrl, "Cannot create additional sysfs "
                                         "entries\n");
                                goto error_info;
                        }
@@ -286,8 +277,8 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
 {
        struct slot *slot = hotplug_slot->private;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                 __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                 __func__, slot_name(slot));
 
        hotplug_slot->info->attention_status = status;
 
@@ -302,8 +293,8 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
 {
        struct slot *slot = hotplug_slot->private;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                __func__, slot_name(slot));
 
        return pciehp_sysfs_enable_slot(slot);
 }
@@ -313,8 +304,8 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
 {
        struct slot *slot = hotplug_slot->private;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                 __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                 __func__, slot_name(slot));
 
        return pciehp_sysfs_disable_slot(slot);
 }
@@ -324,8 +315,8 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
        struct slot *slot = hotplug_slot->private;
        int retval;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                 __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                 __func__, slot_name(slot));
 
        retval = slot->hpc_ops->get_power_status(slot, value);
        if (retval < 0)
@@ -339,8 +330,8 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
        struct slot *slot = hotplug_slot->private;
        int retval;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                 __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                 __func__, slot_name(slot));
 
        retval = slot->hpc_ops->get_attention_status(slot, value);
        if (retval < 0)
@@ -354,8 +345,8 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
        struct slot *slot = hotplug_slot->private;
        int retval;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                __func__, slot_name(slot));
 
        retval = slot->hpc_ops->get_latch_status(slot, value);
        if (retval < 0)
@@ -369,8 +360,8 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
        struct slot *slot = hotplug_slot->private;
        int retval;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                __func__, slot_name(slot));
 
        retval = slot->hpc_ops->get_adapter_status(slot, value);
        if (retval < 0)
@@ -385,8 +376,8 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
        struct slot *slot = hotplug_slot->private;
        int retval;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                __func__, slot_name(slot));
 
        retval = slot->hpc_ops->get_max_bus_speed(slot, value);
        if (retval < 0)
@@ -400,8 +391,8 @@ static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe
        struct slot *slot = hotplug_slot->private;
        int retval;
 
-       ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
-                __func__, hotplug_slot->name);
+       ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
+                __func__, slot_name(slot));
 
        retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
        if (retval < 0)
@@ -427,7 +418,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
 
        ctrl = pcie_init(dev);
        if (!ctrl) {
-               dev_err(&dev->device, "controller initialization failed\n");
+               dev_err(&dev->device, "Controller initialization failed\n");
                goto err_out_none;
        }
        set_service_data(dev, ctrl);
@@ -436,25 +427,26 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
        rc = init_slots(ctrl);
        if (rc) {
                if (rc == -EBUSY)
-                       ctrl_warn(ctrl, "slot already registered by another "
+                       ctrl_warn(ctrl, "Slot already registered by another "
                                  "hotplug driver\n");
                else
-                       ctrl_err(ctrl, "slot initialization failed\n");
+                       ctrl_err(ctrl, "Slot initialization failed\n");
                goto err_out_release_ctlr;
        }
 
+       /* Check if slot is occupied */
        t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset);
-
-       t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */
-       if (value && pciehp_force) {
-               rc = pciehp_enable_slot(t_slot);
-               if (rc) /* -ENODEV: shouldn't happen, but deal with it */
-                       value = 0;
-       }
-       if ((POWER_CTRL(ctrl)) && !value) {
-               rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/
-               if (rc)
-                       goto err_out_free_ctrl_slot;
+       t_slot->hpc_ops->get_adapter_status(t_slot, &value);
+       if (value) {
+               if (pciehp_force)
+                       pciehp_enable_slot(t_slot);
+       } else {
+               /* Power off slot if not occupied */
+               if (POWER_CTRL(ctrl)) {
+                       rc = t_slot->hpc_ops->power_off_slot(t_slot);
+                       if (rc)
+                               goto err_out_free_ctrl_slot;
+               }
        }
 
        return 0;
@@ -532,11 +524,12 @@ static int __init pcied_init(void)
 {
        int retval = 0;
 
+       pciehp_firmware_init();
        retval = pcie_port_service_register(&hpdriver_portdrv);
        dbg("pcie_port_service_register = %d\n", retval);
        info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
        if (retval)
-               dbg("%s: Failure to register service\n", __func__);
+               dbg("Failure to register service\n");
        return retval;
 }