[PATCH] RPA DLPAR/PCIHP cleanups

John Rose johnrose at austin.ibm.com
Tue Feb 10 10:18:13 EST 2004


Hi Linda, World-

I'd like to push the changes below to Ameslab tomorrow morning, and
generate our final submission against the mainline tree from this.  The
patch:
- Fixes whitespace misuse
- Removes some debug prints (which you removed in your VIO code anyway)
- Fixes a hotplug bug
- Adds a semaphore to the DLPAR interface to protect against multiple
users

If there are no objections, will push tomorrow.

Thanks-
John

diff -Nru a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
--- a/drivers/pci/hotplug/rpadlpar_core.c	Mon Feb  9 17:05:49 2004
+++ b/drivers/pci/hotplug/rpadlpar_core.c	Mon Feb  9 17:05:49 2004
@@ -3,7 +3,7 @@
  *
  * John Rose <johnrose at austin.ibm.com>
  * Linda Xie <lxie at us.ibm.com>
- *
+ *
  * October 2003
  *
  * Copyright (C) 2003 IBM.
@@ -16,6 +16,7 @@
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <asm/pci-bridge.h>
+#include <asm/semaphore.h>
 #include "../pci.h"
 #include "rpaphp.h"
 #include "rpadlpar.h"
@@ -23,6 +24,8 @@
 #define MODULE_VERSION "1.0"
 #define MODULE_NAME "rpadlpar_io"

+static DECLARE_MUTEX(rpadlpar_sem);
+
 static inline int is_hotplug_capable(struct device_node *dn)
 {
 	unsigned char *ptr = get_property(dn, "ibm,fw-pci-hot-plug-ctrl", NULL);
@@ -175,7 +178,7 @@
 	struct pci_bus *secondary_bus;

 	if (!bridge_dev) {
-		printk(KERN_ERR "%s: %s() unexpected null device\n",
+		printk(KERN_ERR "%s: %s() unexpected null device\n",
 				MODULE_NAME, __FUNCTION__);
 		return 1;
 	}
@@ -183,7 +186,7 @@
 	secondary_bus = bridge_dev->subordinate;

 	if (unmap_bus_range(secondary_bus)) {
-		printk(KERN_ERR "%s: failed to unmap bus range\n",
+		printk(KERN_ERR "%s: failed to unmap bus range\n",
 				__FUNCTION__);
 		return 1;
 	}
@@ -203,36 +206,47 @@
  * 0			Success
  * -ENODEV		Not a valid drc_name
  * -EINVAL		Slot already added
+ * -ERESTARTSYS		Signalled before obtaining lock
  * -EIO			Internal PCI Error
  */
 int dlpar_add_slot(char *drc_name)
 {
 	struct device_node *dn = find_php_slot_node(drc_name);
 	struct pci_dev *dev;
+	int rc = 0;
+
+	if (down_interruptible(&rpadlpar_sem))
+		return -ERESTARTSYS;

-	if (!dn)
-		return -ENODEV;
+	if (!dn) {
+		rc = -ENODEV;
+		goto exit;
+	}

 	/* Check for existing hotplug slot */
-	if (find_slot(drc_name))
-		return -EINVAL;
+	if (find_slot(drc_name)) {
+		rc = -EINVAL;
+		goto exit;
+	}

 	/* Add pci bus */
 	dev = dlpar_pci_add_bus(dn);
 	if (!dev) {
 		printk(KERN_ERR "%s: unable to add bus %s\n", __FUNCTION__,
 				drc_name);
-		return -EIO;
+		rc = -EIO;
+		goto exit;
 	}

 	/* Add hotplug slot for new bus */
 	if (rpaphp_add_slot(drc_name)) {
 		printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
 				__FUNCTION__, drc_name);
-		return -EIO;
+		rc = -EIO;
 	}
-
-	return 0;
+exit:
+	up(&rpadlpar_sem);
+	return rc;
 }

 /**
@@ -245,6 +259,7 @@
  * 0			Success
  * -ENODEV		Not a valid drc_name
  * -EINVAL		Slot already removed
+ * -ERESTARTSYS		Signalled before obtaining lock
  * -EIO			Internal PCI Error
  */
 int dlpar_remove_slot(char *drc_name)
@@ -252,35 +267,46 @@
 	struct device_node *dn = find_php_slot_node(drc_name);
 	struct slot *slot;
 	struct pci_dev *bridge_dev;
+	int rc = 0;
+
+	if (down_interruptible(&rpadlpar_sem))
+		return -ERESTARTSYS;

-	if (!dn)
-		return -ENODEV;
+	if (!dn) {
+		rc = -ENODEV;
+		goto exit;
+	}

-	if (!(slot = find_slot(drc_name)))
-		return -EINVAL;
+	if (!(slot = find_slot(drc_name))) {
+		rc = -EINVAL;
+		goto exit;
+	}

 	bridge_dev = slot->bridge;
 	if (!bridge_dev) {
 		printk(KERN_ERR "%s: %s(): unexpected null bridge device\n",
 				MODULE_NAME, __FUNCTION__);
-		return -EIO;
+		rc = -EIO;
+		goto exit;
 	}

 	/* Remove hotplug slot */
 	if (rpaphp_remove_slot(slot)) {
 		printk(KERN_ERR "%s: %s(): unable to remove hotplug slot %s\n",
 				MODULE_NAME, __FUNCTION__, drc_name);
-		return -EIO;
+		rc = -EIO;
+		goto exit;
 	}

 	/* Remove pci bus */
 	if (dlpar_pci_remove_bus(bridge_dev)) {
 		printk(KERN_ERR "%s: %s() unable to remove pci bus %s\n",
 				MODULE_NAME, __FUNCTION__, drc_name);
-		return -EIO;
+		rc = -EIO;
 	}
-
-	return 0;
+exit:
+	up(&rpadlpar_sem);
+	return rc;
 }

 static inline int is_dlpar_capable(void)
diff -Nru a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c	Mon Feb  9 17:05:49 2004
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c	Mon Feb  9 17:05:49 2004
@@ -116,7 +116,7 @@
 static void dlpar_io_release(struct kobject *kobj)
 {
 	/* noop */
-	return;
+	return;
 }

 struct kobj_type ktype_dlpar_io = {
diff -Nru a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h
--- a/drivers/pci/hotplug/rpaphp.h	Mon Feb  9 17:05:49 2004
+++ b/drivers/pci/hotplug/rpaphp.h	Mon Feb  9 17:05:49 2004
@@ -47,8 +47,8 @@
 #define ERR_SENSE_USE -9002     /* No DR operation will succeed, slot is unusable  */

 /* Sensor values from rtas_get-sensor */
-#define EMPTY           0       /* No card in slot */
-#define PRESENT         1       /* Card in slot */
+#define EMPTY	0       /* No card in slot */
+#define PRESENT	1       /* Card in slot */

 #if !defined(CONFIG_HOTPLUG_PCI_MODULE)
 	#define MY_NAME "rpaphp"
@@ -81,11 +81,11 @@
  */
 struct slot {
 	u32	magic;
-        int     state;
-        u32     index;
-        u32     type;
-        u32     power_domain;
-        char    *name;
+	int     state;
+	u32     index;
+	u32     type;
+	u32     power_domain;
+	char    *name;
 	struct	device_node *dn;/* slot's device_node in OFDT		*/
 				/* dn has phb info			*/
 	struct	pci_dev	*bridge;/* slot's pci_dev in pci_devices	*/
diff -Nru a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
--- a/drivers/pci/hotplug/rpaphp_core.c	Mon Feb  9 17:05:49 2004
+++ b/drivers/pci/hotplug/rpaphp_core.c	Mon Feb  9 17:05:49 2004
@@ -38,8 +38,8 @@
 #include "pci_hotplug.h"


-static int debug;
-static struct semaphore rpaphp_sem;
+static int debug;
+static struct semaphore rpaphp_sem;
 static int rpaphp_debug;
 static LIST_HEAD (rpaphp_slot_head);
 static int num_slots = 0;
@@ -79,13 +79,13 @@
 {
 	int rc;

-        rc = rtas_get_sensor(DR_ENTITY_SENSE, index, state);
-
-        if (rc) {
+	rc = rtas_get_sensor(DR_ENTITY_SENSE, index, state);
+
+	if (rc) {
 		if (rc ==  NEED_POWER || rc == PWR_ONLY) {
-			dbg("%s: slot must be power up to get sensor-state\n",
+			dbg("%s: slot must be power up to get sensor-state\n",
 				__FUNCTION__);
-		} else if (rc == ERR_SENSE_USE)
+		} else if (rc == ERR_SENSE_USE)
 			info("%s: slot is unusable\n", __FUNCTION__);
 		   else err("%s failed to get sensor state\n", __FUNCTION__);
 	}
@@ -95,8 +95,8 @@
 static struct pci_dev *rpaphp_find_bridge_pdev(struct slot *slot)
 {
 	struct pci_dev		*retval_dev = NULL;
-
-	retval_dev = rpaphp_find_pci_dev(slot->dn);
+
+	retval_dev = rpaphp_find_pci_dev(slot->dn);

 	return retval_dev;
 }
@@ -105,7 +105,7 @@
 {
 	struct pci_dev * retval_dev = NULL;

-	retval_dev = rpaphp_find_pci_dev(slot->dn->child);
+	retval_dev = rpaphp_find_pci_dev(slot->dn->child);

 	return retval_dev;
 }
@@ -118,7 +118,7 @@
 		dbg("%s - slot == NULL\n", function);
 		return -1;
 	}
-
+
 	if (!slot->hotplug_slot) {
 		dbg("%s - slot->hotplug_slot == NULL!\n", function);
 		return -1;
@@ -137,7 +137,7 @@

 	slot = (struct slot *)hotplug_slot->private;
 	if (slot_paranoia_check(slot, function))
-                return NULL;
+		return NULL;
 	return slot;
 }

@@ -145,16 +145,12 @@
 {
 	int	rc;

-	dbg("Entry %s: status=%d\n", __FUNCTION__, status);
-
 	/* status: LED_OFF or LED_ON */
 	rc = rtas_set_indicator(DR_INDICATOR, slot->index, status);
 	if (rc)
-		err("slot(%s) set attention-status(%d) failed! rc=0x%x\n",
-			slot->name, status, rc);
-
-	dbg("Exit %s, rc=0x%x\n", __FUNCTION__, rc);
-
+		err("slot(%s) set attention-status(%d) failed! rc=0x%x\n",
+			slot->name, status, rc);
+
 	return rc;
 }

@@ -162,12 +158,12 @@
 {
 	int	rc;

-        rc = rtas_get_power_level(slot->power_domain, (int *)value);
-        if (rc)
-                err("failed to get power-level for slot(%s), rc=0x%x\n",
+	rc = rtas_get_power_level(slot->power_domain, (int *)value);
+	if (rc)
+		err("failed to get power-level for slot(%s), rc=0x%x\n",
 			slot->name, rc);
-
-        return rc;
+
+	return rc;
 }

 static int rpaphp_get_attention_status(struct slot *slot)
@@ -191,8 +187,6 @@
 	if (slot == NULL)
 		return -ENODEV;

-	dbg("%s - Entry: slot[%s] value[0x%x]\n",
-		__FUNCTION__, slot->name, value);
 	down(&rpaphp_sem);
 	switch (value) {
 		case 0:
@@ -213,8 +207,7 @@

 	}
 	up(&rpaphp_sem);
-
-	dbg("%s - Exit: rc[%d]\n",  __FUNCTION__, retval);
+
 	return retval;
 }

@@ -229,7 +222,7 @@
 {
 	int retval;
 	struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
-
+
 	if (slot == NULL)
 		return -ENODEV;

@@ -254,21 +247,16 @@
 		return -ENODEV;


-	dbg("%s - Entry: slot[%s]\n",
-		__FUNCTION__, slot->name);
-
 	down(&rpaphp_sem);
 	*value = rpaphp_get_attention_status(slot);
 	up(&rpaphp_sem);

-	dbg("%s - Exit: value[0x%x] rc[%d]\n",
-		__FUNCTION__, *value, retval);
 	return retval;
 }

 /*
  * get_adapter_status - get  the status of a slot
- *
+ *
  * 0-- slot is empty
  * 1-- adapter is configured
  * 2-- adapter is not configured
@@ -278,32 +266,30 @@
 {
 	int	state, rc;

-	dbg("Entry %s\n", __FUNCTION__);
+	*value 		  = NOT_VALID;

-	*value 		  = NOT_VALID;
+	rc = rpaphp_get_sensor_state(slot->index, &state);

-	rc = rpaphp_get_sensor_state(slot->index, &state);
-
-	if (rc)
-		goto exit;
+	if (rc)
+		goto exit;

 	if (state == PRESENT) {
 		dbg("slot is occupied\n");
-
+
 		if (!is_init) /* at run-time slot->state can be changed by */
 			  /* config/unconfig adapter	 		   */
 			*value = slot->state;
 		else {
-		if (!slot->dn->child)
-			dbg("%s: %s is not valid OFDT node\n",
+		if (!slot->dn->child)
+			dbg("%s: %s is not valid OFDT node\n",
 				__FUNCTION__, slot->dn->full_name);
-		else
-			if (rpaphp_find_pci_dev(slot->dn->child))
+		else
+			if (rpaphp_find_pci_dev(slot->dn->child))
 				*value = CONFIGURED;
 			else {
 				dbg("%s: can't find pdev of adapter in slot[%s]\n",
 					__FUNCTION__, slot->name);
-				*value = NOT_CONFIGURED;
+				*value = NOT_CONFIGURED;
 				}
 		}
 	}
@@ -312,10 +298,8 @@
 		dbg("slot is empty\n");
 			*value = state;
 		}
-
-exit:    dbg("Exit %s slot[%s] has adapter-status %d rtas call's rc=0x%x\n",
-		__FUNCTION__, slot->name, *value, rc);

+exit:
 	return rc;
 }

@@ -344,14 +328,11 @@

 	if (slot == NULL)
 		return -ENODEV;
-
-	dbg("%s - Entry: slot->name[%s] slot->type[%d]\n",
-		__FUNCTION__, slot->name, slot->type);

-	down(&rpaphp_sem);
+	down(&rpaphp_sem);

 	switch (slot->type) {
-		case 1:
+		case 1:
 		case 2:
 		case 3:
 		case 4:
@@ -378,10 +359,10 @@
 		default:
 			*value = PCI_SPEED_UNKNOWN;
 			break;
-
+
 	}

-	up(&rpaphp_sem);
+	up(&rpaphp_sem);

 	return 0;
 }
@@ -400,7 +381,7 @@
 	return 0;
 }

