2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* CompactPCI Hot Plug Driver
|
|
|
|
*
|
2005-05-27 22:48:52 +02:00
|
|
|
* Copyright (C) 2002,2005 SOMA Networks, Inc.
|
2005-04-17 00:20:36 +02:00
|
|
|
* Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
|
|
|
|
* Copyright (C) 2001 IBM Corp.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Send feedback to <scottm@somanetworks.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/pci.h>
|
2006-10-14 05:05:19 +02:00
|
|
|
#include <linux/pci_hotplug.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
2005-05-09 23:31:50 +02:00
|
|
|
#include <asm/atomic.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/delay.h>
|
2007-07-09 20:55:57 +02:00
|
|
|
#include <linux/kthread.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "cpci_hotplug.h"
|
|
|
|
|
|
|
|
#define DRIVER_AUTHOR "Scott Murray <scottm@somanetworks.com>"
|
|
|
|
#define DRIVER_DESC "CompactPCI Hot Plug Core"
|
|
|
|
|
|
|
|
#define MY_NAME "cpci_hotplug"
|
|
|
|
|
|
|
|
#define dbg(format, arg...) \
|
|
|
|
do { \
|
2005-05-27 22:48:52 +02:00
|
|
|
if (cpci_debug) \
|
2005-04-17 00:20:36 +02:00
|
|
|
printk (KERN_DEBUG "%s: " format "\n", \
|
|
|
|
MY_NAME , ## arg); \
|
2005-05-27 22:48:52 +02:00
|
|
|
} while (0)
|
2005-04-17 00:20:36 +02:00
|
|
|
#define err(format, arg...) printk(KERN_ERR "%s: " format "\n", MY_NAME , ## arg)
|
|
|
|
#define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME , ## arg)
|
|
|
|
#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME , ## arg)
|
|
|
|
|
|
|
|
/* local variables */
|
2005-05-09 23:31:50 +02:00
|
|
|
static DECLARE_RWSEM(list_rwsem);
|
2005-04-17 00:20:36 +02:00
|
|
|
static LIST_HEAD(slot_list);
|
|
|
|
static int slots;
|
2005-05-09 23:31:50 +02:00
|
|
|
static atomic_t extracting;
|
2005-04-17 00:20:36 +02:00
|
|
|
int cpci_debug;
|
|
|
|
static struct cpci_hp_controller *controller;
|
2007-07-09 20:55:57 +02:00
|
|
|
static struct task_struct *cpci_thread;
|
|
|
|
static int thread_finished;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
static int enable_slot(struct hotplug_slot *slot);
|
|
|
|
static int disable_slot(struct hotplug_slot *slot);
|
|
|
|
static int set_attention_status(struct hotplug_slot *slot, u8 value);
|
|
|
|
static int get_power_status(struct hotplug_slot *slot, u8 * value);
|
|
|
|
static int get_attention_status(struct hotplug_slot *slot, u8 * value);
|
2005-05-09 23:31:50 +02:00
|
|
|
static int get_adapter_status(struct hotplug_slot *slot, u8 * value);
|
|
|
|
static int get_latch_status(struct hotplug_slot *slot, u8 * value);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
static struct hotplug_slot_ops cpci_hotplug_slot_ops = {
|
|
|
|
.enable_slot = enable_slot,
|
|
|
|
.disable_slot = disable_slot,
|
|
|
|
.set_attention_status = set_attention_status,
|
|
|
|
.get_power_status = get_power_status,
|
|
|
|
.get_attention_status = get_attention_status,
|
2005-05-09 23:31:50 +02:00
|
|
|
.get_adapter_status = get_adapter_status,
|
|
|
|
.get_latch_status = get_latch_status,
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
update_latch_status(struct hotplug_slot *hotplug_slot, u8 value)
|
|
|
|
{
|
|
|
|
struct hotplug_slot_info info;
|
|
|
|
|
|
|
|
memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info));
|
|
|
|
info.latch_status = value;
|
|
|
|
return pci_hp_change_slot_info(hotplug_slot, &info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
update_adapter_status(struct hotplug_slot *hotplug_slot, u8 value)
|
|
|
|
{
|
|
|
|
struct hotplug_slot_info info;
|
|
|
|
|
|
|
|
memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info));
|
|
|
|
info.adapter_status = value;
|
|
|
|
return pci_hp_change_slot_info(hotplug_slot, &info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
enable_slot(struct hotplug_slot *hotplug_slot)
|
|
|
|
{
|
|
|
|
struct slot *slot = hotplug_slot->private;
|
|
|
|
int retval = 0;
|
|
|
|
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("%s - physical_slot = %s", __func__, slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller->ops->set_power)
|
2005-04-17 00:20:36 +02:00
|
|
|
retval = controller->ops->set_power(slot, 1);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
disable_slot(struct hotplug_slot *hotplug_slot)
|
|
|
|
{
|
|
|
|
struct slot *slot = hotplug_slot->private;
|
|
|
|
int retval = 0;
|
|
|
|
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("%s - physical_slot = %s", __func__, slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
down_write(&list_rwsem);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Unconfigure device */
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("%s - unconfiguring slot %s", __func__, slot_name(slot));
|
2005-05-27 22:48:52 +02:00
|
|
|
if ((retval = cpci_unconfigure_slot(slot))) {
|
2005-04-17 00:20:36 +02:00
|
|
|
err("%s - could not unconfigure slot %s",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot));
|
2005-05-27 22:48:52 +02:00
|
|
|
goto disable_error;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("%s - finished unconfiguring slot %s", __func__, slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Clear EXT (by setting it) */
|
2005-05-27 22:48:52 +02:00
|
|
|
if (cpci_clear_ext(slot)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
err("%s - could not clear EXT for slot %s",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
retval = -ENODEV;
|
2005-05-27 22:48:52 +02:00
|
|
|
goto disable_error;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
cpci_led_on(slot);
|
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller->ops->set_power)
|
|
|
|
if ((retval = controller->ops->set_power(slot, 0)))
|
|
|
|
goto disable_error;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (update_adapter_status(slot->hotplug_slot, 0))
|
2005-04-17 00:20:36 +02:00
|
|
|
warn("failure to update adapter file");
|
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (slot->extracting) {
|
2005-05-09 23:31:50 +02:00
|
|
|
slot->extracting = 0;
|
|
|
|
atomic_dec(&extracting);
|
|
|
|
}
|
2005-05-27 22:48:52 +02:00
|
|
|
disable_error:
|
|
|
|
up_write(&list_rwsem);
|
2005-04-17 00:20:36 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8
|
|
|
|
cpci_get_power_status(struct slot *slot)
|
|
|
|
{
|
|
|
|
u8 power = 1;
|
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller->ops->get_power)
|
2005-04-17 00:20:36 +02:00
|
|
|
power = controller->ops->get_power(slot);
|
|
|
|
return power;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_power_status(struct hotplug_slot *hotplug_slot, u8 * value)
|
|
|
|
{
|
|
|
|
struct slot *slot = hotplug_slot->private;
|
|
|
|
|
|
|
|
*value = cpci_get_power_status(slot);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_attention_status(struct hotplug_slot *hotplug_slot, u8 * value)
|
|
|
|
{
|
|
|
|
struct slot *slot = hotplug_slot->private;
|
|
|
|
|
|
|
|
*value = cpci_get_attention_status(slot);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
|
|
|
|
{
|
|
|
|
return cpci_set_attention_status(hotplug_slot->private, status);
|
|
|
|
}
|
|
|
|
|
2005-05-09 23:31:50 +02:00
|
|
|
static int
|
|
|
|
get_adapter_status(struct hotplug_slot *hotplug_slot, u8 * value)
|
|
|
|
{
|
|
|
|
*value = hotplug_slot->info->adapter_status;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_latch_status(struct hotplug_slot *hotplug_slot, u8 * value)
|
|
|
|
{
|
|
|
|
*value = hotplug_slot->info->latch_status;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
static void release_slot(struct hotplug_slot *hotplug_slot)
|
|
|
|
{
|
|
|
|
struct slot *slot = hotplug_slot->private;
|
|
|
|
|
|
|
|
kfree(slot->hotplug_slot->info);
|
|
|
|
kfree(slot->hotplug_slot);
|
2005-06-06 21:48:04 +02:00
|
|
|
if (slot->dev)
|
|
|
|
pci_dev_put(slot->dev);
|
2005-04-17 00:20:36 +02:00
|
|
|
kfree(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SLOT_NAME_SIZE 6
|
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
|
|
|
|
{
|
|
|
|
struct slot *slot;
|
|
|
|
struct hotplug_slot *hotplug_slot;
|
|
|
|
struct hotplug_slot_info *info;
|
2008-10-21 01:41:17 +02:00
|
|
|
char name[SLOT_NAME_SIZE];
|
2005-04-17 00:20:36 +02:00
|
|
|
int status = -ENOMEM;
|
|
|
|
int i;
|
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (!(controller && bus))
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a structure for each slot, and register that slot
|
|
|
|
* with the pci_hotplug subsystem.
|
|
|
|
*/
|
|
|
|
for (i = first; i <= last; ++i) {
|
2006-02-28 15:34:49 +01:00
|
|
|
slot = kzalloc(sizeof (struct slot), GFP_KERNEL);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!slot)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
hotplug_slot =
|
2006-02-28 15:34:49 +01:00
|
|
|
kzalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!hotplug_slot)
|
|
|
|
goto error_slot;
|
|
|
|
slot->hotplug_slot = hotplug_slot;
|
|
|
|
|
2006-02-28 15:34:49 +01:00
|
|
|
info = kzalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!info)
|
|
|
|
goto error_hpslot;
|
|
|
|
hotplug_slot->info = info;
|
|
|
|
|
|
|
|
slot->bus = bus;
|
|
|
|
slot->number = i;
|
|
|
|
slot->devfn = PCI_DEVFN(i, 0);
|
|
|
|
|
2008-10-21 01:41:17 +02:00
|
|
|
snprintf(name, SLOT_NAME_SIZE, "%02x:%02x", bus->number, i);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
hotplug_slot->private = slot;
|
|
|
|
hotplug_slot->release = &release_slot;
|
|
|
|
hotplug_slot->ops = &cpci_hotplug_slot_ops;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the slot info structure with some known
|
|
|
|
* good values.
|
|
|
|
*/
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("initializing slot %s", name);
|
2005-04-17 00:20:36 +02:00
|
|
|
info->power_status = cpci_get_power_status(slot);
|
|
|
|
info->attention_status = cpci_get_attention_status(slot);
|
|
|
|
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("registering slot %s", name);
|
|
|
|
status = pci_hp_register(slot->hotplug_slot, bus, i, name);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (status) {
|
|
|
|
err("pci_hp_register failed with error %d", status);
|
2008-10-21 01:41:17 +02:00
|
|
|
goto error_info;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("slot registered with name: %s", slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Add slot to our internal list */
|
2005-05-09 23:31:50 +02:00
|
|
|
down_write(&list_rwsem);
|
2005-04-17 00:20:36 +02:00
|
|
|
list_add(&slot->slot_list, &slot_list);
|
|
|
|
slots++;
|
2005-05-09 23:31:50 +02:00
|
|
|
up_write(&list_rwsem);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
error_info:
|
|
|
|
kfree(info);
|
|
|
|
error_hpslot:
|
|
|
|
kfree(hotplug_slot);
|
|
|
|
error_slot:
|
|
|
|
kfree(slot);
|
|
|
|
error:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_unregister_bus(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
struct slot *slot;
|
2005-05-27 22:48:52 +02:00
|
|
|
struct slot *tmp;
|
|
|
|
int status = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-09 23:31:50 +02:00
|
|
|
down_write(&list_rwsem);
|
2005-05-27 22:48:52 +02:00
|
|
|
if (!slots) {
|
2005-05-09 23:31:50 +02:00
|
|
|
up_write(&list_rwsem);
|
2005-04-17 00:20:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2005-05-27 22:48:52 +02:00
|
|
|
list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) {
|
|
|
|
if (slot->bus == bus) {
|
|
|
|
list_del(&slot->slot_list);
|
|
|
|
slots--;
|
|
|
|
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("deregistering slot %s", slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
status = pci_hp_deregister(slot->hotplug_slot);
|
2005-05-27 22:48:52 +02:00
|
|
|
if (status) {
|
2005-04-17 00:20:36 +02:00
|
|
|
err("pci_hp_deregister failed with error %d",
|
|
|
|
status);
|
2005-05-27 22:48:52 +02:00
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-05-09 23:31:50 +02:00
|
|
|
up_write(&list_rwsem);
|
2005-05-27 22:48:52 +02:00
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the interrupt mode interrupt handler */
|
|
|
|
static irqreturn_t
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 15:55:46 +02:00
|
|
|
cpci_hp_intr(int irq, void *data)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
dbg("entered cpci_hp_intr");
|
|
|
|
|
|
|
|
/* Check to see if it was our interrupt */
|
2006-07-02 04:29:41 +02:00
|
|
|
if ((controller->irq_flags & IRQF_SHARED) &&
|
2005-04-17 00:20:36 +02:00
|
|
|
!controller->ops->check_irq(controller->dev_id)) {
|
|
|
|
dbg("exited cpci_hp_intr, not our interrupt");
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable ENUM interrupt */
|
|
|
|
controller->ops->disable_irq();
|
|
|
|
|
|
|
|
/* Trigger processing by the event thread */
|
2007-07-09 20:55:57 +02:00
|
|
|
wake_up_process(cpci_thread);
|
2005-04-17 00:20:36 +02:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-05-09 23:31:50 +02:00
|
|
|
* According to PICMG 2.1 R2.0, section 6.3.2, upon
|
2005-04-17 00:20:36 +02:00
|
|
|
* initialization, the system driver shall clear the
|
|
|
|
* INS bits of the cold-inserted devices.
|
|
|
|
*/
|
|
|
|
static int
|
2005-05-27 22:48:52 +02:00
|
|
|
init_slots(int clear_ins)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct slot *slot;
|
|
|
|
struct pci_dev* dev;
|
|
|
|
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - enter", __func__);
|
2005-05-09 23:31:50 +02:00
|
|
|
down_read(&list_rwsem);
|
2005-05-27 22:48:52 +02:00
|
|
|
if (!slots) {
|
2005-05-09 23:31:50 +02:00
|
|
|
up_read(&list_rwsem);
|
2005-04-17 00:20:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2005-05-27 22:48:52 +02:00
|
|
|
list_for_each_entry(slot, &slot_list, slot_list) {
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("%s - looking at slot %s", __func__, slot_name(slot));
|
2005-05-27 22:48:52 +02:00
|
|
|
if (clear_ins && cpci_check_and_clear_ins(slot))
|
2005-04-17 00:20:36 +02:00
|
|
|
dbg("%s - cleared INS for slot %s",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot));
|
2005-05-27 22:48:52 +02:00
|
|
|
dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0));
|
|
|
|
if (dev) {
|
|
|
|
if (update_adapter_status(slot->hotplug_slot, 1))
|
|
|
|
warn("failure to update adapter file");
|
|
|
|
if (update_latch_status(slot->hotplug_slot, 1))
|
|
|
|
warn("failure to update latch file");
|
|
|
|
slot->dev = dev;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
2005-05-09 23:31:50 +02:00
|
|
|
up_read(&list_rwsem);
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - exit", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
check_slots(void)
|
|
|
|
{
|
|
|
|
struct slot *slot;
|
|
|
|
int extracted;
|
|
|
|
int inserted;
|
2005-05-09 23:31:50 +02:00
|
|
|
u16 hs_csr;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-09 23:31:50 +02:00
|
|
|
down_read(&list_rwsem);
|
2005-05-27 22:48:52 +02:00
|
|
|
if (!slots) {
|
2005-05-09 23:31:50 +02:00
|
|
|
up_read(&list_rwsem);
|
2005-04-17 00:20:36 +02:00
|
|
|
err("no slots registered, shutting down");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
extracted = inserted = 0;
|
2005-05-27 22:48:52 +02:00
|
|
|
list_for_each_entry(slot, &slot_list, slot_list) {
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("%s - looking at slot %s", __func__, slot_name(slot));
|
2005-05-27 22:48:52 +02:00
|
|
|
if (cpci_check_and_clear_ins(slot)) {
|
|
|
|
/*
|
|
|
|
* Some broken hardware (e.g. PLX 9054AB) asserts
|
|
|
|
* ENUM# twice...
|
|
|
|
*/
|
|
|
|
if (slot->dev) {
|
|
|
|
warn("slot %s already inserted",
|
2008-10-21 01:41:17 +02:00
|
|
|
slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
inserted++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process insertion */
|
2008-10-21 01:41:17 +02:00
|
|
|
dbg("%s - slot %s inserted", __func__, slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* GSM, debug */
|
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
|
|
|
dbg("%s - slot %s HS_CSR (1) = %04x",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot), hs_csr);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Configure device */
|
|
|
|
dbg("%s - configuring slot %s",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot));
|
2005-05-27 22:48:52 +02:00
|
|
|
if (cpci_configure_slot(slot)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
err("%s - could not configure slot %s",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dbg("%s - finished configuring slot %s",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* GSM, debug */
|
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
|
|
|
dbg("%s - slot %s HS_CSR (2) = %04x",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot), hs_csr);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (update_latch_status(slot->hotplug_slot, 1))
|
2005-04-17 00:20:36 +02:00
|
|
|
warn("failure to update latch file");
|
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (update_adapter_status(slot->hotplug_slot, 1))
|
2005-04-17 00:20:36 +02:00
|
|
|
warn("failure to update adapter file");
|
|
|
|
|
|
|
|
cpci_led_off(slot);
|
|
|
|
|
|
|
|
/* GSM, debug */
|
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
|
|
|
dbg("%s - slot %s HS_CSR (3) = %04x",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot), hs_csr);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
inserted++;
|
2005-05-27 22:48:52 +02:00
|
|
|
} else if (cpci_check_ext(slot)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Process extraction request */
|
|
|
|
dbg("%s - slot %s extracted",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* GSM, debug */
|
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
|
|
|
dbg("%s - slot %s HS_CSR = %04x",
|
2008-10-21 01:41:17 +02:00
|
|
|
__func__, slot_name(slot), hs_csr);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (!slot->extracting) {
|
|
|
|
if (update_latch_status(slot->hotplug_slot, 0)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
warn("failure to update latch file");
|
|
|
|
}
|
|
|
|
slot->extracting = 1;
|
2005-05-27 22:48:52 +02:00
|
|
|
atomic_inc(&extracting);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
extracted++;
|
2005-05-27 22:48:52 +02:00
|
|
|
} else if (slot->extracting) {
|
2005-05-09 23:31:50 +02:00
|
|
|
hs_csr = cpci_get_hs_csr(slot);
|
2005-05-27 22:48:52 +02:00
|
|
|
if (hs_csr == 0xffff) {
|
2005-05-09 23:31:50 +02:00
|
|
|
/*
|
|
|
|
* Hmmm, we're likely hosed at this point, should we
|
|
|
|
* bother trying to tell the driver or not?
|
|
|
|
*/
|
|
|
|
err("card in slot %s was improperly removed",
|
2008-10-21 01:41:17 +02:00
|
|
|
slot_name(slot));
|
2005-05-27 22:48:52 +02:00
|
|
|
if (update_adapter_status(slot->hotplug_slot, 0))
|
2005-05-09 23:31:50 +02:00
|
|
|
warn("failure to update adapter file");
|
|
|
|
slot->extracting = 0;
|
|
|
|
atomic_dec(&extracting);
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
2005-05-09 23:31:50 +02:00
|
|
|
up_read(&list_rwsem);
|
|
|
|
dbg("inserted=%d, extracted=%d, extracting=%d",
|
|
|
|
inserted, extracted, atomic_read(&extracting));
|
2005-05-27 22:48:52 +02:00
|
|
|
if (inserted || extracted)
|
2005-04-17 00:20:36 +02:00
|
|
|
return extracted;
|
2005-05-27 22:48:52 +02:00
|
|
|
else if (!atomic_read(&extracting)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
err("cannot find ENUM# source, shutting down");
|
|
|
|
return -1;
|
|
|
|
}
|
2005-05-09 23:31:50 +02:00
|
|
|
return 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the interrupt mode worker thread body */
|
|
|
|
static int
|
|
|
|
event_thread(void *data)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - event thread started", __func__);
|
2005-05-27 22:48:52 +02:00
|
|
|
while (1) {
|
2005-04-17 00:20:36 +02:00
|
|
|
dbg("event thread sleeping");
|
2007-07-09 20:55:57 +02:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
schedule();
|
|
|
|
if (kthread_should_stop())
|
2005-04-17 00:20:36 +02:00
|
|
|
break;
|
2005-05-09 23:31:50 +02:00
|
|
|
do {
|
2005-04-17 00:20:36 +02:00
|
|
|
rc = check_slots();
|
2005-05-09 23:31:50 +02:00
|
|
|
if (rc > 0) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Give userspace a chance to handle extraction */
|
|
|
|
msleep(500);
|
2005-05-09 23:31:50 +02:00
|
|
|
} else if (rc < 0) {
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - error checking slots", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
thread_finished = 1;
|
2007-07-09 20:55:57 +02:00
|
|
|
goto out;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2007-07-09 20:55:57 +02:00
|
|
|
} while (atomic_read(&extracting) && !kthread_should_stop());
|
|
|
|
if (kthread_should_stop())
|
2005-05-27 22:48:52 +02:00
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Re-enable ENUM# interrupt */
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - re-enabling irq", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
controller->ops->enable_irq();
|
|
|
|
}
|
2007-07-09 20:55:57 +02:00
|
|
|
out:
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the polling mode worker thread body */
|
|
|
|
static int
|
|
|
|
poll_thread(void *data)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
while (1) {
|
2007-07-09 20:55:57 +02:00
|
|
|
if (kthread_should_stop() || signal_pending(current))
|
2005-04-17 00:20:36 +02:00
|
|
|
break;
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller->ops->query_enum()) {
|
2005-05-09 23:31:50 +02:00
|
|
|
do {
|
|
|
|
rc = check_slots();
|
2005-05-27 22:48:52 +02:00
|
|
|
if (rc > 0) {
|
2005-05-09 23:31:50 +02:00
|
|
|
/* Give userspace a chance to handle extraction */
|
|
|
|
msleep(500);
|
2005-05-27 22:48:52 +02:00
|
|
|
} else if (rc < 0) {
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - error checking slots", __func__);
|
2005-05-09 23:31:50 +02:00
|
|
|
thread_finished = 1;
|
2007-07-09 20:55:57 +02:00
|
|
|
goto out;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2007-07-09 20:55:57 +02:00
|
|
|
} while (atomic_read(&extracting) && !kthread_should_stop());
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
msleep(100);
|
|
|
|
}
|
2007-07-09 20:55:57 +02:00
|
|
|
out:
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpci_start_thread(void)
|
|
|
|
{
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller->irq)
|
2007-07-09 20:55:57 +02:00
|
|
|
cpci_thread = kthread_run(event_thread, NULL, "cpci_hp_eventd");
|
2005-05-27 22:48:52 +02:00
|
|
|
else
|
2007-07-09 20:55:57 +02:00
|
|
|
cpci_thread = kthread_run(poll_thread, NULL, "cpci_hp_polld");
|
|
|
|
if (IS_ERR(cpci_thread)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
err("Can't start up our thread");
|
2007-07-09 20:55:57 +02:00
|
|
|
return PTR_ERR(cpci_thread);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2007-07-09 20:55:57 +02:00
|
|
|
thread_finished = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cpci_stop_thread(void)
|
|
|
|
{
|
2007-07-09 20:55:57 +02:00
|
|
|
kthread_stop(cpci_thread);
|
2005-04-17 00:20:36 +02:00
|
|
|
thread_finished = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_register_controller(struct cpci_hp_controller *new_controller)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller)
|
|
|
|
return -1;
|
|
|
|
if (!(new_controller && new_controller->ops))
|
|
|
|
return -EINVAL;
|
|
|
|
if (new_controller->irq) {
|
|
|
|
if (!(new_controller->ops->enable_irq &&
|
|
|
|
new_controller->ops->disable_irq))
|
|
|
|
status = -EINVAL;
|
|
|
|
if (request_irq(new_controller->irq,
|
|
|
|
cpci_hp_intr,
|
|
|
|
new_controller->irq_flags,
|
|
|
|
MY_NAME,
|
|
|
|
new_controller->dev_id)) {
|
|
|
|
err("Can't get irq %d for the hotplug cPCI controller",
|
|
|
|
new_controller->irq);
|
|
|
|
status = -ENODEV;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2005-05-27 22:48:52 +02:00
|
|
|
dbg("%s - acquired controller irq %d",
|
2008-03-04 04:09:46 +01:00
|
|
|
__func__, new_controller->irq);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2005-05-27 22:48:52 +02:00
|
|
|
if (!status)
|
|
|
|
controller = new_controller;
|
2005-04-17 00:20:36 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
static void
|
|
|
|
cleanup_slots(void)
|
|
|
|
{
|
|
|
|
struct slot *slot;
|
|
|
|
struct slot *tmp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unregister all of our slots with the pci_hotplug subsystem,
|
|
|
|
* and free up all memory that we had allocated.
|
|
|
|
*/
|
|
|
|
down_write(&list_rwsem);
|
|
|
|
if (!slots)
|
|
|
|
goto cleanup_null;
|
|
|
|
list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) {
|
|
|
|
list_del(&slot->slot_list);
|
|
|
|
pci_hp_deregister(slot->hotplug_slot);
|
|
|
|
}
|
|
|
|
cleanup_null:
|
|
|
|
up_write(&list_rwsem);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
int
|
|
|
|
cpci_hp_unregister_controller(struct cpci_hp_controller *old_controller)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller) {
|
|
|
|
if (!thread_finished)
|
2005-04-17 00:20:36 +02:00
|
|
|
cpci_stop_thread();
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller->irq)
|
2005-04-17 00:20:36 +02:00
|
|
|
free_irq(controller->irq, controller->dev_id);
|
|
|
|
controller = NULL;
|
2005-05-27 22:48:52 +02:00
|
|
|
cleanup_slots();
|
|
|
|
} else
|
2005-04-17 00:20:36 +02:00
|
|
|
status = -ENODEV;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_start(void)
|
|
|
|
{
|
|
|
|
static int first = 1;
|
|
|
|
int status;
|
|
|
|
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - enter", __func__);
|
2005-05-27 22:48:52 +02:00
|
|
|
if (!controller)
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENODEV;
|
|
|
|
|
2005-05-09 23:31:50 +02:00
|
|
|
down_read(&list_rwsem);
|
2005-05-27 22:48:52 +02:00
|
|
|
if (list_empty(&slot_list)) {
|
2005-05-09 23:31:50 +02:00
|
|
|
up_read(&list_rwsem);
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2005-05-09 23:31:50 +02:00
|
|
|
up_read(&list_rwsem);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
status = init_slots(first);
|
|
|
|
if (first)
|
2005-04-17 00:20:36 +02:00
|
|
|
first = 0;
|
2005-05-27 22:48:52 +02:00
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
status = cpci_start_thread();
|
2005-05-27 22:48:52 +02:00
|
|
|
if (status)
|
2005-04-17 00:20:36 +02:00
|
|
|
return status;
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - thread started", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller->irq) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Start enum interrupt processing */
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - enabling irq", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
controller->ops->enable_irq();
|
|
|
|
}
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - exit", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cpci_hp_stop(void)
|
|
|
|
{
|
2005-05-27 22:48:52 +02:00
|
|
|
if (!controller)
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENODEV;
|
2005-05-27 22:48:52 +02:00
|
|
|
if (controller->irq) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Stop enum interrupt processing */
|
2008-03-04 04:09:46 +01:00
|
|
|
dbg("%s - disabling irq", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
controller->ops->disable_irq();
|
|
|
|
}
|
|
|
|
cpci_stop_thread();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init
|
|
|
|
cpci_hotplug_init(int debug)
|
|
|
|
{
|
|
|
|
cpci_debug = debug;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __exit
|
|
|
|
cpci_hotplug_exit(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Clean everything up.
|
|
|
|
*/
|
2005-05-27 22:48:52 +02:00
|
|
|
cpci_hp_stop();
|
|
|
|
cpci_hp_unregister_controller(controller);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_register_controller);
|
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_unregister_controller);
|
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_register_bus);
|
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_unregister_bus);
|
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_start);
|
|
|
|
EXPORT_SYMBOL_GPL(cpci_hp_stop);
|