2018-01-27 04:22:04 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* CompactPCI Hot Plug Driver
|
|
|
|
*
|
2005-05-28 04:48:52 +08:00
|
|
|
* Copyright (C) 2002,2005 SOMA Networks, Inc.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
|
|
|
|
* Copyright (C) 2001 IBM Corp.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Send feedback to <scottm@somanetworks.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
2017-02-03 02:15:33 +08:00
|
|
|
#include <linux/sched/signal.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/pci.h>
|
2006-10-14 11:05:19 +08:00
|
|
|
#include <linux/pci_hotplug.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/delay.h>
|
2007-07-10 02:55:57 +08:00
|
|
|
#include <linux/kthread.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "cpci_hotplug.h"
|
|
|
|
|
|
|
|
#define DRIVER_AUTHOR "Scott Murray <scottm@somanetworks.com>"
|
|
|
|
#define DRIVER_DESC "CompactPCI Hot Plug Core"
|
|
|
|
|
|
|
|
#define MY_NAME "cpci_hotplug"
|
|
|
|
|
|
|
|
#define dbg(format, arg...) \
|
|
|
|
do { \
|
2005-05-28 04:48:52 +08:00
|
|
|
if (cpci_debug) \
|
2015-12-28 05:21:11 +08:00
|
|
|
printk(KERN_DEBUG "%s: " format "\n", \
|
|
|
|
MY_NAME, ## arg); \
|
2005-05-28 04:48:52 +08:00
|
|
|
} while (0)
|
2015-12-28 05:21:11 +08:00
|
|
|
#define err(format, arg...) printk(KERN_ERR "%s: " format "\n", MY_NAME, ## arg)
|
|
|
|
#define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME, ## arg)
|
|
|
|
#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME, ## arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* local variables */
|
2005-05-10 05:31:50 +08:00
|
|
|
static DECLARE_RWSEM(list_rwsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
static LIST_HEAD(slot_list);
|
|
|
|
static int slots;
|
2005-05-10 05:31:50 +08:00
|
|
|
static atomic_t extracting;
|
2005-04-17 06:20:36 +08:00
|
|
|
int cpci_debug;
|
|
|
|
static struct cpci_hp_controller *controller;
|
2007-07-10 02:55:57 +08:00
|
|
|
static struct task_struct *cpci_thread;
|
|
|
|
static int thread_finished;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int enable_slot(struct hotplug_slot *slot);
|
|
|
|
static int disable_slot(struct hotplug_slot *slot);
|
|
|
|
static int set_attention_status(struct hotplug_slot *slot, u8 value);
|
2014-04-19 08:13:49 +08:00
|
|
|
static int get_power_status(struct hotplug_slot *slot, u8 *value);
|
|
|
|
static int get_attention_status(struct hotplug_slot *slot, u8 *value);
|
|
|
|
static int get_adapter_status(struct hotplug_slot *slot, u8 *value);
|
|
|
|
static int get_latch_status(struct hotplug_slot *slot, u8 *value);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-08 15:59:01 +08:00
|
|
|
static const struct hotplug_slot_ops cpci_hotplug_slot_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.enable_slot = enable_slot,
|
|
|
|
.disable_slot = disable_slot,
|
|
|
|
.set_attention_status = set_attention_status,
|
|
|
|
.get_power_status = get_power_status,
|
|
|
|
.get_attention_status = get_attention_status,
|
2005-05-10 05:31:50 +08:00
|
|
|
.get_adapter_status = get_adapter_status,
|
|
|
|
.get_latch_status = get_latch_status,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
enable_slot(struct hotplug_slot *hotplug_slot)
|
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
int retval = 0;
|
|
|
|
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("%s - physical_slot = %s", __func__, slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
if (controller->ops->set_power)
|
2005-04-17 06:20:36 +08:00
|
|
|
retval = controller->ops->set_power(slot, 1);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
disable_slot(struct hotplug_slot *hotplug_slot)
|
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
int retval = 0;
|
|
|
|
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("%s - physical_slot = %s", __func__, slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
down_write(&list_rwsem);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Unconfigure device */
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("%s - unconfiguring slot %s", __func__, slot_name(slot));
|
2014-09-08 02:03:32 +08:00
|
|
|
retval = cpci_unconfigure_slot(slot);
|
|
|
|
if (retval) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err("%s - could not unconfigure slot %s",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot));
|
2005-05-28 04:48:52 +08:00
|
|
|
goto disable_error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("%s - finished unconfiguring slot %s", __func__, slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Clear EXT (by setting it) */
|
2005-05-28 04:48:52 +08:00
|
|
|
if (cpci_clear_ext(slot)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err("%s - could not clear EXT for slot %s",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
retval = -ENODEV;
|
2005-05-28 04:48:52 +08:00
|
|
|
goto disable_error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
cpci_led_on(slot);
|
|
|
|
|
2014-09-08 02:03:32 +08:00
|
|
|
if (controller->ops->set_power) {
|
|
|
|
retval = controller->ops->set_power(slot, 0);
|
|
|
|
if (retval)
|
2005-05-28 04:48:52 +08:00
|
|
|
goto disable_error;
|
2014-09-08 02:03:32 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +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
|
|
|
slot->adapter_status = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
if (slot->extracting) {
|
2005-05-10 05:31:50 +08:00
|
|
|
slot->extracting = 0;
|
|
|
|
atomic_dec(&extracting);
|
|
|
|
}
|
2005-05-28 04:48:52 +08:00
|
|
|
disable_error:
|
|
|
|
up_write(&list_rwsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8
|
|
|
|
cpci_get_power_status(struct slot *slot)
|
|
|
|
{
|
|
|
|
u8 power = 1;
|
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
if (controller->ops->get_power)
|
2005-04-17 06:20:36 +08:00
|
|
|
power = controller->ops->get_power(slot);
|
|
|
|
return power;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-04-19 08:13:49 +08:00
|
|
|
get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
*value = cpci_get_power_status(slot);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-04-19 08:13:49 +08:00
|
|
|
get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
*value = cpci_get_attention_status(slot);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
|
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
return cpci_set_attention_status(to_slot(hotplug_slot), status);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-05-10 05:31:50 +08:00
|
|
|
static int
|
2014-04-19 08:13:49 +08:00
|
|
|
get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
|
2005-05-10 05:31:50 +08:00
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
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
|
|
|
|
|
|
|
*value = slot->adapter_status;
|
2005-05-10 05:31:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-04-19 08:13:49 +08:00
|
|
|
get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
|
2005-05-10 05:31:50 +08:00
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
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
|
|
|
|
|
|
|
*value = slot->latch_status;
|
2005-05-10 05:31:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
PCI: hotplug: Demidlayer registration with the core
When a hotplug driver calls pci_hp_register(), all steps necessary for
registration are carried out in one go, including creation of a kobject
and addition to sysfs. That's a problem for pciehp once it's converted
to enable/disable the slot exclusively from the IRQ thread: The thread
needs to be spawned after creation of the kobject (because it uses the
kobject's name), but before addition to sysfs (because it will handle
enable/disable requests submitted via sysfs).
pci_hp_deregister() does offer a ->release callback that's invoked
after deletion from sysfs and before destruction of the kobject. But
because pci_hp_register() doesn't offer a counterpart, hotplug drivers'
->probe and ->remove code becomes asymmetric, which is error prone
as recently discovered use-after-free bugs in pciehp's ->remove hook
have shown.
In a sense, this appears to be a case of the midlayer antipattern:
"The core thesis of the "midlayer mistake" is that midlayers are
bad and should not exist. That common functionality which it is
so tempting to put in a midlayer should instead be provided as
library routines which can [be] used, augmented, or ignored by
each bottom level driver independently. Thus every subsystem
that supports multiple implementations (or drivers) should
provide a very thin top layer which calls directly into the
bottom layer drivers, and a rich library of support code that
eases the implementation of those drivers. This library is
available to, but not forced upon, those drivers."
-- Neil Brown (2009), https://lwn.net/Articles/336262/
The presence of midlayer traits in the PCI hotplug core might be ascribed
to its age: When it was introduced in February 2002, the blessings of a
library approach might not have been well known:
https://git.kernel.org/tglx/history/c/a8a2069f432c
For comparison, the driver core does offer split functions for creating
a kobject (device_initialize()) and addition to sysfs (device_add()) as
an alternative to carrying out everything at once (device_register()).
This was introduced in October 2002:
https://git.kernel.org/tglx/history/c/8b290eb19962
The odd ->release callback in the PCI hotplug core was added in 2003:
https://git.kernel.org/tglx/history/c/69f8d663b595
Clearly, a library approach would not force every hotplug driver to
implement a ->release callback, but rather allow the driver to remove
the sysfs files, release its data structures and finally destroy the
kobject. Alternatively, a driver may choose to remove everything with
pci_hp_deregister(), then release its data structures.
To this end, offer drivers pci_hp_initialize() and pci_hp_add() as a
split-up version of pci_hp_register(). Likewise, offer pci_hp_del()
and pci_hp_destroy() as a split-up version of pci_hp_deregister().
Eliminate the ->release callback and move its code into each driver's
teardown routine.
Declare pci_hp_deregister() void, in keeping with the usual kernel
pattern that enablement can fail, but disablement cannot. It only
returned an error if the caller passed in a NULL pointer or a slot which
has never or is no longer registered or is sharing its name with another
slot. Those would be bugs, so WARN about them. Few hotplug drivers
actually checked the return value and those that did only printed a
useless error message to dmesg. Remove that.
For most drivers the conversion was straightforward since it doesn't
matter whether the code in the ->release callback is executed before or
after destruction of the kobject. But in the case of ibmphp, it was
unclear to me whether setting slot_cur->ctrl and slot_cur->bus_on to
NULL needs to happen before the kobject is destroyed, so I erred on
the side of caution and ensured that the order stays the same. Another
nontrivial case is pnv_php, I've found the list and kref logic difficult
to understand, however my impression was that it is safe to delete the
list element and drop the references until after the kobject is
destroyed.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
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: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Sebastian Ott <sebott@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>
Cc: Andy Shevchenko <andy@infradead.org>
2018-07-20 06:27:43 +08:00
|
|
|
static void release_slot(struct slot *slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-12-27 07:28:08 +08:00
|
|
|
pci_dev_put(slot->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SLOT_NAME_SIZE 6
|
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
|
|
|
|
{
|
|
|
|
struct slot *slot;
|
2008-10-21 07:41:17 +08:00
|
|
|
char name[SLOT_NAME_SIZE];
|
2012-07-16 23:25:56 +08:00
|
|
|
int status;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
if (!(controller && bus))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a structure for each slot, and register that slot
|
|
|
|
* with the pci_hotplug subsystem.
|
|
|
|
*/
|
|
|
|
for (i = first; i <= last; ++i) {
|
2015-12-28 05:21:11 +08:00
|
|
|
slot = kzalloc(sizeof(struct slot), GFP_KERNEL);
|
2012-07-16 23:25:56 +08:00
|
|
|
if (!slot) {
|
|
|
|
status = -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
goto error;
|
2012-07-16 23:25:56 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
slot->bus = bus;
|
|
|
|
slot->number = i;
|
|
|
|
slot->devfn = PCI_DEVFN(i, 0);
|
|
|
|
|
2008-10-21 07:41:17 +08:00
|
|
|
snprintf(name, SLOT_NAME_SIZE, "%02x:%02x", bus->number, i);
|
|
|
|
|
2018-09-08 15:59:01 +08:00
|
|
|
slot->hotplug_slot.ops = &cpci_hotplug_slot_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("registering slot %s", name);
|
2018-09-08 15:59:01 +08:00
|
|
|
status = pci_hp_register(&slot->hotplug_slot, bus, i, name);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status) {
|
|
|
|
err("pci_hp_register failed with error %d", status);
|
2018-09-08 15:59:01 +08:00
|
|
|
goto error_slot;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("slot registered with name: %s", slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Add slot to our internal list */
|
2005-05-10 05:31:50 +08:00
|
|
|
down_write(&list_rwsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
list_add(&slot->slot_list, &slot_list);
|
|
|
|
slots++;
|
2005-05-10 05:31:50 +08:00
|
|
|
up_write(&list_rwsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
error_slot:
|
|
|
|
kfree(slot);
|
|
|
|
error:
|
|
|
|
return status;
|
|
|
|
}
|
2014-04-26 04:32:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_register_bus);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_unregister_bus(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
struct slot *slot;
|
2005-05-28 04:48:52 +08:00
|
|
|
struct slot *tmp;
|
|
|
|
int status = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-10 05:31:50 +08:00
|
|
|
down_write(&list_rwsem);
|
2005-05-28 04:48:52 +08:00
|
|
|
if (!slots) {
|
2005-05-10 05:31:50 +08:00
|
|
|
up_write(&list_rwsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2005-05-28 04:48:52 +08:00
|
|
|
list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) {
|
|
|
|
if (slot->bus == bus) {
|
|
|
|
list_del(&slot->slot_list);
|
|
|
|
slots--;
|
|
|
|
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("deregistering slot %s", slot_name(slot));
|
2018-09-08 15:59:01 +08:00
|
|
|
pci_hp_deregister(&slot->hotplug_slot);
|
PCI: hotplug: Demidlayer registration with the core
When a hotplug driver calls pci_hp_register(), all steps necessary for
registration are carried out in one go, including creation of a kobject
and addition to sysfs. That's a problem for pciehp once it's converted
to enable/disable the slot exclusively from the IRQ thread: The thread
needs to be spawned after creation of the kobject (because it uses the
kobject's name), but before addition to sysfs (because it will handle
enable/disable requests submitted via sysfs).
pci_hp_deregister() does offer a ->release callback that's invoked
after deletion from sysfs and before destruction of the kobject. But
because pci_hp_register() doesn't offer a counterpart, hotplug drivers'
->probe and ->remove code becomes asymmetric, which is error prone
as recently discovered use-after-free bugs in pciehp's ->remove hook
have shown.
In a sense, this appears to be a case of the midlayer antipattern:
"The core thesis of the "midlayer mistake" is that midlayers are
bad and should not exist. That common functionality which it is
so tempting to put in a midlayer should instead be provided as
library routines which can [be] used, augmented, or ignored by
each bottom level driver independently. Thus every subsystem
that supports multiple implementations (or drivers) should
provide a very thin top layer which calls directly into the
bottom layer drivers, and a rich library of support code that
eases the implementation of those drivers. This library is
available to, but not forced upon, those drivers."
-- Neil Brown (2009), https://lwn.net/Articles/336262/
The presence of midlayer traits in the PCI hotplug core might be ascribed
to its age: When it was introduced in February 2002, the blessings of a
library approach might not have been well known:
https://git.kernel.org/tglx/history/c/a8a2069f432c
For comparison, the driver core does offer split functions for creating
a kobject (device_initialize()) and addition to sysfs (device_add()) as
an alternative to carrying out everything at once (device_register()).
This was introduced in October 2002:
https://git.kernel.org/tglx/history/c/8b290eb19962
The odd ->release callback in the PCI hotplug core was added in 2003:
https://git.kernel.org/tglx/history/c/69f8d663b595
Clearly, a library approach would not force every hotplug driver to
implement a ->release callback, but rather allow the driver to remove
the sysfs files, release its data structures and finally destroy the
kobject. Alternatively, a driver may choose to remove everything with
pci_hp_deregister(), then release its data structures.
To this end, offer drivers pci_hp_initialize() and pci_hp_add() as a
split-up version of pci_hp_register(). Likewise, offer pci_hp_del()
and pci_hp_destroy() as a split-up version of pci_hp_deregister().
Eliminate the ->release callback and move its code into each driver's
teardown routine.
Declare pci_hp_deregister() void, in keeping with the usual kernel
pattern that enablement can fail, but disablement cannot. It only
returned an error if the caller passed in a NULL pointer or a slot which
has never or is no longer registered or is sharing its name with another
slot. Those would be bugs, so WARN about them. Few hotplug drivers
actually checked the return value and those that did only printed a
useless error message to dmesg. Remove that.
For most drivers the conversion was straightforward since it doesn't
matter whether the code in the ->release callback is executed before or
after destruction of the kobject. But in the case of ibmphp, it was
unclear to me whether setting slot_cur->ctrl and slot_cur->bus_on to
NULL needs to happen before the kobject is destroyed, so I erred on
the side of caution and ensured that the order stays the same. Another
nontrivial case is pnv_php, I've found the list and kref logic difficult
to understand, however my impression was that it is safe to delete the
list element and drop the references until after the kobject is
destroyed.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
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: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Sebastian Ott <sebott@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>
Cc: Andy Shevchenko <andy@infradead.org>
2018-07-20 06:27:43 +08:00
|
|
|
release_slot(slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2005-05-10 05:31:50 +08:00
|
|
|
up_write(&list_rwsem);
|
2005-05-28 04:48:52 +08:00
|
|
|
return status;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2014-04-26 04:32:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_unregister_bus);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* This is the interrupt mode interrupt handler */
|
|
|
|
static irqreturn_t
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
cpci_hp_intr(int irq, void *data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
dbg("entered cpci_hp_intr");
|
|
|
|
|
|
|
|
/* Check to see if it was our interrupt */
|
2006-07-02 10:29:41 +08:00
|
|
|
if ((controller->irq_flags & IRQF_SHARED) &&
|
2005-04-17 06:20:36 +08:00
|
|
|
!controller->ops->check_irq(controller->dev_id)) {
|
|
|
|
dbg("exited cpci_hp_intr, not our interrupt");
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable ENUM interrupt */
|
|
|
|
controller->ops->disable_irq();
|
|
|
|
|
|
|
|
/* Trigger processing by the event thread */
|
2007-07-10 02:55:57 +08:00
|
|
|
wake_up_process(cpci_thread);
|
2005-04-17 06:20:36 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-05-10 05:31:50 +08:00
|
|
|
* According to PICMG 2.1 R2.0, section 6.3.2, upon
|
2005-04-17 06:20:36 +08:00
|
|
|
* initialization, the system driver shall clear the
|
|
|
|
* INS bits of the cold-inserted devices.
|
|
|
|
*/
|
|
|
|
static int
|
2005-05-28 04:48:52 +08:00
|
|
|
init_slots(int clear_ins)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct slot *slot;
|
2014-04-19 08:13:49 +08:00
|
|
|
struct pci_dev *dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - enter", __func__);
|
2005-05-10 05:31:50 +08:00
|
|
|
down_read(&list_rwsem);
|
2005-05-28 04:48:52 +08:00
|
|
|
if (!slots) {
|
2005-05-10 05:31:50 +08:00
|
|
|
up_read(&list_rwsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2005-05-28 04:48:52 +08:00
|
|
|
list_for_each_entry(slot, &slot_list, slot_list) {
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("%s - looking at slot %s", __func__, slot_name(slot));
|
2005-05-28 04:48:52 +08:00
|
|
|
if (clear_ins && cpci_check_and_clear_ins(slot))
|
2005-04-17 06:20:36 +08:00
|
|
|
dbg("%s - cleared INS for slot %s",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot));
|
2005-05-28 04:48:52 +08:00
|
|
|
dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0));
|
|
|
|
if (dev) {
|
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
|
|
|
slot->adapter_status = 1;
|
|
|
|
slot->latch_status = 1;
|
2005-05-28 04:48:52 +08:00
|
|
|
slot->dev = dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2005-05-10 05:31:50 +08:00
|
|
|
up_read(&list_rwsem);
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - exit", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
check_slots(void)
|
|
|
|
{
|
|
|
|
struct slot *slot;
|
|
|
|
int extracted;
|
|
|
|
int inserted;
|
2005-05-10 05:31:50 +08:00
|
|
|
u16 hs_csr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-10 05:31:50 +08:00
|
|
|
down_read(&list_rwsem);
|
2005-05-28 04:48:52 +08:00
|
|
|
if (!slots) {
|
2005-05-10 05:31:50 +08:00
|
|
|
up_read(&list_rwsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
err("no slots registered, shutting down");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
extracted = inserted = 0;
|
2005-05-28 04:48:52 +08:00
|
|
|
list_for_each_entry(slot, &slot_list, slot_list) {
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("%s - looking at slot %s", __func__, slot_name(slot));
|
2005-05-28 04:48:52 +08:00
|
|
|
if (cpci_check_and_clear_ins(slot)) {
|
|
|
|
/*
|
|
|
|
* Some broken hardware (e.g. PLX 9054AB) asserts
|
|
|
|
* ENUM# twice...
|
|
|
|
*/
|
|
|
|
if (slot->dev) {
|
|
|
|
warn("slot %s already inserted",
|
2008-10-21 07:41:17 +08:00
|
|
|
slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
inserted++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process insertion */
|
2008-10-21 07:41:17 +08:00
|
|
|
dbg("%s - slot %s inserted", __func__, slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* GSM, debug */
|
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
|
|
|
dbg("%s - slot %s HS_CSR (1) = %04x",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot), hs_csr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Configure device */
|
|
|
|
dbg("%s - configuring slot %s",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot));
|
2005-05-28 04:48:52 +08:00
|
|
|
if (cpci_configure_slot(slot)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err("%s - could not configure slot %s",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dbg("%s - finished configuring slot %s",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* GSM, debug */
|
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
|
|
|
dbg("%s - slot %s HS_CSR (2) = %04x",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot), hs_csr);
|
2005-04-17 06:20:36 +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
|
|
|
slot->latch_status = 1;
|
|
|
|
slot->adapter_status = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
cpci_led_off(slot);
|
|
|
|
|
|
|
|
/* GSM, debug */
|
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
|
|
|
dbg("%s - slot %s HS_CSR (3) = %04x",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot), hs_csr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
inserted++;
|
2005-05-28 04:48:52 +08:00
|
|
|
} else if (cpci_check_ext(slot)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Process extraction request */
|
|
|
|
dbg("%s - slot %s extracted",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* GSM, debug */
|
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
|
|
|
dbg("%s - slot %s HS_CSR = %04x",
|
2008-10-21 07:41:17 +08:00
|
|
|
__func__, slot_name(slot), hs_csr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
if (!slot->extracting) {
|
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
|
|
|
slot->latch_status = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
slot->extracting = 1;
|
2005-05-28 04:48:52 +08:00
|
|
|
atomic_inc(&extracting);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
extracted++;
|
2005-05-28 04:48:52 +08:00
|
|
|
} else if (slot->extracting) {
|
2005-05-10 05:31:50 +08:00
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
2005-05-28 04:48:52 +08:00
|
|
|
if (hs_csr == 0xffff) {
|
2005-05-10 05:31:50 +08:00
|
|
|
/*
|
|
|
|
* Hmmm, we're likely hosed at this point, should we
|
|
|
|
* bother trying to tell the driver or not?
|
|
|
|
*/
|
|
|
|
err("card in slot %s was improperly removed",
|
2008-10-21 07:41:17 +08:00
|
|
|
slot_name(slot));
|
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
|
|
|
slot->adapter_status = 0;
|
2005-05-10 05:31:50 +08:00
|
|
|
slot->extracting = 0;
|
|
|
|
atomic_dec(&extracting);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2005-05-10 05:31:50 +08:00
|
|
|
up_read(&list_rwsem);
|
|
|
|
dbg("inserted=%d, extracted=%d, extracting=%d",
|
|
|
|
inserted, extracted, atomic_read(&extracting));
|
2005-05-28 04:48:52 +08:00
|
|
|
if (inserted || extracted)
|
2005-04-17 06:20:36 +08:00
|
|
|
return extracted;
|
2005-05-28 04:48:52 +08:00
|
|
|
else if (!atomic_read(&extracting)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err("cannot find ENUM# source, shutting down");
|
|
|
|
return -1;
|
|
|
|
}
|
2005-05-10 05:31:50 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the interrupt mode worker thread body */
|
|
|
|
static int
|
|
|
|
event_thread(void *data)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - event thread started", __func__);
|
2005-05-28 04:48:52 +08:00
|
|
|
while (1) {
|
2005-04-17 06:20:36 +08:00
|
|
|
dbg("event thread sleeping");
|
2007-07-10 02:55:57 +08:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
schedule();
|
|
|
|
if (kthread_should_stop())
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2005-05-10 05:31:50 +08:00
|
|
|
do {
|
2005-04-17 06:20:36 +08:00
|
|
|
rc = check_slots();
|
2005-05-10 05:31:50 +08:00
|
|
|
if (rc > 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Give userspace a chance to handle extraction */
|
|
|
|
msleep(500);
|
2005-05-10 05:31:50 +08:00
|
|
|
} else if (rc < 0) {
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - error checking slots", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
thread_finished = 1;
|
2007-07-10 02:55:57 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-07-10 02:55:57 +08:00
|
|
|
} while (atomic_read(&extracting) && !kthread_should_stop());
|
|
|
|
if (kthread_should_stop())
|
2005-05-28 04:48:52 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Re-enable ENUM# interrupt */
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - re-enabling irq", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
controller->ops->enable_irq();
|
|
|
|
}
|
2007-07-10 02:55:57 +08:00
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the polling mode worker thread body */
|
|
|
|
static int
|
|
|
|
poll_thread(void *data)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
while (1) {
|
2007-07-10 02:55:57 +08:00
|
|
|
if (kthread_should_stop() || signal_pending(current))
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2005-05-28 04:48:52 +08:00
|
|
|
if (controller->ops->query_enum()) {
|
2005-05-10 05:31:50 +08:00
|
|
|
do {
|
|
|
|
rc = check_slots();
|
2005-05-28 04:48:52 +08:00
|
|
|
if (rc > 0) {
|
2005-05-10 05:31:50 +08:00
|
|
|
/* Give userspace a chance to handle extraction */
|
|
|
|
msleep(500);
|
2005-05-28 04:48:52 +08:00
|
|
|
} else if (rc < 0) {
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - error checking slots", __func__);
|
2005-05-10 05:31:50 +08:00
|
|
|
thread_finished = 1;
|
2007-07-10 02:55:57 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-07-10 02:55:57 +08:00
|
|
|
} while (atomic_read(&extracting) && !kthread_should_stop());
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
msleep(100);
|
|
|
|
}
|
2007-07-10 02:55:57 +08:00
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpci_start_thread(void)
|
|
|
|
{
|
2005-05-28 04:48:52 +08:00
|
|
|
if (controller->irq)
|
2007-07-10 02:55:57 +08:00
|
|
|
cpci_thread = kthread_run(event_thread, NULL, "cpci_hp_eventd");
|
2005-05-28 04:48:52 +08:00
|
|
|
else
|
2007-07-10 02:55:57 +08:00
|
|
|
cpci_thread = kthread_run(poll_thread, NULL, "cpci_hp_polld");
|
|
|
|
if (IS_ERR(cpci_thread)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err("Can't start up our thread");
|
2007-07-10 02:55:57 +08:00
|
|
|
return PTR_ERR(cpci_thread);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-07-10 02:55:57 +08:00
|
|
|
thread_finished = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cpci_stop_thread(void)
|
|
|
|
{
|
2007-07-10 02:55:57 +08:00
|
|
|
kthread_stop(cpci_thread);
|
2005-04-17 06:20:36 +08:00
|
|
|
thread_finished = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_register_controller(struct cpci_hp_controller *new_controller)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
if (controller)
|
|
|
|
return -1;
|
|
|
|
if (!(new_controller && new_controller->ops))
|
|
|
|
return -EINVAL;
|
|
|
|
if (new_controller->irq) {
|
|
|
|
if (!(new_controller->ops->enable_irq &&
|
|
|
|
new_controller->ops->disable_irq))
|
|
|
|
status = -EINVAL;
|
|
|
|
if (request_irq(new_controller->irq,
|
|
|
|
cpci_hp_intr,
|
|
|
|
new_controller->irq_flags,
|
|
|
|
MY_NAME,
|
|
|
|
new_controller->dev_id)) {
|
|
|
|
err("Can't get irq %d for the hotplug cPCI controller",
|
|
|
|
new_controller->irq);
|
|
|
|
status = -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-05-28 04:48:52 +08:00
|
|
|
dbg("%s - acquired controller irq %d",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__, new_controller->irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-05-28 04:48:52 +08:00
|
|
|
if (!status)
|
|
|
|
controller = new_controller;
|
2005-04-17 06:20:36 +08:00
|
|
|
return status;
|
|
|
|
}
|
2014-04-26 04:32:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_register_controller);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
static void
|
|
|
|
cleanup_slots(void)
|
|
|
|
{
|
|
|
|
struct slot *slot;
|
|
|
|
struct slot *tmp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unregister all of our slots with the pci_hotplug subsystem,
|
|
|
|
* and free up all memory that we had allocated.
|
|
|
|
*/
|
|
|
|
down_write(&list_rwsem);
|
|
|
|
if (!slots)
|
|
|
|
goto cleanup_null;
|
|
|
|
list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) {
|
|
|
|
list_del(&slot->slot_list);
|
2018-09-08 15:59:01 +08:00
|
|
|
pci_hp_deregister(&slot->hotplug_slot);
|
PCI: hotplug: Demidlayer registration with the core
When a hotplug driver calls pci_hp_register(), all steps necessary for
registration are carried out in one go, including creation of a kobject
and addition to sysfs. That's a problem for pciehp once it's converted
to enable/disable the slot exclusively from the IRQ thread: The thread
needs to be spawned after creation of the kobject (because it uses the
kobject's name), but before addition to sysfs (because it will handle
enable/disable requests submitted via sysfs).
pci_hp_deregister() does offer a ->release callback that's invoked
after deletion from sysfs and before destruction of the kobject. But
because pci_hp_register() doesn't offer a counterpart, hotplug drivers'
->probe and ->remove code becomes asymmetric, which is error prone
as recently discovered use-after-free bugs in pciehp's ->remove hook
have shown.
In a sense, this appears to be a case of the midlayer antipattern:
"The core thesis of the "midlayer mistake" is that midlayers are
bad and should not exist. That common functionality which it is
so tempting to put in a midlayer should instead be provided as
library routines which can [be] used, augmented, or ignored by
each bottom level driver independently. Thus every subsystem
that supports multiple implementations (or drivers) should
provide a very thin top layer which calls directly into the
bottom layer drivers, and a rich library of support code that
eases the implementation of those drivers. This library is
available to, but not forced upon, those drivers."
-- Neil Brown (2009), https://lwn.net/Articles/336262/
The presence of midlayer traits in the PCI hotplug core might be ascribed
to its age: When it was introduced in February 2002, the blessings of a
library approach might not have been well known:
https://git.kernel.org/tglx/history/c/a8a2069f432c
For comparison, the driver core does offer split functions for creating
a kobject (device_initialize()) and addition to sysfs (device_add()) as
an alternative to carrying out everything at once (device_register()).
This was introduced in October 2002:
https://git.kernel.org/tglx/history/c/8b290eb19962
The odd ->release callback in the PCI hotplug core was added in 2003:
https://git.kernel.org/tglx/history/c/69f8d663b595
Clearly, a library approach would not force every hotplug driver to
implement a ->release callback, but rather allow the driver to remove
the sysfs files, release its data structures and finally destroy the
kobject. Alternatively, a driver may choose to remove everything with
pci_hp_deregister(), then release its data structures.
To this end, offer drivers pci_hp_initialize() and pci_hp_add() as a
split-up version of pci_hp_register(). Likewise, offer pci_hp_del()
and pci_hp_destroy() as a split-up version of pci_hp_deregister().
Eliminate the ->release callback and move its code into each driver's
teardown routine.
Declare pci_hp_deregister() void, in keeping with the usual kernel
pattern that enablement can fail, but disablement cannot. It only
returned an error if the caller passed in a NULL pointer or a slot which
has never or is no longer registered or is sharing its name with another
slot. Those would be bugs, so WARN about them. Few hotplug drivers
actually checked the return value and those that did only printed a
useless error message to dmesg. Remove that.
For most drivers the conversion was straightforward since it doesn't
matter whether the code in the ->release callback is executed before or
after destruction of the kobject. But in the case of ibmphp, it was
unclear to me whether setting slot_cur->ctrl and slot_cur->bus_on to
NULL needs to happen before the kobject is destroyed, so I erred on
the side of caution and ensured that the order stays the same. Another
nontrivial case is pnv_php, I've found the list and kref logic difficult
to understand, however my impression was that it is safe to delete the
list element and drop the references until after the kobject is
destroyed.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
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: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Sebastian Ott <sebott@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>
Cc: Andy Shevchenko <andy@infradead.org>
2018-07-20 06:27:43 +08:00
|
|
|
release_slot(slot);
|
2005-05-28 04:48:52 +08:00
|
|
|
}
|
|
|
|
cleanup_null:
|
|
|
|
up_write(&list_rwsem);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int
|
|
|
|
cpci_hp_unregister_controller(struct cpci_hp_controller *old_controller)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
if (controller) {
|
|
|
|
if (!thread_finished)
|
2005-04-17 06:20:36 +08:00
|
|
|
cpci_stop_thread();
|
2005-05-28 04:48:52 +08:00
|
|
|
if (controller->irq)
|
2005-04-17 06:20:36 +08:00
|
|
|
free_irq(controller->irq, controller->dev_id);
|
|
|
|
controller = NULL;
|
2005-05-28 04:48:52 +08:00
|
|
|
cleanup_slots();
|
|
|
|
} else
|
2005-04-17 06:20:36 +08:00
|
|
|
status = -ENODEV;
|
|
|
|
return status;
|
|
|
|
}
|
2014-04-26 04:32:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_unregister_controller);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_start(void)
|
|
|
|
{
|
|
|
|
static int first = 1;
|
|
|
|
int status;
|
|
|
|
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - enter", __func__);
|
2005-05-28 04:48:52 +08:00
|
|
|
if (!controller)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2005-05-10 05:31:50 +08:00
|
|
|
down_read(&list_rwsem);
|
2005-05-28 04:48:52 +08:00
|
|
|
if (list_empty(&slot_list)) {
|
2005-05-10 05:31:50 +08:00
|
|
|
up_read(&list_rwsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2005-05-10 05:31:50 +08:00
|
|
|
up_read(&list_rwsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
status = init_slots(first);
|
|
|
|
if (first)
|
2005-04-17 06:20:36 +08:00
|
|
|
first = 0;
|
2005-05-28 04:48:52 +08:00
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
status = cpci_start_thread();
|
2005-05-28 04:48:52 +08:00
|
|
|
if (status)
|
2005-04-17 06:20:36 +08:00
|
|
|
return status;
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - thread started", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-28 04:48:52 +08:00
|
|
|
if (controller->irq) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Start enum interrupt processing */
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - enabling irq", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
controller->ops->enable_irq();
|
|
|
|
}
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - exit", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2014-04-26 04:32:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_start);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_stop(void)
|
|
|
|
{
|
2005-05-28 04:48:52 +08:00
|
|
|
if (!controller)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
2005-05-28 04:48:52 +08:00
|
|
|
if (controller->irq) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Stop enum interrupt processing */
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - disabling irq", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
controller->ops->disable_irq();
|
|
|
|
}
|
|
|
|
cpci_stop_thread();
|
|
|
|
return 0;
|
|
|
|
}
|
2014-04-26 04:32:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_stop);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int __init
|
|
|
|
cpci_hotplug_init(int debug)
|
|
|
|
{
|
|
|
|
cpci_debug = debug;
|
|
|
|
return 0;
|
|
|
|
}
|