vserver 1.9.5.x5
[linux-2.6.git] / drivers / pci / hotplug / rpaphp_core.c
index 1572054..e709bad 100644 (file)
@@ -89,7 +89,7 @@ static int rpaphp_get_attention_status(struct slot *slot)
  */
 static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value)
 {
-       int retval;
+       int retval = 0;
        struct slot *slot = (struct slot *)hotplug_slot->private;
 
        down(&rpaphp_sem);
@@ -208,63 +208,155 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe
 
 int rpaphp_remove_slot(struct slot *slot)
 {
-       int retval = 0;
-       struct hotplug_slot *php_slot = slot->hotplug_slot;
+       return deregister_slot(slot);
+}
 
-       list_del(&slot->rpaphp_slot_list);
-       
-       /* remove "php_location" file */
-       rpaphp_sysfs_remove_attr_location(php_slot);
+static int get_children_props(struct device_node *dn, int **drc_indexes,
+               int **drc_names, int **drc_types, int **drc_power_domains)
+{
+       int *indexes, *names;
+       int *types, *domains;
 
-       retval = pci_hp_deregister(php_slot);
-       if (retval)
-               err("Problem unregistering a slot %s\n", slot->name);
+       indexes = (int *) get_property(dn, "ibm,drc-indexes", NULL);
+       names = (int *) get_property(dn, "ibm,drc-names", NULL);
+       types = (int *) get_property(dn, "ibm,drc-types", NULL);
+       domains = (int *) get_property(dn, "ibm,drc-power-domains", NULL);
 
-       num_slots--;
+       if (!indexes || !names || !types || !domains) {
+               /* Slot does not have dynamically-removable children */
+               return -EINVAL;
+       }
+       if (drc_indexes)
+               *drc_indexes = indexes;
+       if (drc_names)
+               /* &drc_names[1] contains NULL terminated slot names */
+               *drc_names = names;
+       if (drc_types)
+               /* &drc_types[1] contains NULL terminated slot types */
+               *drc_types = types;
+       if (drc_power_domains)
+               *drc_power_domains = domains;
 
-       dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
-       return retval;
+       return 0;
 }
 
-static int is_php_dn(struct device_node *dn, int **indexes, int **names, int **types,
-         int **power_domains)
+/* To get the DRC props describing the current node, first obtain it's
+ * my-drc-index property.  Next obtain the DRC list from it's parent.  Use
+ * the my-drc-index for correlation, and obtain the requested properties.
+ */
+int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
+               char **drc_name, char **drc_type, int *drc_power_domain)
 {
-       *indexes = (int *) get_property(dn, "ibm,drc-indexes", NULL);
-       if (!*indexes)
-               return 0;
-       /* &names[1] contains NULL terminated slot names */
-       *names = (int *) get_property(dn, "ibm,drc-names", NULL);
-       if (!*names)
-               return 0;
-       /* &types[1] contains NULL terminated slot types */
-       *types = (int *) get_property(dn, "ibm,drc-types", NULL);
-       if (!*types)
-               return 0;
-       /* power_domains[1...n] are the slot power domains */
-       *power_domains = (int *) get_property(dn,
-                                             "ibm,drc-power-domains", NULL);
-       if (!*power_domains)
-               return 0;
-       if (strcmp(dn->name, "pci") == 0 &&
-                       !get_property(dn, "ibm,fw-pci-hot-plug-ctrl", NULL))
+       int *indexes, *names;
+       int *types, *domains;
+       unsigned int *my_index;
+       char *name_tmp, *type_tmp;
+       int i, rc;
+
+       my_index = (int *) get_property(dn, "ibm,my-drc-index", NULL);
+       if (!my_index) {
+               /* Node isn't DLPAR/hotplug capable */
+               return 1;
+       }
+
+       rc = get_children_props(dn->parent, &indexes, &names, &types, &domains);
+       if (rc < 0) {
+               return 1;
+       }
+
+       name_tmp = (char *) &names[1];
+       type_tmp = (char *) &types[1];
+
+       /* Iterate through parent properties, looking for my-drc-index */
+       for (i = 0; i < indexes[0]; i++) {
+               if ((unsigned int) indexes[i + 1] == *my_index) {
+                       if (drc_name)
+                               *drc_name = name_tmp;
+                       if (drc_type)
+                               *drc_type = type_tmp;
+                       if (drc_index)
+                               *drc_index = *my_index;
+                       if (drc_power_domain)
+                               *drc_power_domain = domains[i+1];
+                       return 0;
+               }
+               name_tmp += (strlen(name_tmp) + 1);
+               type_tmp += (strlen(type_tmp) + 1);
+       }
+
+       return 1;
+}
+
+static int is_php_type(char *drc_type)
+{
+       unsigned long value;
+       char *endptr;
+
+       /* PCI Hotplug nodes have an integer for drc_type */
+       value = simple_strtoul(drc_type, &endptr, 10);
+       if (endptr == drc_type)
                return 0;
+
        return 1;
 }
 