-/*
+/*
  * rpaphp_validate_slot - make sure the name of the slot matches
  * 				the location code , if the slots is not
  *				empty.
@@ -409,11 +390,8 @@
 {
 	struct device_node	*dn;
 	int			retval = 0;
-
-	dbg("Entry %s: (name: %s index: 0x%x\n",
-		__FUNCTION__, slot_name, slot_index);

-	for(dn = find_all_nodes(); dn; dn = dn->next) {
+	for(dn = find_all_nodes(); dn; dn = dn->next) {

 		int 		*index;
 		unsigned char	*loc_code;
@@ -423,30 +401,25 @@
 		if (index && *index == slot_index) {
 		char *slash, tmp_str[128];

-			loc_code = get_property(dn, "ibm,loc-code", NULL);
+			loc_code = get_property(dn, "ibm,loc-code", NULL);
 		if (!loc_code) {
 			retval = -1;
 			goto exit;
 		}

-		dbg("%s: name=%s loc-code=%s index=0x%x\n",
-			__FUNCTION__, slot_name, loc_code, slot_index);
-
 		strcpy(tmp_str, loc_code);
 		slash = strrchr(tmp_str, '/');
 		if (slash) {
 			*slash = '\0';
 		}
-		if (strcmp(slot_name, tmp_str))
+		if (strcmp(slot_name, tmp_str))
 			retval = -1;
-		goto exit;
+		goto exit;
 		}

 	}

 exit:
-	dbg("Exit %s with retval=%d\n", __FUNCTION__, retval);
-
 	return retval;
 }

@@ -454,8 +427,6 @@
 static void rpaphp_fixup_new_devices(struct pci_bus *bus)
 {
 	struct pci_dev *dev;
-
-	dbg("Enter rpaphp_fixup_new_devices()\n");

 	list_for_each_entry(dev, &bus->devices, bus_list) {
 	/*
@@ -467,30 +438,26 @@
 			pcibios_fixup_device_resources(dev, bus);
 			pci_read_irq_line(dev);
 			for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-                        	struct resource *r = &dev->resource[i];
-                        	if (r->parent || !r->start || !r->flags)
-                                	continue;
-                        	rpaphp_claim_resource(dev, i);
-                	}
-
+				struct resource *r = &dev->resource[i];
+				if (r->parent || !r->start || !r->flags)
+					continue;
+				rpaphp_claim_resource(dev, i);
+			}
 		}
 	}
 }

-static struct pci_dev *rpaphp_config_adapter(struct slot *slot)
+static struct pci_dev *rpaphp_config_adapter(struct slot *slot)
 {
 	struct pci_bus 		*pci_bus;
 	struct device_node	*dn;
 	int 			num;
 	struct pci_dev		*dev = NULL;

-	dbg("Entry %s: slot[%s]\n",
-		__FUNCTION__, slot->name);
-
 	if (slot->bridge) {
-
+
 		pci_bus = slot->bridge->subordinate;
-
+
 		if (!pci_bus) {
 			err("%s: can't find bus structure\n", __FUNCTION__);
 			goto exit;
@@ -498,14 +465,12 @@

 		for (dn = slot->dn->child; dn; dn = dn->sibling) {
 			dbg("child dn's devfn=[%x]\n", dn->devfn);
-				num = pci_scan_slot(pci_bus,
+				num = pci_scan_slot(pci_bus,
 				PCI_DEVFN(PCI_SLOT(dn->devfn),  0));

 				dbg("pci_scan_slot return num=%d\n", num);

 			if (num) {
-				dbg("%s: calling rpaphp_fixup_new_devices()\n",
-					__FUNCTION__);
 				rpaphp_fixup_new_devices(pci_bus);
 				pci_bus_add_devices(pci_bus);
 			}
@@ -518,42 +483,37 @@
 		err("slot doesn't have pci_dev structure\n");
 		dev = NULL;
 		goto exit;
-	}
+	}

-exit:
+exit:
 	dbg("Exit %s: pci_dev %s\n", __FUNCTION__, dev? "found":"not found");

 	return dev;
 }

-static int rpaphp_unconfig_adapter(struct slot *slot)
+static int rpaphp_unconfig_adapter(struct slot *slot)
 {
 	int			retval = 0;

-	dbg("Entry %s: slot[%s]\n",
-		__FUNCTION__, slot->name);
 	if (!slot->dev) {
 		info("%s: no card in slot[%s]\n",
 			__FUNCTION__, slot->name);

 		retval = -EINVAL;
-		goto exit;
+		goto exit;
 	}

+	/* remove the device from the pci core */
+	pci_remove_bus_device(slot->dev);

