2018-01-26 20:22:04 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* CompactPCI Hot Plug Core Functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 SOMA Networks, Inc.
|
|
|
|
* Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
|
|
|
|
* Copyright (C) 2001 IBM Corp.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Send feedback to <scottm@somanetworks.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CPCI_HOTPLUG_H
|
|
|
|
#define _CPCI_HOTPLUG_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/pci.h>
|
2008-10-20 23:41:17 +00:00
|
|
|
#include <linux/pci_hotplug.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-05-09 21:31:50 +00:00
|
|
|
/* PICMG 2.1 R2.0 HS CSR bits: */
|
2005-04-16 22:20:36 +00:00
|
|
|
#define HS_CSR_INS 0x0080
|
|
|
|
#define HS_CSR_EXT 0x0040
|
|
|
|
#define HS_CSR_PI 0x0030
|
|
|
|
#define HS_CSR_LOO 0x0008
|
|
|
|
#define HS_CSR_PIE 0x0004
|
|
|
|
#define HS_CSR_EIM 0x0002
|
|
|
|
#define HS_CSR_DHA 0x0001
|
|
|
|
|
|
|
|
struct slot {
|
|
|
|
u8 number;
|
|
|
|
unsigned int devfn;
|
|
|
|
struct pci_bus *bus;
|
|
|
|
struct pci_dev *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 07:59:01 +00:00
|
|
|
unsigned int latch_status:1;
|
|
|
|
unsigned int adapter_status:1;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int extracting;
|
2018-09-08 07:59:01 +00:00
|
|
|
struct hotplug_slot hotplug_slot;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct list_head slot_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cpci_hp_controller_ops {
|
2015-12-27 21:21:11 +00:00
|
|
|
int (*query_enum)(void);
|
|
|
|
int (*enable_irq)(void);
|
|
|
|
int (*disable_irq)(void);
|
|
|
|
int (*check_irq)(void *dev_id);
|
|
|
|
int (*hardware_test)(struct slot *slot, u32 value);
|
|
|
|
u8 (*get_power)(struct slot *slot);
|
|
|
|
int (*set_power)(struct slot *slot, int value);
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cpci_hp_controller {
|
|
|
|
unsigned int irq;
|
|
|
|
unsigned long irq_flags;
|
|
|
|
char *devname;
|
|
|
|
void *dev_id;
|
|
|
|
char *name;
|
|
|
|
struct cpci_hp_controller_ops *ops;
|
|
|
|
};
|
|
|
|
|
2008-10-20 23:41:17 +00:00
|
|
|
static inline const char *slot_name(struct slot *slot)
|
|
|
|
{
|
2018-09-08 07:59:01 +00:00
|
|
|
return hotplug_slot_name(&slot->hotplug_slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct slot *to_slot(struct hotplug_slot *hotplug_slot)
|
|
|
|
{
|
|
|
|
return container_of(hotplug_slot, struct slot, hotplug_slot);
|
2008-10-20 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 18:02:59 +00:00
|
|
|
int cpci_hp_register_controller(struct cpci_hp_controller *controller);
|
|
|
|
int cpci_hp_unregister_controller(struct cpci_hp_controller *controller);
|
|
|
|
int cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last);
|
|
|
|
int cpci_hp_unregister_bus(struct pci_bus *bus);
|
|
|
|
int cpci_hp_start(void);
|
|
|
|
int cpci_hp_stop(void);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal function prototypes, these functions should not be used by
|
|
|
|
* board/chassis drivers.
|
|
|
|
*/
|
2013-04-12 18:02:59 +00:00
|
|
|
u8 cpci_get_attention_status(struct slot *slot);
|
|
|
|
u8 cpci_get_latch_status(struct slot *slot);
|
|
|
|
u8 cpci_get_adapter_status(struct slot *slot);
|
2014-04-19 00:13:49 +00:00
|
|
|
u16 cpci_get_hs_csr(struct slot *slot);
|
2013-04-12 18:02:59 +00:00
|
|
|
int cpci_set_attention_status(struct slot *slot, int status);
|
2014-04-19 00:13:49 +00:00
|
|
|
int cpci_check_and_clear_ins(struct slot *slot);
|
|
|
|
int cpci_check_ext(struct slot *slot);
|
|
|
|
int cpci_clear_ext(struct slot *slot);
|
|
|
|
int cpci_led_on(struct slot *slot);
|
|
|
|
int cpci_led_off(struct slot *slot);
|
2013-04-12 18:02:59 +00:00
|
|
|
int cpci_configure_slot(struct slot *slot);
|
|
|
|
int cpci_unconfigure_slot(struct slot *slot);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-04-15 16:44:18 +00:00
|
|
|
#ifdef CONFIG_HOTPLUG_PCI_CPCI
|
|
|
|
int cpci_hotplug_init(int debug);
|
|
|
|
#else
|
|
|
|
static inline int cpci_hotplug_init(int debug) { return 0; }
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* _CPCI_HOTPLUG_H */
|