+static int is_php_dn(struct device_node *dn, int **indexes, int **names,
+               int **types, int **power_domains)
+{
+       int *drc_types;
+       int rc;
+
+       rc = get_children_props(dn, indexes, names, &drc_types, power_domains);
+       if (rc >= 0) {
+               if (is_php_type((char *) &drc_types[1])) {
+                       *types = drc_types;
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
+static int is_dr_dn(struct device_node *dn, int **indexes, int **names,
+               int **types, int **power_domains, int **my_drc_index)
+{
+       int rc;
+
+       *my_drc_index = (int *) get_property(dn, "ibm,my-drc-index", NULL);
+       if(!*my_drc_index)
+               return (0);
+
+       if (!dn->parent)
+               return (0);
+
+       rc = get_children_props(dn->parent, indexes, names, types,
+                               power_domains);
+       return (rc >= 0);
+}
+
 static inline int is_vdevice_root(struct device_node *dn)
 {
        return !strcmp(dn->name, "vdevice");
 }
 
-/**
- * rpaphp_add_slot: Add  Hot Plug slot(s) to sysfs
- *
- */
+int is_dlpar_type(const char *type_str)
+{
+       /* Only register DLPAR-capable nodes of drc-type PHB or SLOT */
+       return (!strcmp(type_str, "PHB") || !strcmp(type_str, "SLOT"));
+}
+
+/****************************************************************
+ *     rpaphp not only registers PCI hotplug slots(HOTPLUG), 
+ *     but also logical DR slots(EMBEDDED).
+ *     HOTPLUG slot: An adapter can be physically added/removed. 
+ *     EMBEDDED slot: An adapter can be logically removed/added
+ *               from/to a partition with the slot.
+ ***************************************************************/
 int rpaphp_add_slot(struct device_node *dn)
 {
        struct slot *slot;
        int retval = 0;
-       int i;
+       int i, *my_drc_index, slot_type;
        int *indexes, *names, *types, *power_domains;
        char *name, *type;
 
@@ -277,42 +369,68 @@ int rpaphp_add_slot(struct device_node *dn)
        }
 
        /* register PCI devices */
-       if (dn->name != 0 && strcmp(dn->name, "pci") == 0 &&
-           is_php_dn(dn, &indexes, &names, &types, &power_domains)) {
+       if (dn->name != 0 && strcmp(dn->name, "pci") == 0) {
+               if (is_php_dn(dn, &indexes, &names, &types, &power_domains))  
+                       slot_type = HOTPLUG;
+               else if (is_dr_dn(dn, &indexes, &names, &types, &power_domains, &my_drc_index)) 
+                       slot_type = EMBEDDED;
+               else goto exit;
 
                name = (char *) &names[1];
                type = (char *) &types[1];
-               for (i = 0; i < indexes[0];
-                                       i++,
-                                       name += (strlen(name) + 1),
-                                       type += (strlen(type) + 1)) {
-                       if (!(slot = alloc_slot_struct(dn, indexes[i + 1], name,
-                                                      power_domains[i + 1]))) {
-                               retval = -ENOMEM;
-                               goto exit;
+               for (i = 0; i < indexes[0]; i++,
+                       name += (strlen(name) + 1), type += (strlen(type) + 1)) {
+
+                       if (slot_type == HOTPLUG ||
+                           (slot_type == EMBEDDED &&
+                            indexes[i + 1] == my_drc_index[0] &&
+                            is_dlpar_type(type))) {
+                               if (!(slot = alloc_slot_struct(dn, indexes[i + 1], name,
+                                              power_domains[i + 1]))) {
+                                       retval = -ENOMEM;
+                                       goto exit;
+                               }
+                               if (!strcmp(type, "PHB"))
+                                       slot->type = PHB;
+                               else if (slot_type == EMBEDDED)
+                                       slot->type = EMBEDDED;
+                               else
+                                       slot->type = simple_strtoul(type, NULL, 10);
+                               
+                               dbg("    Found drc-index:0x%x drc-name:%s drc-type:%s\n",
+                                       indexes[i + 1], name, type);
+
+                               retval = register_pci_slot(slot);
+                               if (slot_type == EMBEDDED)
+                                       goto exit;
                        }
-                       slot->type = simple_strtoul(type, NULL, 10);
-                       if (slot->type < 1 || slot->type > 16)
-                               slot->type = 0;
-                       retval = register_pci_slot(slot);
-
-               }               /* for indexes */
-       }                       /* end of PCI device_node */
+               }
+       }
 exit:
        dbg("%s - Exit: num_slots=%d rc[%d]\n",
            __FUNCTION__, num_slots, retval);
        return retval;
 }
 
-static int __init init_rpa(void)
+/*
+ * init_slots - initialize 'struct slot' structures for each slot
+ *
+ */
+static void init_slots(void)
 {
        struct device_node *dn;
 
+       for (dn = find_all_nodes(); dn; dn = dn->next)
+               rpaphp_add_slot(dn);
+}
+
+static int __init init_rpa(void)
+{
+
        init_MUTEX(&rpaphp_sem);
 
        /* initialize internal data structure etc. */
-       for (dn = find_all_nodes(); dn; dn = dn->next)
-               rpaphp_add_slot(dn);
+       init_slots();
        if (!num_slots)
                return -ENODEV;
 
@@ -374,14 +492,14 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
                retval = -EINVAL;
        }
        up(&rpaphp_sem);
-      exit:
+exit:
        dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
        return retval;
 }
 
 static int disable_slot(struct hotplug_slot *hotplug_slot)
 {
-       int retval;
+       int retval = -EINVAL;
        struct slot *slot = (struct slot *)hotplug_slot->private;
 
        dbg("%s - Entry: slot[%s]\n", __FUNCTION__, slot->name);
@@ -395,9 +513,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
        down(&rpaphp_sem);
        switch (slot->dev_type) {
        case PCI_DEV:
-               rpaphp_set_attention_status(slot, LED_ID);
                retval = rpaphp_unconfig_pci_adapter(slot);
-               rpaphp_set_attention_status(slot, LED_OFF);
                break;
        case VIO_DEV:
                retval = rpaphp_unconfig_vio_adapter(slot);
@@ -406,7 +522,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
                retval = -ENODEV;
        }
        up(&rpaphp_sem);
-      exit:
+exit:
        dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
        return retval;
 }
@@ -417,3 +533,4 @@ module_exit(rpaphp_exit);
 EXPORT_SYMBOL_GPL(rpaphp_add_slot);
 EXPORT_SYMBOL_GPL(rpaphp_remove_slot);
 EXPORT_SYMBOL_GPL(rpaphp_slot_head);
+EXPORT_SYMBOL_GPL(rpaphp_get_drc_props);