2018-01-27 04:22:04 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* PCI Express Hot Plug Controller Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995,2001 Compaq Computer Corporation
|
|
|
|
* Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
|
|
|
|
* Copyright (C) 2001 IBM Corp.
|
|
|
|
* Copyright (C) 2003-2004 Intel Corporation
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2005-08-17 06:16:10 +08:00
|
|
|
* Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2018-07-20 06:27:56 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include "../pci.h"
|
|
|
|
#include "pciehp.h"
|
|
|
|
|
2007-08-10 07:09:36 +08:00
|
|
|
/* The following routines constitute the bulk of the
|
2005-04-17 06:20:36 +08:00
|
|
|
hotplug controller logic
|
|
|
|
*/
|
|
|
|
|
2014-04-19 08:13:49 +08:00
|
|
|
static void set_slot_off(struct controller *ctrl, struct slot *pslot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* turn off slot, turn on Amber LED, turn off Green LED if supported*/
|
2008-04-26 05:39:06 +08:00
|
|
|
if (POWER_CTRL(ctrl)) {
|
2013-12-15 04:06:16 +08:00
|
|
|
pciehp_power_off_slot(pslot);
|
|
|
|
|
2008-10-24 13:26:35 +08:00
|
|
|
/*
|
|
|
|
* After turning power off, we must wait for at least 1 second
|
|
|
|
* before taking any action that relies on power having been
|
|
|
|
* removed from the slot/adapter.
|
|
|
|
*/
|
|
|
|
msleep(1000);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-12-16 08:23:54 +08:00
|
|
|
pciehp_green_led_off(pslot);
|
|
|
|
pciehp_set_attention_status(pslot, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* board_added - Called after a board has been added to the system.
|
2007-11-29 01:04:30 +08:00
|
|
|
* @p_slot: &slot where board is added
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-11-29 01:04:30 +08:00
|
|
|
* Turns power on for the board.
|
|
|
|
* Configures board.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-11-01 08:20:09 +08:00
|
|
|
static int board_added(struct slot *p_slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-12-22 09:01:09 +08:00
|
|
|
int retval = 0;
|
2005-11-01 08:20:08 +08:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2009-09-15 16:30:14 +08:00
|
|
|
struct pci_bus *parent = ctrl->pcie->port->subordinate;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-26 05:39:06 +08:00
|
|
|
if (POWER_CTRL(ctrl)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Power on slot */
|
2009-09-15 16:30:48 +08:00
|
|
|
retval = pciehp_power_on_slot(p_slot);
|
2006-12-22 09:01:09 +08:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-08-10 07:09:36 +08:00
|
|
|
|
2013-12-16 08:23:54 +08:00
|
|
|
pciehp_green_led_blink(p_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-22 09:01:09 +08:00
|
|
|
/* Check link training status */
|
2009-09-15 16:30:48 +08:00
|
|
|
retval = pciehp_check_link_status(ctrl);
|
2006-12-22 09:01:09 +08:00
|
|
|
if (retval) {
|
2008-10-23 10:47:32 +08:00
|
|
|
ctrl_err(ctrl, "Failed to check link status\n");
|
2009-11-13 14:14:10 +08:00
|
|
|
goto err_exit;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for a power fault */
|
2009-11-13 14:14:10 +08:00
|
|
|
if (ctrl->power_fault_detected || pciehp_query_power_fault(p_slot)) {
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_err(ctrl, "Slot(%s): Power fault\n", slot_name(p_slot));
|
2009-09-15 16:33:30 +08:00
|
|
|
retval = -EIO;
|
2005-11-01 08:20:06 +08:00
|
|
|
goto err_exit;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-12-22 09:01:09 +08:00
|
|
|
retval = pciehp_configure_device(p_slot);
|
|
|
|
if (retval) {
|
2017-10-14 02:35:46 +08:00
|
|
|
if (retval != -EEXIST) {
|
|
|
|
ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n",
|
|
|
|
pci_domain_nr(parent), parent->number);
|
2014-02-12 08:36:51 +08:00
|
|
|
goto err_exit;
|
2017-10-14 02:35:46 +08:00
|
|
|
}
|
2005-11-01 08:20:06 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-16 08:23:54 +08:00
|
|
|
pciehp_green_led_on(p_slot);
|
2016-08-04 07:29:45 +08:00
|
|
|
pciehp_set_attention_status(p_slot, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2005-11-01 08:20:06 +08:00
|
|
|
|
|
|
|
err_exit:
|
|
|
|
set_slot_off(ctrl, p_slot);
|
2006-12-22 09:01:09 +08:00
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-29 01:04:30 +08:00
|
|
|
* remove_board - Turns off slot and LEDs
|
|
|
|
* @p_slot: slot where board is being removed
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2018-07-20 06:27:36 +08:00
|
|
|
static void remove_board(struct slot *p_slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-01 08:20:08 +08:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-07-20 06:27:36 +08:00
|
|
|
pciehp_unconfigure_device(p_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-26 05:39:06 +08:00
|
|
|
if (POWER_CTRL(ctrl)) {
|
2013-12-15 04:06:16 +08:00
|
|
|
pciehp_power_off_slot(p_slot);
|
|
|
|
|
2008-10-24 13:26:35 +08:00
|
|
|
/*
|
|
|
|
* After turning power off, we must wait for at least 1 second
|
|
|
|
* before taking any action that relies on power having been
|
|
|
|
* removed from the slot/adapter.
|
|
|
|
*/
|
|
|
|
msleep(1000);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-15 16:30:48 +08:00
|
|
|
/* turn off Green LED */
|
2013-12-16 08:23:54 +08:00
|
|
|
pciehp_green_led_off(p_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-07-20 06:27:47 +08:00
|
|
|
static int pciehp_enable_slot(struct slot *slot);
|
|
|
|
static int pciehp_disable_slot(struct slot *slot);
|
|
|
|
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
void pciehp_request(struct controller *ctrl, int action)
|
|
|
|
{
|
|
|
|
atomic_or(action, &ctrl->pending_events);
|
|
|
|
if (!pciehp_poll_mode)
|
|
|
|
irq_wake_thread(ctrl->pcie->irq, ctrl);
|
|
|
|
}
|
|
|
|
|
2015-10-13 03:10:12 +08:00
|
|
|
void pciehp_queue_pushbutton_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct slot *p_slot = container_of(work, struct slot, work.work);
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-03-07 07:02:26 +08:00
|
|
|
mutex_lock(&p_slot->lock);
|
|
|
|
switch (p_slot->state) {
|
|
|
|
case BLINKINGOFF_STATE:
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
pciehp_request(ctrl, DISABLE_SLOT);
|
|
|
|
break;
|
2007-03-07 07:02:26 +08:00
|
|
|
case BLINKINGON_STATE:
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC);
|
|
|
|
break;
|
2007-03-07 07:02:26 +08:00
|
|
|
default:
|
2015-10-13 03:10:12 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-03-07 07:02:26 +08:00
|
|
|
mutex_unlock(&p_slot->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-07-20 06:27:41 +08:00
|
|
|
void pciehp_handle_button_press(struct slot *p_slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-03-07 07:02:26 +08:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-07-20 06:27:41 +08:00
|
|
|
mutex_lock(&p_slot->lock);
|
2007-03-07 07:02:26 +08:00
|
|
|
switch (p_slot->state) {
|
2018-07-20 06:27:45 +08:00
|
|
|
case OFF_STATE:
|
|
|
|
case ON_STATE:
|
|
|
|
if (p_slot->state == ON_STATE) {
|
2007-03-07 07:02:26 +08:00
|
|
|
p_slot->state = BLINKINGOFF_STATE;
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Powering off due to button press\n",
|
2014-04-19 08:13:50 +08:00
|
|
|
slot_name(p_slot));
|
2007-03-07 07:02:26 +08:00
|
|
|
} else {
|
|
|
|
p_slot->state = BLINKINGON_STATE;
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s) Powering on due to button press\n",
|
2014-04-19 08:13:50 +08:00
|
|
|
slot_name(p_slot));
|
2007-03-07 07:02:26 +08:00
|
|
|
}
|
|
|
|
/* blink green LED and turn off amber */
|
2013-12-16 08:23:54 +08:00
|
|
|
pciehp_green_led_blink(p_slot);
|
|
|
|
pciehp_set_attention_status(p_slot, 0);
|
2018-07-20 06:27:42 +08:00
|
|
|
schedule_delayed_work(&p_slot->work, 5 * HZ);
|
2007-03-07 07:02:26 +08:00
|
|
|
break;
|
|
|
|
case BLINKINGOFF_STATE:
|
|
|
|
case BLINKINGON_STATE:
|
|
|
|
/*
|
|
|
|
* Cancel if we are still blinking; this means that we
|
|
|
|
* press the attention again before the 5 sec. limit
|
|
|
|
* expires to cancel hot-add or hot-remove
|
|
|
|
*/
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Button cancel\n", slot_name(p_slot));
|
2007-03-07 07:02:26 +08:00
|
|
|
cancel_delayed_work(&p_slot->work);
|
2018-07-20 06:27:45 +08:00
|
|
|
if (p_slot->state == BLINKINGOFF_STATE) {
|
|
|
|
p_slot->state = ON_STATE;
|
2013-12-16 08:23:54 +08:00
|
|
|
pciehp_green_led_on(p_slot);
|
2018-07-20 06:27:45 +08:00
|
|
|
} else {
|
|
|
|
p_slot->state = OFF_STATE;
|
2013-12-16 08:23:54 +08:00
|
|
|
pciehp_green_led_off(p_slot);
|
2018-07-20 06:27:45 +08:00
|
|
|
}
|
2013-12-16 08:23:54 +08:00
|
|
|
pciehp_set_attention_status(p_slot, 0);
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Action canceled due to button press\n",
|
2014-04-19 08:13:50 +08:00
|
|
|
slot_name(p_slot));
|
2007-03-07 07:02:26 +08:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_err(ctrl, "Slot(%s): Ignoring invalid state %#x\n",
|
|
|
|
slot_name(p_slot), p_slot->state);
|
2007-03-07 07:02:26 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2018-07-20 06:27:41 +08:00
|
|
|
mutex_unlock(&p_slot->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
void pciehp_handle_disable_request(struct slot *slot)
|
|
|
|
{
|
|
|
|
struct controller *ctrl = slot->ctrl;
|
|
|
|
|
|
|
|
mutex_lock(&slot->lock);
|
|
|
|
switch (slot->state) {
|
|
|
|
case BLINKINGON_STATE:
|
|
|
|
case BLINKINGOFF_STATE:
|
|
|
|
cancel_delayed_work(&slot->work);
|
2018-07-28 13:22:00 +08:00
|
|
|
break;
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
}
|
|
|
|
slot->state = POWEROFF_STATE;
|
|
|
|
mutex_unlock(&slot->lock);
|
|
|
|
|
|
|
|
ctrl->request_result = pciehp_disable_slot(slot);
|
|
|
|
}
|
|
|
|
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
void pciehp_handle_presence_or_link_change(struct slot *slot, u32 events)
|
2014-02-05 10:29:10 +08:00
|
|
|
{
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
struct controller *ctrl = slot->ctrl;
|
2018-07-20 06:27:41 +08:00
|
|
|
bool link_active;
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
u8 present;
|
2018-07-20 06:27:41 +08:00
|
|
|
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
/*
|
|
|
|
* If the slot is on and presence or link has changed, turn it off.
|
|
|
|
* Even if it's occupied again, we cannot assume the card is the same.
|
|
|
|
*/
|
|
|
|
mutex_lock(&slot->lock);
|
|
|
|
switch (slot->state) {
|
2014-02-05 10:29:10 +08:00
|
|
|
case BLINKINGOFF_STATE:
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
cancel_delayed_work(&slot->work);
|
2018-07-28 13:22:00 +08:00
|
|
|
/* fall through */
|
2018-07-20 06:27:45 +08:00
|
|
|
case ON_STATE:
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
slot->state = POWEROFF_STATE;
|
|
|
|
mutex_unlock(&slot->lock);
|
|
|
|
if (events & PCI_EXP_SLTSTA_DLLSC)
|
|
|
|
ctrl_info(ctrl, "Slot(%s): Link Down\n",
|
|
|
|
slot_name(slot));
|
|
|
|
if (events & PCI_EXP_SLTSTA_PDC)
|
|
|
|
ctrl_info(ctrl, "Slot(%s): Card not present\n",
|
|
|
|
slot_name(slot));
|
|
|
|
pciehp_disable_slot(slot);
|
2014-02-05 10:29:10 +08:00
|
|
|
break;
|
|
|
|
default:
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
mutex_unlock(&slot->lock);
|
2018-07-28 13:22:00 +08:00
|
|
|
break;
|
2014-02-05 10:29:10 +08:00
|
|
|
}
|
2018-07-20 06:27:41 +08:00
|
|
|
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
/* Turn the slot on if it's occupied or link is up */
|
2018-07-20 06:27:41 +08:00
|
|
|
mutex_lock(&slot->lock);
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
pciehp_get_adapter_status(slot, &present);
|
|
|
|
link_active = pciehp_check_link_active(ctrl);
|
|
|
|
if (!present && !link_active) {
|
|
|
|
mutex_unlock(&slot->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
switch (slot->state) {
|
|
|
|
case BLINKINGON_STATE:
|
|
|
|
cancel_delayed_work(&slot->work);
|
2018-07-28 13:22:00 +08:00
|
|
|
/* fall through */
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
case OFF_STATE:
|
2018-07-20 06:27:41 +08:00
|
|
|
slot->state = POWERON_STATE;
|
|
|
|
mutex_unlock(&slot->lock);
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
if (present)
|
|
|
|
ctrl_info(ctrl, "Slot(%s): Card present\n",
|
|
|
|
slot_name(slot));
|
|
|
|
if (link_active)
|
|
|
|
ctrl_info(ctrl, "Slot(%s): Link Up\n",
|
|
|
|
slot_name(slot));
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
ctrl->request_result = pciehp_enable_slot(slot);
|
PCI: pciehp: Become resilient to missed events
A hotplug port's Slot Status register does not count how often each type
of event occurred, it only records the fact *that* an event has occurred.
Previously pciehp queued a work item for each event. But if it missed
an event, e.g. removal of a card in-between two back-to-back insertions,
it queued up the wrong work item or no work item at all. Commit
fad214b0aa72 ("PCI: pciehp: Process all hotplug events before looking
for new ones") sought to improve the situation by shrinking the window
during which events may be missed.
But Stefan Roese reports unbalanced Card present and Link Up events,
suggesting that we're still missing events if they occur very rapidly.
Bjorn Helgaas responds that he considers pciehp's event handling
"baroque" and calls for its simplification and rationalization:
https://lkml.kernel.org/r/20180202192045.GA53759@bhelgaas-glaptop.roam.corp.google.com
It gets worse once a hotplug port is runtime suspended: The port can
signal an interrupt while it and its parents are in D3hot, i.e. while
it is inaccessible. By the time we've runtime resumed all parents to D0
and read the port's Slot Status register, we may have missed an arbitrary
number of events. Event handling therefore needs to be reworked to
become resilient to missed events.
Assume that a Presence Detect Changed event has occurred.
Consider the following truth table:
- Slot is in OFF_STATE and is currently empty. => Do nothing.
(The event is trailing a Link Down or we've
missed an insertion and subsequent removal.)
- Slot is in OFF_STATE and is currently occupied. => Turn the slot on.
- Slot is in ON_STATE and is currently empty. => Turn the slot off.
- Slot is in ON_STATE and is currently occupied. => Turn the slot off,
(Be cautious and assume the card in then back on.
the slot isn't the same as before.)
This leads to the following simple algorithm:
1 If the slot is in ON_STATE, turn it off unconditionally.
2 If the slot is currently occupied, turn it on.
Because those actions are now carried out synchronously, rather than by
scheduled work items, pciehp reacts to the *current* situation and
missed events no longer matter.
Data Link Layer State Changed events can be handled identically to
Presence Detect Changed events. Note that in the above truth table,
a Link Up trailing a Card present event didn't have to be accounted for:
It is filtered out by pciehp_check_link_status().
As for Attention Button Pressed events, PCIe r4.0, sec 6.7.1.5 says:
"Once the Power Indicator begins blinking, a 5-second abort interval
exists during which a second depression of the Attention Button cancels
the operation." In other words, the user can only expect the system to
react to a button press after it starts blinking. Missed button presses
that occur in-between are irrelevant.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Mayurkumar Patel <mayurkumar.patel@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
2018-07-20 06:27:49 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-07-20 06:27:41 +08:00
|
|
|
mutex_unlock(&slot->lock);
|
2018-07-28 13:22:00 +08:00
|
|
|
break;
|
2007-03-07 07:02:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 06:27:40 +08:00
|
|
|
static int __pciehp_enable_slot(struct slot *p_slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u8 getstatus = 0;
|
2008-09-05 11:11:26 +08:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-15 04:06:16 +08:00
|
|
|
pciehp_get_adapter_status(p_slot, &getstatus);
|
|
|
|
if (!getstatus) {
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): No adapter\n", slot_name(p_slot));
|
2006-09-20 08:04:33 +08:00
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-04-26 05:39:06 +08:00
|
|
|
if (MRL_SENS(p_slot->ctrl)) {
|
2013-12-15 04:06:16 +08:00
|
|
|
pciehp_get_latch_status(p_slot, &getstatus);
|
|
|
|
if (getstatus) {
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Latch open\n",
|
2008-10-23 10:47:32 +08:00
|
|
|
slot_name(p_slot));
|
2006-09-20 08:04:33 +08:00
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2007-08-10 07:09:36 +08:00
|
|
|
|
2008-04-26 05:39:06 +08:00
|
|
|
if (POWER_CTRL(p_slot->ctrl)) {
|
2013-12-15 04:06:16 +08:00
|
|
|
pciehp_get_power_status(p_slot, &getstatus);
|
|
|
|
if (getstatus) {
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already enabled\n",
|
2008-10-23 10:47:32 +08:00
|
|
|
slot_name(p_slot));
|
2016-11-19 16:32:46 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 06:50:30 +08:00
|
|
|
return board_added(p_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-07-20 06:27:47 +08:00
|
|
|
static int pciehp_enable_slot(struct slot *slot)
|
2018-07-20 06:27:40 +08:00
|
|
|
{
|
|
|
|
struct controller *ctrl = slot->ctrl;
|
|
|
|
int ret;
|
|
|
|
|
2018-07-20 06:27:56 +08:00
|
|
|
pm_runtime_get_sync(&ctrl->pcie->port->dev);
|
2018-07-20 06:27:40 +08:00
|
|
|
ret = __pciehp_enable_slot(slot);
|
|
|
|
if (ret && ATTN_BUTTN(ctrl))
|
|
|
|
pciehp_green_led_off(slot); /* may be blinking */
|
2018-07-20 06:27:56 +08:00
|
|
|
pm_runtime_put(&ctrl->pcie->port->dev);
|
2018-07-20 06:27:40 +08:00
|
|
|
|
|
|
|
mutex_lock(&slot->lock);
|
2018-07-20 06:27:45 +08:00
|
|
|
slot->state = ret ? OFF_STATE : ON_STATE;
|
2018-07-20 06:27:40 +08:00
|
|
|
mutex_unlock(&slot->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __pciehp_disable_slot(struct slot *p_slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u8 getstatus = 0;
|
2008-09-05 11:11:26 +08:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-26 05:39:06 +08:00
|
|
|
if (POWER_CTRL(p_slot->ctrl)) {
|
2013-12-15 04:06:16 +08:00
|
|
|
pciehp_get_power_status(p_slot, &getstatus);
|
|
|
|
if (!getstatus) {
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already disabled\n",
|
2008-10-23 10:47:32 +08:00
|
|
|
slot_name(p_slot));
|
2006-09-20 08:04:33 +08:00
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 06:27:36 +08:00
|
|
|
remove_board(p_slot);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-07-20 06:27:47 +08:00
|
|
|
static int pciehp_disable_slot(struct slot *slot)
|
2018-07-20 06:27:40 +08:00
|
|
|
{
|
2018-07-20 06:27:56 +08:00
|
|
|
struct controller *ctrl = slot->ctrl;
|
2018-07-20 06:27:40 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-07-20 06:27:56 +08:00
|
|
|
pm_runtime_get_sync(&ctrl->pcie->port->dev);
|
2018-07-20 06:27:40 +08:00
|
|
|
ret = __pciehp_disable_slot(slot);
|
2018-07-20 06:27:56 +08:00
|
|
|
pm_runtime_put(&ctrl->pcie->port->dev);
|
2018-07-20 06:27:40 +08:00
|
|
|
|
|
|
|
mutex_lock(&slot->lock);
|
2018-07-20 06:27:45 +08:00
|
|
|
slot->state = OFF_STATE;
|
2018-07-20 06:27:40 +08:00
|
|
|
mutex_unlock(&slot->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-03-07 07:02:26 +08:00
|
|
|
int pciehp_sysfs_enable_slot(struct slot *p_slot)
|
|
|
|
{
|
2008-09-05 11:11:26 +08:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2007-03-07 07:02:26 +08:00
|
|
|
|
|
|
|
mutex_lock(&p_slot->lock);
|
|
|
|
switch (p_slot->state) {
|
|
|
|
case BLINKINGON_STATE:
|
2018-07-20 06:27:45 +08:00
|
|
|
case OFF_STATE:
|
2007-03-07 07:02:26 +08:00
|
|
|
mutex_unlock(&p_slot->lock);
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
/*
|
|
|
|
* The IRQ thread becomes a no-op if the user pulls out the
|
|
|
|
* card before the thread wakes up, so initialize to -ENODEV.
|
|
|
|
*/
|
|
|
|
ctrl->request_result = -ENODEV;
|
|
|
|
pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC);
|
|
|
|
wait_event(ctrl->requester,
|
|
|
|
!atomic_read(&ctrl->pending_events));
|
|
|
|
return ctrl->request_result;
|
2007-03-07 07:02:26 +08:00
|
|
|
case POWERON_STATE:
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already in powering on state\n",
|
2008-10-21 07:41:38 +08:00
|
|
|
slot_name(p_slot));
|
2007-03-07 07:02:26 +08:00
|
|
|
break;
|
|
|
|
case BLINKINGOFF_STATE:
|
2018-07-20 06:27:45 +08:00
|
|
|
case ON_STATE:
|
2007-03-07 07:02:26 +08:00
|
|
|
case POWEROFF_STATE:
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already enabled\n",
|
2008-10-21 07:41:38 +08:00
|
|
|
slot_name(p_slot));
|
2007-03-07 07:02:26 +08:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n",
|
|
|
|
slot_name(p_slot), p_slot->state);
|
2007-03-07 07:02:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&p_slot->lock);
|
|
|
|
|
2018-07-20 06:27:40 +08:00
|
|
|
return -ENODEV;
|
2007-03-07 07:02:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int pciehp_sysfs_disable_slot(struct slot *p_slot)
|
|
|
|
{
|
2008-09-05 11:11:26 +08:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2007-03-07 07:02:26 +08:00
|
|
|
|
|
|
|
mutex_lock(&p_slot->lock);
|
|
|
|
switch (p_slot->state) {
|
|
|
|
case BLINKINGOFF_STATE:
|
2018-07-20 06:27:45 +08:00
|
|
|
case ON_STATE:
|
2007-03-07 07:02:26 +08:00
|
|
|
mutex_unlock(&p_slot->lock);
|
PCI: pciehp: Enable/disable exclusively from IRQ thread
Besides the IRQ thread, there are several other places in the driver
which enable or disable the slot:
- pciehp_probe() enables the slot if it's occupied and the pciehp_force
module parameter is used.
- pciehp_resume() enables or disables the slot after system sleep.
- pciehp_queue_pushbutton_work() enables or disables the slot after the
5 second delay following an Attention Button press.
- pciehp_sysfs_enable_slot() and pciehp_sysfs_disable_slot() enable or
disable the slot on sysfs write.
This requires locking and complicates pciehp's state machine.
A simplification can be achieved by enabling and disabling the slot
exclusively from the IRQ thread.
Amend the functions listed above to request slot enable/disablement from
the IRQ thread by either synthesizing a Presence Detect Changed event or,
in the case of a disable user request (via sysfs or an Attention Button
press), submitting a newly introduced force disable request. The latter
is needed because the slot shall be forced off despite being occupied.
For this force disable request, avoid colliding with Slot Status register
bits by using a bit number greater than 16.
For synchronous execution of requests (on sysfs write), wait for the
request to finish and retrieve the result. There can only ever be one
sysfs write in flight due to the locking in kernfs_fop_write(), hence
there is no risk of returning the result of a different sysfs request to
user space.
The POWERON_STATE and POWEROFF_STATE is now no longer entered by the
above-listed functions, but solely by the IRQ thread when it begins a
power transition. Afterwards, it moves to STATIC_STATE. The same
applies to canceling the Attention Button work, it likewise becomes an
IRQ thread only operation.
An immediate consequence is that the POWERON_STATE and POWEROFF_STATE is
never observed by the IRQ thread itself, only by functions called in a
different context, such as pciehp_sysfs_enable_slot(). So remove
handling of these states from pciehp_handle_button_press() and
pciehp_handle_link_change() which are exclusively called from the IRQ
thread.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-07-20 06:27:46 +08:00
|
|
|
pciehp_request(ctrl, DISABLE_SLOT);
|
|
|
|
wait_event(ctrl->requester,
|
|
|
|
!atomic_read(&ctrl->pending_events));
|
|
|
|
return ctrl->request_result;
|
2007-03-07 07:02:26 +08:00
|
|
|
case POWEROFF_STATE:
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already in powering off state\n",
|
2008-10-21 07:41:38 +08:00
|
|
|
slot_name(p_slot));
|
2007-03-07 07:02:26 +08:00
|
|
|
break;
|
|
|
|
case BLINKINGON_STATE:
|
2018-07-20 06:27:45 +08:00
|
|
|
case OFF_STATE:
|
2007-03-07 07:02:26 +08:00
|
|
|
case POWERON_STATE:
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already disabled\n",
|
2008-10-21 07:41:38 +08:00
|
|
|
slot_name(p_slot));
|
2007-03-07 07:02:26 +08:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-09 04:19:58 +08:00
|
|
|
ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n",
|
|
|
|
slot_name(p_slot), p_slot->state);
|
2007-03-07 07:02:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&p_slot->lock);
|
|
|
|
|
2018-07-20 06:27:40 +08:00
|
|
|
return -ENODEV;
|
2007-03-07 07:02:26 +08:00
|
|
|
}
|