aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-10-23 13:16:53 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-23 13:16:53 -0400
commita3415dc34f4a615a904852e7a9d0cc2877007e9e (patch)
tree0072b4b3f266c03220ffb2a9b329b2591f2a8e19 /drivers/pci
parentb4d0b08a4c3947c6ac004c9d83154ec5999c1861 (diff)
parent05a34f51ba451c65773ad6f1acf4cc089cc474d8 (diff)
Merge branch 'linux-next' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6
* 'linux-next' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6: (32 commits) PCI hotplug: fix logic in Compaq hotplug controller bus speed setup PCI: don't export linux/io.h from pci.h PCI: PCI_QUIRKS depends on PCI PCI hotplug: pciehp: poll data link layer link active PCI hotplug: pciehp: fix possible memory leak in pcie_init PCI: Workaround invalid P2P bridge bus numbers PCI Hotplug: fakephp: add duplicate slot name debugging PCI: Hotplug core: remove 'name' PCI: shcphp: remove 'name' parameter PCI: SGI Hotplug: stop managing bss_hotplug_slot->name PCI: rpaphp: kmalloc/kfree slot->name directly PCI: pciehp: remove 'name' parameter PCI: ibmphp: stop managing hotplug_slot->name PCI: fakephp: remove 'name' parameter PCI, PCI Hotplug: introduce slot_name helpers PCI: cpqphp: stop managing hotplug_slot->name PCI: cpci_hotplug: stop managing hotplug_slot->name PCI: acpiphp: remove 'name' parameter PCI: prevent duplicate slot names PCI Hotplug: serialize pci_hp_register and pci_hp_deregister ...
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/hotplug/acpiphp.h9
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c32
-rw-r--r--drivers/pci/hotplug/cpci_hotplug.h6
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_core.c75
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_pci.c4
-rw-r--r--drivers/pci/hotplug/cpqphp.h13
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c43
-rw-r--r--drivers/pci/hotplug/cpqphp_ctrl.c2
-rw-r--r--drivers/pci/hotplug/fakephp.c26
-rw-r--r--drivers/pci/hotplug/ibmphp.h5
-rw-r--r--drivers/pci/hotplug/ibmphp_ebda.c19
-rw-r--r--drivers/pci/hotplug/pci_hotplug_core.c64
-rw-r--r--drivers/pci/hotplug/pciehp.h10
-rw-r--r--drivers/pci/hotplug/pciehp_core.c49
-rw-r--r--drivers/pci/hotplug/pciehp_ctrl.c56
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c60
-rw-r--r--drivers/pci/hotplug/rpaphp_slot.c10
-rw-r--r--drivers/pci/hotplug/sgi_hotplug.c18
-rw-r--r--drivers/pci/hotplug/shpchp.h9
-rw-r--r--drivers/pci/hotplug/shpchp_core.c52
-rw-r--r--drivers/pci/hotplug/shpchp_ctrl.c48
-rw-r--r--drivers/pci/msi.c21
-rw-r--r--drivers/pci/pci-acpi.c85
-rw-r--r--drivers/pci/pci.c101
-rw-r--r--drivers/pci/pci.h2
-rw-r--r--drivers/pci/probe.c12
-rw-r--r--drivers/pci/search.c9
-rw-r--r--drivers/pci/slot.c160
28 files changed, 614 insertions, 386 deletions
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index 5a58b075dd8d..f9e244da30ae 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -50,9 +50,6 @@
50#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 50#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
51#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 51#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
52 52
53/* name size which is used for entries in pcihpfs */
54#define SLOT_NAME_SIZE 20 /* {_SUN} */
55
56struct acpiphp_bridge; 53struct acpiphp_bridge;
57struct acpiphp_slot; 54struct acpiphp_slot;
58 55
@@ -63,9 +60,13 @@ struct slot {
63 struct hotplug_slot *hotplug_slot; 60 struct hotplug_slot *hotplug_slot;
64 struct acpiphp_slot *acpi_slot; 61 struct acpiphp_slot *acpi_slot;
65 struct hotplug_slot_info info; 62 struct hotplug_slot_info info;
66 char name[SLOT_NAME_SIZE];
67}; 63};
68 64
65static inline const char *slot_name(struct slot *slot)
66{
67 return hotplug_slot_name(slot->hotplug_slot);
68}
69
69/* 70/*
70 * struct acpiphp_bridge - PCI bridge information 71 * struct acpiphp_bridge - PCI bridge information
71 * 72 *
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index 0e496e866a84..95b536a23d25 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -44,6 +44,9 @@
44 44
45#define MY_NAME "acpiphp" 45#define MY_NAME "acpiphp"
46 46
47/* name size which is used for entries in pcihpfs */
48#define SLOT_NAME_SIZE 21 /* {_SUN} */
49
47static int debug; 50static int debug;
48int acpiphp_debug; 51int acpiphp_debug;
49 52
@@ -84,7 +87,6 @@ static struct hotplug_slot_ops acpi_hotplug_slot_ops = {
84 .get_adapter_status = get_adapter_status, 87 .get_adapter_status = get_adapter_status,
85}; 88};
86 89
87
88/** 90/**
89 * acpiphp_register_attention - set attention LED callback 91 * acpiphp_register_attention - set attention LED callback
90 * @info: must be completely filled with LED callbacks 92 * @info: must be completely filled with LED callbacks
@@ -136,7 +138,7 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
136{ 138{
137 struct slot *slot = hotplug_slot->private; 139 struct slot *slot = hotplug_slot->private;
138 140
139 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 141 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
140 142
141 /* enable the specified slot */ 143 /* enable the specified slot */
142 return acpiphp_enable_slot(slot->acpi_slot); 144 return acpiphp_enable_slot(slot->acpi_slot);
@@ -154,7 +156,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
154 struct slot *slot = hotplug_slot->private; 156 struct slot *slot = hotplug_slot->private;
155 int retval; 157 int retval;
156 158
157 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 159 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
158 160
159 /* disable the specified slot */ 161 /* disable the specified slot */
160 retval = acpiphp_disable_slot(slot->acpi_slot); 162 retval = acpiphp_disable_slot(slot->acpi_slot);
@@ -177,7 +179,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
177 { 179 {
178 int retval = -ENODEV; 180 int retval = -ENODEV;
179 181
180 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 182 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot_name(hotplug_slot));
181 183
182 if (attention_info && try_module_get(attention_info->owner)) { 184 if (attention_info && try_module_get(attention_info->owner)) {
183 retval = attention_info->set_attn(hotplug_slot, status); 185 retval = attention_info->set_attn(hotplug_slot, status);
@@ -200,7 +202,7 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
200{ 202{
201 struct slot *slot = hotplug_slot->private; 203 struct slot *slot = hotplug_slot->private;
202 204
203 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 205 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
204 206
205 *value = acpiphp_get_power_status(slot->acpi_slot); 207 *value = acpiphp_get_power_status(slot->acpi_slot);
206 208
@@ -222,7 +224,7 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
222{ 224{
223 int retval = -EINVAL; 225 int retval = -EINVAL;
224 226
225 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 227 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot_name(hotplug_slot));
226 228
227 if (attention_info && try_module_get(attention_info->owner)) { 229 if (attention_info && try_module_get(attention_info->owner)) {
228 retval = attention_info->get_attn(hotplug_slot, value); 230 retval = attention_info->get_attn(hotplug_slot, value);
@@ -245,7 +247,7 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
245{ 247{
246 struct slot *slot = hotplug_slot->private; 248 struct slot *slot = hotplug_slot->private;
247 249
248 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 250 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
249 251
250 *value = acpiphp_get_latch_status(slot->acpi_slot); 252 *value = acpiphp_get_latch_status(slot->acpi_slot);
251 253
@@ -265,7 +267,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
265{ 267{
266 struct slot *slot = hotplug_slot->private; 268 struct slot *slot = hotplug_slot->private;
267 269
268 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 270 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
269 271
270 *value = acpiphp_get_adapter_status(slot->acpi_slot); 272 *value = acpiphp_get_adapter_status(slot->acpi_slot);
271 273
@@ -299,7 +301,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
299{ 301{
300 struct slot *slot = hotplug_slot->private; 302 struct slot *slot = hotplug_slot->private;
301 303
302 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 304 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
303 305
304 kfree(slot->hotplug_slot); 306 kfree(slot->hotplug_slot);
305 kfree(slot); 307 kfree(slot);
@@ -310,6 +312,7 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
310{ 312{
311 struct slot *slot; 313 struct slot *slot;
312 int retval = -ENOMEM; 314 int retval = -ENOMEM;
315 char name[SLOT_NAME_SIZE];
313 316
314 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 317 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
315 if (!slot) 318 if (!slot)
@@ -321,8 +324,6 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
321 324
322 slot->hotplug_slot->info = &slot->info; 325 slot->hotplug_slot->info = &slot->info;
323 326
324 slot->hotplug_slot->name = slot->name;
325
326 slot->hotplug_slot->private = slot; 327 slot->hotplug_slot->private = slot;
327 slot->hotplug_slot->release = &release_slot; 328 slot->hotplug_slot->release = &release_slot;
328 slot->hotplug_slot->ops = &acpi_hotplug_slot_ops; 329 slot->hotplug_slot->ops = &acpi_hotplug_slot_ops;
@@ -336,11 +337,12 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
336 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; 337 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
337 338
338 acpiphp_slot->slot = slot; 339 acpiphp_slot->slot = slot;
339 snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun); 340 snprintf(name, SLOT_NAME_SIZE, "%u", slot->acpi_slot->sun);
340 341
341 retval = pci_hp_register(slot->hotplug_slot, 342 retval = pci_hp_register(slot->hotplug_slot,
342 acpiphp_slot->bridge->pci_bus, 343 acpiphp_slot->bridge->pci_bus,
343 acpiphp_slot->device); 344 acpiphp_slot->device,
345 name);
344 if (retval == -EBUSY) 346 if (retval == -EBUSY)
345 goto error_hpslot; 347 goto error_hpslot;
346 if (retval) { 348 if (retval) {
@@ -348,7 +350,7 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
348 goto error_hpslot; 350 goto error_hpslot;
349 } 351 }
350 352
351 info("Slot [%s] registered\n", slot->hotplug_slot->name); 353 info("Slot [%s] registered\n", slot_name(slot));
352 354
353 return 0; 355 return 0;
354error_hpslot: 356error_hpslot:
@@ -365,7 +367,7 @@ void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
365 struct slot *slot = acpiphp_slot->slot; 367 struct slot *slot = acpiphp_slot->slot;
366 int retval = 0; 368 int retval = 0;
367 369
368 info ("Slot [%s] unregistered\n", slot->hotplug_slot->name); 370 info("Slot [%s] unregistered\n", slot_name(slot));
369 371
370 retval = pci_hp_deregister(slot->hotplug_slot); 372 retval = pci_hp_deregister(slot->hotplug_slot);
371 if (retval) 373 if (retval)
diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
index d9769b30be9a..9fff878cf026 100644
--- a/drivers/pci/hotplug/cpci_hotplug.h
+++ b/drivers/pci/hotplug/cpci_hotplug.h
@@ -30,6 +30,7 @@
30 30
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/pci.h> 32#include <linux/pci.h>
33#include <linux/pci_hotplug.h>
33 34
34/* PICMG 2.1 R2.0 HS CSR bits: */ 35/* PICMG 2.1 R2.0 HS CSR bits: */
35#define HS_CSR_INS 0x0080 36#define HS_CSR_INS 0x0080
@@ -69,6 +70,11 @@ struct cpci_hp_controller {
69 struct cpci_hp_controller_ops *ops; 70 struct cpci_hp_controller_ops *ops;
70}; 71};
71 72
73static inline const char *slot_name(struct slot *slot)
74{
75 return hotplug_slot_name(slot->hotplug_slot);
76}
77
72extern int cpci_hp_register_controller(struct cpci_hp_controller *controller); 78extern int cpci_hp_register_controller(struct cpci_hp_controller *controller);
73extern int cpci_hp_unregister_controller(struct cpci_hp_controller *controller); 79extern int cpci_hp_unregister_controller(struct cpci_hp_controller *controller);
74extern int cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last); 80extern int cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last);
diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c
index 935947991dc9..de94f4feef8c 100644
--- a/drivers/pci/hotplug/cpci_hotplug_core.c
+++ b/drivers/pci/hotplug/cpci_hotplug_core.c
@@ -108,7 +108,7 @@ enable_slot(struct hotplug_slot *hotplug_slot)
108 struct slot *slot = hotplug_slot->private; 108 struct slot *slot = hotplug_slot->private;
109 int retval = 0; 109 int retval = 0;
110 110
111 dbg("%s - physical_slot = %s", __func__, hotplug_slot->name); 111 dbg("%s - physical_slot = %s", __func__, slot_name(slot));
112 112
113 if (controller->ops->set_power) 113 if (controller->ops->set_power)
114 retval = controller->ops->set_power(slot, 1); 114 retval = controller->ops->set_power(slot, 1);
@@ -121,25 +121,23 @@ disable_slot(struct hotplug_slot *hotplug_slot)
121 struct slot *slot = hotplug_slot->private; 121 struct slot *slot = hotplug_slot->private;
122 int retval = 0; 122 int retval = 0;
123 123
124 dbg("%s - physical_slot = %s", __func__, hotplug_slot->name); 124 dbg("%s - physical_slot = %s", __func__, slot_name(slot));
125 125
126 down_write(&list_rwsem); 126 down_write(&list_rwsem);
127 127
128 /* Unconfigure device */ 128 /* Unconfigure device */
129 dbg("%s - unconfiguring slot %s", 129 dbg("%s - unconfiguring slot %s", __func__, slot_name(slot));
130 __func__, slot->hotplug_slot->name);
131 if ((retval = cpci_unconfigure_slot(slot))) { 130 if ((retval = cpci_unconfigure_slot(slot))) {
132 err("%s - could not unconfigure slot %s", 131 err("%s - could not unconfigure slot %s",
133 __func__, slot->hotplug_slot->name); 132 __func__, slot_name(slot));
134 goto disable_error; 133 goto disable_error;
135 } 134 }
136 dbg("%s - finished unconfiguring slot %s", 135 dbg("%s - finished unconfiguring slot %s", __func__, slot_name(slot));
137 __func__, slot->hotplug_slot->name);
138 136
139 /* Clear EXT (by setting it) */ 137 /* Clear EXT (by setting it) */
140 if (cpci_clear_ext(slot)) { 138 if (cpci_clear_ext(slot)) {
141 err("%s - could not clear EXT for slot %s", 139 err("%s - could not clear EXT for slot %s",
142 __func__, slot->hotplug_slot->name); 140 __func__, slot_name(slot));
143 retval = -ENODEV; 141 retval = -ENODEV;
144 goto disable_error; 142 goto disable_error;
145 } 143 }
@@ -214,7 +212,6 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
214 struct slot *slot = hotplug_slot->private; 212 struct slot *slot = hotplug_slot->private;
215 213
216 kfree(slot->hotplug_slot->info); 214 kfree(slot->hotplug_slot->info);
217 kfree(slot->hotplug_slot->name);
218 kfree(slot->hotplug_slot); 215 kfree(slot->hotplug_slot);
219 if (slot->dev) 216 if (slot->dev)
220 pci_dev_put(slot->dev); 217 pci_dev_put(slot->dev);
@@ -222,12 +219,6 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
222} 219}
223 220
224#define SLOT_NAME_SIZE 6 221#define SLOT_NAME_SIZE 6
225static void
226make_slot_name(struct slot *slot)
227{
228 snprintf(slot->hotplug_slot->name,
229 SLOT_NAME_SIZE, "%02x:%02x", slot->bus->number, slot->number);
230}
231 222
232int 223int
233cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last) 224cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
@@ -235,7 +226,7 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
235 struct slot *slot; 226 struct slot *slot;
236 struct hotplug_slot *hotplug_slot; 227 struct hotplug_slot *hotplug_slot;
237 struct hotplug_slot_info *info; 228 struct hotplug_slot_info *info;
238 char *name; 229 char name[SLOT_NAME_SIZE];
239 int status = -ENOMEM; 230 int status = -ENOMEM;
240 int i; 231 int i;
241 232
@@ -262,34 +253,31 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
262 goto error_hpslot; 253 goto error_hpslot;
263 hotplug_slot->info = info; 254 hotplug_slot->info = info;
264 255
265 name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
266 if (!name)
267 goto error_info;
268 hotplug_slot->name = name;
269
270 slot->bus = bus; 256 slot->bus = bus;
271 slot->number = i; 257 slot->number = i;
272 slot->devfn = PCI_DEVFN(i, 0); 258 slot->devfn = PCI_DEVFN(i, 0);
273 259
260 snprintf(name, SLOT_NAME_SIZE, "%02x:%02x", bus->number, i);
261
274 hotplug_slot->private = slot; 262 hotplug_slot->private = slot;
275 hotplug_slot->release = &release_slot; 263 hotplug_slot->release = &release_slot;
276 make_slot_name(slot);
277 hotplug_slot->ops = &cpci_hotplug_slot_ops; 264 hotplug_slot->ops = &cpci_hotplug_slot_ops;
278 265
279 /* 266 /*
280 * Initialize the slot info structure with some known 267 * Initialize the slot info structure with some known
281 * good values. 268 * good values.
282 */ 269 */
283 dbg("initializing slot %s", slot->hotplug_slot->name); 270 dbg("initializing slot %s", name);
284 info->power_status = cpci_get_power_status(slot); 271 info->power_status = cpci_get_power_status(slot);
285 info->attention_status = cpci_get_attention_status(slot); 272 info->attention_status = cpci_get_attention_status(slot);
286 273
287 dbg("registering slot %s", slot->hotplug_slot->name); 274 dbg("registering slot %s", name);
288 status = pci_hp_register(slot->hotplug_slot, bus, i); 275 status = pci_hp_register(slot->hotplug_slot, bus, i, name);
289 if (status) { 276 if (status) {
290 err("pci_hp_register failed with error %d", status); 277 err("pci_hp_register failed with error %d", status);
291 goto error_name; 278 goto error_info;
292 } 279 }
280 dbg("slot registered with name: %s", slot_name(slot));
293 281
294 /* Add slot to our internal list */ 282 /* Add slot to our internal list */
295 down_write(&list_rwsem); 283 down_write(&list_rwsem);
@@ -298,8 +286,6 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
298 up_write(&list_rwsem); 286 up_write(&list_rwsem);
299 } 287 }
300 return 0; 288 return 0;
301error_name:
302 kfree(name);
303error_info: 289error_info:
304 kfree(info); 290 kfree(info);
305error_hpslot: 291error_hpslot:
@@ -327,7 +313,7 @@ cpci_hp_unregister_bus(struct pci_bus *bus)
327 list_del(&slot->slot_list); 313 list_del(&slot->slot_list);
328 slots--; 314 slots--;
329 315
330 dbg("deregistering slot %s", slot->hotplug_slot->name); 316 dbg("deregistering slot %s", slot_name(slot));
331 status = pci_hp_deregister(slot->hotplug_slot); 317 status = pci_hp_deregister(slot->hotplug_slot);
332 if (status) { 318 if (status) {
333 err("pci_hp_deregister failed with error %d", 319 err("pci_hp_deregister failed with error %d",
@@ -379,11 +365,10 @@ init_slots(int clear_ins)
379 return -1; 365 return -1;
380 } 366 }
381 list_for_each_entry(slot, &slot_list, slot_list) { 367 list_for_each_entry(slot, &slot_list, slot_list) {
382 dbg("%s - looking at slot %s", 368 dbg("%s - looking at slot %s", __func__, slot_name(slot));
383 __func__, slot->hotplug_slot->name);
384 if (clear_ins && cpci_check_and_clear_ins(slot)) 369 if (clear_ins && cpci_check_and_clear_ins(slot))
385 dbg("%s - cleared INS for slot %s", 370 dbg("%s - cleared INS for slot %s",
386 __func__, slot->hotplug_slot->name); 371 __func__, slot_name(slot));
387 dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0)); 372 dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0));
388 if (dev) { 373 if (dev) {
389 if (update_adapter_status(slot->hotplug_slot, 1)) 374 if (update_adapter_status(slot->hotplug_slot, 1))
@@ -414,8 +399,7 @@ check_slots(void)
414 } 399 }
415 extracted = inserted = 0; 400 extracted = inserted = 0;
416 list_for_each_entry(slot, &slot_list, slot_list) { 401 list_for_each_entry(slot, &slot_list, slot_list) {
417 dbg("%s - looking at slot %s", 402 dbg("%s - looking at slot %s", __func__, slot_name(slot));
418 __func__, slot->hotplug_slot->name);
419 if (cpci_check_and_clear_ins(slot)) { 403 if (cpci_check_and_clear_ins(slot)) {
420 /* 404 /*
421 * Some broken hardware (e.g. PLX 9054AB) asserts 405 * Some broken hardware (e.g. PLX 9054AB) asserts
@@ -423,35 +407,34 @@ check_slots(void)
423 */ 407 */
424 if (slot->dev) { 408 if (slot->dev) {
425 warn("slot %s already inserted", 409 warn("slot %s already inserted",
426 slot->hotplug_slot->name); 410 slot_name(slot));
427 inserted++; 411 inserted++;
428 continue; 412 continue;
429 } 413 }
430 414
431 /* Process insertion */ 415 /* Process insertion */
432 dbg("%s - slot %s inserted", 416 dbg("%s - slot %s inserted", __func__, slot_name(slot));
433 __func__, slot->hotplug_slot->name);
434 417
435 /* GSM, debug */ 418 /* GSM, debug */
436 hs_csr = cpci_get_hs_csr(slot); 419 hs_csr = cpci_get_hs_csr(slot);
437 dbg("%s - slot %s HS_CSR (1) = %04x", 420 dbg("%s - slot %s HS_CSR (1) = %04x",
438 __func__, slot->hotplug_slot->name, hs_csr); 421 __func__, slot_name(slot), hs_csr);
439 422
440 /* Configure device */ 423 /* Configure device */
441 dbg("%s - configuring slot %s", 424 dbg("%s - configuring slot %s",
442 __func__, slot->hotplug_slot->name); 425 __func__, slot_name(slot));
443 if (cpci_configure_slot(slot)) { 426 if (cpci_configure_slot(slot)) {
444 err("%s - could not configure slot %s", 427 err("%s - could not configure slot %s",
445 __func__, slot->hotplug_slot->name); 428 __func__, slot_name(slot));
446 continue; 429 continue;
447 } 430 }
448 dbg("%s - finished configuring slot %s", 431 dbg("%s - finished configuring slot %s",
449 __func__, slot->hotplug_slot->name); 432 __func__, slot_name(slot));
450 433
451 /* GSM, debug */ 434 /* GSM, debug */
452 hs_csr = cpci_get_hs_csr(slot); 435 hs_csr = cpci_get_hs_csr(slot);
453 dbg("%s - slot %s HS_CSR (2) = %04x", 436 dbg("%s - slot %s HS_CSR (2) = %04x",
454 __func__, slot->hotplug_slot->name, hs_csr); 437 __func__, slot_name(slot), hs_csr);
455 438
456 if (update_latch_status(slot->hotplug_slot, 1)) 439 if (update_latch_status(slot->hotplug_slot, 1))
457 warn("failure to update latch file"); 440 warn("failure to update latch file");
@@ -464,18 +447,18 @@ check_slots(void)
464 /* GSM, debug */ 447 /* GSM, debug */
465 hs_csr = cpci_get_hs_csr(slot); 448 hs_csr = cpci_get_hs_csr(slot);
466 dbg("%s - slot %s HS_CSR (3) = %04x", 449 dbg("%s - slot %s HS_CSR (3) = %04x",
467 __func__, slot->hotplug_slot->name, hs_csr); 450 __func__, slot_name(slot), hs_csr);
468 451
469 inserted++; 452 inserted++;
470 } else if (cpci_check_ext(slot)) { 453 } else if (cpci_check_ext(slot)) {
471 /* Process extraction request */ 454 /* Process extraction request */
472 dbg("%s - slot %s extracted", 455 dbg("%s - slot %s extracted",
473 __func__, slot->hotplug_slot->name); 456 __func__, slot_name(slot));
474 457
475 /* GSM, debug */ 458 /* GSM, debug */
476 hs_csr = cpci_get_hs_csr(slot); 459 hs_csr = cpci_get_hs_csr(slot);
477 dbg("%s - slot %s HS_CSR = %04x", 460 dbg("%s - slot %s HS_CSR = %04x",
478 __func__, slot->hotplug_slot->name, hs_csr); 461 __func__, slot_name(slot), hs_csr);
479 462
480 if (!slot->extracting) { 463 if (!slot->extracting) {
481 if (update_latch_status(slot->hotplug_slot, 0)) { 464 if (update_latch_status(slot->hotplug_slot, 0)) {
@@ -493,7 +476,7 @@ check_slots(void)
493 * bother trying to tell the driver or not? 476 * bother trying to tell the driver or not?
494 */ 477 */
495 err("card in slot %s was improperly removed", 478 err("card in slot %s was improperly removed",
496 slot->hotplug_slot->name); 479 slot_name(slot));
497 if (update_adapter_status(slot->hotplug_slot, 0)) 480 if (update_adapter_status(slot->hotplug_slot, 0))
498 warn("failure to update adapter file"); 481 warn("failure to update adapter file");
499 slot->extracting = 0; 482 slot->extracting = 0;
diff --git a/drivers/pci/hotplug/cpci_hotplug_pci.c b/drivers/pci/hotplug/cpci_hotplug_pci.c
index df82b95e2874..829c327cfb5e 100644
--- a/drivers/pci/hotplug/cpci_hotplug_pci.c
+++ b/drivers/pci/hotplug/cpci_hotplug_pci.c
@@ -209,7 +209,7 @@ int cpci_led_on(struct slot* slot)
209 hs_cap + 2, 209 hs_cap + 2,
210 hs_csr)) { 210 hs_csr)) {
211 err("Could not set LOO for slot %s", 211 err("Could not set LOO for slot %s",
212 slot->hotplug_slot->name); 212 hotplug_slot_name(slot->hotplug_slot));
213 return -ENODEV; 213 return -ENODEV;
214 } 214 }
215 } 215 }
@@ -238,7 +238,7 @@ int cpci_led_off(struct slot* slot)
238 hs_cap + 2, 238 hs_cap + 2,
239 hs_csr)) { 239 hs_csr)) {
240 err("Could not clear LOO for slot %s", 240 err("Could not clear LOO for slot %s",
241 slot->hotplug_slot->name); 241 hotplug_slot_name(slot->hotplug_slot));
242 return -ENODEV; 242 return -ENODEV;
243 } 243 }
244 } 244 }
diff --git a/drivers/pci/hotplug/cpqphp.h b/drivers/pci/hotplug/cpqphp.h
index b1decfa88b7a..afaf8f69f73e 100644
--- a/drivers/pci/hotplug/cpqphp.h
+++ b/drivers/pci/hotplug/cpqphp.h
@@ -449,6 +449,11 @@ extern u8 cpqhp_disk_irq;
449 449
450/* inline functions */ 450/* inline functions */
451 451
452static inline char *slot_name(struct slot *slot)
453{
454 return hotplug_slot_name(slot->hotplug_slot);
455}
456
452/* 457/*
453 * return_resource 458 * return_resource
454 * 459 *
@@ -696,14 +701,6 @@ static inline int get_presence_status(struct controller *ctrl, struct slot *slot
696 return presence_save; 701 return presence_save;
697} 702}
698 703
699#define SLOT_NAME_SIZE 10
700
701static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
702{
703 snprintf(buffer, buffer_size, "%d", slot->number);
704}
705
706
707static inline int wait_for_ctrl_irq(struct controller *ctrl) 704static inline int wait_for_ctrl_irq(struct controller *ctrl)
708{ 705{
709 DECLARE_WAITQUEUE(wait, current); 706 DECLARE_WAITQUEUE(wait, current);
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index 54defec51d08..724d42c4adbc 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -315,14 +315,15 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
315{ 315{
316 struct slot *slot = hotplug_slot->private; 316 struct slot *slot = hotplug_slot->private;
317 317
318 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 318 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
319 319
320 kfree(slot->hotplug_slot->info); 320 kfree(slot->hotplug_slot->info);
321 kfree(slot->hotplug_slot->name);
322 kfree(slot->hotplug_slot); 321 kfree(slot->hotplug_slot);
323 kfree(slot); 322 kfree(slot);
324} 323}
325 324
325#define SLOT_NAME_SIZE 10
326
326static int ctrl_slot_setup(struct controller *ctrl, 327static int ctrl_slot_setup(struct controller *ctrl,
327 void __iomem *smbios_start, 328 void __iomem *smbios_start,
328 void __iomem *smbios_table) 329 void __iomem *smbios_table)
@@ -335,6 +336,7 @@ static int ctrl_slot_setup(struct controller *ctrl,
335 u8 slot_number; 336 u8 slot_number;
336 u8 ctrl_slot; 337 u8 ctrl_slot;
337 u32 tempdword; 338 u32 tempdword;
339 char name[SLOT_NAME_SIZE];
338 void __iomem *slot_entry= NULL; 340 void __iomem *slot_entry= NULL;
339 int result = -ENOMEM; 341 int result = -ENOMEM;
340 342
@@ -363,16 +365,12 @@ static int ctrl_slot_setup(struct controller *ctrl,
363 if (!hotplug_slot->info) 365 if (!hotplug_slot->info)
364 goto error_hpslot; 366 goto error_hpslot;
365 hotplug_slot_info = hotplug_slot->info; 367 hotplug_slot_info = hotplug_slot->info;
366 hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
367
368 if (!hotplug_slot->name)
369 goto error_info;
370 368
371 slot->ctrl = ctrl; 369 slot->ctrl = ctrl;
372 slot->bus = ctrl->bus; 370 slot->bus = ctrl->bus;
373 slot->device = slot_device; 371 slot->device = slot_device;
374 slot->number = slot_number; 372 slot->number = slot_number;
375 dbg("slot->number = %d\n", slot->number); 373 dbg("slot->number = %u\n", slot->number);
376 374
377 slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9, 375 slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9,
378 slot_entry); 376 slot_entry);
@@ -418,9 +416,9 @@ static int ctrl_slot_setup(struct controller *ctrl,
418 /* register this slot with the hotplug pci core */ 416 /* register this slot with the hotplug pci core */
419 hotplug_slot->release = &release_slot; 417 hotplug_slot->release = &release_slot;
420 hotplug_slot->private = slot; 418 hotplug_slot->private = slot;
421 make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot); 419 snprintf(name, SLOT_NAME_SIZE, "%u", slot->number);
422 hotplug_slot->ops = &cpqphp_hotplug_slot_ops; 420 hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
423 421
424 hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot); 422 hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot);
425 hotplug_slot_info->attention_status = 423 hotplug_slot_info->attention_status =
426 cpq_get_attention_status(ctrl, slot); 424 cpq_get_attention_status(ctrl, slot);
@@ -436,10 +434,11 @@ static int ctrl_slot_setup(struct controller *ctrl,
436 slot_number); 434 slot_number);
437 result = pci_hp_register(hotplug_slot, 435 result = pci_hp_register(hotplug_slot,
438 ctrl->pci_dev->subordinate, 436 ctrl->pci_dev->subordinate,
439 slot->device); 437 slot->device,
438 name);
440 if (result) { 439 if (result) {
441 err("pci_hp_register failed with error %d\n", result); 440 err("pci_hp_register failed with error %d\n", result);
442 goto error_name; 441 goto error_info;
443 } 442 }
444 443
445 slot->next = ctrl->slot; 444 slot->next = ctrl->slot;
@@ -451,8 +450,6 @@ static int ctrl_slot_setup(struct controller *ctrl,
451 } 450 }
452 451
453 return 0; 452 return 0;
454error_name:
455 kfree(hotplug_slot->name);
456error_info: 453error_info:
457 kfree(hotplug_slot_info); 454 kfree(hotplug_slot_info);
458error_hpslot: 455error_hpslot:
@@ -638,7 +635,7 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
638 u8 device; 635 u8 device;
639 u8 function; 636 u8 function;
640 637
641 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 638 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
642 639
643 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1) 640 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
644 return -ENODEV; 641 return -ENODEV;
@@ -665,7 +662,7 @@ static int process_SI(struct hotplug_slot *hotplug_slot)
665 u8 device; 662 u8 device;
666 u8 function; 663 u8 function;
667 664
668 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 665 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
669 666
670 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1) 667 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
671 return -ENODEV; 668 return -ENODEV;
@@ -697,7 +694,7 @@ static int process_SS(struct hotplug_slot *hotplug_slot)
697 u8 device; 694 u8 device;
698 u8 function; 695 u8 function;
699 696
700 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 697 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
701 698
702 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1) 699 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
703 return -ENODEV; 700 return -ENODEV;
@@ -720,7 +717,7 @@ static int hardware_test(struct hotplug_slot *hotplug_slot, u32 value)
720 struct slot *slot = hotplug_slot->private; 717 struct slot *slot = hotplug_slot->private;
721 struct controller *ctrl = slot->ctrl; 718 struct controller *ctrl = slot->ctrl;
722 719
723 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 720 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
724 721
725 return cpqhp_hardware_test(ctrl, value); 722 return cpqhp_hardware_test(ctrl, value);
726} 723}
@@ -731,7 +728,7 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
731 struct slot *slot = hotplug_slot->private; 728 struct slot *slot = hotplug_slot->private;
732 struct controller *ctrl = slot->ctrl; 729 struct controller *ctrl = slot->ctrl;
733 730
734 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 731 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
735 732
736 *value = get_slot_enabled(ctrl, slot); 733 *value = get_slot_enabled(ctrl, slot);
737 return 0; 734 return 0;
@@ -742,7 +739,7 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
742 struct slot *slot = hotplug_slot->private; 739 struct slot *slot = hotplug_slot->private;
743 struct controller *ctrl = slot->ctrl; 740 struct controller *ctrl = slot->ctrl;
744 741
745 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 742 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
746 743
747 *value = cpq_get_attention_status(ctrl, slot); 744 *value = cpq_get_attention_status(ctrl, slot);
748 return 0; 745 return 0;
@@ -753,7 +750,7 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
753 struct slot *slot = hotplug_slot->private; 750 struct slot *slot = hotplug_slot->private;
754 struct controller *ctrl = slot->ctrl; 751 struct controller *ctrl = slot->ctrl;
755 752
756 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 753 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
757 754
758 *value = cpq_get_latch_status(ctrl, slot); 755 *value = cpq_get_latch_status(ctrl, slot);
759 756
@@ -765,7 +762,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
765 struct slot *slot = hotplug_slot->private; 762 struct slot *slot = hotplug_slot->private;
766 struct controller *ctrl = slot->ctrl; 763 struct controller *ctrl = slot->ctrl;
767 764
768 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 765 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
769 766
770 *value = get_presence_status(ctrl, slot); 767 *value = get_presence_status(ctrl, slot);
771 768
@@ -777,7 +774,7 @@ static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
777 struct slot *slot = hotplug_slot->private; 774 struct slot *slot = hotplug_slot->private;
778 struct controller *ctrl = slot->ctrl; 775 struct controller *ctrl = slot->ctrl;
779 776
780 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 777 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
781 778
782 *value = ctrl->speed_capability; 779 *value = ctrl->speed_capability;
783 780
@@ -789,7 +786,7 @@ static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
789 struct slot *slot = hotplug_slot->private; 786 struct slot *slot = hotplug_slot->private;
790 struct controller *ctrl = slot->ctrl; 787 struct controller *ctrl = slot->ctrl;
791 788
792 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 789 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
793 790
794 *value = ctrl->speed; 791 *value = ctrl->speed;
795 792
diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
index ef041ca91c27..a60a25290995 100644
--- a/drivers/pci/hotplug/cpqphp_ctrl.c
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c
@@ -1139,7 +1139,7 @@ static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_
1139 for(slot = ctrl->slot; slot; slot = slot->next) { 1139 for(slot = ctrl->slot; slot; slot = slot->next) {
1140 if (slot->device == (hp_slot + ctrl->slot_device_offset)) 1140 if (slot->device == (hp_slot + ctrl->slot_device_offset))
1141 continue; 1141 continue;
1142 if (!slot->hotplug_slot && !slot->hotplug_slot->info) 1142 if (!slot->hotplug_slot || !slot->hotplug_slot->info)
1143 continue; 1143 continue;
1144 if (slot->hotplug_slot->info->adapter_status == 0) 1144 if (slot->hotplug_slot->info->adapter_status == 0)
1145 continue; 1145 continue;
diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index 146ca9cd1567..3a2637a00934 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -66,10 +66,10 @@ struct dummy_slot {
66 struct pci_dev *dev; 66 struct pci_dev *dev;
67 struct work_struct remove_work; 67 struct work_struct remove_work;
68 unsigned long removed; 68 unsigned long removed;
69 char name[8];
70}; 69};
71 70
72static int debug; 71static int debug;
72static int dup_slots;
73static LIST_HEAD(slot_list); 73static LIST_HEAD(slot_list);
74static struct workqueue_struct *dummyphp_wq; 74static struct workqueue_struct *dummyphp_wq;
75 75
@@ -96,10 +96,13 @@ static void dummy_release(struct hotplug_slot *slot)
96 kfree(dslot); 96 kfree(dslot);
97} 97}
98 98
99#define SLOT_NAME_SIZE 8
100
99static int add_slot(struct pci_dev *dev) 101static int add_slot(struct pci_dev *dev)
100{ 102{
101 struct dummy_slot *dslot; 103 struct dummy_slot *dslot;
102 struct hotplug_slot *slot; 104 struct hotplug_slot *slot;
105 char name[SLOT_NAME_SIZE];
103 int retval = -ENOMEM; 106 int retval = -ENOMEM;
104 static int count = 1; 107 static int count = 1;
105 108
@@ -119,19 +122,22 @@ static int add_slot(struct pci_dev *dev)
119 if (!dslot) 122 if (!dslot)
120 goto error_info; 123 goto error_info;
121 124
122 slot->name = dslot->name; 125 if (dup_slots)
123 snprintf(slot->name, sizeof(dslot->name), "fake%d", count++); 126 snprintf(name, SLOT_NAME_SIZE, "fake");
124 dbg("slot->name = %s\n", slot->name); 127 else
128 snprintf(name, SLOT_NAME_SIZE, "fake%d", count++);
129 dbg("slot->name = %s\n", name);
125 slot->ops = &dummy_hotplug_slot_ops; 130 slot->ops = &dummy_hotplug_slot_ops;
126 slot->release = &dummy_release; 131 slot->release = &dummy_release;
127 slot->private = dslot; 132 slot->private = dslot;
128 133
129 retval = pci_hp_register(slot, dev->bus, PCI_SLOT(dev->devfn)); 134 retval = pci_hp_register(slot, dev->bus, PCI_SLOT(dev->devfn), name);
130 if (retval) { 135 if (retval) {
131 err("pci_hp_register failed with error %d\n", retval); 136 err("pci_hp_register failed with error %d\n", retval);
132 goto error_dslot; 137 goto error_dslot;
133 } 138 }
134 139
140 dbg("slot->name = %s\n", hotplug_slot_name(slot));
135 dslot->slot = slot; 141 dslot->slot = slot;
136 dslot->dev = pci_dev_get(dev); 142 dslot->dev = pci_dev_get(dev);
137 list_add (&dslot->node, &slot_list); 143 list_add (&dslot->node, &slot_list);
@@ -167,10 +173,11 @@ static void remove_slot(struct dummy_slot *dslot)
167{ 173{
168 int retval; 174 int retval;
169 175
170 dbg("removing slot %s\n", dslot->slot->name); 176 dbg("removing slot %s\n", hotplug_slot_name(dslot->slot));
171 retval = pci_hp_deregister(dslot->slot); 177 retval = pci_hp_deregister(dslot->slot);
172 if (retval) 178 if (retval)
173 err("Problem unregistering a slot %s\n", dslot->slot->name); 179 err("Problem unregistering a slot %s\n",
180 hotplug_slot_name(dslot->slot));
174} 181}
175 182
176/* called from the single-threaded workqueue handler to remove a slot */ 183/* called from the single-threaded workqueue handler to remove a slot */
@@ -308,7 +315,7 @@ static int disable_slot(struct hotplug_slot *slot)
308 return -ENODEV; 315 return -ENODEV;
309 dslot = slot->private; 316 dslot = slot->private;
310 317
311 dbg("%s - physical_slot = %s\n", __func__, slot->name); 318 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot_name(slot));
312 319
313 for (func = 7; func >= 0; func--) { 320 for (func = 7; func >= 0; func--) {
314 dev = pci_get_slot(dslot->dev->bus, dslot->dev->devfn + func); 321 dev = pci_get_slot(dslot->dev->bus, dslot->dev->devfn + func);
@@ -373,4 +380,5 @@ MODULE_DESCRIPTION(DRIVER_DESC);
373MODULE_LICENSE("GPL"); 380MODULE_LICENSE("GPL");
374module_param(debug, bool, S_IRUGO | S_IWUSR); 381module_param(debug, bool, S_IRUGO | S_IWUSR);
375MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); 382MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
376 383module_param(dup_slots, bool, S_IRUGO | S_IWUSR);
384MODULE_PARM_DESC(dup_slots, "Force duplicate slot names for debugging");
diff --git a/drivers/pci/hotplug/ibmphp.h b/drivers/pci/hotplug/ibmphp.h
index 612d96301509..a8d391a4957d 100644
--- a/drivers/pci/hotplug/ibmphp.h
+++ b/drivers/pci/hotplug/ibmphp.h
@@ -707,17 +707,16 @@ struct slot {
707 u8 device; 707 u8 device;
708 u8 number; 708 u8 number;
709 u8 real_physical_slot_num; 709 u8 real_physical_slot_num;
710 char name[100];
711 u32 capabilities; 710 u32 capabilities;
712 u8 supported_speed; 711 u8 supported_speed;
713 u8 supported_bus_mode; 712 u8 supported_bus_mode;
713 u8 flag; /* this is for disable slot and polling */
714 u8 ctlr_index;
714 struct hotplug_slot *hotplug_slot; 715 struct hotplug_slot *hotplug_slot;
715 struct controller *ctrl; 716 struct controller *ctrl;
716 struct pci_func *func; 717 struct pci_func *func;
717 u8 irq[4]; 718 u8 irq[4];
718 u8 flag; /* this is for disable slot and polling */
719 int bit_mode; /* 0 = 32, 1 = 64 */ 719 int bit_mode; /* 0 = 32, 1 = 64 */
720 u8 ctlr_index;
721 struct bus_info *bus_on; 720 struct bus_info *bus_on;
722 struct list_head ibm_slot_list; 721 struct list_head ibm_slot_list;
723 u8 status; 722 u8 status;
diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c
index 8cfd1c4926c8..c1abac8ab5c3 100644
--- a/drivers/pci/hotplug/ibmphp_ebda.c
+++ b/drivers/pci/hotplug/ibmphp_ebda.c
@@ -587,11 +587,14 @@ static u8 calculate_first_slot (u8 slot_num)
587 return first_slot + 1; 587 return first_slot + 1;
588 588
589} 589}
590
591#define SLOT_NAME_SIZE 30
592
590static char *create_file_name (struct slot * slot_cur) 593static char *create_file_name (struct slot * slot_cur)
591{ 594{
592 struct opt_rio *opt_vg_ptr = NULL; 595 struct opt_rio *opt_vg_ptr = NULL;
593 struct opt_rio_lo *opt_lo_ptr = NULL; 596 struct opt_rio_lo *opt_lo_ptr = NULL;
594 static char str[30]; 597 static char str[SLOT_NAME_SIZE];
595 int which = 0; /* rxe = 1, chassis = 0 */ 598 int which = 0; /* rxe = 1, chassis = 0 */
596 u8 number = 1; /* either chassis or rxe # */ 599 u8 number = 1; /* either chassis or rxe # */
597 u8 first_slot = 1; 600 u8 first_slot = 1;
@@ -703,7 +706,6 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
703 706
704 slot = hotplug_slot->private; 707 slot = hotplug_slot->private;
705 kfree(slot->hotplug_slot->info); 708 kfree(slot->hotplug_slot->info);
706 kfree(slot->hotplug_slot->name);
707 kfree(slot->hotplug_slot); 709 kfree(slot->hotplug_slot);
708 slot->ctrl = NULL; 710 slot->ctrl = NULL;
709 slot->bus_on = NULL; 711 slot->bus_on = NULL;
@@ -734,6 +736,7 @@ static int __init ebda_rsrc_controller (void)
734 struct bus_info *bus_info_ptr1, *bus_info_ptr2; 736 struct bus_info *bus_info_ptr1, *bus_info_ptr2;
735 int rc; 737 int rc;
736 struct slot *tmp_slot; 738 struct slot *tmp_slot;
739 char name[SLOT_NAME_SIZE];
737 740
738 addr = hpc_list_ptr->phys_addr; 741 addr = hpc_list_ptr->phys_addr;
739 for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) { 742 for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) {
@@ -897,12 +900,6 @@ static int __init ebda_rsrc_controller (void)
897 goto error_no_hp_info; 900 goto error_no_hp_info;
898 } 901 }
899 902
900 hp_slot_ptr->name = kmalloc(30, GFP_KERNEL);
901 if (!hp_slot_ptr->name) {
902 rc = -ENOMEM;
903 goto error_no_hp_name;
904 }
905
906 tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL); 903 tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL);
907 if (!tmp_slot) { 904 if (!tmp_slot) {
908 rc = -ENOMEM; 905 rc = -ENOMEM;
@@ -964,9 +961,9 @@ static int __init ebda_rsrc_controller (void)
964 } /* each hpc */ 961 } /* each hpc */
965 962
966 list_for_each_entry(tmp_slot, &ibmphp_slot_head, ibm_slot_list) { 963 list_for_each_entry(tmp_slot, &ibmphp_slot_head, ibm_slot_list) {
967 snprintf (tmp_slot->hotplug_slot->name, 30, "%s", create_file_name (tmp_slot)); 964 snprintf(name, SLOT_NAME_SIZE, "%s", create_file_name(tmp_slot));
968 pci_hp_register(tmp_slot->hotplug_slot, 965 pci_hp_register(tmp_slot->hotplug_slot,
969 pci_find_bus(0, tmp_slot->bus), tmp_slot->device); 966 pci_find_bus(0, tmp_slot->bus), tmp_slot->device, name);
970 } 967 }
971 968
972 print_ebda_hpc (); 969 print_ebda_hpc ();
@@ -976,8 +973,6 @@ static int __init ebda_rsrc_controller (void)
976error: 973error:
977 kfree (hp_slot_ptr->private); 974 kfree (hp_slot_ptr->private);
978error_no_slot: 975error_no_slot:
979 kfree (hp_slot_ptr->name);
980error_no_hp_name:
981 kfree (hp_slot_ptr->info); 976 kfree (hp_slot_ptr->info);
982error_no_hp_info: 977error_no_hp_info:
983 kfree (hp_slot_ptr); 978 kfree (hp_slot_ptr);
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 2e6c4474644e..535fce0f07f9 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -37,6 +37,7 @@
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/mount.h> 38#include <linux/mount.h>
39#include <linux/namei.h> 39#include <linux/namei.h>
40#include <linux/mutex.h>
40#include <linux/pci.h> 41#include <linux/pci.h>
41#include <linux/pci_hotplug.h> 42#include <linux/pci_hotplug.h>
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
@@ -61,7 +62,7 @@ static int debug;
61////////////////////////////////////////////////////////////////// 62//////////////////////////////////////////////////////////////////
62 63
63static LIST_HEAD(pci_hotplug_slot_list); 64static LIST_HEAD(pci_hotplug_slot_list);
64static DEFINE_SPINLOCK(pci_hotplug_slot_list_lock); 65static DEFINE_MUTEX(pci_hp_mutex);
65 66
66/* these strings match up with the values in pci_bus_speed */ 67/* these strings match up with the values in pci_bus_speed */
67static char *pci_bus_speed_strings[] = { 68static char *pci_bus_speed_strings[] = {
@@ -530,16 +531,12 @@ static struct hotplug_slot *get_slot_from_name (const char *name)
530 struct hotplug_slot *slot; 531 struct hotplug_slot *slot;
531 struct list_head *tmp; 532 struct list_head *tmp;
532 533
533 spin_lock(&pci_hotplug_slot_list_lock);
534 list_for_each (tmp, &pci_hotplug_slot_list) { 534 list_for_each (tmp, &pci_hotplug_slot_list) {
535 slot = list_entry (tmp, struct hotplug_slot, slot_list); 535 slot = list_entry (tmp, struct hotplug_slot, slot_list);
536 if (strcmp(slot->name, name) == 0) 536 if (strcmp(hotplug_slot_name(slot), name) == 0)
537 goto out; 537 return slot;
538 } 538 }
539 slot = NULL; 539 return NULL;
540out:
541 spin_unlock(&pci_hotplug_slot_list_lock);
542 return slot;
543} 540}
544 541
545/** 542/**
@@ -547,13 +544,15 @@ out:
547 * @bus: bus this slot is on 544 * @bus: bus this slot is on
548 * @slot: pointer to the &struct hotplug_slot to register 545 * @slot: pointer to the &struct hotplug_slot to register
549 * @slot_nr: slot number 546 * @slot_nr: slot number
547 * @name: name registered with kobject core
550 * 548 *
551 * Registers a hotplug slot with the pci hotplug subsystem, which will allow 549 * Registers a hotplug slot with the pci hotplug subsystem, which will allow
552 * userspace interaction to the slot. 550 * userspace interaction to the slot.
553 * 551 *
554 * Returns 0 if successful, anything else for an error. 552 * Returns 0 if successful, anything else for an error.
555 */ 553 */
556int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr) 554int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr,
555 const char *name)
557{ 556{
558 int result; 557 int result;
559 struct pci_slot *pci_slot; 558 struct pci_slot *pci_slot;
@@ -568,48 +567,29 @@ int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr)
568 return -EINVAL; 567 return -EINVAL;
569 } 568 }
570 569
571 /* Check if we have already registered a slot with the same name. */ 570 mutex_lock(&pci_hp_mutex);
572 if (get_slot_from_name(slot->name))
573 return -EEXIST;
574 571
575 /* 572 /*
576 * No problems if we call this interface from both ACPI_PCI_SLOT 573 * No problems if we call this interface from both ACPI_PCI_SLOT
577 * driver and call it here again. If we've already created the 574 * driver and call it here again. If we've already created the
578 * pci_slot, the interface will simply bump the refcount. 575 * pci_slot, the interface will simply bump the refcount.
579 */ 576 */
580 pci_slot = pci_create_slot(bus, slot_nr, slot->name); 577 pci_slot = pci_create_slot(bus, slot_nr, name, slot);
581 if (IS_ERR(pci_slot)) 578 if (IS_ERR(pci_slot)) {
582 return PTR_ERR(pci_slot); 579 result = PTR_ERR(pci_slot);
583 580 goto out;
584 if (pci_slot->hotplug) {
585 dbg("%s: already claimed\n", __func__);
586 pci_destroy_slot(pci_slot);
587 return -EBUSY;
588 } 581 }
589 582
590 slot->pci_slot = pci_slot; 583 slot->pci_slot = pci_slot;
591 pci_slot->hotplug = slot; 584 pci_slot->hotplug = slot;
592 585
593 /*
594 * Allow pcihp drivers to override the ACPI_PCI_SLOT name.
595 */
596 if (strcmp(kobject_name(&pci_slot->kobj), slot->name)) {
597 result = kobject_rename(&pci_slot->kobj, slot->name);
598 if (result) {
599 pci_destroy_slot(pci_slot);
600 return result;
601 }
602 }
603
604 spin_lock(&pci_hotplug_slot_list_lock);
605 list_add(&slot->slot_list, &pci_hotplug_slot_list); 586 list_add(&slot->slot_list, &pci_hotplug_slot_list);
606 spin_unlock(&pci_hotplug_slot_list_lock);
607 587
608 result = fs_add_slot(pci_slot); 588 result = fs_add_slot(pci_slot);
609 kobject_uevent(&pci_slot->kobj, KOBJ_ADD); 589 kobject_uevent(&pci_slot->kobj, KOBJ_ADD);
610 dbg("Added slot %s to the list\n", slot->name); 590 dbg("Added slot %s to the list\n", name);
611 591out:
612 592 mutex_unlock(&pci_hp_mutex);
613 return result; 593 return result;
614} 594}
615 595
@@ -630,21 +610,23 @@ int pci_hp_deregister(struct hotplug_slot *hotplug)
630 if (!hotplug) 610 if (!hotplug)
631 return -ENODEV; 611 return -ENODEV;
632 612
633 temp = get_slot_from_name(hotplug->name); 613 mutex_lock(&pci_hp_mutex);
634 if (temp != hotplug) 614 temp = get_slot_from_name(hotplug_slot_name(hotplug));
615 if (temp != hotplug) {
616 mutex_unlock(&pci_hp_mutex);
635 return -ENODEV; 617 return -ENODEV;
618 }
636 619
637 spin_lock(&pci_hotplug_slot_list_lock);
638 list_del(&hotplug->slot_list); 620 list_del(&hotplug->slot_list);
639 spin_unlock(&pci_hotplug_slot_list_lock);
640 621
641 slot = hotplug->pci_slot; 622 slot = hotplug->pci_slot;
642 fs_remove_slot(slot); 623 fs_remove_slot(slot);
643 dbg("Removed slot %s from the list\n", hotplug->name); 624 dbg("Removed slot %s from the list\n", hotplug_slot_name(hotplug));
644 625
645 hotplug->release(hotplug); 626 hotplug->release(hotplug);
646 slot->hotplug = NULL; 627 slot->hotplug = NULL;
647 pci_destroy_slot(slot); 628 pci_destroy_slot(slot);
629 mutex_unlock(&pci_hp_mutex);
648 630
649 return 0; 631 return 0;
650} 632}
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index c367978bd7fe..a4817a841fae 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -74,15 +74,13 @@ extern struct workqueue_struct *pciehp_wq;
74struct slot { 74struct slot {
75 u8 bus; 75 u8 bus;
76 u8 device; 76 u8 device;
77 u32 number;
78 u8 state; 77 u8 state;
79 struct timer_list task_event;
80 u8 hp_slot; 78 u8 hp_slot;
79 u32 number;
81 struct controller *ctrl; 80 struct controller *ctrl;
82 struct hpc_ops *hpc_ops; 81 struct hpc_ops *hpc_ops;
83 struct hotplug_slot *hotplug_slot; 82 struct hotplug_slot *hotplug_slot;
84 struct list_head slot_list; 83 struct list_head slot_list;
85 char name[SLOT_NAME_SIZE];
86 unsigned long last_emi_toggle; 84 unsigned long last_emi_toggle;
87 struct delayed_work work; /* work for button event */ 85 struct delayed_work work; /* work for button event */
88 struct mutex lock; 86 struct mutex lock;
@@ -112,6 +110,7 @@ struct controller {
112 struct timer_list poll_timer; 110 struct timer_list poll_timer;
113 int cmd_busy; 111 int cmd_busy;
114 unsigned int no_cmd_complete:1; 112 unsigned int no_cmd_complete:1;
113 unsigned int link_active_reporting:1;
115}; 114};
116 115
117#define INT_BUTTON_IGNORE 0 116#define INT_BUTTON_IGNORE 0
@@ -175,6 +174,11 @@ int pciehp_enable_slot(struct slot *p_slot);
175int pciehp_disable_slot(struct slot *p_slot); 174int pciehp_disable_slot(struct slot *p_slot);
176int pcie_enable_notification(struct controller *ctrl); 175int pcie_enable_notification(struct controller *ctrl);
177 176
177static inline const char *slot_name(struct slot *slot)
178{
179 return hotplug_slot_name(slot->hotplug_slot);
180}
181
178static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device) 182static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device)
179{ 183{
180 struct slot *slot; 184 struct slot *slot;
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
index c748a19db89d..62be1b59c74b 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -185,7 +185,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
185 struct slot *slot = hotplug_slot->private; 185 struct slot *slot = hotplug_slot->private;
186 186
187 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 187 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
188 __func__, hotplug_slot->name); 188 __func__, hotplug_slot_name(hotplug_slot));
189 189
190 kfree(hotplug_slot->info); 190 kfree(hotplug_slot->info);
191 kfree(hotplug_slot); 191 kfree(hotplug_slot);
@@ -196,7 +196,7 @@ static int init_slots(struct controller *ctrl)
196 struct slot *slot; 196 struct slot *slot;
197 struct hotplug_slot *hotplug_slot; 197 struct hotplug_slot *hotplug_slot;
198 struct hotplug_slot_info *info; 198 struct hotplug_slot_info *info;
199 int len, dup = 1; 199 char name[SLOT_NAME_SIZE];
200 int retval = -ENOMEM; 200 int retval = -ENOMEM;
201 201
202 list_for_each_entry(slot, &ctrl->slot_list, slot_list) { 202 list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
@@ -210,41 +210,28 @@ static int init_slots(struct controller *ctrl)
210 210
211 /* register this slot with the hotplug pci core */ 211 /* register this slot with the hotplug pci core */
212 hotplug_slot->info = info; 212 hotplug_slot->info = info;
213 hotplug_slot->name = slot->name;
214 hotplug_slot->private = slot; 213 hotplug_slot->private = slot;
215 hotplug_slot->release = &release_slot; 214 hotplug_slot->release = &release_slot;
216 hotplug_slot->ops = &pciehp_hotplug_slot_ops; 215 hotplug_slot->ops = &pciehp_hotplug_slot_ops;
217 get_power_status(hotplug_slot, &info->power_status);
218 get_attention_status(hotplug_slot, &info->attention_status);
219 get_latch_status(hotplug_slot, &info->latch_status);
220 get_adapter_status(hotplug_slot, &info->adapter_status);
221 slot->hotplug_slot = hotplug_slot; 216 slot->hotplug_slot = hotplug_slot;
217 snprintf(name, SLOT_NAME_SIZE, "%u", slot->number);
222 218
223 ctrl_dbg(ctrl, "Registering bus=%x dev=%x hp_slot=%x sun=%x " 219 ctrl_dbg(ctrl, "Registering bus=%x dev=%x hp_slot=%x sun=%x "
224 "slot_device_offset=%x\n", slot->bus, slot->device, 220 "slot_device_offset=%x\n", slot->bus, slot->device,
225 slot->hp_slot, slot->number, ctrl->slot_device_offset); 221 slot->hp_slot, slot->number, ctrl->slot_device_offset);
226duplicate_name:
227 retval = pci_hp_register(hotplug_slot, 222 retval = pci_hp_register(hotplug_slot,
228 ctrl->pci_dev->subordinate, 223 ctrl->pci_dev->subordinate,
229 slot->device); 224 slot->device,
225 name);
230 if (retval) { 226 if (retval) {
231 /*
232 * If slot N already exists, we'll try to create
233 * slot N-1, N-2 ... N-M, until we overflow.
234 */
235 if (retval == -EEXIST) {
236 len = snprintf(slot->name, SLOT_NAME_SIZE,
237 "%d-%d", slot->number, dup++);
238 if (len < SLOT_NAME_SIZE)
239 goto duplicate_name;
240 else
241 ctrl_err(ctrl, "duplicate slot name "
242 "overflow\n");
243 }
244 ctrl_err(ctrl, "pci_hp_register failed with error %d\n", 227 ctrl_err(ctrl, "pci_hp_register failed with error %d\n",
245 retval); 228 retval);
246 goto error_info; 229 goto error_info;
247 } 230 }
231 get_power_status(hotplug_slot, &info->power_status);
232 get_attention_status(hotplug_slot, &info->attention_status);
233 get_latch_status(hotplug_slot, &info->latch_status);
234 get_adapter_status(hotplug_slot, &info->adapter_status);
248 /* create additional sysfs entries */ 235 /* create additional sysfs entries */
249 if (EMI(ctrl)) { 236 if (EMI(ctrl)) {
250 retval = sysfs_create_file(&hotplug_slot->pci_slot->kobj, 237 retval = sysfs_create_file(&hotplug_slot->pci_slot->kobj,
@@ -287,7 +274,7 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
287 struct slot *slot = hotplug_slot->private; 274 struct slot *slot = hotplug_slot->private;
288 275
289 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 276 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
290 __func__, hotplug_slot->name); 277 __func__, slot_name(slot));
291 278
292 hotplug_slot->info->attention_status = status; 279 hotplug_slot->info->attention_status = status;
293 280
@@ -303,7 +290,7 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
303 struct slot *slot = hotplug_slot->private; 290 struct slot *slot = hotplug_slot->private;
304 291
305 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 292 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
306 __func__, hotplug_slot->name); 293 __func__, slot_name(slot));
307 294
308 return pciehp_sysfs_enable_slot(slot); 295 return pciehp_sysfs_enable_slot(slot);
309} 296}
@@ -314,7 +301,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
314 struct slot *slot = hotplug_slot->private; 301 struct slot *slot = hotplug_slot->private;
315 302
316 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 303 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
317 __func__, hotplug_slot->name); 304 __func__, slot_name(slot));
318 305
319 return pciehp_sysfs_disable_slot(slot); 306 return pciehp_sysfs_disable_slot(slot);
320} 307}
@@ -325,7 +312,7 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
325 int retval; 312 int retval;
326 313
327 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 314 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
328 __func__, hotplug_slot->name); 315 __func__, slot_name(slot));
329 316
330 retval = slot->hpc_ops->get_power_status(slot, value); 317 retval = slot->hpc_ops->get_power_status(slot, value);
331 if (retval < 0) 318 if (retval < 0)
@@ -340,7 +327,7 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
340 int retval; 327 int retval;
341 328
342 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 329 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
343 __func__, hotplug_slot->name); 330 __func__, slot_name(slot));
344 331
345 retval = slot->hpc_ops->get_attention_status(slot, value); 332 retval = slot->hpc_ops->get_attention_status(slot, value);
346 if (retval < 0) 333 if (retval < 0)
@@ -355,7 +342,7 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
355 int retval; 342 int retval;
356 343
357 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 344 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
358 __func__, hotplug_slot->name); 345 __func__, slot_name(slot));
359 346
360 retval = slot->hpc_ops->get_latch_status(slot, value); 347 retval = slot->hpc_ops->get_latch_status(slot, value);
361 if (retval < 0) 348 if (retval < 0)
@@ -370,7 +357,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
370 int retval; 357 int retval;
371 358
372 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 359 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
373 __func__, hotplug_slot->name); 360 __func__, slot_name(slot));
374 361
375 retval = slot->hpc_ops->get_adapter_status(slot, value); 362 retval = slot->hpc_ops->get_adapter_status(slot, value);
376 if (retval < 0) 363 if (retval < 0)
@@ -386,7 +373,7 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
386 int retval; 373 int retval;
387 374
388 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 375 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
389 __func__, hotplug_slot->name); 376 __func__, slot_name(slot));
390 377
391 retval = slot->hpc_ops->get_max_bus_speed(slot, value); 378 retval = slot->hpc_ops->get_max_bus_speed(slot, value);
392 if (retval < 0) 379 if (retval < 0)
@@ -401,7 +388,7 @@ static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe
401 int retval; 388 int retval;
402 389
403 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n", 390 ctrl_dbg(slot->ctrl, "%s - physical_slot = %s\n",
404 __func__, hotplug_slot->name); 391 __func__, slot_name(slot));
405 392
406 retval = slot->hpc_ops->get_cur_bus_speed(slot, value); 393 retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
407 if (retval < 0) 394 if (retval < 0)
diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
index acb7f9efd182..d6c5eb297753 100644
--- a/drivers/pci/hotplug/pciehp_ctrl.c
+++ b/drivers/pci/hotplug/pciehp_ctrl.c
@@ -66,7 +66,7 @@ u8 pciehp_handle_attention_button(struct slot *p_slot)
66 /* 66 /*
67 * Button pressed - See if need to TAKE ACTION!!! 67 * Button pressed - See if need to TAKE ACTION!!!
68 */ 68 */
69 ctrl_info(ctrl, "Button pressed on Slot(%s)\n", p_slot->name); 69 ctrl_info(ctrl, "Button pressed on Slot(%s)\n", slot_name(p_slot));
70 event_type = INT_BUTTON_PRESS; 70 event_type = INT_BUTTON_PRESS;
71 71
72 queue_interrupt_event(p_slot, event_type); 72 queue_interrupt_event(p_slot, event_type);
@@ -88,13 +88,13 @@ u8 pciehp_handle_switch_change(struct slot *p_slot)
88 /* 88 /*
89 * Switch opened 89 * Switch opened
90 */ 90 */
91 ctrl_info(ctrl, "Latch open on Slot(%s)\n", p_slot->name); 91 ctrl_info(ctrl, "Latch open on Slot(%s)\n", slot_name(p_slot));
92 event_type = INT_SWITCH_OPEN; 92 event_type = INT_SWITCH_OPEN;
93 } else { 93 } else {
94 /* 94 /*
95 * Switch closed 95 * Switch closed
96 */ 96 */
97 ctrl_info(ctrl, "Latch close on Slot(%s)\n", p_slot->name); 97 ctrl_info(ctrl, "Latch close on Slot(%s)\n", slot_name(p_slot));
98 event_type = INT_SWITCH_CLOSE; 98 event_type = INT_SWITCH_CLOSE;
99 } 99 }
100 100
@@ -120,13 +120,14 @@ u8 pciehp_handle_presence_change(struct slot *p_slot)
120 /* 120 /*
121 * Card Present 121 * Card Present
122 */ 122 */
123 ctrl_info(ctrl, "Card present on Slot(%s)\n", p_slot->name); 123 ctrl_info(ctrl, "Card present on Slot(%s)\n", slot_name(p_slot));
124 event_type = INT_PRESENCE_ON; 124 event_type = INT_PRESENCE_ON;
125 } else { 125 } else {
126 /* 126 /*
127 * Not Present 127 * Not Present
128 */ 128 */
129 ctrl_info(ctrl, "Card not present on Slot(%s)\n", p_slot->name); 129 ctrl_info(ctrl, "Card not present on Slot(%s)\n",
130 slot_name(p_slot));
130 event_type = INT_PRESENCE_OFF; 131 event_type = INT_PRESENCE_OFF;
131 } 132 }
132 133
@@ -148,13 +149,13 @@ u8 pciehp_handle_power_fault(struct slot *p_slot)
148 * power fault Cleared 149 * power fault Cleared
149 */ 150 */
150 ctrl_info(ctrl, "Power fault cleared on Slot(%s)\n", 151 ctrl_info(ctrl, "Power fault cleared on Slot(%s)\n",
151 p_slot->name); 152 slot_name(p_slot));
152 event_type = INT_POWER_FAULT_CLEAR; 153 event_type = INT_POWER_FAULT_CLEAR;
153 } else { 154 } else {
154 /* 155 /*
155 * power fault 156 * power fault
156 */ 157 */
157 ctrl_info(ctrl, "Power fault on Slot(%s)\n", p_slot->name); 158 ctrl_info(ctrl, "Power fault on Slot(%s)\n", slot_name(p_slot));
158 event_type = INT_POWER_FAULT; 159 event_type = INT_POWER_FAULT;
159 ctrl_info(ctrl, "power fault bit %x set\n", 0); 160 ctrl_info(ctrl, "power fault bit %x set\n", 0);
160 } 161 }
@@ -225,9 +226,6 @@ static int board_added(struct slot *p_slot)
225 if (PWR_LED(ctrl)) 226 if (PWR_LED(ctrl))
226 p_slot->hpc_ops->green_led_blink(p_slot); 227 p_slot->hpc_ops->green_led_blink(p_slot);
227 228
228 /* Wait for ~1 second */
229 msleep(1000);
230
231 /* Check link training status */ 229 /* Check link training status */
232 retval = p_slot->hpc_ops->check_lnk_status(ctrl); 230 retval = p_slot->hpc_ops->check_lnk_status(ctrl);
233 if (retval) { 231 if (retval) {
@@ -412,12 +410,12 @@ static void handle_button_press_event(struct slot *p_slot)
412 p_slot->state = BLINKINGOFF_STATE; 410 p_slot->state = BLINKINGOFF_STATE;
413 ctrl_info(ctrl, 411 ctrl_info(ctrl,
414 "PCI slot #%s - powering off due to button " 412 "PCI slot #%s - powering off due to button "
415 "press.\n", p_slot->name); 413 "press.\n", slot_name(p_slot));
416 } else { 414 } else {
417 p_slot->state = BLINKINGON_STATE; 415 p_slot->state = BLINKINGON_STATE;
418 ctrl_info(ctrl, 416 ctrl_info(ctrl,
419 "PCI slot #%s - powering on due to button " 417 "PCI slot #%s - powering on due to button "
420 "press.\n", p_slot->name); 418 "press.\n", slot_name(p_slot));
421 } 419 }
422 /* blink green LED and turn off amber */ 420 /* blink green LED and turn off amber */
423 if (PWR_LED(ctrl)) 421 if (PWR_LED(ctrl))
@@ -434,7 +432,7 @@ static void handle_button_press_event(struct slot *p_slot)
434 * press the attention again before the 5 sec. limit 432 * press the attention again before the 5 sec. limit
435 * expires to cancel hot-add or hot-remove 433 * expires to cancel hot-add or hot-remove
436 */ 434 */
437 ctrl_info(ctrl, "Button cancel on Slot(%s)\n", p_slot->name); 435 ctrl_info(ctrl, "Button cancel on Slot(%s)\n", slot_name(p_slot));
438 ctrl_dbg(ctrl, "%s: button cancel\n", __func__); 436 ctrl_dbg(ctrl, "%s: button cancel\n", __func__);
439 cancel_delayed_work(&p_slot->work); 437 cancel_delayed_work(&p_slot->work);
440 if (p_slot->state == BLINKINGOFF_STATE) { 438 if (p_slot->state == BLINKINGOFF_STATE) {
@@ -447,7 +445,7 @@ static void handle_button_press_event(struct slot *p_slot)
447 if (ATTN_LED(ctrl)) 445 if (ATTN_LED(ctrl))
448 p_slot->hpc_ops->set_attention_status(p_slot, 0); 446 p_slot->hpc_ops->set_attention_status(p_slot, 0);
449 ctrl_info(ctrl, "PCI slot #%s - action canceled " 447 ctrl_info(ctrl, "PCI slot #%s - action canceled "
450 "due to button press\n", p_slot->name); 448 "due to button press\n", slot_name(p_slot));
451 p_slot->state = STATIC_STATE; 449 p_slot->state = STATIC_STATE;
452 break; 450 break;
453 case POWEROFF_STATE: 451 case POWEROFF_STATE:
@@ -457,7 +455,7 @@ static void handle_button_press_event(struct slot *p_slot)
457 * this means that the previous attention button action 455 * this means that the previous attention button action
458 * to hot-add or hot-remove is undergoing 456 * to hot-add or hot-remove is undergoing
459 */ 457 */
460 ctrl_info(ctrl, "Button ignore on Slot(%s)\n", p_slot->name); 458 ctrl_info(ctrl, "Button ignore on Slot(%s)\n", slot_name(p_slot));
461 update_slot_info(p_slot); 459 update_slot_info(p_slot);
462 break; 460 break;
463 default: 461 default:
@@ -540,7 +538,7 @@ int pciehp_enable_slot(struct slot *p_slot)
540 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 538 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
541 if (rc || !getstatus) { 539 if (rc || !getstatus) {
542 ctrl_info(ctrl, "%s: no adapter on slot(%s)\n", 540 ctrl_info(ctrl, "%s: no adapter on slot(%s)\n",
543 __func__, p_slot->name); 541 __func__, slot_name(p_slot));
544 mutex_unlock(&p_slot->ctrl->crit_sect); 542 mutex_unlock(&p_slot->ctrl->crit_sect);
545 return -ENODEV; 543 return -ENODEV;
546 } 544 }
@@ -548,7 +546,7 @@ int pciehp_enable_slot(struct slot *p_slot)
548 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 546 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
549 if (rc || getstatus) { 547 if (rc || getstatus) {
550 ctrl_info(ctrl, "%s: latch open on slot(%s)\n", 548 ctrl_info(ctrl, "%s: latch open on slot(%s)\n",
551 __func__, p_slot->name); 549 __func__, slot_name(p_slot));
552 mutex_unlock(&p_slot->ctrl->crit_sect); 550 mutex_unlock(&p_slot->ctrl->crit_sect);
553 return -ENODEV; 551 return -ENODEV;
554 } 552 }
@@ -558,7 +556,7 @@ int pciehp_enable_slot(struct slot *p_slot)
558 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 556 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
559 if (rc || getstatus) { 557 if (rc || getstatus) {
560 ctrl_info(ctrl, "%s: already enabled on slot(%s)\n", 558 ctrl_info(ctrl, "%s: already enabled on slot(%s)\n",
561 __func__, p_slot->name); 559 __func__, slot_name(p_slot));
562 mutex_unlock(&p_slot->ctrl->crit_sect); 560 mutex_unlock(&p_slot->ctrl->crit_sect);
563 return -EINVAL; 561 return -EINVAL;
564 } 562 }
@@ -594,7 +592,7 @@ int pciehp_disable_slot(struct slot *p_slot)
594 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 592 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
595 if (ret || !getstatus) { 593 if (ret || !getstatus) {
596 ctrl_info(ctrl, "%s: no adapter on slot(%s)\n", 594 ctrl_info(ctrl, "%s: no adapter on slot(%s)\n",
597 __func__, p_slot->name); 595 __func__, slot_name(p_slot));
598 mutex_unlock(&p_slot->ctrl->crit_sect); 596 mutex_unlock(&p_slot->ctrl->crit_sect);
599 return -ENODEV; 597 return -ENODEV;
600 } 598 }
@@ -604,7 +602,7 @@ int pciehp_disable_slot(struct slot *p_slot)
604 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 602 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
605 if (ret || getstatus) { 603 if (ret || getstatus) {
606 ctrl_info(ctrl, "%s: latch open on slot(%s)\n", 604 ctrl_info(ctrl, "%s: latch open on slot(%s)\n",
607 __func__, p_slot->name); 605 __func__, slot_name(p_slot));
608 mutex_unlock(&p_slot->ctrl->crit_sect); 606 mutex_unlock(&p_slot->ctrl->crit_sect);
609 return -ENODEV; 607 return -ENODEV;
610 } 608 }
@@ -614,7 +612,7 @@ int pciehp_disable_slot(struct slot *p_slot)
614 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 612 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
615 if (ret || !getstatus) { 613 if (ret || !getstatus) {
616 ctrl_info(ctrl, "%s: already disabled slot(%s)\n", 614 ctrl_info(ctrl, "%s: already disabled slot(%s)\n",
617 __func__, p_slot->name); 615 __func__, slot_name(p_slot));
618 mutex_unlock(&p_slot->ctrl->crit_sect); 616 mutex_unlock(&p_slot->ctrl->crit_sect);
619 return -EINVAL; 617 return -EINVAL;
620 } 618 }
@@ -645,14 +643,16 @@ int pciehp_sysfs_enable_slot(struct slot *p_slot)
645 break; 643 break;
646 case POWERON_STATE: 644 case POWERON_STATE:
647 ctrl_info(ctrl, "Slot %s is already in powering on state\n", 645 ctrl_info(ctrl, "Slot %s is already in powering on state\n",
648 p_slot->name); 646 slot_name(p_slot));
649 break; 647 break;
650 case BLINKINGOFF_STATE: 648 case BLINKINGOFF_STATE:
651 case POWEROFF_STATE: 649 case POWEROFF_STATE:
652 ctrl_info(ctrl, "Already enabled on slot %s\n", p_slot->name); 650 ctrl_info(ctrl, "Already enabled on slot %s\n",
651 slot_name(p_slot));
653 break; 652 break;
654 default: 653 default:
655 ctrl_err(ctrl, "Not a valid state on slot %s\n", p_slot->name); 654 ctrl_err(ctrl, "Not a valid state on slot %s\n",
655 slot_name(p_slot));
656 break; 656 break;
657 } 657 }
658 mutex_unlock(&p_slot->lock); 658 mutex_unlock(&p_slot->lock);
@@ -678,14 +678,16 @@ int pciehp_sysfs_disable_slot(struct slot *p_slot)
678 break; 678 break;
679 case POWEROFF_STATE: 679 case POWEROFF_STATE:
680 ctrl_info(ctrl, "Slot %s is already in powering off state\n", 680 ctrl_info(ctrl, "Slot %s is already in powering off state\n",
681 p_slot->name); 681 slot_name(p_slot));
682 break; 682 break;
683 case BLINKINGON_STATE: 683 case BLINKINGON_STATE:
684 case POWERON_STATE: 684 case POWERON_STATE:
685 ctrl_info(ctrl, "Already disabled on slot %s\n", p_slot->name); 685 ctrl_info(ctrl, "Already disabled on slot %s\n",
686 slot_name(p_slot));
686 break; 687 break;
687 default: 688 default:
688 ctrl_err(ctrl, "Not a valid state on slot %s\n", p_slot->name); 689 ctrl_err(ctrl, "Not a valid state on slot %s\n",
690 slot_name(p_slot));
689 break; 691 break;
690 } 692 }
691 mutex_unlock(&p_slot->lock); 693 mutex_unlock(&p_slot->lock);
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 8e9530c4c36d..58c72d2cc217 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -125,6 +125,7 @@ static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
125/* Field definitions in Link Capabilities Register */ 125/* Field definitions in Link Capabilities Register */
126#define MAX_LNK_SPEED 0x000F 126#define MAX_LNK_SPEED 0x000F
127#define MAX_LNK_WIDTH 0x03F0 127#define MAX_LNK_WIDTH 0x03F0
128#define LINK_ACTIVE_REPORTING 0x00100000
128 129
129/* Link Width Encoding */ 130/* Link Width Encoding */
130#define LNK_X1 0x01 131#define LNK_X1 0x01
@@ -141,6 +142,7 @@ static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
141#define LNK_TRN_ERR 0x0400 142#define LNK_TRN_ERR 0x0400
142#define LNK_TRN 0x0800 143#define LNK_TRN 0x0800
143#define SLOT_CLK_CONF 0x1000 144#define SLOT_CLK_CONF 0x1000
145#define LINK_ACTIVE 0x2000
144 146
145/* Field definitions in Slot Capabilities Register */ 147/* Field definitions in Slot Capabilities Register */
146#define ATTN_BUTTN_PRSN 0x00000001 148#define ATTN_BUTTN_PRSN 0x00000001
@@ -368,11 +370,52 @@ static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
368 return retval; 370 return retval;
369} 371}
370 372
373static inline int check_link_active(struct controller *ctrl)
374{
375 u16 link_status;
376
377 if (pciehp_readw(ctrl, LNKSTATUS, &link_status))
378 return 0;
379 return !!(link_status & LINK_ACTIVE);
380}
381
382static void pcie_wait_link_active(struct controller *ctrl)
383{
384 int timeout = 1000;
385
386 if (check_link_active(ctrl))
387 return;
388 while (timeout > 0) {
389 msleep(10);
390 timeout -= 10;
391 if (check_link_active(ctrl))
392 return;
393 }
394 ctrl_dbg(ctrl, "Data Link Layer Link Active not set in 1000 msec\n");
395}
396
371static int hpc_check_lnk_status(struct controller *ctrl) 397static int hpc_check_lnk_status(struct controller *ctrl)
372{ 398{
373 u16 lnk_status; 399 u16 lnk_status;
374 int retval = 0; 400 int retval = 0;
375 401
402 /*
403 * Data Link Layer Link Active Reporting must be capable for
404 * hot-plug capable downstream port. But old controller might
405 * not implement it. In this case, we wait for 1000 ms.
406 */
407 if (ctrl->link_active_reporting){
408 /* Wait for Data Link Layer Link Active bit to be set */
409 pcie_wait_link_active(ctrl);
410 /*
411 * We must wait for 100 ms after the Data Link Layer
412 * Link Active bit reads 1b before initiating a
413 * configuration access to the hot added device.
414 */
415 msleep(100);
416 } else
417 msleep(1000);
418
376 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); 419 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
377 if (retval) { 420 if (retval) {
378 ctrl_err(ctrl, "%s: Cannot read LNKSTATUS register\n", 421 ctrl_err(ctrl, "%s: Cannot read LNKSTATUS register\n",
@@ -1061,7 +1104,6 @@ static int pcie_init_slot(struct controller *ctrl)
1061 slot->device = ctrl->slot_device_offset + slot->hp_slot; 1104 slot->device = ctrl->slot_device_offset + slot->hp_slot;
1062 slot->hpc_ops = ctrl->hpc_ops; 1105 slot->hpc_ops = ctrl->hpc_ops;
1063 slot->number = ctrl->first_slot; 1106 slot->number = ctrl->first_slot;
1064 snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number);
1065 mutex_init(&slot->lock); 1107 mutex_init(&slot->lock);
1066 INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work); 1108 INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work);
1067 list_add(&slot->slot_list, &ctrl->slot_list); 1109 list_add(&slot->slot_list, &ctrl->slot_list);
@@ -1132,7 +1174,7 @@ static inline void dbg_ctrl(struct controller *ctrl)
1132struct controller *pcie_init(struct pcie_device *dev) 1174struct controller *pcie_init(struct pcie_device *dev)
1133{ 1175{
1134 struct controller *ctrl; 1176 struct controller *ctrl;
1135 u32 slot_cap; 1177 u32 slot_cap, link_cap;
1136 struct pci_dev *pdev = dev->port; 1178 struct pci_dev *pdev = dev->port;
1137 1179
1138 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); 1180 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
@@ -1148,11 +1190,11 @@ struct controller *pcie_init(struct pcie_device *dev)
1148 if (!ctrl->cap_base) { 1190 if (!ctrl->cap_base) {
1149 ctrl_err(ctrl, "%s: Cannot find PCI Express capability\n", 1191 ctrl_err(ctrl, "%s: Cannot find PCI Express capability\n",
1150 __func__); 1192 __func__);
1151 goto abort; 1193 goto abort_ctrl;
1152 } 1194 }
1153 if (pciehp_readl(ctrl, SLOTCAP, &slot_cap)) { 1195 if (pciehp_readl(ctrl, SLOTCAP, &slot_cap)) {
1154 ctrl_err(ctrl, "%s: Cannot read SLOTCAP register\n", __func__); 1196 ctrl_err(ctrl, "%s: Cannot read SLOTCAP register\n", __func__);
1155 goto abort; 1197 goto abort_ctrl;
1156 } 1198 }
1157 1199
1158 ctrl->slot_cap = slot_cap; 1200 ctrl->slot_cap = slot_cap;
@@ -1174,6 +1216,16 @@ struct controller *pcie_init(struct pcie_device *dev)
1174 !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl))) 1216 !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl)))
1175 ctrl->no_cmd_complete = 1; 1217 ctrl->no_cmd_complete = 1;
1176 1218
1219 /* Check if Data Link Layer Link Active Reporting is implemented */
1220 if (pciehp_readl(ctrl, LNKCAP, &link_cap)) {
1221 ctrl_err(ctrl, "%s: Cannot read LNKCAP register\n", __func__);
1222 goto abort_ctrl;
1223 }
1224 if (link_cap & LINK_ACTIVE_REPORTING) {
1225 ctrl_dbg(ctrl, "Link Active Reporting supported\n");
1226 ctrl->link_active_reporting = 1;
1227 }
1228
1177 /* Clear all remaining event bits in Slot Status register */ 1229 /* Clear all remaining event bits in Slot Status register */
1178 if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) 1230 if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f))
1179 goto abort_ctrl; 1231 goto abort_ctrl;
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
index 50884507b8be..2ea9cf1a8d02 100644
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ b/drivers/pci/hotplug/rpaphp_slot.c
@@ -43,7 +43,7 @@ static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
43void dealloc_slot_struct(struct slot *slot) 43void dealloc_slot_struct(struct slot *slot)
44{ 44{
45 kfree(slot->hotplug_slot->info); 45 kfree(slot->hotplug_slot->info);
46 kfree(slot->hotplug_slot->name); 46 kfree(slot->name);
47 kfree(slot->hotplug_slot); 47 kfree(slot->hotplug_slot);
48 kfree(slot); 48 kfree(slot);
49} 49}
@@ -63,11 +63,9 @@ struct slot *alloc_slot_struct(struct device_node *dn,
63 GFP_KERNEL); 63 GFP_KERNEL);
64 if (!slot->hotplug_slot->info) 64 if (!slot->hotplug_slot->info)
65 goto error_hpslot; 65 goto error_hpslot;
66 slot->hotplug_slot->name = kmalloc(strlen(drc_name) + 1, GFP_KERNEL); 66 slot->name = kstrdup(drc_name, GFP_KERNEL);
67 if (!slot->hotplug_slot->name) 67 if (!slot->name)
68 goto error_info; 68 goto error_info;
69 slot->name = slot->hotplug_slot->name;
70 strcpy(slot->name, drc_name);
71 slot->dn = dn; 69 slot->dn = dn;
72 slot->index = drc_index; 70 slot->index = drc_index;
73 slot->power_domain = power_domain; 71 slot->power_domain = power_domain;
@@ -137,7 +135,7 @@ int rpaphp_register_slot(struct slot *slot)
137 slotno = PCI_SLOT(PCI_DN(slot->dn->child)->devfn); 135 slotno = PCI_SLOT(PCI_DN(slot->dn->child)->devfn);
138 else 136 else
139 slotno = -1; 137 slotno = -1;
140 retval = pci_hp_register(php_slot, slot->bus, slotno); 138 retval = pci_hp_register(php_slot, slot->bus, slotno, slot->name);
141 if (retval) { 139 if (retval) {
142 err("pci_hp_register failed with error %d\n", retval); 140 err("pci_hp_register failed with error %d\n", retval);
143 return retval; 141 return retval;
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
index 410fe0394a8e..d748698e31a2 100644
--- a/drivers/pci/hotplug/sgi_hotplug.c
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -161,7 +161,8 @@ static int sn_pci_bus_valid(struct pci_bus *pci_bus)
161} 161}
162 162
163static int sn_hp_slot_private_alloc(struct hotplug_slot *bss_hotplug_slot, 163static int sn_hp_slot_private_alloc(struct hotplug_slot *bss_hotplug_slot,
164 struct pci_bus *pci_bus, int device) 164 struct pci_bus *pci_bus, int device,
165 char *name)
165{ 166{
166 struct pcibus_info *pcibus_info; 167 struct pcibus_info *pcibus_info;
167 struct slot *slot; 168 struct slot *slot;
@@ -173,15 +174,9 @@ static int sn_hp_slot_private_alloc(struct hotplug_slot *bss_hotplug_slot,
173 return -ENOMEM; 174 return -ENOMEM;
174 bss_hotplug_slot->private = slot; 175 bss_hotplug_slot->private = slot;
175 176
176 bss_hotplug_slot->name = kmalloc(SN_SLOT_NAME_SIZE, GFP_KERNEL);
177 if (!bss_hotplug_slot->name) {
178 kfree(bss_hotplug_slot->private);
179 return -ENOMEM;
180 }
181
182 slot->device_num = device; 177 slot->device_num = device;
183 slot->pci_bus = pci_bus; 178 slot->pci_bus = pci_bus;
184 sprintf(bss_hotplug_slot->name, "%04x:%02x:%02x", 179 sprintf(name, "%04x:%02x:%02x",
185 pci_domain_nr(pci_bus), 180 pci_domain_nr(pci_bus),
186 ((u16)pcibus_info->pbi_buscommon.bs_persist_busnum), 181 ((u16)pcibus_info->pbi_buscommon.bs_persist_busnum),
187 device + 1); 182 device + 1);
@@ -608,7 +603,6 @@ static inline int get_power_status(struct hotplug_slot *bss_hotplug_slot,
608static void sn_release_slot(struct hotplug_slot *bss_hotplug_slot) 603static void sn_release_slot(struct hotplug_slot *bss_hotplug_slot)
609{ 604{
610 kfree(bss_hotplug_slot->info); 605 kfree(bss_hotplug_slot->info);
611 kfree(bss_hotplug_slot->name);
612 kfree(bss_hotplug_slot->private); 606 kfree(bss_hotplug_slot->private);
613 kfree(bss_hotplug_slot); 607 kfree(bss_hotplug_slot);
614} 608}
@@ -618,6 +612,7 @@ static int sn_hotplug_slot_register(struct pci_bus *pci_bus)
618 int device; 612 int device;
619 struct pci_slot *pci_slot; 613 struct pci_slot *pci_slot;
620 struct hotplug_slot *bss_hotplug_slot; 614 struct hotplug_slot *bss_hotplug_slot;
615 char name[SN_SLOT_NAME_SIZE];
621 int rc = 0; 616 int rc = 0;
622 617
623 /* 618 /*
@@ -645,15 +640,14 @@ static int sn_hotplug_slot_register(struct pci_bus *pci_bus)
645 } 640 }
646 641
647 if (sn_hp_slot_private_alloc(bss_hotplug_slot, 642 if (sn_hp_slot_private_alloc(bss_hotplug_slot,
648 pci_bus, device)) { 643 pci_bus, device, name)) {
649 rc = -ENOMEM; 644 rc = -ENOMEM;
650 goto alloc_err; 645 goto alloc_err;
651 } 646 }
652
653 bss_hotplug_slot->ops = &sn_hotplug_slot_ops; 647 bss_hotplug_slot->ops = &sn_hotplug_slot_ops;
654 bss_hotplug_slot->release = &sn_release_slot; 648 bss_hotplug_slot->release = &sn_release_slot;
655 649
656 rc = pci_hp_register(bss_hotplug_slot, pci_bus, device); 650 rc = pci_hp_register(bss_hotplug_slot, pci_bus, device, name);
657 if (rc) 651 if (rc)
658 goto register_err; 652 goto register_err;
659 653
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index 8a026f750deb..4d9fed00e1d0 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -69,15 +69,13 @@ struct slot {
69 u8 state; 69 u8 state;
70 u8 presence_save; 70 u8 presence_save;
71 u8 pwr_save; 71 u8 pwr_save;
72 struct timer_list task_event;
73 u8 hp_slot;
74 struct controller *ctrl; 72 struct controller *ctrl;
75 struct hpc_ops *hpc_ops; 73 struct hpc_ops *hpc_ops;
76 struct hotplug_slot *hotplug_slot; 74 struct hotplug_slot *hotplug_slot;
77 struct list_head slot_list; 75 struct list_head slot_list;
78 char name[SLOT_NAME_SIZE];
79 struct delayed_work work; /* work for button event */ 76 struct delayed_work work; /* work for button event */
80 struct mutex lock; 77 struct mutex lock;
78 u8 hp_slot;
81}; 79};
82 80
83struct event_info { 81struct event_info {
@@ -169,6 +167,11 @@ extern void cleanup_slots(struct controller *ctrl);
169extern void shpchp_queue_pushbutton_work(struct work_struct *work); 167extern void shpchp_queue_pushbutton_work(struct work_struct *work);
170extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev); 168extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
171 169
170static inline const char *slot_name(struct slot *slot)
171{
172 return hotplug_slot_name(slot->hotplug_slot);
173}
174
172#ifdef CONFIG_ACPI 175#ifdef CONFIG_ACPI
173#include <linux/pci-acpi.h> 176#include <linux/pci-acpi.h>
174static inline int get_hp_params_from_firmware(struct pci_dev *dev, 177static inline int get_hp_params_from_firmware(struct pci_dev *dev,
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index cc38615395f1..7af9191df4d6 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -89,7 +89,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
89{ 89{
90 struct slot *slot = hotplug_slot->private; 90 struct slot *slot = hotplug_slot->private;
91 91
92 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 92 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
93 93
94 kfree(slot->hotplug_slot->info); 94 kfree(slot->hotplug_slot->info);
95 kfree(slot->hotplug_slot); 95 kfree(slot->hotplug_slot);
@@ -101,8 +101,9 @@ static int init_slots(struct controller *ctrl)
101 struct slot *slot; 101 struct slot *slot;
102 struct hotplug_slot *hotplug_slot; 102 struct hotplug_slot *hotplug_slot;
103 struct hotplug_slot_info *info; 103 struct hotplug_slot_info *info;
104 char name[SLOT_NAME_SIZE];
104 int retval = -ENOMEM; 105 int retval = -ENOMEM;
105 int i, len, dup = 1; 106 int i;
106 107
107 for (i = 0; i < ctrl->num_slots; i++) { 108 for (i = 0; i < ctrl->num_slots; i++) {
108 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 109 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
@@ -119,8 +120,6 @@ static int init_slots(struct controller *ctrl)
119 goto error_hpslot; 120 goto error_hpslot;
120 hotplug_slot->info = info; 121 hotplug_slot->info = info;
121 122
122 hotplug_slot->name = slot->name;
123
124 slot->hp_slot = i; 123 slot->hp_slot = i;
125 slot->ctrl = ctrl; 124 slot->ctrl = ctrl;
126 slot->bus = ctrl->pci_dev->subordinate->number; 125 slot->bus = ctrl->pci_dev->subordinate->number;
@@ -133,37 +132,24 @@ static int init_slots(struct controller *ctrl)
133 /* register this slot with the hotplug pci core */ 132 /* register this slot with the hotplug pci core */
134 hotplug_slot->private = slot; 133 hotplug_slot->private = slot;
135 hotplug_slot->release = &release_slot; 134 hotplug_slot->release = &release_slot;
136 snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number); 135 snprintf(name, SLOT_NAME_SIZE, "%d", slot->number);
137 hotplug_slot->ops = &shpchp_hotplug_slot_ops; 136 hotplug_slot->ops = &shpchp_hotplug_slot_ops;
138 137
139 get_power_status(hotplug_slot, &info->power_status);
140 get_attention_status(hotplug_slot, &info->attention_status);
141 get_latch_status(hotplug_slot, &info->latch_status);
142 get_adapter_status(hotplug_slot, &info->adapter_status);
143
144 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 138 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
145 "slot_device_offset=%x\n", slot->bus, slot->device, 139 "slot_device_offset=%x\n", slot->bus, slot->device,
146 slot->hp_slot, slot->number, ctrl->slot_device_offset); 140 slot->hp_slot, slot->number, ctrl->slot_device_offset);
147duplicate_name:
148 retval = pci_hp_register(slot->hotplug_slot, 141 retval = pci_hp_register(slot->hotplug_slot,
149 ctrl->pci_dev->subordinate, slot->device); 142 ctrl->pci_dev->subordinate, slot->device, name);
150 if (retval) { 143 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); 144 err("pci_hp_register failed with error %d\n", retval);
164 goto error_info; 145 goto error_info;
165 } 146 }
166 147
148 get_power_status(hotplug_slot, &info->power_status);
149 get_attention_status(hotplug_slot, &info->attention_status);
150 get_latch_status(hotplug_slot, &info->latch_status);
151 get_adapter_status(hotplug_slot, &info->adapter_status);
152
167 list_add(&slot->slot_list, &ctrl->slot_list); 153 list_add(&slot->slot_list, &ctrl->slot_list);
168 } 154 }
169 155
@@ -201,7 +187,7 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
201{ 187{
202 struct slot *slot = get_slot(hotplug_slot); 188 struct slot *slot = get_slot(hotplug_slot);
203 189
204 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 190 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
205 191
206 hotplug_slot->info->attention_status = status; 192 hotplug_slot->info->attention_status = status;
207 slot->hpc_ops->set_attention_status(slot, status); 193 slot->hpc_ops->set_attention_status(slot, status);
@@ -213,7 +199,7 @@ static int enable_slot (struct hotplug_slot *hotplug_slot)
213{ 199{
214 struct slot *slot = get_slot(hotplug_slot); 200 struct slot *slot = get_slot(hotplug_slot);
215 201
216 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 202 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
217 203
218 return shpchp_sysfs_enable_slot(slot); 204 return shpchp_sysfs_enable_slot(slot);
219} 205}
@@ -222,7 +208,7 @@ static int disable_slot (struct hotplug_slot *hotplug_slot)
222{ 208{
223 struct slot *slot = get_slot(hotplug_slot); 209 struct slot *slot = get_slot(hotplug_slot);
224 210
225 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 211 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
226 212
227 return shpchp_sysfs_disable_slot(slot); 213 return shpchp_sysfs_disable_slot(slot);
228} 214}
@@ -232,7 +218,7 @@ static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
232 struct slot *slot = get_slot(hotplug_slot); 218 struct slot *slot = get_slot(hotplug_slot);
233 int retval; 219 int retval;
234 220
235 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 221 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
236 222
237 retval = slot->hpc_ops->get_power_status(slot, value); 223 retval = slot->hpc_ops->get_power_status(slot, value);
238 if (retval < 0) 224 if (retval < 0)
@@ -246,7 +232,7 @@ static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
246 struct slot *slot = get_slot(hotplug_slot); 232 struct slot *slot = get_slot(hotplug_slot);
247 int retval; 233 int retval;
248 234
249 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 235 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
250 236
251 retval = slot->hpc_ops->get_attention_status(slot, value); 237 retval = slot->hpc_ops->get_attention_status(slot, value);
252 if (retval < 0) 238 if (retval < 0)
@@ -260,7 +246,7 @@ static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
260 struct slot *slot = get_slot(hotplug_slot); 246 struct slot *slot = get_slot(hotplug_slot);
261 int retval; 247 int retval;
262 248
263 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 249 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
264 250
265 retval = slot->hpc_ops->get_latch_status(slot, value); 251 retval = slot->hpc_ops->get_latch_status(slot, value);
266 if (retval < 0) 252 if (retval < 0)
@@ -274,7 +260,7 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
274 struct slot *slot = get_slot(hotplug_slot); 260 struct slot *slot = get_slot(hotplug_slot);
275 int retval; 261 int retval;
276 262
277 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 263 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
278 264
279 retval = slot->hpc_ops->get_adapter_status(slot, value); 265 retval = slot->hpc_ops->get_adapter_status(slot, value);
280 if (retval < 0) 266 if (retval < 0)
@@ -289,7 +275,7 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
289 struct slot *slot = get_slot(hotplug_slot); 275 struct slot *slot = get_slot(hotplug_slot);
290 int retval; 276 int retval;
291 277
292 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 278 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
293 279
294 retval = slot->hpc_ops->get_max_bus_speed(slot, value); 280 retval = slot->hpc_ops->get_max_bus_speed(slot, value);
295 if (retval < 0) 281 if (retval < 0)
@@ -303,7 +289,7 @@ static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
303 struct slot *slot = get_slot(hotplug_slot); 289 struct slot *slot = get_slot(hotplug_slot);
304 int retval; 290 int retval;
305 291
306 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 292 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
307 293
308 retval = slot->hpc_ops->get_cur_bus_speed(slot, value); 294 retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
309 if (retval < 0) 295 if (retval < 0)
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
index dfb53932dfbc..919b1ee44313 100644
--- a/drivers/pci/hotplug/shpchp_ctrl.c
+++ b/drivers/pci/hotplug/shpchp_ctrl.c
@@ -70,7 +70,7 @@ u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl)
70 /* 70 /*
71 * Button pressed - See if need to TAKE ACTION!!! 71 * Button pressed - See if need to TAKE ACTION!!!
72 */ 72 */
73 info("Button pressed on Slot(%s)\n", p_slot->name); 73 info("Button pressed on Slot(%s)\n", slot_name(p_slot));
74 event_type = INT_BUTTON_PRESS; 74 event_type = INT_BUTTON_PRESS;
75 75
76 queue_interrupt_event(p_slot, event_type); 76 queue_interrupt_event(p_slot, event_type);
@@ -98,7 +98,7 @@ u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl)
98 /* 98 /*
99 * Switch opened 99 * Switch opened
100 */ 100 */
101 info("Latch open on Slot(%s)\n", p_slot->name); 101 info("Latch open on Slot(%s)\n", slot_name(p_slot));
102 event_type = INT_SWITCH_OPEN; 102 event_type = INT_SWITCH_OPEN;
103 if (p_slot->pwr_save && p_slot->presence_save) { 103 if (p_slot->pwr_save && p_slot->presence_save) {
104 event_type = INT_POWER_FAULT; 104 event_type = INT_POWER_FAULT;
@@ -108,7 +108,7 @@ u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl)
108 /* 108 /*
109 * Switch closed 109 * Switch closed
110 */ 110 */
111 info("Latch close on Slot(%s)\n", p_slot->name); 111 info("Latch close on Slot(%s)\n", slot_name(p_slot));
112 event_type = INT_SWITCH_CLOSE; 112 event_type = INT_SWITCH_CLOSE;
113 } 113 }
114 114
@@ -135,13 +135,13 @@ u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl)
135 /* 135 /*
136 * Card Present 136 * Card Present
137 */ 137 */
138 info("Card present on Slot(%s)\n", p_slot->name); 138 info("Card present on Slot(%s)\n", slot_name(p_slot));
139 event_type = INT_PRESENCE_ON; 139 event_type = INT_PRESENCE_ON;
140 } else { 140 } else {
141 /* 141 /*
142 * Not Present 142 * Not Present
143 */ 143 */
144 info("Card not present on Slot(%s)\n", p_slot->name); 144 info("Card not present on Slot(%s)\n", slot_name(p_slot));
145 event_type = INT_PRESENCE_OFF; 145 event_type = INT_PRESENCE_OFF;
146 } 146 }
147 147
@@ -164,14 +164,14 @@ u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl)
164 /* 164 /*
165 * Power fault Cleared 165 * Power fault Cleared
166 */ 166 */
167 info("Power fault cleared on Slot(%s)\n", p_slot->name); 167 info("Power fault cleared on Slot(%s)\n", slot_name(p_slot));
168 p_slot->status = 0x00; 168 p_slot->status = 0x00;
169 event_type = INT_POWER_FAULT_CLEAR; 169 event_type = INT_POWER_FAULT_CLEAR;
170 } else { 170 } else {
171 /* 171 /*
172 * Power fault 172 * Power fault
173 */ 173 */
174 info("Power fault on Slot(%s)\n", p_slot->name); 174 info("Power fault on Slot(%s)\n", slot_name(p_slot));
175 event_type = INT_POWER_FAULT; 175 event_type = INT_POWER_FAULT;
176 /* set power fault status for this board */ 176 /* set power fault status for this board */
177 p_slot->status = 0xFF; 177 p_slot->status = 0xFF;
@@ -493,11 +493,11 @@ static void handle_button_press_event(struct slot *p_slot)
493 if (getstatus) { 493 if (getstatus) {
494 p_slot->state = BLINKINGOFF_STATE; 494 p_slot->state = BLINKINGOFF_STATE;
495 info("PCI slot #%s - powering off due to button " 495 info("PCI slot #%s - powering off due to button "
496 "press.\n", p_slot->name); 496 "press.\n", slot_name(p_slot));
497 } else { 497 } else {
498 p_slot->state = BLINKINGON_STATE; 498 p_slot->state = BLINKINGON_STATE;
499 info("PCI slot #%s - powering on due to button " 499 info("PCI slot #%s - powering on due to button "
500 "press.\n", p_slot->name); 500 "press.\n", slot_name(p_slot));
501 } 501 }
502 /* blink green LED and turn off amber */ 502 /* blink green LED and turn off amber */
503 p_slot->hpc_ops->green_led_blink(p_slot); 503 p_slot->hpc_ops->green_led_blink(p_slot);
@@ -512,7 +512,7 @@ static void handle_button_press_event(struct slot *p_slot)
512 * press the attention again before the 5 sec. limit 512 * press the attention again before the 5 sec. limit
513 * expires to cancel hot-add or hot-remove 513 * expires to cancel hot-add or hot-remove
514 */ 514 */
515 info("Button cancel on Slot(%s)\n", p_slot->name); 515 info("Button cancel on Slot(%s)\n", slot_name(p_slot));
516 dbg("%s: button cancel\n", __func__); 516 dbg("%s: button cancel\n", __func__);
517 cancel_delayed_work(&p_slot->work); 517 cancel_delayed_work(&p_slot->work);
518 if (p_slot->state == BLINKINGOFF_STATE) 518 if (p_slot->state == BLINKINGOFF_STATE)
@@ -521,7 +521,7 @@ static void handle_button_press_event(struct slot *p_slot)
521 p_slot->hpc_ops->green_led_off(p_slot); 521 p_slot->hpc_ops->green_led_off(p_slot);
522 p_slot->hpc_ops->set_attention_status(p_slot, 0); 522 p_slot->hpc_ops->set_attention_status(p_slot, 0);
523 info("PCI slot #%s - action canceled due to button press\n", 523 info("PCI slot #%s - action canceled due to button press\n",
524 p_slot->name); 524 slot_name(p_slot));
525 p_slot->state = STATIC_STATE; 525 p_slot->state = STATIC_STATE;
526 break; 526 break;
527 case POWEROFF_STATE: 527 case POWEROFF_STATE:
@@ -531,7 +531,7 @@ static void handle_button_press_event(struct slot *p_slot)
531 * this means that the previous attention button action 531 * this means that the previous attention button action
532 * to hot-add or hot-remove is undergoing 532 * to hot-add or hot-remove is undergoing
533 */ 533 */
534 info("Button ignore on Slot(%s)\n", p_slot->name); 534 info("Button ignore on Slot(%s)\n", slot_name(p_slot));
535 update_slot_info(p_slot); 535 update_slot_info(p_slot);
536 break; 536 break;
537 default: 537 default:
@@ -574,17 +574,17 @@ static int shpchp_enable_slot (struct slot *p_slot)
574 mutex_lock(&p_slot->ctrl->crit_sect); 574 mutex_lock(&p_slot->ctrl->crit_sect);
575 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 575 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
576 if (rc || !getstatus) { 576 if (rc || !getstatus) {
577 info("No adapter on slot(%s)\n", p_slot->name); 577 info("No adapter on slot(%s)\n", slot_name(p_slot));
578 goto out; 578 goto out;
579 } 579 }
580 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 580 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
581 if (rc || getstatus) { 581 if (rc || getstatus) {
582 info("Latch open on slot(%s)\n", p_slot->name); 582 info("Latch open on slot(%s)\n", slot_name(p_slot));
583 goto out; 583 goto out;
584 } 584 }
585 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 585 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
586 if (rc || getstatus) { 586 if (rc || getstatus) {
587 info("Already enabled on slot(%s)\n", p_slot->name); 587 info("Already enabled on slot(%s)\n", slot_name(p_slot));
588 goto out; 588 goto out;
589 } 589 }
590 590
@@ -633,17 +633,17 @@ static int shpchp_disable_slot (struct slot *p_slot)
633 633
634 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 634 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
635 if (rc || !getstatus) { 635 if (rc || !getstatus) {
636 info("No adapter on slot(%s)\n", p_slot->name); 636 info("No adapter on slot(%s)\n", slot_name(p_slot));
637 goto out; 637 goto out;
638 } 638 }
639 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 639 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
640 if (rc || getstatus) { 640 if (rc || getstatus) {
641 info("Latch open on slot(%s)\n", p_slot->name); 641 info("Latch open on slot(%s)\n", slot_name(p_slot));
642 goto out; 642 goto out;
643 } 643 }
644 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 644 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
645 if (rc || !getstatus) { 645 if (rc || !getstatus) {
646 info("Already disabled slot(%s)\n", p_slot->name); 646 info("Already disabled slot(%s)\n", slot_name(p_slot));
647 goto out; 647 goto out;
648 } 648 }
649 649
@@ -671,14 +671,14 @@ int shpchp_sysfs_enable_slot(struct slot *p_slot)
671 break; 671 break;
672 case POWERON_STATE: 672 case POWERON_STATE:
673 info("Slot %s is already in powering on state\n", 673 info("Slot %s is already in powering on state\n",
674 p_slot->name); 674 slot_name(p_slot));
675 break; 675 break;
676 case BLINKINGOFF_STATE: 676 case BLINKINGOFF_STATE:
677 case POWEROFF_STATE: 677 case POWEROFF_STATE:
678 info("Already enabled on slot %s\n", p_slot->name); 678 info("Already enabled on slot %s\n", slot_name(p_slot));
679 break; 679 break;
680 default: 680 default:
681 err("Not a valid state on slot %s\n", p_slot->name); 681 err("Not a valid state on slot %s\n", slot_name(p_slot));
682 break; 682 break;
683 } 683 }
684 mutex_unlock(&p_slot->lock); 684 mutex_unlock(&p_slot->lock);
@@ -703,14 +703,14 @@ int shpchp_sysfs_disable_slot(struct slot *p_slot)
703 break; 703 break;
704 case POWEROFF_STATE: 704 case POWEROFF_STATE:
705 info("Slot %s is already in powering off state\n", 705 info("Slot %s is already in powering off state\n",
706 p_slot->name); 706 slot_name(p_slot));
707 break; 707 break;
708 case BLINKINGON_STATE: 708 case BLINKINGON_STATE:
709 case POWERON_STATE: 709 case POWERON_STATE:
710 info("Already disabled on slot %s\n", p_slot->name); 710 info("Already disabled on slot %s\n", slot_name(p_slot));
711 break; 711 break;
712 default: 712 default:
713 err("Not a valid state on slot %s\n", p_slot->name); 713 err("Not a valid state on slot %s\n", slot_name(p_slot));
714 break; 714 break;
715 } 715 }
716 mutex_unlock(&p_slot->lock); 716 mutex_unlock(&p_slot->lock);
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index d2812013fd22..74801f7df9c9 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -759,3 +759,24 @@ void pci_msi_init_pci_dev(struct pci_dev *dev)
759{ 759{
760 INIT_LIST_HEAD(&dev->msi_list); 760 INIT_LIST_HEAD(&dev->msi_list);
761} 761}
762
763#ifdef CONFIG_ACPI
764#include <linux/acpi.h>
765#include <linux/pci-acpi.h>
766static void __devinit msi_acpi_init(void)
767{
768 if (acpi_pci_disabled)
769 return;
770 pci_osc_support_set(OSC_MSI_SUPPORT);
771 pcie_osc_support_set(OSC_MSI_SUPPORT);
772}
773#else
774static inline void msi_acpi_init(void) { }
775#endif /* CONFIG_ACPI */
776
777void __devinit msi_init(void)
778{
779 if (!pci_msi_enable)
780 return;
781 msi_acpi_init();
782}
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 89a2f0fa10f9..dfe7c8e1b185 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -24,17 +24,17 @@ struct acpi_osc_data {
24 acpi_handle handle; 24 acpi_handle handle;
25 u32 support_set; 25 u32 support_set;
26 u32 control_set; 26 u32 control_set;
27 int is_queried;
28 u32 query_result;
29 struct list_head sibiling; 27 struct list_head sibiling;
30}; 28};
31static LIST_HEAD(acpi_osc_data_list); 29static LIST_HEAD(acpi_osc_data_list);
32 30
33struct acpi_osc_args { 31struct acpi_osc_args {
34 u32 capbuf[3]; 32 u32 capbuf[3];
35 u32 query_result; 33 u32 ctrl_result;
36}; 34};
37 35
36static DEFINE_MUTEX(pci_acpi_lock);
37
38static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle) 38static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle)
39{ 39{
40 struct acpi_osc_data *data; 40 struct acpi_osc_data *data;
@@ -108,9 +108,8 @@ static acpi_status acpi_run_osc(acpi_handle handle,
108 goto out_kfree; 108 goto out_kfree;
109 } 109 }
110out_success: 110out_success:
111 if (flags & OSC_QUERY_ENABLE) 111 osc_args->ctrl_result =
112 osc_args->query_result = 112 *((u32 *)(out_obj->buffer.pointer + 8));
113 *((u32 *)(out_obj->buffer.pointer + 8));
114 status = AE_OK; 113 status = AE_OK;
115 114
116out_kfree: 115out_kfree:
@@ -118,41 +117,53 @@ out_kfree:
118 return status; 117 return status;
119} 118}
120 119
121static acpi_status acpi_query_osc(acpi_handle handle, 120static acpi_status __acpi_query_osc(u32 flags, struct acpi_osc_data *osc_data,
122 u32 level, void *context, void **retval) 121 u32 *result)
123{ 122{
124 acpi_status status; 123 acpi_status status;
125 struct acpi_osc_data *osc_data; 124 u32 support_set;
126 u32 flags = (unsigned long)context, support_set;
127 acpi_handle tmp;
128 struct acpi_osc_args osc_args; 125 struct acpi_osc_args osc_args;
129 126
130 status = acpi_get_handle(handle, "_OSC", &tmp);
131 if (ACPI_FAILURE(status))
132 return status;
133
134 osc_data = acpi_get_osc_data(handle);
135 if (!osc_data) {
136 printk(KERN_ERR "acpi osc data array is full\n");
137 return AE_ERROR;
138 }
139
140 /* do _OSC query for all possible controls */ 127 /* do _OSC query for all possible controls */
141 support_set = osc_data->support_set | (flags & OSC_SUPPORT_MASKS); 128 support_set = osc_data->support_set | (flags & OSC_SUPPORT_MASKS);
142 osc_args.capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; 129 osc_args.capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
143 osc_args.capbuf[OSC_SUPPORT_TYPE] = support_set; 130 osc_args.capbuf[OSC_SUPPORT_TYPE] = support_set;
144 osc_args.capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS; 131 osc_args.capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
145 132
146 status = acpi_run_osc(handle, &osc_args); 133 status = acpi_run_osc(osc_data->handle, &osc_args);
147 if (ACPI_SUCCESS(status)) { 134 if (ACPI_SUCCESS(status)) {
148 osc_data->support_set = support_set; 135 osc_data->support_set = support_set;
149 osc_data->query_result = osc_args.query_result; 136 *result = osc_args.ctrl_result;
150 osc_data->is_queried = 1;
151 } 137 }
152 138
153 return status; 139 return status;
154} 140}
155 141
142static acpi_status acpi_query_osc(acpi_handle handle,
143 u32 level, void *context, void **retval)
144{
145 acpi_status status;
146 struct acpi_osc_data *osc_data;
147 u32 flags = (unsigned long)context, dummy;
148 acpi_handle tmp;
149
150 status = acpi_get_handle(handle, "_OSC", &tmp);
151 if (ACPI_FAILURE(status))
152 return AE_OK;
153
154 mutex_lock(&pci_acpi_lock);
155 osc_data = acpi_get_osc_data(handle);
156 if (!osc_data) {
157 printk(KERN_ERR "acpi osc data array is full\n");
158 goto out;
159 }
160
161 __acpi_query_osc(flags, osc_data, &dummy);
162out:
163 mutex_unlock(&pci_acpi_lock);
164 return AE_OK;
165}
166
156/** 167/**
157 * __pci_osc_support_set - register OS support to Firmware 168 * __pci_osc_support_set - register OS support to Firmware
158 * @flags: OS support bits 169 * @flags: OS support bits
@@ -181,7 +192,7 @@ acpi_status __pci_osc_support_set(u32 flags, const char *hid)
181acpi_status pci_osc_control_set(acpi_handle handle, u32 flags) 192acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
182{ 193{
183 acpi_status status; 194 acpi_status status;
184 u32 ctrlset, control_set; 195 u32 ctrlset, control_set, result;
185 acpi_handle tmp; 196 acpi_handle tmp;
186 struct acpi_osc_data *osc_data; 197 struct acpi_osc_data *osc_data;
187 struct acpi_osc_args osc_args; 198 struct acpi_osc_args osc_args;
@@ -190,19 +201,28 @@ acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
190 if (ACPI_FAILURE(status)) 201 if (ACPI_FAILURE(status))
191 return status; 202 return status;
192 203
204 mutex_lock(&pci_acpi_lock);
193 osc_data = acpi_get_osc_data(handle); 205 osc_data = acpi_get_osc_data(handle);
194 if (!osc_data) { 206 if (!osc_data) {
195 printk(KERN_ERR "acpi osc data array is full\n"); 207 printk(KERN_ERR "acpi osc data array is full\n");
196 return AE_ERROR; 208 status = AE_ERROR;
209 goto out;
197 } 210 }
198 211
199 ctrlset = (flags & OSC_CONTROL_MASKS); 212 ctrlset = (flags & OSC_CONTROL_MASKS);
200 if (!ctrlset) 213 if (!ctrlset) {
201 return AE_TYPE; 214 status = AE_TYPE;
215 goto out;
216 }
202 217
203 if (osc_data->is_queried && 218 status = __acpi_query_osc(osc_data->support_set, osc_data, &result);
204 ((osc_data->query_result & ctrlset) != ctrlset)) 219 if (ACPI_FAILURE(status))
205 return AE_SUPPORT; 220 goto out;
221
222 if ((result & ctrlset) != ctrlset) {
223 status = AE_SUPPORT;
224 goto out;
225 }
206 226
207 control_set = osc_data->control_set | ctrlset; 227 control_set = osc_data->control_set | ctrlset;
208 osc_args.capbuf[OSC_QUERY_TYPE] = 0; 228 osc_args.capbuf[OSC_QUERY_TYPE] = 0;
@@ -211,7 +231,8 @@ acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
211 status = acpi_run_osc(handle, &osc_args); 231 status = acpi_run_osc(handle, &osc_args);
212 if (ACPI_SUCCESS(status)) 232 if (ACPI_SUCCESS(status))
213 osc_data->control_set = control_set; 233 osc_data->control_set = control_set;
214 234out:
235 mutex_unlock(&pci_acpi_lock);
215 return status; 236 return status;
216} 237}
217EXPORT_SYMBOL(pci_osc_control_set); 238EXPORT_SYMBOL(pci_osc_control_set);
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 4db261e13e69..533aeb5fcbe4 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -18,6 +18,7 @@
18#include <linux/log2.h> 18#include <linux/log2.h>
19#include <linux/pci-aspm.h> 19#include <linux/pci-aspm.h>
20#include <linux/pm_wakeup.h> 20#include <linux/pm_wakeup.h>
21#include <linux/interrupt.h>
21#include <asm/dma.h> /* isa_dma_bridge_buggy */ 22#include <asm/dma.h> /* isa_dma_bridge_buggy */
22#include "pci.h" 23#include "pci.h"
23 24
@@ -1746,6 +1747,103 @@ EXPORT_SYMBOL(pci_set_dma_seg_boundary);
1746#endif 1747#endif
1747 1748
1748/** 1749/**
1750 * pci_execute_reset_function() - Reset a PCI device function
1751 * @dev: Device function to reset
1752 *
1753 * Some devices allow an individual function to be reset without affecting
1754 * other functions in the same device. The PCI device must be responsive
1755 * to PCI config space in order to use this function.
1756 *
1757 * The device function is presumed to be unused when this function is called.
1758 * Resetting the device will make the contents of PCI configuration space
1759 * random, so any caller of this must be prepared to reinitialise the
1760 * device including MSI, bus mastering, BARs, decoding IO and memory spaces,
1761 * etc.
1762 *
1763 * Returns 0 if the device function was successfully reset or -ENOTTY if the
1764 * device doesn't support resetting a single function.
1765 */
1766int pci_execute_reset_function(struct pci_dev *dev)
1767{
1768 u16 status;
1769 u32 cap;
1770 int exppos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1771
1772 if (!exppos)
1773 return -ENOTTY;
1774 pci_read_config_dword(dev, exppos + PCI_EXP_DEVCAP, &cap);
1775 if (!(cap & PCI_EXP_DEVCAP_FLR))
1776 return -ENOTTY;
1777
1778 pci_block_user_cfg_access(dev);
1779
1780 /* Wait for Transaction Pending bit clean */
1781 msleep(100);
1782 pci_read_config_word(dev, exppos + PCI_EXP_DEVSTA, &status);
1783 if (status & PCI_EXP_DEVSTA_TRPND) {
1784 dev_info(&dev->dev, "Busy after 100ms while trying to reset; "
1785 "sleeping for 1 second\n");
1786 ssleep(1);
1787 pci_read_config_word(dev, exppos + PCI_EXP_DEVSTA, &status);
1788 if (status & PCI_EXP_DEVSTA_TRPND)
1789 dev_info(&dev->dev, "Still busy after 1s; "
1790 "proceeding with reset anyway\n");
1791 }
1792
1793 pci_write_config_word(dev, exppos + PCI_EXP_DEVCTL,
1794 PCI_EXP_DEVCTL_BCR_FLR);
1795 mdelay(100);
1796
1797 pci_unblock_user_cfg_access(dev);
1798 return 0;
1799}
1800EXPORT_SYMBOL_GPL(pci_execute_reset_function);
1801
1802/**
1803 * pci_reset_function() - quiesce and reset a PCI device function
1804 * @dev: Device function to reset
1805 *
1806 * Some devices allow an individual function to be reset without affecting
1807 * other functions in the same device. The PCI device must be responsive
1808 * to PCI config space in order to use this function.
1809 *
1810 * This function does not just reset the PCI portion of a device, but
1811 * clears all the state associated with the device. This function differs
1812 * from pci_execute_reset_function in that it saves and restores device state
1813 * over the reset.
1814 *
1815 * Returns 0 if the device function was successfully reset or -ENOTTY if the
1816 * device doesn't support resetting a single function.
1817 */
1818int pci_reset_function(struct pci_dev *dev)
1819{
1820 u32 cap;
1821 int exppos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1822 int r;
1823
1824 if (!exppos)
1825 return -ENOTTY;
1826 pci_read_config_dword(dev, exppos + PCI_EXP_DEVCAP, &cap);
1827 if (!(cap & PCI_EXP_DEVCAP_FLR))
1828 return -ENOTTY;
1829
1830 if (!dev->msi_enabled && !dev->msix_enabled)
1831 disable_irq(dev->irq);
1832 pci_save_state(dev);
1833
1834 pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE);
1835
1836 r = pci_execute_reset_function(dev);
1837
1838 pci_restore_state(dev);
1839 if (!dev->msi_enabled && !dev->msix_enabled)
1840 enable_irq(dev->irq);
1841
1842 return r;
1843}
1844EXPORT_SYMBOL_GPL(pci_reset_function);
1845
1846/**
1749 * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count 1847 * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count
1750 * @dev: PCI device to query 1848 * @dev: PCI device to query
1751 * 1849 *
@@ -1933,6 +2031,9 @@ static int __devinit pci_init(void)
1933 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 2031 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
1934 pci_fixup_device(pci_fixup_final, dev); 2032 pci_fixup_device(pci_fixup_final, dev);
1935 } 2033 }
2034
2035 msi_init();
2036
1936 return 0; 2037 return 0;
1937} 2038}
1938 2039
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index b205ab866a1d..9de87e9f98f5 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -98,9 +98,11 @@ extern unsigned int pci_pm_d3_delay;
98#ifdef CONFIG_PCI_MSI 98#ifdef CONFIG_PCI_MSI
99void pci_no_msi(void); 99void pci_no_msi(void);
100extern void pci_msi_init_pci_dev(struct pci_dev *dev); 100extern void pci_msi_init_pci_dev(struct pci_dev *dev);
101extern void __devinit msi_init(void);
101#else 102#else
102static inline void pci_no_msi(void) { } 103static inline void pci_no_msi(void) { }
103static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { } 104static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { }
105static inline void msi_init(void) { }
104#endif 106#endif
105 107
106#ifdef CONFIG_PCIEAER 108#ifdef CONFIG_PCIEAER
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index aaaf0a1fed22..6f1e51d77bce 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -480,19 +480,27 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
480 int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS); 480 int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS);
481 u32 buses, i, j = 0; 481 u32 buses, i, j = 0;
482 u16 bctl; 482 u16 bctl;
483 int broken = 0;
483 484
484 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses); 485 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses);
485 486
486 dev_dbg(&dev->dev, "scanning behind bridge, config %06x, pass %d\n", 487 dev_dbg(&dev->dev, "scanning behind bridge, config %06x, pass %d\n",
487 buses & 0xffffff, pass); 488 buses & 0xffffff, pass);
488 489
490 /* Check if setup is sensible at all */
491 if (!pass &&
492 ((buses & 0xff) != bus->number || ((buses >> 8) & 0xff) <= bus->number)) {
493 dev_dbg(&dev->dev, "bus configuration invalid, reconfiguring\n");
494 broken = 1;
495 }
496
489 /* Disable MasterAbortMode during probing to avoid reporting 497 /* Disable MasterAbortMode during probing to avoid reporting
490 of bus errors (in some architectures) */ 498 of bus errors (in some architectures) */
491 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &bctl); 499 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &bctl);
492 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, 500 pci_write_config_word(dev, PCI_BRIDGE_CONTROL,
493 bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT); 501 bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT);
494 502
495 if ((buses & 0xffff00) && !pcibios_assign_all_busses() && !is_cardbus) { 503 if ((buses & 0xffff00) && !pcibios_assign_all_busses() && !is_cardbus && !broken) {
496 unsigned int cmax, busnr; 504 unsigned int cmax, busnr;
497 /* 505 /*
498 * Bus already configured by firmware, process it in the first 506 * Bus already configured by firmware, process it in the first
@@ -530,7 +538,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
530 * do in the second pass. 538 * do in the second pass.
531 */ 539 */
532 if (!pass) { 540 if (!pass) {
533 if (pcibios_assign_all_busses()) 541 if (pcibios_assign_all_busses() || broken)
534 /* Temporarily disable forwarding of the 542 /* Temporarily disable forwarding of the
535 configuration cycles on all bridges in 543 configuration cycles on all bridges in
536 this bus segment to avoid possible 544 this bus segment to avoid possible
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 4edfc4731bd4..5af8bd538149 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -166,6 +166,7 @@ struct pci_dev *pci_find_device(unsigned int vendor, unsigned int device,
166{ 166{
167 struct pci_dev *pdev; 167 struct pci_dev *pdev;
168 168
169 pci_dev_get(from);
169 pdev = pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from); 170 pdev = pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
170 pci_dev_put(pdev); 171 pci_dev_put(pdev);
171 return pdev; 172 return pdev;
@@ -270,12 +271,8 @@ static struct pci_dev *pci_get_dev_by_id(const struct pci_device_id *id,
270 struct pci_dev *pdev = NULL; 271 struct pci_dev *pdev = NULL;
271 272
272 WARN_ON(in_interrupt()); 273 WARN_ON(in_interrupt());
273 if (from) { 274 if (from)
274 /* FIXME 275 dev_start = &from->dev;
275 * take the cast off, when bus_find_device is made const.
276 */
277 dev_start = (struct device *)&from->dev;
278 }
279 dev = bus_find_device(&pci_bus_type, dev_start, (void *)id, 276 dev = bus_find_device(&pci_bus_type, dev_start, (void *)id,
280 match_pci_dev_by_id); 277 match_pci_dev_by_id);
281 if (dev) 278 if (dev)
diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
index 0c6db03698ea..4dd1c3e157ae 100644
--- a/drivers/pci/slot.c
+++ b/drivers/pci/slot.c
@@ -78,18 +78,100 @@ static struct kobj_type pci_slot_ktype = {
78 .default_attrs = pci_slot_default_attrs, 78 .default_attrs = pci_slot_default_attrs,
79}; 79};
80 80
81static char *make_slot_name(const char *name)
82{
83 char *new_name;
84 int len, max, dup;
85
86 new_name = kstrdup(name, GFP_KERNEL);
87 if (!new_name)
88 return NULL;
89
90 /*
91 * Make sure we hit the realloc case the first time through the
92 * loop. 'len' will be strlen(name) + 3 at that point which is
93 * enough space for "name-X" and the trailing NUL.
94 */
95 len = strlen(name) + 2;
96 max = 1;
97 dup = 1;
98
99 for (;;) {
100 struct kobject *dup_slot;
101 dup_slot = kset_find_obj(pci_slots_kset, new_name);
102 if (!dup_slot)
103 break;
104 kobject_put(dup_slot);
105 if (dup == max) {
106 len++;
107 max *= 10;
108 kfree(new_name);
109 new_name = kmalloc(len, GFP_KERNEL);
110 if (!new_name)
111 break;
112 }
113 sprintf(new_name, "%s-%d", name, dup++);
114 }
115
116 return new_name;
117}
118
119static int rename_slot(struct pci_slot *slot, const char *name)
120{
121 int result = 0;
122 char *slot_name;
123
124 if (strcmp(pci_slot_name(slot), name) == 0)
125 return result;
126
127 slot_name = make_slot_name(name);
128 if (!slot_name)
129 return -ENOMEM;
130
131 result = kobject_rename(&slot->kobj, slot_name);
132 kfree(slot_name);
133
134 return result;
135}
136
137static struct pci_slot *get_slot(struct pci_bus *parent, int slot_nr)
138{
139 struct pci_slot *slot;
140 /*
141 * We already hold pci_bus_sem so don't worry
142 */
143 list_for_each_entry(slot, &parent->slots, list)
144 if (slot->number == slot_nr) {
145 kobject_get(&slot->kobj);
146 return slot;
147 }
148
149 return NULL;
150}
151
81/** 152/**
82 * pci_create_slot - create or increment refcount for physical PCI slot 153 * pci_create_slot - create or increment refcount for physical PCI slot
83 * @parent: struct pci_bus of parent bridge 154 * @parent: struct pci_bus of parent bridge
84 * @slot_nr: PCI_SLOT(pci_dev->devfn) or -1 for placeholder 155 * @slot_nr: PCI_SLOT(pci_dev->devfn) or -1 for placeholder
85 * @name: user visible string presented in /sys/bus/pci/slots/<name> 156 * @name: user visible string presented in /sys/bus/pci/slots/<name>
157 * @hotplug: set if caller is hotplug driver, NULL otherwise
86 * 158 *
87 * PCI slots have first class attributes such as address, speed, width, 159 * PCI slots have first class attributes such as address, speed, width,
88 * and a &struct pci_slot is used to manage them. This interface will 160 * and a &struct pci_slot is used to manage them. This interface will
89 * either return a new &struct pci_slot to the caller, or if the pci_slot 161 * either return a new &struct pci_slot to the caller, or if the pci_slot
90 * already exists, its refcount will be incremented. 162 * already exists, its refcount will be incremented.
91 * 163 *
92 * Slots are uniquely identified by a @pci_bus, @slot_nr, @name tuple. 164 * Slots are uniquely identified by a @pci_bus, @slot_nr tuple.
165 *
166 * There are known platforms with broken firmware that assign the same
167 * name to multiple slots. Workaround these broken platforms by renaming
168 * the slots on behalf of the caller. If firmware assigns name N to
169 * multiple slots:
170 *
171 * The first slot is assigned N
172 * The second slot is assigned N-1
173 * The third slot is assigned N-2
174 * etc.
93 * 175 *
94 * Placeholder slots: 176 * Placeholder slots:
95 * In most cases, @pci_bus, @slot_nr will be sufficient to uniquely identify 177 * In most cases, @pci_bus, @slot_nr will be sufficient to uniquely identify
@@ -98,61 +180,67 @@ static struct kobj_type pci_slot_ktype = {
98 * the slot. In this scenario, the caller may pass -1 for @slot_nr. 180 * the slot. In this scenario, the caller may pass -1 for @slot_nr.
99 * 181 *
100 * The following semantics are imposed when the caller passes @slot_nr == 182 * The following semantics are imposed when the caller passes @slot_nr ==
101 * -1. First, the check for existing %struct pci_slot is skipped, as the 183 * -1. First, we no longer check for an existing %struct pci_slot, as there
102 * caller may know about several unpopulated slots on a given %struct 184 * may be many slots with @slot_nr of -1. The other change in semantics is
103 * pci_bus, and each slot would have a @slot_nr of -1. Uniqueness for
104 * these slots is then determined by the @name parameter. We expect
105 * kobject_init_and_add() to warn us if the caller attempts to create
106 * multiple slots with the same name. The other change in semantics is
107 * user-visible, which is the 'address' parameter presented in sysfs will 185 * user-visible, which is the 'address' parameter presented in sysfs will
108 * consist solely of a dddd:bb tuple, where dddd is the PCI domain of the 186 * consist solely of a dddd:bb tuple, where dddd is the PCI domain of the
109 * %struct pci_bus and bb is the bus number. In other words, the devfn of 187 * %struct pci_bus and bb is the bus number. In other words, the devfn of
110 * the 'placeholder' slot will not be displayed. 188 * the 'placeholder' slot will not be displayed.
111 */ 189 */
112
113struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr, 190struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
114 const char *name) 191 const char *name,
192 struct hotplug_slot *hotplug)
115{ 193{
116 struct pci_dev *dev; 194 struct pci_dev *dev;
117 struct pci_slot *slot; 195 struct pci_slot *slot;
118 int err; 196 int err = 0;
197 char *slot_name = NULL;
119 198
120 down_write(&pci_bus_sem); 199 down_write(&pci_bus_sem);
121 200
122 if (slot_nr == -1) 201 if (slot_nr == -1)
123 goto placeholder; 202 goto placeholder;
124 203
125 /* If we've already created this slot, bump refcount and return. */ 204 /*
126 list_for_each_entry(slot, &parent->slots, list) { 205 * Hotplug drivers are allowed to rename an existing slot,
127 if (slot->number == slot_nr) { 206 * but only if not already claimed.
128 kobject_get(&slot->kobj); 207 */
129 pr_debug("%s: inc refcount to %d on %04x:%02x:%02x\n", 208 slot = get_slot(parent, slot_nr);
130 __func__, 209 if (slot) {
131 atomic_read(&slot->kobj.kref.refcount), 210 if (hotplug) {
132 pci_domain_nr(parent), parent->number, 211 if ((err = slot->hotplug ? -EBUSY : 0)
133 slot_nr); 212 || (err = rename_slot(slot, name))) {
134 goto out; 213 kobject_put(&slot->kobj);
214 slot = NULL;
215 goto err;
216 }
135 } 217 }
218 goto out;
136 } 219 }
137 220
138placeholder: 221placeholder:
139 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 222 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
140 if (!slot) { 223 if (!slot) {
141 slot = ERR_PTR(-ENOMEM); 224 err = -ENOMEM;
142 goto out; 225 goto err;
143 } 226 }
144 227
145 slot->bus = parent; 228 slot->bus = parent;
146 slot->number = slot_nr; 229 slot->number = slot_nr;
147 230
148 slot->kobj.kset = pci_slots_kset; 231 slot->kobj.kset = pci_slots_kset;
149 err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL, 232
150 "%s", name); 233 slot_name = make_slot_name(name);
151 if (err) { 234 if (!slot_name) {
152 printk(KERN_ERR "Unable to register kobject %s\n", name); 235 err = -ENOMEM;
153 goto err; 236 goto err;
154 } 237 }
155 238
239 err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL,
240 "%s", slot_name);
241 if (err)
242 goto err;
243
156 INIT_LIST_HEAD(&slot->list); 244 INIT_LIST_HEAD(&slot->list);
157 list_add(&slot->list, &parent->slots); 245 list_add(&slot->list, &parent->slots);
158 246
@@ -164,10 +252,10 @@ placeholder:
164 pr_debug("%s: created pci_slot on %04x:%02x:%02x\n", 252 pr_debug("%s: created pci_slot on %04x:%02x:%02x\n",
165 __func__, pci_domain_nr(parent), parent->number, slot_nr); 253 __func__, pci_domain_nr(parent), parent->number, slot_nr);
166 254
167 out: 255out:
168 up_write(&pci_bus_sem); 256 up_write(&pci_bus_sem);
169 return slot; 257 return slot;
170 err: 258err:
171 kfree(slot); 259 kfree(slot);
172 slot = ERR_PTR(err); 260 slot = ERR_PTR(err);
173 goto out; 261 goto out;
@@ -175,7 +263,7 @@ placeholder:
175EXPORT_SYMBOL_GPL(pci_create_slot); 263EXPORT_SYMBOL_GPL(pci_create_slot);
176 264
177/** 265/**
178 * pci_update_slot_number - update %struct pci_slot -> number 266 * pci_renumber_slot - update %struct pci_slot -> number
179 * @slot - %struct pci_slot to update 267 * @slot - %struct pci_slot to update
180 * @slot_nr - new number for slot 268 * @slot_nr - new number for slot
181 * 269 *
@@ -183,27 +271,22 @@ EXPORT_SYMBOL_GPL(pci_create_slot);
183 * created a placeholder slot in pci_create_slot() by passing a -1 as 271 * created a placeholder slot in pci_create_slot() by passing a -1 as
184 * slot_nr, to update their %struct pci_slot with the correct @slot_nr. 272 * slot_nr, to update their %struct pci_slot with the correct @slot_nr.
185 */ 273 */
186 274void pci_renumber_slot(struct pci_slot *slot, int slot_nr)
187void pci_update_slot_number(struct pci_slot *slot, int slot_nr)
188{ 275{
189 int name_count = 0;
190 struct pci_slot *tmp; 276 struct pci_slot *tmp;
191 277
192 down_write(&pci_bus_sem); 278 down_write(&pci_bus_sem);
193 279
194 list_for_each_entry(tmp, &slot->bus->slots, list) { 280 list_for_each_entry(tmp, &slot->bus->slots, list) {
195 WARN_ON(tmp->number == slot_nr); 281 WARN_ON(tmp->number == slot_nr);
196 if (!strcmp(kobject_name(&tmp->kobj), kobject_name(&slot->kobj))) 282 goto out;
197 name_count++;
198 } 283 }
199 284
200 if (name_count > 1)
201 printk(KERN_WARNING "pci_update_slot_number found %d slots with the same name: %s\n", name_count, kobject_name(&slot->kobj));
202
203 slot->number = slot_nr; 285 slot->number = slot_nr;
286out:
204 up_write(&pci_bus_sem); 287 up_write(&pci_bus_sem);
205} 288}
206EXPORT_SYMBOL_GPL(pci_update_slot_number); 289EXPORT_SYMBOL_GPL(pci_renumber_slot);
207 290
208/** 291/**
209 * pci_destroy_slot - decrement refcount for physical PCI slot 292 * pci_destroy_slot - decrement refcount for physical PCI slot
@@ -213,7 +296,6 @@ EXPORT_SYMBOL_GPL(pci_update_slot_number);
213 * just call kobject_put on its kobj and let our release methods do the 296 * just call kobject_put on its kobj and let our release methods do the
214 * rest. 297 * rest.
215 */ 298 */
216
217void pci_destroy_slot(struct pci_slot *slot) 299void pci_destroy_slot(struct pci_slot *slot)
218{ 300{
219 pr_debug("%s: dec refcount to %d on %04x:%02x:%02x\n", __func__, 301 pr_debug("%s: dec refcount to %d on %04x:%02x:%02x\n", __func__,