2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* drivers/s390/cio/device_fsm.c
|
|
|
|
* finite state machine for device handling
|
|
|
|
*
|
2008-07-14 07:58:45 +00:00
|
|
|
* Copyright IBM Corp. 2002,2008
|
2006-01-14 21:21:04 +00:00
|
|
|
* Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
|
2005-04-16 22:20:36 +00:00
|
|
|
* Martin Schwidefsky (schwidefsky@de.ibm.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
2005-10-30 23:03:48 +00:00
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/string.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <asm/ccwdev.h>
|
2005-09-03 22:58:01 +00:00
|
|
|
#include <asm/cio.h>
|
2007-04-27 14:01:31 +00:00
|
|
|
#include <asm/chpid.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "cio.h"
|
|
|
|
#include "cio_debug.h"
|
|
|
|
#include "css.h"
|
|
|
|
#include "device.h"
|
|
|
|
#include "chsc.h"
|
|
|
|
#include "ioasm.h"
|
2007-04-27 14:01:28 +00:00
|
|
|
#include "chp.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-26 13:10:37 +00:00
|
|
|
static int timeout_log_enabled;
|
|
|
|
|
|
|
|
static int __init ccw_timeout_log_setup(char *unused)
|
|
|
|
{
|
|
|
|
timeout_log_enabled = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__setup("ccw_timeout_log", ccw_timeout_log_setup);
|
|
|
|
|
|
|
|
static void ccw_timeout_log(struct ccw_device *cdev)
|
|
|
|
{
|
|
|
|
struct schib schib;
|
|
|
|
struct subchannel *sch;
|
2008-01-26 13:10:43 +00:00
|
|
|
struct io_subchannel_private *private;
|
2008-07-14 07:58:51 +00:00
|
|
|
union orb *orb;
|
2008-01-26 13:10:37 +00:00
|
|
|
int cc;
|
|
|
|
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
2008-01-26 13:10:43 +00:00
|
|
|
private = to_io_private(sch);
|
2008-07-14 07:58:51 +00:00
|
|
|
orb = &private->orb;
|
2008-01-26 13:10:37 +00:00
|
|
|
cc = stsch(sch->schid, &schib);
|
|
|
|
|
|
|
|
printk(KERN_WARNING "cio: ccw device timeout occurred at %llx, "
|
|
|
|
"device information:\n", get_clock());
|
|
|
|
printk(KERN_WARNING "cio: orb:\n");
|
|
|
|
print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
|
2008-07-14 07:58:51 +00:00
|
|
|
orb, sizeof(*orb), 0);
|
2008-10-10 19:33:09 +00:00
|
|
|
printk(KERN_WARNING "cio: ccw device bus id: %s\n",
|
|
|
|
dev_name(&cdev->dev));
|
|
|
|
printk(KERN_WARNING "cio: subchannel bus id: %s\n",
|
|
|
|
dev_name(&sch->dev));
|
2008-01-26 13:10:37 +00:00
|
|
|
printk(KERN_WARNING "cio: subchannel lpm: %02x, opm: %02x, "
|
|
|
|
"vpm: %02x\n", sch->lpm, sch->opm, sch->vpm);
|
|
|
|
|
2008-07-14 07:58:51 +00:00
|
|
|
if (orb->tm.b) {
|
|
|
|
printk(KERN_WARNING "cio: orb indicates transport mode\n");
|
|
|
|
printk(KERN_WARNING "cio: last tcw:\n");
|
|
|
|
print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
|
|
|
|
(void *)(addr_t)orb->tm.tcw,
|
|
|
|
sizeof(struct tcw), 0);
|
|
|
|
} else {
|
|
|
|
printk(KERN_WARNING "cio: orb indicates command mode\n");
|
|
|
|
if ((void *)(addr_t)orb->cmd.cpa == &private->sense_ccw ||
|
|
|
|
(void *)(addr_t)orb->cmd.cpa == cdev->private->iccws)
|
|
|
|
printk(KERN_WARNING "cio: last channel program "
|
|
|
|
"(intern):\n");
|
|
|
|
else
|
|
|
|
printk(KERN_WARNING "cio: last channel program:\n");
|
|
|
|
|
|
|
|
print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
|
|
|
|
(void *)(addr_t)orb->cmd.cpa,
|
|
|
|
sizeof(struct ccw1), 0);
|
|
|
|
}
|
2008-01-26 13:10:37 +00:00
|
|
|
printk(KERN_WARNING "cio: ccw device state: %d\n",
|
|
|
|
cdev->private->state);
|
|
|
|
printk(KERN_WARNING "cio: store subchannel returned: cc=%d\n", cc);
|
|
|
|
printk(KERN_WARNING "cio: schib:\n");
|
|
|
|
print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
|
|
|
|
&schib, sizeof(schib), 0);
|
|
|
|
printk(KERN_WARNING "cio: ccw device flags:\n");
|
|
|
|
print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
|
|
|
|
&cdev->private->flags, sizeof(cdev->private->flags), 0);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ccw_device_timeout(unsigned long data)
|
|
|
|
{
|
|
|
|
struct ccw_device *cdev;
|
|
|
|
|
|
|
|
cdev = (struct ccw_device *) data;
|
|
|
|
spin_lock_irq(cdev->ccwlock);
|
2008-01-26 13:10:37 +00:00
|
|
|
if (timeout_log_enabled)
|
|
|
|
ccw_timeout_log(cdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
dev_fsm_event(cdev, DEV_EVENT_TIMEOUT);
|
|
|
|
spin_unlock_irq(cdev->ccwlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set timeout
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ccw_device_set_timeout(struct ccw_device *cdev, int expires)
|
|
|
|
{
|
|
|
|
if (expires == 0) {
|
|
|
|
del_timer(&cdev->private->timer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (timer_pending(&cdev->private->timer)) {
|
|
|
|
if (mod_timer(&cdev->private->timer, jiffies + expires))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cdev->private->timer.function = ccw_device_timeout;
|
|
|
|
cdev->private->timer.data = (unsigned long) cdev;
|
|
|
|
cdev->private->timer.expires = jiffies + expires;
|
|
|
|
add_timer(&cdev->private->timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel running i/o. This is called repeatedly since halt/clear are
|
|
|
|
* asynchronous operations. We do one try with cio_cancel, two tries
|
|
|
|
* with cio_halt, 255 tries with cio_clear. If everythings fails panic.
|
|
|
|
* Returns 0 if device now idle, -ENODEV for device not operational and
|
|
|
|
* -EBUSY if an interrupt is expected (either from halt/clear or from a
|
|
|
|
* status pending).
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ccw_device_cancel_halt_clear(struct ccw_device *cdev)
|
|
|
|
{
|
|
|
|
struct subchannel *sch;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
2008-12-25 12:39:12 +00:00
|
|
|
if (cio_update_schib(sch))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
2007-03-05 22:36:02 +00:00
|
|
|
if (!sch->schib.pmcw.ena)
|
|
|
|
/* Not operational -> done. */
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
/* Stage 1: cancel io. */
|
2008-07-14 07:58:50 +00:00
|
|
|
if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_HALT_PEND) &&
|
|
|
|
!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
|
2008-07-14 07:58:51 +00:00
|
|
|
if (!scsw_is_tm(&sch->schib.scsw)) {
|
|
|
|
ret = cio_cancel(sch);
|
|
|
|
if (ret != -EINVAL)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* cancel io unsuccessful or not applicable (transport mode).
|
|
|
|
* Continue with asynchronous instructions. */
|
2005-04-16 22:20:36 +00:00
|
|
|
cdev->private->iretry = 3; /* 3 halt retries. */
|
|
|
|
}
|
2008-07-14 07:58:50 +00:00
|
|
|
if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Stage 2: halt io. */
|
|
|
|
if (cdev->private->iretry) {
|
|
|
|
cdev->private->iretry--;
|
|
|
|
ret = cio_halt(sch);
|
2006-07-27 12:00:23 +00:00
|
|
|
if (ret != -EBUSY)
|
|
|
|
return (ret == 0) ? -EBUSY : ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
/* halt io unsuccessful. */
|
|
|
|
cdev->private->iretry = 255; /* 255 clear retries. */
|
|
|
|
}
|
|
|
|
/* Stage 3: clear io. */
|
|
|
|
if (cdev->private->iretry) {
|
|
|
|
cdev->private->iretry--;
|
|
|
|
ret = cio_clear (sch);
|
|
|
|
return (ret == 0) ? -EBUSY : ret;
|
|
|
|
}
|
|
|
|
panic("Can't stop i/o on subchannel.\n");
|
|
|
|
}
|
|
|
|
|
2009-06-16 08:30:20 +00:00
|
|
|
void ccw_device_update_sense_data(struct ccw_device *cdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-06-16 08:30:20 +00:00
|
|
|
memset(&cdev->id, 0, sizeof(cdev->id));
|
|
|
|
cdev->id.cu_type = cdev->private->senseid.cu_type;
|
|
|
|
cdev->id.cu_model = cdev->private->senseid.cu_model;
|
|
|
|
cdev->id.dev_type = cdev->private->senseid.dev_type;
|
|
|
|
cdev->id.dev_model = cdev->private->senseid.dev_model;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-06-16 08:30:20 +00:00
|
|
|
int ccw_device_test_sense_data(struct ccw_device *cdev)
|
|
|
|
{
|
|
|
|
return cdev->id.cu_type == cdev->private->senseid.cu_type &&
|
|
|
|
cdev->id.cu_model == cdev->private->senseid.cu_model &&
|
|
|
|
cdev->id.dev_type == cdev->private->senseid.dev_type &&
|
|
|
|
cdev->id.dev_model == cdev->private->senseid.dev_model;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The machine won't give us any notification by machine check if a chpid has
|
|
|
|
* been varied online on the SE so we have to find out by magic (i. e. driving
|
|
|
|
* the channel subsystem to device selection and updating our path masks).
|
|
|
|
*/
|
2007-02-05 20:18:53 +00:00
|
|
|
static void
|
2005-04-16 22:20:36 +00:00
|
|
|
__recover_lost_chpids(struct subchannel *sch, int old_lpm)
|
|
|
|
{
|
|
|
|
int mask, i;
|
2007-04-27 14:01:26 +00:00
|
|
|
struct chp_id chpid;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-27 14:01:26 +00:00
|
|
|
chp_id_init(&chpid);
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i<8; i++) {
|
|
|
|
mask = 0x80 >> i;
|
|
|
|
if (!(sch->lpm & mask))
|
|
|
|
continue;
|
|
|
|
if (old_lpm & mask)
|
|
|
|
continue;
|
2007-04-27 14:01:26 +00:00
|
|
|
chpid.id = sch->schib.pmcw.chpid[i];
|
2007-04-27 14:01:34 +00:00
|
|
|
if (!chp_is_registered(chpid))
|
|
|
|
css_schedule_eval_all();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop device recognition.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ccw_device_recog_done(struct ccw_device *cdev, int state)
|
|
|
|
{
|
|
|
|
struct subchannel *sch;
|
2009-06-16 08:30:20 +00:00
|
|
|
int old_lpm;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
|
|
|
|
2009-12-07 11:51:36 +00:00
|
|
|
if (cio_disable_subchannel(sch))
|
|
|
|
state = DEV_STATE_NOT_OPER;
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Now that we tried recognition, we have performed device selection
|
|
|
|
* through ssch() and the path information is up to date.
|
|
|
|
*/
|
|
|
|
old_lpm = sch->lpm;
|
2008-12-25 12:39:12 +00:00
|
|
|
|
2005-07-29 21:03:37 +00:00
|
|
|
/* Check since device may again have become not operational. */
|
2008-12-25 12:39:12 +00:00
|
|
|
if (cio_update_schib(sch))
|
2005-07-29 21:03:37 +00:00
|
|
|
state = DEV_STATE_NOT_OPER;
|
2008-12-25 12:39:12 +00:00
|
|
|
else
|
|
|
|
sch->lpm = sch->schib.pmcw.pam & sch->opm;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
|
|
|
|
/* Force reprobe on all chpids. */
|
|
|
|
old_lpm = 0;
|
|
|
|
if (sch->lpm != old_lpm)
|
|
|
|
__recover_lost_chpids(sch, old_lpm);
|
2009-03-31 17:16:05 +00:00
|
|
|
if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID &&
|
|
|
|
(state == DEV_STATE_NOT_OPER || state == DEV_STATE_BOXED)) {
|
|
|
|
cdev->private->flags.recog_done = 1;
|
|
|
|
cdev->private->state = DEV_STATE_DISCONNECTED;
|
|
|
|
wake_up(&cdev->private->wait_q);
|
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-06-16 08:30:20 +00:00
|
|
|
if (cdev->private->flags.resuming) {
|
|
|
|
cdev->private->state = state;
|
|
|
|
cdev->private->flags.recog_done = 1;
|
|
|
|
wake_up(&cdev->private->wait_q);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (state) {
|
|
|
|
case DEV_STATE_NOT_OPER:
|
|
|
|
break;
|
|
|
|
case DEV_STATE_OFFLINE:
|
2009-06-16 08:30:20 +00:00
|
|
|
if (!cdev->online) {
|
|
|
|
ccw_device_update_sense_data(cdev);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-06-16 08:30:20 +00:00
|
|
|
cdev->private->state = DEV_STATE_OFFLINE;
|
|
|
|
cdev->private->flags.recog_done = 1;
|
|
|
|
if (ccw_device_test_sense_data(cdev)) {
|
|
|
|
cdev->private->flags.donotify = 1;
|
|
|
|
ccw_device_online(cdev);
|
|
|
|
wake_up(&cdev->private->wait_q);
|
|
|
|
} else {
|
|
|
|
ccw_device_update_sense_data(cdev);
|
2009-12-07 11:51:19 +00:00
|
|
|
ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-06-16 08:30:20 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
case DEV_STATE_BOXED:
|
2009-03-31 17:16:05 +00:00
|
|
|
if (cdev->id.cu_type != 0) { /* device was recognized before */
|
|
|
|
cdev->private->flags.recog_done = 1;
|
|
|
|
cdev->private->state = DEV_STATE_BOXED;
|
|
|
|
wake_up(&cdev->private->wait_q);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
cdev->private->state = state;
|
|
|
|
io_subchannel_recog_done(cdev);
|
2009-03-31 17:16:03 +00:00
|
|
|
wake_up(&cdev->private->wait_q);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function called from device_id.c after sense id has completed.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ccw_device_sense_id_done(struct ccw_device *cdev, int err)
|
|
|
|
{
|
|
|
|
switch (err) {
|
|
|
|
case 0:
|
|
|
|
ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
|
|
|
|
break;
|
|
|
|
case -ETIME: /* Sense id stopped by timeout. */
|
|
|
|
ccw_device_recog_done(cdev, DEV_STATE_BOXED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-26 21:37:28 +00:00
|
|
|
/**
|
|
|
|
* ccw_device_notify() - inform the device's driver about an event
|
|
|
|
* @cdev: device for which an event occured
|
|
|
|
* @event: event that occurred
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* -%EINVAL if the device is offline or has no driver.
|
|
|
|
* -%EOPNOTSUPP if the device's driver has no notifier registered.
|
|
|
|
* %NOTIFY_OK if the driver wants to keep the device.
|
|
|
|
* %NOTIFY_BAD if the driver doesn't want to keep the device.
|
|
|
|
*/
|
2008-07-14 07:58:45 +00:00
|
|
|
int ccw_device_notify(struct ccw_device *cdev, int event)
|
|
|
|
{
|
2010-02-26 21:37:28 +00:00
|
|
|
int ret = -EINVAL;
|
|
|
|
|
2008-07-14 07:58:45 +00:00
|
|
|
if (!cdev->drv)
|
2010-02-26 21:37:28 +00:00
|
|
|
goto out;
|
2008-07-14 07:58:45 +00:00
|
|
|
if (!cdev->online)
|
2010-02-26 21:37:28 +00:00
|
|
|
goto out;
|
2008-08-21 17:46:39 +00:00
|
|
|
CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
|
|
|
|
cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
|
|
|
|
event);
|
2010-02-26 21:37:28 +00:00
|
|
|
if (!cdev->drv->notify) {
|
|
|
|
ret = -EOPNOTSUPP;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (cdev->drv->notify(cdev, event))
|
|
|
|
ret = NOTIFY_OK;
|
|
|
|
else
|
|
|
|
ret = NOTIFY_BAD;
|
|
|
|
out:
|
|
|
|
return ret;
|
2008-07-14 07:58:45 +00:00
|
|
|
}
|
|
|
|
|
2008-08-21 17:46:39 +00:00
|
|
|
static void ccw_device_oper_notify(struct ccw_device *cdev)
|
|
|
|
{
|
2010-02-26 21:37:28 +00:00
|
|
|
if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_OK) {
|
2006-06-29 13:08:41 +00:00
|
|
|
/* Reenable channel measurements, if needed. */
|
2009-12-07 11:51:19 +00:00
|
|
|
ccw_device_sched_todo(cdev, CDEV_TODO_ENABLE_CMF);
|
2008-08-21 17:46:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Driver doesn't want device back. */
|
|
|
|
ccw_device_set_notoper(cdev);
|
2009-12-07 11:51:19 +00:00
|
|
|
ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finished with online/offline processing.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ccw_device_done(struct ccw_device *cdev, int state)
|
|
|
|
{
|
|
|
|
struct subchannel *sch;
|
|
|
|
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
|
|
|
|
2006-10-04 18:02:02 +00:00
|
|
|
ccw_device_set_timeout(cdev, 0);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (state != DEV_STATE_ONLINE)
|
|
|
|
cio_disable_subchannel(sch);
|
|
|
|
|
|
|
|
/* Reset device status. */
|
|
|
|
memset(&cdev->private->irb, 0, sizeof(struct irb));
|
|
|
|
|
|
|
|
cdev->private->state = state;
|
|
|
|
|
2009-10-06 08:34:01 +00:00
|
|
|
switch (state) {
|
|
|
|
case DEV_STATE_BOXED:
|
2008-05-07 07:22:54 +00:00
|
|
|
CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
|
|
|
|
cdev->private->dev_id.devno, sch->schid.sch_no);
|
2010-02-26 21:37:28 +00:00
|
|
|
if (cdev->online &&
|
|
|
|
ccw_device_notify(cdev, CIO_BOXED) != NOTIFY_OK)
|
2009-12-07 11:51:19 +00:00
|
|
|
ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
|
2009-03-31 17:16:05 +00:00
|
|
|
cdev->private->flags.donotify = 0;
|
2009-10-06 08:34:01 +00:00
|
|
|
break;
|
|
|
|
case DEV_STATE_NOT_OPER:
|
2009-09-11 08:28:17 +00:00
|
|
|
CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n",
|
|
|
|
cdev->private->dev_id.devno, sch->schid.sch_no);
|
2010-02-26 21:37:28 +00:00
|
|
|
if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
|
2009-12-07 11:51:19 +00:00
|
|
|
ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
|
2009-10-06 08:34:02 +00:00
|
|
|
else
|
|
|
|
ccw_device_set_disconnected(cdev);
|
2009-09-11 08:28:17 +00:00
|
|
|
cdev->private->flags.donotify = 0;
|
2009-10-06 08:34:01 +00:00
|
|
|
break;
|
|
|
|
case DEV_STATE_DISCONNECTED:
|
|
|
|
CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel "
|
|
|
|
"%04x\n", cdev->private->dev_id.devno,
|
|
|
|
sch->schid.sch_no);
|
2010-02-26 21:37:28 +00:00
|
|
|
if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK)
|
2009-12-07 11:51:19 +00:00
|
|
|
ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
|
2009-10-06 08:34:01 +00:00
|
|
|
else
|
|
|
|
ccw_device_set_disconnected(cdev);
|
|
|
|
cdev->private->flags.donotify = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-09-11 08:28:17 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (cdev->private->flags.donotify) {
|
|
|
|
cdev->private->flags.donotify = 0;
|
2008-08-21 17:46:39 +00:00
|
|
|
ccw_device_oper_notify(cdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
wake_up(&cdev->private->wait_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start device recognition.
|
|
|
|
*/
|
2009-12-07 11:51:21 +00:00
|
|
|
void ccw_device_recognition(struct ccw_device *cdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-12-07 11:51:21 +00:00
|
|
|
struct subchannel *sch = to_subchannel(cdev->dev.parent);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We used to start here with a sense pgid to find out whether a device
|
|
|
|
* is locked by someone else. Unfortunately, the sense pgid command
|
|
|
|
* code has other meanings on devices predating the path grouping
|
|
|
|
* algorithm, so we start with sense id and box the device after an
|
|
|
|
* timeout (or if sense pgid during path verification detects the device
|
|
|
|
* is locked, as may happen on newer devices).
|
|
|
|
*/
|
|
|
|
cdev->private->flags.recog_done = 0;
|
|
|
|
cdev->private->state = DEV_STATE_SENSE_ID;
|
2009-12-07 11:51:21 +00:00
|
|
|
if (cio_enable_subchannel(sch, (u32) (addr_t) sch)) {
|
|
|
|
ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
ccw_device_sense_id_start(cdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-12-07 11:51:26 +00:00
|
|
|
* Handle events for states that use the ccw request infrastructure.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2009-12-07 11:51:26 +00:00
|
|
|
static void ccw_device_request_event(struct ccw_device *cdev, enum dev_event e)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-12-07 11:51:26 +00:00
|
|
|
switch (e) {
|
|
|
|
case DEV_EVENT_NOTOPER:
|
|
|
|
ccw_request_notoper(cdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2009-12-07 11:51:26 +00:00
|
|
|
case DEV_EVENT_INTERRUPT:
|
|
|
|
ccw_request_handler(cdev);
|
|
|
|
break;
|
|
|
|
case DEV_EVENT_TIMEOUT:
|
|
|
|
ccw_request_timeout(cdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-12-07 11:51:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ccw_device_verify_done(struct ccw_device *cdev, int err)
|
|
|
|
{
|
2006-09-20 13:59:59 +00:00
|
|
|
struct subchannel *sch;
|
|
|
|
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
|
|
|
/* Update schib - pom may have changed. */
|
2008-12-25 12:39:12 +00:00
|
|
|
if (cio_update_schib(sch)) {
|
2009-12-07 11:51:22 +00:00
|
|
|
err = -ENODEV;
|
|
|
|
goto callback;
|
2008-12-25 12:39:12 +00:00
|
|
|
}
|
2006-09-20 13:59:59 +00:00
|
|
|
/* Update lpm with verified path mask. */
|
|
|
|
sch->lpm = sch->vpm;
|
|
|
|
/* Repeat path verification? */
|
|
|
|
if (cdev->private->flags.doverify) {
|
|
|
|
ccw_device_verify_start(cdev);
|
|
|
|
return;
|
|
|
|
}
|
2009-12-07 11:51:22 +00:00
|
|
|
callback:
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (err) {
|
|
|
|
case 0:
|
|
|
|
ccw_device_done(cdev, DEV_STATE_ONLINE);
|
|
|
|
/* Deliver fake irb to device driver, if needed. */
|
|
|
|
if (cdev->private->flags.fake_irb) {
|
|
|
|
memset(&cdev->private->irb, 0, sizeof(struct irb));
|
2008-07-14 07:58:50 +00:00
|
|
|
cdev->private->irb.scsw.cmd.cc = 1;
|
|
|
|
cdev->private->irb.scsw.cmd.fctl = SCSW_FCTL_START_FUNC;
|
|
|
|
cdev->private->irb.scsw.cmd.actl = SCSW_ACTL_START_PEND;
|
|
|
|
cdev->private->irb.scsw.cmd.stctl =
|
|
|
|
SCSW_STCTL_STATUS_PEND;
|
2005-04-16 22:20:36 +00:00
|
|
|
cdev->private->flags.fake_irb = 0;
|
|
|
|
if (cdev->handler)
|
|
|
|
cdev->handler(cdev, cdev->private->intparm,
|
|
|
|
&cdev->private->irb);
|
|
|
|
memset(&cdev->private->irb, 0, sizeof(struct irb));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case -ETIME:
|
2009-12-07 11:51:31 +00:00
|
|
|
case -EUSERS:
|
2006-10-18 16:30:43 +00:00
|
|
|
/* Reset oper notify indication after verify error. */
|
|
|
|
cdev->private->flags.donotify = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
ccw_device_done(cdev, DEV_STATE_BOXED);
|
|
|
|
break;
|
2009-12-07 11:51:22 +00:00
|
|
|
case -EACCES:
|
|
|
|
/* Reset oper notify indication after verify error. */
|
|
|
|
cdev->private->flags.donotify = 0;
|
|
|
|
ccw_device_done(cdev, DEV_STATE_DISCONNECTED);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
2006-10-18 16:30:43 +00:00
|
|
|
/* Reset oper notify indication after verify error. */
|
|
|
|
cdev->private->flags.donotify = 0;
|
2009-12-07 11:51:22 +00:00
|
|
|
ccw_device_done(cdev, DEV_STATE_NOT_OPER);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get device online.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ccw_device_online(struct ccw_device *cdev)
|
|
|
|
{
|
|
|
|
struct subchannel *sch;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((cdev->private->state != DEV_STATE_OFFLINE) &&
|
|
|
|
(cdev->private->state != DEV_STATE_BOXED))
|
|
|
|
return -EINVAL;
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
2008-04-30 11:38:39 +00:00
|
|
|
ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
/* Couldn't enable the subchannel for i/o. Sick device. */
|
|
|
|
if (ret == -ENODEV)
|
|
|
|
dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-12-07 11:51:31 +00:00
|
|
|
/* Start initial path verification. */
|
|
|
|
cdev->private->state = DEV_STATE_VERIFY;
|
|
|
|
ccw_device_verify_start(cdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ccw_device_disband_done(struct ccw_device *cdev, int err)
|
|
|
|
{
|
|
|
|
switch (err) {
|
|
|
|
case 0:
|
|
|
|
ccw_device_done(cdev, DEV_STATE_OFFLINE);
|
|
|
|
break;
|
|
|
|
case -ETIME:
|
|
|
|
ccw_device_done(cdev, DEV_STATE_BOXED);
|
|
|
|
break;
|
|
|
|
default:
|
2007-05-31 15:38:07 +00:00
|
|
|
cdev->private->flags.donotify = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
ccw_device_done(cdev, DEV_STATE_NOT_OPER);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown device.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ccw_device_offline(struct ccw_device *cdev)
|
|
|
|
{
|
|
|
|
struct subchannel *sch;
|
|
|
|
|
2008-09-09 10:38:59 +00:00
|
|
|
/* Allow ccw_device_offline while disconnected. */
|
|
|
|
if (cdev->private->state == DEV_STATE_DISCONNECTED ||
|
|
|
|
cdev->private->state == DEV_STATE_NOT_OPER) {
|
|
|
|
cdev->private->flags.donotify = 0;
|
|
|
|
ccw_device_done(cdev, DEV_STATE_NOT_OPER);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-10-06 08:34:03 +00:00
|
|
|
if (cdev->private->state == DEV_STATE_BOXED) {
|
|
|
|
ccw_device_done(cdev, DEV_STATE_BOXED);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-12-08 14:54:28 +00:00
|
|
|
if (ccw_device_is_orphan(cdev)) {
|
|
|
|
ccw_device_done(cdev, DEV_STATE_OFFLINE);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
2008-12-25 12:39:12 +00:00
|
|
|
if (cio_update_schib(sch))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
2008-07-14 07:58:50 +00:00
|
|
|
if (scsw_actl(&sch->schib.scsw) != 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EBUSY;
|
2008-07-14 07:58:50 +00:00
|
|
|
if (cdev->private->state != DEV_STATE_ONLINE)
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Are we doing path grouping? */
|
2009-12-07 11:51:30 +00:00
|
|
|
if (!cdev->private->flags.pgroup) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* No, set state offline immediately. */
|
|
|
|
ccw_device_done(cdev, DEV_STATE_OFFLINE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Start Set Path Group commands. */
|
|
|
|
cdev->private->state = DEV_STATE_DISBAND_PGID;
|
|
|
|
ccw_device_disband_start(cdev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-12 14:11:26 +00:00
|
|
|
* Handle not operational event in non-special state.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2007-10-12 14:11:26 +00:00
|
|
|
static void ccw_device_generic_notoper(struct ccw_device *cdev,
|
|
|
|
enum dev_event dev_event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2010-02-26 21:37:28 +00:00
|
|
|
if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
|
2009-12-07 11:51:19 +00:00
|
|
|
ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
|
2009-10-06 08:34:02 +00:00
|
|
|
else
|
|
|
|
ccw_device_set_disconnected(cdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 08:28:14 +00:00
|
|
|
/*
|
|
|
|
* Handle path verification event in offline state.
|
|
|
|
*/
|
|
|
|
static void ccw_device_offline_verify(struct ccw_device *cdev,
|
|
|
|
enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
struct subchannel *sch = to_subchannel(cdev->dev.parent);
|
|
|
|
|
|
|
|
css_schedule_eval(sch->schid);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Handle path verification event.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
struct subchannel *sch;
|
|
|
|
|
|
|
|
if (cdev->private->state == DEV_STATE_W4SENSE) {
|
|
|
|
cdev->private->flags.doverify = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
|
|
|
/*
|
|
|
|
* Since we might not just be coming from an interrupt from the
|
|
|
|
* subchannel we have to update the schib.
|
|
|
|
*/
|
2008-12-25 12:39:12 +00:00
|
|
|
if (cio_update_schib(sch)) {
|
|
|
|
ccw_device_verify_done(cdev, -ENODEV);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-14 07:58:50 +00:00
|
|
|
if (scsw_actl(&sch->schib.scsw) != 0 ||
|
|
|
|
(scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_STATUS_PEND) ||
|
|
|
|
(scsw_stctl(&cdev->private->irb.scsw) & SCSW_STCTL_STATUS_PEND)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* No final status yet or final status not yet delivered
|
|
|
|
* to the device driver. Can't do path verfication now,
|
|
|
|
* delay until final status was delivered.
|
|
|
|
*/
|
|
|
|
cdev->private->flags.doverify = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Device is idle, we can do the path verification. */
|
|
|
|
cdev->private->state = DEV_STATE_VERIFY;
|
|
|
|
ccw_device_verify_start(cdev);
|
|
|
|
}
|
|
|
|
|
2009-12-07 11:51:32 +00:00
|
|
|
/*
|
|
|
|
* Handle path verification event in boxed state.
|
|
|
|
*/
|
|
|
|
static void ccw_device_boxed_verify(struct ccw_device *cdev,
|
|
|
|
enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
struct subchannel *sch = to_subchannel(cdev->dev.parent);
|
|
|
|
|
|
|
|
if (cdev->online) {
|
|
|
|
if (cio_enable_subchannel(sch, (u32) (addr_t) sch))
|
|
|
|
ccw_device_done(cdev, DEV_STATE_NOT_OPER);
|
|
|
|
else
|
|
|
|
ccw_device_online_verify(cdev, dev_event);
|
|
|
|
} else
|
|
|
|
css_schedule_eval(sch->schid);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Got an interrupt for a normal io (state online).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
struct irb *irb;
|
2008-07-14 07:58:51 +00:00
|
|
|
int is_cmd;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
irb = (struct irb *) __LC_IRB;
|
2008-07-14 07:58:51 +00:00
|
|
|
is_cmd = !scsw_is_tm(&irb->scsw);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Check for unsolicited interrupt. */
|
2008-07-14 07:58:50 +00:00
|
|
|
if (!scsw_is_solicited(&irb->scsw)) {
|
2008-07-14 07:58:51 +00:00
|
|
|
if (is_cmd && (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
|
2005-04-16 22:20:36 +00:00
|
|
|
!irb->esw.esw0.erw.cons) {
|
|
|
|
/* Unit check but no sense data. Need basic sense. */
|
|
|
|
if (ccw_device_do_sense(cdev, irb) != 0)
|
|
|
|
goto call_handler_unsol;
|
2006-06-04 09:51:27 +00:00
|
|
|
memcpy(&cdev->private->irb, irb, sizeof(struct irb));
|
2005-04-16 22:20:36 +00:00
|
|
|
cdev->private->state = DEV_STATE_W4SENSE;
|
|
|
|
cdev->private->intparm = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
call_handler_unsol:
|
|
|
|
if (cdev->handler)
|
|
|
|
cdev->handler (cdev, 0, irb);
|
2007-02-05 20:17:09 +00:00
|
|
|
if (cdev->private->flags.doverify)
|
|
|
|
ccw_device_online_verify(cdev, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Accumulate status and find out if a basic sense is needed. */
|
|
|
|
ccw_device_accumulate_irb(cdev, irb);
|
2008-07-14 07:58:51 +00:00
|
|
|
if (is_cmd && cdev->private->flags.dosense) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ccw_device_do_sense(cdev, irb) == 0) {
|
|
|
|
cdev->private->state = DEV_STATE_W4SENSE;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Call the handler. */
|
|
|
|
if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
|
|
|
|
/* Start delayed path verification. */
|
|
|
|
ccw_device_online_verify(cdev, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Got an timeout in online state.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ccw_device_set_timeout(cdev, 0);
|
|
|
|
ret = ccw_device_cancel_halt_clear(cdev);
|
|
|
|
if (ret == -EBUSY) {
|
|
|
|
ccw_device_set_timeout(cdev, 3*HZ);
|
|
|
|
cdev->private->state = DEV_STATE_TIMEOUT_KILL;
|
|
|
|
return;
|
|
|
|
}
|
2007-10-12 14:11:26 +00:00
|
|
|
if (ret == -ENODEV)
|
|
|
|
dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
|
|
|
|
else if (cdev->handler)
|
2005-04-16 22:20:36 +00:00
|
|
|
cdev->handler(cdev, cdev->private->intparm,
|
|
|
|
ERR_PTR(-ETIMEDOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Got an interrupt for a basic sense.
|
|
|
|
*/
|
2007-02-05 20:16:47 +00:00
|
|
|
static void
|
2005-04-16 22:20:36 +00:00
|
|
|
ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
struct irb *irb;
|
|
|
|
|
|
|
|
irb = (struct irb *) __LC_IRB;
|
|
|
|
/* Check for unsolicited interrupt. */
|
2008-07-14 07:58:50 +00:00
|
|
|
if (scsw_stctl(&irb->scsw) ==
|
|
|
|
(SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
|
|
|
|
if (scsw_cc(&irb->scsw) == 1)
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Basic sense hasn't started. Try again. */
|
|
|
|
ccw_device_do_sense(cdev, irb);
|
|
|
|
else {
|
2008-05-07 07:22:54 +00:00
|
|
|
CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
|
2007-07-27 10:29:19 +00:00
|
|
|
"interrupt during w4sense...\n",
|
|
|
|
cdev->private->dev_id.ssid,
|
|
|
|
cdev->private->dev_id.devno);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cdev->handler)
|
|
|
|
cdev->handler (cdev, 0, irb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2006-03-24 11:15:12 +00:00
|
|
|
/*
|
|
|
|
* Check if a halt or clear has been issued in the meanwhile. If yes,
|
|
|
|
* only deliver the halt/clear interrupt to the device driver as if it
|
|
|
|
* had killed the original request.
|
|
|
|
*/
|
2008-07-14 07:58:50 +00:00
|
|
|
if (scsw_fctl(&irb->scsw) &
|
|
|
|
(SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
|
2006-03-24 11:15:12 +00:00
|
|
|
cdev->private->flags.dosense = 0;
|
|
|
|
memset(&cdev->private->irb, 0, sizeof(struct irb));
|
|
|
|
ccw_device_accumulate_irb(cdev, irb);
|
|
|
|
goto call_handler;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Add basic sense info to irb. */
|
|
|
|
ccw_device_accumulate_basic_sense(cdev, irb);
|
|
|
|
if (cdev->private->flags.dosense) {
|
|
|
|
/* Another basic sense is needed. */
|
|
|
|
ccw_device_do_sense(cdev, irb);
|
|
|
|
return;
|
|
|
|
}
|
2006-03-24 11:15:12 +00:00
|
|
|
call_handler:
|
2005-04-16 22:20:36 +00:00
|
|
|
cdev->private->state = DEV_STATE_ONLINE;
|
2009-09-11 08:28:21 +00:00
|
|
|
/* In case sensing interfered with setting the device online */
|
|
|
|
wake_up(&cdev->private->wait_q);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Call the handler. */
|
|
|
|
if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
|
|
|
|
/* Start delayed path verification. */
|
|
|
|
ccw_device_online_verify(cdev, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
struct subchannel *sch;
|
|
|
|
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
|
|
|
ccw_device_set_timeout(cdev, 0);
|
2007-03-05 22:35:59 +00:00
|
|
|
/* Start delayed path verification. */
|
|
|
|
ccw_device_online_verify(cdev, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* OK, i/o is dead now. Call interrupt handler. */
|
|
|
|
if (cdev->handler)
|
|
|
|
cdev->handler(cdev, cdev->private->intparm,
|
2006-10-11 13:31:41 +00:00
|
|
|
ERR_PTR(-EIO));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ccw_device_cancel_halt_clear(cdev);
|
|
|
|
if (ret == -EBUSY) {
|
|
|
|
ccw_device_set_timeout(cdev, 3*HZ);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-05 22:35:59 +00:00
|
|
|
/* Start delayed path verification. */
|
|
|
|
ccw_device_online_verify(cdev, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cdev->handler)
|
|
|
|
cdev->handler(cdev, cdev->private->intparm,
|
2006-10-11 13:31:41 +00:00
|
|
|
ERR_PTR(-EIO));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-07-14 07:58:45 +00:00
|
|
|
void ccw_device_kill_io(struct ccw_device *cdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ccw_device_cancel_halt_clear(cdev);
|
|
|
|
if (ret == -EBUSY) {
|
|
|
|
ccw_device_set_timeout(cdev, 3*HZ);
|
|
|
|
cdev->private->state = DEV_STATE_TIMEOUT_KILL;
|
|
|
|
return;
|
|
|
|
}
|
2007-03-05 22:35:59 +00:00
|
|
|
/* Start delayed path verification. */
|
|
|
|
ccw_device_online_verify(cdev, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cdev->handler)
|
|
|
|
cdev->handler(cdev, cdev->private->intparm,
|
2006-10-11 13:31:41 +00:00
|
|
|
ERR_PTR(-EIO));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-09-20 13:59:59 +00:00
|
|
|
ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-20 13:59:59 +00:00
|
|
|
/* Start verification after current task finished. */
|
2006-07-12 14:40:19 +00:00
|
|
|
cdev->private->flags.doverify = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
struct subchannel *sch;
|
|
|
|
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
2008-04-30 11:38:39 +00:00
|
|
|
if (cio_enable_subchannel(sch, (u32)(addr_t)sch) != 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Couldn't enable the subchannel for i/o. Sick device. */
|
|
|
|
return;
|
|
|
|
cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
|
|
|
|
ccw_device_sense_id_start(cdev);
|
|
|
|
}
|
|
|
|
|
2008-07-14 07:58:45 +00:00
|
|
|
void ccw_device_trigger_reprobe(struct ccw_device *cdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-14 07:58:45 +00:00
|
|
|
struct subchannel *sch;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (cdev->private->state != DEV_STATE_DISCONNECTED)
|
|
|
|
return;
|
|
|
|
|
2008-07-14 07:58:45 +00:00
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Update some values. */
|
2008-12-25 12:39:12 +00:00
|
|
|
if (cio_update_schib(sch))
|
2006-12-08 14:54:21 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* The pim, pam, pom values may not be accurate, but they are the best
|
|
|
|
* we have before performing device selection :/
|
|
|
|
*/
|
2006-09-20 13:59:59 +00:00
|
|
|
sch->lpm = sch->schib.pmcw.pam & sch->opm;
|
2008-12-25 12:39:13 +00:00
|
|
|
/*
|
|
|
|
* Use the initial configuration since we can't be shure that the old
|
|
|
|
* paths are valid.
|
|
|
|
*/
|
|
|
|
io_subchannel_init_config(sch);
|
2008-12-25 12:39:14 +00:00
|
|
|
if (cio_commit_config(sch))
|
|
|
|
return;
|
2008-12-25 12:39:13 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* We should also udate ssd info, but this has to wait. */
|
2006-12-08 14:54:28 +00:00
|
|
|
/* Check if this is another device which appeared on the same sch. */
|
2009-12-07 11:51:17 +00:00
|
|
|
if (sch->schib.pmcw.dev != cdev->private->dev_id.devno)
|
|
|
|
css_schedule_eval(sch->schid);
|
|
|
|
else
|
2006-12-08 14:54:28 +00:00
|
|
|
ccw_device_start_id(cdev, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-12-07 11:51:24 +00:00
|
|
|
static void ccw_device_disabled_irq(struct ccw_device *cdev,
|
|
|
|
enum dev_event dev_event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct subchannel *sch;
|
|
|
|
|
|
|
|
sch = to_subchannel(cdev->dev.parent);
|
|
|
|
/*
|
2009-12-07 11:51:24 +00:00
|
|
|
* An interrupt in a disabled state means a previous disable was not
|
2009-03-26 14:24:06 +00:00
|
|
|
* successful - should not happen, but we try to disable again.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
cio_disable_subchannel(sch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
retry_set_schib(cdev);
|
|
|
|
cdev->private->state = DEV_STATE_ONLINE;
|
|
|
|
dev_fsm_event(cdev, dev_event);
|
|
|
|
}
|
|
|
|
|
2006-06-29 13:08:41 +00:00
|
|
|
static void ccw_device_update_cmfblock(struct ccw_device *cdev,
|
|
|
|
enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
cmf_retry_copy_block(cdev);
|
|
|
|
cdev->private->state = DEV_STATE_ONLINE;
|
|
|
|
dev_fsm_event(cdev, dev_event);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
ccw_device_set_timeout(cdev, 0);
|
2009-12-07 11:51:35 +00:00
|
|
|
cdev->private->state = DEV_STATE_NOT_OPER;
|
2005-04-16 22:20:36 +00:00
|
|
|
wake_up(&cdev->private->wait_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ccw_device_cancel_halt_clear(cdev);
|
2009-12-07 11:51:35 +00:00
|
|
|
if (ret == -EBUSY) {
|
|
|
|
ccw_device_set_timeout(cdev, HZ/10);
|
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
cdev->private->state = DEV_STATE_NOT_OPER;
|
|
|
|
wake_up(&cdev->private->wait_q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No operation action. This is used e.g. to ignore a timeout event in
|
|
|
|
* state offline.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* device statemachine
|
|
|
|
*/
|
|
|
|
fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
|
|
|
|
[DEV_STATE_NOT_OPER] = {
|
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_nop,
|
2009-12-07 11:51:24 +00:00
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_disabled_irq,
|
2005-04-16 22:20:36 +00:00
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_nop,
|
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_nop,
|
|
|
|
},
|
|
|
|
[DEV_STATE_SENSE_PGID] = {
|
2009-12-07 11:51:27 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_request_event,
|
2005-04-16 22:20:36 +00:00
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_nop,
|
|
|
|
},
|
|
|
|
[DEV_STATE_SENSE_ID] = {
|
2009-12-07 11:51:26 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_request_event,
|
2005-04-16 22:20:36 +00:00
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_nop,
|
|
|
|
},
|
|
|
|
[DEV_STATE_OFFLINE] = {
|
2007-10-12 14:11:26 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
|
2009-12-07 11:51:24 +00:00
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_disabled_irq,
|
2005-04-16 22:20:36 +00:00
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_nop,
|
2009-09-11 08:28:14 +00:00
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_offline_verify,
|
2005-04-16 22:20:36 +00:00
|
|
|
},
|
|
|
|
[DEV_STATE_VERIFY] = {
|
2009-12-07 11:51:27 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_request_event,
|
2006-09-20 13:59:59 +00:00
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_delay_verify,
|
2005-04-16 22:20:36 +00:00
|
|
|
},
|
|
|
|
[DEV_STATE_ONLINE] = {
|
2007-10-12 14:11:26 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
|
2005-04-16 22:20:36 +00:00
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_irq,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
|
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_online_verify,
|
|
|
|
},
|
|
|
|
[DEV_STATE_W4SENSE] = {
|
2007-10-12 14:11:26 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
|
2005-04-16 22:20:36 +00:00
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_nop,
|
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_online_verify,
|
|
|
|
},
|
|
|
|
[DEV_STATE_DISBAND_PGID] = {
|
2009-12-07 11:51:27 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_request_event,
|
2005-04-16 22:20:36 +00:00
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_nop,
|
|
|
|
},
|
|
|
|
[DEV_STATE_BOXED] = {
|
2007-10-12 14:11:26 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
|
2009-12-07 11:51:32 +00:00
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_nop,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_nop,
|
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_boxed_verify,
|
2005-04-16 22:20:36 +00:00
|
|
|
},
|
|
|
|
/* states to wait for i/o completion before doing something */
|
|
|
|
[DEV_STATE_TIMEOUT_KILL] = {
|
2007-10-12 14:11:26 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
|
2005-04-16 22:20:36 +00:00
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
|
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
|
|
|
|
},
|
|
|
|
[DEV_STATE_QUIESCE] = {
|
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
|
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_nop,
|
|
|
|
},
|
|
|
|
/* special states for devices gone not operational */
|
|
|
|
[DEV_STATE_DISCONNECTED] = {
|
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_nop,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_start_id,
|
2009-12-07 11:51:24 +00:00
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_nop,
|
2006-09-20 13:59:59 +00:00
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_start_id,
|
2005-04-16 22:20:36 +00:00
|
|
|
},
|
|
|
|
[DEV_STATE_DISCONNECTED_SENSE_ID] = {
|
2009-12-07 11:51:26 +00:00
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_request_event,
|
2005-04-16 22:20:36 +00:00
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_nop,
|
|
|
|
},
|
|
|
|
[DEV_STATE_CMFCHANGE] = {
|
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
|
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
|
|
|
|
},
|
2006-06-29 13:08:41 +00:00
|
|
|
[DEV_STATE_CMFUPDATE] = {
|
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
|
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
|
|
|
|
},
|
2009-12-07 11:51:32 +00:00
|
|
|
[DEV_STATE_STEAL_LOCK] = {
|
|
|
|
[DEV_EVENT_NOTOPER] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_INTERRUPT] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_TIMEOUT] = ccw_device_request_event,
|
|
|
|
[DEV_EVENT_VERIFY] = ccw_device_nop,
|
|
|
|
},
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(ccw_device_set_timeout);
|