Commit f9da4716 authored by Linda Xie's avatar Linda Xie Committed by Greg Kroah-Hartman

[PATCH] PCI Hotplug: rpaphp.patch -- multi-function devices not handled correctly

I made changes to rpaphp code, so it can handle multi-fuction
devices correctly. The problem is that the pci_dev field of slot struct
can only record one pci_dev of  the devices of a multi-fuction card.  I
changed pci_dev (a single pci_dev type pointer) to pci_funcs( a list of
pci_dev type pointers). I  rewrote some of the config/unconfig code to
support  the slot struct change.

Along with above changes,  I added LDRSLOT(logical I/O slot) support.
We need LDRSLOT support for DLPAR I/O.  A card in a LDRSLOT can't be
physically removed, but can be logically removed  from one partiton and
reassinged to another partition.

I also merged rpaphp changes from ames tree.
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 42d5f1e1
...@@ -24,25 +24,6 @@ ...@@ -24,25 +24,6 @@
static DECLARE_MUTEX(rpadlpar_sem); 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);
return (int) (ptr != NULL);
}
static char *get_node_drc_name(struct device_node *dn)
{
char *ptr = NULL;
int *drc_names;
drc_names = (int *) get_property(dn, "ibm,drc-names", NULL);
if (drc_names)
ptr = (char *) &drc_names[1];
return ptr;
}
static struct device_node *find_php_slot_vio_node(char *drc_name) static struct device_node *find_php_slot_vio_node(char *drc_name)
{ {
struct device_node *child; struct device_node *child;
...@@ -53,9 +34,9 @@ static struct device_node *find_php_slot_vio_node(char *drc_name) ...@@ -53,9 +34,9 @@ static struct device_node *find_php_slot_vio_node(char *drc_name)
return NULL; return NULL;
for (child = of_get_next_child(parent, NULL); for (child = of_get_next_child(parent, NULL);
child; child = of_get_next_child(parent, child)) { child; child = of_get_next_child(parent, child)) {
loc_code = get_property(child, "ibm,loc-code", NULL); loc_code = get_property(child, "ibm,loc-code", NULL);
if (loc_code && !strcmp(loc_code, drc_name)) if (loc_code && !strncmp(loc_code, drc_name, strlen(drc_name)))
return child; return child;
} }
...@@ -69,7 +50,7 @@ static struct device_node *find_php_slot_pci_node(char *drc_name) ...@@ -69,7 +50,7 @@ static struct device_node *find_php_slot_pci_node(char *drc_name)
while ((np = of_find_node_by_type(np, "pci"))) while ((np = of_find_node_by_type(np, "pci")))
if (is_hotplug_capable(np)) { if (is_hotplug_capable(np)) {
name = get_node_drc_name(np); name = rpaphp_get_drc_name(np);
if (name && (!strcmp(drc_name, name))) if (name && (!strcmp(drc_name, name)))
break; break;
} }
...@@ -324,6 +305,7 @@ int dlpar_remove_pci_slot(struct slot *slot, char *drc_name) ...@@ -324,6 +305,7 @@ int dlpar_remove_pci_slot(struct slot *slot, char *drc_name)
} }
/* Remove pci bus */ /* Remove pci bus */
if (dlpar_pci_remove_bus(bridge_dev)) { if (dlpar_pci_remove_bus(bridge_dev)) {
printk(KERN_ERR "%s: unable to remove pci bus %s\n", printk(KERN_ERR "%s: unable to remove pci bus %s\n",
__FUNCTION__, drc_name); __FUNCTION__, drc_name);
...@@ -364,7 +346,7 @@ int dlpar_remove_slot(char *drc_name) ...@@ -364,7 +346,7 @@ int dlpar_remove_slot(char *drc_name)
rc = -EINVAL; rc = -EINVAL;
goto exit; goto exit;
} }
switch (slot->dev_type) { switch (slot->dev_type) {
case PCI_DEV: case PCI_DEV:
rc = dlpar_remove_pci_slot(slot, drc_name); rc = dlpar_remove_pci_slot(slot, drc_name);
......
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
#include <linux/pci.h> #include <linux/pci.h>
#include "pci_hotplug.h" #include "pci_hotplug.h"
#define HOTPLUG 1
#define EMBEDDED 0
#define DR_INDICATOR 9002 #define DR_INDICATOR 9002
#define DR_ENTITY_SENSE 9003 #define DR_ENTITY_SENSE 9003
...@@ -73,6 +76,11 @@ extern int debug; ...@@ -73,6 +76,11 @@ extern int debug;
#define CONFIGURED 1 #define CONFIGURED 1
#define EMPTY 0 #define EMPTY 0
struct rpaphp_pci_func {
struct pci_dev *pci_dev;
struct list_head sibling;
};
/* /*
* struct slot - slot information for each *physical* slot * struct slot - slot information for each *physical* slot
*/ */
...@@ -83,14 +91,13 @@ struct slot { ...@@ -83,14 +91,13 @@ struct slot {
u32 power_domain; u32 power_domain;
char *name; char *name;
char *location; char *location;
u8 removable;
struct device_node *dn; /* slot's device_node in OFDT */ struct device_node *dn; /* slot's device_node in OFDT */
/* dn has phb info */ /* dn has phb info */
struct pci_dev *bridge; /* slot's pci_dev in pci_devices */ struct pci_dev *bridge; /* slot's pci_dev in pci_devices */
union { union {
struct pci_dev *pci_dev; /* pci_dev of device in this slot */ struct list_head pci_funcs; /* pci_devs in PCI slot */
/* it will be used for unconfig */ struct vio_dev *vio_dev; /* vio_dev in VIO slot */
/* NULL if slot is empty */
struct vio_dev *vio_dev; /* vio_dev of the device in this slot */
} dev; } dev;
u8 dev_type; /* VIO or PCI */ u8 dev_type; /* VIO or PCI */
struct hotplug_slot *hotplug_slot; struct hotplug_slot *hotplug_slot;
...@@ -101,6 +108,13 @@ extern struct hotplug_slot_ops rpaphp_hotplug_slot_ops; ...@@ -101,6 +108,13 @@ extern struct hotplug_slot_ops rpaphp_hotplug_slot_ops;
extern struct list_head rpaphp_slot_head; extern struct list_head rpaphp_slot_head;
extern int num_slots; extern int num_slots;
static inline int is_hotplug_capable(struct device_node *dn)
{
unsigned char *ptr = get_property(dn, "ibm,fw-pci-hot-plug-ctrl", NULL);
return (int) (ptr != NULL);
}
/* function prototypes */ /* function prototypes */
/* rpaphp_pci.c */ /* rpaphp_pci.c */
...@@ -110,10 +124,12 @@ extern int rpaphp_enable_pci_slot(struct slot *slot); ...@@ -110,10 +124,12 @@ extern int rpaphp_enable_pci_slot(struct slot *slot);
extern int register_pci_slot(struct slot *slot); extern int register_pci_slot(struct slot *slot);
extern int rpaphp_unconfig_pci_adapter(struct slot *slot); extern int rpaphp_unconfig_pci_adapter(struct slot *slot);
extern int rpaphp_get_pci_adapter_status(struct slot *slot, int is_init, u8 * value); extern int rpaphp_get_pci_adapter_status(struct slot *slot, int is_init, u8 * value);
extern struct hotplug_slot *rpaphp_find_hotplug_slot(struct pci_dev *dev);
/* rpaphp_core.c */ /* rpaphp_core.c */
extern int rpaphp_add_slot(struct device_node *dn); extern int rpaphp_add_slot(struct device_node *dn);
extern int rpaphp_remove_slot(struct slot *slot); extern int rpaphp_remove_slot(struct slot *slot);
extern char *rpaphp_get_drc_name(struct device_node *dn);
/* rpaphp_vio.c */ /* rpaphp_vio.c */
extern int rpaphp_get_vio_adapter_status(struct slot *slot, int is_init, u8 * value); extern int rpaphp_get_vio_adapter_status(struct slot *slot, int is_init, u8 * value);
...@@ -125,8 +141,8 @@ extern int rpaphp_enable_vio_slot(struct slot *slot); ...@@ -125,8 +141,8 @@ extern int rpaphp_enable_vio_slot(struct slot *slot);
extern void dealloc_slot_struct(struct slot *slot); extern void dealloc_slot_struct(struct slot *slot);
extern struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_name, int power_domain); extern struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_name, int power_domain);
extern int register_slot(struct slot *slot); extern int register_slot(struct slot *slot);
extern int deregister_slot(struct slot *slot);
extern int rpaphp_get_power_status(struct slot *slot, u8 * value); extern int rpaphp_get_power_status(struct slot *slot, u8 * value);
extern int rpaphp_set_attention_status(struct slot *slot, u8 status); extern int rpaphp_set_attention_status(struct slot *slot, u8 status);
extern void rpaphp_sysfs_remove_attr_location(struct hotplug_slot *slot);
#endif /* _PPC64PHP_H */ #endif /* _PPC64PHP_H */
...@@ -54,6 +54,8 @@ MODULE_AUTHOR(DRIVER_AUTHOR); ...@@ -54,6 +54,8 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC); MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
void eeh_register_disable_func(int (*)(struct pci_dev *));
module_param(debug, bool, 0644); module_param(debug, bool, 0644);
static int enable_slot(struct hotplug_slot *slot); static int enable_slot(struct hotplug_slot *slot);
...@@ -63,6 +65,7 @@ static int get_power_status(struct hotplug_slot *slot, u8 * value); ...@@ -63,6 +65,7 @@ static int get_power_status(struct hotplug_slot *slot, u8 * value);
static int get_attention_status(struct hotplug_slot *slot, u8 * value); static int get_attention_status(struct hotplug_slot *slot, u8 * value);
static int get_adapter_status(struct hotplug_slot *slot, u8 * value); static int get_adapter_status(struct hotplug_slot *slot, u8 * value);
static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value); static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value);
static int rpaphp_disable_slot(struct pci_dev *dev);
struct hotplug_slot_ops rpaphp_hotplug_slot_ops = { struct hotplug_slot_ops rpaphp_hotplug_slot_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -89,7 +92,7 @@ static int rpaphp_get_attention_status(struct slot *slot) ...@@ -89,7 +92,7 @@ static int rpaphp_get_attention_status(struct slot *slot)
*/ */
static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value) 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; struct slot *slot = (struct slot *)hotplug_slot->private;
down(&rpaphp_sem); down(&rpaphp_sem);
...@@ -208,47 +211,53 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe ...@@ -208,47 +211,53 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe
int rpaphp_remove_slot(struct slot *slot) int rpaphp_remove_slot(struct slot *slot)
{ {
int retval = 0; return deregister_slot(slot);
struct hotplug_slot *php_slot = slot->hotplug_slot;
list_del(&slot->rpaphp_slot_list);
/* remove "php_location" file */
rpaphp_sysfs_remove_attr_location(php_slot);
retval = pci_hp_deregister(php_slot);
if (retval)
err("Problem unregistering a slot %s\n", slot->name);
num_slots--;
dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
return retval;
} }
static int is_php_dn(struct device_node *dn, int **indexes, int **names, int **types, static int get_dn_properties(struct device_node *dn, int **indexes, int **names,
int **power_domains) int **types, int **power_domains)
{ {
*indexes = (int *) get_property(dn, "ibm,drc-indexes", NULL); *indexes = (int *) get_property(dn, "ibm,drc-indexes", NULL);
if (!*indexes)
return 0;
/* &names[1] contains NULL terminated slot names */ /* &names[1] contains NULL terminated slot names */
*names = (int *) get_property(dn, "ibm,drc-names", NULL); *names = (int *) get_property(dn, "ibm,drc-names", NULL);
if (!*names)
return 0;
/* &types[1] contains NULL terminated slot types */ /* &types[1] contains NULL terminated slot types */
*types = (int *) get_property(dn, "ibm,drc-types", NULL); *types = (int *) get_property(dn, "ibm,drc-types", NULL);
if (!*types)
return 0;
/* power_domains[1...n] are the slot power domains */ /* power_domains[1...n] are the slot power domains */
*power_domains = (int *) get_property(dn, *power_domains = (int *) get_property(dn, "ibm,drc-power-domains", NULL);
"ibm,drc-power-domains", NULL);
if (!*power_domains) if (*indexes && *names && *types && *power_domains)
return 0; return (1);
if (strcmp(dn->name, "pci") == 0 &&
!get_property(dn, "ibm,fw-pci-hot-plug-ctrl", NULL)) return (0);
return 0; }
return 1;
static int is_php_dn(struct device_node *dn, int **indexes, int **names, int **types,
int **power_domains)
{
if (!is_hotplug_capable(dn))
return (0);
if (!get_dn_properties(dn, indexes, names, types, power_domains))
return (0);
return (1);
}
static int is_dr_dn(struct device_node *dn, int **indexes, int **names, int **types,
int **power_domains, int **my_drc_index)
{
if (!is_hotplug_capable(dn))
return (0);
*my_drc_index = (int *) get_property(dn, "ibm,my-drc-index", NULL);
if(!*my_drc_index)
return (0);
if (!dn->parent)
return (0);
return get_dn_properties(dn->parent, indexes, names, types, power_domains);
} }
static inline int is_vdevice_root(struct device_node *dn) static inline int is_vdevice_root(struct device_node *dn)
...@@ -256,15 +265,48 @@ static inline int is_vdevice_root(struct device_node *dn) ...@@ -256,15 +265,48 @@ static inline int is_vdevice_root(struct device_node *dn)
return !strcmp(dn->name, "vdevice"); return !strcmp(dn->name, "vdevice");
} }
/** char *rpaphp_get_drc_name(struct device_node *dn)
* rpaphp_add_slot: Add Hot Plug slot(s) to sysfs {
* char *name, *ptr = NULL;
*/ int *drc_names, *drc_indexes, i;
struct device_node *parent = dn->parent;
u32 *my_drc_index;
if (!parent)
return NULL;
my_drc_index = (u32 *) get_property(dn, "ibm,my-drc-index", NULL);
if (!my_drc_index)
return NULL;
drc_names = (int *) get_property(parent, "ibm,drc-names", NULL);
drc_indexes = (int *) get_property(parent, "ibm,drc-indexes", NULL);
if (!drc_names || !drc_indexes)
return NULL;
name = (char *) &drc_names[1];
for (i = 0; i < drc_indexes[0]; i++, name += (strlen(name) + 1)) {
if (drc_indexes[i + 1] == *my_drc_index) {
ptr = (char *) name;
break;
}
}
return ptr;
}
/****************************************************************
* 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) int rpaphp_add_slot(struct device_node *dn)
{ {
struct slot *slot; struct slot *slot;
int retval = 0; int retval = 0;
int i; int i, *my_drc_index, slot_type;
int *indexes, *names, *types, *power_domains; int *indexes, *names, *types, *power_domains;
char *name, *type; char *name, *type;
...@@ -277,42 +319,65 @@ int rpaphp_add_slot(struct device_node *dn) ...@@ -277,42 +319,65 @@ int rpaphp_add_slot(struct device_node *dn)
} }
/* register PCI devices */ /* register PCI devices */
if (dn->name != 0 && strcmp(dn->name, "pci") == 0 && if (dn->name != 0 && strcmp(dn->name, "pci") == 0) {
is_php_dn(dn, &indexes, &names, &types, &power_domains)) { 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]; name = (char *) &names[1];
type = (char *) &types[1]; type = (char *) &types[1];
for (i = 0; i < indexes[0]; for (i = 0; i < indexes[0]; i++,
i++, name += (strlen(name) + 1), type += (strlen(type) + 1)) {
name += (strlen(name) + 1),
type += (strlen(type) + 1)) { if ( slot_type == HOTPLUG ||
if (!(slot = alloc_slot_struct(dn, indexes[i + 1], name, (slot_type == EMBEDDED && indexes[i + 1] == my_drc_index[0])) {
power_domains[i + 1]))) {
retval = -ENOMEM; if (!(slot = alloc_slot_struct(dn, indexes[i + 1], name,
goto exit; power_domains[i + 1]))) {
retval = -ENOMEM;
goto exit;
}
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: exit:
dbg("%s - Exit: num_slots=%d rc[%d]\n", dbg("%s - Exit: num_slots=%d rc[%d]\n",
__FUNCTION__, num_slots, retval); __FUNCTION__, num_slots, retval);
return 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; 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); init_MUTEX(&rpaphp_sem);
/* initialize internal data structure etc. */ /* initialize internal data structure etc. */
for (dn = find_all_nodes(); dn; dn = dn->next) init_slots();
rpaphp_add_slot(dn);
if (!num_slots) if (!num_slots)
return -ENODEV; return -ENODEV;
...@@ -342,12 +407,18 @@ static int __init rpaphp_init(void) ...@@ -342,12 +407,18 @@ static int __init rpaphp_init(void)
{ {
info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
/* let EEH know they can use hotplug */
eeh_register_disable_func(&rpaphp_disable_slot);
/* read all the PRA info from the system */ /* read all the PRA info from the system */
return init_rpa(); return init_rpa();
} }
static void __exit rpaphp_exit(void) static void __exit rpaphp_exit(void)
{ {
/* let EEH know we are going away */
eeh_register_disable_func(NULL);
cleanup_slots(); cleanup_slots();
} }
...@@ -374,11 +445,16 @@ static int enable_slot(struct hotplug_slot *hotplug_slot) ...@@ -374,11 +445,16 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
retval = -EINVAL; retval = -EINVAL;
} }
up(&rpaphp_sem); up(&rpaphp_sem);
exit: exit:
dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval); dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
return retval; return retval;
} }
static int rpaphp_disable_slot(struct pci_dev *dev)
{
return disable_slot(rpaphp_find_hotplug_slot(dev));
}
static int disable_slot(struct hotplug_slot *hotplug_slot) static int disable_slot(struct hotplug_slot *hotplug_slot)
{ {
int retval; int retval;
...@@ -395,9 +471,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot) ...@@ -395,9 +471,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
down(&rpaphp_sem); down(&rpaphp_sem);
switch (slot->dev_type) { switch (slot->dev_type) {
case PCI_DEV: case PCI_DEV:
rpaphp_set_attention_status(slot, LED_ID);
retval = rpaphp_unconfig_pci_adapter(slot); retval = rpaphp_unconfig_pci_adapter(slot);
rpaphp_set_attention_status(slot, LED_OFF);
break; break;
case VIO_DEV: case VIO_DEV:
retval = rpaphp_unconfig_vio_adapter(slot); retval = rpaphp_unconfig_vio_adapter(slot);
...@@ -406,7 +480,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot) ...@@ -406,7 +480,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
retval = -ENODEV; retval = -ENODEV;
} }
up(&rpaphp_sem); up(&rpaphp_sem);
exit: exit:
dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval); dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
return retval; return retval;
} }
...@@ -417,3 +491,4 @@ module_exit(rpaphp_exit); ...@@ -417,3 +491,4 @@ module_exit(rpaphp_exit);
EXPORT_SYMBOL_GPL(rpaphp_add_slot); EXPORT_SYMBOL_GPL(rpaphp_add_slot);
EXPORT_SYMBOL_GPL(rpaphp_remove_slot); EXPORT_SYMBOL_GPL(rpaphp_remove_slot);
EXPORT_SYMBOL_GPL(rpaphp_slot_head); EXPORT_SYMBOL_GPL(rpaphp_slot_head);
EXPORT_SYMBOL_GPL(rpaphp_get_drc_name);
This diff is collapsed.
...@@ -29,6 +29,35 @@ ...@@ -29,6 +29,35 @@
#include <linux/pci.h> #include <linux/pci.h>
#include "rpaphp.h" #include "rpaphp.h"
static ssize_t removable_read_file (struct hotplug_slot *php_slot, char *buf)
{
u8 value;
int retval = -ENOENT;
struct slot *slot = (struct slot *)php_slot->private;
if (!slot)
return retval;
value = slot->removable;
retval = sprintf (buf, "%d\n", value);
return retval;
}
static struct hotplug_slot_attribute hotplug_slot_attr_removable = {
.attr = {.name = "phy_removable", .mode = S_IFREG | S_IRUGO},
.show = removable_read_file,
};
static void rpaphp_sysfs_add_attr_removable (struct hotplug_slot *slot)
{
sysfs_create_file(&slot->kobj, &hotplug_slot_attr_removable.attr);
}
static void rpaphp_sysfs_remove_attr_removable (struct hotplug_slot *slot)
{
sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_removable.attr);
}
static ssize_t location_read_file (struct hotplug_slot *php_slot, char *buf) static ssize_t location_read_file (struct hotplug_slot *php_slot, char *buf)
{ {
char *value; char *value;
...@@ -53,7 +82,7 @@ static void rpaphp_sysfs_add_attr_location (struct hotplug_slot *slot) ...@@ -53,7 +82,7 @@ static void rpaphp_sysfs_add_attr_location (struct hotplug_slot *slot)
sysfs_create_file(&slot->kobj, &hotplug_slot_attr_location.attr); sysfs_create_file(&slot->kobj, &hotplug_slot_attr_location.attr);
} }
void rpaphp_sysfs_remove_attr_location (struct hotplug_slot *slot) static void rpaphp_sysfs_remove_attr_location (struct hotplug_slot *slot)
{ {
sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_location.attr); sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_location.attr);
} }
...@@ -68,6 +97,17 @@ static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot) ...@@ -68,6 +97,17 @@ static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
void dealloc_slot_struct(struct slot *slot) void dealloc_slot_struct(struct slot *slot)
{ {
struct list_head *ln, *n;
if (slot->dev_type == PCI_DEV) {
list_for_each_safe (ln, n, &slot->dev.pci_funcs) {
struct rpaphp_pci_func *func;
func = list_entry(ln, struct rpaphp_pci_func, sibling);
kfree(func);
}
}
kfree(slot->hotplug_slot->info); kfree(slot->hotplug_slot->info);
kfree(slot->hotplug_slot->name); kfree(slot->hotplug_slot->name);
kfree(slot->hotplug_slot); kfree(slot->hotplug_slot);
...@@ -86,7 +126,7 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_ ...@@ -86,7 +126,7 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_
memset(slot, 0, sizeof (struct slot)); memset(slot, 0, sizeof (struct slot));
slot->hotplug_slot = kmalloc(sizeof (struct hotplug_slot), GFP_KERNEL); slot->hotplug_slot = kmalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
if (!slot->hotplug_slot) if (!slot->hotplug_slot)
goto error_slot; goto error_slot;
memset(slot->hotplug_slot, 0, sizeof (struct hotplug_slot)); 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); GFP_KERNEL);
...@@ -95,7 +135,7 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_ ...@@ -95,7 +135,7 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_
memset(slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info)); memset(slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info));
slot->hotplug_slot->name = kmalloc(BUS_ID_SIZE + 1, GFP_KERNEL); slot->hotplug_slot->name = kmalloc(BUS_ID_SIZE + 1, GFP_KERNEL);
if (!slot->hotplug_slot->name) if (!slot->hotplug_slot->name)
goto error_info; goto error_info;
slot->location = kmalloc(strlen(drc_name) + 1, GFP_KERNEL); slot->location = kmalloc(strlen(drc_name) + 1, GFP_KERNEL);
if (!slot->location) if (!slot->location)
goto error_name; goto error_name;
...@@ -107,9 +147,8 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_ ...@@ -107,9 +147,8 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_
slot->hotplug_slot->private = slot; slot->hotplug_slot->private = slot;
slot->hotplug_slot->ops = &rpaphp_hotplug_slot_ops; slot->hotplug_slot->ops = &rpaphp_hotplug_slot_ops;
slot->hotplug_slot->release = &rpaphp_release_slot; slot->hotplug_slot->release = &rpaphp_release_slot;
slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
return (slot);
return slot;
error_name: error_name:
kfree(slot->hotplug_slot->name); kfree(slot->hotplug_slot->name);
...@@ -123,15 +162,56 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_ ...@@ -123,15 +162,56 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_
return NULL; return NULL;
} }
static int is_registered(struct slot *slot)
{
struct slot *tmp_slot;
list_for_each_entry(tmp_slot, &rpaphp_slot_head, rpaphp_slot_list) {
if (!strcmp(tmp_slot->name, slot->name))
return 1;
}
return 0;
}
int deregister_slot(struct slot *slot)
{
int retval = 0;
struct hotplug_slot *php_slot = slot->hotplug_slot;
dbg("%s - Entry: deregistering slot=%s\n",
__FUNCTION__, slot->name);
list_del(&slot->rpaphp_slot_list);
/* remove "phy_location" file */
rpaphp_sysfs_remove_attr_location(php_slot);
/* remove "phy_removable" file */
rpaphp_sysfs_remove_attr_removable(php_slot);
retval = pci_hp_deregister(php_slot);
if (retval)
err("Problem unregistering a slot %s\n", slot->name);
else
num_slots--;
dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
return retval;
}
int register_slot(struct slot *slot) int register_slot(struct slot *slot)
{ {
int retval; int retval;
char *vio_uni_addr = NULL;
dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n", dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n",
__FUNCTION__, slot->dn->full_name, slot->index, slot->name, __FUNCTION__, slot->dn->full_name, slot->index, slot->name,
slot->power_domain, slot->type); slot->power_domain, slot->type);
/* should not try to register the same slot twice */
if (is_registered(slot)) { /* should't be here */
err("register_slot: slot[%s] is already registered\n", slot->name);
rpaphp_release_slot(slot->hotplug_slot);
return 1;
}
retval = pci_hp_register(slot->hotplug_slot); retval = pci_hp_register(slot->hotplug_slot);
if (retval) { if (retval) {
err("pci_hp_register failed with error %d\n", retval); err("pci_hp_register failed with error %d\n", retval);
...@@ -142,30 +222,40 @@ int register_slot(struct slot *slot) ...@@ -142,30 +222,40 @@ int register_slot(struct slot *slot)
/* create "phy_locatoin" file */ /* create "phy_locatoin" file */
rpaphp_sysfs_add_attr_location(slot->hotplug_slot); rpaphp_sysfs_add_attr_location(slot->hotplug_slot);
/* create "phy_removable" file */
rpaphp_sysfs_add_attr_removable(slot->hotplug_slot);
/* add slot to our internal list */ /* 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); __FUNCTION__, slot->name);
list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head); list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);
if (vio_uni_addr) if (slot->dev_type == VIO_DEV)
info("Slot [%s](vio_uni_addr=%s) registered\n", info("Slot [%s](VIO location=%s) registered\n",
slot->name, vio_uni_addr); slot->name, slot->location);
else else
info("Slot [%s](bus_id=%s) registered\n", info("Slot [%s](PCI location=%s) registered\n",
slot->name, pci_name(slot->bridge)); slot->name, slot->location);
num_slots++; num_slots++;
return 0; return 0;
} }
int rpaphp_get_power_status(struct slot *slot, u8 * value) int rpaphp_get_power_status(struct slot *slot, u8 * value)
{ {
int rc; int rc = 0;
rc = rtas_get_power_level(slot->power_domain, (int *) value); if (slot->type == EMBEDDED) {
if (rc) dbg("%s set to POWER_ON for EMBEDDED slot %s\n",
err("failed to get power-level for slot(%s), rc=0x%x\n", __FUNCTION__, slot->location);
slot->name, rc); *value = POWER_ON;
}
else {
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->location, rc);
}
return rc; return rc;
} }
...@@ -177,8 +267,8 @@ int rpaphp_set_attention_status(struct slot *slot, u8 status) ...@@ -177,8 +267,8 @@ int rpaphp_set_attention_status(struct slot *slot, u8 status)
/* status: LED_OFF or LED_ON */ /* status: LED_OFF or LED_ON */
rc = rtas_set_indicator(DR_INDICATOR, slot->index, status); rc = rtas_set_indicator(DR_INDICATOR, slot->index, status);
if (rc) if (rc)
err("slot(%s) set attention-status(%d) failed! rc=0x%x\n", err("slot(name=%s location=%s index=0x%x) set attention-status(%d) failed! rc=0x%x\n",
slot->name, status, rc); slot->name, slot->location, slot->index, status, rc);
return rc; return rc;
} }
...@@ -74,12 +74,12 @@ int register_vio_slot(struct device_node *dn) ...@@ -74,12 +74,12 @@ int register_vio_slot(struct device_node *dn)
int rc = 1; int rc = 1;
struct slot *slot = NULL; struct slot *slot = NULL;
name = rpaphp_get_drc_name(dn);
if (!name)
goto exit_rc;
index = (u32 *) get_property(dn, "ibm,my-drc-index", NULL); index = (u32 *) get_property(dn, "ibm,my-drc-index", NULL);
if (!index) if (!index)
goto exit_rc; goto exit_rc;
name = get_property(dn, "ibm,loc-code", NULL);
if (!name)
goto exit_rc;
if (!(slot = alloc_slot_struct(dn, *index, name, 0))) { if (!(slot = alloc_slot_struct(dn, *index, name, 0))) {
rc = -ENOMEM; rc = -ENOMEM;
goto exit_rc; goto exit_rc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment