aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/hotplug/ibmphp_core.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/ibmphp_core.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/ibmphp_core.c')
-rw-r--r--drivers/pci/hotplug/ibmphp_core.c27
1 files changed, 2 insertions, 25 deletions
diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
index b82fdc17040d..96e5b1f544ac 100644
--- a/drivers/pci/hotplug/ibmphp_core.c
+++ b/drivers/pci/hotplug/ibmphp_core.c
@@ -582,29 +582,10 @@ static int validate(struct slot *slot_cur, int opn)
582 ****************************************************************************/ 582 ****************************************************************************/
583int ibmphp_update_slot_info(struct slot *slot_cur) 583int ibmphp_update_slot_info(struct slot *slot_cur)
584{ 584{
585 struct hotplug_slot_info *info;
586 struct pci_bus *bus = slot_cur->hotplug_slot->pci_slot->bus; 585 struct pci_bus *bus = slot_cur->hotplug_slot->pci_slot->bus;
587 int rc;
588 u8 bus_speed; 586 u8 bus_speed;
589 u8 mode; 587 u8 mode;
590 588
591 info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
592 if (!info)
593 return -ENOMEM;
594
595 info->power_status = SLOT_PWRGD(slot_cur->status);
596 info->attention_status = SLOT_ATTN(slot_cur->status,
597 slot_cur->ext_status);
598 info->latch_status = SLOT_LATCH(slot_cur->status);
599 if (!SLOT_PRESENT(slot_cur->status)) {
600 info->adapter_status = 0;
601/* info->max_adapter_speed_status = MAX_ADAPTER_NONE; */
602 } else {
603 info->adapter_status = 1;
604/* get_max_adapter_speed_1(slot_cur->hotplug_slot,
605 &info->max_adapter_speed_status, 0); */
606 }
607
608 bus_speed = slot_cur->bus_on->current_speed; 589 bus_speed = slot_cur->bus_on->current_speed;
609 mode = slot_cur->bus_on->current_bus_mode; 590 mode = slot_cur->bus_on->current_bus_mode;
610 591
@@ -630,9 +611,7 @@ int ibmphp_update_slot_info(struct slot *slot_cur)
630 bus->cur_bus_speed = bus_speed; 611 bus->cur_bus_speed = bus_speed;
631 // To do: bus_names 612 // To do: bus_names
632 613
633 rc = pci_hp_change_slot_info(slot_cur->hotplug_slot, info); 614 return 0;
634 kfree(info);
635 return rc;
636} 615}
637 616
638 617
@@ -684,7 +663,6 @@ static void free_slots(void)
684 ibmphp_unconfigure_card(&slot_cur, -1); 663 ibmphp_unconfigure_card(&slot_cur, -1);
685 664
686 pci_hp_destroy(slot_cur->hotplug_slot); 665 pci_hp_destroy(slot_cur->hotplug_slot);
687 kfree(slot_cur->hotplug_slot->info);
688 kfree(slot_cur->hotplug_slot); 666 kfree(slot_cur->hotplug_slot);
689 kfree(slot_cur); 667 kfree(slot_cur);
690 } 668 }
@@ -1095,8 +1073,7 @@ static int enable_slot(struct hotplug_slot *hs)
1095 1073
1096 slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL); 1074 slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
1097 if (!slot_cur->func) { 1075 if (!slot_cur->func) {
1098 /* We cannot do update_slot_info here, since no memory for 1076 /* do update_slot_info here? */
1099 * kmalloc n.e.ways, and update_slot_info allocates some */
1100 rc = -ENOMEM; 1077 rc = -ENOMEM;
1101 goto error_power; 1078 goto error_power;
1102 } 1079 }