-        /* remove the device from the pci core */
-        pci_remove_bus_device(slot->dev);
+	pci_dev_put(slot->dev);
+	slot->state = NOT_CONFIGURED;

-        pci_dev_put(slot->dev);
-        slot->state = NOT_CONFIGURED;
-
 	dbg("%s: adapter in slot[%s] unconfigured.\n", __FUNCTION__, slot->name);
-
-exit:
-	dbg("Exit %s, rc=0x%x\n", __FUNCTION__, retval);

+exit:
 	return retval;
-
+
 }

 /* free up the memory user be a slot */
@@ -561,39 +521,32 @@
 static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
 {
 	struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
-
+
 	if (slot == NULL)
 		return;

-	dbg("%s - Entry: slot[%s]\n",
-		__FUNCTION__, slot->name);
 	kfree(slot->hotplug_slot->info);
 	kfree(slot->hotplug_slot->name);
 	kfree(slot->hotplug_slot);
 	pci_dev_put(slot->bridge);
 	pci_dev_put(slot->dev);
 	kfree(slot);
-	dbg("%s - Exit\n", __FUNCTION__);
 }

 int rpaphp_remove_slot(struct slot *slot)
 {
 	int retval = 0;

-	dbg("%s - Entry: slot[%s]\n",
-		__FUNCTION__, slot->name);
-
   	sysfs_remove_link(slot->hotplug_slot->kobj.parent,
-                          slot->bridge->slot_name);
-
+			slot->bridge->slot_name);
+
 	list_del(&slot->rpaphp_slot_list);
 	retval = pci_hp_deregister(slot->hotplug_slot);
 	if (retval)
 		err("Problem unregistering a slot %s\n", slot->name);
 	num_slots--;

