aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/hotplug/pnv_php.c
diff options
context:
space:
mode:
authorLukas Wunner <lukas@wunner.de>2018-09-08 03:59:01 -0400
committerBjorn Helgaas <bhelgaas@google.com>2018-09-18 18:52:15 -0400
commita7da21613c4efcd4cc0235e6a30bec96ae47c619 (patch)
tree130c0fc6bc359509cb0c27ea6fe01d38a61b890c /drivers/pci/hotplug/pnv_php.c
parent81c4b5bf30de01a0f6b43ccaa1d220f4a0a5d99c (diff)
PCI: hotplug: Drop hotplug_slot_info
Ever since the PCI hotplug core was introduced in 2002, drivers had to allocate and register a struct hotplug_slot_info for every slot: https://git.kernel.org/tglx/history/c/a8a2069f432c Apparently the idea was that drivers furnish the hotplug core with an up-to-date card presence status, power status, latch status and attention indicator status as well as notify the hotplug core of changes thereof. However only 4 out of 12 hotplug drivers bother to notify the hotplug core with pci_hp_change_slot_info() and the hotplug core never made any use of the information: There is just a single macro in pci_hotplug_core.c, GET_STATUS(), which uses the hotplug_slot_info if the driver lacks the corresponding callback in hotplug_slot_ops. The macro is called when the user reads the attribute via sysfs. Now, if the callback isn't defined, the attribute isn't exposed in sysfs in the first place (see e.g. has_power_file()). There are only two situations when the hotplug_slot_info would actually be accessed: * If the driver defines ->enable_slot or ->disable_slot but not ->get_power_status. * If the driver defines ->set_attention_status but not ->get_attention_status. There is no driver doing the former and just a single driver doing the latter, namely pnv_php.c. Amend it with a ->get_attention_status callback. With that, the hotplug_slot_info becomes completely unused by the PCI hotplug core. But a few drivers use it internally as a cache: cpcihp uses it to cache the latch_status and adapter_status. cpqhp uses it to cache the adapter_status. pnv_php and rpaphp use it to cache the attention_status. shpchp uses it to cache all four values. Amend these drivers to cache the information in their private slot struct. shpchp's slot struct already contains members to cache the power_status and adapter_status, so additional members are only needed for the other two values. In the case of cpqphp, the cached value is only accessed in a single place, so instead of caching it, read the current value from the hardware. Caution: acpiphp, cpci, cpqhp, shpchp, asus-wmi and eeepc-laptop populate the hotplug_slot_info with initial values on probe. That code is herewith removed. There is a theoretical chance that the code has side effects without which the driver fails to function, e.g. if the ACPI method to read the adapter status needs to be executed at least once on probe. That seems unlikely to me, still maintainers should review the changes carefully for this possibility. Rafael adds: "I'm not aware of any case in which it will break anything, [...] but if that happens, it may be necessary to add the execution of the control methods in question directly to the initialization part." Signed-off-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com> # drivers/pci/hotplug/rpa* Acked-by: Sebastian Ott <sebott@linux.ibm.com> # drivers/pci/hotplug/s390* Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86 Cc: Len Brown <lenb@kernel.org> Cc: Scott Murray <scott@spiteful.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Oliver OHalloran <oliveroh@au1.ibm.com> Cc: Gavin Shan <gwshan@linux.vnet.ibm.com> Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com> Cc: Corentin Chary <corentin.chary@gmail.com> Cc: Darren Hart <dvhart@infradead.org>
Diffstat (limited to 'drivers/pci/hotplug/pnv_php.c')
-rw-r--r--drivers/pci/hotplug/pnv_php.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
index 12b92a0ff688..5bb63430262e 100644
--- a/drivers/pci/hotplug/pnv_php.c
+++ b/drivers/pci/hotplug/pnv_php.c
@@ -328,6 +328,11 @@ out:
328 return ret; 328 return ret;
329} 329}
330 330
331static inline struct pnv_php_slot *to_pnv_php_slot(struct hotplug_slot *slot)
332{
333 return container_of(slot, struct pnv_php_slot, slot);
334}
335
331int pnv_php_set_slot_power_state(struct hotplug_slot *slot, 336int pnv_php_set_slot_power_state(struct hotplug_slot *slot,
332 uint8_t state) 337 uint8_t state)
333{ 338{
@@ -378,7 +383,6 @@ static int pnv_php_get_power_state(struct hotplug_slot *slot, u8 *state)
378 ret); 383 ret);
379 } else { 384 } else {
380 *state = power_state; 385 *state = power_state;
381 slot->info->power_status = power_state;
382 } 386 }
383 387
384 return 0; 388 return 0;
@@ -397,7 +401,6 @@ static int pnv_php_get_adapter_state(struct hotplug_slot *slot, u8 *state)
397 ret = pnv_pci_get_presence_state(php_slot->id, &presence); 401 ret = pnv_pci_get_presence_state(php_slot->id, &presence);
398 if (ret >= 0) { 402 if (ret >= 0) {
399 *state = presence; 403 *state = presence;
400 slot->info->adapter_status = presence;
401 ret = 0; 404 ret = 0;
402 } else { 405 } else {
403 pci_warn(php_slot->pdev, "Error %d getting presence\n", ret); 406 pci_warn(php_slot->pdev, "Error %d getting presence\n", ret);
@@ -406,10 +409,20 @@ static int pnv_php_get_adapter_state(struct hotplug_slot *slot, u8 *state)
406 return ret; 409 return ret;
407} 410}
408 411
412static int pnv_php_get_attention_state(struct hotplug_slot *slot, u8 *state)
413{
414 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
415
416 *state = php_slot->attention_state;
417 return 0;
418}
419
409static int pnv_php_set_attention_state(struct hotplug_slot *slot, u8 state) 420static int pnv_php_set_attention_state(struct hotplug_slot *slot, u8 state)
410{ 421{
422 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
423
411 /* FIXME: Make it real once firmware supports it */ 424 /* FIXME: Make it real once firmware supports it */
412 slot->info->attention_status = state; 425 php_slot->attention_state = state;
413 426
414 return 0; 427 return 0;
415} 428}
@@ -501,8 +514,7 @@ scan:
501 514
502static int pnv_php_enable_slot(struct hotplug_slot *slot) 515static int pnv_php_enable_slot(struct hotplug_slot *slot)
503{ 516{
504 struct pnv_php_slot *php_slot = container_of(slot, 517 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
505 struct pnv_php_slot, slot);
506 518
507 return pnv_php_enable(php_slot, true); 519 return pnv_php_enable(php_slot, true);
508} 520}
@@ -533,6 +545,7 @@ static int pnv_php_disable_slot(struct hotplug_slot *slot)
533static const struct hotplug_slot_ops php_slot_ops = { 545static const struct hotplug_slot_ops php_slot_ops = {
534 .get_power_status = pnv_php_get_power_state, 546 .get_power_status = pnv_php_get_power_state,
535 .get_adapter_status = pnv_php_get_adapter_state, 547 .get_adapter_status = pnv_php_get_adapter_state,
548 .get_attention_status = pnv_php_get_attention_state,
536 .set_attention_status = pnv_php_set_attention_state, 549 .set_attention_status = pnv_php_set_attention_state,
537 .enable_slot = pnv_php_enable_slot, 550 .enable_slot = pnv_php_enable_slot,
538 .disable_slot = pnv_php_disable_slot, 551 .disable_slot = pnv_php_disable_slot,
@@ -594,7 +607,6 @@ static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn)
594 php_slot->id = id; 607 php_slot->id = id;
595 php_slot->power_state_check = false; 608 php_slot->power_state_check = false;
596 php_slot->slot.ops = &php_slot_ops; 609 php_slot->slot.ops = &php_slot_ops;
597 php_slot->slot.info = &php_slot->slot_info;
598 php_slot->slot.private = php_slot; 610 php_slot->slot.private = php_slot;
599 611
600 INIT_LIST_HEAD(&php_slot->children); 612 INIT_LIST_HEAD(&php_slot->children);