2018-01-27 04:22:04 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
|
|
|
|
* Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Send feedback to <lxie@us.ibm.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/pci.h>
|
2005-10-31 07:03:48 +08:00
|
|
|
#include <linux/string.h>
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/pci-bridge.h>
|
|
|
|
#include <asm/rtas.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
|
2005-10-31 07:03:48 +08:00
|
|
|
#include "../pci.h" /* for pci_add_new_bus */
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "rpaphp.h"
|
|
|
|
|
2006-01-13 08:28:22 +08:00
|
|
|
int rpaphp_get_sensor_state(struct slot *slot, int *state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int setlevel;
|
|
|
|
|
|
|
|
rc = rtas_get_sensor(DR_ENTITY_SENSE, slot->index, state);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
if (rc == -EFAULT || rc == -EEXIST) {
|
|
|
|
dbg("%s: slot must be power up to get sensor-state\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-11-15 02:28:18 +08:00
|
|
|
/* some slots have to be powered up
|
2005-04-17 06:20:36 +08:00
|
|
|
* before get-sensor will succeed.
|
|
|
|
*/
|
|
|
|
rc = rtas_set_power_level(slot->power_domain, POWER_ON,
|
|
|
|
&setlevel);
|
|
|
|
if (rc < 0) {
|
|
|
|
dbg("%s: power on slot[%s] failed rc=%d.\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__, slot->name, rc);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
rc = rtas_get_sensor(DR_ENTITY_SENSE,
|
|
|
|
slot->index, state);
|
|
|
|
}
|
|
|
|
} else if (rc == -ENODEV)
|
2008-03-04 11:09:46 +08:00
|
|
|
info("%s: slot is unusable\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2008-03-04 11:09:46 +08:00
|
|
|
err("%s failed to get sensor state\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-04-14 06:34:20 +08:00
|
|
|
/**
|
|
|
|
* rpaphp_enable_slot - record slot state, config pci device
|
2007-11-29 01:04:30 +08:00
|
|
|
* @slot: target &slot
|
2007-04-14 06:34:20 +08:00
|
|
|
*
|
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>
2018-09-08 15:59:01 +08:00
|
|
|
* Initialize values in the slot structure to indicate if there is a pci card
|
|
|
|
* plugged into the slot. If the slot is not empty, run the pcibios routine
|
2007-04-14 06:34:20 +08:00
|
|
|
* to get pcibios stuff correctly set up.
|
|
|
|
*/
|
|
|
|
int rpaphp_enable_slot(struct slot *slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-04-14 06:34:14 +08:00
|
|
|
int rc, level, state;
|
|
|
|
struct pci_bus *bus;
|
2007-04-14 06:34:12 +08:00
|
|
|
|
2007-04-14 06:34:16 +08:00
|
|
|
slot->state = EMPTY;
|
|
|
|
|
2007-04-14 06:34:14 +08:00
|
|
|
/* Find out if the power is turned on for the slot */
|
2007-04-14 06:34:13 +08:00
|
|
|
rc = rtas_get_power_level(slot->power_domain, &level);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2007-04-14 06:34:14 +08:00
|
|
|
/* Figure out if there is an adapter in the slot */
|
|
|
|
rc = rpaphp_get_sensor_state(slot, &state);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2007-04-14 06:34:12 +08:00
|
|
|
|
2016-05-03 13:41:38 +08:00
|
|
|
bus = pci_find_bus_by_node(slot->dn);
|
2007-04-14 06:34:16 +08:00
|
|
|
if (!bus) {
|
2017-07-19 05:43:21 +08:00
|
|
|
err("%s: no pci_bus for dn %pOF\n", __func__, slot->dn);
|
2007-04-14 06:34:16 +08:00
|
|
|
return -EINVAL;
|
2007-04-14 06:34:12 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-14 06:34:16 +08:00
|
|
|
slot->bus = bus;
|
|
|
|
slot->pci_devs = &bus->devices;
|
|
|
|
|
|
|
|
/* if there's an adapter in the slot, go add the pci devices */
|
|
|
|
if (state == PRESENT) {
|
|
|
|
slot->state = NOT_CONFIGURED;
|
|
|
|
|
|
|
|
/* non-empty slot has to have child */
|
|
|
|
if (!slot->dn->child) {
|
|
|
|
err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__, slot->name);
|
2007-04-14 06:34:16 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-03-06 15:39:01 +08:00
|
|
|
if (list_empty(&bus->devices)) {
|
2020-03-06 15:39:03 +08:00
|
|
|
pseries_eeh_init_edev_recursive(PCI_DN(slot->dn));
|
2016-05-03 13:41:37 +08:00
|
|
|
pci_hp_add_devices(bus);
|
2020-03-06 15:39:01 +08:00
|
|
|
}
|
2007-04-14 06:34:16 +08:00
|
|
|
|
|
|
|
if (!list_empty(&bus->devices)) {
|
|
|
|
slot->state = CONFIGURED;
|
|
|
|
}
|
2007-04-14 06:34:17 +08:00
|
|
|
|
2008-10-14 00:59:12 +08:00
|
|
|
if (rpaphp_debug) {
|
2007-04-14 06:34:17 +08:00
|
|
|
struct pci_dev *dev;
|
2017-07-19 05:43:21 +08:00
|
|
|
dbg("%s: pci_devs of slot[%pOF]\n", __func__, slot->dn);
|
2015-12-28 05:21:11 +08:00
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list)
|
2007-04-14 06:34:17 +08:00
|
|
|
dbg("\t%s\n", pci_name(dev));
|
|
|
|
}
|
2007-04-14 06:34:16 +08:00
|
|
|
}
|
2007-04-14 06:34:12 +08:00
|
|
|
|
2007-04-14 06:34:19 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|