-	dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
-	return retval;
+	return retval;
 }

 static int is_php_dn(struct device_node *dn, int **indexes,  int **names, int **types, int **power_domains)
@@ -604,7 +557,7 @@

 	/* &names[1] contains NULL terminated slot names */
 	*names = (int *)get_property(dn, "ibm,drc-names", NULL);
-	if (!*names)
+	if (!*names)
 		return(0);

 	/* &types[1] contains NULL terminated slot types */
@@ -615,7 +568,7 @@
 	/* power_domains[1...n] are the slot power domains */
 	*power_domains = (int *)get_property(dn,
 		"ibm,drc-power-domains", NULL);
-	if (!*power_domains)
+	if (!*power_domains)
 		return(0);

 	if (!get_property(dn, "ibm,fw-pci-hot-plug-ctrl", NULL))
@@ -629,17 +582,17 @@
 	struct slot *slot;

 	slot = kmalloc(sizeof(struct slot), GFP_KERNEL);
-	if (!slot)
+	if (!slot)
 		return (NULL);
 	memset(slot, 0, sizeof(struct slot));
-	slot->hotplug_slot = kmalloc(sizeof(struct hotplug_slot),
+	slot->hotplug_slot = kmalloc(sizeof(struct hotplug_slot),
 		GFP_KERNEL);
 	if (!slot->hotplug_slot) {
 		kfree(slot);
 		return (NULL);
-        }
+	}
 	memset(slot->hotplug_slot, 0, sizeof(struct hotplug_slot));
-	slot->hotplug_slot->info = kmalloc(sizeof(struct hotplug_slot_info),
+	slot->hotplug_slot->info = kmalloc(sizeof(struct hotplug_slot_info),
 		GFP_KERNEL);
 	if (!slot->hotplug_slot->info) {
 		kfree(slot->hotplug_slot);
@@ -659,17 +612,14 @@

 static int setup_hotplug_slot_info(struct slot *slot)
 {
-	dbg("%s Initilize the slot info structure ...\n",
-		__FUNCTION__);
-
-	rpaphp_get_power_status(slot,
-		&slot->hotplug_slot->info->power_status);
+	rpaphp_get_power_status(slot,
+		&slot->hotplug_slot->info->power_status);

 	rpaphp_get_adapter_status(slot, 1,
-		&slot->hotplug_slot->info->adapter_status);
+		&slot->hotplug_slot->info->adapter_status);

 	if (slot->hotplug_slot->info->adapter_status == NOT_VALID) {
-		dbg("%s: NOT_VALID: skip dn->full_name=%s\n",
+		dbg("%s: NOT_VALID: skip dn->full_name=%s\n",
 			__FUNCTION__, slot->dn->full_name);
 		    kfree(slot->hotplug_slot->info);
 		    kfree(slot->hotplug_slot->name);
@@ -682,7 +632,7 @@

 static int register_slot(struct slot *slot)
 {
-	int retval;
+	int retval;

 	retval = pci_hp_register(slot->hotplug_slot);
 	if (retval) {
@@ -692,7 +642,7 @@
 	}
 	/* create symlink between slot->name and it's bus_id */
 	dbg("%s: sysfs_create_link: %s --> %s\n", __FUNCTION__,
-		slot->bridge->slot_name, slot->name);
+		slot->bridge->slot_name, slot->name);
 	retval = sysfs_create_link(slot->hotplug_slot->kobj.parent,
 			&slot->hotplug_slot->kobj,
 			slot->bridge->slot_name);
@@ -702,12 +652,12 @@
 		return (retval);
 	}
 	/* add slot to our internal list */
-	dbg("%s adding slot[%s] to rpaphp_slot_list\n",
+	dbg("%s adding slot[%s] to rpaphp_slot_list\n",
 		__FUNCTION__, slot->name);

 	list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);

-	info("Slot [%s] (bus_id=%s) registered\n",
+	info("Slot [%s] (bus_id=%s) registered\n",
 		slot->name, slot->bridge->slot_name);
 	return (0);
 }
@@ -721,38 +671,33 @@
 	struct slot		*slot;
 	int 			retval = 0;
 	int 			i;
-        struct device_node 	*dn;
-        int 			*indexes, *names, *types, *power_domains;
-        char 			*name, *type;
-
-	dbg("Entry %s: %s\n", __FUNCTION__,
-			slot_name? slot_name: "init");
+	struct device_node 	*dn;
+	int 			*indexes, *names, *types, *power_domains;
+	char 			*name, *type;

 	for (dn = find_all_nodes(); dn; dn = dn->next) {

 		if (dn->name != 0 && strcmp(dn->name, "pci") == 0)	{
 			if (!is_php_dn(dn, &indexes, &names, &types, &power_domains))
 				continue;
-
+
 			dbg("%s : found device_node in OFDT full_name=%s, name=%s\n",
 				__FUNCTION__, dn->full_name, dn->name);

 			name = (char *)&names[1];
 			type = (char *)&types[1];
-
-			dbg("%s: indexes=%d\n", __FUNCTION__, indexes[0]);

-			for (i = 0; i < indexes[0];
-				i++,
+			for (i = 0; i < indexes[0];
+				i++,
 				name += (strlen(name) + 1),
 				type += (strlen(type) + 1)) {

 				dbg("%s: name[%s] index[%x]\n",
 					__FUNCTION__, name, indexes[i+1]);

-				if (slot_name && strcmp(slot_name, name))
+				if (slot_name && strcmp(slot_name, name))
 					continue;
-
+
 				if (rpaphp_validate_slot(name, indexes[i + 1])) {
 					dbg("%s: slot(%s, 0x%x) is invalid.\n",
 						__FUNCTION__, name, indexes[i+ 1]);
@@ -767,7 +712,7 @@
 				slot->name = slot->hotplug_slot->name;
 				slot->index = indexes[i + 1];
 				strcpy(slot->name, name);
-				slot->type = simple_strtoul(type, NULL, 10);
+				slot->type = simple_strtoul(type, NULL, 10);
 				if (slot->type < 1  || slot->type > 16)
 					slot->type = 0;

@@ -779,7 +724,7 @@
 				slot->dn = dn;

 				/*
-			 	* Initilize the slot info structure with some known
+			 	* Initilize the slot info structure with some known
 			 	* good values.
 			 	*/
 				if (setup_hotplug_slot_info(slot))
@@ -787,15 +732,15 @@

 				slot->bridge = rpaphp_find_bridge_pdev(slot);
 				if (!slot->bridge && slot_name) { /* slot being added doesn't have pci_dev yet*/
-					dbg("%s: no pci_dev for bridge dn %s\n",
+					dbg("%s: no pci_dev for bridge dn %s\n",
 							__FUNCTION__, slot_name);
-					    kfree(slot->hotplug_slot->info);
-					    kfree(slot->hotplug_slot->name);
-					    kfree(slot->hotplug_slot);
-					    kfree(slot);
+					kfree(slot->hotplug_slot->info);
+					kfree(slot->hotplug_slot->name);
+					kfree(slot->hotplug_slot);
+					kfree(slot);
 					continue;
 				}
-
+
 				/* find slot's pci_dev if it's not empty*/
 				if (slot->hotplug_slot->info->adapter_status == EMPTY) {
 					slot->state = EMPTY;  /* slot is empty */
@@ -812,49 +757,35 @@
 						continue;

 					}
-
-					slot->dev = rpaphp_find_adapter_pdev(slot);
-
-					if (!slot->dev && slot_name) {
-						 /* adapter being added doesn't have pci_dev yet */
-						slot->dev = rpaphp_config_adapter(slot);
-						if (!slot->dev) {
-							err("%s: add new adapter device for slot[%s] failed\n",
-							__FUNCTION__, slot->name);
-							kfree(slot->hotplug_slot->info);
-							kfree(slot->hotplug_slot->name);
-							kfree(slot->hotplug_slot);
-							kfree(slot);
-							pci_dev_put(slot->bridge);
-							continue;
-
-						}
-					}

+					slot->dev = rpaphp_find_adapter_pdev(slot);
 					if(slot->dev) {
 						slot->state = CONFIGURED;
 						pci_dev_get(slot->dev);
 					}
-					else
+					else {
+						/* DLPAR add as opposed to
+						 * boot time */
 						slot->state = NOT_CONFIGURED;
+					}
 				}
 				dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n",
-					__FUNCTION__, dn->full_name, slot->index, slot->name,
-					slot->power_domain, slot->type);
+					__FUNCTION__, dn->full_name, slot->index, slot->name,
+					slot->power_domain, slot->type);

 				if ((retval = register_slot(slot)))
 					goto exit;

 				num_slots++;
-
-				if (slot_name)
+
+				if (slot_name)
 					goto exit;

 			}/* for indexes */
 		}/* "pci" */
 	}/* find_all_nodes */
 exit:
-	dbg("%s - Exit: num_slots=%d rc[%d]\n",
+	dbg("%s - Exit: num_slots=%d rc[%d]\n",
 		__FUNCTION__, num_slots, retval);
 	return retval;
 }
@@ -867,12 +798,8 @@
 {
 	int 			retval = 0;

-	dbg("Entry %s\n", __FUNCTION__);
-
 	retval = rpaphp_add_slot(NULL);

-	dbg("Exit %s with retval=%d\n", __FUNCTION__, retval);
-
 	return retval;
 }

@@ -881,17 +808,12 @@
 {
 	int 			retval = 0;

-	dbg("Entry %s\n", __FUNCTION__);
-
 	init_MUTEX(&rpaphp_sem);
-
+
 	/* initialize internal data structure etc. */
 	retval = init_slots();
 	if (!num_slots)
 		retval = -ENODEV;
-
-	dbg("Exit %s with retval=%d, num_slots=%d\n",
-		__FUNCTION__, retval, num_slots);

 	return retval;
 }
@@ -904,12 +826,12 @@
 	/*
 	 * Unregister all of our slots with the pci_hotplug subsystem,
 	 * and free up all memory that we had allocated.
-	 * memory will be freed in release_slot callback.
+	 * memory will be freed in release_slot callback.
 	 */

 	list_for_each_safe (tmp, n, &rpaphp_slot_head) {
 		slot = list_entry(tmp, struct slot, rpaphp_slot_list);
-		sysfs_remove_link(slot->hotplug_slot->kobj.parent,
+		sysfs_remove_link(slot->hotplug_slot->kobj.parent,
 			slot->bridge->slot_name);
 		list_del(&slot->rpaphp_slot_list);
 		pci_hp_deregister(slot->hotplug_slot);
@@ -923,7 +845,6 @@
 {
 	int retval = 0;

-	dbg("Entry %s\n", __FUNCTION__);
 	info(DRIVER_DESC " version: " DRIVER_VERSION "\n");

 	rpaphp_debug = debug;
@@ -931,7 +852,6 @@
 	/* read all the PRA info from the system */
 	retval = init_rpa();

-	dbg("Exit %s with retval=%d\n", __FUNCTION__, retval);
 	return retval;
 }

@@ -951,21 +871,24 @@
 	if (slot == NULL)
 		return -ENODEV;

-	dbg("%s - Entry: slot[%s]\n",
-		__FUNCTION__, slot->name);
-
+	if (slot->state == CONFIGURED) {
+		dbg("%s: %s is already enabled\n",
+			__FUNCTION__, slot->name);
+		goto exit;
+	}
+
 	dbg("ENABLING SLOT %s\n", slot->name);

 	down(&rpaphp_sem);

-	retval = rpaphp_get_sensor_state(slot->index, &state);
-
-	if (retval)
-		goto exit;
+	retval = rpaphp_get_sensor_state(slot->index, &state);
+
+	if (retval)
+		goto exit;

 	dbg("%s: sensor state[%d]\n", __FUNCTION__, state);

-	/* if slot is not empty, enable the adapter */
+	/* if slot is not empty, enable the adapter */
 	if (state == PRESENT) {
 		dbg("%s : slot[%s] is occupid.\n", __FUNCTION__, slot->name);

@@ -984,7 +907,7 @@
 		}

 	}
-	else if (state == EMPTY) {
+	else if (state == EMPTY) {
 		dbg("%s : slot[%s] is empty\n", __FUNCTION__, slot->name);
 		slot->state = EMPTY;
 	}
@@ -993,30 +916,26 @@
 		slot->state = NOT_VALID;
 		retval = -EINVAL;
 	}
-
-exit:
+
+exit:
 	if (slot->state != NOT_VALID)
 		rpaphp_set_attention_status(slot, LED_ON);
 	else
 		rpaphp_set_attention_status(slot, LED_ID);

 	up(&rpaphp_sem);
-	dbg("%s - Exit: rc[%d]\n",  __FUNCTION__, retval);
-
-        return retval;
+
+	return retval;
 }

 static int disable_slot(struct hotplug_slot *hotplug_slot)
 {
 	int	retval;
 	struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
-

 	if (slot == NULL)
 		return -ENODEV;
-
-	dbg("%s - Entry: slot[%s]\n",
-		__FUNCTION__, slot->name);
+
 	dbg("DISABLING SLOT %s\n", slot->name);

 	down(&rpaphp_sem);
@@ -1024,13 +943,12 @@
 	rpaphp_set_attention_status(slot, LED_ID);

 	retval = rpaphp_unconfig_adapter(slot);
-
+
 	rpaphp_set_attention_status(slot, LED_OFF);

 	up(&rpaphp_sem);

-	dbg("%s - Exit: rc[%d]\n",  __FUNCTION__, retval);
-        return retval;
+	return retval;
 }

 module_init(rpaphp_init);
diff -Nru a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c
--- a/drivers/pci/hotplug/rpaphp_pci.c	Mon Feb  9 17:05:49 2004
+++ b/drivers/pci/hotplug/rpaphp_pci.c	Mon Feb  9 17:05:49 2004
@@ -32,12 +32,12 @@
 	struct pci_dev		*retval_dev = NULL, *dev = NULL;

 	while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
-		if(!dev->bus)
+		if(!dev->bus)
 			continue;
-
-		if (dev->devfn != dn->devfn)
+
+		if (dev->devfn != dn->devfn)
 			continue;
-
+
 		if (dn->phb->global_number == pci_domain_nr(dev->bus) &&
 		    dn->busno == dev->bus->number) {
 			retval_dev = dev;
@@ -46,9 +46,9 @@
 	}

 	return retval_dev;
-
+
 }
-
+
 int rpaphp_claim_resource(struct pci_dev *dev, int resource)
 {
 	struct resource *res = &dev->resource[resource];
@@ -63,9 +63,9 @@

 	if (err) {
 		err("PCI: %s region %d of %s %s [%lx:%lx]\n",
-		       root ? "Address space collision on" :
-			      "No parent found for",
-		       resource, dtype, pci_name(dev), res->start, res->end);
+			root ? "Address space collision on" :
+			"No parent found for",
+			resource, dtype, pci_name(dev), res->start, res->end);
 	}

 	return err;


** Sent via the linuxppc64-dev mail list. See http://lists.linuxppc.org/





More information about the Linuxppc64-dev mailing list