2005-04-17 05:20:36 +07: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.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
|
|
* NON INFRINGEMENT. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
2005-08-17 05:16:10 +07:00
|
|
|
* Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
|
2005-04-17 05:20:36 +07: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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include "../pci.h"
|
|
|
|
#include "pciehp.h"
|
|
|
|
|
2007-03-07 06:02:26 +07:00
|
|
|
static void interrupt_event_handler(struct work_struct *work);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-06-15 09:35:13 +07:00
|
|
|
void pciehp_queue_interrupt_event(struct slot *p_slot, u32 event_type)
|
2006-09-23 00:17:10 +07:00
|
|
|
{
|
2007-03-07 06:02:26 +07:00
|
|
|
struct event_info *info;
|
|
|
|
|
|
|
|
info = kmalloc(sizeof(*info), GFP_ATOMIC);
|
2015-06-15 09:27:52 +07:00
|
|
|
if (!info) {
|
|
|
|
ctrl_err(p_slot->ctrl, "dropped event %d (ENOMEM)\n", event_type);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-07 06:02:26 +07:00
|
|
|
|
2015-06-15 09:27:52 +07:00
|
|
|
INIT_WORK(&info->work, interrupt_event_handler);
|
2007-03-07 06:02:26 +07:00
|
|
|
info->event_type = event_type;
|
|
|
|
info->p_slot = p_slot;
|
2013-01-11 09:15:54 +07:00
|
|
|
queue_work(p_slot->wq, &info->work);
|
2006-09-23 00:17:10 +07:00
|
|
|
}
|
|
|
|
|
2007-08-10 06:09:36 +07:00
|
|
|
/* The following routines constitute the bulk of the
|
2005-04-17 05:20:36 +07:00
|
|
|
hotplug controller logic
|
|
|
|
*/
|
|
|
|
|
2014-04-19 07:13:49 +07:00
|
|
|
static void set_slot_off(struct controller *ctrl, struct slot *pslot)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
/* turn off slot, turn on Amber LED, turn off Green LED if supported*/
|
2008-04-26 04:39:06 +07:00
|
|
|
if (POWER_CTRL(ctrl)) {
|
2013-12-15 03:06:16 +07:00
|
|
|
pciehp_power_off_slot(pslot);
|
|
|
|
|
2008-10-24 12:26:35 +07: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 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2013-12-16 07:23:54 +07:00
|
|
|
pciehp_green_led_off(pslot);
|
|
|
|
pciehp_set_attention_status(pslot, 1);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* board_added - Called after a board has been added to the system.
|
2007-11-29 00:04:30 +07:00
|
|
|
* @p_slot: &slot where board is added
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2007-11-29 00:04:30 +07:00
|
|
|
* Turns power on for the board.
|
|
|
|
* Configures board.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2005-11-01 07:20:09 +07:00
|
|
|
static int board_added(struct slot *p_slot)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2006-12-22 08:01:09 +07:00
|
|
|
int retval = 0;
|
2005-11-01 07:20:08 +07:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2009-09-15 15:30:14 +07:00
|
|
|
struct pci_bus *parent = ctrl->pcie->port->subordinate;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-04-26 04:39:06 +07:00
|
|
|
if (POWER_CTRL(ctrl)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Power on slot */
|
2009-09-15 15:30:48 +07:00
|
|
|
retval = pciehp_power_on_slot(p_slot);
|
2006-12-22 08:01:09 +07:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2007-08-10 06:09:36 +07:00
|
|
|
|
2013-12-16 07:23:54 +07:00
|
|
|
pciehp_green_led_blink(p_slot);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-12-22 08:01:09 +07:00
|
|
|
/* Check link training status */
|
2009-09-15 15:30:48 +07:00
|
|
|
retval = pciehp_check_link_status(ctrl);
|
2006-12-22 08:01:09 +07:00
|
|
|
if (retval) {
|
2008-10-23 09:47:32 +07:00
|
|
|
ctrl_err(ctrl, "Failed to check link status\n");
|
2009-11-13 13:14:10 +07:00
|
|
|
goto err_exit;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for a power fault */
|
2009-11-13 13:14:10 +07:00
|
|
|
if (ctrl->power_fault_detected || pciehp_query_power_fault(p_slot)) {
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_err(ctrl, "Slot(%s): Power fault\n", slot_name(p_slot));
|
2009-09-15 15:33:30 +07:00
|
|
|
retval = -EIO;
|
2005-11-01 07:20:06 +07:00
|
|
|
goto err_exit;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-12-22 08:01:09 +07:00
|
|
|
retval = pciehp_configure_device(p_slot);
|
|
|
|
if (retval) {
|
2009-09-15 15:26:56 +07:00
|
|
|
ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n",
|
|
|
|
pci_domain_nr(parent), parent->number);
|
2014-02-12 07:36:51 +07:00
|
|
|
if (retval != -EEXIST)
|
|
|
|
goto err_exit;
|
2005-11-01 07:20:06 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-12-16 07:23:54 +07:00
|
|
|
pciehp_green_led_on(p_slot);
|
2016-08-04 06:29:45 +07:00
|
|
|
pciehp_set_attention_status(p_slot, 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
2005-11-01 07:20:06 +07:00
|
|
|
|
|
|
|
err_exit:
|
|
|
|
set_slot_off(ctrl, p_slot);
|
2006-12-22 08:01:09 +07:00
|
|
|
return retval;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-29 00:04:30 +07:00
|
|
|
* remove_board - Turns off slot and LEDs
|
|
|
|
* @p_slot: slot where board is being removed
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2005-11-01 07:20:09 +07:00
|
|
|
static int remove_board(struct slot *p_slot)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-12-15 03:06:16 +07:00
|
|
|
int retval;
|
2005-11-01 07:20:08 +07:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-12-22 08:01:09 +07:00
|
|
|
retval = pciehp_unconfigure_device(p_slot);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-04-26 04:39:06 +07:00
|
|
|
if (POWER_CTRL(ctrl)) {
|
2013-12-15 03:06:16 +07:00
|
|
|
pciehp_power_off_slot(p_slot);
|
|
|
|
|
2008-10-24 12:26:35 +07: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 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-09-15 15:30:48 +07:00
|
|
|
/* turn off Green LED */
|
2013-12-16 07:23:54 +07:00
|
|
|
pciehp_green_led_off(p_slot);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-07 06:02:26 +07:00
|
|
|
struct power_work_info {
|
|
|
|
struct slot *p_slot;
|
|
|
|
struct work_struct work;
|
2014-02-05 09:30:56 +07:00
|
|
|
unsigned int req;
|
|
|
|
#define DISABLE_REQ 0
|
|
|
|
#define ENABLE_REQ 1
|
2007-03-07 06:02:26 +07:00
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
2007-11-29 00:04:30 +07:00
|
|
|
* pciehp_power_thread - handle pushbutton events
|
|
|
|
* @work: &struct work_struct describing work to be done
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2007-11-29 00:04:30 +07:00
|
|
|
* Scheduled procedure to handle blocking stuff for the pushbuttons.
|
2005-04-17 05:20:36 +07:00
|
|
|
* Handles all pending events and exits.
|
|
|
|
*/
|
2007-03-07 06:02:26 +07:00
|
|
|
static void pciehp_power_thread(struct work_struct *work)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-03-07 06:02:26 +07:00
|
|
|
struct power_work_info *info =
|
|
|
|
container_of(work, struct power_work_info, work);
|
|
|
|
struct slot *p_slot = info->p_slot;
|
2014-02-05 09:31:11 +07:00
|
|
|
int ret;
|
2007-03-07 06:02:26 +07:00
|
|
|
|
2014-02-05 09:30:56 +07:00
|
|
|
switch (info->req) {
|
|
|
|
case DISABLE_REQ:
|
2014-02-05 09:31:11 +07:00
|
|
|
mutex_lock(&p_slot->hotplug_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
pciehp_disable_slot(p_slot);
|
2014-02-05 09:31:11 +07:00
|
|
|
mutex_unlock(&p_slot->hotplug_lock);
|
2007-03-07 06:02:26 +07:00
|
|
|
mutex_lock(&p_slot->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
p_slot->state = STATIC_STATE;
|
2007-03-07 06:02:26 +07:00
|
|
|
mutex_unlock(&p_slot->lock);
|
2014-02-05 09:30:56 +07:00
|
|
|
break;
|
|
|
|
case ENABLE_REQ:
|
2014-02-05 09:31:11 +07:00
|
|
|
mutex_lock(&p_slot->hotplug_lock);
|
|
|
|
ret = pciehp_enable_slot(p_slot);
|
|
|
|
mutex_unlock(&p_slot->hotplug_lock);
|
|
|
|
if (ret)
|
2009-09-15 15:30:48 +07:00
|
|
|
pciehp_green_led_off(p_slot);
|
2007-03-07 06:02:26 +07:00
|
|
|
mutex_lock(&p_slot->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
p_slot->state = STATIC_STATE;
|
2014-02-05 09:30:56 +07:00
|
|
|
mutex_unlock(&p_slot->lock);
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-03-07 06:02:26 +07:00
|
|
|
kfree(info);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:10:12 +07:00
|
|
|
static void pciehp_queue_power_work(struct slot *p_slot, int req)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-03-07 06:02:26 +07:00
|
|
|
struct power_work_info *info;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-10-13 02:10:12 +07:00
|
|
|
p_slot->state = (req == ENABLE_REQ) ? POWERON_STATE : POWEROFF_STATE;
|
|
|
|
|
2007-03-07 06:02:26 +07:00
|
|
|
info = kmalloc(sizeof(*info), GFP_KERNEL);
|
|
|
|
if (!info) {
|
2015-10-13 02:10:12 +07:00
|
|
|
ctrl_err(p_slot->ctrl, "no memory to queue %s request\n",
|
|
|
|
(req == ENABLE_REQ) ? "poweron" : "poweroff");
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
}
|
2007-03-07 06:02:26 +07:00
|
|
|
info->p_slot = p_slot;
|
|
|
|
INIT_WORK(&info->work, pciehp_power_thread);
|
2015-10-13 02:10:12 +07:00
|
|
|
info->req = req;
|
|
|
|
queue_work(p_slot->wq, &info->work);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pciehp_queue_pushbutton_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct slot *p_slot = container_of(work, struct slot, work.work);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-03-07 06:02:26 +07:00
|
|
|
mutex_lock(&p_slot->lock);
|
|
|
|
switch (p_slot->state) {
|
|
|
|
case BLINKINGOFF_STATE:
|
2015-10-13 02:10:12 +07:00
|
|
|
pciehp_queue_power_work(p_slot, DISABLE_REQ);
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
case BLINKINGON_STATE:
|
2015-10-13 02:10:12 +07:00
|
|
|
pciehp_queue_power_work(p_slot, ENABLE_REQ);
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-13 02:10:12 +07:00
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2007-03-07 06:02:26 +07:00
|
|
|
mutex_unlock(&p_slot->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-03-07 06:02:26 +07:00
|
|
|
/*
|
|
|
|
* Note: This function must be called with slot->lock held
|
|
|
|
*/
|
|
|
|
static void handle_button_press_event(struct slot *p_slot)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-03-07 06:02:26 +07:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2005-04-17 05:20:36 +07:00
|
|
|
u8 getstatus;
|
|
|
|
|
2007-03-07 06:02:26 +07:00
|
|
|
switch (p_slot->state) {
|
|
|
|
case STATIC_STATE:
|
2009-09-15 15:30:48 +07:00
|
|
|
pciehp_get_power_status(p_slot, &getstatus);
|
2007-03-07 06:02:26 +07:00
|
|
|
if (getstatus) {
|
|
|
|
p_slot->state = BLINKINGOFF_STATE;
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Powering off due to button press\n",
|
2014-04-19 07:13:50 +07:00
|
|
|
slot_name(p_slot));
|
2007-03-07 06:02:26 +07:00
|
|
|
} else {
|
|
|
|
p_slot->state = BLINKINGON_STATE;
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s) Powering on due to button press\n",
|
2014-04-19 07:13:50 +07:00
|
|
|
slot_name(p_slot));
|
2007-03-07 06:02:26 +07:00
|
|
|
}
|
|
|
|
/* blink green LED and turn off amber */
|
2013-12-16 07:23:54 +07:00
|
|
|
pciehp_green_led_blink(p_slot);
|
|
|
|
pciehp_set_attention_status(p_slot, 0);
|
2013-01-11 09:15:54 +07:00
|
|
|
queue_delayed_work(p_slot->wq, &p_slot->work, 5*HZ);
|
2007-03-07 06:02:26 +07: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 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Button cancel\n", slot_name(p_slot));
|
2007-03-07 06:02:26 +07:00
|
|
|
cancel_delayed_work(&p_slot->work);
|
2014-02-12 05:26:29 +07:00
|
|
|
if (p_slot->state == BLINKINGOFF_STATE)
|
2013-12-16 07:23:54 +07:00
|
|
|
pciehp_green_led_on(p_slot);
|
2014-02-12 05:26:29 +07:00
|
|
|
else
|
2013-12-16 07:23:54 +07:00
|
|
|
pciehp_green_led_off(p_slot);
|
|
|
|
pciehp_set_attention_status(p_slot, 0);
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Action canceled due to button press\n",
|
2014-04-19 07:13:50 +07:00
|
|
|
slot_name(p_slot));
|
2007-03-07 06:02:26 +07:00
|
|
|
p_slot->state = STATIC_STATE;
|
|
|
|
break;
|
|
|
|
case POWEROFF_STATE:
|
|
|
|
case POWERON_STATE:
|
|
|
|
/*
|
|
|
|
* Ignore if the slot is on power-on or power-off state;
|
|
|
|
* this means that the previous attention button action
|
|
|
|
* to hot-add or hot-remove is undergoing
|
|
|
|
*/
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Button ignored\n",
|
|
|
|
slot_name(p_slot));
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_err(ctrl, "Slot(%s): Ignoring invalid state %#x\n",
|
|
|
|
slot_name(p_slot), p_slot->state);
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-05 09:29:10 +07:00
|
|
|
/*
|
|
|
|
* Note: This function must be called with slot->lock held
|
|
|
|
*/
|
|
|
|
static void handle_link_event(struct slot *p_slot, u32 event)
|
|
|
|
{
|
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
|
|
|
|
|
|
|
switch (p_slot->state) {
|
|
|
|
case BLINKINGON_STATE:
|
|
|
|
case BLINKINGOFF_STATE:
|
|
|
|
cancel_delayed_work(&p_slot->work);
|
|
|
|
/* Fall through */
|
|
|
|
case STATIC_STATE:
|
2015-10-13 02:10:12 +07:00
|
|
|
pciehp_queue_power_work(p_slot, event == INT_LINK_UP ?
|
|
|
|
ENABLE_REQ : DISABLE_REQ);
|
2014-02-05 09:29:10 +07:00
|
|
|
break;
|
|
|
|
case POWERON_STATE:
|
|
|
|
if (event == INT_LINK_UP) {
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Link Up event ignored; already powering on\n",
|
2014-02-05 09:29:10 +07:00
|
|
|
slot_name(p_slot));
|
|
|
|
} else {
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Link Down event queued; currently getting powered on\n",
|
2014-02-05 09:29:10 +07:00
|
|
|
slot_name(p_slot));
|
2015-10-13 02:10:12 +07:00
|
|
|
pciehp_queue_power_work(p_slot, DISABLE_REQ);
|
2014-02-05 09:29:10 +07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case POWEROFF_STATE:
|
|
|
|
if (event == INT_LINK_UP) {
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Link Up event queued; currently getting powered off\n",
|
2014-02-05 09:29:10 +07:00
|
|
|
slot_name(p_slot));
|
2015-10-13 02:10:12 +07:00
|
|
|
pciehp_queue_power_work(p_slot, ENABLE_REQ);
|
2014-02-05 09:29:10 +07:00
|
|
|
} else {
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Link Down event ignored; already powering off\n",
|
2014-02-05 09:29:10 +07:00
|
|
|
slot_name(p_slot));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_err(ctrl, "Slot(%s): Ignoring invalid state %#x\n",
|
|
|
|
slot_name(p_slot), p_slot->state);
|
2014-02-05 09:29:10 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 06:02:26 +07:00
|
|
|
static void interrupt_event_handler(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct event_info *info = container_of(work, struct event_info, work);
|
|
|
|
struct slot *p_slot = info->p_slot;
|
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
|
|
|
|
|
|
|
mutex_lock(&p_slot->lock);
|
|
|
|
switch (info->event_type) {
|
|
|
|
case INT_BUTTON_PRESS:
|
|
|
|
handle_button_press_event(p_slot);
|
|
|
|
break;
|
|
|
|
case INT_POWER_FAULT:
|
2008-04-26 04:39:06 +07:00
|
|
|
if (!POWER_CTRL(ctrl))
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
2013-12-16 07:23:54 +07:00
|
|
|
pciehp_set_attention_status(p_slot, 1);
|
|
|
|
pciehp_green_led_off(p_slot);
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
case INT_PRESENCE_ON:
|
2016-08-23 15:58:51 +07:00
|
|
|
pciehp_queue_power_work(p_slot, ENABLE_REQ);
|
2014-02-19 09:53:19 +07:00
|
|
|
break;
|
|
|
|
case INT_PRESENCE_OFF:
|
|
|
|
/*
|
|
|
|
* Regardless of surprise capability, we need to
|
|
|
|
* definitely remove a card that has been pulled out!
|
|
|
|
*/
|
2016-08-23 15:58:51 +07:00
|
|
|
pciehp_queue_power_work(p_slot, DISABLE_REQ);
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
2014-02-05 09:29:10 +07:00
|
|
|
case INT_LINK_UP:
|
|
|
|
case INT_LINK_DOWN:
|
|
|
|
handle_link_event(p_slot, info->event_type);
|
|
|
|
break;
|
2007-03-07 06:02:26 +07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&p_slot->lock);
|
|
|
|
|
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
|
2014-02-05 09:31:11 +07:00
|
|
|
/*
|
|
|
|
* Note: This function must be called with slot->hotplug_lock held
|
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
int pciehp_enable_slot(struct slot *p_slot)
|
|
|
|
{
|
|
|
|
u8 getstatus = 0;
|
2008-09-05 10:11:26 +07:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-12-15 03:06:16 +07:00
|
|
|
pciehp_get_adapter_status(p_slot, &getstatus);
|
|
|
|
if (!getstatus) {
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): No adapter\n", slot_name(p_slot));
|
2006-09-20 07:04:33 +07:00
|
|
|
return -ENODEV;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2008-04-26 04:39:06 +07:00
|
|
|
if (MRL_SENS(p_slot->ctrl)) {
|
2013-12-15 03:06:16 +07:00
|
|
|
pciehp_get_latch_status(p_slot, &getstatus);
|
|
|
|
if (getstatus) {
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Latch open\n",
|
2008-10-23 09:47:32 +07:00
|
|
|
slot_name(p_slot));
|
2006-09-20 07:04:33 +07:00
|
|
|
return -ENODEV;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
2007-08-10 06:09:36 +07:00
|
|
|
|
2008-04-26 04:39:06 +07:00
|
|
|
if (POWER_CTRL(p_slot->ctrl)) {
|
2013-12-15 03:06:16 +07:00
|
|
|
pciehp_get_power_status(p_slot, &getstatus);
|
|
|
|
if (getstatus) {
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already enabled\n",
|
2008-10-23 09:47:32 +07:00
|
|
|
slot_name(p_slot));
|
2016-11-19 15:32:46 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 05:50:30 +07:00
|
|
|
return board_added(p_slot);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2014-02-05 09:31:11 +07:00
|
|
|
/*
|
|
|
|
* Note: This function must be called with slot->hotplug_lock held
|
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
int pciehp_disable_slot(struct slot *p_slot)
|
|
|
|
{
|
|
|
|
u8 getstatus = 0;
|
2008-09-05 10:11:26 +07:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (!p_slot->ctrl)
|
|
|
|
return 1;
|
|
|
|
|
2008-04-26 04:39:06 +07:00
|
|
|
if (POWER_CTRL(p_slot->ctrl)) {
|
2013-12-15 03:06:16 +07:00
|
|
|
pciehp_get_power_status(p_slot, &getstatus);
|
|
|
|
if (!getstatus) {
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already disabled\n",
|
2008-10-23 09:47:32 +07:00
|
|
|
slot_name(p_slot));
|
2006-09-20 07:04:33 +07:00
|
|
|
return -EINVAL;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 15:42:59 +07:00
|
|
|
return remove_board(p_slot);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-03-07 06:02:26 +07:00
|
|
|
int pciehp_sysfs_enable_slot(struct slot *p_slot)
|
|
|
|
{
|
|
|
|
int retval = -ENODEV;
|
2008-09-05 10:11:26 +07:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2007-03-07 06:02:26 +07:00
|
|
|
|
|
|
|
mutex_lock(&p_slot->lock);
|
|
|
|
switch (p_slot->state) {
|
|
|
|
case BLINKINGON_STATE:
|
|
|
|
cancel_delayed_work(&p_slot->work);
|
|
|
|
case STATIC_STATE:
|
|
|
|
p_slot->state = POWERON_STATE;
|
|
|
|
mutex_unlock(&p_slot->lock);
|
2014-02-05 09:31:11 +07:00
|
|
|
mutex_lock(&p_slot->hotplug_lock);
|
2007-03-07 06:02:26 +07:00
|
|
|
retval = pciehp_enable_slot(p_slot);
|
2014-02-05 09:31:11 +07:00
|
|
|
mutex_unlock(&p_slot->hotplug_lock);
|
2007-03-07 06:02:26 +07:00
|
|
|
mutex_lock(&p_slot->lock);
|
|
|
|
p_slot->state = STATIC_STATE;
|
|
|
|
break;
|
|
|
|
case POWERON_STATE:
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already in powering on state\n",
|
2008-10-21 06:41:38 +07:00
|
|
|
slot_name(p_slot));
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
case BLINKINGOFF_STATE:
|
|
|
|
case POWEROFF_STATE:
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already enabled\n",
|
2008-10-21 06:41:38 +07:00
|
|
|
slot_name(p_slot));
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n",
|
|
|
|
slot_name(p_slot), p_slot->state);
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&p_slot->lock);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pciehp_sysfs_disable_slot(struct slot *p_slot)
|
|
|
|
{
|
|
|
|
int retval = -ENODEV;
|
2008-09-05 10:11:26 +07:00
|
|
|
struct controller *ctrl = p_slot->ctrl;
|
2007-03-07 06:02:26 +07:00
|
|
|
|
|
|
|
mutex_lock(&p_slot->lock);
|
|
|
|
switch (p_slot->state) {
|
|
|
|
case BLINKINGOFF_STATE:
|
|
|
|
cancel_delayed_work(&p_slot->work);
|
|
|
|
case STATIC_STATE:
|
|
|
|
p_slot->state = POWEROFF_STATE;
|
|
|
|
mutex_unlock(&p_slot->lock);
|
2015-11-02 04:58:40 +07:00
|
|
|
mutex_lock(&p_slot->hotplug_lock);
|
2007-03-07 06:02:26 +07:00
|
|
|
retval = pciehp_disable_slot(p_slot);
|
2015-11-02 04:58:40 +07:00
|
|
|
mutex_unlock(&p_slot->hotplug_lock);
|
2007-03-07 06:02:26 +07:00
|
|
|
mutex_lock(&p_slot->lock);
|
|
|
|
p_slot->state = STATIC_STATE;
|
|
|
|
break;
|
|
|
|
case POWEROFF_STATE:
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already in powering off state\n",
|
2008-10-21 06:41:38 +07:00
|
|
|
slot_name(p_slot));
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
case BLINKINGON_STATE:
|
|
|
|
case POWERON_STATE:
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_info(ctrl, "Slot(%s): Already disabled\n",
|
2008-10-21 06:41:38 +07:00
|
|
|
slot_name(p_slot));
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-09 03:19:58 +07:00
|
|
|
ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n",
|
|
|
|
slot_name(p_slot), p_slot->state);
|
2007-03-07 06:02:26 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&p_slot->lock);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|