diff options
author | Alex Chiang <achiang@hp.com> | 2008-08-21 17:13:47 -0400 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2008-08-21 18:15:31 -0400 |
commit | d6a9e9b40be7da84f82eb414c2ad98c5bb69986b (patch) | |
tree | 28737d4feaa4b16f63b498229ae13653947f7b36 | |
parent | 167e782e301188c7c7e31e486bbeea5f918324c1 (diff) |
PCI: shpchp: Rename duplicate slot name N as N-1, N-2, N-M...
Commit ef0ff95f136f0f2d035667af5d18b824609de320 (shpchp: fix slot name)
introduces the shpchp_slot_with_bus module parameter, which was intended
to help work around broken firmware that assigns the same name to multiple
slots.
Commit b3bd307c628af2f0a581c42d5d7e4bcdbbf64b6a (shpchp: add message about
shpchp_slot_with_bus option) tells the user to use the above parameter
in the event of a name collision.
This approach is sub-optimal because it requires too much work from
the user.
Instead, let's rename the slot on behalf of the user. If firmware
assigns the name N to multiple slots, then:
The first registered slot is assigned N
The second registered slot is assigned N-1
The third registered slot is assigned N-2
The Mth registered slot becomes N-M
In the event we overflow the slot->name parameter, we report an
error to the user.
This is a temporary fix until the entire PCI core can be reworked
such that individual drivers no longer have to manage their own
slot names.
Tested-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Acked-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: Alex Chiang <achiang@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
-rw-r--r-- | drivers/pci/hotplug/shpchp_core.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c index a8cbd039b85b..cc38615395f1 100644 --- a/drivers/pci/hotplug/shpchp_core.c +++ b/drivers/pci/hotplug/shpchp_core.c | |||
@@ -39,7 +39,6 @@ | |||
39 | int shpchp_debug; | 39 | int shpchp_debug; |
40 | int shpchp_poll_mode; | 40 | int shpchp_poll_mode; |
41 | int shpchp_poll_time; | 41 | int shpchp_poll_time; |
42 | static int shpchp_slot_with_bus; | ||
43 | struct workqueue_struct *shpchp_wq; | 42 | struct workqueue_struct *shpchp_wq; |
44 | 43 | ||
45 | #define DRIVER_VERSION "0.4" | 44 | #define DRIVER_VERSION "0.4" |
@@ -53,11 +52,9 @@ MODULE_LICENSE("GPL"); | |||
53 | module_param(shpchp_debug, bool, 0644); | 52 | module_param(shpchp_debug, bool, 0644); |
54 | module_param(shpchp_poll_mode, bool, 0644); | 53 | module_param(shpchp_poll_mode, bool, 0644); |
55 | module_param(shpchp_poll_time, int, 0644); | 54 | module_param(shpchp_poll_time, int, 0644); |
56 | module_param(shpchp_slot_with_bus, bool, 0644); | ||
57 | MODULE_PARM_DESC(shpchp_debug, "Debugging mode enabled or not"); | 55 | MODULE_PARM_DESC(shpchp_debug, "Debugging mode enabled or not"); |
58 | MODULE_PARM_DESC(shpchp_poll_mode, "Using polling mechanism for hot-plug events or not"); | 56 | MODULE_PARM_DESC(shpchp_poll_mode, "Using polling mechanism for hot-plug events or not"); |
59 | MODULE_PARM_DESC(shpchp_poll_time, "Polling mechanism frequency, in seconds"); | 57 | MODULE_PARM_DESC(shpchp_poll_time, "Polling mechanism frequency, in seconds"); |
60 | MODULE_PARM_DESC(shpchp_slot_with_bus, "Use bus number in the slot name"); | ||
61 | 58 | ||
62 | #define SHPC_MODULE_NAME "shpchp" | 59 | #define SHPC_MODULE_NAME "shpchp" |
63 | 60 | ||
@@ -99,23 +96,13 @@ static void release_slot(struct hotplug_slot *hotplug_slot) | |||
99 | kfree(slot); | 96 | kfree(slot); |
100 | } | 97 | } |
101 | 98 | ||
102 | static void make_slot_name(struct slot *slot) | ||
103 | { | ||
104 | if (shpchp_slot_with_bus) | ||
105 | snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", | ||
106 | slot->bus, slot->number); | ||
107 | else | ||
108 | snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d", | ||
109 | slot->number); | ||
110 | } | ||
111 | |||
112 | static int init_slots(struct controller *ctrl) | 99 | static int init_slots(struct controller *ctrl) |
113 | { | 100 | { |
114 | struct slot *slot; | 101 | struct slot *slot; |
115 | struct hotplug_slot *hotplug_slot; | 102 | struct hotplug_slot *hotplug_slot; |
116 | struct hotplug_slot_info *info; | 103 | struct hotplug_slot_info *info; |
117 | int retval = -ENOMEM; | 104 | int retval = -ENOMEM; |
118 | int i; | 105 | int i, len, dup = 1; |
119 | 106 | ||
120 | for (i = 0; i < ctrl->num_slots; i++) { | 107 | for (i = 0; i < ctrl->num_slots; i++) { |
121 | slot = kzalloc(sizeof(*slot), GFP_KERNEL); | 108 | slot = kzalloc(sizeof(*slot), GFP_KERNEL); |
@@ -146,7 +133,7 @@ static int init_slots(struct controller *ctrl) | |||
146 | /* register this slot with the hotplug pci core */ | 133 | /* register this slot with the hotplug pci core */ |
147 | hotplug_slot->private = slot; | 134 | hotplug_slot->private = slot; |
148 | hotplug_slot->release = &release_slot; | 135 | hotplug_slot->release = &release_slot; |
149 | make_slot_name(slot); | 136 | snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number); |
150 | hotplug_slot->ops = &shpchp_hotplug_slot_ops; | 137 | hotplug_slot->ops = &shpchp_hotplug_slot_ops; |
151 | 138 | ||
152 | get_power_status(hotplug_slot, &info->power_status); | 139 | get_power_status(hotplug_slot, &info->power_status); |
@@ -157,14 +144,23 @@ static int init_slots(struct controller *ctrl) | |||
157 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " | 144 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " |
158 | "slot_device_offset=%x\n", slot->bus, slot->device, | 145 | "slot_device_offset=%x\n", slot->bus, slot->device, |
159 | slot->hp_slot, slot->number, ctrl->slot_device_offset); | 146 | slot->hp_slot, slot->number, ctrl->slot_device_offset); |
147 | duplicate_name: | ||
160 | retval = pci_hp_register(slot->hotplug_slot, | 148 | retval = pci_hp_register(slot->hotplug_slot, |
161 | ctrl->pci_dev->subordinate, slot->device); | 149 | ctrl->pci_dev->subordinate, slot->device); |
162 | if (retval) { | 150 | if (retval) { |
151 | /* | ||
152 | * If slot N already exists, we'll try to create | ||
153 | * slot N-1, N-2 ... N-M, until we overflow. | ||
154 | */ | ||
155 | if (retval == -EEXIST) { | ||
156 | len = snprintf(slot->name, SLOT_NAME_SIZE, | ||
157 | "%d-%d", slot->number, dup++); | ||
158 | if (len < SLOT_NAME_SIZE) | ||
159 | goto duplicate_name; | ||
160 | else | ||
161 | err("duplicate slot name overflow\n"); | ||
162 | } | ||
163 | err("pci_hp_register failed with error %d\n", retval); | 163 | err("pci_hp_register failed with error %d\n", retval); |
164 | if (retval == -EEXIST) | ||
165 | err("Failed to register slot because of name " | ||
166 | "collision. Try \'shpchp_slot_with_bus\' " | ||
167 | "module option.\n"); | ||
168 | goto error_info; | 164 | goto error_info; |
169 | } | 165 | } |
170 | 166 | ||